Browse Source

Add base option for BN.fromString

patch-2
Braydon Fuller 10 years ago
parent
commit
a03e6b9385
  1. 4
      lib/crypto/bn.js
  2. 6
      test/crypto/bn.js

4
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) {

6
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');
});
});

Loading…
Cancel
Save