@volter/tabnode 0.5.20 → 0.5.22
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-IRKbkQwk.js → runtime-worker-Bw5ePWPu.js} +106 -8
- package/dist/index.mjs +107 -9
- package/dist/shims/crypto.d.ts +39 -1
- package/package.json +1 -1
- package/src/node-lib/binding/fs.ts +11 -4
- package/src/shims/child_process.ts +11 -2
- package/src/shims/crypto.ts +88 -1
|
@@ -8246,20 +8246,30 @@ function descriptorWriter(fd2) {
|
|
|
8246
8246
|
if (!file || file.directory || (file.flags & 3) === 0) return null;
|
|
8247
8247
|
const { tree: tree2, path: path2 } = file;
|
|
8248
8248
|
const append = (file.flags & flagBits().append) !== 0;
|
|
8249
|
-
let
|
|
8249
|
+
let cursor = descriptorCursors.get(file);
|
|
8250
|
+
if (!cursor) {
|
|
8251
|
+
cursor = { position: file.position };
|
|
8252
|
+
descriptorCursors.set(file, cursor);
|
|
8253
|
+
}
|
|
8254
|
+
const offset2 = cursor;
|
|
8250
8255
|
return (text) => {
|
|
8251
8256
|
const bytes2 = new TextEncoder().encode(text);
|
|
8252
8257
|
const shared = openFiles.get(fd2) === file ? file : null;
|
|
8258
|
+
if (shared) offset2.position = shared.position;
|
|
8253
8259
|
const existing = (shared == null ? void 0 : shared.cached) ?? (tree2.existsSync(path2) ? tree2.readFileSync(path2) : new Uint8Array(0));
|
|
8254
|
-
const at3 = append ? existing.length : position;
|
|
8260
|
+
const at3 = append ? existing.length : offset2.position;
|
|
8255
8261
|
const next2 = new Uint8Array(Math.max(existing.length, at3 + bytes2.length));
|
|
8256
8262
|
next2.set(existing, 0);
|
|
8257
8263
|
next2.set(bytes2, at3);
|
|
8258
8264
|
tree2.writeFileSync(path2, next2);
|
|
8259
|
-
position = at3 + bytes2.length;
|
|
8260
|
-
if (shared)
|
|
8265
|
+
offset2.position = at3 + bytes2.length;
|
|
8266
|
+
if (shared) {
|
|
8267
|
+
shared.cached = next2;
|
|
8268
|
+
shared.position = offset2.position;
|
|
8269
|
+
}
|
|
8261
8270
|
};
|
|
8262
8271
|
}
|
|
8272
|
+
const descriptorCursors = /* @__PURE__ */ new WeakMap();
|
|
8263
8273
|
function statArray(stats, bigint, path2) {
|
|
8264
8274
|
var _a3, _b3, _c3;
|
|
8265
8275
|
const mtime = stats.mtime instanceof Date ? stats.mtime.getTime() : Number(stats.mtimeMs ?? 0);
|
|
@@ -23695,6 +23705,83 @@ function createCryptoModule(require2) {
|
|
|
23695
23705
|
const keyInfo = extractKeyInfo(key);
|
|
23696
23706
|
return new KeyObject2("private", keyInfo.keyData, keyInfo.algorithm);
|
|
23697
23707
|
}
|
|
23708
|
+
const NAMED_CURVES = {
|
|
23709
|
+
"prime256v1": "P-256",
|
|
23710
|
+
"p-256": "P-256",
|
|
23711
|
+
"secp256r1": "P-256",
|
|
23712
|
+
"secp384r1": "P-384",
|
|
23713
|
+
"p-384": "P-384",
|
|
23714
|
+
"secp521r1": "P-521",
|
|
23715
|
+
"p-521": "P-521"
|
|
23716
|
+
};
|
|
23717
|
+
function keyPairAlgorithm(type2, options) {
|
|
23718
|
+
const exponent = (value) => {
|
|
23719
|
+
let rest = value ?? 65537;
|
|
23720
|
+
const bytes2 = [];
|
|
23721
|
+
while (rest > 0) {
|
|
23722
|
+
bytes2.unshift(rest & 255);
|
|
23723
|
+
rest = Math.floor(rest / 256);
|
|
23724
|
+
}
|
|
23725
|
+
return new Uint8Array(bytes2);
|
|
23726
|
+
};
|
|
23727
|
+
switch (type2) {
|
|
23728
|
+
case "rsa":
|
|
23729
|
+
case "rsa-pss": {
|
|
23730
|
+
if (!Number.isInteger(options.modulusLength)) throw Object.assign(new TypeError('The "options.modulusLength" property must be of type number.'), { code: "ERR_INVALID_ARG_TYPE" });
|
|
23731
|
+
const name = type2 === "rsa" ? "RSASSA-PKCS1-v1_5" : "RSA-PSS";
|
|
23732
|
+
return { generate: { name, modulusLength: options.modulusLength, publicExponent: exponent(options.publicExponent), hash: "SHA-256" }, usages: ["sign", "verify"], name: type2 === "rsa" ? "RSA-SHA256" : "RSA-PSS" };
|
|
23733
|
+
}
|
|
23734
|
+
case "ec": {
|
|
23735
|
+
const curve = NAMED_CURVES[String(options.namedCurve ?? "").toLowerCase()];
|
|
23736
|
+
if (!curve) throw Object.assign(new TypeError(`Invalid EC curve name ${String(options.namedCurve)}`), { code: "ERR_CRYPTO_INVALID_CURVE" });
|
|
23737
|
+
return { generate: { name: "ECDSA", namedCurve: curve }, usages: ["sign", "verify"], name: curve === "P-256" ? "ES256" : curve === "P-384" ? "ES384" : "ES512" };
|
|
23738
|
+
}
|
|
23739
|
+
case "ed25519":
|
|
23740
|
+
return { generate: { name: "Ed25519" }, usages: ["sign", "verify"], name: "Ed25519" };
|
|
23741
|
+
case "x25519":
|
|
23742
|
+
return { generate: { name: "X25519" }, usages: ["deriveBits"], name: "X25519" };
|
|
23743
|
+
default:
|
|
23744
|
+
throw Object.assign(new TypeError(`The argument 'type' must be a supported key type. Received '${type2}'`), { code: "ERR_INVALID_ARG_VALUE" });
|
|
23745
|
+
}
|
|
23746
|
+
}
|
|
23747
|
+
function encodedKey(der, encoding, kind) {
|
|
23748
|
+
const expected = kind === "public" ? "spki" : "pkcs8";
|
|
23749
|
+
if (encoding.type !== void 0 && encoding.type !== expected) {
|
|
23750
|
+
unsupported2(`Encoding a ${kind} key as ${encoding.type}`);
|
|
23751
|
+
}
|
|
23752
|
+
const bytes2 = Buffer2.from(der);
|
|
23753
|
+
if (encoding.format === "der") return bytes2;
|
|
23754
|
+
if (encoding.format !== "pem") unsupported2(`Encoding a key in the ${String(encoding.format)} format`);
|
|
23755
|
+
const label = kind === "public" ? "PUBLIC KEY" : "PRIVATE KEY";
|
|
23756
|
+
const body = bytes2.toString("base64").match(/.{1,64}/g).join("\n");
|
|
23757
|
+
return `-----BEGIN ${label}-----
|
|
23758
|
+
${body}
|
|
23759
|
+
-----END ${label}-----
|
|
23760
|
+
`;
|
|
23761
|
+
}
|
|
23762
|
+
async function generateKeyPairAsync(type2, options) {
|
|
23763
|
+
const algorithm = keyPairAlgorithm(type2, options);
|
|
23764
|
+
const pair = await crypto.subtle.generateKey(algorithm.generate, true, algorithm.usages);
|
|
23765
|
+
const publicKey = options.publicKeyEncoding ? encodedKey(await crypto.subtle.exportKey("spki", pair.publicKey), options.publicKeyEncoding, "public") : new KeyObject2("public", pair.publicKey, algorithm.name);
|
|
23766
|
+
const privateKey = options.privateKeyEncoding ? encodedKey(await crypto.subtle.exportKey("pkcs8", pair.privateKey), options.privateKeyEncoding, "private") : new KeyObject2("private", pair.privateKey, algorithm.name);
|
|
23767
|
+
return { publicKey, privateKey };
|
|
23768
|
+
}
|
|
23769
|
+
function generateKeyPair2(type2, options, callback) {
|
|
23770
|
+
if (typeof options === "function") {
|
|
23771
|
+
callback = options;
|
|
23772
|
+
options = {};
|
|
23773
|
+
}
|
|
23774
|
+
if (typeof callback !== "function") throw Object.assign(new TypeError('The "callback" argument must be of type function.'), { code: "ERR_INVALID_ARG_TYPE" });
|
|
23775
|
+
const done = callback;
|
|
23776
|
+
keyPairAlgorithm(type2, options ?? {});
|
|
23777
|
+
generateKeyPairAsync(type2, options ?? {}).then(
|
|
23778
|
+
({ publicKey, privateKey }) => done(null, publicKey, privateKey),
|
|
23779
|
+
(error) => done(error instanceof Error ? error : new Error(String(error)))
|
|
23780
|
+
);
|
|
23781
|
+
}
|
|
23782
|
+
Object.defineProperty(generateKeyPair2, Symbol.for("nodejs.util.promisify.custom"), {
|
|
23783
|
+
value: (type2, options) => generateKeyPairAsync(type2, options ?? {})
|
|
23784
|
+
});
|
|
23698
23785
|
function timingSafeEqual2(a, b) {
|
|
23699
23786
|
if (a.length !== b.length) {
|
|
23700
23787
|
return false;
|
|
@@ -23851,11 +23938,12 @@ function createCryptoModule(require2) {
|
|
|
23851
23938
|
KeyObject: KeyObject2,
|
|
23852
23939
|
createSecretKey: createSecretKey2,
|
|
23853
23940
|
createPublicKey: createPublicKey2,
|
|
23854
|
-
createPrivateKey: createPrivateKey2
|
|
23941
|
+
createPrivateKey: createPrivateKey2,
|
|
23942
|
+
generateKeyPair: generateKeyPair2
|
|
23855
23943
|
};
|
|
23856
23944
|
}
|
|
23857
23945
|
const cryptoModule = createCryptoModule();
|
|
23858
|
-
const { randomBytes, randomFillSync, randomFill, randomUUID, randomInt, getRandomValues, unsupported, createHash, createHmac, hash, pbkdf2Sync, pbkdf2, sign, verify, createSign, createVerify, KeyObject, createSecretKey, createPublicKey, createPrivateKey, timingSafeEqual, getCiphers, getHashes } = cryptoModule;
|
|
23946
|
+
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;
|
|
23859
23947
|
var cryptoShim = /* @__PURE__ */ Object.freeze({
|
|
23860
23948
|
__proto__: null,
|
|
23861
23949
|
KeyObject,
|
|
@@ -23869,6 +23957,7 @@ var cryptoShim = /* @__PURE__ */ Object.freeze({
|
|
|
23869
23957
|
createSign,
|
|
23870
23958
|
createVerify,
|
|
23871
23959
|
default: cryptoModule,
|
|
23960
|
+
generateKeyPair,
|
|
23872
23961
|
getCiphers,
|
|
23873
23962
|
getHashes,
|
|
23874
23963
|
getRandomValues,
|
|
@@ -74566,8 +74655,15 @@ async function handleNpmInstall(args, ctx) {
|
|
|
74566
74655
|
}
|
|
74567
74656
|
}
|
|
74568
74657
|
async function handleNpmInit(args, ctx) {
|
|
74658
|
+
var _a3;
|
|
74569
74659
|
const yes = args.includes("-y") || args.includes("--yes");
|
|
74570
|
-
const
|
|
74660
|
+
const takesValue = (flag) => !flag.includes("=") && (flag === "--scope" || flag === "-w" || flag === "--workspace" || flag.startsWith("--init-"));
|
|
74661
|
+
const valueOf = (flag) => {
|
|
74662
|
+
const at3 = args.findIndex((a) => a === flag || a.startsWith(`${flag}=`));
|
|
74663
|
+
if (at3 < 0) return void 0;
|
|
74664
|
+
return args[at3].includes("=") ? args[at3].slice(args[at3].indexOf("=") + 1) : args[at3 + 1];
|
|
74665
|
+
};
|
|
74666
|
+
const initializer = args.find((a, i10) => !a.startsWith("-") && !(i10 > 0 && takesValue(args[i10 - 1])));
|
|
74571
74667
|
if (initializer) {
|
|
74572
74668
|
return { stdout: "", stderr: `npm ERR! npm init ${initializer} runs an initializer package, which this engine's npm does not; write package.json, or run \`npm init -y\`.
|
|
74573
74669
|
`, exitCode: 1 };
|
|
@@ -74587,7 +74683,9 @@ async function handleNpmInit(args, ctx) {
|
|
|
74587
74683
|
}
|
|
74588
74684
|
}
|
|
74589
74685
|
const base = ctx.cwd.split("/").filter(Boolean).pop() ?? "package";
|
|
74590
|
-
const
|
|
74686
|
+
const bare = base.toLowerCase().replace(/^[._]+/, "").replace(/[^a-z0-9._~-]+/g, "-") || "package";
|
|
74687
|
+
const scope = (_a3 = valueOf("--scope")) == null ? void 0 : _a3.replace(/^@?/, "@");
|
|
74688
|
+
const name = scope ? `${scope}/${bare}` : bare;
|
|
74591
74689
|
const manifest = {
|
|
74592
74690
|
name,
|
|
74593
74691
|
version: "1.0.0",
|
package/dist/index.mjs
CHANGED
|
@@ -8402,20 +8402,30 @@ function descriptorWriter(fd) {
|
|
|
8402
8402
|
if (!file || file.directory || (file.flags & 3) === 0) return null;
|
|
8403
8403
|
const { tree: tree2, path: path2 } = file;
|
|
8404
8404
|
const append = (file.flags & flagBits().append) !== 0;
|
|
8405
|
-
let
|
|
8405
|
+
let cursor = descriptorCursors.get(file);
|
|
8406
|
+
if (!cursor) {
|
|
8407
|
+
cursor = { position: file.position };
|
|
8408
|
+
descriptorCursors.set(file, cursor);
|
|
8409
|
+
}
|
|
8410
|
+
const offset2 = cursor;
|
|
8406
8411
|
return (text) => {
|
|
8407
8412
|
const bytes2 = new TextEncoder().encode(text);
|
|
8408
8413
|
const shared = openFiles.get(fd) === file ? file : null;
|
|
8414
|
+
if (shared) offset2.position = shared.position;
|
|
8409
8415
|
const existing = (shared == null ? void 0 : shared.cached) ?? (tree2.existsSync(path2) ? tree2.readFileSync(path2) : new Uint8Array(0));
|
|
8410
|
-
const at2 = append ? existing.length : position;
|
|
8416
|
+
const at2 = append ? existing.length : offset2.position;
|
|
8411
8417
|
const next = new Uint8Array(Math.max(existing.length, at2 + bytes2.length));
|
|
8412
8418
|
next.set(existing, 0);
|
|
8413
8419
|
next.set(bytes2, at2);
|
|
8414
8420
|
tree2.writeFileSync(path2, next);
|
|
8415
|
-
position = at2 + bytes2.length;
|
|
8416
|
-
if (shared)
|
|
8421
|
+
offset2.position = at2 + bytes2.length;
|
|
8422
|
+
if (shared) {
|
|
8423
|
+
shared.cached = next;
|
|
8424
|
+
shared.position = offset2.position;
|
|
8425
|
+
}
|
|
8417
8426
|
};
|
|
8418
8427
|
}
|
|
8428
|
+
const descriptorCursors = /* @__PURE__ */ new WeakMap();
|
|
8419
8429
|
function statArray(stats, bigint, path2) {
|
|
8420
8430
|
var _a2, _b2, _c2;
|
|
8421
8431
|
const mtime = stats.mtime instanceof Date ? stats.mtime.getTime() : Number(stats.mtimeMs ?? 0);
|
|
@@ -23871,6 +23881,83 @@ function createCryptoModule(require2) {
|
|
|
23871
23881
|
const keyInfo = extractKeyInfo(key);
|
|
23872
23882
|
return new KeyObject2("private", keyInfo.keyData, keyInfo.algorithm);
|
|
23873
23883
|
}
|
|
23884
|
+
const NAMED_CURVES = {
|
|
23885
|
+
"prime256v1": "P-256",
|
|
23886
|
+
"p-256": "P-256",
|
|
23887
|
+
"secp256r1": "P-256",
|
|
23888
|
+
"secp384r1": "P-384",
|
|
23889
|
+
"p-384": "P-384",
|
|
23890
|
+
"secp521r1": "P-521",
|
|
23891
|
+
"p-521": "P-521"
|
|
23892
|
+
};
|
|
23893
|
+
function keyPairAlgorithm(type2, options) {
|
|
23894
|
+
const exponent = (value) => {
|
|
23895
|
+
let rest = value ?? 65537;
|
|
23896
|
+
const bytes2 = [];
|
|
23897
|
+
while (rest > 0) {
|
|
23898
|
+
bytes2.unshift(rest & 255);
|
|
23899
|
+
rest = Math.floor(rest / 256);
|
|
23900
|
+
}
|
|
23901
|
+
return new Uint8Array(bytes2);
|
|
23902
|
+
};
|
|
23903
|
+
switch (type2) {
|
|
23904
|
+
case "rsa":
|
|
23905
|
+
case "rsa-pss": {
|
|
23906
|
+
if (!Number.isInteger(options.modulusLength)) throw Object.assign(new TypeError('The "options.modulusLength" property must be of type number.'), { code: "ERR_INVALID_ARG_TYPE" });
|
|
23907
|
+
const name = type2 === "rsa" ? "RSASSA-PKCS1-v1_5" : "RSA-PSS";
|
|
23908
|
+
return { generate: { name, modulusLength: options.modulusLength, publicExponent: exponent(options.publicExponent), hash: "SHA-256" }, usages: ["sign", "verify"], name: type2 === "rsa" ? "RSA-SHA256" : "RSA-PSS" };
|
|
23909
|
+
}
|
|
23910
|
+
case "ec": {
|
|
23911
|
+
const curve = NAMED_CURVES[String(options.namedCurve ?? "").toLowerCase()];
|
|
23912
|
+
if (!curve) throw Object.assign(new TypeError(`Invalid EC curve name ${String(options.namedCurve)}`), { code: "ERR_CRYPTO_INVALID_CURVE" });
|
|
23913
|
+
return { generate: { name: "ECDSA", namedCurve: curve }, usages: ["sign", "verify"], name: curve === "P-256" ? "ES256" : curve === "P-384" ? "ES384" : "ES512" };
|
|
23914
|
+
}
|
|
23915
|
+
case "ed25519":
|
|
23916
|
+
return { generate: { name: "Ed25519" }, usages: ["sign", "verify"], name: "Ed25519" };
|
|
23917
|
+
case "x25519":
|
|
23918
|
+
return { generate: { name: "X25519" }, usages: ["deriveBits"], name: "X25519" };
|
|
23919
|
+
default:
|
|
23920
|
+
throw Object.assign(new TypeError(`The argument 'type' must be a supported key type. Received '${type2}'`), { code: "ERR_INVALID_ARG_VALUE" });
|
|
23921
|
+
}
|
|
23922
|
+
}
|
|
23923
|
+
function encodedKey(der, encoding, kind) {
|
|
23924
|
+
const expected = kind === "public" ? "spki" : "pkcs8";
|
|
23925
|
+
if (encoding.type !== void 0 && encoding.type !== expected) {
|
|
23926
|
+
unsupported2(`Encoding a ${kind} key as ${encoding.type}`);
|
|
23927
|
+
}
|
|
23928
|
+
const bytes2 = Buffer2.from(der);
|
|
23929
|
+
if (encoding.format === "der") return bytes2;
|
|
23930
|
+
if (encoding.format !== "pem") unsupported2(`Encoding a key in the ${String(encoding.format)} format`);
|
|
23931
|
+
const label = kind === "public" ? "PUBLIC KEY" : "PRIVATE KEY";
|
|
23932
|
+
const body = bytes2.toString("base64").match(/.{1,64}/g).join("\n");
|
|
23933
|
+
return `-----BEGIN ${label}-----
|
|
23934
|
+
${body}
|
|
23935
|
+
-----END ${label}-----
|
|
23936
|
+
`;
|
|
23937
|
+
}
|
|
23938
|
+
async function generateKeyPairAsync(type2, options) {
|
|
23939
|
+
const algorithm = keyPairAlgorithm(type2, options);
|
|
23940
|
+
const pair = await crypto.subtle.generateKey(algorithm.generate, true, algorithm.usages);
|
|
23941
|
+
const publicKey = options.publicKeyEncoding ? encodedKey(await crypto.subtle.exportKey("spki", pair.publicKey), options.publicKeyEncoding, "public") : new KeyObject2("public", pair.publicKey, algorithm.name);
|
|
23942
|
+
const privateKey = options.privateKeyEncoding ? encodedKey(await crypto.subtle.exportKey("pkcs8", pair.privateKey), options.privateKeyEncoding, "private") : new KeyObject2("private", pair.privateKey, algorithm.name);
|
|
23943
|
+
return { publicKey, privateKey };
|
|
23944
|
+
}
|
|
23945
|
+
function generateKeyPair2(type2, options, callback) {
|
|
23946
|
+
if (typeof options === "function") {
|
|
23947
|
+
callback = options;
|
|
23948
|
+
options = {};
|
|
23949
|
+
}
|
|
23950
|
+
if (typeof callback !== "function") throw Object.assign(new TypeError('The "callback" argument must be of type function.'), { code: "ERR_INVALID_ARG_TYPE" });
|
|
23951
|
+
const done = callback;
|
|
23952
|
+
keyPairAlgorithm(type2, options ?? {});
|
|
23953
|
+
generateKeyPairAsync(type2, options ?? {}).then(
|
|
23954
|
+
({ publicKey, privateKey }) => done(null, publicKey, privateKey),
|
|
23955
|
+
(error) => done(error instanceof Error ? error : new Error(String(error)))
|
|
23956
|
+
);
|
|
23957
|
+
}
|
|
23958
|
+
Object.defineProperty(generateKeyPair2, Symbol.for("nodejs.util.promisify.custom"), {
|
|
23959
|
+
value: (type2, options) => generateKeyPairAsync(type2, options ?? {})
|
|
23960
|
+
});
|
|
23874
23961
|
function timingSafeEqual2(a, b) {
|
|
23875
23962
|
if (a.length !== b.length) {
|
|
23876
23963
|
return false;
|
|
@@ -24027,11 +24114,12 @@ function createCryptoModule(require2) {
|
|
|
24027
24114
|
KeyObject: KeyObject2,
|
|
24028
24115
|
createSecretKey: createSecretKey2,
|
|
24029
24116
|
createPublicKey: createPublicKey2,
|
|
24030
|
-
createPrivateKey: createPrivateKey2
|
|
24117
|
+
createPrivateKey: createPrivateKey2,
|
|
24118
|
+
generateKeyPair: generateKeyPair2
|
|
24031
24119
|
};
|
|
24032
24120
|
}
|
|
24033
24121
|
const cryptoModule = createCryptoModule();
|
|
24034
|
-
const { randomBytes, randomFillSync, randomFill, randomUUID, randomInt, getRandomValues, unsupported: unsupported$1, createHash, createHmac, hash, pbkdf2Sync, pbkdf2, sign, verify, createSign, createVerify, KeyObject, createSecretKey, createPublicKey, createPrivateKey, timingSafeEqual, getCiphers, getHashes } = cryptoModule;
|
|
24122
|
+
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;
|
|
24035
24123
|
const cryptoShim = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
24036
24124
|
__proto__: null,
|
|
24037
24125
|
KeyObject,
|
|
@@ -24045,6 +24133,7 @@ const cryptoShim = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePr
|
|
|
24045
24133
|
createSign,
|
|
24046
24134
|
createVerify,
|
|
24047
24135
|
default: cryptoModule,
|
|
24136
|
+
generateKeyPair,
|
|
24048
24137
|
getCiphers,
|
|
24049
24138
|
getHashes,
|
|
24050
24139
|
getRandomValues,
|
|
@@ -34229,8 +34318,15 @@ async function handleNpmInstall(args, ctx) {
|
|
|
34229
34318
|
}
|
|
34230
34319
|
}
|
|
34231
34320
|
async function handleNpmInit(args, ctx) {
|
|
34321
|
+
var _a2;
|
|
34232
34322
|
const yes = args.includes("-y") || args.includes("--yes");
|
|
34233
|
-
const
|
|
34323
|
+
const takesValue = (flag) => !flag.includes("=") && (flag === "--scope" || flag === "-w" || flag === "--workspace" || flag.startsWith("--init-"));
|
|
34324
|
+
const valueOf = (flag) => {
|
|
34325
|
+
const at2 = args.findIndex((a) => a === flag || a.startsWith(`${flag}=`));
|
|
34326
|
+
if (at2 < 0) return void 0;
|
|
34327
|
+
return args[at2].includes("=") ? args[at2].slice(args[at2].indexOf("=") + 1) : args[at2 + 1];
|
|
34328
|
+
};
|
|
34329
|
+
const initializer = args.find((a, i2) => !a.startsWith("-") && !(i2 > 0 && takesValue(args[i2 - 1])));
|
|
34234
34330
|
if (initializer) {
|
|
34235
34331
|
return { stdout: "", stderr: `npm ERR! npm init ${initializer} runs an initializer package, which this engine's npm does not; write package.json, or run \`npm init -y\`.
|
|
34236
34332
|
`, exitCode: 1 };
|
|
@@ -34250,7 +34346,9 @@ async function handleNpmInit(args, ctx) {
|
|
|
34250
34346
|
}
|
|
34251
34347
|
}
|
|
34252
34348
|
const base = ctx.cwd.split("/").filter(Boolean).pop() ?? "package";
|
|
34253
|
-
const
|
|
34349
|
+
const bare = base.toLowerCase().replace(/^[._]+/, "").replace(/[^a-z0-9._~-]+/g, "-") || "package";
|
|
34350
|
+
const scope = (_a2 = valueOf("--scope")) == null ? void 0 : _a2.replace(/^@?/, "@");
|
|
34351
|
+
const name = scope ? `${scope}/${bare}` : bare;
|
|
34254
34352
|
const manifest = {
|
|
34255
34353
|
name,
|
|
34256
34354
|
version: "1.0.0",
|
|
@@ -39827,7 +39925,7 @@ class WorkerRuntime {
|
|
|
39827
39925
|
this.worker = new Worker(
|
|
39828
39926
|
new URL(
|
|
39829
39927
|
/* @vite-ignore */
|
|
39830
|
-
"/assets/runtime-worker-
|
|
39928
|
+
"/assets/runtime-worker-Bw5ePWPu.js",
|
|
39831
39929
|
import.meta.url
|
|
39832
39930
|
),
|
|
39833
39931
|
{ type: "module" }
|
package/dist/shims/crypto.d.ts
CHANGED
|
@@ -245,6 +245,19 @@ export declare function createCryptoModule(require?: (name: string) => any): {
|
|
|
245
245
|
format?: string;
|
|
246
246
|
}): Buffer | string;
|
|
247
247
|
};
|
|
248
|
+
generateKeyPair: (type: string, options: {
|
|
249
|
+
modulusLength?: number;
|
|
250
|
+
publicExponent?: number;
|
|
251
|
+
namedCurve?: string;
|
|
252
|
+
publicKeyEncoding?: {
|
|
253
|
+
type?: string;
|
|
254
|
+
format?: string;
|
|
255
|
+
};
|
|
256
|
+
privateKeyEncoding?: {
|
|
257
|
+
type?: string;
|
|
258
|
+
format?: string;
|
|
259
|
+
};
|
|
260
|
+
} | ((error: Error | null, publicKey?: unknown, privateKey?: unknown) => void), callback?: (error: Error | null, publicKey?: unknown, privateKey?: unknown) => void) => void;
|
|
248
261
|
};
|
|
249
262
|
declare const cryptoModule: {
|
|
250
263
|
unsupported: (operation: string) => never;
|
|
@@ -477,6 +490,19 @@ declare const cryptoModule: {
|
|
|
477
490
|
format?: string;
|
|
478
491
|
}): Buffer | string;
|
|
479
492
|
};
|
|
493
|
+
generateKeyPair: (type: string, options: {
|
|
494
|
+
modulusLength?: number;
|
|
495
|
+
publicExponent?: number;
|
|
496
|
+
namedCurve?: string;
|
|
497
|
+
publicKeyEncoding?: {
|
|
498
|
+
type?: string;
|
|
499
|
+
format?: string;
|
|
500
|
+
};
|
|
501
|
+
privateKeyEncoding?: {
|
|
502
|
+
type?: string;
|
|
503
|
+
format?: string;
|
|
504
|
+
};
|
|
505
|
+
} | ((error: Error | null, publicKey?: unknown, privateKey?: unknown) => void), callback?: (error: Error | null, publicKey?: unknown, privateKey?: unknown) => void) => void;
|
|
480
506
|
};
|
|
481
507
|
export declare const randomBytes: {
|
|
482
508
|
(size: number): Buffer;
|
|
@@ -679,6 +705,18 @@ export declare const randomBytes: {
|
|
|
679
705
|
type?: string;
|
|
680
706
|
format?: string;
|
|
681
707
|
}): Buffer | string;
|
|
682
|
-
},
|
|
708
|
+
}, generateKeyPair: (type: string, options: {
|
|
709
|
+
modulusLength?: number;
|
|
710
|
+
publicExponent?: number;
|
|
711
|
+
namedCurve?: string;
|
|
712
|
+
publicKeyEncoding?: {
|
|
713
|
+
type?: string;
|
|
714
|
+
format?: string;
|
|
715
|
+
};
|
|
716
|
+
privateKeyEncoding?: {
|
|
717
|
+
type?: string;
|
|
718
|
+
format?: string;
|
|
719
|
+
};
|
|
720
|
+
} | ((error: Error | null, publicKey?: unknown, privateKey?: unknown) => void), callback?: (error: Error | null, publicKey?: unknown, privateKey?: unknown) => void) => void, timingSafeEqual: (a: Buffer | Uint8Array, b: Buffer | Uint8Array) => boolean, getCiphers: () => string[], getHashes: () => string[];
|
|
683
721
|
export type KeyObject = InstanceType<typeof KeyObject>;
|
|
684
722
|
export default cryptoModule;
|
package/package.json
CHANGED
|
@@ -186,21 +186,28 @@ export function descriptorWriter(fd: number): ((text: string) => void) | null {
|
|
|
186
186
|
if (!file || file.directory || (file.flags & 3) === 0) return null;
|
|
187
187
|
const { tree, path } = file;
|
|
188
188
|
const append = (file.flags & flagBits().append) !== 0;
|
|
189
|
-
|
|
189
|
+
// One offset per open file, as a dup'd descriptor shares one: a child's
|
|
190
|
+
// stdout and stderr on the same file follow each other, and the parent's
|
|
191
|
+
// own position moves with them while its copy is open.
|
|
192
|
+
let cursor = descriptorCursors.get(file);
|
|
193
|
+
if (!cursor) { cursor = { position: file.position }; descriptorCursors.set(file, cursor); }
|
|
194
|
+
const offset = cursor;
|
|
190
195
|
return (text) => {
|
|
191
196
|
const bytes = new TextEncoder().encode(text);
|
|
192
197
|
// the parent's copy, while it is open, holds the file's bytes as it last wrote them
|
|
193
198
|
const shared = openFiles.get(fd) === file ? file : null;
|
|
199
|
+
if (shared) offset.position = shared.position;
|
|
194
200
|
const existing = shared?.cached ?? (tree.existsSync(path) ? tree.readFileSync(path) as Uint8Array : new Uint8Array(0));
|
|
195
|
-
const at = append ? existing.length : position;
|
|
201
|
+
const at = append ? existing.length : offset.position;
|
|
196
202
|
const next = new Uint8Array(Math.max(existing.length, at + bytes.length));
|
|
197
203
|
next.set(existing, 0);
|
|
198
204
|
next.set(bytes, at);
|
|
199
205
|
tree.writeFileSync(path, next);
|
|
200
|
-
position = at + bytes.length;
|
|
201
|
-
if (shared) shared.cached = next;
|
|
206
|
+
offset.position = at + bytes.length;
|
|
207
|
+
if (shared) { shared.cached = next; shared.position = offset.position; }
|
|
202
208
|
};
|
|
203
209
|
}
|
|
210
|
+
const descriptorCursors = new WeakMap<object, { position: number }>();
|
|
204
211
|
|
|
205
212
|
/** Node's stat array: eighteen numbers, with each time a second and a nanosecond. */
|
|
206
213
|
function statArray(stats: VfsStats, bigint: boolean, path?: string): Float64Array | BigInt64Array {
|
|
@@ -1308,7 +1308,14 @@ async function handleNpmInstall(args: string[], ctx: CommandContext): Promise<Ju
|
|
|
1308
1308
|
*/
|
|
1309
1309
|
async function handleNpmInit(args: string[], ctx: CommandContext): Promise<JustBashExecResult> {
|
|
1310
1310
|
const yes = args.includes('-y') || args.includes('--yes');
|
|
1311
|
-
|
|
1311
|
+
// a flag's value is not an initializer: `--scope @x`, `-w pkg`, `--init-license MIT`
|
|
1312
|
+
const takesValue = (flag: string) => !flag.includes('=') && (flag === '--scope' || flag === '-w' || flag === '--workspace' || flag.startsWith('--init-'));
|
|
1313
|
+
const valueOf = (flag: string) => {
|
|
1314
|
+
const at = args.findIndex((a) => a === flag || a.startsWith(`${flag}=`));
|
|
1315
|
+
if (at < 0) return undefined;
|
|
1316
|
+
return args[at].includes('=') ? args[at].slice(args[at].indexOf('=') + 1) : args[at + 1];
|
|
1317
|
+
};
|
|
1318
|
+
const initializer = args.find((a, i) => !a.startsWith('-') && !(i > 0 && takesValue(args[i - 1]!)));
|
|
1312
1319
|
if (initializer) {
|
|
1313
1320
|
return { stdout: '', stderr: `npm ERR! npm init ${initializer} runs an initializer package, which this engine's npm does not; write package.json, or run \`npm init -y\`.\n`, exitCode: 1 };
|
|
1314
1321
|
}
|
|
@@ -1323,7 +1330,9 @@ async function handleNpmInit(args: string[], ctx: CommandContext): Promise<JustB
|
|
|
1323
1330
|
catch { return { stdout: '', stderr: `npm ERR! ${file} is not valid JSON\n`, exitCode: 1 }; }
|
|
1324
1331
|
}
|
|
1325
1332
|
const base = ctx.cwd.split('/').filter(Boolean).pop() ?? 'package';
|
|
1326
|
-
const
|
|
1333
|
+
const bare = base.toLowerCase().replace(/^[._]+/, '').replace(/[^a-z0-9._~-]+/g, '-') || 'package';
|
|
1334
|
+
const scope = valueOf('--scope')?.replace(/^@?/, '@');
|
|
1335
|
+
const name = scope ? `${scope}/${bare}` : bare;
|
|
1327
1336
|
const manifest = {
|
|
1328
1337
|
name,
|
|
1329
1338
|
version: '1.0.0',
|
package/src/shims/crypto.ts
CHANGED
|
@@ -800,6 +800,92 @@ function createPrivateKey(key: KeyLike): KeyObject {
|
|
|
800
800
|
return new KeyObject('private', keyInfo.keyData as Uint8Array, keyInfo.algorithm);
|
|
801
801
|
}
|
|
802
802
|
|
|
803
|
+
// ============================================================================
|
|
804
|
+
// generateKeyPair: Node's asynchronous key generation, done by WebCrypto.
|
|
805
|
+
// A browser has no synchronous key generation, so generateKeyPairSync stays
|
|
806
|
+
// absent; the callback form and its promisified form (which resolves
|
|
807
|
+
// { publicKey, privateKey }, as Node's custom promisify does) are complete for
|
|
808
|
+
// the types WebCrypto generates. jose's Node build promisifies this function
|
|
809
|
+
// when it loads, so its absence failed any module that imported jose.
|
|
810
|
+
// ============================================================================
|
|
811
|
+
|
|
812
|
+
type KeyEncoding = { type?: string; format?: string };
|
|
813
|
+
type KeyPairOptions = { modulusLength?: number; publicExponent?: number; namedCurve?: string; publicKeyEncoding?: KeyEncoding; privateKeyEncoding?: KeyEncoding };
|
|
814
|
+
|
|
815
|
+
const NAMED_CURVES: Record<string, string> = {
|
|
816
|
+
'prime256v1': 'P-256', 'p-256': 'P-256', 'secp256r1': 'P-256',
|
|
817
|
+
'secp384r1': 'P-384', 'p-384': 'P-384',
|
|
818
|
+
'secp521r1': 'P-521', 'p-521': 'P-521',
|
|
819
|
+
};
|
|
820
|
+
|
|
821
|
+
function keyPairAlgorithm(type: string, options: KeyPairOptions): { generate: AlgorithmIdentifier & Record<string, unknown>; usages: KeyUsage[]; name: string } {
|
|
822
|
+
const exponent = (value: number | undefined): Uint8Array => {
|
|
823
|
+
let rest = value ?? 0x10001;
|
|
824
|
+
const bytes: number[] = [];
|
|
825
|
+
while (rest > 0) { bytes.unshift(rest & 0xff); rest = Math.floor(rest / 256); }
|
|
826
|
+
return new Uint8Array(bytes);
|
|
827
|
+
};
|
|
828
|
+
switch (type) {
|
|
829
|
+
case 'rsa':
|
|
830
|
+
case 'rsa-pss': {
|
|
831
|
+
if (!Number.isInteger(options.modulusLength)) throw Object.assign(new TypeError('The "options.modulusLength" property must be of type number.'), { code: 'ERR_INVALID_ARG_TYPE' });
|
|
832
|
+
const name = type === 'rsa' ? 'RSASSA-PKCS1-v1_5' : 'RSA-PSS';
|
|
833
|
+
return { generate: { name, modulusLength: options.modulusLength, publicExponent: exponent(options.publicExponent), hash: 'SHA-256' }, usages: ['sign', 'verify'], name: type === 'rsa' ? 'RSA-SHA256' : 'RSA-PSS' };
|
|
834
|
+
}
|
|
835
|
+
case 'ec': {
|
|
836
|
+
const curve = NAMED_CURVES[String(options.namedCurve ?? '').toLowerCase()];
|
|
837
|
+
if (!curve) throw Object.assign(new TypeError(`Invalid EC curve name ${String(options.namedCurve)}`), { code: 'ERR_CRYPTO_INVALID_CURVE' });
|
|
838
|
+
return { generate: { name: 'ECDSA', namedCurve: curve }, usages: ['sign', 'verify'], name: curve === 'P-256' ? 'ES256' : curve === 'P-384' ? 'ES384' : 'ES512' };
|
|
839
|
+
}
|
|
840
|
+
case 'ed25519':
|
|
841
|
+
return { generate: { name: 'Ed25519' }, usages: ['sign', 'verify'], name: 'Ed25519' };
|
|
842
|
+
case 'x25519':
|
|
843
|
+
return { generate: { name: 'X25519' }, usages: ['deriveBits'], name: 'X25519' };
|
|
844
|
+
default:
|
|
845
|
+
throw Object.assign(new TypeError(`The argument 'type' must be a supported key type. Received '${type}'`), { code: 'ERR_INVALID_ARG_VALUE' });
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
|
|
849
|
+
function encodedKey(der: ArrayBuffer, encoding: KeyEncoding, kind: 'public' | 'private'): string | Buffer {
|
|
850
|
+
const expected = kind === 'public' ? 'spki' : 'pkcs8';
|
|
851
|
+
if (encoding.type !== undefined && encoding.type !== expected) {
|
|
852
|
+
unsupported(`Encoding a ${kind} key as ${encoding.type}`);
|
|
853
|
+
}
|
|
854
|
+
const bytes = Buffer.from(der);
|
|
855
|
+
if (encoding.format === 'der') return bytes;
|
|
856
|
+
if (encoding.format !== 'pem') unsupported(`Encoding a key in the ${String(encoding.format)} format`);
|
|
857
|
+
const label = kind === 'public' ? 'PUBLIC KEY' : 'PRIVATE KEY';
|
|
858
|
+
const body = bytes.toString('base64').match(/.{1,64}/g)!.join('\n');
|
|
859
|
+
return `-----BEGIN ${label}-----\n${body}\n-----END ${label}-----\n`;
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
async function generateKeyPairAsync(type: string, options: KeyPairOptions): Promise<{ publicKey: KeyObject | string | Buffer; privateKey: KeyObject | string | Buffer }> {
|
|
863
|
+
const algorithm = keyPairAlgorithm(type, options);
|
|
864
|
+
const pair = await crypto.subtle.generateKey(algorithm.generate as AlgorithmIdentifier, true, algorithm.usages) as CryptoKeyPair;
|
|
865
|
+
const publicKey = options.publicKeyEncoding
|
|
866
|
+
? encodedKey(await crypto.subtle.exportKey('spki', pair.publicKey), options.publicKeyEncoding, 'public')
|
|
867
|
+
: new KeyObject('public', pair.publicKey, algorithm.name);
|
|
868
|
+
const privateKey = options.privateKeyEncoding
|
|
869
|
+
? encodedKey(await crypto.subtle.exportKey('pkcs8', pair.privateKey), options.privateKeyEncoding, 'private')
|
|
870
|
+
: new KeyObject('private', pair.privateKey, algorithm.name);
|
|
871
|
+
return { publicKey, privateKey };
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
function generateKeyPair(type: string, options: KeyPairOptions | ((error: Error | null, publicKey?: unknown, privateKey?: unknown) => void), callback?: (error: Error | null, publicKey?: unknown, privateKey?: unknown) => void): void {
|
|
875
|
+
if (typeof options === 'function') { callback = options; options = {}; }
|
|
876
|
+
if (typeof callback !== 'function') throw Object.assign(new TypeError('The "callback" argument must be of type function.'), { code: 'ERR_INVALID_ARG_TYPE' });
|
|
877
|
+
const done = callback;
|
|
878
|
+
// Argument errors throw synchronously, as Node's do.
|
|
879
|
+
keyPairAlgorithm(type, options ?? {});
|
|
880
|
+
generateKeyPairAsync(type, options ?? {}).then(
|
|
881
|
+
({ publicKey, privateKey }) => done(null, publicKey, privateKey),
|
|
882
|
+
(error) => done(error instanceof Error ? error : new Error(String(error))),
|
|
883
|
+
);
|
|
884
|
+
}
|
|
885
|
+
Object.defineProperty(generateKeyPair, Symbol.for('nodejs.util.promisify.custom'), {
|
|
886
|
+
value: (type: string, options?: KeyPairOptions) => generateKeyPairAsync(type, options ?? {}),
|
|
887
|
+
});
|
|
888
|
+
|
|
803
889
|
// ============================================================================
|
|
804
890
|
// Utility functions
|
|
805
891
|
// ============================================================================
|
|
@@ -1067,10 +1153,11 @@ return {
|
|
|
1067
1153
|
createSecretKey,
|
|
1068
1154
|
createPublicKey,
|
|
1069
1155
|
createPrivateKey,
|
|
1156
|
+
generateKeyPair,
|
|
1070
1157
|
};
|
|
1071
1158
|
|
|
1072
1159
|
}
|
|
1073
1160
|
const cryptoModule = createCryptoModule();
|
|
1074
|
-
export const { randomBytes, randomFillSync, randomFill, randomUUID, randomInt, getRandomValues, unsupported, createHash, createHmac, hash, pbkdf2Sync, pbkdf2, sign, verify, createSign, createVerify, KeyObject, createSecretKey, createPublicKey, createPrivateKey, timingSafeEqual, getCiphers, getHashes } = cryptoModule;
|
|
1161
|
+
export 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;
|
|
1075
1162
|
export type KeyObject = InstanceType<typeof KeyObject>;
|
|
1076
1163
|
export default cryptoModule;
|