✨ types(hooks): crypto.hmac und timingSafeEqual (#60)
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
This commit is contained in:
1 parent
cbec4753a1
commit
ce0ac300f5
1 file changed
+48
Vendored
+48
@@ -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 {
|
||||
|
||||
Reference in new issue
Block a user