import { IccReceiptApi } from '../icc-api'; import { IccCryptoXApi } from './icc-crypto-x-api'; import * as models from '../icc-api/model/models'; import { IccDataOwnerXApi } from './icc-data-owner-x-api'; import { AuthenticationProvider } from './auth/AuthenticationProvider'; import { ShareMetadataBehaviour } from './crypto/ShareMetadataBehaviour'; import { ShareResult } from './utils/ShareResult'; import { EntityShareRequest } from '../icc-api/model/requests/EntityShareRequest'; import RequestedPermissionEnum = EntityShareRequest.RequestedPermissionEnum; import { SecureDelegation } from '../icc-api/model/SecureDelegation'; import AccessLevelEnum = SecureDelegation.AccessLevelEnum; import { XHR } from '../icc-api/api/XHR'; import { EncryptedEntityXApi } from './basexapi/EncryptedEntityXApi'; export declare class IccReceiptXApi extends IccReceiptApi implements EncryptedEntityXApi { private readonly crypto; private readonly dataOwnerApi; private readonly autofillAuthor; get headers(): Promise>; constructor(host: string, headers: { [key: string]: string; }, crypto: IccCryptoXApi, dataOwnerApi: IccDataOwnerXApi, autofillAuthor: boolean, authenticationProvider?: AuthenticationProvider, fetchImpl?: (input: RequestInfo, init?: RequestInit) => Promise); /** * Creates a new instance of receipt with initialised encryption metadata (not in the database). * @param user the current user. * @param r initialised data for the receipt. Metadata such as id, creation data, etc. will be automatically initialised, but you can specify * other kinds of data or overwrite generated metadata with this. You can't specify encryption metadata. * @param options optional parameters: * - additionalDelegates: delegates which will have access to the entity in addition to the current data owner and delegates from the * auto-delegations. Must be an object which associates each data owner id with the access level to give to that data owner. May overlap with * auto-delegations, in such case the access level specified here will be used. * - ignoreAutoDelegations: if true the data won't be shared with the autodelegations of the user, but only with additional delegates * - alternateRootDelegation: by default a new entity is created with a root delegation from self to self. In keyless mode this is not possible, * and instead the root delegation will be from self to another. You have to specify which delegate will be part of the root delegation. * @return a new instance of receipt. */ newInstance(user: models.User, r: any, options?: { additionalDelegates?: { [dataOwnerId: string]: AccessLevelEnum; }; ignoreAutoDelegations?: boolean; alternateRootDelegation?: string; }): Promise; /** * Creates a new receipt linked to a document and optionally attaches a blob to it. * @param user the current user. * @param docId the id of the document this receipt refers to. * @param refs an array of reference strings to associate with the receipt. * @param blobType the type of the blob attachment. * @param blob the binary content to attach; if empty (byteLength == 0), no attachment is set. * @return the created receipt, with the attachment set if the blob was non-empty. */ logReceipt(user: models.User, docId: string, refs: Array, blobType: string, blob: ArrayBuffer): Promise; /** * Adds an attachment to a receipt, encrypting it on client side using the encryption keys of the provided receipt. * @param receipt a receipt. * @param blobType the type of the attachment. * @param attachment a attachment for the receipt. * @return the updated receipt. */ encryptAndSetReceiptAttachment(receipt: models.Receipt, blobType: string, attachment: ArrayBuffer | Uint8Array): Promise; /** * Adds an unencrypted attachment to a receipt. * @param receipt a receipt. * @param blobType the type of the attachment. * @param attachment a attachment for the receipt. * @return the updated receipt. */ setClearReceiptAttachment(receipt: models.Receipt, blobType: string, attachment: ArrayBuffer | Uint8Array): Promise; /** * Gets the attachment of a receipt and tries to decrypt it using the encryption keys of the receipt. * @param receipt a receipt. * @param attachmentId id of the attachment of this receipt to retrieve. * @param returnNonDecrypted in case an attachment should have been encrypted and could not be decrypted, return it as is * @param validator optionally a validator function which checks if the decryption was successful. In cases where the receipt has many encryption * keys and it is unclear which one should be used this function can help to detect bad decryptions. * @return the decrypted attachment, if it could be decrypted, else the encrypted attachment. */ getAndDecryptReceiptAttachment(receipt: models.Receipt, attachmentId: string, returnNonDecrypted?: boolean, validator?: (decrypted: ArrayBuffer) => Promise): Promise; /** * Gets the attachment of a receipt and tries to decrypt it using the encryption keys of the receipt. * @param receipt a receipt. * @param attachmentId id of the attachment of this receipt to retrieve. * @param validator optionally a validator function which checks if the decryption was successful. In cases where the receipt has many encryption * keys and it is unclear which one should be used this function can help to detect bad decryptions. * @return an object containing: * - data: the decrypted attachment, if it could be decrypted, else the encrypted attachment. * - wasDecrypted: if the data was successfully decrypted or not */ getAndTryDecryptReceiptAttachment(receipt: models.Receipt, attachmentId: string, validator?: (decrypted: ArrayBuffer) => Promise): Promise<{ data: ArrayBuffer; wasDecrypted: boolean; }>; /** * Compresses, encrypts, and uploads a receipt attachment using the new data attachment endpoint. * Compression is attempted automatically; if the compressed result is not smaller, the original data is used. * @param receipt a receipt. * @param blobType the type of the attachment. * @param attachment the raw attachment data. * @param deflate if true, compress the attachment before uploading. Reliable decompression of compressed data requires version 26.5 of the API and all users to be using at least version 8.7.0 of the SDK * @return the updated receipt. */ encryptCompressAndSetReceiptDataAttachment(receipt: models.Receipt, blobType: string, attachment: ArrayBuffer | Uint8Array, deflate?: boolean): Promise; /** * Compresses and uploads an unencrypted receipt attachment using the new data attachment endpoint. * Compression is attempted automatically; if the compressed result is not smaller, the original data is used. * @param receipt a receipt. * @param blobType the type of the attachment. * @param attachment the raw attachment data. * @param deflate if true, compress the attachment before uploading. Reliable decompression of compressed data requires version 26.5 of the API and all users to be using at least version 8.7.0 of the SDK * @return the updated receipt. */ setClearReceiptDataAttachment(receipt: models.Receipt, blobType: string, attachment: ArrayBuffer | Uint8Array, deflate?: boolean): Promise; /** * Gets a receipt's data attachment by blob type, decrypts it, and decompresses if needed. * Throws if decryption fails. * @param receipt a receipt. * @param blobType the blob type of the attachment to retrieve. * @param returnNonDecrypted in case an attachment should have been encrypted and could not be decrypted, return it as is * @param validator optionally a validator function which checks if the decryption was successful. * @return the decrypted (and decompressed) attachment. */ getAndDecryptReceiptDataAttachment(receipt: models.Receipt, blobType: string, returnNonDecrypted?: boolean, validator?: (decrypted: ArrayBuffer) => Promise): Promise; /** * Gets a receipt's data attachment by blob type, tries to decrypt it, and decompresses if needed. * @param receipt a receipt. * @param blobType the blob type of the attachment to retrieve. * @param validator optionally a validator function which checks if the decryption was successful. * @return an object containing: * - data: the decrypted (and decompressed) attachment, or the raw data if decryption failed. * - wasDecrypted: if the data was successfully decrypted or not. */ getAndTryDecryptReceiptDataAttachment(receipt: models.Receipt, blobType: string, validator?: (decrypted: ArrayBuffer) => Promise): Promise<{ data: ArrayBuffer; wasDecrypted: boolean; }>; /** * Lists the receipts created within the provided date interval, based on the `created` timestamp of the receipt. * Both bounds are inclusive and optional: an undefined bound leaves that side of the interval open. * * Requests made through this api also carry the access control keys headers of the current data owner, which is * what makes receipts reachable only through anonymous delegations visible. Receipts have no encrypted fields, so * the returned entities need no decryption; use {@link getAndTryDecryptReceiptDataAttachment} or * {@link getAndTryDecryptReceiptAttachment} to read their attachments. * * Note that the result is not paginated: when scanning a large database, prefer several calls over successive * sub-intervals to keep each response to a workable size. * * @param startDate the start of the interval as a unix epoch in ms (inclusive), no lower bound if undefined. * @param endDate the end of the interval as a unix epoch in ms (inclusive), no upper bound if undefined. * @param descending whether to sort the result from the most recently created receipt to the oldest. * @return the receipts created within the provided interval. */ listReceiptsBetweenDates(startDate?: number, endDate?: number, descending?: boolean): Promise>; /** * @return if the logged data owner has write access to the content of the given receipt */ hasWriteAccess(receipt: models.Receipt): Promise; /** * Share an existing receipt with other data owners, allowing them to access the non-encrypted data of the receipt and optionally also * the encrypted content, with read-only or read-write permissions. * @param delegateId the id of the data owner which will be granted access to the receipt. * @param receipt the receipt to share. * @param options optional parameters to customize the sharing behaviour: * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a * receipt does not have encrypted content. * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}. * @return the updated entity */ shareWith(delegateId: string, receipt: models.Receipt, options?: { shareSecretIds?: string[]; requestedPermissions?: RequestedPermissionEnum; shareEncryptionKey?: ShareMetadataBehaviour; }): Promise; /** * Share an existing receipt with other data owners, allowing them to access the non-encrypted data of the receipt and optionally also * the encrypted content, with read-only or read-write permissions. * @param receipt the receipt to share. * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options: * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a * receipt does not have encrypted content. * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}. * @return the updated entity */ shareWithMany(receipt: models.Receipt, delegates: { [delegateId: string]: { shareSecretIds?: string[]; requestedPermissions?: RequestedPermissionEnum; shareEncryptionKey?: ShareMetadataBehaviour; }; }): Promise; /** * Share an existing receipt with other data owners, allowing them to access the non-encrypted data of the receipt and optionally also * the encrypted content, with read-only or read-write permissions. * @param receipt the receipt to share. * @param delegates associates the id of data owners which will be granted access to the entity, to the following sharing options: * - shareSecretIds: specifies which secret ids of the entity should be shared. If not provided all secret ids available to the current user will be shared * - shareEncryptionKey: specifies if the encryption key of the access log should be shared with the delegate, giving access to all encrypted * content of the entity, excluding other encrypted metadata (defaults to {@link ShareMetadataBehaviour.IF_AVAILABLE}). Note that by default a * receipt does not have encrypted content. * - requestedPermissions: the requested permissions for the delegate, defaults to {@link RequestedPermissionEnum.MAX_WRITE}. * @return a promise which will contain the result of the operation: the updated entity if the operation was successful or details of the error if * the operation failed. */ tryShareWithMany(receipt: models.Receipt, delegates: { [delegateId: string]: { shareSecretIds?: string[]; requestedPermissions?: RequestedPermissionEnum; shareEncryptionKey?: ShareMetadataBehaviour; }; }): Promise>; /** * Retrieves the data owners that have access to the given receipt, along with their access levels. * @param entity the receipt. * @return an object containing a map of data owner ids to their access levels, and a flag indicating if there are unknown anonymous data owners. */ getDataOwnersWithAccessTo(entity: models.Receipt): Promise<{ permissionsByDataOwnerId: { [p: string]: AccessLevelEnum; }; hasUnknownAnonymousDataOwners: boolean; }>; /** * Retrieves the encryption keys of the given receipt. * @param entity the receipt. * @return the encryption key ids. */ getEncryptionKeysOf(entity: models.Receipt): Promise; /** * Creates or updates de-anonymization metadata for the given receipt, allowing the specified delegates to * identify the data owners that have access to it. * @param entity the receipt. * @param delegates the data owner ids for which to create de-anonymization metadata. */ createDelegationDeAnonymizationMetadata(entity: models.Receipt, delegates: string[]): Promise; }