@@ -38,7 +38,7 @@ const METHOD_TYPE_OFFSET: usize = 5;
3838/// [`KeysInterface::get_inbound_payment_key_material`].
3939///
4040/// [`KeysInterface::get_inbound_payment_key_material`]: crate::chain::keysinterface::KeysInterface::get_inbound_payment_key_material
41- pub ( super ) struct ExpandedKey {
41+ pub struct ExpandedKey {
4242 /// The key used to encrypt the bytes containing the payment metadata (i.e. the amount and
4343 /// expiry, included for payment verification on decryption).
4444 metadata_key : [ u8 ; 32 ] ,
@@ -51,7 +51,10 @@ pub(super) struct ExpandedKey {
5151}
5252
5353impl ExpandedKey {
54- pub ( super ) fn new ( key_material : & KeyMaterial ) -> ExpandedKey {
54+ /// Create a new [`ExpandedKey`] for generating an inbound payment hash and secret.
55+ ///
56+ /// It is recommended to cache this value and not regenerate it for each new inbound payment.
57+ pub fn new ( key_material : & KeyMaterial ) -> ExpandedKey {
5558 let ( metadata_key, ldk_pmt_hash_key, user_pmt_hash_key) =
5659 hkdf_extract_expand_thrice ( b"LDK Inbound Payment Key Expansion" , & key_material. 0 ) ;
5760 Self {
@@ -77,10 +80,21 @@ impl Method {
7780 }
7881}
7982
80- pub ( super ) fn create < Signer : Sign , K : Deref > ( keys : & ExpandedKey , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 , keys_manager : & K , highest_seen_timestamp : u64 ) -> Result < ( PaymentHash , PaymentSecret ) , ( ) >
83+ /// Equivalent to [`crate::ln::channelmanager::ChannelManager::create_inbound_payment`], but no
84+ /// `ChannelManager` is required. Useful for generating invoices for [phantom node payments] without
85+ /// a `ChannelManager`.
86+ ///
87+ /// `keys` is generated by calling [`KeysInterface::get_inbound_payment_key_material`] and then
88+ /// calling [`ExpandedKey::new`] with its result. It is recommended to cache this value and not
89+ /// regenerate it for each new inbound payment.
90+ ///
91+ /// `current_time` is a Unix timestamp representing the current time.
92+ ///
93+ /// [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
94+ pub fn create < Signer : Sign , K : Deref > ( keys : & ExpandedKey , min_value_msat : Option < u64 > , invoice_expiry_delta_secs : u32 , keys_manager : & K , current_time : u64 ) -> Result < ( PaymentHash , PaymentSecret ) , ( ) >
8195 where K :: Target : KeysInterface < Signer = Signer >
8296{
83- let metadata_bytes = construct_metadata_bytes ( min_value_msat, Method :: LdkPaymentHash , invoice_expiry_delta_secs, highest_seen_timestamp ) ?;
97+ let metadata_bytes = construct_metadata_bytes ( min_value_msat, Method :: LdkPaymentHash , invoice_expiry_delta_secs, current_time ) ?;
8498
8599 let mut iv_bytes = [ 0 as u8 ; IV_LEN ] ;
86100 let rand_bytes = keys_manager. get_secure_random_bytes ( ) ;
@@ -96,8 +110,15 @@ pub(super) fn create<Signer: Sign, K: Deref>(keys: &ExpandedKey, min_value_msat:
96110 Ok ( ( ldk_pmt_hash, payment_secret) )
97111}
98112
99- pub ( super ) fn create_from_hash ( keys : & ExpandedKey , min_value_msat : Option < u64 > , payment_hash : PaymentHash , invoice_expiry_delta_secs : u32 , highest_seen_timestamp : u64 ) -> Result < PaymentSecret , ( ) > {
100- let metadata_bytes = construct_metadata_bytes ( min_value_msat, Method :: UserPaymentHash , invoice_expiry_delta_secs, highest_seen_timestamp) ?;
113+ /// Equivalent to [`crate::ln::channelmanager::ChannelManager::create_inbound_payment_for_hash`],
114+ /// but no `ChannelManager` is required. Useful for generating invoices for [phantom node payments]
115+ /// without a `ChannelManager`.
116+ ///
117+ /// See [`create`] for information on the `keys` and `current_time` parameters.
118+ ///
119+ /// [phantom node payments]: crate::chain::keysinterface::PhantomKeysManager
120+ pub fn create_from_hash ( keys : & ExpandedKey , min_value_msat : Option < u64 > , payment_hash : PaymentHash , invoice_expiry_delta_secs : u32 , current_time : u64 ) -> Result < PaymentSecret , ( ) > {
121+ let metadata_bytes = construct_metadata_bytes ( min_value_msat, Method :: UserPaymentHash , invoice_expiry_delta_secs, current_time) ?;
101122
102123 let mut hmac = HmacEngine :: < Sha256 > :: new ( & keys. user_pmt_hash_key ) ;
103124 hmac. input ( & metadata_bytes) ;
0 commit comments