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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
//! 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`],
//! [`InvitationId`], [`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, and
//! [`NostrSecretKey::sign_request_with_nonce`] adds a random `nonce` tag
//! so identical requests signed in one second are distinct events.
//! [`verify_request_without_body`] checks everything but the body digest,
//! for a proxy that never sees the body, and returns a
//! [`BodyUncheckedRequest`]. [`UnverifiedRequest`] parses a header once so
//! its claimed author can be looked up before a signature is verified.
//! - **Bootstrap claims.** [`ClaimBody`] is the immutable body an
//! administrator signs to claim a node, kept as the exact bytes issued.
//! - **Pod paths.** [`PodPath`] is a request path under the pod allow-list
//! (`/pods/<pk>/…` or `/pods/<pk>.acl`) and its shape rules, with the
//! owner, container and sibling-ACL helpers a client needs;
//! [`is_valid_pod_query`] checks a query string.
//! - **Admission.** [`AdmissionClaim`] is the body a tenant signs to redeem
//! an invitation ([`InvitationId`]) after reading
//! [`ADMISSION_NOTICE_V1`]; [`MemberState`] names the states a membership
//! moves through.
//!
//! 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 ;
pub use ;
pub use ;
/// The version of the signed-request profile [`verify_request`] enforces and
/// [`NostrSecretKey::sign_request`] and
/// [`NostrSecretKey::sign_request_with_nonce`] produce. The `nonce` tag is
/// outside the profile, which ignores tags it does not name.
pub const REQUEST_PROFILE_VERSION: u32 = 1;
/// Compiles and runs the README example as a doctest.
;