use baddress/bcrypto/bscript for ambuigities
This commit is contained in:
parent
6ec687deba
commit
8934de591c
9 changed files with 113 additions and 113 deletions
|
@ -1,9 +1,9 @@
|
|||
var address = require('./address')
|
||||
var baddress = require('./address')
|
||||
var bcrypto = require('./crypto')
|
||||
var bscript = require('./script')
|
||||
var bufferutils = require('./bufferutils')
|
||||
var networks = require('./networks')
|
||||
var ops = require('./opcodes')
|
||||
var script = require('./script')
|
||||
|
||||
var ECPair = require('./ecpair')
|
||||
var ECSignature = require('./ecsignature')
|
||||
|
@ -12,21 +12,21 @@ var Transaction = require('./transaction')
|
|||
function extractInput (txIn) {
|
||||
var redeemScript
|
||||
var scriptSig = txIn.script
|
||||
var scriptSigChunks = script.decompile(scriptSig)
|
||||
var scriptSigChunks = bscript.decompile(scriptSig)
|
||||
|
||||
var prevOutScript
|
||||
var prevOutType = script.classifyInput(scriptSig, true)
|
||||
var prevOutType = bscript.classifyInput(scriptSig, true)
|
||||
var scriptType
|
||||
|
||||
// Re-classify if scriptHash
|
||||
if (prevOutType === 'scripthash') {
|
||||
redeemScript = scriptSigChunks.slice(-1)[0]
|
||||
prevOutScript = script.scriptHashOutput(bcrypto.hash160(redeemScript))
|
||||
prevOutScript = bscript.scriptHashOutput(bcrypto.hash160(redeemScript))
|
||||
|
||||
scriptSig = script.compile(scriptSigChunks.slice(0, -1))
|
||||
scriptSig = bscript.compile(scriptSigChunks.slice(0, -1))
|
||||
scriptSigChunks = scriptSigChunks.slice(0, -1)
|
||||
|
||||
scriptType = script.classifyInput(scriptSig, true)
|
||||
scriptType = bscript.classifyInput(scriptSig, true)
|
||||
} else {
|
||||
scriptType = prevOutType
|
||||
}
|
||||
|
@ -34,7 +34,7 @@ function extractInput (txIn) {
|
|||
// pre-empt redeemScript decompilation
|
||||
var redeemScriptChunks
|
||||
if (redeemScript) {
|
||||
redeemScriptChunks = script.decompile(redeemScript)
|
||||
redeemScriptChunks = bscript.decompile(redeemScript)
|
||||
}
|
||||
|
||||
// Extract hashType, pubKeys and signatures
|
||||
|
@ -46,7 +46,7 @@ function extractInput (txIn) {
|
|||
hashType = parsed.hashType
|
||||
pubKeys = scriptSigChunks.slice(1)
|
||||
signatures = [parsed.signature]
|
||||
prevOutScript = script.pubKeyHashOutput(bcrypto.hash160(pubKeys[0]))
|
||||
prevOutScript = bscript.pubKeyHashOutput(bcrypto.hash160(pubKeys[0]))
|
||||
|
||||
break
|
||||
|
||||
|
@ -147,8 +147,8 @@ TransactionBuilder.prototype.addInput = function (txHash, vout, sequence, prevOu
|
|||
|
||||
var input = {}
|
||||
if (prevOutScript) {
|
||||
var prevOutScriptChunks = script.decompile(prevOutScript)
|
||||
var prevOutType = script.classifyOutput(prevOutScriptChunks)
|
||||
var prevOutScriptChunks = bscript.decompile(prevOutScript)
|
||||
var prevOutType = bscript.classifyOutput(prevOutScriptChunks)
|
||||
|
||||
// if we can, extract pubKey information
|
||||
switch (prevOutType) {
|
||||
|
@ -198,7 +198,7 @@ TransactionBuilder.prototype.addOutput = function (scriptPubKey, value) {
|
|||
|
||||
// Attempt to get a script if it's a base58 address string
|
||||
if (typeof scriptPubKey === 'string') {
|
||||
scriptPubKey = address.toOutputScript(scriptPubKey, this.network)
|
||||
scriptPubKey = baddress.toOutputScript(scriptPubKey, this.network)
|
||||
}
|
||||
|
||||
return this.tx.addOutput(scriptPubKey, value)
|
||||
|
@ -240,7 +240,7 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
|
|||
switch (scriptType) {
|
||||
case 'pubkeyhash':
|
||||
var pkhSignature = input.signatures[0].toScriptSignature(input.hashType)
|
||||
scriptSig = script.pubKeyHashInput(pkhSignature, input.pubKeys[0])
|
||||
scriptSig = bscript.pubKeyHashInput(pkhSignature, input.pubKeys[0])
|
||||
break
|
||||
|
||||
case 'multisig':
|
||||
|
@ -262,12 +262,12 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
|
|||
}
|
||||
|
||||
var redeemScript = allowIncomplete ? undefined : input.redeemScript
|
||||
scriptSig = script.multisigInput(msSignatures, redeemScript)
|
||||
scriptSig = bscript.multisigInput(msSignatures, redeemScript)
|
||||
break
|
||||
|
||||
case 'pubkey':
|
||||
var pkSignature = input.signatures[0].toScriptSignature(input.hashType)
|
||||
scriptSig = script.pubKeyInput(pkSignature)
|
||||
scriptSig = bscript.pubKeyInput(pkSignature)
|
||||
break
|
||||
}
|
||||
}
|
||||
|
@ -276,7 +276,7 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
|
|||
if (scriptSig) {
|
||||
// wrap as scriptHash if necessary
|
||||
if (input.prevOutType === 'scripthash') {
|
||||
scriptSig = script.scriptHashInput(scriptSig, input.redeemScript)
|
||||
scriptSig = bscript.scriptHashInput(scriptSig, input.redeemScript)
|
||||
}
|
||||
|
||||
tx.setInputScript(index, scriptSig)
|
||||
|
@ -318,14 +318,14 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
|
|||
if (input.prevOutScript) {
|
||||
if (input.prevOutType !== 'scripthash') throw new Error('PrevOutScript must be P2SH')
|
||||
|
||||
var scriptHash = script.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'))
|
||||
}
|
||||
|
||||
var scriptType = script.classifyOutput(redeemScript)
|
||||
var scriptType = bscript.classifyOutput(redeemScript)
|
||||
if (!canSignTypes[scriptType]) throw new Error('RedeemScript not supported (' + scriptType + ')')
|
||||
|
||||
var redeemScriptChunks = script.decompile(redeemScript)
|
||||
var redeemScriptChunks = bscript.decompile(redeemScript)
|
||||
var pubKeys = []
|
||||
switch (scriptType) {
|
||||
case 'multisig':
|
||||
|
@ -347,7 +347,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
|
|||
|
||||
// if we don't have a prevOutScript, generate a P2SH script
|
||||
if (!input.prevOutScript) {
|
||||
input.prevOutScript = script.scriptHashOutput(bcrypto.hash160(redeemScript))
|
||||
input.prevOutScript = bscript.scriptHashOutput(bcrypto.hash160(redeemScript))
|
||||
input.prevOutType = 'scripthash'
|
||||
}
|
||||
|
||||
|
@ -365,7 +365,7 @@ TransactionBuilder.prototype.sign = function (index, keyPair, redeemScript, hash
|
|||
|
||||
// we know nothin' Jon Snow, assume pubKeyHash
|
||||
} else {
|
||||
input.prevOutScript = script.pubKeyHashOutput(bcrypto.hash160(keyPair.getPublicKeyBuffer()))
|
||||
input.prevOutScript = bscript.pubKeyHashOutput(bcrypto.hash160(keyPair.getPublicKeyBuffer()))
|
||||
input.prevOutType = 'pubkeyhash'
|
||||
input.pubKeys = [kpPubKey]
|
||||
input.scriptType = input.prevOutType
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue