Skip to content

Commit 5868a68

Browse files
committed
Pass Nonce directly to RefundBuilder
When using RefundBuilder::deriving_payer_id, the nonce generated needs to be the same one included in any RefundBuilder::paths. This is because the nonce is used along with the refund TLVs to derive a payer id and will soon be used to authenticate any invoices.
1 parent 2f852a6 commit 5868a68

File tree

2 files changed

+10
-7
lines changed

2 files changed

+10
-7
lines changed

lightning/src/ln/channelmanager.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8697,11 +8697,12 @@ macro_rules! create_refund_builder { ($self: ident, $builder: ty) => {
86978697
let entropy = &*$self.entropy_source;
86988698
let secp_ctx = &$self.secp_ctx;
86998699

8700+
let nonce = Nonce::from_entropy_source(entropy);
87008701
let context = OffersContext::OutboundPayment { payment_id };
87018702
let path = $self.create_blinded_path_using_absolute_expiry(context, Some(absolute_expiry))
87028703
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
87038704
let builder = RefundBuilder::deriving_payer_id(
8704-
node_id, expanded_key, entropy, secp_ctx, amount_msats, payment_id
8705+
node_id, expanded_key, nonce, secp_ctx, amount_msats, payment_id
87058706
)?
87068707
.chain_hash($self.chain_hash)
87078708
.absolute_expiry(absolute_expiry)

lightning/src/offers/refund.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -197,15 +197,14 @@ macro_rules! refund_builder_methods { (
197197
///
198198
/// [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
199199
/// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
200-
pub fn deriving_payer_id<ES: Deref>(
201-
node_id: PublicKey, expanded_key: &ExpandedKey, entropy_source: ES,
200+
pub fn deriving_payer_id(
201+
node_id: PublicKey, expanded_key: &ExpandedKey, nonce: Nonce,
202202
secp_ctx: &'a Secp256k1<$secp_context>, amount_msats: u64, payment_id: PaymentId
203-
) -> Result<Self, Bolt12SemanticError> where ES::Target: EntropySource {
203+
) -> Result<Self, Bolt12SemanticError> {
204204
if amount_msats > MAX_VALUE_MSAT {
205205
return Err(Bolt12SemanticError::InvalidAmount);
206206
}
207207

208-
let nonce = Nonce::from_entropy_source(entropy_source);
209208
let payment_id = Some(payment_id);
210209
let derivation_material = MetadataMaterial::new(nonce, expanded_key, IV_BYTES, payment_id);
211210
let metadata = Metadata::DerivedSigningPubkey(derivation_material);
@@ -940,6 +939,7 @@ mod tests {
940939
use crate::ln::inbound_payment::ExpandedKey;
941940
use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
942941
use crate::offers::invoice_request::InvoiceRequestTlvStreamRef;
942+
use crate::offers::nonce::Nonce;
943943
use crate::offers::offer::OfferTlvStreamRef;
944944
use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError};
945945
use crate::offers::payer::PayerTlvStreamRef;
@@ -1029,11 +1029,12 @@ mod tests {
10291029
let node_id = payer_pubkey();
10301030
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
10311031
let entropy = FixedEntropy {};
1032+
let nonce = Nonce::from_entropy_source(&entropy);
10321033
let secp_ctx = Secp256k1::new();
10331034
let payment_id = PaymentId([1; 32]);
10341035

10351036
let refund = RefundBuilder
1036-
::deriving_payer_id(node_id, &expanded_key, &entropy, &secp_ctx, 1000, payment_id)
1037+
::deriving_payer_id(node_id, &expanded_key, nonce, &secp_ctx, 1000, payment_id)
10371038
.unwrap()
10381039
.build().unwrap();
10391040
assert_eq!(refund.payer_id(), node_id);
@@ -1083,6 +1084,7 @@ mod tests {
10831084
let node_id = payer_pubkey();
10841085
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
10851086
let entropy = FixedEntropy {};
1087+
let nonce = Nonce::from_entropy_source(&entropy);
10861088
let secp_ctx = Secp256k1::new();
10871089
let payment_id = PaymentId([1; 32]);
10881090

@@ -1096,7 +1098,7 @@ mod tests {
10961098
};
10971099

10981100
let refund = RefundBuilder
1099-
::deriving_payer_id(node_id, &expanded_key, &entropy, &secp_ctx, 1000, payment_id)
1101+
::deriving_payer_id(node_id, &expanded_key, nonce, &secp_ctx, 1000, payment_id)
11001102
.unwrap()
11011103
.path(blinded_path)
11021104
.build().unwrap();

0 commit comments

Comments
 (0)