UNPKG

@code-yeongyu/senpi

Version:

Coding agent CLI with read, bash, edit, write tools and session management

144 lines • 7.43 kB
import { type KeyObject } from "node:crypto"; import type { Duplex } from "node:stream"; import type { McpFormBinding, McpPresenterIdentity } from "../../core/mcp-form-types.ts"; /** * Same-account presenter enrollment (senpi#4249, D11). The engine knows no omo account; the distribution that * launches the host injects this authority at host start. It is never reachable from an RPC command, argument, * environment variable, settings file, or session state. Without it, account enrollment fails closed. */ /** Why an attestation was refused. Account mismatch and `jti` replay are decided by the host, not here. */ export type PresenterAttestationRefusal = "attestation_malformed" | "attestation_signature" | "attestation_audience" | "attestation_expired" | "attestation_key_mismatch"; /** The verified claims of an `aud: "omo-mcp-presenter"`, `typ: "mcp_presenter"` token. */ export interface PresenterAttestation { readonly acc: string; readonly dev: string; /** The account's device name; display data only, never used for decisions. */ readonly dname: string; /** JWT `exp`, in seconds since the epoch. */ readonly exp: number; readonly jti: string; } export type PresenterAttestationResult = { readonly ok: true; readonly attestation: PresenterAttestation; } | { readonly ok: false; readonly reason: PresenterAttestationRefusal; }; /** The issuer's half of the host-key proof (D11 secret phase 3.1); the engine builds the rest of the transcript. */ export interface SecretHostProof { readonly issuer: string; readonly nonce: string; } /** One host token mint for a session (D11 secret phase 3.1). */ export interface SecretHostTokenRequest { readonly hostInstance: string; readonly durableSessionId: string; /** This host instance's in-memory Ed25519 key as a 44-byte SPKI DER; the wire form is the raw 32 bytes after it. */ readonly hostKeySpki: Uint8Array; /** * The host key's base64url Ed25519 signature over * `["omo-secret-host-proof/v1", issuer, "omo-secret-host", jkt, nonce, hostInstance, durableSessionId].join("\n")`. * It throws for an `issuer` or `nonce` outside the claim bounds, and once the mint has settled. The private key * never crosses the seam. */ readonly sign: (proof: SecretHostProof) => string; } /** Why a step-up token was refused (D11 secret phase 6.5). */ export type SecretAnswerRefusal = "stepup_malformed" | "stepup_signature" | "stepup_audience" | "stepup_expired" | "stepup_key_mismatch" | "stepup_binding"; /** The verified claims of an `aud: "omo-secret-answer"`, `typ: "secret_answer"` step-up token. */ export interface SecretAnswerStepUp { readonly acc: string; readonly dev: string; readonly jti: string; /** JWT `exp`, in seconds since the epoch. */ readonly exp: number; /** The host token's `dev` the step-up was minted for. */ readonly hdev: string; } export type SecretAnswerVerification = { readonly ok: true; readonly stepUp: SecretAnswerStepUp; } | { readonly ok: false; readonly reason: SecretAnswerRefusal; }; export interface PresenterAccountAuthority { /** The account this host's installation is signed in as, re-read on every call; `undefined` when signed out. */ hostAccount(): string | undefined; /** * Checks the issuer signature against the pinned JWKS, `iss`, `aud`/`typ` (code constants), the lifetime, and * that `cnf.jkt` is `presenterKeyThumbprint(publicKeySpkiDer)`. */ verify(token: string, publicKeySpkiDer: Uint8Array, nowS: number): Promise<PresenterAttestationResult>; /** Fires on sign-out or an account switch; returns the unsubscribe function. */ onAccountChange(listener: () => void): () => void; /** * D11 secret phase (3.1): mints an `aud: "omo-secret-host"` token that binds the host key to the signed-in account * and device, the host instance and the session, with the device access token used in process and dropped. * Resolves to the compact JWT. The sealed secret route needs this and `verifySecretAnswer`: an authority without * both gets no host key and no call, and its host is byte-identical to one without them. */ mintSecretHostToken?(request: SecretHostTokenRequest): Promise<string>; /** * D11 secret phase (6.5): checks a step-up token's issuer signature against the pinned JWKS, `iss`, the * `aud`/`typ` code constants, the lifetime (`exp - iat <= 120`, 60 s skew), `uv === true`, that `cnf.jkt` is * `presenterKeyThumbprint(presenterSpki)`, and that `req` equals the passed binding hash. */ verifySecretAnswer?(token: string, presenterSpki: Uint8Array, req: string, nowS: number): Promise<SecretAnswerVerification>; } export type PresenterAccountRefusal = PresenterAttestationRefusal | "attestation_replayed" | "presenter_account_unavailable" | "presenter_account_mismatch" | "presenter_busy" | "presenter_proof_invalid"; /** A presenter admitted by a same-account attestation. Never a launch owner; in memory only. */ export interface AccountPrincipal { readonly kind: "account"; readonly id: string; readonly key: KeyObject; readonly acc: string; readonly dev: string; readonly dname: string; readonly installationKeyId: string; /** The current attestation's `exp`, in seconds since the epoch. */ attestedUntil: number; /** The control stream it enrolled on: its only management stream. */ readonly stream: Duplex; readonly sessions: WeakSet<McpFormBinding>; } /** How the settle audit names an account principal: by its verified attestation, never by `remoteOrigin` (D11 2.5). */ export declare function accountIdentity(principal: AccountPrincipal): McpPresenterIdentity; /** * `account_enroll` and `account_reattest` on the presenter control endpoint (D11 S3-2). The pre-auth exchange is one * attempt within the control connection's 30 s window: attestation, then a signature over the host's transcript. */ export declare class McpPresenterAccounts { private readonly hostInstance; private readonly principals; private readonly authority; private readonly revokeStream; private readonly jtis; private readonly attempts; private readonly started; private readonly verifying; private readonly closing; private readonly expiry; private readonly unsubscribe; constructor(hostInstance: string, principals: Map<string, AccountPrincipal | { readonly kind: "inherited"; }>, authority: PresenterAccountAuthority | undefined, revokeStream: (stream: Duplex) => void); /** Takes account frames; `fresh` is a control stream that has sent nothing else. False leaves the frame alone. */ receive(stream: Duplex, value: Record<string, unknown>, fresh: boolean, authenticated: () => void): boolean; /** Revokes an account principal whose host account or attestation is no longer current; true when it did. */ lapsed(principal: AccountPrincipal | { readonly kind: "inherited"; }): boolean; dispose(): void; private enroll; private prove; private reattest; private attest; private expireAt; private principalOn; /** Revokes the principal's registrations now, then closes its stream: with the refusal flushed, if one is given. */ private revoke; private refuse; } //# sourceMappingURL=mcp-presenter-account.d.ts.map