@@ -26,12 +26,10 @@ use crate::offers::nonce::Nonce;
26
26
use crate :: offers:: offer:: OfferId ;
27
27
use crate :: onion_message:: packet:: ControlTlvs ;
28
28
use crate :: routing:: gossip:: { NodeId , ReadOnlyNetworkGraph } ;
29
- use crate :: sign:: { EntropySource , NodeSigner , Recipient } ;
29
+ use crate :: sign:: { EntropySource , NodeSigner , ReceiveAuthKey , Recipient } ;
30
30
use crate :: types:: payment:: PaymentHash ;
31
31
use crate :: util:: scid_utils;
32
32
use crate :: util:: ser:: { FixedLengthReader , LengthReadableArgs , Readable , Writeable , Writer } ;
33
- use bitcoin:: hashes:: hmac:: Hmac ;
34
- use bitcoin:: hashes:: sha256:: Hash as Sha256 ;
35
33
36
34
use core:: mem;
37
35
use core:: ops:: Deref ;
@@ -57,13 +55,13 @@ impl Readable for BlindedMessagePath {
57
55
impl BlindedMessagePath {
58
56
/// Create a one-hop blinded path for a message.
59
57
pub fn one_hop < ES : Deref , T : secp256k1:: Signing + secp256k1:: Verification > (
60
- recipient_node_id : PublicKey , context : MessageContext , entropy_source : ES ,
61
- secp_ctx : & Secp256k1 < T > ,
58
+ recipient_node_id : PublicKey , local_node_receive_key : ReceiveAuthKey ,
59
+ context : MessageContext , entropy_source : ES , secp_ctx : & Secp256k1 < T > ,
62
60
) -> Result < Self , ( ) >
63
61
where
64
62
ES :: Target : EntropySource ,
65
63
{
66
- Self :: new ( & [ ] , recipient_node_id, context, entropy_source, secp_ctx)
64
+ Self :: new ( & [ ] , recipient_node_id, local_node_receive_key , context, entropy_source, secp_ctx)
67
65
}
68
66
69
67
/// Create a path for an onion message, to be forwarded along `node_pks`. The last node
@@ -73,7 +71,8 @@ impl BlindedMessagePath {
73
71
// TODO: make all payloads the same size with padding + add dummy hops
74
72
pub fn new < ES : Deref , T : secp256k1:: Signing + secp256k1:: Verification > (
75
73
intermediate_nodes : & [ MessageForwardNode ] , recipient_node_id : PublicKey ,
76
- context : MessageContext , entropy_source : ES , secp_ctx : & Secp256k1 < T > ,
74
+ local_node_receive_key : ReceiveAuthKey , context : MessageContext , entropy_source : ES ,
75
+ secp_ctx : & Secp256k1 < T > ,
77
76
) -> Result < Self , ( ) >
78
77
where
79
78
ES :: Target : EntropySource ,
@@ -94,6 +93,7 @@ impl BlindedMessagePath {
94
93
recipient_node_id,
95
94
context,
96
95
& blinding_secret,
96
+ local_node_receive_key,
97
97
)
98
98
. map_err ( |_| ( ) ) ?,
99
99
} ) )
@@ -404,12 +404,6 @@ pub enum OffersContext {
404
404
/// [`Refund`]: crate::offers::refund::Refund
405
405
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
406
406
nonce : Nonce ,
407
-
408
- /// Authentication code for the [`PaymentId`], which should be checked when the context is
409
- /// used with an [`InvoiceError`].
410
- ///
411
- /// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
412
- hmac : Option < Hmac < Sha256 > > ,
413
407
} ,
414
408
/// Context used by a [`BlindedMessagePath`] as a reply path for a [`Bolt12Invoice`].
415
409
///
@@ -422,19 +416,6 @@ pub enum OffersContext {
422
416
///
423
417
/// [`Bolt12Invoice::payment_hash`]: crate::offers::invoice::Bolt12Invoice::payment_hash
424
418
payment_hash : PaymentHash ,
425
-
426
- /// A nonce used for authenticating that a received [`InvoiceError`] is for a valid
427
- /// sent [`Bolt12Invoice`].
428
- ///
429
- /// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
430
- /// [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
431
- nonce : Nonce ,
432
-
433
- /// Authentication code for the [`PaymentHash`], which should be checked when the context is
434
- /// used to log the received [`InvoiceError`].
435
- ///
436
- /// [`InvoiceError`]: crate::offers::invoice_error::InvoiceError
437
- hmac : Hmac < Sha256 > ,
438
419
} ,
439
420
}
440
421
@@ -542,35 +523,12 @@ pub enum AsyncPaymentsContext {
542
523
///
543
524
/// [`Offer`]: crate::offers::offer::Offer
544
525
payment_id : PaymentId ,
545
- /// A nonce used for authenticating that a [`ReleaseHeldHtlc`] message is valid for a preceding
546
- /// [`HeldHtlcAvailable`] message.
547
- ///
548
- /// [`ReleaseHeldHtlc`]: crate::onion_message::async_payments::ReleaseHeldHtlc
549
- /// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
550
- nonce : Nonce ,
551
- /// Authentication code for the [`PaymentId`].
552
- ///
553
- /// Prevents the recipient from being able to deanonymize us by creating a blinded path to us
554
- /// containing the expected [`PaymentId`].
555
- hmac : Hmac < Sha256 > ,
556
526
} ,
557
527
/// Context contained within the [`BlindedMessagePath`]s we put in static invoices, provided back
558
528
/// to us in corresponding [`HeldHtlcAvailable`] messages.
559
529
///
560
530
/// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
561
531
InboundPayment {
562
- /// A nonce used for authenticating that a [`HeldHtlcAvailable`] message is valid for a
563
- /// preceding static invoice.
564
- ///
565
- /// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
566
- nonce : Nonce ,
567
- /// Authentication code for the [`HeldHtlcAvailable`] message.
568
- ///
569
- /// Prevents nodes from creating their own blinded path to us, sending a [`HeldHtlcAvailable`]
570
- /// message and trivially getting notified whenever we come online.
571
- ///
572
- /// [`HeldHtlcAvailable`]: crate::onion_message::async_payments::HeldHtlcAvailable
573
- hmac : Hmac < Sha256 > ,
574
532
/// The time as duration since the Unix epoch at which this path expires and messages sent over
575
533
/// it should be ignored. Without this, anyone with the path corresponding to this context is
576
534
/// able to trivially ask if we're online forever.
@@ -585,19 +543,27 @@ impl_writeable_tlv_based_enum!(MessageContext,
585
543
{ 3 , DNSResolver } => ( ) ,
586
544
) ;
587
545
546
+ // NOTE:
547
+ // Several TLV fields (`nonce`, `hmac`, etc.) were removed in LDK v0.2
548
+ // following the introduction of `ReceiveAuthKey`-based authentication for
549
+ // inbound `BlindedMessagePath`s. These fields are now commented out and
550
+ // their `type` values must not be reused unless support for LDK v0.2
551
+ // and earlier is fully dropped.
552
+ //
553
+ // For context-specific removals, see the commented-out fields within each enum variant.
588
554
impl_writeable_tlv_based_enum ! ( OffersContext ,
589
555
( 0 , InvoiceRequest ) => {
590
556
( 0 , nonce, required) ,
591
557
} ,
592
558
( 1 , OutboundPayment ) => {
593
559
( 0 , payment_id, required) ,
594
560
( 1 , nonce, required) ,
595
- ( 2 , hmac, option) ,
561
+ // Removed: (2, hmac, option)
596
562
} ,
597
563
( 2 , InboundPayment ) => {
598
564
( 0 , payment_hash, required) ,
599
- ( 1 , nonce, required) ,
600
- ( 2 , hmac, required)
565
+ // Removed: (1, nonce, required),
566
+ // Removed: (2, hmac, required)
601
567
} ,
602
568
( 3 , StaticInvoiceRequested ) => {
603
569
( 0 , recipient_id, required) ,
@@ -609,12 +575,12 @@ impl_writeable_tlv_based_enum!(OffersContext,
609
575
impl_writeable_tlv_based_enum ! ( AsyncPaymentsContext ,
610
576
( 0 , OutboundPayment ) => {
611
577
( 0 , payment_id, required) ,
612
- ( 2 , nonce, required) ,
613
- ( 4 , hmac, required) ,
578
+ // Removed: (2, nonce, required),
579
+ // Removed: (4, hmac, required),
614
580
} ,
615
581
( 1 , InboundPayment ) => {
616
- ( 0 , nonce, required) ,
617
- ( 2 , hmac, required) ,
582
+ // Removed: (0, nonce, required),
583
+ // Removed: (2, hmac, required),
618
584
( 4 , path_absolute_expiry, required) ,
619
585
} ,
620
586
( 2 , OfferPaths ) => {
@@ -642,10 +608,8 @@ impl_writeable_tlv_based_enum!(AsyncPaymentsContext,
642
608
/// [`DNSSECProof`]: crate::onion_message::dns_resolution::DNSSECProof
643
609
#[ derive( Clone , Debug , Hash , PartialEq , Eq ) ]
644
610
pub struct DNSResolverContext {
645
- /// A nonce which uniquely describes a DNS resolution.
646
- ///
647
- /// When we receive a DNSSEC proof message, we should check that it was sent over the blinded
648
- /// path we included in the request by comparing a stored nonce with this one.
611
+ /// A nonce which uniquely describes a DNS resolution, useful for looking up metadata about the
612
+ /// request.
649
613
pub nonce : [ u8 ; 16 ] ,
650
614
}
651
615
@@ -661,18 +625,19 @@ pub(crate) const MESSAGE_PADDING_ROUND_OFF: usize = 100;
661
625
pub ( super ) fn blinded_hops < T : secp256k1:: Signing + secp256k1:: Verification > (
662
626
secp_ctx : & Secp256k1 < T > , intermediate_nodes : & [ MessageForwardNode ] ,
663
627
recipient_node_id : PublicKey , context : MessageContext , session_priv : & SecretKey ,
628
+ local_node_receive_key : ReceiveAuthKey ,
664
629
) -> Result < Vec < BlindedHop > , secp256k1:: Error > {
665
630
let pks = intermediate_nodes
666
631
. iter ( )
667
- . map ( |node| node. node_id )
668
- . chain ( core:: iter:: once ( recipient_node_id) ) ;
632
+ . map ( |node| ( node. node_id , None ) )
633
+ . chain ( core:: iter:: once ( ( recipient_node_id, Some ( local_node_receive_key ) ) ) ) ;
669
634
let is_compact = intermediate_nodes. iter ( ) . any ( |node| node. short_channel_id . is_some ( ) ) ;
670
635
671
636
let tlvs = pks
672
637
. clone ( )
673
638
. skip ( 1 ) // The first node's TLVs contains the next node's pubkey
674
639
. zip ( intermediate_nodes. iter ( ) . map ( |node| node. short_channel_id ) )
675
- . map ( |( pubkey, scid) | match scid {
640
+ . map ( |( ( pubkey, _ ) , scid) | match scid {
676
641
Some ( scid) => NextMessageHop :: ShortChannelId ( scid) ,
677
642
None => NextMessageHop :: NodeId ( pubkey) ,
678
643
} )
0 commit comments