@code-yeongyu/senpi
Version:
Coding agent CLI with read, bash, edit, write tools and session management
63 lines • 3.43 kB
TypeScript
/**
* HPKE base mode (RFC 9180): DHKEM(P-256, HKDF-SHA256), HKDF-SHA256, AES-256-GCM, on Web Crypto only so the same code
* runs on Bun, Node, compiled binaries, the desktop renderer and Workers. Every wrap is single-shot (sequence 0).
*
* The recipient side takes a Diffie-Hellman function instead of a private key, so a recipient whose key never leaves
* hardware (a KMS key that only performs ECDH) opens wraps through the same code as a device key.
*
* Base mode authenticates nothing about the sender: anyone holding a recipient public key can produce a wrap that opens.
* A successful open proves only that the wrap was made for this key, so origin is established above this layer
* (signed wraps documents, per-dekId owners), never by an open.
*/
export type SealedFormatErrorCode = "open_failed" | "unsupported_version" | "invalid_public_key" | "invalid_private_key" | "invalid_key" | "invalid_aad" | "empty_secret";
/** Errors carry a code only: no key material, ciphertext or plaintext is ever echoed. */
export declare class SealedFormatError extends Error {
readonly code: SealedFormatErrorCode;
constructor(code: SealedFormatErrorCode);
}
/** A P-256 HPKE recipient. `dh` returns the 32-byte x-coordinate of the ECDH shared point with `peer`. */
export interface HpkeRecipient {
/** Uncompressed SEC1 encoding (65 bytes, leading 0x04). */
readonly publicKey: Uint8Array;
dh(peer: Uint8Array): Promise<Uint8Array>;
}
export interface HpkeSealInput {
readonly info: Uint8Array;
readonly aad: Uint8Array;
readonly pt: Uint8Array;
}
export interface HpkeOpenInput {
readonly enc: Uint8Array;
readonly ct: Uint8Array;
readonly info: Uint8Array;
readonly aad: Uint8Array;
}
export interface HpkeSealed {
readonly enc: Uint8Array;
readonly ct: Uint8Array;
}
type Bytes = Uint8Array<ArrayBuffer>;
/** A recipient whose private scalar is held in this process (device keys, tests). */
export declare function p256Recipient(privateKey: Uint8Array, publicKey: Uint8Array): Promise<HpkeRecipient>;
/** RFC 9180 Decap: the shared secret for `enc` addressed to `recipient`. */
export declare function hpkeDecap(recipient: HpkeRecipient, enc: Uint8Array): Promise<Bytes>;
/**
* RFC 9180 Encap with a caller-supplied ephemeral key pair. KNOWN-ANSWER TESTS ONLY: reusing an ephemeral key
* across wraps breaks HPKE's guarantees. Production sealing goes through {@link hpkeSealBase}, which mints one.
* @internal
*/
export declare function hpkeEncapDeterministic(recipientPublicKey: Uint8Array, ephemeralPrivateKey: Uint8Array, ephemeralPublicKey: Uint8Array): Promise<{
readonly enc: Uint8Array;
readonly sharedSecret: Uint8Array;
}>;
/** RFC 9180 KeySchedule for mode_base (no PSK). The exporter secret is not derived: the format never exports. */
export declare function hpkeKeySchedule(sharedSecret: Uint8Array, info: Uint8Array): Promise<{
readonly key: Bytes;
readonly baseNonce: Bytes;
}>;
/** Single-shot HPKE seal (sequence 0) to `recipientPublicKey` under a freshly generated ephemeral key. */
export declare function hpkeSealBase(recipientPublicKey: Uint8Array, input: HpkeSealInput): Promise<HpkeSealed>;
/** Single-shot HPKE open (sequence 0). Any failure is the one code `open_failed`. */
export declare function hpkeOpenBase(recipient: HpkeRecipient, input: HpkeOpenInput): Promise<Bytes>;
export {};
//# sourceMappingURL=hpke.d.ts.map