Skip to content

Commit

Permalink
Merge pull request #1253 from maraoz/bn-fromstring
Browse files Browse the repository at this point in the history
add base to BN.fromString
  • Loading branch information
Braydon Fuller committed Jun 1, 2015
2 parents 5ee1c3f + 60b07b5 commit 5d77ff7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/crypto/bn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
4 changes: 4 additions & 0 deletions test/crypto/bn.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit 5d77ff7

Please sign in to comment.