1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//! Zero-I/O core types for Stratum pod nodes.
//!
//! **Pre-release:** this is `0.1.0-alpha`. The API and formats may change
//! before 0.1.0.
//!
//! A Stratum node is administered by a Nostr key. This crate holds the parts
//! of that model that need no I/O, so the controller, the command-line client
//! and any other implementation agree byte for byte:
//!
//! - **Principals.** [`DidNostr`] is a `did:nostr` identifier over a BIP-340
//! x-only public key, convertible to and from hex and NIP-19 `npub`.
//! - **Identifiers.** [`EventId`], [`Sha256Digest`], [`ChallengeId`],
//! [`OperationId`], [`Revision`] and [`UnixTime`] each have one canonical
//! text form and validate on construction and deserialisation.
//! - **Events.** [`SignedEvent`] is a NIP-01 event whose ID and signature
//! have been verified; [`UnsignedEvent`] is one waiting to be signed by a
//! [`NostrSecretKey`].
//! - **Signed requests.** [`verify_request`] checks an `Authorization: Nostr`
//! header against the request the server received, under a profile
//! stricter than NIP-98, and returns a [`VerifiedRequest`].
//! [`NostrSecretKey::sign_request`] produces such headers.
//! - **Bootstrap claims.** [`ClaimBody`] is the immutable body an
//! administrator signs to claim a node, kept as the exact bytes issued.
//!
//! The crate never reads a clock, a random source, the environment, the
//! filesystem or the network. The current time, auxiliary signing
//! randomness, challenge bytes and the expected request are all parameters,
//! which keeps every check deterministic and testable.
//!
//! Cryptography comes from maintained crates: BIP-340 Schnorr from `k256`,
//! SHA-256 from `sha2`, bech32 from `bech32`. The signing and verification
//! paths are tested against the published BIP-340 vectors.
//!
//! # Replay protection
//!
//! [`verify_request`] proves who signed a request, for which URL, method and
//! body, and roughly when. It does not make a request single use. A server
//! must record [`VerifiedRequest::event_id`] durably and refuse a repeat.
//!
//! # Example
//!
//! ```
//! use stratum_node_core::{verify_request, ExpectedRequest, NostrSecretKey, RequestPolicy, UnixTime};
//!
//! # fn main() -> Result<(), Box<dyn std::error::Error>> {
//! // Client side: sign a request. Use real randomness for the 32 bytes.
//! let key = NostrSecretKey::from_nsec(
//! "nsec1vl029mgpspedva04g90vltkh6fvh240zqtv9k0t9af8935ke9laqsnlfe5",
//! )?;
//! let body = br#"{"node":"did:nostr:...","operation_id":"op-1"}"#;
//! let request = ExpectedRequest::new("POST", "http://127.0.0.1:7070/api/v1/config/apply", Some(body));
//! let now = UnixTime::from_secs(1_764_720_000);
//! let header = key.sign_request(&request, now, &[0x42; 32])?;
//!
//! // Server side: verify it against what actually arrived.
//! let verified = verify_request(&header, &request, now, &RequestPolicy::new())?;
//! assert_eq!(verified.signer(), key.public());
//! # Ok(())
//! # }
//! ```
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
/// The version of the signed-request profile [`verify_request`] enforces and
/// [`NostrSecretKey::sign_request`] produces.
pub const REQUEST_PROFILE_VERSION: u32 = 1;
/// Compiles and runs the README example as a doctest.
;