Remove KeyMaterial

Now that NodeSigner::get_inbound_payment_key returns an ExpandedKey
instead of KeyMaterial, the latter is no longer needed. Remove
KeyMaterial and replace its uses with [u8; 32].
This commit is contained in:
Jeffrey Czyz 2024-12-05 14:38:06 -06:00
parent 09bec6eee9
commit a29153025f
No known key found for this signature in database
GPG key ID: 912EF12EA67705F5
12 changed files with 87 additions and 106 deletions

View file

@ -61,9 +61,7 @@ use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessa
use lightning::routing::router::{
InFlightHtlcs, Path, PaymentParameters, Route, RouteHop, RouteParameters, Router,
};
use lightning::sign::{
EntropySource, InMemorySigner, KeyMaterial, NodeSigner, Recipient, SignerProvider,
};
use lightning::sign::{EntropySource, InMemorySigner, NodeSigner, Recipient, SignerProvider};
use lightning::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
use lightning::util::config::UserConfig;
use lightning::util::errors::APIError;
@ -338,7 +336,7 @@ impl NodeSigner for KeyProvider {
fn get_inbound_payment_key(&self) -> ExpandedKey {
#[rustfmt::skip]
let random_bytes = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, self.node_secret[31]];
ExpandedKey::new(&KeyMaterial(random_bytes))
ExpandedKey::new(random_bytes)
}
fn sign_invoice(

View file

@ -57,9 +57,7 @@ use lightning::routing::router::{
InFlightHtlcs, PaymentParameters, Route, RouteParameters, Router,
};
use lightning::routing::utxo::UtxoLookup;
use lightning::sign::{
EntropySource, InMemorySigner, KeyMaterial, NodeSigner, Recipient, SignerProvider,
};
use lightning::sign::{EntropySource, InMemorySigner, NodeSigner, Recipient, SignerProvider};
use lightning::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
use lightning::util::config::{ChannelConfig, UserConfig};
use lightning::util::errors::APIError;
@ -636,7 +634,7 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
let keys_manager = Arc::new(KeyProvider {
node_secret: our_network_key.clone(),
inbound_payment_key: ExpandedKey::new(&KeyMaterial(inbound_payment_key)),
inbound_payment_key: ExpandedKey::new(inbound_payment_key),
counter: AtomicU64::new(0),
signer_state: RefCell::new(new_hash_map()),
});

View file

@ -16,7 +16,7 @@ use lightning::offers::invoice_request::InvoiceRequest;
use lightning::offers::nonce::Nonce;
use lightning::offers::offer::{Amount, Offer, Quantity};
use lightning::offers::parse::Bolt12SemanticError;
use lightning::sign::{EntropySource, KeyMaterial};
use lightning::sign::EntropySource;
use lightning::util::ser::Writeable;
#[inline]
@ -43,7 +43,7 @@ impl EntropySource for FixedEntropy {
}
fn build_request(offer: &Offer) -> Result<InvoiceRequest, Bolt12SemanticError> {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();

View file

@ -20,7 +20,7 @@ use crate::ln::msgs;
use crate::ln::msgs::MAX_VALUE_MSAT;
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
use crate::offers::nonce::Nonce;
use crate::sign::{KeyMaterial, EntropySource};
use crate::sign::EntropySource;
use crate::util::errors::APIError;
use crate::util::logger::Logger;
@ -64,7 +64,7 @@ impl ExpandedKey {
/// Create a new [`ExpandedKey`] for generating an inbound payment hash and secret.
///
/// It is recommended to cache this value and not regenerate it for each new inbound payment.
pub fn new(key_material: &KeyMaterial) -> ExpandedKey {
pub fn new(key_material: [u8; 32]) -> ExpandedKey {
let (
metadata_key,
ldk_pmt_hash_key,
@ -72,7 +72,7 @@ impl ExpandedKey {
offers_base_key,
offers_encryption_key,
spontaneous_pmt_key,
) = hkdf_extract_expand_6x(b"LDK Inbound Payment Key Expansion", &key_material.0);
) = hkdf_extract_expand_6x(b"LDK Inbound Payment Key Expansion", &key_material);
Self {
metadata_key,
ldk_pmt_hash_key,

View file

@ -2411,7 +2411,6 @@ mod tests {
use crate::offers::test_utils::*;
use crate::routing::gossip::NetworkGraph;
use crate::routing::router::{InFlightHtlcs, Path, PaymentParameters, Route, RouteHop, RouteParameters};
use crate::sign::KeyMaterial;
use crate::sync::{Arc, Mutex, RwLock};
use crate::util::errors::APIError;
use crate::util::hash_tables::new_hash_map;
@ -2756,7 +2755,7 @@ mod tests {
let router = test_utils::TestRouter::new(network_graph, &logger, &scorer);
let secp_ctx = Secp256k1::new();
let keys_manager = test_utils::TestKeysInterface::new(&[0; 32], Network::Testnet);
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let nonce = Nonce([0; 16]);
let pending_events = Mutex::new(VecDeque::new());
@ -2813,7 +2812,7 @@ mod tests {
let pending_events = Mutex::new(VecDeque::new());
let outbound_payments = OutboundPayments::new(new_hash_map());
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let nonce = Nonce([0; 16]);
let payment_id = PaymentId([0; 32]);
let expiration = StaleExpiration::AbsoluteTimeout(Duration::from_secs(100));
@ -2875,7 +2874,7 @@ mod tests {
let pending_events = Mutex::new(VecDeque::new());
let outbound_payments = OutboundPayments::new(new_hash_map());
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let nonce = Nonce([0; 16]);
let payment_id = PaymentId([0; 32]);
let expiration = StaleExpiration::AbsoluteTimeout(Duration::from_secs(100));
@ -2960,7 +2959,7 @@ mod tests {
}
fn dummy_invoice_request() -> InvoiceRequest {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();

View file

@ -1605,7 +1605,6 @@ mod tests {
use crate::blinded_path::BlindedHop;
use crate::blinded_path::message::BlindedMessagePath;
use crate::sign::KeyMaterial;
use crate::types::features::{Bolt12InvoiceFeatures, InvoiceRequestFeatures, OfferFeatures};
use crate::ln::channelmanager::PaymentId;
use crate::ln::inbound_payment::ExpandedKey;
@ -1649,7 +1648,7 @@ mod tests {
#[test]
fn builds_invoice_for_offer_with_defaults() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1913,7 +1912,7 @@ mod tests {
#[cfg(feature = "std")]
#[test]
fn builds_invoice_from_offer_with_expiration() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1981,7 +1980,7 @@ mod tests {
#[test]
fn builds_invoice_from_offer_using_derived_keys() {
let node_id = recipient_pubkey();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2014,7 +2013,7 @@ mod tests {
panic!("error building invoice: {:?}", e);
}
let expanded_key = ExpandedKey::new(&KeyMaterial([41; 32]));
let expanded_key = ExpandedKey::new([41; 32]);
assert!(
invoice_request.verify_using_recipient_data(nonce, &expanded_key, &secp_ctx).is_err()
);
@ -2039,7 +2038,7 @@ mod tests {
#[test]
fn builds_invoice_from_refund_using_derived_keys() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let secp_ctx = Secp256k1::new();
@ -2061,7 +2060,7 @@ mod tests {
#[test]
fn builds_invoice_from_refund_with_path() {
let node_id = payer_pubkey();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let secp_ctx = Secp256k1::new();
@ -2090,7 +2089,7 @@ mod tests {
#[test]
fn builds_invoice_with_relative_expiry() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2132,7 +2131,7 @@ mod tests {
#[test]
fn builds_invoice_with_amount_from_request() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2154,7 +2153,7 @@ mod tests {
#[test]
fn builds_invoice_with_quantity_from_request() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2190,7 +2189,7 @@ mod tests {
#[test]
fn builds_invoice_with_fallback_address() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2242,7 +2241,7 @@ mod tests {
#[test]
fn builds_invoice_with_allow_mpp() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2267,7 +2266,7 @@ mod tests {
#[test]
fn fails_signing_invoice() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2302,7 +2301,7 @@ mod tests {
#[test]
fn parses_invoice_with_payment_paths() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2362,7 +2361,7 @@ mod tests {
#[test]
fn parses_invoice_with_created_at() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2397,7 +2396,7 @@ mod tests {
#[test]
fn parses_invoice_with_relative_expiry() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2424,7 +2423,7 @@ mod tests {
#[test]
fn parses_invoice_with_payment_hash() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2459,7 +2458,7 @@ mod tests {
#[test]
fn parses_invoice_with_amount() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2492,7 +2491,7 @@ mod tests {
#[test]
fn parses_invoice_with_allow_mpp() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2523,7 +2522,7 @@ mod tests {
#[test]
fn parses_invoice_with_fallback_address() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2587,7 +2586,7 @@ mod tests {
#[test]
fn parses_invoice_with_node_id() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2633,7 +2632,7 @@ mod tests {
#[test]
fn parses_invoice_with_node_id_from_blinded_path() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2710,7 +2709,7 @@ mod tests {
#[test]
fn fails_parsing_invoice_without_signature() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2735,7 +2734,7 @@ mod tests {
#[test]
fn fails_parsing_invoice_with_invalid_signature() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2765,7 +2764,7 @@ mod tests {
#[test]
fn parses_invoice_with_unknown_tlv_records() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let payment_id = PaymentId([1; 32]);
@ -2849,7 +2848,7 @@ mod tests {
#[test]
fn parses_invoice_with_experimental_tlv_records() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let payment_id = PaymentId([1; 32]);
@ -2979,7 +2978,7 @@ mod tests {
#[test]
fn fails_parsing_invoice_with_out_of_range_tlv_records() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -3008,7 +3007,7 @@ mod tests {
#[test]
fn fails_parsing_invoice_with_message_paths() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();

View file

@ -32,7 +32,6 @@
//! # use lightning::offers::nonce::Nonce;
//! use lightning::offers::offer::Offer;
//! # use lightning::sign::EntropySource;
//! use lightning::sign::KeyMaterial;
//! use lightning::util::ser::Writeable;
//!
//! # struct FixedEntropy;
@ -42,7 +41,7 @@
//! # }
//! # }
//! # fn parse() -> Result<(), lightning::offers::parse::Bolt12ParseError> {
//! let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
//! let expanded_key = ExpandedKey::new([42; 32]);
//! # let entropy = FixedEntropy {};
//! # let nonce = Nonce::from_entropy_source(&entropy);
//! let secp_ctx = Secp256k1::new();
@ -1329,7 +1328,6 @@ mod tests {
use core::num::NonZeroU64;
#[cfg(feature = "std")]
use core::time::Duration;
use crate::sign::KeyMaterial;
use crate::ln::channelmanager::PaymentId;
use crate::types::features::{InvoiceRequestFeatures, OfferFeatures};
use crate::ln::inbound_payment::ExpandedKey;
@ -1354,7 +1352,7 @@ mod tests {
#[test]
fn builds_invoice_request_with_defaults() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1440,7 +1438,7 @@ mod tests {
#[cfg(feature = "std")]
#[test]
fn builds_invoice_request_from_offer_with_expiration() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1473,7 +1471,7 @@ mod tests {
#[test]
fn builds_invoice_request_with_derived_payer_signing_pubkey() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1566,7 +1564,7 @@ mod tests {
#[test]
fn builds_invoice_request_with_chain() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1646,7 +1644,7 @@ mod tests {
#[test]
fn builds_invoice_request_with_amount() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1752,7 +1750,7 @@ mod tests {
#[test]
fn builds_invoice_request_with_features() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1782,7 +1780,7 @@ mod tests {
#[test]
fn builds_invoice_request_with_quantity() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1874,7 +1872,7 @@ mod tests {
#[test]
fn builds_invoice_request_with_payer_note() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1904,7 +1902,7 @@ mod tests {
#[test]
fn fails_responding_with_unknown_required_features() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1925,7 +1923,7 @@ mod tests {
#[test]
fn parses_invoice_request_with_metadata() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1947,7 +1945,7 @@ mod tests {
#[test]
fn parses_invoice_request_with_chain() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1985,7 +1983,7 @@ mod tests {
#[test]
fn parses_invoice_request_with_amount() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2081,7 +2079,7 @@ mod tests {
#[test]
fn parses_invoice_request_with_quantity() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2205,7 +2203,7 @@ mod tests {
#[test]
fn fails_parsing_invoice_request_without_metadata() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2232,7 +2230,7 @@ mod tests {
#[test]
fn fails_parsing_invoice_request_without_payer_signing_pubkey() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2257,7 +2255,7 @@ mod tests {
#[test]
fn fails_parsing_invoice_request_without_issuer_id() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2284,7 +2282,7 @@ mod tests {
#[test]
fn fails_parsing_invoice_request_without_signature() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2307,7 +2305,7 @@ mod tests {
#[test]
fn fails_parsing_invoice_request_with_invalid_signature() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2334,7 +2332,7 @@ mod tests {
#[test]
fn parses_invoice_request_with_unknown_tlv_records() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let payment_id = PaymentId([1; 32]);
@ -2420,7 +2418,7 @@ mod tests {
#[test]
fn parses_invoice_request_with_experimental_tlv_records() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let payment_id = PaymentId([1; 32]);
@ -2530,7 +2528,7 @@ mod tests {
#[test]
fn fails_parsing_invoice_request_with_out_of_range_tlv_records() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -2568,7 +2566,7 @@ mod tests {
#[test]
fn copies_verified_invoice_request_fields() {
let node_id = recipient_pubkey();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();

View file

@ -309,7 +309,6 @@ mod tests {
use crate::offers::parse::Bech32Encode;
use crate::offers::signer::Metadata;
use crate::offers::test_utils::recipient_pubkey;
use crate::sign::KeyMaterial;
use crate::util::ser::Writeable;
#[test]
@ -334,7 +333,7 @@ mod tests {
#[test]
fn calculates_merkle_root_hash_from_invoice_request() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let nonce = Nonce([0u8; 16]);
let secp_ctx = Secp256k1::new();
let payment_id = PaymentId([1; 32]);
@ -378,7 +377,7 @@ mod tests {
#[test]
fn compute_tagged_hash() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let nonce = Nonce([0u8; 16]);
let secp_ctx = Secp256k1::new();
let payment_id = PaymentId([1; 32]);
@ -401,7 +400,7 @@ mod tests {
#[test]
fn skips_encoding_signature_tlv_records() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let nonce = Nonce([0u8; 16]);
let secp_ctx = Secp256k1::new();
let payment_id = PaymentId([1; 32]);
@ -433,7 +432,7 @@ mod tests {
#[test]
fn iterates_over_tlv_stream_range() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let nonce = Nonce([0u8; 16]);
let secp_ctx = Secp256k1::new();
let payment_id = PaymentId([1; 32]);

View file

@ -1220,7 +1220,6 @@ mod tests {
use core::time::Duration;
use crate::blinded_path::BlindedHop;
use crate::blinded_path::message::BlindedMessagePath;
use crate::sign::KeyMaterial;
use crate::types::features::OfferFeatures;
use crate::ln::channelmanager::PaymentId;
use crate::ln::inbound_payment::ExpandedKey;
@ -1343,7 +1342,7 @@ mod tests {
#[test]
fn builds_offer_with_metadata_derived() {
let node_id = recipient_pubkey();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1403,7 +1402,7 @@ mod tests {
#[test]
fn builds_offer_with_derived_signing_pubkey() {
let node_id = recipient_pubkey();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1692,7 +1691,7 @@ mod tests {
#[test]
fn fails_requesting_invoice_with_unknown_required_features() {
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();

View file

@ -999,7 +999,6 @@ mod tests {
use crate::blinded_path::BlindedHop;
use crate::blinded_path::message::BlindedMessagePath;
use crate::sign::KeyMaterial;
use crate::ln::channelmanager::PaymentId;
use crate::types::features::{InvoiceRequestFeatures, OfferFeatures};
use crate::ln::inbound_payment::ExpandedKey;
@ -1100,7 +1099,7 @@ mod tests {
#[test]
fn builds_refund_with_metadata_derived() {
let node_id = payer_pubkey();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1161,7 +1160,7 @@ mod tests {
#[test]
fn builds_refund_with_derived_signing_pubkey() {
let node_id = payer_pubkey();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();

View file

@ -720,7 +720,6 @@ mod tests {
SIGNATURE_TAG,
};
use crate::offers::test_utils::*;
use crate::sign::KeyMaterial;
use crate::types::features::{Bolt12InvoiceFeatures, OfferFeatures};
use crate::util::ser::{BigSize, Iterable, Writeable};
use bitcoin::constants::ChainHash;
@ -776,7 +775,7 @@ mod tests {
let node_id = recipient_pubkey();
let payment_paths = payment_paths();
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -816,7 +815,7 @@ mod tests {
let node_id = recipient_pubkey();
let payment_paths = payment_paths();
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -913,7 +912,7 @@ mod tests {
fn builds_invoice_from_offer_with_expiration() {
let node_id = recipient_pubkey();
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -971,7 +970,7 @@ mod tests {
fn builds_invoice_from_offer_using_derived_key() {
let node_id = recipient_pubkey();
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -997,7 +996,7 @@ mod tests {
panic!("error building invoice: {:?}", e);
}
let expanded_key = ExpandedKey::new(&KeyMaterial([41; 32]));
let expanded_key = ExpandedKey::new([41; 32]);
if let Err(e) = StaticInvoiceBuilder::for_offer_using_derived_keys(
&offer,
payment_paths(),
@ -1017,7 +1016,7 @@ mod tests {
fn fails_build_with_missing_paths() {
let node_id = recipient_pubkey();
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1084,7 +1083,7 @@ mod tests {
fn fails_building_with_missing_issuer_signing_pubkey() {
let node_id = recipient_pubkey();
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1120,7 +1119,7 @@ mod tests {
#[test]
fn fails_building_with_invalid_metadata() {
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1150,7 +1149,7 @@ mod tests {
fn fails_building_with_extra_offer_chains() {
let node_id = recipient_pubkey();
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1183,7 +1182,7 @@ mod tests {
let node_id = recipient_pubkey();
let payment_paths = payment_paths();
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1225,7 +1224,7 @@ mod tests {
let node_id = recipient_pubkey();
let payment_paths = payment_paths();
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1362,7 +1361,7 @@ mod tests {
let node_id = recipient_pubkey();
let payment_paths = payment_paths();
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();
@ -1462,7 +1461,7 @@ mod tests {
let node_id = recipient_pubkey();
let payment_paths = payment_paths();
let now = now();
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
let expanded_key = ExpandedKey::new([42; 32]);
let entropy = FixedEntropy {};
let nonce = Nonce::from_entropy_source(&entropy);
let secp_ctx = Secp256k1::new();

View file

@ -82,13 +82,6 @@ pub mod ecdsa;
#[cfg(taproot)]
pub mod taproot;
/// Used as initial key material, to be expanded into multiple secret keys (but not to be used
/// directly). This is used within LDK to encrypt/decrypt inbound payment data.
///
/// This is not exported to bindings users as we just use `[u8; 32]` directly
#[derive(Hash, Copy, Clone, PartialEq, Eq, Debug)]
pub struct KeyMaterial(pub [u8; 32]);
/// Information about a spendable output to a P2WSH script.
///
/// See [`SpendableOutputDescriptor::DelayedPaymentOutput`] for more details on how to spend this.
@ -1939,7 +1932,7 @@ impl KeysManager {
secp_ctx,
node_secret,
node_id,
inbound_payment_key: ExpandedKey::new(&KeyMaterial(inbound_pmt_key_bytes)),
inbound_payment_key: ExpandedKey::new(inbound_pmt_key_bytes),
destination_script,
shutdown_pubkey,
@ -2445,7 +2438,7 @@ impl PhantomKeysManager {
let phantom_node_id = PublicKey::from_secret_key(&inner.secp_ctx, &phantom_secret);
Self {
inner,
inbound_payment_key: ExpandedKey::new(&KeyMaterial(inbound_key)),
inbound_payment_key: ExpandedKey::new(inbound_key),
phantom_secret,
phantom_node_id,
}