functionalscript
Version:
FunctionalScript is a purely functional subset of JavaScript
29 lines (28 loc) • 1.02 kB
TypeScript
/**
* Provides an implementation of HMAC (Hash-based Message Authentication Code).
*
* https://en.wikipedia.org/wiki/HMAC
*
* @module
*
* @example
*
* ```ts
* import { vec } from '../../types/bit_vec/module.f.ts'
* import { msbUtf8 } from '../../text/module.f.ts'
* import { sha256 } from '../sha2/module.f.ts'
*
* const r = hmac(sha256)(msbUtf8('key'))(msbUtf8('The quick brown fox jumps over the lazy dog'))
* if (r !== vec(256n)(0xf7bc83f430538424b13298e6aa6fb143ef4d59a14946175997479dbc2d1a3cd8n)) { throw r }
* ```
*/
import { type Vec } from '../../types/bit_vec/module.f.ts';
import { type Sha2 } from '../sha2/module.f.ts';
/**
* Generates an HMAC (Hash-based Message Authentication Code) using the specified SHA-2 hash function.
*
* @param sha2 - The SHA-2 hash function implementation to use.
* @returns - A function that takes a key and returns another function
* that takes a message and computes the HMAC.
*/
export declare const hmac: (sha2: Sha2) => (k: Vec) => (m: Vec) => Vec;