@stryke/crypto 0.5.34 → 0.5.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +14 -0
- package/dist/base-64.cjs +440 -1
- package/dist/base-64.mjs +437 -1
- package/dist/base-64.mjs.map +1 -1
- package/dist/convert/src/array-buffer-to-string.cjs +19 -1
- package/dist/convert/src/array-buffer-to-string.mjs +18 -1
- package/dist/convert/src/array-buffer-to-string.mjs.map +1 -1
- package/dist/convert/src/neutral.cjs +7 -1
- package/dist/convert/src/neutral.mjs +9 -1
- package/dist/convert/src/parse-type-definition.cjs +1 -1
- package/dist/convert/src/parse-type-definition.mjs +3 -1
- package/dist/convert/src/string-to-uint8-array.cjs +24 -1
- package/dist/convert/src/string-to-uint8-array.mjs +22 -1
- package/dist/convert/src/string-to-uint8-array.mjs.map +1 -1
- package/dist/convert/src/string-to-utf8-array.cjs +15 -1
- package/dist/convert/src/string-to-utf8-array.mjs +14 -1
- package/dist/convert/src/string-to-utf8-array.mjs.map +1 -1
- package/dist/convert/src/uint8-array-to-stream.cjs +22 -1
- package/dist/convert/src/uint8-array-to-stream.mjs +21 -1
- package/dist/convert/src/uint8-array-to-stream.mjs.map +1 -1
- package/dist/convert/src/uint8-array-to-string.cjs +15 -1
- package/dist/convert/src/uint8-array-to-string.mjs +15 -1
- package/dist/convert/src/uint8-array-to-string.mjs.map +1 -1
- package/dist/convert/src/utf8-array-to-string.cjs +15 -1
- package/dist/convert/src/utf8-array-to-string.mjs +14 -1
- package/dist/convert/src/utf8-array-to-string.mjs.map +1 -1
- package/dist/encryption.cjs +134 -1
- package/dist/encryption.mjs +128 -1
- package/dist/encryption.mjs.map +1 -1
- package/dist/encryption.node.cjs +63 -1
- package/dist/encryption.node.mjs +61 -1
- package/dist/encryption.node.mjs.map +1 -1
- package/dist/hex.cjs +62 -1
- package/dist/hex.mjs +60 -1
- package/dist/hex.mjs.map +1 -1
- package/dist/index.cjs +13 -1
- package/dist/index.mjs +5 -1
- package/dist/neutral.cjs +17 -1
- package/dist/neutral.mjs +5 -1
- package/dist/type-checks/src/index.cjs +5 -1
- package/dist/type-checks/src/index.mjs +7 -1
- package/dist/type-checks/src/is-buffer.cjs +12 -1
- package/dist/type-checks/src/is-buffer.mjs +11 -1
- package/dist/type-checks/src/is-buffer.mjs.map +1 -1
- package/dist/type-checks/src/is-collection.cjs +1 -1
- package/dist/type-checks/src/is-collection.mjs +3 -1
- package/dist/type-checks/src/is-string.cjs +12 -1
- package/dist/type-checks/src/is-string.mjs +11 -1
- package/dist/type-checks/src/is-string.mjs.map +1 -1
- package/dist/type-checks/src/is-undefined.cjs +8 -1
- package/dist/type-checks/src/is-undefined.mjs +7 -1
- package/dist/type-checks/src/is-undefined.mjs.map +1 -1
- package/dist/type-checks/src/type-detect.cjs +15 -1
- package/dist/type-checks/src/type-detect.mjs +16 -1
- package/dist/type-checks/src/type-detect.mjs.map +1 -1
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,20 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog for Stryke - Crypto
|
|
4
4
|
|
|
5
|
+
## [0.5.35](https://github.com/storm-software/stryke/releases/tag/crypto%400.5.35) (01/16/2026)
|
|
6
|
+
|
|
7
|
+
### Updated Dependencies
|
|
8
|
+
|
|
9
|
+
- Updated **type-checks** to **v0.5.19**
|
|
10
|
+
- Updated **convert** to **v0.6.34**
|
|
11
|
+
|
|
12
|
+
## [0.5.34](https://github.com/storm-software/stryke/releases/tag/crypto%400.5.34) (01/16/2026)
|
|
13
|
+
|
|
14
|
+
### Updated Dependencies
|
|
15
|
+
|
|
16
|
+
- Updated **type-checks** to **v0.5.18**
|
|
17
|
+
- Updated **convert** to **v0.6.33**
|
|
18
|
+
|
|
5
19
|
## [0.5.33](https://github.com/storm-software/stryke/releases/tag/crypto%400.5.33) (01/15/2026)
|
|
6
20
|
|
|
7
21
|
### Updated Dependencies
|
package/dist/base-64.cjs
CHANGED
|
@@ -1 +1,440 @@
|
|
|
1
|
-
const
|
|
1
|
+
const require_is_undefined = require('./type-checks/src/is-undefined.cjs');
|
|
2
|
+
const require_is_string = require('./type-checks/src/is-string.cjs');
|
|
3
|
+
const require_string_to_uint8_array = require('./convert/src/string-to-uint8-array.cjs');
|
|
4
|
+
const require_utf8_array_to_string = require('./convert/src/utf8-array-to-string.cjs');
|
|
5
|
+
require('./convert/src/neutral.cjs');
|
|
6
|
+
|
|
7
|
+
//#region src/base-64.ts
|
|
8
|
+
const ENCODE_MAP = new Uint8Array([
|
|
9
|
+
65,
|
|
10
|
+
66,
|
|
11
|
+
67,
|
|
12
|
+
68,
|
|
13
|
+
69,
|
|
14
|
+
70,
|
|
15
|
+
71,
|
|
16
|
+
72,
|
|
17
|
+
73,
|
|
18
|
+
74,
|
|
19
|
+
75,
|
|
20
|
+
76,
|
|
21
|
+
77,
|
|
22
|
+
78,
|
|
23
|
+
79,
|
|
24
|
+
80,
|
|
25
|
+
81,
|
|
26
|
+
82,
|
|
27
|
+
83,
|
|
28
|
+
84,
|
|
29
|
+
85,
|
|
30
|
+
86,
|
|
31
|
+
87,
|
|
32
|
+
88,
|
|
33
|
+
89,
|
|
34
|
+
90,
|
|
35
|
+
97,
|
|
36
|
+
98,
|
|
37
|
+
99,
|
|
38
|
+
100,
|
|
39
|
+
101,
|
|
40
|
+
102,
|
|
41
|
+
103,
|
|
42
|
+
104,
|
|
43
|
+
105,
|
|
44
|
+
106,
|
|
45
|
+
107,
|
|
46
|
+
108,
|
|
47
|
+
109,
|
|
48
|
+
110,
|
|
49
|
+
111,
|
|
50
|
+
112,
|
|
51
|
+
113,
|
|
52
|
+
114,
|
|
53
|
+
115,
|
|
54
|
+
116,
|
|
55
|
+
117,
|
|
56
|
+
118,
|
|
57
|
+
119,
|
|
58
|
+
120,
|
|
59
|
+
121,
|
|
60
|
+
122,
|
|
61
|
+
48,
|
|
62
|
+
49,
|
|
63
|
+
50,
|
|
64
|
+
51,
|
|
65
|
+
52,
|
|
66
|
+
53,
|
|
67
|
+
54,
|
|
68
|
+
55,
|
|
69
|
+
56,
|
|
70
|
+
57,
|
|
71
|
+
43,
|
|
72
|
+
47
|
|
73
|
+
]);
|
|
74
|
+
const ENCODE_PAD = 61;
|
|
75
|
+
const DECODE_MAP = new Uint8Array([
|
|
76
|
+
100,
|
|
77
|
+
100,
|
|
78
|
+
100,
|
|
79
|
+
100,
|
|
80
|
+
100,
|
|
81
|
+
100,
|
|
82
|
+
100,
|
|
83
|
+
100,
|
|
84
|
+
100,
|
|
85
|
+
100,
|
|
86
|
+
100,
|
|
87
|
+
100,
|
|
88
|
+
100,
|
|
89
|
+
100,
|
|
90
|
+
100,
|
|
91
|
+
100,
|
|
92
|
+
100,
|
|
93
|
+
100,
|
|
94
|
+
100,
|
|
95
|
+
100,
|
|
96
|
+
100,
|
|
97
|
+
100,
|
|
98
|
+
100,
|
|
99
|
+
100,
|
|
100
|
+
100,
|
|
101
|
+
100,
|
|
102
|
+
100,
|
|
103
|
+
100,
|
|
104
|
+
100,
|
|
105
|
+
100,
|
|
106
|
+
100,
|
|
107
|
+
100,
|
|
108
|
+
100,
|
|
109
|
+
100,
|
|
110
|
+
100,
|
|
111
|
+
100,
|
|
112
|
+
100,
|
|
113
|
+
100,
|
|
114
|
+
100,
|
|
115
|
+
100,
|
|
116
|
+
100,
|
|
117
|
+
100,
|
|
118
|
+
100,
|
|
119
|
+
62,
|
|
120
|
+
100,
|
|
121
|
+
100,
|
|
122
|
+
100,
|
|
123
|
+
63,
|
|
124
|
+
52,
|
|
125
|
+
53,
|
|
126
|
+
54,
|
|
127
|
+
55,
|
|
128
|
+
56,
|
|
129
|
+
57,
|
|
130
|
+
58,
|
|
131
|
+
59,
|
|
132
|
+
60,
|
|
133
|
+
61,
|
|
134
|
+
100,
|
|
135
|
+
100,
|
|
136
|
+
100,
|
|
137
|
+
100,
|
|
138
|
+
100,
|
|
139
|
+
100,
|
|
140
|
+
100,
|
|
141
|
+
0,
|
|
142
|
+
1,
|
|
143
|
+
2,
|
|
144
|
+
3,
|
|
145
|
+
4,
|
|
146
|
+
5,
|
|
147
|
+
6,
|
|
148
|
+
7,
|
|
149
|
+
8,
|
|
150
|
+
9,
|
|
151
|
+
10,
|
|
152
|
+
11,
|
|
153
|
+
12,
|
|
154
|
+
13,
|
|
155
|
+
14,
|
|
156
|
+
15,
|
|
157
|
+
16,
|
|
158
|
+
17,
|
|
159
|
+
18,
|
|
160
|
+
19,
|
|
161
|
+
20,
|
|
162
|
+
21,
|
|
163
|
+
22,
|
|
164
|
+
23,
|
|
165
|
+
24,
|
|
166
|
+
25,
|
|
167
|
+
100,
|
|
168
|
+
100,
|
|
169
|
+
100,
|
|
170
|
+
100,
|
|
171
|
+
100,
|
|
172
|
+
100,
|
|
173
|
+
26,
|
|
174
|
+
27,
|
|
175
|
+
28,
|
|
176
|
+
29,
|
|
177
|
+
30,
|
|
178
|
+
31,
|
|
179
|
+
32,
|
|
180
|
+
33,
|
|
181
|
+
34,
|
|
182
|
+
35,
|
|
183
|
+
36,
|
|
184
|
+
37,
|
|
185
|
+
38,
|
|
186
|
+
39,
|
|
187
|
+
40,
|
|
188
|
+
41,
|
|
189
|
+
42,
|
|
190
|
+
43,
|
|
191
|
+
44,
|
|
192
|
+
45,
|
|
193
|
+
46,
|
|
194
|
+
47,
|
|
195
|
+
48,
|
|
196
|
+
49,
|
|
197
|
+
50,
|
|
198
|
+
51,
|
|
199
|
+
100,
|
|
200
|
+
100,
|
|
201
|
+
100,
|
|
202
|
+
100,
|
|
203
|
+
100,
|
|
204
|
+
100,
|
|
205
|
+
100,
|
|
206
|
+
100,
|
|
207
|
+
100,
|
|
208
|
+
100,
|
|
209
|
+
100,
|
|
210
|
+
100,
|
|
211
|
+
100,
|
|
212
|
+
100,
|
|
213
|
+
100,
|
|
214
|
+
100,
|
|
215
|
+
100,
|
|
216
|
+
100,
|
|
217
|
+
100,
|
|
218
|
+
100,
|
|
219
|
+
100,
|
|
220
|
+
100,
|
|
221
|
+
100,
|
|
222
|
+
100,
|
|
223
|
+
100,
|
|
224
|
+
100,
|
|
225
|
+
100,
|
|
226
|
+
100,
|
|
227
|
+
100,
|
|
228
|
+
100,
|
|
229
|
+
100,
|
|
230
|
+
100,
|
|
231
|
+
100,
|
|
232
|
+
100,
|
|
233
|
+
100,
|
|
234
|
+
100,
|
|
235
|
+
100,
|
|
236
|
+
100,
|
|
237
|
+
100,
|
|
238
|
+
100,
|
|
239
|
+
100,
|
|
240
|
+
100,
|
|
241
|
+
100,
|
|
242
|
+
100,
|
|
243
|
+
100,
|
|
244
|
+
100,
|
|
245
|
+
100,
|
|
246
|
+
100,
|
|
247
|
+
100,
|
|
248
|
+
100,
|
|
249
|
+
100,
|
|
250
|
+
100,
|
|
251
|
+
100,
|
|
252
|
+
100,
|
|
253
|
+
100,
|
|
254
|
+
100,
|
|
255
|
+
100,
|
|
256
|
+
100,
|
|
257
|
+
100,
|
|
258
|
+
100,
|
|
259
|
+
100,
|
|
260
|
+
100,
|
|
261
|
+
100,
|
|
262
|
+
100,
|
|
263
|
+
100,
|
|
264
|
+
100,
|
|
265
|
+
100,
|
|
266
|
+
100,
|
|
267
|
+
100,
|
|
268
|
+
100,
|
|
269
|
+
100,
|
|
270
|
+
100,
|
|
271
|
+
100,
|
|
272
|
+
100,
|
|
273
|
+
100,
|
|
274
|
+
100,
|
|
275
|
+
100,
|
|
276
|
+
100,
|
|
277
|
+
100,
|
|
278
|
+
100,
|
|
279
|
+
100,
|
|
280
|
+
100,
|
|
281
|
+
100,
|
|
282
|
+
100,
|
|
283
|
+
100,
|
|
284
|
+
100,
|
|
285
|
+
100,
|
|
286
|
+
100,
|
|
287
|
+
100,
|
|
288
|
+
100,
|
|
289
|
+
100,
|
|
290
|
+
100,
|
|
291
|
+
100,
|
|
292
|
+
100,
|
|
293
|
+
100,
|
|
294
|
+
100,
|
|
295
|
+
100,
|
|
296
|
+
100,
|
|
297
|
+
100,
|
|
298
|
+
100,
|
|
299
|
+
100,
|
|
300
|
+
100,
|
|
301
|
+
100,
|
|
302
|
+
100,
|
|
303
|
+
100,
|
|
304
|
+
100,
|
|
305
|
+
100,
|
|
306
|
+
100,
|
|
307
|
+
100,
|
|
308
|
+
100,
|
|
309
|
+
100,
|
|
310
|
+
100,
|
|
311
|
+
100,
|
|
312
|
+
100,
|
|
313
|
+
100,
|
|
314
|
+
100,
|
|
315
|
+
100,
|
|
316
|
+
100,
|
|
317
|
+
100,
|
|
318
|
+
100,
|
|
319
|
+
100,
|
|
320
|
+
100,
|
|
321
|
+
100,
|
|
322
|
+
100,
|
|
323
|
+
100,
|
|
324
|
+
100,
|
|
325
|
+
100,
|
|
326
|
+
100,
|
|
327
|
+
100,
|
|
328
|
+
100,
|
|
329
|
+
100,
|
|
330
|
+
100
|
|
331
|
+
]);
|
|
332
|
+
/**
|
|
333
|
+
* Encodes a Uint8Array into a Base64 encoded Uint8Array.
|
|
334
|
+
*
|
|
335
|
+
* @credit https://github.com/hi-ogawa/js-utils
|
|
336
|
+
*
|
|
337
|
+
* @param input - The input Uint8Array or string to encode.
|
|
338
|
+
* @returns The Base64 encoded Uint8Array.
|
|
339
|
+
*/
|
|
340
|
+
function encodeBase64(input) {
|
|
341
|
+
if (require_is_string.isString(input)) input = require_string_to_uint8_array.stringToUint8Array(input);
|
|
342
|
+
const xLen = input.length;
|
|
343
|
+
const result = new Uint8Array(Math.ceil(xLen / 3) * 4);
|
|
344
|
+
const chunkLen = Math.floor(xLen / 3);
|
|
345
|
+
for (let i$1 = 0; i$1 < chunkLen; i$1++) {
|
|
346
|
+
const chunk = input[3 * i$1 + 0] << 16 | input[3 * i$1 + 1] << 8 | input[3 * i$1 + 2];
|
|
347
|
+
result[4 * i$1 + 0] = ENCODE_MAP[chunk >> 18 & 63];
|
|
348
|
+
result[4 * i$1 + 1] = ENCODE_MAP[chunk >> 12 & 63];
|
|
349
|
+
result[4 * i$1 + 2] = ENCODE_MAP[chunk >> 6 & 63];
|
|
350
|
+
result[4 * i$1 + 3] = ENCODE_MAP[chunk >> 0 & 63];
|
|
351
|
+
}
|
|
352
|
+
const i = chunkLen;
|
|
353
|
+
switch (xLen % 3) {
|
|
354
|
+
case 1: {
|
|
355
|
+
const chunk = input[3 * i + 0] << 16;
|
|
356
|
+
result[4 * i + 0] = ENCODE_MAP[chunk >> 18 & 63];
|
|
357
|
+
result[4 * i + 1] = ENCODE_MAP[chunk >> 12 & 63];
|
|
358
|
+
result[4 * i + 2] = ENCODE_PAD;
|
|
359
|
+
result[4 * i + 3] = ENCODE_PAD;
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
case 2: {
|
|
363
|
+
const chunk = input[3 * i + 0] << 16 | input[3 * i + 1] << 8;
|
|
364
|
+
result[4 * i + 0] = ENCODE_MAP[chunk >> 18 & 63];
|
|
365
|
+
result[4 * i + 1] = ENCODE_MAP[chunk >> 12 & 63];
|
|
366
|
+
result[4 * i + 2] = ENCODE_MAP[chunk >> 6 & 63];
|
|
367
|
+
result[4 * i + 3] = ENCODE_PAD;
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
return require_utf8_array_to_string.utf8ArrayToString(result);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Decodes a Base64 encoded Uint8Array into a Uint8Array.
|
|
375
|
+
*
|
|
376
|
+
* @credit https://github.com/hi-ogawa/js-utils
|
|
377
|
+
*
|
|
378
|
+
* @param input - The Base64 encoded Uint8Array or string to decode.
|
|
379
|
+
* @returns The decoded Uint8Array.
|
|
380
|
+
*/
|
|
381
|
+
function decodeBase64(input) {
|
|
382
|
+
if (require_is_string.isString(input)) input = require_string_to_uint8_array.stringToUint8Array(input);
|
|
383
|
+
const yLen = input.length;
|
|
384
|
+
if (yLen % 4 !== 0) throw new Error("invalid length");
|
|
385
|
+
let padLen = 0;
|
|
386
|
+
while (padLen < 2 && padLen < input.length && input[input.length - 1 - padLen] === ENCODE_PAD) padLen++;
|
|
387
|
+
for (let i$1 = 0; i$1 < input.length - padLen; i$1++) if (require_is_undefined.isUndefined(input[i$1]) || require_is_undefined.isUndefined(DECODE_MAP[input[i$1]]) || DECODE_MAP[input[i$1]] >= 64) throw new Error("invalid data");
|
|
388
|
+
const chunkLen = Math.floor((yLen - padLen) / 4);
|
|
389
|
+
const xLen = 3 * chunkLen + (3 - padLen) % 3;
|
|
390
|
+
const result = new Uint8Array(xLen);
|
|
391
|
+
for (let i$1 = 0; i$1 < chunkLen; i$1++) {
|
|
392
|
+
const chunk = DECODE_MAP[input[4 * i$1 + 0]] << 18 | DECODE_MAP[input[4 * i$1 + 1]] << 12 | DECODE_MAP[input[4 * i$1 + 2]] << 6 | DECODE_MAP[input[4 * i$1 + 3]] << 0;
|
|
393
|
+
result[3 * i$1] = chunk >> 16 & 255;
|
|
394
|
+
result[3 * i$1 + 1] = chunk >> 8 & 255;
|
|
395
|
+
result[3 * i$1 + 2] = chunk >> 0 & 255;
|
|
396
|
+
}
|
|
397
|
+
const i = chunkLen;
|
|
398
|
+
switch (xLen % 3) {
|
|
399
|
+
case 1: {
|
|
400
|
+
const chunk = DECODE_MAP[input[4 * i + 0]] << 18 | DECODE_MAP[input[4 * i + 1]] << 12;
|
|
401
|
+
result[3 * i] = chunk >> 16 & 255;
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
case 2: {
|
|
405
|
+
const chunk = DECODE_MAP[input[4 * i + 0]] << 18 | DECODE_MAP[input[4 * i + 1]] << 12 | DECODE_MAP[input[4 * i + 2]] << 6;
|
|
406
|
+
result[3 * i] = chunk >> 16 & 255;
|
|
407
|
+
result[3 * i + 1] = chunk >> 8 & 255;
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return result;
|
|
412
|
+
}
|
|
413
|
+
/**
|
|
414
|
+
* Converts a Base64 encoded string to a [Base64url](https://datatracker.ietf.org/doc/html/rfc7515#appendix-C) encoded string.
|
|
415
|
+
*
|
|
416
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7515#appendix-C
|
|
417
|
+
*
|
|
418
|
+
* @param base64 - The Base64 encoded string to convert.
|
|
419
|
+
* @returns The Base64url encoded string.
|
|
420
|
+
*/
|
|
421
|
+
function base64ToBase64url(base64) {
|
|
422
|
+
return base64.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/g, "");
|
|
423
|
+
}
|
|
424
|
+
/**
|
|
425
|
+
* Converts a [Base64url](https://datatracker.ietf.org/doc/html/rfc7515#appendix-C) encoded string to a Base64 encoded string.
|
|
426
|
+
*
|
|
427
|
+
* @see https://datatracker.ietf.org/doc/html/rfc7515#appendix-C
|
|
428
|
+
*
|
|
429
|
+
* @param base64url - The Base64url encoded string to convert.
|
|
430
|
+
* @returns The Base64 encoded string.
|
|
431
|
+
*/
|
|
432
|
+
function base64FromBase64url(base64url) {
|
|
433
|
+
return base64url.replace(/-/g, "+").replace(/_/g, "/") + "=".repeat((4 - base64url.length % 4) % 4);
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
//#endregion
|
|
437
|
+
exports.base64FromBase64url = base64FromBase64url;
|
|
438
|
+
exports.base64ToBase64url = base64ToBase64url;
|
|
439
|
+
exports.decodeBase64 = decodeBase64;
|
|
440
|
+
exports.encodeBase64 = encodeBase64;
|