@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
package/dist/index.mjs
CHANGED
|
@@ -5132,7 +5132,7 @@ function parse$1(urlString, parseQueryString = false, slashesDenoteHost = false)
|
|
|
5132
5132
|
hostname: null,
|
|
5133
5133
|
hash: __hash,
|
|
5134
5134
|
search: __search,
|
|
5135
|
-
query: parseQueryString ? Object.fromEntries(new URLSearchParams(__search || "")) : __search ? __search.slice(1) : null,
|
|
5135
|
+
query: parseQueryString ? Object.fromEntries(new URLSearchParams$1(__search || "")) : __search ? __search.slice(1) : null,
|
|
5136
5136
|
pathname: __pathname || null,
|
|
5137
5137
|
path: __pathname + (__search || "") || null,
|
|
5138
5138
|
href: urlString
|
|
@@ -5206,7 +5206,7 @@ function format$1(urlObject) {
|
|
|
5206
5206
|
if (typeof urlObject.query === "string") {
|
|
5207
5207
|
result += "?" + urlObject.query;
|
|
5208
5208
|
} else {
|
|
5209
|
-
const params = new URLSearchParams();
|
|
5209
|
+
const params = new URLSearchParams$1();
|
|
5210
5210
|
for (const [key, value] of Object.entries(urlObject.query)) {
|
|
5211
5211
|
if (Array.isArray(value)) {
|
|
5212
5212
|
for (const v of value) {
|
|
@@ -5235,7 +5235,7 @@ function resolve$2(from, to) {
|
|
|
5235
5235
|
}
|
|
5236
5236
|
}
|
|
5237
5237
|
const URL$1 = globalThis.URL;
|
|
5238
|
-
const URLSearchParams = globalThis.URLSearchParams;
|
|
5238
|
+
const URLSearchParams$1 = globalThis.URLSearchParams;
|
|
5239
5239
|
function fileURLToPath(url2) {
|
|
5240
5240
|
const urlObj = typeof url2 === "string" ? new globalThis.URL(url2) : url2;
|
|
5241
5241
|
if (urlObj.protocol !== "file:") {
|
|
@@ -5258,7 +5258,7 @@ const url$1 = {
|
|
|
5258
5258
|
format: format$1,
|
|
5259
5259
|
resolve: resolve$2,
|
|
5260
5260
|
URL: URL$1,
|
|
5261
|
-
URLSearchParams,
|
|
5261
|
+
URLSearchParams: URLSearchParams$1,
|
|
5262
5262
|
URLPattern: URLPattern$1,
|
|
5263
5263
|
fileURLToPath,
|
|
5264
5264
|
pathToFileURL
|
|
@@ -5267,7 +5267,7 @@ const urlShim = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
|
|
|
5267
5267
|
__proto__: null,
|
|
5268
5268
|
URL: URL$1,
|
|
5269
5269
|
URLPattern: URLPattern$1,
|
|
5270
|
-
URLSearchParams,
|
|
5270
|
+
URLSearchParams: URLSearchParams$1,
|
|
5271
5271
|
default: url$1,
|
|
5272
5272
|
fileURLToPath,
|
|
5273
5273
|
format: format$1,
|
|
@@ -19400,14 +19400,14 @@ var safeBuffer = { exports: {} };
|
|
|
19400
19400
|
var buffer = {};
|
|
19401
19401
|
var ieee754 = {};
|
|
19402
19402
|
/*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh <https://feross.org/opensource> */
|
|
19403
|
-
ieee754.read = function(buffer2, offset2,
|
|
19403
|
+
ieee754.read = function(buffer2, offset2, isLE2, mLen, nBytes) {
|
|
19404
19404
|
var e, m;
|
|
19405
19405
|
var eLen = nBytes * 8 - mLen - 1;
|
|
19406
19406
|
var eMax = (1 << eLen) - 1;
|
|
19407
19407
|
var eBias = eMax >> 1;
|
|
19408
19408
|
var nBits = -7;
|
|
19409
|
-
var i2 =
|
|
19410
|
-
var d =
|
|
19409
|
+
var i2 = isLE2 ? nBytes - 1 : 0;
|
|
19410
|
+
var d = isLE2 ? -1 : 1;
|
|
19411
19411
|
var s = buffer2[offset2 + i2];
|
|
19412
19412
|
i2 += d;
|
|
19413
19413
|
e = s & (1 << -nBits) - 1;
|
|
@@ -19430,14 +19430,14 @@ ieee754.read = function(buffer2, offset2, isLE, mLen, nBytes) {
|
|
|
19430
19430
|
}
|
|
19431
19431
|
return (s ? -1 : 1) * m * Math.pow(2, e - mLen);
|
|
19432
19432
|
};
|
|
19433
|
-
ieee754.write = function(buffer2, value, offset2,
|
|
19433
|
+
ieee754.write = function(buffer2, value, offset2, isLE2, mLen, nBytes) {
|
|
19434
19434
|
var e, m, c;
|
|
19435
19435
|
var eLen = nBytes * 8 - mLen - 1;
|
|
19436
19436
|
var eMax = (1 << eLen) - 1;
|
|
19437
19437
|
var eBias = eMax >> 1;
|
|
19438
19438
|
var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0;
|
|
19439
|
-
var i2 =
|
|
19440
|
-
var d =
|
|
19439
|
+
var i2 = isLE2 ? 0 : nBytes - 1;
|
|
19440
|
+
var d = isLE2 ? 1 : -1;
|
|
19441
19441
|
var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0;
|
|
19442
19442
|
value = Math.abs(value);
|
|
19443
19443
|
if (isNaN(value) || value === Infinity) {
|
|
@@ -20328,10 +20328,10 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20328
20328
|
byteLength3 = byteLength3 >>> 0;
|
|
20329
20329
|
if (!noAssert) checkOffset(offset2, byteLength3, this.length);
|
|
20330
20330
|
let val = this[offset2];
|
|
20331
|
-
let
|
|
20331
|
+
let mul3 = 1;
|
|
20332
20332
|
let i2 = 0;
|
|
20333
|
-
while (++i2 < byteLength3 && (
|
|
20334
|
-
val += this[offset2 + i2] *
|
|
20333
|
+
while (++i2 < byteLength3 && (mul3 *= 256)) {
|
|
20334
|
+
val += this[offset2 + i2] * mul3;
|
|
20335
20335
|
}
|
|
20336
20336
|
return val;
|
|
20337
20337
|
};
|
|
@@ -20342,9 +20342,9 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20342
20342
|
checkOffset(offset2, byteLength3, this.length);
|
|
20343
20343
|
}
|
|
20344
20344
|
let val = this[offset2 + --byteLength3];
|
|
20345
|
-
let
|
|
20346
|
-
while (byteLength3 > 0 && (
|
|
20347
|
-
val += this[offset2 + --byteLength3] *
|
|
20345
|
+
let mul3 = 1;
|
|
20346
|
+
while (byteLength3 > 0 && (mul3 *= 256)) {
|
|
20347
|
+
val += this[offset2 + --byteLength3] * mul3;
|
|
20348
20348
|
}
|
|
20349
20349
|
return val;
|
|
20350
20350
|
};
|
|
@@ -20402,13 +20402,13 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20402
20402
|
byteLength3 = byteLength3 >>> 0;
|
|
20403
20403
|
if (!noAssert) checkOffset(offset2, byteLength3, this.length);
|
|
20404
20404
|
let val = this[offset2];
|
|
20405
|
-
let
|
|
20405
|
+
let mul3 = 1;
|
|
20406
20406
|
let i2 = 0;
|
|
20407
|
-
while (++i2 < byteLength3 && (
|
|
20408
|
-
val += this[offset2 + i2] *
|
|
20407
|
+
while (++i2 < byteLength3 && (mul3 *= 256)) {
|
|
20408
|
+
val += this[offset2 + i2] * mul3;
|
|
20409
20409
|
}
|
|
20410
|
-
|
|
20411
|
-
if (val >=
|
|
20410
|
+
mul3 *= 128;
|
|
20411
|
+
if (val >= mul3) val -= Math.pow(2, 8 * byteLength3);
|
|
20412
20412
|
return val;
|
|
20413
20413
|
};
|
|
20414
20414
|
Buffer2.prototype.readIntBE = function readIntBE(offset2, byteLength3, noAssert) {
|
|
@@ -20416,13 +20416,13 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20416
20416
|
byteLength3 = byteLength3 >>> 0;
|
|
20417
20417
|
if (!noAssert) checkOffset(offset2, byteLength3, this.length);
|
|
20418
20418
|
let i2 = byteLength3;
|
|
20419
|
-
let
|
|
20419
|
+
let mul3 = 1;
|
|
20420
20420
|
let val = this[offset2 + --i2];
|
|
20421
|
-
while (i2 > 0 && (
|
|
20422
|
-
val += this[offset2 + --i2] *
|
|
20421
|
+
while (i2 > 0 && (mul3 *= 256)) {
|
|
20422
|
+
val += this[offset2 + --i2] * mul3;
|
|
20423
20423
|
}
|
|
20424
|
-
|
|
20425
|
-
if (val >=
|
|
20424
|
+
mul3 *= 128;
|
|
20425
|
+
if (val >= mul3) val -= Math.pow(2, 8 * byteLength3);
|
|
20426
20426
|
return val;
|
|
20427
20427
|
};
|
|
20428
20428
|
Buffer2.prototype.readInt8 = function readInt8(offset2, noAssert) {
|
|
@@ -20509,11 +20509,11 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20509
20509
|
const maxBytes = Math.pow(2, 8 * byteLength3) - 1;
|
|
20510
20510
|
checkInt(this, value, offset2, byteLength3, maxBytes, 0);
|
|
20511
20511
|
}
|
|
20512
|
-
let
|
|
20512
|
+
let mul3 = 1;
|
|
20513
20513
|
let i2 = 0;
|
|
20514
20514
|
this[offset2] = value & 255;
|
|
20515
|
-
while (++i2 < byteLength3 && (
|
|
20516
|
-
this[offset2 + i2] = value /
|
|
20515
|
+
while (++i2 < byteLength3 && (mul3 *= 256)) {
|
|
20516
|
+
this[offset2 + i2] = value / mul3 & 255;
|
|
20517
20517
|
}
|
|
20518
20518
|
return offset2 + byteLength3;
|
|
20519
20519
|
};
|
|
@@ -20526,10 +20526,10 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20526
20526
|
checkInt(this, value, offset2, byteLength3, maxBytes, 0);
|
|
20527
20527
|
}
|
|
20528
20528
|
let i2 = byteLength3 - 1;
|
|
20529
|
-
let
|
|
20529
|
+
let mul3 = 1;
|
|
20530
20530
|
this[offset2 + i2] = value & 255;
|
|
20531
|
-
while (--i2 >= 0 && (
|
|
20532
|
-
this[offset2 + i2] = value /
|
|
20531
|
+
while (--i2 >= 0 && (mul3 *= 256)) {
|
|
20532
|
+
this[offset2 + i2] = value / mul3 & 255;
|
|
20533
20533
|
}
|
|
20534
20534
|
return offset2 + byteLength3;
|
|
20535
20535
|
};
|
|
@@ -20630,14 +20630,14 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20630
20630
|
checkInt(this, value, offset2, byteLength3, limit - 1, -limit);
|
|
20631
20631
|
}
|
|
20632
20632
|
let i2 = 0;
|
|
20633
|
-
let
|
|
20633
|
+
let mul3 = 1;
|
|
20634
20634
|
let sub = 0;
|
|
20635
20635
|
this[offset2] = value & 255;
|
|
20636
|
-
while (++i2 < byteLength3 && (
|
|
20636
|
+
while (++i2 < byteLength3 && (mul3 *= 256)) {
|
|
20637
20637
|
if (value < 0 && sub === 0 && this[offset2 + i2 - 1] !== 0) {
|
|
20638
20638
|
sub = 1;
|
|
20639
20639
|
}
|
|
20640
|
-
this[offset2 + i2] = (value /
|
|
20640
|
+
this[offset2 + i2] = (value / mul3 >> 0) - sub & 255;
|
|
20641
20641
|
}
|
|
20642
20642
|
return offset2 + byteLength3;
|
|
20643
20643
|
};
|
|
@@ -20649,14 +20649,14 @@ ieee754.write = function(buffer2, value, offset2, isLE, mLen, nBytes) {
|
|
|
20649
20649
|
checkInt(this, value, offset2, byteLength3, limit - 1, -limit);
|
|
20650
20650
|
}
|
|
20651
20651
|
let i2 = byteLength3 - 1;
|
|
20652
|
-
let
|
|
20652
|
+
let mul3 = 1;
|
|
20653
20653
|
let sub = 0;
|
|
20654
20654
|
this[offset2 + i2] = value & 255;
|
|
20655
|
-
while (--i2 >= 0 && (
|
|
20655
|
+
while (--i2 >= 0 && (mul3 *= 256)) {
|
|
20656
20656
|
if (value < 0 && sub === 0 && this[offset2 + i2 + 1] !== 0) {
|
|
20657
20657
|
sub = 1;
|
|
20658
20658
|
}
|
|
20659
|
-
this[offset2 + i2] = (value /
|
|
20659
|
+
this[offset2 + i2] = (value / mul3 >> 0) - sub & 255;
|
|
20660
20660
|
}
|
|
20661
20661
|
return offset2 + byteLength3;
|
|
20662
20662
|
};
|
|
@@ -21339,17 +21339,10 @@ var implementation$1 = function bind2(that) {
|
|
|
21339
21339
|
var implementation = implementation$1;
|
|
21340
21340
|
var functionBind = Function.prototype.bind || implementation;
|
|
21341
21341
|
var functionCall = Function.prototype.call;
|
|
21342
|
-
var functionApply;
|
|
21343
|
-
var hasRequiredFunctionApply;
|
|
21344
|
-
function requireFunctionApply() {
|
|
21345
|
-
if (hasRequiredFunctionApply) return functionApply;
|
|
21346
|
-
hasRequiredFunctionApply = 1;
|
|
21347
|
-
functionApply = Function.prototype.apply;
|
|
21348
|
-
return functionApply;
|
|
21349
|
-
}
|
|
21342
|
+
var functionApply = Function.prototype.apply;
|
|
21350
21343
|
var reflectApply = typeof Reflect !== "undefined" && Reflect && Reflect.apply;
|
|
21351
21344
|
var bind$2 = functionBind;
|
|
21352
|
-
var $apply$1 =
|
|
21345
|
+
var $apply$1 = functionApply;
|
|
21353
21346
|
var $call$2 = functionCall;
|
|
21354
21347
|
var $reflectApply = reflectApply;
|
|
21355
21348
|
var actualApply = $reflectApply || bind$2.call($call$2, $apply$1);
|
|
@@ -21469,7 +21462,7 @@ var hasSymbols = requireHasSymbols()();
|
|
|
21469
21462
|
var getProto = requireGetProto();
|
|
21470
21463
|
var $ObjectGPO = requireObject_getPrototypeOf();
|
|
21471
21464
|
var $ReflectGPO = requireReflect_getPrototypeOf();
|
|
21472
|
-
var $apply =
|
|
21465
|
+
var $apply = functionApply;
|
|
21473
21466
|
var $call = functionCall;
|
|
21474
21467
|
var needsEval = {};
|
|
21475
21468
|
var TypedArray = typeof Uint8Array === "undefined" || !getProto ? undefined$1 : getProto(Uint8Array);
|
|
@@ -22110,7 +22103,7 @@ function requireApplyBind() {
|
|
|
22110
22103
|
if (hasRequiredApplyBind) return applyBind;
|
|
22111
22104
|
hasRequiredApplyBind = 1;
|
|
22112
22105
|
var bind3 = functionBind;
|
|
22113
|
-
var $apply2 =
|
|
22106
|
+
var $apply2 = functionApply;
|
|
22114
22107
|
var actualApply$1 = actualApply;
|
|
22115
22108
|
applyBind = function applyBind2() {
|
|
22116
22109
|
return actualApply$1(bind3, $apply2, arguments);
|
|
@@ -23157,23 +23150,23 @@ var sha_jsExports = sha_js.exports;
|
|
|
23157
23150
|
const SHA = /* @__PURE__ */ getDefaultExportFromCjs(sha_jsExports);
|
|
23158
23151
|
const fromNumH = (n) => n / 2 ** 32 | 0;
|
|
23159
23152
|
const fromNumL = (n) => n >>> 0;
|
|
23160
|
-
function setU64FromNum(view, byteOffset, n,
|
|
23153
|
+
function setU64FromNum(view, byteOffset, n, isLE2) {
|
|
23161
23154
|
const h = fromNumH(n);
|
|
23162
23155
|
const l = fromNumL(n);
|
|
23163
|
-
view.setUint32(byteOffset,
|
|
23164
|
-
view.setUint32(byteOffset + 4,
|
|
23156
|
+
view.setUint32(byteOffset, isLE2 ? l : h, isLE2);
|
|
23157
|
+
view.setUint32(byteOffset + 4, isLE2 ? h : l, isLE2);
|
|
23165
23158
|
}
|
|
23166
|
-
function isBytes(a) {
|
|
23159
|
+
function isBytes$1(a) {
|
|
23167
23160
|
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
23168
23161
|
}
|
|
23169
|
-
const atitle = (title) => title ? `"${title}" ` : "";
|
|
23170
|
-
function abytes(value, length, title = "") {
|
|
23171
|
-
if (isBytes(value) && length === void 0)
|
|
23162
|
+
const atitle$1 = (title) => title ? `"${title}" ` : "";
|
|
23163
|
+
function abytes$1(value, length, title = "") {
|
|
23164
|
+
if (isBytes$1(value) && length === void 0)
|
|
23172
23165
|
return value;
|
|
23173
|
-
const bytes2 = isBytes(value);
|
|
23166
|
+
const bytes2 = isBytes$1(value);
|
|
23174
23167
|
const ofLen = "";
|
|
23175
23168
|
const got = bytes2 ? `length=${value.length}` : `type=${typeof value}`;
|
|
23176
|
-
const message = atitle(title) + "expected Uint8Array" + ofLen + ", got " + got;
|
|
23169
|
+
const message = atitle$1(title) + "expected Uint8Array" + ofLen + ", got " + got;
|
|
23177
23170
|
if (!bytes2)
|
|
23178
23171
|
throw new TypeError(message);
|
|
23179
23172
|
throw new RangeError(message);
|
|
@@ -23182,25 +23175,25 @@ const aobject = (value, label) => {
|
|
|
23182
23175
|
if (value === null || typeof value !== "object" || Array.isArray(value))
|
|
23183
23176
|
throw new TypeError((label === "object" ? "" : `"${label}" `) + "expected object, got type=" + typeof value);
|
|
23184
23177
|
};
|
|
23185
|
-
function aexists(instance, checkFinished = true) {
|
|
23178
|
+
function aexists$1(instance, checkFinished = true) {
|
|
23186
23179
|
if (instance.destroyed)
|
|
23187
23180
|
throw new Error("hash was destroyed");
|
|
23188
23181
|
if (checkFinished && instance.finished)
|
|
23189
23182
|
throw new Error("digest() was already called");
|
|
23190
23183
|
}
|
|
23191
|
-
function aoutput(out, instance) {
|
|
23192
|
-
abytes(out, void 0, "output");
|
|
23184
|
+
function aoutput$1(out, instance) {
|
|
23185
|
+
abytes$1(out, void 0, "output");
|
|
23193
23186
|
const min2 = instance.outputLen;
|
|
23194
23187
|
if (!(out.length >= min2)) {
|
|
23195
23188
|
throw new RangeError('"output" expected length >= ' + min2);
|
|
23196
23189
|
}
|
|
23197
23190
|
}
|
|
23198
|
-
function clean(...arrays) {
|
|
23191
|
+
function clean$1(...arrays) {
|
|
23199
23192
|
for (let i2 = 0; i2 < arrays.length; i2++) {
|
|
23200
23193
|
arrays[i2].fill(0);
|
|
23201
23194
|
}
|
|
23202
23195
|
}
|
|
23203
|
-
function createView(arr) {
|
|
23196
|
+
function createView$1(arr) {
|
|
23204
23197
|
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
23205
23198
|
}
|
|
23206
23199
|
function rotr(word, shift) {
|
|
@@ -23215,7 +23208,7 @@ const hasHexBuiltin = /* @__PURE__ */ (() => (
|
|
|
23215
23208
|
))();
|
|
23216
23209
|
const hexes = /* @__PURE__ */ Array.from({ length: 256 }, (_, i2) => i2.toString(16).padStart(2, "0"));
|
|
23217
23210
|
function bytesToHex(bytes2) {
|
|
23218
|
-
abytes(bytes2);
|
|
23211
|
+
abytes$1(bytes2);
|
|
23219
23212
|
if (hasHexBuiltin)
|
|
23220
23213
|
return bytes2.toHex();
|
|
23221
23214
|
let hex = "";
|
|
@@ -23256,7 +23249,7 @@ function Maj(a, b, c) {
|
|
|
23256
23249
|
return a & b ^ a & c ^ b & c;
|
|
23257
23250
|
}
|
|
23258
23251
|
class HashMD {
|
|
23259
|
-
constructor(blockLen, outputLen, padOffset,
|
|
23252
|
+
constructor(blockLen, outputLen, padOffset, isLE2) {
|
|
23260
23253
|
__publicField(this, "blockLen");
|
|
23261
23254
|
__publicField(this, "outputLen");
|
|
23262
23255
|
__publicField(this, "canXOF", false);
|
|
@@ -23272,20 +23265,20 @@ class HashMD {
|
|
|
23272
23265
|
this.blockLen = blockLen;
|
|
23273
23266
|
this.outputLen = outputLen;
|
|
23274
23267
|
this.padOffset = padOffset;
|
|
23275
|
-
this.isLE =
|
|
23268
|
+
this.isLE = isLE2;
|
|
23276
23269
|
this.buffer = new Uint8Array(blockLen);
|
|
23277
|
-
this.view = createView(this.buffer);
|
|
23270
|
+
this.view = createView$1(this.buffer);
|
|
23278
23271
|
}
|
|
23279
23272
|
update(data2) {
|
|
23280
|
-
aexists(this);
|
|
23281
|
-
abytes(data2);
|
|
23273
|
+
aexists$1(this);
|
|
23274
|
+
abytes$1(data2);
|
|
23282
23275
|
const { view, buffer: buffer2, blockLen } = this;
|
|
23283
23276
|
const len2 = data2.length;
|
|
23284
23277
|
let processed = false;
|
|
23285
23278
|
for (let pos = 0; pos < len2; ) {
|
|
23286
23279
|
const take = Math.min(blockLen - this.pos, len2 - pos);
|
|
23287
23280
|
if (take === blockLen) {
|
|
23288
|
-
const dataView = createView(data2);
|
|
23281
|
+
const dataView = createView$1(data2);
|
|
23289
23282
|
for (; blockLen <= len2 - pos; pos += blockLen)
|
|
23290
23283
|
this.process(dataView, pos);
|
|
23291
23284
|
processed = true;
|
|
@@ -23306,10 +23299,10 @@ class HashMD {
|
|
|
23306
23299
|
return this;
|
|
23307
23300
|
}
|
|
23308
23301
|
digestInto(out) {
|
|
23309
|
-
aexists(this);
|
|
23310
|
-
aoutput(out, this);
|
|
23302
|
+
aexists$1(this);
|
|
23303
|
+
aoutput$1(out, this);
|
|
23311
23304
|
this.finished = true;
|
|
23312
|
-
const { buffer: buffer2, view, blockLen, isLE } = this;
|
|
23305
|
+
const { buffer: buffer2, view, blockLen, isLE: isLE2 } = this;
|
|
23313
23306
|
let { pos } = this;
|
|
23314
23307
|
buffer2[pos++] = 128;
|
|
23315
23308
|
buffer2.fill(0, pos);
|
|
@@ -23317,17 +23310,17 @@ class HashMD {
|
|
|
23317
23310
|
this.process(view, 0);
|
|
23318
23311
|
buffer2.fill(0);
|
|
23319
23312
|
}
|
|
23320
|
-
setU64FromNum(view, blockLen - 8, this.length * 8,
|
|
23313
|
+
setU64FromNum(view, blockLen - 8, this.length * 8, isLE2);
|
|
23321
23314
|
this.process(view, 0);
|
|
23322
23315
|
this.roundClean();
|
|
23323
|
-
const oview = out === buffer2 ? view : createView(out);
|
|
23316
|
+
const oview = out === buffer2 ? view : createView$1(out);
|
|
23324
23317
|
const len2 = this.outputLen;
|
|
23325
23318
|
const outLen = len2 / 4;
|
|
23326
23319
|
const state = this.get();
|
|
23327
23320
|
if (len2 % 4 || outLen > state.length)
|
|
23328
23321
|
throw new Error("invalid outputLen");
|
|
23329
23322
|
for (let i2 = 0; i2 < outLen; i2++)
|
|
23330
|
-
oview.setUint32(4 * i2, state[i2],
|
|
23323
|
+
oview.setUint32(4 * i2, state[i2], isLE2);
|
|
23331
23324
|
}
|
|
23332
23325
|
digest() {
|
|
23333
23326
|
const { buffer: buffer2, outputLen } = this;
|
|
@@ -23434,12 +23427,12 @@ class _MD5 extends HashMD {
|
|
|
23434
23427
|
this.set(A, B, C, D);
|
|
23435
23428
|
}
|
|
23436
23429
|
roundClean() {
|
|
23437
|
-
clean(MD5_W);
|
|
23430
|
+
clean$1(MD5_W);
|
|
23438
23431
|
}
|
|
23439
23432
|
destroy() {
|
|
23440
23433
|
this.destroyed = true;
|
|
23441
23434
|
this.set(0, 0, 0, 0);
|
|
23442
|
-
clean(this.buffer);
|
|
23435
|
+
clean$1(this.buffer);
|
|
23443
23436
|
}
|
|
23444
23437
|
}
|
|
23445
23438
|
const md5 = /* @__PURE__ */ createHasher(() => new _MD5());
|
|
@@ -23449,6 +23442,993 @@ const cryptoConstants = {
|
|
|
23449
23442
|
RSA_PKCS1_OAEP_PADDING: 4,
|
|
23450
23443
|
RSA_PKCS1_PSS_PADDING: 6
|
|
23451
23444
|
};
|
|
23445
|
+
/*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) */
|
|
23446
|
+
function isBytes(a) {
|
|
23447
|
+
return a instanceof Uint8Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint8Array" && "BYTES_PER_ELEMENT" in a && a.BYTES_PER_ELEMENT === 1;
|
|
23448
|
+
}
|
|
23449
|
+
const atitle = (title) => title ? `"${title}" ` : "";
|
|
23450
|
+
function anumber(n, title = "") {
|
|
23451
|
+
if (typeof n !== "number")
|
|
23452
|
+
throw new TypeError(atitle(title) + "expected number, got " + typeof n);
|
|
23453
|
+
if (!Number.isSafeInteger(n) || n < 0)
|
|
23454
|
+
throw new RangeError(atitle(title) + "expected integer >= 0, got " + n);
|
|
23455
|
+
return n;
|
|
23456
|
+
}
|
|
23457
|
+
function abytes(value, length, title = "") {
|
|
23458
|
+
if (isBytes(value) && (length === void 0 || value.length === length))
|
|
23459
|
+
return value;
|
|
23460
|
+
if (length !== void 0)
|
|
23461
|
+
anumber(length, "length");
|
|
23462
|
+
const bytes2 = isBytes(value);
|
|
23463
|
+
const ofLen = length !== void 0 ? ` of length ${length}` : "";
|
|
23464
|
+
const got = bytes2 ? `length=${value.length}` : `type=${typeof value}`;
|
|
23465
|
+
const message = atitle(title) + "expected Uint8Array" + ofLen + ", got " + got;
|
|
23466
|
+
if (!bytes2)
|
|
23467
|
+
throw new TypeError(message);
|
|
23468
|
+
throw new RangeError(message);
|
|
23469
|
+
}
|
|
23470
|
+
function aexists(instance, checkFinished = true) {
|
|
23471
|
+
if (instance.destroyed)
|
|
23472
|
+
throw new Error("hash was destroyed");
|
|
23473
|
+
if (checkFinished && instance.finished)
|
|
23474
|
+
throw new Error("digest() was already called");
|
|
23475
|
+
}
|
|
23476
|
+
function aoutput(out, instance) {
|
|
23477
|
+
abytes(out, void 0, "output");
|
|
23478
|
+
const min2 = instance.outputLen;
|
|
23479
|
+
if (!(out.length >= min2)) {
|
|
23480
|
+
throw new RangeError('"output" expected length >= ' + min2);
|
|
23481
|
+
}
|
|
23482
|
+
}
|
|
23483
|
+
function aoutput32(out, instance) {
|
|
23484
|
+
aoutput(out, instance);
|
|
23485
|
+
if (!isAligned32(out))
|
|
23486
|
+
throw new Error("invalid output, must be aligned");
|
|
23487
|
+
}
|
|
23488
|
+
function u8(arr) {
|
|
23489
|
+
return new Uint8Array(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
23490
|
+
}
|
|
23491
|
+
function u32(arr) {
|
|
23492
|
+
return new Uint32Array(arr.buffer, arr.byteOffset, Math.floor(arr.byteLength / 4));
|
|
23493
|
+
}
|
|
23494
|
+
function clean(...arrays) {
|
|
23495
|
+
for (let i2 = 0; i2 < arrays.length; i2++) {
|
|
23496
|
+
arrays[i2].fill(0);
|
|
23497
|
+
}
|
|
23498
|
+
}
|
|
23499
|
+
function createView(arr) {
|
|
23500
|
+
return new DataView(arr.buffer, arr.byteOffset, arr.byteLength);
|
|
23501
|
+
}
|
|
23502
|
+
const isLE = /* @__PURE__ */ (() => new Uint8Array(new Uint32Array([287454020]).buffer)[0] === 68)();
|
|
23503
|
+
function byteSwap(word) {
|
|
23504
|
+
return word << 24 & 4278190080 | word << 8 & 16711680 | word >>> 8 & 65280 | word >>> 24 & 255;
|
|
23505
|
+
}
|
|
23506
|
+
const swap8IfBE = isLE ? (n) => n : (n) => byteSwap(n) >>> 0;
|
|
23507
|
+
function byteSwap32(arr) {
|
|
23508
|
+
for (let i2 = 0; i2 < arr.length; i2++) {
|
|
23509
|
+
arr[i2] = byteSwap(arr[i2]);
|
|
23510
|
+
}
|
|
23511
|
+
return arr;
|
|
23512
|
+
}
|
|
23513
|
+
const swap32IfBE = isLE ? (u) => u : byteSwap32;
|
|
23514
|
+
function overlapBytes(a, b) {
|
|
23515
|
+
if (!a.byteLength || !b.byteLength)
|
|
23516
|
+
return false;
|
|
23517
|
+
return a.buffer === b.buffer && // best we can do, may fail with an obscure Proxy
|
|
23518
|
+
a.byteOffset < b.byteOffset + b.byteLength && // a starts before b end
|
|
23519
|
+
b.byteOffset < a.byteOffset + a.byteLength;
|
|
23520
|
+
}
|
|
23521
|
+
function complexOverlapBytes(input, output) {
|
|
23522
|
+
if (overlapBytes(input, output) && input.byteOffset < output.byteOffset)
|
|
23523
|
+
throw new Error("complex overlap of input and output is not supported");
|
|
23524
|
+
}
|
|
23525
|
+
function wrapMacConstructor(keyLen, macCons, fromMsg) {
|
|
23526
|
+
const mac = macCons;
|
|
23527
|
+
const getArgs = fromMsg || (() => []);
|
|
23528
|
+
const macC = (msg2, key) => mac(key, ...getArgs(msg2)).update(msg2).digest();
|
|
23529
|
+
const tmp = mac(new Uint8Array(keyLen), ...getArgs(new Uint8Array(0)));
|
|
23530
|
+
macC.outputLen = tmp.outputLen;
|
|
23531
|
+
macC.blockLen = tmp.blockLen;
|
|
23532
|
+
macC.create = (key, ...args) => mac(key, ...args);
|
|
23533
|
+
return macC;
|
|
23534
|
+
}
|
|
23535
|
+
function getOutput(expectedLength, out, onlyAligned = true) {
|
|
23536
|
+
if (out === void 0)
|
|
23537
|
+
return new Uint8Array(expectedLength);
|
|
23538
|
+
abytes(out, expectedLength, "output");
|
|
23539
|
+
if (onlyAligned && !isAligned32(out))
|
|
23540
|
+
throw new Error("invalid output, must be aligned");
|
|
23541
|
+
return out;
|
|
23542
|
+
}
|
|
23543
|
+
function isAligned32(bytes2) {
|
|
23544
|
+
return bytes2.byteOffset % 4 === 0;
|
|
23545
|
+
}
|
|
23546
|
+
function copyBytes(bytes2) {
|
|
23547
|
+
return Uint8Array.from(abytes(bytes2));
|
|
23548
|
+
}
|
|
23549
|
+
const BLOCK_SIZE$1 = 16;
|
|
23550
|
+
const ZEROS16 = /* @__PURE__ */ new Uint8Array(16);
|
|
23551
|
+
const ZEROS32 = /* @__PURE__ */ u32(ZEROS16);
|
|
23552
|
+
const POLY$1 = 225;
|
|
23553
|
+
const mul2$1 = (s0, s1, s2, s3) => {
|
|
23554
|
+
const hiBit = s3 & 1;
|
|
23555
|
+
return {
|
|
23556
|
+
s3: s2 << 31 | s3 >>> 1,
|
|
23557
|
+
s2: s1 << 31 | s2 >>> 1,
|
|
23558
|
+
s1: s0 << 31 | s1 >>> 1,
|
|
23559
|
+
// NIST SP 800-38D §6.3 applies `V >> 1` and XORs R on carry. In this
|
|
23560
|
+
// 4x32-bit split, R = 0xe1 || 0^120 lives in the top byte of s0.
|
|
23561
|
+
s0: s0 >>> 1 ^ POLY$1 << 24 & -(hiBit & 1)
|
|
23562
|
+
// reduce % poly
|
|
23563
|
+
};
|
|
23564
|
+
};
|
|
23565
|
+
const swapLE = (n) => (n >>> 0 & 255) << 24 | (n >>> 8 & 255) << 16 | (n >>> 16 & 255) << 8 | n >>> 24 & 255 | 0;
|
|
23566
|
+
const estimateWindow = (bytes2) => {
|
|
23567
|
+
if (bytes2 > 64 * 1024)
|
|
23568
|
+
return 8;
|
|
23569
|
+
if (bytes2 > 1024)
|
|
23570
|
+
return 4;
|
|
23571
|
+
return 2;
|
|
23572
|
+
};
|
|
23573
|
+
class GHASH {
|
|
23574
|
+
// We select bits per window adaptively based on expectedLength
|
|
23575
|
+
constructor(key, expectedLength) {
|
|
23576
|
+
__publicField(this, "blockLen", BLOCK_SIZE$1);
|
|
23577
|
+
__publicField(this, "outputLen", BLOCK_SIZE$1);
|
|
23578
|
+
__publicField(this, "s0", 0);
|
|
23579
|
+
__publicField(this, "s1", 0);
|
|
23580
|
+
__publicField(this, "s2", 0);
|
|
23581
|
+
__publicField(this, "s3", 0);
|
|
23582
|
+
__publicField(this, "finished", false);
|
|
23583
|
+
__publicField(this, "destroyed", false);
|
|
23584
|
+
__publicField(this, "t");
|
|
23585
|
+
__publicField(this, "W");
|
|
23586
|
+
__publicField(this, "windowSize");
|
|
23587
|
+
abytes(key, 16, "key");
|
|
23588
|
+
key = copyBytes(key);
|
|
23589
|
+
const kView = createView(key);
|
|
23590
|
+
let k0 = kView.getUint32(0, false);
|
|
23591
|
+
let k1 = kView.getUint32(4, false);
|
|
23592
|
+
let k2 = kView.getUint32(8, false);
|
|
23593
|
+
let k3 = kView.getUint32(12, false);
|
|
23594
|
+
const doubles = [];
|
|
23595
|
+
for (let i2 = 0; i2 < 128; i2++) {
|
|
23596
|
+
doubles.push({ s0: swapLE(k0), s1: swapLE(k1), s2: swapLE(k2), s3: swapLE(k3) });
|
|
23597
|
+
({ s0: k0, s1: k1, s2: k2, s3: k3 } = mul2$1(k0, k1, k2, k3));
|
|
23598
|
+
}
|
|
23599
|
+
const W2 = estimateWindow(expectedLength || 1024);
|
|
23600
|
+
if (![1, 2, 4, 8].includes(W2))
|
|
23601
|
+
throw new Error("ghash: invalid window size, expected 2, 4 or 8");
|
|
23602
|
+
this.W = W2;
|
|
23603
|
+
const bits = 128;
|
|
23604
|
+
const windows = bits / W2;
|
|
23605
|
+
const windowSize = this.windowSize = 2 ** W2;
|
|
23606
|
+
const items = [];
|
|
23607
|
+
for (let w = 0; w < windows; w++) {
|
|
23608
|
+
for (let byte = 0; byte < windowSize; byte++) {
|
|
23609
|
+
let s0 = 0, s1 = 0, s2 = 0, s3 = 0;
|
|
23610
|
+
for (let j = 0; j < W2; j++) {
|
|
23611
|
+
const bit = byte >>> W2 - j - 1 & 1;
|
|
23612
|
+
if (!bit)
|
|
23613
|
+
continue;
|
|
23614
|
+
const { s0: d0, s1: d1, s2: d2, s3: d3 } = doubles[W2 * w + j];
|
|
23615
|
+
s0 ^= d0, s1 ^= d1, s2 ^= d2, s3 ^= d3;
|
|
23616
|
+
}
|
|
23617
|
+
items.push({ s0, s1, s2, s3 });
|
|
23618
|
+
}
|
|
23619
|
+
}
|
|
23620
|
+
this.t = items;
|
|
23621
|
+
}
|
|
23622
|
+
_updateBlock(s0, s1, s2, s3) {
|
|
23623
|
+
s0 ^= this.s0, s1 ^= this.s1, s2 ^= this.s2, s3 ^= this.s3;
|
|
23624
|
+
const { W: W2, t, windowSize } = this;
|
|
23625
|
+
let o0 = 0, o1 = 0, o2 = 0, o3 = 0;
|
|
23626
|
+
const mask = (1 << W2) - 1;
|
|
23627
|
+
let w = 0;
|
|
23628
|
+
for (const num of [s0, s1, s2, s3]) {
|
|
23629
|
+
for (let bytePos = 0; bytePos < 4; bytePos++) {
|
|
23630
|
+
const byte = num >>> 8 * bytePos & 255;
|
|
23631
|
+
for (let bitPos = 8 / W2 - 1; bitPos >= 0; bitPos--) {
|
|
23632
|
+
const bit = byte >>> W2 * bitPos & mask;
|
|
23633
|
+
const { s0: e0, s1: e1, s2: e2, s3: e3 } = t[w * windowSize + bit];
|
|
23634
|
+
o0 ^= e0, o1 ^= e1, o2 ^= e2, o3 ^= e3;
|
|
23635
|
+
w += 1;
|
|
23636
|
+
}
|
|
23637
|
+
}
|
|
23638
|
+
}
|
|
23639
|
+
this.s0 = o0;
|
|
23640
|
+
this.s1 = o1;
|
|
23641
|
+
this.s2 = o2;
|
|
23642
|
+
this.s3 = o3;
|
|
23643
|
+
}
|
|
23644
|
+
update(data2) {
|
|
23645
|
+
aexists(this);
|
|
23646
|
+
abytes(data2);
|
|
23647
|
+
data2 = copyBytes(data2);
|
|
23648
|
+
const b32 = u32(data2);
|
|
23649
|
+
const blocks = Math.floor(data2.length / BLOCK_SIZE$1);
|
|
23650
|
+
const left = data2.length % BLOCK_SIZE$1;
|
|
23651
|
+
for (let i2 = 0; i2 < blocks; i2++) {
|
|
23652
|
+
this._updateBlock(swap8IfBE(b32[i2 * 4 + 0]), swap8IfBE(b32[i2 * 4 + 1]), swap8IfBE(b32[i2 * 4 + 2]), swap8IfBE(b32[i2 * 4 + 3]));
|
|
23653
|
+
}
|
|
23654
|
+
if (left) {
|
|
23655
|
+
ZEROS16.set(data2.subarray(blocks * BLOCK_SIZE$1));
|
|
23656
|
+
this._updateBlock(swap8IfBE(ZEROS32[0]), swap8IfBE(ZEROS32[1]), swap8IfBE(ZEROS32[2]), swap8IfBE(ZEROS32[3]));
|
|
23657
|
+
clean(ZEROS32);
|
|
23658
|
+
}
|
|
23659
|
+
return this;
|
|
23660
|
+
}
|
|
23661
|
+
destroy() {
|
|
23662
|
+
this.destroyed = true;
|
|
23663
|
+
const { t } = this;
|
|
23664
|
+
for (const elm of t) {
|
|
23665
|
+
elm.s0 = 0, elm.s1 = 0, elm.s2 = 0, elm.s3 = 0;
|
|
23666
|
+
}
|
|
23667
|
+
}
|
|
23668
|
+
digestInto(out) {
|
|
23669
|
+
aexists(this);
|
|
23670
|
+
aoutput32(out, this);
|
|
23671
|
+
this.finished = true;
|
|
23672
|
+
const { s0, s1, s2, s3 } = this;
|
|
23673
|
+
const o32 = u32(out);
|
|
23674
|
+
o32[0] = s0;
|
|
23675
|
+
o32[1] = s1;
|
|
23676
|
+
o32[2] = s2;
|
|
23677
|
+
o32[3] = s3;
|
|
23678
|
+
if (!isLE)
|
|
23679
|
+
swap32IfBE(o32.subarray(0, BLOCK_SIZE$1 / 4));
|
|
23680
|
+
}
|
|
23681
|
+
digest() {
|
|
23682
|
+
const res = new Uint8Array(BLOCK_SIZE$1);
|
|
23683
|
+
this.digestInto(res);
|
|
23684
|
+
this.destroy();
|
|
23685
|
+
return res;
|
|
23686
|
+
}
|
|
23687
|
+
}
|
|
23688
|
+
const BLOCK_SIZE = 16;
|
|
23689
|
+
const BLOCK_SIZE32 = 4;
|
|
23690
|
+
const EMPTY_BLOCK = /* @__PURE__ */ new Uint8Array(BLOCK_SIZE);
|
|
23691
|
+
const ONE_BLOCK = /* @__PURE__ */ Uint8Array.from([
|
|
23692
|
+
0,
|
|
23693
|
+
0,
|
|
23694
|
+
0,
|
|
23695
|
+
0,
|
|
23696
|
+
0,
|
|
23697
|
+
0,
|
|
23698
|
+
0,
|
|
23699
|
+
0,
|
|
23700
|
+
0,
|
|
23701
|
+
0,
|
|
23702
|
+
0,
|
|
23703
|
+
0,
|
|
23704
|
+
0,
|
|
23705
|
+
0,
|
|
23706
|
+
0,
|
|
23707
|
+
1
|
|
23708
|
+
]);
|
|
23709
|
+
const POLY = 283;
|
|
23710
|
+
function validateKeyLength(key) {
|
|
23711
|
+
if (![16, 24, 32].includes(key.length))
|
|
23712
|
+
throw new Error('"aes key" expected Uint8Array of length 16/24/32, got length=' + key.length);
|
|
23713
|
+
}
|
|
23714
|
+
function mul2(n) {
|
|
23715
|
+
return n << 1 ^ POLY & -(n >> 7);
|
|
23716
|
+
}
|
|
23717
|
+
function mul(a, b) {
|
|
23718
|
+
let res = 0;
|
|
23719
|
+
for (; b > 0; b >>= 1) {
|
|
23720
|
+
res ^= a & -(b & 1);
|
|
23721
|
+
a = mul2(a);
|
|
23722
|
+
}
|
|
23723
|
+
return res;
|
|
23724
|
+
}
|
|
23725
|
+
const sbox = /* @__PURE__ */ (() => {
|
|
23726
|
+
const t = new Uint8Array(256);
|
|
23727
|
+
for (let i2 = 0, x = 1; i2 < 256; i2++, x ^= mul2(x))
|
|
23728
|
+
t[i2] = x;
|
|
23729
|
+
const box = new Uint8Array(256);
|
|
23730
|
+
box[0] = 99;
|
|
23731
|
+
for (let i2 = 0; i2 < 255; i2++) {
|
|
23732
|
+
let x = t[255 - i2];
|
|
23733
|
+
x |= x << 8;
|
|
23734
|
+
box[t[i2]] = (x ^ x >> 4 ^ x >> 5 ^ x >> 6 ^ x >> 7 ^ 99) & 255;
|
|
23735
|
+
}
|
|
23736
|
+
clean(t);
|
|
23737
|
+
return box;
|
|
23738
|
+
})();
|
|
23739
|
+
const invSbox = /* @__PURE__ */ sbox.map((_, j) => sbox.indexOf(j));
|
|
23740
|
+
const rotr32_8 = (n) => n << 24 | n >>> 8;
|
|
23741
|
+
const rotl32_8 = (n) => n << 8 | n >>> 24;
|
|
23742
|
+
function genTtable(sbox2, fn) {
|
|
23743
|
+
if (sbox2.length !== 256)
|
|
23744
|
+
throw new Error("wrong sbox length");
|
|
23745
|
+
const T0 = new Uint32Array(256).map((_, j) => fn(sbox2[j]));
|
|
23746
|
+
const T1 = T0.map(rotl32_8);
|
|
23747
|
+
const T2 = T1.map(rotl32_8);
|
|
23748
|
+
const T3 = T2.map(rotl32_8);
|
|
23749
|
+
const T01 = new Uint32Array(256 * 256);
|
|
23750
|
+
const T23 = new Uint32Array(256 * 256);
|
|
23751
|
+
const sbox22 = new Uint16Array(256 * 256);
|
|
23752
|
+
for (let i2 = 0; i2 < 256; i2++) {
|
|
23753
|
+
for (let j = 0; j < 256; j++) {
|
|
23754
|
+
const idx = i2 * 256 + j;
|
|
23755
|
+
T01[idx] = T0[i2] ^ T1[j];
|
|
23756
|
+
T23[idx] = T2[i2] ^ T3[j];
|
|
23757
|
+
sbox22[idx] = sbox2[i2] << 8 | sbox2[j];
|
|
23758
|
+
}
|
|
23759
|
+
}
|
|
23760
|
+
return { sbox: sbox2, sbox2: sbox22, T0, T1, T2, T3, T01, T23 };
|
|
23761
|
+
}
|
|
23762
|
+
const tableEncoding = /* @__PURE__ */ genTtable(sbox, (s) => mul(s, 3) << 24 | s << 16 | s << 8 | mul(s, 2));
|
|
23763
|
+
const tableDecoding = /* @__PURE__ */ genTtable(invSbox, (s) => mul(s, 11) << 24 | mul(s, 13) << 16 | mul(s, 9) << 8 | mul(s, 14));
|
|
23764
|
+
const xPowers = /* @__PURE__ */ (() => {
|
|
23765
|
+
const p = new Uint8Array(16);
|
|
23766
|
+
for (let i2 = 0, x = 1; i2 < 16; i2++, x = mul2(x))
|
|
23767
|
+
p[i2] = x;
|
|
23768
|
+
return p;
|
|
23769
|
+
})();
|
|
23770
|
+
function expandKeyLE(key) {
|
|
23771
|
+
abytes(key);
|
|
23772
|
+
const len2 = key.length;
|
|
23773
|
+
validateKeyLength(key);
|
|
23774
|
+
const { sbox2 } = tableEncoding;
|
|
23775
|
+
const toClean = [];
|
|
23776
|
+
if (!isLE || !isAligned32(key))
|
|
23777
|
+
toClean.push(key = copyBytes(key));
|
|
23778
|
+
const k32 = swap32IfBE(u32(key));
|
|
23779
|
+
const Nk = k32.length;
|
|
23780
|
+
const subByte = (n) => applySbox(sbox2, n, n, n, n);
|
|
23781
|
+
const xk = new Uint32Array(len2 + 28);
|
|
23782
|
+
xk.set(k32);
|
|
23783
|
+
for (let i2 = Nk; i2 < xk.length; i2++) {
|
|
23784
|
+
let t = xk[i2 - 1];
|
|
23785
|
+
if (i2 % Nk === 0)
|
|
23786
|
+
t = subByte(rotr32_8(t)) ^ xPowers[i2 / Nk - 1];
|
|
23787
|
+
else if (Nk > 6 && i2 % Nk === 4)
|
|
23788
|
+
t = subByte(t);
|
|
23789
|
+
xk[i2] = xk[i2 - Nk] ^ t;
|
|
23790
|
+
}
|
|
23791
|
+
clean(...toClean);
|
|
23792
|
+
return xk;
|
|
23793
|
+
}
|
|
23794
|
+
function expandKeyDecLE(key) {
|
|
23795
|
+
const encKey = expandKeyLE(key);
|
|
23796
|
+
const xk = encKey.slice();
|
|
23797
|
+
const Nk = encKey.length;
|
|
23798
|
+
const { sbox2 } = tableEncoding;
|
|
23799
|
+
const { T0, T1, T2, T3 } = tableDecoding;
|
|
23800
|
+
for (let i2 = 0; i2 < Nk; i2 += 4) {
|
|
23801
|
+
for (let j = 0; j < 4; j++)
|
|
23802
|
+
xk[i2 + j] = encKey[Nk - i2 - 4 + j];
|
|
23803
|
+
}
|
|
23804
|
+
clean(encKey);
|
|
23805
|
+
for (let i2 = 4; i2 < Nk - 4; i2++) {
|
|
23806
|
+
const x = xk[i2];
|
|
23807
|
+
const w = applySbox(sbox2, x, x, x, x);
|
|
23808
|
+
xk[i2] = T0[w & 255] ^ T1[w >>> 8 & 255] ^ T2[w >>> 16 & 255] ^ T3[w >>> 24];
|
|
23809
|
+
}
|
|
23810
|
+
return xk;
|
|
23811
|
+
}
|
|
23812
|
+
function apply0123(T01, T23, s0, s1, s2, s3) {
|
|
23813
|
+
return T01[s0 << 8 & 65280 | s1 >>> 8 & 255] ^ T23[s2 >>> 8 & 65280 | s3 >>> 24 & 255];
|
|
23814
|
+
}
|
|
23815
|
+
function applySbox(sbox2, s0, s1, s2, s3) {
|
|
23816
|
+
return sbox2[s0 & 255 | s1 & 65280] | sbox2[s2 >>> 16 & 255 | s3 >>> 16 & 65280] << 16;
|
|
23817
|
+
}
|
|
23818
|
+
function encrypt(xk, s0, s1, s2, s3) {
|
|
23819
|
+
const { sbox2, T01, T23 } = tableEncoding;
|
|
23820
|
+
let k = 0;
|
|
23821
|
+
s0 ^= xk[k++], s1 ^= xk[k++], s2 ^= xk[k++], s3 ^= xk[k++];
|
|
23822
|
+
const rounds = xk.length / 4 - 2;
|
|
23823
|
+
for (let i2 = 0; i2 < rounds; i2++) {
|
|
23824
|
+
const t02 = xk[k++] ^ apply0123(T01, T23, s0, s1, s2, s3);
|
|
23825
|
+
const t12 = xk[k++] ^ apply0123(T01, T23, s1, s2, s3, s0);
|
|
23826
|
+
const t22 = xk[k++] ^ apply0123(T01, T23, s2, s3, s0, s1);
|
|
23827
|
+
const t32 = xk[k++] ^ apply0123(T01, T23, s3, s0, s1, s2);
|
|
23828
|
+
s0 = t02, s1 = t12, s2 = t22, s3 = t32;
|
|
23829
|
+
}
|
|
23830
|
+
const t0 = xk[k++] ^ applySbox(sbox2, s0, s1, s2, s3);
|
|
23831
|
+
const t1 = xk[k++] ^ applySbox(sbox2, s1, s2, s3, s0);
|
|
23832
|
+
const t2 = xk[k++] ^ applySbox(sbox2, s2, s3, s0, s1);
|
|
23833
|
+
const t3 = xk[k++] ^ applySbox(sbox2, s3, s0, s1, s2);
|
|
23834
|
+
return { s0: t0, s1: t1, s2: t2, s3: t3 };
|
|
23835
|
+
}
|
|
23836
|
+
function decrypt(xk, s0, s1, s2, s3) {
|
|
23837
|
+
const { sbox2, T01, T23 } = tableDecoding;
|
|
23838
|
+
let k = 0;
|
|
23839
|
+
s0 ^= xk[k++], s1 ^= xk[k++], s2 ^= xk[k++], s3 ^= xk[k++];
|
|
23840
|
+
const rounds = xk.length / 4 - 2;
|
|
23841
|
+
for (let i2 = 0; i2 < rounds; i2++) {
|
|
23842
|
+
const t02 = xk[k++] ^ apply0123(T01, T23, s0, s3, s2, s1);
|
|
23843
|
+
const t12 = xk[k++] ^ apply0123(T01, T23, s1, s0, s3, s2);
|
|
23844
|
+
const t22 = xk[k++] ^ apply0123(T01, T23, s2, s1, s0, s3);
|
|
23845
|
+
const t32 = xk[k++] ^ apply0123(T01, T23, s3, s2, s1, s0);
|
|
23846
|
+
s0 = t02, s1 = t12, s2 = t22, s3 = t32;
|
|
23847
|
+
}
|
|
23848
|
+
const t0 = xk[k++] ^ applySbox(sbox2, s0, s3, s2, s1);
|
|
23849
|
+
const t1 = xk[k++] ^ applySbox(sbox2, s1, s0, s3, s2);
|
|
23850
|
+
const t2 = xk[k++] ^ applySbox(sbox2, s2, s1, s0, s3);
|
|
23851
|
+
const t3 = xk[k++] ^ applySbox(sbox2, s3, s2, s1, s0);
|
|
23852
|
+
return { s0: t0, s1: t1, s2: t2, s3: t3 };
|
|
23853
|
+
}
|
|
23854
|
+
function ctrCounter(xk, nonce, src, dst) {
|
|
23855
|
+
abytes(nonce, BLOCK_SIZE, "nonce");
|
|
23856
|
+
abytes(src);
|
|
23857
|
+
const srcLen = src.length;
|
|
23858
|
+
dst = getOutput(srcLen, dst);
|
|
23859
|
+
complexOverlapBytes(src, dst);
|
|
23860
|
+
const ctr = nonce;
|
|
23861
|
+
const c32 = u32(ctr);
|
|
23862
|
+
const src32 = u32(src);
|
|
23863
|
+
const dst32 = u32(dst);
|
|
23864
|
+
for (let i2 = 0; i2 + 4 <= src32.length; i2 += 4) {
|
|
23865
|
+
const { s0, s1, s2, s3 } = encrypt(xk, swap8IfBE(c32[0]), swap8IfBE(c32[1]), swap8IfBE(c32[2]), swap8IfBE(c32[3]));
|
|
23866
|
+
dst32[i2 + 0] = src32[i2 + 0] ^ swap8IfBE(s0);
|
|
23867
|
+
dst32[i2 + 1] = src32[i2 + 1] ^ swap8IfBE(s1);
|
|
23868
|
+
dst32[i2 + 2] = src32[i2 + 2] ^ swap8IfBE(s2);
|
|
23869
|
+
dst32[i2 + 3] = src32[i2 + 3] ^ swap8IfBE(s3);
|
|
23870
|
+
for (let j = BLOCK_SIZE - 1, carry = 1; j >= 0; j--) {
|
|
23871
|
+
carry = carry + ctr[j] | 0;
|
|
23872
|
+
ctr[j] = carry & 255;
|
|
23873
|
+
carry >>>= 8;
|
|
23874
|
+
}
|
|
23875
|
+
}
|
|
23876
|
+
const start = BLOCK_SIZE * Math.floor(src32.length / BLOCK_SIZE32);
|
|
23877
|
+
if (start < srcLen) {
|
|
23878
|
+
const { s0, s1, s2, s3 } = encrypt(xk, swap8IfBE(c32[0]), swap8IfBE(c32[1]), swap8IfBE(c32[2]), swap8IfBE(c32[3]));
|
|
23879
|
+
const b32 = new Uint32Array([s0, s1, s2, s3]);
|
|
23880
|
+
swap32IfBE(b32);
|
|
23881
|
+
const buf = u8(b32);
|
|
23882
|
+
for (let i2 = start, pos = 0; i2 < srcLen; i2++, pos++)
|
|
23883
|
+
dst[i2] = src[i2] ^ buf[pos];
|
|
23884
|
+
clean(b32);
|
|
23885
|
+
}
|
|
23886
|
+
return dst;
|
|
23887
|
+
}
|
|
23888
|
+
function ctr32(xk, isLE2, nonce, src, dst) {
|
|
23889
|
+
abytes(nonce, BLOCK_SIZE, "nonce");
|
|
23890
|
+
abytes(src);
|
|
23891
|
+
dst = getOutput(src.length, dst);
|
|
23892
|
+
const ctr = nonce;
|
|
23893
|
+
const c32 = u32(ctr);
|
|
23894
|
+
const view = createView(ctr);
|
|
23895
|
+
const src32 = u32(src);
|
|
23896
|
+
const dst32 = u32(dst);
|
|
23897
|
+
const ctrPos = isLE2 ? 0 : 12;
|
|
23898
|
+
const srcLen = src.length;
|
|
23899
|
+
let ctrNum = view.getUint32(ctrPos, isLE2);
|
|
23900
|
+
for (let i2 = 0; i2 + 4 <= src32.length; i2 += 4) {
|
|
23901
|
+
const { s0, s1, s2, s3 } = encrypt(xk, swap8IfBE(c32[0]), swap8IfBE(c32[1]), swap8IfBE(c32[2]), swap8IfBE(c32[3]));
|
|
23902
|
+
dst32[i2 + 0] = src32[i2 + 0] ^ swap8IfBE(s0);
|
|
23903
|
+
dst32[i2 + 1] = src32[i2 + 1] ^ swap8IfBE(s1);
|
|
23904
|
+
dst32[i2 + 2] = src32[i2 + 2] ^ swap8IfBE(s2);
|
|
23905
|
+
dst32[i2 + 3] = src32[i2 + 3] ^ swap8IfBE(s3);
|
|
23906
|
+
ctrNum = ctrNum + 1 >>> 0;
|
|
23907
|
+
view.setUint32(ctrPos, ctrNum, isLE2);
|
|
23908
|
+
}
|
|
23909
|
+
const start = BLOCK_SIZE * Math.floor(src32.length / BLOCK_SIZE32);
|
|
23910
|
+
if (start < srcLen) {
|
|
23911
|
+
const { s0, s1, s2, s3 } = encrypt(xk, swap8IfBE(c32[0]), swap8IfBE(c32[1]), swap8IfBE(c32[2]), swap8IfBE(c32[3]));
|
|
23912
|
+
const b32 = new Uint32Array([s0, s1, s2, s3]);
|
|
23913
|
+
swap32IfBE(b32);
|
|
23914
|
+
const buf = u8(b32);
|
|
23915
|
+
for (let i2 = start, pos = 0; i2 < srcLen; i2++, pos++)
|
|
23916
|
+
dst[i2] = src[i2] ^ buf[pos];
|
|
23917
|
+
clean(b32);
|
|
23918
|
+
}
|
|
23919
|
+
return dst;
|
|
23920
|
+
}
|
|
23921
|
+
function isBytes32(a) {
|
|
23922
|
+
return a instanceof Uint32Array || ArrayBuffer.isView(a) && a.constructor.name === "Uint32Array";
|
|
23923
|
+
}
|
|
23924
|
+
function encryptBlock(xk, block) {
|
|
23925
|
+
abytes(block, 16, "block");
|
|
23926
|
+
if (!isBytes32(xk))
|
|
23927
|
+
throw new Error("_encryptBlock accepts result of expandKeyLE");
|
|
23928
|
+
const b32 = u32(block);
|
|
23929
|
+
swap32IfBE(b32);
|
|
23930
|
+
let { s0, s1, s2, s3 } = encrypt(xk, b32[0], b32[1], b32[2], b32[3]);
|
|
23931
|
+
b32[0] = s0, b32[1] = s1, b32[2] = s2, b32[3] = s3;
|
|
23932
|
+
swap32IfBE(b32);
|
|
23933
|
+
return block;
|
|
23934
|
+
}
|
|
23935
|
+
function decryptBlock(xk, block) {
|
|
23936
|
+
abytes(block, 16, "block");
|
|
23937
|
+
if (!isBytes32(xk))
|
|
23938
|
+
throw new Error("_decryptBlock accepts result of expandKeyLE");
|
|
23939
|
+
const b32 = u32(block);
|
|
23940
|
+
swap32IfBE(b32);
|
|
23941
|
+
let { s0, s1, s2, s3 } = decrypt(xk, b32[0], b32[1], b32[2], b32[3]);
|
|
23942
|
+
b32[0] = s0, b32[1] = s1, b32[2] = s2, b32[3] = s3;
|
|
23943
|
+
swap32IfBE(b32);
|
|
23944
|
+
return block;
|
|
23945
|
+
}
|
|
23946
|
+
function dbl(block) {
|
|
23947
|
+
let carry = 0;
|
|
23948
|
+
for (let i2 = BLOCK_SIZE - 1; i2 >= 0; i2--) {
|
|
23949
|
+
const newCarry = (block[i2] & 128) >>> 7;
|
|
23950
|
+
block[i2] = block[i2] << 1 | carry;
|
|
23951
|
+
carry = newCarry;
|
|
23952
|
+
}
|
|
23953
|
+
block[BLOCK_SIZE - 1] ^= 135 & -carry;
|
|
23954
|
+
return block;
|
|
23955
|
+
}
|
|
23956
|
+
function xorBlock(a, b) {
|
|
23957
|
+
if (a.length !== b.length)
|
|
23958
|
+
throw new Error("xorBlock: blocks must have same length");
|
|
23959
|
+
for (let i2 = 0; i2 < a.length; i2++) {
|
|
23960
|
+
a[i2] = a[i2] ^ b[i2];
|
|
23961
|
+
}
|
|
23962
|
+
return a;
|
|
23963
|
+
}
|
|
23964
|
+
function xorend(a, b) {
|
|
23965
|
+
if (b.length > a.length) {
|
|
23966
|
+
throw new Error("xorend: expected len(B) <= len(A)");
|
|
23967
|
+
}
|
|
23968
|
+
const offset2 = a.length - b.length;
|
|
23969
|
+
for (let i2 = 0; i2 < b.length; i2++) {
|
|
23970
|
+
a[offset2 + i2] = a[offset2 + i2] ^ b[i2];
|
|
23971
|
+
}
|
|
23972
|
+
return a;
|
|
23973
|
+
}
|
|
23974
|
+
class _CMAC {
|
|
23975
|
+
constructor(key) {
|
|
23976
|
+
__publicField(this, "blockLen", BLOCK_SIZE);
|
|
23977
|
+
__publicField(this, "outputLen", BLOCK_SIZE);
|
|
23978
|
+
// CMAC can only decide between `K1` and `K2` once the true final block is known,
|
|
23979
|
+
// so updates process older blocks eagerly but keep one pending block buffered.
|
|
23980
|
+
__publicField(this, "buffer");
|
|
23981
|
+
__publicField(this, "pos");
|
|
23982
|
+
__publicField(this, "finished");
|
|
23983
|
+
__publicField(this, "destroyed");
|
|
23984
|
+
__publicField(this, "k1");
|
|
23985
|
+
__publicField(this, "k2");
|
|
23986
|
+
__publicField(this, "x");
|
|
23987
|
+
__publicField(this, "x32");
|
|
23988
|
+
__publicField(this, "xk");
|
|
23989
|
+
abytes(key);
|
|
23990
|
+
validateKeyLength(key);
|
|
23991
|
+
this.xk = expandKeyLE(key);
|
|
23992
|
+
this.buffer = new Uint8Array(BLOCK_SIZE);
|
|
23993
|
+
this.pos = 0;
|
|
23994
|
+
this.finished = false;
|
|
23995
|
+
this.destroyed = false;
|
|
23996
|
+
this.x = new Uint8Array(BLOCK_SIZE);
|
|
23997
|
+
this.x32 = u32(this.x);
|
|
23998
|
+
const L = new Uint8Array(BLOCK_SIZE);
|
|
23999
|
+
encryptBlock(this.xk, L);
|
|
24000
|
+
this.k1 = dbl(L);
|
|
24001
|
+
this.k2 = dbl(new Uint8Array(this.k1));
|
|
24002
|
+
}
|
|
24003
|
+
// Consumes 16 bytes of `data` starting at `pos`; `pos` avoids a per-block
|
|
24004
|
+
// subarray view allocation in update().
|
|
24005
|
+
process(data2, pos) {
|
|
24006
|
+
const { x, x32, xk } = this;
|
|
24007
|
+
for (let i2 = 0; i2 < BLOCK_SIZE; i2++)
|
|
24008
|
+
x[i2] ^= data2[pos + i2];
|
|
24009
|
+
swap32IfBE(x32);
|
|
24010
|
+
const { s0, s1, s2, s3 } = encrypt(xk, x32[0], x32[1], x32[2], x32[3]);
|
|
24011
|
+
x32[0] = s0, x32[1] = s1, x32[2] = s2, x32[3] = s3;
|
|
24012
|
+
swap32IfBE(x32);
|
|
24013
|
+
}
|
|
24014
|
+
update(data2) {
|
|
24015
|
+
aexists(this);
|
|
24016
|
+
abytes(data2);
|
|
24017
|
+
let pos = 0;
|
|
24018
|
+
if (this.pos) {
|
|
24019
|
+
const take = Math.min(BLOCK_SIZE - this.pos, data2.length);
|
|
24020
|
+
this.buffer.set(data2.subarray(0, take), this.pos);
|
|
24021
|
+
this.pos += take;
|
|
24022
|
+
pos = take;
|
|
24023
|
+
if (this.pos === BLOCK_SIZE && pos < data2.length) {
|
|
24024
|
+
this.process(this.buffer, 0);
|
|
24025
|
+
this.pos = 0;
|
|
24026
|
+
}
|
|
24027
|
+
}
|
|
24028
|
+
while (pos + BLOCK_SIZE < data2.length) {
|
|
24029
|
+
this.process(data2, pos);
|
|
24030
|
+
pos += BLOCK_SIZE;
|
|
24031
|
+
}
|
|
24032
|
+
if (pos < data2.length) {
|
|
24033
|
+
this.buffer.set(data2.subarray(pos), 0);
|
|
24034
|
+
this.pos = data2.length - pos;
|
|
24035
|
+
}
|
|
24036
|
+
return this;
|
|
24037
|
+
}
|
|
24038
|
+
// See {@link https://www.rfc-editor.org/rfc/rfc4493.html#section-2.4 | RFC 4493 Section 2.4}.
|
|
24039
|
+
digestInto(out) {
|
|
24040
|
+
aexists(this);
|
|
24041
|
+
aoutput32(out, this);
|
|
24042
|
+
this.finished = true;
|
|
24043
|
+
const view = out.subarray(0, this.outputLen);
|
|
24044
|
+
let last = new Uint8Array(BLOCK_SIZE);
|
|
24045
|
+
if (this.pos === BLOCK_SIZE) {
|
|
24046
|
+
last.set(this.buffer);
|
|
24047
|
+
xorBlock(last, this.k1);
|
|
24048
|
+
} else {
|
|
24049
|
+
last.set(this.buffer.subarray(0, this.pos));
|
|
24050
|
+
last[this.pos] = 128;
|
|
24051
|
+
xorBlock(last, this.k2);
|
|
24052
|
+
}
|
|
24053
|
+
view.set(this.x);
|
|
24054
|
+
xorBlock(view, last);
|
|
24055
|
+
encryptBlock(this.xk, view);
|
|
24056
|
+
clean(last);
|
|
24057
|
+
}
|
|
24058
|
+
digest() {
|
|
24059
|
+
const { buffer: buffer2, outputLen } = this;
|
|
24060
|
+
this.digestInto(buffer2);
|
|
24061
|
+
const res = buffer2.slice(0, outputLen);
|
|
24062
|
+
this.destroy();
|
|
24063
|
+
return res;
|
|
24064
|
+
}
|
|
24065
|
+
destroy() {
|
|
24066
|
+
const { buffer: buffer2, destroyed, x, xk, k1, k2 } = this;
|
|
24067
|
+
if (destroyed)
|
|
24068
|
+
return;
|
|
24069
|
+
this.destroyed = true;
|
|
24070
|
+
clean(buffer2, x, xk, k1, k2);
|
|
24071
|
+
}
|
|
24072
|
+
}
|
|
24073
|
+
const cmac = /* @__PURE__ */ wrapMacConstructor(16, (key) => new _CMAC(key));
|
|
24074
|
+
function s2v(key, strings) {
|
|
24075
|
+
validateKeyLength(key);
|
|
24076
|
+
const len2 = strings.length;
|
|
24077
|
+
if (len2 > 127) {
|
|
24078
|
+
throw new Error("s2v: expected <= 127 inputs");
|
|
24079
|
+
}
|
|
24080
|
+
if (len2 === 0)
|
|
24081
|
+
return cmac(ONE_BLOCK, key);
|
|
24082
|
+
let d = cmac(EMPTY_BLOCK, key);
|
|
24083
|
+
for (let i2 = 0; i2 < len2 - 1; i2++) {
|
|
24084
|
+
dbl(d);
|
|
24085
|
+
const cmacResult = cmac(strings[i2], key);
|
|
24086
|
+
xorBlock(d, cmacResult);
|
|
24087
|
+
clean(cmacResult);
|
|
24088
|
+
}
|
|
24089
|
+
const s_n = strings[len2 - 1];
|
|
24090
|
+
abytes(s_n);
|
|
24091
|
+
let t;
|
|
24092
|
+
if (s_n.byteLength >= BLOCK_SIZE) {
|
|
24093
|
+
t = xorend(Uint8Array.from(s_n), d);
|
|
24094
|
+
} else {
|
|
24095
|
+
const paddedSn = new Uint8Array(BLOCK_SIZE);
|
|
24096
|
+
paddedSn.set(s_n);
|
|
24097
|
+
paddedSn[s_n.length] = 128;
|
|
24098
|
+
t = xorBlock(dbl(d), paddedSn);
|
|
24099
|
+
clean(paddedSn);
|
|
24100
|
+
}
|
|
24101
|
+
const result = cmac(t, key);
|
|
24102
|
+
clean(d, t);
|
|
24103
|
+
return result;
|
|
24104
|
+
}
|
|
24105
|
+
const unsafe = /* @__PURE__ */ Object.freeze({
|
|
24106
|
+
expandKeyLE,
|
|
24107
|
+
expandKeyDecLE,
|
|
24108
|
+
encrypt,
|
|
24109
|
+
decrypt,
|
|
24110
|
+
encryptBlock,
|
|
24111
|
+
decryptBlock,
|
|
24112
|
+
ctrCounter,
|
|
24113
|
+
ctr32,
|
|
24114
|
+
dbl,
|
|
24115
|
+
xorBlock,
|
|
24116
|
+
xorend,
|
|
24117
|
+
s2v
|
|
24118
|
+
});
|
|
24119
|
+
const CIPHERS = /^aes-(128|192|256)-(gcm|cbc|ctr|ecb)$/u;
|
|
24120
|
+
function cipherNames() {
|
|
24121
|
+
const names2 = [];
|
|
24122
|
+
for (const bits of [128, 192, 256]) for (const mode of ["cbc", "ctr", "ecb", "gcm"]) names2.push(`aes-${bits}-${mode}`);
|
|
24123
|
+
return names2;
|
|
24124
|
+
}
|
|
24125
|
+
const GCM_TAG_LENGTHS = /* @__PURE__ */ new Set([4, 8, 12, 13, 14, 15, 16]);
|
|
24126
|
+
function createCipherClasses(deps) {
|
|
24127
|
+
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;
|
|
24128
|
+
const { error } = deps;
|
|
24129
|
+
function parse4(algorithm) {
|
|
24130
|
+
if (typeof algorithm !== "string") throw Object.assign(new TypeError('The "cipher" argument must be of type string.'), { code: "ERR_INVALID_ARG_TYPE" });
|
|
24131
|
+
const match = CIPHERS.exec(algorithm.toLowerCase());
|
|
24132
|
+
if (!match) throw error("ERR_CRYPTO_UNKNOWN_CIPHER", "Unknown cipher");
|
|
24133
|
+
return { keyLength: Number(match[1]) / 8, mode: match[2] };
|
|
24134
|
+
}
|
|
24135
|
+
function keyOf(key, keyLength) {
|
|
24136
|
+
const bytes2 = deps.secretKeyBytes(key) ?? deps.bytesOf(key);
|
|
24137
|
+
if (bytes2.length !== keyLength) throw Object.assign(new RangeError("Invalid key length"), { code: "ERR_CRYPTO_INVALID_KEYLEN" });
|
|
24138
|
+
return new Uint8Array(bytes2);
|
|
24139
|
+
}
|
|
24140
|
+
function ivOf(iv, mode) {
|
|
24141
|
+
if (mode === "ecb") {
|
|
24142
|
+
if (iv === null || iv === void 0) return void 0;
|
|
24143
|
+
const bytes22 = deps.bytesOf(iv);
|
|
24144
|
+
if (bytes22.length !== 0) throw Object.assign(new TypeError("Invalid initialization vector"), { code: "ERR_CRYPTO_INVALID_IV" });
|
|
24145
|
+
return void 0;
|
|
24146
|
+
}
|
|
24147
|
+
if (iv === null || iv === void 0) throw Object.assign(new TypeError("Invalid initialization vector"), { code: "ERR_CRYPTO_INVALID_IV" });
|
|
24148
|
+
const bytes2 = new Uint8Array(deps.bytesOf(iv));
|
|
24149
|
+
if (mode === "gcm" ? bytes2.length === 0 : bytes2.length !== 16) throw Object.assign(new TypeError("Invalid initialization vector"), { code: "ERR_CRYPTO_INVALID_IV" });
|
|
24150
|
+
return bytes2;
|
|
24151
|
+
}
|
|
24152
|
+
function encryptBlock2(xk, block) {
|
|
24153
|
+
const out = new Uint8Array(16);
|
|
24154
|
+
out.set(block);
|
|
24155
|
+
return unsafe.encryptBlock(xk, out);
|
|
24156
|
+
}
|
|
24157
|
+
function decryptBlock2(xk, block) {
|
|
24158
|
+
const out = new Uint8Array(16);
|
|
24159
|
+
out.set(block);
|
|
24160
|
+
return unsafe.decryptBlock(xk, out);
|
|
24161
|
+
}
|
|
24162
|
+
function concat(a, b) {
|
|
24163
|
+
if (a.length === 0) return b;
|
|
24164
|
+
if (b.length === 0) return a;
|
|
24165
|
+
const out = new Uint8Array(a.length + b.length);
|
|
24166
|
+
out.set(a);
|
|
24167
|
+
out.set(b, a.length);
|
|
24168
|
+
return out;
|
|
24169
|
+
}
|
|
24170
|
+
function increment(counter, from) {
|
|
24171
|
+
for (let i2 = 15; i2 >= from; i2--) {
|
|
24172
|
+
counter[i2] = counter[i2] + 1 & 255;
|
|
24173
|
+
if (counter[i2] !== 0) return;
|
|
24174
|
+
}
|
|
24175
|
+
}
|
|
24176
|
+
let authTagOf;
|
|
24177
|
+
let expectTagOf;
|
|
24178
|
+
class CipherBase {
|
|
24179
|
+
constructor(decrypt2, algorithm, key, iv, options) {
|
|
24180
|
+
__privateAdd(this, _CipherBase_instances);
|
|
24181
|
+
__privateAdd(this, _decrypt);
|
|
24182
|
+
__privateAdd(this, _mode);
|
|
24183
|
+
__privateAdd(this, _xk);
|
|
24184
|
+
__privateAdd(this, _xkDec);
|
|
24185
|
+
__privateAdd(this, _padding, true);
|
|
24186
|
+
__privateAdd(this, _finished, false);
|
|
24187
|
+
__privateAdd(this, _started, false);
|
|
24188
|
+
/** CBC/ECB: bytes not yet a whole block (and, decrypting with padding, the last whole block). */
|
|
24189
|
+
__privateAdd(this, _pending, new Uint8Array(0));
|
|
24190
|
+
/** CBC's chaining block. */
|
|
24191
|
+
__privateAdd(this, _chain);
|
|
24192
|
+
/** CTR/GCM: the next counter block and what is left of the current keystream block. */
|
|
24193
|
+
__privateAdd(this, _counter);
|
|
24194
|
+
__privateAdd(this, _keystream, new Uint8Array(0));
|
|
24195
|
+
/** GCM. */
|
|
24196
|
+
__privateAdd(this, _ghash);
|
|
24197
|
+
__privateAdd(this, _tagMask);
|
|
24198
|
+
__privateAdd(this, _ghashPending, new Uint8Array(0));
|
|
24199
|
+
__privateAdd(this, _aadLength, 0);
|
|
24200
|
+
__privateAdd(this, _dataLength, 0);
|
|
24201
|
+
__privateAdd(this, _authTagLength);
|
|
24202
|
+
__privateAdd(this, _authTag);
|
|
24203
|
+
const { keyLength, mode } = parse4(algorithm);
|
|
24204
|
+
__privateSet(this, _decrypt, decrypt2);
|
|
24205
|
+
__privateSet(this, _mode, mode);
|
|
24206
|
+
const keyBytes = keyOf(key, keyLength);
|
|
24207
|
+
const ivBytes = ivOf(iv, mode);
|
|
24208
|
+
__privateSet(this, _xk, unsafe.expandKeyLE(keyBytes));
|
|
24209
|
+
__privateSet(this, _xkDec, decrypt2 && (mode === "cbc" || mode === "ecb") ? unsafe.expandKeyDecLE(keyBytes) : void 0);
|
|
24210
|
+
const tagLength = options == null ? void 0 : options.authTagLength;
|
|
24211
|
+
if (tagLength !== void 0) {
|
|
24212
|
+
if (mode !== "gcm") throw Object.assign(new TypeError(`Invalid authentication tag length: ${tagLength}`), { code: "ERR_CRYPTO_INVALID_AUTH_TAG" });
|
|
24213
|
+
if (!GCM_TAG_LENGTHS.has(tagLength)) throw Object.assign(new TypeError(`Invalid authentication tag length: ${tagLength}`), { code: "ERR_CRYPTO_INVALID_AUTH_TAG" });
|
|
24214
|
+
__privateSet(this, _authTagLength, tagLength);
|
|
24215
|
+
}
|
|
24216
|
+
if (mode === "cbc") __privateSet(this, _chain, ivBytes);
|
|
24217
|
+
if (mode === "ctr") __privateSet(this, _counter, new Uint8Array(ivBytes));
|
|
24218
|
+
if (mode === "gcm") {
|
|
24219
|
+
const h = encryptBlock2(__privateGet(this, _xk), new Uint8Array(16));
|
|
24220
|
+
let j0;
|
|
24221
|
+
if (ivBytes.length === 12) {
|
|
24222
|
+
j0 = new Uint8Array(16);
|
|
24223
|
+
j0.set(ivBytes);
|
|
24224
|
+
j0[15] = 1;
|
|
24225
|
+
} else {
|
|
24226
|
+
const lengths = new Uint8Array(16);
|
|
24227
|
+
new DataView(lengths.buffer).setBigUint64(8, BigInt(ivBytes.length * 8), false);
|
|
24228
|
+
const g2 = new GHASH(h);
|
|
24229
|
+
g2.update(ivBytes).update(lengths);
|
|
24230
|
+
j0 = g2.digest();
|
|
24231
|
+
}
|
|
24232
|
+
__privateSet(this, _tagMask, encryptBlock2(__privateGet(this, _xk), j0));
|
|
24233
|
+
__privateSet(this, _counter, new Uint8Array(j0));
|
|
24234
|
+
increment(__privateGet(this, _counter), 12);
|
|
24235
|
+
__privateSet(this, _ghash, new GHASH(h));
|
|
24236
|
+
}
|
|
24237
|
+
}
|
|
24238
|
+
setAutoPadding(autoPadding = true) {
|
|
24239
|
+
if (__privateGet(this, _finished)) throw error("ERR_CRYPTO_INVALID_STATE", "Invalid state for operation setAutoPadding");
|
|
24240
|
+
__privateSet(this, _padding, Boolean(autoPadding));
|
|
24241
|
+
return this;
|
|
24242
|
+
}
|
|
24243
|
+
setAAD(buffer2, _options2) {
|
|
24244
|
+
if (__privateGet(this, _mode) !== "gcm" || __privateGet(this, _started) || __privateGet(this, _finished)) throw error("ERR_CRYPTO_INVALID_STATE", "Invalid state for operation setAAD");
|
|
24245
|
+
const aad = deps.bytesOf(buffer2);
|
|
24246
|
+
__privateGet(this, _ghash).update(aad);
|
|
24247
|
+
__privateSet(this, _aadLength, __privateGet(this, _aadLength) + aad.length);
|
|
24248
|
+
return this;
|
|
24249
|
+
}
|
|
24250
|
+
update(data2, inputEncoding, outputEncoding) {
|
|
24251
|
+
if (__privateGet(this, _finished)) throw error("ERR_CRYPTO_INVALID_STATE", "Invalid state for operation update");
|
|
24252
|
+
__privateSet(this, _started, true);
|
|
24253
|
+
const input = typeof data2 === "string" ? deps.bytesOf(data2, inputEncoding) : deps.bytesOf(data2);
|
|
24254
|
+
return deps.encode(__privateMethod(this, _CipherBase_instances, process_fn).call(this, new Uint8Array(input)), outputEncoding);
|
|
24255
|
+
}
|
|
24256
|
+
final(outputEncoding) {
|
|
24257
|
+
if (__privateGet(this, _finished)) throw error("ERR_CRYPTO_INVALID_STATE", "Unsupported state");
|
|
24258
|
+
__privateSet(this, _finished, true);
|
|
24259
|
+
return deps.encode(__privateMethod(this, _CipherBase_instances, finish_fn).call(this), outputEncoding);
|
|
24260
|
+
}
|
|
24261
|
+
}
|
|
24262
|
+
_decrypt = new WeakMap();
|
|
24263
|
+
_mode = new WeakMap();
|
|
24264
|
+
_xk = new WeakMap();
|
|
24265
|
+
_xkDec = new WeakMap();
|
|
24266
|
+
_padding = new WeakMap();
|
|
24267
|
+
_finished = new WeakMap();
|
|
24268
|
+
_started = new WeakMap();
|
|
24269
|
+
_pending = new WeakMap();
|
|
24270
|
+
_chain = new WeakMap();
|
|
24271
|
+
_counter = new WeakMap();
|
|
24272
|
+
_keystream = new WeakMap();
|
|
24273
|
+
_ghash = new WeakMap();
|
|
24274
|
+
_tagMask = new WeakMap();
|
|
24275
|
+
_ghashPending = new WeakMap();
|
|
24276
|
+
_aadLength = new WeakMap();
|
|
24277
|
+
_dataLength = new WeakMap();
|
|
24278
|
+
_authTagLength = new WeakMap();
|
|
24279
|
+
_authTag = new WeakMap();
|
|
24280
|
+
_CipherBase_instances = new WeakSet();
|
|
24281
|
+
getTag_fn = function() {
|
|
24282
|
+
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");
|
|
24283
|
+
return __privateGet(this, _authTag);
|
|
24284
|
+
};
|
|
24285
|
+
setTag_fn = function(tag, encoding) {
|
|
24286
|
+
if (__privateGet(this, _mode) !== "gcm" || !__privateGet(this, _decrypt) || __privateGet(this, _finished)) throw error("ERR_CRYPTO_INVALID_STATE", "Invalid state for operation setAuthTag");
|
|
24287
|
+
const bytes2 = new Uint8Array(typeof tag === "string" ? deps.bytesOf(tag, encoding) : deps.bytesOf(tag));
|
|
24288
|
+
const allowed = __privateGet(this, _authTagLength) === void 0 ? GCM_TAG_LENGTHS.has(bytes2.length) : bytes2.length === __privateGet(this, _authTagLength);
|
|
24289
|
+
if (!allowed) throw Object.assign(new TypeError(`Invalid authentication tag length: ${bytes2.length}`), { code: "ERR_CRYPTO_INVALID_AUTH_TAG" });
|
|
24290
|
+
__privateSet(this, _authTag, bytes2);
|
|
24291
|
+
};
|
|
24292
|
+
process_fn = function(input) {
|
|
24293
|
+
switch (__privateGet(this, _mode)) {
|
|
24294
|
+
case "ctr":
|
|
24295
|
+
return __privateMethod(this, _CipherBase_instances, stream_fn).call(this, input);
|
|
24296
|
+
case "gcm": {
|
|
24297
|
+
if (__privateGet(this, _decrypt)) __privateMethod(this, _CipherBase_instances, absorb_fn).call(this, input);
|
|
24298
|
+
const out = __privateMethod(this, _CipherBase_instances, stream_fn).call(this, input);
|
|
24299
|
+
if (!__privateGet(this, _decrypt)) __privateMethod(this, _CipherBase_instances, absorb_fn).call(this, out);
|
|
24300
|
+
__privateSet(this, _dataLength, __privateGet(this, _dataLength) + input.length);
|
|
24301
|
+
return out;
|
|
24302
|
+
}
|
|
24303
|
+
default:
|
|
24304
|
+
return __privateMethod(this, _CipherBase_instances, blocks_fn).call(this, input);
|
|
24305
|
+
}
|
|
24306
|
+
};
|
|
24307
|
+
/** XOR with the counter's keystream, carrying a partial block across calls. */
|
|
24308
|
+
stream_fn = function(input) {
|
|
24309
|
+
const out = new Uint8Array(input.length);
|
|
24310
|
+
let at2 = 0;
|
|
24311
|
+
while (at2 < input.length) {
|
|
24312
|
+
if (__privateGet(this, _keystream).length === 0) {
|
|
24313
|
+
__privateSet(this, _keystream, encryptBlock2(__privateGet(this, _xk), __privateGet(this, _counter)));
|
|
24314
|
+
increment(__privateGet(this, _counter), __privateGet(this, _mode) === "gcm" ? 12 : 0);
|
|
24315
|
+
}
|
|
24316
|
+
const take = Math.min(__privateGet(this, _keystream).length, input.length - at2);
|
|
24317
|
+
for (let i2 = 0; i2 < take; i2++) out[at2 + i2] = input[at2 + i2] ^ __privateGet(this, _keystream)[i2];
|
|
24318
|
+
__privateSet(this, _keystream, __privateGet(this, _keystream).subarray(take));
|
|
24319
|
+
at2 += take;
|
|
24320
|
+
}
|
|
24321
|
+
return out;
|
|
24322
|
+
};
|
|
24323
|
+
/** GHASH over the ciphertext, in whole blocks: GHASH pads each update, so a partial block waits for the next. */
|
|
24324
|
+
absorb_fn = function(ciphertext) {
|
|
24325
|
+
const all = concat(__privateGet(this, _ghashPending), ciphertext);
|
|
24326
|
+
const whole = all.length - all.length % 16;
|
|
24327
|
+
if (whole > 0) __privateGet(this, _ghash).update(all.subarray(0, whole));
|
|
24328
|
+
__privateSet(this, _ghashPending, all.slice(whole));
|
|
24329
|
+
};
|
|
24330
|
+
/** CBC and ECB: every whole block now; decrypting with padding, the last whole block waits for `final`. */
|
|
24331
|
+
blocks_fn = function(input) {
|
|
24332
|
+
const all = concat(__privateGet(this, _pending), input);
|
|
24333
|
+
let whole = all.length - all.length % 16;
|
|
24334
|
+
if (__privateGet(this, _decrypt) && __privateGet(this, _padding) && whole === all.length && whole > 0) whole -= 16;
|
|
24335
|
+
const out = new Uint8Array(whole);
|
|
24336
|
+
for (let at2 = 0; at2 < whole; at2 += 16) out.set(__privateMethod(this, _CipherBase_instances, block_fn).call(this, all.subarray(at2, at2 + 16)), at2);
|
|
24337
|
+
__privateSet(this, _pending, all.slice(whole));
|
|
24338
|
+
return out;
|
|
24339
|
+
};
|
|
24340
|
+
block_fn = function(block) {
|
|
24341
|
+
if (__privateGet(this, _mode) === "ecb") return __privateGet(this, _decrypt) ? decryptBlock2(__privateGet(this, _xkDec), block) : encryptBlock2(__privateGet(this, _xk), block);
|
|
24342
|
+
if (__privateGet(this, _decrypt)) {
|
|
24343
|
+
const plain = decryptBlock2(__privateGet(this, _xkDec), block);
|
|
24344
|
+
for (let i2 = 0; i2 < 16; i2++) plain[i2] = plain[i2] ^ __privateGet(this, _chain)[i2];
|
|
24345
|
+
__privateSet(this, _chain, new Uint8Array(block));
|
|
24346
|
+
return plain;
|
|
24347
|
+
}
|
|
24348
|
+
const mixed = new Uint8Array(16);
|
|
24349
|
+
for (let i2 = 0; i2 < 16; i2++) mixed[i2] = block[i2] ^ __privateGet(this, _chain)[i2];
|
|
24350
|
+
const cipher = encryptBlock2(__privateGet(this, _xk), mixed);
|
|
24351
|
+
__privateSet(this, _chain, cipher);
|
|
24352
|
+
return cipher;
|
|
24353
|
+
};
|
|
24354
|
+
finish_fn = function() {
|
|
24355
|
+
if (__privateGet(this, _mode) === "ctr") return new Uint8Array(0);
|
|
24356
|
+
if (__privateGet(this, _mode) === "gcm") return __privateMethod(this, _CipherBase_instances, finishGcm_fn).call(this);
|
|
24357
|
+
const rest = __privateGet(this, _pending);
|
|
24358
|
+
__privateSet(this, _pending, new Uint8Array(0));
|
|
24359
|
+
if (!__privateGet(this, _decrypt)) {
|
|
24360
|
+
if (!__privateGet(this, _padding)) {
|
|
24361
|
+
if (rest.length !== 0) throw error("ERR_OSSL_WRONG_FINAL_BLOCK_LENGTH", "error:1C80006B:Provider routines::wrong final block length");
|
|
24362
|
+
return rest;
|
|
24363
|
+
}
|
|
24364
|
+
const pad2 = 16 - rest.length;
|
|
24365
|
+
const block = new Uint8Array(16);
|
|
24366
|
+
block.set(rest);
|
|
24367
|
+
block.fill(pad2, rest.length);
|
|
24368
|
+
return __privateMethod(this, _CipherBase_instances, block_fn).call(this, block);
|
|
24369
|
+
}
|
|
24370
|
+
if (!__privateGet(this, _padding)) {
|
|
24371
|
+
if (rest.length !== 0) throw error("ERR_OSSL_WRONG_FINAL_BLOCK_LENGTH", "error:1C80006B:Provider routines::wrong final block length");
|
|
24372
|
+
return rest;
|
|
24373
|
+
}
|
|
24374
|
+
if (rest.length !== 16) throw error("ERR_OSSL_WRONG_FINAL_BLOCK_LENGTH", "error:1C80006B:Provider routines::wrong final block length");
|
|
24375
|
+
const plain = __privateMethod(this, _CipherBase_instances, block_fn).call(this, rest);
|
|
24376
|
+
const pad = plain[15];
|
|
24377
|
+
let valid = pad >= 1 && pad <= 16;
|
|
24378
|
+
for (let i2 = 16 - pad; valid && i2 < 16; i2++) valid = plain[i2] === pad;
|
|
24379
|
+
if (!valid) throw error("ERR_OSSL_BAD_DECRYPT", "error:1C800064:Provider routines::bad decrypt");
|
|
24380
|
+
return plain.slice(0, 16 - pad);
|
|
24381
|
+
};
|
|
24382
|
+
finishGcm_fn = function() {
|
|
24383
|
+
if (__privateGet(this, _ghashPending).length) __privateGet(this, _ghash).update(__privateGet(this, _ghashPending));
|
|
24384
|
+
const lengths = new Uint8Array(16);
|
|
24385
|
+
const view = new DataView(lengths.buffer);
|
|
24386
|
+
view.setBigUint64(0, BigInt(__privateGet(this, _aadLength) * 8), false);
|
|
24387
|
+
view.setBigUint64(8, BigInt(__privateGet(this, _dataLength) * 8), false);
|
|
24388
|
+
const full = __privateGet(this, _ghash).update(lengths).digest();
|
|
24389
|
+
for (let i2 = 0; i2 < 16; i2++) full[i2] = full[i2] ^ __privateGet(this, _tagMask)[i2];
|
|
24390
|
+
if (!__privateGet(this, _decrypt)) {
|
|
24391
|
+
__privateSet(this, _authTag, full.slice(0, __privateGet(this, _authTagLength) ?? 16));
|
|
24392
|
+
return new Uint8Array(0);
|
|
24393
|
+
}
|
|
24394
|
+
const expected = __privateGet(this, _authTag);
|
|
24395
|
+
let same = expected !== void 0;
|
|
24396
|
+
if (expected) for (let i2 = 0; i2 < expected.length; i2++) same = same && full[i2] === expected[i2];
|
|
24397
|
+
if (!same) throw new Error("Unsupported state or unable to authenticate data");
|
|
24398
|
+
return new Uint8Array(0);
|
|
24399
|
+
};
|
|
24400
|
+
authTagOf = (cipher) => {
|
|
24401
|
+
var _a2;
|
|
24402
|
+
return __privateMethod(_a2 = cipher, _CipherBase_instances, getTag_fn).call(_a2);
|
|
24403
|
+
};
|
|
24404
|
+
expectTagOf = (cipher, tag, encoding) => {
|
|
24405
|
+
var _a2;
|
|
24406
|
+
return __privateMethod(_a2 = cipher, _CipherBase_instances, setTag_fn).call(_a2, tag, encoding);
|
|
24407
|
+
};
|
|
24408
|
+
class Cipheriv2 extends CipherBase {
|
|
24409
|
+
constructor(algorithm, key, iv, options) {
|
|
24410
|
+
super(false, algorithm, key, iv, options);
|
|
24411
|
+
}
|
|
24412
|
+
getAuthTag() {
|
|
24413
|
+
return deps.toBuffer(authTagOf(this));
|
|
24414
|
+
}
|
|
24415
|
+
}
|
|
24416
|
+
class Decipheriv2 extends CipherBase {
|
|
24417
|
+
constructor(algorithm, key, iv, options) {
|
|
24418
|
+
super(true, algorithm, key, iv, options);
|
|
24419
|
+
}
|
|
24420
|
+
setAuthTag(tag, encoding) {
|
|
24421
|
+
expectTagOf(this, tag, encoding);
|
|
24422
|
+
return this;
|
|
24423
|
+
}
|
|
24424
|
+
}
|
|
24425
|
+
return {
|
|
24426
|
+
Cipheriv: Cipheriv2,
|
|
24427
|
+
Decipheriv: Decipheriv2,
|
|
24428
|
+
createCipheriv: (algorithm, key, iv, options) => new Cipheriv2(algorithm, key, iv, options),
|
|
24429
|
+
createDecipheriv: (algorithm, key, iv, options) => new Decipheriv2(algorithm, key, iv, options)
|
|
24430
|
+
};
|
|
24431
|
+
}
|
|
23452
24432
|
function createCryptoModule(require2) {
|
|
23453
24433
|
var _state, _done, _inner, _outer, _done2, _algorithm, _data, _algorithm2, _data2, __keyData, __type, __algorithm;
|
|
23454
24434
|
const bufferModule2 = require2 ? require2("buffer") : lazyModule("buffer");
|
|
@@ -24028,7 +25008,7 @@ ${body}
|
|
|
24028
25008
|
return result === 0;
|
|
24029
25009
|
}
|
|
24030
25010
|
function getCiphers2() {
|
|
24031
|
-
return
|
|
25011
|
+
return cipherNames();
|
|
24032
25012
|
}
|
|
24033
25013
|
function getHashes2() {
|
|
24034
25014
|
return HASH_ALGORITHMS.slice();
|
|
@@ -24149,7 +25129,25 @@ ${body}
|
|
|
24149
25129
|
}
|
|
24150
25130
|
throw new Error(`Unsupported key format: ${keyInfo.format}`);
|
|
24151
25131
|
}
|
|
25132
|
+
const { Cipheriv: Cipheriv2, Decipheriv: Decipheriv2, createCipheriv: createCipheriv2, createDecipheriv: createDecipheriv2 } = createCipherClasses({
|
|
25133
|
+
toBuffer: (bytes2) => Buffer2.from(bytes2),
|
|
25134
|
+
bytesOf: (value, encoding) => cryptoBytes(value, encoding, true),
|
|
25135
|
+
secretKeyBytes: (value) => {
|
|
25136
|
+
if (!(value instanceof KeyObject2)) return void 0;
|
|
25137
|
+
const info = keyInfoOf(value);
|
|
25138
|
+
if (info.type !== "secret" || !(info.keyData instanceof Uint8Array)) {
|
|
25139
|
+
throw Object.assign(new TypeError(`Invalid key object type ${info.type}, expected secret.`), { code: "ERR_CRYPTO_INVALID_KEY_OBJECT_TYPE" });
|
|
25140
|
+
}
|
|
25141
|
+
return info.keyData;
|
|
25142
|
+
},
|
|
25143
|
+
encode: (bytes2, encoding) => digestResult(bytes2, encoding),
|
|
25144
|
+
error: cryptoError
|
|
25145
|
+
});
|
|
24152
25146
|
return {
|
|
25147
|
+
Cipheriv: Cipheriv2,
|
|
25148
|
+
Decipheriv: Decipheriv2,
|
|
25149
|
+
createCipheriv: createCipheriv2,
|
|
25150
|
+
createDecipheriv: createDecipheriv2,
|
|
24153
25151
|
unsupported: unsupported2,
|
|
24154
25152
|
randomBytes: randomBytes2,
|
|
24155
25153
|
randomFill: randomFill2,
|
|
@@ -24178,12 +25176,16 @@ ${body}
|
|
|
24178
25176
|
};
|
|
24179
25177
|
}
|
|
24180
25178
|
const cryptoModule = createCryptoModule();
|
|
24181
|
-
const { randomBytes, randomFillSync, randomFill, randomUUID, randomInt, getRandomValues, unsupported: unsupported$1, createHash, createHmac, hash, pbkdf2Sync, pbkdf2, sign, verify, createSign, createVerify, KeyObject, createSecretKey, createPublicKey, createPrivateKey, generateKeyPair, timingSafeEqual, getCiphers, getHashes } = cryptoModule;
|
|
25179
|
+
const { Cipheriv, Decipheriv, createCipheriv, createDecipheriv, randomBytes, randomFillSync, randomFill, randomUUID, randomInt, getRandomValues, unsupported: unsupported$1, createHash, createHmac, hash, pbkdf2Sync, pbkdf2, sign, verify, createSign, createVerify, KeyObject, createSecretKey, createPublicKey, createPrivateKey, generateKeyPair, timingSafeEqual, getCiphers, getHashes } = cryptoModule;
|
|
24182
25180
|
const cryptoShim = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
24183
25181
|
__proto__: null,
|
|
25182
|
+
Cipheriv,
|
|
25183
|
+
Decipheriv,
|
|
24184
25184
|
KeyObject,
|
|
24185
25185
|
constants: cryptoConstants,
|
|
25186
|
+
createCipheriv,
|
|
24186
25187
|
createCryptoModule,
|
|
25188
|
+
createDecipheriv,
|
|
24187
25189
|
createHash,
|
|
24188
25190
|
createHmac,
|
|
24189
25191
|
createPrivateKey,
|
|
@@ -32424,6 +33426,68 @@ function guestPromise(owner) {
|
|
|
32424
33426
|
}
|
|
32425
33427
|
return constructor;
|
|
32426
33428
|
}
|
|
33429
|
+
const kIsDisturbed = Symbol.for("nodejs.stream.disturbed");
|
|
33430
|
+
function isAsyncIterableBody(body) {
|
|
33431
|
+
if (body === null || typeof body !== "object") return false;
|
|
33432
|
+
if (typeof ReadableStream === "function" && body instanceof ReadableStream) return false;
|
|
33433
|
+
if (typeof Blob === "function" && body instanceof Blob) return false;
|
|
33434
|
+
if (body instanceof ArrayBuffer || ArrayBuffer.isView(body)) return false;
|
|
33435
|
+
if (typeof FormData === "function" && body instanceof FormData) return false;
|
|
33436
|
+
if (body instanceof URLSearchParams) return false;
|
|
33437
|
+
return typeof body[Symbol.asyncIterator] === "function";
|
|
33438
|
+
}
|
|
33439
|
+
function refuseDisturbed(body) {
|
|
33440
|
+
const stream = body;
|
|
33441
|
+
const disturbed = stream[kIsDisturbed] !== void 0 ? Boolean(stream[kIsDisturbed]) : Boolean(stream.readableDidRead || stream.readableAborted);
|
|
33442
|
+
if (disturbed || stream.locked === true) throw new TypeError("Response body object should not be disturbed or locked");
|
|
33443
|
+
}
|
|
33444
|
+
function streamFrom(iterable) {
|
|
33445
|
+
let iterator;
|
|
33446
|
+
return new ReadableStream({
|
|
33447
|
+
async start() {
|
|
33448
|
+
iterator = iterable[Symbol.asyncIterator]();
|
|
33449
|
+
},
|
|
33450
|
+
async pull(controller) {
|
|
33451
|
+
for (; ; ) {
|
|
33452
|
+
const { done, value } = await iterator.next();
|
|
33453
|
+
if (done) {
|
|
33454
|
+
controller.close();
|
|
33455
|
+
return;
|
|
33456
|
+
}
|
|
33457
|
+
const bytes2 = Buffer$9.isBuffer(value) ? value : Buffer$9.from(value);
|
|
33458
|
+
if (bytes2.byteLength) {
|
|
33459
|
+
controller.enqueue(new Uint8Array(bytes2));
|
|
33460
|
+
return;
|
|
33461
|
+
}
|
|
33462
|
+
}
|
|
33463
|
+
},
|
|
33464
|
+
async cancel() {
|
|
33465
|
+
var _a2;
|
|
33466
|
+
await ((_a2 = iterator == null ? void 0 : iterator.return) == null ? void 0 : _a2.call(iterator));
|
|
33467
|
+
}
|
|
33468
|
+
}, { highWaterMark: 0 });
|
|
33469
|
+
}
|
|
33470
|
+
const REQUEST_INIT_MEMBERS = ["method", "headers", "referrer", "referrerPolicy", "mode", "credentials", "cache", "redirect", "integrity", "keepalive", "signal", "window", "duplex", "priority"];
|
|
33471
|
+
function withNodeRequestBody(init) {
|
|
33472
|
+
if (!init) return init;
|
|
33473
|
+
const body = init.body;
|
|
33474
|
+
if (!isAsyncIterableBody(body)) return init;
|
|
33475
|
+
refuseDisturbed(body);
|
|
33476
|
+
const copy2 = {};
|
|
33477
|
+
for (const member of Object.keys(init)) if (member !== "body") copy2[member] = init[member];
|
|
33478
|
+
for (const member of REQUEST_INIT_MEMBERS) {
|
|
33479
|
+
if (member in copy2) continue;
|
|
33480
|
+
const value = init[member];
|
|
33481
|
+
if (value !== void 0) copy2[member] = value;
|
|
33482
|
+
}
|
|
33483
|
+
copy2.body = streamFrom(body);
|
|
33484
|
+
return copy2;
|
|
33485
|
+
}
|
|
33486
|
+
function nodeResponseBody(body) {
|
|
33487
|
+
if (!isAsyncIterableBody(body)) return body;
|
|
33488
|
+
refuseDisturbed(body);
|
|
33489
|
+
return streamFrom(body);
|
|
33490
|
+
}
|
|
32427
33491
|
let transport;
|
|
32428
33492
|
const staticRequestBodies = /* @__PURE__ */ new WeakSet();
|
|
32429
33493
|
function rememberRequestBodySource(request, input, init) {
|
|
@@ -32478,14 +33542,19 @@ function activity(owner, cancel) {
|
|
|
32478
33542
|
function guestFetch(process2, fallback) {
|
|
32479
33543
|
return function fetch2(input, init) {
|
|
32480
33544
|
const adapter = transport;
|
|
32481
|
-
|
|
32482
|
-
const owner = __tokenForProcess(process2);
|
|
33545
|
+
const owner = adapter ? __tokenForProcess(process2) : null;
|
|
32483
33546
|
const ended = () => {
|
|
32484
33547
|
var _a2;
|
|
32485
33548
|
return owner !== null && ((_a2 = __runFor(owner)) == null ? void 0 : _a2.process) !== process2;
|
|
32486
33549
|
};
|
|
32487
33550
|
const stopped2 = () => new DOMException("The requesting process has ended.", "AbortError");
|
|
32488
|
-
if (ended()) return Promise.reject(stopped2());
|
|
33551
|
+
if (adapter && ended()) return Promise.reject(stopped2());
|
|
33552
|
+
try {
|
|
33553
|
+
init = withNodeRequestBody(init);
|
|
33554
|
+
} catch (error) {
|
|
33555
|
+
return Promise.reject(error);
|
|
33556
|
+
}
|
|
33557
|
+
if (!adapter) return fallback.call(globalThis, input, init);
|
|
32489
33558
|
const context2 = { begin(cancel) {
|
|
32490
33559
|
if (ended()) throw stopped2();
|
|
32491
33560
|
return activity(owner, cancel);
|
|
@@ -32529,7 +33598,8 @@ function installNodeResponse(target) {
|
|
|
32529
33598
|
const Native = target.Response;
|
|
32530
33599
|
if (typeof Native !== "function" || Native[INSTALLED]) return;
|
|
32531
33600
|
const proto = Native.prototype;
|
|
32532
|
-
|
|
33601
|
+
let nativeHeaders;
|
|
33602
|
+
for (let at2 = proto; at2 && !nativeHeaders; at2 = Object.getPrototypeOf(at2)) nativeHeaders = (_a2 = Object.getOwnPropertyDescriptor(at2, "headers")) == null ? void 0 : _a2.get;
|
|
32533
33603
|
const nativeFormData = proto.formData;
|
|
32534
33604
|
const nativeBlob = proto.blob;
|
|
32535
33605
|
const nativeArrayBuffer = proto.arrayBuffer;
|
|
@@ -32539,7 +33609,7 @@ function installNodeResponse(target) {
|
|
|
32539
33609
|
const NodeResponse = function Response(body, init) {
|
|
32540
33610
|
if (!new.target) throw new TypeError("Class constructor Response cannot be invoked without 'new'");
|
|
32541
33611
|
const given = givenHeaders(init);
|
|
32542
|
-
const response = Reflect.construct(Native, [body, given ? withHeaders(init, given) : init], new.target === NodeResponse ? Native : new.target);
|
|
33612
|
+
const response = Reflect.construct(Native, [nodeResponseBody(body), given ? withHeaders(init, given) : init], new.target === NodeResponse ? Native : new.target);
|
|
32543
33613
|
kept.set(response, withCookies(nativeHeaders.call(response), given));
|
|
32544
33614
|
return response;
|
|
32545
33615
|
};
|
|
@@ -32765,12 +33835,12 @@ class SHA2_32B extends HashMD {
|
|
|
32765
33835
|
this.set(A, B, C, D, E, F, G, H);
|
|
32766
33836
|
}
|
|
32767
33837
|
roundClean() {
|
|
32768
|
-
clean(SHA256_W);
|
|
33838
|
+
clean$1(SHA256_W);
|
|
32769
33839
|
}
|
|
32770
33840
|
destroy() {
|
|
32771
33841
|
this.destroyed = true;
|
|
32772
33842
|
this.set(0, 0, 0, 0, 0, 0, 0, 0);
|
|
32773
|
-
clean(this.buffer);
|
|
33843
|
+
clean$1(this.buffer);
|
|
32774
33844
|
}
|
|
32775
33845
|
}
|
|
32776
33846
|
class _SHA256 extends SHA2_32B {
|
|
@@ -33809,6 +34879,63 @@ function installShellJobs(bash, host2) {
|
|
|
33809
34879
|
if (shell.jobs.size === 0) shells$1.delete(id);
|
|
33810
34880
|
return { stdout: held.stdout, stderr: held.stderr + stderr, exitCode: status };
|
|
33811
34881
|
}));
|
|
34882
|
+
for (const shell of ["sh", "bash"]) {
|
|
34883
|
+
bash.registerCommand(defineCommand(shell, async (args, ctx) => {
|
|
34884
|
+
var _a2;
|
|
34885
|
+
const exec = ctx.exec;
|
|
34886
|
+
if (!exec) return { stdout: "", stderr: `bash: ${shell}: needs a shell that can run a script
|
|
34887
|
+
`, exitCode: 1 };
|
|
34888
|
+
let script;
|
|
34889
|
+
let zero2;
|
|
34890
|
+
let positional;
|
|
34891
|
+
let sourced;
|
|
34892
|
+
let at2 = 0;
|
|
34893
|
+
while (at2 < args.length && /^[-+][a-bd-zA-Z]+$/u.test(args[at2])) at2++;
|
|
34894
|
+
args = args.slice(at2);
|
|
34895
|
+
if (args[0] === "-c" && args.length >= 2) {
|
|
34896
|
+
script = args[1];
|
|
34897
|
+
zero2 = args[2] ?? shell;
|
|
34898
|
+
positional = args.slice(3);
|
|
34899
|
+
} else if (args.length === 0) {
|
|
34900
|
+
if (!((_a2 = ctx.stdin) == null ? void 0 : _a2.trim())) return { stdout: "", stderr: "", exitCode: 0 };
|
|
34901
|
+
script = ctx.stdin;
|
|
34902
|
+
zero2 = shell;
|
|
34903
|
+
positional = [];
|
|
34904
|
+
} else {
|
|
34905
|
+
const path2 = ctx.fs.resolvePath(ctx.cwd, args[0]);
|
|
34906
|
+
try {
|
|
34907
|
+
script = String(await ctx.fs.readFile(path2));
|
|
34908
|
+
} catch {
|
|
34909
|
+
return { stdout: "", stderr: `${shell}: ${args[0]}: No such file or directory
|
|
34910
|
+
`, exitCode: 127 };
|
|
34911
|
+
}
|
|
34912
|
+
zero2 = args[0];
|
|
34913
|
+
positional = args.slice(1);
|
|
34914
|
+
sourced = path2;
|
|
34915
|
+
}
|
|
34916
|
+
if (script.startsWith("#!")) {
|
|
34917
|
+
const newline = script.indexOf("\n");
|
|
34918
|
+
if (newline !== -1) script = script.slice(newline + 1);
|
|
34919
|
+
}
|
|
34920
|
+
const env = { ...ctx.exportedEnv ?? {}, "0": zero2, "#": String(positional.length), "@": positional.join(" "), "*": positional.join(" ") };
|
|
34921
|
+
positional.forEach((word, index2) => {
|
|
34922
|
+
env[String(index2 + 1)] = word;
|
|
34923
|
+
});
|
|
34924
|
+
const token = ctx.env.get(PROCESS_TOKEN_ENV);
|
|
34925
|
+
if (token) env[PROCESS_TOKEN_ENV] = token;
|
|
34926
|
+
if (sourced !== void 0) script = `. ${sourced.replace(/'/gu, "'\\''").replace(/^(.*)$/su, "'$1'")}`;
|
|
34927
|
+
const result = await exec(script, { env, cwd: ctx.cwd, stdin: ctx.stdin, signal: ctx.signal });
|
|
34928
|
+
return { stdout: result.stdout ?? "", stderr: result.stderr ?? "", exitCode: result.exitCode ?? 0 };
|
|
34929
|
+
}));
|
|
34930
|
+
}
|
|
34931
|
+
bash.registerCommand(defineCommand("exec", async (args, ctx) => {
|
|
34932
|
+
if (args.length === 0) return { stdout: "", stderr: "", exitCode: 0 };
|
|
34933
|
+
if (!ctx.exec) return { stdout: "", stderr: "bash: exec: needs a shell that can run a line\n", exitCode: 1 };
|
|
34934
|
+
const line = args.map((word) => /^[A-Za-z0-9_./:=@%+,-]+$/u.test(word) ? word : `'${word.replace(/'/gu, "'\\''")}'`).join(" ");
|
|
34935
|
+
const env = Object.fromEntries(ctx.env);
|
|
34936
|
+
const result = await ctx.exec(line, { env, cwd: ctx.cwd, replaceEnv: true });
|
|
34937
|
+
return { stdout: result.stdout ?? "", stderr: result.stderr ?? "", exitCode: result.exitCode ?? 0 };
|
|
34938
|
+
}));
|
|
33812
34939
|
bash.registerCommand(defineCommand("kill", async (args) => {
|
|
33813
34940
|
let signal = "SIGTERM";
|
|
33814
34941
|
let index2 = 0;
|
|
@@ -34009,6 +35136,18 @@ function registerRunStreams(token, streams2) {
|
|
|
34009
35136
|
}
|
|
34010
35137
|
function releaseRunStreams(token) {
|
|
34011
35138
|
_runStreams.delete(token);
|
|
35139
|
+
shellRuns.delete(token);
|
|
35140
|
+
hostedNodes.delete(token);
|
|
35141
|
+
}
|
|
35142
|
+
const shellRuns = /* @__PURE__ */ new Set();
|
|
35143
|
+
const hostedNodes = /* @__PURE__ */ new Set();
|
|
35144
|
+
function nestedNodeToken(parentToken, args, cwd) {
|
|
35145
|
+
var _a2;
|
|
35146
|
+
const token = `child-${__nextChildRun++}`;
|
|
35147
|
+
setRunPid(token, mintPid(), ((_a2 = runPid(parentToken)) == null ? void 0 : _a2.pid) ?? 0, { argv: ["node", ...args], ...cwd ? { cwd } : {} });
|
|
35148
|
+
const parentStreams = runStreamsFor(parentToken);
|
|
35149
|
+
if (parentStreams) registerRunStreams(token, parentStreams);
|
|
35150
|
+
return token;
|
|
34012
35151
|
}
|
|
34013
35152
|
function runStreamsFor(token) {
|
|
34014
35153
|
return _runStreams.get(token);
|
|
@@ -34100,19 +35239,26 @@ function initChildProcess(vfs2) {
|
|
|
34100
35239
|
if (!tree2) {
|
|
34101
35240
|
return { stdout: "", stderr: "VFS not initialized\n", exitCode: 1 };
|
|
34102
35241
|
}
|
|
34103
|
-
const
|
|
35242
|
+
const parentToken = runTokenOf(ctx);
|
|
35243
|
+
const nested = parentToken !== null && (shellRuns.has(parentToken) || hostedNodes.has(parentToken));
|
|
35244
|
+
const runToken = nested ? nestedNodeToken(parentToken, args, ctx.cwd) : parentToken;
|
|
34104
35245
|
const streams2 = runToken === null ? void 0 : runStreamsFor(runToken);
|
|
34105
35246
|
const processHost = nodeProcessHostFor(runToken);
|
|
34106
35247
|
if (processHost && runToken !== null) {
|
|
34107
|
-
|
|
34108
|
-
|
|
34109
|
-
|
|
34110
|
-
|
|
34111
|
-
|
|
34112
|
-
|
|
34113
|
-
|
|
34114
|
-
|
|
34115
|
-
|
|
35248
|
+
if (!nested) hostedNodes.add(runToken);
|
|
35249
|
+
try {
|
|
35250
|
+
return await runHostedNode(processHost, {
|
|
35251
|
+
token: runToken,
|
|
35252
|
+
argv: [...args],
|
|
35253
|
+
cwd: ctx.cwd,
|
|
35254
|
+
filesystem: tree2,
|
|
35255
|
+
env: guestEnvironmentOf(ctx),
|
|
35256
|
+
...typeof ctx.stdin === "string" ? { stdin: ctx.stdin } : {},
|
|
35257
|
+
...streams2 ? { streams: streams2 } : {}
|
|
35258
|
+
});
|
|
35259
|
+
} finally {
|
|
35260
|
+
if (nested) releaseRunStreams(runToken);
|
|
35261
|
+
}
|
|
34116
35262
|
}
|
|
34117
35263
|
const execArgv = [];
|
|
34118
35264
|
let first = 0;
|
|
@@ -35018,6 +36164,7 @@ function existsInTree(path2) {
|
|
|
35018
36164
|
return false;
|
|
35019
36165
|
}
|
|
35020
36166
|
}
|
|
36167
|
+
const SHELL_PROGRAMS = /* @__PURE__ */ new Set(["sh", "bash", "dash", "/bin/sh", "/bin/bash", "/usr/bin/sh", "/usr/bin/bash"]);
|
|
35021
36168
|
function engineProgramFor(file, cwd) {
|
|
35022
36169
|
const name = __substrateProgramName(file);
|
|
35023
36170
|
if (!name.includes("/")) return name;
|
|
@@ -35064,6 +36211,7 @@ function startChildRun(request) {
|
|
|
35064
36211
|
const controller = new AbortController();
|
|
35065
36212
|
const pendingStdin = [];
|
|
35066
36213
|
const admittedNode = nodeProcessHostInstalled() && engineProgramFor(request.file, request.cwd) === "node";
|
|
36214
|
+
if (!admittedNode) shellRuns.add(token);
|
|
35067
36215
|
const hostTerminal = request.terminal !== void 0 && hostExecutor() !== null && !admittedNode;
|
|
35068
36216
|
let wakeInput;
|
|
35069
36217
|
let liveInput = false;
|
|
@@ -35162,7 +36310,8 @@ function startChildRun(request) {
|
|
|
35162
36310
|
const begin = () => {
|
|
35163
36311
|
if (started2 || finished) return;
|
|
35164
36312
|
started2 = true;
|
|
35165
|
-
const
|
|
36313
|
+
const shellChild = SHELL_PROGRAMS.has(engineProgramFor(request.file, request.cwd)) && hostExecutor() !== null;
|
|
36314
|
+
const engineFirst = !hostTerminal && !shellChild && programExists(request.file, request.cwd, request.env);
|
|
35166
36315
|
liveInput = !hostTerminal && !admittedNode && request.stdinIsPipe && !engineFirst;
|
|
35167
36316
|
if (liveInput) {
|
|
35168
36317
|
pendingStdin.unshift(...initialStdin);
|
|
@@ -40220,6 +41369,7 @@ forGuestRealm(() => {
|
|
|
40220
41369
|
const kept = /* @__PURE__ */ new WeakMap();
|
|
40221
41370
|
class NodeRequest extends Native {
|
|
40222
41371
|
constructor(input, init) {
|
|
41372
|
+
init = withNodeRequestBody(init);
|
|
40223
41373
|
super(input, init);
|
|
40224
41374
|
rememberRequestBodySource(this, input, init);
|
|
40225
41375
|
const asked = new Headers((init == null ? void 0 : init.headers) ?? (input instanceof Native ? input.headers : void 0));
|
|
@@ -40548,7 +41698,7 @@ class WorkerRuntime {
|
|
|
40548
41698
|
this.worker = new Worker(
|
|
40549
41699
|
new URL(
|
|
40550
41700
|
/* @vite-ignore */
|
|
40551
|
-
"/assets/runtime-worker-
|
|
41701
|
+
"/assets/runtime-worker-Cu2mr9G9.js",
|
|
40552
41702
|
import.meta.url
|
|
40553
41703
|
),
|
|
40554
41704
|
{ type: "module" }
|