@vardario/cognito-client 0.1.3 → 0.1.4

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/dist/index.js ADDED
@@ -0,0 +1,3814 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
8
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
9
+ }) : x)(function(x) {
10
+ if (typeof require !== "undefined")
11
+ return require.apply(this, arguments);
12
+ throw new Error('Dynamic require of "' + x + '" is not supported');
13
+ });
14
+ var __commonJS = (cb, mod) => function __require2() {
15
+ return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
16
+ };
17
+ var __copyProps = (to, from, except, desc) => {
18
+ if (from && typeof from === "object" || typeof from === "function") {
19
+ for (let key of __getOwnPropNames(from))
20
+ if (!__hasOwnProp.call(to, key) && key !== except)
21
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
22
+ }
23
+ return to;
24
+ };
25
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
26
+ // If the importer is in node compatibility mode or this is not an ESM
27
+ // file that has been converted to a CommonJS file using a Babel-
28
+ // compatible transform (i.e. "__esModule" has not been set), then set
29
+ // "default" to the CommonJS "module.exports" for node compatibility.
30
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
31
+ mod
32
+ ));
33
+
34
+ // node_modules/.pnpm/minimalistic-assert@1.0.1/node_modules/minimalistic-assert/index.js
35
+ var require_minimalistic_assert = __commonJS({
36
+ "node_modules/.pnpm/minimalistic-assert@1.0.1/node_modules/minimalistic-assert/index.js"(exports, module) {
37
+ module.exports = assert;
38
+ function assert(val, msg) {
39
+ if (!val)
40
+ throw new Error(msg || "Assertion failed");
41
+ }
42
+ assert.equal = function assertEqual(l, r, msg) {
43
+ if (l != r)
44
+ throw new Error(msg || "Assertion failed: " + l + " != " + r);
45
+ };
46
+ }
47
+ });
48
+
49
+ // node_modules/.pnpm/inherits@2.0.4/node_modules/inherits/inherits_browser.js
50
+ var require_inherits_browser = __commonJS({
51
+ "node_modules/.pnpm/inherits@2.0.4/node_modules/inherits/inherits_browser.js"(exports, module) {
52
+ if (typeof Object.create === "function") {
53
+ module.exports = function inherits(ctor, superCtor) {
54
+ if (superCtor) {
55
+ ctor.super_ = superCtor;
56
+ ctor.prototype = Object.create(superCtor.prototype, {
57
+ constructor: {
58
+ value: ctor,
59
+ enumerable: false,
60
+ writable: true,
61
+ configurable: true
62
+ }
63
+ });
64
+ }
65
+ };
66
+ } else {
67
+ module.exports = function inherits(ctor, superCtor) {
68
+ if (superCtor) {
69
+ ctor.super_ = superCtor;
70
+ var TempCtor = function() {
71
+ };
72
+ TempCtor.prototype = superCtor.prototype;
73
+ ctor.prototype = new TempCtor();
74
+ ctor.prototype.constructor = ctor;
75
+ }
76
+ };
77
+ }
78
+ }
79
+ });
80
+
81
+ // node_modules/.pnpm/inherits@2.0.4/node_modules/inherits/inherits.js
82
+ var require_inherits = __commonJS({
83
+ "node_modules/.pnpm/inherits@2.0.4/node_modules/inherits/inherits.js"(exports, module) {
84
+ try {
85
+ util = __require("util");
86
+ if (typeof util.inherits !== "function")
87
+ throw "";
88
+ module.exports = util.inherits;
89
+ } catch (e) {
90
+ module.exports = require_inherits_browser();
91
+ }
92
+ var util;
93
+ }
94
+ });
95
+
96
+ // node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/utils.js
97
+ var require_utils = __commonJS({
98
+ "node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/utils.js"(exports) {
99
+ "use strict";
100
+ var assert = require_minimalistic_assert();
101
+ var inherits = require_inherits();
102
+ exports.inherits = inherits;
103
+ function isSurrogatePair(msg, i) {
104
+ if ((msg.charCodeAt(i) & 64512) !== 55296) {
105
+ return false;
106
+ }
107
+ if (i < 0 || i + 1 >= msg.length) {
108
+ return false;
109
+ }
110
+ return (msg.charCodeAt(i + 1) & 64512) === 56320;
111
+ }
112
+ function toArray(msg, enc) {
113
+ if (Array.isArray(msg))
114
+ return msg.slice();
115
+ if (!msg)
116
+ return [];
117
+ var res = [];
118
+ if (typeof msg === "string") {
119
+ if (!enc) {
120
+ var p = 0;
121
+ for (var i = 0; i < msg.length; i++) {
122
+ var c = msg.charCodeAt(i);
123
+ if (c < 128) {
124
+ res[p++] = c;
125
+ } else if (c < 2048) {
126
+ res[p++] = c >> 6 | 192;
127
+ res[p++] = c & 63 | 128;
128
+ } else if (isSurrogatePair(msg, i)) {
129
+ c = 65536 + ((c & 1023) << 10) + (msg.charCodeAt(++i) & 1023);
130
+ res[p++] = c >> 18 | 240;
131
+ res[p++] = c >> 12 & 63 | 128;
132
+ res[p++] = c >> 6 & 63 | 128;
133
+ res[p++] = c & 63 | 128;
134
+ } else {
135
+ res[p++] = c >> 12 | 224;
136
+ res[p++] = c >> 6 & 63 | 128;
137
+ res[p++] = c & 63 | 128;
138
+ }
139
+ }
140
+ } else if (enc === "hex") {
141
+ msg = msg.replace(/[^a-z0-9]+/ig, "");
142
+ if (msg.length % 2 !== 0)
143
+ msg = "0" + msg;
144
+ for (i = 0; i < msg.length; i += 2)
145
+ res.push(parseInt(msg[i] + msg[i + 1], 16));
146
+ }
147
+ } else {
148
+ for (i = 0; i < msg.length; i++)
149
+ res[i] = msg[i] | 0;
150
+ }
151
+ return res;
152
+ }
153
+ exports.toArray = toArray;
154
+ function toHex(msg) {
155
+ var res = "";
156
+ for (var i = 0; i < msg.length; i++)
157
+ res += zero2(msg[i].toString(16));
158
+ return res;
159
+ }
160
+ exports.toHex = toHex;
161
+ function htonl(w) {
162
+ var res = w >>> 24 | w >>> 8 & 65280 | w << 8 & 16711680 | (w & 255) << 24;
163
+ return res >>> 0;
164
+ }
165
+ exports.htonl = htonl;
166
+ function toHex32(msg, endian) {
167
+ var res = "";
168
+ for (var i = 0; i < msg.length; i++) {
169
+ var w = msg[i];
170
+ if (endian === "little")
171
+ w = htonl(w);
172
+ res += zero8(w.toString(16));
173
+ }
174
+ return res;
175
+ }
176
+ exports.toHex32 = toHex32;
177
+ function zero2(word) {
178
+ if (word.length === 1)
179
+ return "0" + word;
180
+ else
181
+ return word;
182
+ }
183
+ exports.zero2 = zero2;
184
+ function zero8(word) {
185
+ if (word.length === 7)
186
+ return "0" + word;
187
+ else if (word.length === 6)
188
+ return "00" + word;
189
+ else if (word.length === 5)
190
+ return "000" + word;
191
+ else if (word.length === 4)
192
+ return "0000" + word;
193
+ else if (word.length === 3)
194
+ return "00000" + word;
195
+ else if (word.length === 2)
196
+ return "000000" + word;
197
+ else if (word.length === 1)
198
+ return "0000000" + word;
199
+ else
200
+ return word;
201
+ }
202
+ exports.zero8 = zero8;
203
+ function join32(msg, start, end, endian) {
204
+ var len = end - start;
205
+ assert(len % 4 === 0);
206
+ var res = new Array(len / 4);
207
+ for (var i = 0, k2 = start; i < res.length; i++, k2 += 4) {
208
+ var w;
209
+ if (endian === "big")
210
+ w = msg[k2] << 24 | msg[k2 + 1] << 16 | msg[k2 + 2] << 8 | msg[k2 + 3];
211
+ else
212
+ w = msg[k2 + 3] << 24 | msg[k2 + 2] << 16 | msg[k2 + 1] << 8 | msg[k2];
213
+ res[i] = w >>> 0;
214
+ }
215
+ return res;
216
+ }
217
+ exports.join32 = join32;
218
+ function split32(msg, endian) {
219
+ var res = new Array(msg.length * 4);
220
+ for (var i = 0, k2 = 0; i < msg.length; i++, k2 += 4) {
221
+ var m = msg[i];
222
+ if (endian === "big") {
223
+ res[k2] = m >>> 24;
224
+ res[k2 + 1] = m >>> 16 & 255;
225
+ res[k2 + 2] = m >>> 8 & 255;
226
+ res[k2 + 3] = m & 255;
227
+ } else {
228
+ res[k2 + 3] = m >>> 24;
229
+ res[k2 + 2] = m >>> 16 & 255;
230
+ res[k2 + 1] = m >>> 8 & 255;
231
+ res[k2] = m & 255;
232
+ }
233
+ }
234
+ return res;
235
+ }
236
+ exports.split32 = split32;
237
+ function rotr32(w, b) {
238
+ return w >>> b | w << 32 - b;
239
+ }
240
+ exports.rotr32 = rotr32;
241
+ function rotl32(w, b) {
242
+ return w << b | w >>> 32 - b;
243
+ }
244
+ exports.rotl32 = rotl32;
245
+ function sum32(a, b) {
246
+ return a + b >>> 0;
247
+ }
248
+ exports.sum32 = sum32;
249
+ function sum32_3(a, b, c) {
250
+ return a + b + c >>> 0;
251
+ }
252
+ exports.sum32_3 = sum32_3;
253
+ function sum32_4(a, b, c, d) {
254
+ return a + b + c + d >>> 0;
255
+ }
256
+ exports.sum32_4 = sum32_4;
257
+ function sum32_5(a, b, c, d, e) {
258
+ return a + b + c + d + e >>> 0;
259
+ }
260
+ exports.sum32_5 = sum32_5;
261
+ function sum64(buf, pos, ah, al) {
262
+ var bh = buf[pos];
263
+ var bl = buf[pos + 1];
264
+ var lo = al + bl >>> 0;
265
+ var hi = (lo < al ? 1 : 0) + ah + bh;
266
+ buf[pos] = hi >>> 0;
267
+ buf[pos + 1] = lo;
268
+ }
269
+ exports.sum64 = sum64;
270
+ function sum64_hi(ah, al, bh, bl) {
271
+ var lo = al + bl >>> 0;
272
+ var hi = (lo < al ? 1 : 0) + ah + bh;
273
+ return hi >>> 0;
274
+ }
275
+ exports.sum64_hi = sum64_hi;
276
+ function sum64_lo(ah, al, bh, bl) {
277
+ var lo = al + bl;
278
+ return lo >>> 0;
279
+ }
280
+ exports.sum64_lo = sum64_lo;
281
+ function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) {
282
+ var carry = 0;
283
+ var lo = al;
284
+ lo = lo + bl >>> 0;
285
+ carry += lo < al ? 1 : 0;
286
+ lo = lo + cl >>> 0;
287
+ carry += lo < cl ? 1 : 0;
288
+ lo = lo + dl >>> 0;
289
+ carry += lo < dl ? 1 : 0;
290
+ var hi = ah + bh + ch + dh + carry;
291
+ return hi >>> 0;
292
+ }
293
+ exports.sum64_4_hi = sum64_4_hi;
294
+ function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) {
295
+ var lo = al + bl + cl + dl;
296
+ return lo >>> 0;
297
+ }
298
+ exports.sum64_4_lo = sum64_4_lo;
299
+ function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
300
+ var carry = 0;
301
+ var lo = al;
302
+ lo = lo + bl >>> 0;
303
+ carry += lo < al ? 1 : 0;
304
+ lo = lo + cl >>> 0;
305
+ carry += lo < cl ? 1 : 0;
306
+ lo = lo + dl >>> 0;
307
+ carry += lo < dl ? 1 : 0;
308
+ lo = lo + el >>> 0;
309
+ carry += lo < el ? 1 : 0;
310
+ var hi = ah + bh + ch + dh + eh + carry;
311
+ return hi >>> 0;
312
+ }
313
+ exports.sum64_5_hi = sum64_5_hi;
314
+ function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) {
315
+ var lo = al + bl + cl + dl + el;
316
+ return lo >>> 0;
317
+ }
318
+ exports.sum64_5_lo = sum64_5_lo;
319
+ function rotr64_hi(ah, al, num) {
320
+ var r = al << 32 - num | ah >>> num;
321
+ return r >>> 0;
322
+ }
323
+ exports.rotr64_hi = rotr64_hi;
324
+ function rotr64_lo(ah, al, num) {
325
+ var r = ah << 32 - num | al >>> num;
326
+ return r >>> 0;
327
+ }
328
+ exports.rotr64_lo = rotr64_lo;
329
+ function shr64_hi(ah, al, num) {
330
+ return ah >>> num;
331
+ }
332
+ exports.shr64_hi = shr64_hi;
333
+ function shr64_lo(ah, al, num) {
334
+ var r = ah << 32 - num | al >>> num;
335
+ return r >>> 0;
336
+ }
337
+ exports.shr64_lo = shr64_lo;
338
+ }
339
+ });
340
+
341
+ // node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/common.js
342
+ var require_common = __commonJS({
343
+ "node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/common.js"(exports) {
344
+ "use strict";
345
+ var utils = require_utils();
346
+ var assert = require_minimalistic_assert();
347
+ function BlockHash() {
348
+ this.pending = null;
349
+ this.pendingTotal = 0;
350
+ this.blockSize = this.constructor.blockSize;
351
+ this.outSize = this.constructor.outSize;
352
+ this.hmacStrength = this.constructor.hmacStrength;
353
+ this.padLength = this.constructor.padLength / 8;
354
+ this.endian = "big";
355
+ this._delta8 = this.blockSize / 8;
356
+ this._delta32 = this.blockSize / 32;
357
+ }
358
+ exports.BlockHash = BlockHash;
359
+ BlockHash.prototype.update = function update(msg, enc) {
360
+ msg = utils.toArray(msg, enc);
361
+ if (!this.pending)
362
+ this.pending = msg;
363
+ else
364
+ this.pending = this.pending.concat(msg);
365
+ this.pendingTotal += msg.length;
366
+ if (this.pending.length >= this._delta8) {
367
+ msg = this.pending;
368
+ var r = msg.length % this._delta8;
369
+ this.pending = msg.slice(msg.length - r, msg.length);
370
+ if (this.pending.length === 0)
371
+ this.pending = null;
372
+ msg = utils.join32(msg, 0, msg.length - r, this.endian);
373
+ for (var i = 0; i < msg.length; i += this._delta32)
374
+ this._update(msg, i, i + this._delta32);
375
+ }
376
+ return this;
377
+ };
378
+ BlockHash.prototype.digest = function digest(enc) {
379
+ this.update(this._pad());
380
+ assert(this.pending === null);
381
+ return this._digest(enc);
382
+ };
383
+ BlockHash.prototype._pad = function pad() {
384
+ var len = this.pendingTotal;
385
+ var bytes = this._delta8;
386
+ var k2 = bytes - (len + this.padLength) % bytes;
387
+ var res = new Array(k2 + this.padLength);
388
+ res[0] = 128;
389
+ for (var i = 1; i < k2; i++)
390
+ res[i] = 0;
391
+ len <<= 3;
392
+ if (this.endian === "big") {
393
+ for (var t = 8; t < this.padLength; t++)
394
+ res[i++] = 0;
395
+ res[i++] = 0;
396
+ res[i++] = 0;
397
+ res[i++] = 0;
398
+ res[i++] = 0;
399
+ res[i++] = len >>> 24 & 255;
400
+ res[i++] = len >>> 16 & 255;
401
+ res[i++] = len >>> 8 & 255;
402
+ res[i++] = len & 255;
403
+ } else {
404
+ res[i++] = len & 255;
405
+ res[i++] = len >>> 8 & 255;
406
+ res[i++] = len >>> 16 & 255;
407
+ res[i++] = len >>> 24 & 255;
408
+ res[i++] = 0;
409
+ res[i++] = 0;
410
+ res[i++] = 0;
411
+ res[i++] = 0;
412
+ for (t = 8; t < this.padLength; t++)
413
+ res[i++] = 0;
414
+ }
415
+ return res;
416
+ };
417
+ }
418
+ });
419
+
420
+ // node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/sha/common.js
421
+ var require_common2 = __commonJS({
422
+ "node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/sha/common.js"(exports) {
423
+ "use strict";
424
+ var utils = require_utils();
425
+ var rotr32 = utils.rotr32;
426
+ function ft_1(s, x, y, z) {
427
+ if (s === 0)
428
+ return ch32(x, y, z);
429
+ if (s === 1 || s === 3)
430
+ return p32(x, y, z);
431
+ if (s === 2)
432
+ return maj32(x, y, z);
433
+ }
434
+ exports.ft_1 = ft_1;
435
+ function ch32(x, y, z) {
436
+ return x & y ^ ~x & z;
437
+ }
438
+ exports.ch32 = ch32;
439
+ function maj32(x, y, z) {
440
+ return x & y ^ x & z ^ y & z;
441
+ }
442
+ exports.maj32 = maj32;
443
+ function p32(x, y, z) {
444
+ return x ^ y ^ z;
445
+ }
446
+ exports.p32 = p32;
447
+ function s0_256(x) {
448
+ return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22);
449
+ }
450
+ exports.s0_256 = s0_256;
451
+ function s1_256(x) {
452
+ return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25);
453
+ }
454
+ exports.s1_256 = s1_256;
455
+ function g0_256(x) {
456
+ return rotr32(x, 7) ^ rotr32(x, 18) ^ x >>> 3;
457
+ }
458
+ exports.g0_256 = g0_256;
459
+ function g1_256(x) {
460
+ return rotr32(x, 17) ^ rotr32(x, 19) ^ x >>> 10;
461
+ }
462
+ exports.g1_256 = g1_256;
463
+ }
464
+ });
465
+
466
+ // node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/sha/1.js
467
+ var require__ = __commonJS({
468
+ "node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/sha/1.js"(exports, module) {
469
+ "use strict";
470
+ var utils = require_utils();
471
+ var common = require_common();
472
+ var shaCommon = require_common2();
473
+ var rotl32 = utils.rotl32;
474
+ var sum32 = utils.sum32;
475
+ var sum32_5 = utils.sum32_5;
476
+ var ft_1 = shaCommon.ft_1;
477
+ var BlockHash = common.BlockHash;
478
+ var sha1_K = [
479
+ 1518500249,
480
+ 1859775393,
481
+ 2400959708,
482
+ 3395469782
483
+ ];
484
+ function SHA1() {
485
+ if (!(this instanceof SHA1))
486
+ return new SHA1();
487
+ BlockHash.call(this);
488
+ this.h = [
489
+ 1732584193,
490
+ 4023233417,
491
+ 2562383102,
492
+ 271733878,
493
+ 3285377520
494
+ ];
495
+ this.W = new Array(80);
496
+ }
497
+ utils.inherits(SHA1, BlockHash);
498
+ module.exports = SHA1;
499
+ SHA1.blockSize = 512;
500
+ SHA1.outSize = 160;
501
+ SHA1.hmacStrength = 80;
502
+ SHA1.padLength = 64;
503
+ SHA1.prototype._update = function _update(msg, start) {
504
+ var W = this.W;
505
+ for (var i = 0; i < 16; i++)
506
+ W[i] = msg[start + i];
507
+ for (; i < W.length; i++)
508
+ W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1);
509
+ var a = this.h[0];
510
+ var b = this.h[1];
511
+ var c = this.h[2];
512
+ var d = this.h[3];
513
+ var e = this.h[4];
514
+ for (i = 0; i < W.length; i++) {
515
+ var s = ~~(i / 20);
516
+ var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]);
517
+ e = d;
518
+ d = c;
519
+ c = rotl32(b, 30);
520
+ b = a;
521
+ a = t;
522
+ }
523
+ this.h[0] = sum32(this.h[0], a);
524
+ this.h[1] = sum32(this.h[1], b);
525
+ this.h[2] = sum32(this.h[2], c);
526
+ this.h[3] = sum32(this.h[3], d);
527
+ this.h[4] = sum32(this.h[4], e);
528
+ };
529
+ SHA1.prototype._digest = function digest(enc) {
530
+ if (enc === "hex")
531
+ return utils.toHex32(this.h, "big");
532
+ else
533
+ return utils.split32(this.h, "big");
534
+ };
535
+ }
536
+ });
537
+
538
+ // node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/sha/256.js
539
+ var require__2 = __commonJS({
540
+ "node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/sha/256.js"(exports, module) {
541
+ "use strict";
542
+ var utils = require_utils();
543
+ var common = require_common();
544
+ var shaCommon = require_common2();
545
+ var assert = require_minimalistic_assert();
546
+ var sum32 = utils.sum32;
547
+ var sum32_4 = utils.sum32_4;
548
+ var sum32_5 = utils.sum32_5;
549
+ var ch32 = shaCommon.ch32;
550
+ var maj32 = shaCommon.maj32;
551
+ var s0_256 = shaCommon.s0_256;
552
+ var s1_256 = shaCommon.s1_256;
553
+ var g0_256 = shaCommon.g0_256;
554
+ var g1_256 = shaCommon.g1_256;
555
+ var BlockHash = common.BlockHash;
556
+ var sha256_K = [
557
+ 1116352408,
558
+ 1899447441,
559
+ 3049323471,
560
+ 3921009573,
561
+ 961987163,
562
+ 1508970993,
563
+ 2453635748,
564
+ 2870763221,
565
+ 3624381080,
566
+ 310598401,
567
+ 607225278,
568
+ 1426881987,
569
+ 1925078388,
570
+ 2162078206,
571
+ 2614888103,
572
+ 3248222580,
573
+ 3835390401,
574
+ 4022224774,
575
+ 264347078,
576
+ 604807628,
577
+ 770255983,
578
+ 1249150122,
579
+ 1555081692,
580
+ 1996064986,
581
+ 2554220882,
582
+ 2821834349,
583
+ 2952996808,
584
+ 3210313671,
585
+ 3336571891,
586
+ 3584528711,
587
+ 113926993,
588
+ 338241895,
589
+ 666307205,
590
+ 773529912,
591
+ 1294757372,
592
+ 1396182291,
593
+ 1695183700,
594
+ 1986661051,
595
+ 2177026350,
596
+ 2456956037,
597
+ 2730485921,
598
+ 2820302411,
599
+ 3259730800,
600
+ 3345764771,
601
+ 3516065817,
602
+ 3600352804,
603
+ 4094571909,
604
+ 275423344,
605
+ 430227734,
606
+ 506948616,
607
+ 659060556,
608
+ 883997877,
609
+ 958139571,
610
+ 1322822218,
611
+ 1537002063,
612
+ 1747873779,
613
+ 1955562222,
614
+ 2024104815,
615
+ 2227730452,
616
+ 2361852424,
617
+ 2428436474,
618
+ 2756734187,
619
+ 3204031479,
620
+ 3329325298
621
+ ];
622
+ function SHA256() {
623
+ if (!(this instanceof SHA256))
624
+ return new SHA256();
625
+ BlockHash.call(this);
626
+ this.h = [
627
+ 1779033703,
628
+ 3144134277,
629
+ 1013904242,
630
+ 2773480762,
631
+ 1359893119,
632
+ 2600822924,
633
+ 528734635,
634
+ 1541459225
635
+ ];
636
+ this.k = sha256_K;
637
+ this.W = new Array(64);
638
+ }
639
+ utils.inherits(SHA256, BlockHash);
640
+ module.exports = SHA256;
641
+ SHA256.blockSize = 512;
642
+ SHA256.outSize = 256;
643
+ SHA256.hmacStrength = 192;
644
+ SHA256.padLength = 64;
645
+ SHA256.prototype._update = function _update(msg, start) {
646
+ var W = this.W;
647
+ for (var i = 0; i < 16; i++)
648
+ W[i] = msg[start + i];
649
+ for (; i < W.length; i++)
650
+ W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]);
651
+ var a = this.h[0];
652
+ var b = this.h[1];
653
+ var c = this.h[2];
654
+ var d = this.h[3];
655
+ var e = this.h[4];
656
+ var f = this.h[5];
657
+ var g2 = this.h[6];
658
+ var h = this.h[7];
659
+ assert(this.k.length === W.length);
660
+ for (i = 0; i < W.length; i++) {
661
+ var T1 = sum32_5(h, s1_256(e), ch32(e, f, g2), this.k[i], W[i]);
662
+ var T2 = sum32(s0_256(a), maj32(a, b, c));
663
+ h = g2;
664
+ g2 = f;
665
+ f = e;
666
+ e = sum32(d, T1);
667
+ d = c;
668
+ c = b;
669
+ b = a;
670
+ a = sum32(T1, T2);
671
+ }
672
+ this.h[0] = sum32(this.h[0], a);
673
+ this.h[1] = sum32(this.h[1], b);
674
+ this.h[2] = sum32(this.h[2], c);
675
+ this.h[3] = sum32(this.h[3], d);
676
+ this.h[4] = sum32(this.h[4], e);
677
+ this.h[5] = sum32(this.h[5], f);
678
+ this.h[6] = sum32(this.h[6], g2);
679
+ this.h[7] = sum32(this.h[7], h);
680
+ };
681
+ SHA256.prototype._digest = function digest(enc) {
682
+ if (enc === "hex")
683
+ return utils.toHex32(this.h, "big");
684
+ else
685
+ return utils.split32(this.h, "big");
686
+ };
687
+ }
688
+ });
689
+
690
+ // node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/sha/224.js
691
+ var require__3 = __commonJS({
692
+ "node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/sha/224.js"(exports, module) {
693
+ "use strict";
694
+ var utils = require_utils();
695
+ var SHA256 = require__2();
696
+ function SHA224() {
697
+ if (!(this instanceof SHA224))
698
+ return new SHA224();
699
+ SHA256.call(this);
700
+ this.h = [
701
+ 3238371032,
702
+ 914150663,
703
+ 812702999,
704
+ 4144912697,
705
+ 4290775857,
706
+ 1750603025,
707
+ 1694076839,
708
+ 3204075428
709
+ ];
710
+ }
711
+ utils.inherits(SHA224, SHA256);
712
+ module.exports = SHA224;
713
+ SHA224.blockSize = 512;
714
+ SHA224.outSize = 224;
715
+ SHA224.hmacStrength = 192;
716
+ SHA224.padLength = 64;
717
+ SHA224.prototype._digest = function digest(enc) {
718
+ if (enc === "hex")
719
+ return utils.toHex32(this.h.slice(0, 7), "big");
720
+ else
721
+ return utils.split32(this.h.slice(0, 7), "big");
722
+ };
723
+ }
724
+ });
725
+
726
+ // node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/sha/512.js
727
+ var require__4 = __commonJS({
728
+ "node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/sha/512.js"(exports, module) {
729
+ "use strict";
730
+ var utils = require_utils();
731
+ var common = require_common();
732
+ var assert = require_minimalistic_assert();
733
+ var rotr64_hi = utils.rotr64_hi;
734
+ var rotr64_lo = utils.rotr64_lo;
735
+ var shr64_hi = utils.shr64_hi;
736
+ var shr64_lo = utils.shr64_lo;
737
+ var sum64 = utils.sum64;
738
+ var sum64_hi = utils.sum64_hi;
739
+ var sum64_lo = utils.sum64_lo;
740
+ var sum64_4_hi = utils.sum64_4_hi;
741
+ var sum64_4_lo = utils.sum64_4_lo;
742
+ var sum64_5_hi = utils.sum64_5_hi;
743
+ var sum64_5_lo = utils.sum64_5_lo;
744
+ var BlockHash = common.BlockHash;
745
+ var sha512_K = [
746
+ 1116352408,
747
+ 3609767458,
748
+ 1899447441,
749
+ 602891725,
750
+ 3049323471,
751
+ 3964484399,
752
+ 3921009573,
753
+ 2173295548,
754
+ 961987163,
755
+ 4081628472,
756
+ 1508970993,
757
+ 3053834265,
758
+ 2453635748,
759
+ 2937671579,
760
+ 2870763221,
761
+ 3664609560,
762
+ 3624381080,
763
+ 2734883394,
764
+ 310598401,
765
+ 1164996542,
766
+ 607225278,
767
+ 1323610764,
768
+ 1426881987,
769
+ 3590304994,
770
+ 1925078388,
771
+ 4068182383,
772
+ 2162078206,
773
+ 991336113,
774
+ 2614888103,
775
+ 633803317,
776
+ 3248222580,
777
+ 3479774868,
778
+ 3835390401,
779
+ 2666613458,
780
+ 4022224774,
781
+ 944711139,
782
+ 264347078,
783
+ 2341262773,
784
+ 604807628,
785
+ 2007800933,
786
+ 770255983,
787
+ 1495990901,
788
+ 1249150122,
789
+ 1856431235,
790
+ 1555081692,
791
+ 3175218132,
792
+ 1996064986,
793
+ 2198950837,
794
+ 2554220882,
795
+ 3999719339,
796
+ 2821834349,
797
+ 766784016,
798
+ 2952996808,
799
+ 2566594879,
800
+ 3210313671,
801
+ 3203337956,
802
+ 3336571891,
803
+ 1034457026,
804
+ 3584528711,
805
+ 2466948901,
806
+ 113926993,
807
+ 3758326383,
808
+ 338241895,
809
+ 168717936,
810
+ 666307205,
811
+ 1188179964,
812
+ 773529912,
813
+ 1546045734,
814
+ 1294757372,
815
+ 1522805485,
816
+ 1396182291,
817
+ 2643833823,
818
+ 1695183700,
819
+ 2343527390,
820
+ 1986661051,
821
+ 1014477480,
822
+ 2177026350,
823
+ 1206759142,
824
+ 2456956037,
825
+ 344077627,
826
+ 2730485921,
827
+ 1290863460,
828
+ 2820302411,
829
+ 3158454273,
830
+ 3259730800,
831
+ 3505952657,
832
+ 3345764771,
833
+ 106217008,
834
+ 3516065817,
835
+ 3606008344,
836
+ 3600352804,
837
+ 1432725776,
838
+ 4094571909,
839
+ 1467031594,
840
+ 275423344,
841
+ 851169720,
842
+ 430227734,
843
+ 3100823752,
844
+ 506948616,
845
+ 1363258195,
846
+ 659060556,
847
+ 3750685593,
848
+ 883997877,
849
+ 3785050280,
850
+ 958139571,
851
+ 3318307427,
852
+ 1322822218,
853
+ 3812723403,
854
+ 1537002063,
855
+ 2003034995,
856
+ 1747873779,
857
+ 3602036899,
858
+ 1955562222,
859
+ 1575990012,
860
+ 2024104815,
861
+ 1125592928,
862
+ 2227730452,
863
+ 2716904306,
864
+ 2361852424,
865
+ 442776044,
866
+ 2428436474,
867
+ 593698344,
868
+ 2756734187,
869
+ 3733110249,
870
+ 3204031479,
871
+ 2999351573,
872
+ 3329325298,
873
+ 3815920427,
874
+ 3391569614,
875
+ 3928383900,
876
+ 3515267271,
877
+ 566280711,
878
+ 3940187606,
879
+ 3454069534,
880
+ 4118630271,
881
+ 4000239992,
882
+ 116418474,
883
+ 1914138554,
884
+ 174292421,
885
+ 2731055270,
886
+ 289380356,
887
+ 3203993006,
888
+ 460393269,
889
+ 320620315,
890
+ 685471733,
891
+ 587496836,
892
+ 852142971,
893
+ 1086792851,
894
+ 1017036298,
895
+ 365543100,
896
+ 1126000580,
897
+ 2618297676,
898
+ 1288033470,
899
+ 3409855158,
900
+ 1501505948,
901
+ 4234509866,
902
+ 1607167915,
903
+ 987167468,
904
+ 1816402316,
905
+ 1246189591
906
+ ];
907
+ function SHA512() {
908
+ if (!(this instanceof SHA512))
909
+ return new SHA512();
910
+ BlockHash.call(this);
911
+ this.h = [
912
+ 1779033703,
913
+ 4089235720,
914
+ 3144134277,
915
+ 2227873595,
916
+ 1013904242,
917
+ 4271175723,
918
+ 2773480762,
919
+ 1595750129,
920
+ 1359893119,
921
+ 2917565137,
922
+ 2600822924,
923
+ 725511199,
924
+ 528734635,
925
+ 4215389547,
926
+ 1541459225,
927
+ 327033209
928
+ ];
929
+ this.k = sha512_K;
930
+ this.W = new Array(160);
931
+ }
932
+ utils.inherits(SHA512, BlockHash);
933
+ module.exports = SHA512;
934
+ SHA512.blockSize = 1024;
935
+ SHA512.outSize = 512;
936
+ SHA512.hmacStrength = 192;
937
+ SHA512.padLength = 128;
938
+ SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) {
939
+ var W = this.W;
940
+ for (var i = 0; i < 32; i++)
941
+ W[i] = msg[start + i];
942
+ for (; i < W.length; i += 2) {
943
+ var c0_hi = g1_512_hi(W[i - 4], W[i - 3]);
944
+ var c0_lo = g1_512_lo(W[i - 4], W[i - 3]);
945
+ var c1_hi = W[i - 14];
946
+ var c1_lo = W[i - 13];
947
+ var c2_hi = g0_512_hi(W[i - 30], W[i - 29]);
948
+ var c2_lo = g0_512_lo(W[i - 30], W[i - 29]);
949
+ var c3_hi = W[i - 32];
950
+ var c3_lo = W[i - 31];
951
+ W[i] = sum64_4_hi(
952
+ c0_hi,
953
+ c0_lo,
954
+ c1_hi,
955
+ c1_lo,
956
+ c2_hi,
957
+ c2_lo,
958
+ c3_hi,
959
+ c3_lo
960
+ );
961
+ W[i + 1] = sum64_4_lo(
962
+ c0_hi,
963
+ c0_lo,
964
+ c1_hi,
965
+ c1_lo,
966
+ c2_hi,
967
+ c2_lo,
968
+ c3_hi,
969
+ c3_lo
970
+ );
971
+ }
972
+ };
973
+ SHA512.prototype._update = function _update(msg, start) {
974
+ this._prepareBlock(msg, start);
975
+ var W = this.W;
976
+ var ah = this.h[0];
977
+ var al = this.h[1];
978
+ var bh = this.h[2];
979
+ var bl = this.h[3];
980
+ var ch = this.h[4];
981
+ var cl = this.h[5];
982
+ var dh = this.h[6];
983
+ var dl = this.h[7];
984
+ var eh = this.h[8];
985
+ var el = this.h[9];
986
+ var fh = this.h[10];
987
+ var fl = this.h[11];
988
+ var gh = this.h[12];
989
+ var gl = this.h[13];
990
+ var hh = this.h[14];
991
+ var hl = this.h[15];
992
+ assert(this.k.length === W.length);
993
+ for (var i = 0; i < W.length; i += 2) {
994
+ var c0_hi = hh;
995
+ var c0_lo = hl;
996
+ var c1_hi = s1_512_hi(eh, el);
997
+ var c1_lo = s1_512_lo(eh, el);
998
+ var c2_hi = ch64_hi(eh, el, fh, fl, gh, gl);
999
+ var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl);
1000
+ var c3_hi = this.k[i];
1001
+ var c3_lo = this.k[i + 1];
1002
+ var c4_hi = W[i];
1003
+ var c4_lo = W[i + 1];
1004
+ var T1_hi = sum64_5_hi(
1005
+ c0_hi,
1006
+ c0_lo,
1007
+ c1_hi,
1008
+ c1_lo,
1009
+ c2_hi,
1010
+ c2_lo,
1011
+ c3_hi,
1012
+ c3_lo,
1013
+ c4_hi,
1014
+ c4_lo
1015
+ );
1016
+ var T1_lo = sum64_5_lo(
1017
+ c0_hi,
1018
+ c0_lo,
1019
+ c1_hi,
1020
+ c1_lo,
1021
+ c2_hi,
1022
+ c2_lo,
1023
+ c3_hi,
1024
+ c3_lo,
1025
+ c4_hi,
1026
+ c4_lo
1027
+ );
1028
+ c0_hi = s0_512_hi(ah, al);
1029
+ c0_lo = s0_512_lo(ah, al);
1030
+ c1_hi = maj64_hi(ah, al, bh, bl, ch, cl);
1031
+ c1_lo = maj64_lo(ah, al, bh, bl, ch, cl);
1032
+ var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo);
1033
+ var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo);
1034
+ hh = gh;
1035
+ hl = gl;
1036
+ gh = fh;
1037
+ gl = fl;
1038
+ fh = eh;
1039
+ fl = el;
1040
+ eh = sum64_hi(dh, dl, T1_hi, T1_lo);
1041
+ el = sum64_lo(dl, dl, T1_hi, T1_lo);
1042
+ dh = ch;
1043
+ dl = cl;
1044
+ ch = bh;
1045
+ cl = bl;
1046
+ bh = ah;
1047
+ bl = al;
1048
+ ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo);
1049
+ al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo);
1050
+ }
1051
+ sum64(this.h, 0, ah, al);
1052
+ sum64(this.h, 2, bh, bl);
1053
+ sum64(this.h, 4, ch, cl);
1054
+ sum64(this.h, 6, dh, dl);
1055
+ sum64(this.h, 8, eh, el);
1056
+ sum64(this.h, 10, fh, fl);
1057
+ sum64(this.h, 12, gh, gl);
1058
+ sum64(this.h, 14, hh, hl);
1059
+ };
1060
+ SHA512.prototype._digest = function digest(enc) {
1061
+ if (enc === "hex")
1062
+ return utils.toHex32(this.h, "big");
1063
+ else
1064
+ return utils.split32(this.h, "big");
1065
+ };
1066
+ function ch64_hi(xh, xl, yh, yl, zh) {
1067
+ var r = xh & yh ^ ~xh & zh;
1068
+ if (r < 0)
1069
+ r += 4294967296;
1070
+ return r;
1071
+ }
1072
+ function ch64_lo(xh, xl, yh, yl, zh, zl) {
1073
+ var r = xl & yl ^ ~xl & zl;
1074
+ if (r < 0)
1075
+ r += 4294967296;
1076
+ return r;
1077
+ }
1078
+ function maj64_hi(xh, xl, yh, yl, zh) {
1079
+ var r = xh & yh ^ xh & zh ^ yh & zh;
1080
+ if (r < 0)
1081
+ r += 4294967296;
1082
+ return r;
1083
+ }
1084
+ function maj64_lo(xh, xl, yh, yl, zh, zl) {
1085
+ var r = xl & yl ^ xl & zl ^ yl & zl;
1086
+ if (r < 0)
1087
+ r += 4294967296;
1088
+ return r;
1089
+ }
1090
+ function s0_512_hi(xh, xl) {
1091
+ var c0_hi = rotr64_hi(xh, xl, 28);
1092
+ var c1_hi = rotr64_hi(xl, xh, 2);
1093
+ var c2_hi = rotr64_hi(xl, xh, 7);
1094
+ var r = c0_hi ^ c1_hi ^ c2_hi;
1095
+ if (r < 0)
1096
+ r += 4294967296;
1097
+ return r;
1098
+ }
1099
+ function s0_512_lo(xh, xl) {
1100
+ var c0_lo = rotr64_lo(xh, xl, 28);
1101
+ var c1_lo = rotr64_lo(xl, xh, 2);
1102
+ var c2_lo = rotr64_lo(xl, xh, 7);
1103
+ var r = c0_lo ^ c1_lo ^ c2_lo;
1104
+ if (r < 0)
1105
+ r += 4294967296;
1106
+ return r;
1107
+ }
1108
+ function s1_512_hi(xh, xl) {
1109
+ var c0_hi = rotr64_hi(xh, xl, 14);
1110
+ var c1_hi = rotr64_hi(xh, xl, 18);
1111
+ var c2_hi = rotr64_hi(xl, xh, 9);
1112
+ var r = c0_hi ^ c1_hi ^ c2_hi;
1113
+ if (r < 0)
1114
+ r += 4294967296;
1115
+ return r;
1116
+ }
1117
+ function s1_512_lo(xh, xl) {
1118
+ var c0_lo = rotr64_lo(xh, xl, 14);
1119
+ var c1_lo = rotr64_lo(xh, xl, 18);
1120
+ var c2_lo = rotr64_lo(xl, xh, 9);
1121
+ var r = c0_lo ^ c1_lo ^ c2_lo;
1122
+ if (r < 0)
1123
+ r += 4294967296;
1124
+ return r;
1125
+ }
1126
+ function g0_512_hi(xh, xl) {
1127
+ var c0_hi = rotr64_hi(xh, xl, 1);
1128
+ var c1_hi = rotr64_hi(xh, xl, 8);
1129
+ var c2_hi = shr64_hi(xh, xl, 7);
1130
+ var r = c0_hi ^ c1_hi ^ c2_hi;
1131
+ if (r < 0)
1132
+ r += 4294967296;
1133
+ return r;
1134
+ }
1135
+ function g0_512_lo(xh, xl) {
1136
+ var c0_lo = rotr64_lo(xh, xl, 1);
1137
+ var c1_lo = rotr64_lo(xh, xl, 8);
1138
+ var c2_lo = shr64_lo(xh, xl, 7);
1139
+ var r = c0_lo ^ c1_lo ^ c2_lo;
1140
+ if (r < 0)
1141
+ r += 4294967296;
1142
+ return r;
1143
+ }
1144
+ function g1_512_hi(xh, xl) {
1145
+ var c0_hi = rotr64_hi(xh, xl, 19);
1146
+ var c1_hi = rotr64_hi(xl, xh, 29);
1147
+ var c2_hi = shr64_hi(xh, xl, 6);
1148
+ var r = c0_hi ^ c1_hi ^ c2_hi;
1149
+ if (r < 0)
1150
+ r += 4294967296;
1151
+ return r;
1152
+ }
1153
+ function g1_512_lo(xh, xl) {
1154
+ var c0_lo = rotr64_lo(xh, xl, 19);
1155
+ var c1_lo = rotr64_lo(xl, xh, 29);
1156
+ var c2_lo = shr64_lo(xh, xl, 6);
1157
+ var r = c0_lo ^ c1_lo ^ c2_lo;
1158
+ if (r < 0)
1159
+ r += 4294967296;
1160
+ return r;
1161
+ }
1162
+ }
1163
+ });
1164
+
1165
+ // node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/sha/384.js
1166
+ var require__5 = __commonJS({
1167
+ "node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/sha/384.js"(exports, module) {
1168
+ "use strict";
1169
+ var utils = require_utils();
1170
+ var SHA512 = require__4();
1171
+ function SHA384() {
1172
+ if (!(this instanceof SHA384))
1173
+ return new SHA384();
1174
+ SHA512.call(this);
1175
+ this.h = [
1176
+ 3418070365,
1177
+ 3238371032,
1178
+ 1654270250,
1179
+ 914150663,
1180
+ 2438529370,
1181
+ 812702999,
1182
+ 355462360,
1183
+ 4144912697,
1184
+ 1731405415,
1185
+ 4290775857,
1186
+ 2394180231,
1187
+ 1750603025,
1188
+ 3675008525,
1189
+ 1694076839,
1190
+ 1203062813,
1191
+ 3204075428
1192
+ ];
1193
+ }
1194
+ utils.inherits(SHA384, SHA512);
1195
+ module.exports = SHA384;
1196
+ SHA384.blockSize = 1024;
1197
+ SHA384.outSize = 384;
1198
+ SHA384.hmacStrength = 192;
1199
+ SHA384.padLength = 128;
1200
+ SHA384.prototype._digest = function digest(enc) {
1201
+ if (enc === "hex")
1202
+ return utils.toHex32(this.h.slice(0, 12), "big");
1203
+ else
1204
+ return utils.split32(this.h.slice(0, 12), "big");
1205
+ };
1206
+ }
1207
+ });
1208
+
1209
+ // node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/sha.js
1210
+ var require_sha = __commonJS({
1211
+ "node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/sha.js"(exports) {
1212
+ "use strict";
1213
+ exports.sha1 = require__();
1214
+ exports.sha224 = require__3();
1215
+ exports.sha256 = require__2();
1216
+ exports.sha384 = require__5();
1217
+ exports.sha512 = require__4();
1218
+ }
1219
+ });
1220
+
1221
+ // node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/ripemd.js
1222
+ var require_ripemd = __commonJS({
1223
+ "node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/ripemd.js"(exports) {
1224
+ "use strict";
1225
+ var utils = require_utils();
1226
+ var common = require_common();
1227
+ var rotl32 = utils.rotl32;
1228
+ var sum32 = utils.sum32;
1229
+ var sum32_3 = utils.sum32_3;
1230
+ var sum32_4 = utils.sum32_4;
1231
+ var BlockHash = common.BlockHash;
1232
+ function RIPEMD160() {
1233
+ if (!(this instanceof RIPEMD160))
1234
+ return new RIPEMD160();
1235
+ BlockHash.call(this);
1236
+ this.h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
1237
+ this.endian = "little";
1238
+ }
1239
+ utils.inherits(RIPEMD160, BlockHash);
1240
+ exports.ripemd160 = RIPEMD160;
1241
+ RIPEMD160.blockSize = 512;
1242
+ RIPEMD160.outSize = 160;
1243
+ RIPEMD160.hmacStrength = 192;
1244
+ RIPEMD160.padLength = 64;
1245
+ RIPEMD160.prototype._update = function update(msg, start) {
1246
+ var A = this.h[0];
1247
+ var B = this.h[1];
1248
+ var C = this.h[2];
1249
+ var D = this.h[3];
1250
+ var E = this.h[4];
1251
+ var Ah = A;
1252
+ var Bh = B;
1253
+ var Ch = C;
1254
+ var Dh = D;
1255
+ var Eh = E;
1256
+ for (var j = 0; j < 80; j++) {
1257
+ var T = sum32(
1258
+ rotl32(
1259
+ sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)),
1260
+ s[j]
1261
+ ),
1262
+ E
1263
+ );
1264
+ A = E;
1265
+ E = D;
1266
+ D = rotl32(C, 10);
1267
+ C = B;
1268
+ B = T;
1269
+ T = sum32(
1270
+ rotl32(
1271
+ sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)),
1272
+ sh[j]
1273
+ ),
1274
+ Eh
1275
+ );
1276
+ Ah = Eh;
1277
+ Eh = Dh;
1278
+ Dh = rotl32(Ch, 10);
1279
+ Ch = Bh;
1280
+ Bh = T;
1281
+ }
1282
+ T = sum32_3(this.h[1], C, Dh);
1283
+ this.h[1] = sum32_3(this.h[2], D, Eh);
1284
+ this.h[2] = sum32_3(this.h[3], E, Ah);
1285
+ this.h[3] = sum32_3(this.h[4], A, Bh);
1286
+ this.h[4] = sum32_3(this.h[0], B, Ch);
1287
+ this.h[0] = T;
1288
+ };
1289
+ RIPEMD160.prototype._digest = function digest(enc) {
1290
+ if (enc === "hex")
1291
+ return utils.toHex32(this.h, "little");
1292
+ else
1293
+ return utils.split32(this.h, "little");
1294
+ };
1295
+ function f(j, x, y, z) {
1296
+ if (j <= 15)
1297
+ return x ^ y ^ z;
1298
+ else if (j <= 31)
1299
+ return x & y | ~x & z;
1300
+ else if (j <= 47)
1301
+ return (x | ~y) ^ z;
1302
+ else if (j <= 63)
1303
+ return x & z | y & ~z;
1304
+ else
1305
+ return x ^ (y | ~z);
1306
+ }
1307
+ function K(j) {
1308
+ if (j <= 15)
1309
+ return 0;
1310
+ else if (j <= 31)
1311
+ return 1518500249;
1312
+ else if (j <= 47)
1313
+ return 1859775393;
1314
+ else if (j <= 63)
1315
+ return 2400959708;
1316
+ else
1317
+ return 2840853838;
1318
+ }
1319
+ function Kh(j) {
1320
+ if (j <= 15)
1321
+ return 1352829926;
1322
+ else if (j <= 31)
1323
+ return 1548603684;
1324
+ else if (j <= 47)
1325
+ return 1836072691;
1326
+ else if (j <= 63)
1327
+ return 2053994217;
1328
+ else
1329
+ return 0;
1330
+ }
1331
+ var r = [
1332
+ 0,
1333
+ 1,
1334
+ 2,
1335
+ 3,
1336
+ 4,
1337
+ 5,
1338
+ 6,
1339
+ 7,
1340
+ 8,
1341
+ 9,
1342
+ 10,
1343
+ 11,
1344
+ 12,
1345
+ 13,
1346
+ 14,
1347
+ 15,
1348
+ 7,
1349
+ 4,
1350
+ 13,
1351
+ 1,
1352
+ 10,
1353
+ 6,
1354
+ 15,
1355
+ 3,
1356
+ 12,
1357
+ 0,
1358
+ 9,
1359
+ 5,
1360
+ 2,
1361
+ 14,
1362
+ 11,
1363
+ 8,
1364
+ 3,
1365
+ 10,
1366
+ 14,
1367
+ 4,
1368
+ 9,
1369
+ 15,
1370
+ 8,
1371
+ 1,
1372
+ 2,
1373
+ 7,
1374
+ 0,
1375
+ 6,
1376
+ 13,
1377
+ 11,
1378
+ 5,
1379
+ 12,
1380
+ 1,
1381
+ 9,
1382
+ 11,
1383
+ 10,
1384
+ 0,
1385
+ 8,
1386
+ 12,
1387
+ 4,
1388
+ 13,
1389
+ 3,
1390
+ 7,
1391
+ 15,
1392
+ 14,
1393
+ 5,
1394
+ 6,
1395
+ 2,
1396
+ 4,
1397
+ 0,
1398
+ 5,
1399
+ 9,
1400
+ 7,
1401
+ 12,
1402
+ 2,
1403
+ 10,
1404
+ 14,
1405
+ 1,
1406
+ 3,
1407
+ 8,
1408
+ 11,
1409
+ 6,
1410
+ 15,
1411
+ 13
1412
+ ];
1413
+ var rh = [
1414
+ 5,
1415
+ 14,
1416
+ 7,
1417
+ 0,
1418
+ 9,
1419
+ 2,
1420
+ 11,
1421
+ 4,
1422
+ 13,
1423
+ 6,
1424
+ 15,
1425
+ 8,
1426
+ 1,
1427
+ 10,
1428
+ 3,
1429
+ 12,
1430
+ 6,
1431
+ 11,
1432
+ 3,
1433
+ 7,
1434
+ 0,
1435
+ 13,
1436
+ 5,
1437
+ 10,
1438
+ 14,
1439
+ 15,
1440
+ 8,
1441
+ 12,
1442
+ 4,
1443
+ 9,
1444
+ 1,
1445
+ 2,
1446
+ 15,
1447
+ 5,
1448
+ 1,
1449
+ 3,
1450
+ 7,
1451
+ 14,
1452
+ 6,
1453
+ 9,
1454
+ 11,
1455
+ 8,
1456
+ 12,
1457
+ 2,
1458
+ 10,
1459
+ 0,
1460
+ 4,
1461
+ 13,
1462
+ 8,
1463
+ 6,
1464
+ 4,
1465
+ 1,
1466
+ 3,
1467
+ 11,
1468
+ 15,
1469
+ 0,
1470
+ 5,
1471
+ 12,
1472
+ 2,
1473
+ 13,
1474
+ 9,
1475
+ 7,
1476
+ 10,
1477
+ 14,
1478
+ 12,
1479
+ 15,
1480
+ 10,
1481
+ 4,
1482
+ 1,
1483
+ 5,
1484
+ 8,
1485
+ 7,
1486
+ 6,
1487
+ 2,
1488
+ 13,
1489
+ 14,
1490
+ 0,
1491
+ 3,
1492
+ 9,
1493
+ 11
1494
+ ];
1495
+ var s = [
1496
+ 11,
1497
+ 14,
1498
+ 15,
1499
+ 12,
1500
+ 5,
1501
+ 8,
1502
+ 7,
1503
+ 9,
1504
+ 11,
1505
+ 13,
1506
+ 14,
1507
+ 15,
1508
+ 6,
1509
+ 7,
1510
+ 9,
1511
+ 8,
1512
+ 7,
1513
+ 6,
1514
+ 8,
1515
+ 13,
1516
+ 11,
1517
+ 9,
1518
+ 7,
1519
+ 15,
1520
+ 7,
1521
+ 12,
1522
+ 15,
1523
+ 9,
1524
+ 11,
1525
+ 7,
1526
+ 13,
1527
+ 12,
1528
+ 11,
1529
+ 13,
1530
+ 6,
1531
+ 7,
1532
+ 14,
1533
+ 9,
1534
+ 13,
1535
+ 15,
1536
+ 14,
1537
+ 8,
1538
+ 13,
1539
+ 6,
1540
+ 5,
1541
+ 12,
1542
+ 7,
1543
+ 5,
1544
+ 11,
1545
+ 12,
1546
+ 14,
1547
+ 15,
1548
+ 14,
1549
+ 15,
1550
+ 9,
1551
+ 8,
1552
+ 9,
1553
+ 14,
1554
+ 5,
1555
+ 6,
1556
+ 8,
1557
+ 6,
1558
+ 5,
1559
+ 12,
1560
+ 9,
1561
+ 15,
1562
+ 5,
1563
+ 11,
1564
+ 6,
1565
+ 8,
1566
+ 13,
1567
+ 12,
1568
+ 5,
1569
+ 12,
1570
+ 13,
1571
+ 14,
1572
+ 11,
1573
+ 8,
1574
+ 5,
1575
+ 6
1576
+ ];
1577
+ var sh = [
1578
+ 8,
1579
+ 9,
1580
+ 9,
1581
+ 11,
1582
+ 13,
1583
+ 15,
1584
+ 15,
1585
+ 5,
1586
+ 7,
1587
+ 7,
1588
+ 8,
1589
+ 11,
1590
+ 14,
1591
+ 14,
1592
+ 12,
1593
+ 6,
1594
+ 9,
1595
+ 13,
1596
+ 15,
1597
+ 7,
1598
+ 12,
1599
+ 8,
1600
+ 9,
1601
+ 11,
1602
+ 7,
1603
+ 7,
1604
+ 12,
1605
+ 7,
1606
+ 6,
1607
+ 15,
1608
+ 13,
1609
+ 11,
1610
+ 9,
1611
+ 7,
1612
+ 15,
1613
+ 11,
1614
+ 8,
1615
+ 6,
1616
+ 6,
1617
+ 14,
1618
+ 12,
1619
+ 13,
1620
+ 5,
1621
+ 14,
1622
+ 13,
1623
+ 13,
1624
+ 7,
1625
+ 5,
1626
+ 15,
1627
+ 5,
1628
+ 8,
1629
+ 11,
1630
+ 14,
1631
+ 14,
1632
+ 6,
1633
+ 14,
1634
+ 6,
1635
+ 9,
1636
+ 12,
1637
+ 9,
1638
+ 12,
1639
+ 5,
1640
+ 15,
1641
+ 8,
1642
+ 8,
1643
+ 5,
1644
+ 12,
1645
+ 9,
1646
+ 12,
1647
+ 5,
1648
+ 14,
1649
+ 6,
1650
+ 8,
1651
+ 13,
1652
+ 6,
1653
+ 5,
1654
+ 15,
1655
+ 13,
1656
+ 11,
1657
+ 11
1658
+ ];
1659
+ }
1660
+ });
1661
+
1662
+ // node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/hmac.js
1663
+ var require_hmac = __commonJS({
1664
+ "node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash/hmac.js"(exports, module) {
1665
+ "use strict";
1666
+ var utils = require_utils();
1667
+ var assert = require_minimalistic_assert();
1668
+ function Hmac(hash, key, enc) {
1669
+ if (!(this instanceof Hmac))
1670
+ return new Hmac(hash, key, enc);
1671
+ this.Hash = hash;
1672
+ this.blockSize = hash.blockSize / 8;
1673
+ this.outSize = hash.outSize / 8;
1674
+ this.inner = null;
1675
+ this.outer = null;
1676
+ this._init(utils.toArray(key, enc));
1677
+ }
1678
+ module.exports = Hmac;
1679
+ Hmac.prototype._init = function init(key) {
1680
+ if (key.length > this.blockSize)
1681
+ key = new this.Hash().update(key).digest();
1682
+ assert(key.length <= this.blockSize);
1683
+ for (var i = key.length; i < this.blockSize; i++)
1684
+ key.push(0);
1685
+ for (i = 0; i < key.length; i++)
1686
+ key[i] ^= 54;
1687
+ this.inner = new this.Hash().update(key);
1688
+ for (i = 0; i < key.length; i++)
1689
+ key[i] ^= 106;
1690
+ this.outer = new this.Hash().update(key);
1691
+ };
1692
+ Hmac.prototype.update = function update(msg, enc) {
1693
+ this.inner.update(msg, enc);
1694
+ return this;
1695
+ };
1696
+ Hmac.prototype.digest = function digest(enc) {
1697
+ this.outer.update(this.inner.digest());
1698
+ return this.outer.digest(enc);
1699
+ };
1700
+ }
1701
+ });
1702
+
1703
+ // node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash.js
1704
+ var require_hash = __commonJS({
1705
+ "node_modules/.pnpm/hash.js@1.1.7/node_modules/hash.js/lib/hash.js"(exports) {
1706
+ var hash = exports;
1707
+ hash.utils = require_utils();
1708
+ hash.common = require_common();
1709
+ hash.sha = require_sha();
1710
+ hash.ripemd = require_ripemd();
1711
+ hash.hmac = require_hmac();
1712
+ hash.sha1 = hash.sha.sha1;
1713
+ hash.sha256 = hash.sha.sha256;
1714
+ hash.sha224 = hash.sha.sha224;
1715
+ hash.sha384 = hash.sha.sha384;
1716
+ hash.sha512 = hash.sha.sha512;
1717
+ hash.ripemd160 = hash.ripemd.ripemd160;
1718
+ }
1719
+ });
1720
+
1721
+ // node_modules/.pnpm/jsbn@1.1.0/node_modules/jsbn/index.js
1722
+ var require_jsbn = __commonJS({
1723
+ "node_modules/.pnpm/jsbn@1.1.0/node_modules/jsbn/index.js"(exports, module) {
1724
+ (function() {
1725
+ var dbits;
1726
+ var canary = 244837814094590;
1727
+ var j_lm = (canary & 16777215) == 15715070;
1728
+ function BigInteger3(a, b, c) {
1729
+ if (a != null)
1730
+ if ("number" == typeof a)
1731
+ this.fromNumber(a, b, c);
1732
+ else if (b == null && "string" != typeof a)
1733
+ this.fromString(a, 256);
1734
+ else
1735
+ this.fromString(a, b);
1736
+ }
1737
+ function nbi() {
1738
+ return new BigInteger3(null);
1739
+ }
1740
+ function am1(i, x, w, j, c, n) {
1741
+ while (--n >= 0) {
1742
+ var v = x * this[i++] + w[j] + c;
1743
+ c = Math.floor(v / 67108864);
1744
+ w[j++] = v & 67108863;
1745
+ }
1746
+ return c;
1747
+ }
1748
+ function am2(i, x, w, j, c, n) {
1749
+ var xl = x & 32767, xh = x >> 15;
1750
+ while (--n >= 0) {
1751
+ var l = this[i] & 32767;
1752
+ var h = this[i++] >> 15;
1753
+ var m = xh * l + h * xl;
1754
+ l = xl * l + ((m & 32767) << 15) + w[j] + (c & 1073741823);
1755
+ c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30);
1756
+ w[j++] = l & 1073741823;
1757
+ }
1758
+ return c;
1759
+ }
1760
+ function am3(i, x, w, j, c, n) {
1761
+ var xl = x & 16383, xh = x >> 14;
1762
+ while (--n >= 0) {
1763
+ var l = this[i] & 16383;
1764
+ var h = this[i++] >> 14;
1765
+ var m = xh * l + h * xl;
1766
+ l = xl * l + ((m & 16383) << 14) + w[j] + c;
1767
+ c = (l >> 28) + (m >> 14) + xh * h;
1768
+ w[j++] = l & 268435455;
1769
+ }
1770
+ return c;
1771
+ }
1772
+ var inBrowser = typeof navigator !== "undefined";
1773
+ if (inBrowser && j_lm && navigator.appName == "Microsoft Internet Explorer") {
1774
+ BigInteger3.prototype.am = am2;
1775
+ dbits = 30;
1776
+ } else if (inBrowser && j_lm && navigator.appName != "Netscape") {
1777
+ BigInteger3.prototype.am = am1;
1778
+ dbits = 26;
1779
+ } else {
1780
+ BigInteger3.prototype.am = am3;
1781
+ dbits = 28;
1782
+ }
1783
+ BigInteger3.prototype.DB = dbits;
1784
+ BigInteger3.prototype.DM = (1 << dbits) - 1;
1785
+ BigInteger3.prototype.DV = 1 << dbits;
1786
+ var BI_FP = 52;
1787
+ BigInteger3.prototype.FV = Math.pow(2, BI_FP);
1788
+ BigInteger3.prototype.F1 = BI_FP - dbits;
1789
+ BigInteger3.prototype.F2 = 2 * dbits - BI_FP;
1790
+ var BI_RM = "0123456789abcdefghijklmnopqrstuvwxyz";
1791
+ var BI_RC = new Array();
1792
+ var rr, vv;
1793
+ rr = "0".charCodeAt(0);
1794
+ for (vv = 0; vv <= 9; ++vv)
1795
+ BI_RC[rr++] = vv;
1796
+ rr = "a".charCodeAt(0);
1797
+ for (vv = 10; vv < 36; ++vv)
1798
+ BI_RC[rr++] = vv;
1799
+ rr = "A".charCodeAt(0);
1800
+ for (vv = 10; vv < 36; ++vv)
1801
+ BI_RC[rr++] = vv;
1802
+ function int2char(n) {
1803
+ return BI_RM.charAt(n);
1804
+ }
1805
+ function intAt(s, i) {
1806
+ var c = BI_RC[s.charCodeAt(i)];
1807
+ return c == null ? -1 : c;
1808
+ }
1809
+ function bnpCopyTo(r) {
1810
+ for (var i = this.t - 1; i >= 0; --i)
1811
+ r[i] = this[i];
1812
+ r.t = this.t;
1813
+ r.s = this.s;
1814
+ }
1815
+ function bnpFromInt(x) {
1816
+ this.t = 1;
1817
+ this.s = x < 0 ? -1 : 0;
1818
+ if (x > 0)
1819
+ this[0] = x;
1820
+ else if (x < -1)
1821
+ this[0] = x + this.DV;
1822
+ else
1823
+ this.t = 0;
1824
+ }
1825
+ function nbv(i) {
1826
+ var r = nbi();
1827
+ r.fromInt(i);
1828
+ return r;
1829
+ }
1830
+ function bnpFromString(s, b) {
1831
+ var k2;
1832
+ if (b == 16)
1833
+ k2 = 4;
1834
+ else if (b == 8)
1835
+ k2 = 3;
1836
+ else if (b == 256)
1837
+ k2 = 8;
1838
+ else if (b == 2)
1839
+ k2 = 1;
1840
+ else if (b == 32)
1841
+ k2 = 5;
1842
+ else if (b == 4)
1843
+ k2 = 2;
1844
+ else {
1845
+ this.fromRadix(s, b);
1846
+ return;
1847
+ }
1848
+ this.t = 0;
1849
+ this.s = 0;
1850
+ var i = s.length, mi = false, sh = 0;
1851
+ while (--i >= 0) {
1852
+ var x = k2 == 8 ? s[i] & 255 : intAt(s, i);
1853
+ if (x < 0) {
1854
+ if (s.charAt(i) == "-")
1855
+ mi = true;
1856
+ continue;
1857
+ }
1858
+ mi = false;
1859
+ if (sh == 0)
1860
+ this[this.t++] = x;
1861
+ else if (sh + k2 > this.DB) {
1862
+ this[this.t - 1] |= (x & (1 << this.DB - sh) - 1) << sh;
1863
+ this[this.t++] = x >> this.DB - sh;
1864
+ } else
1865
+ this[this.t - 1] |= x << sh;
1866
+ sh += k2;
1867
+ if (sh >= this.DB)
1868
+ sh -= this.DB;
1869
+ }
1870
+ if (k2 == 8 && (s[0] & 128) != 0) {
1871
+ this.s = -1;
1872
+ if (sh > 0)
1873
+ this[this.t - 1] |= (1 << this.DB - sh) - 1 << sh;
1874
+ }
1875
+ this.clamp();
1876
+ if (mi)
1877
+ BigInteger3.ZERO.subTo(this, this);
1878
+ }
1879
+ function bnpClamp() {
1880
+ var c = this.s & this.DM;
1881
+ while (this.t > 0 && this[this.t - 1] == c)
1882
+ --this.t;
1883
+ }
1884
+ function bnToString(b) {
1885
+ if (this.s < 0)
1886
+ return "-" + this.negate().toString(b);
1887
+ var k2;
1888
+ if (b == 16)
1889
+ k2 = 4;
1890
+ else if (b == 8)
1891
+ k2 = 3;
1892
+ else if (b == 2)
1893
+ k2 = 1;
1894
+ else if (b == 32)
1895
+ k2 = 5;
1896
+ else if (b == 4)
1897
+ k2 = 2;
1898
+ else
1899
+ return this.toRadix(b);
1900
+ var km = (1 << k2) - 1, d, m = false, r = "", i = this.t;
1901
+ var p = this.DB - i * this.DB % k2;
1902
+ if (i-- > 0) {
1903
+ if (p < this.DB && (d = this[i] >> p) > 0) {
1904
+ m = true;
1905
+ r = int2char(d);
1906
+ }
1907
+ while (i >= 0) {
1908
+ if (p < k2) {
1909
+ d = (this[i] & (1 << p) - 1) << k2 - p;
1910
+ d |= this[--i] >> (p += this.DB - k2);
1911
+ } else {
1912
+ d = this[i] >> (p -= k2) & km;
1913
+ if (p <= 0) {
1914
+ p += this.DB;
1915
+ --i;
1916
+ }
1917
+ }
1918
+ if (d > 0)
1919
+ m = true;
1920
+ if (m)
1921
+ r += int2char(d);
1922
+ }
1923
+ }
1924
+ return m ? r : "0";
1925
+ }
1926
+ function bnNegate() {
1927
+ var r = nbi();
1928
+ BigInteger3.ZERO.subTo(this, r);
1929
+ return r;
1930
+ }
1931
+ function bnAbs() {
1932
+ return this.s < 0 ? this.negate() : this;
1933
+ }
1934
+ function bnCompareTo(a) {
1935
+ var r = this.s - a.s;
1936
+ if (r != 0)
1937
+ return r;
1938
+ var i = this.t;
1939
+ r = i - a.t;
1940
+ if (r != 0)
1941
+ return this.s < 0 ? -r : r;
1942
+ while (--i >= 0)
1943
+ if ((r = this[i] - a[i]) != 0)
1944
+ return r;
1945
+ return 0;
1946
+ }
1947
+ function nbits(x) {
1948
+ var r = 1, t2;
1949
+ if ((t2 = x >>> 16) != 0) {
1950
+ x = t2;
1951
+ r += 16;
1952
+ }
1953
+ if ((t2 = x >> 8) != 0) {
1954
+ x = t2;
1955
+ r += 8;
1956
+ }
1957
+ if ((t2 = x >> 4) != 0) {
1958
+ x = t2;
1959
+ r += 4;
1960
+ }
1961
+ if ((t2 = x >> 2) != 0) {
1962
+ x = t2;
1963
+ r += 2;
1964
+ }
1965
+ if ((t2 = x >> 1) != 0) {
1966
+ x = t2;
1967
+ r += 1;
1968
+ }
1969
+ return r;
1970
+ }
1971
+ function bnBitLength() {
1972
+ if (this.t <= 0)
1973
+ return 0;
1974
+ return this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ this.s & this.DM);
1975
+ }
1976
+ function bnpDLShiftTo(n, r) {
1977
+ var i;
1978
+ for (i = this.t - 1; i >= 0; --i)
1979
+ r[i + n] = this[i];
1980
+ for (i = n - 1; i >= 0; --i)
1981
+ r[i] = 0;
1982
+ r.t = this.t + n;
1983
+ r.s = this.s;
1984
+ }
1985
+ function bnpDRShiftTo(n, r) {
1986
+ for (var i = n; i < this.t; ++i)
1987
+ r[i - n] = this[i];
1988
+ r.t = Math.max(this.t - n, 0);
1989
+ r.s = this.s;
1990
+ }
1991
+ function bnpLShiftTo(n, r) {
1992
+ var bs = n % this.DB;
1993
+ var cbs = this.DB - bs;
1994
+ var bm = (1 << cbs) - 1;
1995
+ var ds = Math.floor(n / this.DB), c = this.s << bs & this.DM, i;
1996
+ for (i = this.t - 1; i >= 0; --i) {
1997
+ r[i + ds + 1] = this[i] >> cbs | c;
1998
+ c = (this[i] & bm) << bs;
1999
+ }
2000
+ for (i = ds - 1; i >= 0; --i)
2001
+ r[i] = 0;
2002
+ r[ds] = c;
2003
+ r.t = this.t + ds + 1;
2004
+ r.s = this.s;
2005
+ r.clamp();
2006
+ }
2007
+ function bnpRShiftTo(n, r) {
2008
+ r.s = this.s;
2009
+ var ds = Math.floor(n / this.DB);
2010
+ if (ds >= this.t) {
2011
+ r.t = 0;
2012
+ return;
2013
+ }
2014
+ var bs = n % this.DB;
2015
+ var cbs = this.DB - bs;
2016
+ var bm = (1 << bs) - 1;
2017
+ r[0] = this[ds] >> bs;
2018
+ for (var i = ds + 1; i < this.t; ++i) {
2019
+ r[i - ds - 1] |= (this[i] & bm) << cbs;
2020
+ r[i - ds] = this[i] >> bs;
2021
+ }
2022
+ if (bs > 0)
2023
+ r[this.t - ds - 1] |= (this.s & bm) << cbs;
2024
+ r.t = this.t - ds;
2025
+ r.clamp();
2026
+ }
2027
+ function bnpSubTo(a, r) {
2028
+ var i = 0, c = 0, m = Math.min(a.t, this.t);
2029
+ while (i < m) {
2030
+ c += this[i] - a[i];
2031
+ r[i++] = c & this.DM;
2032
+ c >>= this.DB;
2033
+ }
2034
+ if (a.t < this.t) {
2035
+ c -= a.s;
2036
+ while (i < this.t) {
2037
+ c += this[i];
2038
+ r[i++] = c & this.DM;
2039
+ c >>= this.DB;
2040
+ }
2041
+ c += this.s;
2042
+ } else {
2043
+ c += this.s;
2044
+ while (i < a.t) {
2045
+ c -= a[i];
2046
+ r[i++] = c & this.DM;
2047
+ c >>= this.DB;
2048
+ }
2049
+ c -= a.s;
2050
+ }
2051
+ r.s = c < 0 ? -1 : 0;
2052
+ if (c < -1)
2053
+ r[i++] = this.DV + c;
2054
+ else if (c > 0)
2055
+ r[i++] = c;
2056
+ r.t = i;
2057
+ r.clamp();
2058
+ }
2059
+ function bnpMultiplyTo(a, r) {
2060
+ var x = this.abs(), y = a.abs();
2061
+ var i = x.t;
2062
+ r.t = i + y.t;
2063
+ while (--i >= 0)
2064
+ r[i] = 0;
2065
+ for (i = 0; i < y.t; ++i)
2066
+ r[i + x.t] = x.am(0, y[i], r, i, 0, x.t);
2067
+ r.s = 0;
2068
+ r.clamp();
2069
+ if (this.s != a.s)
2070
+ BigInteger3.ZERO.subTo(r, r);
2071
+ }
2072
+ function bnpSquareTo(r) {
2073
+ var x = this.abs();
2074
+ var i = r.t = 2 * x.t;
2075
+ while (--i >= 0)
2076
+ r[i] = 0;
2077
+ for (i = 0; i < x.t - 1; ++i) {
2078
+ var c = x.am(i, x[i], r, 2 * i, 0, 1);
2079
+ if ((r[i + x.t] += x.am(i + 1, 2 * x[i], r, 2 * i + 1, c, x.t - i - 1)) >= x.DV) {
2080
+ r[i + x.t] -= x.DV;
2081
+ r[i + x.t + 1] = 1;
2082
+ }
2083
+ }
2084
+ if (r.t > 0)
2085
+ r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1);
2086
+ r.s = 0;
2087
+ r.clamp();
2088
+ }
2089
+ function bnpDivRemTo(m, q, r) {
2090
+ var pm = m.abs();
2091
+ if (pm.t <= 0)
2092
+ return;
2093
+ var pt = this.abs();
2094
+ if (pt.t < pm.t) {
2095
+ if (q != null)
2096
+ q.fromInt(0);
2097
+ if (r != null)
2098
+ this.copyTo(r);
2099
+ return;
2100
+ }
2101
+ if (r == null)
2102
+ r = nbi();
2103
+ var y = nbi(), ts = this.s, ms = m.s;
2104
+ var nsh = this.DB - nbits(pm[pm.t - 1]);
2105
+ if (nsh > 0) {
2106
+ pm.lShiftTo(nsh, y);
2107
+ pt.lShiftTo(nsh, r);
2108
+ } else {
2109
+ pm.copyTo(y);
2110
+ pt.copyTo(r);
2111
+ }
2112
+ var ys = y.t;
2113
+ var y0 = y[ys - 1];
2114
+ if (y0 == 0)
2115
+ return;
2116
+ var yt = y0 * (1 << this.F1) + (ys > 1 ? y[ys - 2] >> this.F2 : 0);
2117
+ var d1 = this.FV / yt, d2 = (1 << this.F1) / yt, e = 1 << this.F2;
2118
+ var i = r.t, j = i - ys, t2 = q == null ? nbi() : q;
2119
+ y.dlShiftTo(j, t2);
2120
+ if (r.compareTo(t2) >= 0) {
2121
+ r[r.t++] = 1;
2122
+ r.subTo(t2, r);
2123
+ }
2124
+ BigInteger3.ONE.dlShiftTo(ys, t2);
2125
+ t2.subTo(y, y);
2126
+ while (y.t < ys)
2127
+ y[y.t++] = 0;
2128
+ while (--j >= 0) {
2129
+ var qd = r[--i] == y0 ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2);
2130
+ if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) {
2131
+ y.dlShiftTo(j, t2);
2132
+ r.subTo(t2, r);
2133
+ while (r[i] < --qd)
2134
+ r.subTo(t2, r);
2135
+ }
2136
+ }
2137
+ if (q != null) {
2138
+ r.drShiftTo(ys, q);
2139
+ if (ts != ms)
2140
+ BigInteger3.ZERO.subTo(q, q);
2141
+ }
2142
+ r.t = ys;
2143
+ r.clamp();
2144
+ if (nsh > 0)
2145
+ r.rShiftTo(nsh, r);
2146
+ if (ts < 0)
2147
+ BigInteger3.ZERO.subTo(r, r);
2148
+ }
2149
+ function bnMod(a) {
2150
+ var r = nbi();
2151
+ this.abs().divRemTo(a, null, r);
2152
+ if (this.s < 0 && r.compareTo(BigInteger3.ZERO) > 0)
2153
+ a.subTo(r, r);
2154
+ return r;
2155
+ }
2156
+ function Classic(m) {
2157
+ this.m = m;
2158
+ }
2159
+ function cConvert(x) {
2160
+ if (x.s < 0 || x.compareTo(this.m) >= 0)
2161
+ return x.mod(this.m);
2162
+ else
2163
+ return x;
2164
+ }
2165
+ function cRevert(x) {
2166
+ return x;
2167
+ }
2168
+ function cReduce(x) {
2169
+ x.divRemTo(this.m, null, x);
2170
+ }
2171
+ function cMulTo(x, y, r) {
2172
+ x.multiplyTo(y, r);
2173
+ this.reduce(r);
2174
+ }
2175
+ function cSqrTo(x, r) {
2176
+ x.squareTo(r);
2177
+ this.reduce(r);
2178
+ }
2179
+ Classic.prototype.convert = cConvert;
2180
+ Classic.prototype.revert = cRevert;
2181
+ Classic.prototype.reduce = cReduce;
2182
+ Classic.prototype.mulTo = cMulTo;
2183
+ Classic.prototype.sqrTo = cSqrTo;
2184
+ function bnpInvDigit() {
2185
+ if (this.t < 1)
2186
+ return 0;
2187
+ var x = this[0];
2188
+ if ((x & 1) == 0)
2189
+ return 0;
2190
+ var y = x & 3;
2191
+ y = y * (2 - (x & 15) * y) & 15;
2192
+ y = y * (2 - (x & 255) * y) & 255;
2193
+ y = y * (2 - ((x & 65535) * y & 65535)) & 65535;
2194
+ y = y * (2 - x * y % this.DV) % this.DV;
2195
+ return y > 0 ? this.DV - y : -y;
2196
+ }
2197
+ function Montgomery(m) {
2198
+ this.m = m;
2199
+ this.mp = m.invDigit();
2200
+ this.mpl = this.mp & 32767;
2201
+ this.mph = this.mp >> 15;
2202
+ this.um = (1 << m.DB - 15) - 1;
2203
+ this.mt2 = 2 * m.t;
2204
+ }
2205
+ function montConvert(x) {
2206
+ var r = nbi();
2207
+ x.abs().dlShiftTo(this.m.t, r);
2208
+ r.divRemTo(this.m, null, r);
2209
+ if (x.s < 0 && r.compareTo(BigInteger3.ZERO) > 0)
2210
+ this.m.subTo(r, r);
2211
+ return r;
2212
+ }
2213
+ function montRevert(x) {
2214
+ var r = nbi();
2215
+ x.copyTo(r);
2216
+ this.reduce(r);
2217
+ return r;
2218
+ }
2219
+ function montReduce(x) {
2220
+ while (x.t <= this.mt2)
2221
+ x[x.t++] = 0;
2222
+ for (var i = 0; i < this.m.t; ++i) {
2223
+ var j = x[i] & 32767;
2224
+ var u0 = j * this.mpl + ((j * this.mph + (x[i] >> 15) * this.mpl & this.um) << 15) & x.DM;
2225
+ j = i + this.m.t;
2226
+ x[j] += this.m.am(0, u0, x, i, 0, this.m.t);
2227
+ while (x[j] >= x.DV) {
2228
+ x[j] -= x.DV;
2229
+ x[++j]++;
2230
+ }
2231
+ }
2232
+ x.clamp();
2233
+ x.drShiftTo(this.m.t, x);
2234
+ if (x.compareTo(this.m) >= 0)
2235
+ x.subTo(this.m, x);
2236
+ }
2237
+ function montSqrTo(x, r) {
2238
+ x.squareTo(r);
2239
+ this.reduce(r);
2240
+ }
2241
+ function montMulTo(x, y, r) {
2242
+ x.multiplyTo(y, r);
2243
+ this.reduce(r);
2244
+ }
2245
+ Montgomery.prototype.convert = montConvert;
2246
+ Montgomery.prototype.revert = montRevert;
2247
+ Montgomery.prototype.reduce = montReduce;
2248
+ Montgomery.prototype.mulTo = montMulTo;
2249
+ Montgomery.prototype.sqrTo = montSqrTo;
2250
+ function bnpIsEven() {
2251
+ return (this.t > 0 ? this[0] & 1 : this.s) == 0;
2252
+ }
2253
+ function bnpExp(e, z2) {
2254
+ if (e > 4294967295 || e < 1)
2255
+ return BigInteger3.ONE;
2256
+ var r = nbi(), r2 = nbi(), g2 = z2.convert(this), i = nbits(e) - 1;
2257
+ g2.copyTo(r);
2258
+ while (--i >= 0) {
2259
+ z2.sqrTo(r, r2);
2260
+ if ((e & 1 << i) > 0)
2261
+ z2.mulTo(r2, g2, r);
2262
+ else {
2263
+ var t2 = r;
2264
+ r = r2;
2265
+ r2 = t2;
2266
+ }
2267
+ }
2268
+ return z2.revert(r);
2269
+ }
2270
+ function bnModPowInt(e, m) {
2271
+ var z2;
2272
+ if (e < 256 || m.isEven())
2273
+ z2 = new Classic(m);
2274
+ else
2275
+ z2 = new Montgomery(m);
2276
+ return this.exp(e, z2);
2277
+ }
2278
+ BigInteger3.prototype.copyTo = bnpCopyTo;
2279
+ BigInteger3.prototype.fromInt = bnpFromInt;
2280
+ BigInteger3.prototype.fromString = bnpFromString;
2281
+ BigInteger3.prototype.clamp = bnpClamp;
2282
+ BigInteger3.prototype.dlShiftTo = bnpDLShiftTo;
2283
+ BigInteger3.prototype.drShiftTo = bnpDRShiftTo;
2284
+ BigInteger3.prototype.lShiftTo = bnpLShiftTo;
2285
+ BigInteger3.prototype.rShiftTo = bnpRShiftTo;
2286
+ BigInteger3.prototype.subTo = bnpSubTo;
2287
+ BigInteger3.prototype.multiplyTo = bnpMultiplyTo;
2288
+ BigInteger3.prototype.squareTo = bnpSquareTo;
2289
+ BigInteger3.prototype.divRemTo = bnpDivRemTo;
2290
+ BigInteger3.prototype.invDigit = bnpInvDigit;
2291
+ BigInteger3.prototype.isEven = bnpIsEven;
2292
+ BigInteger3.prototype.exp = bnpExp;
2293
+ BigInteger3.prototype.toString = bnToString;
2294
+ BigInteger3.prototype.negate = bnNegate;
2295
+ BigInteger3.prototype.abs = bnAbs;
2296
+ BigInteger3.prototype.compareTo = bnCompareTo;
2297
+ BigInteger3.prototype.bitLength = bnBitLength;
2298
+ BigInteger3.prototype.mod = bnMod;
2299
+ BigInteger3.prototype.modPowInt = bnModPowInt;
2300
+ BigInteger3.ZERO = nbv(0);
2301
+ BigInteger3.ONE = nbv(1);
2302
+ function bnClone() {
2303
+ var r = nbi();
2304
+ this.copyTo(r);
2305
+ return r;
2306
+ }
2307
+ function bnIntValue() {
2308
+ if (this.s < 0) {
2309
+ if (this.t == 1)
2310
+ return this[0] - this.DV;
2311
+ else if (this.t == 0)
2312
+ return -1;
2313
+ } else if (this.t == 1)
2314
+ return this[0];
2315
+ else if (this.t == 0)
2316
+ return 0;
2317
+ return (this[1] & (1 << 32 - this.DB) - 1) << this.DB | this[0];
2318
+ }
2319
+ function bnByteValue() {
2320
+ return this.t == 0 ? this.s : this[0] << 24 >> 24;
2321
+ }
2322
+ function bnShortValue() {
2323
+ return this.t == 0 ? this.s : this[0] << 16 >> 16;
2324
+ }
2325
+ function bnpChunkSize(r) {
2326
+ return Math.floor(Math.LN2 * this.DB / Math.log(r));
2327
+ }
2328
+ function bnSigNum() {
2329
+ if (this.s < 0)
2330
+ return -1;
2331
+ else if (this.t <= 0 || this.t == 1 && this[0] <= 0)
2332
+ return 0;
2333
+ else
2334
+ return 1;
2335
+ }
2336
+ function bnpToRadix(b) {
2337
+ if (b == null)
2338
+ b = 10;
2339
+ if (this.signum() == 0 || b < 2 || b > 36)
2340
+ return "0";
2341
+ var cs = this.chunkSize(b);
2342
+ var a = Math.pow(b, cs);
2343
+ var d = nbv(a), y = nbi(), z2 = nbi(), r = "";
2344
+ this.divRemTo(d, y, z2);
2345
+ while (y.signum() > 0) {
2346
+ r = (a + z2.intValue()).toString(b).substr(1) + r;
2347
+ y.divRemTo(d, y, z2);
2348
+ }
2349
+ return z2.intValue().toString(b) + r;
2350
+ }
2351
+ function bnpFromRadix(s, b) {
2352
+ this.fromInt(0);
2353
+ if (b == null)
2354
+ b = 10;
2355
+ var cs = this.chunkSize(b);
2356
+ var d = Math.pow(b, cs), mi = false, j = 0, w = 0;
2357
+ for (var i = 0; i < s.length; ++i) {
2358
+ var x = intAt(s, i);
2359
+ if (x < 0) {
2360
+ if (s.charAt(i) == "-" && this.signum() == 0)
2361
+ mi = true;
2362
+ continue;
2363
+ }
2364
+ w = b * w + x;
2365
+ if (++j >= cs) {
2366
+ this.dMultiply(d);
2367
+ this.dAddOffset(w, 0);
2368
+ j = 0;
2369
+ w = 0;
2370
+ }
2371
+ }
2372
+ if (j > 0) {
2373
+ this.dMultiply(Math.pow(b, j));
2374
+ this.dAddOffset(w, 0);
2375
+ }
2376
+ if (mi)
2377
+ BigInteger3.ZERO.subTo(this, this);
2378
+ }
2379
+ function bnpFromNumber(a, b, c) {
2380
+ if ("number" == typeof b) {
2381
+ if (a < 2)
2382
+ this.fromInt(1);
2383
+ else {
2384
+ this.fromNumber(a, c);
2385
+ if (!this.testBit(a - 1))
2386
+ this.bitwiseTo(BigInteger3.ONE.shiftLeft(a - 1), op_or, this);
2387
+ if (this.isEven())
2388
+ this.dAddOffset(1, 0);
2389
+ while (!this.isProbablePrime(b)) {
2390
+ this.dAddOffset(2, 0);
2391
+ if (this.bitLength() > a)
2392
+ this.subTo(BigInteger3.ONE.shiftLeft(a - 1), this);
2393
+ }
2394
+ }
2395
+ } else {
2396
+ var x = new Array(), t2 = a & 7;
2397
+ x.length = (a >> 3) + 1;
2398
+ b.nextBytes(x);
2399
+ if (t2 > 0)
2400
+ x[0] &= (1 << t2) - 1;
2401
+ else
2402
+ x[0] = 0;
2403
+ this.fromString(x, 256);
2404
+ }
2405
+ }
2406
+ function bnToByteArray() {
2407
+ var i = this.t, r = new Array();
2408
+ r[0] = this.s;
2409
+ var p = this.DB - i * this.DB % 8, d, k2 = 0;
2410
+ if (i-- > 0) {
2411
+ if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p)
2412
+ r[k2++] = d | this.s << this.DB - p;
2413
+ while (i >= 0) {
2414
+ if (p < 8) {
2415
+ d = (this[i] & (1 << p) - 1) << 8 - p;
2416
+ d |= this[--i] >> (p += this.DB - 8);
2417
+ } else {
2418
+ d = this[i] >> (p -= 8) & 255;
2419
+ if (p <= 0) {
2420
+ p += this.DB;
2421
+ --i;
2422
+ }
2423
+ }
2424
+ if ((d & 128) != 0)
2425
+ d |= -256;
2426
+ if (k2 == 0 && (this.s & 128) != (d & 128))
2427
+ ++k2;
2428
+ if (k2 > 0 || d != this.s)
2429
+ r[k2++] = d;
2430
+ }
2431
+ }
2432
+ return r;
2433
+ }
2434
+ function bnEquals(a) {
2435
+ return this.compareTo(a) == 0;
2436
+ }
2437
+ function bnMin(a) {
2438
+ return this.compareTo(a) < 0 ? this : a;
2439
+ }
2440
+ function bnMax(a) {
2441
+ return this.compareTo(a) > 0 ? this : a;
2442
+ }
2443
+ function bnpBitwiseTo(a, op, r) {
2444
+ var i, f, m = Math.min(a.t, this.t);
2445
+ for (i = 0; i < m; ++i)
2446
+ r[i] = op(this[i], a[i]);
2447
+ if (a.t < this.t) {
2448
+ f = a.s & this.DM;
2449
+ for (i = m; i < this.t; ++i)
2450
+ r[i] = op(this[i], f);
2451
+ r.t = this.t;
2452
+ } else {
2453
+ f = this.s & this.DM;
2454
+ for (i = m; i < a.t; ++i)
2455
+ r[i] = op(f, a[i]);
2456
+ r.t = a.t;
2457
+ }
2458
+ r.s = op(this.s, a.s);
2459
+ r.clamp();
2460
+ }
2461
+ function op_and(x, y) {
2462
+ return x & y;
2463
+ }
2464
+ function bnAnd(a) {
2465
+ var r = nbi();
2466
+ this.bitwiseTo(a, op_and, r);
2467
+ return r;
2468
+ }
2469
+ function op_or(x, y) {
2470
+ return x | y;
2471
+ }
2472
+ function bnOr(a) {
2473
+ var r = nbi();
2474
+ this.bitwiseTo(a, op_or, r);
2475
+ return r;
2476
+ }
2477
+ function op_xor(x, y) {
2478
+ return x ^ y;
2479
+ }
2480
+ function bnXor(a) {
2481
+ var r = nbi();
2482
+ this.bitwiseTo(a, op_xor, r);
2483
+ return r;
2484
+ }
2485
+ function op_andnot(x, y) {
2486
+ return x & ~y;
2487
+ }
2488
+ function bnAndNot(a) {
2489
+ var r = nbi();
2490
+ this.bitwiseTo(a, op_andnot, r);
2491
+ return r;
2492
+ }
2493
+ function bnNot() {
2494
+ var r = nbi();
2495
+ for (var i = 0; i < this.t; ++i)
2496
+ r[i] = this.DM & ~this[i];
2497
+ r.t = this.t;
2498
+ r.s = ~this.s;
2499
+ return r;
2500
+ }
2501
+ function bnShiftLeft(n) {
2502
+ var r = nbi();
2503
+ if (n < 0)
2504
+ this.rShiftTo(-n, r);
2505
+ else
2506
+ this.lShiftTo(n, r);
2507
+ return r;
2508
+ }
2509
+ function bnShiftRight(n) {
2510
+ var r = nbi();
2511
+ if (n < 0)
2512
+ this.lShiftTo(-n, r);
2513
+ else
2514
+ this.rShiftTo(n, r);
2515
+ return r;
2516
+ }
2517
+ function lbit(x) {
2518
+ if (x == 0)
2519
+ return -1;
2520
+ var r = 0;
2521
+ if ((x & 65535) == 0) {
2522
+ x >>= 16;
2523
+ r += 16;
2524
+ }
2525
+ if ((x & 255) == 0) {
2526
+ x >>= 8;
2527
+ r += 8;
2528
+ }
2529
+ if ((x & 15) == 0) {
2530
+ x >>= 4;
2531
+ r += 4;
2532
+ }
2533
+ if ((x & 3) == 0) {
2534
+ x >>= 2;
2535
+ r += 2;
2536
+ }
2537
+ if ((x & 1) == 0)
2538
+ ++r;
2539
+ return r;
2540
+ }
2541
+ function bnGetLowestSetBit() {
2542
+ for (var i = 0; i < this.t; ++i)
2543
+ if (this[i] != 0)
2544
+ return i * this.DB + lbit(this[i]);
2545
+ if (this.s < 0)
2546
+ return this.t * this.DB;
2547
+ return -1;
2548
+ }
2549
+ function cbit(x) {
2550
+ var r = 0;
2551
+ while (x != 0) {
2552
+ x &= x - 1;
2553
+ ++r;
2554
+ }
2555
+ return r;
2556
+ }
2557
+ function bnBitCount() {
2558
+ var r = 0, x = this.s & this.DM;
2559
+ for (var i = 0; i < this.t; ++i)
2560
+ r += cbit(this[i] ^ x);
2561
+ return r;
2562
+ }
2563
+ function bnTestBit(n) {
2564
+ var j = Math.floor(n / this.DB);
2565
+ if (j >= this.t)
2566
+ return this.s != 0;
2567
+ return (this[j] & 1 << n % this.DB) != 0;
2568
+ }
2569
+ function bnpChangeBit(n, op) {
2570
+ var r = BigInteger3.ONE.shiftLeft(n);
2571
+ this.bitwiseTo(r, op, r);
2572
+ return r;
2573
+ }
2574
+ function bnSetBit(n) {
2575
+ return this.changeBit(n, op_or);
2576
+ }
2577
+ function bnClearBit(n) {
2578
+ return this.changeBit(n, op_andnot);
2579
+ }
2580
+ function bnFlipBit(n) {
2581
+ return this.changeBit(n, op_xor);
2582
+ }
2583
+ function bnpAddTo(a, r) {
2584
+ var i = 0, c = 0, m = Math.min(a.t, this.t);
2585
+ while (i < m) {
2586
+ c += this[i] + a[i];
2587
+ r[i++] = c & this.DM;
2588
+ c >>= this.DB;
2589
+ }
2590
+ if (a.t < this.t) {
2591
+ c += a.s;
2592
+ while (i < this.t) {
2593
+ c += this[i];
2594
+ r[i++] = c & this.DM;
2595
+ c >>= this.DB;
2596
+ }
2597
+ c += this.s;
2598
+ } else {
2599
+ c += this.s;
2600
+ while (i < a.t) {
2601
+ c += a[i];
2602
+ r[i++] = c & this.DM;
2603
+ c >>= this.DB;
2604
+ }
2605
+ c += a.s;
2606
+ }
2607
+ r.s = c < 0 ? -1 : 0;
2608
+ if (c > 0)
2609
+ r[i++] = c;
2610
+ else if (c < -1)
2611
+ r[i++] = this.DV + c;
2612
+ r.t = i;
2613
+ r.clamp();
2614
+ }
2615
+ function bnAdd(a) {
2616
+ var r = nbi();
2617
+ this.addTo(a, r);
2618
+ return r;
2619
+ }
2620
+ function bnSubtract(a) {
2621
+ var r = nbi();
2622
+ this.subTo(a, r);
2623
+ return r;
2624
+ }
2625
+ function bnMultiply(a) {
2626
+ var r = nbi();
2627
+ this.multiplyTo(a, r);
2628
+ return r;
2629
+ }
2630
+ function bnSquare() {
2631
+ var r = nbi();
2632
+ this.squareTo(r);
2633
+ return r;
2634
+ }
2635
+ function bnDivide(a) {
2636
+ var r = nbi();
2637
+ this.divRemTo(a, r, null);
2638
+ return r;
2639
+ }
2640
+ function bnRemainder(a) {
2641
+ var r = nbi();
2642
+ this.divRemTo(a, null, r);
2643
+ return r;
2644
+ }
2645
+ function bnDivideAndRemainder(a) {
2646
+ var q = nbi(), r = nbi();
2647
+ this.divRemTo(a, q, r);
2648
+ return new Array(q, r);
2649
+ }
2650
+ function bnpDMultiply(n) {
2651
+ this[this.t] = this.am(0, n - 1, this, 0, 0, this.t);
2652
+ ++this.t;
2653
+ this.clamp();
2654
+ }
2655
+ function bnpDAddOffset(n, w) {
2656
+ if (n == 0)
2657
+ return;
2658
+ while (this.t <= w)
2659
+ this[this.t++] = 0;
2660
+ this[w] += n;
2661
+ while (this[w] >= this.DV) {
2662
+ this[w] -= this.DV;
2663
+ if (++w >= this.t)
2664
+ this[this.t++] = 0;
2665
+ ++this[w];
2666
+ }
2667
+ }
2668
+ function NullExp() {
2669
+ }
2670
+ function nNop(x) {
2671
+ return x;
2672
+ }
2673
+ function nMulTo(x, y, r) {
2674
+ x.multiplyTo(y, r);
2675
+ }
2676
+ function nSqrTo(x, r) {
2677
+ x.squareTo(r);
2678
+ }
2679
+ NullExp.prototype.convert = nNop;
2680
+ NullExp.prototype.revert = nNop;
2681
+ NullExp.prototype.mulTo = nMulTo;
2682
+ NullExp.prototype.sqrTo = nSqrTo;
2683
+ function bnPow(e) {
2684
+ return this.exp(e, new NullExp());
2685
+ }
2686
+ function bnpMultiplyLowerTo(a, n, r) {
2687
+ var i = Math.min(this.t + a.t, n);
2688
+ r.s = 0;
2689
+ r.t = i;
2690
+ while (i > 0)
2691
+ r[--i] = 0;
2692
+ var j;
2693
+ for (j = r.t - this.t; i < j; ++i)
2694
+ r[i + this.t] = this.am(0, a[i], r, i, 0, this.t);
2695
+ for (j = Math.min(a.t, n); i < j; ++i)
2696
+ this.am(0, a[i], r, i, 0, n - i);
2697
+ r.clamp();
2698
+ }
2699
+ function bnpMultiplyUpperTo(a, n, r) {
2700
+ --n;
2701
+ var i = r.t = this.t + a.t - n;
2702
+ r.s = 0;
2703
+ while (--i >= 0)
2704
+ r[i] = 0;
2705
+ for (i = Math.max(n - this.t, 0); i < a.t; ++i)
2706
+ r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n);
2707
+ r.clamp();
2708
+ r.drShiftTo(1, r);
2709
+ }
2710
+ function Barrett(m) {
2711
+ this.r2 = nbi();
2712
+ this.q3 = nbi();
2713
+ BigInteger3.ONE.dlShiftTo(2 * m.t, this.r2);
2714
+ this.mu = this.r2.divide(m);
2715
+ this.m = m;
2716
+ }
2717
+ function barrettConvert(x) {
2718
+ if (x.s < 0 || x.t > 2 * this.m.t)
2719
+ return x.mod(this.m);
2720
+ else if (x.compareTo(this.m) < 0)
2721
+ return x;
2722
+ else {
2723
+ var r = nbi();
2724
+ x.copyTo(r);
2725
+ this.reduce(r);
2726
+ return r;
2727
+ }
2728
+ }
2729
+ function barrettRevert(x) {
2730
+ return x;
2731
+ }
2732
+ function barrettReduce(x) {
2733
+ x.drShiftTo(this.m.t - 1, this.r2);
2734
+ if (x.t > this.m.t + 1) {
2735
+ x.t = this.m.t + 1;
2736
+ x.clamp();
2737
+ }
2738
+ this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3);
2739
+ this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2);
2740
+ while (x.compareTo(this.r2) < 0)
2741
+ x.dAddOffset(1, this.m.t + 1);
2742
+ x.subTo(this.r2, x);
2743
+ while (x.compareTo(this.m) >= 0)
2744
+ x.subTo(this.m, x);
2745
+ }
2746
+ function barrettSqrTo(x, r) {
2747
+ x.squareTo(r);
2748
+ this.reduce(r);
2749
+ }
2750
+ function barrettMulTo(x, y, r) {
2751
+ x.multiplyTo(y, r);
2752
+ this.reduce(r);
2753
+ }
2754
+ Barrett.prototype.convert = barrettConvert;
2755
+ Barrett.prototype.revert = barrettRevert;
2756
+ Barrett.prototype.reduce = barrettReduce;
2757
+ Barrett.prototype.mulTo = barrettMulTo;
2758
+ Barrett.prototype.sqrTo = barrettSqrTo;
2759
+ function bnModPow(e, m) {
2760
+ var i = e.bitLength(), k2, r = nbv(1), z2;
2761
+ if (i <= 0)
2762
+ return r;
2763
+ else if (i < 18)
2764
+ k2 = 1;
2765
+ else if (i < 48)
2766
+ k2 = 3;
2767
+ else if (i < 144)
2768
+ k2 = 4;
2769
+ else if (i < 768)
2770
+ k2 = 5;
2771
+ else
2772
+ k2 = 6;
2773
+ if (i < 8)
2774
+ z2 = new Classic(m);
2775
+ else if (m.isEven())
2776
+ z2 = new Barrett(m);
2777
+ else
2778
+ z2 = new Montgomery(m);
2779
+ var g2 = new Array(), n = 3, k1 = k2 - 1, km = (1 << k2) - 1;
2780
+ g2[1] = z2.convert(this);
2781
+ if (k2 > 1) {
2782
+ var g22 = nbi();
2783
+ z2.sqrTo(g2[1], g22);
2784
+ while (n <= km) {
2785
+ g2[n] = nbi();
2786
+ z2.mulTo(g22, g2[n - 2], g2[n]);
2787
+ n += 2;
2788
+ }
2789
+ }
2790
+ var j = e.t - 1, w, is1 = true, r2 = nbi(), t2;
2791
+ i = nbits(e[j]) - 1;
2792
+ while (j >= 0) {
2793
+ if (i >= k1)
2794
+ w = e[j] >> i - k1 & km;
2795
+ else {
2796
+ w = (e[j] & (1 << i + 1) - 1) << k1 - i;
2797
+ if (j > 0)
2798
+ w |= e[j - 1] >> this.DB + i - k1;
2799
+ }
2800
+ n = k2;
2801
+ while ((w & 1) == 0) {
2802
+ w >>= 1;
2803
+ --n;
2804
+ }
2805
+ if ((i -= n) < 0) {
2806
+ i += this.DB;
2807
+ --j;
2808
+ }
2809
+ if (is1) {
2810
+ g2[w].copyTo(r);
2811
+ is1 = false;
2812
+ } else {
2813
+ while (n > 1) {
2814
+ z2.sqrTo(r, r2);
2815
+ z2.sqrTo(r2, r);
2816
+ n -= 2;
2817
+ }
2818
+ if (n > 0)
2819
+ z2.sqrTo(r, r2);
2820
+ else {
2821
+ t2 = r;
2822
+ r = r2;
2823
+ r2 = t2;
2824
+ }
2825
+ z2.mulTo(r2, g2[w], r);
2826
+ }
2827
+ while (j >= 0 && (e[j] & 1 << i) == 0) {
2828
+ z2.sqrTo(r, r2);
2829
+ t2 = r;
2830
+ r = r2;
2831
+ r2 = t2;
2832
+ if (--i < 0) {
2833
+ i = this.DB - 1;
2834
+ --j;
2835
+ }
2836
+ }
2837
+ }
2838
+ return z2.revert(r);
2839
+ }
2840
+ function bnGCD(a) {
2841
+ var x = this.s < 0 ? this.negate() : this.clone();
2842
+ var y = a.s < 0 ? a.negate() : a.clone();
2843
+ if (x.compareTo(y) < 0) {
2844
+ var t2 = x;
2845
+ x = y;
2846
+ y = t2;
2847
+ }
2848
+ var i = x.getLowestSetBit(), g2 = y.getLowestSetBit();
2849
+ if (g2 < 0)
2850
+ return x;
2851
+ if (i < g2)
2852
+ g2 = i;
2853
+ if (g2 > 0) {
2854
+ x.rShiftTo(g2, x);
2855
+ y.rShiftTo(g2, y);
2856
+ }
2857
+ while (x.signum() > 0) {
2858
+ if ((i = x.getLowestSetBit()) > 0)
2859
+ x.rShiftTo(i, x);
2860
+ if ((i = y.getLowestSetBit()) > 0)
2861
+ y.rShiftTo(i, y);
2862
+ if (x.compareTo(y) >= 0) {
2863
+ x.subTo(y, x);
2864
+ x.rShiftTo(1, x);
2865
+ } else {
2866
+ y.subTo(x, y);
2867
+ y.rShiftTo(1, y);
2868
+ }
2869
+ }
2870
+ if (g2 > 0)
2871
+ y.lShiftTo(g2, y);
2872
+ return y;
2873
+ }
2874
+ function bnpModInt(n) {
2875
+ if (n <= 0)
2876
+ return 0;
2877
+ var d = this.DV % n, r = this.s < 0 ? n - 1 : 0;
2878
+ if (this.t > 0)
2879
+ if (d == 0)
2880
+ r = this[0] % n;
2881
+ else
2882
+ for (var i = this.t - 1; i >= 0; --i)
2883
+ r = (d * r + this[i]) % n;
2884
+ return r;
2885
+ }
2886
+ function bnModInverse(m) {
2887
+ var ac = m.isEven();
2888
+ if (this.isEven() && ac || m.signum() == 0)
2889
+ return BigInteger3.ZERO;
2890
+ var u = m.clone(), v = this.clone();
2891
+ var a = nbv(1), b = nbv(0), c = nbv(0), d = nbv(1);
2892
+ while (u.signum() != 0) {
2893
+ while (u.isEven()) {
2894
+ u.rShiftTo(1, u);
2895
+ if (ac) {
2896
+ if (!a.isEven() || !b.isEven()) {
2897
+ a.addTo(this, a);
2898
+ b.subTo(m, b);
2899
+ }
2900
+ a.rShiftTo(1, a);
2901
+ } else if (!b.isEven())
2902
+ b.subTo(m, b);
2903
+ b.rShiftTo(1, b);
2904
+ }
2905
+ while (v.isEven()) {
2906
+ v.rShiftTo(1, v);
2907
+ if (ac) {
2908
+ if (!c.isEven() || !d.isEven()) {
2909
+ c.addTo(this, c);
2910
+ d.subTo(m, d);
2911
+ }
2912
+ c.rShiftTo(1, c);
2913
+ } else if (!d.isEven())
2914
+ d.subTo(m, d);
2915
+ d.rShiftTo(1, d);
2916
+ }
2917
+ if (u.compareTo(v) >= 0) {
2918
+ u.subTo(v, u);
2919
+ if (ac)
2920
+ a.subTo(c, a);
2921
+ b.subTo(d, b);
2922
+ } else {
2923
+ v.subTo(u, v);
2924
+ if (ac)
2925
+ c.subTo(a, c);
2926
+ d.subTo(b, d);
2927
+ }
2928
+ }
2929
+ if (v.compareTo(BigInteger3.ONE) != 0)
2930
+ return BigInteger3.ZERO;
2931
+ if (d.compareTo(m) >= 0)
2932
+ return d.subtract(m);
2933
+ if (d.signum() < 0)
2934
+ d.addTo(m, d);
2935
+ else
2936
+ return d;
2937
+ if (d.signum() < 0)
2938
+ return d.add(m);
2939
+ else
2940
+ return d;
2941
+ }
2942
+ var lowprimes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997];
2943
+ var lplim = (1 << 26) / lowprimes[lowprimes.length - 1];
2944
+ function bnIsProbablePrime(t2) {
2945
+ var i, x = this.abs();
2946
+ if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) {
2947
+ for (i = 0; i < lowprimes.length; ++i)
2948
+ if (x[0] == lowprimes[i])
2949
+ return true;
2950
+ return false;
2951
+ }
2952
+ if (x.isEven())
2953
+ return false;
2954
+ i = 1;
2955
+ while (i < lowprimes.length) {
2956
+ var m = lowprimes[i], j = i + 1;
2957
+ while (j < lowprimes.length && m < lplim)
2958
+ m *= lowprimes[j++];
2959
+ m = x.modInt(m);
2960
+ while (i < j)
2961
+ if (m % lowprimes[i++] == 0)
2962
+ return false;
2963
+ }
2964
+ return x.millerRabin(t2);
2965
+ }
2966
+ function bnpMillerRabin(t2) {
2967
+ var n1 = this.subtract(BigInteger3.ONE);
2968
+ var k2 = n1.getLowestSetBit();
2969
+ if (k2 <= 0)
2970
+ return false;
2971
+ var r = n1.shiftRight(k2);
2972
+ t2 = t2 + 1 >> 1;
2973
+ if (t2 > lowprimes.length)
2974
+ t2 = lowprimes.length;
2975
+ var a = nbi();
2976
+ for (var i = 0; i < t2; ++i) {
2977
+ a.fromInt(lowprimes[Math.floor(Math.random() * lowprimes.length)]);
2978
+ var y = a.modPow(r, this);
2979
+ if (y.compareTo(BigInteger3.ONE) != 0 && y.compareTo(n1) != 0) {
2980
+ var j = 1;
2981
+ while (j++ < k2 && y.compareTo(n1) != 0) {
2982
+ y = y.modPowInt(2, this);
2983
+ if (y.compareTo(BigInteger3.ONE) == 0)
2984
+ return false;
2985
+ }
2986
+ if (y.compareTo(n1) != 0)
2987
+ return false;
2988
+ }
2989
+ }
2990
+ return true;
2991
+ }
2992
+ BigInteger3.prototype.chunkSize = bnpChunkSize;
2993
+ BigInteger3.prototype.toRadix = bnpToRadix;
2994
+ BigInteger3.prototype.fromRadix = bnpFromRadix;
2995
+ BigInteger3.prototype.fromNumber = bnpFromNumber;
2996
+ BigInteger3.prototype.bitwiseTo = bnpBitwiseTo;
2997
+ BigInteger3.prototype.changeBit = bnpChangeBit;
2998
+ BigInteger3.prototype.addTo = bnpAddTo;
2999
+ BigInteger3.prototype.dMultiply = bnpDMultiply;
3000
+ BigInteger3.prototype.dAddOffset = bnpDAddOffset;
3001
+ BigInteger3.prototype.multiplyLowerTo = bnpMultiplyLowerTo;
3002
+ BigInteger3.prototype.multiplyUpperTo = bnpMultiplyUpperTo;
3003
+ BigInteger3.prototype.modInt = bnpModInt;
3004
+ BigInteger3.prototype.millerRabin = bnpMillerRabin;
3005
+ BigInteger3.prototype.clone = bnClone;
3006
+ BigInteger3.prototype.intValue = bnIntValue;
3007
+ BigInteger3.prototype.byteValue = bnByteValue;
3008
+ BigInteger3.prototype.shortValue = bnShortValue;
3009
+ BigInteger3.prototype.signum = bnSigNum;
3010
+ BigInteger3.prototype.toByteArray = bnToByteArray;
3011
+ BigInteger3.prototype.equals = bnEquals;
3012
+ BigInteger3.prototype.min = bnMin;
3013
+ BigInteger3.prototype.max = bnMax;
3014
+ BigInteger3.prototype.and = bnAnd;
3015
+ BigInteger3.prototype.or = bnOr;
3016
+ BigInteger3.prototype.xor = bnXor;
3017
+ BigInteger3.prototype.andNot = bnAndNot;
3018
+ BigInteger3.prototype.not = bnNot;
3019
+ BigInteger3.prototype.shiftLeft = bnShiftLeft;
3020
+ BigInteger3.prototype.shiftRight = bnShiftRight;
3021
+ BigInteger3.prototype.getLowestSetBit = bnGetLowestSetBit;
3022
+ BigInteger3.prototype.bitCount = bnBitCount;
3023
+ BigInteger3.prototype.testBit = bnTestBit;
3024
+ BigInteger3.prototype.setBit = bnSetBit;
3025
+ BigInteger3.prototype.clearBit = bnClearBit;
3026
+ BigInteger3.prototype.flipBit = bnFlipBit;
3027
+ BigInteger3.prototype.add = bnAdd;
3028
+ BigInteger3.prototype.subtract = bnSubtract;
3029
+ BigInteger3.prototype.multiply = bnMultiply;
3030
+ BigInteger3.prototype.divide = bnDivide;
3031
+ BigInteger3.prototype.remainder = bnRemainder;
3032
+ BigInteger3.prototype.divideAndRemainder = bnDivideAndRemainder;
3033
+ BigInteger3.prototype.modPow = bnModPow;
3034
+ BigInteger3.prototype.modInverse = bnModInverse;
3035
+ BigInteger3.prototype.pow = bnPow;
3036
+ BigInteger3.prototype.gcd = bnGCD;
3037
+ BigInteger3.prototype.isProbablePrime = bnIsProbablePrime;
3038
+ BigInteger3.prototype.square = bnSquare;
3039
+ BigInteger3.prototype.Barrett = Barrett;
3040
+ var rng_state;
3041
+ var rng_pool;
3042
+ var rng_pptr;
3043
+ function rng_seed_int(x) {
3044
+ rng_pool[rng_pptr++] ^= x & 255;
3045
+ rng_pool[rng_pptr++] ^= x >> 8 & 255;
3046
+ rng_pool[rng_pptr++] ^= x >> 16 & 255;
3047
+ rng_pool[rng_pptr++] ^= x >> 24 & 255;
3048
+ if (rng_pptr >= rng_psize)
3049
+ rng_pptr -= rng_psize;
3050
+ }
3051
+ function rng_seed_time() {
3052
+ rng_seed_int((/* @__PURE__ */ new Date()).getTime());
3053
+ }
3054
+ if (rng_pool == null) {
3055
+ rng_pool = new Array();
3056
+ rng_pptr = 0;
3057
+ var t;
3058
+ if (typeof window !== "undefined" && window.crypto) {
3059
+ if (window.crypto.getRandomValues) {
3060
+ var ua = new Uint8Array(32);
3061
+ window.crypto.getRandomValues(ua);
3062
+ for (t = 0; t < 32; ++t)
3063
+ rng_pool[rng_pptr++] = ua[t];
3064
+ } else if (navigator.appName == "Netscape" && navigator.appVersion < "5") {
3065
+ var z = window.crypto.random(32);
3066
+ for (t = 0; t < z.length; ++t)
3067
+ rng_pool[rng_pptr++] = z.charCodeAt(t) & 255;
3068
+ }
3069
+ }
3070
+ while (rng_pptr < rng_psize) {
3071
+ t = Math.floor(65536 * Math.random());
3072
+ rng_pool[rng_pptr++] = t >>> 8;
3073
+ rng_pool[rng_pptr++] = t & 255;
3074
+ }
3075
+ rng_pptr = 0;
3076
+ rng_seed_time();
3077
+ }
3078
+ function rng_get_byte() {
3079
+ if (rng_state == null) {
3080
+ rng_seed_time();
3081
+ rng_state = prng_newstate();
3082
+ rng_state.init(rng_pool);
3083
+ for (rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr)
3084
+ rng_pool[rng_pptr] = 0;
3085
+ rng_pptr = 0;
3086
+ }
3087
+ return rng_state.next();
3088
+ }
3089
+ function rng_get_bytes(ba) {
3090
+ var i;
3091
+ for (i = 0; i < ba.length; ++i)
3092
+ ba[i] = rng_get_byte();
3093
+ }
3094
+ function SecureRandom() {
3095
+ }
3096
+ SecureRandom.prototype.nextBytes = rng_get_bytes;
3097
+ function Arcfour() {
3098
+ this.i = 0;
3099
+ this.j = 0;
3100
+ this.S = new Array();
3101
+ }
3102
+ function ARC4init(key) {
3103
+ var i, j, t2;
3104
+ for (i = 0; i < 256; ++i)
3105
+ this.S[i] = i;
3106
+ j = 0;
3107
+ for (i = 0; i < 256; ++i) {
3108
+ j = j + this.S[i] + key[i % key.length] & 255;
3109
+ t2 = this.S[i];
3110
+ this.S[i] = this.S[j];
3111
+ this.S[j] = t2;
3112
+ }
3113
+ this.i = 0;
3114
+ this.j = 0;
3115
+ }
3116
+ function ARC4next() {
3117
+ var t2;
3118
+ this.i = this.i + 1 & 255;
3119
+ this.j = this.j + this.S[this.i] & 255;
3120
+ t2 = this.S[this.i];
3121
+ this.S[this.i] = this.S[this.j];
3122
+ this.S[this.j] = t2;
3123
+ return this.S[t2 + this.S[this.i] & 255];
3124
+ }
3125
+ Arcfour.prototype.init = ARC4init;
3126
+ Arcfour.prototype.next = ARC4next;
3127
+ function prng_newstate() {
3128
+ return new Arcfour();
3129
+ }
3130
+ var rng_psize = 256;
3131
+ if (typeof exports !== "undefined") {
3132
+ exports = module.exports = {
3133
+ default: BigInteger3,
3134
+ BigInteger: BigInteger3,
3135
+ SecureRandom
3136
+ };
3137
+ } else {
3138
+ this.jsbn = {
3139
+ BigInteger: BigInteger3,
3140
+ SecureRandom
3141
+ };
3142
+ }
3143
+ }).call(exports);
3144
+ }
3145
+ });
3146
+
3147
+ // node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js
3148
+ var require_randombytes = __commonJS({
3149
+ "node_modules/.pnpm/randombytes@2.1.0/node_modules/randombytes/index.js"(exports, module) {
3150
+ module.exports = __require("crypto").randomBytes;
3151
+ }
3152
+ });
3153
+
3154
+ // src/cognito-client.ts
3155
+ var import_hash2 = __toESM(require_hash(), 1);
3156
+ var import_jsbn2 = __toESM(require_jsbn(), 1);
3157
+ var import_randombytes2 = __toESM(require_randombytes(), 1);
3158
+ import addSeconds from "date-fns/addSeconds";
3159
+
3160
+ // src/error.ts
3161
+ var AuthError = /* @__PURE__ */ ((AuthError2) => {
3162
+ AuthError2["UserConfirmedAlready"] = "user_confirmed_already";
3163
+ AuthError2["UserDoesNotExist"] = "user_does_not_exist";
3164
+ AuthError2["UserAlreadyExists"] = "user_already_exists";
3165
+ AuthError2["EmailOrPasswordWrong"] = "email_or_password_wrong";
3166
+ AuthError2["LimitExceededException"] = "limit_exceeded_exception";
3167
+ AuthError2["UserNotAuthenticated"] = "user_not_authenticated";
3168
+ AuthError2["PasswordAttempsExceeded"] = "password_attemps_exceeded";
3169
+ AuthError2["UserEmailNotVerified"] = "user_email_not_verified";
3170
+ AuthError2["Unknown"] = "unknown";
3171
+ return AuthError2;
3172
+ })(AuthError || {});
3173
+ var AuthException = class extends Error {
3174
+ constructor(message, authError) {
3175
+ super(message);
3176
+ this.authError = authError;
3177
+ }
3178
+ };
3179
+ var ErrorCode = /* @__PURE__ */ ((ErrorCode2) => {
3180
+ ErrorCode2["UserNotFoundException"] = "UserNotFoundException";
3181
+ ErrorCode2["NotAuthorizedException"] = "NotAuthorizedException";
3182
+ ErrorCode2["LimitExceededException"] = "LimitExceededException";
3183
+ return ErrorCode2;
3184
+ })(ErrorCode || {});
3185
+ function getAuthError(errorResponse) {
3186
+ const mapping = {
3187
+ "UserNotFoundException:User cannot be confirmed. Current status is CONFIRMED": "user_confirmed_already" /* UserConfirmedAlready */,
3188
+ "NotAuthorizedException:Incorrect username or password.": "email_or_password_wrong" /* EmailOrPasswordWrong */,
3189
+ "LimitExceededException:Attempt limit exceeded, please try after some time.": "limit_exceeded_exception" /* LimitExceededException */,
3190
+ "UserNotFoundException:Username/client id combination not found.": "user_does_not_exist" /* UserDoesNotExist */,
3191
+ "UserNotFoundException:User does not exist.": "user_does_not_exist" /* UserDoesNotExist */,
3192
+ "NotAuthorizedException:Password attempts exceeded": "password_attemps_exceeded" /* PasswordAttempsExceeded */,
3193
+ "UsernameExistsException:An account with the given email already exists.": "user_already_exists" /* UserAlreadyExists */,
3194
+ "InvalidParameterException:Cannot reset password for the user as there is no registered/verified email or phone_number": "user_email_not_verified" /* UserEmailNotVerified */,
3195
+ "UserNotConfirmedException:User is not confirmed.": "user_email_not_verified" /* UserEmailNotVerified */
3196
+ };
3197
+ const message = `${errorResponse.__type}:${errorResponse.message}`;
3198
+ const authError = mapping[message] || "unknown" /* Unknown */;
3199
+ return new AuthException(message, authError);
3200
+ }
3201
+
3202
+ // src/utils.ts
3203
+ var import_hash = __toESM(require_hash(), 1);
3204
+ var import_jsbn = __toESM(require_jsbn(), 1);
3205
+ var import_randombytes = __toESM(require_randombytes(), 1);
3206
+ import formatInTimeZone from "date-fns-tz/formatInTimeZone";
3207
+ var initN = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE45B3DC2007CB8A163BF0598DA48361C55D39A69163FA8FD24CF5F83655D23DCA3AD961C62F356208552BB9ED529077096966D670C354E4ABC9804F1746C08CA18217C32905E462E36CE3BE39E772C180E86039B2783A2EC07A28FB5C55DF06F4C52C9DE2BCBF6955817183995497CEA956AE515D2261898FA051015728E5A8AAAC42DAD33170D04507A33A85521ABDF1CBA64ECFB850458DBEF0A8AEA71575D060C7DB3970F85A6E1E4C7ABF5AE8CDB0933D71E8C94E04A25619DCEE3D2261AD2EE6BF12FFA06D98A0864D87602733EC86A64521F2B18177B200CBBE117577A615D6C770988C0BAD946E208E24FA074E5AB3143DB5BFCE0FD108E4B82D120A93AD2CAFFFFFFFFFFFFFFFF";
3208
+ var N = new import_jsbn.BigInteger(initN, 16);
3209
+ var g = new import_jsbn.BigInteger("2", 16);
3210
+ var k = new import_jsbn.BigInteger(hashHexString(`${padHex(N)}${padHex(g)}`), 16);
3211
+ function padHex(bigInt) {
3212
+ const HEX_MSB_REGEX = /^[89a-f]/i;
3213
+ const isNegative = bigInt.compareTo(import_jsbn.BigInteger.ZERO) < 0;
3214
+ let hexStr = bigInt.abs().toString(16);
3215
+ hexStr = hexStr.length % 2 !== 0 ? `0${hexStr}` : hexStr;
3216
+ hexStr = HEX_MSB_REGEX.test(hexStr) ? `00${hexStr}` : hexStr;
3217
+ if (isNegative) {
3218
+ const invertedNibbles = hexStr.split("").map((x) => {
3219
+ const invertedNibble = ~parseInt(x, 16) & 15;
3220
+ return "0123456789ABCDEF".charAt(invertedNibble);
3221
+ }).join("");
3222
+ const flippedBitsBI = new import_jsbn.BigInteger(invertedNibbles, 16).add(import_jsbn.BigInteger.ONE);
3223
+ hexStr = flippedBitsBI.toString(16);
3224
+ if (hexStr.toUpperCase().startsWith("FF8")) {
3225
+ hexStr = hexStr.substring(2);
3226
+ }
3227
+ }
3228
+ return hexStr;
3229
+ }
3230
+ function hashHexString(str) {
3231
+ return hashBuffer(Buffer.from(str, "hex"));
3232
+ }
3233
+ function hashBuffer(buffer) {
3234
+ const hash = (0, import_hash.sha256)().update(buffer).digest("hex");
3235
+ return new Array(64 - hash.length).join("0") + hash;
3236
+ }
3237
+ function generateSmallA() {
3238
+ return new import_jsbn.BigInteger((0, import_randombytes.default)(128).toString("hex"), 16);
3239
+ }
3240
+ function generateA(smallA) {
3241
+ const A = g.modPow(smallA, N);
3242
+ return A;
3243
+ }
3244
+ function calculateU(A, B) {
3245
+ return new import_jsbn.BigInteger(hashHexString(padHex(A) + padHex(B)), 16);
3246
+ }
3247
+ function calculateS(X, B, U, smallA) {
3248
+ const gModPowXN = g.modPow(X, N);
3249
+ const bMinusKMult = B.subtract(k.multiply(gModPowXN));
3250
+ return bMinusKMult.modPow(smallA.add(U.multiply(X)), N).mod(N);
3251
+ }
3252
+ function calculateHKDF(ikm, salt) {
3253
+ const infoBitsBuffer = Buffer.concat([
3254
+ Buffer.from("Caldera Derived Key", "utf8"),
3255
+ Buffer.from(String.fromCharCode(1), "utf8")
3256
+ ]);
3257
+ const prk = (0, import_hash.hmac)(import_hash.sha256, salt).update(ikm).digest();
3258
+ const hmacResult = (0, import_hash.hmac)(import_hash.sha256, prk).update(infoBitsBuffer).digest();
3259
+ return hmacResult.slice(0, 16);
3260
+ }
3261
+ function getPasswordAuthenticationKey(poolName, username, password, B, U, smallA, salt) {
3262
+ const usernamePassword = `${poolName}${username}:${password}`;
3263
+ const usernamePasswordHash = hashBuffer(Buffer.from(usernamePassword, "utf-8"));
3264
+ const X = new import_jsbn.BigInteger(hashHexString(padHex(salt) + usernamePasswordHash), 16);
3265
+ const S = calculateS(X, B, U, smallA);
3266
+ return calculateHKDF(Buffer.from(padHex(S), "hex"), Buffer.from(padHex(U), "hex"));
3267
+ }
3268
+ function calculateSignature(poolName, userId, secretBlock, hkdf) {
3269
+ const timeStamp = formatInTimeZone(/* @__PURE__ */ new Date(), "UTC", "EEE MMM d HH:mm:ss 'UTC' yyyy");
3270
+ const concatBuffer = Buffer.concat([
3271
+ Buffer.from(poolName, "utf8"),
3272
+ Buffer.from(userId, "utf8"),
3273
+ Buffer.from(secretBlock, "base64"),
3274
+ Buffer.from(timeStamp, "utf8")
3275
+ ]);
3276
+ const signature = Buffer.from(
3277
+ (0, import_hash.hmac)(import_hash.sha256, hkdf).update(concatBuffer).digest()
3278
+ ).toString("base64");
3279
+ return {
3280
+ signature,
3281
+ timeStamp
3282
+ };
3283
+ }
3284
+ function decodeJwt(jwt) {
3285
+ const [header, payload, signature] = jwt.split(".");
3286
+ return {
3287
+ header: JSON.parse(Buffer.from(header, "base64").toString("utf-8")),
3288
+ payload: JSON.parse(Buffer.from(payload, "base64").toString("utf-8")),
3289
+ signature
3290
+ };
3291
+ }
3292
+
3293
+ // src/cognito-client.ts
3294
+ var CognitoServiceTarget = /* @__PURE__ */ ((CognitoServiceTarget2) => {
3295
+ CognitoServiceTarget2["InitiateAuth"] = "InitiateAuth";
3296
+ CognitoServiceTarget2["RespondToAuthChallenge"] = "RespondToAuthChallenge";
3297
+ CognitoServiceTarget2["SignUp"] = "SignUp";
3298
+ CognitoServiceTarget2["ConfirmSignUp"] = "ConfirmSignUp";
3299
+ CognitoServiceTarget2["ChangePassword"] = "ChangePassword";
3300
+ CognitoServiceTarget2["RevokeToken"] = "RevokeToken";
3301
+ CognitoServiceTarget2["ForgotPassword"] = "ForgotPassword";
3302
+ CognitoServiceTarget2["ConfirmForgotPassword"] = "ConfirmForgotPassword";
3303
+ CognitoServiceTarget2["ResendConfirmationCode"] = "ResendConfirmationCode";
3304
+ CognitoServiceTarget2["UpdateUserAttributes"] = "UpdateUserAttributes";
3305
+ CognitoServiceTarget2["VerifyUserAttribute"] = "VerifyUserAttribute";
3306
+ return CognitoServiceTarget2;
3307
+ })(CognitoServiceTarget || {});
3308
+ var CognitoIdentityProvider = /* @__PURE__ */ ((CognitoIdentityProvider2) => {
3309
+ CognitoIdentityProvider2["Cognito"] = "COGNITO";
3310
+ CognitoIdentityProvider2["Google"] = "Google";
3311
+ CognitoIdentityProvider2["Facebook"] = "Facebook";
3312
+ CognitoIdentityProvider2["Amazon"] = "LoginWithAmazon";
3313
+ CognitoIdentityProvider2["Apple"] = "SignInWithApple";
3314
+ return CognitoIdentityProvider2;
3315
+ })(CognitoIdentityProvider || {});
3316
+ var CognitoClient = class {
3317
+ constructor({ userPoolId, userPoolClientId, endpoint, sessionStorage, oAuth2: oAuth }) {
3318
+ const [cognitoPoolRegion, cognitoPoolName] = userPoolId.split("_");
3319
+ this.cognitoEndpoint = (endpoint || `https://cognito-idp.${cognitoPoolRegion}.amazonaws.com`).replace(/\/$/, "");
3320
+ this.cognitoPoolName = cognitoPoolName;
3321
+ this.userPoolClientId = userPoolClientId;
3322
+ this.sessionStorage = sessionStorage;
3323
+ this.oAuth = oAuth;
3324
+ }
3325
+ static getDecodedTokenFromSession(session) {
3326
+ const { payload: idToken } = decodeJwt(session.idToken);
3327
+ const { payload: accessToken } = decodeJwt(session.accessToken);
3328
+ return {
3329
+ idToken,
3330
+ accessToken
3331
+ };
3332
+ }
3333
+ async cognitoRequest(body, serviceTarget) {
3334
+ const respondToAuthChallenge = await fetch(this.cognitoEndpoint, {
3335
+ headers: {
3336
+ "x-amz-target": `AWSCognitoIdentityProviderService.${serviceTarget}`,
3337
+ "content-type": "application/x-amz-json-1.1"
3338
+ },
3339
+ method: "POST",
3340
+ body: JSON.stringify(body)
3341
+ });
3342
+ if (respondToAuthChallenge.status < 200 || respondToAuthChallenge.status > 299) {
3343
+ const errorMessage = await respondToAuthChallenge.json();
3344
+ throw getAuthError(errorMessage);
3345
+ }
3346
+ return respondToAuthChallenge.json();
3347
+ }
3348
+ static authResultToSession(authenticationResult) {
3349
+ return {
3350
+ accessToken: authenticationResult.AccessToken,
3351
+ idToken: authenticationResult.IdToken,
3352
+ expiresIn: addSeconds(/* @__PURE__ */ new Date(), authenticationResult.ExpiresIn).getTime(),
3353
+ refreshToken: authenticationResult.RefreshToken
3354
+ };
3355
+ }
3356
+ /**
3357
+ *
3358
+ * Performs user authentication with username and password through ALLOW_USER_SRP_AUTH .
3359
+ * @see https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow.html for more details
3360
+ *
3361
+ * @param username Username
3362
+ * @param password Password
3363
+ * @throws {AuthException}
3364
+ */
3365
+ async authenticateUserSrp(username, password) {
3366
+ const smallA = generateSmallA();
3367
+ const A = generateA(smallA);
3368
+ const initiateAuthPayload = {
3369
+ AuthFlow: "USER_SRP_AUTH",
3370
+ ClientId: this.userPoolClientId,
3371
+ AuthParameters: {
3372
+ USERNAME: username,
3373
+ SRP_A: A.toString(16)
3374
+ },
3375
+ ClientMetadata: {}
3376
+ };
3377
+ const challenge = await this.cognitoRequest(
3378
+ initiateAuthPayload,
3379
+ "InitiateAuth" /* InitiateAuth */
3380
+ );
3381
+ const B = new import_jsbn2.BigInteger(challenge.ChallengeParameters.SRP_B, 16);
3382
+ const salt = new import_jsbn2.BigInteger(challenge.ChallengeParameters.SALT, 16);
3383
+ const U = calculateU(A, B);
3384
+ const hkdf = getPasswordAuthenticationKey(
3385
+ this.cognitoPoolName,
3386
+ challenge.ChallengeParameters.USER_ID_FOR_SRP,
3387
+ password,
3388
+ B,
3389
+ U,
3390
+ smallA,
3391
+ salt
3392
+ );
3393
+ const { signature, timeStamp } = calculateSignature(
3394
+ this.cognitoPoolName,
3395
+ challenge.ChallengeParameters.USER_ID_FOR_SRP,
3396
+ challenge.ChallengeParameters.SECRET_BLOCK,
3397
+ hkdf
3398
+ );
3399
+ const respondToAuthChallengePayload = {
3400
+ ChallengeName: "PASSWORD_VERIFIER",
3401
+ ClientId: this.userPoolClientId,
3402
+ ChallengeResponses: {
3403
+ PASSWORD_CLAIM_SECRET_BLOCK: challenge.ChallengeParameters.SECRET_BLOCK,
3404
+ PASSWORD_CLAIM_SIGNATURE: signature,
3405
+ USERNAME: challenge.ChallengeParameters.USER_ID_FOR_SRP,
3406
+ TIMESTAMP: timeStamp
3407
+ },
3408
+ ClientMetadata: {}
3409
+ };
3410
+ const { AuthenticationResult } = await this.cognitoRequest(
3411
+ respondToAuthChallengePayload,
3412
+ "RespondToAuthChallenge" /* RespondToAuthChallenge */
3413
+ );
3414
+ const session = CognitoClient.authResultToSession(AuthenticationResult);
3415
+ this.sessionStorage.setSession(session);
3416
+ return session;
3417
+ }
3418
+ /**
3419
+ *
3420
+ * Performs user authentication with username and password through USER_PASSWORD_AUTH .
3421
+ * @see https://docs.aws.amazon.com/cognito/latest/developerguide/amazon-cognito-user-pools-authentication-flow.html for more details
3422
+ *
3423
+ * @param username Username
3424
+ * @param password Password
3425
+ * @throws {AuthException}
3426
+ */
3427
+ async authenticateUser(username, password) {
3428
+ const initiateAuthPayload = {
3429
+ AuthFlow: "USER_PASSWORD_AUTH",
3430
+ ClientId: this.userPoolClientId,
3431
+ AuthParameters: {
3432
+ USERNAME: username,
3433
+ PASSWORD: password
3434
+ },
3435
+ ClientMetadata: {}
3436
+ };
3437
+ const { AuthenticationResult } = await this.cognitoRequest(
3438
+ initiateAuthPayload,
3439
+ "InitiateAuth" /* InitiateAuth */
3440
+ );
3441
+ const session = CognitoClient.authResultToSession(AuthenticationResult);
3442
+ this.sessionStorage.setSession(session);
3443
+ return session;
3444
+ }
3445
+ async refreshSession(session) {
3446
+ const refreshTokenPayload = {
3447
+ AuthFlow: "REFRESH_TOKEN_AUTH",
3448
+ ClientId: this.userPoolClientId,
3449
+ AuthParameters: {
3450
+ REFRESH_TOKEN: session.refreshToken
3451
+ },
3452
+ ClientMetadata: {}
3453
+ };
3454
+ const { AuthenticationResult } = await this.cognitoRequest(
3455
+ refreshTokenPayload,
3456
+ "InitiateAuth" /* InitiateAuth */
3457
+ );
3458
+ const newSession = CognitoClient.authResultToSession({
3459
+ ...AuthenticationResult,
3460
+ RefreshToken: session.refreshToken
3461
+ });
3462
+ this.sessionStorage.setSession(newSession);
3463
+ return newSession;
3464
+ }
3465
+ /**
3466
+ * Returns the current auth session.
3467
+ * The auth session is only defined when we previously had a successful user authentication.
3468
+ * This function will also take care to refresh the session with the refresh token in case
3469
+ * the current session has expired.
3470
+ *
3471
+ * @throws {AuthException}
3472
+ */
3473
+ async getSession() {
3474
+ const session = this.sessionStorage.getSession();
3475
+ if (session) {
3476
+ if ((/* @__PURE__ */ new Date()).getTime() >= session.expiresIn) {
3477
+ return this.refreshSession(session);
3478
+ }
3479
+ }
3480
+ return session;
3481
+ }
3482
+ /**
3483
+ *
3484
+ * @param username Username
3485
+ * @param password Password
3486
+ *
3487
+ * @throws {AuthException}
3488
+ */
3489
+ async signUp(username, password, userAttributes) {
3490
+ const signUpPayload = {
3491
+ ClientId: this.userPoolClientId,
3492
+ Username: username,
3493
+ Password: password,
3494
+ UserAttributes: userAttributes
3495
+ };
3496
+ const data = await this.cognitoRequest(signUpPayload, "SignUp" /* SignUp */);
3497
+ return {
3498
+ id: data.UserSub,
3499
+ confirmed: data.UserConfirmed
3500
+ };
3501
+ }
3502
+ /**
3503
+ * Confirms the user registration via verification code.
3504
+ *
3505
+ * @param username Username
3506
+ * @param code Confirmation code the user gets through the registration E-Mail
3507
+ *
3508
+ * @throws {AuthException}
3509
+ */
3510
+ async confirmSignUp(username, code) {
3511
+ const confirmSignUpPayload = {
3512
+ ClientId: this.userPoolClientId,
3513
+ ConfirmationCode: code,
3514
+ Username: username
3515
+ };
3516
+ const result = await this.cognitoRequest(confirmSignUpPayload, "ConfirmSignUp" /* ConfirmSignUp */);
3517
+ }
3518
+ /**
3519
+ *
3520
+ * @param currentPassword Current user password.
3521
+ * @param newPassword New user password.
3522
+ *
3523
+ * @throws {AuthException}
3524
+ */
3525
+ async changePassword(currentPassword, newPassword) {
3526
+ const session = await this.getSession();
3527
+ if (session === void 0) {
3528
+ throw new AuthException("User must be authenticated", "user_not_authenticated" /* UserNotAuthenticated */);
3529
+ }
3530
+ const changePasswordPayload = {
3531
+ PreviousPassword: currentPassword,
3532
+ ProposedPassword: newPassword,
3533
+ AccessToken: session.accessToken
3534
+ };
3535
+ const result = await this.cognitoRequest(changePasswordPayload, "ChangePassword" /* ChangePassword */);
3536
+ }
3537
+ async updateUserAttributes(userAttributes) {
3538
+ const session = await this.getSession();
3539
+ if (session === void 0) {
3540
+ throw new AuthException("User must be authenticated", "user_not_authenticated" /* UserNotAuthenticated */);
3541
+ }
3542
+ const updateUserAttributesPayload = {
3543
+ UserAttributes: userAttributes,
3544
+ AccessToken: session.accessToken
3545
+ };
3546
+ const result = await this.cognitoRequest(updateUserAttributesPayload, "UpdateUserAttributes" /* UpdateUserAttributes */);
3547
+ }
3548
+ async verifyUserAttribute(attributeName, code) {
3549
+ const session = await this.getSession();
3550
+ if (session === void 0) {
3551
+ throw new AuthException("User must be authenticated", "user_not_authenticated" /* UserNotAuthenticated */);
3552
+ }
3553
+ const verifyUserAttributePayload = {
3554
+ AttributeName: attributeName,
3555
+ Code: code,
3556
+ AccessToken: session.accessToken
3557
+ };
3558
+ const result = await this.cognitoRequest(verifyUserAttributePayload, "VerifyUserAttribute" /* VerifyUserAttribute */);
3559
+ }
3560
+ /**
3561
+ * Sign out the user and remove the current user session.
3562
+ *
3563
+ * @throws {AuthException}
3564
+ */
3565
+ async signOut() {
3566
+ const session = await this.getSession();
3567
+ if (session === void 0) {
3568
+ throw new AuthException("User must be authenticated", "user_not_authenticated" /* UserNotAuthenticated */);
3569
+ }
3570
+ const revokeTokenPayload = {
3571
+ Token: session.refreshToken,
3572
+ ClientId: this.userPoolClientId
3573
+ };
3574
+ this.sessionStorage.setSession(void 0);
3575
+ await this.cognitoRequest(revokeTokenPayload, "RevokeToken" /* RevokeToken */);
3576
+ }
3577
+ /**
3578
+ * Request forgot password.
3579
+ * @param username Username
3580
+ *
3581
+ * @throws {AuthException}
3582
+ */
3583
+ async forgotPassword(username) {
3584
+ const forgotPasswordPayload = {
3585
+ ClientId: this.userPoolClientId,
3586
+ Username: username
3587
+ };
3588
+ await this.cognitoRequest(forgotPasswordPayload, "ForgotPassword" /* ForgotPassword */);
3589
+ }
3590
+ /**
3591
+ * Confirms the new password via the given code send via cognito triggered by @see forgotPassword .
3592
+ *
3593
+ * @param username Username
3594
+ * @param newPassword New password
3595
+ * @param confirmationCode Confirmation code which the user got through E-mail
3596
+ *
3597
+ * @throws {AuthException}
3598
+ */
3599
+ async confirmForgotPassword(username, newPassword, confirmationCode) {
3600
+ const confirmForgotPasswordPayload = {
3601
+ ClientId: this.userPoolClientId,
3602
+ Username: username,
3603
+ ConfirmationCode: confirmationCode,
3604
+ Password: newPassword
3605
+ };
3606
+ await this.cognitoRequest(confirmForgotPasswordPayload, "ConfirmForgotPassword" /* ConfirmForgotPassword */);
3607
+ }
3608
+ /**
3609
+ * Triggers cognito to resend the confirmation code
3610
+ * @param username Username
3611
+ */
3612
+ async resendConfirmationCode(username) {
3613
+ const resendConfirmationCodePayLoad = {
3614
+ ClientId: this.userPoolClientId,
3615
+ Username: username
3616
+ };
3617
+ await this.cognitoRequest(resendConfirmationCodePayLoad, "ResendConfirmationCode" /* ResendConfirmationCode */);
3618
+ }
3619
+ /**
3620
+ * Returns a link to Cognito`s Hosted UI for OAuth2 authentication.
3621
+ * This method works in conjunction with @see handleCodeFlow .
3622
+ *
3623
+ * @param identityProvider When provided, this will generate a link which
3624
+ * tells Cognito`s Hosted UI to redirect to the given federated identity provider.
3625
+ *
3626
+ * @throws {Error}
3627
+ */
3628
+ generateOAuthSignInUrl(identityProvider) {
3629
+ if (this.oAuth === void 0) {
3630
+ throw Error("You have to define oAuth options to use generateFederatedSignUrl");
3631
+ }
3632
+ const state = (0, import_randombytes2.default)(32).toString("hex");
3633
+ const pkce = (0, import_randombytes2.default)(128).toString("hex");
3634
+ const code_challenge = Buffer.from((0, import_hash2.sha256)().update(pkce).digest()).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
3635
+ const queryParams = new URLSearchParams();
3636
+ queryParams.append("redirect_uri", this.oAuth.redirectUrl);
3637
+ queryParams.append("response_type", this.oAuth.responseType);
3638
+ queryParams.append("client_id", this.userPoolClientId);
3639
+ identityProvider && queryParams.append("identity_provider", identityProvider);
3640
+ queryParams.append("scope", this.oAuth.scopes.join(" "));
3641
+ queryParams.append("state", state);
3642
+ queryParams.append("code_challenge", code_challenge);
3643
+ queryParams.append("code_challenge_method", "S256");
3644
+ this.sessionStorage.setOauthVerificationParams({
3645
+ state,
3646
+ pkce
3647
+ });
3648
+ return `${this.oAuth.cognitoDomain}/oauth2/authorize?${queryParams.toString()}`;
3649
+ }
3650
+ /**
3651
+ *
3652
+ * Handles Cognito`s OAuth2 code flow after redirection from Cognito`s Hosted UI.
3653
+ * The method call assumes that @see generateOAuthSignInUrl was used to
3654
+ * generated the link to the Hosted UI.
3655
+ *
3656
+ * @param returnUrl The full return URL from redirection after a successful OAuth2
3657
+ * authentication.
3658
+ *
3659
+ * @throws {Error}
3660
+ */
3661
+ async handleCodeFlow(returnUrl) {
3662
+ if (this.oAuth === void 0) {
3663
+ throw Error("You have to define oAuth options to use handleCodeFlow");
3664
+ }
3665
+ const url = new URL(returnUrl);
3666
+ const code = url.searchParams.get("code");
3667
+ const state = url.searchParams.get("state");
3668
+ if (code === null || state === null) {
3669
+ throw Error("code or state parameter is missing from return url.");
3670
+ }
3671
+ const oAuthVerificationParams = this.sessionStorage.getOauthVerificationParams();
3672
+ if (oAuthVerificationParams === void 0) {
3673
+ throw new Error("OAuth verification parameters are missing, did you forgot to call generateOAuthSignInUrl ?");
3674
+ }
3675
+ if (oAuthVerificationParams.state !== state) {
3676
+ throw new Error(
3677
+ "state parameter does not match with previous value generated by previous call of generateOAuthSignInUrl ."
3678
+ );
3679
+ }
3680
+ const urlParams = new URLSearchParams();
3681
+ urlParams.append("grant_type", "authorization_code");
3682
+ urlParams.append("code", code);
3683
+ urlParams.append("client_id", this.userPoolClientId);
3684
+ urlParams.append("redirect_uri", this.oAuth.redirectUrl);
3685
+ urlParams.append("code_verifier", oAuthVerificationParams.pkce);
3686
+ const tokenEndpoint = `${this.oAuth.cognitoDomain}/oauth2/token`;
3687
+ const response = await fetch(tokenEndpoint, {
3688
+ method: "POST",
3689
+ headers: {
3690
+ "Content-Type": "application/x-www-form-urlencoded"
3691
+ },
3692
+ body: urlParams.toString()
3693
+ });
3694
+ const { access_token, refresh_token, id_token, expires_in, token_type, error } = await response.json();
3695
+ if (error) {
3696
+ throw new Error(error);
3697
+ }
3698
+ const session = CognitoClient.authResultToSession({
3699
+ AccessToken: access_token,
3700
+ RefreshToken: refresh_token,
3701
+ IdToken: id_token,
3702
+ ExpiresIn: expires_in,
3703
+ TokenType: token_type
3704
+ });
3705
+ this.sessionStorage.setSession(session);
3706
+ return session;
3707
+ }
3708
+ };
3709
+
3710
+ // src/session-storage/cookie-session-storage/cookie-session-storage.ts
3711
+ import { Cookies } from "@vardario/cookies";
3712
+
3713
+ // src/session-storage/session-storage.ts
3714
+ var SessionStorage = class {
3715
+ };
3716
+
3717
+ // src/session-storage/cookie-session-storage/cookie-session-storage.ts
3718
+ var CookieSessionStorage = class extends SessionStorage {
3719
+ constructor(props) {
3720
+ super();
3721
+ this.props = {
3722
+ domain: props.domain,
3723
+ path: props.path ?? "/",
3724
+ expires: props.expires ?? 365,
3725
+ secure: props.secure ?? true,
3726
+ sameSite: props.sameSite ?? "None",
3727
+ cookieName: props.cookieName
3728
+ };
3729
+ this.cookies = new Cookies(this.props);
3730
+ this.sessionCookieName = `${props.cookieName}`;
3731
+ this.oAuthParamCookieName = `${props.cookieName}_oauth`;
3732
+ }
3733
+ getSession() {
3734
+ const session = this.cookies.getCookie(this.sessionCookieName);
3735
+ if (session === void 0) {
3736
+ return void 0;
3737
+ }
3738
+ return JSON.parse(session);
3739
+ }
3740
+ setSession(session) {
3741
+ this.cookies.setCookie(this.sessionCookieName, JSON.stringify(session));
3742
+ }
3743
+ getOauthVerificationParams() {
3744
+ const oAuthParams = this.cookies.getCookie(this.oAuthParamCookieName);
3745
+ if (oAuthParams === void 0) {
3746
+ return void 0;
3747
+ }
3748
+ return JSON.parse(oAuthParams);
3749
+ }
3750
+ setOauthVerificationParams(oAuthParams) {
3751
+ this.cookies.setCookie(this.oAuthParamCookieName, JSON.stringify(oAuthParams));
3752
+ }
3753
+ };
3754
+
3755
+ // src/session-storage/local-storage-session-storage.ts
3756
+ var LocalStorageSessionStorage = class extends SessionStorage {
3757
+ constructor(props) {
3758
+ super();
3759
+ this.props = props;
3760
+ }
3761
+ getSession() {
3762
+ const payload = window.localStorage.getItem(this.props.storageName);
3763
+ if (payload === null) {
3764
+ return void 0;
3765
+ }
3766
+ return JSON.parse(payload);
3767
+ }
3768
+ setSession(session) {
3769
+ if (session === void 0) {
3770
+ window.localStorage.removeItem(this.props.storageName);
3771
+ return;
3772
+ }
3773
+ window.localStorage.setItem(this.props.storageName, JSON.stringify(session));
3774
+ }
3775
+ setOauthVerificationParams(oAuthParams) {
3776
+ window.localStorage.setItem(`${this.props.storageName}_oauth`, JSON.stringify(oAuthParams));
3777
+ }
3778
+ getOauthVerificationParams() {
3779
+ const payload = window.localStorage.getItem(`${this.props.storageName}_oauth`);
3780
+ if (payload === null) {
3781
+ return void 0;
3782
+ }
3783
+ return JSON.parse(payload);
3784
+ }
3785
+ };
3786
+
3787
+ // src/session-storage/memory-session-storage.ts
3788
+ var MemorySessionStorage = class extends SessionStorage {
3789
+ getSession() {
3790
+ return this.session;
3791
+ }
3792
+ setSession(session) {
3793
+ this.session = session;
3794
+ }
3795
+ getOauthVerificationParams() {
3796
+ return this.oAuthVerificationParams;
3797
+ }
3798
+ setOauthVerificationParams(oAuthParams) {
3799
+ this.oAuthVerificationParams = oAuthParams;
3800
+ }
3801
+ };
3802
+ export {
3803
+ AuthError,
3804
+ AuthException,
3805
+ CognitoClient,
3806
+ CognitoIdentityProvider,
3807
+ CognitoServiceTarget,
3808
+ CookieSessionStorage,
3809
+ ErrorCode,
3810
+ LocalStorageSessionStorage,
3811
+ MemorySessionStorage,
3812
+ SessionStorage,
3813
+ getAuthError
3814
+ };