lightning_signer/signer/
mod.rs

1/// An implementation of KeysInterface
2pub mod my_keys_manager;
3/// A multi-node signer
4#[macro_use]
5pub mod multi_signer;
6/// Derivation styles
7pub mod derive;
8
9#[cfg(feature = "std")]
10use alloc::sync::Arc;
11
12use crate::prelude::SendSync;
13
14/// A factory for entropy generation (often using the precise real time)
15pub trait StartingTimeFactory: SendSync {
16    /// Generate unique entropy
17    //
18    // LDK: KeysManager: starting_time isn't strictly required to actually be a time, but it must
19    // absolutely, without a doubt, be unique to this instance
20    fn starting_time(&self) -> (u64, u32);
21}
22
23/// A starting time factory which uses a hi-res tstamp for entropy
24#[cfg(feature = "std")]
25pub struct ClockStartingTimeFactory {}
26
27#[cfg(feature = "std")]
28impl SendSync for ClockStartingTimeFactory {}
29
30#[cfg(feature = "std")]
31impl StartingTimeFactory for ClockStartingTimeFactory {
32    // LDK: KeysManager: starting_time isn't strictly required to actually be a time, but it must
33    // absolutely, without a doubt, be unique to this instance
34    fn starting_time(&self) -> (u64, u32) {
35        use std::time::SystemTime;
36        let now =
37            SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).expect("is this the future?");
38        (now.as_secs(), now.subsec_nanos())
39    }
40}
41
42#[cfg(feature = "std")]
43impl ClockStartingTimeFactory {
44    /// Create a ClockStartingTimeFactory
45    pub fn new() -> Arc<dyn StartingTimeFactory> {
46        Arc::new(ClockStartingTimeFactory {})
47    }
48}