@@ -38,7 +38,7 @@ const METHOD_TYPE_OFFSET: usize = 5;
38
38
/// [`KeysInterface::get_inbound_payment_key_material`].
39
39
///
40
40
/// [`KeysInterface::get_inbound_payment_key_material`]: crate::chain::keysinterface::KeysInterface::get_inbound_payment_key_material
41
- pub ( super ) struct ExpandedKey {
41
+ pub struct ExpandedKey {
42
42
/// The key used to encrypt the bytes containing the payment metadata (i.e. the amount and
43
43
/// expiry, included for payment verification on decryption).
44
44
metadata_key : [ u8 ; 32 ] ,
@@ -51,7 +51,10 @@ pub(super) struct ExpandedKey {
51
51
}
52
52
53
53
impl 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 {
55
58
let ( metadata_key, ldk_pmt_hash_key, user_pmt_hash_key) =
56
59
hkdf_extract_expand_thrice ( b"LDK Inbound Payment Key Expansion" , & key_material. 0 ) ;
57
60
Self {
@@ -77,10 +80,21 @@ impl Method {
77
80
}
78
81
}
79
82
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 ) , ( ) >
81
95
where K :: Target : KeysInterface < Signer = Signer >
82
96
{
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 ) ?;
84
98
85
99
let mut iv_bytes = [ 0 as u8 ; IV_LEN ] ;
86
100
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:
96
110
Ok ( ( ldk_pmt_hash, payment_secret) )
97
111
}
98
112
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) ?;
101
122
102
123
let mut hmac = HmacEngine :: < Sha256 > :: new ( & keys. user_pmt_hash_key ) ;
103
124
hmac. input ( & metadata_bytes) ;
0 commit comments