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 channelmanager;
17 pub mod inbound_payment;
26 pub mod peer_channel_encryptor;
28 pub(crate) mod peer_channel_encryptor;
33 pub(crate) mod channel;
35 // Re-export ChannelId
36 pub use channel_id::ChannelId;
38 pub(crate) mod onion_utils;
42 // Older rustc (which we support) refuses to let us call the get_payment_preimage_hash!() macro
43 // without the node parameter being mut. This is incorrect, and thus newer rustcs will complain
44 // about an unnecessary mut. Thus, we silence the unused_mut warning in two test modules below.
48 mod blinded_payment_tests;
57 mod priv_short_conf_tests;
60 mod chanmon_update_fail_tests;
69 mod onion_route_tests;
77 pub use self::peer_channel_encryptor::LN_MAX_MSG_LEN;
79 /// payment_hash type, use to cross-lock hop
81 /// This is not exported to bindings users as we just use [u8; 32] directly
82 #[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
83 pub struct PaymentHash(pub [u8; 32]);
85 impl core::fmt::Display for PaymentHash {
86 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
87 crate::util::logger::DebugBytes(&self.0).fmt(f)
91 /// payment_preimage type, use to route payment between hop
93 /// This is not exported to bindings users as we just use [u8; 32] directly
94 #[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
95 pub struct PaymentPreimage(pub [u8; 32]);
97 impl core::fmt::Display for PaymentPreimage {
98 fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
99 crate::util::logger::DebugBytes(&self.0).fmt(f)
103 /// payment_secret type, use to authenticate sender to the receiver and tie MPP HTLCs together
105 /// This is not exported to bindings users as we just use [u8; 32] directly
106 #[derive(Hash, Copy, Clone, PartialEq, Eq, Debug, Ord, PartialOrd)]
107 pub struct PaymentSecret(pub [u8; 32]);
109 use crate::prelude::*;
111 use bitcoin::bech32::{Base32Len, FromBase32, ToBase32, WriteBase32, u5};
113 impl FromBase32 for PaymentSecret {
114 type Err = bech32::Error;
116 fn from_base32(field_data: &[u5]) -> Result<PaymentSecret, bech32::Error> {
117 if field_data.len() != 52 {
118 return Err(bech32::Error::InvalidLength)
120 let data_bytes = Vec::<u8>::from_base32(field_data)?;
121 let mut payment_secret = [0; 32];
122 payment_secret.copy_from_slice(&data_bytes);
123 Ok(PaymentSecret(payment_secret))
128 impl ToBase32 for PaymentSecret {
129 fn write_base32<W: WriteBase32>(&self, writer: &mut W) -> Result<(), <W as WriteBase32>::Err> {
130 (&self.0[..]).write_base32(writer)
134 impl Base32Len for PaymentSecret {
135 fn base32_len(&self) -> usize {