UNPKG

@code-yeongyu/senpi

Version:

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

91 lines • 4.71 kB
import { type KeyObject } from "node:crypto"; /** * The engine half of sealed secret answers: omo-relay-spec decision 0022 section 3, at 5da46fd262 (D11 secret phase, design 4.1-4.3; * senpi#4249). Implemented here from the decision text; cross-implementation vectors are verified in the spec repo. */ /** `B` of 0022 3.2: `["omo-secret-binding-v1", hin, hostJkt, durableSessionId, uiRequestId, deadlineAtMs, hpkePk, displayHash]`. */ export type SecretBinding = readonly ["omo-secret-binding-v1", string, string, string, string, number, string, string]; export interface SecretBindingInput { readonly hostInstance: string; readonly hostJkt: string; readonly durableSessionId: string; readonly uiRequestId: string; readonly deadlineAtMs: number; readonly hpkePk: string; readonly title: string; readonly placeholder: string | undefined; } /** Engine to holder (design 4.3): sent only to a sealed holder, whose grant negotiated `secret_input_v1`. */ export interface McpPresenterSecretRequest { readonly type: "mcp_presenter_secret_request"; readonly v: 1; readonly sessionId: string; readonly durableSessionId: string; readonly uiRequestId: string; readonly title: string; readonly placeholder?: string; readonly deadlineAtMs: number; readonly hostInstance: string; readonly hpkePk: string; readonly hostPk: string; readonly hostToken: string; readonly sig: string; } /** Engine to holder (design 3.2): a re-minted host token for every pending request of the session. Value-free. */ export interface McpPresenterSecretToken { readonly type: "mcp_presenter_secret_token"; readonly v: 1; readonly hostInstance: string; readonly durableSessionId: string; readonly hostToken: string; } /** Engine to holder (design 4.3, 7.2): value-free; `elsewhere` is false only for the winning holder. */ export interface McpPresenterSecretSettled { readonly type: "mcp_presenter_secret_settled"; readonly v: 1; readonly uiRequestId: string; readonly outcome: "answered" | "cancelled" | "timed_out" | "unavailable"; readonly elsewhere: boolean; } export type McpPresenterSecretFrame = McpPresenterSecretRequest | McpPresenterSecretToken | McpPresenterSecretSettled; /** The per-request X25519 key of 0022 3.1: the public half as unpadded base64url of the raw 32 bytes. */ export interface SecretRequestKey { readonly hpkePk: string; readonly privateKey: KeyObject; } /** Builds `B`; refuses a deadline that is not a safe integer and any key or hash that is not 32 base64url bytes. */ export declare function secretBinding(input: SecretBindingInput): SecretBinding; /** `req = b64url(SHA-256(UTF-8(JSON.stringify(B))))`: names one request everywhere an answer is bound to it. */ export declare function secretRequestHash(binding: SecretBinding): string; /** HPKE `info`: `UTF-8("omo-secret-answer-v1") || 0x00 || req` (its 32 bytes). */ export declare function secretAnswerInfo(req: string): Buffer; /** HPKE AAD: `UTF-8(JSON.stringify(["omo-secret-answer-aad-v1", req, principalId, grantId, answerId, stepupJti]))`. */ export declare function secretAnswerAad(req: string, principalId: string, grantId: string, answerId: string, jti: string): Buffer; /** What the installation key signs for a value answer; the ciphertext enters as `b64url(SHA-256(enc || ct))`. */ export declare function secretAnswerTranscript(ids: { readonly req: string; readonly principalId: string; readonly grantId: string; readonly answerId: string; }, jti: string, enc: Uint8Array, ct: Uint8Array): string; /** What the installation key signs for a cancel. */ export declare function secretCancelTranscript(ids: { readonly req: string; readonly principalId: string; readonly grantId: string; readonly answerId: string; }): string; /** * The canonical plaintext only: `u32be(byteLength) || UTF-8(value) || zeros`, exactly the next power of two of at * least 256 and at most 64 KiB, all-zero padding and valid UTF-8 (a leading BOM is kept). Anything else is * `undefined`. */ export declare function unpadSecretValue(plaintext: Uint8Array): string | undefined; /** The host key signs exactly this: `"omo-secret-request-v1\n" + JSON.stringify(B)`. */ export declare function secretRequestTranscript(binding: SecretBinding): string; /** * A fresh request key, held only by the pending request that owns the latch (design 4.1). Generated off the host loop: * it is on the session path, which holds no new synchronous crypto (no-sync-in-session-path, senpi#3993). */ export declare function generateSecretRequestKey(): Promise<SecretRequestKey>; //# sourceMappingURL=secret-sealed.d.ts.map