import { Cipher } from '@interop/minimal-cipher'; import type { IEDVDocument, IEncryptedDocument, IHMAC, IJWE, IKeyAgreementKey, IKeyResolver, IRecipientTemplate } from '@interop/data-integrity-core'; export declare class EdvDocumentCipher { cipher: Cipher; indexHelper: any; /** * Creates a document cipher. Pairs a JWE `cipher` with an optional * `indexHelper`; the latter is only consulted by `encrypt` when an `hmac` is * supplied (to blind indexable attributes), so callers that do not index -- * such as a WAS encrypted collection -- may omit it. * * @param options {object} * @param options.cipher {Cipher} the JWE cipher (from `minimal-cipher`) * @param [options.indexHelper] {object} blinds indexable attributes when an * `hmac` is given to `encrypt` */ constructor({ cipher, indexHelper }: { cipher: Cipher; indexHelper?: any; }); /** * Builds the default JWE recipient list for a key agreement key, using the * only supported algorithm (`ECDH-ES+A256KW`). Returns an empty array if no * key is given. * * @param keyAgreementKey {IKeyAgreementKey} the recipient key * @returns {IRecipientTemplate[]} */ createDefaultRecipients(keyAgreementKey: IKeyAgreementKey): IRecipientTemplate[]; /** * Derives a deterministic, content-derived EDV document id from an encrypted * document's JWE: the SHA-256 of the raw ciphertext octets, truncated to the * 128-bit EDV id width and encoded in the same multibase identity layout as * `EdvClientCore.generateId()` (`'z' + base58btc([0x00, 0x10, ...16 bytes])`). * The result passes the standard EDV id format check and is * indistinguishable on the wire from a random id. * * Only `jwe.ciphertext` is hashed -- not the whole envelope -- so the id * stays stable when a recipient is later added (re-wrapping the content * encryption key changes `jwe.recipients` but not the ciphertext), and * hashing ciphertext the server already stores leaks nothing about the * plaintext. Because JWE encryption is non-deterministic, two independent * encryptions of the same plaintext yield different ids: the id is stable * across replicas of one encryption, not across re-encryptions. * * A content-derived id makes the document content-addressed and therefore * immutable: changing the content changes the id, so an "update" becomes * delete-old + add-new rather than an in-place `sequence` bump. Callers * wanting the classic mutable-document model should keep using random * `generateId()` ids. * * The typical flow is encrypt-then-stamp: `encrypt()` a document without an * `id`, derive the id from the returned envelope's `jwe`, then set it on the * envelope (the id lives outside the JWE, so this does not invalidate it). * * @param options {object} * @param options.jwe {IJWE} the envelope JWE; must carry a non-empty * base64url `ciphertext` * @returns {Promise} - Resolves to the multibase-encoded id. */ static deriveId({ jwe }: { jwe: IJWE; }): Promise; /** * Instance convenience for the static {@link EdvDocumentCipher.deriveId}. * * @param options {object} * @param options.jwe {IJWE} the envelope JWE * @returns {Promise} - Resolves to the multibase-encoded id. */ deriveId({ jwe }: { jwe: IJWE; }): Promise; /** * Decrypts an encrypted document, returning a working document that includes * its cleartext `content` (and `meta` / `stream`). * * @param options {object} * @param options.encryptedDoc {IEncryptedDocument} the encrypted document * @param [options.keyAgreementKey] {IKeyAgreementKey} the key for unwrapping * the content encryption key * @returns {Promise} */ decrypt({ encryptedDoc, keyAgreementKey }: { encryptedDoc: IEncryptedDocument; keyAgreementKey?: IKeyAgreementKey; }): Promise; /** * Encrypts a document's (clear) `content`, `meta`, and `stream` into a JWE * envelope, blinding any indexable attributes when an `hmac` is supplied, and * managing the document `sequence` (incremented on update, pinned to `0` on * insert). * * @param options {object} * @param options.doc {IEDVDocument} the document to encrypt * @param [options.recipients] {IRecipientTemplate[]} JWE recipients; merged * with any recipients already on `doc.jwe` * @param [options.keyResolver] {IKeyResolver} resolves a key ID to a DH * public key * @param [options.hmac] {IHMAC} blinds indexable attributes; * when absent, indexing is skipped * @param [options.update] {boolean} `true` to advance `sequence` * (an existing document), `false` for a fresh insert * @param [options.additionalProtectedParams] {Record} extra * members merged into the JWE protected header (the AEAD-authenticated AAD); * forwarded to `cipher.encryptObject`. Callers verify these by parsing * `jwe.protected` after a successful decrypt. The reserved `enc` and `caad` * members must not be set here. * @returns {Promise} */ encrypt({ doc, recipients, keyResolver, hmac, update, additionalProtectedParams }: { doc: IEDVDocument; recipients?: IRecipientTemplate[]; keyResolver?: IKeyResolver; hmac?: IHMAC; update?: boolean; additionalProtectedParams?: Record; }): Promise; } //# sourceMappingURL=EdvDocumentCipher.d.ts.map