Skip to content

Commit 7f76b46

Browse files
committed
f - clean-up and comments
1 parent 16e953e commit 7f76b46

File tree

2 files changed

+30
-17
lines changed

2 files changed

+30
-17
lines changed

lightning/src/ln/inbound_payment.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ impl ExpandedKey {
7575
hmac
7676
}
7777

78+
/// Derives a pubkey using the given nonce for use as [`Offer::signing_pubkey`].
79+
///
80+
/// [`Offer::signing_pubkey`]: crate::offers::offer::Offer::signing_pubkey
7881
pub(crate) fn signing_pubkey_for_offer(&self, nonce: Nonce) -> PublicKey {
7982
let secp_ctx = Secp256k1::new();
8083
let mut tweak = [0; 32];
@@ -88,23 +91,29 @@ impl ExpandedKey {
8891
}
8992
}
9093

94+
/// A 128-bit number used only once.
95+
///
96+
/// Needed when constructing [`Offer::metadata`] and deriving [`Offer::signing_pubkey`] from
97+
/// [`ExpandedKey`].
9198
///
99+
/// [`Offer::metadata`]: crate::offers::offer::Offer::metadata
100+
/// [`Offer::signing_pubkey`]: crate::offers::offer::Offer::signing_pubkey
92101
#[derive(Clone, Copy)]
93102
pub struct Nonce(pub(crate) [u8; Self::LENGTH]);
94103

95104
impl Nonce {
96-
///
105+
/// Number of bytes in the nonce.
97106
pub const LENGTH: usize = 16;
98107

99-
///
108+
/// Creates a `Nonce` from the given [`EntropySource`].
100109
pub fn from_entropy_source<ES: EntropySource>(entropy_source: &ES) -> Self {
101-
let mut bytes = [0 as u8; Self::LENGTH];
110+
let mut bytes = [0u8; Self::LENGTH];
102111
let rand_bytes = entropy_source.get_secure_random_bytes();
103112
bytes.copy_from_slice(&rand_bytes[..Self::LENGTH]);
104113
Nonce(bytes)
105114
}
106115

107-
///
116+
/// Returns a slice of the underlying bytes of size [`Nonce::LENGTH`].
108117
pub fn as_slice(&self) -> &[u8] {
109118
&self.0
110119
}

lightning/src/offers/offer.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
//! let pubkey = PublicKey::from(keys);
4242
//!
4343
//! let expiration = SystemTime::now() + Duration::from_secs(24 * 60 * 60);
44-
//! let offer = OfferBuilder::new("coffee, large".to_string(), pubkey)
44+
//! let offer = OfferBuilder::new("coffee, large".to_string(), pubkey.into())
4545
//! .amount_msats(20_000)
4646
//! .supported_quantity(Quantity::Unbounded)
4747
//! .absolute_expiry(expiration.duration_since(SystemTime::UNIX_EPOCH).unwrap())
@@ -92,19 +92,12 @@ use crate::prelude::*;
9292
#[cfg(feature = "std")]
9393
use std::time::SystemTime;
9494

95-
/// Builds an [`Offer`] for the "offer to be paid" flow.
96-
///
97-
/// See [module-level documentation] for usage.
98-
///
99-
/// [module-level documentation]: self
100-
pub struct OfferBuilder {
101-
offer: OfferContents,
102-
metadata_material: Option<(Nonce, HmacEngine<Sha256>)>,
103-
}
104-
105-
///
95+
/// A pubkey for signing invoices, either given explicitly or derived.
10696
pub enum SigningPubkey<'a> {
97+
/// A pubkey that is typically known like a node id.
10798
Explicit(PublicKey),
99+
100+
/// Data needed to derive a pubkey.
108101
Derived(&'a ExpandedKey, Nonce),
109102
}
110103

@@ -114,6 +107,16 @@ impl<'a> From<PublicKey> for SigningPubkey<'a> {
114107
}
115108
}
116109

110+
/// Builds an [`Offer`] for the "offer to be paid" flow.
111+
///
112+
/// See [module-level documentation] for usage.
113+
///
114+
/// [module-level documentation]: self
115+
pub struct OfferBuilder {
116+
offer: OfferContents,
117+
metadata_material: Option<(Nonce, HmacEngine<Sha256>)>,
118+
}
119+
117120
impl OfferBuilder {
118121
/// Creates a new builder for an offer setting the [`Offer::description`] and using the
119122
/// [`Offer::signing_pubkey`] for signing invoices. The associated secret key must be remembered
@@ -250,7 +253,8 @@ impl OfferBuilder {
250253
}
251254
}
252255

253-
// Created the metadata for stateless verification.
256+
// Create the metadata for stateless verification. It consists of a 16-byte nonce and a
257+
// 32-byte HMAC of the offer bytes excluding the signing pubkey.
254258
if let Some((nonce, mut hmac)) = self.metadata_material {
255259
debug_assert!(self.offer.metadata.is_none());
256260
let mut tlv_stream = self.offer.as_tlv_stream();

0 commit comments

Comments
 (0)