Skip to content

Commit 2d4f55b

Browse files
committed
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].
1 parent d4d22f6 commit 2d4f55b

12 files changed

+87
-106
lines changed

fuzz/src/chanmon_consistency.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,7 @@ use lightning::ln::types::ChannelId;
6060
use lightning::offers::invoice::UnsignedBolt12Invoice;
6161
use lightning::onion_message::messenger::{Destination, MessageRouter, OnionMessagePath};
6262
use lightning::routing::router::{InFlightHtlcs, Path, Route, RouteHop, RouteParameters, Router};
63-
use lightning::sign::{
64-
EntropySource, InMemorySigner, KeyMaterial, NodeSigner, Recipient, SignerProvider,
65-
};
63+
use lightning::sign::{EntropySource, InMemorySigner, NodeSigner, Recipient, SignerProvider};
6664
use lightning::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
6765
use lightning::util::config::UserConfig;
6866
use lightning::util::errors::APIError;
@@ -331,7 +329,7 @@ impl NodeSigner for KeyProvider {
331329
fn get_inbound_payment_key(&self) -> ExpandedKey {
332330
#[rustfmt::skip]
333331
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]];
334-
ExpandedKey::new(&KeyMaterial(random_bytes))
332+
ExpandedKey::new(random_bytes)
335333
}
336334

337335
fn sign_invoice(

fuzz/src/full_stack.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,7 @@ use lightning::routing::router::{
5757
InFlightHtlcs, PaymentParameters, Route, RouteParameters, Router,
5858
};
5959
use lightning::routing::utxo::UtxoLookup;
60-
use lightning::sign::{
61-
EntropySource, InMemorySigner, KeyMaterial, NodeSigner, Recipient, SignerProvider,
62-
};
60+
use lightning::sign::{EntropySource, InMemorySigner, NodeSigner, Recipient, SignerProvider};
6361
use lightning::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
6462
use lightning::util::config::{ChannelConfig, UserConfig};
6563
use lightning::util::errors::APIError;
@@ -636,7 +634,7 @@ pub fn do_test(mut data: &[u8], logger: &Arc<dyn Logger>) {
636634

637635
let keys_manager = Arc::new(KeyProvider {
638636
node_secret: our_network_key.clone(),
639-
inbound_payment_key: ExpandedKey::new(&KeyMaterial(inbound_payment_key)),
637+
inbound_payment_key: ExpandedKey::new(inbound_payment_key),
640638
counter: AtomicU64::new(0),
641639
signer_state: RefCell::new(new_hash_map()),
642640
});

fuzz/src/offer_deser.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use lightning::offers::invoice_request::InvoiceRequest;
1616
use lightning::offers::nonce::Nonce;
1717
use lightning::offers::offer::{Amount, Offer, Quantity};
1818
use lightning::offers::parse::Bolt12SemanticError;
19-
use lightning::sign::{EntropySource, KeyMaterial};
19+
use lightning::sign::EntropySource;
2020
use lightning::util::ser::Writeable;
2121

2222
#[inline]
@@ -43,7 +43,7 @@ impl EntropySource for FixedEntropy {
4343
}
4444

4545
fn build_request(offer: &Offer) -> Result<InvoiceRequest, Bolt12SemanticError> {
46-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
46+
let expanded_key = ExpandedKey::new([42; 32]);
4747
let entropy = FixedEntropy {};
4848
let nonce = Nonce::from_entropy_source(&entropy);
4949
let secp_ctx = Secp256k1::new();

lightning/src/ln/inbound_payment.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use crate::ln::msgs;
2020
use crate::ln::msgs::MAX_VALUE_MSAT;
2121
use crate::types::payment::{PaymentHash, PaymentPreimage, PaymentSecret};
2222
use crate::offers::nonce::Nonce;
23-
use crate::sign::{KeyMaterial, EntropySource};
23+
use crate::sign::EntropySource;
2424
use crate::util::errors::APIError;
2525
use crate::util::logger::Logger;
2626

@@ -64,15 +64,15 @@ impl ExpandedKey {
6464
/// Create a new [`ExpandedKey`] for generating an inbound payment hash and secret.
6565
///
6666
/// It is recommended to cache this value and not regenerate it for each new inbound payment.
67-
pub fn new(key_material: &KeyMaterial) -> ExpandedKey {
67+
pub fn new(key_material: [u8; 32]) -> ExpandedKey {
6868
let (
6969
metadata_key,
7070
ldk_pmt_hash_key,
7171
user_pmt_hash_key,
7272
offers_base_key,
7373
offers_encryption_key,
7474
spontaneous_pmt_key,
75-
) = hkdf_extract_expand_6x(b"LDK Inbound Payment Key Expansion", &key_material.0);
75+
) = hkdf_extract_expand_6x(b"LDK Inbound Payment Key Expansion", &key_material);
7676
Self {
7777
metadata_key,
7878
ldk_pmt_hash_key,

lightning/src/ln/outbound_payment.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -2400,7 +2400,6 @@ mod tests {
24002400
use crate::offers::test_utils::*;
24012401
use crate::routing::gossip::NetworkGraph;
24022402
use crate::routing::router::{InFlightHtlcs, Path, PaymentParameters, Route, RouteHop, RouteParameters};
2403-
use crate::sign::KeyMaterial;
24042403
use crate::sync::{Arc, Mutex, RwLock};
24052404
use crate::util::errors::APIError;
24062405
use crate::util::hash_tables::new_hash_map;
@@ -2745,7 +2744,7 @@ mod tests {
27452744
let router = test_utils::TestRouter::new(network_graph, &logger, &scorer);
27462745
let secp_ctx = Secp256k1::new();
27472746
let keys_manager = test_utils::TestKeysInterface::new(&[0; 32], Network::Testnet);
2748-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2747+
let expanded_key = ExpandedKey::new([42; 32]);
27492748
let nonce = Nonce([0; 16]);
27502749

27512750
let pending_events = Mutex::new(VecDeque::new());
@@ -2802,7 +2801,7 @@ mod tests {
28022801

28032802
let pending_events = Mutex::new(VecDeque::new());
28042803
let outbound_payments = OutboundPayments::new(new_hash_map());
2805-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2804+
let expanded_key = ExpandedKey::new([42; 32]);
28062805
let nonce = Nonce([0; 16]);
28072806
let payment_id = PaymentId([0; 32]);
28082807
let expiration = StaleExpiration::AbsoluteTimeout(Duration::from_secs(100));
@@ -2864,7 +2863,7 @@ mod tests {
28642863

28652864
let pending_events = Mutex::new(VecDeque::new());
28662865
let outbound_payments = OutboundPayments::new(new_hash_map());
2867-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2866+
let expanded_key = ExpandedKey::new([42; 32]);
28682867
let nonce = Nonce([0; 16]);
28692868
let payment_id = PaymentId([0; 32]);
28702869
let expiration = StaleExpiration::AbsoluteTimeout(Duration::from_secs(100));
@@ -2949,7 +2948,7 @@ mod tests {
29492948
}
29502949

29512950
fn dummy_invoice_request() -> InvoiceRequest {
2952-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2951+
let expanded_key = ExpandedKey::new([42; 32]);
29532952
let entropy = FixedEntropy {};
29542953
let nonce = Nonce::from_entropy_source(&entropy);
29552954
let secp_ctx = Secp256k1::new();

lightning/src/offers/invoice.rs

+27-28
Original file line numberDiff line numberDiff line change
@@ -1605,7 +1605,6 @@ mod tests {
16051605

16061606
use crate::blinded_path::BlindedHop;
16071607
use crate::blinded_path::message::BlindedMessagePath;
1608-
use crate::sign::KeyMaterial;
16091608
use crate::types::features::{Bolt12InvoiceFeatures, InvoiceRequestFeatures, OfferFeatures};
16101609
use crate::ln::channelmanager::PaymentId;
16111610
use crate::ln::inbound_payment::ExpandedKey;
@@ -1649,7 +1648,7 @@ mod tests {
16491648

16501649
#[test]
16511650
fn builds_invoice_for_offer_with_defaults() {
1652-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
1651+
let expanded_key = ExpandedKey::new([42; 32]);
16531652
let entropy = FixedEntropy {};
16541653
let nonce = Nonce::from_entropy_source(&entropy);
16551654
let secp_ctx = Secp256k1::new();
@@ -1913,7 +1912,7 @@ mod tests {
19131912
#[cfg(feature = "std")]
19141913
#[test]
19151914
fn builds_invoice_from_offer_with_expiration() {
1916-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
1915+
let expanded_key = ExpandedKey::new([42; 32]);
19171916
let entropy = FixedEntropy {};
19181917
let nonce = Nonce::from_entropy_source(&entropy);
19191918
let secp_ctx = Secp256k1::new();
@@ -1981,7 +1980,7 @@ mod tests {
19811980
#[test]
19821981
fn builds_invoice_from_offer_using_derived_keys() {
19831982
let node_id = recipient_pubkey();
1984-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
1983+
let expanded_key = ExpandedKey::new([42; 32]);
19851984
let entropy = FixedEntropy {};
19861985
let nonce = Nonce::from_entropy_source(&entropy);
19871986
let secp_ctx = Secp256k1::new();
@@ -2014,7 +2013,7 @@ mod tests {
20142013
panic!("error building invoice: {:?}", e);
20152014
}
20162015

2017-
let expanded_key = ExpandedKey::new(&KeyMaterial([41; 32]));
2016+
let expanded_key = ExpandedKey::new([41; 32]);
20182017
assert!(
20192018
invoice_request.verify_using_recipient_data(nonce, &expanded_key, &secp_ctx).is_err()
20202019
);
@@ -2039,7 +2038,7 @@ mod tests {
20392038

20402039
#[test]
20412040
fn builds_invoice_from_refund_using_derived_keys() {
2042-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2041+
let expanded_key = ExpandedKey::new([42; 32]);
20432042
let entropy = FixedEntropy {};
20442043
let secp_ctx = Secp256k1::new();
20452044

@@ -2061,7 +2060,7 @@ mod tests {
20612060
#[test]
20622061
fn builds_invoice_from_refund_with_path() {
20632062
let node_id = payer_pubkey();
2064-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2063+
let expanded_key = ExpandedKey::new([42; 32]);
20652064
let entropy = FixedEntropy {};
20662065
let secp_ctx = Secp256k1::new();
20672066

@@ -2090,7 +2089,7 @@ mod tests {
20902089

20912090
#[test]
20922091
fn builds_invoice_with_relative_expiry() {
2093-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2092+
let expanded_key = ExpandedKey::new([42; 32]);
20942093
let entropy = FixedEntropy {};
20952094
let nonce = Nonce::from_entropy_source(&entropy);
20962095
let secp_ctx = Secp256k1::new();
@@ -2132,7 +2131,7 @@ mod tests {
21322131

21332132
#[test]
21342133
fn builds_invoice_with_amount_from_request() {
2135-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2134+
let expanded_key = ExpandedKey::new([42; 32]);
21362135
let entropy = FixedEntropy {};
21372136
let nonce = Nonce::from_entropy_source(&entropy);
21382137
let secp_ctx = Secp256k1::new();
@@ -2154,7 +2153,7 @@ mod tests {
21542153

21552154
#[test]
21562155
fn builds_invoice_with_quantity_from_request() {
2157-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2156+
let expanded_key = ExpandedKey::new([42; 32]);
21582157
let entropy = FixedEntropy {};
21592158
let nonce = Nonce::from_entropy_source(&entropy);
21602159
let secp_ctx = Secp256k1::new();
@@ -2190,7 +2189,7 @@ mod tests {
21902189

21912190
#[test]
21922191
fn builds_invoice_with_fallback_address() {
2193-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2192+
let expanded_key = ExpandedKey::new([42; 32]);
21942193
let entropy = FixedEntropy {};
21952194
let nonce = Nonce::from_entropy_source(&entropy);
21962195
let secp_ctx = Secp256k1::new();
@@ -2242,7 +2241,7 @@ mod tests {
22422241

22432242
#[test]
22442243
fn builds_invoice_with_allow_mpp() {
2245-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2244+
let expanded_key = ExpandedKey::new([42; 32]);
22462245
let entropy = FixedEntropy {};
22472246
let nonce = Nonce::from_entropy_source(&entropy);
22482247
let secp_ctx = Secp256k1::new();
@@ -2267,7 +2266,7 @@ mod tests {
22672266

22682267
#[test]
22692268
fn fails_signing_invoice() {
2270-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2269+
let expanded_key = ExpandedKey::new([42; 32]);
22712270
let entropy = FixedEntropy {};
22722271
let nonce = Nonce::from_entropy_source(&entropy);
22732272
let secp_ctx = Secp256k1::new();
@@ -2302,7 +2301,7 @@ mod tests {
23022301

23032302
#[test]
23042303
fn parses_invoice_with_payment_paths() {
2305-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2304+
let expanded_key = ExpandedKey::new([42; 32]);
23062305
let entropy = FixedEntropy {};
23072306
let nonce = Nonce::from_entropy_source(&entropy);
23082307
let secp_ctx = Secp256k1::new();
@@ -2362,7 +2361,7 @@ mod tests {
23622361

23632362
#[test]
23642363
fn parses_invoice_with_created_at() {
2365-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2364+
let expanded_key = ExpandedKey::new([42; 32]);
23662365
let entropy = FixedEntropy {};
23672366
let nonce = Nonce::from_entropy_source(&entropy);
23682367
let secp_ctx = Secp256k1::new();
@@ -2397,7 +2396,7 @@ mod tests {
23972396

23982397
#[test]
23992398
fn parses_invoice_with_relative_expiry() {
2400-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2399+
let expanded_key = ExpandedKey::new([42; 32]);
24012400
let entropy = FixedEntropy {};
24022401
let nonce = Nonce::from_entropy_source(&entropy);
24032402
let secp_ctx = Secp256k1::new();
@@ -2424,7 +2423,7 @@ mod tests {
24242423

24252424
#[test]
24262425
fn parses_invoice_with_payment_hash() {
2427-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2426+
let expanded_key = ExpandedKey::new([42; 32]);
24282427
let entropy = FixedEntropy {};
24292428
let nonce = Nonce::from_entropy_source(&entropy);
24302429
let secp_ctx = Secp256k1::new();
@@ -2459,7 +2458,7 @@ mod tests {
24592458

24602459
#[test]
24612460
fn parses_invoice_with_amount() {
2462-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2461+
let expanded_key = ExpandedKey::new([42; 32]);
24632462
let entropy = FixedEntropy {};
24642463
let nonce = Nonce::from_entropy_source(&entropy);
24652464
let secp_ctx = Secp256k1::new();
@@ -2492,7 +2491,7 @@ mod tests {
24922491

24932492
#[test]
24942493
fn parses_invoice_with_allow_mpp() {
2495-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2494+
let expanded_key = ExpandedKey::new([42; 32]);
24962495
let entropy = FixedEntropy {};
24972496
let nonce = Nonce::from_entropy_source(&entropy);
24982497
let secp_ctx = Secp256k1::new();
@@ -2523,7 +2522,7 @@ mod tests {
25232522

25242523
#[test]
25252524
fn parses_invoice_with_fallback_address() {
2526-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2525+
let expanded_key = ExpandedKey::new([42; 32]);
25272526
let entropy = FixedEntropy {};
25282527
let nonce = Nonce::from_entropy_source(&entropy);
25292528
let secp_ctx = Secp256k1::new();
@@ -2587,7 +2586,7 @@ mod tests {
25872586

25882587
#[test]
25892588
fn parses_invoice_with_node_id() {
2590-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2589+
let expanded_key = ExpandedKey::new([42; 32]);
25912590
let entropy = FixedEntropy {};
25922591
let nonce = Nonce::from_entropy_source(&entropy);
25932592
let secp_ctx = Secp256k1::new();
@@ -2633,7 +2632,7 @@ mod tests {
26332632

26342633
#[test]
26352634
fn parses_invoice_with_node_id_from_blinded_path() {
2636-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2635+
let expanded_key = ExpandedKey::new([42; 32]);
26372636
let entropy = FixedEntropy {};
26382637
let nonce = Nonce::from_entropy_source(&entropy);
26392638
let secp_ctx = Secp256k1::new();
@@ -2710,7 +2709,7 @@ mod tests {
27102709

27112710
#[test]
27122711
fn fails_parsing_invoice_without_signature() {
2713-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2712+
let expanded_key = ExpandedKey::new([42; 32]);
27142713
let entropy = FixedEntropy {};
27152714
let nonce = Nonce::from_entropy_source(&entropy);
27162715
let secp_ctx = Secp256k1::new();
@@ -2735,7 +2734,7 @@ mod tests {
27352734

27362735
#[test]
27372736
fn fails_parsing_invoice_with_invalid_signature() {
2738-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2737+
let expanded_key = ExpandedKey::new([42; 32]);
27392738
let entropy = FixedEntropy {};
27402739
let nonce = Nonce::from_entropy_source(&entropy);
27412740
let secp_ctx = Secp256k1::new();
@@ -2765,7 +2764,7 @@ mod tests {
27652764

27662765
#[test]
27672766
fn parses_invoice_with_unknown_tlv_records() {
2768-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2767+
let expanded_key = ExpandedKey::new([42; 32]);
27692768
let entropy = FixedEntropy {};
27702769
let nonce = Nonce::from_entropy_source(&entropy);
27712770
let payment_id = PaymentId([1; 32]);
@@ -2849,7 +2848,7 @@ mod tests {
28492848

28502849
#[test]
28512850
fn parses_invoice_with_experimental_tlv_records() {
2852-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2851+
let expanded_key = ExpandedKey::new([42; 32]);
28532852
let entropy = FixedEntropy {};
28542853
let nonce = Nonce::from_entropy_source(&entropy);
28552854
let payment_id = PaymentId([1; 32]);
@@ -2979,7 +2978,7 @@ mod tests {
29792978

29802979
#[test]
29812980
fn fails_parsing_invoice_with_out_of_range_tlv_records() {
2982-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
2981+
let expanded_key = ExpandedKey::new([42; 32]);
29832982
let entropy = FixedEntropy {};
29842983
let nonce = Nonce::from_entropy_source(&entropy);
29852984
let secp_ctx = Secp256k1::new();
@@ -3008,7 +3007,7 @@ mod tests {
30083007

30093008
#[test]
30103009
fn fails_parsing_invoice_with_message_paths() {
3011-
let expanded_key = ExpandedKey::new(&KeyMaterial([42; 32]));
3010+
let expanded_key = ExpandedKey::new([42; 32]);
30123011
let entropy = FixedEntropy {};
30133012
let nonce = Nonce::from_entropy_source(&entropy);
30143013
let secp_ctx = Secp256k1::new();

0 commit comments

Comments
 (0)