add BN.prototype.fromBuffer
This commit is contained in:
parent
f6f7a870fb
commit
f8fc3812f0
|
@ -31,6 +31,13 @@ bnjs.fromBuffer = function(buf, opts) {
|
|||
return bn;
|
||||
};
|
||||
|
||||
bnjs.prototype.fromBuffer = function(buf, opts) {
|
||||
var bn = bnjs.fromBuffer(buf, opts);
|
||||
bn.copy(this);
|
||||
|
||||
return this;
|
||||
};
|
||||
|
||||
bnjs.prototype.toBuffer = function(opts) {
|
||||
var buf;
|
||||
if (opts && opts.size) {
|
||||
|
|
|
@ -83,6 +83,11 @@ describe('bn', function() {
|
|||
bn.toString().should.equal('1');
|
||||
});
|
||||
|
||||
it('should work as a prototype method', function() {
|
||||
var bn = BN().fromBuffer(new Buffer('0100', 'hex'), {size: 2, endian: 'little'});
|
||||
bn.toString().should.equal('1');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('#toBuffer', function() {
|
||||
|
|
Loading…
Reference in New Issue