Browse Source

use buffer-equals

hk-custom-address
Daniel Cousens 9 years ago
parent
commit
28372f0cd7
  1. 1
      package.json
  2. 12
      src/bufferutils.js
  3. 12
      src/transaction_builder.js

1
package.json

@ -62,6 +62,7 @@
"bigi": "^1.4.0",
"bip66": "^1.1.0",
"bs58check": "^1.0.5",
"buffer-equals": "^1.0.3",
"create-hash": "^1.1.0",
"create-hmac": "^1.1.3",
"ecurve": "^1.0.0",

12
src/bufferutils.js

@ -167,16 +167,6 @@ 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)
@ -184,7 +174,7 @@ function reverse (buffer) {
}
module.exports = {
equal: equal,
equal: require('buffer-equals'),
pushDataSize: pushDataSize,
readPushDataInt: readPushDataInt,
readUInt64LE: readUInt64LE,

12
src/transaction_builder.js

@ -1,7 +1,7 @@
var baddress = require('./address')
var bcrypto = require('./crypto')
var bscript = require('./script')
var bufferutils = require('./bufferutils')
var bufferEquals = require('buffer-equals')
var networks = require('./networks')
var ops = require('./opcodes')
@ -17,7 +17,7 @@ function fixMSSignatures (transaction, vin, pubKeys, signatures, prevOutScript,
return pubKeys.map(function (pubKey) {
// skip optionally provided pubKey
if (skipPubKey && bufferutils.equal(skipPubKey, pubKey)) return undefined
if (skipPubKey && bufferEquals(skipPubKey, pubKey)) return undefined
var matched
var keyPair2 = ECPair.fromPublicKeyBuffer(pubKey)
@ -346,7 +346,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
if (canSign) {
// if redeemScript was provided, enforce consistency
if (redeemScript) {
if (!bufferutils.equal(input.redeemScript, redeemScript)) throw new Error('Inconsistent redeemScript')
if (!bufferEquals(input.redeemScript, redeemScript)) throw new Error('Inconsistent redeemScript')
}
if (input.hashType !== hashType) throw new Error('Inconsistent hashType')
@ -360,7 +360,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
if (input.prevOutType !== 'scripthash') throw new Error('PrevOutScript must be P2SH')
var scriptHash = bscript.decompile(input.prevOutScript)[1]
if (!bufferutils.equal(scriptHash, bcrypto.hash160(redeemScript))) throw new Error('RedeemScript does not match ' + scriptHash.toString('hex'))
if (!bufferEquals(scriptHash, bcrypto.hash160(redeemScript))) throw new Error('RedeemScript does not match ' + scriptHash.toString('hex'))
}
var scriptType = bscript.classifyOutput(redeemScript)
@ -377,7 +377,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
var pkh1 = redeemScriptChunks[2]
var pkh2 = bcrypto.hash160(keyPair.getPublicKeyBuffer())
if (!bufferutils.equal(pkh1, pkh2)) throw new Error('privateKey cannot sign for this input')
if (!bufferEquals(pkh1, pkh2)) throw new Error('privateKey cannot sign for this input')
pubKeys = [kpPubKey]
break
@ -427,7 +427,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
// enforce in order signing of public keys
var valid = input.pubKeys.some(function (pubKey, i) {
if (!bufferutils.equal(kpPubKey, pubKey)) return false
if (!bufferEquals(kpPubKey, pubKey)) return false
if (input.signatures[i]) throw new Error('Signature already exists')
var signature = keyPair.sign(signatureHash)

Loading…
Cancel
Save