Skip to content

Commit bf720a4

Browse files
author
Pepe Cano
authored
🤖 Merge PR DefinitelyTyped#45259 [k6] Update documentation. Add namepaces by @ppcano
* [k6] Update documentation. Add namepaces Fix tests and lint errors * Avoid disabling `no-redundant-jsdoc-2` and fix lint errors
1 parent 321f622 commit bf720a4

10 files changed

+522
-402
lines changed

types/k6/crypto.d.ts

+176-51
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
1-
/*
2-
* Cryptography utilities.
3-
* https://docs.k6.io/docs/k6crypto
4-
*/
5-
61
import { bytes } from '.';
72

83
/**
94
* Generate random bytes.
105
* @param size - Number of bytes to generate.
116
* @returns Random bytes.
12-
* @public
137
*/
148
export function randomBytes(size: number): bytes;
159

1610
/**
1711
* Produce HMAC.
18-
* https://docs.k6.io/docs/hmac-algorithm-secret-data-outputencoding
12+
* https://k6.io/docs/javascript-api/k6-crypto/hmac-algorithm-secret-data-outputencoding
1913
* @param algorithm - Hash algorithm.
2014
* @param secret - Shared secret.
2115
* @param data - Input data.
2216
* @param outputEncoding - Output encoding.
2317
* @returns Produced HMAC.
24-
* @public
2518
*/
2619
export function hmac<OE extends OutputEncoding>(
2720
algorithm: Algorithm,
@@ -32,11 +25,10 @@ export function hmac<OE extends OutputEncoding>(
3225

3326
/**
3427
* Hash with MD4.
35-
* https://docs.k6.io/docs/md4-input-outputencoding
28+
* https://k6.io/docs/javascript-api/k6-crypto/md4-input-outputencoding
3629
* @param input - Data to hash.
3730
* @param outputEncoding - Output encoding.
3831
* @returns MD4 digest.
39-
* @public
4032
*/
4133
export function md4<OE extends OutputEncoding>(
4234
input: string,
@@ -45,11 +37,10 @@ export function md4<OE extends OutputEncoding>(
4537

4638
/**
4739
* Hash with MD5.
48-
* https://docs.k6.io/docs/md5-input-outputencoding
40+
* https://k6.io/docs/javascript-api/k6-crypto/md5-input-outputencoding
4941
* @param input - Data to hash.
5042
* @param outputEncoding - Output encoding.
5143
* @returns MD5 digest.
52-
* @public
5344
*/
5445
export function md5<OE extends OutputEncoding>(
5546
input: string,
@@ -58,11 +49,10 @@ export function md5<OE extends OutputEncoding>(
5849

5950
/**
6051
* Hash with SHA-1.
61-
* https://docs.k6.io/docs/sha1-input-outputencoding
52+
* https://k6.io/docs/javascript-api/k6-crypto/sha1-input-outputencoding
6253
* @param input - Data to hash.
6354
* @param outputEncoding - Output encoding.
6455
* @returns SHA-1 digest.
65-
* @public
6656
*/
6757
export function sha1<OE extends OutputEncoding>(
6858
input: string,
@@ -71,11 +61,10 @@ export function sha1<OE extends OutputEncoding>(
7161

7262
/**
7363
* Hash with SHA-256.
74-
* https://docs.k6.io/docs/sha256-input-outputencoding
64+
* https://k6.io/docs/javascript-api/k6-crypto/sha256-input-outputencoding
7565
* @param input - Data to hash.
7666
* @param outputEncoding - Output encoding.
7767
* @returns SHA-256 digest.
78-
* @public
7968
*/
8069
export function sha256<OE extends OutputEncoding>(
8170
input: string,
@@ -84,11 +73,10 @@ export function sha256<OE extends OutputEncoding>(
8473

8574
/**
8675
* Hash with SHA-384.
87-
* https://docs.k6.io/docs/sha384-input-outputencoding
76+
* https://k6.io/docs/javascript-api/k6-crypto/sha384-input-outputencoding
8877
* @param input - Data to hash.
8978
* @param outputEncoding - Output encoding.
9079
* @returns SHA-384 digest.
91-
* @public
9280
*/
9381
export function sha384<OE extends OutputEncoding>(
9482
input: string,
@@ -97,11 +85,10 @@ export function sha384<OE extends OutputEncoding>(
9785

9886
/**
9987
* Hash with SHA-512.
100-
* https://docs.k6.io/docs/sha512-input-outputencoding
88+
* https://k6.io/docs/javascript-api/k6-crypto/sha512-input-outputencoding
10189
* @param input - Data to hash.
10290
* @param outputEncoding - Output encoding.
10391
* @returns SHA-512 digest.
104-
* @public
10592
*/
10693
export function sha512<OE extends OutputEncoding>(
10794
input: string,
@@ -110,11 +97,10 @@ export function sha512<OE extends OutputEncoding>(
11097

11198
/**
11299
* Hash with SHA-512/224.
113-
* https://docs.k6.io/docs/sha512_224-input-outputencoding
100+
* https://k6.io/docs/javascript-api/k6-crypto/sha512_224-input-outputencoding
114101
* @param input - Data to hash.
115102
* @param outputEncoding - Output encoding.
116103
* @returns SHA-512/224 digest.
117-
* @public
118104
*/
119105
export function sha512_224<OE extends OutputEncoding>(
120106
input: string,
@@ -123,11 +109,10 @@ export function sha512_224<OE extends OutputEncoding>(
123109

124110
/**
125111
* Hash with SHA-512/256.
126-
* https://docs.k6.io/docs/sha512_256-input-outputencoding
112+
* https://k6.io/docs/javascript-api/k6-crypto/sha512_256-input-outputencoding
127113
* @param input - Data to hash.
128114
* @param outputEncoding - Output encoding.
129115
* @returns SHA-512/256 digest.
130-
* @public
131116
*/
132117
export function sha512_256<OE extends OutputEncoding>(
133118
input: string,
@@ -136,11 +121,10 @@ export function sha512_256<OE extends OutputEncoding>(
136121

137122
/**
138123
* Hash with RIPEMD-160.
139-
* https://docs.k6.io/docs/ripemd160-input-outputencoding
124+
* https://k6.io/docs/javascript-api/k6-crypto/ripemd160-input-outputencoding
140125
* @param input - Data to hash.
141126
* @param outputEncoding - Output encoding.
142127
* @returns RIPEMD-160 digest.
143-
* @public
144128
*/
145129
export function ripemd160<OE extends OutputEncoding>(
146130
input: string,
@@ -149,26 +133,23 @@ export function ripemd160<OE extends OutputEncoding>(
149133

150134
/**
151135
* Create a hashing object.
152-
* https://docs.k6.io/docs/createhash-algorithm
136+
* https://k6.io/docs/javascript-api/k6-crypto/createhash-algorithm
153137
* @param algorithm - Hash algorithm.
154138
* @returns Hashing object.
155-
* @public
156139
*/
157140
export function createHash(algorithm: Algorithm): Hasher;
158141

159142
/**
160143
* Create an HMAC hashing object.
161-
* https://docs.k6.io/docs/createhmacalgorithm-secret
144+
* https://k6.io/docs/javascript-api/k6-crypto/createhmac-algorithm-secret
162145
* @param algorithm - Hash algorithm.
163146
* @param secret - Shared secret.
164147
* @returns HMAC hashing object.
165-
* @public
166148
*/
167149
export function createHMAC(algorithm: Algorithm, secret: string): Hasher;
168150

169151
/**
170152
* Hash algorithm.
171-
* @public
172153
*/
173154
export type Algorithm =
174155
| 'md4'
@@ -183,26 +164,22 @@ export type Algorithm =
183164

184165
/**
185166
* String output encoding.
186-
* @public
187167
*/
188168
export type StringEncoding = 'hex' | 'base64' | 'base64url' | 'base64rawurl';
189169

190170
/**
191171
* Binary output encoding.
192-
* @public
193172
*/
194173
export type BinaryEncoding = 'binary';
195174

196175
/**
197176
* Output encoding.
198-
* @public
199177
*/
200178
export type OutputEncoding = StringEncoding | BinaryEncoding;
201179

202180
/**
203181
* Output type. Varies with output encoding.
204182
* @typeParam OE - Output encoding.
205-
* @public
206183
*/
207184
export type Output<OE extends OutputEncoding> = OE extends StringEncoding
208185
? string
@@ -213,21 +190,169 @@ export type Output<OE extends OutputEncoding> = OE extends StringEncoding
213190
/**
214191
* Hashing object.
215192
* https://docs.k6.io/docs/hasher-k6crypto
216-
* @public
217193
*/
218194
export abstract class Hasher {
219-
protected __brand: never;
220-
221-
/**
222-
* Add more data to the string we want to create a hash of.
223-
* @param input - Data to add.
224-
*/
225-
update(input: string): void;
226-
227-
/**
228-
* Return a digest from the data added so far.
229-
* @param outputEncoding - Output encoding.
230-
* @returns Digest of data added so far.
231-
*/
232-
digest<OE extends OutputEncoding>(outputEncoding: OE): Output<OE>;
233-
}
195+
protected __brand: never;
196+
197+
/**
198+
* Add more data to the string we want to create a hash of.
199+
* @param input - Data to add.
200+
*/
201+
update(input: string): void;
202+
203+
/**
204+
* Return a digest from the data added so far.
205+
* @param outputEncoding - Output encoding.
206+
* @returns Digest of data added so far.
207+
*/
208+
digest<OE extends OutputEncoding>(outputEncoding: OE): Output<OE>;
209+
}
210+
211+
/**
212+
* This module provides common hashing functionality available in the GoLang crypto package.
213+
* https://k6.io/docs/javascript-api/k6-crypto
214+
*/
215+
declare namespace crypto {
216+
/**
217+
* Produce HMAC.
218+
* https://k6.io/docs/javascript-api/k6-crypto/hmac-algorithm-secret-data-outputencoding
219+
* @param algorithm - Hash algorithm.
220+
* @param secret - Shared secret.
221+
* @param data - Input data.
222+
* @param outputEncoding - Output encoding.
223+
* @returns Produced HMAC.
224+
*/
225+
function hmac<OE extends OutputEncoding>(
226+
algorithm: Algorithm,
227+
secret: string,
228+
data: string,
229+
outputEncoding: OE
230+
): Output<OE>;
231+
232+
/**
233+
* Hash with MD4.
234+
* https://k6.io/docs/javascript-api/k6-crypto/md4-input-outputencoding
235+
* @param input - Data to hash.
236+
* @param outputEncoding - Output encoding.
237+
* @returns MD4 digest.
238+
*/
239+
function md4<OE extends OutputEncoding>(
240+
input: string,
241+
outputEncoding: OE
242+
): Output<OE>;
243+
244+
/**
245+
* Hash with MD5.
246+
* https://k6.io/docs/javascript-api/k6-crypto/md5-input-outputencoding
247+
* @param input - Data to hash.
248+
* @param outputEncoding - Output encoding.
249+
* @returns MD5 digest.
250+
*/
251+
function md5<OE extends OutputEncoding>(
252+
input: string,
253+
outputEncoding: OE
254+
): Output<OE>;
255+
256+
/**
257+
* Hash with SHA-1.
258+
* https://k6.io/docs/javascript-api/k6-crypto/sha1-input-outputencoding
259+
* @param input - Data to hash.
260+
* @param outputEncoding - Output encoding.
261+
* @returns SHA-1 digest.
262+
*/
263+
function sha1<OE extends OutputEncoding>(
264+
input: string,
265+
outputEncoding: OE
266+
): Output<OE>;
267+
268+
/**
269+
* Hash with SHA-256.
270+
* https://k6.io/docs/javascript-api/k6-crypto/sha256-input-outputencoding
271+
* @param input - Data to hash.
272+
* @param outputEncoding - Output encoding.
273+
* @returns SHA-256 digest.
274+
*/
275+
function sha256<OE extends OutputEncoding>(
276+
input: string,
277+
outputEncoding: OE
278+
): Output<OE>;
279+
280+
/**
281+
* Hash with SHA-384.
282+
* https://k6.io/docs/javascript-api/k6-crypto/sha384-input-outputencoding
283+
* @param input - Data to hash.
284+
* @param outputEncoding - Output encoding.
285+
* @returns SHA-384 digest.
286+
*/
287+
function sha384<OE extends OutputEncoding>(
288+
input: string,
289+
outputEncoding: OE
290+
): Output<OE>;
291+
292+
/**
293+
* Hash with SHA-512.
294+
* https://k6.io/docs/javascript-api/k6-crypto/sha512-input-outputencoding
295+
* @param input - Data to hash.
296+
* @param outputEncoding - Output encoding.
297+
* @returns SHA-512 digest.
298+
*/
299+
function sha512<OE extends OutputEncoding>(
300+
input: string,
301+
outputEncoding: OE
302+
): Output<OE>;
303+
304+
/**
305+
* Hash with SHA-512/224.
306+
* https://k6.io/docs/javascript-api/k6-crypto/sha512_224-input-outputencoding
307+
* @param input - Data to hash.
308+
* @param outputEncoding - Output encoding.
309+
* @returns SHA-512/224 digest.
310+
*/
311+
function sha512_224<OE extends OutputEncoding>(
312+
input: string,
313+
outputEncoding: OE
314+
): Output<OE>;
315+
316+
/**
317+
* Hash with SHA-512/256.
318+
* https://k6.io/docs/javascript-api/k6-crypto/sha512_256-input-outputencoding
319+
* @param input - Data to hash.
320+
* @param outputEncoding - Output encoding.
321+
* @returns SHA-512/256 digest.
322+
*/
323+
function sha512_256<OE extends OutputEncoding>(
324+
input: string,
325+
outputEncoding: OE
326+
): Output<OE>;
327+
328+
/**
329+
* Hash with RIPEMD-160.
330+
* https://k6.io/docs/javascript-api/k6-crypto/ripemd160-input-outputencoding
331+
* @param input - Data to hash.
332+
* @param outputEncoding - Output encoding.
333+
* @returns RIPEMD-160 digest.
334+
*/
335+
function ripemd160<OE extends OutputEncoding>(
336+
input: string,
337+
outputEncoding: OE
338+
): Output<OE>;
339+
340+
/**
341+
* Create a hashing object.
342+
* https://k6.io/docs/javascript-api/k6-crypto/createhash-algorithm
343+
* @param algorithm - Hash algorithm.
344+
* @returns Hashing object.
345+
*/
346+
function createHash(algorithm: Algorithm): Hasher;
347+
348+
/**
349+
* Create an HMAC hashing object.
350+
* https://k6.io/docs/javascript-api/k6-crypto/createhmac-algorithm-secret
351+
* @param algorithm - Hash algorithm.
352+
* @param secret - Shared secret.
353+
* @returns HMAC hashing object.
354+
*/
355+
function createHMAC(algorithm: Algorithm, secret: string): Hasher;
356+
}
357+
358+
export default crypto;

0 commit comments

Comments
 (0)