@@ -19,6 +19,7 @@ use crate::crypto::utils::hkdf_extract_expand_5x;
1919use crate :: ln:: types:: { PaymentHash , PaymentPreimage , PaymentSecret } ;
2020use crate :: ln:: msgs;
2121use crate :: ln:: msgs:: MAX_VALUE_MSAT ;
22+ use crate :: offers:: nonce:: Nonce ;
2223use crate :: sign:: { KeyMaterial , EntropySource } ;
2324use crate :: util:: errors:: APIError ;
2425use crate :: util:: logger:: Logger ;
@@ -97,53 +98,6 @@ impl ExpandedKey {
9798 }
9899}
99100
100- /// A 128-bit number used only once.
101- ///
102- /// Needed when constructing [`Offer::metadata`] and deriving [`Offer::signing_pubkey`] from
103- /// [`ExpandedKey`]. Must not be reused for any other derivation without first hashing.
104- ///
105- /// [`Offer::metadata`]: crate::offers::offer::Offer::metadata
106- /// [`Offer::signing_pubkey`]: crate::offers::offer::Offer::signing_pubkey
107- #[ derive( Clone , Copy , Debug , PartialEq ) ]
108- pub struct Nonce ( pub ( crate ) [ u8 ; Self :: LENGTH ] ) ;
109-
110- impl Nonce {
111- /// Number of bytes in the nonce.
112- pub const LENGTH : usize = 16 ;
113-
114- /// Creates a `Nonce` from the given [`EntropySource`].
115- pub fn from_entropy_source < ES : Deref > ( entropy_source : ES ) -> Self
116- where
117- ES :: Target : EntropySource ,
118- {
119- let mut bytes = [ 0u8 ; Self :: LENGTH ] ;
120- let rand_bytes = entropy_source. get_secure_random_bytes ( ) ;
121- bytes. copy_from_slice ( & rand_bytes[ ..Self :: LENGTH ] ) ;
122-
123- Nonce ( bytes)
124- }
125-
126- /// Returns a slice of the underlying bytes of size [`Nonce::LENGTH`].
127- pub fn as_slice ( & self ) -> & [ u8 ] {
128- & self . 0
129- }
130- }
131-
132- impl TryFrom < & [ u8 ] > for Nonce {
133- type Error = ( ) ;
134-
135- fn try_from ( bytes : & [ u8 ] ) -> Result < Self , ( ) > {
136- if bytes. len ( ) != Self :: LENGTH {
137- return Err ( ( ) ) ;
138- }
139-
140- let mut copied_bytes = [ 0u8 ; Self :: LENGTH ] ;
141- copied_bytes. copy_from_slice ( bytes) ;
142-
143- Ok ( Self ( copied_bytes) )
144- }
145- }
146-
147101enum Method {
148102 LdkPaymentHash = 0 ,
149103 UserPaymentHash = 1 ,
0 commit comments