From a03e6b9385b4eb2631baad182f705c03a0ad63dc Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Wed, 27 May 2015 14:11:43 -0400 Subject: [PATCH] Add base option for BN.fromString --- lib/crypto/bn.js | 4 ++-- test/crypto/bn.js | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/crypto/bn.js b/lib/crypto/bn.js index a1d381c..20b53f8 100644 --- a/lib/crypto/bn.js +++ b/lib/crypto/bn.js @@ -21,9 +21,9 @@ BN.fromNumber = function(n) { return new BN(n); }; -BN.fromString = function(str) { +BN.fromString = function(str, base) { $.checkArgument(_.isString(str)); - return new BN(str); + return new BN(str, base); }; BN.fromBuffer = function(buf, opts) { diff --git a/test/crypto/bn.js b/test/crypto/bn.js index 45d6272..085b40c 100644 --- a/test/crypto/bn.js +++ b/test/crypto/bn.js @@ -79,9 +79,9 @@ describe('BN', function() { it('should make BN from a string', function() { BN.fromString('5').toString().should.equal('5'); }); - it('should work with 7fffff0000000000000000000000000000000000000000000000000000000000', function() { - BN.fromString('7fffff0000000000000000000000000000000000000000000000000000000000') - .toString().should.equal('7fffff0000000000000000000000000000000000000000000000000000000000'); + it('should work with hex string', function() { + BN.fromString('7fffff0000000000000000000000000000000000000000000000000000000000', 16) + .toString(16).should.equal('7fffff0000000000000000000000000000000000000000000000000000000000'); }); });