/** * End-to-end encryption primitives (Web Crypto): ECDH P-256 for key agreement * + AES-GCM for message content. The server only ever relays public keys and * stores ciphertext — it cannot read messages. * * Scope/limitations (honest): this secures a *live 1:1* session — the guest and * one agent exchange public keys while both are connected, then messages between * them are encrypted. True asynchronous E2E (encrypting to an offline party) * needs a prekey/X3DH scheme, which is out of scope here. When E2E is on, the * AI assistant cannot read the room (by design). */ export interface KeyPair { publicKey: CryptoKey; privateKey: CryptoKey; } export declare function generateKeyPair(): Promise; /** Export a public key to a compact base64 string (raw, 65 bytes for P-256). */ export declare function exportPublicKey(key: CryptoKey): Promise; /** Derive the shared AES-GCM key from our private key + the peer's public key. */ export declare function deriveSharedKey(privateKey: CryptoKey, peerPublicKeyB64: string): Promise; export interface Ciphertext { ct: string; iv: string; } export declare function encrypt(key: CryptoKey, plaintext: string): Promise; export declare function decrypt(key: CryptoKey, ct: string, iv: string): Promise; /** Persist/restore our keypair across reloads (so prior ciphertext stays readable). */ export declare function loadOrCreateKeyPair(storageKey: string): Promise; /** Sign a prekey public key bytes using ECDSA P-256 SHA-256. * The signingKey must be an ECDSA P-256 private key (not ECDH). * In the full X3DH setup the identity key pair contains both an ECDH key * (for DH) and an ECDSA key (for signing). We keep them separate here. */ export declare function signPrekey(signingPrivateKey: CryptoKey, spkPublicKey: CryptoKey): Promise; /** Verify an SPK signature. verifyPublicKey must be an ECDSA P-256 public key. */ export declare function verifyPrekeySignature(verifyPublicKeyB64: string, spkPublicKeyB64: string, signatureB64: string): Promise; /** A full identity keypair for X3DH: ECDH key for DH computations + ECDSA key * for signing prekeys. The two key objects share the same P-256 curve but have * different usages, so Web Crypto treats them separately. */ export interface IdentityKeyPair { ecdhKP: KeyPair; ecdsaKP: { publicKey: CryptoKey; privateKey: CryptoKey; }; /** The ECDH public key exported as base64 — used as the X3DH identity key. */ publicKeyB64: string; /** The ECDSA public key exported as base64 — used for SPK signature verification. */ sigPublicKeyB64: string; } /** Generate a full X3DH identity keypair (ECDH + ECDSA on the same P-256 curve). */ export declare function generateIdentityKeyPair(): Promise; /** Load or generate an identity keypair, persisting both components. */ export declare function loadOrCreateIdentityKeyPair(storageKey: string): Promise; export interface X3DHBundle { identityKey: string; signedPrekey: string; signedPrekeyId: string; signature: string; oneTimePrekey?: string; } /** X3DH sender side: derive a shared key from the recipient's prekey bundle. * Returns the shared AES-GCM key and the ephemeral public key to transmit. */ export declare function x3dhSend(senderIK: KeyPair, recipientBundle: X3DHBundle): Promise<{ sharedKey: CryptoKey; ephemeralPublicKey: string; }>; /** X3DH recipient side: rederive the shared key from an init message. * Returns the shared AES-GCM key. */ export declare function x3dhReceive(recipientIK: KeyPair, recipientSPK: KeyPair, senderIKb64: string, ephemeralKeyB64: string, recipientOPK?: KeyPair): Promise;