hpke-js
Version:
A Hybrid Public Key Encryption (HPKE) module for various JavaScript runtimes
20 lines (19 loc) • 684 B
JavaScript
import { hmac } from "@noble/hashes/hmac";
import { sha384 } from "@noble/hashes/sha512";
import { HkdfSha384Native } from "@hpke/common";
export class HkdfSha384 extends HkdfSha384Native {
async extract(salt, ikm) {
await this._setup();
if (salt.byteLength === 0) {
salt = new ArrayBuffer(this.hashSize);
}
if (salt.byteLength !== this.hashSize) {
return hmac(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);
}
}