From ce0ac300f55ce849fbc3dda5b66456a829ca0dd2 Mon Sep 17 00:00:00 2001 From: Sebastian Frank Date: Wed, 4 Nov 2026 14:20:15 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20types(hooks):=20crypto.hmac=20und?= =?UTF-8?q?=20timingSafeEqual=20(#60)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit hmac mit sha1|sha256|sha512, Schlüssel/Daten als String oder Bytes und encoding-abhängigem Rückgabetyp; timingSafeEqual als boolean. Kommentare nennen die Begründung für SHA-1 (TOTP) und die Length-Grenze. Refs cms/tibi-server#60 --- index.d.ts | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) 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 {