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