matrix-react-sdk
Version:
SDK for matrix.org using React
50 lines (49 loc) • 2.35 kB
TypeScript
/**
* Encrypted format of a pickle key, as stored in IndexedDB.
*/
export interface EncryptedPickleKey {
/** The encrypted payload. */
encrypted?: BufferSource;
/** Initialisation vector for the encryption. */
iv?: BufferSource;
/** The encryption key which was used to encrypt the payload. */
cryptoKey?: CryptoKey;
}
/**
* Calculates the `additionalData` for the AES-GCM key used by the pickling processes. This
* additional data is *not* encrypted, but *is* authenticated. The additional data is constructed
* from the user ID and device ID provided.
*
* The later-constructed pickle key is used to decrypt values, such as access tokens, from IndexedDB.
*
* See https://developer.mozilla.org/en-US/docs/Web/API/AesGcmParams for more information on
* `additionalData`.
*
* @param {string} userId The user ID who owns the pickle key.
* @param {string} deviceId The device ID which owns the pickle key.
* @return {Uint8Array} The additional data as a Uint8Array.
*/
export declare function getPickleAdditionalData(userId: string, deviceId: string): Uint8Array;
/**
* Encrypt the given pickle key, ready for storage in the database.
*
* @param pickleKey - The key to be encrypted.
* @param userId - The user ID the pickle key belongs to.
* @param deviceId - The device ID the pickle key belongs to.
*
* @returns Data object ready for storing in indexeddb.
*/
export declare function encryptPickleKey(pickleKey: Uint8Array, userId: string, deviceId: string): Promise<EncryptedPickleKey | undefined>;
/**
* Decrypts the provided data into a pickle key and base64-encodes it ready for use elsewhere.
*
* If `data` is undefined in part or in full, returns undefined.
*
* If crypto functions are not available, returns undefined regardless of input.
*
* @param data An object containing the encrypted pickle key data: encrypted payload, initialization vector (IV), and crypto key. Typically loaded from indexedDB.
* @param userId The user ID the pickle key belongs to.
* @param deviceId The device ID the pickle key belongs to.
* @returns A promise that resolves to the encoded pickle key, or undefined if the key cannot be built and encoded.
*/
export declare function buildAndEncodePickleKey(data: EncryptedPickleKey | undefined, userId: string, deviceId: string): Promise<string | undefined>;