stratum-node-core 0.1.0-alpha.4

Zero-I/O core types for Stratum pod nodes: did:nostr principals, typed identifiers, a strict NIP-98 signed-request verifier and bootstrap claim bodies
Documentation
# stratum-node-core

> **Pre-release (`0.1.0-alpha`).** The API and the formats it defines may change
> before 0.1.0. Do not rely on it for production authentication yet.

Zero-I/O core types for [Stratum](https://github.com/DreamLab-AI/stratum) pod
nodes, shared by the node controller and the `stratum` command-line client:

- `DidNostr`: a `did:nostr` principal over a BIP-340 x-only public key, with
  hex and NIP-19 `npub` forms.
- Typed identifiers: `EventId`, `Sha256Digest`, `ChallengeId`,
  `InvitationId`, `OperationId`, `Revision` and `UnixTime`, each with one
  canonical text form.
- `SignedEvent` and `UnsignedEvent`: NIP-01 events with event-ID
  recomputation and BIP-340 verification.
- `verify_request`: a signed-request verifier for `Authorization: Nostr`
  headers that is stricter than NIP-98: exactly one `u` and `method` tag,
  mandatory body binding, byte-exact URL match and a bounded clock window.
- `UnverifiedRequest`, `verify_request_without_body` and
  `BodyUncheckedRequest`: read a header's claimed author before spending a
  signature verification, and verify everything but the body digest for a
  proxy that never sees the body.
- `PodPath` and `is_valid_pod_query`: pod request paths under the Stratum
  gate's allow-list and shape rules, with owner, container and sibling-ACL
  helpers.
- `AdmissionClaim`, `InvitationId`, `ADMISSION_NOTICE_V1` and `MemberState`:
  the body a tenant signs to redeem an invitation, the notice it binds, and
  the states a membership moves through (including `suspended` and
  `removed`), with one predicate each for capacity, provisioning and the
  gate's directory. `DirectoryMemberState` reads a directory entry so that
  an unknown state refuses that one member instead of failing the document.
- `MemberActionRequest`, `RemoveRequest`, `SuspendResponse`,
  `ResumeResponse`, `ArchiveResponse`, `RemoveResponse`, `MemberView`,
  `Enforcement` and `RemovalArchive`: the bodies of the administrator's
  suspend, resume, archive, remove and member-view routes. `ErrorCode`
  defines the codes Steps 3a and 3b add, such as `suspended` (403),
  `archive_required` (409), `lease_revoked` (403) and `lease_expired` (503).
- `ValidManifest`, `Manifest`, `ManifestRule`, `JobCeilings` and
  `JobLimits`: an application manifest, validated member by member against
  the node's ceilings, with each refusal naming its member and rule.
  `render_offered` renders the WAC authorisations (`OfferedGrant`) a member
  consents to, byte for byte as the node stores them, and `Schedule` does a
  scheduled installation's period arithmetic.
- The bodies of the administrator's application routes and the member's
  installation routes, their identifiers (`ApplicationId`,
  `InstallationId`, `JobId`) and states, the `EnforcementParts` of a
  withdrawal or suspension, and `DirectoryAppKey`, the gate directory's
  `app_keys` entry.
- `profile_card_path`, `profile_owner`, `profile_card`, `profile_acl` and
  `card_names_owner`: the one public profile document per pod, the gate's
  byte-exact matcher for its path, the Turtle document and ACL a client
  writes, and a conservative check that an existing card names its owner.
- `NostrSecretKey`: signs events and request headers. It is zeroised on drop
  and redacted in `Debug`.
- `ClaimBody`: the immutable bootstrap claim an administrator signs, kept as
  the exact bytes issued.

The crate never reads a clock, a random source, the environment, the
filesystem or the network: time, randomness and expected values are
parameters. Cryptography comes from `k256` (BIP-340), `sha2` and `bech32`, and
is tested against the published BIP-340 vectors and against headers minted
by an independent NIP-98 implementation.

The verifier does **not** make requests single use. Record
`VerifiedRequest::event_id()` durably and refuse repeats.

## Example

```rust
use stratum_node_core::{verify_request, ExpectedRequest, NostrSecretKey, RequestPolicy, UnixTime};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let key = NostrSecretKey::from_hex(&"01".repeat(32))?;
    let request = ExpectedRequest::new("POST", "http://127.0.0.1:7070/api/v1/config/apply", Some(b"{}"));
    let now = UnixTime::from_secs(1_764_720_000);

    // Use 32 bytes from a secure random source in real code.
    let header = key.sign_request(&request, now, &[0x42; 32])?;

    let verified = verify_request(&header, &request, now, &RequestPolicy::new())?;
    assert_eq!(verified.signer(), key.public());
    Ok(())
}
```

## Minimum supported Rust version

1.89.

## Licence

AGPL-3.0-only. See [LICENSE](LICENSE).