use crate::offers::invoice::{BlindedPayInfo, Bolt12Invoice, DEFAULT_RELATIVE_EXPIRY, DerivedSigningPubkey, ExplicitSigningPubkey, InvoiceBuilder, UnsignedBolt12Invoice};
use crate::offers::invoice_error::InvoiceError;
use crate::offers::invoice_request::{DerivedPayerId, InvoiceRequestBuilder};
+use crate::offers::nonce::Nonce;
use crate::offers::offer::{Offer, OfferBuilder};
use crate::offers::parse::Bolt12SemanticError;
use crate::offers::refund::{Refund, RefundBuilder};
let entropy = &*$self.entropy_source;
let secp_ctx = &$self.secp_ctx;
+ let nonce = Nonce::from_entropy_source(entropy);
let path = $self.create_blinded_paths_using_absolute_expiry(OffersContext::Unknown {}, absolute_expiry)
.and_then(|paths| paths.into_iter().next().ok_or(()))
.map_err(|_| Bolt12SemanticError::MissingPaths)?;
-
- let builder = OfferBuilder::deriving_signing_pubkey(
- node_id, expanded_key, entropy, secp_ctx
- )
+ let builder = OfferBuilder::deriving_signing_pubkey(node_id, expanded_key, nonce, secp_ctx)
.chain_hash($self.chain_hash)
.path(path);
use crate::ln::msgs::DecodeError;
use crate::offers::invoice_request::InvoiceRequestTlvStreamRef;
use crate::offers::merkle::{SignError, SignatureTlvStreamRef, TaggedHash, self};
+ use crate::offers::nonce::Nonce;
use crate::offers::offer::{Amount, OfferTlvStreamRef, Quantity};
use crate::prelude::*;
#[cfg(not(c_bindings))]
let node_id = recipient_pubkey();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let entropy = FixedEntropy {};
+ let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
let blinded_path = BlindedPath {
#[cfg(c_bindings)]
use crate::offers::offer::OfferWithDerivedMetadataBuilder as OfferBuilder;
- let offer = OfferBuilder
- ::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx)
+ let offer = OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx)
.amount_msats(1000)
.path(blinded_path)
.build().unwrap();
let expanded_key = ExpandedKey::new(&KeyMaterial([41; 32]));
assert!(invoice_request.verify(&expanded_key, &secp_ctx).is_err());
- let offer = OfferBuilder
- ::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx)
+ let offer = OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx)
.amount_msats(1000)
// Omit the path so that node_id is used for the signing pubkey instead of deriving
.build().unwrap();
use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
use crate::offers::invoice::{Bolt12Invoice, SIGNATURE_TAG as INVOICE_SIGNATURE_TAG};
use crate::offers::merkle::{SignError, SignatureTlvStreamRef, TaggedHash, self};
+ use crate::offers::nonce::Nonce;
use crate::offers::offer::{Amount, OfferTlvStreamRef, Quantity};
#[cfg(not(c_bindings))]
use {
let node_id = recipient_pubkey();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let entropy = FixedEntropy {};
+ let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
#[cfg(c_bindings)]
use crate::offers::offer::OfferWithDerivedMetadataBuilder as OfferBuilder;
- let offer = OfferBuilder
- ::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx)
+ let offer = OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx)
.chain(Network::Testnet)
.amount_msats(1000)
.supported_quantity(Quantity::Unbounded)
macro_rules! offer_derived_metadata_builder_methods { ($secp_context: ty) => {
/// Similar to [`OfferBuilder::new`] except, if [`OfferBuilder::path`] is called, the signing
- /// pubkey is derived from the given [`ExpandedKey`] and [`EntropySource`]. This provides
- /// recipient privacy by using a different signing pubkey for each offer. Otherwise, the
- /// provided `node_id` is used for the signing pubkey.
+ /// pubkey is derived from the given [`ExpandedKey`] and [`Nonce`]. This provides recipient
+ /// privacy by using a different signing pubkey for each offer. Otherwise, the provided
+ /// `node_id` is used for the signing pubkey.
///
/// Also, sets the metadata when [`OfferBuilder::build`] is called such that it can be used by
/// [`InvoiceRequest::verify`] to determine if the request was produced for the offer given an
///
/// [`InvoiceRequest::verify`]: crate::offers::invoice_request::InvoiceRequest::verify
/// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
- pub fn deriving_signing_pubkey<ES: Deref>(
- node_id: PublicKey, expanded_key: &ExpandedKey, entropy_source: ES,
+ pub fn deriving_signing_pubkey(
+ node_id: PublicKey, expanded_key: &ExpandedKey, nonce: Nonce,
secp_ctx: &'a Secp256k1<$secp_context>
- ) -> Self where ES::Target: EntropySource {
- let nonce = Nonce::from_entropy_source(entropy_source);
+ ) -> Self {
let derivation_material = MetadataMaterial::new(nonce, expanded_key, IV_BYTES, None);
let metadata = Metadata::DerivedSigningPubkey(derivation_material);
Self {
use crate::ln::features::OfferFeatures;
use crate::ln::inbound_payment::ExpandedKey;
use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
+ use crate::offers::nonce::Nonce;
use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError};
use crate::offers::test_utils::*;
use crate::util::ser::{BigSize, Writeable};
let node_id = recipient_pubkey();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let entropy = FixedEntropy {};
+ let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
#[cfg(c_bindings)]
use super::OfferWithDerivedMetadataBuilder as OfferBuilder;
- let offer = OfferBuilder
- ::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx)
+ let offer = OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx)
.amount_msats(1000)
.build().unwrap();
assert_eq!(offer.signing_pubkey(), Some(node_id));
let node_id = recipient_pubkey();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let entropy = FixedEntropy {};
+ let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
let blinded_path = BlindedPath {
#[cfg(c_bindings)]
use super::OfferWithDerivedMetadataBuilder as OfferBuilder;
- let offer = OfferBuilder
- ::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx)
+ let offer = OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx)
.amount_msats(1000)
.path(blinded_path)
.build().unwrap();
use crate::offers::invoice::InvoiceTlvStreamRef;
use crate::offers::merkle;
use crate::offers::merkle::{SignatureTlvStreamRef, TaggedHash};
+ use crate::offers::nonce::Nonce;
use crate::offers::offer::{Offer, OfferBuilder, OfferTlvStreamRef, Quantity};
use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError};
use crate::offers::static_invoice::{
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let entropy = FixedEntropy {};
+ let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
- let offer =
- OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx)
- .path(blinded_path())
- .build()
- .unwrap();
+ let offer = OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx)
+ .path(blinded_path())
+ .build()
+ .unwrap();
StaticInvoiceBuilder::for_offer_using_derived_keys(
&offer,
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let entropy = FixedEntropy {};
+ let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
- let offer =
- OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx)
- .path(blinded_path())
- .build()
- .unwrap();
+ let offer = OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx)
+ .path(blinded_path())
+ .build()
+ .unwrap();
let invoice = StaticInvoiceBuilder::for_offer_using_derived_keys(
&offer,
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let entropy = FixedEntropy {};
+ let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
let future_expiry = Duration::from_secs(u64::max_value());
let past_expiry = Duration::from_secs(0);
let valid_offer =
- OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx)
+ OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx)
.path(blinded_path())
.absolute_expiry(future_expiry)
.build()
assert_eq!(invoice.absolute_expiry(), Some(future_expiry));
let expired_offer =
- OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx)
+ OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx)
.path(blinded_path())
.absolute_expiry(past_expiry)
.build()
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let entropy = FixedEntropy {};
+ let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
let valid_offer =
- OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx)
+ OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx)
.path(blinded_path())
.build()
.unwrap();
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let entropy = FixedEntropy {};
+ let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
let valid_offer =
- OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx)
+ OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx)
.path(blinded_path())
.build()
.unwrap();
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let entropy = FixedEntropy {};
+ let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
let offer_with_extra_chain =
- OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx)
+ OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx)
.path(blinded_path())
.chain(Network::Bitcoin)
.chain(Network::Testnet)
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let entropy = FixedEntropy {};
+ let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
- let offer =
- OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx)
- .path(blinded_path())
- .build()
- .unwrap();
+ let offer = OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx)
+ .path(blinded_path())
+ .build()
+ .unwrap();
const TEST_RELATIVE_EXPIRY: u32 = 3600;
let invoice = StaticInvoiceBuilder::for_offer_using_derived_keys(
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let entropy = FixedEntropy {};
+ let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
- let offer =
- OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, &entropy, &secp_ctx)
- .path(blinded_path())
- .build()
- .unwrap();
+ let offer = OfferBuilder::deriving_signing_pubkey(node_id, &expanded_key, nonce, &secp_ctx)
+ .path(blinded_path())
+ .build()
+ .unwrap();
let invoice = StaticInvoiceBuilder::for_offer_using_derived_keys(
&offer,