Expand description
basil-nats: build NATS JWTs (the ed25519-nkey JWS profile) without
holding the signing key.
NATS credentials (nsc-style) are JWTs signed by an Ed25519 NKey. This crate
produces the exact wire bytes a NATS server expects, but splits signing out:
you build the signing input, hand it to whatever holds the key (an HSM, a
nkeys::KeyPair, or a Vault transit engine) to produce a raw 64-byte
Ed25519 signature, then assemble the final token. The key never has to
enter this process, which is the whole point of using it from a broker.
Wire format (matches nats-io/jwt v2 / nsc):
- header:
{"typ":"JWT","alg":"ed25519-nkey"} jti: base32 (no pad) of SHA-512/256 over the standard claims only (aud,exp,jti="",iat,iss,name,nbf,sub). Thenatsobject is excluded.- header & claims:
base64urlno-pad; signing input isheader.claims. - signature: raw 64-byte Ed25519,
base64urlno-pad, appended as the 3rd part.
Claim field order does not affect validity (servers parse JSON), but the
jti hash is order-sensitive, so the hash struct mirrors nats-io/jwt.
Structs§
- Account
Claims - Account-specific fields inside a NATS account JWT (the
natsclaim block fortype=account). All fields are optional; empty ones are omitted from the serialized claims. - Account
Export - An account-level export of a stream or service that other accounts may import.
- Account
Import - An account-level import of another account’s stream or service.
- Account
Jwt - A NATS account JWT to be signed by its issuing operator key.
- Account
Limits - Account-wide limits (a
-1value means unlimited). - Decoded
Nats Jwt - A decoded compact NATS JWT.
- External
Authorization - External (delegated) authorization config for an account: auth is performed
by an external service rather than by per-user
NKeys. - JetStream
Limits JetStreamresource limits for an account or a named tier (a-1value means unlimited).- Matched
Nats Signer - The signer that matched a token’s embedded
iss. - MsgTrace
- Message-trace configuration: where traced messages are reported and how often they are sampled.
- Nats
JwtClaims - Standard claims extracted from a decoded NATS JWT.
- Nats
JwtValidation - Result of validating a NATS JWT against a candidate signer set.
- Nats
Limits - Per-connection NATS limits (a
-1value means unlimited). - Operator
Claims - Operator-specific fields inside a NATS operator JWT (the
natsclaim block fortype=operator). All fields are optional; empty ones are omitted. - Operator
Jwt - A NATS operator JWT to be signed by its operator key (usually
self-signed:
iss == sub). Samesigning_input/assemblesplit as the others. - Operator
Limits - The full operator-limits block on an account JWT: the
nats,account, andjetstreamlimit groups (flattened into one JSON object) plus per-tierJetStreamlimits. - Permission
- A subject allow/deny list for one direction (publish or subscribe). An empty
allowmeans “no allow restriction”;denyalways subtracts. - Permissions
- A pub/sub permission pair as the account
default_permissionsblock carries it ({"pub":{…},"sub":{…}}). - Response
Permission - Bounds on the implicit reply-subject permissions a request grants its responder.
- RoleJwt
- A minimal NATS JWT for a role whose current broker RPC carries only issuer,
subject, name, and expiry (
server,curve, account-signer). Thenatsclaim block is just{type, version}. - Service
Latency - Latency-sampling configuration for an exported service.
- UserJwt
- A NATS user JWT to be signed by its issuing account key.
- User
Permissions - Publish / subscribe permission lists for a user (empty = unrestricted within the account).
- Weighted
Mapping - One weighted target in a subject mapping (for traffic splitting / canaries).
Enums§
- Candidate
Signer - A caller-supplied signer candidate for NATS JWT validation.
- Cluster
Traffic - Which account a cluster’s system traffic is attributed to.
- Error
- Export
Type - Whether an import/export is a one-way
streamor a request/replyservice. - Nats
JwtValidation Reason - Authoritative validation result for a decoded NATS JWT.
- Nkey
Type - The role of a public NATS
NKey, identified by its single base32 prefix letter (the first character of an encoded key string). - Response
Type - Reply cardinality of a service export.
- Role
Kind - The
nats.typeclaim of a minimal role JWT minted viaRoleJwt. These are the roles the broker mints through the generic role path; account, user, and operator have their own dedicated builders. - Sampling
Rate - How often an exported service samples latency.
Functions§
- assemble
- Append a raw 64-byte Ed25519
signatureto asigning_input, producing the final compact JWT. - decode_
nats_ jwt - Decode a compact NATS JWT and expose its claims plus literal signing input.
- decode_
public - Decode any public
NKeystring back to itsNkeyTyperole and raw 32-byte Ed25519 key, verifying the CRC. - encode_
public - Encode a raw 32-byte public key as the public
NKeyforrole. - format_
user_ creds - Render a
nsc-styleNATSuser.credsdocument from a compact user JWT and userNKeyseed. - jti_
for_ standard_ claims - Compute the NATS JWT
jti: base32-nopad SHA-512/256 over the standard claims withjtiitself omitted. - open_
nats_ curve - Decrypt a NATS xkey authenticated box.
- require_
public_ prefix - Decode a public
NKeyand require a specificNkeyTyperole. - seal_
nats_ curve - Encrypt a small payload using the NATS xkey authenticated box format.
- signing_
input_ from_ claims - Build the NATS JWS signing input from a fully validated claim document.
- verify_
public_ signature - Verify a raw Ed25519 signature against a public
NKey. - xkey_
public_ from_ private - Derive a public xkey from raw 32-byte X25519 private material.