@volter/tabnode 0.5.48 → 0.5.50
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assets/{runtime-worker-B-BP9mj-.js → runtime-worker-Cu2mr9G9.js} +1253 -89
- package/dist/fetch-transport.d.ts +0 -1
- package/dist/index.mjs +1250 -100
- package/dist/node-body.d.ts +9 -0
- package/dist/shims/crypto-cipher.d.ts +203 -0
- package/dist/shims/crypto.d.ts +465 -1
- package/package.json +2 -1
- package/src/fetch-transport.ts +7 -3
- package/src/node-body.ts +88 -0
- package/src/node-response.ts +5 -2
- package/src/runtime.ts +3 -0
- package/src/shims/child_process.ts +49 -6
- package/src/shims/crypto-cipher.ts +354 -0
- package/src/shims/crypto.ts +27 -2
- package/src/shims/shell-jobs.ts +72 -0
|
@@ -5425,7 +5425,7 @@ function parse(urlString, parseQueryString = false, slashesDenoteHost = false) {
|
|
|
5425
5425
|
hostname: null,
|
|
5426
5426
|
hash: __hash,
|
|
5427
5427
|
search: __search,
|
|
5428
|
-
query: parseQueryString ? Object.fromEntries(new URLSearchParams(__search || "")) : __search ? __search.slice(1) : null,
|
|
5428
|
+
query: parseQueryString ? Object.fromEntries(new URLSearchParams$1(__search || "")) : __search ? __search.slice(1) : null,
|
|
5429
5429
|
pathname: __pathname || null,
|
|
5430
5430
|
path: __pathname + (__search || "") || null,
|
|
5431
5431
|
href: urlString
|
|
@@ -5499,7 +5499,7 @@ function format(urlObject) {
|
|
|
5499
5499
|
if (typeof urlObject.query === "string") {
|
|
5500
5500
|
result += "?" + urlObject.query;
|
|
5501
5501
|
} else {
|
|
5502
|
-
const params = new URLSearchParams();
|
|
5502
|
+
const params = new URLSearchParams$1();
|
|
5503
5503
|
for (const [key, value] of Object.entries(urlObject.query)) {
|
|
5504
5504
|
if (Array.isArray(value)) {
|
|
5505
5505
|
for (const v2 of value) {
|
|
@@ -5528,7 +5528,7 @@ function resolve$2(from, to2) {
|
|
|
5528
5528
|
}
|
|
5529
5529
|
}
|
|
5530
5530
|
const URL$1 = globalThis.URL;
|
|
5531
|
-
const URLSearchParams = globalThis.URLSearchParams;
|
|
5531
|
+
const URLSearchParams$1 = globalThis.URLSearchParams;
|
|
5532
5532
|
function fileURLToPath(url2) {
|
|
5533
5533
|
const urlObj = typeof url2 === "string" ? new globalThis.URL(url2) : url2;
|
|
5534
5534
|
if (urlObj.protocol !== "file:") {
|
|
@@ -5551,7 +5551,7 @@ var url$1 = {
|
|
|
5551
5551
|
format,
|
|
5552
5552
|
resolve: resolve$2,
|
|
5553
5553
|
URL: URL$1,
|
|
5554
|
-
URLSearchParams,
|
|
5554
|
+
URLSearchParams: URLSearchParams$1,
|
|
5555
5555
|
URLPattern: URLPattern$1,
|
|
5556
5556
|
fileURLToPath,
|
|
5557
5557
|
pathToFileURL
|
|
@@ -5560,7 +5560,7 @@ var urlShim = /* @__PURE__ */ Object.freeze({
|
|
|
5560
5560
|
__proto__: null,
|
|
5561
5561
|
URL: URL$1,
|
|
5562
5562
|
URLPattern: URLPattern$1,
|
|
5563
|
-
URLSearchParams,
|
|
5563
|
+
URLSearchParams: URLSearchParams$1,
|
|
5564
5564
|
default: url$1,
|
|
5565
5565
|
fileURLToPath,
|
|
5566
5566
|
format,
|
|
@@ -19252,14 +19252,14 @@ var safeBuffer = { exports: {} };
|
|
|
19252
19252
|
var buffer = {};
|
|
19253
19253
|
var ieee754 = {};
|
|
19254
19254
|
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
19255
|
-
ieee754.read = function(buffer2, offset2,
|
|
19255
|
+
ieee754.read = function(buffer2, offset2, isLE2, mLen, nBytes) {
|
|
19256
19256
|
var e2, m;
|
|
19257
19257
|
var eLen = nBytes * 8 - mLen - 1;
|
|
19258
19258
|
var eMax = (1 << eLen) - 1;
|
|
19259
19259
|
var eBias = eMax >> 1;
|
|
19260
19260
|
var nBits = -7;
|
|
19261
|
-
var i10 =
|
|
19262
|
-
var d =
|
|
19261
|
+
var i10 = isLE2 ? nBytes - 1 : 0;
|
|
19262
|
+
var d = isLE2 ? -1 : 1;
|
|
19263
19263
|
var s10 = buffer2[offset2 + i10];
|
|
19264
19264
|
i10 += d;
|
|
19265
19265
|
e2 = s10 & (1 << -nBits) - 1;
|
|
@@ -19282,14 +19282,14 @@ ieee754.read = function(buffer2, offset2, isLE, mLen, nBytes) {
|
|
|
19282
19282
|
}
|
|
19283
19283
|
return (s10 ? -1 : 1) * m * Math.pow(2, e2 - mLen);
|
|
19284
19284
|
};
|
|
19285
|
-
ieee754.write = function(buffer2, value, offset2,
|
|
19285
|
+
ieee754.write = function(buffer2, value, offset2, isLE2, mLen, nBytes) {
|
|
19286
19286
|
var e2, m, c;
|
|
19287
19287
|
var eLen = nBytes * 8 - mLen - 1;
|
|
19288
19288
|
var eMax = (1 << eLen) - 1;
|
|
19289
19289
|
var eBias = eMax >> 1;
|
|
19290
19290
|
var rt2 = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
19291
|
-
var i10 =
|
|
19292
|
-
var d =
|
|
19291
|
+
var i10 = isLE2 ? 0 : nBytes - 1;
|
|
19292
|
+
var d = isLE2 ? 1 : -1;
|
|
19293
19293
|
var s10 = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
19294
19294
|
value = Math.abs(value);
|
|
19295
19295
|
if (isNaN(value) || value === Infinity) {
|
|
@@ -20180,10 +20180,10 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20180
20180
|
byteLength3 = byteLength3 >>> 0;
|
|
20181
20181
|
if (!noAssert) checkOffset(offset2, byteLength3, this.length);
|
|
20182
20182
|
let val = this[offset2];
|
|
20183
|
-
let
|
|
20183
|
+
let mul3 = 1;
|
|
20184
20184
|
let i10 = 0;
|
|
20185
|
-
while (++i10 < byteLength3 && (
|
|
20186
|
-
val += this[offset2 + i10] *
|
|
20185
|
+
while (++i10 < byteLength3 && (mul3 *= 256)) {
|
|
20186
|
+
val += this[offset2 + i10] * mul3;
|
|
20187
20187
|
}
|
|
20188
20188
|
return val;
|
|
20189
20189
|
};
|
|
@@ -20194,9 +20194,9 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20194
20194
|
checkOffset(offset2, byteLength3, this.length);
|
|
20195
20195
|
}
|
|
20196
20196
|
let val = this[offset2 + --byteLength3];
|
|
20197
|
-
let
|
|
20198
|
-
while (byteLength3 > 0 && (
|
|
20199
|
-
val += this[offset2 + --byteLength3] *
|
|
20197
|
+
let mul3 = 1;
|
|
20198
|
+
while (byteLength3 > 0 && (mul3 *= 256)) {
|
|
20199
|
+
val += this[offset2 + --byteLength3] * mul3;
|
|
20200
20200
|
}
|
|
20201
20201
|
return val;
|
|
20202
20202
|
};
|
|
@@ -20254,13 +20254,13 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20254
20254
|
byteLength3 = byteLength3 >>> 0;
|
|
20255
20255
|
if (!noAssert) checkOffset(offset2, byteLength3, this.length);
|
|
20256
20256
|
let val = this[offset2];
|
|
20257
|
-
let
|
|
20257
|
+
let mul3 = 1;
|
|
20258
20258
|
let i10 = 0;
|
|
20259
|
-
while (++i10 < byteLength3 && (
|
|
20260
|
-
val += this[offset2 + i10] *
|
|
20259
|
+
while (++i10 < byteLength3 && (mul3 *= 256)) {
|
|
20260
|
+
val += this[offset2 + i10] * mul3;
|
|
20261
20261
|
}
|
|
20262
|
-
|
|
20263
|
-
if (val >=
|
|
20262
|
+
mul3 *= 128;
|
|
20263
|
+
if (val >= mul3) val -= Math.pow(2, 8 * byteLength3);
|
|
20264
20264
|
return val;
|
|
20265
20265
|
};
|
|
20266
20266
|
Buffer2.prototype.readIntBE = function readIntBE(offset2, byteLength3, noAssert) {
|
|
@@ -20268,13 +20268,13 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20268
20268
|
byteLength3 = byteLength3 >>> 0;
|
|
20269
20269
|
if (!noAssert) checkOffset(offset2, byteLength3, this.length);
|
|
20270
20270
|
let i10 = byteLength3;
|
|
20271
|
-
let
|
|
20271
|
+
let mul3 = 1;
|
|
20272
20272
|
let val = this[offset2 + --i10];
|
|
20273
|
-
while (i10 > 0 && (
|
|
20274
|
-
val += this[offset2 + --i10] *
|
|
20273
|
+
while (i10 > 0 && (mul3 *= 256)) {
|
|
20274
|
+
val += this[offset2 + --i10] * mul3;
|
|
20275
20275
|
}
|
|
20276
|
-
|
|
20277
|
-
if (val >=
|
|
20276
|
+
mul3 *= 128;
|
|
20277
|
+
if (val >= mul3) val -= Math.pow(2, 8 * byteLength3);
|
|
20278
20278
|
return val;
|
|
20279
20279
|
};
|
|
20280
20280
|
Buffer2.prototype.readInt8 = function readInt8(offset2, noAssert) {
|
|
@@ -20361,11 +20361,11 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20361
20361
|
const maxBytes = Math.pow(2, 8 * byteLength3) - 1;
|
|
20362
20362
|
checkInt(this, value, offset2, byteLength3, maxBytes, 0);
|
|
20363
20363
|
}
|
|
20364
|
-
let
|
|
20364
|
+
let mul3 = 1;
|
|
20365
20365
|
let i10 = 0;
|
|
20366
20366
|
this[offset2] = value & 255;
|
|
20367
|
-
while (++i10 < byteLength3 && (
|
|
20368
|
-
this[offset2 + i10] = value /
|
|
20367
|
+
while (++i10 < byteLength3 && (mul3 *= 256)) {
|
|
20368
|
+
this[offset2 + i10] = value / mul3 & 255;
|
|
20369
20369
|
}
|
|
20370
20370
|
return offset2 + byteLength3;
|
|
20371
20371
|
};
|
|
@@ -20378,10 +20378,10 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20378
20378
|
checkInt(this, value, offset2, byteLength3, maxBytes, 0);
|
|
20379
20379
|
}
|
|
20380
20380
|
let i10 = byteLength3 - 1;
|
|
20381
|
-
let
|
|
20381
|
+
let mul3 = 1;
|
|
20382
20382
|
this[offset2 + i10] = value & 255;
|
|
20383
|
-
while (--i10 >= 0 && (
|
|
20384
|
-
this[offset2 + i10] = value /
|
|
20383
|
+
while (--i10 >= 0 && (mul3 *= 256)) {
|
|
20384
|
+
this[offset2 + i10] = value / mul3 & 255;
|
|
20385
20385
|
}
|
|
20386
20386
|
return offset2 + byteLength3;
|
|
20387
20387
|
};
|
|
@@ -20482,14 +20482,14 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20482
20482
|
checkInt(this, value, offset2, byteLength3, limit - 1, -limit);
|
|
20483
20483
|
}
|
|
20484
20484
|
let i10 = 0;
|
|
20485
|
-
let
|
|
20485
|
+
let mul3 = 1;
|
|
20486
20486
|
let sub = 0;
|
|
20487
20487
|
this[offset2] = value & 255;
|
|
20488
|
-
while (++i10 < byteLength3 && (
|
|
20488
|
+
while (++i10 < byteLength3 && (mul3 *= 256)) {
|
|
20489
20489
|
if (value < 0 && sub === 0 && this[offset2 + i10 - 1] !== 0) {
|
|
20490
20490
|
sub = 1;
|
|
20491
20491
|
}
|
|
20492
|
-
this[offset2 + i10] = (value /
|
|
20492
|
+
this[offset2 + i10] = (value / mul3 >> 0) - sub & 255;
|
|
20493
20493
|
}
|
|
20494
20494
|
return offset2 + byteLength3;
|
|
20495
20495
|
};
|
|
@@ -20501,14 +20501,14 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20501
20501
|
checkInt(this, value, offset2, byteLength3, limit - 1, -limit);
|
|
20502
20502
|
}
|
|
20503
20503
|
let i10 = byteLength3 - 1;
|
|
20504
|
-
let
|
|
20504
|
+
let mul3 = 1;
|
|
20505
20505
|
let sub = 0;
|
|
20506
20506
|
this[offset2 + i10] = value & 255;
|
|
20507
|
-
while (--i10 >= 0 && (
|
|
20507
|
+
while (--i10 >= 0 && (mul3 *= 256)) {
|
|
20508
20508
|
if (value < 0 && sub === 0 && this[offset2 + i10 + 1] !== 0) {
|
|
20509
20509
|
sub = 1;
|
|
20510
20510
|
}
|
|
20511
|
-
this[offset2 + i10] = (value /
|
|
20511
|
+
this[offset2 + i10] = (value / mul3 >> 0) - sub & 255;
|
|
20512
20512
|
}
|
|
20513
20513
|
return offset2 + byteLength3;
|
|
20514
20514
|
};
|
|
@@ -21191,10 +21191,17 @@ var implementation$1 = function bind2(that) {
|
|
|
21191
21191
|
var implementation = implementation$1;
|
|
21192
21192
|
var functionBind = Function.prototype.bind || implementation;
|
|
21193
21193
|
var functionCall = Function.prototype.call;
|
|
21194
|
-
var functionApply
|
|
21194
|
+
var functionApply;
|
|
21195
|
+
var hasRequiredFunctionApply;
|
|
21196
|
+
function requireFunctionApply() {
|
|
21197
|
+
if (hasRequiredFunctionApply) return functionApply;
|
|
21198
|
+
hasRequiredFunctionApply = 1;
|
|
21199
|
+
functionApply = Function.prototype.apply;
|
|
21200
|
+
return functionApply;
|
|
21201
|
+
}
|
|
21195
21202
|
var reflectApply = typeof Reflect !== "undefined" && Reflect && Reflect.apply;
|
|
21196
21203
|
var bind$2 = functionBind;
|
|
21197
|
-
var $apply$1 =
|
|
21204
|
+
var $apply$1 = requireFunctionApply();
|
|
21198
21205
|
var $call$2 = functionCall;
|
|
21199
21206
|
var $reflectApply = reflectApply;
|
|
21200
21207
|
var actualApply = $reflectApply || bind$2.call($call$2, $apply$1);
|
|
@@ -21314,7 +21321,7 @@ var hasSymbols = requireHasSymbols()();
|
|
|
21314
21321
|
var getProto = requireGetProto();
|
|
21315
21322
|
var $ObjectGPO = requireObject_getPrototypeOf();
|
|
21316
21323
|
var $ReflectGPO = requireReflect_getPrototypeOf();
|
|
21317
|
-
var $apply =
|
|
21324
|
+
var $apply = requireFunctionApply();
|
|
21318
21325
|
var $call = functionCall;
|
|
21319
21326
|
var needsEval = {};
|
|
21320
21327
|
var TypedArray = typeof Uint8Array === "undefined" || !getProto ? undefined$1 : getProto(Uint8Array);
|
|
@@ -21955,7 +21962,7 @@ function requireApplyBind() {
|
|
|
21955
21962
|
if (hasRequiredApplyBind) return applyBind;
|
|
21956
21963
|
hasRequiredApplyBind = 1;
|
|
21957
21964
|
var bind3 = functionBind;
|
|
21958
|
-
var $apply2 =
|
|
21965
|
+
var $apply2 = requireFunctionApply();
|
|
21959
21966
|
var actualApply$1 = actualApply;
|
|
21960
21967
|
applyBind = function applyBind2() {
|
|
21961
21968
|
return actualApply$1(bind3, $apply2, arguments);
|
|
@@ -23002,23 +23009,23 @@ var sha_jsExports = sha_js.exports;
|
|
|
23002
23009
|
var SHA = /* @__PURE__ */ getDefaultExportFromCjs(sha_jsExports);
|
|
23003
23010
|
const fromNumH = (n8) => n8 / 2 ** 32 | 0;
|
|
23004
23011
|
const fromNumL = (n8) => n8 >>> 0;
|
|
23005
|
-
function setU64FromNum(view, byteOffset, n8,
|
|
23012
|
+
function setU64FromNum(view, byteOffset, n8, isLE2) {
|
|
23006
23013
|
const h = fromNumH(n8);
|
|
23007
23014
|
const l = fromNumL(n8);
|
|
23008
|
-
view.setUint32(byteOffset,
|
|
23009
|
-
view.setUint32(byteOffset + 4,
|
|
23015
|
+
view.setUint32(byteOffset, isLE2 ? l : h, isLE2);
|
|
23016
|
+
view.setUint32(byteOffset + 4, isLE2 ? h : l, isLE2);
|
|
23010
23017
|
}
|
|
23011
|
-
function isBytes(a) {
|
|
23018
|
+
function isBytes$1(a) {
|
|
23012
23019
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
23013
23020
|
}
|
|
23014
|
-
const atitle = (title) => title ? `"${title}" ` : "";
|
|
23015
|
-
function abytes(value, length, title = "") {
|
|
23016
|
-
if (isBytes(value) && length === void 0)
|
|
23021
|
+
const atitle$1 = (title) => title ? `"${title}" ` : "";
|
|
23022
|
+
function abytes$1(value, length, title = "") {
|
|
23023
|
+
if (isBytes$1(value) && length === void 0)
|
|
23017
23024
|
return value;
|
|
23018
|
-
const bytes2 = isBytes(value);
|
|
23025
|
+
const bytes2 = isBytes$1(value);
|
|
23019
23026
|
const ofLen = "";
|
|
23020
23027
|
const got = bytes2 ? `length=${value.length}` : `type=${typeof value}`;
|
|
23021
|
-
const message = atitle(title) + "expected Uint8Array" + ofLen + ", got " + got;
|
|
23028
|
+
const message = atitle$1(title) + "expected Uint8Array" + ofLen + ", got " + got;
|
|
23022
23029
|
if (!bytes2)
|
|
23023
23030
|
throw new TypeError(message);
|
|
23024
23031
|
throw new RangeError(message);
|
|
@@ -23027,25 +23034,25 @@ const aobject = (value, label) => {
|
|
|
23027
23034
|
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
23028
23035
|
throw new TypeError((label === "object" ? "" : `"${label}" `) + "expected object, got type=" + typeof value);
|
|
23029
23036
|
};
|
|
23030
|
-
function aexists(instance, checkFinished = true) {
|
|
23037
|
+
function aexists$1(instance, checkFinished = true) {
|
|
23031
23038
|
if (instance.destroyed)
|
|
23032
23039
|
throw new Error("hash was destroyed");
|
|
23033
23040
|
if (checkFinished && instance.finished)
|
|
23034
23041
|
throw new Error("digest() was already called");
|
|
23035
23042
|
}
|
|
23036
|
-
function aoutput(out, instance) {
|
|
23037
|
-
abytes(out, void 0, "output");
|
|
23043
|
+
function aoutput$1(out, instance) {
|
|
23044
|
+
abytes$1(out, void 0, "output");
|
|
23038
23045
|
const min2 = instance.outputLen;
|
|
23039
23046
|
if (!(out.length >= min2)) {
|
|
23040
23047
|
throw new RangeError('"output" expected length >= ' + min2);
|
|
23041
23048
|
}
|
|
23042
23049
|
}
|
|
23043
|
-
function clean(...arrays) {
|
|
23050
|
+
function clean$1(...arrays) {
|
|
23044
23051
|
for (let i10 = 0; i10 < arrays.length; i10++) {
|
|
23045
23052
|
arrays[i10].fill(0);
|
|
23046
23053
|
}
|
|
23047
23054
|
}
|
|
23048
|
-
function createView(arr) {
|
|
23055
|
+
function createView$1(arr) {
|
|
23049
23056
|
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
23050
23057
|
}
|
|
23051
23058
|
function rotr(word, shift) {
|
|
@@ -23060,7 +23067,7 @@ const hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
|
23060
23067
|
))();
|
|
23061
23068
|
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i10) => i10.toString(16).padStart(2, "0"));
|
|
23062
23069
|
function bytesToHex(bytes2) {
|
|
23063
|
-
abytes(bytes2);
|
|
23070
|
+
abytes$1(bytes2);
|
|
23064
23071
|
if (hasHexBuiltin)
|
|
23065
23072
|
return bytes2.toHex();
|
|
23066
23073
|
let hex = "";
|
|
@@ -23101,7 +23108,7 @@ function Maj(a, b, c) {
|
|
|
23101
23108
|
return a & b ^ a & c ^ b & c;
|
|
23102
23109
|
}
|
|
23103
23110
|
class HashMD {
|
|
23104
|
-
constructor(blockLen, outputLen, padOffset,
|
|
23111
|
+
constructor(blockLen, outputLen, padOffset, isLE2) {
|
|
23105
23112
|
__publicField(this, "blockLen");
|
|
23106
23113
|
__publicField(this, "outputLen");
|
|
23107
23114
|
__publicField(this, "canXOF", false);
|
|
@@ -23117,20 +23124,20 @@ class HashMD {
|
|
|
23117
23124
|
this.blockLen = blockLen;
|
|
23118
23125
|
this.outputLen = outputLen;
|
|
23119
23126
|
this.padOffset = padOffset;
|
|
23120
|
-
this.isLE =
|
|
23127
|
+
this.isLE = isLE2;
|
|
23121
23128
|
this.buffer = new Uint8Array(blockLen);
|
|
23122
|
-
this.view = createView(this.buffer);
|
|
23129
|
+
this.view = createView$1(this.buffer);
|
|
23123
23130
|
}
|
|
23124
23131
|
update(data2) {
|
|
23125
|
-
aexists(this);
|
|
23126
|
-
abytes(data2);
|
|
23132
|
+
aexists$1(this);
|
|
23133
|
+
abytes$1(data2);
|
|
23127
23134
|
const { view, buffer: buffer2, blockLen } = this;
|
|
23128
23135
|
const len2 = data2.length;
|
|
23129
23136
|
let processed = false;
|
|
23130
23137
|
for (let pos = 0; pos < len2; ) {
|
|
23131
23138
|
const take = Math.min(blockLen - this.pos, len2 - pos);
|
|
23132
23139
|
if (take === blockLen) {
|
|
23133
|
-
const dataView = createView(data2);
|
|
23140
|
+
const dataView = createView$1(data2);
|
|
23134
23141
|
for (; blockLen <= len2 - pos; pos += blockLen)
|
|
23135
23142
|
this.process(dataView, pos);
|
|
23136
23143
|
processed = true;
|
|
@@ -23151,10 +23158,10 @@ class HashMD {
|
|
|
23151
23158
|
return this;
|
|
23152
23159
|
}
|
|
23153
23160
|
digestInto(out) {
|
|
23154
|
-
aexists(this);
|
|
23155
|
-
aoutput(out, this);
|
|
23161
|
+
aexists$1(this);
|
|
23162
|
+
aoutput$1(out, this);
|
|
23156
23163
|
this.finished = true;
|
|
23157
|
-
const { buffer: buffer2, view, blockLen, isLE } = this;
|
|
23164
|
+
const { buffer: buffer2, view, blockLen, isLE: isLE2 } = this;
|
|
23158
23165
|
let { pos } = this;
|
|
23159
23166
|
buffer2[pos++] = 128;
|
|
23160
23167
|
buffer2.fill(0, pos);
|
|
@@ -23162,17 +23169,17 @@ class HashMD {
|
|
|
23162
23169
|
this.process(view, 0);
|
|
23163
23170
|
buffer2.fill(0);
|
|
23164
23171
|
}
|
|
23165
|
-
setU64FromNum(view, blockLen - 8, this.length * 8,
|
|
23172
|
+
setU64FromNum(view, blockLen - 8, this.length * 8, isLE2);
|
|
23166
23173
|
this.process(view, 0);
|
|
23167
23174
|
this.roundClean();
|
|
23168
|
-
const oview = out === buffer2 ? view : createView(out);
|
|
23175
|
+
const oview = out === buffer2 ? view : createView$1(out);
|
|
23169
23176
|
const len2 = this.outputLen;
|
|
23170
23177
|
const outLen = len2 / 4;
|
|
23171
23178
|
const state = this.get();
|
|
23172
23179
|
if (len2 % 4 || outLen > state.length)
|
|
23173
23180
|
throw new Error("invalid outputLen");
|
|
23174
23181
|
for (let i10 = 0; i10 < outLen; i10++)
|
|
23175
|
-
oview.setUint32(4 * i10, state[i10],
|
|
23182
|
+
oview.setUint32(4 * i10, state[i10], isLE2);
|
|
23176
23183
|
}
|
|
23177
23184
|
digest() {
|
|
23178
23185
|
const { buffer: buffer2, outputLen } = this;
|
|
@@ -23279,12 +23286,12 @@ class _MD5 extends HashMD {
|
|
|
23279
23286
|
this.set(A10, B, C, D10);
|
|
23280
23287
|
}
|
|
23281
23288
|
roundClean() {
|
|
23282
|
-
clean(MD5_W);
|
|
23289
|
+
clean$1(MD5_W);
|
|
23283
23290
|
}
|
|
23284
23291
|
destroy() {
|
|
23285
23292
|
this.destroyed = true;
|
|
23286
23293
|
this.set(0, 0, 0, 0);
|
|
23287
|
-
clean(this.buffer);
|
|
23294
|
+
clean$1(this.buffer);
|
|
23288
23295
|
}
|
|
23289
23296
|
}
|
|
23290
23297
|
const md5 = /* @__PURE__ */ createHasher(() => new _MD5());
|
|
@@ -23294,6 +23301,993 @@ const cryptoConstants = {
|
|
|
23294
23301
|
RSA_PKCS1_OAEP_PADDING: 4,
|
|
23295
23302
|
RSA_PKCS1_PSS_PADDING: 6
|
|
23296
23303
|
};
|
|
23304
|
+
/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
|
|
23305
|
+
function isBytes(a) {
|
|
23306
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
23307
|
+
}
|
|
23308
|
+
const atitle = (title) => title ? `"${title}" ` : "";
|
|
23309
|
+
function anumber(n8, title = "") {
|
|
23310
|
+
if (typeof n8 !== "number")
|
|
23311
|
+
throw new TypeError(atitle(title) + "expected number, got " + typeof n8);
|
|
23312
|
+
if (!Number.isSafeInteger(n8) || n8 < 0)
|
|
23313
|
+
throw new RangeError(atitle(title) + "expected integer >= 0, got " + n8);
|
|
23314
|
+
return n8;
|
|
23315
|
+
}
|
|
23316
|
+
function abytes(value, length, title = "") {
|
|
23317
|
+
if (isBytes(value) && (length === void 0 || value.length === length))
|
|
23318
|
+
return value;
|
|
23319
|
+
if (length !== void 0)
|
|
23320
|
+
anumber(length, "length");
|
|
23321
|
+
const bytes2 = isBytes(value);
|
|
23322
|
+
const ofLen = length !== void 0 ? ` of length ${length}` : "";
|
|
23323
|
+
const got = bytes2 ? `length=${value.length}` : `type=${typeof value}`;
|
|
23324
|
+
const message = atitle(title) + "expected Uint8Array" + ofLen + ", got " + got;
|
|
23325
|
+
if (!bytes2)
|
|
23326
|
+
throw new TypeError(message);
|
|
23327
|
+
throw new RangeError(message);
|
|
23328
|
+
}
|
|
23329
|
+
function aexists(instance, checkFinished = true) {
|
|
23330
|
+
if (instance.destroyed)
|
|
23331
|
+
throw new Error("hash was destroyed");
|
|
23332
|
+
if (checkFinished && instance.finished)
|
|
23333
|
+
throw new Error("digest() was already called");
|
|
23334
|
+
}
|
|
23335
|
+
function aoutput(out, instance) {
|
|
23336
|
+
abytes(out, void 0, "output");
|
|
23337
|
+
const min2 = instance.outputLen;
|
|
23338
|
+
if (!(out.length >= min2)) {
|
|
23339
|
+
throw new RangeError('"output" expected length >= ' + min2);
|
|
23340
|
+
}
|
|
23341
|
+
}
|
|
23342
|
+
function aoutput32(out, instance) {
|
|
23343
|
+
aoutput(out, instance);
|
|
23344
|
+
if (!isAligned32(out))
|
|
23345
|
+
throw new Error("invalid output, must be aligned");
|
|
23346
|
+
}
|
|
23347
|
+
function u8$1(arr) {
|
|
23348
|
+
return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
23349
|
+
}
|
|
23350
|
+
function u32(arr) {
|
|
23351
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
23352
|
+
}
|
|
23353
|
+
function clean(...arrays) {
|
|
23354
|
+
for (let i10 = 0; i10 < arrays.length; i10++) {
|
|
23355
|
+
arrays[i10].fill(0);
|
|
23356
|
+
}
|
|
23357
|
+
}
|
|
23358
|
+
function createView(arr) {
|
|
23359
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
23360
|
+
}
|
|
23361
|
+
const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
23362
|
+
function byteSwap(word) {
|
|
23363
|
+
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
23364
|
+
}
|
|
23365
|
+
const swap8IfBE = isLE ? (n8) => n8 : (n8) => byteSwap(n8) >>> 0;
|
|
23366
|
+
function byteSwap32(arr) {
|
|
23367
|
+
for (let i10 = 0; i10 < arr.length; i10++) {
|
|
23368
|
+
arr[i10] = byteSwap(arr[i10]);
|
|
23369
|
+
}
|
|
23370
|
+
return arr;
|
|
23371
|
+
}
|
|
23372
|
+
const swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
23373
|
+
function overlapBytes(a, b) {
|
|
23374
|
+
if (!a.byteLength || !b.byteLength)
|
|
23375
|
+
return false;
|
|
23376
|
+
return a.buffer === b.buffer && // best we can do, may fail with an obscure Proxy
|
|
23377
|
+
a.byteOffset < b.byteOffset + b.byteLength && // a starts before b end
|
|
23378
|
+
b.byteOffset < a.byteOffset + a.byteLength;
|
|
23379
|
+
}
|
|
23380
|
+
function complexOverlapBytes(input, output) {
|
|
23381
|
+
if (overlapBytes(input, output) && input.byteOffset < output.byteOffset)
|
|
23382
|
+
throw new Error("complex overlap of input and output is not supported");
|
|
23383
|
+
}
|
|
23384
|
+
function wrapMacConstructor(keyLen, macCons, fromMsg) {
|
|
23385
|
+
const mac = macCons;
|
|
23386
|
+
const getArgs = fromMsg || (() => []);
|
|
23387
|
+
const macC = (msg2, key) => mac(key, ...getArgs(msg2)).update(msg2).digest();
|
|
23388
|
+
const tmp = mac(new Uint8Array(keyLen), ...getArgs(new Uint8Array(0)));
|
|
23389
|
+
macC.outputLen = tmp.outputLen;
|
|
23390
|
+
macC.blockLen = tmp.blockLen;
|
|
23391
|
+
macC.create = (key, ...args) => mac(key, ...args);
|
|
23392
|
+
return macC;
|
|
23393
|
+
}
|
|
23394
|
+
function getOutput(expectedLength, out, onlyAligned = true) {
|
|
23395
|
+
if (out === void 0)
|
|
23396
|
+
return new Uint8Array(expectedLength);
|
|
23397
|
+
abytes(out, expectedLength, "output");
|
|
23398
|
+
if (onlyAligned && !isAligned32(out))
|
|
23399
|
+
throw new Error("invalid output, must be aligned");
|
|
23400
|
+
return out;
|
|
23401
|
+
}
|
|
23402
|
+
function isAligned32(bytes2) {
|
|
23403
|
+
return bytes2.byteOffset % 4 === 0;
|
|
23404
|
+
}
|
|
23405
|
+
function copyBytes(bytes2) {
|
|
23406
|
+
return Uint8Array.from(abytes(bytes2));
|
|
23407
|
+
}
|
|
23408
|
+
const BLOCK_SIZE$1 = 16;
|
|
23409
|
+
const ZEROS16 = /* @__PURE__ */ new Uint8Array(16);
|
|
23410
|
+
const ZEROS32 = /* @__PURE__ */ u32(ZEROS16);
|
|
23411
|
+
const POLY$1 = 225;
|
|
23412
|
+
const mul2$1 = (s02, s12, s22, s32) => {
|
|
23413
|
+
const hiBit = s32 & 1;
|
|
23414
|
+
return {
|
|
23415
|
+
s3: s22 << 31 | s32 >>> 1,
|
|
23416
|
+
s2: s12 << 31 | s22 >>> 1,
|
|
23417
|
+
s1: s02 << 31 | s12 >>> 1,
|
|
23418
|
+
// NIST SP 800-38D §6.3 applies `V >> 1` and XORs R on carry. In this
|
|
23419
|
+
// 4x32-bit split, R = 0xe1 || 0^120 lives in the top byte of s0.
|
|
23420
|
+
s0: s02 >>> 1 ^ POLY$1 << 24 & -(hiBit & 1)
|
|
23421
|
+
// reduce % poly
|
|
23422
|
+
};
|
|
23423
|
+
};
|
|
23424
|
+
const swapLE = (n8) => (n8 >>> 0 & 255) << 24 | (n8 >>> 8 & 255) << 16 | (n8 >>> 16 & 255) << 8 | n8 >>> 24 & 255 | 0;
|
|
23425
|
+
const estimateWindow = (bytes2) => {
|
|
23426
|
+
if (bytes2 > 64 * 1024)
|
|
23427
|
+
return 8;
|
|
23428
|
+
if (bytes2 > 1024)
|
|
23429
|
+
return 4;
|
|
23430
|
+
return 2;
|
|
23431
|
+
};
|
|
23432
|
+
class GHASH {
|
|
23433
|
+
// We select bits per window adaptively based on expectedLength
|
|
23434
|
+
constructor(key, expectedLength) {
|
|
23435
|
+
__publicField(this, "blockLen", BLOCK_SIZE$1);
|
|
23436
|
+
__publicField(this, "outputLen", BLOCK_SIZE$1);
|
|
23437
|
+
__publicField(this, "s0", 0);
|
|
23438
|
+
__publicField(this, "s1", 0);
|
|
23439
|
+
__publicField(this, "s2", 0);
|
|
23440
|
+
__publicField(this, "s3", 0);
|
|
23441
|
+
__publicField(this, "finished", false);
|
|
23442
|
+
__publicField(this, "destroyed", false);
|
|
23443
|
+
__publicField(this, "t");
|
|
23444
|
+
__publicField(this, "W");
|
|
23445
|
+
__publicField(this, "windowSize");
|
|
23446
|
+
abytes(key, 16, "key");
|
|
23447
|
+
key = copyBytes(key);
|
|
23448
|
+
const kView = createView(key);
|
|
23449
|
+
let k02 = kView.getUint32(0, false);
|
|
23450
|
+
let k12 = kView.getUint32(4, false);
|
|
23451
|
+
let k22 = kView.getUint32(8, false);
|
|
23452
|
+
let k32 = kView.getUint32(12, false);
|
|
23453
|
+
const doubles = [];
|
|
23454
|
+
for (let i10 = 0; i10 < 128; i10++) {
|
|
23455
|
+
doubles.push({ s0: swapLE(k02), s1: swapLE(k12), s2: swapLE(k22), s3: swapLE(k32) });
|
|
23456
|
+
({ s0: k02, s1: k12, s2: k22, s3: k32 } = mul2$1(k02, k12, k22, k32));
|
|
23457
|
+
}
|
|
23458
|
+
const W10 = estimateWindow(expectedLength || 1024);
|
|
23459
|
+
if (![1, 2, 4, 8].includes(W10))
|
|
23460
|
+
throw new Error("ghash: invalid window size, expected 2, 4 or 8");
|
|
23461
|
+
this.W = W10;
|
|
23462
|
+
const bits = 128;
|
|
23463
|
+
const windows = bits / W10;
|
|
23464
|
+
const windowSize = this.windowSize = 2 ** W10;
|
|
23465
|
+
const items = [];
|
|
23466
|
+
for (let w = 0; w < windows; w++) {
|
|
23467
|
+
for (let byte = 0; byte < windowSize; byte++) {
|
|
23468
|
+
let s02 = 0, s12 = 0, s22 = 0, s32 = 0;
|
|
23469
|
+
for (let j = 0; j < W10; j++) {
|
|
23470
|
+
const bit = byte >>> W10 - j - 1 & 1;
|
|
23471
|
+
if (!bit)
|
|
23472
|
+
continue;
|
|
23473
|
+
const { s0: d02, s1: d12, s2: d22, s3: d32 } = doubles[W10 * w + j];
|
|
23474
|
+
s02 ^= d02, s12 ^= d12, s22 ^= d22, s32 ^= d32;
|
|
23475
|
+
}
|
|
23476
|
+
items.push({ s0: s02, s1: s12, s2: s22, s3: s32 });
|
|
23477
|
+
}
|
|
23478
|
+
}
|
|
23479
|
+
this.t = items;
|
|
23480
|
+
}
|
|
23481
|
+
_updateBlock(s02, s12, s22, s32) {
|
|
23482
|
+
s02 ^= this.s0, s12 ^= this.s1, s22 ^= this.s2, s32 ^= this.s3;
|
|
23483
|
+
const { W: W10, t: t10, windowSize } = this;
|
|
23484
|
+
let o02 = 0, o12 = 0, o22 = 0, o32 = 0;
|
|
23485
|
+
const mask = (1 << W10) - 1;
|
|
23486
|
+
let w = 0;
|
|
23487
|
+
for (const num of [s02, s12, s22, s32]) {
|
|
23488
|
+
for (let bytePos = 0; bytePos < 4; bytePos++) {
|
|
23489
|
+
const byte = num >>> 8 * bytePos & 255;
|
|
23490
|
+
for (let bitPos = 8 / W10 - 1; bitPos >= 0; bitPos--) {
|
|
23491
|
+
const bit = byte >>> W10 * bitPos & mask;
|
|
23492
|
+
const { s0: e0, s1: e12, s2: e2, s3: e32 } = t10[w * windowSize + bit];
|
|
23493
|
+
o02 ^= e0, o12 ^= e12, o22 ^= e2, o32 ^= e32;
|
|
23494
|
+
w += 1;
|
|
23495
|
+
}
|
|
23496
|
+
}
|
|
23497
|
+
}
|
|
23498
|
+
this.s0 = o02;
|
|
23499
|
+
this.s1 = o12;
|
|
23500
|
+
this.s2 = o22;
|
|
23501
|
+
this.s3 = o32;
|
|
23502
|
+
}
|
|
23503
|
+
update(data2) {
|
|
23504
|
+
aexists(this);
|
|
23505
|
+
abytes(data2);
|
|
23506
|
+
data2 = copyBytes(data2);
|
|
23507
|
+
const b32 = u32(data2);
|
|
23508
|
+
const blocks = Math.floor(data2.length / BLOCK_SIZE$1);
|
|
23509
|
+
const left = data2.length % BLOCK_SIZE$1;
|
|
23510
|
+
for (let i10 = 0; i10 < blocks; i10++) {
|
|
23511
|
+
this._updateBlock(swap8IfBE(b32[i10 * 4 + 0]), swap8IfBE(b32[i10 * 4 + 1]), swap8IfBE(b32[i10 * 4 + 2]), swap8IfBE(b32[i10 * 4 + 3]));
|
|
23512
|
+
}
|
|
23513
|
+
if (left) {
|
|
23514
|
+
ZEROS16.set(data2.subarray(blocks * BLOCK_SIZE$1));
|
|
23515
|
+
this._updateBlock(swap8IfBE(ZEROS32[0]), swap8IfBE(ZEROS32[1]), swap8IfBE(ZEROS32[2]), swap8IfBE(ZEROS32[3]));
|
|
23516
|
+
clean(ZEROS32);
|
|
23517
|
+
}
|
|
23518
|
+
return this;
|
|
23519
|
+
}
|
|
23520
|
+
destroy() {
|
|
23521
|
+
this.destroyed = true;
|
|
23522
|
+
const { t: t10 } = this;
|
|
23523
|
+
for (const elm of t10) {
|
|
23524
|
+
elm.s0 = 0, elm.s1 = 0, elm.s2 = 0, elm.s3 = 0;
|
|
23525
|
+
}
|
|
23526
|
+
}
|
|
23527
|
+
digestInto(out) {
|
|
23528
|
+
aexists(this);
|
|
23529
|
+
aoutput32(out, this);
|
|
23530
|
+
this.finished = true;
|
|
23531
|
+
const { s0: s02, s1: s12, s2: s22, s3: s32 } = this;
|
|
23532
|
+
const o32 = u32(out);
|
|
23533
|
+
o32[0] = s02;
|
|
23534
|
+
o32[1] = s12;
|
|
23535
|
+
o32[2] = s22;
|
|
23536
|
+
o32[3] = s32;
|
|
23537
|
+
if (!isLE)
|
|
23538
|
+
swap32IfBE(o32.subarray(0, BLOCK_SIZE$1 / 4));
|
|
23539
|
+
}
|
|
23540
|
+
digest() {
|
|
23541
|
+
const res = new Uint8Array(BLOCK_SIZE$1);
|
|
23542
|
+
this.digestInto(res);
|
|
23543
|
+
this.destroy();
|
|
23544
|
+
return res;
|
|
23545
|
+
}
|
|
23546
|
+
}
|
|
23547
|
+
const BLOCK_SIZE = 16;
|
|
23548
|
+
const BLOCK_SIZE32 = 4;
|
|
23549
|
+
const EMPTY_BLOCK = /* @__PURE__ */ new Uint8Array(BLOCK_SIZE);
|
|
23550
|
+
const ONE_BLOCK = /* @__PURE__ */ Uint8Array.from([
|
|
23551
|
+
0,
|
|
23552
|
+
0,
|
|
23553
|
+
0,
|
|
23554
|
+
0,
|
|
23555
|
+
0,
|
|
23556
|
+
0,
|
|
23557
|
+
0,
|
|
23558
|
+
0,
|
|
23559
|
+
0,
|
|
23560
|
+
0,
|
|
23561
|
+
0,
|
|
23562
|
+
0,
|
|
23563
|
+
0,
|
|
23564
|
+
0,
|
|
23565
|
+
0,
|
|
23566
|
+
1
|
|
23567
|
+
]);
|
|
23568
|
+
const POLY = 283;
|
|
23569
|
+
function validateKeyLength(key) {
|
|
23570
|
+
if (![16, 24, 32].includes(key.length))
|
|
23571
|
+
throw new Error('"aes key" expected Uint8Array of length 16/24/32, got length=' + key.length);
|
|
23572
|
+
}
|
|
23573
|
+
function mul2(n8) {
|
|
23574
|
+
return n8 << 1 ^ POLY & -(n8 >> 7);
|
|
23575
|
+
}
|
|
23576
|
+
function mul(a, b) {
|
|
23577
|
+
let res = 0;
|
|
23578
|
+
for (; b > 0; b >>= 1) {
|
|
23579
|
+
res ^= a & -(b & 1);
|
|
23580
|
+
a = mul2(a);
|
|
23581
|
+
}
|
|
23582
|
+
return res;
|
|
23583
|
+
}
|
|
23584
|
+
const sbox = /* @__PURE__ */ (() => {
|
|
23585
|
+
const t10 = new Uint8Array(256);
|
|
23586
|
+
for (let i10 = 0, x = 1; i10 < 256; i10++, x ^= mul2(x))
|
|
23587
|
+
t10[i10] = x;
|
|
23588
|
+
const box = new Uint8Array(256);
|
|
23589
|
+
box[0] = 99;
|
|
23590
|
+
for (let i10 = 0; i10 < 255; i10++) {
|
|
23591
|
+
let x = t10[255 - i10];
|
|
23592
|
+
x |= x << 8;
|
|
23593
|
+
box[t10[i10]] = (x ^ x >> 4 ^ x >> 5 ^ x >> 6 ^ x >> 7 ^ 99) & 255;
|
|
23594
|
+
}
|
|
23595
|
+
clean(t10);
|
|
23596
|
+
return box;
|
|
23597
|
+
})();
|
|
23598
|
+
const invSbox = /* @__PURE__ */ sbox.map((_, j) => sbox.indexOf(j));
|
|
23599
|
+
const rotr32_8 = (n8) => n8 << 24 | n8 >>> 8;
|
|
23600
|
+
const rotl32_8 = (n8) => n8 << 8 | n8 >>> 24;
|
|
23601
|
+
function genTtable(sbox2, fn2) {
|
|
23602
|
+
if (sbox2.length !== 256)
|
|
23603
|
+
throw new Error("wrong sbox length");
|
|
23604
|
+
const T02 = new Uint32Array(256).map((_, j) => fn2(sbox2[j]));
|
|
23605
|
+
const T12 = T02.map(rotl32_8);
|
|
23606
|
+
const T22 = T12.map(rotl32_8);
|
|
23607
|
+
const T32 = T22.map(rotl32_8);
|
|
23608
|
+
const T01 = new Uint32Array(256 * 256);
|
|
23609
|
+
const T23 = new Uint32Array(256 * 256);
|
|
23610
|
+
const sbox22 = new Uint16Array(256 * 256);
|
|
23611
|
+
for (let i10 = 0; i10 < 256; i10++) {
|
|
23612
|
+
for (let j = 0; j < 256; j++) {
|
|
23613
|
+
const idx = i10 * 256 + j;
|
|
23614
|
+
T01[idx] = T02[i10] ^ T12[j];
|
|
23615
|
+
T23[idx] = T22[i10] ^ T32[j];
|
|
23616
|
+
sbox22[idx] = sbox2[i10] << 8 | sbox2[j];
|
|
23617
|
+
}
|
|
23618
|
+
}
|
|
23619
|
+
return { sbox: sbox2, sbox2: sbox22, T0: T02, T1: T12, T2: T22, T3: T32, T01, T23 };
|
|
23620
|
+
}
|
|
23621
|
+
const tableEncoding = /* @__PURE__ */ genTtable(sbox, (s10) => mul(s10, 3) << 24 | s10 << 16 | s10 << 8 | mul(s10, 2));
|
|
23622
|
+
const tableDecoding = /* @__PURE__ */ genTtable(invSbox, (s10) => mul(s10, 11) << 24 | mul(s10, 13) << 16 | mul(s10, 9) << 8 | mul(s10, 14));
|
|
23623
|
+
const xPowers = /* @__PURE__ */ (() => {
|
|
23624
|
+
const p = new Uint8Array(16);
|
|
23625
|
+
for (let i10 = 0, x = 1; i10 < 16; i10++, x = mul2(x))
|
|
23626
|
+
p[i10] = x;
|
|
23627
|
+
return p;
|
|
23628
|
+
})();
|
|
23629
|
+
function expandKeyLE(key) {
|
|
23630
|
+
abytes(key);
|
|
23631
|
+
const len2 = key.length;
|
|
23632
|
+
validateKeyLength(key);
|
|
23633
|
+
const { sbox2 } = tableEncoding;
|
|
23634
|
+
const toClean = [];
|
|
23635
|
+
if (!isLE || !isAligned32(key))
|
|
23636
|
+
toClean.push(key = copyBytes(key));
|
|
23637
|
+
const k32 = swap32IfBE(u32(key));
|
|
23638
|
+
const Nk = k32.length;
|
|
23639
|
+
const subByte = (n8) => applySbox(sbox2, n8, n8, n8, n8);
|
|
23640
|
+
const xk = new Uint32Array(len2 + 28);
|
|
23641
|
+
xk.set(k32);
|
|
23642
|
+
for (let i10 = Nk; i10 < xk.length; i10++) {
|
|
23643
|
+
let t10 = xk[i10 - 1];
|
|
23644
|
+
if (i10 % Nk === 0)
|
|
23645
|
+
t10 = subByte(rotr32_8(t10)) ^ xPowers[i10 / Nk - 1];
|
|
23646
|
+
else if (Nk > 6 && i10 % Nk === 4)
|
|
23647
|
+
t10 = subByte(t10);
|
|
23648
|
+
xk[i10] = xk[i10 - Nk] ^ t10;
|
|
23649
|
+
}
|
|
23650
|
+
clean(...toClean);
|
|
23651
|
+
return xk;
|
|
23652
|
+
}
|
|
23653
|
+
function expandKeyDecLE(key) {
|
|
23654
|
+
const encKey = expandKeyLE(key);
|
|
23655
|
+
const xk = encKey.slice();
|
|
23656
|
+
const Nk = encKey.length;
|
|
23657
|
+
const { sbox2 } = tableEncoding;
|
|
23658
|
+
const { T0: T02, T1: T12, T2: T22, T3: T32 } = tableDecoding;
|
|
23659
|
+
for (let i10 = 0; i10 < Nk; i10 += 4) {
|
|
23660
|
+
for (let j = 0; j < 4; j++)
|
|
23661
|
+
xk[i10 + j] = encKey[Nk - i10 - 4 + j];
|
|
23662
|
+
}
|
|
23663
|
+
clean(encKey);
|
|
23664
|
+
for (let i10 = 4; i10 < Nk - 4; i10++) {
|
|
23665
|
+
const x = xk[i10];
|
|
23666
|
+
const w = applySbox(sbox2, x, x, x, x);
|
|
23667
|
+
xk[i10] = T02[w & 255] ^ T12[w >>> 8 & 255] ^ T22[w >>> 16 & 255] ^ T32[w >>> 24];
|
|
23668
|
+
}
|
|
23669
|
+
return xk;
|
|
23670
|
+
}
|
|
23671
|
+
function apply0123(T01, T23, s02, s12, s22, s32) {
|
|
23672
|
+
return T01[s02 << 8 & 65280 | s12 >>> 8 & 255] ^ T23[s22 >>> 8 & 65280 | s32 >>> 24 & 255];
|
|
23673
|
+
}
|
|
23674
|
+
function applySbox(sbox2, s02, s12, s22, s32) {
|
|
23675
|
+
return sbox2[s02 & 255 | s12 & 65280] | sbox2[s22 >>> 16 & 255 | s32 >>> 16 & 65280] << 16;
|
|
23676
|
+
}
|
|
23677
|
+
function encrypt(xk, s02, s12, s22, s32) {
|
|
23678
|
+
const { sbox2, T01, T23 } = tableEncoding;
|
|
23679
|
+
let k10 = 0;
|
|
23680
|
+
s02 ^= xk[k10++], s12 ^= xk[k10++], s22 ^= xk[k10++], s32 ^= xk[k10++];
|
|
23681
|
+
const rounds = xk.length / 4 - 2;
|
|
23682
|
+
for (let i10 = 0; i10 < rounds; i10++) {
|
|
23683
|
+
const t03 = xk[k10++] ^ apply0123(T01, T23, s02, s12, s22, s32);
|
|
23684
|
+
const t13 = xk[k10++] ^ apply0123(T01, T23, s12, s22, s32, s02);
|
|
23685
|
+
const t23 = xk[k10++] ^ apply0123(T01, T23, s22, s32, s02, s12);
|
|
23686
|
+
const t33 = xk[k10++] ^ apply0123(T01, T23, s32, s02, s12, s22);
|
|
23687
|
+
s02 = t03, s12 = t13, s22 = t23, s32 = t33;
|
|
23688
|
+
}
|
|
23689
|
+
const t02 = xk[k10++] ^ applySbox(sbox2, s02, s12, s22, s32);
|
|
23690
|
+
const t12 = xk[k10++] ^ applySbox(sbox2, s12, s22, s32, s02);
|
|
23691
|
+
const t22 = xk[k10++] ^ applySbox(sbox2, s22, s32, s02, s12);
|
|
23692
|
+
const t32 = xk[k10++] ^ applySbox(sbox2, s32, s02, s12, s22);
|
|
23693
|
+
return { s0: t02, s1: t12, s2: t22, s3: t32 };
|
|
23694
|
+
}
|
|
23695
|
+
function decrypt(xk, s02, s12, s22, s32) {
|
|
23696
|
+
const { sbox2, T01, T23 } = tableDecoding;
|
|
23697
|
+
let k10 = 0;
|
|
23698
|
+
s02 ^= xk[k10++], s12 ^= xk[k10++], s22 ^= xk[k10++], s32 ^= xk[k10++];
|
|
23699
|
+
const rounds = xk.length / 4 - 2;
|
|
23700
|
+
for (let i10 = 0; i10 < rounds; i10++) {
|
|
23701
|
+
const t03 = xk[k10++] ^ apply0123(T01, T23, s02, s32, s22, s12);
|
|
23702
|
+
const t13 = xk[k10++] ^ apply0123(T01, T23, s12, s02, s32, s22);
|
|
23703
|
+
const t23 = xk[k10++] ^ apply0123(T01, T23, s22, s12, s02, s32);
|
|
23704
|
+
const t33 = xk[k10++] ^ apply0123(T01, T23, s32, s22, s12, s02);
|
|
23705
|
+
s02 = t03, s12 = t13, s22 = t23, s32 = t33;
|
|
23706
|
+
}
|
|
23707
|
+
const t02 = xk[k10++] ^ applySbox(sbox2, s02, s32, s22, s12);
|
|
23708
|
+
const t12 = xk[k10++] ^ applySbox(sbox2, s12, s02, s32, s22);
|
|
23709
|
+
const t22 = xk[k10++] ^ applySbox(sbox2, s22, s12, s02, s32);
|
|
23710
|
+
const t32 = xk[k10++] ^ applySbox(sbox2, s32, s22, s12, s02);
|
|
23711
|
+
return { s0: t02, s1: t12, s2: t22, s3: t32 };
|
|
23712
|
+
}
|
|
23713
|
+
function ctrCounter(xk, nonce, src, dst) {
|
|
23714
|
+
abytes(nonce, BLOCK_SIZE, "nonce");
|
|
23715
|
+
abytes(src);
|
|
23716
|
+
const srcLen = src.length;
|
|
23717
|
+
dst = getOutput(srcLen, dst);
|
|
23718
|
+
complexOverlapBytes(src, dst);
|
|
23719
|
+
const ctr = nonce;
|
|
23720
|
+
const c32 = u32(ctr);
|
|
23721
|
+
const src32 = u32(src);
|
|
23722
|
+
const dst32 = u32(dst);
|
|
23723
|
+
for (let i10 = 0; i10 + 4 <= src32.length; i10 += 4) {
|
|
23724
|
+
const { s0: s02, s1: s12, s2: s22, s3: s32 } = encrypt(xk, swap8IfBE(c32[0]), swap8IfBE(c32[1]), swap8IfBE(c32[2]), swap8IfBE(c32[3]));
|
|
23725
|
+
dst32[i10 + 0] = src32[i10 + 0] ^ swap8IfBE(s02);
|
|
23726
|
+
dst32[i10 + 1] = src32[i10 + 1] ^ swap8IfBE(s12);
|
|
23727
|
+
dst32[i10 + 2] = src32[i10 + 2] ^ swap8IfBE(s22);
|
|
23728
|
+
dst32[i10 + 3] = src32[i10 + 3] ^ swap8IfBE(s32);
|
|
23729
|
+
for (let j = BLOCK_SIZE - 1, carry = 1; j >= 0; j--) {
|
|
23730
|
+
carry = carry + ctr[j] | 0;
|
|
23731
|
+
ctr[j] = carry & 255;
|
|
23732
|
+
carry >>>= 8;
|
|
23733
|
+
}
|
|
23734
|
+
}
|
|
23735
|
+
const start = BLOCK_SIZE * Math.floor(src32.length / BLOCK_SIZE32);
|
|
23736
|
+
if (start < srcLen) {
|
|
23737
|
+
const { s0: s02, s1: s12, s2: s22, s3: s32 } = encrypt(xk, swap8IfBE(c32[0]), swap8IfBE(c32[1]), swap8IfBE(c32[2]), swap8IfBE(c32[3]));
|
|
23738
|
+
const b32 = new Uint32Array([s02, s12, s22, s32]);
|
|
23739
|
+
swap32IfBE(b32);
|
|
23740
|
+
const buf = u8$1(b32);
|
|
23741
|
+
for (let i10 = start, pos = 0; i10 < srcLen; i10++, pos++)
|
|
23742
|
+
dst[i10] = src[i10] ^ buf[pos];
|
|
23743
|
+
clean(b32);
|
|
23744
|
+
}
|
|
23745
|
+
return dst;
|
|
23746
|
+
}
|
|
23747
|
+
function ctr32(xk, isLE2, nonce, src, dst) {
|
|
23748
|
+
abytes(nonce, BLOCK_SIZE, "nonce");
|
|
23749
|
+
abytes(src);
|
|
23750
|
+
dst = getOutput(src.length, dst);
|
|
23751
|
+
const ctr = nonce;
|
|
23752
|
+
const c32 = u32(ctr);
|
|
23753
|
+
const view = createView(ctr);
|
|
23754
|
+
const src32 = u32(src);
|
|
23755
|
+
const dst32 = u32(dst);
|
|
23756
|
+
const ctrPos = isLE2 ? 0 : 12;
|
|
23757
|
+
const srcLen = src.length;
|
|
23758
|
+
let ctrNum = view.getUint32(ctrPos, isLE2);
|
|
23759
|
+
for (let i10 = 0; i10 + 4 <= src32.length; i10 += 4) {
|
|
23760
|
+
const { s0: s02, s1: s12, s2: s22, s3: s32 } = encrypt(xk, swap8IfBE(c32[0]), swap8IfBE(c32[1]), swap8IfBE(c32[2]), swap8IfBE(c32[3]));
|
|
23761
|
+
dst32[i10 + 0] = src32[i10 + 0] ^ swap8IfBE(s02);
|
|
23762
|
+
dst32[i10 + 1] = src32[i10 + 1] ^ swap8IfBE(s12);
|
|
23763
|
+
dst32[i10 + 2] = src32[i10 + 2] ^ swap8IfBE(s22);
|
|
23764
|
+
dst32[i10 + 3] = src32[i10 + 3] ^ swap8IfBE(s32);
|
|
23765
|
+
ctrNum = ctrNum + 1 >>> 0;
|
|
23766
|
+
view.setUint32(ctrPos, ctrNum, isLE2);
|
|
23767
|
+
}
|
|
23768
|
+
const start = BLOCK_SIZE * Math.floor(src32.length / BLOCK_SIZE32);
|
|
23769
|
+
if (start < srcLen) {
|
|
23770
|
+
const { s0: s02, s1: s12, s2: s22, s3: s32 } = encrypt(xk, swap8IfBE(c32[0]), swap8IfBE(c32[1]), swap8IfBE(c32[2]), swap8IfBE(c32[3]));
|
|
23771
|
+
const b32 = new Uint32Array([s02, s12, s22, s32]);
|
|
23772
|
+
swap32IfBE(b32);
|
|
23773
|
+
const buf = u8$1(b32);
|
|
23774
|
+
for (let i10 = start, pos = 0; i10 < srcLen; i10++, pos++)
|
|
23775
|
+
dst[i10] = src[i10] ^ buf[pos];
|
|
23776
|
+
clean(b32);
|
|
23777
|
+
}
|
|
23778
|
+
return dst;
|
|
23779
|
+
}
|
|
23780
|
+
function isBytes32(a) {
|
|
23781
|
+
return a instanceof Uint32Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint32Array";
|
|
23782
|
+
}
|
|
23783
|
+
function encryptBlock(xk, block) {
|
|
23784
|
+
abytes(block, 16, "block");
|
|
23785
|
+
if (!isBytes32(xk))
|
|
23786
|
+
throw new Error("_encryptBlock accepts result of expandKeyLE");
|
|
23787
|
+
const b32 = u32(block);
|
|
23788
|
+
swap32IfBE(b32);
|
|
23789
|
+
let { s0: s02, s1: s12, s2: s22, s3: s32 } = encrypt(xk, b32[0], b32[1], b32[2], b32[3]);
|
|
23790
|
+
b32[0] = s02, b32[1] = s12, b32[2] = s22, b32[3] = s32;
|
|
23791
|
+
swap32IfBE(b32);
|
|
23792
|
+
return block;
|
|
23793
|
+
}
|
|
23794
|
+
function decryptBlock(xk, block) {
|
|
23795
|
+
abytes(block, 16, "block");
|
|
23796
|
+
if (!isBytes32(xk))
|
|
23797
|
+
throw new Error("_decryptBlock accepts result of expandKeyLE");
|
|
23798
|
+
const b32 = u32(block);
|
|
23799
|
+
swap32IfBE(b32);
|
|
23800
|
+
let { s0: s02, s1: s12, s2: s22, s3: s32 } = decrypt(xk, b32[0], b32[1], b32[2], b32[3]);
|
|
23801
|
+
b32[0] = s02, b32[1] = s12, b32[2] = s22, b32[3] = s32;
|
|
23802
|
+
swap32IfBE(b32);
|
|
23803
|
+
return block;
|
|
23804
|
+
}
|
|
23805
|
+
function dbl(block) {
|
|
23806
|
+
let carry = 0;
|
|
23807
|
+
for (let i10 = BLOCK_SIZE - 1; i10 >= 0; i10--) {
|
|
23808
|
+
const newCarry = (block[i10] & 128) >>> 7;
|
|
23809
|
+
block[i10] = block[i10] << 1 | carry;
|
|
23810
|
+
carry = newCarry;
|
|
23811
|
+
}
|
|
23812
|
+
block[BLOCK_SIZE - 1] ^= 135 & -carry;
|
|
23813
|
+
return block;
|
|
23814
|
+
}
|
|
23815
|
+
function xorBlock(a, b) {
|
|
23816
|
+
if (a.length !== b.length)
|
|
23817
|
+
throw new Error("xorBlock: blocks must have same length");
|
|
23818
|
+
for (let i10 = 0; i10 < a.length; i10++) {
|
|
23819
|
+
a[i10] = a[i10] ^ b[i10];
|
|
23820
|
+
}
|
|
23821
|
+
return a;
|
|
23822
|
+
}
|
|
23823
|
+
function xorend(a, b) {
|
|
23824
|
+
if (b.length > a.length) {
|
|
23825
|
+
throw new Error("xorend: expected len(B) <= len(A)");
|
|
23826
|
+
}
|
|
23827
|
+
const offset2 = a.length - b.length;
|
|
23828
|
+
for (let i10 = 0; i10 < b.length; i10++) {
|
|
23829
|
+
a[offset2 + i10] = a[offset2 + i10] ^ b[i10];
|
|
23830
|
+
}
|
|
23831
|
+
return a;
|
|
23832
|
+
}
|
|
23833
|
+
class _CMAC {
|
|
23834
|
+
constructor(key) {
|
|
23835
|
+
__publicField(this, "blockLen", BLOCK_SIZE);
|
|
23836
|
+
__publicField(this, "outputLen", BLOCK_SIZE);
|
|
23837
|
+
// CMAC can only decide between `K1` and `K2` once the true final block is known,
|
|
23838
|
+
// so updates process older blocks eagerly but keep one pending block buffered.
|
|
23839
|
+
__publicField(this, "buffer");
|
|
23840
|
+
__publicField(this, "pos");
|
|
23841
|
+
__publicField(this, "finished");
|
|
23842
|
+
__publicField(this, "destroyed");
|
|
23843
|
+
__publicField(this, "k1");
|
|
23844
|
+
__publicField(this, "k2");
|
|
23845
|
+
__publicField(this, "x");
|
|
23846
|
+
__publicField(this, "x32");
|
|
23847
|
+
__publicField(this, "xk");
|
|
23848
|
+
abytes(key);
|
|
23849
|
+
validateKeyLength(key);
|
|
23850
|
+
this.xk = expandKeyLE(key);
|
|
23851
|
+
this.buffer = new Uint8Array(BLOCK_SIZE);
|
|
23852
|
+
this.pos = 0;
|
|
23853
|
+
this.finished = false;
|
|
23854
|
+
this.destroyed = false;
|
|
23855
|
+
this.x = new Uint8Array(BLOCK_SIZE);
|
|
23856
|
+
this.x32 = u32(this.x);
|
|
23857
|
+
const L = new Uint8Array(BLOCK_SIZE);
|
|
23858
|
+
encryptBlock(this.xk, L);
|
|
23859
|
+
this.k1 = dbl(L);
|
|
23860
|
+
this.k2 = dbl(new Uint8Array(this.k1));
|
|
23861
|
+
}
|
|
23862
|
+
// Consumes 16 bytes of `data` starting at `pos`; `pos` avoids a per-block
|
|
23863
|
+
// subarray view allocation in update().
|
|
23864
|
+
process(data2, pos) {
|
|
23865
|
+
const { x, x32, xk } = this;
|
|
23866
|
+
for (let i10 = 0; i10 < BLOCK_SIZE; i10++)
|
|
23867
|
+
x[i10] ^= data2[pos + i10];
|
|
23868
|
+
swap32IfBE(x32);
|
|
23869
|
+
const { s0: s02, s1: s12, s2: s22, s3: s32 } = encrypt(xk, x32[0], x32[1], x32[2], x32[3]);
|
|
23870
|
+
x32[0] = s02, x32[1] = s12, x32[2] = s22, x32[3] = s32;
|
|
23871
|
+
swap32IfBE(x32);
|
|
23872
|
+
}
|
|
23873
|
+
update(data2) {
|
|
23874
|
+
aexists(this);
|
|
23875
|
+
abytes(data2);
|
|
23876
|
+
let pos = 0;
|
|
23877
|
+
if (this.pos) {
|
|
23878
|
+
const take = Math.min(BLOCK_SIZE - this.pos, data2.length);
|
|
23879
|
+
this.buffer.set(data2.subarray(0, take), this.pos);
|
|
23880
|
+
this.pos += take;
|
|
23881
|
+
pos = take;
|
|
23882
|
+
if (this.pos === BLOCK_SIZE && pos < data2.length) {
|
|
23883
|
+
this.process(this.buffer, 0);
|
|
23884
|
+
this.pos = 0;
|
|
23885
|
+
}
|
|
23886
|
+
}
|
|
23887
|
+
while (pos + BLOCK_SIZE < data2.length) {
|
|
23888
|
+
this.process(data2, pos);
|
|
23889
|
+
pos += BLOCK_SIZE;
|
|
23890
|
+
}
|
|
23891
|
+
if (pos < data2.length) {
|
|
23892
|
+
this.buffer.set(data2.subarray(pos), 0);
|
|
23893
|
+
this.pos = data2.length - pos;
|
|
23894
|
+
}
|
|
23895
|
+
return this;
|
|
23896
|
+
}
|
|
23897
|
+
// See {@link https://www.rfc-editor.org/rfc/rfc4493.html#section-2.4 | RFC 4493 Section 2.4}.
|
|
23898
|
+
digestInto(out) {
|
|
23899
|
+
aexists(this);
|
|
23900
|
+
aoutput32(out, this);
|
|
23901
|
+
this.finished = true;
|
|
23902
|
+
const view = out.subarray(0, this.outputLen);
|
|
23903
|
+
let last = new Uint8Array(BLOCK_SIZE);
|
|
23904
|
+
if (this.pos === BLOCK_SIZE) {
|
|
23905
|
+
last.set(this.buffer);
|
|
23906
|
+
xorBlock(last, this.k1);
|
|
23907
|
+
} else {
|
|
23908
|
+
last.set(this.buffer.subarray(0, this.pos));
|
|
23909
|
+
last[this.pos] = 128;
|
|
23910
|
+
xorBlock(last, this.k2);
|
|
23911
|
+
}
|
|
23912
|
+
view.set(this.x);
|
|
23913
|
+
xorBlock(view, last);
|
|
23914
|
+
encryptBlock(this.xk, view);
|
|
23915
|
+
clean(last);
|
|
23916
|
+
}
|
|
23917
|
+
digest() {
|
|
23918
|
+
const { buffer: buffer2, outputLen } = this;
|
|
23919
|
+
this.digestInto(buffer2);
|
|
23920
|
+
const res = buffer2.slice(0, outputLen);
|
|
23921
|
+
this.destroy();
|
|
23922
|
+
return res;
|
|
23923
|
+
}
|
|
23924
|
+
destroy() {
|
|
23925
|
+
const { buffer: buffer2, destroyed, x, xk, k1: k12, k2: k22 } = this;
|
|
23926
|
+
if (destroyed)
|
|
23927
|
+
return;
|
|
23928
|
+
this.destroyed = true;
|
|
23929
|
+
clean(buffer2, x, xk, k12, k22);
|
|
23930
|
+
}
|
|
23931
|
+
}
|
|
23932
|
+
const cmac = /* @__PURE__ */ wrapMacConstructor(16, (key) => new _CMAC(key));
|
|
23933
|
+
function s2v(key, strings2) {
|
|
23934
|
+
validateKeyLength(key);
|
|
23935
|
+
const len2 = strings2.length;
|
|
23936
|
+
if (len2 > 127) {
|
|
23937
|
+
throw new Error("s2v: expected <= 127 inputs");
|
|
23938
|
+
}
|
|
23939
|
+
if (len2 === 0)
|
|
23940
|
+
return cmac(ONE_BLOCK, key);
|
|
23941
|
+
let d = cmac(EMPTY_BLOCK, key);
|
|
23942
|
+
for (let i10 = 0; i10 < len2 - 1; i10++) {
|
|
23943
|
+
dbl(d);
|
|
23944
|
+
const cmacResult = cmac(strings2[i10], key);
|
|
23945
|
+
xorBlock(d, cmacResult);
|
|
23946
|
+
clean(cmacResult);
|
|
23947
|
+
}
|
|
23948
|
+
const s_n = strings2[len2 - 1];
|
|
23949
|
+
abytes(s_n);
|
|
23950
|
+
let t10;
|
|
23951
|
+
if (s_n.byteLength >= BLOCK_SIZE) {
|
|
23952
|
+
t10 = xorend(Uint8Array.from(s_n), d);
|
|
23953
|
+
} else {
|
|
23954
|
+
const paddedSn = new Uint8Array(BLOCK_SIZE);
|
|
23955
|
+
paddedSn.set(s_n);
|
|
23956
|
+
paddedSn[s_n.length] = 128;
|
|
23957
|
+
t10 = xorBlock(dbl(d), paddedSn);
|
|
23958
|
+
clean(paddedSn);
|
|
23959
|
+
}
|
|
23960
|
+
const result = cmac(t10, key);
|
|
23961
|
+
clean(d, t10);
|
|
23962
|
+
return result;
|
|
23963
|
+
}
|
|
23964
|
+
const unsafe = /* @__PURE__ */ Object.freeze({
|
|
23965
|
+
expandKeyLE,
|
|
23966
|
+
expandKeyDecLE,
|
|
23967
|
+
encrypt,
|
|
23968
|
+
decrypt,
|
|
23969
|
+
encryptBlock,
|
|
23970
|
+
decryptBlock,
|
|
23971
|
+
ctrCounter,
|
|
23972
|
+
ctr32,
|
|
23973
|
+
dbl,
|
|
23974
|
+
xorBlock,
|
|
23975
|
+
xorend,
|
|
23976
|
+
s2v
|
|
23977
|
+
});
|
|
23978
|
+
const CIPHERS = /^aes-(128|192|256)-(gcm|cbc|ctr|ecb)$/u;
|
|
23979
|
+
function cipherNames() {
|
|
23980
|
+
const names2 = [];
|
|
23981
|
+
for (const bits of [128, 192, 256]) for (const mode of ["cbc", "ctr", "ecb", "gcm"]) names2.push(`aes-${bits}-${mode}`);
|
|
23982
|
+
return names2;
|
|
23983
|
+
}
|
|
23984
|
+
const GCM_TAG_LENGTHS = /* @__PURE__ */ new Set([4, 8, 12, 13, 14, 15, 16]);
|
|
23985
|
+
function createCipherClasses(deps) {
|
|
23986
|
+
var _decrypt, _mode, _xk, _xkDec, _padding, _finished, _started, _pending, _chain, _counter, _keystream, _ghash, _tagMask, _ghashPending, _aadLength, _dataLength, _authTagLength, _authTag, _CipherBase_instances, getTag_fn, setTag_fn, process_fn, stream_fn, absorb_fn, blocks_fn, block_fn, finish_fn, finishGcm_fn;
|
|
23987
|
+
const { error } = deps;
|
|
23988
|
+
function parse4(algorithm) {
|
|
23989
|
+
if (typeof algorithm !== "string") throw Object.assign(new TypeError('The "cipher" argument must be of type string.'), { code: "ERR_INVALID_ARG_TYPE" });
|
|
23990
|
+
const match2 = CIPHERS.exec(algorithm.toLowerCase());
|
|
23991
|
+
if (!match2) throw error("ERR_CRYPTO_UNKNOWN_CIPHER", "Unknown cipher");
|
|
23992
|
+
return { keyLength: Number(match2[1]) / 8, mode: match2[2] };
|
|
23993
|
+
}
|
|
23994
|
+
function keyOf(key, keyLength) {
|
|
23995
|
+
const bytes2 = deps.secretKeyBytes(key) ?? deps.bytesOf(key);
|
|
23996
|
+
if (bytes2.length !== keyLength) throw Object.assign(new RangeError("Invalid key length"), { code: "ERR_CRYPTO_INVALID_KEYLEN" });
|
|
23997
|
+
return new Uint8Array(bytes2);
|
|
23998
|
+
}
|
|
23999
|
+
function ivOf(iv2, mode) {
|
|
24000
|
+
if (mode === "ecb") {
|
|
24001
|
+
if (iv2 === null || iv2 === void 0) return void 0;
|
|
24002
|
+
const bytes22 = deps.bytesOf(iv2);
|
|
24003
|
+
if (bytes22.length !== 0) throw Object.assign(new TypeError("Invalid initialization vector"), { code: "ERR_CRYPTO_INVALID_IV" });
|
|
24004
|
+
return void 0;
|
|
24005
|
+
}
|
|
24006
|
+
if (iv2 === null || iv2 === void 0) throw Object.assign(new TypeError("Invalid initialization vector"), { code: "ERR_CRYPTO_INVALID_IV" });
|
|
24007
|
+
const bytes2 = new Uint8Array(deps.bytesOf(iv2));
|
|
24008
|
+
if (mode === "gcm" ? bytes2.length === 0 : bytes2.length !== 16) throw Object.assign(new TypeError("Invalid initialization vector"), { code: "ERR_CRYPTO_INVALID_IV" });
|
|
24009
|
+
return bytes2;
|
|
24010
|
+
}
|
|
24011
|
+
function encryptBlock2(xk, block) {
|
|
24012
|
+
const out = new Uint8Array(16);
|
|
24013
|
+
out.set(block);
|
|
24014
|
+
return unsafe.encryptBlock(xk, out);
|
|
24015
|
+
}
|
|
24016
|
+
function decryptBlock2(xk, block) {
|
|
24017
|
+
const out = new Uint8Array(16);
|
|
24018
|
+
out.set(block);
|
|
24019
|
+
return unsafe.decryptBlock(xk, out);
|
|
24020
|
+
}
|
|
24021
|
+
function concat(a, b) {
|
|
24022
|
+
if (a.length === 0) return b;
|
|
24023
|
+
if (b.length === 0) return a;
|
|
24024
|
+
const out = new Uint8Array(a.length + b.length);
|
|
24025
|
+
out.set(a);
|
|
24026
|
+
out.set(b, a.length);
|
|
24027
|
+
return out;
|
|
24028
|
+
}
|
|
24029
|
+
function increment(counter, from) {
|
|
24030
|
+
for (let i10 = 15; i10 >= from; i10--) {
|
|
24031
|
+
counter[i10] = counter[i10] + 1 & 255;
|
|
24032
|
+
if (counter[i10] !== 0) return;
|
|
24033
|
+
}
|
|
24034
|
+
}
|
|
24035
|
+
let authTagOf;
|
|
24036
|
+
let expectTagOf;
|
|
24037
|
+
class CipherBase {
|
|
24038
|
+
constructor(decrypt2, algorithm, key, iv2, options) {
|
|
24039
|
+
__privateAdd(this, _CipherBase_instances);
|
|
24040
|
+
__privateAdd(this, _decrypt);
|
|
24041
|
+
__privateAdd(this, _mode);
|
|
24042
|
+
__privateAdd(this, _xk);
|
|
24043
|
+
__privateAdd(this, _xkDec);
|
|
24044
|
+
__privateAdd(this, _padding, true);
|
|
24045
|
+
__privateAdd(this, _finished, false);
|
|
24046
|
+
__privateAdd(this, _started, false);
|
|
24047
|
+
/** CBC/ECB: bytes not yet a whole block (and, decrypting with padding, the last whole block). */
|
|
24048
|
+
__privateAdd(this, _pending, new Uint8Array(0));
|
|
24049
|
+
/** CBC's chaining block. */
|
|
24050
|
+
__privateAdd(this, _chain);
|
|
24051
|
+
/** CTR/GCM: the next counter block and what is left of the current keystream block. */
|
|
24052
|
+
__privateAdd(this, _counter);
|
|
24053
|
+
__privateAdd(this, _keystream, new Uint8Array(0));
|
|
24054
|
+
/** GCM. */
|
|
24055
|
+
__privateAdd(this, _ghash);
|
|
24056
|
+
__privateAdd(this, _tagMask);
|
|
24057
|
+
__privateAdd(this, _ghashPending, new Uint8Array(0));
|
|
24058
|
+
__privateAdd(this, _aadLength, 0);
|
|
24059
|
+
__privateAdd(this, _dataLength, 0);
|
|
24060
|
+
__privateAdd(this, _authTagLength);
|
|
24061
|
+
__privateAdd(this, _authTag);
|
|
24062
|
+
const { keyLength, mode } = parse4(algorithm);
|
|
24063
|
+
__privateSet(this, _decrypt, decrypt2);
|
|
24064
|
+
__privateSet(this, _mode, mode);
|
|
24065
|
+
const keyBytes = keyOf(key, keyLength);
|
|
24066
|
+
const ivBytes = ivOf(iv2, mode);
|
|
24067
|
+
__privateSet(this, _xk, unsafe.expandKeyLE(keyBytes));
|
|
24068
|
+
__privateSet(this, _xkDec, decrypt2 && (mode === "cbc" || mode === "ecb") ? unsafe.expandKeyDecLE(keyBytes) : void 0);
|
|
24069
|
+
const tagLength = options == null ? void 0 : options.authTagLength;
|
|
24070
|
+
if (tagLength !== void 0) {
|
|
24071
|
+
if (mode !== "gcm") throw Object.assign(new TypeError(`Invalid authentication tag length: ${tagLength}`), { code: "ERR_CRYPTO_INVALID_AUTH_TAG" });
|
|
24072
|
+
if (!GCM_TAG_LENGTHS.has(tagLength)) throw Object.assign(new TypeError(`Invalid authentication tag length: ${tagLength}`), { code: "ERR_CRYPTO_INVALID_AUTH_TAG" });
|
|
24073
|
+
__privateSet(this, _authTagLength, tagLength);
|
|
24074
|
+
}
|
|
24075
|
+
if (mode === "cbc") __privateSet(this, _chain, ivBytes);
|
|
24076
|
+
if (mode === "ctr") __privateSet(this, _counter, new Uint8Array(ivBytes));
|
|
24077
|
+
if (mode === "gcm") {
|
|
24078
|
+
const h = encryptBlock2(__privateGet(this, _xk), new Uint8Array(16));
|
|
24079
|
+
let j02;
|
|
24080
|
+
if (ivBytes.length === 12) {
|
|
24081
|
+
j02 = new Uint8Array(16);
|
|
24082
|
+
j02.set(ivBytes);
|
|
24083
|
+
j02[15] = 1;
|
|
24084
|
+
} else {
|
|
24085
|
+
const lengths = new Uint8Array(16);
|
|
24086
|
+
new DataView(lengths.buffer).setBigUint64(8, BigInt(ivBytes.length * 8), false);
|
|
24087
|
+
const g = new GHASH(h);
|
|
24088
|
+
g.update(ivBytes).update(lengths);
|
|
24089
|
+
j02 = g.digest();
|
|
24090
|
+
}
|
|
24091
|
+
__privateSet(this, _tagMask, encryptBlock2(__privateGet(this, _xk), j02));
|
|
24092
|
+
__privateSet(this, _counter, new Uint8Array(j02));
|
|
24093
|
+
increment(__privateGet(this, _counter), 12);
|
|
24094
|
+
__privateSet(this, _ghash, new GHASH(h));
|
|
24095
|
+
}
|
|
24096
|
+
}
|
|
24097
|
+
setAutoPadding(autoPadding = true) {
|
|
24098
|
+
if (__privateGet(this, _finished)) throw error("ERR_CRYPTO_INVALID_STATE", "Invalid state for operation setAutoPadding");
|
|
24099
|
+
__privateSet(this, _padding, Boolean(autoPadding));
|
|
24100
|
+
return this;
|
|
24101
|
+
}
|
|
24102
|
+
setAAD(buffer2, _options3) {
|
|
24103
|
+
if (__privateGet(this, _mode) !== "gcm" || __privateGet(this, _started) || __privateGet(this, _finished)) throw error("ERR_CRYPTO_INVALID_STATE", "Invalid state for operation setAAD");
|
|
24104
|
+
const aad = deps.bytesOf(buffer2);
|
|
24105
|
+
__privateGet(this, _ghash).update(aad);
|
|
24106
|
+
__privateSet(this, _aadLength, __privateGet(this, _aadLength) + aad.length);
|
|
24107
|
+
return this;
|
|
24108
|
+
}
|
|
24109
|
+
update(data2, inputEncoding, outputEncoding) {
|
|
24110
|
+
if (__privateGet(this, _finished)) throw error("ERR_CRYPTO_INVALID_STATE", "Invalid state for operation update");
|
|
24111
|
+
__privateSet(this, _started, true);
|
|
24112
|
+
const input = typeof data2 === "string" ? deps.bytesOf(data2, inputEncoding) : deps.bytesOf(data2);
|
|
24113
|
+
return deps.encode(__privateMethod(this, _CipherBase_instances, process_fn).call(this, new Uint8Array(input)), outputEncoding);
|
|
24114
|
+
}
|
|
24115
|
+
final(outputEncoding) {
|
|
24116
|
+
if (__privateGet(this, _finished)) throw error("ERR_CRYPTO_INVALID_STATE", "Unsupported state");
|
|
24117
|
+
__privateSet(this, _finished, true);
|
|
24118
|
+
return deps.encode(__privateMethod(this, _CipherBase_instances, finish_fn).call(this), outputEncoding);
|
|
24119
|
+
}
|
|
24120
|
+
}
|
|
24121
|
+
_decrypt = new WeakMap();
|
|
24122
|
+
_mode = new WeakMap();
|
|
24123
|
+
_xk = new WeakMap();
|
|
24124
|
+
_xkDec = new WeakMap();
|
|
24125
|
+
_padding = new WeakMap();
|
|
24126
|
+
_finished = new WeakMap();
|
|
24127
|
+
_started = new WeakMap();
|
|
24128
|
+
_pending = new WeakMap();
|
|
24129
|
+
_chain = new WeakMap();
|
|
24130
|
+
_counter = new WeakMap();
|
|
24131
|
+
_keystream = new WeakMap();
|
|
24132
|
+
_ghash = new WeakMap();
|
|
24133
|
+
_tagMask = new WeakMap();
|
|
24134
|
+
_ghashPending = new WeakMap();
|
|
24135
|
+
_aadLength = new WeakMap();
|
|
24136
|
+
_dataLength = new WeakMap();
|
|
24137
|
+
_authTagLength = new WeakMap();
|
|
24138
|
+
_authTag = new WeakMap();
|
|
24139
|
+
_CipherBase_instances = new WeakSet();
|
|
24140
|
+
getTag_fn = function() {
|
|
24141
|
+
if (__privateGet(this, _mode) !== "gcm" || __privateGet(this, _decrypt) || !__privateGet(this, _finished) || !__privateGet(this, _authTag)) throw error("ERR_CRYPTO_INVALID_STATE", "Invalid state for operation getAuthTag");
|
|
24142
|
+
return __privateGet(this, _authTag);
|
|
24143
|
+
};
|
|
24144
|
+
setTag_fn = function(tag, encoding) {
|
|
24145
|
+
if (__privateGet(this, _mode) !== "gcm" || !__privateGet(this, _decrypt) || __privateGet(this, _finished)) throw error("ERR_CRYPTO_INVALID_STATE", "Invalid state for operation setAuthTag");
|
|
24146
|
+
const bytes2 = new Uint8Array(typeof tag === "string" ? deps.bytesOf(tag, encoding) : deps.bytesOf(tag));
|
|
24147
|
+
const allowed = __privateGet(this, _authTagLength) === void 0 ? GCM_TAG_LENGTHS.has(bytes2.length) : bytes2.length === __privateGet(this, _authTagLength);
|
|
24148
|
+
if (!allowed) throw Object.assign(new TypeError(`Invalid authentication tag length: ${bytes2.length}`), { code: "ERR_CRYPTO_INVALID_AUTH_TAG" });
|
|
24149
|
+
__privateSet(this, _authTag, bytes2);
|
|
24150
|
+
};
|
|
24151
|
+
process_fn = function(input) {
|
|
24152
|
+
switch (__privateGet(this, _mode)) {
|
|
24153
|
+
case "ctr":
|
|
24154
|
+
return __privateMethod(this, _CipherBase_instances, stream_fn).call(this, input);
|
|
24155
|
+
case "gcm": {
|
|
24156
|
+
if (__privateGet(this, _decrypt)) __privateMethod(this, _CipherBase_instances, absorb_fn).call(this, input);
|
|
24157
|
+
const out = __privateMethod(this, _CipherBase_instances, stream_fn).call(this, input);
|
|
24158
|
+
if (!__privateGet(this, _decrypt)) __privateMethod(this, _CipherBase_instances, absorb_fn).call(this, out);
|
|
24159
|
+
__privateSet(this, _dataLength, __privateGet(this, _dataLength) + input.length);
|
|
24160
|
+
return out;
|
|
24161
|
+
}
|
|
24162
|
+
default:
|
|
24163
|
+
return __privateMethod(this, _CipherBase_instances, blocks_fn).call(this, input);
|
|
24164
|
+
}
|
|
24165
|
+
};
|
|
24166
|
+
/** XOR with the counter's keystream, carrying a partial block across calls. */
|
|
24167
|
+
stream_fn = function(input) {
|
|
24168
|
+
const out = new Uint8Array(input.length);
|
|
24169
|
+
let at3 = 0;
|
|
24170
|
+
while (at3 < input.length) {
|
|
24171
|
+
if (__privateGet(this, _keystream).length === 0) {
|
|
24172
|
+
__privateSet(this, _keystream, encryptBlock2(__privateGet(this, _xk), __privateGet(this, _counter)));
|
|
24173
|
+
increment(__privateGet(this, _counter), __privateGet(this, _mode) === "gcm" ? 12 : 0);
|
|
24174
|
+
}
|
|
24175
|
+
const take = Math.min(__privateGet(this, _keystream).length, input.length - at3);
|
|
24176
|
+
for (let i10 = 0; i10 < take; i10++) out[at3 + i10] = input[at3 + i10] ^ __privateGet(this, _keystream)[i10];
|
|
24177
|
+
__privateSet(this, _keystream, __privateGet(this, _keystream).subarray(take));
|
|
24178
|
+
at3 += take;
|
|
24179
|
+
}
|
|
24180
|
+
return out;
|
|
24181
|
+
};
|
|
24182
|
+
/** GHASH over the ciphertext, in whole blocks: GHASH pads each update, so a partial block waits for the next. */
|
|
24183
|
+
absorb_fn = function(ciphertext) {
|
|
24184
|
+
const all = concat(__privateGet(this, _ghashPending), ciphertext);
|
|
24185
|
+
const whole = all.length - all.length % 16;
|
|
24186
|
+
if (whole > 0) __privateGet(this, _ghash).update(all.subarray(0, whole));
|
|
24187
|
+
__privateSet(this, _ghashPending, all.slice(whole));
|
|
24188
|
+
};
|
|
24189
|
+
/** CBC and ECB: every whole block now; decrypting with padding, the last whole block waits for `final`. */
|
|
24190
|
+
blocks_fn = function(input) {
|
|
24191
|
+
const all = concat(__privateGet(this, _pending), input);
|
|
24192
|
+
let whole = all.length - all.length % 16;
|
|
24193
|
+
if (__privateGet(this, _decrypt) && __privateGet(this, _padding) && whole === all.length && whole > 0) whole -= 16;
|
|
24194
|
+
const out = new Uint8Array(whole);
|
|
24195
|
+
for (let at3 = 0; at3 < whole; at3 += 16) out.set(__privateMethod(this, _CipherBase_instances, block_fn).call(this, all.subarray(at3, at3 + 16)), at3);
|
|
24196
|
+
__privateSet(this, _pending, all.slice(whole));
|
|
24197
|
+
return out;
|
|
24198
|
+
};
|
|
24199
|
+
block_fn = function(block) {
|
|
24200
|
+
if (__privateGet(this, _mode) === "ecb") return __privateGet(this, _decrypt) ? decryptBlock2(__privateGet(this, _xkDec), block) : encryptBlock2(__privateGet(this, _xk), block);
|
|
24201
|
+
if (__privateGet(this, _decrypt)) {
|
|
24202
|
+
const plain = decryptBlock2(__privateGet(this, _xkDec), block);
|
|
24203
|
+
for (let i10 = 0; i10 < 16; i10++) plain[i10] = plain[i10] ^ __privateGet(this, _chain)[i10];
|
|
24204
|
+
__privateSet(this, _chain, new Uint8Array(block));
|
|
24205
|
+
return plain;
|
|
24206
|
+
}
|
|
24207
|
+
const mixed = new Uint8Array(16);
|
|
24208
|
+
for (let i10 = 0; i10 < 16; i10++) mixed[i10] = block[i10] ^ __privateGet(this, _chain)[i10];
|
|
24209
|
+
const cipher = encryptBlock2(__privateGet(this, _xk), mixed);
|
|
24210
|
+
__privateSet(this, _chain, cipher);
|
|
24211
|
+
return cipher;
|
|
24212
|
+
};
|
|
24213
|
+
finish_fn = function() {
|
|
24214
|
+
if (__privateGet(this, _mode) === "ctr") return new Uint8Array(0);
|
|
24215
|
+
if (__privateGet(this, _mode) === "gcm") return __privateMethod(this, _CipherBase_instances, finishGcm_fn).call(this);
|
|
24216
|
+
const rest = __privateGet(this, _pending);
|
|
24217
|
+
__privateSet(this, _pending, new Uint8Array(0));
|
|
24218
|
+
if (!__privateGet(this, _decrypt)) {
|
|
24219
|
+
if (!__privateGet(this, _padding)) {
|
|
24220
|
+
if (rest.length !== 0) throw error("ERR_OSSL_WRONG_FINAL_BLOCK_LENGTH", "error:1C80006B:Provider routines::wrong final block length");
|
|
24221
|
+
return rest;
|
|
24222
|
+
}
|
|
24223
|
+
const pad2 = 16 - rest.length;
|
|
24224
|
+
const block = new Uint8Array(16);
|
|
24225
|
+
block.set(rest);
|
|
24226
|
+
block.fill(pad2, rest.length);
|
|
24227
|
+
return __privateMethod(this, _CipherBase_instances, block_fn).call(this, block);
|
|
24228
|
+
}
|
|
24229
|
+
if (!__privateGet(this, _padding)) {
|
|
24230
|
+
if (rest.length !== 0) throw error("ERR_OSSL_WRONG_FINAL_BLOCK_LENGTH", "error:1C80006B:Provider routines::wrong final block length");
|
|
24231
|
+
return rest;
|
|
24232
|
+
}
|
|
24233
|
+
if (rest.length !== 16) throw error("ERR_OSSL_WRONG_FINAL_BLOCK_LENGTH", "error:1C80006B:Provider routines::wrong final block length");
|
|
24234
|
+
const plain = __privateMethod(this, _CipherBase_instances, block_fn).call(this, rest);
|
|
24235
|
+
const pad = plain[15];
|
|
24236
|
+
let valid = pad >= 1 && pad <= 16;
|
|
24237
|
+
for (let i10 = 16 - pad; valid && i10 < 16; i10++) valid = plain[i10] === pad;
|
|
24238
|
+
if (!valid) throw error("ERR_OSSL_BAD_DECRYPT", "error:1C800064:Provider routines::bad decrypt");
|
|
24239
|
+
return plain.slice(0, 16 - pad);
|
|
24240
|
+
};
|
|
24241
|
+
finishGcm_fn = function() {
|
|
24242
|
+
if (__privateGet(this, _ghashPending).length) __privateGet(this, _ghash).update(__privateGet(this, _ghashPending));
|
|
24243
|
+
const lengths = new Uint8Array(16);
|
|
24244
|
+
const view = new DataView(lengths.buffer);
|
|
24245
|
+
view.setBigUint64(0, BigInt(__privateGet(this, _aadLength) * 8), false);
|
|
24246
|
+
view.setBigUint64(8, BigInt(__privateGet(this, _dataLength) * 8), false);
|
|
24247
|
+
const full = __privateGet(this, _ghash).update(lengths).digest();
|
|
24248
|
+
for (let i10 = 0; i10 < 16; i10++) full[i10] = full[i10] ^ __privateGet(this, _tagMask)[i10];
|
|
24249
|
+
if (!__privateGet(this, _decrypt)) {
|
|
24250
|
+
__privateSet(this, _authTag, full.slice(0, __privateGet(this, _authTagLength) ?? 16));
|
|
24251
|
+
return new Uint8Array(0);
|
|
24252
|
+
}
|
|
24253
|
+
const expected = __privateGet(this, _authTag);
|
|
24254
|
+
let same = expected !== void 0;
|
|
24255
|
+
if (expected) for (let i10 = 0; i10 < expected.length; i10++) same = same && full[i10] === expected[i10];
|
|
24256
|
+
if (!same) throw new Error("Unsupported state or unable to authenticate data");
|
|
24257
|
+
return new Uint8Array(0);
|
|
24258
|
+
};
|
|
24259
|
+
authTagOf = (cipher) => {
|
|
24260
|
+
var _a3;
|
|
24261
|
+
return __privateMethod(_a3 = cipher, _CipherBase_instances, getTag_fn).call(_a3);
|
|
24262
|
+
};
|
|
24263
|
+
expectTagOf = (cipher, tag, encoding) => {
|
|
24264
|
+
var _a3;
|
|
24265
|
+
return __privateMethod(_a3 = cipher, _CipherBase_instances, setTag_fn).call(_a3, tag, encoding);
|
|
24266
|
+
};
|
|
24267
|
+
class Cipheriv2 extends CipherBase {
|
|
24268
|
+
constructor(algorithm, key, iv2, options) {
|
|
24269
|
+
super(false, algorithm, key, iv2, options);
|
|
24270
|
+
}
|
|
24271
|
+
getAuthTag() {
|
|
24272
|
+
return deps.toBuffer(authTagOf(this));
|
|
24273
|
+
}
|
|
24274
|
+
}
|
|
24275
|
+
class Decipheriv2 extends CipherBase {
|
|
24276
|
+
constructor(algorithm, key, iv2, options) {
|
|
24277
|
+
super(true, algorithm, key, iv2, options);
|
|
24278
|
+
}
|
|
24279
|
+
setAuthTag(tag, encoding) {
|
|
24280
|
+
expectTagOf(this, tag, encoding);
|
|
24281
|
+
return this;
|
|
24282
|
+
}
|
|
24283
|
+
}
|
|
24284
|
+
return {
|
|
24285
|
+
Cipheriv: Cipheriv2,
|
|
24286
|
+
Decipheriv: Decipheriv2,
|
|
24287
|
+
createCipheriv: (algorithm, key, iv2, options) => new Cipheriv2(algorithm, key, iv2, options),
|
|
24288
|
+
createDecipheriv: (algorithm, key, iv2, options) => new Decipheriv2(algorithm, key, iv2, options)
|
|
24289
|
+
};
|
|
24290
|
+
}
|
|
23297
24291
|
function createCryptoModule(require2) {
|
|
23298
24292
|
var _state, _done, _inner, _outer, _done2, _algorithm, _data, _algorithm2, _data2, __keyData, __type, __algorithm;
|
|
23299
24293
|
const bufferModule2 = require2 ? require2("buffer") : lazyModule("buffer");
|
|
@@ -23873,7 +24867,7 @@ ${body}
|
|
|
23873
24867
|
return result === 0;
|
|
23874
24868
|
}
|
|
23875
24869
|
function getCiphers2() {
|
|
23876
|
-
return
|
|
24870
|
+
return cipherNames();
|
|
23877
24871
|
}
|
|
23878
24872
|
function getHashes2() {
|
|
23879
24873
|
return HASH_ALGORITHMS.slice();
|
|
@@ -23994,7 +24988,25 @@ ${body}
|
|
|
23994
24988
|
}
|
|
23995
24989
|
throw new Error(`Unsupported key format: ${keyInfo.format}`);
|
|
23996
24990
|
}
|
|
24991
|
+
const { Cipheriv: Cipheriv2, Decipheriv: Decipheriv2, createCipheriv: createCipheriv2, createDecipheriv: createDecipheriv2 } = createCipherClasses({
|
|
24992
|
+
toBuffer: (bytes2) => Buffer2.from(bytes2),
|
|
24993
|
+
bytesOf: (value, encoding) => cryptoBytes(value, encoding, true),
|
|
24994
|
+
secretKeyBytes: (value) => {
|
|
24995
|
+
if (!(value instanceof KeyObject2)) return void 0;
|
|
24996
|
+
const info = keyInfoOf(value);
|
|
24997
|
+
if (info.type !== "secret" || !(info.keyData instanceof Uint8Array)) {
|
|
24998
|
+
throw Object.assign(new TypeError(`Invalid key object type ${info.type}, expected secret.`), { code: "ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE" });
|
|
24999
|
+
}
|
|
25000
|
+
return info.keyData;
|
|
25001
|
+
},
|
|
25002
|
+
encode: (bytes2, encoding) => digestResult(bytes2, encoding),
|
|
25003
|
+
error: cryptoError
|
|
25004
|
+
});
|
|
23997
25005
|
return {
|
|
25006
|
+
Cipheriv: Cipheriv2,
|
|
25007
|
+
Decipheriv: Decipheriv2,
|
|
25008
|
+
createCipheriv: createCipheriv2,
|
|
25009
|
+
createDecipheriv: createDecipheriv2,
|
|
23998
25010
|
unsupported: unsupported2,
|
|
23999
25011
|
randomBytes: randomBytes2,
|
|
24000
25012
|
randomFill: randomFill2,
|
|
@@ -24023,12 +25035,16 @@ ${body}
|
|
|
24023
25035
|
};
|
|
24024
25036
|
}
|
|
24025
25037
|
const cryptoModule = createCryptoModule();
|
|
24026
|
-
const { randomBytes, randomFillSync, randomFill, randomUUID, randomInt, getRandomValues, unsupported, createHash, createHmac, hash, pbkdf2Sync, pbkdf2, sign, verify, createSign, createVerify, KeyObject, createSecretKey, createPublicKey, createPrivateKey, generateKeyPair, timingSafeEqual, getCiphers, getHashes } = cryptoModule;
|
|
25038
|
+
const { Cipheriv, Decipheriv, createCipheriv, createDecipheriv, randomBytes, randomFillSync, randomFill, randomUUID, randomInt, getRandomValues, unsupported, createHash, createHmac, hash, pbkdf2Sync, pbkdf2, sign, verify, createSign, createVerify, KeyObject, createSecretKey, createPublicKey, createPrivateKey, generateKeyPair, timingSafeEqual, getCiphers, getHashes } = cryptoModule;
|
|
24027
25039
|
var cryptoShim = /* @__PURE__ */ Object.freeze({
|
|
24028
25040
|
__proto__: null,
|
|
25041
|
+
Cipheriv,
|
|
25042
|
+
Decipheriv,
|
|
24029
25043
|
KeyObject,
|
|
24030
25044
|
constants: cryptoConstants,
|
|
25045
|
+
createCipheriv,
|
|
24031
25046
|
createCryptoModule,
|
|
25047
|
+
createDecipheriv,
|
|
24032
25048
|
createHash,
|
|
24033
25049
|
createHmac,
|
|
24034
25050
|
createPrivateKey,
|
|
@@ -32263,6 +33279,68 @@ function guestPromise(owner) {
|
|
|
32263
33279
|
}
|
|
32264
33280
|
return constructor;
|
|
32265
33281
|
}
|
|
33282
|
+
const kIsDisturbed = Symbol.for("nodejs.stream.disturbed");
|
|
33283
|
+
function isAsyncIterableBody(body) {
|
|
33284
|
+
if (body === null || typeof body !== "object") return false;
|
|
33285
|
+
if (typeof ReadableStream === "function" && body instanceof ReadableStream) return false;
|
|
33286
|
+
if (typeof Blob === "function" && body instanceof Blob) return false;
|
|
33287
|
+
if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) return false;
|
|
33288
|
+
if (typeof FormData === "function" && body instanceof FormData) return false;
|
|
33289
|
+
if (body instanceof URLSearchParams) return false;
|
|
33290
|
+
return typeof body[Symbol.asyncIterator] === "function";
|
|
33291
|
+
}
|
|
33292
|
+
function refuseDisturbed(body) {
|
|
33293
|
+
const stream = body;
|
|
33294
|
+
const disturbed = stream[kIsDisturbed] !== void 0 ? Boolean(stream[kIsDisturbed]) : Boolean(stream.readableDidRead || stream.readableAborted);
|
|
33295
|
+
if (disturbed || stream.locked === true) throw new TypeError("Response body object should not be disturbed or locked");
|
|
33296
|
+
}
|
|
33297
|
+
function streamFrom(iterable) {
|
|
33298
|
+
let iterator;
|
|
33299
|
+
return new ReadableStream({
|
|
33300
|
+
async start() {
|
|
33301
|
+
iterator = iterable[Symbol.asyncIterator]();
|
|
33302
|
+
},
|
|
33303
|
+
async pull(controller) {
|
|
33304
|
+
for (; ; ) {
|
|
33305
|
+
const { done, value } = await iterator.next();
|
|
33306
|
+
if (done) {
|
|
33307
|
+
controller.close();
|
|
33308
|
+
return;
|
|
33309
|
+
}
|
|
33310
|
+
const bytes2 = Buffer$9.isBuffer(value) ? value : Buffer$9.from(value);
|
|
33311
|
+
if (bytes2.byteLength) {
|
|
33312
|
+
controller.enqueue(new Uint8Array(bytes2));
|
|
33313
|
+
return;
|
|
33314
|
+
}
|
|
33315
|
+
}
|
|
33316
|
+
},
|
|
33317
|
+
async cancel() {
|
|
33318
|
+
var _a3;
|
|
33319
|
+
await ((_a3 = iterator == null ? void 0 : iterator.return) == null ? void 0 : _a3.call(iterator));
|
|
33320
|
+
}
|
|
33321
|
+
}, { highWaterMark: 0 });
|
|
33322
|
+
}
|
|
33323
|
+
const REQUEST_INIT_MEMBERS = ["method", "headers", "referrer", "referrerPolicy", "mode", "credentials", "cache", "redirect", "integrity", "keepalive", "signal", "window", "duplex", "priority"];
|
|
33324
|
+
function withNodeRequestBody(init) {
|
|
33325
|
+
if (!init) return init;
|
|
33326
|
+
const body = init.body;
|
|
33327
|
+
if (!isAsyncIterableBody(body)) return init;
|
|
33328
|
+
refuseDisturbed(body);
|
|
33329
|
+
const copy2 = {};
|
|
33330
|
+
for (const member of Object.keys(init)) if (member !== "body") copy2[member] = init[member];
|
|
33331
|
+
for (const member of REQUEST_INIT_MEMBERS) {
|
|
33332
|
+
if (member in copy2) continue;
|
|
33333
|
+
const value = init[member];
|
|
33334
|
+
if (value !== void 0) copy2[member] = value;
|
|
33335
|
+
}
|
|
33336
|
+
copy2.body = streamFrom(body);
|
|
33337
|
+
return copy2;
|
|
33338
|
+
}
|
|
33339
|
+
function nodeResponseBody(body) {
|
|
33340
|
+
if (!isAsyncIterableBody(body)) return body;
|
|
33341
|
+
refuseDisturbed(body);
|
|
33342
|
+
return streamFrom(body);
|
|
33343
|
+
}
|
|
32266
33344
|
const staticRequestBodies = /* @__PURE__ */ new WeakSet();
|
|
32267
33345
|
function rememberRequestBodySource(request, input, init) {
|
|
32268
33346
|
if (!request.body) return;
|
|
@@ -32272,6 +33350,11 @@ function rememberRequestBodySource(request, input, init) {
|
|
|
32272
33350
|
}
|
|
32273
33351
|
function guestFetch(process2, fallback) {
|
|
32274
33352
|
return function fetch2(input, init) {
|
|
33353
|
+
try {
|
|
33354
|
+
init = withNodeRequestBody(init);
|
|
33355
|
+
} catch (error) {
|
|
33356
|
+
return Promise.reject(error);
|
|
33357
|
+
}
|
|
32275
33358
|
return fallback.call(globalThis, input, init);
|
|
32276
33359
|
};
|
|
32277
33360
|
}
|
|
@@ -32310,7 +33393,8 @@ function installNodeResponse(target) {
|
|
|
32310
33393
|
const Native = target.Response;
|
|
32311
33394
|
if (typeof Native !== "function" || Native[INSTALLED]) return;
|
|
32312
33395
|
const proto = Native.prototype;
|
|
32313
|
-
|
|
33396
|
+
let nativeHeaders;
|
|
33397
|
+
for (let at3 = proto; at3 && !nativeHeaders; at3 = Object.getPrototypeOf(at3)) nativeHeaders = (_a3 = Object.getOwnPropertyDescriptor(at3, "headers")) == null ? void 0 : _a3.get;
|
|
32314
33398
|
const nativeFormData = proto.formData;
|
|
32315
33399
|
const nativeBlob = proto.blob;
|
|
32316
33400
|
const nativeArrayBuffer = proto.arrayBuffer;
|
|
@@ -32320,7 +33404,7 @@ function installNodeResponse(target) {
|
|
|
32320
33404
|
const NodeResponse = function Response2(body, init) {
|
|
32321
33405
|
if (!new.target) throw new TypeError("Class constructor Response cannot be invoked without 'new'");
|
|
32322
33406
|
const given = givenHeaders(init);
|
|
32323
|
-
const response = Reflect.construct(Native, [body, given ? withHeaders(init, given) : init], new.target === NodeResponse ? Native : new.target);
|
|
33407
|
+
const response = Reflect.construct(Native, [nodeResponseBody(body), given ? withHeaders(init, given) : init], new.target === NodeResponse ? Native : new.target);
|
|
32324
33408
|
kept.set(response, withCookies(nativeHeaders.call(response), given));
|
|
32325
33409
|
return response;
|
|
32326
33410
|
};
|
|
@@ -32546,12 +33630,12 @@ class SHA2_32B extends HashMD {
|
|
|
32546
33630
|
this.set(A10, B, C, D10, E7, F, G10, H);
|
|
32547
33631
|
}
|
|
32548
33632
|
roundClean() {
|
|
32549
|
-
clean(SHA256_W);
|
|
33633
|
+
clean$1(SHA256_W);
|
|
32550
33634
|
}
|
|
32551
33635
|
destroy() {
|
|
32552
33636
|
this.destroyed = true;
|
|
32553
33637
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
32554
|
-
clean(this.buffer);
|
|
33638
|
+
clean$1(this.buffer);
|
|
32555
33639
|
}
|
|
32556
33640
|
}
|
|
32557
33641
|
class _SHA256 extends SHA2_32B {
|
|
@@ -74207,6 +75291,63 @@ function installShellJobs(bash, host) {
|
|
|
74207
75291
|
if (shell.jobs.size === 0) shells$1.delete(id2);
|
|
74208
75292
|
return { stdout: held.stdout, stderr: held.stderr + stderr, exitCode: status };
|
|
74209
75293
|
}));
|
|
75294
|
+
for (const shell of ["sh", "bash"]) {
|
|
75295
|
+
bash.registerCommand(uA(shell, async (args, ctx) => {
|
|
75296
|
+
var _a3;
|
|
75297
|
+
const exec = ctx.exec;
|
|
75298
|
+
if (!exec) return { stdout: "", stderr: `bash: ${shell}: needs a shell that can run a script
|
|
75299
|
+
`, exitCode: 1 };
|
|
75300
|
+
let script;
|
|
75301
|
+
let zero2;
|
|
75302
|
+
let positional;
|
|
75303
|
+
let sourced;
|
|
75304
|
+
let at3 = 0;
|
|
75305
|
+
while (at3 < args.length && /^[-+][a-bd-zA-Z]+$/u.test(args[at3])) at3++;
|
|
75306
|
+
args = args.slice(at3);
|
|
75307
|
+
if (args[0] === "-c" && args.length >= 2) {
|
|
75308
|
+
script = args[1];
|
|
75309
|
+
zero2 = args[2] ?? shell;
|
|
75310
|
+
positional = args.slice(3);
|
|
75311
|
+
} else if (args.length === 0) {
|
|
75312
|
+
if (!((_a3 = ctx.stdin) == null ? void 0 : _a3.trim())) return { stdout: "", stderr: "", exitCode: 0 };
|
|
75313
|
+
script = ctx.stdin;
|
|
75314
|
+
zero2 = shell;
|
|
75315
|
+
positional = [];
|
|
75316
|
+
} else {
|
|
75317
|
+
const path2 = ctx.fs.resolvePath(ctx.cwd, args[0]);
|
|
75318
|
+
try {
|
|
75319
|
+
script = String(await ctx.fs.readFile(path2));
|
|
75320
|
+
} catch {
|
|
75321
|
+
return { stdout: "", stderr: `${shell}: ${args[0]}: No such file or directory
|
|
75322
|
+
`, exitCode: 127 };
|
|
75323
|
+
}
|
|
75324
|
+
zero2 = args[0];
|
|
75325
|
+
positional = args.slice(1);
|
|
75326
|
+
sourced = path2;
|
|
75327
|
+
}
|
|
75328
|
+
if (script.startsWith("#!")) {
|
|
75329
|
+
const newline = script.indexOf("\n");
|
|
75330
|
+
if (newline !== -1) script = script.slice(newline + 1);
|
|
75331
|
+
}
|
|
75332
|
+
const env = { ...ctx.exportedEnv ?? {}, "0": zero2, "#": String(positional.length), "@": positional.join(" "), "*": positional.join(" ") };
|
|
75333
|
+
positional.forEach((word, index2) => {
|
|
75334
|
+
env[String(index2 + 1)] = word;
|
|
75335
|
+
});
|
|
75336
|
+
const token = ctx.env.get(PROCESS_TOKEN_ENV);
|
|
75337
|
+
if (token) env[PROCESS_TOKEN_ENV] = token;
|
|
75338
|
+
if (sourced !== void 0) script = `. ${sourced.replace(/'/gu, "'\\''").replace(/^(.*)$/su, "'$1'")}`;
|
|
75339
|
+
const result = await exec(script, { env, cwd: ctx.cwd, stdin: ctx.stdin, signal: ctx.signal });
|
|
75340
|
+
return { stdout: result.stdout ?? "", stderr: result.stderr ?? "", exitCode: result.exitCode ?? 0 };
|
|
75341
|
+
}));
|
|
75342
|
+
}
|
|
75343
|
+
bash.registerCommand(uA("exec", async (args, ctx) => {
|
|
75344
|
+
if (args.length === 0) return { stdout: "", stderr: "", exitCode: 0 };
|
|
75345
|
+
if (!ctx.exec) return { stdout: "", stderr: "bash: exec: needs a shell that can run a line\n", exitCode: 1 };
|
|
75346
|
+
const line = args.map((word) => /^[A-Za-z0-9_./:=@%+,-]+$/u.test(word) ? word : `'${word.replace(/'/gu, "'\\''")}'`).join(" ");
|
|
75347
|
+
const env = Object.fromEntries(ctx.env);
|
|
75348
|
+
const result = await ctx.exec(line, { env, cwd: ctx.cwd, replaceEnv: true });
|
|
75349
|
+
return { stdout: result.stdout ?? "", stderr: result.stderr ?? "", exitCode: result.exitCode ?? 0 };
|
|
75350
|
+
}));
|
|
74210
75351
|
bash.registerCommand(uA("kill", async (args) => {
|
|
74211
75352
|
let signal = "SIGTERM";
|
|
74212
75353
|
let index2 = 0;
|
|
@@ -74388,6 +75529,18 @@ function registerRunStreams(token, streams2) {
|
|
|
74388
75529
|
}
|
|
74389
75530
|
function releaseRunStreams(token) {
|
|
74390
75531
|
_runStreams.delete(token);
|
|
75532
|
+
shellRuns.delete(token);
|
|
75533
|
+
hostedNodes.delete(token);
|
|
75534
|
+
}
|
|
75535
|
+
const shellRuns = /* @__PURE__ */ new Set();
|
|
75536
|
+
const hostedNodes = /* @__PURE__ */ new Set();
|
|
75537
|
+
function nestedNodeToken(parentToken, args, cwd) {
|
|
75538
|
+
var _a3;
|
|
75539
|
+
const token = `child-${__nextChildRun++}`;
|
|
75540
|
+
setRunPid(token, mintPid(), ((_a3 = runPid(parentToken)) == null ? void 0 : _a3.pid) ?? 0, { argv: ["node", ...args], ...cwd ? { cwd } : {} });
|
|
75541
|
+
const parentStreams = runStreamsFor(parentToken);
|
|
75542
|
+
if (parentStreams) registerRunStreams(token, parentStreams);
|
|
75543
|
+
return token;
|
|
74391
75544
|
}
|
|
74392
75545
|
function runStreamsFor(token) {
|
|
74393
75546
|
return _runStreams.get(token);
|
|
@@ -74456,19 +75609,26 @@ function initChildProcess(vfs2) {
|
|
|
74456
75609
|
if (!tree2) {
|
|
74457
75610
|
return { stdout: "", stderr: "VFS not initialized\n", exitCode: 1 };
|
|
74458
75611
|
}
|
|
74459
|
-
const
|
|
75612
|
+
const parentToken = runTokenOf(ctx);
|
|
75613
|
+
const nested = parentToken !== null && (shellRuns.has(parentToken) || hostedNodes.has(parentToken));
|
|
75614
|
+
const runToken = nested ? nestedNodeToken(parentToken, args, ctx.cwd) : parentToken;
|
|
74460
75615
|
const streams2 = runToken === null ? void 0 : runStreamsFor(runToken);
|
|
74461
75616
|
const processHost = nodeProcessHostFor();
|
|
74462
75617
|
if (processHost && runToken !== null) {
|
|
74463
|
-
|
|
74464
|
-
|
|
74465
|
-
|
|
74466
|
-
|
|
74467
|
-
|
|
74468
|
-
|
|
74469
|
-
|
|
74470
|
-
|
|
74471
|
-
|
|
75618
|
+
if (!nested) hostedNodes.add(runToken);
|
|
75619
|
+
try {
|
|
75620
|
+
return await runHostedNode(processHost, {
|
|
75621
|
+
token: runToken,
|
|
75622
|
+
argv: [...args],
|
|
75623
|
+
cwd: ctx.cwd,
|
|
75624
|
+
filesystem: tree2,
|
|
75625
|
+
env: guestEnvironmentOf(ctx),
|
|
75626
|
+
...typeof ctx.stdin === "string" ? { stdin: ctx.stdin } : {},
|
|
75627
|
+
...streams2 ? { streams: streams2 } : {}
|
|
75628
|
+
});
|
|
75629
|
+
} finally {
|
|
75630
|
+
if (nested) releaseRunStreams(runToken);
|
|
75631
|
+
}
|
|
74472
75632
|
}
|
|
74473
75633
|
const execArgv = [];
|
|
74474
75634
|
let first = 0;
|
|
@@ -75354,6 +76514,7 @@ function existsInTree(path2) {
|
|
|
75354
76514
|
return false;
|
|
75355
76515
|
}
|
|
75356
76516
|
}
|
|
76517
|
+
const SHELL_PROGRAMS = /* @__PURE__ */ new Set(["sh", "bash", "dash", "/bin/sh", "/bin/bash", "/usr/bin/sh", "/usr/bin/bash"]);
|
|
75357
76518
|
function engineProgramFor(file, cwd) {
|
|
75358
76519
|
const name = __substrateProgramName(file);
|
|
75359
76520
|
if (!name.includes("/")) return name;
|
|
@@ -75400,6 +76561,7 @@ function startChildRun(request) {
|
|
|
75400
76561
|
const controller = new AbortController();
|
|
75401
76562
|
const pendingStdin = [];
|
|
75402
76563
|
const admittedNode = nodeProcessHostInstalled();
|
|
76564
|
+
shellRuns.add(token);
|
|
75403
76565
|
const hostTerminal = request.terminal !== void 0 && hostExecutor() !== null && !admittedNode;
|
|
75404
76566
|
let wakeInput;
|
|
75405
76567
|
let liveInput = false;
|
|
@@ -75498,7 +76660,8 @@ function startChildRun(request) {
|
|
|
75498
76660
|
const begin = () => {
|
|
75499
76661
|
if (started || finished) return;
|
|
75500
76662
|
started = true;
|
|
75501
|
-
const
|
|
76663
|
+
const shellChild = SHELL_PROGRAMS.has(engineProgramFor(request.file, request.cwd)) && hostExecutor() !== null;
|
|
76664
|
+
const engineFirst = !hostTerminal && !shellChild && programExists(request.file, request.cwd, request.env);
|
|
75502
76665
|
liveInput = !hostTerminal && !admittedNode && request.stdinIsPipe && !engineFirst;
|
|
75503
76666
|
if (liveInput) {
|
|
75504
76667
|
pendingStdin.unshift(...initialStdin);
|
|
@@ -80548,6 +81711,7 @@ forGuestRealm(() => {
|
|
|
80548
81711
|
const kept = /* @__PURE__ */ new WeakMap();
|
|
80549
81712
|
class NodeRequest extends Native {
|
|
80550
81713
|
constructor(input, init) {
|
|
81714
|
+
init = withNodeRequestBody(init);
|
|
80551
81715
|
super(input, init);
|
|
80552
81716
|
rememberRequestBodySource(this, input, init);
|
|
80553
81717
|
const asked = new Headers((init == null ? void 0 : init.headers) ?? (input instanceof Native ? input.headers : void 0));
|