df-spec: use an empty bit-set as the basepoint for chan-id at start

> If the peer's revocation basepoint is unknown (e.g. `open_channel2`),
> a temporary `channel_id` should be found by using a zeroed out basepoint
> for the unknown peer.
This commit is contained in:
niftynei
2021-03-03 14:07:32 -06:00
committed by Rusty Russell
parent 31e3bdb42d
commit a5fedc4e1f
3 changed files with 74 additions and 32 deletions

View File

@@ -47,6 +47,24 @@ void derive_channel_id_v2(struct channel_id *channel_id,
memcpy(channel_id, &sha, sizeof(*channel_id));
}
void derive_tmp_channel_id(struct channel_id *channel_id,
const struct pubkey *opener_basepoint)
{
struct sha256 sha;
/* BOLT-f53ca2301232db780843e894f55d95d512f297f9 #2:
* If the peer's revocation basepoint is unknown
* (e.g. `open_channel2`), a temporary `channel_id` should be
* found by using a zeroed out basepoint for the unknown peer.
*/
u8 der_keys[PUBKEY_CMPR_LEN * 2];
memset(der_keys, 0, PUBKEY_CMPR_LEN);
pubkey_to_der(der_keys + PUBKEY_CMPR_LEN, opener_basepoint);
sha256(&sha, der_keys, sizeof(der_keys));
BUILD_ASSERT(sizeof(*channel_id) == sizeof(sha));
memcpy(channel_id, &sha, sizeof(*channel_id));
}
/* BOLT #2:
*
* The sending node:

View File

@@ -20,14 +20,22 @@ struct channel_id {
/* Define channel_id_eq (no padding) */
STRUCTEQ_DEF(channel_id, 0, id);
/* For v1 channel establishment */
void derive_channel_id(struct channel_id *channel_id,
const struct bitcoin_txid *txid, u16 txout);
/* For v1 channel establishment */
void temporary_channel_id(struct channel_id *channel_id);
/* For v2 channel establishment */
void derive_channel_id_v2(struct channel_id *channel_id,
const struct pubkey *basepoint_1,
const struct pubkey *basepoint_2);
void temporary_channel_id(struct channel_id *channel_id);
/* For v2 channel establishment */
void derive_tmp_channel_id(struct channel_id *channel_id,
const struct pubkey *opener_basepoint);
/* Marshalling/unmarshalling functions */
void towire_channel_id(u8 **pptr, const struct channel_id *channel_id);
void fromwire_channel_id(const u8 **cursor, size_t *max,