From e2542866d1134c11920190b686be69434c092dbf Mon Sep 17 00:00:00 2001 From: Manuel Araoz Date: Wed, 27 May 2015 15:01:26 -0300 Subject: [PATCH 1/2] expose BN.fromString problem --- test/crypto/bn.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/crypto/bn.js b/test/crypto/bn.js index a57260d..45d6272 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 7fffff0000000000000000000000000000000000000000000000000000000000', function() { + BN.fromString('7fffff0000000000000000000000000000000000000000000000000000000000') + .toString().should.equal('7fffff0000000000000000000000000000000000000000000000000000000000'); + }); }); describe('#toString', function() { From a03e6b9385b4eb2631baad182f705c03a0ad63dc Mon Sep 17 00:00:00 2001 From: Braydon Fuller Date: Wed, 27 May 2015 14:11:43 -0400 Subject: [PATCH 2/2] 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'); }); });