@secure-exec/core 0.1.1-rc.3 → 0.2.0-rc.1
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/esm-compiler.d.ts +5 -1
- package/dist/esm-compiler.js +5 -1
- package/dist/fs-helpers.d.ts +1 -1
- package/dist/generated/isolate-runtime.d.ts +15 -15
- package/dist/generated/isolate-runtime.js +15 -15
- package/dist/index.d.ts +24 -5
- package/dist/index.js +23 -3
- package/dist/isolate-runtime/apply-custom-global-policy.js +3 -3
- package/dist/isolate-runtime/apply-timing-mitigation-freeze.js +2 -2
- package/dist/isolate-runtime/apply-timing-mitigation-off.js +2 -2
- package/dist/isolate-runtime/bridge-attach.js +2 -2
- package/dist/isolate-runtime/bridge-initial-globals.js +145 -6
- package/dist/isolate-runtime/eval-script-result.js +1 -1
- package/dist/isolate-runtime/global-exposure-helpers.js +2 -2
- package/dist/isolate-runtime/init-commonjs-module-globals.js +2 -2
- package/dist/isolate-runtime/override-process-cwd.js +1 -1
- package/dist/isolate-runtime/override-process-env.js +1 -1
- package/dist/isolate-runtime/require-setup.js +1600 -338
- package/dist/isolate-runtime/set-commonjs-file-globals.js +2 -2
- package/dist/isolate-runtime/set-stdin-data.js +1 -1
- package/dist/isolate-runtime/setup-dynamic-import.js +47 -19
- package/dist/isolate-runtime/setup-fs-facade.js +62 -23
- package/dist/kernel/command-registry.d.ts +44 -0
- package/dist/kernel/command-registry.js +114 -0
- package/dist/kernel/device-layer.d.ts +12 -0
- package/dist/kernel/device-layer.js +262 -0
- package/dist/kernel/dns-cache.d.ts +29 -0
- package/dist/kernel/dns-cache.js +52 -0
- package/dist/kernel/fd-table.d.ts +84 -0
- package/dist/kernel/fd-table.js +278 -0
- package/dist/kernel/file-lock.d.ts +34 -0
- package/dist/kernel/file-lock.js +123 -0
- package/dist/kernel/host-adapter.d.ts +50 -0
- package/dist/kernel/host-adapter.js +8 -0
- package/dist/kernel/index.d.ts +36 -0
- package/dist/kernel/index.js +34 -0
- package/dist/kernel/inode-table.d.ts +43 -0
- package/dist/kernel/inode-table.js +85 -0
- package/dist/kernel/kernel.d.ts +9 -0
- package/dist/kernel/kernel.js +1396 -0
- package/dist/kernel/permissions.d.ts +27 -0
- package/dist/kernel/permissions.js +118 -0
- package/dist/kernel/pipe-manager.d.ts +64 -0
- package/dist/kernel/pipe-manager.js +267 -0
- package/dist/kernel/proc-layer.d.ts +11 -0
- package/dist/kernel/proc-layer.js +501 -0
- package/dist/kernel/process-table.d.ts +124 -0
- package/dist/kernel/process-table.js +631 -0
- package/dist/kernel/pty.d.ts +108 -0
- package/dist/kernel/pty.js +541 -0
- package/dist/kernel/socket-table.d.ts +305 -0
- package/dist/kernel/socket-table.js +1124 -0
- package/dist/kernel/timer-table.d.ts +54 -0
- package/dist/kernel/timer-table.js +108 -0
- package/dist/kernel/types.d.ts +500 -0
- package/dist/kernel/types.js +89 -0
- package/dist/kernel/user.d.ts +29 -0
- package/dist/kernel/user.js +35 -0
- package/dist/kernel/vfs.d.ts +54 -0
- package/dist/kernel/vfs.js +8 -0
- package/dist/kernel/wait.d.ts +45 -0
- package/dist/kernel/wait.js +112 -0
- package/dist/kernel/wstatus.d.ts +21 -0
- package/dist/kernel/wstatus.js +33 -0
- package/dist/module-resolver.d.ts +4 -0
- package/dist/module-resolver.js +4 -0
- package/dist/package-bundler.d.ts +6 -1
- package/dist/runtime-driver.d.ts +3 -1
- package/dist/shared/bridge-contract.d.ts +329 -20
- package/dist/shared/bridge-contract.js +60 -5
- package/dist/shared/console-formatter.js +8 -4
- package/dist/shared/global-exposure.js +269 -19
- package/dist/shared/in-memory-fs.d.ts +30 -11
- package/dist/shared/in-memory-fs.js +383 -109
- package/dist/shared/permissions.d.ts +4 -6
- package/dist/shared/permissions.js +19 -39
- package/dist/types.d.ts +8 -159
- package/dist/types.js +5 -0
- package/package.json +12 -22
- package/dist/bridge/active-handles.d.ts +0 -22
- package/dist/bridge/active-handles.js +0 -55
- package/dist/bridge/child-process.d.ts +0 -99
- package/dist/bridge/child-process.js +0 -670
- package/dist/bridge/fs.d.ts +0 -281
- package/dist/bridge/fs.js +0 -2235
- package/dist/bridge/index.d.ts +0 -10
- package/dist/bridge/index.js +0 -41
- package/dist/bridge/module.d.ts +0 -75
- package/dist/bridge/module.js +0 -308
- package/dist/bridge/network.d.ts +0 -350
- package/dist/bridge/network.js +0 -2050
- package/dist/bridge/os.d.ts +0 -13
- package/dist/bridge/os.js +0 -256
- package/dist/bridge/polyfills.d.ts +0 -2
- package/dist/bridge/polyfills.js +0 -11
- package/dist/bridge/process.d.ts +0 -89
- package/dist/bridge/process.js +0 -1015
- package/dist/bridge.js +0 -12496
- package/dist/python-runtime.d.ts +0 -16
- package/dist/python-runtime.js +0 -45
- package/dist/runtime.d.ts +0 -31
- package/dist/runtime.js +0 -69
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
(() => {
|
|
3
|
-
// isolate-runtime/src/inject/require-setup.ts
|
|
3
|
+
// ../core/isolate-runtime/src/inject/require-setup.ts
|
|
4
4
|
var __requireExposeCustomGlobal = typeof globalThis.__runtimeExposeCustomGlobal === "function" ? globalThis.__runtimeExposeCustomGlobal : function exposeCustomGlobal(name2, value) {
|
|
5
5
|
Object.defineProperty(globalThis, name2, {
|
|
6
6
|
value,
|
|
@@ -9,23 +9,48 @@
|
|
|
9
9
|
enumerable: true
|
|
10
10
|
});
|
|
11
11
|
};
|
|
12
|
-
if (typeof globalThis.AbortController === "undefined" || typeof globalThis.AbortSignal === "undefined") {
|
|
12
|
+
if (typeof globalThis.AbortController === "undefined" || typeof globalThis.AbortSignal === "undefined" || typeof globalThis.AbortSignal?.prototype?.addEventListener !== "function" || typeof globalThis.AbortSignal?.prototype?.removeEventListener !== "function") {
|
|
13
|
+
let getAbortSignalState = function(signal) {
|
|
14
|
+
const state = abortSignalState.get(signal);
|
|
15
|
+
if (!state) {
|
|
16
|
+
throw new Error("Invalid AbortSignal");
|
|
17
|
+
}
|
|
18
|
+
return state;
|
|
19
|
+
};
|
|
20
|
+
getAbortSignalState2 = getAbortSignalState;
|
|
21
|
+
const abortSignalState = /* @__PURE__ */ new WeakMap();
|
|
13
22
|
class AbortSignal {
|
|
14
23
|
constructor() {
|
|
15
|
-
this.aborted = false;
|
|
16
|
-
this.reason = void 0;
|
|
17
24
|
this.onabort = null;
|
|
18
|
-
this
|
|
25
|
+
abortSignalState.set(this, {
|
|
26
|
+
aborted: false,
|
|
27
|
+
reason: void 0,
|
|
28
|
+
listeners: []
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
get aborted() {
|
|
32
|
+
return getAbortSignalState(this).aborted;
|
|
33
|
+
}
|
|
34
|
+
get reason() {
|
|
35
|
+
return getAbortSignalState(this).reason;
|
|
36
|
+
}
|
|
37
|
+
get _listeners() {
|
|
38
|
+
return getAbortSignalState(this).listeners.slice();
|
|
39
|
+
}
|
|
40
|
+
getEventListeners(type) {
|
|
41
|
+
if (type !== "abort") return [];
|
|
42
|
+
return getAbortSignalState(this).listeners.slice();
|
|
19
43
|
}
|
|
20
44
|
addEventListener(type, listener) {
|
|
21
45
|
if (type !== "abort" || typeof listener !== "function") return;
|
|
22
|
-
this.
|
|
46
|
+
getAbortSignalState(this).listeners.push(listener);
|
|
23
47
|
}
|
|
24
48
|
removeEventListener(type, listener) {
|
|
25
49
|
if (type !== "abort" || typeof listener !== "function") return;
|
|
26
|
-
const
|
|
50
|
+
const listeners = getAbortSignalState(this).listeners;
|
|
51
|
+
const index = listeners.indexOf(listener);
|
|
27
52
|
if (index !== -1) {
|
|
28
|
-
|
|
53
|
+
listeners.splice(index, 1);
|
|
29
54
|
}
|
|
30
55
|
}
|
|
31
56
|
dispatchEvent(event) {
|
|
@@ -36,7 +61,7 @@
|
|
|
36
61
|
} catch {
|
|
37
62
|
}
|
|
38
63
|
}
|
|
39
|
-
const listeners = this.
|
|
64
|
+
const listeners = getAbortSignalState(this).listeners.slice();
|
|
40
65
|
for (const listener of listeners) {
|
|
41
66
|
try {
|
|
42
67
|
listener.call(this, event);
|
|
@@ -51,15 +76,24 @@
|
|
|
51
76
|
this.signal = new AbortSignal();
|
|
52
77
|
}
|
|
53
78
|
abort(reason) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
79
|
+
const state = getAbortSignalState(this.signal);
|
|
80
|
+
if (state.aborted) return;
|
|
81
|
+
state.aborted = true;
|
|
82
|
+
state.reason = reason;
|
|
57
83
|
this.signal.dispatchEvent({ type: "abort" });
|
|
58
84
|
}
|
|
59
85
|
}
|
|
60
86
|
__requireExposeCustomGlobal("AbortSignal", AbortSignal);
|
|
61
87
|
__requireExposeCustomGlobal("AbortController", AbortController);
|
|
62
88
|
}
|
|
89
|
+
var getAbortSignalState2;
|
|
90
|
+
if (typeof globalThis.AbortSignal === "function" && typeof globalThis.AbortController === "function" && typeof globalThis.AbortSignal.abort !== "function") {
|
|
91
|
+
globalThis.AbortSignal.abort = function abort(reason) {
|
|
92
|
+
const controller = new globalThis.AbortController();
|
|
93
|
+
controller.abort(reason);
|
|
94
|
+
return controller.signal;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
63
97
|
if (typeof globalThis.structuredClone !== "function") {
|
|
64
98
|
let structuredClonePolyfill = function(value) {
|
|
65
99
|
if (value === null || typeof value !== "object") {
|
|
@@ -80,6 +114,10 @@
|
|
|
80
114
|
__requireExposeCustomGlobal("structuredClone", structuredClonePolyfill);
|
|
81
115
|
}
|
|
82
116
|
var structuredClonePolyfill2;
|
|
117
|
+
if (typeof globalThis.SharedArrayBuffer === "undefined") {
|
|
118
|
+
globalThis.SharedArrayBuffer = ArrayBuffer;
|
|
119
|
+
__requireExposeCustomGlobal("SharedArrayBuffer", ArrayBuffer);
|
|
120
|
+
}
|
|
83
121
|
if (typeof globalThis.btoa !== "function") {
|
|
84
122
|
__requireExposeCustomGlobal("btoa", function btoa(input) {
|
|
85
123
|
return Buffer.from(String(input), "binary").toString("base64");
|
|
@@ -157,24 +195,39 @@
|
|
|
157
195
|
if (typeof BufferCtor.constants !== "object" || BufferCtor.constants === null) {
|
|
158
196
|
BufferCtor.constants = result2.constants;
|
|
159
197
|
}
|
|
160
|
-
var
|
|
161
|
-
if (
|
|
162
|
-
var
|
|
163
|
-
for (var ei = 0; ei <
|
|
198
|
+
var proto = BufferCtor.prototype;
|
|
199
|
+
if (proto && typeof proto.utf8Slice !== "function") {
|
|
200
|
+
var encodings = ["utf8", "latin1", "ascii", "hex", "base64", "ucs2", "utf16le"];
|
|
201
|
+
for (var ei = 0; ei < encodings.length; ei++) {
|
|
202
|
+
var enc = encodings[ei];
|
|
164
203
|
(function(e) {
|
|
165
|
-
if (typeof
|
|
166
|
-
|
|
204
|
+
if (typeof proto[e + "Slice"] !== "function") {
|
|
205
|
+
proto[e + "Slice"] = function(start, end) {
|
|
167
206
|
return this.toString(e, start, end);
|
|
168
207
|
};
|
|
169
208
|
}
|
|
170
|
-
if (typeof
|
|
171
|
-
|
|
172
|
-
return this.write(
|
|
209
|
+
if (typeof proto[e + "Write"] !== "function") {
|
|
210
|
+
proto[e + "Write"] = function(string, offset, length) {
|
|
211
|
+
return this.write(string, offset, length, e);
|
|
173
212
|
};
|
|
174
213
|
}
|
|
175
|
-
})(
|
|
214
|
+
})(enc);
|
|
176
215
|
}
|
|
177
216
|
}
|
|
217
|
+
if (typeof BufferCtor.allocUnsafe === "function" && !BufferCtor.allocUnsafe._secureExecPatched) {
|
|
218
|
+
var _origAllocUnsafe = BufferCtor.allocUnsafe;
|
|
219
|
+
BufferCtor.allocUnsafe = function(size) {
|
|
220
|
+
try {
|
|
221
|
+
return _origAllocUnsafe.apply(this, arguments);
|
|
222
|
+
} catch (error) {
|
|
223
|
+
if (error && error.name === "RangeError" && typeof size === "number" && size > maxLength) {
|
|
224
|
+
throw new Error("Array buffer allocation failed");
|
|
225
|
+
}
|
|
226
|
+
throw error;
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
BufferCtor.allocUnsafe._secureExecPatched = true;
|
|
230
|
+
}
|
|
178
231
|
}
|
|
179
232
|
return result2;
|
|
180
233
|
}
|
|
@@ -182,6 +235,146 @@
|
|
|
182
235
|
result2.formatWithOptions = function formatWithOptions(inspectOptions, ...args) {
|
|
183
236
|
return result2.format.apply(null, args);
|
|
184
237
|
};
|
|
238
|
+
}
|
|
239
|
+
if (name2 === "util") {
|
|
240
|
+
if (typeof result2.inspect === "function" && typeof result2.inspect.custom === "undefined") {
|
|
241
|
+
result2.inspect.custom = /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
242
|
+
}
|
|
243
|
+
if (typeof result2.inspect === "function" && !result2.inspect._secureExecPatchedCustomInspect) {
|
|
244
|
+
const customInspectSymbol = result2.inspect.custom || /* @__PURE__ */ Symbol.for("nodejs.util.inspect.custom");
|
|
245
|
+
const originalInspect = result2.inspect;
|
|
246
|
+
const formatObjectKey = function(key) {
|
|
247
|
+
return /^[A-Za-z_$][A-Za-z0-9_$]*$/.test(key) ? key : originalInspect(key);
|
|
248
|
+
};
|
|
249
|
+
const containsCustomInspectable = function(value, depth, seen) {
|
|
250
|
+
if (value === null) {
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
if (typeof value !== "object" && typeof value !== "function") {
|
|
254
|
+
return false;
|
|
255
|
+
}
|
|
256
|
+
if (typeof value[customInspectSymbol] === "function") {
|
|
257
|
+
return true;
|
|
258
|
+
}
|
|
259
|
+
if (depth < 0 || seen.has(value)) {
|
|
260
|
+
return false;
|
|
261
|
+
}
|
|
262
|
+
seen.add(value);
|
|
263
|
+
if (Array.isArray(value)) {
|
|
264
|
+
for (const entry of value) {
|
|
265
|
+
if (containsCustomInspectable(entry, depth - 1, seen)) {
|
|
266
|
+
seen.delete(value);
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
seen.delete(value);
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
for (const key of Object.keys(value)) {
|
|
274
|
+
if (containsCustomInspectable(value[key], depth - 1, seen)) {
|
|
275
|
+
seen.delete(value);
|
|
276
|
+
return true;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
seen.delete(value);
|
|
280
|
+
return false;
|
|
281
|
+
};
|
|
282
|
+
const inspectWithCustom = function(value, depth, options, seen) {
|
|
283
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") {
|
|
284
|
+
return originalInspect(value, options);
|
|
285
|
+
}
|
|
286
|
+
if (seen.has(value)) {
|
|
287
|
+
return "[Circular]";
|
|
288
|
+
}
|
|
289
|
+
if (typeof value[customInspectSymbol] === "function") {
|
|
290
|
+
return value[customInspectSymbol](depth, options, result2.inspect);
|
|
291
|
+
}
|
|
292
|
+
if (depth < 0) {
|
|
293
|
+
return originalInspect(value, options);
|
|
294
|
+
}
|
|
295
|
+
seen.add(value);
|
|
296
|
+
if (Array.isArray(value)) {
|
|
297
|
+
const items = value.map((entry) => inspectWithCustom(entry, depth - 1, options, seen));
|
|
298
|
+
seen.delete(value);
|
|
299
|
+
return `[ ${items.join(", ")} ]`;
|
|
300
|
+
}
|
|
301
|
+
const proto2 = Object.getPrototypeOf(value);
|
|
302
|
+
if (proto2 === Object.prototype || proto2 === null) {
|
|
303
|
+
const entries = Object.keys(value).map(
|
|
304
|
+
(key) => `${formatObjectKey(key)}: ${inspectWithCustom(value[key], depth - 1, options, seen)}`
|
|
305
|
+
);
|
|
306
|
+
seen.delete(value);
|
|
307
|
+
return `{ ${entries.join(", ")} }`;
|
|
308
|
+
}
|
|
309
|
+
seen.delete(value);
|
|
310
|
+
return originalInspect(value, options);
|
|
311
|
+
};
|
|
312
|
+
result2.inspect = function inspect(value, options) {
|
|
313
|
+
const inspectOptions = typeof options === "object" && options !== null ? options : {};
|
|
314
|
+
const depth = typeof inspectOptions.depth === "number" ? inspectOptions.depth : 2;
|
|
315
|
+
if (!containsCustomInspectable(value, depth, /* @__PURE__ */ new Set())) {
|
|
316
|
+
return originalInspect.call(this, value, options);
|
|
317
|
+
}
|
|
318
|
+
return inspectWithCustom(value, depth, inspectOptions, /* @__PURE__ */ new Set());
|
|
319
|
+
};
|
|
320
|
+
result2.inspect.custom = customInspectSymbol;
|
|
321
|
+
result2.inspect._secureExecPatchedCustomInspect = true;
|
|
322
|
+
}
|
|
323
|
+
return result2;
|
|
324
|
+
}
|
|
325
|
+
if (name2 === "events") {
|
|
326
|
+
if (typeof result2.getEventListeners !== "function") {
|
|
327
|
+
result2.getEventListeners = function getEventListeners(target, eventName) {
|
|
328
|
+
if (target && typeof target.listeners === "function") {
|
|
329
|
+
return target.listeners(eventName);
|
|
330
|
+
}
|
|
331
|
+
if (target && typeof target.getEventListeners === "function") {
|
|
332
|
+
return target.getEventListeners(eventName);
|
|
333
|
+
}
|
|
334
|
+
if (target && eventName === "abort" && Array.isArray(target._listeners)) {
|
|
335
|
+
return target._listeners.slice();
|
|
336
|
+
}
|
|
337
|
+
return [];
|
|
338
|
+
};
|
|
339
|
+
}
|
|
340
|
+
return result2;
|
|
341
|
+
}
|
|
342
|
+
if (name2 === "stream") {
|
|
343
|
+
const ReadableCtor = result2.Readable;
|
|
344
|
+
const readableFrom = typeof ReadableCtor === "function" ? ReadableCtor.from : void 0;
|
|
345
|
+
const readableFromSource = typeof readableFrom === "function" ? Function.prototype.toString.call(readableFrom) : "";
|
|
346
|
+
const hasBrowserReadableFromStub = readableFromSource.indexOf(
|
|
347
|
+
"Readable.from is not available in the browser"
|
|
348
|
+
) !== -1 || readableFromSource.indexOf("require_from_browser") !== -1;
|
|
349
|
+
if (typeof ReadableCtor === "function" && (typeof readableFrom !== "function" || hasBrowserReadableFromStub)) {
|
|
350
|
+
ReadableCtor.from = function from(iterable, options) {
|
|
351
|
+
const readable = new ReadableCtor(Object.assign({ read() {
|
|
352
|
+
} }, options || {}));
|
|
353
|
+
Promise.resolve().then(async function() {
|
|
354
|
+
try {
|
|
355
|
+
if (iterable && typeof iterable[Symbol.asyncIterator] === "function") {
|
|
356
|
+
for await (const chunk of iterable) {
|
|
357
|
+
readable.push(chunk);
|
|
358
|
+
}
|
|
359
|
+
} else if (iterable && typeof iterable[Symbol.iterator] === "function") {
|
|
360
|
+
for (const chunk of iterable) {
|
|
361
|
+
readable.push(chunk);
|
|
362
|
+
}
|
|
363
|
+
} else {
|
|
364
|
+
readable.push(iterable);
|
|
365
|
+
}
|
|
366
|
+
readable.push(null);
|
|
367
|
+
} catch (error) {
|
|
368
|
+
if (typeof readable.destroy === "function") {
|
|
369
|
+
readable.destroy(error);
|
|
370
|
+
} else {
|
|
371
|
+
readable.emit("error", error);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
});
|
|
375
|
+
return readable;
|
|
376
|
+
};
|
|
377
|
+
}
|
|
185
378
|
return result2;
|
|
186
379
|
}
|
|
187
380
|
if (name2 === "url") {
|
|
@@ -253,44 +446,161 @@
|
|
|
253
446
|
return result2;
|
|
254
447
|
}
|
|
255
448
|
if (name2 === "crypto") {
|
|
449
|
+
let createCryptoRangeError2 = function(name3, message) {
|
|
450
|
+
var error = new RangeError(message);
|
|
451
|
+
error.code = "ERR_OUT_OF_RANGE";
|
|
452
|
+
error.name = "RangeError";
|
|
453
|
+
return error;
|
|
454
|
+
}, createCryptoError2 = function(code, message) {
|
|
455
|
+
var error = new Error(message);
|
|
456
|
+
error.code = code;
|
|
457
|
+
return error;
|
|
458
|
+
}, encodeCryptoResult2 = function(buffer, encoding) {
|
|
459
|
+
if (!encoding || encoding === "buffer") return buffer;
|
|
460
|
+
return buffer.toString(encoding);
|
|
461
|
+
}, isSharedArrayBufferInstance2 = function(value) {
|
|
462
|
+
return typeof SharedArrayBuffer !== "undefined" && value instanceof SharedArrayBuffer;
|
|
463
|
+
}, isBinaryLike2 = function(value) {
|
|
464
|
+
return Buffer.isBuffer(value) || ArrayBuffer.isView(value) || value instanceof ArrayBuffer || isSharedArrayBufferInstance2(value);
|
|
465
|
+
}, normalizeByteSource2 = function(value, name3, options) {
|
|
466
|
+
var allowNull = options && options.allowNull;
|
|
467
|
+
if (allowNull && value === null) {
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
if (typeof value === "string") {
|
|
471
|
+
return Buffer.from(value, "utf8");
|
|
472
|
+
}
|
|
473
|
+
if (Buffer.isBuffer(value)) {
|
|
474
|
+
return Buffer.from(value);
|
|
475
|
+
}
|
|
476
|
+
if (ArrayBuffer.isView(value)) {
|
|
477
|
+
return Buffer.from(value.buffer, value.byteOffset, value.byteLength);
|
|
478
|
+
}
|
|
479
|
+
if (value instanceof ArrayBuffer || isSharedArrayBufferInstance2(value)) {
|
|
480
|
+
return Buffer.from(value);
|
|
481
|
+
}
|
|
482
|
+
throw createInvalidArgTypeError(
|
|
483
|
+
name3,
|
|
484
|
+
"of type string or an instance of ArrayBuffer, Buffer, TypedArray, or DataView",
|
|
485
|
+
value
|
|
486
|
+
);
|
|
487
|
+
}, serializeCipherBridgeOptions2 = function(options) {
|
|
488
|
+
if (!options) {
|
|
489
|
+
return "";
|
|
490
|
+
}
|
|
491
|
+
var serialized = {};
|
|
492
|
+
if (options.authTagLength !== void 0) {
|
|
493
|
+
serialized.authTagLength = options.authTagLength;
|
|
494
|
+
}
|
|
495
|
+
if (options.authTag) {
|
|
496
|
+
serialized.authTag = options.authTag.toString("base64");
|
|
497
|
+
}
|
|
498
|
+
if (options.aad) {
|
|
499
|
+
serialized.aad = options.aad.toString("base64");
|
|
500
|
+
}
|
|
501
|
+
if (options.aadOptions !== void 0) {
|
|
502
|
+
serialized.aadOptions = options.aadOptions;
|
|
503
|
+
}
|
|
504
|
+
if (options.autoPadding !== void 0) {
|
|
505
|
+
serialized.autoPadding = options.autoPadding;
|
|
506
|
+
}
|
|
507
|
+
if (options.validateOnly !== void 0) {
|
|
508
|
+
serialized.validateOnly = options.validateOnly;
|
|
509
|
+
}
|
|
510
|
+
return JSON.stringify(serialized);
|
|
511
|
+
};
|
|
512
|
+
var createCryptoRangeError = createCryptoRangeError2, createCryptoError = createCryptoError2, encodeCryptoResult = encodeCryptoResult2, isSharedArrayBufferInstance = isSharedArrayBufferInstance2, isBinaryLike = isBinaryLike2, normalizeByteSource = normalizeByteSource2, serializeCipherBridgeOptions = serializeCipherBridgeOptions2;
|
|
513
|
+
var _runtimeRequire = globalThis.require;
|
|
514
|
+
var _streamModule = _runtimeRequire && _runtimeRequire("stream");
|
|
515
|
+
var _utilModule = _runtimeRequire && _runtimeRequire("util");
|
|
516
|
+
var _Transform = _streamModule && _streamModule.Transform;
|
|
517
|
+
var _inherits = _utilModule && _utilModule.inherits;
|
|
256
518
|
if (typeof _cryptoHashDigest !== "undefined") {
|
|
257
|
-
let SandboxHash2 = function(algorithm) {
|
|
519
|
+
let SandboxHash2 = function(algorithm, options) {
|
|
520
|
+
if (!(this instanceof SandboxHash2)) {
|
|
521
|
+
return new SandboxHash2(algorithm, options);
|
|
522
|
+
}
|
|
523
|
+
if (!_Transform || !_inherits) {
|
|
524
|
+
throw new Error("stream.Transform is required for crypto.Hash");
|
|
525
|
+
}
|
|
526
|
+
if (typeof algorithm !== "string") {
|
|
527
|
+
throw createInvalidArgTypeError("algorithm", "of type string", algorithm);
|
|
528
|
+
}
|
|
529
|
+
_Transform.call(this, options);
|
|
258
530
|
this._algorithm = algorithm;
|
|
259
531
|
this._chunks = [];
|
|
532
|
+
this._finalized = false;
|
|
533
|
+
this._cachedDigest = null;
|
|
534
|
+
this._allowCachedDigest = false;
|
|
260
535
|
};
|
|
261
536
|
var SandboxHash = SandboxHash2;
|
|
537
|
+
_inherits(SandboxHash2, _Transform);
|
|
262
538
|
SandboxHash2.prototype.update = function update(data, inputEncoding) {
|
|
539
|
+
if (this._finalized) {
|
|
540
|
+
throw createCryptoError2("ERR_CRYPTO_HASH_FINALIZED", "Digest already called");
|
|
541
|
+
}
|
|
263
542
|
if (typeof data === "string") {
|
|
264
543
|
this._chunks.push(Buffer.from(data, inputEncoding || "utf8"));
|
|
265
|
-
} else {
|
|
544
|
+
} else if (isBinaryLike2(data)) {
|
|
266
545
|
this._chunks.push(Buffer.from(data));
|
|
546
|
+
} else {
|
|
547
|
+
throw createInvalidArgTypeError(
|
|
548
|
+
"data",
|
|
549
|
+
"one of type string, Buffer, TypedArray, or DataView",
|
|
550
|
+
data
|
|
551
|
+
);
|
|
267
552
|
}
|
|
268
553
|
return this;
|
|
269
554
|
};
|
|
270
|
-
SandboxHash2.prototype.
|
|
555
|
+
SandboxHash2.prototype._finishDigest = function _finishDigest() {
|
|
556
|
+
if (this._cachedDigest) {
|
|
557
|
+
return this._cachedDigest;
|
|
558
|
+
}
|
|
271
559
|
var combined = Buffer.concat(this._chunks);
|
|
272
560
|
var resultBase64 = _cryptoHashDigest.applySync(void 0, [
|
|
273
561
|
this._algorithm,
|
|
274
562
|
combined.toString("base64")
|
|
275
563
|
]);
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
return
|
|
564
|
+
this._cachedDigest = Buffer.from(resultBase64, "base64");
|
|
565
|
+
this._finalized = true;
|
|
566
|
+
return this._cachedDigest;
|
|
567
|
+
};
|
|
568
|
+
SandboxHash2.prototype.digest = function digest(encoding) {
|
|
569
|
+
if (this._finalized && !this._allowCachedDigest) {
|
|
570
|
+
throw createCryptoError2("ERR_CRYPTO_HASH_FINALIZED", "Digest already called");
|
|
571
|
+
}
|
|
572
|
+
var resultBuffer = this._finishDigest();
|
|
573
|
+
this._allowCachedDigest = false;
|
|
574
|
+
return encodeCryptoResult2(resultBuffer, encoding);
|
|
279
575
|
};
|
|
280
576
|
SandboxHash2.prototype.copy = function copy() {
|
|
577
|
+
if (this._finalized) {
|
|
578
|
+
throw createCryptoError2("ERR_CRYPTO_HASH_FINALIZED", "Digest already called");
|
|
579
|
+
}
|
|
281
580
|
var c = new SandboxHash2(this._algorithm);
|
|
282
581
|
c._chunks = this._chunks.slice();
|
|
283
582
|
return c;
|
|
284
583
|
};
|
|
285
|
-
SandboxHash2.prototype.
|
|
286
|
-
|
|
287
|
-
|
|
584
|
+
SandboxHash2.prototype._transform = function _transform(chunk, encoding, callback) {
|
|
585
|
+
try {
|
|
586
|
+
this.update(chunk, encoding === "buffer" ? void 0 : encoding);
|
|
587
|
+
callback();
|
|
588
|
+
} catch (error) {
|
|
589
|
+
callback(normalizeCryptoBridgeError(error));
|
|
590
|
+
}
|
|
288
591
|
};
|
|
289
|
-
SandboxHash2.prototype.
|
|
290
|
-
|
|
592
|
+
SandboxHash2.prototype._flush = function _flush(callback) {
|
|
593
|
+
try {
|
|
594
|
+
var output = this._finishDigest();
|
|
595
|
+
this._allowCachedDigest = true;
|
|
596
|
+
this.push(output);
|
|
597
|
+
callback();
|
|
598
|
+
} catch (error) {
|
|
599
|
+
callback(normalizeCryptoBridgeError(error));
|
|
600
|
+
}
|
|
291
601
|
};
|
|
292
|
-
result2.createHash = function createHash(algorithm) {
|
|
293
|
-
return new SandboxHash2(algorithm);
|
|
602
|
+
result2.createHash = function createHash(algorithm, options) {
|
|
603
|
+
return new SandboxHash2(algorithm, options);
|
|
294
604
|
};
|
|
295
605
|
result2.Hash = SandboxHash2;
|
|
296
606
|
}
|
|
@@ -471,24 +781,89 @@
|
|
|
471
781
|
};
|
|
472
782
|
}
|
|
473
783
|
if (typeof _cryptoPbkdf2 !== "undefined") {
|
|
784
|
+
let createPbkdf2ArgTypeError2 = function(name3, value) {
|
|
785
|
+
var received;
|
|
786
|
+
if (value == null) {
|
|
787
|
+
received = " Received " + value;
|
|
788
|
+
} else if (typeof value === "object") {
|
|
789
|
+
received = value.constructor && value.constructor.name ? " Received an instance of " + value.constructor.name : " Received [object Object]";
|
|
790
|
+
} else {
|
|
791
|
+
var inspected = typeof value === "string" ? "'" + value + "'" : String(value);
|
|
792
|
+
received = " Received type " + typeof value + " (" + inspected + ")";
|
|
793
|
+
}
|
|
794
|
+
var error = new TypeError('The "' + name3 + '" argument must be of type number.' + received);
|
|
795
|
+
error.code = "ERR_INVALID_ARG_TYPE";
|
|
796
|
+
return error;
|
|
797
|
+
}, validatePbkdf2Args2 = function(password, salt, iterations, keylen, digest) {
|
|
798
|
+
var pwBuf = normalizeByteSource2(password, "password");
|
|
799
|
+
var saltBuf = normalizeByteSource2(salt, "salt");
|
|
800
|
+
if (typeof iterations !== "number") {
|
|
801
|
+
throw createPbkdf2ArgTypeError2("iterations", iterations);
|
|
802
|
+
}
|
|
803
|
+
if (!Number.isInteger(iterations)) {
|
|
804
|
+
throw createCryptoRangeError2(
|
|
805
|
+
"iterations",
|
|
806
|
+
'The value of "iterations" is out of range. It must be an integer. Received ' + iterations
|
|
807
|
+
);
|
|
808
|
+
}
|
|
809
|
+
if (iterations < 1 || iterations > 2147483647) {
|
|
810
|
+
throw createCryptoRangeError2(
|
|
811
|
+
"iterations",
|
|
812
|
+
'The value of "iterations" is out of range. It must be >= 1 && <= 2147483647. Received ' + iterations
|
|
813
|
+
);
|
|
814
|
+
}
|
|
815
|
+
if (typeof keylen !== "number") {
|
|
816
|
+
throw createPbkdf2ArgTypeError2("keylen", keylen);
|
|
817
|
+
}
|
|
818
|
+
if (!Number.isInteger(keylen)) {
|
|
819
|
+
throw createCryptoRangeError2(
|
|
820
|
+
"keylen",
|
|
821
|
+
'The value of "keylen" is out of range. It must be an integer. Received ' + keylen
|
|
822
|
+
);
|
|
823
|
+
}
|
|
824
|
+
if (keylen < 0 || keylen > 2147483647) {
|
|
825
|
+
throw createCryptoRangeError2(
|
|
826
|
+
"keylen",
|
|
827
|
+
'The value of "keylen" is out of range. It must be >= 0 && <= 2147483647. Received ' + keylen
|
|
828
|
+
);
|
|
829
|
+
}
|
|
830
|
+
if (typeof digest !== "string") {
|
|
831
|
+
throw createInvalidArgTypeError("digest", "of type string", digest);
|
|
832
|
+
}
|
|
833
|
+
return {
|
|
834
|
+
password: pwBuf,
|
|
835
|
+
salt: saltBuf
|
|
836
|
+
};
|
|
837
|
+
};
|
|
838
|
+
var createPbkdf2ArgTypeError = createPbkdf2ArgTypeError2, validatePbkdf2Args = validatePbkdf2Args2;
|
|
474
839
|
result2.pbkdf2Sync = function pbkdf2Sync(password, salt, iterations, keylen, digest) {
|
|
475
|
-
var
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
840
|
+
var normalized = validatePbkdf2Args2(password, salt, iterations, keylen, digest);
|
|
841
|
+
try {
|
|
842
|
+
var resultBase64 = _cryptoPbkdf2.applySync(void 0, [
|
|
843
|
+
normalized.password.toString("base64"),
|
|
844
|
+
normalized.salt.toString("base64"),
|
|
845
|
+
iterations,
|
|
846
|
+
keylen,
|
|
847
|
+
digest
|
|
848
|
+
]);
|
|
849
|
+
return Buffer.from(resultBase64, "base64");
|
|
850
|
+
} catch (error) {
|
|
851
|
+
throw normalizeCryptoBridgeError(error);
|
|
852
|
+
}
|
|
485
853
|
};
|
|
486
854
|
result2.pbkdf2 = function pbkdf2(password, salt, iterations, keylen, digest, callback) {
|
|
855
|
+
if (typeof digest === "function" && callback === void 0) {
|
|
856
|
+
callback = digest;
|
|
857
|
+
digest = void 0;
|
|
858
|
+
}
|
|
859
|
+
if (typeof callback !== "function") {
|
|
860
|
+
throw createInvalidArgTypeError("callback", "of type function", callback);
|
|
861
|
+
}
|
|
487
862
|
try {
|
|
488
863
|
var derived = result2.pbkdf2Sync(password, salt, iterations, keylen, digest);
|
|
489
|
-
callback
|
|
864
|
+
scheduleCryptoCallback(callback, [null, derived]);
|
|
490
865
|
} catch (e) {
|
|
491
|
-
|
|
866
|
+
throw normalizeCryptoBridgeError(e);
|
|
492
867
|
}
|
|
493
868
|
};
|
|
494
869
|
}
|
|
@@ -529,232 +904,929 @@
|
|
|
529
904
|
}
|
|
530
905
|
};
|
|
531
906
|
}
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
907
|
+
if (typeof _cryptoCipheriv !== "undefined") {
|
|
908
|
+
let SandboxCipher2 = function(algorithm, key, iv, options) {
|
|
909
|
+
if (!(this instanceof SandboxCipher2)) {
|
|
910
|
+
return new SandboxCipher2(algorithm, key, iv, options);
|
|
911
|
+
}
|
|
912
|
+
if (typeof algorithm !== "string") {
|
|
913
|
+
throw createInvalidArgTypeError("cipher", "of type string", algorithm);
|
|
914
|
+
}
|
|
915
|
+
_Transform.call(this);
|
|
535
916
|
this._algorithm = algorithm;
|
|
536
|
-
this._key =
|
|
537
|
-
this._iv =
|
|
917
|
+
this._key = normalizeByteSource2(key, "key");
|
|
918
|
+
this._iv = normalizeByteSource2(iv, "iv", { allowNull: true });
|
|
919
|
+
this._options = options || void 0;
|
|
538
920
|
this._authTag = null;
|
|
539
921
|
this._finalized = false;
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
922
|
+
this._sessionCreated = false;
|
|
923
|
+
this._sessionId = void 0;
|
|
924
|
+
this._aad = null;
|
|
925
|
+
this._aadOptions = void 0;
|
|
926
|
+
this._autoPadding = void 0;
|
|
927
|
+
this._chunks = [];
|
|
928
|
+
this._bufferedMode = !_useSessionCipher || !!options;
|
|
929
|
+
if (!this._bufferedMode) {
|
|
930
|
+
this._ensureSession();
|
|
931
|
+
} else if (!options) {
|
|
932
|
+
_cryptoCipheriv.applySync(void 0, [
|
|
933
|
+
this._algorithm,
|
|
544
934
|
this._key.toString("base64"),
|
|
545
|
-
this._iv.toString("base64")
|
|
935
|
+
this._iv === null ? null : this._iv.toString("base64"),
|
|
936
|
+
"",
|
|
937
|
+
serializeCipherBridgeOptions2({ validateOnly: true })
|
|
546
938
|
]);
|
|
547
|
-
} else {
|
|
548
|
-
this._sessionId = -1;
|
|
549
|
-
this._chunks = [];
|
|
550
939
|
}
|
|
551
940
|
};
|
|
552
941
|
var SandboxCipher = SandboxCipher2;
|
|
942
|
+
var _useSessionCipher = typeof _cryptoCipherivCreate !== "undefined";
|
|
943
|
+
_inherits(SandboxCipher2, _Transform);
|
|
944
|
+
SandboxCipher2.prototype._ensureSession = function _ensureSession() {
|
|
945
|
+
if (this._bufferedMode || this._sessionCreated) {
|
|
946
|
+
return;
|
|
947
|
+
}
|
|
948
|
+
this._sessionCreated = true;
|
|
949
|
+
this._sessionId = _cryptoCipherivCreate.applySync(void 0, [
|
|
950
|
+
"cipher",
|
|
951
|
+
this._algorithm,
|
|
952
|
+
this._key.toString("base64"),
|
|
953
|
+
this._iv === null ? null : this._iv.toString("base64"),
|
|
954
|
+
serializeCipherBridgeOptions2(this._getBridgeOptions())
|
|
955
|
+
]);
|
|
956
|
+
};
|
|
957
|
+
SandboxCipher2.prototype._getBridgeOptions = function _getBridgeOptions() {
|
|
958
|
+
var options = {};
|
|
959
|
+
if (this._options && this._options.authTagLength !== void 0) {
|
|
960
|
+
options.authTagLength = this._options.authTagLength;
|
|
961
|
+
}
|
|
962
|
+
if (this._aad) {
|
|
963
|
+
options.aad = this._aad;
|
|
964
|
+
}
|
|
965
|
+
if (this._aadOptions !== void 0) {
|
|
966
|
+
options.aadOptions = this._aadOptions;
|
|
967
|
+
}
|
|
968
|
+
if (this._autoPadding !== void 0) {
|
|
969
|
+
options.autoPadding = this._autoPadding;
|
|
970
|
+
}
|
|
971
|
+
return Object.keys(options).length === 0 ? null : options;
|
|
972
|
+
};
|
|
553
973
|
SandboxCipher2.prototype.update = function update(data, inputEncoding, outputEncoding) {
|
|
974
|
+
if (this._finalized) {
|
|
975
|
+
throw new Error("Attempting to call update() after final()");
|
|
976
|
+
}
|
|
554
977
|
var buf;
|
|
555
978
|
if (typeof data === "string") {
|
|
556
979
|
buf = Buffer.from(data, inputEncoding || "utf8");
|
|
557
980
|
} else {
|
|
558
|
-
buf =
|
|
981
|
+
buf = normalizeByteSource2(data, "data");
|
|
559
982
|
}
|
|
560
|
-
if (this.
|
|
983
|
+
if (!this._bufferedMode) {
|
|
984
|
+
this._ensureSession();
|
|
561
985
|
var resultBase64 = _cryptoCipherivUpdate.applySync(void 0, [this._sessionId, buf.toString("base64")]);
|
|
562
986
|
var resultBuffer = Buffer.from(resultBase64, "base64");
|
|
563
|
-
|
|
564
|
-
return resultBuffer;
|
|
987
|
+
return encodeCryptoResult2(resultBuffer, outputEncoding);
|
|
565
988
|
}
|
|
566
989
|
this._chunks.push(buf);
|
|
567
|
-
|
|
568
|
-
return Buffer.alloc(0);
|
|
990
|
+
return encodeCryptoResult2(Buffer.alloc(0), outputEncoding);
|
|
569
991
|
};
|
|
570
992
|
SandboxCipher2.prototype.final = function final(outputEncoding) {
|
|
571
993
|
if (this._finalized) throw new Error("Attempting to call final() after already finalized");
|
|
572
994
|
this._finalized = true;
|
|
573
|
-
|
|
995
|
+
var parsed;
|
|
996
|
+
if (!this._bufferedMode) {
|
|
997
|
+
this._ensureSession();
|
|
574
998
|
var resultJson = _cryptoCipherivFinal.applySync(void 0, [this._sessionId]);
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
var
|
|
578
|
-
|
|
579
|
-
|
|
999
|
+
parsed = JSON.parse(resultJson);
|
|
1000
|
+
} else {
|
|
1001
|
+
var combined = Buffer.concat(this._chunks);
|
|
1002
|
+
var resultJson2 = _cryptoCipheriv.applySync(void 0, [
|
|
1003
|
+
this._algorithm,
|
|
1004
|
+
this._key.toString("base64"),
|
|
1005
|
+
this._iv === null ? null : this._iv.toString("base64"),
|
|
1006
|
+
combined.toString("base64"),
|
|
1007
|
+
serializeCipherBridgeOptions2(this._getBridgeOptions())
|
|
1008
|
+
]);
|
|
1009
|
+
parsed = JSON.parse(resultJson2);
|
|
580
1010
|
}
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
combined.toString("base64")
|
|
587
|
-
]);
|
|
588
|
-
var parsed2 = JSON.parse(resultJson2);
|
|
589
|
-
if (parsed2.authTag) this._authTag = Buffer.from(parsed2.authTag, "base64");
|
|
590
|
-
var resultBuffer2 = Buffer.from(parsed2.data, "base64");
|
|
591
|
-
if (outputEncoding && outputEncoding !== "buffer") return resultBuffer2.toString(outputEncoding);
|
|
592
|
-
return resultBuffer2;
|
|
1011
|
+
if (parsed.authTag) {
|
|
1012
|
+
this._authTag = Buffer.from(parsed.authTag, "base64");
|
|
1013
|
+
}
|
|
1014
|
+
var resultBuffer = Buffer.from(parsed.data, "base64");
|
|
1015
|
+
return encodeCryptoResult2(resultBuffer, outputEncoding);
|
|
593
1016
|
};
|
|
594
1017
|
SandboxCipher2.prototype.getAuthTag = function getAuthTag() {
|
|
595
1018
|
if (!this._finalized) throw new Error("Cannot call getAuthTag before final()");
|
|
596
|
-
if (!this._authTag) throw new Error("Auth tag is
|
|
1019
|
+
if (!this._authTag) throw new Error("Auth tag is not available");
|
|
597
1020
|
return this._authTag;
|
|
598
1021
|
};
|
|
599
|
-
SandboxCipher2.prototype.setAAD = function setAAD(
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
}
|
|
1022
|
+
SandboxCipher2.prototype.setAAD = function setAAD(aad, options) {
|
|
1023
|
+
this._bufferedMode = true;
|
|
1024
|
+
this._aad = normalizeByteSource2(aad, "buffer");
|
|
1025
|
+
this._aadOptions = options;
|
|
604
1026
|
return this;
|
|
605
1027
|
};
|
|
606
1028
|
SandboxCipher2.prototype.setAutoPadding = function setAutoPadding(autoPadding) {
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
}
|
|
1029
|
+
this._bufferedMode = true;
|
|
1030
|
+
this._autoPadding = autoPadding !== false;
|
|
610
1031
|
return this;
|
|
611
1032
|
};
|
|
612
|
-
|
|
613
|
-
|
|
1033
|
+
SandboxCipher2.prototype._transform = function _transform(chunk, encoding, callback) {
|
|
1034
|
+
try {
|
|
1035
|
+
var output = this.update(chunk, encoding === "buffer" ? void 0 : encoding);
|
|
1036
|
+
if (output.length) {
|
|
1037
|
+
this.push(output);
|
|
1038
|
+
}
|
|
1039
|
+
callback();
|
|
1040
|
+
} catch (error) {
|
|
1041
|
+
callback(normalizeCryptoBridgeError(error));
|
|
1042
|
+
}
|
|
1043
|
+
};
|
|
1044
|
+
SandboxCipher2.prototype._flush = function _flush(callback) {
|
|
1045
|
+
try {
|
|
1046
|
+
var output = this.final();
|
|
1047
|
+
if (output.length) {
|
|
1048
|
+
this.push(output);
|
|
1049
|
+
}
|
|
1050
|
+
callback();
|
|
1051
|
+
} catch (error) {
|
|
1052
|
+
callback(normalizeCryptoBridgeError(error));
|
|
1053
|
+
}
|
|
1054
|
+
};
|
|
1055
|
+
result2.createCipheriv = function createCipheriv(algorithm, key, iv, options) {
|
|
1056
|
+
return new SandboxCipher2(algorithm, key, iv, options);
|
|
614
1057
|
};
|
|
615
1058
|
result2.Cipheriv = SandboxCipher2;
|
|
616
1059
|
}
|
|
617
|
-
if (typeof _cryptoDecipheriv !== "undefined"
|
|
618
|
-
let SandboxDecipher2 = function(algorithm, key, iv) {
|
|
1060
|
+
if (typeof _cryptoDecipheriv !== "undefined") {
|
|
1061
|
+
let SandboxDecipher2 = function(algorithm, key, iv, options) {
|
|
1062
|
+
if (!(this instanceof SandboxDecipher2)) {
|
|
1063
|
+
return new SandboxDecipher2(algorithm, key, iv, options);
|
|
1064
|
+
}
|
|
1065
|
+
if (typeof algorithm !== "string") {
|
|
1066
|
+
throw createInvalidArgTypeError("cipher", "of type string", algorithm);
|
|
1067
|
+
}
|
|
1068
|
+
_Transform.call(this);
|
|
619
1069
|
this._algorithm = algorithm;
|
|
620
|
-
this._key =
|
|
621
|
-
this._iv =
|
|
1070
|
+
this._key = normalizeByteSource2(key, "key");
|
|
1071
|
+
this._iv = normalizeByteSource2(iv, "iv", { allowNull: true });
|
|
1072
|
+
this._options = options || void 0;
|
|
622
1073
|
this._authTag = null;
|
|
623
1074
|
this._finalized = false;
|
|
624
|
-
|
|
1075
|
+
this._sessionCreated = false;
|
|
1076
|
+
this._aad = null;
|
|
1077
|
+
this._aadOptions = void 0;
|
|
1078
|
+
this._autoPadding = void 0;
|
|
1079
|
+
this._chunks = [];
|
|
1080
|
+
this._bufferedMode = !_useSessionCipher || !!options;
|
|
1081
|
+
if (!this._bufferedMode) {
|
|
1082
|
+
this._ensureSession();
|
|
1083
|
+
} else if (!options) {
|
|
1084
|
+
_cryptoDecipheriv.applySync(void 0, [
|
|
1085
|
+
this._algorithm,
|
|
1086
|
+
this._key.toString("base64"),
|
|
1087
|
+
this._iv === null ? null : this._iv.toString("base64"),
|
|
1088
|
+
"",
|
|
1089
|
+
serializeCipherBridgeOptions2({ validateOnly: true })
|
|
1090
|
+
]);
|
|
1091
|
+
}
|
|
1092
|
+
};
|
|
1093
|
+
var SandboxDecipher = SandboxDecipher2;
|
|
1094
|
+
_inherits(SandboxDecipher2, _Transform);
|
|
1095
|
+
SandboxDecipher2.prototype._ensureSession = function _ensureSession() {
|
|
1096
|
+
if (!this._bufferedMode && !this._sessionCreated) {
|
|
1097
|
+
this._sessionCreated = true;
|
|
625
1098
|
this._sessionId = _cryptoCipherivCreate.applySync(void 0, [
|
|
626
1099
|
"decipher",
|
|
627
|
-
|
|
1100
|
+
this._algorithm,
|
|
628
1101
|
this._key.toString("base64"),
|
|
629
|
-
this._iv.toString("base64")
|
|
1102
|
+
this._iv === null ? null : this._iv.toString("base64"),
|
|
1103
|
+
serializeCipherBridgeOptions2(this._getBridgeOptions())
|
|
630
1104
|
]);
|
|
631
|
-
} else {
|
|
632
|
-
this._sessionId = -1;
|
|
633
|
-
this._chunks = [];
|
|
634
1105
|
}
|
|
635
1106
|
};
|
|
636
|
-
|
|
1107
|
+
SandboxDecipher2.prototype._getBridgeOptions = function _getBridgeOptions() {
|
|
1108
|
+
var options = {};
|
|
1109
|
+
if (this._options && this._options.authTagLength !== void 0) {
|
|
1110
|
+
options.authTagLength = this._options.authTagLength;
|
|
1111
|
+
}
|
|
1112
|
+
if (this._authTag) {
|
|
1113
|
+
options.authTag = this._authTag;
|
|
1114
|
+
}
|
|
1115
|
+
if (this._aad) {
|
|
1116
|
+
options.aad = this._aad;
|
|
1117
|
+
}
|
|
1118
|
+
if (this._aadOptions !== void 0) {
|
|
1119
|
+
options.aadOptions = this._aadOptions;
|
|
1120
|
+
}
|
|
1121
|
+
if (this._autoPadding !== void 0) {
|
|
1122
|
+
options.autoPadding = this._autoPadding;
|
|
1123
|
+
}
|
|
1124
|
+
return Object.keys(options).length === 0 ? null : options;
|
|
1125
|
+
};
|
|
637
1126
|
SandboxDecipher2.prototype.update = function update(data, inputEncoding, outputEncoding) {
|
|
1127
|
+
if (this._finalized) {
|
|
1128
|
+
throw new Error("Attempting to call update() after final()");
|
|
1129
|
+
}
|
|
638
1130
|
var buf;
|
|
639
1131
|
if (typeof data === "string") {
|
|
640
1132
|
buf = Buffer.from(data, inputEncoding || "utf8");
|
|
641
1133
|
} else {
|
|
642
|
-
buf =
|
|
1134
|
+
buf = normalizeByteSource2(data, "data");
|
|
1135
|
+
}
|
|
1136
|
+
if (!this._bufferedMode) {
|
|
1137
|
+
this._ensureSession();
|
|
1138
|
+
var resultBase64 = _cryptoCipherivUpdate.applySync(void 0, [this._sessionId, buf.toString("base64")]);
|
|
1139
|
+
var resultBuffer = Buffer.from(resultBase64, "base64");
|
|
1140
|
+
return encodeCryptoResult2(resultBuffer, outputEncoding);
|
|
1141
|
+
}
|
|
1142
|
+
this._chunks.push(buf);
|
|
1143
|
+
return encodeCryptoResult2(Buffer.alloc(0), outputEncoding);
|
|
1144
|
+
};
|
|
1145
|
+
SandboxDecipher2.prototype.final = function final(outputEncoding) {
|
|
1146
|
+
if (this._finalized) throw new Error("Attempting to call final() after already finalized");
|
|
1147
|
+
this._finalized = true;
|
|
1148
|
+
var resultBuffer;
|
|
1149
|
+
if (!this._bufferedMode) {
|
|
1150
|
+
this._ensureSession();
|
|
1151
|
+
var resultJson = _cryptoCipherivFinal.applySync(void 0, [this._sessionId]);
|
|
1152
|
+
var parsed = JSON.parse(resultJson);
|
|
1153
|
+
resultBuffer = Buffer.from(parsed.data, "base64");
|
|
1154
|
+
} else {
|
|
1155
|
+
var combined = Buffer.concat(this._chunks);
|
|
1156
|
+
var options = {};
|
|
1157
|
+
var resultBase64 = _cryptoDecipheriv.applySync(void 0, [
|
|
1158
|
+
this._algorithm,
|
|
1159
|
+
this._key.toString("base64"),
|
|
1160
|
+
this._iv === null ? null : this._iv.toString("base64"),
|
|
1161
|
+
combined.toString("base64"),
|
|
1162
|
+
serializeCipherBridgeOptions2(this._getBridgeOptions())
|
|
1163
|
+
]);
|
|
1164
|
+
resultBuffer = Buffer.from(resultBase64, "base64");
|
|
1165
|
+
}
|
|
1166
|
+
return encodeCryptoResult2(resultBuffer, outputEncoding);
|
|
1167
|
+
};
|
|
1168
|
+
SandboxDecipher2.prototype.setAuthTag = function setAuthTag(tag) {
|
|
1169
|
+
this._bufferedMode = true;
|
|
1170
|
+
this._authTag = typeof tag === "string" ? Buffer.from(tag, "base64") : normalizeByteSource2(tag, "buffer");
|
|
1171
|
+
return this;
|
|
1172
|
+
};
|
|
1173
|
+
SandboxDecipher2.prototype.setAAD = function setAAD(aad, options) {
|
|
1174
|
+
this._bufferedMode = true;
|
|
1175
|
+
this._aad = normalizeByteSource2(aad, "buffer");
|
|
1176
|
+
this._aadOptions = options;
|
|
1177
|
+
return this;
|
|
1178
|
+
};
|
|
1179
|
+
SandboxDecipher2.prototype.setAutoPadding = function setAutoPadding(autoPadding) {
|
|
1180
|
+
this._bufferedMode = true;
|
|
1181
|
+
this._autoPadding = autoPadding !== false;
|
|
1182
|
+
return this;
|
|
1183
|
+
};
|
|
1184
|
+
SandboxDecipher2.prototype._transform = function _transform(chunk, encoding, callback) {
|
|
1185
|
+
try {
|
|
1186
|
+
var output = this.update(chunk, encoding === "buffer" ? void 0 : encoding);
|
|
1187
|
+
if (output.length) {
|
|
1188
|
+
this.push(output);
|
|
1189
|
+
}
|
|
1190
|
+
callback();
|
|
1191
|
+
} catch (error) {
|
|
1192
|
+
callback(normalizeCryptoBridgeError(error));
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
SandboxDecipher2.prototype._flush = function _flush(callback) {
|
|
1196
|
+
try {
|
|
1197
|
+
var output = this.final();
|
|
1198
|
+
if (output.length) {
|
|
1199
|
+
this.push(output);
|
|
1200
|
+
}
|
|
1201
|
+
callback();
|
|
1202
|
+
} catch (error) {
|
|
1203
|
+
callback(normalizeCryptoBridgeError(error));
|
|
1204
|
+
}
|
|
1205
|
+
};
|
|
1206
|
+
result2.createDecipheriv = function createDecipheriv(algorithm, key, iv, options) {
|
|
1207
|
+
return new SandboxDecipher2(algorithm, key, iv, options);
|
|
1208
|
+
};
|
|
1209
|
+
result2.Decipheriv = SandboxDecipher2;
|
|
1210
|
+
}
|
|
1211
|
+
if (typeof _cryptoSign !== "undefined") {
|
|
1212
|
+
result2.sign = function sign(algorithm, data, key) {
|
|
1213
|
+
var dataBuf = typeof data === "string" ? Buffer.from(data, "utf8") : Buffer.from(data);
|
|
1214
|
+
var sigBase64;
|
|
1215
|
+
try {
|
|
1216
|
+
sigBase64 = _cryptoSign.applySync(void 0, [
|
|
1217
|
+
algorithm === void 0 ? null : algorithm,
|
|
1218
|
+
dataBuf.toString("base64"),
|
|
1219
|
+
JSON.stringify(serializeBridgeValue(key))
|
|
1220
|
+
]);
|
|
1221
|
+
} catch (error) {
|
|
1222
|
+
throw normalizeCryptoBridgeError(error);
|
|
1223
|
+
}
|
|
1224
|
+
return Buffer.from(sigBase64, "base64");
|
|
1225
|
+
};
|
|
1226
|
+
}
|
|
1227
|
+
if (typeof _cryptoVerify !== "undefined") {
|
|
1228
|
+
result2.verify = function verify(algorithm, data, key, signature) {
|
|
1229
|
+
var dataBuf = typeof data === "string" ? Buffer.from(data, "utf8") : Buffer.from(data);
|
|
1230
|
+
var sigBuf = typeof signature === "string" ? Buffer.from(signature, "base64") : Buffer.from(signature);
|
|
1231
|
+
try {
|
|
1232
|
+
return _cryptoVerify.applySync(void 0, [
|
|
1233
|
+
algorithm === void 0 ? null : algorithm,
|
|
1234
|
+
dataBuf.toString("base64"),
|
|
1235
|
+
JSON.stringify(serializeBridgeValue(key)),
|
|
1236
|
+
sigBuf.toString("base64")
|
|
1237
|
+
]);
|
|
1238
|
+
} catch (error) {
|
|
1239
|
+
throw normalizeCryptoBridgeError(error);
|
|
1240
|
+
}
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
if (typeof _cryptoAsymmetricOp !== "undefined") {
|
|
1244
|
+
let asymmetricBridgeCall2 = function(operation, key, data) {
|
|
1245
|
+
var dataBuf = toRawBuffer(data);
|
|
1246
|
+
var resultBase64;
|
|
1247
|
+
try {
|
|
1248
|
+
resultBase64 = _cryptoAsymmetricOp.applySync(void 0, [
|
|
1249
|
+
operation,
|
|
1250
|
+
JSON.stringify(serializeBridgeValue(key)),
|
|
1251
|
+
dataBuf.toString("base64")
|
|
1252
|
+
]);
|
|
1253
|
+
} catch (error) {
|
|
1254
|
+
throw normalizeCryptoBridgeError(error);
|
|
1255
|
+
}
|
|
1256
|
+
return Buffer.from(resultBase64, "base64");
|
|
1257
|
+
};
|
|
1258
|
+
var asymmetricBridgeCall = asymmetricBridgeCall2;
|
|
1259
|
+
result2.publicEncrypt = function publicEncrypt(key, data) {
|
|
1260
|
+
return asymmetricBridgeCall2("publicEncrypt", key, data);
|
|
1261
|
+
};
|
|
1262
|
+
result2.privateDecrypt = function privateDecrypt(key, data) {
|
|
1263
|
+
return asymmetricBridgeCall2("privateDecrypt", key, data);
|
|
1264
|
+
};
|
|
1265
|
+
result2.privateEncrypt = function privateEncrypt(key, data) {
|
|
1266
|
+
return asymmetricBridgeCall2("privateEncrypt", key, data);
|
|
1267
|
+
};
|
|
1268
|
+
result2.publicDecrypt = function publicDecrypt(key, data) {
|
|
1269
|
+
return asymmetricBridgeCall2("publicDecrypt", key, data);
|
|
1270
|
+
};
|
|
1271
|
+
}
|
|
1272
|
+
if (typeof _cryptoDiffieHellmanSessionCreate !== "undefined" && typeof _cryptoDiffieHellmanSessionCall !== "undefined") {
|
|
1273
|
+
let serializeDhKeyObject2 = function(value) {
|
|
1274
|
+
if (value.type === "secret") {
|
|
1275
|
+
return {
|
|
1276
|
+
type: "secret",
|
|
1277
|
+
raw: Buffer.from(value.export()).toString("base64")
|
|
1278
|
+
};
|
|
1279
|
+
}
|
|
1280
|
+
return {
|
|
1281
|
+
type: value.type,
|
|
1282
|
+
pem: value._pem || value.export({
|
|
1283
|
+
type: value.type === "private" ? "pkcs8" : "spki",
|
|
1284
|
+
format: "pem"
|
|
1285
|
+
})
|
|
1286
|
+
};
|
|
1287
|
+
}, serializeDhValue2 = function(value) {
|
|
1288
|
+
if (value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
1289
|
+
return value;
|
|
1290
|
+
}
|
|
1291
|
+
if (Buffer.isBuffer(value)) {
|
|
1292
|
+
return {
|
|
1293
|
+
__type: "buffer",
|
|
1294
|
+
value: Buffer.from(value).toString("base64")
|
|
1295
|
+
};
|
|
1296
|
+
}
|
|
1297
|
+
if (value instanceof ArrayBuffer) {
|
|
1298
|
+
return {
|
|
1299
|
+
__type: "buffer",
|
|
1300
|
+
value: Buffer.from(new Uint8Array(value)).toString("base64")
|
|
1301
|
+
};
|
|
1302
|
+
}
|
|
1303
|
+
if (ArrayBuffer.isView(value)) {
|
|
1304
|
+
return {
|
|
1305
|
+
__type: "buffer",
|
|
1306
|
+
value: Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString("base64")
|
|
1307
|
+
};
|
|
1308
|
+
}
|
|
1309
|
+
if (typeof value === "bigint") {
|
|
1310
|
+
return {
|
|
1311
|
+
__type: "bigint",
|
|
1312
|
+
value: value.toString()
|
|
1313
|
+
};
|
|
1314
|
+
}
|
|
1315
|
+
if (value && typeof value === "object" && (value.type === "public" || value.type === "private" || value.type === "secret") && typeof value.export === "function") {
|
|
1316
|
+
return {
|
|
1317
|
+
__type: "keyObject",
|
|
1318
|
+
value: serializeDhKeyObject2(value)
|
|
1319
|
+
};
|
|
1320
|
+
}
|
|
1321
|
+
if (Array.isArray(value)) {
|
|
1322
|
+
return value.map(serializeDhValue2);
|
|
1323
|
+
}
|
|
1324
|
+
if (value && typeof value === "object") {
|
|
1325
|
+
var output = {};
|
|
1326
|
+
var keys = Object.keys(value);
|
|
1327
|
+
for (var i = 0; i < keys.length; i++) {
|
|
1328
|
+
if (value[keys[i]] !== void 0) {
|
|
1329
|
+
output[keys[i]] = serializeDhValue2(value[keys[i]]);
|
|
1330
|
+
}
|
|
1331
|
+
}
|
|
1332
|
+
return output;
|
|
1333
|
+
}
|
|
1334
|
+
return String(value);
|
|
1335
|
+
}, restoreDhValue2 = function(value) {
|
|
1336
|
+
if (!value || typeof value !== "object") {
|
|
1337
|
+
return value;
|
|
1338
|
+
}
|
|
1339
|
+
if (value.__type === "buffer") {
|
|
1340
|
+
return Buffer.from(value.value, "base64");
|
|
1341
|
+
}
|
|
1342
|
+
if (value.__type === "bigint") {
|
|
1343
|
+
return BigInt(value.value);
|
|
1344
|
+
}
|
|
1345
|
+
if (Array.isArray(value)) {
|
|
1346
|
+
return value.map(restoreDhValue2);
|
|
1347
|
+
}
|
|
1348
|
+
var output = {};
|
|
1349
|
+
var keys = Object.keys(value);
|
|
1350
|
+
for (var i = 0; i < keys.length; i++) {
|
|
1351
|
+
output[keys[i]] = restoreDhValue2(value[keys[i]]);
|
|
1352
|
+
}
|
|
1353
|
+
return output;
|
|
1354
|
+
}, createDhSession2 = function(type, name3, argsLike) {
|
|
1355
|
+
var args = [];
|
|
1356
|
+
for (var i = 0; i < argsLike.length; i++) {
|
|
1357
|
+
args.push(serializeDhValue2(argsLike[i]));
|
|
1358
|
+
}
|
|
1359
|
+
return _cryptoDiffieHellmanSessionCreate.applySync(void 0, [
|
|
1360
|
+
JSON.stringify({
|
|
1361
|
+
type,
|
|
1362
|
+
name: name3,
|
|
1363
|
+
args
|
|
1364
|
+
})
|
|
1365
|
+
]);
|
|
1366
|
+
}, callDhSession2 = function(sessionId, method, argsLike) {
|
|
1367
|
+
var args = [];
|
|
1368
|
+
for (var i = 0; i < argsLike.length; i++) {
|
|
1369
|
+
args.push(serializeDhValue2(argsLike[i]));
|
|
1370
|
+
}
|
|
1371
|
+
var response = JSON.parse(_cryptoDiffieHellmanSessionCall.applySync(void 0, [
|
|
1372
|
+
sessionId,
|
|
1373
|
+
JSON.stringify({
|
|
1374
|
+
method,
|
|
1375
|
+
args
|
|
1376
|
+
})
|
|
1377
|
+
]));
|
|
1378
|
+
if (response && response.hasResult === false) {
|
|
1379
|
+
return void 0;
|
|
1380
|
+
}
|
|
1381
|
+
return restoreDhValue2(response && response.result);
|
|
1382
|
+
}, SandboxDiffieHellman2 = function(sessionId) {
|
|
1383
|
+
this._sessionId = sessionId;
|
|
1384
|
+
}, SandboxECDH2 = function(sessionId) {
|
|
1385
|
+
SandboxDiffieHellman2.call(this, sessionId);
|
|
1386
|
+
};
|
|
1387
|
+
var serializeDhKeyObject = serializeDhKeyObject2, serializeDhValue = serializeDhValue2, restoreDhValue = restoreDhValue2, createDhSession = createDhSession2, callDhSession = callDhSession2, SandboxDiffieHellman = SandboxDiffieHellman2, SandboxECDH = SandboxECDH2;
|
|
1388
|
+
Object.defineProperty(SandboxDiffieHellman2.prototype, "verifyError", {
|
|
1389
|
+
get: function getVerifyError() {
|
|
1390
|
+
return callDhSession2(this._sessionId, "verifyError", []);
|
|
1391
|
+
}
|
|
1392
|
+
});
|
|
1393
|
+
SandboxDiffieHellman2.prototype.generateKeys = function generateKeys(encoding) {
|
|
1394
|
+
if (arguments.length === 0) return callDhSession2(this._sessionId, "generateKeys", []);
|
|
1395
|
+
return callDhSession2(this._sessionId, "generateKeys", [encoding]);
|
|
1396
|
+
};
|
|
1397
|
+
SandboxDiffieHellman2.prototype.computeSecret = function computeSecret(key, inputEncoding, outputEncoding) {
|
|
1398
|
+
return callDhSession2(this._sessionId, "computeSecret", Array.prototype.slice.call(arguments));
|
|
1399
|
+
};
|
|
1400
|
+
SandboxDiffieHellman2.prototype.getPrime = function getPrime(encoding) {
|
|
1401
|
+
if (arguments.length === 0) return callDhSession2(this._sessionId, "getPrime", []);
|
|
1402
|
+
return callDhSession2(this._sessionId, "getPrime", [encoding]);
|
|
1403
|
+
};
|
|
1404
|
+
SandboxDiffieHellman2.prototype.getGenerator = function getGenerator(encoding) {
|
|
1405
|
+
if (arguments.length === 0) return callDhSession2(this._sessionId, "getGenerator", []);
|
|
1406
|
+
return callDhSession2(this._sessionId, "getGenerator", [encoding]);
|
|
1407
|
+
};
|
|
1408
|
+
SandboxDiffieHellman2.prototype.getPublicKey = function getPublicKey(encoding) {
|
|
1409
|
+
if (arguments.length === 0) return callDhSession2(this._sessionId, "getPublicKey", []);
|
|
1410
|
+
return callDhSession2(this._sessionId, "getPublicKey", [encoding]);
|
|
1411
|
+
};
|
|
1412
|
+
SandboxDiffieHellman2.prototype.getPrivateKey = function getPrivateKey(encoding) {
|
|
1413
|
+
if (arguments.length === 0) return callDhSession2(this._sessionId, "getPrivateKey", []);
|
|
1414
|
+
return callDhSession2(this._sessionId, "getPrivateKey", [encoding]);
|
|
1415
|
+
};
|
|
1416
|
+
SandboxDiffieHellman2.prototype.setPublicKey = function setPublicKey(key, encoding) {
|
|
1417
|
+
return callDhSession2(this._sessionId, "setPublicKey", Array.prototype.slice.call(arguments));
|
|
1418
|
+
};
|
|
1419
|
+
SandboxDiffieHellman2.prototype.setPrivateKey = function setPrivateKey(key, encoding) {
|
|
1420
|
+
return callDhSession2(this._sessionId, "setPrivateKey", Array.prototype.slice.call(arguments));
|
|
1421
|
+
};
|
|
1422
|
+
SandboxECDH2.prototype = Object.create(SandboxDiffieHellman2.prototype);
|
|
1423
|
+
SandboxECDH2.prototype.constructor = SandboxECDH2;
|
|
1424
|
+
SandboxECDH2.prototype.getPublicKey = function getPublicKey(encoding, format) {
|
|
1425
|
+
return callDhSession2(this._sessionId, "getPublicKey", Array.prototype.slice.call(arguments));
|
|
1426
|
+
};
|
|
1427
|
+
result2.createDiffieHellman = function createDiffieHellman() {
|
|
1428
|
+
return new SandboxDiffieHellman2(createDhSession2("dh", void 0, arguments));
|
|
1429
|
+
};
|
|
1430
|
+
result2.getDiffieHellman = function getDiffieHellman(name3) {
|
|
1431
|
+
return new SandboxDiffieHellman2(createDhSession2("group", name3, []));
|
|
1432
|
+
};
|
|
1433
|
+
result2.createDiffieHellmanGroup = result2.getDiffieHellman;
|
|
1434
|
+
result2.createECDH = function createECDH(curve) {
|
|
1435
|
+
return new SandboxECDH2(createDhSession2("ecdh", curve, []));
|
|
1436
|
+
};
|
|
1437
|
+
if (typeof _cryptoDiffieHellman !== "undefined") {
|
|
1438
|
+
result2.diffieHellman = function diffieHellman(options) {
|
|
1439
|
+
var resultJson = _cryptoDiffieHellman.applySync(void 0, [
|
|
1440
|
+
JSON.stringify(serializeDhValue2(options))
|
|
1441
|
+
]);
|
|
1442
|
+
return restoreDhValue2(JSON.parse(resultJson));
|
|
1443
|
+
};
|
|
1444
|
+
}
|
|
1445
|
+
result2.DiffieHellman = SandboxDiffieHellman2;
|
|
1446
|
+
result2.DiffieHellmanGroup = SandboxDiffieHellman2;
|
|
1447
|
+
result2.ECDH = SandboxECDH2;
|
|
1448
|
+
}
|
|
1449
|
+
if (typeof _cryptoGenerateKeyPairSync !== "undefined") {
|
|
1450
|
+
let restoreBridgeValue2 = function(value) {
|
|
1451
|
+
if (!value || typeof value !== "object") {
|
|
1452
|
+
return value;
|
|
1453
|
+
}
|
|
1454
|
+
if (value.__type === "buffer") {
|
|
1455
|
+
return Buffer.from(value.value, "base64");
|
|
1456
|
+
}
|
|
1457
|
+
if (value.__type === "bigint") {
|
|
1458
|
+
return BigInt(value.value);
|
|
1459
|
+
}
|
|
1460
|
+
if (Array.isArray(value)) {
|
|
1461
|
+
return value.map(restoreBridgeValue2);
|
|
1462
|
+
}
|
|
1463
|
+
var output = {};
|
|
1464
|
+
var keys = Object.keys(value);
|
|
1465
|
+
for (var i = 0; i < keys.length; i++) {
|
|
1466
|
+
output[keys[i]] = restoreBridgeValue2(value[keys[i]]);
|
|
1467
|
+
}
|
|
1468
|
+
return output;
|
|
1469
|
+
}, cloneObject2 = function(value) {
|
|
1470
|
+
if (!value || typeof value !== "object") {
|
|
1471
|
+
return value;
|
|
1472
|
+
}
|
|
1473
|
+
if (Array.isArray(value)) {
|
|
1474
|
+
return value.map(cloneObject2);
|
|
1475
|
+
}
|
|
1476
|
+
var output = {};
|
|
1477
|
+
var keys = Object.keys(value);
|
|
1478
|
+
for (var i = 0; i < keys.length; i++) {
|
|
1479
|
+
output[keys[i]] = cloneObject2(value[keys[i]]);
|
|
1480
|
+
}
|
|
1481
|
+
return output;
|
|
1482
|
+
}, createDomException2 = function(message, name3) {
|
|
1483
|
+
if (typeof DOMException === "function") {
|
|
1484
|
+
return new DOMException(message, name3);
|
|
1485
|
+
}
|
|
1486
|
+
var error = new Error(message);
|
|
1487
|
+
error.name = name3;
|
|
1488
|
+
return error;
|
|
1489
|
+
}, toRawBuffer2 = function(data, encoding) {
|
|
1490
|
+
if (Buffer.isBuffer(data)) {
|
|
1491
|
+
return Buffer.from(data);
|
|
1492
|
+
}
|
|
1493
|
+
if (data instanceof ArrayBuffer) {
|
|
1494
|
+
return Buffer.from(new Uint8Array(data));
|
|
1495
|
+
}
|
|
1496
|
+
if (ArrayBuffer.isView(data)) {
|
|
1497
|
+
return Buffer.from(data.buffer, data.byteOffset, data.byteLength);
|
|
1498
|
+
}
|
|
1499
|
+
if (typeof data === "string") {
|
|
1500
|
+
return Buffer.from(data, encoding || "utf8");
|
|
1501
|
+
}
|
|
1502
|
+
return Buffer.from(data);
|
|
1503
|
+
}, serializeBridgeValue2 = function(value) {
|
|
1504
|
+
if (value === null) {
|
|
1505
|
+
return null;
|
|
1506
|
+
}
|
|
1507
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
1508
|
+
return value;
|
|
1509
|
+
}
|
|
1510
|
+
if (typeof value === "bigint") {
|
|
1511
|
+
return {
|
|
1512
|
+
__type: "bigint",
|
|
1513
|
+
value: value.toString()
|
|
1514
|
+
};
|
|
1515
|
+
}
|
|
1516
|
+
if (Buffer.isBuffer(value)) {
|
|
1517
|
+
return {
|
|
1518
|
+
__type: "buffer",
|
|
1519
|
+
value: Buffer.from(value).toString("base64")
|
|
1520
|
+
};
|
|
1521
|
+
}
|
|
1522
|
+
if (value instanceof ArrayBuffer) {
|
|
1523
|
+
return {
|
|
1524
|
+
__type: "buffer",
|
|
1525
|
+
value: Buffer.from(new Uint8Array(value)).toString("base64")
|
|
1526
|
+
};
|
|
1527
|
+
}
|
|
1528
|
+
if (ArrayBuffer.isView(value)) {
|
|
1529
|
+
return {
|
|
1530
|
+
__type: "buffer",
|
|
1531
|
+
value: Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString("base64")
|
|
1532
|
+
};
|
|
1533
|
+
}
|
|
1534
|
+
if (Array.isArray(value)) {
|
|
1535
|
+
return value.map(serializeBridgeValue2);
|
|
1536
|
+
}
|
|
1537
|
+
if (value && typeof value === "object" && (value.type === "public" || value.type === "private" || value.type === "secret") && typeof value.export === "function") {
|
|
1538
|
+
if (value.type === "secret") {
|
|
1539
|
+
return {
|
|
1540
|
+
__type: "keyObject",
|
|
1541
|
+
value: {
|
|
1542
|
+
type: "secret",
|
|
1543
|
+
raw: Buffer.from(value.export()).toString("base64")
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1547
|
+
return {
|
|
1548
|
+
__type: "keyObject",
|
|
1549
|
+
value: {
|
|
1550
|
+
type: value.type,
|
|
1551
|
+
pem: value._pem
|
|
1552
|
+
}
|
|
1553
|
+
};
|
|
1554
|
+
}
|
|
1555
|
+
if (value && typeof value === "object") {
|
|
1556
|
+
var output = {};
|
|
1557
|
+
var keys = Object.keys(value);
|
|
1558
|
+
for (var i = 0; i < keys.length; i++) {
|
|
1559
|
+
var entry = value[keys[i]];
|
|
1560
|
+
if (entry !== void 0) {
|
|
1561
|
+
output[keys[i]] = serializeBridgeValue2(entry);
|
|
1562
|
+
}
|
|
1563
|
+
}
|
|
1564
|
+
return output;
|
|
1565
|
+
}
|
|
1566
|
+
return String(value);
|
|
1567
|
+
}, normalizeCryptoBridgeError2 = function(error) {
|
|
1568
|
+
if (!error || typeof error !== "object") {
|
|
1569
|
+
return error;
|
|
1570
|
+
}
|
|
1571
|
+
if (error.code === void 0 && error.message === "error:07880109:common libcrypto routines::interrupted or cancelled") {
|
|
1572
|
+
error.code = "ERR_OSSL_CRYPTO_INTERRUPTED_OR_CANCELLED";
|
|
1573
|
+
}
|
|
1574
|
+
return error;
|
|
1575
|
+
}, deserializeGeneratedKeyValue2 = function(value) {
|
|
1576
|
+
if (!value || typeof value !== "object") {
|
|
1577
|
+
return value;
|
|
1578
|
+
}
|
|
1579
|
+
if (value.kind === "string") {
|
|
1580
|
+
return value.value;
|
|
1581
|
+
}
|
|
1582
|
+
if (value.kind === "buffer") {
|
|
1583
|
+
return Buffer.from(value.value, "base64");
|
|
1584
|
+
}
|
|
1585
|
+
if (value.kind === "keyObject") {
|
|
1586
|
+
return createGeneratedKeyObject2(value.value);
|
|
1587
|
+
}
|
|
1588
|
+
if (value.kind === "object") {
|
|
1589
|
+
return value.value;
|
|
1590
|
+
}
|
|
1591
|
+
return value;
|
|
1592
|
+
}, serializeBridgeOptions2 = function(options) {
|
|
1593
|
+
return JSON.stringify({
|
|
1594
|
+
hasOptions: options !== void 0,
|
|
1595
|
+
options: options === void 0 ? null : serializeBridgeValue2(options)
|
|
1596
|
+
});
|
|
1597
|
+
}, createInvalidArgTypeError2 = function(name3, expected, value) {
|
|
1598
|
+
var received;
|
|
1599
|
+
if (value == null) {
|
|
1600
|
+
received = " Received " + value;
|
|
1601
|
+
} else if (typeof value === "function") {
|
|
1602
|
+
received = " Received function " + (value.name || "anonymous");
|
|
1603
|
+
} else if (typeof value === "object") {
|
|
1604
|
+
if (value.constructor && value.constructor.name) {
|
|
1605
|
+
received = " Received an instance of " + value.constructor.name;
|
|
1606
|
+
} else {
|
|
1607
|
+
received = " Received [object Object]";
|
|
1608
|
+
}
|
|
1609
|
+
} else {
|
|
1610
|
+
var inspected = typeof value === "string" ? "'" + value + "'" : String(value);
|
|
1611
|
+
if (inspected.length > 28) {
|
|
1612
|
+
inspected = inspected.slice(0, 25) + "...";
|
|
1613
|
+
}
|
|
1614
|
+
received = " Received type " + typeof value + " (" + inspected + ")";
|
|
643
1615
|
}
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
1616
|
+
var error = new TypeError('The "' + name3 + '" argument must be ' + expected + "." + received);
|
|
1617
|
+
error.code = "ERR_INVALID_ARG_TYPE";
|
|
1618
|
+
return error;
|
|
1619
|
+
}, scheduleCryptoCallback2 = function(callback, args) {
|
|
1620
|
+
setTimeout(function() {
|
|
1621
|
+
callback.apply(void 0, args);
|
|
1622
|
+
}, 0);
|
|
1623
|
+
}, shouldThrowCryptoValidationError2 = function(error) {
|
|
1624
|
+
if (!error || typeof error !== "object") {
|
|
1625
|
+
return false;
|
|
649
1626
|
}
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
1627
|
+
if (error.name === "TypeError" || error.name === "RangeError") {
|
|
1628
|
+
return true;
|
|
1629
|
+
}
|
|
1630
|
+
var code = error.code;
|
|
1631
|
+
return code === "ERR_MISSING_OPTION" || code === "ERR_CRYPTO_UNKNOWN_DH_GROUP" || code === "ERR_OUT_OF_RANGE" || typeof code === "string" && code.indexOf("ERR_INVALID_ARG_") === 0;
|
|
1632
|
+
}, ensureCryptoCallback2 = function(callback, syncValidator) {
|
|
1633
|
+
if (typeof callback === "function") {
|
|
1634
|
+
return callback;
|
|
1635
|
+
}
|
|
1636
|
+
if (typeof syncValidator === "function") {
|
|
1637
|
+
syncValidator();
|
|
1638
|
+
}
|
|
1639
|
+
throw createInvalidArgTypeError2("callback", "of type function", callback);
|
|
1640
|
+
}, SandboxKeyObject2 = function(type, handle) {
|
|
1641
|
+
this.type = type;
|
|
1642
|
+
this._pem = handle && handle.pem !== void 0 ? handle.pem : void 0;
|
|
1643
|
+
this._raw = handle && handle.raw !== void 0 ? handle.raw : void 0;
|
|
1644
|
+
this._jwk = handle && handle.jwk !== void 0 ? cloneObject2(handle.jwk) : void 0;
|
|
1645
|
+
this.asymmetricKeyType = handle && handle.asymmetricKeyType !== void 0 ? handle.asymmetricKeyType : void 0;
|
|
1646
|
+
this.asymmetricKeyDetails = handle && handle.asymmetricKeyDetails !== void 0 ? restoreBridgeValue2(handle.asymmetricKeyDetails) : void 0;
|
|
1647
|
+
this.symmetricKeySize = type === "secret" && handle && handle.raw !== void 0 ? Buffer.from(handle.raw, "base64").byteLength : void 0;
|
|
1648
|
+
}, normalizeNamedCurve2 = function(namedCurve) {
|
|
1649
|
+
if (!namedCurve) {
|
|
1650
|
+
return namedCurve;
|
|
1651
|
+
}
|
|
1652
|
+
var upper = String(namedCurve).toUpperCase();
|
|
1653
|
+
if (upper === "PRIME256V1" || upper === "SECP256R1") return "P-256";
|
|
1654
|
+
if (upper === "SECP384R1") return "P-384";
|
|
1655
|
+
if (upper === "SECP521R1") return "P-521";
|
|
1656
|
+
return namedCurve;
|
|
1657
|
+
}, normalizeAlgorithmInput2 = function(algorithm) {
|
|
1658
|
+
if (typeof algorithm === "string") {
|
|
1659
|
+
return { name: algorithm };
|
|
1660
|
+
}
|
|
1661
|
+
return Object.assign({}, algorithm);
|
|
1662
|
+
}, createCompatibleCryptoKey2 = function(keyData) {
|
|
1663
|
+
var key;
|
|
1664
|
+
if (globalThis.CryptoKey && globalThis.CryptoKey.prototype && globalThis.CryptoKey.prototype !== SandboxCryptoKey.prototype) {
|
|
1665
|
+
key = Object.create(globalThis.CryptoKey.prototype);
|
|
1666
|
+
key.type = keyData.type;
|
|
1667
|
+
key.extractable = keyData.extractable;
|
|
1668
|
+
key.algorithm = keyData.algorithm;
|
|
1669
|
+
key.usages = keyData.usages;
|
|
1670
|
+
key._keyData = keyData;
|
|
1671
|
+
key._pem = keyData._pem;
|
|
1672
|
+
key._jwk = keyData._jwk;
|
|
1673
|
+
key._raw = keyData._raw;
|
|
1674
|
+
key._sourceKeyObjectData = keyData._sourceKeyObjectData;
|
|
1675
|
+
return key;
|
|
1676
|
+
}
|
|
1677
|
+
return new SandboxCryptoKey(keyData);
|
|
1678
|
+
}, buildCryptoKeyFromKeyObject2 = function(keyObject, algorithm, extractable, usages) {
|
|
1679
|
+
var algo = normalizeAlgorithmInput2(algorithm);
|
|
1680
|
+
var name3 = algo.name;
|
|
1681
|
+
if (keyObject.type === "secret") {
|
|
1682
|
+
var secretBytes = Buffer.from(keyObject._raw || "", "base64");
|
|
1683
|
+
if (name3 === "PBKDF2") {
|
|
1684
|
+
if (extractable) {
|
|
1685
|
+
throw new SyntaxError("PBKDF2 keys are not extractable");
|
|
1686
|
+
}
|
|
1687
|
+
if (usages.some(function(usage) {
|
|
1688
|
+
return usage !== "deriveBits" && usage !== "deriveKey";
|
|
1689
|
+
})) {
|
|
1690
|
+
throw new SyntaxError("Unsupported key usage for a PBKDF2 key");
|
|
1691
|
+
}
|
|
1692
|
+
return createCompatibleCryptoKey2({
|
|
1693
|
+
type: "secret",
|
|
1694
|
+
extractable,
|
|
1695
|
+
algorithm: { name: name3 },
|
|
1696
|
+
usages: Array.from(usages),
|
|
1697
|
+
_raw: keyObject._raw,
|
|
1698
|
+
_sourceKeyObjectData: {
|
|
1699
|
+
type: "secret",
|
|
1700
|
+
raw: keyObject._raw
|
|
1701
|
+
}
|
|
1702
|
+
});
|
|
660
1703
|
}
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
1704
|
+
if (name3 === "HMAC") {
|
|
1705
|
+
if (!secretBytes.byteLength || algo.length === 0) {
|
|
1706
|
+
throw createDomException2("Zero-length key is not supported", "DataError");
|
|
1707
|
+
}
|
|
1708
|
+
if (!usages.length) {
|
|
1709
|
+
throw new SyntaxError("Usages cannot be empty when importing a secret key.");
|
|
1710
|
+
}
|
|
1711
|
+
return createCompatibleCryptoKey2({
|
|
1712
|
+
type: "secret",
|
|
1713
|
+
extractable,
|
|
1714
|
+
algorithm: {
|
|
1715
|
+
name: name3,
|
|
1716
|
+
hash: typeof algo.hash === "string" ? { name: algo.hash } : cloneObject2(algo.hash),
|
|
1717
|
+
length: secretBytes.byteLength * 8
|
|
1718
|
+
},
|
|
1719
|
+
usages: Array.from(usages),
|
|
1720
|
+
_raw: keyObject._raw,
|
|
1721
|
+
_sourceKeyObjectData: {
|
|
1722
|
+
type: "secret",
|
|
1723
|
+
raw: keyObject._raw
|
|
1724
|
+
}
|
|
1725
|
+
});
|
|
1726
|
+
}
|
|
1727
|
+
return createCompatibleCryptoKey2({
|
|
1728
|
+
type: "secret",
|
|
1729
|
+
extractable,
|
|
1730
|
+
algorithm: {
|
|
1731
|
+
name: name3,
|
|
1732
|
+
length: secretBytes.byteLength * 8
|
|
1733
|
+
},
|
|
1734
|
+
usages: Array.from(usages),
|
|
1735
|
+
_raw: keyObject._raw,
|
|
1736
|
+
_sourceKeyObjectData: {
|
|
1737
|
+
type: "secret",
|
|
1738
|
+
raw: keyObject._raw
|
|
1739
|
+
}
|
|
1740
|
+
});
|
|
666
1741
|
}
|
|
667
|
-
var
|
|
668
|
-
var
|
|
669
|
-
if (
|
|
670
|
-
|
|
671
|
-
this._algorithm,
|
|
672
|
-
this._key.toString("base64"),
|
|
673
|
-
this._iv.toString("base64"),
|
|
674
|
-
combined.toString("base64"),
|
|
675
|
-
JSON.stringify(options)
|
|
676
|
-
]);
|
|
677
|
-
var resultBuffer2 = Buffer.from(resultBase64, "base64");
|
|
678
|
-
if (outputEncoding && outputEncoding !== "buffer") return resultBuffer2.toString(outputEncoding);
|
|
679
|
-
return resultBuffer2;
|
|
680
|
-
};
|
|
681
|
-
SandboxDecipher2.prototype.setAuthTag = function setAuthTag(tag) {
|
|
682
|
-
this._authTag = typeof tag === "string" ? Buffer.from(tag, "base64") : Buffer.from(tag);
|
|
683
|
-
return this;
|
|
684
|
-
};
|
|
685
|
-
SandboxDecipher2.prototype.setAAD = function setAAD(data) {
|
|
686
|
-
if (this._sessionId >= 0) {
|
|
687
|
-
var buf = typeof data === "string" ? Buffer.from(data, "utf8") : Buffer.from(data);
|
|
688
|
-
_cryptoCipherivUpdate.applySync(void 0, [this._sessionId, "", JSON.stringify({ setAAD: buf.toString("base64") })]);
|
|
1742
|
+
var keyType = String(keyObject.asymmetricKeyType || "").toLowerCase();
|
|
1743
|
+
var algorithmName = String(name3 || "");
|
|
1744
|
+
if ((keyType === "ed25519" || keyType === "ed448" || keyType === "x25519" || keyType === "x448") && keyType !== algorithmName.toLowerCase()) {
|
|
1745
|
+
throw createDomException2("Invalid key type", "DataError");
|
|
689
1746
|
}
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
1747
|
+
if (algorithmName === "ECDH") {
|
|
1748
|
+
if (keyObject.type === "private" && !usages.length) {
|
|
1749
|
+
throw new SyntaxError("Usages cannot be empty when importing a private key.");
|
|
1750
|
+
}
|
|
1751
|
+
var actualCurve = normalizeNamedCurve2(
|
|
1752
|
+
keyObject.asymmetricKeyDetails && keyObject.asymmetricKeyDetails.namedCurve
|
|
1753
|
+
);
|
|
1754
|
+
if (algo.namedCurve && actualCurve && normalizeNamedCurve2(algo.namedCurve) !== actualCurve) {
|
|
1755
|
+
throw createDomException2("Named curve mismatch", "DataError");
|
|
1756
|
+
}
|
|
695
1757
|
}
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
return new SandboxDecipher2(algorithm, key, iv);
|
|
700
|
-
};
|
|
701
|
-
result2.Decipheriv = SandboxDecipher2;
|
|
702
|
-
}
|
|
703
|
-
if (typeof _cryptoSign !== "undefined") {
|
|
704
|
-
result2.sign = function sign(algorithm, data, key) {
|
|
705
|
-
var dataBuf = typeof data === "string" ? Buffer.from(data, "utf8") : Buffer.from(data);
|
|
706
|
-
var keyPem;
|
|
707
|
-
if (typeof key === "string") {
|
|
708
|
-
keyPem = key;
|
|
709
|
-
} else if (key && typeof key === "object" && key._pem) {
|
|
710
|
-
keyPem = key._pem;
|
|
711
|
-
} else if (Buffer.isBuffer(key)) {
|
|
712
|
-
keyPem = key.toString("utf8");
|
|
713
|
-
} else {
|
|
714
|
-
keyPem = String(key);
|
|
1758
|
+
var normalizedAlgo = cloneObject2(algo);
|
|
1759
|
+
if (typeof normalizedAlgo.hash === "string") {
|
|
1760
|
+
normalizedAlgo.hash = { name: normalizedAlgo.hash };
|
|
715
1761
|
}
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
1762
|
+
return createCompatibleCryptoKey2({
|
|
1763
|
+
type: keyObject.type,
|
|
1764
|
+
extractable,
|
|
1765
|
+
algorithm: normalizedAlgo,
|
|
1766
|
+
usages: Array.from(usages),
|
|
1767
|
+
_pem: keyObject._pem,
|
|
1768
|
+
_jwk: cloneObject2(keyObject._jwk),
|
|
1769
|
+
_sourceKeyObjectData: {
|
|
1770
|
+
type: keyObject.type,
|
|
1771
|
+
pem: keyObject._pem,
|
|
1772
|
+
jwk: cloneObject2(keyObject._jwk),
|
|
1773
|
+
asymmetricKeyType: keyObject.asymmetricKeyType,
|
|
1774
|
+
asymmetricKeyDetails: cloneObject2(keyObject.asymmetricKeyDetails)
|
|
1775
|
+
}
|
|
1776
|
+
});
|
|
1777
|
+
}, createAsymmetricKeyObject2 = function(type, key) {
|
|
728
1778
|
if (typeof key === "string") {
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
keyPem = key.toString("utf8");
|
|
734
|
-
} else {
|
|
735
|
-
keyPem = String(key);
|
|
1779
|
+
if (key.indexOf("-----BEGIN") === -1) {
|
|
1780
|
+
throw new TypeError("error:0900006e:PEM routines:OPENSSL_internal:NO_START_LINE");
|
|
1781
|
+
}
|
|
1782
|
+
return new SandboxKeyObject2(type, { pem: key });
|
|
736
1783
|
}
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
1784
|
+
if (key && typeof key === "object" && key._pem) {
|
|
1785
|
+
return new SandboxKeyObject2(type, {
|
|
1786
|
+
pem: key._pem,
|
|
1787
|
+
jwk: key._jwk,
|
|
1788
|
+
asymmetricKeyType: key.asymmetricKeyType,
|
|
1789
|
+
asymmetricKeyDetails: key.asymmetricKeyDetails
|
|
1790
|
+
});
|
|
1791
|
+
}
|
|
1792
|
+
if (key && typeof key === "object" && key.key) {
|
|
1793
|
+
var keyData = typeof key.key === "string" ? key.key : key.key.toString("utf8");
|
|
1794
|
+
return new SandboxKeyObject2(type, { pem: keyData });
|
|
1795
|
+
}
|
|
1796
|
+
if (Buffer.isBuffer(key)) {
|
|
1797
|
+
var keyStr = key.toString("utf8");
|
|
1798
|
+
if (keyStr.indexOf("-----BEGIN") === -1) {
|
|
1799
|
+
throw new TypeError("error:0900006e:PEM routines:OPENSSL_internal:NO_START_LINE");
|
|
1800
|
+
}
|
|
1801
|
+
return new SandboxKeyObject2(type, { pem: keyStr });
|
|
1802
|
+
}
|
|
1803
|
+
return new SandboxKeyObject2(type, { pem: String(key) });
|
|
1804
|
+
}, createGeneratedKeyObject2 = function(value) {
|
|
1805
|
+
return new SandboxKeyObject2(value.type, {
|
|
1806
|
+
pem: value.pem,
|
|
1807
|
+
raw: value.raw,
|
|
1808
|
+
jwk: value.jwk,
|
|
1809
|
+
asymmetricKeyType: value.asymmetricKeyType,
|
|
1810
|
+
asymmetricKeyDetails: value.asymmetricKeyDetails
|
|
1811
|
+
});
|
|
750
1812
|
};
|
|
751
|
-
var SandboxKeyObject = SandboxKeyObject2;
|
|
1813
|
+
var restoreBridgeValue = restoreBridgeValue2, cloneObject = cloneObject2, createDomException = createDomException2, toRawBuffer = toRawBuffer2, serializeBridgeValue = serializeBridgeValue2, normalizeCryptoBridgeError = normalizeCryptoBridgeError2, deserializeGeneratedKeyValue = deserializeGeneratedKeyValue2, serializeBridgeOptions = serializeBridgeOptions2, createInvalidArgTypeError = createInvalidArgTypeError2, scheduleCryptoCallback = scheduleCryptoCallback2, shouldThrowCryptoValidationError = shouldThrowCryptoValidationError2, ensureCryptoCallback = ensureCryptoCallback2, SandboxKeyObject = SandboxKeyObject2, normalizeNamedCurve = normalizeNamedCurve2, normalizeAlgorithmInput = normalizeAlgorithmInput2, createCompatibleCryptoKey = createCompatibleCryptoKey2, buildCryptoKeyFromKeyObject = buildCryptoKeyFromKeyObject2, createAsymmetricKeyObject = createAsymmetricKeyObject2, createGeneratedKeyObject = createGeneratedKeyObject2;
|
|
1814
|
+
Object.defineProperty(SandboxKeyObject2.prototype, Symbol.toStringTag, {
|
|
1815
|
+
value: "KeyObject",
|
|
1816
|
+
configurable: true
|
|
1817
|
+
});
|
|
752
1818
|
SandboxKeyObject2.prototype.export = function exportKey(options) {
|
|
753
|
-
if (
|
|
754
|
-
return this.
|
|
1819
|
+
if (this.type === "secret") {
|
|
1820
|
+
return Buffer.from(this._raw || "", "base64");
|
|
1821
|
+
}
|
|
1822
|
+
if (!options || typeof options !== "object") {
|
|
1823
|
+
throw new TypeError('The "options" argument must be of type object.');
|
|
1824
|
+
}
|
|
1825
|
+
if (options.format === "jwk") {
|
|
1826
|
+
return cloneObject2(this._jwk);
|
|
755
1827
|
}
|
|
756
1828
|
if (options.format === "der") {
|
|
757
|
-
var lines = this._pem.split("\n").filter(function(l) {
|
|
1829
|
+
var lines = String(this._pem || "").split("\n").filter(function(l) {
|
|
758
1830
|
return l && l.indexOf("-----") !== 0;
|
|
759
1831
|
});
|
|
760
1832
|
return Buffer.from(lines.join(""), "base64");
|
|
@@ -762,95 +1834,168 @@
|
|
|
762
1834
|
return this._pem;
|
|
763
1835
|
};
|
|
764
1836
|
SandboxKeyObject2.prototype.toString = function() {
|
|
765
|
-
return
|
|
1837
|
+
return "[object KeyObject]";
|
|
766
1838
|
};
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
if (options.divisorLength !== void 0) opts.divisorLength = options.divisorLength;
|
|
774
|
-
if (options.primeLength !== void 0) opts.primeLength = options.primeLength;
|
|
1839
|
+
SandboxKeyObject2.prototype.equals = function equals(other) {
|
|
1840
|
+
if (!(other instanceof SandboxKeyObject2)) {
|
|
1841
|
+
return false;
|
|
1842
|
+
}
|
|
1843
|
+
if (this.type !== other.type) {
|
|
1844
|
+
return false;
|
|
775
1845
|
}
|
|
1846
|
+
if (this.type === "secret") {
|
|
1847
|
+
return (this._raw || "") === (other._raw || "");
|
|
1848
|
+
}
|
|
1849
|
+
return (this._pem || "") === (other._pem || "") && this.asymmetricKeyType === other.asymmetricKeyType;
|
|
1850
|
+
};
|
|
1851
|
+
SandboxKeyObject2.prototype.toCryptoKey = function toCryptoKey(algorithm, extractable, usages) {
|
|
1852
|
+
return buildCryptoKeyFromKeyObject2(this, algorithm, extractable, Array.from(usages || []));
|
|
1853
|
+
};
|
|
1854
|
+
result2.generateKeyPairSync = function generateKeyPairSync(type, options) {
|
|
776
1855
|
var resultJson = _cryptoGenerateKeyPairSync.applySync(void 0, [
|
|
777
1856
|
type,
|
|
778
|
-
|
|
1857
|
+
serializeBridgeOptions2(options)
|
|
779
1858
|
]);
|
|
780
1859
|
var parsed = JSON.parse(resultJson);
|
|
781
|
-
if (
|
|
782
|
-
return {
|
|
1860
|
+
if (parsed.publicKey && parsed.publicKey.kind) {
|
|
1861
|
+
return {
|
|
1862
|
+
publicKey: deserializeGeneratedKeyValue2(parsed.publicKey),
|
|
1863
|
+
privateKey: deserializeGeneratedKeyValue2(parsed.privateKey)
|
|
1864
|
+
};
|
|
783
1865
|
}
|
|
784
1866
|
return {
|
|
785
|
-
publicKey:
|
|
786
|
-
privateKey:
|
|
1867
|
+
publicKey: createGeneratedKeyObject2(parsed.publicKey),
|
|
1868
|
+
privateKey: createGeneratedKeyObject2(parsed.privateKey)
|
|
787
1869
|
};
|
|
788
1870
|
};
|
|
789
1871
|
result2.generateKeyPair = function generateKeyPair(type, options, callback) {
|
|
1872
|
+
if (typeof options === "function") {
|
|
1873
|
+
callback = options;
|
|
1874
|
+
options = void 0;
|
|
1875
|
+
}
|
|
1876
|
+
callback = ensureCryptoCallback2(callback, function() {
|
|
1877
|
+
result2.generateKeyPairSync(type, options);
|
|
1878
|
+
});
|
|
790
1879
|
try {
|
|
791
1880
|
var pair = result2.generateKeyPairSync(type, options);
|
|
792
|
-
callback
|
|
1881
|
+
scheduleCryptoCallback2(callback, [null, pair.publicKey, pair.privateKey]);
|
|
793
1882
|
} catch (e) {
|
|
794
|
-
|
|
1883
|
+
if (shouldThrowCryptoValidationError2(e)) {
|
|
1884
|
+
throw e;
|
|
1885
|
+
}
|
|
1886
|
+
scheduleCryptoCallback2(callback, [e]);
|
|
795
1887
|
}
|
|
796
1888
|
};
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
1889
|
+
if (typeof _cryptoGenerateKeySync !== "undefined") {
|
|
1890
|
+
result2.generateKeySync = function generateKeySync(type, options) {
|
|
1891
|
+
var resultJson;
|
|
1892
|
+
try {
|
|
1893
|
+
resultJson = _cryptoGenerateKeySync.applySync(void 0, [
|
|
1894
|
+
type,
|
|
1895
|
+
serializeBridgeOptions2(options)
|
|
1896
|
+
]);
|
|
1897
|
+
} catch (error) {
|
|
1898
|
+
throw normalizeCryptoBridgeError2(error);
|
|
801
1899
|
}
|
|
802
|
-
return
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
1900
|
+
return createGeneratedKeyObject2(JSON.parse(resultJson));
|
|
1901
|
+
};
|
|
1902
|
+
result2.generateKey = function generateKey(type, options, callback) {
|
|
1903
|
+
callback = ensureCryptoCallback2(callback, function() {
|
|
1904
|
+
result2.generateKeySync(type, options);
|
|
1905
|
+
});
|
|
1906
|
+
try {
|
|
1907
|
+
var key = result2.generateKeySync(type, options);
|
|
1908
|
+
scheduleCryptoCallback2(callback, [null, key]);
|
|
1909
|
+
} catch (e) {
|
|
1910
|
+
if (shouldThrowCryptoValidationError2(e)) {
|
|
1911
|
+
throw e;
|
|
1912
|
+
}
|
|
1913
|
+
scheduleCryptoCallback2(callback, [e]);
|
|
1914
|
+
}
|
|
1915
|
+
};
|
|
1916
|
+
}
|
|
1917
|
+
if (typeof _cryptoGeneratePrimeSync !== "undefined") {
|
|
1918
|
+
result2.generatePrimeSync = function generatePrimeSync(size, options) {
|
|
1919
|
+
var resultJson;
|
|
1920
|
+
try {
|
|
1921
|
+
resultJson = _cryptoGeneratePrimeSync.applySync(void 0, [
|
|
1922
|
+
size,
|
|
1923
|
+
serializeBridgeOptions2(options)
|
|
1924
|
+
]);
|
|
1925
|
+
} catch (error) {
|
|
1926
|
+
throw normalizeCryptoBridgeError2(error);
|
|
1927
|
+
}
|
|
1928
|
+
return restoreBridgeValue2(JSON.parse(resultJson));
|
|
1929
|
+
};
|
|
1930
|
+
result2.generatePrime = function generatePrime(size, options, callback) {
|
|
1931
|
+
if (typeof options === "function") {
|
|
1932
|
+
callback = options;
|
|
1933
|
+
options = void 0;
|
|
1934
|
+
}
|
|
1935
|
+
callback = ensureCryptoCallback2(callback, function() {
|
|
1936
|
+
result2.generatePrimeSync(size, options);
|
|
1937
|
+
});
|
|
1938
|
+
try {
|
|
1939
|
+
var prime = result2.generatePrimeSync(size, options);
|
|
1940
|
+
scheduleCryptoCallback2(callback, [null, prime]);
|
|
1941
|
+
} catch (e) {
|
|
1942
|
+
if (shouldThrowCryptoValidationError2(e)) {
|
|
1943
|
+
throw e;
|
|
1944
|
+
}
|
|
1945
|
+
scheduleCryptoCallback2(callback, [e]);
|
|
1946
|
+
}
|
|
1947
|
+
};
|
|
1948
|
+
}
|
|
1949
|
+
result2.createPublicKey = function createPublicKey(key) {
|
|
1950
|
+
if (typeof _cryptoCreateKeyObject !== "undefined") {
|
|
1951
|
+
var resultJson;
|
|
1952
|
+
try {
|
|
1953
|
+
resultJson = _cryptoCreateKeyObject.applySync(void 0, [
|
|
1954
|
+
"createPublicKey",
|
|
1955
|
+
JSON.stringify(serializeBridgeValue2(key))
|
|
1956
|
+
]);
|
|
1957
|
+
} catch (error) {
|
|
1958
|
+
throw normalizeCryptoBridgeError2(error);
|
|
818
1959
|
}
|
|
819
|
-
return
|
|
1960
|
+
return createGeneratedKeyObject2(JSON.parse(resultJson));
|
|
820
1961
|
}
|
|
821
|
-
return
|
|
1962
|
+
return createAsymmetricKeyObject2("public", key);
|
|
822
1963
|
};
|
|
823
1964
|
result2.createPrivateKey = function createPrivateKey(key) {
|
|
824
|
-
if (typeof
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
if (key && typeof key === "object" && key.key) {
|
|
834
|
-
var keyData = typeof key.key === "string" ? key.key : key.key.toString("utf8");
|
|
835
|
-
return new SandboxKeyObject2("private", keyData);
|
|
836
|
-
}
|
|
837
|
-
if (Buffer.isBuffer(key)) {
|
|
838
|
-
var keyStr = key.toString("utf8");
|
|
839
|
-
if (keyStr.indexOf("-----BEGIN") === -1) {
|
|
840
|
-
throw new TypeError("error:0900006e:PEM routines:OPENSSL_internal:NO_START_LINE");
|
|
1965
|
+
if (typeof _cryptoCreateKeyObject !== "undefined") {
|
|
1966
|
+
var resultJson;
|
|
1967
|
+
try {
|
|
1968
|
+
resultJson = _cryptoCreateKeyObject.applySync(void 0, [
|
|
1969
|
+
"createPrivateKey",
|
|
1970
|
+
JSON.stringify(serializeBridgeValue2(key))
|
|
1971
|
+
]);
|
|
1972
|
+
} catch (error) {
|
|
1973
|
+
throw normalizeCryptoBridgeError2(error);
|
|
841
1974
|
}
|
|
842
|
-
return
|
|
1975
|
+
return createGeneratedKeyObject2(JSON.parse(resultJson));
|
|
843
1976
|
}
|
|
844
|
-
return
|
|
1977
|
+
return createAsymmetricKeyObject2("private", key);
|
|
845
1978
|
};
|
|
846
|
-
result2.createSecretKey = function createSecretKey(key) {
|
|
847
|
-
|
|
848
|
-
|
|
1979
|
+
result2.createSecretKey = function createSecretKey(key, encoding) {
|
|
1980
|
+
return new SandboxKeyObject2("secret", {
|
|
1981
|
+
raw: toRawBuffer2(key, encoding).toString("base64")
|
|
1982
|
+
});
|
|
1983
|
+
};
|
|
1984
|
+
SandboxKeyObject2.from = function from(key) {
|
|
1985
|
+
if (!key || typeof key !== "object" || key[Symbol.toStringTag] !== "CryptoKey") {
|
|
1986
|
+
throw new TypeError('The "key" argument must be an instance of CryptoKey.');
|
|
849
1987
|
}
|
|
850
|
-
if (
|
|
851
|
-
return new SandboxKeyObject2("secret",
|
|
1988
|
+
if (key._sourceKeyObjectData && key._sourceKeyObjectData.type === "secret") {
|
|
1989
|
+
return new SandboxKeyObject2("secret", {
|
|
1990
|
+
raw: key._sourceKeyObjectData.raw
|
|
1991
|
+
});
|
|
852
1992
|
}
|
|
853
|
-
return new SandboxKeyObject2(
|
|
1993
|
+
return new SandboxKeyObject2(key.type, {
|
|
1994
|
+
pem: key._pem,
|
|
1995
|
+
jwk: key._jwk,
|
|
1996
|
+
asymmetricKeyType: key._sourceKeyObjectData && key._sourceKeyObjectData.asymmetricKeyType,
|
|
1997
|
+
asymmetricKeyDetails: key._sourceKeyObjectData && key._sourceKeyObjectData.asymmetricKeyDetails
|
|
1998
|
+
});
|
|
854
1999
|
};
|
|
855
2000
|
result2.KeyObject = SandboxKeyObject2;
|
|
856
2001
|
}
|
|
@@ -861,6 +2006,10 @@
|
|
|
861
2006
|
this.algorithm = keyData.algorithm;
|
|
862
2007
|
this.usages = keyData.usages;
|
|
863
2008
|
this._keyData = keyData;
|
|
2009
|
+
this._pem = keyData._pem;
|
|
2010
|
+
this._jwk = keyData._jwk;
|
|
2011
|
+
this._raw = keyData._raw;
|
|
2012
|
+
this._sourceKeyObjectData = keyData._sourceKeyObjectData;
|
|
864
2013
|
}, toBase642 = function(data) {
|
|
865
2014
|
if (typeof data === "string") return Buffer.from(data).toString("base64");
|
|
866
2015
|
if (data instanceof ArrayBuffer) return Buffer.from(new Uint8Array(data)).toString("base64");
|
|
@@ -873,6 +2022,24 @@
|
|
|
873
2022
|
return algorithm;
|
|
874
2023
|
};
|
|
875
2024
|
var SandboxCryptoKey = SandboxCryptoKey2, toBase64 = toBase642, subtleCall = subtleCall2, normalizeAlgo = normalizeAlgo2;
|
|
2025
|
+
Object.defineProperty(SandboxCryptoKey2.prototype, Symbol.toStringTag, {
|
|
2026
|
+
value: "CryptoKey",
|
|
2027
|
+
configurable: true
|
|
2028
|
+
});
|
|
2029
|
+
Object.defineProperty(SandboxCryptoKey2, Symbol.hasInstance, {
|
|
2030
|
+
value: function(candidate) {
|
|
2031
|
+
return !!(candidate && typeof candidate === "object" && (candidate._keyData || candidate[Symbol.toStringTag] === "CryptoKey"));
|
|
2032
|
+
},
|
|
2033
|
+
configurable: true
|
|
2034
|
+
});
|
|
2035
|
+
if (globalThis.CryptoKey && globalThis.CryptoKey.prototype && globalThis.CryptoKey.prototype !== SandboxCryptoKey2.prototype) {
|
|
2036
|
+
Object.setPrototypeOf(SandboxCryptoKey2.prototype, globalThis.CryptoKey.prototype);
|
|
2037
|
+
}
|
|
2038
|
+
if (typeof globalThis.CryptoKey === "undefined") {
|
|
2039
|
+
__requireExposeCustomGlobal("CryptoKey", SandboxCryptoKey2);
|
|
2040
|
+
} else if (globalThis.CryptoKey !== SandboxCryptoKey2) {
|
|
2041
|
+
globalThis.CryptoKey = SandboxCryptoKey2;
|
|
2042
|
+
}
|
|
876
2043
|
var SandboxSubtle = {};
|
|
877
2044
|
SandboxSubtle.digest = function digest(algorithm, data) {
|
|
878
2045
|
return Promise.resolve().then(function() {
|
|
@@ -977,22 +2144,6 @@
|
|
|
977
2144
|
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
978
2145
|
});
|
|
979
2146
|
};
|
|
980
|
-
SandboxSubtle.deriveBits = function deriveBits(algorithm, baseKey, length) {
|
|
981
|
-
return Promise.resolve().then(function() {
|
|
982
|
-
var algo = normalizeAlgo2(algorithm);
|
|
983
|
-
var reqAlgo = Object.assign({}, algo);
|
|
984
|
-
if (reqAlgo.hash) reqAlgo.hash = normalizeAlgo2(reqAlgo.hash);
|
|
985
|
-
if (reqAlgo.salt) reqAlgo.salt = toBase642(reqAlgo.salt);
|
|
986
|
-
var result22 = JSON.parse(subtleCall2({
|
|
987
|
-
op: "deriveBits",
|
|
988
|
-
algorithm: reqAlgo,
|
|
989
|
-
key: baseKey._keyData,
|
|
990
|
-
length
|
|
991
|
-
}));
|
|
992
|
-
var buf = Buffer.from(result22.data, "base64");
|
|
993
|
-
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
|
|
994
|
-
});
|
|
995
|
-
};
|
|
996
2147
|
SandboxSubtle.sign = function sign(algorithm, key, data) {
|
|
997
2148
|
return Promise.resolve().then(function() {
|
|
998
2149
|
var result22 = JSON.parse(subtleCall2({
|
|
@@ -1017,8 +2168,45 @@
|
|
|
1017
2168
|
return result22.result;
|
|
1018
2169
|
});
|
|
1019
2170
|
};
|
|
1020
|
-
|
|
1021
|
-
|
|
2171
|
+
SandboxSubtle.deriveBits = function deriveBits(algorithm, baseKey, length) {
|
|
2172
|
+
return Promise.resolve().then(function() {
|
|
2173
|
+
var algo = normalizeAlgo2(algorithm);
|
|
2174
|
+
var reqAlgo = Object.assign({}, algo);
|
|
2175
|
+
if (reqAlgo.salt) reqAlgo.salt = toBase642(reqAlgo.salt);
|
|
2176
|
+
if (reqAlgo.info) reqAlgo.info = toBase642(reqAlgo.info);
|
|
2177
|
+
var result22 = JSON.parse(subtleCall2({
|
|
2178
|
+
op: "deriveBits",
|
|
2179
|
+
algorithm: reqAlgo,
|
|
2180
|
+
baseKey: baseKey._keyData,
|
|
2181
|
+
length
|
|
2182
|
+
}));
|
|
2183
|
+
return Buffer.from(result22.data, "base64").buffer;
|
|
2184
|
+
});
|
|
2185
|
+
};
|
|
2186
|
+
SandboxSubtle.deriveKey = function deriveKey(algorithm, baseKey, derivedKeyAlgorithm, extractable, keyUsages) {
|
|
2187
|
+
return Promise.resolve().then(function() {
|
|
2188
|
+
var algo = normalizeAlgo2(algorithm);
|
|
2189
|
+
var reqAlgo = Object.assign({}, algo);
|
|
2190
|
+
if (reqAlgo.salt) reqAlgo.salt = toBase642(reqAlgo.salt);
|
|
2191
|
+
if (reqAlgo.info) reqAlgo.info = toBase642(reqAlgo.info);
|
|
2192
|
+
var result22 = JSON.parse(subtleCall2({
|
|
2193
|
+
op: "deriveKey",
|
|
2194
|
+
algorithm: reqAlgo,
|
|
2195
|
+
baseKey: baseKey._keyData,
|
|
2196
|
+
derivedKeyAlgorithm: normalizeAlgo2(derivedKeyAlgorithm),
|
|
2197
|
+
extractable,
|
|
2198
|
+
usages: keyUsages
|
|
2199
|
+
}));
|
|
2200
|
+
return new SandboxCryptoKey2(result22.key);
|
|
2201
|
+
});
|
|
2202
|
+
};
|
|
2203
|
+
if (globalThis.crypto && globalThis.crypto.subtle && typeof globalThis.crypto.subtle.importKey === "function") {
|
|
2204
|
+
result2.subtle = globalThis.crypto.subtle;
|
|
2205
|
+
result2.webcrypto = globalThis.crypto;
|
|
2206
|
+
} else {
|
|
2207
|
+
result2.subtle = SandboxSubtle;
|
|
2208
|
+
result2.webcrypto = { subtle: SandboxSubtle, getRandomValues: result2.randomFillSync };
|
|
2209
|
+
}
|
|
1022
2210
|
}
|
|
1023
2211
|
if (typeof result2.getCurves !== "function") {
|
|
1024
2212
|
result2.getCurves = function getCurves() {
|
|
@@ -1065,6 +2253,16 @@
|
|
|
1065
2253
|
return out === 0;
|
|
1066
2254
|
};
|
|
1067
2255
|
}
|
|
2256
|
+
if (typeof result2.getFips !== "function") {
|
|
2257
|
+
result2.getFips = function getFips() {
|
|
2258
|
+
return 0;
|
|
2259
|
+
};
|
|
2260
|
+
}
|
|
2261
|
+
if (typeof result2.setFips !== "function") {
|
|
2262
|
+
result2.setFips = function setFips() {
|
|
2263
|
+
throw new Error("FIPS mode is not supported in sandbox");
|
|
2264
|
+
};
|
|
2265
|
+
}
|
|
1068
2266
|
return result2;
|
|
1069
2267
|
}
|
|
1070
2268
|
if (name2 === "stream") {
|
|
@@ -1124,7 +2322,6 @@
|
|
|
1124
2322
|
return result2;
|
|
1125
2323
|
}
|
|
1126
2324
|
var _deferredCoreModules = /* @__PURE__ */ new Set([
|
|
1127
|
-
"tls",
|
|
1128
2325
|
"readline",
|
|
1129
2326
|
"perf_hooks",
|
|
1130
2327
|
"async_hooks",
|
|
@@ -1132,7 +2329,6 @@
|
|
|
1132
2329
|
"diagnostics_channel"
|
|
1133
2330
|
]);
|
|
1134
2331
|
var _unsupportedCoreModules = /* @__PURE__ */ new Set([
|
|
1135
|
-
"dgram",
|
|
1136
2332
|
"cluster",
|
|
1137
2333
|
"wasi",
|
|
1138
2334
|
"inspector",
|
|
@@ -1168,25 +2364,14 @@
|
|
|
1168
2364
|
return _requireFrom(moduleName2, _currentModule.dirname);
|
|
1169
2365
|
};
|
|
1170
2366
|
__requireExposeCustomGlobal("require", __require);
|
|
1171
|
-
var _resolveCache = /* @__PURE__ */ Object.create(null);
|
|
1172
2367
|
function _resolveFrom(moduleName2, fromDir2) {
|
|
1173
|
-
|
|
1174
|
-
if (cacheKey2 in _resolveCache) {
|
|
1175
|
-
const cached = _resolveCache[cacheKey2];
|
|
1176
|
-
if (cached === null) {
|
|
1177
|
-
const err = new Error("Cannot find module '" + moduleName2 + "'");
|
|
1178
|
-
err.code = "MODULE_NOT_FOUND";
|
|
1179
|
-
throw err;
|
|
1180
|
-
}
|
|
1181
|
-
return cached;
|
|
1182
|
-
}
|
|
1183
|
-
let resolved2;
|
|
2368
|
+
var resolved2;
|
|
1184
2369
|
if (typeof _resolveModuleSync !== "undefined") {
|
|
1185
2370
|
resolved2 = _resolveModuleSync.applySync(void 0, [moduleName2, fromDir2]);
|
|
1186
|
-
} else {
|
|
1187
|
-
resolved2 = _resolveModule.applySyncPromise(void 0, [moduleName2, fromDir2]);
|
|
1188
2371
|
}
|
|
1189
|
-
|
|
2372
|
+
if (resolved2 === null || resolved2 === void 0) {
|
|
2373
|
+
resolved2 = _resolveModule.applySyncPromise(void 0, [moduleName2, fromDir2, "require"]);
|
|
2374
|
+
}
|
|
1190
2375
|
if (resolved2 === null) {
|
|
1191
2376
|
const err = new Error("Cannot find module '" + moduleName2 + "'");
|
|
1192
2377
|
err.code = "MODULE_NOT_FOUND";
|
|
@@ -1285,18 +2470,99 @@
|
|
|
1285
2470
|
_debugRequire("loaded", name, "stream-promises-special");
|
|
1286
2471
|
return promisesModule;
|
|
1287
2472
|
}
|
|
2473
|
+
if (name === "stream/consumers") {
|
|
2474
|
+
if (__internalModuleCache["stream/consumers"]) return __internalModuleCache["stream/consumers"];
|
|
2475
|
+
const consumersModule = {};
|
|
2476
|
+
consumersModule.buffer = async function buffer(stream) {
|
|
2477
|
+
const chunks = [];
|
|
2478
|
+
const pushChunk = function(chunk) {
|
|
2479
|
+
if (typeof chunk === "string") {
|
|
2480
|
+
chunks.push(Buffer.from(chunk));
|
|
2481
|
+
} else if (Buffer.isBuffer(chunk)) {
|
|
2482
|
+
chunks.push(chunk);
|
|
2483
|
+
} else if (ArrayBuffer.isView(chunk)) {
|
|
2484
|
+
chunks.push(Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength));
|
|
2485
|
+
} else if (chunk instanceof ArrayBuffer) {
|
|
2486
|
+
chunks.push(Buffer.from(new Uint8Array(chunk)));
|
|
2487
|
+
} else {
|
|
2488
|
+
chunks.push(Buffer.from(String(chunk)));
|
|
2489
|
+
}
|
|
2490
|
+
};
|
|
2491
|
+
if (stream && typeof stream[Symbol.asyncIterator] === "function") {
|
|
2492
|
+
for await (const chunk of stream) {
|
|
2493
|
+
pushChunk(chunk);
|
|
2494
|
+
}
|
|
2495
|
+
return Buffer.concat(chunks);
|
|
2496
|
+
}
|
|
2497
|
+
return new Promise(function(resolve2, reject) {
|
|
2498
|
+
stream.on("data", pushChunk);
|
|
2499
|
+
stream.on("end", function() {
|
|
2500
|
+
resolve2(Buffer.concat(chunks));
|
|
2501
|
+
});
|
|
2502
|
+
stream.on("error", reject);
|
|
2503
|
+
});
|
|
2504
|
+
};
|
|
2505
|
+
consumersModule.text = async function text(stream) {
|
|
2506
|
+
return (await consumersModule.buffer(stream)).toString("utf8");
|
|
2507
|
+
};
|
|
2508
|
+
consumersModule.json = async function json(stream) {
|
|
2509
|
+
return JSON.parse(await consumersModule.text(stream));
|
|
2510
|
+
};
|
|
2511
|
+
consumersModule.arrayBuffer = async function arrayBuffer(stream) {
|
|
2512
|
+
const buffer = await consumersModule.buffer(stream);
|
|
2513
|
+
return buffer.buffer.slice(
|
|
2514
|
+
buffer.byteOffset,
|
|
2515
|
+
buffer.byteOffset + buffer.byteLength
|
|
2516
|
+
);
|
|
2517
|
+
};
|
|
2518
|
+
__internalModuleCache["stream/consumers"] = consumersModule;
|
|
2519
|
+
_debugRequire("loaded", name, "stream-consumers-special");
|
|
2520
|
+
return consumersModule;
|
|
2521
|
+
}
|
|
1288
2522
|
if (name === "child_process") {
|
|
1289
2523
|
if (__internalModuleCache["child_process"]) return __internalModuleCache["child_process"];
|
|
1290
2524
|
__internalModuleCache["child_process"] = _childProcessModule;
|
|
1291
2525
|
_debugRequire("loaded", name, "child-process-special");
|
|
1292
2526
|
return _childProcessModule;
|
|
1293
2527
|
}
|
|
2528
|
+
if (name === "net") {
|
|
2529
|
+
if (__internalModuleCache["net"]) return __internalModuleCache["net"];
|
|
2530
|
+
__internalModuleCache["net"] = _netModule;
|
|
2531
|
+
_debugRequire("loaded", name, "net-special");
|
|
2532
|
+
return _netModule;
|
|
2533
|
+
}
|
|
2534
|
+
if (name === "tls") {
|
|
2535
|
+
if (__internalModuleCache["tls"]) return __internalModuleCache["tls"];
|
|
2536
|
+
__internalModuleCache["tls"] = _tlsModule;
|
|
2537
|
+
_debugRequire("loaded", name, "tls-special");
|
|
2538
|
+
return _tlsModule;
|
|
2539
|
+
}
|
|
1294
2540
|
if (name === "http") {
|
|
1295
2541
|
if (__internalModuleCache["http"]) return __internalModuleCache["http"];
|
|
1296
2542
|
__internalModuleCache["http"] = _httpModule;
|
|
1297
2543
|
_debugRequire("loaded", name, "http-special");
|
|
1298
2544
|
return _httpModule;
|
|
1299
2545
|
}
|
|
2546
|
+
if (name === "_http_agent") {
|
|
2547
|
+
if (__internalModuleCache["_http_agent"]) return __internalModuleCache["_http_agent"];
|
|
2548
|
+
const httpAgentModule = {
|
|
2549
|
+
Agent: _httpModule.Agent,
|
|
2550
|
+
globalAgent: _httpModule.globalAgent
|
|
2551
|
+
};
|
|
2552
|
+
__internalModuleCache["_http_agent"] = httpAgentModule;
|
|
2553
|
+
_debugRequire("loaded", name, "http-agent-special");
|
|
2554
|
+
return httpAgentModule;
|
|
2555
|
+
}
|
|
2556
|
+
if (name === "_http_common") {
|
|
2557
|
+
if (__internalModuleCache["_http_common"]) return __internalModuleCache["_http_common"];
|
|
2558
|
+
const httpCommonModule = {
|
|
2559
|
+
_checkIsHttpToken: _httpModule._checkIsHttpToken,
|
|
2560
|
+
_checkInvalidHeaderChar: _httpModule._checkInvalidHeaderChar
|
|
2561
|
+
};
|
|
2562
|
+
__internalModuleCache["_http_common"] = httpCommonModule;
|
|
2563
|
+
_debugRequire("loaded", name, "http-common-special");
|
|
2564
|
+
return httpCommonModule;
|
|
2565
|
+
}
|
|
1300
2566
|
if (name === "https") {
|
|
1301
2567
|
if (__internalModuleCache["https"]) return __internalModuleCache["https"];
|
|
1302
2568
|
__internalModuleCache["https"] = _httpsModule;
|
|
@@ -1309,23 +2575,34 @@
|
|
|
1309
2575
|
_debugRequire("loaded", name, "http2-special");
|
|
1310
2576
|
return _http2Module;
|
|
1311
2577
|
}
|
|
2578
|
+
if (name === "internal/http2/util") {
|
|
2579
|
+
if (__internalModuleCache[name]) return __internalModuleCache[name];
|
|
2580
|
+
class NghttpError extends Error {
|
|
2581
|
+
constructor(message) {
|
|
2582
|
+
super(message);
|
|
2583
|
+
this.name = "Error";
|
|
2584
|
+
this.code = "ERR_HTTP2_ERROR";
|
|
2585
|
+
}
|
|
2586
|
+
}
|
|
2587
|
+
const utilModule = {
|
|
2588
|
+
kSocket: /* @__PURE__ */ Symbol.for("secure-exec.http2.kSocket"),
|
|
2589
|
+
NghttpError
|
|
2590
|
+
};
|
|
2591
|
+
__internalModuleCache[name] = utilModule;
|
|
2592
|
+
_debugRequire("loaded", name, "http2-util-special");
|
|
2593
|
+
return utilModule;
|
|
2594
|
+
}
|
|
1312
2595
|
if (name === "dns") {
|
|
1313
2596
|
if (__internalModuleCache["dns"]) return __internalModuleCache["dns"];
|
|
1314
2597
|
__internalModuleCache["dns"] = _dnsModule;
|
|
1315
2598
|
_debugRequire("loaded", name, "dns-special");
|
|
1316
2599
|
return _dnsModule;
|
|
1317
2600
|
}
|
|
1318
|
-
if (name === "
|
|
1319
|
-
if (__internalModuleCache["
|
|
1320
|
-
__internalModuleCache["
|
|
1321
|
-
_debugRequire("loaded", name, "
|
|
1322
|
-
return
|
|
1323
|
-
}
|
|
1324
|
-
if (name === "tls") {
|
|
1325
|
-
if (__internalModuleCache["tls"]) return __internalModuleCache["tls"];
|
|
1326
|
-
__internalModuleCache["tls"] = _tlsModule;
|
|
1327
|
-
_debugRequire("loaded", name, "tls-special");
|
|
1328
|
-
return _tlsModule;
|
|
2601
|
+
if (name === "dgram") {
|
|
2602
|
+
if (__internalModuleCache["dgram"]) return __internalModuleCache["dgram"];
|
|
2603
|
+
__internalModuleCache["dgram"] = _dgramModule;
|
|
2604
|
+
_debugRequire("loaded", name, "dgram-special");
|
|
2605
|
+
return _dgramModule;
|
|
1329
2606
|
}
|
|
1330
2607
|
if (name === "os") {
|
|
1331
2608
|
if (__internalModuleCache["os"]) return __internalModuleCache["os"];
|
|
@@ -1483,12 +2760,7 @@
|
|
|
1483
2760
|
if (_unsupportedCoreModules.has(name)) {
|
|
1484
2761
|
throw new Error(name + " is not supported in sandbox");
|
|
1485
2762
|
}
|
|
1486
|
-
|
|
1487
|
-
_debugRequire("name-cache-hit", name, name);
|
|
1488
|
-
return __internalModuleCache[name];
|
|
1489
|
-
}
|
|
1490
|
-
const isPath = name[0] === "." || name[0] === "/";
|
|
1491
|
-
const polyfillCode = isPath ? null : _loadPolyfill.applySyncPromise(void 0, [name]);
|
|
2763
|
+
const polyfillCode = _loadPolyfill.applySyncPromise(void 0, [name]);
|
|
1492
2764
|
if (polyfillCode !== null) {
|
|
1493
2765
|
if (__internalModuleCache[name]) return __internalModuleCache[name];
|
|
1494
2766
|
const moduleObj = { exports: {} };
|
|
@@ -1505,14 +2777,6 @@
|
|
|
1505
2777
|
_debugRequire("loaded", name, "polyfill");
|
|
1506
2778
|
return __internalModuleCache[name];
|
|
1507
2779
|
}
|
|
1508
|
-
const resolveCacheKey = fromDir + "\0" + name;
|
|
1509
|
-
if (resolveCacheKey in _resolveCache) {
|
|
1510
|
-
const cachedPath = _resolveCache[resolveCacheKey];
|
|
1511
|
-
if (cachedPath !== null && __internalModuleCache[cachedPath]) {
|
|
1512
|
-
_debugRequire("resolve-cache-hit", name, cachedPath);
|
|
1513
|
-
return __internalModuleCache[cachedPath];
|
|
1514
|
-
}
|
|
1515
|
-
}
|
|
1516
2780
|
resolved = _resolveFrom(name, fromDir);
|
|
1517
2781
|
cacheKey = resolved;
|
|
1518
2782
|
if (__internalModuleCache[cacheKey]) {
|
|
@@ -1523,11 +2787,12 @@
|
|
|
1523
2787
|
_debugRequire("pending-hit", name, cacheKey);
|
|
1524
2788
|
return _pendingModules[cacheKey].exports;
|
|
1525
2789
|
}
|
|
1526
|
-
|
|
2790
|
+
var source;
|
|
1527
2791
|
if (typeof _loadFileSync !== "undefined") {
|
|
1528
2792
|
source = _loadFileSync.applySync(void 0, [resolved]);
|
|
1529
|
-
}
|
|
1530
|
-
|
|
2793
|
+
}
|
|
2794
|
+
if (source === null || source === void 0) {
|
|
2795
|
+
source = _loadFile.applySyncPromise(void 0, [resolved, "require"]);
|
|
1531
2796
|
}
|
|
1532
2797
|
if (source === null) {
|
|
1533
2798
|
const err = new Error("Cannot find module '" + resolved + "'");
|
|
@@ -1594,9 +2859,6 @@
|
|
|
1594
2859
|
_currentModule = prevModule;
|
|
1595
2860
|
}
|
|
1596
2861
|
__internalModuleCache[cacheKey] = module.exports;
|
|
1597
|
-
if (!isPath && name !== cacheKey) {
|
|
1598
|
-
__internalModuleCache[name] = module.exports;
|
|
1599
|
-
}
|
|
1600
2862
|
delete _pendingModules[cacheKey];
|
|
1601
2863
|
_debugRequire("loaded", name, cacheKey);
|
|
1602
2864
|
return module.exports;
|