Skip to content

Commit cb165be

Browse files
committed
feat(module): added checksum
1 parent 6b5a56b commit cb165be

File tree

3 files changed

+63
-8
lines changed

3 files changed

+63
-8
lines changed

packages/types/src/checksum.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/**
2+
* An object that provides a checksum of data provided in chunks to `update`.
3+
* The checksum may be performed incrementally as chunks are received or all
4+
* at once when the checksum is finalized, depending on the underlying
5+
* implementation.
6+
*
7+
* It's recommended to compute checksum incrementally to avoid reading the
8+
* entire payload in memory.
9+
*
10+
* The constructor may accept an optional secret key while computing checksum
11+
* value, when using HMAC. If provided, this secret key would be used when
12+
* computing checksum.
13+
*/
14+
export interface Checksum {
15+
/**
16+
* Constant length of the digest created by the algorithm in bytes.
17+
*/
18+
digestLength?: string;
19+
20+
/**
21+
* Creates a new checksum object that contains a deep copy of the internal
22+
* state of the current `Checksum` object.
23+
* This is required by certain languages like Java.
24+
*/
25+
copy?: () => Checksum;
26+
27+
/**
28+
* Returns the digest of all of the data passed.
29+
*
30+
* This interface may be async, following digest interface standards
31+
* for language.
32+
* For the purpose of this document, we assume it's called synchronously.
33+
*/
34+
digest: () => Promise<Uint8Array>;
35+
36+
/**
37+
* Allows marking a checksum for checksums that support the ability
38+
* to mark and reset.
39+
*
40+
* @param {number} readLimit - The maximum limit of bytes that can be read
41+
* before the mark position becomes invalid.
42+
*/
43+
mark?: (readLimit: number) => void;
44+
45+
/**
46+
* Resets the checksum to its initial value.
47+
*/
48+
reset: () => void;
49+
50+
/**
51+
* Adds a chunk of data for which checksum needs to be computed.
52+
* This can be called many times with new data as it is streamed.
53+
*
54+
* Implementations may override this method which passes second param
55+
* which makes Checksum object stateless.
56+
*
57+
* @param {Uint8Array} chunk - The buffer to update checksum with.
58+
*/
59+
update(chunk: Uint8Array): void;
60+
}

packages/types/src/crypto.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ export type SourceData = string | ArrayBuffer | ArrayBufferView;
44
* An object that provides a hash of data provided in chunks to `update`. The
55
* hash may be performed incrementally as chunks are received or all at once
66
* when the hash is finalized, depending on the underlying implementation.
7+
*
8+
* @deprecated use {@link Checksum}
79
*/
810
export interface Hash {
911
/**
@@ -40,11 +42,3 @@ export interface HashConstructor {
4042
export interface StreamHasher<StreamType = any> {
4143
(hashCtor: HashConstructor, stream: StreamType): Promise<Uint8Array>;
4244
}
43-
44-
/**
45-
* A function that returns a promise fulfilled with bytes from a
46-
* cryptographically secure pseudorandom number generator.
47-
*/
48-
export interface randomValues {
49-
(byteLength: number): Promise<Uint8Array>;
50-
}

packages/types/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export * from "./abort";
22
export * from "./auth";
3+
export * from "./checksum";
34
export * from "./client";
45
export * from "./command";
56
export * from "./credentials";

0 commit comments

Comments
 (0)