mirror of
https://github.com/ElementsProject/lightning.git
synced 2024-11-19 09:54:16 +01:00
derive_basepoints: make arguments optional.
We want to use it in peer_control to generate the transaction, but we really only need the funding_pubkey. Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
parent
7bfd282319
commit
4220362692
@ -22,25 +22,34 @@ bool derive_basepoints(const struct privkey *seed,
|
||||
hkdf_sha256(&keys, sizeof(keys), NULL, 0, seed, sizeof(*seed),
|
||||
"c-lightning", strlen("c-lightning"));
|
||||
|
||||
secrets->funding_privkey = keys.f;
|
||||
secrets->revocation_basepoint_secret = keys.r.secret;
|
||||
secrets->payment_basepoint_secret = keys.p.secret;
|
||||
secrets->delayed_payment_basepoint_secret = keys.d.secret;
|
||||
if (secrets) {
|
||||
secrets->funding_privkey = keys.f;
|
||||
secrets->revocation_basepoint_secret = keys.r.secret;
|
||||
secrets->payment_basepoint_secret = keys.p.secret;
|
||||
secrets->delayed_payment_basepoint_secret = keys.d.secret;
|
||||
}
|
||||
|
||||
if (!pubkey_from_privkey(&keys.f, funding_pubkey)
|
||||
|| !pubkey_from_privkey(&keys.r, &basepoints->revocation)
|
||||
|| !pubkey_from_privkey(&keys.p, &basepoints->payment)
|
||||
|| !pubkey_from_privkey(&keys.d, &basepoints->delayed_payment))
|
||||
return false;
|
||||
if (funding_pubkey) {
|
||||
if (!pubkey_from_privkey(&keys.f, funding_pubkey))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (basepoints) {
|
||||
if (!pubkey_from_privkey(&keys.r, &basepoints->revocation)
|
||||
|| !pubkey_from_privkey(&keys.p, &basepoints->payment)
|
||||
|| !pubkey_from_privkey(&keys.d, &basepoints->delayed_payment))
|
||||
return false;
|
||||
}
|
||||
|
||||
/* BOLT #3:
|
||||
*
|
||||
* A node MUST select an unguessable 256-bit seed for each connection,
|
||||
* and MUST NOT reveal the seed.
|
||||
*/
|
||||
*shaseed = keys.shaseed;
|
||||
if (shaseed)
|
||||
*shaseed = keys.shaseed;
|
||||
|
||||
shachain_from_seed(shaseed, shachain_index(per_commit_index),
|
||||
shachain_from_seed(&keys.shaseed, shachain_index(per_commit_index),
|
||||
&per_commit_secret);
|
||||
|
||||
/* BOLT #3:
|
||||
@ -49,10 +58,12 @@ bool derive_basepoints(const struct privkey *seed,
|
||||
*
|
||||
* per-commitment-point = per-commitment-secret * G
|
||||
*/
|
||||
if (secp256k1_ec_pubkey_create(secp256k1_ctx,
|
||||
&per_commit_point->pubkey,
|
||||
per_commit_secret.u.u8) != 1)
|
||||
return false;
|
||||
if (per_commit_point) {
|
||||
if (secp256k1_ec_pubkey_create(secp256k1_ctx,
|
||||
&per_commit_point->pubkey,
|
||||
per_commit_secret.u.u8) != 1)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -19,6 +19,16 @@ struct secrets {
|
||||
struct secret delayed_payment_basepoint_secret;
|
||||
};
|
||||
|
||||
/**
|
||||
* derive_basepoints - given a (per-peer) seed, get the basepoints
|
||||
* @seed: (in) seed (derived by master daemon from counter and main seed)
|
||||
* @funding_pubkey: (out) pubkey for funding tx output (if non-NULL)
|
||||
* @basepoints: (out) basepoints for channel (if non-NULL)
|
||||
* @secrets: (out) basepoints for channel (if non-NULL)
|
||||
* @shaseed: (out) seed for shachain (if non-NULL)
|
||||
* @per_commit_point: (out) per-commit-point for @per_commit_index (if non-NULL)
|
||||
* @per_commit_index: (in) which @per_commit_point to set.
|
||||
*/
|
||||
bool derive_basepoints(const struct privkey *seed,
|
||||
struct pubkey *funding_pubkey,
|
||||
struct basepoints *basepoints,
|
||||
|
Loading…
Reference in New Issue
Block a user