Skip to content

Commit a3e89a7

Browse files
committed
f: Rename Verification trait function to a more generic name
This prepares the trait for use in dummy hop verification and Offer messages. Renaming helps generalize its purpose ahead of upcoming changes.
1 parent c7f1080 commit a3e89a7

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

lightning/src/blinded_path/payment.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -351,10 +351,7 @@ impl UnauthenticatedReceiveTlvs {
351351
/// Creates an authenticated [`ReceiveTlvs`], which includes an HMAC and the provide [`Nonce`]
352352
/// that can be use later to verify it authenticity.
353353
pub fn authenticate(self, nonce: Nonce, expanded_key: &ExpandedKey) -> ReceiveTlvs {
354-
ReceiveTlvs {
355-
authentication: (self.hmac_for_offer_payment(nonce, expanded_key), nonce),
356-
tlvs: self,
357-
}
354+
ReceiveTlvs { authentication: (self.hmac_data(nonce, expanded_key), nonce), tlvs: self }
358355
}
359356
}
360357

lightning/src/ln/channelmanager.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -475,42 +475,42 @@ impl Ord for ClaimableHTLC {
475475
pub trait Verification {
476476
/// Constructs an HMAC to include in [`OffersContext`] for the data along with the given
477477
/// [`Nonce`].
478-
fn hmac_for_offer_payment(
478+
fn hmac_data(
479479
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
480480
) -> Hmac<Sha256>;
481481

482482
/// Authenticates the data using an HMAC and a [`Nonce`] taken from an [`OffersContext`].
483-
fn verify_for_offer_payment(
483+
fn verify_data(
484484
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
485485
) -> Result<(), ()>;
486486
}
487487

488488
impl Verification for PaymentHash {
489489
/// Constructs an HMAC to include in [`OffersContext::InboundPayment`] for the payment hash
490490
/// along with the given [`Nonce`].
491-
fn hmac_for_offer_payment(
491+
fn hmac_data(
492492
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
493493
) -> Hmac<Sha256> {
494494
signer::hmac_for_payment_hash(*self, nonce, expanded_key)
495495
}
496496

497497
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
498498
/// [`OffersContext::InboundPayment`].
499-
fn verify_for_offer_payment(
499+
fn verify_data(
500500
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
501501
) -> Result<(), ()> {
502502
signer::verify_payment_hash(*self, hmac, nonce, expanded_key)
503503
}
504504
}
505505

506506
impl Verification for UnauthenticatedReceiveTlvs {
507-
fn hmac_for_offer_payment(
507+
fn hmac_data(
508508
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
509509
) -> Hmac<Sha256> {
510510
signer::hmac_for_payment_tlvs(self, nonce, expanded_key)
511511
}
512512

513-
fn verify_for_offer_payment(
513+
fn verify_data(
514514
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
515515
) -> Result<(), ()> {
516516
signer::verify_payment_tlvs(self, hmac, nonce, expanded_key)
@@ -550,15 +550,15 @@ impl PaymentId {
550550
impl Verification for PaymentId {
551551
/// Constructs an HMAC to include in [`OffersContext::OutboundPayment`] for the payment id
552552
/// along with the given [`Nonce`].
553-
fn hmac_for_offer_payment(
553+
fn hmac_data(
554554
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
555555
) -> Hmac<Sha256> {
556556
signer::hmac_for_offer_payment_id(*self, nonce, expanded_key)
557557
}
558558

559559
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
560560
/// [`OffersContext::OutboundPayment`].
561-
fn verify_for_offer_payment(
561+
fn verify_data(
562562
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
563563
) -> Result<(), ()> {
564564
signer::verify_offer_payment_id(*self, hmac, nonce, expanded_key)
@@ -10560,7 +10560,7 @@ where
1056010560
};
1056110561
let invoice_request = builder.build_and_sign()?;
1056210562

10563-
let hmac = payment_id.hmac_for_offer_payment(nonce, expanded_key);
10563+
let hmac = payment_id.hmac_data(nonce, expanded_key);
1056410564
let context = MessageContext::Offers(
1056510565
OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }
1056610566
);
@@ -10664,7 +10664,7 @@ where
1066410664
let invoice = builder.allow_mpp().build_and_sign(secp_ctx)?;
1066510665

1066610666
let nonce = Nonce::from_entropy_source(entropy);
10667-
let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key);
10667+
let hmac = payment_hash.hmac_data(nonce, expanded_key);
1066810668
let context = MessageContext::Offers(OffersContext::InboundPayment {
1066910669
payment_hash: invoice.payment_hash(), nonce, hmac
1067010670
});
@@ -12444,7 +12444,7 @@ where
1244412444
.release_invoice_requests_awaiting_invoice()
1244512445
{
1244612446
let RetryableInvoiceRequest { invoice_request, nonce, .. } = retryable_invoice_request;
12447-
let hmac = payment_id.hmac_for_offer_payment(nonce, &self.inbound_payment_key);
12447+
let hmac = payment_id.hmac_data(nonce, &self.inbound_payment_key);
1244812448
let context = MessageContext::Offers(OffersContext::OutboundPayment {
1244912449
payment_id,
1245012450
nonce,
@@ -12627,7 +12627,7 @@ where
1262712627
match response {
1262812628
Ok(invoice) => {
1262912629
let nonce = Nonce::from_entropy_source(&*self.entropy_source);
12630-
let hmac = payment_hash.hmac_for_offer_payment(nonce, expanded_key);
12630+
let hmac = payment_hash.hmac_data(nonce, expanded_key);
1263112631
let context = MessageContext::Offers(OffersContext::InboundPayment { payment_hash, nonce, hmac });
1263212632
Some((OffersMessage::Invoice(invoice), responder.respond_with_reply_path(context)))
1263312633
},
@@ -12664,7 +12664,7 @@ where
1266412664
OffersMessage::StaticInvoice(invoice) => {
1266512665
let payment_id = match context {
1266612666
Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => {
12667-
if payment_id.verify_for_offer_payment(hmac, nonce, expanded_key).is_err() {
12667+
if payment_id.verify_data(hmac, nonce, expanded_key).is_err() {
1266812668
return None
1266912669
}
1267012670
payment_id
@@ -12677,7 +12677,7 @@ where
1267712677
OffersMessage::InvoiceError(invoice_error) => {
1267812678
let payment_hash = match context {
1267912679
Some(OffersContext::InboundPayment { payment_hash, nonce, hmac }) => {
12680-
match payment_hash.verify_for_offer_payment(hmac, nonce, expanded_key) {
12680+
match payment_hash.verify_data(hmac, nonce, expanded_key) {
1268112681
Ok(_) => Some(payment_hash),
1268212682
Err(_) => None,
1268312683
}
@@ -12690,7 +12690,7 @@ where
1269012690

1269112691
match context {
1269212692
Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => {
12693-
if let Ok(()) = payment_id.verify_for_offer_payment(hmac, nonce, expanded_key) {
12693+
if let Ok(()) = payment_id.verify_data(hmac, nonce, expanded_key) {
1269412694
self.abandon_payment_with_reason(
1269512695
payment_id, PaymentFailureReason::InvoiceRequestRejected,
1269612696
);

lightning/src/ln/msgs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3444,7 +3444,7 @@ where
34443444
ChaChaPolyReadAdapter { readable: BlindedPaymentTlvs::Receive(receive_tlvs) } => {
34453445
let ReceiveTlvs { tlvs, authentication: (hmac, nonce) } = receive_tlvs;
34463446
let expanded_key = node_signer.get_expanded_key();
3447-
if tlvs.verify_for_offer_payment(hmac, nonce, &expanded_key).is_err() {
3447+
if tlvs.verify_data(hmac, nonce, &expanded_key).is_err() {
34483448
return Err(DecodeError::InvalidValue);
34493449
}
34503450

@@ -3596,7 +3596,7 @@ where
35963596
} => {
35973597
let ReceiveTlvs { tlvs, authentication: (hmac, nonce) } = receive_tlvs;
35983598
let expanded_key = node_signer.get_expanded_key();
3599-
if tlvs.verify_for_offer_payment(hmac, nonce, &expanded_key).is_err() {
3599+
if tlvs.verify_data(hmac, nonce, &expanded_key).is_err() {
36003600
return Err(DecodeError::InvalidValue);
36013601
}
36023602

0 commit comments

Comments
 (0)