keys
Import
Section titled “Import”import * as api from "@fungi.computer/ear-tag/keys";Exports
Section titled “Exports”| Kind | Export | Description |
|---|---|---|
| type alias | KeyRefusalCode | Stable, closed reasons a key-store operation refuses to proceed. |
| type alias | KeySummary | Owner-facing key metadata; neither the human owner id nor digest is exposed. |
| type alias | KeyWire | Shared request decoders and secret-free key metadata for host transports. |
| type alias | KeySqlValue | One bound SQL value a key store statement may carry. |
| type alias | KeySqlRow | One materialized SQL row, keyed by column name. |
| type alias | KeySqlCursor | Materialized result of one executed statement. |
| type alias | KeySql | Synchronous SQL execution the key store runs its statements against. This shape
fits Cloudflare Durable Object SQLite (state.storage.sql) as is. A
node:sqlite adapter for hosts outside a Durable Object lives at
@fungi.computer/ear-tag/keys/node, kept out of this module so a Worker
consumer of this type never needs Node’s own types to typecheck. |
| type alias | RateLimitPolicy | A per-key fixed-window request policy. |
| type alias | KeyRecord | A stored key’s durable state, without its bearer secret. |
| type alias | KeyPrincipal | A verified bearer credential: a live key’s identity and current authority. |
| type alias | KeyRefusal | One closed refusal, carried as data rather than a thrown error type. |
| type alias | KeyOutcome | The outcome of one key-store operation: its value, or a closed refusal. |
| type alias | IssuerAuthority | What an issuing actor may grant. "unrestricted" may grant any capability in
the host’s vocabulary; "bounded" may grant only a subset of its own live
grants, checked with the vocabulary’s isSubset. |
| type alias | AuthorityFence | One durable notice that a key’s authority changed, for a host’s own downstream fencing. |
| type alias | AuthorityEpoch | Optional external epoch fence around a durable grant edit or revocation. |
| type alias | CreateKeyStoreOptions | Construction options for createKeyStore. |
| type alias | IssueKeyInput | Input to KeyStore’s issue. |
| type alias | IssuedKey | Result of KeyStore’s issue: the bearer secret and its durable
record. |
| type alias | UpdateGrantsInput | Input to KeyStore’s updateGrants: a compare-and-swap grant
replacement. |
| type alias | RevokeInput | Input to KeyStore’s revoke: an exact, replayable revocation. |
| type alias | AdmitUseInput | Input to KeyStore’s admitUse: one exact, replayable spend
admission. |
| type alias | KeyStore | The operations one key store exposes over its tenant’s keys. |
| constant | keyRefusalCodes | The closed refusal vocabulary used by key-owner outcomes and transport decoders. |
| constant | keyRefusalSchema | Closed key-owner refusals crossing JSON or RPC transports. |
| function | keyWire() | One wire grammar for both Hub and standalone Oyster key transports. |
| function | createKeyStore() | Create one tenant-scoped key store: bearer-key issuance, verification and lifecycle over one host’s capability vocabulary. One store instance is one tenant; namespacing between tenants is the host’s own table or storage boundary, not a column inside this store. |
KeyRefusalCodetype alias
Section titled “KeyRefusalCode”type KeyRefusalCode = (typeof keyRefusalCodes)[number];Stable, closed reasons a key-store operation refuses to proceed.
KeySummarytype alias
Section titled “KeySummary”type KeySummary<Capability> = Readonly< Omit<KeyRecord<Capability>, "owner" | "scope"> & object>;Owner-facing key metadata; neither the human owner id nor digest is exposed.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Capability extends string |
KeyWiretype alias
Section titled “KeyWire”type KeyWire<Capability> = Readonly<{ issue: z.ZodType<IssueKeyInput<Capability>>; updateGrants: z.ZodType<UpdateGrantsInput<Capability>>; revoke: z.ZodType<RevokeInput>; summary: z.ZodType<KeySummary<Capability>>; toSummary: (record) => KeySummary<Capability>;}>;Shared request decoders and secret-free key metadata for host transports.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Capability extends string |
KeySqlValuetype alias
Section titled “KeySqlValue”type KeySqlValue = string | number | null;One bound SQL value a key store statement may carry.
KeySqlRowtype alias
Section titled “KeySqlRow”type KeySqlRow = Readonly<Record<string, KeySqlValue>>;One materialized SQL row, keyed by column name.
KeySqlCursortype alias
Section titled “KeySqlCursor”type KeySqlCursor = Readonly<{ toArray: () => readonly KeySqlRow[];}>;Materialized result of one executed statement.
KeySqltype alias
Section titled “KeySql”type KeySql = Readonly<{ exec: (statement, ...bindings) => KeySqlCursor;}>;Synchronous SQL execution the key store runs its statements against. This shape
fits Cloudflare Durable Object SQLite (state.storage.sql) as is. A
node:sqlite adapter for hosts outside a Durable Object lives at
@fungi.computer/ear-tag/keys/node, kept out of this module so a Worker
consumer of this type never needs Node’s own types to typecheck.
RateLimitPolicytype alias
Section titled “RateLimitPolicy”type RateLimitPolicy = Readonly<{ limit: number; windowSeconds: number;}>;A per-key fixed-window request policy.
KeyRecordtype alias
Section titled “KeyRecord”type KeyRecord<Capability> = Readonly<{ keyId: string; owner: string; name: string; scope: Scope<Capability> | null; grantVersion: number; expiresAt: number | null; revokedAt: number | null; rateLimit: RateLimitPolicy | null; lastUsedAt: number | null; createdAt: number; updatedAt: number;}>;A stored key’s durable state, without its bearer secret.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Capability extends string |
KeyPrincipaltype alias
Section titled “KeyPrincipal”type KeyPrincipal<Capability> = Readonly<{ keyId: string; owner: string; name: string; scope: Scope<Capability>; grantVersion: number; expiresAt: number | null;}>;A verified bearer credential: a live key’s identity and current authority.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Capability extends string |
KeyRefusaltype alias
Section titled “KeyRefusal”type KeyRefusal = Readonly<{ code: KeyRefusalCode; retryAfterSeconds?: number;}>;One closed refusal, carried as data rather than a thrown error type.
invalid means the caller’s own input failed the operation’s schema; it is the
caller’s bug. denied means well-formed input was refused on its merits (no
authority, revoked, suspended). unavailable means the store could not read
back its own state (a corrupt row, a corrupt rate limit, or any other failure
that is not one of the other closed reasons); that is the store’s own fault,
never the caller’s, and every such failure is also logged before this outcome is
returned.
KeyOutcometype alias
Section titled “KeyOutcome”type KeyOutcome<Value> = Readonly< | Readonly<{ kind: "ok"; value: Value; }> | Readonly<{ kind: "error"; error: KeyRefusal; }>>;The outcome of one key-store operation: its value, or a closed refusal.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Value |
IssuerAuthoritytype alias
Section titled “IssuerAuthority”type IssuerAuthority<Capability> = | Readonly<{ kind: "unrestricted"; }> | Readonly<{ kind: "bounded"; grants: readonly Grant<Capability>[]; }>;What an issuing actor may grant. "unrestricted" may grant any capability in
the host’s vocabulary; "bounded" may grant only a subset of its own live
grants, checked with the vocabulary’s isSubset.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Capability extends string |
AuthorityFencetype alias
Section titled “AuthorityFence”type AuthorityFence = Readonly<{ requestId: string; keyId: string; kind: "grants" | "revoke" | "suspend" | "close"; throughGrantVersion: number; grantVersion: number; expiresAt: number | null;}>;One durable notice that a key’s authority changed, for a host’s own downstream fencing.
AuthorityEpochtype alias
Section titled “AuthorityEpoch”type AuthorityEpoch = Readonly<{ begin: (decisionId) => Promise<void>; finish: (decisionId) => Promise<void>; abort: (decisionId) => Promise<void>;}>;Optional external epoch fence around a durable grant edit or revocation.
CreateKeyStoreOptionstype alias
Section titled “CreateKeyStoreOptions”type CreateKeyStoreOptions<Capability> = Readonly<{ sql: KeySql; commit: <Value>(body) => Promise<Value>; vocabulary: GrantVocabulary<Capability>; prefix: string; authorizeIssuer: (actorId) => Promise<IssuerAuthority<Capability> | null>; delegation?: Readonly<{ manage: Capability; }>; epoch?: AuthorityEpoch; onAuthorityChange?: (fence) => void; now?: () => number;}>;Construction options for createKeyStore.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Capability extends string |
IssueKeyInputtype alias
Section titled “IssueKeyInput”type IssueKeyInput<Capability> = Readonly<{ name: string; grants: readonly Grant<Capability>[]; keyId?: string; expiresAt?: number; rateLimit?: RateLimitPolicy;}>;Input to KeyStore’s issue.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Capability extends string |
IssuedKeytype alias
Section titled “IssuedKey”type IssuedKey<Capability> = Readonly<{ key: string; record: KeyRecord<Capability>;}>;Result of KeyStore’s issue: the bearer secret and its durable
record.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Capability extends string |
UpdateGrantsInputtype alias
Section titled “UpdateGrantsInput”type UpdateGrantsInput<Capability> = Readonly<{ requestId: string; keyId: string; expectedGrantVersion: number; grants: readonly Grant<Capability>[];}>;Input to KeyStore’s updateGrants: a compare-and-swap grant
replacement.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Capability extends string |
RevokeInputtype alias
Section titled “RevokeInput”type RevokeInput = Readonly<{ requestId: string; keyId: string;}>;Input to KeyStore’s revoke: an exact, replayable revocation.
AdmitUseInputtype alias
Section titled “AdmitUseInput”type AdmitUseInput<Capability> = Readonly<{ capability: Capability; target?: string; requestId: string;}>;Input to KeyStore’s admitUse: one exact, replayable spend
admission.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Capability extends string |
KeyStoretype alias
Section titled “KeyStore”type KeyStore<Capability> = Readonly<{ issue: ( actorId, input, parent?, ) => Promise<KeyOutcome<IssuedKey<Capability>>>; verify: (secret) => Promise<KeyOutcome<KeyPrincipal<Capability>>>; current: (principal) => KeyOutcome<KeyPrincipal<Capability>>; live: (ref) => Promise<KeyOutcome<KeyPrincipal<Capability>>>; list: ( actorId, owner?, ) => Promise<KeyOutcome<readonly KeyRecord<Capability>[]>>; updateGrants: ( actorId, input, parent?, ) => Promise<KeyOutcome<KeyRecord<Capability>>>; revoke: (actorId, input) => Promise<KeyOutcome<KeyRecord<Capability>>>; suspendOwner: (owner, requestId) => Promise<KeyOutcome<void>>; close: (closedAt) => KeyOutcome<void>; admitUse: (principal, input) => Promise<KeyOutcome<KeyPrincipal<Capability>>>; touch: (keyId) => Promise<KeyOutcome<void>>;}>;The operations one key store exposes over its tenant’s keys.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Capability extends string |
keyRefusalCodesconstant
Section titled “keyRefusalCodes”const keyRefusalCodes: readonly [ "invalid", "denied", "conflict", "expired", "rate_limited", "unavailable",];The closed refusal vocabulary used by key-owner outcomes and transport decoders.
keyRefusalSchemaconstant
Section titled “keyRefusalSchema”const keyRefusalSchema: z.ZodType<KeyRefusal>;Closed key-owner refusals crossing JSON or RPC transports.
keyWire()function
Section titled “keyWire()”function keyWire<Capability>(vocabulary): KeyWire<Capability>;One wire grammar for both Hub and standalone Oyster key transports.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Capability extends string |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
vocabulary |
GrantVocabulary<Capability> |
Returns
Section titled “Returns”KeyWire<Capability>
createKeyStore()function
Section titled “createKeyStore()”function createKeyStore<Capability>(options): KeyStore<Capability>;Create one tenant-scoped key store: bearer-key issuance, verification and lifecycle over one host’s capability vocabulary. One store instance is one tenant; namespacing between tenants is the host’s own table or storage boundary, not a column inside this store.
Type Parameters
Section titled “Type Parameters”| Type Parameter |
|---|
Capability extends string |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
options |
CreateKeyStoreOptions<Capability> |
Returns
Section titled “Returns”KeyStore<Capability>