UNPKG

@wireapp/cryptobox

Version:

High-level API with persistent storage for Proteus.

71 lines (70 loc) 2.72 kB
/// <reference types="node" /> import { keys as ProteusKeys } from '@wireapp/proteus'; import type { CRUDEngineBaseCollection } from '@wireapp/store-engine'; import { EventEmitter } from 'events'; import { CryptoboxSession } from './CryptoboxSession'; import type { SerializedCryptobox } from './SerializedCryptobox'; declare enum TOPIC { NEW_PREKEYS = "new-prekeys", NEW_SESSION = "new-session" } export interface Cryptobox { on(event: TOPIC.NEW_PREKEYS, listener: (prekeys: ProteusKeys.PreKey[]) => void): this; on(event: TOPIC.NEW_SESSION, listener: (session: string) => void): this; } export declare class Cryptobox extends EventEmitter { private cachedSessions; private queues; private readonly minimumAmountOfPreKeys; private readonly store; private identity; static VERSION: string; static readonly TOPIC: typeof TOPIC; lastResortPreKey: ProteusKeys.PreKey | undefined; constructor(engine: CRUDEngineBaseCollection, minimumAmountOfPreKeys?: number); private get_session_queue; private save_session_in_cache; private load_session_from_cache; private remove_session_from_cache; create(entropyData?: Uint8Array): Promise<ProteusKeys.PreKey[]>; getIdentity(): ProteusKeys.IdentityKeyPair; load(): Promise<ProteusKeys.PreKey[]>; private init; get_serialized_last_resort_prekey(): Promise<{ id: number; key: string; }>; private get_prekey; protected get_prekey_bundle(preKeyId?: number): Promise<ProteusKeys.PreKeyBundle>; get_serialized_standard_prekeys(): Promise<{ id: number; key: string; }[]>; private publish_event; private publish_prekeys; private publish_session_id; private refill_prekeys; private create_new_identity; private save_identity; session_from_prekey(sessionId: string, preKeyBundle: ArrayBuffer): Promise<CryptoboxSession>; private session_from_message; session_load(sessionId: string): Promise<CryptoboxSession>; private session_save; private session_update; session_delete(sessionId: string): Promise<string>; private create_last_resort_prekey; serialize_prekey(prekey: ProteusKeys.PreKey): { id: number; key: string; }; private new_prekeys; encrypt(sessionId: string, payload: string | Uint8Array, preKeyBundle?: ArrayBuffer): Promise<ArrayBuffer>; decrypt(sessionId: string, ciphertext: ArrayBuffer): Promise<Uint8Array>; private deleteData; private importIdentity; private importPreKeys; private importSessions; deserialize(payload: SerializedCryptobox): Promise<ProteusKeys.PreKey[]>; serialize(): Promise<SerializedCryptobox>; } export {};