UNPKG

1.74 kBTypeScriptView Raw
1export declare type SourceData = string | ArrayBuffer | ArrayBufferView;
2/**
3 * An object that provides a hash of data provided in chunks to `update`. The
4 * hash may be performed incrementally as chunks are received or all at once
5 * when the hash is finalized, depending on the underlying implementation.
6 */
7export interface Hash {
8 /**
9 * Adds a chunk of data to the hash. If a buffer is provided, the `encoding`
10 * argument will be ignored. If a string is provided without a specified
11 * encoding, implementations must assume UTF-8 encoding.
12 *
13 * Not all encodings are supported on all platforms, though all must support
14 * UTF-8.
15 */
16 update(toHash: SourceData, encoding?: "utf8" | "ascii" | "latin1"): void;
17 /**
18 * Finalizes the hash and provides a promise that will be fulfilled with the
19 * raw bytes of the calculated hash.
20 */
21 digest(): Promise<Uint8Array>;
22}
23/**
24 * A constructor for a hash that may be used to calculate an HMAC. Implementing
25 * classes should not directly hold the provided key in memory beyond the
26 * lexical scope of the constructor.
27 */
28export interface HashConstructor {
29 new (secret?: SourceData): Hash;
30}
31/**
32 * A function that calculates the hash of a data stream. Determining the hash
33 * will consume the stream, so only replayable streams should be provided to an
34 * implementation of this interface.
35 */
36export interface StreamHasher<StreamType = any> {
37 (hashCtor: HashConstructor, stream: StreamType): Promise<Uint8Array>;
38}
39/**
40 * A function that returns a promise fulfilled with bytes from a
41 * cryptographically secure pseudorandom number generator.
42 */
43export interface randomValues {
44 (byteLength: number): Promise<Uint8Array>;
45}