Skip to content

Commit

Permalink
bn: toString(16,2) for JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
dcousens authored and indutny committed Nov 29, 2017
1 parent c69b4ae commit a46d2e2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/bn.js
Original file line number Diff line number Diff line change
Expand Up @@ -509,7 +509,7 @@
};

BN.prototype.toJSON = function toJSON () {
return this.toString(16);
return this.toString(16, 2);
};

BN.prototype.toBuffer = function toBuffer (endian, length) {
Expand Down
6 changes: 5 additions & 1 deletion test/utils-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,11 @@ describe('BN.js/Utils', function () {

describe('.toJSON', function () {
it('should return hex string', function () {
assert.equal(new BN(0x123).toJSON(), '123');
assert.equal(new BN(0x123).toJSON(), '0123');
});

it('should be padded to multiple of 2 bytes for interop', function () {
assert.equal(new BN(0x1).toJSON(), '01');
});
});

Expand Down

0 comments on commit a46d2e2

Please sign in to comment.