use buffer-equals
This commit is contained in:
parent
c50d510aea
commit
28372f0cd7
@ -62,6 +62,7 @@
|
|||||||
"bigi": "^1.4.0",
|
"bigi": "^1.4.0",
|
||||||
"bip66": "^1.1.0",
|
"bip66": "^1.1.0",
|
||||||
"bs58check": "^1.0.5",
|
"bs58check": "^1.0.5",
|
||||||
|
"buffer-equals": "^1.0.3",
|
||||||
"create-hash": "^1.1.0",
|
"create-hash": "^1.1.0",
|
||||||
"create-hmac": "^1.1.3",
|
"create-hmac": "^1.1.3",
|
||||||
"ecurve": "^1.0.0",
|
"ecurve": "^1.0.0",
|
||||||
|
|||||||
@ -167,16 +167,6 @@ function varIntBuffer (i) {
|
|||||||
return buffer
|
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) {
|
function reverse (buffer) {
|
||||||
var buffer2 = new Buffer(buffer)
|
var buffer2 = new Buffer(buffer)
|
||||||
Array.prototype.reverse.call(buffer2)
|
Array.prototype.reverse.call(buffer2)
|
||||||
@ -184,7 +174,7 @@ function reverse (buffer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
equal: equal,
|
equal: require('buffer-equals'),
|
||||||
pushDataSize: pushDataSize,
|
pushDataSize: pushDataSize,
|
||||||
readPushDataInt: readPushDataInt,
|
readPushDataInt: readPushDataInt,
|
||||||
readUInt64LE: readUInt64LE,
|
readUInt64LE: readUInt64LE,
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
var baddress = require('./address')
|
var baddress = require('./address')
|
||||||
var bcrypto = require('./crypto')
|
var bcrypto = require('./crypto')
|
||||||
var bscript = require('./script')
|
var bscript = require('./script')
|
||||||
var bufferutils = require('./bufferutils')
|
var bufferEquals = require('buffer-equals')
|
||||||
var networks = require('./networks')
|
var networks = require('./networks')
|
||||||
var ops = require('./opcodes')
|
var ops = require('./opcodes')
|
||||||
|
|
||||||
@ -17,7 +17,7 @@ function fixMSSignatures (transaction, vin, pubKeys, signatures, prevOutScript,
|
|||||||
|
|
||||||
return pubKeys.map(function (pubKey) {
|
return pubKeys.map(function (pubKey) {
|
||||||
// skip optionally provided pubKey
|
// skip optionally provided pubKey
|
||||||
if (skipPubKey && bufferutils.equal(skipPubKey, pubKey)) return undefined
|
if (skipPubKey && bufferEquals(skipPubKey, pubKey)) return undefined
|
||||||
|
|
||||||
var matched
|
var matched
|
||||||
var keyPair2 = ECPair.fromPublicKeyBuffer(pubKey)
|
var keyPair2 = ECPair.fromPublicKeyBuffer(pubKey)
|
||||||
@ -346,7 +346,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
|
|||||||
if (canSign) {
|
if (canSign) {
|
||||||
// if redeemScript was provided, enforce consistency
|
// if redeemScript was provided, enforce consistency
|
||||||
if (redeemScript) {
|
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')
|
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')
|
if (input.prevOutType !== 'scripthash') throw new Error('PrevOutScript must be P2SH')
|
||||||
|
|
||||||
var scriptHash = bscript.decompile(input.prevOutScript)[1]
|
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)
|
var scriptType = bscript.classifyOutput(redeemScript)
|
||||||
@ -377,7 +377,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
|
|||||||
var pkh1 = redeemScriptChunks[2]
|
var pkh1 = redeemScriptChunks[2]
|
||||||
var pkh2 = bcrypto.hash160(keyPair.getPublicKeyBuffer())
|
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]
|
pubKeys = [kpPubKey]
|
||||||
|
|
||||||
break
|
break
|
||||||
@ -427,7 +427,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
|
|||||||
|
|
||||||
// enforce in order signing of public keys
|
// enforce in order signing of public keys
|
||||||
var valid = input.pubKeys.some(function (pubKey, i) {
|
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')
|
if (input.signatures[i]) throw new Error('Signature already exists')
|
||||||
|
|
||||||
var signature = keyPair.sign(signatureHash)
|
var signature = keyPair.sign(signatureHash)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user