From 621b87f9210d73010a8cc4012299075729506cbe Mon Sep 17 00:00:00 2001 From: Mihai Cimpoesu Date: Mon, 12 Sep 2016 11:58:07 +0100 Subject: [PATCH 1/2] Changed 'ripemd160' to 'rmd160' for compatibility with ' crypto-browserify' --- lib/crypto/hash.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/crypto/hash.js b/lib/crypto/hash.js index 01e4d1547..1a019098d 100644 --- a/lib/crypto/hash.js +++ b/lib/crypto/hash.js @@ -27,7 +27,7 @@ Hash.sha256sha256 = function(buf) { Hash.ripemd160 = function(buf) { $.checkArgument(BufferUtil.isBuffer(buf)); - return crypto.createHash('ripemd160').update(buf).digest(); + return crypto.createHash('rmd160').update(buf).digest(); }; Hash.sha256ripemd160 = function(buf) { From 8ababf2cd7781329acb1dffd7378fa3122b11b85 Mon Sep 17 00:00:00 2001 From: Kirill Fomichev Date: Thu, 25 Feb 2016 19:03:39 +0300 Subject: [PATCH 2/2] Fix PrivateKey.toBuffer --- lib/privatekey.js | 2 +- test/privatekey.js | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/privatekey.js b/lib/privatekey.js index 9697bbfba..636eb2d52 100644 --- a/lib/privatekey.js +++ b/lib/privatekey.js @@ -336,7 +336,7 @@ PrivateKey.prototype.toBigNumber = function(){ * @returns {Buffer} A buffer of the private key */ PrivateKey.prototype.toBuffer = function(){ - return this.bn.toBuffer(); + return this.bn.toBuffer({ size: 32 }); }; /** diff --git a/test/privatekey.js b/test/privatekey.js index 6df029934..ffbaaf893 100644 --- a/test/privatekey.js +++ b/test/privatekey.js @@ -330,6 +330,13 @@ describe('PrivateKey', function() { var fromBuffer = PrivateKey.fromBuffer(toBuffer.toBuffer()); fromBuffer.toString().should.equal(privkey.toString()); }); + + it('should return buffer with length equal 32', function() { + var bn = BN.fromBuffer(buf.slice(0, 31)); + var privkey = new PrivateKey(bn, 'livenet'); + var expected = Buffer.concat([ new Buffer([0]), buf.slice(0, 31) ]); + privkey.toBuffer().toString('hex').should.equal(expected.toString('hex')); + }); }); describe('#toBigNumber', function() {