@@ -405,6 +405,11 @@ pub trait KeysInterface {
405
405
/// This method must return the same value each time it is called with a given `Recipient`
406
406
/// parameter.
407
407
fn get_node_secret ( & self , recipient : Recipient ) -> Result < SecretKey , ( ) > ;
408
+ /// Get node id based on the provided [`Recipient`].
409
+ ///
410
+ /// This method must return the same value each time it is called with a given `Recipient`
411
+ /// parameter.
412
+ fn get_node_id ( & self , recipient : Recipient ) -> Result < PublicKey , ( ) > ;
408
413
/// Gets the ECDH shared secret of our [`node secret`] and `other_key`, multiplying by `tweak` if
409
414
/// one is provided. Note that this tweak can be applied to `other_key` instead of our node
410
415
/// secret, though this is less efficient.
@@ -853,6 +858,7 @@ impl ReadableArgs<SecretKey> for InMemorySigner {
853
858
pub struct KeysManager {
854
859
secp_ctx : Secp256k1 < secp256k1:: All > ,
855
860
node_secret : SecretKey ,
861
+ node_id : PublicKey ,
856
862
inbound_payment_key : KeyMaterial ,
857
863
destination_script : Script ,
858
864
shutdown_pubkey : PublicKey ,
@@ -894,6 +900,7 @@ impl KeysManager {
894
900
match ExtendedPrivKey :: new_master ( Network :: Testnet , seed) {
895
901
Ok ( master_key) => {
896
902
let node_secret = master_key. ckd_priv ( & secp_ctx, ChildNumber :: from_hardened_idx ( 0 ) . unwrap ( ) ) . expect ( "Your RNG is busted" ) . private_key ;
903
+ let node_id = PublicKey :: from_secret_key ( & secp_ctx, & node_secret) ;
897
904
let destination_script = match master_key. ckd_priv ( & secp_ctx, ChildNumber :: from_hardened_idx ( 1 ) . unwrap ( ) ) {
898
905
Ok ( destination_key) => {
899
906
let wpubkey_hash = WPubkeyHash :: hash ( & ExtendedPubKey :: from_priv ( & secp_ctx, & destination_key) . to_pub ( ) . to_bytes ( ) ) ;
@@ -921,6 +928,7 @@ impl KeysManager {
921
928
let mut res = KeysManager {
922
929
secp_ctx,
923
930
node_secret,
931
+ node_id,
924
932
inbound_payment_key : KeyMaterial ( inbound_pmt_key_bytes) ,
925
933
926
934
destination_script,
@@ -1140,6 +1148,13 @@ impl KeysInterface for KeysManager {
1140
1148
}
1141
1149
}
1142
1150
1151
+ fn get_node_id ( & self , recipient : Recipient ) -> Result < PublicKey , ( ) > {
1152
+ match recipient {
1153
+ Recipient :: Node => Ok ( self . node_id . clone ( ) ) ,
1154
+ Recipient :: PhantomNode => Err ( ( ) )
1155
+ }
1156
+ }
1157
+
1143
1158
fn ecdh ( & self , recipient : Recipient , other_key : & PublicKey , tweak : Option < & Scalar > ) -> Result < SharedSecret , ( ) > {
1144
1159
let mut node_secret = self . get_node_secret ( recipient) ?;
1145
1160
if let Some ( tweak) = tweak {
@@ -1220,6 +1235,7 @@ pub struct PhantomKeysManager {
1220
1235
inner : KeysManager ,
1221
1236
inbound_payment_key : KeyMaterial ,
1222
1237
phantom_secret : SecretKey ,
1238
+ phantom_node_id : PublicKey ,
1223
1239
}
1224
1240
1225
1241
impl KeysInterface for PhantomKeysManager {
@@ -1232,6 +1248,13 @@ impl KeysInterface for PhantomKeysManager {
1232
1248
}
1233
1249
}
1234
1250
1251
+ fn get_node_id ( & self , recipient : Recipient ) -> Result < PublicKey , ( ) > {
1252
+ match recipient {
1253
+ Recipient :: Node => self . inner . get_node_id ( Recipient :: Node ) ,
1254
+ Recipient :: PhantomNode => Ok ( self . phantom_node_id . clone ( ) ) ,
1255
+ }
1256
+ }
1257
+
1235
1258
fn ecdh ( & self , recipient : Recipient , other_key : & PublicKey , tweak : Option < & Scalar > ) -> Result < SharedSecret , ( ) > {
1236
1259
let mut node_secret = self . get_node_secret ( recipient) ?;
1237
1260
if let Some ( tweak) = tweak {
@@ -1285,10 +1308,13 @@ impl PhantomKeysManager {
1285
1308
pub fn new ( seed : & [ u8 ; 32 ] , starting_time_secs : u64 , starting_time_nanos : u32 , cross_node_seed : & [ u8 ; 32 ] ) -> Self {
1286
1309
let inner = KeysManager :: new ( seed, starting_time_secs, starting_time_nanos) ;
1287
1310
let ( inbound_key, phantom_key) = hkdf_extract_expand_twice ( b"LDK Inbound and Phantom Payment Key Expansion" , cross_node_seed) ;
1311
+ let phantom_secret = SecretKey :: from_slice ( & phantom_key) . unwrap ( ) ;
1312
+ let phantom_node_id = PublicKey :: from_secret_key ( & inner. secp_ctx , & phantom_secret) ;
1288
1313
Self {
1289
1314
inner,
1290
1315
inbound_payment_key : KeyMaterial ( inbound_key) ,
1291
- phantom_secret : SecretKey :: from_slice ( & phantom_key) . unwrap ( ) ,
1316
+ phantom_secret,
1317
+ phantom_node_id,
1292
1318
}
1293
1319
}
1294
1320
0 commit comments