Skip to content

Commit 437a10b

Browse files
keysmanager: support multi-node receive
To support the feature of generating invoices that can be paid to any of multiple nodes, KeysManagers need to be able to share an inbound_payment_key XXX fill in
1 parent e6b657e commit 437a10b

File tree

1 file changed

+19
-4
lines changed

1 file changed

+19
-4
lines changed

lightning/src/chain/keysinterface.rs

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,15 @@ impl KeysManager {
813813
/// versions. Once the library is more fully supported, the docs will be updated to include a
814814
/// detailed description of the guarantee.
815815
pub fn new(seed: &[u8; 32], starting_time_secs: u64, starting_time_nanos: u32) -> Self {
816+
Self::new_inner(seed, starting_time_secs, starting_time_nanos, None)
817+
}
818+
819+
/// XXX
820+
pub fn new_multi_receive(seed: &[u8; 32], starting_time_secs: u64, starting_time_nanos: u32, inbound_payment_key: KeyMaterial) -> Self {
821+
Self::new_inner(seed, starting_time_secs, starting_time_nanos, Some(inbound_payment_key))
822+
}
823+
824+
fn new_inner(seed: &[u8; 32], starting_time_secs: u64, starting_time_nanos: u32, inbound_payment_key_opt: Option<KeyMaterial>) -> Self {
816825
let secp_ctx = Secp256k1::new();
817826
// Note that when we aren't serializing the key, network doesn't matter
818827
match ExtendedPrivKey::new_master(Network::Testnet, seed) {
@@ -833,9 +842,14 @@ impl KeysManager {
833842
};
834843
let channel_master_key = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(3).unwrap()).expect("Your RNG is busted");
835844
let rand_bytes_master_key = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(4).unwrap()).expect("Your RNG is busted");
836-
let inbound_payment_key: SecretKey = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(5).unwrap()).expect("Your RNG is busted").private_key.key;
837-
let mut inbound_pmt_key_bytes = [0; 32];
838-
inbound_pmt_key_bytes.copy_from_slice(&inbound_payment_key[..]);
845+
let inbound_payment_key = if let Some(key) = inbound_payment_key_opt {
846+
key
847+
} else {
848+
let inbound_payment_key: SecretKey = master_key.ckd_priv(&secp_ctx, ChildNumber::from_hardened_idx(5).unwrap()).expect("Your RNG is busted").private_key.key;
849+
let mut inbound_pmt_key_bytes = [0; 32];
850+
inbound_pmt_key_bytes.copy_from_slice(&inbound_payment_key[..]);
851+
KeyMaterial(inbound_pmt_key_bytes)
852+
};
839853

840854
let mut rand_bytes_unique_start = Sha256::engine();
841855
rand_bytes_unique_start.input(&byte_utils::be64_to_array(starting_time_secs));
@@ -845,7 +859,7 @@ impl KeysManager {
845859
let mut res = KeysManager {
846860
secp_ctx,
847861
node_secret,
848-
inbound_payment_key: KeyMaterial(inbound_pmt_key_bytes),
862+
inbound_payment_key,
849863

850864
destination_script,
851865
shutdown_pubkey,
@@ -868,6 +882,7 @@ impl KeysManager {
868882
Err(_) => panic!("Your rng is busted"),
869883
}
870884
}
885+
871886
/// Derive an old Sign containing per-channel secrets based on a key derivation parameters.
872887
///
873888
/// Key derivation parameters are accessible through a per-channel secrets

0 commit comments

Comments
 (0)