lnwallet: export the Ripemd160H function

The reason for exporting this function is that we now have external
applications that generate custom Bitcoin scripts.
This commit is contained in:
Joost Jager 2018-10-03 18:22:12 +02:00
parent b00e43eec1
commit cf57c1daa3
No known key found for this signature in database
GPG Key ID: AE6B0D042C8E38D9

@ -152,11 +152,11 @@ func FindScriptOutputIndex(tx *wire.MsgTx, script []byte) (bool, uint32) {
return found, index return found, index
} }
// ripemd160H calculates the ripemd160 of the passed byte slice. This is used to // Ripemd160H calculates the ripemd160 of the passed byte slice. This is used to
// calculate the intermediate hash for payment pre-images. Payment hashes are // calculate the intermediate hash for payment pre-images. Payment hashes are
// the result of ripemd160(sha256(paymentPreimage)). As a result, the value // the result of ripemd160(sha256(paymentPreimage)). As a result, the value
// passed in should be the sha256 of the payment hash. // passed in should be the sha256 of the payment hash.
func ripemd160H(d []byte) []byte { func Ripemd160H(d []byte) []byte {
h := ripemd160.New() h := ripemd160.New()
h.Write(d) h.Write(d)
return h.Sum(nil) return h.Sum(nil)
@ -256,7 +256,7 @@ func senderHTLCScript(senderHtlcKey, receiverHtlcKey,
// pre-image. By using this little trick we're able save space on-chain // pre-image. By using this little trick we're able save space on-chain
// as the witness includes a 20-byte hash rather than a 32-byte hash. // as the witness includes a 20-byte hash rather than a 32-byte hash.
builder.AddOp(txscript.OP_HASH160) builder.AddOp(txscript.OP_HASH160)
builder.AddData(ripemd160H(paymentHash)) builder.AddData(Ripemd160H(paymentHash))
builder.AddOp(txscript.OP_EQUALVERIFY) builder.AddOp(txscript.OP_EQUALVERIFY)
// This checks the receiver's signature so that a third party with // This checks the receiver's signature so that a third party with
@ -457,7 +457,7 @@ func receiverHTLCScript(cltvExpiry uint32, senderHtlcKey,
// payment pre-image, then we'll continue. Otherwise, we'll end the // payment pre-image, then we'll continue. Otherwise, we'll end the
// script here as this is the invalid payment pre-image. // script here as this is the invalid payment pre-image.
builder.AddOp(txscript.OP_HASH160) builder.AddOp(txscript.OP_HASH160)
builder.AddData(ripemd160H(paymentHash)) builder.AddData(Ripemd160H(paymentHash))
builder.AddOp(txscript.OP_EQUALVERIFY) builder.AddOp(txscript.OP_EQUALVERIFY)
// If the payment hash matches, then we'll also need to satisfy the // If the payment hash matches, then we'll also need to satisfy the