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