) -> Hmac<Sha256>;
/// Authenticates the data using an HMAC and a [`Nonce`] taken from an [`OffersContext`].
- fn verify(
+ fn verify_for_offer_payment(
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
) -> Result<(), ()>;
}
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
/// [`OffersContext::InboundPayment`].
- fn verify(
+ fn verify_for_offer_payment(
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
) -> Result<(), ()> {
signer::verify_payment_hash(*self, hmac, nonce, expanded_key)
fn hmac_for_offer_payment(
&self, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
) -> Hmac<Sha256> {
- signer::hmac_for_payment_id(*self, nonce, expanded_key)
+ signer::hmac_for_offer_payment_id(*self, nonce, expanded_key)
}
/// Authenticates the payment id using an HMAC and a [`Nonce`] taken from an
/// [`OffersContext::OutboundPayment`].
- fn verify(
+ fn verify_for_offer_payment(
&self, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &inbound_payment::ExpandedKey,
) -> Result<(), ()> {
- signer::verify_payment_id(*self, hmac, nonce, expanded_key)
+ signer::verify_offer_payment_id(*self, hmac, nonce, expanded_key)
}
}
OffersMessage::StaticInvoice(invoice) => {
let payment_id = match context {
Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => {
- if payment_id.verify(hmac, nonce, expanded_key).is_err() {
+ if payment_id.verify_for_offer_payment(hmac, nonce, expanded_key).is_err() {
return None
}
payment_id
OffersMessage::InvoiceError(invoice_error) => {
let payment_hash = match context {
Some(OffersContext::InboundPayment { payment_hash, nonce, hmac }) => {
- match payment_hash.verify(hmac, nonce, expanded_key) {
+ match payment_hash.verify_for_offer_payment(hmac, nonce, expanded_key) {
Ok(_) => Some(payment_hash),
Err(_) => None,
}
match context {
Some(OffersContext::OutboundPayment { payment_id, nonce, hmac: Some(hmac) }) => {
- if let Ok(()) = payment_id.verify(hmac, nonce, expanded_key) {
+ if let Ok(()) = payment_id.verify_for_offer_payment(hmac, nonce, expanded_key) {
self.abandon_payment_with_reason(
payment_id, PaymentFailureReason::InvoiceRequestRejected,
);
const WITH_ENCRYPTED_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[4; 16];
// HMAC input for a `PaymentId`. The HMAC is used in `OffersContext::OutboundPayment`.
-const PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[5; 16];
+const OFFER_PAYMENT_ID_HMAC_INPUT: &[u8; 16] = &[5; 16];
// HMAC input for a `PaymentHash`. The HMAC is used in `OffersContext::InboundPayment`.
const PAYMENT_HASH_HMAC_INPUT: &[u8; 16] = &[6; 16];
Ok(hmac)
}
-pub(crate) fn hmac_for_payment_id(
+pub(crate) fn hmac_for_offer_payment_id(
payment_id: PaymentId, nonce: Nonce, expanded_key: &ExpandedKey,
) -> Hmac<Sha256> {
const IV_BYTES: &[u8; IV_LEN] = b"LDK Payment ID ~";
let mut hmac = expanded_key.hmac_for_offer();
hmac.input(IV_BYTES);
hmac.input(&nonce.0);
- hmac.input(PAYMENT_ID_HMAC_INPUT);
+ hmac.input(OFFER_PAYMENT_ID_HMAC_INPUT);
hmac.input(&payment_id.0);
Hmac::from_engine(hmac)
}
-pub(crate) fn verify_payment_id(
+pub(crate) fn verify_offer_payment_id(
payment_id: PaymentId, hmac: Hmac<Sha256>, nonce: Nonce, expanded_key: &ExpandedKey,
) -> Result<(), ()> {
- if hmac_for_payment_id(payment_id, nonce, expanded_key) == hmac { Ok(()) } else { Err(()) }
+ if hmac_for_offer_payment_id(payment_id, nonce, expanded_key) == hmac { Ok(()) } else { Err(()) }
}
pub(crate) fn hmac_for_payment_hash(