import { type SupportedEncodings } from 'uint8arrays'; /** * A recipient's X25519 public key, in any of four forms: * - `CryptoKey`: an X25519 public key. * - `CryptoKeyPair`: its `.publicKey` is used (encryption never needs the * private half). * - `Uint8Array`: 32 raw X25519 public-key bytes. * - `{ publicKey, encoding? }`: the public key as an encoded string; * `encoding` defaults to `base64url`. */ export type RecipientKey = CryptoKey | CryptoKeyPair | Uint8Array | { publicKey: string; encoding?: SupportedEncodings; }; /** * AEAD (AES-256-GCM), single-shot at sequence 0 */ export declare function aeadSeal(key: Uint8Array, nonce: Uint8Array, plaintext: Uint8Array): Promise; export declare function aeadOpen(key: Uint8Array, nonce: Uint8Array, ciphertext: Uint8Array): Promise; /** * Wrap a fresh (or supplied) AES key to `recipient`, then AES-GCM encrypt a * message under it. The wrapped key, IV, and ciphertext are concatenated * into a single self-describing envelope. * * Wire format: `wrappedLen(2, big-endian) ‖ wrapped ‖ iv(12) ‖ ciphertext`. * The length prefix lets `decrypt` slice the segments apart for either * 128- or 256-bit wrapped keys. * * @param recipient The recipient's X25519 public key, as a `CryptoKey`, * `CryptoKeyPair` (its `.publicKey` is used), 32 raw bytes (`Uint8Array`), * or `{ publicKey:string, encoding? }` (encoding defaults to `base64url`). * @param message Plaintext to encrypt. A `string` is UTF-8 encoded. * @param aesKey Optional key, as either an AES-GCM `CryptoKey` or its raw * bytes (`Uint8Array`, 16 or 32 bytes). Omit to generate a fresh key of * `opts.size` bits. A supplied `CryptoKey` MUST be extractable. Each * call picks a fresh random 96-bit IV for the message ciphertext, so * reusing the same `aesKey` across many calls carries the standard * birthday bound for random nonces (collision risk becomes * non-negligible around 2^32 messages under one key, NIST SP 800-38D) -- * prefer a fresh key per call (the default) over reusing one at scale. * @param opts `size` (128/256, default 256; ignored when `aesKey` is * supplied) and `info` (bound into the HPKE key schedule). * @returns The concatenated envelope bytes. * * `encrypt.asString(...)` returns the same envelope as an encoded string. */ export declare function encryptBytes(recipient: RecipientKey, message: Uint8Array | string, aesKey?: CryptoKey | Uint8Array | null, opts?: { size?: 128 | 256; info?: Uint8Array | string; }): Promise; /** * Like `encrypt`, but encodes the envelope bytes to a string -- handy for * transports that carry text (JSON, URLs, headers). Decode with * `fromString(...)` (or any matching decoder) and pass the bytes to * `decrypt` / `decrypt.asString`. Exposed as `encrypt.asString`. * * @param recipient The recipient's X25519 public key, as a `CryptoKey`, * `CryptoKeyPair` (its `.publicKey` is used), 32 raw bytes (`Uint8Array`), * or `{ publicKey:string, encoding? }` (encoding defaults to `base64url`). * @param message Plaintext to encrypt. A `string` is UTF-8 encoded. * @param aesKey Optional key, as either an AES-GCM `CryptoKey` or its raw * bytes (`Uint8Array`, 16 or 32 bytes). Omit to generate a fresh key of * `opts.size` bits. A supplied `CryptoKey` MUST be extractable. Each * call picks a fresh random 96-bit IV for the message ciphertext, so * reusing the same `aesKey` across many calls carries the standard * birthday bound for random nonces (collision risk becomes * non-negligible around 2^32 messages under one key, NIST SP 800-38D) -- * prefer a fresh key per call (the default) over reusing one at scale. * @param opts `size` (128/256, default 256; ignored when `aesKey` is * supplied), `info` (bound into the HPKE key schedule), and `encoding` * (the string encoding of the returned envelope; default `base64url`). * @returns The encoded envelope string. */ export declare function encryptToString(recipient: RecipientKey, message: Uint8Array | string, aesKey?: CryptoKey | Uint8Array | null, opts?: { size?: 128 | 256; info?: Uint8Array | string; encoding?: SupportedEncodings; }): Promise; export declare function hmac(key: Uint8Array, data: Uint8Array): Promise; export declare function labeledExtract(suiteId: Uint8Array, salt: Uint8Array, label: string, ikm: Uint8Array): Promise; export declare function labeledExpand(suiteId: Uint8Array, prk: Uint8Array, label: string, info: Uint8Array, length: number): Promise; export declare function resolveRecipientPublicKey(recipient: RecipientKey): Promise; export declare function encap(pkR: CryptoKey): Promise<{ sharedSecret: Uint8Array; enc: Uint8Array; }>; export declare function decap(enc: Uint8Array, keypair: CryptoKeyPair): Promise; /** * A stable fingerprint for an AES-GCM key: the same key bytes always give * the same string, and two different keys effectively never collide. * * Derived from the key's *behavior* rather than its bytes, so it works on * a non-extractable key -- including one rehydrated from IndexedDB, and * the keys `create` / `encryptKey` / `open` return by default. The obvious * implementation, `exportKey('raw')` then SHA-256, would force every such * key to be extractable. HKDF is not an option either: WebCrypto cannot * convert an AES-GCM key into an HKDF key, and `deriveBits` only accepts a * key imported under HKDF, which needs the raw bytes a non-extractable key * withholds. AES-GCM as a PRF is the only primitive such a key still * exposes. * * The derivation is fixed forever (see `src/constants.ts`): * * ``` * LABEL = utf8("simple-hpke/keyId/v1") * N = SHA-256(LABEL)[0..12] // fixed nonce * C = AES-GCM(key, N, LABEL) // ciphertext || 16-byte tag * keyId = base64url(SHA-256(LABEL || C)) * ``` * * @param key An AES-GCM `CryptoKey` with the `encrypt` usage. It does not * need to be extractable. * @returns The fingerprint: the full 32-byte digest, base64url, unpadded * (43 characters). * @throws {HpkeError} `ERR_INVALID_AES_KEY` if `key` is not an AES-GCM key * or cannot encrypt. */ export declare function keyId(key: CryptoKey): Promise; export declare function i2osp(n: number, len: number): Uint8Array; export declare function concat(...arrays: Uint8Array[]): Uint8Array; //# sourceMappingURL=util.d.ts.map