# 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.
- `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).