@bigbinary/neeto-playwright-commons 1.8.28 → 1.8.30

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/index.js CHANGED
@@ -13,7 +13,7 @@ import require$$0$4 from 'path';
13
13
  import require$$0$5 from 'stream';
14
14
  import require$$0$6 from 'events';
15
15
  import { getI18nInstance, initI18n } from 'playwright-i18next-fixture';
16
- import { isNotEmpty, humanize } from '@bigbinary/neeto-cist';
16
+ import { isNotEmpty, humanize, isNotPresent } from '@bigbinary/neeto-cist';
17
17
  import require$$3 from 'crypto';
18
18
 
19
19
  const ENVIRONMENT = {
@@ -98,11 +98,23 @@ const skipTest = {
98
98
  forAllExceptStagingEnv: () => test$1.skip(process.env.TEST_ENV !== ENVIRONMENT.staging),
99
99
  forNonNightlyRun: () => {
100
100
  const currentBranch = execCommand("git rev-parse --abbrev-ref HEAD");
101
- const isNightlyRun = currentBranch === "main" && process.env.TEST_ENV === ENVIRONMENT.staging;
101
+ const isNightlyRun = currentBranch === "main" &&
102
+ process.env.TEST_ENV === ENVIRONMENT.staging &&
103
+ !!process.env.NEETO_CI_JOB_ID;
102
104
  return test$1.skip(not(isNightlyRun), "Run test only in playwright-nightly");
103
105
  },
106
+ ifNotWithinAllowedNightlyHours: ({ reason, allowedNightlyRunHours = [0, 6, 12, 18], }) => {
107
+ skipTest.forNonNightlyRun();
108
+ const currentDate = new Date();
109
+ const day = currentDate.getUTCDay();
110
+ const hour = currentDate.getUTCHours();
111
+ const isAllowedNightlyRun = 0 < day && day < 6 && allowedNightlyRunHours.includes(hour);
112
+ test$1.skip(not(isAllowedNightlyRun), `Nightly run is skipped due to ${reason}`);
113
+ },
104
114
  };
105
115
  const shouldSkipSetupAndTeardown = () => { var _a; return ((_a = getGlobalUserState()) === null || _a === void 0 ? void 0 : _a.isLoggedIn) && process.env.SKIP_SETUP === "true"; };
116
+ // trims and replaces multiple whitespace characters in a string with a single space
117
+ const squish = (text) => text.trim().replace(/\s+/g, " ");
106
118
 
107
119
  const COMMON_SELECTORS = {
108
120
  spinner: ".neeto-ui-spinner",
@@ -12809,6 +12821,7 @@ const SIGNUP_SELECTORS = {
12809
12821
  subdomainNameTextField: "signup-organization-subdomain-text-field",
12810
12822
  subdomainError: "subdomain-input-error",
12811
12823
  tryFreeButton: "neeto-auth-signup-link",
12824
+ unregisterdEmailError: "unregisterd-email-error",
12812
12825
  };
12813
12826
 
12814
12827
  const extractSubdomainFromError = (errorString) => {
@@ -13232,6 +13245,1516 @@ const headerUtils = {
13232
13245
  verifyBreadcrumbs,
13233
13246
  };
13234
13247
 
13248
+ /// <reference types="./otpauth.d.ts" />
13249
+ /**
13250
+ * Converts an integer to an ArrayBuffer.
13251
+ * @param {number} num Integer.
13252
+ * @returns {ArrayBuffer} ArrayBuffer.
13253
+ */
13254
+ const uintToBuf = num => {
13255
+ const buf = new ArrayBuffer(8);
13256
+ const arr = new Uint8Array(buf);
13257
+ let acc = num;
13258
+ for (let i = 7; i >= 0; i--) {
13259
+ if (acc === 0) break;
13260
+ arr[i] = acc & 255;
13261
+ acc -= arr[i];
13262
+ acc /= 256;
13263
+ }
13264
+ return buf;
13265
+ };
13266
+
13267
+ /**
13268
+ * A JavaScript implementation of the SHA family of hashes - defined in FIPS PUB 180-4, FIPS PUB 202,
13269
+ * and SP 800-185 - as well as the corresponding HMAC implementation as defined in FIPS PUB 198-1.
13270
+ *
13271
+ * Copyright 2008-2023 Brian Turek, 1998-2009 Paul Johnston & Contributors
13272
+ * Distributed under the BSD License
13273
+ * See http://caligatio.github.com/jsSHA/ for more information
13274
+ */
13275
+ const t = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",
13276
+ n = "ARRAYBUFFER not supported by this environment",
13277
+ e = "UINT8ARRAY not supported by this environment";
13278
+ function r(t, n, e, r) {
13279
+ let i, s, o;
13280
+ const h = n || [0],
13281
+ u = (e = e || 0) >>> 3,
13282
+ w = -1 === r ? 3 : 0;
13283
+ for (i = 0; i < t.length; i += 1) o = i + u, s = o >>> 2, h.length <= s && h.push(0), h[s] |= t[i] << 8 * (w + r * (o % 4));
13284
+ return {
13285
+ value: h,
13286
+ binLen: 8 * t.length + e
13287
+ };
13288
+ }
13289
+ function i(i, s, o) {
13290
+ switch (s) {
13291
+ case "UTF8":
13292
+ case "UTF16BE":
13293
+ case "UTF16LE":
13294
+ break;
13295
+ default:
13296
+ throw new Error("encoding must be UTF8, UTF16BE, or UTF16LE");
13297
+ }
13298
+ switch (i) {
13299
+ case "HEX":
13300
+ return function (t, n, e) {
13301
+ return function (t, n, e, r) {
13302
+ let i, s, o, h;
13303
+ if (0 != t.length % 2) throw new Error("String of HEX type must be in byte increments");
13304
+ const u = n || [0],
13305
+ w = (e = e || 0) >>> 3,
13306
+ c = -1 === r ? 3 : 0;
13307
+ for (i = 0; i < t.length; i += 2) {
13308
+ if (s = parseInt(t.substr(i, 2), 16), isNaN(s)) throw new Error("String of HEX type contains invalid characters");
13309
+ for (h = (i >>> 1) + w, o = h >>> 2; u.length <= o;) u.push(0);
13310
+ u[o] |= s << 8 * (c + r * (h % 4));
13311
+ }
13312
+ return {
13313
+ value: u,
13314
+ binLen: 4 * t.length + e
13315
+ };
13316
+ }(t, n, e, o);
13317
+ };
13318
+ case "TEXT":
13319
+ return function (t, n, e) {
13320
+ return function (t, n, e, r, i) {
13321
+ let s,
13322
+ o,
13323
+ h,
13324
+ u,
13325
+ w,
13326
+ c,
13327
+ f,
13328
+ a,
13329
+ l = 0;
13330
+ const A = e || [0],
13331
+ E = (r = r || 0) >>> 3;
13332
+ if ("UTF8" === n) for (f = -1 === i ? 3 : 0, h = 0; h < t.length; h += 1) for (s = t.charCodeAt(h), o = [], 128 > s ? o.push(s) : 2048 > s ? (o.push(192 | s >>> 6), o.push(128 | 63 & s)) : 55296 > s || 57344 <= s ? o.push(224 | s >>> 12, 128 | s >>> 6 & 63, 128 | 63 & s) : (h += 1, s = 65536 + ((1023 & s) << 10 | 1023 & t.charCodeAt(h)), o.push(240 | s >>> 18, 128 | s >>> 12 & 63, 128 | s >>> 6 & 63, 128 | 63 & s)), u = 0; u < o.length; u += 1) {
13333
+ for (c = l + E, w = c >>> 2; A.length <= w;) A.push(0);
13334
+ A[w] |= o[u] << 8 * (f + i * (c % 4)), l += 1;
13335
+ } else for (f = -1 === i ? 2 : 0, a = "UTF16LE" === n && 1 !== i || "UTF16LE" !== n && 1 === i, h = 0; h < t.length; h += 1) {
13336
+ for (s = t.charCodeAt(h), !0 === a && (u = 255 & s, s = u << 8 | s >>> 8), c = l + E, w = c >>> 2; A.length <= w;) A.push(0);
13337
+ A[w] |= s << 8 * (f + i * (c % 4)), l += 2;
13338
+ }
13339
+ return {
13340
+ value: A,
13341
+ binLen: 8 * l + r
13342
+ };
13343
+ }(t, s, n, e, o);
13344
+ };
13345
+ case "B64":
13346
+ return function (n, e, r) {
13347
+ return function (n, e, r, i) {
13348
+ let s,
13349
+ o,
13350
+ h,
13351
+ u,
13352
+ w,
13353
+ c,
13354
+ f,
13355
+ a = 0;
13356
+ const l = e || [0],
13357
+ A = (r = r || 0) >>> 3,
13358
+ E = -1 === i ? 3 : 0,
13359
+ H = n.indexOf("=");
13360
+ if (-1 === n.search(/^[a-zA-Z0-9=+/]+$/)) throw new Error("Invalid character in base-64 string");
13361
+ if (n = n.replace(/=/g, ""), -1 !== H && H < n.length) throw new Error("Invalid '=' found in base-64 string");
13362
+ for (o = 0; o < n.length; o += 4) {
13363
+ for (w = n.substr(o, 4), u = 0, h = 0; h < w.length; h += 1) s = t.indexOf(w.charAt(h)), u |= s << 18 - 6 * h;
13364
+ for (h = 0; h < w.length - 1; h += 1) {
13365
+ for (f = a + A, c = f >>> 2; l.length <= c;) l.push(0);
13366
+ l[c] |= (u >>> 16 - 8 * h & 255) << 8 * (E + i * (f % 4)), a += 1;
13367
+ }
13368
+ }
13369
+ return {
13370
+ value: l,
13371
+ binLen: 8 * a + r
13372
+ };
13373
+ }(n, e, r, o);
13374
+ };
13375
+ case "BYTES":
13376
+ return function (t, n, e) {
13377
+ return function (t, n, e, r) {
13378
+ let i, s, o, h;
13379
+ const u = n || [0],
13380
+ w = (e = e || 0) >>> 3,
13381
+ c = -1 === r ? 3 : 0;
13382
+ for (s = 0; s < t.length; s += 1) i = t.charCodeAt(s), h = s + w, o = h >>> 2, u.length <= o && u.push(0), u[o] |= i << 8 * (c + r * (h % 4));
13383
+ return {
13384
+ value: u,
13385
+ binLen: 8 * t.length + e
13386
+ };
13387
+ }(t, n, e, o);
13388
+ };
13389
+ case "ARRAYBUFFER":
13390
+ try {
13391
+ new ArrayBuffer(0);
13392
+ } catch (t) {
13393
+ throw new Error(n);
13394
+ }
13395
+ return function (t, n, e) {
13396
+ return function (t, n, e, i) {
13397
+ return r(new Uint8Array(t), n, e, i);
13398
+ }(t, n, e, o);
13399
+ };
13400
+ case "UINT8ARRAY":
13401
+ try {
13402
+ new Uint8Array(0);
13403
+ } catch (t) {
13404
+ throw new Error(e);
13405
+ }
13406
+ return function (t, n, e) {
13407
+ return r(t, n, e, o);
13408
+ };
13409
+ default:
13410
+ throw new Error("format must be HEX, TEXT, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY");
13411
+ }
13412
+ }
13413
+ function s(r, i, s, o) {
13414
+ switch (r) {
13415
+ case "HEX":
13416
+ return function (t) {
13417
+ return function (t, n, e, r) {
13418
+ const i = "0123456789abcdef";
13419
+ let s,
13420
+ o,
13421
+ h = "";
13422
+ const u = n / 8,
13423
+ w = -1 === e ? 3 : 0;
13424
+ for (s = 0; s < u; s += 1) o = t[s >>> 2] >>> 8 * (w + e * (s % 4)), h += i.charAt(o >>> 4 & 15) + i.charAt(15 & o);
13425
+ return r.outputUpper ? h.toUpperCase() : h;
13426
+ }(t, i, s, o);
13427
+ };
13428
+ case "B64":
13429
+ return function (n) {
13430
+ return function (n, e, r, i) {
13431
+ let s,
13432
+ o,
13433
+ h,
13434
+ u,
13435
+ w,
13436
+ c = "";
13437
+ const f = e / 8,
13438
+ a = -1 === r ? 3 : 0;
13439
+ for (s = 0; s < f; s += 3) for (u = s + 1 < f ? n[s + 1 >>> 2] : 0, w = s + 2 < f ? n[s + 2 >>> 2] : 0, h = (n[s >>> 2] >>> 8 * (a + r * (s % 4)) & 255) << 16 | (u >>> 8 * (a + r * ((s + 1) % 4)) & 255) << 8 | w >>> 8 * (a + r * ((s + 2) % 4)) & 255, o = 0; o < 4; o += 1) c += 8 * s + 6 * o <= e ? t.charAt(h >>> 6 * (3 - o) & 63) : i.b64Pad;
13440
+ return c;
13441
+ }(n, i, s, o);
13442
+ };
13443
+ case "BYTES":
13444
+ return function (t) {
13445
+ return function (t, n, e) {
13446
+ let r,
13447
+ i,
13448
+ s = "";
13449
+ const o = n / 8,
13450
+ h = -1 === e ? 3 : 0;
13451
+ for (r = 0; r < o; r += 1) i = t[r >>> 2] >>> 8 * (h + e * (r % 4)) & 255, s += String.fromCharCode(i);
13452
+ return s;
13453
+ }(t, i, s);
13454
+ };
13455
+ case "ARRAYBUFFER":
13456
+ try {
13457
+ new ArrayBuffer(0);
13458
+ } catch (t) {
13459
+ throw new Error(n);
13460
+ }
13461
+ return function (t) {
13462
+ return function (t, n, e) {
13463
+ let r;
13464
+ const i = n / 8,
13465
+ s = new ArrayBuffer(i),
13466
+ o = new Uint8Array(s),
13467
+ h = -1 === e ? 3 : 0;
13468
+ for (r = 0; r < i; r += 1) o[r] = t[r >>> 2] >>> 8 * (h + e * (r % 4)) & 255;
13469
+ return s;
13470
+ }(t, i, s);
13471
+ };
13472
+ case "UINT8ARRAY":
13473
+ try {
13474
+ new Uint8Array(0);
13475
+ } catch (t) {
13476
+ throw new Error(e);
13477
+ }
13478
+ return function (t) {
13479
+ return function (t, n, e) {
13480
+ let r;
13481
+ const i = n / 8,
13482
+ s = -1 === e ? 3 : 0,
13483
+ o = new Uint8Array(i);
13484
+ for (r = 0; r < i; r += 1) o[r] = t[r >>> 2] >>> 8 * (s + e * (r % 4)) & 255;
13485
+ return o;
13486
+ }(t, i, s);
13487
+ };
13488
+ default:
13489
+ throw new Error("format must be HEX, B64, BYTES, ARRAYBUFFER, or UINT8ARRAY");
13490
+ }
13491
+ }
13492
+ const o = 4294967296,
13493
+ h = [1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298],
13494
+ u = [3238371032, 914150663, 812702999, 4144912697, 4290775857, 1750603025, 1694076839, 3204075428],
13495
+ w = [1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225],
13496
+ c = "Chosen SHA variant is not supported",
13497
+ f = "Cannot set numRounds with MAC";
13498
+ function a(t, n) {
13499
+ let e, r;
13500
+ const i = t.binLen >>> 3,
13501
+ s = n.binLen >>> 3,
13502
+ o = i << 3,
13503
+ h = 4 - i << 3;
13504
+ if (i % 4 != 0) {
13505
+ for (e = 0; e < s; e += 4) r = i + e >>> 2, t.value[r] |= n.value[e >>> 2] << o, t.value.push(0), t.value[r + 1] |= n.value[e >>> 2] >>> h;
13506
+ return (t.value.length << 2) - 4 >= s + i && t.value.pop(), {
13507
+ value: t.value,
13508
+ binLen: t.binLen + n.binLen
13509
+ };
13510
+ }
13511
+ return {
13512
+ value: t.value.concat(n.value),
13513
+ binLen: t.binLen + n.binLen
13514
+ };
13515
+ }
13516
+ function l(t) {
13517
+ const n = {
13518
+ outputUpper: !1,
13519
+ b64Pad: "=",
13520
+ outputLen: -1
13521
+ },
13522
+ e = t || {},
13523
+ r = "Output length must be a multiple of 8";
13524
+ if (n.outputUpper = e.outputUpper || !1, e.b64Pad && (n.b64Pad = e.b64Pad), e.outputLen) {
13525
+ if (e.outputLen % 8 != 0) throw new Error(r);
13526
+ n.outputLen = e.outputLen;
13527
+ } else if (e.shakeLen) {
13528
+ if (e.shakeLen % 8 != 0) throw new Error(r);
13529
+ n.outputLen = e.shakeLen;
13530
+ }
13531
+ if ("boolean" != typeof n.outputUpper) throw new Error("Invalid outputUpper formatting option");
13532
+ if ("string" != typeof n.b64Pad) throw new Error("Invalid b64Pad formatting option");
13533
+ return n;
13534
+ }
13535
+ function A(t, n, e, r) {
13536
+ const s = t + " must include a value and format";
13537
+ if (!n) {
13538
+ if (!r) throw new Error(s);
13539
+ return r;
13540
+ }
13541
+ if (void 0 === n.value || !n.format) throw new Error(s);
13542
+ return i(n.format, n.encoding || "UTF8", e)(n.value);
13543
+ }
13544
+ class E {
13545
+ constructor(t, n, e) {
13546
+ const r = e || {};
13547
+ if (this.t = n, this.i = r.encoding || "UTF8", this.numRounds = r.numRounds || 1, isNaN(this.numRounds) || this.numRounds !== parseInt(this.numRounds, 10) || 1 > this.numRounds) throw new Error("numRounds must a integer >= 1");
13548
+ this.o = t, this.h = [], this.u = 0, this.l = !1, this.A = 0, this.H = !1, this.S = [], this.p = [];
13549
+ }
13550
+ update(t) {
13551
+ let n,
13552
+ e = 0;
13553
+ const r = this.m >>> 5,
13554
+ i = this.C(t, this.h, this.u),
13555
+ s = i.binLen,
13556
+ o = i.value,
13557
+ h = s >>> 5;
13558
+ for (n = 0; n < h; n += r) e + this.m <= s && (this.U = this.v(o.slice(n, n + r), this.U), e += this.m);
13559
+ return this.A += e, this.h = o.slice(e >>> 5), this.u = s % this.m, this.l = !0, this;
13560
+ }
13561
+ getHash(t, n) {
13562
+ let e,
13563
+ r,
13564
+ i = this.R;
13565
+ const o = l(n);
13566
+ if (this.K) {
13567
+ if (-1 === o.outputLen) throw new Error("Output length must be specified in options");
13568
+ i = o.outputLen;
13569
+ }
13570
+ const h = s(t, i, this.T, o);
13571
+ if (this.H && this.g) return h(this.g(o));
13572
+ for (r = this.F(this.h.slice(), this.u, this.A, this.L(this.U), i), e = 1; e < this.numRounds; e += 1) this.K && i % 32 != 0 && (r[r.length - 1] &= 16777215 >>> 24 - i % 32), r = this.F(r, i, 0, this.B(this.o), i);
13573
+ return h(r);
13574
+ }
13575
+ setHMACKey(t, n, e) {
13576
+ if (!this.M) throw new Error("Variant does not support HMAC");
13577
+ if (this.l) throw new Error("Cannot set MAC key after calling update");
13578
+ const r = i(n, (e || {}).encoding || "UTF8", this.T);
13579
+ this.k(r(t));
13580
+ }
13581
+ k(t) {
13582
+ const n = this.m >>> 3,
13583
+ e = n / 4 - 1;
13584
+ let r;
13585
+ if (1 !== this.numRounds) throw new Error(f);
13586
+ if (this.H) throw new Error("MAC key already set");
13587
+ for (n < t.binLen / 8 && (t.value = this.F(t.value, t.binLen, 0, this.B(this.o), this.R)); t.value.length <= e;) t.value.push(0);
13588
+ for (r = 0; r <= e; r += 1) this.S[r] = 909522486 ^ t.value[r], this.p[r] = 1549556828 ^ t.value[r];
13589
+ this.U = this.v(this.S, this.U), this.A = this.m, this.H = !0;
13590
+ }
13591
+ getHMAC(t, n) {
13592
+ const e = l(n);
13593
+ return s(t, this.R, this.T, e)(this.Y());
13594
+ }
13595
+ Y() {
13596
+ let t;
13597
+ if (!this.H) throw new Error("Cannot call getHMAC without first setting MAC key");
13598
+ const n = this.F(this.h.slice(), this.u, this.A, this.L(this.U), this.R);
13599
+ return t = this.v(this.p, this.B(this.o)), t = this.F(n, this.R, this.m, t, this.R), t;
13600
+ }
13601
+ }
13602
+ function H(t, n) {
13603
+ return t << n | t >>> 32 - n;
13604
+ }
13605
+ function S(t, n) {
13606
+ return t >>> n | t << 32 - n;
13607
+ }
13608
+ function b(t, n) {
13609
+ return t >>> n;
13610
+ }
13611
+ function p(t, n, e) {
13612
+ return t ^ n ^ e;
13613
+ }
13614
+ function d(t, n, e) {
13615
+ return t & n ^ ~t & e;
13616
+ }
13617
+ function m(t, n, e) {
13618
+ return t & n ^ t & e ^ n & e;
13619
+ }
13620
+ function C(t) {
13621
+ return S(t, 2) ^ S(t, 13) ^ S(t, 22);
13622
+ }
13623
+ function y(t, n) {
13624
+ const e = (65535 & t) + (65535 & n);
13625
+ return (65535 & (t >>> 16) + (n >>> 16) + (e >>> 16)) << 16 | 65535 & e;
13626
+ }
13627
+ function U(t, n, e, r) {
13628
+ const i = (65535 & t) + (65535 & n) + (65535 & e) + (65535 & r);
13629
+ return (65535 & (t >>> 16) + (n >>> 16) + (e >>> 16) + (r >>> 16) + (i >>> 16)) << 16 | 65535 & i;
13630
+ }
13631
+ function v(t, n, e, r, i) {
13632
+ const s = (65535 & t) + (65535 & n) + (65535 & e) + (65535 & r) + (65535 & i);
13633
+ return (65535 & (t >>> 16) + (n >>> 16) + (e >>> 16) + (r >>> 16) + (i >>> 16) + (s >>> 16)) << 16 | 65535 & s;
13634
+ }
13635
+ function R(t) {
13636
+ return S(t, 7) ^ S(t, 18) ^ b(t, 3);
13637
+ }
13638
+ function K(t) {
13639
+ return S(t, 6) ^ S(t, 11) ^ S(t, 25);
13640
+ }
13641
+ function T(t) {
13642
+ return [1732584193, 4023233417, 2562383102, 271733878, 3285377520];
13643
+ }
13644
+ function g(t, n) {
13645
+ let e, r, i, s, o, h, u;
13646
+ const w = [];
13647
+ for (e = n[0], r = n[1], i = n[2], s = n[3], o = n[4], u = 0; u < 80; u += 1) w[u] = u < 16 ? t[u] : H(w[u - 3] ^ w[u - 8] ^ w[u - 14] ^ w[u - 16], 1), h = u < 20 ? v(H(e, 5), d(r, i, s), o, 1518500249, w[u]) : u < 40 ? v(H(e, 5), p(r, i, s), o, 1859775393, w[u]) : u < 60 ? v(H(e, 5), m(r, i, s), o, 2400959708, w[u]) : v(H(e, 5), p(r, i, s), o, 3395469782, w[u]), o = s, s = i, i = H(r, 30), r = e, e = h;
13648
+ return n[0] = y(e, n[0]), n[1] = y(r, n[1]), n[2] = y(i, n[2]), n[3] = y(s, n[3]), n[4] = y(o, n[4]), n;
13649
+ }
13650
+ function F(t, n, e, r) {
13651
+ let i;
13652
+ const s = 15 + (n + 65 >>> 9 << 4),
13653
+ h = n + e;
13654
+ for (; t.length <= s;) t.push(0);
13655
+ for (t[n >>> 5] |= 128 << 24 - n % 32, t[s] = 4294967295 & h, t[s - 1] = h / o | 0, i = 0; i < t.length; i += 16) r = g(t.slice(i, i + 16), r);
13656
+ return r;
13657
+ }
13658
+ let L = class extends E {
13659
+ constructor(t, n, e) {
13660
+ if ("SHA-1" !== t) throw new Error(c);
13661
+ super(t, n, e);
13662
+ const r = e || {};
13663
+ this.M = !0, this.g = this.Y, this.T = -1, this.C = i(this.t, this.i, this.T), this.v = g, this.L = function (t) {
13664
+ return t.slice();
13665
+ }, this.B = T, this.F = F, this.U = [1732584193, 4023233417, 2562383102, 271733878, 3285377520], this.m = 512, this.R = 160, this.K = !1, r.hmacKey && this.k(A("hmacKey", r.hmacKey, this.T));
13666
+ }
13667
+ };
13668
+ function B(t) {
13669
+ let n;
13670
+ return n = "SHA-224" == t ? u.slice() : w.slice(), n;
13671
+ }
13672
+ function M(t, n) {
13673
+ let e, r, i, s, o, u, w, c, f, a, l;
13674
+ const A = [];
13675
+ for (e = n[0], r = n[1], i = n[2], s = n[3], o = n[4], u = n[5], w = n[6], c = n[7], l = 0; l < 64; l += 1) A[l] = l < 16 ? t[l] : U(S(E = A[l - 2], 17) ^ S(E, 19) ^ b(E, 10), A[l - 7], R(A[l - 15]), A[l - 16]), f = v(c, K(o), d(o, u, w), h[l], A[l]), a = y(C(e), m(e, r, i)), c = w, w = u, u = o, o = y(s, f), s = i, i = r, r = e, e = y(f, a);
13676
+ var E;
13677
+ return n[0] = y(e, n[0]), n[1] = y(r, n[1]), n[2] = y(i, n[2]), n[3] = y(s, n[3]), n[4] = y(o, n[4]), n[5] = y(u, n[5]), n[6] = y(w, n[6]), n[7] = y(c, n[7]), n;
13678
+ }
13679
+ let k = class extends E {
13680
+ constructor(t, n, e) {
13681
+ if ("SHA-224" !== t && "SHA-256" !== t) throw new Error(c);
13682
+ super(t, n, e);
13683
+ const r = e || {};
13684
+ this.g = this.Y, this.M = !0, this.T = -1, this.C = i(this.t, this.i, this.T), this.v = M, this.L = function (t) {
13685
+ return t.slice();
13686
+ }, this.B = B, this.F = function (n, e, r, i) {
13687
+ return function (t, n, e, r, i) {
13688
+ let s, h;
13689
+ const u = 15 + (n + 65 >>> 9 << 4),
13690
+ w = n + e;
13691
+ for (; t.length <= u;) t.push(0);
13692
+ for (t[n >>> 5] |= 128 << 24 - n % 32, t[u] = 4294967295 & w, t[u - 1] = w / o | 0, s = 0; s < t.length; s += 16) r = M(t.slice(s, s + 16), r);
13693
+ return h = "SHA-224" === i ? [r[0], r[1], r[2], r[3], r[4], r[5], r[6]] : r, h;
13694
+ }(n, e, r, i, t);
13695
+ }, this.U = B(t), this.m = 512, this.R = "SHA-224" === t ? 224 : 256, this.K = !1, r.hmacKey && this.k(A("hmacKey", r.hmacKey, this.T));
13696
+ }
13697
+ };
13698
+ class Y {
13699
+ constructor(t, n) {
13700
+ this.N = t, this.I = n;
13701
+ }
13702
+ }
13703
+ function N(t, n) {
13704
+ let e;
13705
+ return n > 32 ? (e = 64 - n, new Y(t.I << n | t.N >>> e, t.N << n | t.I >>> e)) : 0 !== n ? (e = 32 - n, new Y(t.N << n | t.I >>> e, t.I << n | t.N >>> e)) : t;
13706
+ }
13707
+ function I(t, n) {
13708
+ let e;
13709
+ return n < 32 ? (e = 32 - n, new Y(t.N >>> n | t.I << e, t.I >>> n | t.N << e)) : (e = 64 - n, new Y(t.I >>> n | t.N << e, t.N >>> n | t.I << e));
13710
+ }
13711
+ function X(t, n) {
13712
+ return new Y(t.N >>> n, t.I >>> n | t.N << 32 - n);
13713
+ }
13714
+ function z(t, n, e) {
13715
+ return new Y(t.N & n.N ^ t.N & e.N ^ n.N & e.N, t.I & n.I ^ t.I & e.I ^ n.I & e.I);
13716
+ }
13717
+ function x(t) {
13718
+ const n = I(t, 28),
13719
+ e = I(t, 34),
13720
+ r = I(t, 39);
13721
+ return new Y(n.N ^ e.N ^ r.N, n.I ^ e.I ^ r.I);
13722
+ }
13723
+ function _(t, n) {
13724
+ let e, r;
13725
+ e = (65535 & t.I) + (65535 & n.I), r = (t.I >>> 16) + (n.I >>> 16) + (e >>> 16);
13726
+ const i = (65535 & r) << 16 | 65535 & e;
13727
+ e = (65535 & t.N) + (65535 & n.N) + (r >>> 16), r = (t.N >>> 16) + (n.N >>> 16) + (e >>> 16);
13728
+ return new Y((65535 & r) << 16 | 65535 & e, i);
13729
+ }
13730
+ function O(t, n, e, r) {
13731
+ let i, s;
13732
+ i = (65535 & t.I) + (65535 & n.I) + (65535 & e.I) + (65535 & r.I), s = (t.I >>> 16) + (n.I >>> 16) + (e.I >>> 16) + (r.I >>> 16) + (i >>> 16);
13733
+ const o = (65535 & s) << 16 | 65535 & i;
13734
+ i = (65535 & t.N) + (65535 & n.N) + (65535 & e.N) + (65535 & r.N) + (s >>> 16), s = (t.N >>> 16) + (n.N >>> 16) + (e.N >>> 16) + (r.N >>> 16) + (i >>> 16);
13735
+ return new Y((65535 & s) << 16 | 65535 & i, o);
13736
+ }
13737
+ function P(t, n, e, r, i) {
13738
+ let s, o;
13739
+ s = (65535 & t.I) + (65535 & n.I) + (65535 & e.I) + (65535 & r.I) + (65535 & i.I), o = (t.I >>> 16) + (n.I >>> 16) + (e.I >>> 16) + (r.I >>> 16) + (i.I >>> 16) + (s >>> 16);
13740
+ const h = (65535 & o) << 16 | 65535 & s;
13741
+ s = (65535 & t.N) + (65535 & n.N) + (65535 & e.N) + (65535 & r.N) + (65535 & i.N) + (o >>> 16), o = (t.N >>> 16) + (n.N >>> 16) + (e.N >>> 16) + (r.N >>> 16) + (i.N >>> 16) + (s >>> 16);
13742
+ return new Y((65535 & o) << 16 | 65535 & s, h);
13743
+ }
13744
+ function V(t, n) {
13745
+ return new Y(t.N ^ n.N, t.I ^ n.I);
13746
+ }
13747
+ function Z(t) {
13748
+ const n = I(t, 19),
13749
+ e = I(t, 61),
13750
+ r = X(t, 6);
13751
+ return new Y(n.N ^ e.N ^ r.N, n.I ^ e.I ^ r.I);
13752
+ }
13753
+ function j(t) {
13754
+ const n = I(t, 1),
13755
+ e = I(t, 8),
13756
+ r = X(t, 7);
13757
+ return new Y(n.N ^ e.N ^ r.N, n.I ^ e.I ^ r.I);
13758
+ }
13759
+ function q(t) {
13760
+ const n = I(t, 14),
13761
+ e = I(t, 18),
13762
+ r = I(t, 41);
13763
+ return new Y(n.N ^ e.N ^ r.N, n.I ^ e.I ^ r.I);
13764
+ }
13765
+ const D = [new Y(h[0], 3609767458), new Y(h[1], 602891725), new Y(h[2], 3964484399), new Y(h[3], 2173295548), new Y(h[4], 4081628472), new Y(h[5], 3053834265), new Y(h[6], 2937671579), new Y(h[7], 3664609560), new Y(h[8], 2734883394), new Y(h[9], 1164996542), new Y(h[10], 1323610764), new Y(h[11], 3590304994), new Y(h[12], 4068182383), new Y(h[13], 991336113), new Y(h[14], 633803317), new Y(h[15], 3479774868), new Y(h[16], 2666613458), new Y(h[17], 944711139), new Y(h[18], 2341262773), new Y(h[19], 2007800933), new Y(h[20], 1495990901), new Y(h[21], 1856431235), new Y(h[22], 3175218132), new Y(h[23], 2198950837), new Y(h[24], 3999719339), new Y(h[25], 766784016), new Y(h[26], 2566594879), new Y(h[27], 3203337956), new Y(h[28], 1034457026), new Y(h[29], 2466948901), new Y(h[30], 3758326383), new Y(h[31], 168717936), new Y(h[32], 1188179964), new Y(h[33], 1546045734), new Y(h[34], 1522805485), new Y(h[35], 2643833823), new Y(h[36], 2343527390), new Y(h[37], 1014477480), new Y(h[38], 1206759142), new Y(h[39], 344077627), new Y(h[40], 1290863460), new Y(h[41], 3158454273), new Y(h[42], 3505952657), new Y(h[43], 106217008), new Y(h[44], 3606008344), new Y(h[45], 1432725776), new Y(h[46], 1467031594), new Y(h[47], 851169720), new Y(h[48], 3100823752), new Y(h[49], 1363258195), new Y(h[50], 3750685593), new Y(h[51], 3785050280), new Y(h[52], 3318307427), new Y(h[53], 3812723403), new Y(h[54], 2003034995), new Y(h[55], 3602036899), new Y(h[56], 1575990012), new Y(h[57], 1125592928), new Y(h[58], 2716904306), new Y(h[59], 442776044), new Y(h[60], 593698344), new Y(h[61], 3733110249), new Y(h[62], 2999351573), new Y(h[63], 3815920427), new Y(3391569614, 3928383900), new Y(3515267271, 566280711), new Y(3940187606, 3454069534), new Y(4118630271, 4000239992), new Y(116418474, 1914138554), new Y(174292421, 2731055270), new Y(289380356, 3203993006), new Y(460393269, 320620315), new Y(685471733, 587496836), new Y(852142971, 1086792851), new Y(1017036298, 365543100), new Y(1126000580, 2618297676), new Y(1288033470, 3409855158), new Y(1501505948, 4234509866), new Y(1607167915, 987167468), new Y(1816402316, 1246189591)];
13766
+ function G(t) {
13767
+ return "SHA-384" === t ? [new Y(3418070365, u[0]), new Y(1654270250, u[1]), new Y(2438529370, u[2]), new Y(355462360, u[3]), new Y(1731405415, u[4]), new Y(41048885895, u[5]), new Y(3675008525, u[6]), new Y(1203062813, u[7])] : [new Y(w[0], 4089235720), new Y(w[1], 2227873595), new Y(w[2], 4271175723), new Y(w[3], 1595750129), new Y(w[4], 2917565137), new Y(w[5], 725511199), new Y(w[6], 4215389547), new Y(w[7], 327033209)];
13768
+ }
13769
+ function J(t, n) {
13770
+ let e, r, i, s, o, h, u, w, c, f, a, l;
13771
+ const A = [];
13772
+ for (e = n[0], r = n[1], i = n[2], s = n[3], o = n[4], h = n[5], u = n[6], w = n[7], a = 0; a < 80; a += 1) a < 16 ? (l = 2 * a, A[a] = new Y(t[l], t[l + 1])) : A[a] = O(Z(A[a - 2]), A[a - 7], j(A[a - 15]), A[a - 16]), c = P(w, q(o), (H = h, S = u, new Y((E = o).N & H.N ^ ~E.N & S.N, E.I & H.I ^ ~E.I & S.I)), D[a], A[a]), f = _(x(e), z(e, r, i)), w = u, u = h, h = o, o = _(s, c), s = i, i = r, r = e, e = _(c, f);
13773
+ var E, H, S;
13774
+ return n[0] = _(e, n[0]), n[1] = _(r, n[1]), n[2] = _(i, n[2]), n[3] = _(s, n[3]), n[4] = _(o, n[4]), n[5] = _(h, n[5]), n[6] = _(u, n[6]), n[7] = _(w, n[7]), n;
13775
+ }
13776
+ let Q = class extends E {
13777
+ constructor(t, n, e) {
13778
+ if ("SHA-384" !== t && "SHA-512" !== t) throw new Error(c);
13779
+ super(t, n, e);
13780
+ const r = e || {};
13781
+ this.g = this.Y, this.M = !0, this.T = -1, this.C = i(this.t, this.i, this.T), this.v = J, this.L = function (t) {
13782
+ return t.slice();
13783
+ }, this.B = G, this.F = function (n, e, r, i) {
13784
+ return function (t, n, e, r, i) {
13785
+ let s, h;
13786
+ const u = 31 + (n + 129 >>> 10 << 5),
13787
+ w = n + e;
13788
+ for (; t.length <= u;) t.push(0);
13789
+ for (t[n >>> 5] |= 128 << 24 - n % 32, t[u] = 4294967295 & w, t[u - 1] = w / o | 0, s = 0; s < t.length; s += 32) r = J(t.slice(s, s + 32), r);
13790
+ return h = "SHA-384" === i ? [r[0].N, r[0].I, r[1].N, r[1].I, r[2].N, r[2].I, r[3].N, r[3].I, r[4].N, r[4].I, r[5].N, r[5].I] : [r[0].N, r[0].I, r[1].N, r[1].I, r[2].N, r[2].I, r[3].N, r[3].I, r[4].N, r[4].I, r[5].N, r[5].I, r[6].N, r[6].I, r[7].N, r[7].I], h;
13791
+ }(n, e, r, i, t);
13792
+ }, this.U = G(t), this.m = 1024, this.R = "SHA-384" === t ? 384 : 512, this.K = !1, r.hmacKey && this.k(A("hmacKey", r.hmacKey, this.T));
13793
+ }
13794
+ };
13795
+ const W = [new Y(0, 1), new Y(0, 32898), new Y(2147483648, 32906), new Y(2147483648, 2147516416), new Y(0, 32907), new Y(0, 2147483649), new Y(2147483648, 2147516545), new Y(2147483648, 32777), new Y(0, 138), new Y(0, 136), new Y(0, 2147516425), new Y(0, 2147483658), new Y(0, 2147516555), new Y(2147483648, 139), new Y(2147483648, 32905), new Y(2147483648, 32771), new Y(2147483648, 32770), new Y(2147483648, 128), new Y(0, 32778), new Y(2147483648, 2147483658), new Y(2147483648, 2147516545), new Y(2147483648, 32896), new Y(0, 2147483649), new Y(2147483648, 2147516424)],
13796
+ $ = [[0, 36, 3, 41, 18], [1, 44, 10, 45, 2], [62, 6, 43, 15, 61], [28, 55, 25, 21, 56], [27, 20, 39, 8, 14]];
13797
+ function tt(t) {
13798
+ let n;
13799
+ const e = [];
13800
+ for (n = 0; n < 5; n += 1) e[n] = [new Y(0, 0), new Y(0, 0), new Y(0, 0), new Y(0, 0), new Y(0, 0)];
13801
+ return e;
13802
+ }
13803
+ function nt(t) {
13804
+ let n;
13805
+ const e = [];
13806
+ for (n = 0; n < 5; n += 1) e[n] = t[n].slice();
13807
+ return e;
13808
+ }
13809
+ function et(t, n) {
13810
+ let e, r, i, s;
13811
+ const o = [],
13812
+ h = [];
13813
+ if (null !== t) for (r = 0; r < t.length; r += 2) n[(r >>> 1) % 5][(r >>> 1) / 5 | 0] = V(n[(r >>> 1) % 5][(r >>> 1) / 5 | 0], new Y(t[r + 1], t[r]));
13814
+ for (e = 0; e < 24; e += 1) {
13815
+ for (s = tt(), r = 0; r < 5; r += 1) o[r] = (u = n[r][0], w = n[r][1], c = n[r][2], f = n[r][3], a = n[r][4], new Y(u.N ^ w.N ^ c.N ^ f.N ^ a.N, u.I ^ w.I ^ c.I ^ f.I ^ a.I));
13816
+ for (r = 0; r < 5; r += 1) h[r] = V(o[(r + 4) % 5], N(o[(r + 1) % 5], 1));
13817
+ for (r = 0; r < 5; r += 1) for (i = 0; i < 5; i += 1) n[r][i] = V(n[r][i], h[r]);
13818
+ for (r = 0; r < 5; r += 1) for (i = 0; i < 5; i += 1) s[i][(2 * r + 3 * i) % 5] = N(n[r][i], $[r][i]);
13819
+ for (r = 0; r < 5; r += 1) for (i = 0; i < 5; i += 1) n[r][i] = V(s[r][i], new Y(~s[(r + 1) % 5][i].N & s[(r + 2) % 5][i].N, ~s[(r + 1) % 5][i].I & s[(r + 2) % 5][i].I));
13820
+ n[0][0] = V(n[0][0], W[e]);
13821
+ }
13822
+ var u, w, c, f, a;
13823
+ return n;
13824
+ }
13825
+ function rt(t) {
13826
+ let n,
13827
+ e,
13828
+ r = 0;
13829
+ const i = [0, 0],
13830
+ s = [4294967295 & t, t / o & 2097151];
13831
+ for (n = 6; n >= 0; n--) e = s[n >> 2] >>> 8 * n & 255, 0 === e && 0 === r || (i[r + 1 >> 2] |= e << 8 * (r + 1), r += 1);
13832
+ return r = 0 !== r ? r : 1, i[0] |= r, {
13833
+ value: r + 1 > 4 ? i : [i[0]],
13834
+ binLen: 8 + 8 * r
13835
+ };
13836
+ }
13837
+ function it(t) {
13838
+ return a(rt(t.binLen), t);
13839
+ }
13840
+ function st(t, n) {
13841
+ let e,
13842
+ r = rt(n);
13843
+ r = a(r, t);
13844
+ const i = n >>> 2,
13845
+ s = (i - r.value.length % i) % i;
13846
+ for (e = 0; e < s; e++) r.value.push(0);
13847
+ return r.value;
13848
+ }
13849
+ let ot = class extends E {
13850
+ constructor(t, n, e) {
13851
+ let r = 6,
13852
+ s = 0;
13853
+ super(t, n, e);
13854
+ const o = e || {};
13855
+ if (1 !== this.numRounds) {
13856
+ if (o.kmacKey || o.hmacKey) throw new Error(f);
13857
+ if ("CSHAKE128" === this.o || "CSHAKE256" === this.o) throw new Error("Cannot set numRounds for CSHAKE variants");
13858
+ }
13859
+ switch (this.T = 1, this.C = i(this.t, this.i, this.T), this.v = et, this.L = nt, this.B = tt, this.U = tt(), this.K = !1, t) {
13860
+ case "SHA3-224":
13861
+ this.m = s = 1152, this.R = 224, this.M = !0, this.g = this.Y;
13862
+ break;
13863
+ case "SHA3-256":
13864
+ this.m = s = 1088, this.R = 256, this.M = !0, this.g = this.Y;
13865
+ break;
13866
+ case "SHA3-384":
13867
+ this.m = s = 832, this.R = 384, this.M = !0, this.g = this.Y;
13868
+ break;
13869
+ case "SHA3-512":
13870
+ this.m = s = 576, this.R = 512, this.M = !0, this.g = this.Y;
13871
+ break;
13872
+ case "SHAKE128":
13873
+ r = 31, this.m = s = 1344, this.R = -1, this.K = !0, this.M = !1, this.g = null;
13874
+ break;
13875
+ case "SHAKE256":
13876
+ r = 31, this.m = s = 1088, this.R = -1, this.K = !0, this.M = !1, this.g = null;
13877
+ break;
13878
+ case "KMAC128":
13879
+ r = 4, this.m = s = 1344, this.X(e), this.R = -1, this.K = !0, this.M = !1, this.g = this._;
13880
+ break;
13881
+ case "KMAC256":
13882
+ r = 4, this.m = s = 1088, this.X(e), this.R = -1, this.K = !0, this.M = !1, this.g = this._;
13883
+ break;
13884
+ case "CSHAKE128":
13885
+ this.m = s = 1344, r = this.O(e), this.R = -1, this.K = !0, this.M = !1, this.g = null;
13886
+ break;
13887
+ case "CSHAKE256":
13888
+ this.m = s = 1088, r = this.O(e), this.R = -1, this.K = !0, this.M = !1, this.g = null;
13889
+ break;
13890
+ default:
13891
+ throw new Error(c);
13892
+ }
13893
+ this.F = function (t, n, e, i, o) {
13894
+ return function (t, n, e, r, i, s, o) {
13895
+ let h,
13896
+ u,
13897
+ w = 0;
13898
+ const c = [],
13899
+ f = i >>> 5,
13900
+ a = n >>> 5;
13901
+ for (h = 0; h < a && n >= i; h += f) r = et(t.slice(h, h + f), r), n -= i;
13902
+ for (t = t.slice(h), n %= i; t.length < f;) t.push(0);
13903
+ for (h = n >>> 3, t[h >> 2] ^= s << h % 4 * 8, t[f - 1] ^= 2147483648, r = et(t, r); 32 * c.length < o && (u = r[w % 5][w / 5 | 0], c.push(u.I), !(32 * c.length >= o));) c.push(u.N), w += 1, 0 == 64 * w % i && (et(null, r), w = 0);
13904
+ return c;
13905
+ }(t, n, 0, i, s, r, o);
13906
+ }, o.hmacKey && this.k(A("hmacKey", o.hmacKey, this.T));
13907
+ }
13908
+ O(t, n) {
13909
+ const e = function (t) {
13910
+ const n = t || {};
13911
+ return {
13912
+ funcName: A("funcName", n.funcName, 1, {
13913
+ value: [],
13914
+ binLen: 0
13915
+ }),
13916
+ customization: A("Customization", n.customization, 1, {
13917
+ value: [],
13918
+ binLen: 0
13919
+ })
13920
+ };
13921
+ }(t || {});
13922
+ n && (e.funcName = n);
13923
+ const r = a(it(e.funcName), it(e.customization));
13924
+ if (0 !== e.customization.binLen || 0 !== e.funcName.binLen) {
13925
+ const t = st(r, this.m >>> 3);
13926
+ for (let n = 0; n < t.length; n += this.m >>> 5) this.U = this.v(t.slice(n, n + (this.m >>> 5)), this.U), this.A += this.m;
13927
+ return 4;
13928
+ }
13929
+ return 31;
13930
+ }
13931
+ X(t) {
13932
+ const n = function (t) {
13933
+ const n = t || {};
13934
+ return {
13935
+ kmacKey: A("kmacKey", n.kmacKey, 1),
13936
+ funcName: {
13937
+ value: [1128353099],
13938
+ binLen: 32
13939
+ },
13940
+ customization: A("Customization", n.customization, 1, {
13941
+ value: [],
13942
+ binLen: 0
13943
+ })
13944
+ };
13945
+ }(t || {});
13946
+ this.O(t, n.funcName);
13947
+ const e = st(it(n.kmacKey), this.m >>> 3);
13948
+ for (let t = 0; t < e.length; t += this.m >>> 5) this.U = this.v(e.slice(t, t + (this.m >>> 5)), this.U), this.A += this.m;
13949
+ this.H = !0;
13950
+ }
13951
+ _(t) {
13952
+ const n = a({
13953
+ value: this.h.slice(),
13954
+ binLen: this.u
13955
+ }, function (t) {
13956
+ let n,
13957
+ e,
13958
+ r = 0;
13959
+ const i = [0, 0],
13960
+ s = [4294967295 & t, t / o & 2097151];
13961
+ for (n = 6; n >= 0; n--) e = s[n >> 2] >>> 8 * n & 255, 0 === e && 0 === r || (i[r >> 2] |= e << 8 * r, r += 1);
13962
+ return r = 0 !== r ? r : 1, i[r >> 2] |= r << 8 * r, {
13963
+ value: r + 1 > 4 ? i : [i[0]],
13964
+ binLen: 8 + 8 * r
13965
+ };
13966
+ }(t.outputLen));
13967
+ return this.F(n.value, n.binLen, this.A, this.L(this.U), t.outputLen);
13968
+ }
13969
+ };
13970
+ class ht {
13971
+ constructor(t, n, e) {
13972
+ if ("SHA-1" == t) this.P = new L(t, n, e);else if ("SHA-224" == t || "SHA-256" == t) this.P = new k(t, n, e);else if ("SHA-384" == t || "SHA-512" == t) this.P = new Q(t, n, e);else {
13973
+ if ("SHA3-224" != t && "SHA3-256" != t && "SHA3-384" != t && "SHA3-512" != t && "SHAKE128" != t && "SHAKE256" != t && "CSHAKE128" != t && "CSHAKE256" != t && "KMAC128" != t && "KMAC256" != t) throw new Error(c);
13974
+ this.P = new ot(t, n, e);
13975
+ }
13976
+ }
13977
+ update(t) {
13978
+ return this.P.update(t), this;
13979
+ }
13980
+ getHash(t, n) {
13981
+ return this.P.getHash(t, n);
13982
+ }
13983
+ setHMACKey(t, n, e) {
13984
+ this.P.setHMACKey(t, n, e);
13985
+ }
13986
+ getHMAC(t, n) {
13987
+ return this.P.getHMAC(t, n);
13988
+ }
13989
+ }
13990
+
13991
+ /**
13992
+ * "globalThis" ponyfill.
13993
+ * @see [A horrifying globalThis polyfill in universal JavaScript](https://mathiasbynens.be/notes/globalthis)
13994
+ * @type {Object.<string, *>}
13995
+ */
13996
+ const globalScope = (() => {
13997
+ if (typeof globalThis === "object") return globalThis;else {
13998
+ Object.defineProperty(Object.prototype, "__GLOBALTHIS__", {
13999
+ get() {
14000
+ return this;
14001
+ },
14002
+ configurable: true
14003
+ });
14004
+ try {
14005
+ // @ts-ignore
14006
+ // eslint-disable-next-line no-undef
14007
+ if (typeof __GLOBALTHIS__ !== "undefined") return __GLOBALTHIS__;
14008
+ } finally {
14009
+ // @ts-ignore
14010
+ delete Object.prototype.__GLOBALTHIS__;
14011
+ }
14012
+ }
14013
+
14014
+ // Still unable to determine "globalThis", fall back to a naive method.
14015
+ if (typeof self !== "undefined") return self;else if (typeof window !== "undefined") return window;else if (typeof global !== "undefined") return global;
14016
+ return undefined;
14017
+ })();
14018
+
14019
+ /**
14020
+ * OpenSSL to jsSHA algorithms map.
14021
+ * @type {Object.<string, "SHA-1"|"SHA-224"|"SHA-256"|"SHA-384"|"SHA-512"|"SHA3-224"|"SHA3-256"|"SHA3-384"|"SHA3-512">}
14022
+ */
14023
+ const OPENSSL_JSSHA_ALGO_MAP = {
14024
+ SHA1: "SHA-1",
14025
+ SHA224: "SHA-224",
14026
+ SHA256: "SHA-256",
14027
+ SHA384: "SHA-384",
14028
+ SHA512: "SHA-512",
14029
+ "SHA3-224": "SHA3-224",
14030
+ "SHA3-256": "SHA3-256",
14031
+ "SHA3-384": "SHA3-384",
14032
+ "SHA3-512": "SHA3-512"
14033
+ };
14034
+
14035
+ /**
14036
+ * Calculates an HMAC digest.
14037
+ * In Node.js, the command "openssl list -digest-algorithms" displays the available digest algorithms.
14038
+ * @param {string} algorithm Algorithm.
14039
+ * @param {ArrayBuffer} key Key.
14040
+ * @param {ArrayBuffer} message Message.
14041
+ * @returns {ArrayBuffer} Digest.
14042
+ */
14043
+ const hmacDigest = (algorithm, key, message) => {
14044
+ {
14045
+ const variant = OPENSSL_JSSHA_ALGO_MAP[algorithm.toUpperCase()];
14046
+ if (typeof variant === "undefined") {
14047
+ throw new TypeError("Unknown hash function");
14048
+ }
14049
+ const hmac = new ht(variant, "ARRAYBUFFER");
14050
+ hmac.setHMACKey(key, "ARRAYBUFFER");
14051
+ hmac.update(message);
14052
+ return hmac.getHMAC("ARRAYBUFFER");
14053
+ }
14054
+ };
14055
+
14056
+ /**
14057
+ * RFC 4648 base32 alphabet without pad.
14058
+ * @type {string}
14059
+ */
14060
+ const ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567";
14061
+
14062
+ /**
14063
+ * Converts a base32 string to an ArrayBuffer (RFC 4648).
14064
+ * @see [LinusU/base32-decode](https://github.com/LinusU/base32-decode)
14065
+ * @param {string} str Base32 string.
14066
+ * @returns {ArrayBuffer} ArrayBuffer.
14067
+ */
14068
+ const base32ToBuf = str => {
14069
+ // Canonicalize to all upper case and remove padding if it exists.
14070
+ let end = str.length;
14071
+ while (str[end - 1] === "=") --end;
14072
+ const cstr = (end < str.length ? str.substring(0, end) : str).toUpperCase();
14073
+ const buf = new ArrayBuffer(cstr.length * 5 / 8 | 0);
14074
+ const arr = new Uint8Array(buf);
14075
+ let bits = 0;
14076
+ let value = 0;
14077
+ let index = 0;
14078
+ for (let i = 0; i < cstr.length; i++) {
14079
+ const idx = ALPHABET.indexOf(cstr[i]);
14080
+ if (idx === -1) throw new TypeError(`Invalid character found: ${cstr[i]}`);
14081
+ value = value << 5 | idx;
14082
+ bits += 5;
14083
+ if (bits >= 8) {
14084
+ bits -= 8;
14085
+ arr[index++] = value >>> bits;
14086
+ }
14087
+ }
14088
+ return buf;
14089
+ };
14090
+
14091
+ /**
14092
+ * Converts an ArrayBuffer to a base32 string (RFC 4648).
14093
+ * @see [LinusU/base32-encode](https://github.com/LinusU/base32-encode)
14094
+ * @param {ArrayBuffer} buf ArrayBuffer.
14095
+ * @returns {string} Base32 string.
14096
+ */
14097
+ const base32FromBuf = buf => {
14098
+ const arr = new Uint8Array(buf);
14099
+ let bits = 0;
14100
+ let value = 0;
14101
+ let str = "";
14102
+ for (let i = 0; i < arr.length; i++) {
14103
+ value = value << 8 | arr[i];
14104
+ bits += 8;
14105
+ while (bits >= 5) {
14106
+ str += ALPHABET[value >>> bits - 5 & 31];
14107
+ bits -= 5;
14108
+ }
14109
+ }
14110
+ if (bits > 0) {
14111
+ str += ALPHABET[value << 5 - bits & 31];
14112
+ }
14113
+ return str;
14114
+ };
14115
+
14116
+ /**
14117
+ * Converts a hexadecimal string to an ArrayBuffer.
14118
+ * @param {string} str Hexadecimal string.
14119
+ * @returns {ArrayBuffer} ArrayBuffer.
14120
+ */
14121
+ const hexToBuf = str => {
14122
+ const buf = new ArrayBuffer(str.length / 2);
14123
+ const arr = new Uint8Array(buf);
14124
+ for (let i = 0; i < str.length; i += 2) {
14125
+ arr[i / 2] = parseInt(str.substring(i, i + 2), 16);
14126
+ }
14127
+ return buf;
14128
+ };
14129
+
14130
+ /**
14131
+ * Converts an ArrayBuffer to a hexadecimal string.
14132
+ * @param {ArrayBuffer} buf ArrayBuffer.
14133
+ * @returns {string} Hexadecimal string.
14134
+ */
14135
+ const hexFromBuf = buf => {
14136
+ const arr = new Uint8Array(buf);
14137
+ let str = "";
14138
+ for (let i = 0; i < arr.length; i++) {
14139
+ const hex = arr[i].toString(16);
14140
+ if (hex.length === 1) str += "0";
14141
+ str += hex;
14142
+ }
14143
+ return str.toUpperCase();
14144
+ };
14145
+
14146
+ /**
14147
+ * Converts a Latin-1 string to an ArrayBuffer.
14148
+ * @param {string} str Latin-1 string.
14149
+ * @returns {ArrayBuffer} ArrayBuffer.
14150
+ */
14151
+ const latin1ToBuf = str => {
14152
+ const buf = new ArrayBuffer(str.length);
14153
+ const arr = new Uint8Array(buf);
14154
+ for (let i = 0; i < str.length; i++) {
14155
+ arr[i] = str.charCodeAt(i) & 0xff;
14156
+ }
14157
+ return buf;
14158
+ };
14159
+
14160
+ /**
14161
+ * Converts an ArrayBuffer to a Latin-1 string.
14162
+ * @param {ArrayBuffer} buf ArrayBuffer.
14163
+ * @returns {string} Latin-1 string.
14164
+ */
14165
+ const latin1FromBuf = buf => {
14166
+ const arr = new Uint8Array(buf);
14167
+ let str = "";
14168
+ for (let i = 0; i < arr.length; i++) {
14169
+ str += String.fromCharCode(arr[i]);
14170
+ }
14171
+ return str;
14172
+ };
14173
+
14174
+ /**
14175
+ * TextEncoder instance.
14176
+ * @type {TextEncoder|null}
14177
+ */
14178
+ const ENCODER = globalScope.TextEncoder ? new globalScope.TextEncoder("utf-8") : null;
14179
+
14180
+ /**
14181
+ * TextDecoder instance.
14182
+ * @type {TextDecoder|null}
14183
+ */
14184
+ const DECODER = globalScope.TextDecoder ? new globalScope.TextDecoder("utf-8") : null;
14185
+
14186
+ /**
14187
+ * Converts an UTF-8 string to an ArrayBuffer.
14188
+ * @param {string} str String.
14189
+ * @returns {ArrayBuffer} ArrayBuffer.
14190
+ */
14191
+ const utf8ToBuf = str => {
14192
+ if (!ENCODER) {
14193
+ throw new Error("Encoding API not available");
14194
+ }
14195
+ return ENCODER.encode(str).buffer;
14196
+ };
14197
+
14198
+ /**
14199
+ * Converts an ArrayBuffer to an UTF-8 string.
14200
+ * @param {ArrayBuffer} buf ArrayBuffer.
14201
+ * @returns {string} String.
14202
+ */
14203
+ const utf8FromBuf = buf => {
14204
+ if (!DECODER) {
14205
+ throw new Error("Encoding API not available");
14206
+ }
14207
+ return DECODER.decode(buf);
14208
+ };
14209
+
14210
+ /**
14211
+ * Returns random bytes.
14212
+ * @param {number} size Size.
14213
+ * @returns {ArrayBuffer} Random bytes.
14214
+ */
14215
+ const randomBytes = size => {
14216
+ {
14217
+ if (!globalScope.crypto?.getRandomValues) {
14218
+ throw new Error("Cryptography API not available");
14219
+ }
14220
+ return globalScope.crypto.getRandomValues(new Uint8Array(size)).buffer;
14221
+ }
14222
+ };
14223
+
14224
+ /**
14225
+ * OTP secret key.
14226
+ */
14227
+ class Secret {
14228
+ /**
14229
+ * Creates a secret key object.
14230
+ * @param {Object} [config] Configuration options.
14231
+ * @param {ArrayBuffer} [config.buffer=randomBytes] Secret key.
14232
+ * @param {number} [config.size=20] Number of random bytes to generate, ignored if 'buffer' is provided.
14233
+ */
14234
+ constructor({
14235
+ buffer,
14236
+ size = 20
14237
+ } = {}) {
14238
+ /**
14239
+ * Secret key.
14240
+ * @type {ArrayBuffer}
14241
+ */
14242
+ this.buffer = typeof buffer === "undefined" ? randomBytes(size) : buffer;
14243
+ }
14244
+
14245
+ /**
14246
+ * Converts a Latin-1 string to a Secret object.
14247
+ * @param {string} str Latin-1 string.
14248
+ * @returns {Secret} Secret object.
14249
+ */
14250
+ static fromLatin1(str) {
14251
+ return new Secret({
14252
+ buffer: latin1ToBuf(str)
14253
+ });
14254
+ }
14255
+
14256
+ /**
14257
+ * Converts an UTF-8 string to a Secret object.
14258
+ * @param {string} str UTF-8 string.
14259
+ * @returns {Secret} Secret object.
14260
+ */
14261
+ static fromUTF8(str) {
14262
+ return new Secret({
14263
+ buffer: utf8ToBuf(str)
14264
+ });
14265
+ }
14266
+
14267
+ /**
14268
+ * Converts a base32 string to a Secret object.
14269
+ * @param {string} str Base32 string.
14270
+ * @returns {Secret} Secret object.
14271
+ */
14272
+ static fromBase32(str) {
14273
+ return new Secret({
14274
+ buffer: base32ToBuf(str)
14275
+ });
14276
+ }
14277
+
14278
+ /**
14279
+ * Converts a hexadecimal string to a Secret object.
14280
+ * @param {string} str Hexadecimal string.
14281
+ * @returns {Secret} Secret object.
14282
+ */
14283
+ static fromHex(str) {
14284
+ return new Secret({
14285
+ buffer: hexToBuf(str)
14286
+ });
14287
+ }
14288
+
14289
+ /**
14290
+ * Latin-1 string representation of secret key.
14291
+ * @type {string}
14292
+ */
14293
+ get latin1() {
14294
+ Object.defineProperty(this, "latin1", {
14295
+ enumerable: true,
14296
+ value: latin1FromBuf(this.buffer)
14297
+ });
14298
+ return this.latin1;
14299
+ }
14300
+
14301
+ /**
14302
+ * UTF-8 string representation of secret key.
14303
+ * @type {string}
14304
+ */
14305
+ get utf8() {
14306
+ Object.defineProperty(this, "utf8", {
14307
+ enumerable: true,
14308
+ value: utf8FromBuf(this.buffer)
14309
+ });
14310
+ return this.utf8;
14311
+ }
14312
+
14313
+ /**
14314
+ * Base32 string representation of secret key.
14315
+ * @type {string}
14316
+ */
14317
+ get base32() {
14318
+ Object.defineProperty(this, "base32", {
14319
+ enumerable: true,
14320
+ value: base32FromBuf(this.buffer)
14321
+ });
14322
+ return this.base32;
14323
+ }
14324
+
14325
+ /**
14326
+ * Hexadecimal string representation of secret key.
14327
+ * @type {string}
14328
+ */
14329
+ get hex() {
14330
+ Object.defineProperty(this, "hex", {
14331
+ enumerable: true,
14332
+ value: hexFromBuf(this.buffer)
14333
+ });
14334
+ return this.hex;
14335
+ }
14336
+ }
14337
+
14338
+ /**
14339
+ * Returns true if a is equal to b, without leaking timing information that would allow an attacker to guess one of the values.
14340
+ * @param {string} a String a.
14341
+ * @param {string} b String b.
14342
+ * @returns {boolean} Equality result.
14343
+ */
14344
+ const timingSafeEqual = (a, b) => {
14345
+ {
14346
+ if (a.length !== b.length) {
14347
+ throw new TypeError("Input strings must have the same length");
14348
+ }
14349
+ let i = -1;
14350
+ let out = 0;
14351
+ while (++i < a.length) {
14352
+ out |= a.charCodeAt(i) ^ b.charCodeAt(i);
14353
+ }
14354
+ return out === 0;
14355
+ }
14356
+ };
14357
+
14358
+ /**
14359
+ * HOTP: An HMAC-based One-time Password Algorithm.
14360
+ * @see [RFC 4226](https://tools.ietf.org/html/rfc4226)
14361
+ */
14362
+ class HOTP {
14363
+ /**
14364
+ * Default configuration.
14365
+ * @type {{
14366
+ * issuer: string,
14367
+ * label: string,
14368
+ * issuerInLabel: boolean,
14369
+ * algorithm: string,
14370
+ * digits: number,
14371
+ * counter: number
14372
+ * window: number
14373
+ * }}
14374
+ */
14375
+ static get defaults() {
14376
+ return {
14377
+ issuer: "",
14378
+ label: "OTPAuth",
14379
+ issuerInLabel: true,
14380
+ algorithm: "SHA1",
14381
+ digits: 6,
14382
+ counter: 0,
14383
+ window: 1
14384
+ };
14385
+ }
14386
+
14387
+ /**
14388
+ * Creates an HOTP object.
14389
+ * @param {Object} [config] Configuration options.
14390
+ * @param {string} [config.issuer=''] Account provider.
14391
+ * @param {string} [config.label='OTPAuth'] Account label.
14392
+ * @param {boolean} [config.issuerInLabel=true] Include issuer prefix in label.
14393
+ * @param {Secret|string} [config.secret=Secret] Secret key.
14394
+ * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
14395
+ * @param {number} [config.digits=6] Token length.
14396
+ * @param {number} [config.counter=0] Initial counter value.
14397
+ */
14398
+ constructor({
14399
+ issuer = HOTP.defaults.issuer,
14400
+ label = HOTP.defaults.label,
14401
+ issuerInLabel = HOTP.defaults.issuerInLabel,
14402
+ secret = new Secret(),
14403
+ algorithm = HOTP.defaults.algorithm,
14404
+ digits = HOTP.defaults.digits,
14405
+ counter = HOTP.defaults.counter
14406
+ } = {}) {
14407
+ /**
14408
+ * Account provider.
14409
+ * @type {string}
14410
+ */
14411
+ this.issuer = issuer;
14412
+ /**
14413
+ * Account label.
14414
+ * @type {string}
14415
+ */
14416
+ this.label = label;
14417
+ /**
14418
+ * Include issuer prefix in label.
14419
+ * @type {boolean}
14420
+ */
14421
+ this.issuerInLabel = issuerInLabel;
14422
+ /**
14423
+ * Secret key.
14424
+ * @type {Secret}
14425
+ */
14426
+ this.secret = typeof secret === "string" ? Secret.fromBase32(secret) : secret;
14427
+ /**
14428
+ * HMAC hashing algorithm.
14429
+ * @type {string}
14430
+ */
14431
+ this.algorithm = algorithm.toUpperCase();
14432
+ /**
14433
+ * Token length.
14434
+ * @type {number}
14435
+ */
14436
+ this.digits = digits;
14437
+ /**
14438
+ * Initial counter value.
14439
+ * @type {number}
14440
+ */
14441
+ this.counter = counter;
14442
+ }
14443
+
14444
+ /**
14445
+ * Generates an HOTP token.
14446
+ * @param {Object} config Configuration options.
14447
+ * @param {Secret} config.secret Secret key.
14448
+ * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
14449
+ * @param {number} [config.digits=6] Token length.
14450
+ * @param {number} [config.counter=0] Counter value.
14451
+ * @returns {string} Token.
14452
+ */
14453
+ static generate({
14454
+ secret,
14455
+ algorithm = HOTP.defaults.algorithm,
14456
+ digits = HOTP.defaults.digits,
14457
+ counter = HOTP.defaults.counter
14458
+ }) {
14459
+ const digest = new Uint8Array(hmacDigest(algorithm, secret.buffer, uintToBuf(counter)));
14460
+ const offset = digest[digest.byteLength - 1] & 15;
14461
+ const otp = ((digest[offset] & 127) << 24 | (digest[offset + 1] & 255) << 16 | (digest[offset + 2] & 255) << 8 | digest[offset + 3] & 255) % 10 ** digits;
14462
+ return otp.toString().padStart(digits, "0");
14463
+ }
14464
+
14465
+ /**
14466
+ * Generates an HOTP token.
14467
+ * @param {Object} [config] Configuration options.
14468
+ * @param {number} [config.counter=this.counter++] Counter value.
14469
+ * @returns {string} Token.
14470
+ */
14471
+ generate({
14472
+ counter = this.counter++
14473
+ } = {}) {
14474
+ return HOTP.generate({
14475
+ secret: this.secret,
14476
+ algorithm: this.algorithm,
14477
+ digits: this.digits,
14478
+ counter
14479
+ });
14480
+ }
14481
+
14482
+ /**
14483
+ * Validates an HOTP token.
14484
+ * @param {Object} config Configuration options.
14485
+ * @param {string} config.token Token value.
14486
+ * @param {Secret} config.secret Secret key.
14487
+ * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
14488
+ * @param {number} config.digits Token length.
14489
+ * @param {number} [config.counter=0] Counter value.
14490
+ * @param {number} [config.window=1] Window of counter values to test.
14491
+ * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
14492
+ */
14493
+ static validate({
14494
+ token,
14495
+ secret,
14496
+ algorithm,
14497
+ digits,
14498
+ counter = HOTP.defaults.counter,
14499
+ window = HOTP.defaults.window
14500
+ }) {
14501
+ // Return early if the token length does not match the digit number.
14502
+ if (token.length !== digits) return null;
14503
+ let delta = null;
14504
+ for (let i = counter - window; i <= counter + window; ++i) {
14505
+ const generatedToken = HOTP.generate({
14506
+ secret,
14507
+ algorithm,
14508
+ digits,
14509
+ counter: i
14510
+ });
14511
+ if (timingSafeEqual(token, generatedToken)) {
14512
+ delta = i - counter;
14513
+ }
14514
+ }
14515
+ return delta;
14516
+ }
14517
+
14518
+ /**
14519
+ * Validates an HOTP token.
14520
+ * @param {Object} config Configuration options.
14521
+ * @param {string} config.token Token value.
14522
+ * @param {number} [config.counter=this.counter] Counter value.
14523
+ * @param {number} [config.window=1] Window of counter values to test.
14524
+ * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
14525
+ */
14526
+ validate({
14527
+ token,
14528
+ counter = this.counter,
14529
+ window
14530
+ }) {
14531
+ return HOTP.validate({
14532
+ token,
14533
+ secret: this.secret,
14534
+ algorithm: this.algorithm,
14535
+ digits: this.digits,
14536
+ counter,
14537
+ window
14538
+ });
14539
+ }
14540
+
14541
+ /**
14542
+ * Returns a Google Authenticator key URI.
14543
+ * @returns {string} URI.
14544
+ */
14545
+ toString() {
14546
+ const e = encodeURIComponent;
14547
+ return "otpauth://hotp/" + `${this.issuer.length > 0 ? this.issuerInLabel ? `${e(this.issuer)}:${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?`}` + `secret=${e(this.secret.base32)}&` + `algorithm=${e(this.algorithm)}&` + `digits=${e(this.digits)}&` + `counter=${e(this.counter)}`;
14548
+ }
14549
+ }
14550
+
14551
+ /**
14552
+ * TOTP: Time-Based One-Time Password Algorithm.
14553
+ * @see [RFC 6238](https://tools.ietf.org/html/rfc6238)
14554
+ */
14555
+ class TOTP {
14556
+ /**
14557
+ * Default configuration.
14558
+ * @type {{
14559
+ * issuer: string,
14560
+ * label: string,
14561
+ * issuerInLabel: boolean,
14562
+ * algorithm: string,
14563
+ * digits: number,
14564
+ * period: number
14565
+ * window: number
14566
+ * }}
14567
+ */
14568
+ static get defaults() {
14569
+ return {
14570
+ issuer: "",
14571
+ label: "OTPAuth",
14572
+ issuerInLabel: true,
14573
+ algorithm: "SHA1",
14574
+ digits: 6,
14575
+ period: 30,
14576
+ window: 1
14577
+ };
14578
+ }
14579
+
14580
+ /**
14581
+ * Creates a TOTP object.
14582
+ * @param {Object} [config] Configuration options.
14583
+ * @param {string} [config.issuer=''] Account provider.
14584
+ * @param {string} [config.label='OTPAuth'] Account label.
14585
+ * @param {boolean} [config.issuerInLabel=true] Include issuer prefix in label.
14586
+ * @param {Secret|string} [config.secret=Secret] Secret key.
14587
+ * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
14588
+ * @param {number} [config.digits=6] Token length.
14589
+ * @param {number} [config.period=30] Token time-step duration.
14590
+ */
14591
+ constructor({
14592
+ issuer = TOTP.defaults.issuer,
14593
+ label = TOTP.defaults.label,
14594
+ issuerInLabel = TOTP.defaults.issuerInLabel,
14595
+ secret = new Secret(),
14596
+ algorithm = TOTP.defaults.algorithm,
14597
+ digits = TOTP.defaults.digits,
14598
+ period = TOTP.defaults.period
14599
+ } = {}) {
14600
+ /**
14601
+ * Account provider.
14602
+ * @type {string}
14603
+ */
14604
+ this.issuer = issuer;
14605
+ /**
14606
+ * Account label.
14607
+ * @type {string}
14608
+ */
14609
+ this.label = label;
14610
+ /**
14611
+ * Include issuer prefix in label.
14612
+ * @type {boolean}
14613
+ */
14614
+ this.issuerInLabel = issuerInLabel;
14615
+ /**
14616
+ * Secret key.
14617
+ * @type {Secret}
14618
+ */
14619
+ this.secret = typeof secret === "string" ? Secret.fromBase32(secret) : secret;
14620
+ /**
14621
+ * HMAC hashing algorithm.
14622
+ * @type {string}
14623
+ */
14624
+ this.algorithm = algorithm.toUpperCase();
14625
+ /**
14626
+ * Token length.
14627
+ * @type {number}
14628
+ */
14629
+ this.digits = digits;
14630
+ /**
14631
+ * Token time-step duration.
14632
+ * @type {number}
14633
+ */
14634
+ this.period = period;
14635
+ }
14636
+
14637
+ /**
14638
+ * Generates a TOTP token.
14639
+ * @param {Object} config Configuration options.
14640
+ * @param {Secret} config.secret Secret key.
14641
+ * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
14642
+ * @param {number} [config.digits=6] Token length.
14643
+ * @param {number} [config.period=30] Token time-step duration.
14644
+ * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
14645
+ * @returns {string} Token.
14646
+ */
14647
+ static generate({
14648
+ secret,
14649
+ algorithm,
14650
+ digits,
14651
+ period = TOTP.defaults.period,
14652
+ timestamp = Date.now()
14653
+ }) {
14654
+ return HOTP.generate({
14655
+ secret,
14656
+ algorithm,
14657
+ digits,
14658
+ counter: Math.floor(timestamp / 1000 / period)
14659
+ });
14660
+ }
14661
+
14662
+ /**
14663
+ * Generates a TOTP token.
14664
+ * @param {Object} [config] Configuration options.
14665
+ * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
14666
+ * @returns {string} Token.
14667
+ */
14668
+ generate({
14669
+ timestamp = Date.now()
14670
+ } = {}) {
14671
+ return TOTP.generate({
14672
+ secret: this.secret,
14673
+ algorithm: this.algorithm,
14674
+ digits: this.digits,
14675
+ period: this.period,
14676
+ timestamp
14677
+ });
14678
+ }
14679
+
14680
+ /**
14681
+ * Validates a TOTP token.
14682
+ * @param {Object} config Configuration options.
14683
+ * @param {string} config.token Token value.
14684
+ * @param {Secret} config.secret Secret key.
14685
+ * @param {string} [config.algorithm='SHA1'] HMAC hashing algorithm.
14686
+ * @param {number} config.digits Token length.
14687
+ * @param {number} [config.period=30] Token time-step duration.
14688
+ * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
14689
+ * @param {number} [config.window=1] Window of counter values to test.
14690
+ * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
14691
+ */
14692
+ static validate({
14693
+ token,
14694
+ secret,
14695
+ algorithm,
14696
+ digits,
14697
+ period = TOTP.defaults.period,
14698
+ timestamp = Date.now(),
14699
+ window
14700
+ }) {
14701
+ return HOTP.validate({
14702
+ token,
14703
+ secret,
14704
+ algorithm,
14705
+ digits,
14706
+ counter: Math.floor(timestamp / 1000 / period),
14707
+ window
14708
+ });
14709
+ }
14710
+
14711
+ /**
14712
+ * Validates a TOTP token.
14713
+ * @param {Object} config Configuration options.
14714
+ * @param {string} config.token Token value.
14715
+ * @param {number} [config.timestamp=Date.now] Timestamp value in milliseconds.
14716
+ * @param {number} [config.window=1] Window of counter values to test.
14717
+ * @returns {number|null} Token delta or null if it is not found in the search window, in which case it should be considered invalid.
14718
+ */
14719
+ validate({
14720
+ token,
14721
+ timestamp,
14722
+ window
14723
+ }) {
14724
+ return TOTP.validate({
14725
+ token,
14726
+ secret: this.secret,
14727
+ algorithm: this.algorithm,
14728
+ digits: this.digits,
14729
+ period: this.period,
14730
+ timestamp,
14731
+ window
14732
+ });
14733
+ }
14734
+
14735
+ /**
14736
+ * Returns a Google Authenticator key URI.
14737
+ * @returns {string} URI.
14738
+ */
14739
+ toString() {
14740
+ const e = encodeURIComponent;
14741
+ return "otpauth://totp/" + `${this.issuer.length > 0 ? this.issuerInLabel ? `${e(this.issuer)}:${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?issuer=${e(this.issuer)}&` : `${e(this.label)}?`}` + `secret=${e(this.secret.base32)}&` + `algorithm=${e(this.algorithm)}&` + `digits=${e(this.digits)}&` + `period=${e(this.period)}`;
14742
+ }
14743
+ }
14744
+
14745
+ const initializeTotp = ({ issuer, secret, }) => {
14746
+ if (isNotPresent(secret)) {
14747
+ throw new Error("Secret for TOTP generation is not defined.");
14748
+ }
14749
+ return new TOTP({
14750
+ issuer,
14751
+ algorithm: "SHA1",
14752
+ digits: 6,
14753
+ period: 30,
14754
+ secret,
14755
+ });
14756
+ };
14757
+
13235
14758
  var main$2 = {exports: {}};
13236
14759
 
13237
14760
  var name = "dotenv";
@@ -13771,5 +15294,5 @@ const definePlaywrightConfig = (overrides) => {
13771
15294
  });
13772
15295
  };
13773
15296
 
13774
- export { API_ROUTES, BASE_URL, CHANGELOG_WIDGET_SELECTORS, CHAT_WIDGET_SELECTORS, CHAT_WIDGET_TEXTS, COMMON_SELECTORS, CREDENTIALS, CustomCommands, ENVIRONMENT, GLOBAL_TRANSLATIONS_PATTERN, HELP_CENTER_SELECTORS, HelpAndProfilePage, INTEGRATIONS_TEXTS, INTEGRATION_SELECTORS, IS_STAGING_ENV, IntegrationBase, KEYBOARD_SHORTCUTS_SELECTORS, LOGIN_SELECTORS, MEMBER_FORM_SELECTORS, MEMBER_SELECTORS, MEMBER_TEXTS, MERGE_TAGS_SELECTORS, MailosaurUtils, NEETO_AUTH_BASE_URL, NEETO_EDITOR_SELECTORS, NEETO_FILTERS_SELECTORS, OTP_EMAIL_PATTERN, OrganizationPage, PROFILE_SECTION_SELECTORS, PROJECT_TRANSLATIONS_PATH, ROLES_SELECTORS, ROUTES, SIGNUP_SELECTORS, SLACK_DEFAULT_CHANNEL, SLACK_SELECTORS, SLACK_WEB_TEXTS, STORAGE_STATE, SlackPage, TAGS_SELECTORS, THIRD_PARTY_ROUTES, USER_AGENTS, WebhooksPage, clearCredentials, commands, definePlaywrightConfig, extractSubdomainFromError, generateStagingData, getGlobalUserState, headerUtils, hyphenize, i18nFixture, initializeCredentials, joinHyphenCase, joinString, login, loginWithoutSSO, memberUtils, readFileSyncIfExists, removeCredentialFile, shouldSkipSetupAndTeardown, skipTest, stealth as stealthTest, tableUtils, updateCredentials, writeDataToFile };
15297
+ export { API_ROUTES, BASE_URL, CHANGELOG_WIDGET_SELECTORS, CHAT_WIDGET_SELECTORS, CHAT_WIDGET_TEXTS, COMMON_SELECTORS, CREDENTIALS, CustomCommands, ENVIRONMENT, GLOBAL_TRANSLATIONS_PATTERN, HELP_CENTER_SELECTORS, HelpAndProfilePage, INTEGRATIONS_TEXTS, INTEGRATION_SELECTORS, IS_STAGING_ENV, IntegrationBase, KEYBOARD_SHORTCUTS_SELECTORS, LOGIN_SELECTORS, MEMBER_FORM_SELECTORS, MEMBER_SELECTORS, MEMBER_TEXTS, MERGE_TAGS_SELECTORS, MailosaurUtils, NEETO_AUTH_BASE_URL, NEETO_EDITOR_SELECTORS, NEETO_FILTERS_SELECTORS, OTP_EMAIL_PATTERN, OrganizationPage, PROFILE_SECTION_SELECTORS, PROJECT_TRANSLATIONS_PATH, ROLES_SELECTORS, ROUTES, SIGNUP_SELECTORS, SLACK_DEFAULT_CHANNEL, SLACK_SELECTORS, SLACK_WEB_TEXTS, STORAGE_STATE, SlackPage, TAGS_SELECTORS, THIRD_PARTY_ROUTES, USER_AGENTS, WebhooksPage, clearCredentials, commands, definePlaywrightConfig, extractSubdomainFromError, generateStagingData, getGlobalUserState, headerUtils, hyphenize, i18nFixture, initializeCredentials, initializeTotp, joinHyphenCase, joinString, login, loginWithoutSSO, memberUtils, readFileSyncIfExists, removeCredentialFile, shouldSkipSetupAndTeardown, skipTest, squish, stealth as stealthTest, tableUtils, updateCredentials, writeDataToFile };
13775
15298
  //# sourceMappingURL=index.js.map