| 4 | #include <common/keyset.h> |
| 5 | |
| 6 | bool 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 `remotepubkey` uses the remote node's `payment_basepoint`; |
| 22 | * the `local_htlcpubkey` uses the local node's `htlc_basepoint`; |
| 23 | * the `remote_htlcpubkey` uses the remote node's `htlc_basepoint`; |
| 24 | * the `local_delayedpubkey` uses the local node's `delayed_payment_basepoint`; |
| 25 | * and the `remote_delayedpubkey` uses the remote node's `delayed_payment_basepoint`. |
| 26 | */ |
| 27 | if (!derive_simple_key(&self->payment, |
| 28 | per_commitment_point, |
| 29 | &keyset->self_payment_key)) |
| 30 | return false; |
| 31 | |
| 32 | /* BOLT #3: |
| 33 | * |
| 34 | * ### `remotepubkey` Derivation |
| 35 | * |
| 36 | * If `option_static_remotekey` or `option_anchors` is |
| 37 | * negotiated, the `remotepubkey` is simply the remote node's |
| 38 | * `payment_basepoint`, otherwise it is calculated as above using the |
| 39 | * remote node's `payment_basepoint`. |
| 40 | */ |
| 41 | if (option_static_remotekey) |
| 42 | keyset->other_payment_key = other->payment; |
| 43 | else if (!derive_simple_key(&other->payment, |
| 44 | per_commitment_point, |
| 45 | &keyset->other_payment_key)) |
| 46 | return false; |
| 47 | |
| 48 | if (!derive_simple_key(&self->htlc, |
| 49 | per_commitment_point, |
| 50 | &keyset->self_htlc_key)) |
| 51 | return false; |
| 52 | |
| 53 | if (!derive_simple_key(&other->htlc, |
| 54 | per_commitment_point, |
| 55 | &keyset->other_htlc_key)) |
| 56 | return false; |
| 57 | |
| 58 | if (!derive_simple_key(&self->delayed_payment, |
| 59 | per_commitment_point, |
| 60 | &keyset->self_delayed_payment_key)) |
| 61 | return false; |
| 62 | |
| 63 | /* BOLT #3: |
no test coverage detected