mirror of
https://github.com/aljazceru/lightning.git
synced 2026-01-19 13:54:24 +01:00
bitcoin: hand in a secp256k1_context to all routines.
We don't want to re-create them internally, ever. The test-cli tools are patched to generate them all the time, but they're not performance critical. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
@@ -50,7 +50,9 @@ int main(int argc, char *argv[])
|
||||
o2 = pkt_from_file(argv[2], PKT__PKT_OPEN)->open;
|
||||
a = pkt_from_file(argv[3], PKT__PKT_OPEN_ANCHOR)->open_anchor;
|
||||
|
||||
if (!key_from_base58(argv[4], strlen(argv[4]), &testnet, &privkey, &pubkey1))
|
||||
if (!key_from_base58(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||
| SECP256K1_CONTEXT_SIGN),
|
||||
argv[4], strlen(argv[4]), &testnet, &privkey, &pubkey1))
|
||||
errx(1, "Invalid private key '%s'", argv[4]);
|
||||
if (!testnet)
|
||||
errx(1, "Private key '%s' not on testnet!", argv[4]);
|
||||
@@ -68,7 +70,8 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
/* Pubkey well-formed? */
|
||||
if (!proto_to_pubkey(o2->commit_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o2->commit_key, &pubkey2))
|
||||
errx(1, "Invalid o2 commit_key");
|
||||
|
||||
if (is_funder(o1) == is_funder(o2))
|
||||
@@ -86,7 +89,8 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* Check signature. */
|
||||
subscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2);
|
||||
if (!check_tx_sig(commit, 0, subscript, tal_count(subscript),
|
||||
if (!check_tx_sig(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY),
|
||||
commit, 0, subscript, tal_count(subscript),
|
||||
&pubkey2, &sig))
|
||||
errx(1, "Their signature invalid");
|
||||
|
||||
|
||||
@@ -62,7 +62,9 @@ int main(int argc, char *argv[])
|
||||
o2 = pkt_from_file(argv[2], PKT__PKT_OPEN)->open;
|
||||
a = pkt_from_file(argv[3], PKT__PKT_OPEN_ANCHOR)->open_anchor;
|
||||
|
||||
if (!key_from_base58(argv[4], strlen(argv[4]), &testnet, &privkey, &pubkey1))
|
||||
if (!key_from_base58(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||
| SECP256K1_CONTEXT_SIGN),
|
||||
argv[4], strlen(argv[4]), &testnet, &privkey, &pubkey1))
|
||||
errx(1, "Invalid private key '%s'", argv[4]);
|
||||
if (!testnet)
|
||||
errx(1, "Private key '%s' not on testnet!", argv[4]);
|
||||
@@ -77,22 +79,26 @@ int main(int argc, char *argv[])
|
||||
NULL, NULL, NULL);
|
||||
|
||||
/* Get pubkeys */
|
||||
if (!proto_to_pubkey(o1->commit_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o1->commit_key, &pubkey2))
|
||||
errx(1, "Invalid o1 commit pubkey");
|
||||
if (!pubkey_eq(&pubkey1, &pubkey2))
|
||||
errx(1, "o1 pubkey != this privkey");
|
||||
if (!proto_to_pubkey(o2->commit_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o2->commit_key, &pubkey2))
|
||||
errx(1, "Invalid o2 commit pubkey");
|
||||
|
||||
/* This is what the anchor pays to. */
|
||||
redeemscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2);
|
||||
|
||||
close_tx = create_close_tx(ctx, o1, o2, a,
|
||||
close_tx = create_close_tx(secp256k1_context_create(0),
|
||||
ctx, o1, o2, a,
|
||||
cstate->a.pay_msat / 1000,
|
||||
cstate->b.pay_msat / 1000);
|
||||
|
||||
/* Sign it for them. */
|
||||
sign_tx_input(close_tx, 0, redeemscript, tal_count(redeemscript),
|
||||
sign_tx_input(secp256k1_context_create(SECP256K1_CONTEXT_SIGN),
|
||||
close_tx, 0, redeemscript, tal_count(redeemscript),
|
||||
&privkey, &pubkey1, &sig);
|
||||
|
||||
if (close_file)
|
||||
|
||||
@@ -64,7 +64,9 @@ static void parse_anchor_input(const char *spec, struct input *in)
|
||||
if (*end != '/')
|
||||
errx(1, "Expected / after hexscript");
|
||||
|
||||
if (!key_from_base58(end+1, strlen(end + 1), &testnet,
|
||||
if (!key_from_base58(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||
| SECP256K1_CONTEXT_SIGN),
|
||||
end+1, strlen(end + 1), &testnet,
|
||||
&in->privkey, &in->pubkey))
|
||||
errx(1, "Invalid private key '%s'", end+1);
|
||||
if (!testnet)
|
||||
@@ -102,9 +104,11 @@ int main(int argc, char *argv[])
|
||||
|
||||
o1 = pkt_from_file(argv[1], PKT__PKT_OPEN)->open;
|
||||
o2 = pkt_from_file(argv[2], PKT__PKT_OPEN)->open;
|
||||
if (!proto_to_pubkey(o1->commit_key, &pubkey1))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o1->commit_key, &pubkey1))
|
||||
errx(1, "Invalid o1 commit_key");
|
||||
if (!proto_to_pubkey(o2->commit_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o2->commit_key, &pubkey2))
|
||||
errx(1, "Invalid o2 commit_key");
|
||||
|
||||
amount = atol(argv[3]);
|
||||
@@ -142,7 +146,8 @@ int main(int argc, char *argv[])
|
||||
if (change) {
|
||||
struct pubkey change_key;
|
||||
|
||||
if (!pubkey_from_hexstr(argv[4], strlen(argv[4]), &change_key))
|
||||
if (!pubkey_from_hexstr(secp256k1_context_create(0),
|
||||
argv[4], strlen(argv[4]), &change_key))
|
||||
errx(1, "Invalid change key %s", argv[3]);
|
||||
|
||||
redeemscript = bitcoin_redeem_single(anchor, &change_key);
|
||||
@@ -163,11 +168,11 @@ int main(int argc, char *argv[])
|
||||
/* Now, sign each input. */
|
||||
for (i = 0; i < tal_count(in); i++) {
|
||||
in[i].sig.stype = SIGHASH_ALL;
|
||||
if (!sign_tx_input(anchor, i, in[i].in.script,
|
||||
in[i].in.script_length,
|
||||
&in[i].privkey, &in[i].pubkey,
|
||||
&in[i].sig.sig))
|
||||
errx(1, "Error signing input %zi", i);
|
||||
sign_tx_input(secp256k1_context_create(SECP256K1_CONTEXT_SIGN),
|
||||
anchor, i, in[i].in.script,
|
||||
in[i].in.script_length,
|
||||
&in[i].privkey, &in[i].pubkey,
|
||||
&in[i].sig.sig);
|
||||
}
|
||||
|
||||
/* Finally, complete inputs using signatures. */
|
||||
|
||||
@@ -53,9 +53,11 @@ int main(int argc, char *argv[])
|
||||
closecomplete = pkt_from_file(argv[5], PKT__PKT_CLOSE_COMPLETE)->close_complete;
|
||||
|
||||
/* Pubkeys well-formed? */
|
||||
if (!proto_to_pubkey(o1->commit_key, &pubkey1))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o1->commit_key, &pubkey1))
|
||||
errx(1, "Invalid o1 commit_key");
|
||||
if (!proto_to_pubkey(o2->commit_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o2->commit_key, &pubkey2))
|
||||
errx(1, "Invalid o2 commit_key");
|
||||
|
||||
/* Get delta by accumulting all the updates. */
|
||||
@@ -66,7 +68,8 @@ int main(int argc, char *argv[])
|
||||
redeemscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2);
|
||||
|
||||
/* Now create the close tx to spend 2/2 output of anchor. */
|
||||
close_tx = create_close_tx(ctx, o1, o2, a,
|
||||
close_tx = create_close_tx(secp256k1_context_create(0),
|
||||
ctx, o1, o2, a,
|
||||
cstate->a.pay_msat / 1000,
|
||||
cstate->b.pay_msat / 1000);
|
||||
|
||||
@@ -78,7 +81,8 @@ int main(int argc, char *argv[])
|
||||
errx(1, "Invalid closecomplete-packet");
|
||||
|
||||
/* Combined signatures must validate correctly. */
|
||||
if (!check_2of2_sig(close_tx, 0, redeemscript, tal_count(redeemscript),
|
||||
if (!check_2of2_sig(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY),
|
||||
close_tx, 0, redeemscript, tal_count(redeemscript),
|
||||
&pubkey1, &pubkey2, &sig1, &sig2))
|
||||
errx(1, "Signature failed");
|
||||
|
||||
|
||||
@@ -68,20 +68,25 @@ int main(int argc, char *argv[])
|
||||
errx(1, "Invalid locktime in o2");
|
||||
|
||||
/* We need our private key to spend commit output. */
|
||||
if (!key_from_base58(argv[5], strlen(argv[5]), &testnet, &privkey, &pubkey1))
|
||||
if (!key_from_base58(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||
| SECP256K1_CONTEXT_SIGN),
|
||||
argv[5], strlen(argv[5]), &testnet, &privkey, &pubkey1))
|
||||
errx(1, "Invalid private key '%s'", argv[5]);
|
||||
if (!testnet)
|
||||
errx(1, "Private key '%s' not on testnet!", argv[5]);
|
||||
|
||||
if (!pubkey_from_hexstr(argv[6], strlen(argv[6]), &outpubkey))
|
||||
if (!pubkey_from_hexstr(secp256k1_context_create(0),
|
||||
argv[6], strlen(argv[6]), &outpubkey))
|
||||
errx(1, "Invalid bitcoin pubkey '%s'", argv[6]);
|
||||
|
||||
/* Get pubkeys */
|
||||
if (!proto_to_pubkey(o1->final_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o1->final_key, &pubkey2))
|
||||
errx(1, "Invalid o1 final pubkey");
|
||||
if (!pubkey_eq(&pubkey1, &pubkey2))
|
||||
errx(1, "o1 pubkey != this privkey");
|
||||
if (!proto_to_pubkey(o2->final_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o2->final_key, &pubkey2))
|
||||
errx(1, "Invalid o2 final pubkey");
|
||||
|
||||
/* We use this simply to get final revocation hash. */
|
||||
@@ -114,9 +119,9 @@ int main(int argc, char *argv[])
|
||||
tx->output[0].script_length = tal_count(tx->output[0].script);
|
||||
|
||||
/* Now get signature, to set up input script. */
|
||||
if (!sign_tx_input(tx, 0, redeemscript, tal_count(redeemscript),
|
||||
&privkey, &pubkey1, &sig.sig))
|
||||
errx(1, "Could not sign tx");
|
||||
sign_tx_input(secp256k1_context_create(SECP256K1_CONTEXT_SIGN),
|
||||
tx, 0, redeemscript, tal_count(redeemscript),
|
||||
&privkey, &pubkey1, &sig.sig);
|
||||
sig.stype = SIGHASH_ALL;
|
||||
tx->input[0].script = scriptsig_p2sh_secret(tx, NULL, 0, &sig,
|
||||
redeemscript,
|
||||
|
||||
@@ -52,17 +52,21 @@ int main(int argc, char *argv[])
|
||||
o2 = pkt_from_file(argv[2], PKT__PKT_OPEN)->open;
|
||||
a = pkt_from_file(argv[3], PKT__PKT_OPEN_ANCHOR)->open_anchor;
|
||||
|
||||
if (!key_from_base58(argv[4], strlen(argv[4]), &testnet, &privkey, &pubkey1))
|
||||
if (!key_from_base58(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||
| SECP256K1_CONTEXT_SIGN),
|
||||
argv[4], strlen(argv[4]), &testnet, &privkey, &pubkey1))
|
||||
errx(1, "Invalid private key '%s'", argv[4]);
|
||||
if (!testnet)
|
||||
errx(1, "Private key '%s' not on testnet!", argv[4]);
|
||||
|
||||
/* Get pubkeys */
|
||||
if (!proto_to_pubkey(o1->commit_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o1->commit_key, &pubkey2))
|
||||
errx(1, "Invalid o1 commit pubkey");
|
||||
if (!pubkey_eq(&pubkey1, &pubkey2))
|
||||
errx(1, "o1 pubkey != this privkey");
|
||||
if (!proto_to_pubkey(o2->commit_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o2->commit_key, &pubkey2))
|
||||
errx(1, "Invalid o2 commit pubkey");
|
||||
|
||||
sig2.stype = SIGHASH_ALL;
|
||||
@@ -84,11 +88,13 @@ int main(int argc, char *argv[])
|
||||
|
||||
/* We generate our signature. */
|
||||
sig1.stype = SIGHASH_ALL;
|
||||
sign_tx_input(commit, 0, redeemscript, tal_count(redeemscript),
|
||||
sign_tx_input(secp256k1_context_create(SECP256K1_CONTEXT_SIGN),
|
||||
commit, 0, redeemscript, tal_count(redeemscript),
|
||||
&privkey, &pubkey1, &sig1.sig);
|
||||
|
||||
/* Check it works with theirs... */
|
||||
if (!check_2of2_sig(commit, 0, redeemscript, tal_count(redeemscript),
|
||||
if (!check_2of2_sig(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY),
|
||||
commit, 0, redeemscript, tal_count(redeemscript),
|
||||
&pubkey1, &pubkey2, &sig1, &sig2))
|
||||
errx(1, "Signature failed");
|
||||
|
||||
|
||||
@@ -88,18 +88,23 @@ int main(int argc, char *argv[])
|
||||
errx(1, "Expected update or update-add-htlc for %s", argv[5]);
|
||||
}
|
||||
|
||||
if (!key_from_base58(argv[6], strlen(argv[6]), &testnet, &privkey, &key))
|
||||
if (!key_from_base58(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||
| SECP256K1_CONTEXT_SIGN),
|
||||
argv[6], strlen(argv[6]), &testnet, &privkey, &key))
|
||||
errx(1, "Invalid private key '%s'", argv[6]);
|
||||
if (!testnet)
|
||||
errx(1, "Private key '%s' not on testnet!", argv[6]);
|
||||
|
||||
if (!pubkey_from_hexstr(argv[7], strlen(argv[7]), &outpubkey))
|
||||
if (!pubkey_from_hexstr(secp256k1_context_create(0),
|
||||
argv[7], strlen(argv[7]), &outpubkey))
|
||||
errx(1, "Invalid commit key '%s'", argv[7]);
|
||||
|
||||
/* Get pubkeys */
|
||||
if (!proto_to_pubkey(o1->final_key, &pubkey1))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o1->final_key, &pubkey1))
|
||||
errx(1, "Invalid o1 final pubkey");
|
||||
if (!proto_to_pubkey(o2->final_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o2->final_key, &pubkey2))
|
||||
errx(1, "Invalid o2 final pubkey");
|
||||
|
||||
if (pubkey_eq(&key, &pubkey1)) {
|
||||
@@ -186,9 +191,9 @@ int main(int argc, char *argv[])
|
||||
tx->output[0].script_length = tal_count(tx->output[0].script);
|
||||
|
||||
/* Now get signature, to set up input script. */
|
||||
if (!sign_tx_input(tx, 0, redeemscript, tal_count(redeemscript),
|
||||
&privkey, &key, &sig.sig))
|
||||
errx(1, "Could not sign tx");
|
||||
sign_tx_input(secp256k1_context_create(SECP256K1_CONTEXT_SIGN),
|
||||
tx, 0, redeemscript, tal_count(redeemscript),
|
||||
&privkey, &key, &sig.sig);
|
||||
|
||||
sig.stype = SIGHASH_ALL;
|
||||
tx->input[0].script = scriptsig_p2sh_secret(tx, secret, secret_len,
|
||||
|
||||
@@ -63,7 +63,9 @@ int main(int argc, char *argv[])
|
||||
errx(1, "Expected update or update-complete in %s", argv[2]);
|
||||
}
|
||||
|
||||
if (!key_from_base58(argv[3], strlen(argv[3]), &testnet, &privkey, &pubkey1))
|
||||
if (!key_from_base58(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||
| SECP256K1_CONTEXT_SIGN),
|
||||
argv[3], strlen(argv[3]), &testnet, &privkey, &pubkey1))
|
||||
errx(1, "Invalid private key '%s'", argv[3]);
|
||||
if (!testnet)
|
||||
errx(1, "Private key '%s' not on testnet!", argv[3]);
|
||||
@@ -73,15 +75,18 @@ int main(int argc, char *argv[])
|
||||
if (!proto_to_rel_locktime(o1->delay, &locktime))
|
||||
errx(1, "Invalid locktime in o2");
|
||||
|
||||
if (!pubkey_from_hexstr(argv[6], strlen(argv[6]), &outpubkey))
|
||||
if (!pubkey_from_hexstr(secp256k1_context_create(0),
|
||||
argv[6], strlen(argv[6]), &outpubkey))
|
||||
errx(1, "Invalid bitcoin pubkey '%s'", argv[6]);
|
||||
|
||||
/* Get pubkeys */
|
||||
if (!proto_to_pubkey(o1->final_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o1->final_key, &pubkey2))
|
||||
errx(1, "Invalid o1 final pubkey");
|
||||
if (!pubkey_eq(&pubkey1, &pubkey2))
|
||||
errx(1, "o1 pubkey != this privkey");
|
||||
if (!proto_to_pubkey(o2->final_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o2->final_key, &pubkey2))
|
||||
errx(1, "Invalid o2 final pubkey");
|
||||
|
||||
/* Now, which commit output? Match redeem script. */
|
||||
@@ -113,9 +118,9 @@ int main(int argc, char *argv[])
|
||||
tx->output[0].script_length = tal_count(tx->output[0].script);
|
||||
|
||||
/* Now get signature, to set up input script. */
|
||||
if (!sign_tx_input(tx, 0, redeemscript, tal_count(redeemscript),
|
||||
&privkey, &pubkey1, &sig.sig))
|
||||
errx(1, "Could not sign tx");
|
||||
sign_tx_input(secp256k1_context_create(SECP256K1_CONTEXT_SIGN),
|
||||
tx, 0, redeemscript, tal_count(redeemscript),
|
||||
&privkey, &pubkey1, &sig.sig);
|
||||
sig.stype = SIGHASH_ALL;
|
||||
tx->input[0].script = scriptsig_p2sh_secret(tx,
|
||||
&revoke_preimage,
|
||||
|
||||
@@ -56,13 +56,16 @@ int main(int argc, char *argv[])
|
||||
|
||||
o1 = pkt_from_file(argv[1], PKT__PKT_OPEN)->open;
|
||||
o2 = pkt_from_file(argv[2], PKT__PKT_OPEN)->open;
|
||||
if (!proto_to_pubkey(o2->commit_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o2->commit_key, &pubkey2))
|
||||
errx(1, "Invalid o2 commit_key");
|
||||
|
||||
anchor = bitcoin_tx_from_file(ctx, argv[3]);
|
||||
bitcoin_txid(anchor, &txid);
|
||||
|
||||
if (!key_from_base58(argv[4], strlen(argv[4]), &testnet, &privkey, &pubkey1))
|
||||
if (!key_from_base58(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||
| SECP256K1_CONTEXT_SIGN),
|
||||
argv[4], strlen(argv[4]), &testnet, &privkey, &pubkey1))
|
||||
errx(1, "Invalid private key '%s'", argv[4]);
|
||||
if (!testnet)
|
||||
errx(1, "Private key '%s' not on testnet!", argv[4]);
|
||||
@@ -88,7 +91,8 @@ int main(int argc, char *argv[])
|
||||
invert_cstate(cstate);
|
||||
commit = commit_tx_from_pkts(ctx, o2, o1, &oa, &rhash, cstate);
|
||||
|
||||
sign_tx_input(commit, 0, redeemscript, tal_count(redeemscript),
|
||||
sign_tx_input(secp256k1_context_create(SECP256K1_CONTEXT_SIGN),
|
||||
commit, 0, redeemscript, tal_count(redeemscript),
|
||||
&privkey, &pubkey1, &sig);
|
||||
|
||||
oa.commit_sig = signature_to_proto(ctx, &sig);
|
||||
|
||||
@@ -69,10 +69,12 @@ int main(int argc, char *argv[])
|
||||
if (!hex_decode(argv[1], strlen(argv[1]), &seed, sizeof(seed)))
|
||||
errx(1, "Invalid seed '%s' - need 256 hex bits", argv[1]);
|
||||
|
||||
if (!pubkey_from_hexstr(argv[2], strlen(argv[2]), &commitkey))
|
||||
if (!pubkey_from_hexstr(secp256k1_context_create(0),
|
||||
argv[2], strlen(argv[2]), &commitkey))
|
||||
errx(1, "Invalid commit key '%s'", argv[2]);
|
||||
|
||||
if (!pubkey_from_hexstr(argv[3], strlen(argv[3]), &finalkey))
|
||||
if (!pubkey_from_hexstr(secp256k1_context_create(0),
|
||||
argv[3], strlen(argv[3]), &finalkey))
|
||||
errx(1, "Invalid final key '%s'", argv[3]);
|
||||
|
||||
if (offer_anchor && min_confirms == 0)
|
||||
|
||||
@@ -52,7 +52,9 @@ int main(int argc, char *argv[])
|
||||
o2 = pkt_from_file(argv[2], PKT__PKT_OPEN)->open;
|
||||
a = pkt_from_file(argv[3], PKT__PKT_OPEN_ANCHOR)->open_anchor;
|
||||
|
||||
if (!key_from_base58(argv[4], strlen(argv[4]), &testnet, &privkey, &pubkey1))
|
||||
if (!key_from_base58(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||
| SECP256K1_CONTEXT_SIGN),
|
||||
argv[4], strlen(argv[4]), &testnet, &privkey, &pubkey1))
|
||||
errx(1, "Invalid private key '%s'", argv[4]);
|
||||
if (!testnet)
|
||||
errx(1, "Private key '%s' not on testnet!", argv[4]);
|
||||
@@ -75,12 +77,14 @@ int main(int argc, char *argv[])
|
||||
errx(1, "Invalid packets?");
|
||||
|
||||
/* Their pubkey must be valid */
|
||||
if (!proto_to_pubkey(o2->commit_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o2->commit_key, &pubkey2))
|
||||
errx(1, "Invalid public open-channel-file2");
|
||||
|
||||
/* Sign it for them. */
|
||||
subscript = bitcoin_redeem_2of2(ctx, &pubkey1, &pubkey2);
|
||||
sign_tx_input(commit, 0, subscript, tal_count(subscript),
|
||||
sign_tx_input(secp256k1_context_create(SECP256K1_CONTEXT_SIGN),
|
||||
commit, 0, subscript, tal_count(subscript),
|
||||
&privkey, &pubkey1, &sig);
|
||||
|
||||
pkt = open_commit_sig_pkt(ctx, &sig);
|
||||
|
||||
@@ -240,9 +240,11 @@ struct bitcoin_tx *commit_tx_from_pkts(const tal_t *ctx,
|
||||
|
||||
proto_to_sha256(anchor->txid, &txid.sha);
|
||||
/* Output goes to our final pubkeys */
|
||||
if (!proto_to_pubkey(ours->final_key, &ourkey))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
ours->final_key, &ourkey))
|
||||
return NULL;
|
||||
if (!proto_to_pubkey(theirs->final_key, &theirkey))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
theirs->final_key, &theirkey))
|
||||
return NULL;
|
||||
if (!proto_to_rel_locktime(theirs->delay, &locktime))
|
||||
return NULL;
|
||||
|
||||
@@ -57,7 +57,9 @@ int main(int argc, char *argv[])
|
||||
o2 = pkt_from_file(argv[3], PKT__PKT_OPEN)->open;
|
||||
a = pkt_from_file(argv[4], PKT__PKT_OPEN_ANCHOR)->open_anchor;
|
||||
|
||||
if (!key_from_base58(argv[5], strlen(argv[5]), &testnet, &privkey, &pubkey1))
|
||||
if (!key_from_base58(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||
| SECP256K1_CONTEXT_SIGN),
|
||||
argv[5], strlen(argv[5]), &testnet, &privkey, &pubkey1))
|
||||
errx(1, "Invalid private key '%s'", argv[5]);
|
||||
if (!testnet)
|
||||
errx(1, "Private key '%s' not on testnet!", argv[5]);
|
||||
@@ -75,11 +77,13 @@ int main(int argc, char *argv[])
|
||||
revocation_hash.u.u8, sizeof(revocation_hash.u.u8));
|
||||
|
||||
/* Get pubkeys */
|
||||
if (!proto_to_pubkey(o1->commit_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o1->commit_key, &pubkey2))
|
||||
errx(1, "Invalid o1 commit pubkey");
|
||||
if (!pubkey_eq(&pubkey1, &pubkey2))
|
||||
errx(1, "o1 pubkey != this privkey");
|
||||
if (!proto_to_pubkey(o2->commit_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o2->commit_key, &pubkey2))
|
||||
errx(1, "Invalid o2 commit pubkey");
|
||||
|
||||
/* This is what the anchor pays to; figure out whick output. */
|
||||
@@ -94,7 +98,8 @@ int main(int argc, char *argv[])
|
||||
errx(1, "Delta too large");
|
||||
|
||||
/* Sign it for them. */
|
||||
sign_tx_input(commit, 0, redeemscript, tal_count(redeemscript),
|
||||
sign_tx_input(secp256k1_context_create(SECP256K1_CONTEXT_SIGN),
|
||||
commit, 0, redeemscript, tal_count(redeemscript),
|
||||
&privkey, &pubkey1, &sig.sig);
|
||||
|
||||
pkt = update_accept_pkt(ctx, &sig.sig, &revocation_hash);
|
||||
|
||||
@@ -68,9 +68,11 @@ int main(int argc, char *argv[])
|
||||
errx(1, "Expected at least one update!");
|
||||
|
||||
/* Get pubkeys */
|
||||
if (!proto_to_pubkey(o1->commit_key, &pubkey1))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o1->commit_key, &pubkey1))
|
||||
errx(1, "Invalid o1 commit pubkey");
|
||||
if (!proto_to_pubkey(o2->commit_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o2->commit_key, &pubkey2))
|
||||
errx(1, "Invalid o2 commit pubkey");
|
||||
|
||||
/* This is what the anchor pays to. */
|
||||
@@ -81,7 +83,8 @@ int main(int argc, char *argv[])
|
||||
if (!commit)
|
||||
errx(1, "Delta too large");
|
||||
|
||||
if (!check_tx_sig(commit, 0, redeemscript, tal_count(redeemscript),
|
||||
if (!check_tx_sig(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY),
|
||||
commit, 0, redeemscript, tal_count(redeemscript),
|
||||
&pubkey2, &sig))
|
||||
errx(1, "Invalid signature.");
|
||||
|
||||
|
||||
@@ -57,7 +57,9 @@ int main(int argc, char *argv[])
|
||||
o2 = pkt_from_file(argv[3], PKT__PKT_OPEN)->open;
|
||||
a = pkt_from_file(argv[4], PKT__PKT_OPEN_ANCHOR)->open_anchor;
|
||||
|
||||
if (!key_from_base58(argv[5], strlen(argv[5]), &testnet, &privkey, &pubkey1))
|
||||
if (!key_from_base58(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY
|
||||
| SECP256K1_CONTEXT_SIGN),
|
||||
argv[5], strlen(argv[5]), &testnet, &privkey, &pubkey1))
|
||||
errx(1, "Invalid private key '%s'", argv[5]);
|
||||
if (!testnet)
|
||||
errx(1, "Private key '%s' not on testnet!", argv[5]);
|
||||
@@ -78,11 +80,13 @@ int main(int argc, char *argv[])
|
||||
shachain_from_seed(&seed, num_updates - 1, &preimage);
|
||||
|
||||
/* Get pubkeys */
|
||||
if (!proto_to_pubkey(o1->commit_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o1->commit_key, &pubkey2))
|
||||
errx(1, "Invalid o1 commit pubkey");
|
||||
if (!pubkey_eq(&pubkey1, &pubkey2))
|
||||
errx(1, "o1 pubkey != this privkey");
|
||||
if (!proto_to_pubkey(o2->commit_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o2->commit_key, &pubkey2))
|
||||
errx(1, "Invalid o2 commit pubkey");
|
||||
|
||||
/* This is what the anchor pays to. */
|
||||
@@ -94,7 +98,8 @@ int main(int argc, char *argv[])
|
||||
errx(1, "Invalid packets");
|
||||
|
||||
/* Check their signature signs this input correctly. */
|
||||
if (!check_tx_sig(commit, 0, redeemscript, tal_count(redeemscript),
|
||||
if (!check_tx_sig(secp256k1_context_create(SECP256K1_CONTEXT_VERIFY),
|
||||
commit, 0, redeemscript, tal_count(redeemscript),
|
||||
&pubkey2, &sig))
|
||||
errx(1, "Invalid signature.");
|
||||
|
||||
@@ -105,11 +110,13 @@ int main(int argc, char *argv[])
|
||||
errx(1, "Invalid packets");
|
||||
|
||||
/* Their pubkey must be valid */
|
||||
if (!proto_to_pubkey(o2->commit_key, &pubkey2))
|
||||
if (!proto_to_pubkey(secp256k1_context_create(0),
|
||||
o2->commit_key, &pubkey2))
|
||||
errx(1, "Invalid public open-channel-file2");
|
||||
|
||||
/* Sign it for them. */
|
||||
sign_tx_input(commit, 0, redeemscript, tal_count(redeemscript),
|
||||
sign_tx_input(secp256k1_context_create(SECP256K1_CONTEXT_SIGN),
|
||||
commit, 0, redeemscript, tal_count(redeemscript),
|
||||
&privkey, &pubkey1, &sig.sig);
|
||||
|
||||
pkt = update_signature_pkt(ctx, &sig.sig, &preimage);
|
||||
|
||||
Reference in New Issue
Block a user