use crate::ln::msgs;
use crate::ln::msgs::MAX_VALUE_MSAT;
use crate::ln::types::{PaymentHash, PaymentPreimage, PaymentSecret};
+use crate::offers::nonce::Nonce;
use crate::sign::{KeyMaterial, EntropySource};
use crate::util::errors::APIError;
use crate::util::logger::Logger;
}
}
-/// A 128-bit number used only once.
-///
-/// Needed when constructing [`Offer::metadata`] and deriving [`Offer::signing_pubkey`] from
-/// [`ExpandedKey`]. Must not be reused for any other derivation without first hashing.
-///
-/// [`Offer::metadata`]: crate::offers::offer::Offer::metadata
-/// [`Offer::signing_pubkey`]: crate::offers::offer::Offer::signing_pubkey
-#[derive(Clone, Copy, Debug, PartialEq)]
-pub struct Nonce(pub(crate) [u8; Self::LENGTH]);
-
-impl Nonce {
- /// Number of bytes in the nonce.
- pub const LENGTH: usize = 16;
-
- /// Creates a `Nonce` from the given [`EntropySource`].
- pub fn from_entropy_source<ES: Deref>(entropy_source: ES) -> Self
- where
- ES::Target: EntropySource,
- {
- let mut bytes = [0u8; Self::LENGTH];
- let rand_bytes = entropy_source.get_secure_random_bytes();
- bytes.copy_from_slice(&rand_bytes[..Self::LENGTH]);
-
- Nonce(bytes)
- }
-
- /// Returns a slice of the underlying bytes of size [`Nonce::LENGTH`].
- pub fn as_slice(&self) -> &[u8] {
- &self.0
- }
-}
-
-impl TryFrom<&[u8]> for Nonce {
- type Error = ();
-
- fn try_from(bytes: &[u8]) -> Result<Self, ()> {
- if bytes.len() != Self::LENGTH {
- return Err(());
- }
-
- let mut copied_bytes = [0u8; Self::LENGTH];
- copied_bytes.copy_from_slice(bytes);
-
- Ok(Self(copied_bytes))
- }
-}
-
enum Method {
LdkPaymentHash = 0,
UserPaymentHash = 1,
use crate::ln::types::PaymentHash;
use crate::ln::channelmanager::PaymentId;
use crate::ln::features::InvoiceRequestFeatures;
-use crate::ln::inbound_payment::{ExpandedKey, IV_LEN, Nonce};
+use crate::ln::inbound_payment::{ExpandedKey, IV_LEN};
use crate::ln::msgs::DecodeError;
use crate::offers::invoice::BlindedPayInfo;
use crate::offers::merkle::{SignError, SignFn, SignatureTlvStream, SignatureTlvStreamRef, TaggedHash, self};
+use crate::offers::nonce::Nonce;
use crate::offers::offer::{Offer, OfferContents, OfferId, OfferTlvStream, OfferTlvStreamRef};
use crate::offers::parse::{Bolt12ParseError, ParsedMessage, Bolt12SemanticError};
use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef};
mod invoice_macros;
pub mod invoice_request;
pub mod merkle;
+pub mod nonce;
pub mod parse;
mod payer;
pub mod refund;
--- /dev/null
+// This file is Copyright its original authors, visible in version control
+// history.
+//
+// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
+// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
+// You may not use this file except in accordance with one or both of these
+// licenses.
+
+//! A number used only once.
+
+use crate::sign::EntropySource;
+use core::ops::Deref;
+
+#[allow(unused_imports)]
+use crate::prelude::*;
+
+/// A 128-bit number used only once.
+///
+/// Needed when constructing [`Offer::metadata`] and deriving [`Offer::signing_pubkey`] from
+/// [`ExpandedKey`]. Must not be reused for any other derivation without first hashing.
+///
+/// [`Offer::metadata`]: crate::offers::offer::Offer::metadata
+/// [`Offer::signing_pubkey`]: crate::offers::offer::Offer::signing_pubkey
+/// [`ExpandedKey`]: crate::ln::inbound_payment::ExpandedKey
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct Nonce(pub(crate) [u8; Self::LENGTH]);
+
+impl Nonce {
+ /// Number of bytes in the nonce.
+ pub const LENGTH: usize = 16;
+
+ /// Creates a `Nonce` from the given [`EntropySource`].
+ pub fn from_entropy_source<ES: Deref>(entropy_source: ES) -> Self
+ where
+ ES::Target: EntropySource,
+ {
+ let mut bytes = [0u8; Self::LENGTH];
+ let rand_bytes = entropy_source.get_secure_random_bytes();
+ bytes.copy_from_slice(&rand_bytes[..Self::LENGTH]);
+
+ Nonce(bytes)
+ }
+
+ /// Returns a slice of the underlying bytes of size [`Nonce::LENGTH`].
+ pub fn as_slice(&self) -> &[u8] {
+ &self.0
+ }
+}
+
+impl TryFrom<&[u8]> for Nonce {
+ type Error = ();
+
+ fn try_from(bytes: &[u8]) -> Result<Self, ()> {
+ if bytes.len() != Self::LENGTH {
+ return Err(());
+ }
+
+ let mut copied_bytes = [0u8; Self::LENGTH];
+ copied_bytes.copy_from_slice(bytes);
+
+ Ok(Self(copied_bytes))
+ }
+}
use crate::blinded_path::BlindedPath;
use crate::ln::channelmanager::PaymentId;
use crate::ln::features::OfferFeatures;
-use crate::ln::inbound_payment::{ExpandedKey, IV_LEN, Nonce};
+use crate::ln::inbound_payment::{ExpandedKey, IV_LEN};
use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
use crate::offers::merkle::{TaggedHash, TlvStream};
+use crate::offers::nonce::Nonce;
use crate::offers::parse::{Bech32Encode, Bolt12ParseError, Bolt12SemanticError, ParsedMessage};
use crate::offers::signer::{Metadata, MetadataMaterial, self};
use crate::util::ser::{HighZeroBytesDroppedBigSize, Readable, WithoutLength, Writeable, Writer};
use crate::ln::types::PaymentHash;
use crate::ln::channelmanager::PaymentId;
use crate::ln::features::InvoiceRequestFeatures;
-use crate::ln::inbound_payment::{ExpandedKey, IV_LEN, Nonce};
+use crate::ln::inbound_payment::{ExpandedKey, IV_LEN};
use crate::ln::msgs::{DecodeError, MAX_VALUE_MSAT};
use crate::offers::invoice::BlindedPayInfo;
use crate::offers::invoice_request::{InvoiceRequestTlvStream, InvoiceRequestTlvStreamRef};
+use crate::offers::nonce::Nonce;
use crate::offers::offer::{OfferTlvStream, OfferTlvStreamRef};
use crate::offers::parse::{Bech32Encode, Bolt12ParseError, Bolt12SemanticError, ParsedMessage};
use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef};
use bitcoin::secp256k1::{Keypair, PublicKey, Secp256k1, SecretKey, self};
use core::fmt;
use crate::ln::channelmanager::PaymentId;
-use crate::ln::inbound_payment::{ExpandedKey, IV_LEN, Nonce};
+use crate::ln::inbound_payment::{ExpandedKey, IV_LEN};
use crate::offers::merkle::TlvRecord;
+use crate::offers::nonce::Nonce;
use crate::util::ser::Writeable;
use crate::prelude::*;