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