Add BIP174 pseudo code for signing checks

This commit is contained in:
Luke Childs 2019-06-26 16:29:00 +07:00
parent 6ed635d7b4
commit ff3caa02fe
2 changed files with 42 additions and 0 deletions

View file

@ -8,6 +8,27 @@ class Psbt extends bip174_1.Psbt {
signInput(inputIndex, keyPair) {
// TODO: Implement BIP174 pre-sign checks:
// https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#signer
//
// if non_witness_utxo.exists:
// assert(sha256d(non_witness_utxo) == psbt.tx.innput[i].prevout.hash)
// if redeemScript.exists:
// assert(non_witness_utxo.vout[psbt.tx.input[i].prevout.n].scriptPubKey == P2SH(redeemScript))
// sign_non_witness(redeemScript)
// else:
// sign_non_witness(non_witness_utxo.vout[psbt.tx.input[i].prevout.n].scriptPubKey)
// else if witness_utxo.exists:
// if redeemScript.exists:
// assert(witness_utxo.scriptPubKey == P2SH(redeemScript))
// script = redeemScript
// else:
// script = witness_utxo.scriptPubKey
// if IsP2WPKH(script):
// sign_witness(P2PKH(script[2:22]))
// else if IsP2WSH(script):
// assert(script == P2WSH(witnessScript))
// sign_witness(witnessScript)
// else:
// assert False
// TODO: Get hash to sign
const hash = Buffer.alloc(32);
const partialSig = {

View file

@ -9,6 +9,27 @@ export class Psbt extends PsbtBase {
signInput(inputIndex: number, keyPair: Signer): Psbt {
// TODO: Implement BIP174 pre-sign checks:
// https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#signer
//
// if non_witness_utxo.exists:
// assert(sha256d(non_witness_utxo) == psbt.tx.innput[i].prevout.hash)
// if redeemScript.exists:
// assert(non_witness_utxo.vout[psbt.tx.input[i].prevout.n].scriptPubKey == P2SH(redeemScript))
// sign_non_witness(redeemScript)
// else:
// sign_non_witness(non_witness_utxo.vout[psbt.tx.input[i].prevout.n].scriptPubKey)
// else if witness_utxo.exists:
// if redeemScript.exists:
// assert(witness_utxo.scriptPubKey == P2SH(redeemScript))
// script = redeemScript
// else:
// script = witness_utxo.scriptPubKey
// if IsP2WPKH(script):
// sign_witness(P2PKH(script[2:22]))
// else if IsP2WSH(script):
// assert(script == P2WSH(witnessScript))
// sign_witness(witnessScript)
// else:
// assert False
// TODO: Get hash to sign
const hash = Buffer.alloc(32);