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 a57260d..085b40c 100644 --- a/test/crypto/bn.js +++ b/test/crypto/bn.js @@ -79,6 +79,10 @@ describe('BN', function() { it('should make BN from a string', function() { BN.fromString('5').toString().should.equal('5'); }); + it('should work with hex string', function() { + BN.fromString('7fffff0000000000000000000000000000000000000000000000000000000000', 16) + .toString(16).should.equal('7fffff0000000000000000000000000000000000000000000000000000000000'); + }); }); describe('#toString', function() {