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, with one predicate each for capacity, provisioning and the gate’s directory.DirectoryMemberStateis the gate’s tolerant reading of a directory entry, which keeps an unknown state as a refused member instead of failing the whole document. - Member administration.
MemberActionRequest,RemoveRequest,SuspendResponse,ResumeResponse,ArchiveResponse,RemoveResponseandMemberVieware the bodies of the administrator’s suspend, resume, archive, remove and member-view routes;Enforcementreports whether the gate applies a suspension, andRemovalArchiveis an archive reference or a waiver.ErrorCodedefines the codes Steps 3a and 3b add, fromsuspendedtolease_expired. - Applications and installations (Step 3b).
ValidManifestvalidates an applicationManifestagainst the node’sJobCeilings, naming the member andManifestRuleof a refusal;ImageId,ContainerPath,MilliCpusandJobLimitsare its parts.render_offeredrenders theOfferedGrant, the WAC authorisations a member consents to, byte for byte as the controller stores them.Scheduledoes the period arithmetic. The tenant and administrator route bodies, the identifiers (ApplicationId,InstallationId,JobId), the states and theEnforcementPartsof a withdrawal or suspension are in the same group, andDirectoryAppKeyis the gate directory’sapp_keysentry. - Profile document.
profile_card_pathandprofile_ownergive the one public path per pod and the gate’s byte-exact matcher for it;profile_cardandprofile_aclare the document and ACL a client writes, andcard_names_ownerisprofile init’s conservative check of an existing card.
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. - Application
Action Request - The body of
POST /api/v1/applications/{id}/withdraw,…/approveand…/disable. - Application
Id - The identifier of an approved application.
- Application
List - The answer to
GET /api/v1/applications. - Application
State Response - The answer to an application transition.
- Application
View - One application in
GET /api/v1/applications. - Approve
Application Request - The body of
POST /api/v1/applications: the manifest to approve. - Approve
Application Response - The answer to
POST /api/v1/applications. - Archive
Response - The answer to
POST /api/v1/members/{pk}/archive. - Body
Unchecked Request - A signed request checked in every respect except its body.
- Catalogue
- The answer to
GET /api/v1/catalogue: theapprovedapplications. - Catalogue
Entry - One application in the member’s catalogue.
- 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. - Cleanup
Request - The body of
POST /api/v1/installations/{id}/cleanup. - Cleanup
Response - The answer to
POST /api/v1/installations/{id}/cleanup. - Consent
Request - The body of
POST /api/v1/installations/{id}/consent. - Consent
Response - The answer to
POST /api/v1/installations/{id}/consent. - Container
Grant - One granted container: its path, the modes and the operations.
- Container
Path - A manifest container path: relative to the owner’s pod root, naming a container.
- Create
Installation Request - The body of
POST /api/v1/installations. - Create
Installation Response - The answer to
POST /api/v1/installations. - DidNostr
- A
did:nostrprincipal over a 32-byte x-only secp256k1 public key. - Directory
AppKey - One listed application key: an enabled key and its active owner.
- Ended
Periods - The scheduler’s work at one tick: one period to run, the others skipped.
- Enforcement
Parts - The parts of one enforcement (a suspension, a withdrawal or an application disable): the authorisation at the gate and the proxy, the keys at the signer and the work at the runner. None of it is stored; it is recomputed for each answer.
- Error
Code - An error code and the HTTP status it is sent with.
- 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.
- ImageId
- A container image identifier:
sha256:and 64 lower-case hex digits. - Installation
Action Request - The body of
POST /api/v1/installations/{id}/withdrawand…/resume. - Installation
Id - The identifier of an installation: one member’s use of one application, with its own key. It is a single lower-case segment, so it fits the tenant route grammar and the report’s resource name.
- Installation
List - The answer to
GET /api/v1/installations. - Installation
View - One installation as the member (
GET /api/v1/installations,…/{id}) and the administrator (GET /api/v1/installations) see it. It never carries a result body. - Invitation
Id - The identifier of an invitation, written as 32 lowercase hex digits.
- JobCeilings
- The node’s ceilings on job limits, from configuration
(
limits.job_max_*). Approval refuses a manifest above them, and so does launch, in case a ceiling was lowered since. - JobCounts
- An installation’s jobs counted by state.
- JobId
- The identifier of a job: one installation’s work for one period.
- JobLimits
- The limits a job actually runs under: the manifest’s, with defaults applied.
- JobList
- The answer to
GET /api/v1/installations/{id}/jobs. - JobView
- One job in
GET /api/v1/installations/{id}/jobs. - Manifest
- An application manifest, in the shape an administrator approves.
- Manifest
Error - A manifest refusal: the rule and the member it concerns.
- Manifest
Limits - The limits a manifest names; an absent limit takes its default.
- Member
Action Request - The body of
POST /api/v1/members/{pk}/suspend,…/resumeand…/archive: the node it is addressed to and the operation ID. - Member
View - The answer to
GET /api/v1/members/{pk}: one member as it is now. - Milli
Cpus - A CPU limit in thousandths of a CPU.
- Nostr
Secret Key - A secp256k1 secret key used to sign Nostr events with BIP-340.
- Offered
Container - The authorisation offered for one container.
- Offered
Grant - The whole offered grant: the combined text and hash, and each container’s.
- Operation
Id - A caller-chosen identifier for a mutating operation.
- Parse
Image IdError - The text is not
sha256:followed by 64 lower-case hex digits. - Parse
Name Error - The text is not one of the type’s names. The match is exact and case-sensitive.
- Parse
Removal Archive Error - The text is neither
"waived"nor an event ID in lowercase hex. - PodPath
- A validated pod request path.
- Remove
Request - The body of
POST /api/v1/members/{pk}/remove. - Remove
Response - The answer to
POST /api/v1/members/{pk}/remove. - Request
Policy - Limits applied by
verify_request. - Request
Target - The method and URL a signed header is bound to, without a body.
- Resume
Installation Response - The answer to
POST /api/v1/installations/{id}/resume: the key’s state after therestorereason is removed. - Resume
Response - The answer to
POST /api/v1/members/{pk}/resume: the state the member returned to,provisionedoractive. - Revision
- A configuration revision number.
- RunRequest
- The body of
POST /api/v1/installations/{id}/run. - RunResponse
- The answer to
POST /api/v1/installations/{id}/run: the period’s job, new or existing. - Schedule
- An installation’s schedule.
- Schedule
Error schedule_secsis neither 0 nor between 300 and 604 800.- 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.
- Suspend
Response - The answer to
POST /api/v1/members/{pk}/suspend. - 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. - Valid
Manifest - A manifest that passed validation, with its effective limits.
- Verified
Request - The outcome of a successful
verify_request. - Withdraw
Response - The answer to
POST /api/v1/installations/{id}/withdraw. - Workspace
Grant - A workspace given at consent: the slot and its usable size (Step 3b-3;
always
nullin 3b-2). - Workspace
View - A member’s workspace slot as the administrator sees it: its state and
usable size, never its contents. Always
nullin Step 3b-2.
Enums§
- AclMode
- A WAC access mode a manifest may grant:
"Read"or"Write". - Application
State - An application’s state.
disabledis terminal. - 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. - Container
Path Error - The rule of the manifest path rule that a path breaks.
- Directory
Member State - A member state as the gate reads it from the member directory: a known
MemberStateor a state this build does not know. - Enforcement
- Whether the gate is known to enforce one suspension.
- Grant
State - The node’s record of a grant, per installation and container: what the member’s client has told it, signed, at a point in time. It is not an observation of the pod’s ACLs.
- Installation
State - An installation’s state.
withdrawnandremovedare terminal. - JobOutcome
- What a job’s last attempt came to: the five results a job reports;
limits_not_appliedwhen the runner could not verify the container’s limits and killed it; andlimit_above_ceilingwhen the job was never launched because its application’s manifest asks for a limit above a ceiling lowered since the approval. - JobState
- A job’s state.
- KeyReason
- A reason an application key is disabled. A key is enabled when it has none and is not destroyed.
- KeyStatus
- The state of an installation’s key as the node wants it:
enabledwhen it has no disable reason, elsedisabled, ordestroyed. - Keys
Part - Whether the signer is known to refuse the keys an enforcement covers.
- Lease
State - A lease’s state. Only
claimedandstartedare current. - Manifest
Profile - The job profile a manifest asks for. Only
"job"exists. - Manifest
Rule - The validation rule a manifest broke.
- 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. - PodMethod
- A pod operation a manifest may allow:
GET,HEAD,PUTorDELETE. - Removal
Archive - 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.
- 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. - Work
Part - Whether the work an enforcement covers is known to have stopped.
- Workspace
Mode - The most workspace an application may be given, or an installation
asks for:
"none","read"or"write". - Workspace
Slot State - A workspace slot’s state (Step 3b-3; 3b-2 never reports a slot).
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).
- MAX_
CONTAINERS - The most containers one manifest may grant.
- MAX_
LABEL_ CHARS - The longest
nameorversion, in characters. - MAX_
SCHEDULE_ SECS - The longest interval, in seconds: one week.
- MEMORY_
STEP_ BYTES memory_bytesmust be a multiple of this many bytes (one page). The kernel rounds a memory limit down to a whole page, so any other value could never be verified as applied.- MIN_
MEMORY_ BYTES - The smallest
memory_bytesa manifest may ask for: 6 MiB, the least the container engine accepts. - MIN_
SCHEDULE_ SECS - The shortest interval a scheduled installation may have, in seconds.
- MIN_
TIMEOUT_ SECS - The shortest timeout a manifest may ask for, in seconds. It gives an attempt at least 180 s of retry window before the 60 s cut-off.
- OPERATION_
ID_ MAX_ LEN - The longest
OperationIdaccepted, 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_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. - card_
names_ owner - Returns
truewhen an existing profile card namesowner, forprofile init’s decision to leave it alone. - check_
schedule_ secs - Checks a
schedule_secsvalue: 0, or300..=604800. - is_
acl_ path - Returns
truewhenpathnames an access-control resource. - is_
valid_ pod_ query - Returns
truewhenqueryis 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
Nonewhen the target is anything but exactly/pods/<64 lower-case hex>/profile/card. - render_
container - Renders one container’s offered authorisation.
- render_
offered - Renders the offered grant for an application key
appinowner’s pod, one authorisation per container in manifest order. - 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.