MCPcopy Create free account
hub / github.com/ElementsProject/lightning / derive_keyset

Function derive_keyset

common/keyset.c:6–82  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

4#include <common/keyset.h>
5
6bool derive_keyset(const struct pubkey *per_commitment_point,
7 const struct basepoints *self,
8 const struct basepoints *other,
9 bool option_static_remotekey,
10 struct keyset *keyset)
11{
12 /* BOLT #3:
13 *
14 * ### `localpubkey`, `local_htlcpubkey`, `remote_htlcpubkey`, `local_delayedpubkey`, and `remote_delayedpubkey` Derivation
15 *
16 * These pubkeys are simply generated by addition from their base points:
17 *
18 * pubkey = basepoint + SHA256(per_commitment_point || basepoint) * G
19 *
20 * - The `localpubkey` uses the local node's `payment_basepoint`;
21 * - The `local_htlcpubkey` uses the local node's `htlc_basepoint`;
22 * - The `remote_htlcpubkey` uses the remote node's `htlc_basepoint`;
23 * - The `local_delayedpubkey` uses the local node's `delayed_payment_basepoint`;
24 * - The `remote_delayedpubkey` uses the remote node's `delayed_payment_basepoint`.
25 */
26 if (!derive_simple_key(&self->payment,
27 per_commitment_point,
28 &keyset->self_payment_key))
29 return false;
30
31 /* BOLT #3:
32 *
33 * ### `remotepubkey` Derivation
34 *
35 * The `remotepubkey` is simply the remote node's `payment_basepoint`.
36 */
37 /* The old BOLT defined what happened prior to option_static_remotekey,
38 * which we still support for existing channels:
39 *
40 * If `option_static_remotekey` or `option_anchors` is
41 * negotiated, the `remotepubkey` is simply the remote node's
42 * `payment_basepoint`, otherwise it is calculated as above using the
43 * remote node's `payment_basepoint`.
44 */
45 if (option_static_remotekey)
46 keyset->other_payment_key = other->payment;
47 else if (!derive_simple_key(&other->payment,
48 per_commitment_point,
49 &keyset->other_payment_key))
50 return false;
51
52 if (!derive_simple_key(&self->htlc,
53 per_commitment_point,
54 &keyset->self_htlc_key))
55 return false;
56
57 if (!derive_simple_key(&other->htlc,
58 per_commitment_point,
59 &keyset->other_htlc_key))
60 return false;
61
62 if (!derive_simple_key(&self->delayed_payment,
63 per_commitment_point,

Callers 3

initial_channel_txFunction · 0.70
penalty_tx_createFunction · 0.50
channel_txsFunction · 0.50

Calls 1

derive_simple_keyFunction · 0.85

Tested by

no test coverage detected