UNPKG

@hpke/core

Version:

A Hybrid Public Key Encryption (HPKE) core module for various JavaScript runtimes

78 lines (77 loc) 2.99 kB
(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", "./utils/emitNotSupported.js"], factory); } })(function (require, exports) { "use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SenderExporterContextImpl = exports.RecipientExporterContextImpl = exports.ExporterContextImpl = void 0; const common_1 = require("@hpke/common"); const emitNotSupported_js_1 = require("./utils/emitNotSupported.js"); // b"sec" const LABEL_SEC = new Uint8Array([115, 101, 99]); class ExporterContextImpl { constructor(api, kdf, exporterSecret) { Object.defineProperty(this, "_api", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "exporterSecret", { enumerable: true, configurable: true, writable: true, value: void 0 }); Object.defineProperty(this, "_kdf", { enumerable: true, configurable: true, writable: true, value: void 0 }); this._api = api; this._kdf = kdf; this.exporterSecret = exporterSecret; } async seal(_data, _aad) { return await (0, emitNotSupported_js_1.emitNotSupported)(); } async open(_data, _aad) { return await (0, emitNotSupported_js_1.emitNotSupported)(); } async export(exporterContext, len) { if (exporterContext.byteLength > common_1.INPUT_LENGTH_LIMIT) { throw new common_1.InvalidParamError("Too long exporter context"); } try { return await this._kdf.labeledExpand(this.exporterSecret, LABEL_SEC, new Uint8Array(exporterContext), len); } catch (e) { throw new common_1.ExportError(e); } } } exports.ExporterContextImpl = ExporterContextImpl; class RecipientExporterContextImpl extends ExporterContextImpl { } exports.RecipientExporterContextImpl = RecipientExporterContextImpl; class SenderExporterContextImpl extends ExporterContextImpl { constructor(api, kdf, exporterSecret, enc) { super(api, kdf, exporterSecret); Object.defineProperty(this, "enc", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.enc = enc; return; } } exports.SenderExporterContextImpl = SenderExporterContextImpl; });