hpke-js
Version:
A Hybrid Public Key Encryption (HPKE) module for various JavaScript runtimes
18 lines (17 loc) • 608 B
JavaScript
import { HkdfSha384Native, hmac, sha384 } 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);
}
}