import { Cipher } from '@interop/minimal-cipher'; import type { IEDVConfig, IEDVDocument, IHMAC, IKeyAgreementKey, IKeyResolver, IRecipientTemplate } from '@interop/data-integrity-core'; import type { Transport } from './Transport.js'; import { EdvDocumentCipher } from './EdvDocumentCipher.js'; /** * An `equals` attribute filter for `find` / `count`: either a single object of * key/value attribute pairs to match, or an array of such objects. The names * and values are HMAC-blinded by `IndexHelper` before being sent to the server. */ export type EqualsFilter = Record | Array>; /** * A `has` attribute filter for `find` / `count`: an attribute name, or an * array of attribute names, that a document must possess to match. */ export type HasFilter = string | string[]; /** * Options shared by the core document write methods (`insert` / `update`). */ export interface IWriteOptions { doc?: IEDVDocument; stream?: ReadableStream; chunkSize?: number; recipients?: IRecipientTemplate[]; keyResolver?: IKeyResolver; keyAgreementKey?: IKeyAgreementKey; hmac?: IHMAC; additionalProtectedParams?: Record; chunkedAad?: boolean; transport?: Transport; } /** * Options for `count` and the attribute-matching portion of `find`. */ export interface ICountOptions { keyAgreementKey?: IKeyAgreementKey; hmac?: IHMAC; equals?: EqualsFilter; has?: HasFilter; transport?: Transport; } /** * Options for `find`. */ export interface IFindOptions extends ICountOptions { returnDocuments?: boolean; count?: boolean; limit?: number; cursor?: string; } export declare class EdvClientCore { hmac?: IHMAC; id?: string; keyAgreementKey?: IKeyAgreementKey; keyResolver?: IKeyResolver; cipher: Cipher; indexHelper: any; /** * The transport-free JWE codec backing this core. Public so that callers * which own their own transport (for example, Wallet Attached Storage) can * encrypt / decrypt EDV envelopes directly, without driving any I/O. */ documentCipher: EdvDocumentCipher; /** * Creates the core of an EdvClient. The core must be coupled with a * Transport layer. * * @param {object} options - The options to use. * @param {object} [options.hmac] - A default HMAC API for blinding * indexable attributes. * @param {string} [options.id] - The ID of the EDV. * @param {object} [options.keyAgreementKey] - A default KeyAgreementKey * API for deriving shared KEKs for wrapping content encryption keys. * @param {Function} [options.keyResolver] - A default function that returns * a Promise that resolves a key ID to a DH public key. * @param {string} [options.cipherVersion='recommended'] - Sets the cipher * version to either "recommended" or "fips". * @param {string} [options._attributeVersion=2] - Sets the blinded attribute * version to use; for internal use only. * * @returns {EdvClientCore} An EdvClientCore instance. */ constructor({ hmac, id, keyAgreementKey, keyResolver, cipherVersion, _attributeVersion }?: { hmac?: IHMAC; id?: string; keyAgreementKey?: IKeyAgreementKey; keyResolver?: IKeyResolver; cipherVersion?: 'recommended' | 'fips'; _attributeVersion?: number; }); /** * Ensures that future documents inserted or updated using this Edv * instance will be indexed according to the given attribute, provided that * they contain that attribute. Compound indexes can be specified by * providing an array for `attribute`. * * @param {object} options - The options to use. * @param {string|Array} options.attribute - The attribute name or an array of * attribute names to create a unique compound index. * @param {boolean} [options.unique=false] - Should be `true` if the index is * considered unique, `false` if not. */ ensureIndex({ attribute, unique }?: { attribute?: string | string[]; unique?: boolean; }): void; /** * Encrypts and inserts a document into the EDV if it does not already * exist. If a document matching its ID already exists, a `DuplicateError` is * thrown. If a `stream` is given, the document will be inserted, then * the stream will be read, chunked, and stored. Finally, the document will * be updated to include meta data about the stored data from the stream, * including a message digest. * * @param {object} options - The options to use. * @param {object} options.doc - The document to insert. * @param {ReadableStream} [options.stream] - A WHATWG Readable stream to read * from to associate chunked data with this document. * @param {number} [options.chunkSize=1048576] - The size, in bytes, of the * chunks to break the incoming stream data into. * @param {object[]} [options.recipients=[]] - A set of JWE recipients * to encrypt the document for; if not present, a default recipient will * be added using `this.keyAgreementKey` and if no `keyAgreementKey` is * set, an error will be thrown. * @param {Function} [options.keyResolver=this.keyResolver] - A function that * returns a Promise that resolves a key ID to a DH public key. * @param {object} [options.keyAgreementKey=this.keyAgreementKey] - A * KeyAgreementKey API for deriving shared KEKs for wrapping content * encryption keys. * @param {object} [options.hmac=this.hmac] - An HMAC API for blinding * indexable attributes. * @param {object} [options.additionalProtectedParams] - Extra members merged * into the document envelope's JWE protected header (the AEAD-authenticated * AAD); verify them by parsing `jwe.protected` after a successful decrypt. * @param {boolean} [options.chunkedAad=true] - When a `stream` is given, bind * each stream chunk to its 0-based index in the AEAD AAD so that reordering, * substituting, or dropping a chunk fails the read. Readers must be upgraded * before writers; pass `false` to emit the legacy chunk format. * @param {object} options.transport - The Transport instance to use. * * @returns {Promise} - Resolves to the inserted document. */ insert({ doc, stream, chunkSize, recipients, keyResolver, keyAgreementKey, hmac, additionalProtectedParams, chunkedAad, transport }?: IWriteOptions): Promise; /** * Encrypts and updates a document in the EDV. If the document does not * already exist, it is created. If a `stream` is provided, the document * will be updated twice, once using the given update and a second time * once the stream has been read, chunked, and stored to include meta data * information such as the stream data's message digest. * * @param {object} options - The options to use. * @param {object} options.doc - The document to insert. * @param {ReadableStream} [options.stream] - A WHATWG Readable stream to read * from to associate chunked data with this document. * @param {number} [options.chunkSize=1048576] - The size, in bytes, of the * chunks to break the incoming stream data into. * @param {object} [options.recipients=[]] - A set of JWE recipients to * encrypt the document for; if present, recipients will be added to any * existing recipients; to remove existing recipients, modify the * `encryptedDoc.jwe.recipients` field. * @param {Function} [options.keyResolver=this.keyResolver] - A function that * returns a Promise that resolves a key ID to a DH public key. * @param {object} [options.keyAgreementKey=this.keyAgreementKey] - A * KeyAgreementKey API for deriving shared KEKs for wrapping content * encryption keys. * @param {object} [options.hmac=this.hmac] - An HMAC API for blinding * indexable attributes. * @param {object} [options.additionalProtectedParams] - Extra members merged * into the document envelope's JWE protected header (the AEAD-authenticated * AAD); verify them by parsing `jwe.protected` after a successful decrypt. * @param {boolean} [options.chunkedAad=true] - When a `stream` is given, bind * each stream chunk to its 0-based index in the AEAD AAD so that reordering, * substituting, or dropping a chunk fails the read. Readers must be upgraded * before writers; pass `false` to emit the legacy chunk format. * @param {object} options.transport - The Transport instance to use. * * @returns {Promise} - Resolves to the updated document. */ update({ doc, stream, chunkSize, recipients, keyResolver, keyAgreementKey, hmac, additionalProtectedParams, chunkedAad, transport }?: IWriteOptions): Promise; /** * Updates an index for the given document, without updating the document * contents itself. An index entry will be updated and sent to the EDV; its * sequence number must match the document's current sequence number or the * update will be rejected with an `InvalidStateError`. Recovery from this * error requires fetching the latest document and trying again. * * Note: If the index does not exist or the document does not have an * existing entry for the index, it will be added. * * @param {object} options - The options to use. * @param {object} options.doc - The document to create or update an index * for. * @param {object} [options.hmac=this.hmac] - An HMAC API for blinding * indexable attributes. * @param {object} options.transport - The Transport instance to use. * * @returns {Promise} - Resolves once the operation completes. */ updateIndex({ doc, hmac, transport }?: { doc?: IEDVDocument; hmac?: IHMAC; transport?: Transport; }): Promise; /** * Deletes a document from the EDV. * * @param {object} options - The options to use. * @param {object} options.doc - The document to delete. * @param {object} [options.recipients=[]] - A set of JWE recipients to * encrypt the document for; if present, recipients will be added to * any existing recipients; to remove existing recipients, modify * the `encryptedDoc.jwe.recipients` field. * @param {Function} [options.keyResolver=this.keyResolver] - A function that * returns a Promise that resolves a key ID to a DH public key. * @param {object} [options.keyAgreementKey=this.keyAgreementKey] - A * KeyAgreementKey API for deriving shared KEKs for wrapping content * encryption keys. * @param {object} options.transport - The Transport instance to use. * * @returns {Promise} - Resolves to `true` if the document was * deleted. */ delete({ doc, recipients, keyResolver, keyAgreementKey, transport }?: { doc?: IEDVDocument; recipients?: IRecipientTemplate[]; keyResolver?: IKeyResolver; keyAgreementKey?: IKeyAgreementKey; transport?: Transport; }): Promise; /** * Gets a document from the EDV by its ID. * * @param {object} options - The options to use. * @param {string} options.id - The ID of the document to get. * @param {object} [options.keyAgreementKey=this.keyAgreementKey] - A * KeyAgreementKey API for deriving a shared KEK to unwrap the content * encryption key. * @param {object} options.transport - The Transport instance to use. * * @returns {Promise} - Resolves to the document. */ get({ id, keyAgreementKey, transport }?: { id?: string; keyAgreementKey?: IKeyAgreementKey; transport?: Transport; }): Promise; /** * Gets a `ReadableStream` to read the chunked data associated with a * document. * * @param {object} options - The options to use. * @param {object} options.doc - The document to get a stream for. * @param {object} [options.keyAgreementKey=this.keyAgreementKey] - A * KeyAgreementKey API for deriving a shared KEK to unwrap the content * encryption key. * @param {object} options.transport - The Transport instance to use. * * @returns {Promise} - Resolves to a `ReadableStream` to read * the chunked data from. */ getStream({ doc, keyAgreementKey, transport }?: { doc?: IEDVDocument; keyAgreementKey?: IKeyAgreementKey; transport?: Transport; }): Promise>; /** * Counts how many documents match a query in an EDV. * * @see find - For more detailed documentation on the search options. * * @param {object} options - The options to use. * @param {object} [options.keyAgreementKey=this.keyAgreementKey] - A * KeyAgreementKey API for deriving a shared KEK to unwrap the content * encryption key. * @param {object} [options.hmac=this.hmac] - An HMAC API for blinding * indexable attributes. * @param {object|Array} [options.equals] - An object with key-value * attribute pairs to match or an array of such objects. * @param {string|Array} [options.has] - A string with an attribute name to * match or an array of such strings. * @param {object} options.transport - The Transport instance to use. * * @returns {Promise} - Resolves to the number of matching documents. */ count({ keyAgreementKey, hmac, equals, has, transport }?: ICountOptions): Promise; /** * Finds documents based on their attributes. Currently, matching can be * performed using an `equals` or a `has` filter (but not both at once). * * The `equals` filter is an object with key-value attribute pairs. Any * document that matches *all* given key-value attribute pairs will be * returned. If equals is an array, it may contain multiple such filters -- * whereby the results will be all documents that matched any one of the * filters. If the document's value for a matching a key is an array and * the array contains a matching value, the document will be considered * a match (provided that other key-value attribute pairs also match). * * The `has` filter is a string representing the attribute name or an * array of such strings. If an array is used, then the results will only * contain documents that possess *all* of the attributes listed. * * @param {object} options - The options to use. * @param {object} [options.keyAgreementKey=this.keyAgreementKey] - A * KeyAgreementKey API for deriving a shared KEK to unwrap the content * encryption key. * @param {object} [options.hmac=this.hmac] - An HMAC API for blinding * indexable attributes. * @param {object|Array} [options.equals] - An object with key-value * attribute pairs to match or an array of such objects. * @param {string|Array} [options.has] - A string with an attribute name to * match or an array of such strings. * @param {boolean} [options.returnDocuments] - Set to `false` to * request only document IDs from the server (not full documents); note * that a server that does not accept this option will return full * documents, so either return value is possible. * @param {boolean} [options.count] - Set to `false` to find all documents * that match a query or to `true` to give a count of documents. * @param {number} [options.limit] - Set to limit the number of documents * to be returned from a query (min=1, max=1000). * @param {string} [options.cursor] - An opaque pagination cursor from a * previous page's result, passed back verbatim to resume after that page. * @param {object} options.transport - The Transport instance to use. * * @returns {Promise} - Resolves to the matching documents: * {documents: [...]}. When the server paginates, the result also includes * `hasMore` (whether more results remain) and, if provided, an opaque * `cursor` to pass back in a subsequent `find` to fetch the next page. */ find({ keyAgreementKey, hmac, equals, has, returnDocuments, count, limit, cursor, transport }?: IFindOptions): Promise; /** * Gets the configuration for an EDV. * * @param {object} options - The options to use. * @param {string} [options.id] - The ID of the EDV config. * @param {object} options.transport - The Transport instance to use. * * @returns {Promise} - Resolves to the configuration for the EDV. */ getConfig({ id, transport }?: { id?: string; transport?: Transport; }): Promise; /** * Updates an EDV configuration. The new configuration `sequence` must * be incremented by `1` over the previous configuration or the update will * fail. * * @param {object} options - The options to use. * @param {object} options.config - The new EDV config. * @param {object} options.transport - The Transport instance to use. * * @returns {Promise} - Resolves once the operation completes. */ updateConfig({ config, transport }?: { config?: IEDVConfig; transport?: Transport; }): Promise; /** * Generates a multibase encoded random 128-bit identifier for a document. * * @returns {Promise} - Resolves to the identifier. */ static generateId(): Promise; generateId(): Promise; _updateStream({ doc, stream, chunkSize, recipients, keyResolver, keyAgreementKey, hmac, additionalProtectedParams, chunkedAad, transport }: any): Promise; } //# sourceMappingURL=EdvClientCore.d.ts.map