BOLT #3: * * ### `localpubkey`, `local_htlcpubkey`, `remote_htlcpubkey`, `local_delayedpubkey`, and `remote_delayedpubkey` Derivation * * These pubkeys are simply generated by addition from their base points: * * pubkey = basepoint + SHA256(per_commitment_point || basepoint) * G * * The `localpubkey` uses the local node's `payment_basepoint`; * The `remotepubkey` uses the remote node's `p
| 25 | * it is calculated as above using the remote node's `payment_basepoint`. |
| 26 | */ |
| 27 | bool derive_simple_key(const struct pubkey *basepoint, |
| 28 | const struct pubkey *per_commitment_point, |
| 29 | struct pubkey *key) |
| 30 | { |
| 31 | struct sha256 sha; |
| 32 | unsigned char der_keys[PUBKEY_CMPR_LEN * 2]; |
| 33 | |
| 34 | pubkey_to_der(der_keys, per_commitment_point); |
| 35 | pubkey_to_der(der_keys + PUBKEY_CMPR_LEN, basepoint); |
| 36 | sha256(&sha, der_keys, sizeof(der_keys)); |
| 37 | #ifdef SUPERVERBOSE |
| 38 | printf("# SHA256(per_commitment_point || basepoint)\n"); |
| 39 | printf("# => SHA256(0x%s || 0x%s)\n", |
| 40 | tal_hexstr(tmpctx, der_keys, PUBKEY_CMPR_LEN), |
| 41 | tal_hexstr(tmpctx, der_keys + PUBKEY_CMPR_LEN, PUBKEY_CMPR_LEN)); |
| 42 | printf("# = 0x%s\n", |
| 43 | tal_hexstr(tmpctx, &sha, sizeof(sha))); |
| 44 | #endif |
| 45 | |
| 46 | *key = *basepoint; |
| 47 | if (secp256k1_ec_pubkey_tweak_add(secp256k1_ctx, |
| 48 | &key->pubkey, sha.u.u8) != 1) |
| 49 | return false; |
| 50 | #ifdef SUPERVERBOSE |
| 51 | printf("# + basepoint (0x%s)\n", |
| 52 | type_to_string(tmpctx, struct pubkey, basepoint)); |
| 53 | printf("# = 0x%s\n", |
| 54 | type_to_string(tmpctx, struct pubkey, key)); |
| 55 | #endif |
| 56 | return true; |
| 57 | } |
| 58 | |
| 59 | /* BOLT #3: |
| 60 | * |