|
@ -28,7 +28,7 @@ int main(int argc, char *argv[]) |
|
|
OpenCommitSig *cs2; |
|
|
OpenCommitSig *cs2; |
|
|
struct bitcoin_tx *anchor, *commit; |
|
|
struct bitcoin_tx *anchor, *commit; |
|
|
struct sha256_double txid; |
|
|
struct sha256_double txid; |
|
|
u8 *tx_arr; |
|
|
u8 *tx_arr, *subscript; |
|
|
size_t *inmap, *outmap; |
|
|
size_t *inmap, *outmap; |
|
|
struct pubkey pubkey1, pubkey2; |
|
|
struct pubkey pubkey1, pubkey2; |
|
|
struct bitcoin_signature sig1, sig2; |
|
|
struct bitcoin_signature sig1, sig2; |
|
@ -58,6 +58,10 @@ int main(int argc, char *argv[]) |
|
|
if (!testnet) |
|
|
if (!testnet) |
|
|
errx(1, "Private key '%s' not on testnet!", argv[4]); |
|
|
errx(1, "Private key '%s' not on testnet!", argv[4]); |
|
|
|
|
|
|
|
|
|
|
|
/* Pubkey well-formed? */ |
|
|
|
|
|
if (!proto_to_pubkey(o2->anchor->pubkey, &pubkey2)) |
|
|
|
|
|
errx(1, "Invalid anchor-2 key"); |
|
|
|
|
|
|
|
|
/* Get the transaction ID of the anchor. */ |
|
|
/* Get the transaction ID of the anchor. */ |
|
|
anchor = anchor_tx_create(ctx, o1, o2, &inmap, &outmap); |
|
|
anchor = anchor_tx_create(ctx, o1, o2, &inmap, &outmap); |
|
|
if (!anchor) |
|
|
if (!anchor) |
|
@ -79,19 +83,17 @@ int main(int argc, char *argv[]) |
|
|
* is overkill: if their signature and pubkey signed the commit txin, |
|
|
* is overkill: if their signature and pubkey signed the commit txin, |
|
|
* we're happy. */ |
|
|
* we're happy. */ |
|
|
sig1.stype = SIGHASH_ALL; |
|
|
sig1.stype = SIGHASH_ALL; |
|
|
sign_tx_input(ctx, commit, 0, anchor->output[outmap[0]].script, |
|
|
subscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2); |
|
|
anchor->output[outmap[0]].script_length, privkey, |
|
|
sign_tx_input(ctx, commit, 0, subscript, tal_count(subscript), |
|
|
&sig1.sig); |
|
|
privkey, &sig1.sig); |
|
|
|
|
|
|
|
|
/* Signatures and pubkeys well-formed? */ |
|
|
/* Signatures well-formed? */ |
|
|
if (!proto_to_signature(cs2->sig, &sig2.sig)) |
|
|
if (!proto_to_signature(cs2->sig, &sig2.sig)) |
|
|
errx(1, "Invalid commit-sig-2"); |
|
|
errx(1, "Invalid commit-sig-2"); |
|
|
sig2.stype = SIGHASH_ALL; |
|
|
sig2.stype = SIGHASH_ALL; |
|
|
if (!proto_to_pubkey(o2->anchor->pubkey, &pubkey2)) |
|
|
|
|
|
errx(1, "Invalid anchor-2 key"); |
|
|
|
|
|
|
|
|
|
|
|
/* Combined signatures must validate correctly. */ |
|
|
/* Combined signatures must validate correctly. */ |
|
|
if (!check_2of2_sig(commit, 0, &anchor->output[outmap[0]], |
|
|
if (!check_2of2_sig(commit, 0, subscript, tal_count(subscript), |
|
|
&pubkey1, &pubkey2, &sig1, &sig2)) |
|
|
&pubkey1, &pubkey2, &sig1, &sig2)) |
|
|
errx(1, "Signature failed"); |
|
|
errx(1, "Signature failed"); |
|
|
|
|
|
|
|
|