Expand description
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.
DidNostris adid:nostridentifier over a BIP-340 x-only public key, convertible to and from hex and NIP-19npub. - Identifiers.
EventId,Sha256Digest,ChallengeId,InvitationId,OperationId,RevisionandUnixTimeeach have one canonical text form and validate on construction and deserialisation. - Events.
SignedEventis a NIP-01 event whose ID and signature have been verified;UnsignedEventis one waiting to be signed by aNostrSecretKey. - Signed requests.
verify_requestchecks anAuthorization: Nostrheader against the request the server received, under a profile stricter than NIP-98, and returns aVerifiedRequest.NostrSecretKey::sign_requestproduces such headers, andNostrSecretKey::sign_request_with_nonceadds a randomnoncetag so identical requests signed in one second are distinct events.verify_request_without_bodychecks everything but the body digest, for a proxy that never sees the body, and returns aBodyUncheckedRequest.UnverifiedRequestparses a header once so its claimed author can be looked up before a signature is verified. - Bootstrap claims.
ClaimBodyis the immutable body an administrator signs to claim a node, kept as the exact bytes issued. - Pod paths.
PodPathis 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_querychecks a query string. - Admission.
AdmissionClaimis the body a tenant signs to redeem an invitation (InvitationId) after readingADMISSION_NOTICE_V1;MemberStatenames 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};
// 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());Structs§
- Admission
Claim - The body of a redemption request, together with its exact JSON bytes.
- Admission
Fields - The fields of an admission claim, for
AdmissionClaim::new. - Body
Unchecked Request - A signed request checked in every respect except its body.
- Challenge
Id - The identifier of a single-use challenge, written as 32 lowercase hex digits.
- Claim
Body - An immutable bootstrap claim body together with its exact JSON bytes.
- Claim
Fields - The fields of a version-1 claim body, for
ClaimBody::new. - DidNostr
- A
did:nostrprincipal over a 32-byte x-only secp256k1 public key. - EventId
- A Nostr event identifier: the SHA-256 of the NIP-01 serialisation.
- Expected
Request - The request a signed header is bound to: method, URL and optional body.
- Invitation
Id - The identifier of an invitation, written as 32 lowercase hex digits.
- Nostr
Secret Key - A secp256k1 secret key used to sign Nostr events with BIP-340.
- Operation
Id - A caller-chosen identifier for a mutating operation.
- PodPath
- A validated pod request path.
- Request
Policy - Limits applied by
verify_request. - Request
Target - The method and URL a signed header is bound to, without a body.
- Revision
- A configuration revision number.
- Sha256
Digest - A SHA-256 digest, written as 64 lowercase hexadecimal digits.
- Signed
Event - A Nostr event whose event ID and BIP-340 signature have been verified.
- Unix
Time - A point in time as whole seconds since the Unix epoch.
- Unsigned
Event - An event that has not been signed yet: kind, tags, content and creation time.
- Unverified
Request - An
Authorization: Nostrheader that has been decoded and parsed but not verified. - Verified
Request - The outcome of a successful
verify_request.
Enums§
- Check
Admission Error - The reasons a parsed admission claim can fail
AdmissionClaim::check. - Check
Claim Error - The reasons a parsed claim can fail
ClaimBody::check. - Member
State - The state of a tenant’s membership of a node.
- Parse
Admission Error - The reasons admission-claim bytes can fail to parse.
- Parse
Claim Error - The reasons claim-body bytes can fail to parse.
- Parse
DidError - The reasons a
did:nostrprincipal can fail to parse. - Parse
Event Error - The reasons event JSON can fail to parse or verify.
- Parse
IdError - The reasons an identifier can fail to parse.
- Parse
KeyError - The reasons a secret key can fail to parse.
- Parse
Member State Error - The reasons a
MemberStatecan fail to parse. - Parse
PodPath Error - The reasons a path can fail to be a
PodPath. - Request
Policy Error - The reasons a
RequestPolicysetting can be refused. - Sign
Error - The reasons signing can fail.
- Verify
Request Error - The reasons
verify_requestcan refuse a request, one per check.
Constants§
- ADMISSION_
CLAIM_ PURPOSE - The value of an admission claim’s
purposemember. - ADMISSION_
NOTICE_ V1 - The admission notice, version 1: what a tenant is told before joining.
- CLAIM_
BODY_ VERSION - The claim-body format version this crate reads and writes.
- HTTP_
AUTH_ KIND - The Nostr event kind for HTTP authorisation (NIP-98).
- OPERATION_
ID_ MAX_ LEN - The longest
OperationIdaccepted, in characters. - REQUEST_
PROFILE_ VERSION - The version of the signed-request profile
verify_requestenforces andNostrSecretKey::sign_requestandNostrSecretKey::sign_request_with_nonceproduce. Thenoncetag is outside the profile, which ignores tags it does not name.
Functions§
- admission_
notice_ v1_ sha256 - Returns the SHA-256 of
ADMISSION_NOTICE_V1: the value an admission claim’snotice_sha256must carry for this notice. - is_
valid_ pod_ query - Returns
truewhenqueryis acceptable as the query string of a pod request. - verify_
request - Verifies an
Authorizationheader against the signed-request profile. - verify_
request_ without_ body - Verifies an
Authorizationheader in every respect except the body digest, for a caller that never sees the body.