lexe/lib.rs
1// Use README.md as module docs
2#![doc = include_str!("../README.md")]
3//
4// NOTE: Docs for all stable APIs (i.e. all public items accessible via this
5// crate) must be written for consumption by external users.
6//
7// Preview the public API rustdoc: `$ just www-build-rustdoc --open`
8//
9// - Internal-facing documentation can still be written for public items, but
10// should be placed in `//` comments, not `///` comments, to avoid being
11// rendered in the public API docs at <rust.lexe.tech>.
12// - `///` comments are still preferred for private, crate-private, and unstable
13// items.
14#![deny(missing_docs)]
15
16// --- Public API --- //
17//
18// All APIs accessible via these public modules must respect semver guarantees.
19
20/// Configuration options for a `LexeWallet`.
21pub mod config;
22/// Types used by the Lexe SDK.
23pub mod types;
24/// `LexeWallet`: the top-level handle to a Lexe wallet.
25pub mod wallet;
26
27/// Returns the default Lexe data directory (`~/.lexe`).
28pub use lexe_common::default_lexe_data_dir;
29
30/// `BlockingLexeWallet`: synchronous wrapper around `LexeWallet`.
31///
32/// Enabled by the `blocking` feature flag.
33#[cfg(feature = "blocking")]
34pub mod blocking_wallet;
35
36/// General-purpose utilities and re-exports.
37pub mod util {
38 pub use lexe_byte_array::ByteArray;
39 pub use lexe_hex::hex;
40
41 /// ed25519 keys and signatures.
42 //
43 // We *could* replace this with the actual ed25519 module later if desired.
44 pub mod ed25519 {
45 pub use lexe_crypto::ed25519::PublicKey;
46 }
47}
48
49// Reexport crates and items reachable through the stable public API surface.
50pub use anyhow;
51pub use bip39;
52pub use bitcoin;
53pub use lightning;
54pub use semver;
55
56/// Initialize the Lexe logger with the given default log level.
57///
58/// Example: `lexe::init_logger("info")`
59pub fn init_logger(default_level: &str) {
60 lexe_logger::init_with_default(default_level);
61}
62
63// Reexport additional dependencies that may be useful to SDK consumers.
64pub use serde_json;
65pub use tracing;
66
67// --- Unstable APIs --- //
68
69/// This module ensures all unstable APIs are accessible within the crate, but
70/// not to external users of the crate, unless they enable the `unstable`
71/// feature, in which case they can access it via the re-export below.
72mod unstable {
73 /// A flat file system abstraction.
74 pub mod ffs;
75 /// Local payments database synced from the user node.
76 pub mod payments_db;
77 /// Provision-related utilities.
78 pub mod provision;
79 /// Wallet database.
80 pub mod wallet_db;
81
82 /// Builds the `<crate>/<version>` token for the calling crate.
83 pub use lexe_api::user_agent_to_lexe;
84
85 /// The user agent string used for SDK requests to Lexe infrastructure.
86 ///
87 /// Format: `lexe/<sdk_version> node/<latest_node_version>`
88 ///
89 /// Example: `lexe/0.1.0 node/0.8.11`
90 pub static SDK_USER_AGENT: std::sync::LazyLock<&'static str> =
91 std::sync::LazyLock::new(|| {
92 let (latest_node_version, _) =
93 provision::latest_trusted_node_release();
94 let sdk_with_version = user_agent_to_lexe!();
95 let user_agent =
96 format!("{sdk_with_version} node/{latest_node_version}");
97
98 Box::leak(user_agent.into_boxed_str())
99 });
100}
101
102/// Opt-in to unstable APIs.
103#[cfg(feature = "unstable")]
104pub use unstable::*;