@hpke/core
Version:
A Hybrid Public Key Encryption (HPKE) core module for various JavaScript runtimes
40 lines (39 loc) • 1.45 kB
JavaScript
(function (factory) {
if (typeof module === "object" && typeof module.exports === "object") {
var v = factory(require, exports);
if (v !== undefined) module.exports = v;
}
else if (typeof define === "function" && define.amd) {
define(["require", "exports", "@hpke/common", "./encryptionContext.js"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SenderContextImpl = void 0;
const common_1 = require("@hpke/common");
const encryptionContext_js_1 = require("./encryptionContext.js");
class SenderContextImpl extends encryptionContext_js_1.EncryptionContextImpl {
constructor(api, kdf, params, enc) {
super(api, kdf, params);
Object.defineProperty(this, "enc", {
enumerable: true,
configurable: true,
writable: true,
value: void 0
});
this.enc = enc;
}
async seal(data, aad = common_1.EMPTY.buffer) {
let ct;
try {
ct = await this._ctx.key.seal(this.computeNonce(this._ctx), data, aad);
}
catch (e) {
throw new common_1.SealError(e);
}
this.incrementSeq(this._ctx);
return ct;
}
}
exports.SenderContextImpl = SenderContextImpl;
});