UNPKG

cryptobox-hd

Version:

High-level API with persistent storage for Proteus-HD.

34 lines (33 loc) 1.37 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var Proteus = require("proteus-hd"); var DecryptionError_1 = require("./DecryptionError"); var CryptoboxSession = (function () { function CryptoboxSession(id, pk_store, session) { this.id = id; this.pk_store = pk_store; this.session = session; Object.freeze(this); } CryptoboxSession.prototype.decrypt = function (ciphertext) { if (ciphertext.byteLength === 0) { return Promise.reject(new DecryptionError_1.DecryptionError('Cannot decrypt an empty ArrayBuffer.')); } var envelope = Proteus.message.Envelope.deserialise(ciphertext); return this.session.decrypt(this.pk_store, envelope); }; CryptoboxSession.prototype.encrypt = function (plaintext, confuse_pre_key_id) { return this.session.encrypt(plaintext, confuse_pre_key_id) .then(function (ciphertext) { return ciphertext.serialise(); }); }; CryptoboxSession.prototype.fingerprint_local = function () { return this.session.local_identity.public_key.fingerprint(); }; CryptoboxSession.prototype.fingerprint_remote = function () { return this.session.remote_identity.fingerprint(); }; return CryptoboxSession; }()); exports.CryptoboxSession = CryptoboxSession;