lightning_signer/
lib.rs

1#![crate_name = "lightning_signer"]
2
3//! A policy-enforcing signer for Lightning
4//! See [`node::Node`] for the entry point.
5
6#![forbid(unsafe_code)]
7#![allow(bare_trait_objects)]
8#![allow(ellipsis_inclusive_range_patterns)]
9#![warn(rustdoc::broken_intra_doc_links)]
10#![warn(missing_docs)]
11#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]
12
13#[cfg(not(any(feature = "std", feature = "no-std")))]
14compile_error!("at least one of the `std` or `no-std` features must be enabled");
15
16#[macro_use]
17extern crate alloc;
18extern crate core;
19#[cfg(feature = "grpc")]
20extern crate tonic;
21
22pub use bitcoin;
23pub use lightning;
24pub use lightning_invoice;
25pub use txoo;
26
27/// Chain tracking and validation
28pub mod chain;
29/// Various utilities
30#[macro_use]
31pub mod util;
32/// Channel
33#[macro_use]
34pub mod channel;
35/// Channel on-chain monitor
36pub mod monitor;
37/// Node
38#[macro_use]
39pub mod node;
40/// Invoices
41pub mod invoice;
42/// Persistence
43pub mod persist;
44/// Policy enforcement
45pub mod policy;
46/// KeysManager
47pub mod signer;
48/// Transaction parsing and construction
49pub mod tx;
50/// Layer-1 wallet
51pub mod wallet;
52/// Reexport the hex crate
53pub use hex;
54
55#[doc(hidden)]
56pub use alloc::collections::BTreeSet as OrderedSet;
57#[doc(hidden)]
58pub use alloc::rc::Rc;
59
60use bitcoin::secp256k1::PublicKey;
61use lightning::ln::chan_utils::ChannelTransactionParameters;
62
63#[cfg(not(feature = "std"))]
64mod nostd;
65
66#[doc(hidden)]
67/// std / no_std compat
68pub mod prelude {
69    pub use alloc::{boxed::Box, string::String, vec, vec::Vec};
70
71    // TODO clean up naming
72    pub use hashbrown::HashMap as Map;
73    pub use hashbrown::HashSet as UnorderedSet;
74
75    pub use alloc::collections::BTreeMap as OrderedMap;
76    pub use alloc::collections::BTreeSet as OrderedSet;
77
78    pub use alloc::borrow::ToOwned;
79    pub use alloc::string::ToString;
80
81    #[cfg(not(all(test, feature = "shuttle")))]
82    pub use alloc::sync::{Arc, Weak};
83    #[cfg(all(test, feature = "shuttle"))]
84    pub use shuttle::sync::{Arc, Mutex, MutexGuard, Weak};
85    #[cfg(all(feature = "std", not(all(test, feature = "shuttle"))))]
86    pub use std::sync::{Mutex, MutexGuard};
87
88    #[cfg(not(feature = "std"))]
89    pub use crate::nostd::*;
90
91    /// Convenience trait for Send + Sync
92    #[cfg(feature = "std")]
93    pub trait SendSync: Send + Sync {}
94}
95
96#[doc(hidden)]
97pub use prelude::SendSync;
98
99use prelude::*;
100
101/// A trait for getting a commitment point for a given commitment number,
102/// if known.
103pub trait CommitmentPointProvider: SendSync {
104    /// Get the commitment point for a holder commitment transaction
105    fn get_holder_commitment_point(&self, commitment_number: u64) -> PublicKey;
106    /// Get the commitment point for a counterparty commitment transaction, if known.
107    /// It might not be known if we didn't reach that commitment number yet
108    /// or it's a revoked commitment transaction and we don't store revocation secrets.
109    fn get_counterparty_commitment_point(&self, commitment_number: u64) -> Option<PublicKey>;
110    /// Get channel transaction parameters, for decoding on-chain transactions
111    fn get_transaction_parameters(&self) -> ChannelTransactionParameters;
112    /// Clone
113    fn clone_box(&self) -> Box<dyn CommitmentPointProvider>;
114}
115
116impl Clone for Box<dyn CommitmentPointProvider> {
117    fn clone(&self) -> Self {
118        (**self).clone_box()
119    }
120}
121
122#[cfg(not(feature = "std"))]
123#[allow(unused)]
124mod sync;
125
126#[cfg(test)]
127mod setup_channel_tests;
128#[cfg(test)]
129mod sign_counterparty_commitment_tests;
130#[cfg(test)]
131mod sign_counterparty_htlc_sweep_tests;
132#[cfg(test)]
133mod sign_delayed_sweep_tests;
134#[cfg(test)]
135mod sign_holder_commitment_tests;
136#[cfg(test)]
137mod sign_htlc_tx_tests;
138#[cfg(test)]
139mod sign_justice_sweep_tests;
140#[cfg(test)]
141mod sign_mutual_close_tests;
142#[cfg(test)]
143mod sign_onchain_tx_tests;
144#[cfg(test)]
145mod validate_counterparty_revocation_tests;
146#[cfg(test)]
147mod validate_holder_commitment_tests;