@@ -45,6 +45,8 @@ use crate::onion_message::messenger::{MessageSendInstructions, Responder, Respon
45
45
use crate :: onion_message:: packet:: OnionMessageContents ;
46
46
use crate :: prelude:: * ;
47
47
#[ cfg( feature = "dnssec" ) ]
48
+ use crate :: sign:: EntropySource ;
49
+ #[ cfg( feature = "dnssec" ) ]
48
50
use crate :: sync:: Mutex ;
49
51
use crate :: util:: ser:: { Readable , ReadableArgs , Writeable , Writer } ;
50
52
@@ -320,28 +322,28 @@ impl OMNameResolver {
320
322
321
323
/// Begins the process of resolving a BIP 353 Human Readable Name.
322
324
///
323
- /// The given `random_context` must be a [`DNSResolverContext`] with a fresh, unused random
324
- /// nonce which is included in the blinded path which will be set as the reply path when
325
- /// sending the returned [`DNSSECQuery`].
326
- ///
327
- /// Returns a [`DNSSECQuery`] onion message which should be sent to a resolver on success.
328
- pub fn resolve_name (
329
- & self , payment_id : PaymentId , name : HumanReadableName , random_context : DNSResolverContext ,
330
- ) -> Result < DNSSECQuery , ( ) > {
325
+ /// Returns a [`DNSSECQuery`] onion message and a [`DNSResolverContext`] which should be sent
326
+ /// to a resolver (with the context used to generate the blinded response path) on success.
327
+ pub fn resolve_name < ES : EntropySource + ?Sized > (
328
+ & self , payment_id : PaymentId , name : HumanReadableName , entropy_source : & ES ,
329
+ ) -> Result < ( DNSSECQuery , DNSResolverContext ) , ( ) > {
331
330
let dns_name =
332
331
Name :: try_from ( format ! ( "{}.user._bitcoin-payment.{}." , name. user, name. domain) ) ;
333
332
debug_assert ! (
334
333
dns_name. is_ok( ) ,
335
334
"The HumanReadableName constructor shouldn't allow names which are too long"
336
335
) ;
337
- let name_query = dns_name. clone ( ) . map ( |q| DNSSECQuery ( q) ) ;
336
+ let mut context = DNSResolverContext { nonce : [ 0 ; 16 ] } ;
337
+ context. nonce . copy_from_slice ( & entropy_source. get_secure_random_bytes ( ) [ ..16 ] ) ;
338
338
if let Ok ( dns_name) = dns_name {
339
339
let height = self . latest_block_height . load ( Ordering :: Acquire ) ;
340
340
let mut pending_resolves = self . pending_resolves . lock ( ) . unwrap ( ) ;
341
- let resolution = ( height as u32 , random_context, name, payment_id) ;
342
- pending_resolves. entry ( dns_name) . or_insert_with ( Vec :: new) . push ( resolution) ;
341
+ let resolution = ( height as u32 , context. clone ( ) , name, payment_id) ;
342
+ pending_resolves. entry ( dns_name. clone ( ) ) . or_insert_with ( Vec :: new) . push ( resolution) ;
343
+ Ok ( ( DNSSECQuery ( dns_name) , context) )
344
+ } else {
345
+ Err ( ( ) )
343
346
}
344
- name_query
345
347
}
346
348
347
349
/// Handles a [`DNSSECProof`] message, attempting to verify it and match it against a pending
0 commit comments