1 // This file is Copyright its original authors, visible in version control
4 // This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5 // or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7 // You may not use this file except in accordance with one or both of these
10 //! Implementations of various parts of the Lightning protocol are in this module.
12 #[cfg(any(test, feature = "_test_utils"))]
14 pub mod functional_test_utils;
16 pub mod onion_payment;
17 pub mod channelmanager;
19 pub mod inbound_payment;
28 pub mod peer_channel_encryptor;
30 pub(crate) mod peer_channel_encryptor;
35 pub(crate) mod channel;
37 // Re-export ChannelId
38 pub use channel_id::ChannelId;
40 pub(crate) mod onion_utils;
44 pub use onion_utils::create_payment_onion;
45 // Older rustc (which we support) refuses to let us call the get_payment_preimage_hash!() macro
46 // without the node parameter being mut. This is incorrect, and thus newer rustcs will complain
47 // about an unnecessary mut. Thus, we silence the unused_mut warning in two test modules below.
51 mod blinded_payment_tests;
60 mod priv_short_conf_tests;
63 mod chanmon_update_fail_tests;
72 mod onion_route_tests;
79 #[cfg(all(test, async_signing))]
81 mod async_signer_tests;
86 pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;
88 /// payment_hash type, use to cross-lock hop
90 /// This is not exported to bindings users as we just use [u8; 32] directly
91 #[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
92 pub struct PaymentHash(pub [u8; 32]);
94 impl core::fmt::Display for PaymentHash {
95 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
96 crate::util::logger::DebugBytes(&self.0).fmt(f)
100 /// payment_preimage type, use to route payment between hop
102 /// This is not exported to bindings users as we just use [u8; 32] directly
103 #[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
104 pub struct PaymentPreimage(pub [u8; 32]);
106 impl core::fmt::Display for PaymentPreimage {
107 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
108 crate::util::logger::DebugBytes(&self.0).fmt(f)
112 /// payment_secret type, use to authenticate sender to the receiver and tie MPP HTLCs together
114 /// This is not exported to bindings users as we just use [u8; 32] directly
115 #[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
116 pub struct PaymentSecret(pub [u8; 32]);
118 use crate::prelude::*;
120 use bitcoin::bech32::{Base32Len, FromBase32, ToBase32, WriteBase32, u5};
122 impl FromBase32 for PaymentSecret {
123 type Err = bech32::Error;
125 fn from_base32(field_data: &[u5]) -> Result<PaymentSecret, bech32::Error> {
126 if field_data.len() != 52 {
127 return Err(bech32::Error::InvalidLength)
129 let data_bytes = Vec::<u8>::from_base32(field_data)?;
130 let mut payment_secret = [0; 32];
131 payment_secret.copy_from_slice(&data_bytes);
132 Ok(PaymentSecret(payment_secret))
137 impl ToBase32 for PaymentSecret {
138 fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
139 (&self.0[..]).write_base32(writer)
143 impl Base32Len for PaymentSecret {
144 fn base32_len(&self) -> usize {