P2WSH working, now for tests
This commit is contained in:
parent
3ad31571b6
commit
b24dc44770
2 changed files with 10 additions and 9 deletions
src
|
@ -36,7 +36,7 @@ function encodeStack (signatures, scriptPubKey) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return [].concat(OPS.OP_0, signatures)
|
return [].concat(new Buffer(0), signatures)
|
||||||
}
|
}
|
||||||
|
|
||||||
function encode (signatures, scriptPubKey) {
|
function encode (signatures, scriptPubKey) {
|
||||||
|
|
|
@ -194,7 +194,7 @@ function checkP2WSHInput (input, witnessScriptHash) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function prepareInput (input, kpPubKey, redeemScript, witnessScript) {
|
function prepareInput (input, kpPubKey, redeemScript, witnessValue, witnessScript) {
|
||||||
var expanded
|
var expanded
|
||||||
var prevOutType
|
var prevOutType
|
||||||
var prevOutScript
|
var prevOutScript
|
||||||
|
@ -204,13 +204,15 @@ function prepareInput (input, kpPubKey, redeemScript, witnessScript) {
|
||||||
var redeemScriptHash
|
var redeemScriptHash
|
||||||
|
|
||||||
var witness = false
|
var witness = false
|
||||||
|
var p2wsh = false
|
||||||
var witnessType
|
var witnessType
|
||||||
var witnessScriptHash
|
var witnessScriptHash
|
||||||
|
|
||||||
if (redeemScript && witnessScript) {
|
if (redeemScript && witnessScript) {
|
||||||
redeemScriptHash = bcrypto.hash160(redeemScript)
|
redeemScriptHash = bcrypto.hash160(redeemScript)
|
||||||
witnessScriptHash = bcrypto.hash256(witnessScript)
|
witnessScriptHash = bcrypto.sha256(witnessScript)
|
||||||
checkP2shInput(input, redeemScriptHash)
|
checkP2shInput(input, redeemScriptHash)
|
||||||
|
|
||||||
if (!redeemScript.equals(bscript.witnessScriptHash.output.encode(witnessScriptHash))) throw new Error('Witness script inconsistent with redeem script')
|
if (!redeemScript.equals(bscript.witnessScriptHash.output.encode(witnessScriptHash))) throw new Error('Witness script inconsistent with redeem script')
|
||||||
|
|
||||||
expanded = expandOutput(witnessScript, undefined, kpPubKey)
|
expanded = expandOutput(witnessScript, undefined, kpPubKey)
|
||||||
|
@ -218,7 +220,7 @@ function prepareInput (input, kpPubKey, redeemScript, witnessScript) {
|
||||||
|
|
||||||
prevOutType = bscript.types.P2SH
|
prevOutType = bscript.types.P2SH
|
||||||
prevOutScript = bscript.scriptHash.output.encode(redeemScriptHash)
|
prevOutScript = bscript.scriptHash.output.encode(redeemScriptHash)
|
||||||
p2sh = witness = true
|
p2sh = witness = p2wsh = true
|
||||||
p2shType = bscript.types.P2WSH
|
p2shType = bscript.types.P2WSH
|
||||||
witnessType = expanded.scriptType
|
witnessType = expanded.scriptType
|
||||||
} else if (redeemScript) {
|
} else if (redeemScript) {
|
||||||
|
@ -241,7 +243,7 @@ function prepareInput (input, kpPubKey, redeemScript, witnessScript) {
|
||||||
|
|
||||||
prevOutType = bscript.types.P2WSH
|
prevOutType = bscript.types.P2WSH
|
||||||
prevOutScript = bscript.witnessScriptHash.output.encode(witnessScriptHash)
|
prevOutScript = bscript.witnessScriptHash.output.encode(witnessScriptHash)
|
||||||
witness = true
|
witness = p2wsh = true
|
||||||
witnessType = expanded.scriptType
|
witnessType = expanded.scriptType
|
||||||
} else if (input.prevOutType) {
|
} else if (input.prevOutType) {
|
||||||
// embedded scripts are not possible without a redeemScript
|
// embedded scripts are not possible without a redeemScript
|
||||||
|
@ -268,7 +270,7 @@ function prepareInput (input, kpPubKey, redeemScript, witnessScript) {
|
||||||
input.redeemScriptType = p2shType
|
input.redeemScriptType = p2shType
|
||||||
}
|
}
|
||||||
|
|
||||||
if (witness && witnessType === bscript.types.P2WSH) {
|
if (p2wsh) {
|
||||||
input.witnessScript = witnessScript
|
input.witnessScript = witnessScript
|
||||||
input.witnessScriptType = witnessType
|
input.witnessScriptType = witnessType
|
||||||
}
|
}
|
||||||
|
@ -516,7 +518,6 @@ TransactionBuilder.prototype.__build = function (allowIncomplete) {
|
||||||
}
|
}
|
||||||
|
|
||||||
var tx = this.tx.clone()
|
var tx = this.tx.clone()
|
||||||
|
|
||||||
// Create script signatures from inputs
|
// Create script signatures from inputs
|
||||||
this.inputs.forEach(function (input, i) {
|
this.inputs.forEach(function (input, i) {
|
||||||
var scriptType = input.redeemScriptType || input.prevOutType
|
var scriptType = input.redeemScriptType || input.prevOutType
|
||||||
|
@ -553,7 +554,7 @@ function canSign (input) {
|
||||||
input.witness !== undefined
|
input.witness !== undefined
|
||||||
}
|
}
|
||||||
|
|
||||||
TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashType, witnessValue) {
|
TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashType, witnessValue, witnessScript) {
|
||||||
if (keyPair.network !== this.network) throw new Error('Inconsistent network')
|
if (keyPair.network !== this.network) throw new Error('Inconsistent network')
|
||||||
if (!this.inputs[vin]) throw new Error('No input at index: ' + vin)
|
if (!this.inputs[vin]) throw new Error('No input at index: ' + vin)
|
||||||
hashType = hashType || Transaction.SIGHASH_ALL
|
hashType = hashType || Transaction.SIGHASH_ALL
|
||||||
|
@ -569,7 +570,7 @@ TransactionBuilder.prototype.sign = function (vin, keyPair, redeemScript, hashTy
|
||||||
|
|
||||||
var kpPubKey = keyPair.getPublicKeyBuffer()
|
var kpPubKey = keyPair.getPublicKeyBuffer()
|
||||||
if (!canSign(input)) {
|
if (!canSign(input)) {
|
||||||
prepareInput(input, kpPubKey, redeemScript, witnessValue)
|
prepareInput(input, kpPubKey, redeemScript, witnessValue, witnessScript)
|
||||||
|
|
||||||
if (!canSign(input)) throw Error(input.prevOutType + ' not supported')
|
if (!canSign(input)) throw Error(input.prevOutType + ' not supported')
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue