From d7019e7492e3675d9d90158e42a90808f11ef7c3 Mon Sep 17 00:00:00 2001 From: Wei Lu Date: Sat, 30 May 2015 11:50:38 +0800 Subject: [PATCH] Revert "bufferutils: remove equal, use Buffer.compare" This reverts commit 75540b61169a7975944d8b5bc0e12dcbf50f838d. See discussion in https://github.com/bitcoinjs/bitcoinjs-lib/pull/410 --- src/bufferutils.js | 11 +++++++++++ src/transaction_builder.js | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/bufferutils.js b/src/bufferutils.js index 9f1c85e..773e502 100644 --- a/src/bufferutils.js +++ b/src/bufferutils.js @@ -168,6 +168,16 @@ function varIntBuffer (i) { return buffer } +function equal (a, b) { + if (a.length !== b.length) return false + + for (var i = 0; i < a.length; ++i) { + if (a[i] !== b[i]) return false + } + + return true +} + function reverse (buffer) { var buffer2 = new Buffer(buffer) Array.prototype.reverse.call(buffer2) @@ -175,6 +185,7 @@ function reverse (buffer) { } module.exports = { + equal: equal, pushDataSize: pushDataSize, readPushDataInt: readPushDataInt, readUInt64LE: readUInt64LE, diff --git a/src/transaction_builder.js b/src/transaction_builder.js index cafcfc8..e2b7e28 100644 --- a/src/transaction_builder.js +++ b/src/transaction_builder.js @@ -399,7 +399,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash // enforce in order signing of public keys assert(input.pubKeys.some(function (pubKey, i) { - if (kpPubKey.compare(pubKey) !== 0) return false + if (!bufferutils.equal(kpPubKey, pubKey)) return false assert(!input.signatures[i], 'Signature already exists') @@ -407,7 +407,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash input.signatures[i] = signature return true - }), 'key pair cannot sign for this input') + }, this), 'key pair cannot sign for this input') } module.exports = TransactionBuilder