diff --git a/index.d.ts b/index.d.ts index 85017a2..1869a65 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1808,6 +1808,54 @@ declare global { n: number, options: { encoding: "hex" | "base64" | "base64url" } ): string + + /** + * HMAC signature over `data`, keyed with `key`. + * + * Supported algorithms: `sha1` (TOTP/RFC 6238 requires it), `sha256`, + * `sha512`. MD5 is not offered. `key` must not be empty. Output defaults + * to hex. + * + * @param alg hash algorithm, case-insensitive + * @param key secret key (string = UTF-8, or bytes) + * @param data payload (string = UTF-8, or bytes) + * @param options.encoding `hex` (default) | `base64` | `base64url` | `bytes` + */ + hmac( + alg: "sha1" | "sha256" | "sha512" | (string & {}), + key: string | Int8Array, + data: string | Int8Array + ): string + hmac( + alg: "sha1" | "sha256" | "sha512" | (string & {}), + key: string | Int8Array, + data: string | Int8Array, + options: { encoding: "bytes" } + ): Int8Array + hmac( + alg: "sha1" | "sha256" | "sha512" | (string & {}), + key: string | Int8Array, + data: string | Int8Array, + options: { encoding: "hex" | "base64" | "base64url" } + ): string + hmac( + alg: string, + key: string | Int8Array, + data: string | Int8Array, + options: { encoding: ByteEncoding } + ): string | Int8Array + + /** + * Constant-time comparison of two values (`hmac.Equal`). + * + * Use this for signatures, tokens and TOTP codes — never `===`, which + * returns early and leaks how many leading characters matched. + * Different lengths return `false` immediately: the length is not secret. + */ + timingSafeEqual( + a: string | Int8Array, + b: string | Int8Array + ): boolean } interface JsonPackage {