1
- /*
2
- * Cryptography utilities.
3
- * https://docs.k6.io/docs/k6crypto
4
- */
5
-
6
1
import { bytes } from '.' ;
7
2
8
3
/**
9
4
* Generate random bytes.
10
5
* @param size - Number of bytes to generate.
11
6
* @returns Random bytes.
12
- * @public
13
7
*/
14
8
export function randomBytes ( size : number ) : bytes ;
15
9
16
10
/**
17
11
* 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
19
13
* @param algorithm - Hash algorithm.
20
14
* @param secret - Shared secret.
21
15
* @param data - Input data.
22
16
* @param outputEncoding - Output encoding.
23
17
* @returns Produced HMAC.
24
- * @public
25
18
*/
26
19
export function hmac < OE extends OutputEncoding > (
27
20
algorithm : Algorithm ,
@@ -32,11 +25,10 @@ export function hmac<OE extends OutputEncoding>(
32
25
33
26
/**
34
27
* Hash with MD4.
35
- * https://docs. k6.io/docs/md4-input-outputencoding
28
+ * https://k6.io/docs/javascript-api/k6-crypto /md4-input-outputencoding
36
29
* @param input - Data to hash.
37
30
* @param outputEncoding - Output encoding.
38
31
* @returns MD4 digest.
39
- * @public
40
32
*/
41
33
export function md4 < OE extends OutputEncoding > (
42
34
input : string ,
@@ -45,11 +37,10 @@ export function md4<OE extends OutputEncoding>(
45
37
46
38
/**
47
39
* Hash with MD5.
48
- * https://docs. k6.io/docs/md5-input-outputencoding
40
+ * https://k6.io/docs/javascript-api/k6-crypto /md5-input-outputencoding
49
41
* @param input - Data to hash.
50
42
* @param outputEncoding - Output encoding.
51
43
* @returns MD5 digest.
52
- * @public
53
44
*/
54
45
export function md5 < OE extends OutputEncoding > (
55
46
input : string ,
@@ -58,11 +49,10 @@ export function md5<OE extends OutputEncoding>(
58
49
59
50
/**
60
51
* 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
62
53
* @param input - Data to hash.
63
54
* @param outputEncoding - Output encoding.
64
55
* @returns SHA-1 digest.
65
- * @public
66
56
*/
67
57
export function sha1 < OE extends OutputEncoding > (
68
58
input : string ,
@@ -71,11 +61,10 @@ export function sha1<OE extends OutputEncoding>(
71
61
72
62
/**
73
63
* 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
75
65
* @param input - Data to hash.
76
66
* @param outputEncoding - Output encoding.
77
67
* @returns SHA-256 digest.
78
- * @public
79
68
*/
80
69
export function sha256 < OE extends OutputEncoding > (
81
70
input : string ,
@@ -84,11 +73,10 @@ export function sha256<OE extends OutputEncoding>(
84
73
85
74
/**
86
75
* 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
88
77
* @param input - Data to hash.
89
78
* @param outputEncoding - Output encoding.
90
79
* @returns SHA-384 digest.
91
- * @public
92
80
*/
93
81
export function sha384 < OE extends OutputEncoding > (
94
82
input : string ,
@@ -97,11 +85,10 @@ export function sha384<OE extends OutputEncoding>(
97
85
98
86
/**
99
87
* 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
101
89
* @param input - Data to hash.
102
90
* @param outputEncoding - Output encoding.
103
91
* @returns SHA-512 digest.
104
- * @public
105
92
*/
106
93
export function sha512 < OE extends OutputEncoding > (
107
94
input : string ,
@@ -110,11 +97,10 @@ export function sha512<OE extends OutputEncoding>(
110
97
111
98
/**
112
99
* 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
114
101
* @param input - Data to hash.
115
102
* @param outputEncoding - Output encoding.
116
103
* @returns SHA-512/224 digest.
117
- * @public
118
104
*/
119
105
export function sha512_224 < OE extends OutputEncoding > (
120
106
input : string ,
@@ -123,11 +109,10 @@ export function sha512_224<OE extends OutputEncoding>(
123
109
124
110
/**
125
111
* 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
127
113
* @param input - Data to hash.
128
114
* @param outputEncoding - Output encoding.
129
115
* @returns SHA-512/256 digest.
130
- * @public
131
116
*/
132
117
export function sha512_256 < OE extends OutputEncoding > (
133
118
input : string ,
@@ -136,11 +121,10 @@ export function sha512_256<OE extends OutputEncoding>(
136
121
137
122
/**
138
123
* 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
140
125
* @param input - Data to hash.
141
126
* @param outputEncoding - Output encoding.
142
127
* @returns RIPEMD-160 digest.
143
- * @public
144
128
*/
145
129
export function ripemd160 < OE extends OutputEncoding > (
146
130
input : string ,
@@ -149,26 +133,23 @@ export function ripemd160<OE extends OutputEncoding>(
149
133
150
134
/**
151
135
* Create a hashing object.
152
- * https://docs. k6.io/docs/createhash-algorithm
136
+ * https://k6.io/docs/javascript-api/k6-crypto /createhash-algorithm
153
137
* @param algorithm - Hash algorithm.
154
138
* @returns Hashing object.
155
- * @public
156
139
*/
157
140
export function createHash ( algorithm : Algorithm ) : Hasher ;
158
141
159
142
/**
160
143
* 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
162
145
* @param algorithm - Hash algorithm.
163
146
* @param secret - Shared secret.
164
147
* @returns HMAC hashing object.
165
- * @public
166
148
*/
167
149
export function createHMAC ( algorithm : Algorithm , secret : string ) : Hasher ;
168
150
169
151
/**
170
152
* Hash algorithm.
171
- * @public
172
153
*/
173
154
export type Algorithm =
174
155
| 'md4'
@@ -183,26 +164,22 @@ export type Algorithm =
183
164
184
165
/**
185
166
* String output encoding.
186
- * @public
187
167
*/
188
168
export type StringEncoding = 'hex' | 'base64' | 'base64url' | 'base64rawurl' ;
189
169
190
170
/**
191
171
* Binary output encoding.
192
- * @public
193
172
*/
194
173
export type BinaryEncoding = 'binary' ;
195
174
196
175
/**
197
176
* Output encoding.
198
- * @public
199
177
*/
200
178
export type OutputEncoding = StringEncoding | BinaryEncoding ;
201
179
202
180
/**
203
181
* Output type. Varies with output encoding.
204
182
* @typeParam OE - Output encoding.
205
- * @public
206
183
*/
207
184
export type Output < OE extends OutputEncoding > = OE extends StringEncoding
208
185
? string
@@ -213,21 +190,169 @@ export type Output<OE extends OutputEncoding> = OE extends StringEncoding
213
190
/**
214
191
* Hashing object.
215
192
* https://docs.k6.io/docs/hasher-k6crypto
216
- * @public
217
193
*/
218
194
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