UNPKG

@nfen/webcrypto-ts

Version:
72 lines 2.36 kB
import * as params from "../params.js"; import * as proxy from "../proxy.js"; export interface HmacCryptoKey extends CryptoKey { _hmacKeyBrand: any; } export interface HmacProxiedCryptoKey extends proxy.ProxiedCryptoKey<HmacCryptoKey> { sign: (data: BufferSource) => Promise<ArrayBuffer>; verify: (signature: BufferSource, data: BufferSource) => Promise<boolean>; exportKey: (format: KeyFormat) => Promise<JsonWebKey | ArrayBuffer>; } /** @hidden */ export declare const handler: ProxyHandler<HmacCryptoKey>; export declare namespace Alg { enum Code { HMAC = "HMAC" } type Codes = `${Code}`; } /** * Generate a new HMAC key * @example * ```ts * const key = await HMAC.generateKey(); * ``` */ export declare const generateKey: (algorithm?: Omit<params.EnforcedHmacKeyGenParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]) => Promise<HmacProxiedCryptoKey>; /** * Import an HMAC key from the specified format * @example * ```ts * const key = await HMAC.importKey("jwk", jwk, {hash: "SHA-512"}); * ``` */ export declare const importKey: (format: KeyFormat, key: BufferSource | JsonWebKey, algorithm: Omit<params.EnforcedHmacImportParams, "name">, extractable?: boolean, keyUsages?: KeyUsage[]) => Promise<HmacProxiedCryptoKey>; /** * Export an HMAC key into the specified format * @example * ```ts * const jwk = await HMAC.exportKey("jwk", key.self); * ``` * @example * ```ts * const jwk = await key.exportKey("jwk"); * ``` */ export declare function exportKey(format: KeyFormat, key: HmacCryptoKey): Promise<JsonWebKey | ArrayBuffer>; /** * Sign a given payload * @example * ```ts * const message = new TextEncoder().encode("a message"); * const signature = await HMAC.sign(key.self, message); * ``` * ```ts * const message = new TextEncoder().encode("a message"); * const signature = await key.sign(message); * ``` */ export declare function sign(key: HmacCryptoKey, data: BufferSource): Promise<ArrayBuffer>; /** * Verify a given signature * @example * ```ts * const isVerified = await HMAC.verify(key, signature, message); * ``` * @example * ```ts * const isVerified = await key.verify(signature, message); * ``` */ export declare function verify(key: HmacCryptoKey, signature: BufferSource, data: BufferSource): Promise<boolean>; //# sourceMappingURL=index.d.ts.map