UNPKG

@wireapp/cryptobox

Version:

High-level API with persistent storage for Proteus.

62 lines (61 loc) 2.35 kB
/// <reference types="node" /> import * as ProteusKeys from '@wireapp/proteus/dist/keys/root'; import CryptoboxCRUDStore from './store/CryptoboxCRUDStore'; import CryptoboxSession from './CryptoboxSession'; import EventEmitter = require('events'); export interface SessionFromMessageTuple extends Array<CryptoboxSession | Uint8Array> { 0: CryptoboxSession; 1: Uint8Array; } declare class Cryptobox extends EventEmitter { static TOPIC: { NEW_PREKEYS: string; NEW_SESSION: string; }; private cachedPreKeys; private cachedSessions; private logger; private minimumAmountOfPreKeys; private pk_store; private queue; private store; lastResortPreKey: ProteusKeys.PreKey | undefined; identity: ProteusKeys.IdentityKeyPair | undefined; VERSION: string; constructor(cryptoBoxStore: CryptoboxCRUDStore, minimumAmountOfPreKeys?: number); private save_session_in_cache(session); private load_session_from_cache(session_id); private remove_session_from_cache(session_id); create(): Promise<Array<ProteusKeys.PreKey>>; load(): Promise<Array<ProteusKeys.PreKey>>; private init(); get_serialized_last_resort_prekey(): Promise<{ id: number; key: string; }>; get_serialized_standard_prekeys(): Promise<Array<{ id: number; key: string; }>>; private publish_event(topic, event); private publish_prekeys(newPreKeys); private publish_session_id(session); private refill_prekeys(); private create_new_identity(); session_from_prekey(session_id: string, pre_key_bundle: ArrayBuffer): Promise<CryptoboxSession>; private session_from_message(session_id, envelope); session_load(session_id: string): Promise<CryptoboxSession>; private session_cleanup(session); private session_save(session); private session_update(session); session_delete(session_id: string): Promise<string>; private create_last_resort_prekey(); serialize_prekey(prekey: ProteusKeys.PreKey): { id: number; key: string; }; private new_prekeys(start, size?); encrypt(session_id: string, payload: string | Uint8Array, pre_key_bundle: ArrayBuffer): Promise<ArrayBuffer>; decrypt(session_id: string, ciphertext: ArrayBuffer): Promise<Uint8Array>; } export default Cryptobox;