hpke-js
Version:
A Hybrid Public Key Encryption (HPKE) module for various JavaScript runtimes
34 lines (33 loc) • 1.35 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", "@noble/hashes/hmac", "@noble/hashes/sha512", "@hpke/common"], factory);
}
})(function (require, exports) {
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HkdfSha384 = void 0;
const hmac_1 = require("@noble/hashes/hmac");
const sha512_1 = require("@noble/hashes/sha512");
const common_1 = require("@hpke/common");
class HkdfSha384 extends common_1.HkdfSha384Native {
async extract(salt, ikm) {
await this._setup();
if (salt.byteLength === 0) {
salt = new ArrayBuffer(this.hashSize);
}
if (salt.byteLength !== this.hashSize) {
return (0, hmac_1.hmac)(sha512_1.sha384, new Uint8Array(salt), new Uint8Array(ikm))
.buffer;
}
const key = await this._api.importKey("raw", salt, this.algHash, false, [
"sign",
]);
return await this._api.sign("HMAC", key, ikm);
}
}
exports.HkdfSha384 = HkdfSha384;
});