UNPKG

@nfen/webcrypto-ts

Version:
99 lines 2.94 kB
import { AesProxiedCryptoKeys } from "../aes/shared.js"; import { HmacProxiedCryptoKey } from "../hmac/index.js"; import * as params from "../params.js"; import { HkdfKeyMaterial, HkdfProxiedKeyMaterial } from "./shared.js"; /** * Generate key material for deriving * @example * ```ts * const keyMaterial = await HKDF.generateKeyMaterial("raw", new TextEncoder().encode("lots_of_entropy")); * ``` */ export declare const generateKeyMaterial: (format: KeyFormat, key: BufferSource, extractable?: boolean) => Promise<HkdfProxiedKeyMaterial>; /** * Derive a shared key from HKDF key material * @example * ```ts * const hmacParams: params.EnforcedHmacKeyGenParams = { * name: Authentication.Alg.Code.HMAC, * hash: SHA.Alg.Variant.SHA_512, * length: 512, * }; * const salt = await Random.Salt.generate(); * const info = await Random.getValues(6); * let key = await HKDF.deriveKey( * { salt, info, hash: "SHA-512" }, * keyMaterial, * hmacParams * ); * ``` * @example * ```ts * const hmacParams: params.EnforcedHmacKeyGenParams = { * name: Authentication.Alg.Code.HMAC, * hash: SHA.Alg.Variant.SHA_512, * length: 512, * }; * const salt = await Random.Salt.generate(); * const info = await Random.getValues(6); * let key = await keyMaterial.deriveKey( * { salt, info, hash: "SHA-512" }, * hmacParams * ); * ``` * @example * ```ts * const keyMaterial = await HKDF.generateKeyMaterial( * "raw", * await Random.getValues(16) * ); * let key = await HKDF.deriveKey( * { * hash: "SHA-256", * salt, * }, * keyMaterial.self, * { * name: "AES-GCM", * length: 256, * } * ); * ``` * @example * ```ts * const key = await keyMaterial.deriveKey( * { * hash: "SHA-256", * salt, * }, * { * name: "AES-GCM", * length: 256, * } * ); */ export declare const deriveKey: (algorithm: Omit<params.EnforcedHkdfParams, "name">, baseKey: HkdfKeyMaterial, derivedKeyType: params.EnforcedAesKeyGenParams | params.EnforcedHmacKeyGenParams, extractable?: boolean, keyUsages?: KeyUsage[]) => Promise<HmacProxiedCryptoKey | AesProxiedCryptoKeys>; /** * Derive a number bits with a given key material * @example * ```ts * const salt = await Random.Salt.generate(); * const info = await Random.getValues(6); * const bits = await HKDF.deriveBits( * { salt, info, hash: "SHA-512" }, * keyMaterial, * 128 * ); * ``` * @example * ```ts * const salt = await Random.Salt.generate(); * const info = await Random.getValues(6); * const bits = await keyMaterial.deriveBits( * { salt, info, hash: "SHA-512" }, * 128 * ); * ``` */ export declare const deriveBits: (algorithm: Omit<params.EnforcedHkdfParams, "name">, baseKey: HkdfKeyMaterial, length: number) => Promise<ArrayBuffer>; //# sourceMappingURL=hkdf.d.ts.map