From 4a6dc670675cb1cc1770ab0e5636285f0c57ff03 Mon Sep 17 00:00:00 2001 From: Olaoluwa Osuntokun Date: Wed, 4 Jan 2017 16:28:38 -0800 Subject: [PATCH] txscript: add exported sighash calc func --- txscript/script.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/txscript/script.go b/txscript/script.go index aac3d4aaa..29f1e4d90 100644 --- a/txscript/script.go +++ b/txscript/script.go @@ -424,6 +424,19 @@ func calcHashOutputs(tx *wire.MsgTx) chainhash.Hash { return chainhash.DoubleHashH(b.Bytes()) } +// CalcWitnessSigHash exports calcWitnessSignatureHash so that signatures +// can be verified. +func CalcWitnessSigHash(subScript []byte, sigHashes *TxSigHashes, + hashType SigHashType, tx *wire.MsgTx, idx int, amt int64) ([]byte, error) { + parsedScript, err := parseScript(subScript) + if err != nil { + return nil, fmt.Errorf("cannot parse output script: %v", err) + } + sighash := calcWitnessSignatureHash( + parsedScript, sigHashes, hashType, tx, idx, amt) + return sighash, nil +} + // calcWitnessSignatureHash computes the sighash digest of a transaction's // segwit input using the new, optimized digest calculation algorithm defined // in BIP0143: https://github.com/bitcoin/bips/blob/master/bip-0143.mediawiki.