Skip to main content

Crate stratum_node_core

Crate stratum_node_core 

Source
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:

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§

AdmissionClaim
The body of a redemption request, together with its exact JSON bytes.
AdmissionFields
The fields of an admission claim, for AdmissionClaim::new.
ArchiveResponse
The answer to POST /api/v1/members/{pk}/archive.
BodyUncheckedRequest
A signed request checked in every respect except its body.
ChallengeId
The identifier of a single-use challenge, written as 32 lowercase hex digits.
ClaimBody
An immutable bootstrap claim body together with its exact JSON bytes.
ClaimFields
The fields of a version-1 claim body, for ClaimBody::new.
DidNostr
A did:nostr principal over a 32-byte x-only secp256k1 public key.
ErrorCode
An error code and the HTTP status it is sent with.
EventId
A Nostr event identifier: the SHA-256 of the NIP-01 serialisation.
ExpectedRequest
The request a signed header is bound to: method, URL and optional body.
InvitationId
The identifier of an invitation, written as 32 lowercase hex digits.
MemberActionRequest
The body of POST /api/v1/members/{pk}/suspend, …/resume and …/archive: the node it is addressed to and the operation ID.
MemberView
The answer to GET /api/v1/members/{pk}: one member as it is now.
NostrSecretKey
A secp256k1 secret key used to sign Nostr events with BIP-340.
OperationId
A caller-chosen identifier for a mutating operation.
ParseRemovalArchiveError
The text is neither "waived" nor an event ID in lowercase hex.
PodPath
A validated pod request path.
RemoveRequest
The body of POST /api/v1/members/{pk}/remove.
RemoveResponse
The answer to POST /api/v1/members/{pk}/remove.
RequestPolicy
Limits applied by verify_request.
RequestTarget
The method and URL a signed header is bound to, without a body.
ResumeResponse
The answer to POST /api/v1/members/{pk}/resume: the state the member returned to, provisioned or active.
Revision
A configuration revision number.
Sha256Digest
A SHA-256 digest, written as 64 lowercase hexadecimal digits.
SignedEvent
A Nostr event whose event ID and BIP-340 signature have been verified.
SuspendResponse
The answer to POST /api/v1/members/{pk}/suspend.
UnixTime
A point in time as whole seconds since the Unix epoch.
UnsignedEvent
An event that has not been signed yet: kind, tags, content and creation time.
UnverifiedRequest
An Authorization: Nostr header that has been decoded and parsed but not verified.
VerifiedRequest
The outcome of a successful verify_request.

Enums§

CheckAdmissionError
The reasons a parsed admission claim can fail AdmissionClaim::check.
CheckClaimError
The reasons a parsed claim can fail ClaimBody::check.
DirectoryMemberState
A member state as the gate reads it from the member directory: a known MemberState or a state this build does not know.
Enforcement
Whether the gate is known to enforce one suspension.
MemberState
The state of a tenant’s membership of a node.
ParseAdmissionError
The reasons admission-claim bytes can fail to parse.
ParseClaimError
The reasons claim-body bytes can fail to parse.
ParseDidError
The reasons a did:nostr principal can fail to parse.
ParseEventError
The reasons event JSON can fail to parse or verify.
ParseIdError
The reasons an identifier can fail to parse.
ParseKeyError
The reasons a secret key can fail to parse.
ParseMemberStateError
The reasons a MemberState can fail to parse.
ParsePodPathError
The reasons a path can fail to be a PodPath.
RemovalArchive
What a removal recorded about the archive: the reference of the archive taken in the removed member’s last suspension, or the administrator’s waiver.
RequestPolicyError
The reasons a RequestPolicy setting can be refused.
SignError
The reasons signing can fail.
VerifyRequestError
The reasons verify_request can refuse a request, one per check.

Constants§

ADMISSION_CLAIM_PURPOSE
The value of an admission claim’s purpose member.
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 OperationId accepted, in characters.
PROFILE_CARD_RELATIVE
The profile document’s path inside a pod, relative to the pod root: profile/card.
PROFILE_CONTENT_TYPE
The content type the profile document is written and served with.
PROFILE_MAX_BYTES
The largest profile document the gate serves unsigned: 64 KiB. A larger one is answered 404.
REQUEST_PROFILE_VERSION
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.

Functions§

admission_notice_v1_sha256
Returns the SHA-256 of ADMISSION_NOTICE_V1: the value an admission claim’s notice_sha256 must carry for this notice.
card_names_owner
Returns true when an existing profile card names owner, for profile init’s decision to leave it alone.
is_acl_path
Returns true when path names an access-control resource.
is_valid_pod_query
Returns true when query is acceptable as the query string of a pod request.
profile_acl
Returns the ACL for the profile document of owner, exactly as the client writes it beside the card.
profile_card
Returns the profile document for owner, exactly as the client writes it.
profile_card_path
Returns the profile document’s path for owner: /pods/<pk>/profile/card.
profile_owner
Returns the owner of the profile document named by a request target, or None when the target is anything but exactly /pods/<64 lower-case hex>/profile/card.
verify_request
Verifies an Authorization header against the signed-request profile.
verify_request_without_body
Verifies an Authorization header in every respect except the body digest, for a caller that never sees the body.