From 63b534419b388b56bd4af0e877810272ae2be9a0 Mon Sep 17 00:00:00 2001 From: Nathan Flurry Date: Wed, 25 Mar 2026 21:45:21 -0700 Subject: [PATCH] fix: add explicit zlib constant fallbacks --- .../src/inject/require-setup.ts | 32 +++++++++- .../core/src/generated/isolate-runtime.ts | 2 +- .../tests/test-suite/node/polyfills.ts | 63 +++++++++++++++++++ 3 files changed, 94 insertions(+), 3 deletions(-) diff --git a/packages/core/isolate-runtime/src/inject/require-setup.ts b/packages/core/isolate-runtime/src/inject/require-setup.ts index 9f4cc944..d3d8bfbb 100644 --- a/packages/core/isolate-runtime/src/inject/require-setup.ts +++ b/packages/core/isolate-runtime/src/inject/require-setup.ts @@ -300,8 +300,10 @@ // constants object. Node.js zlib.constants bundles all Z_ values plus // DEFLATE (1), INFLATE (2), GZIP (3), DEFLATERAW (4), INFLATERAW (5), // UNZIP (6), GUNZIP (7). Packages like ssh2 destructure constants. + var zlibConstants = typeof result.constants === 'object' && result.constants !== null + ? result.constants + : {}; if (typeof result.constants !== 'object' || result.constants === null) { - var zlibConstants = {}; var constKeys = Object.keys(result); for (var ci = 0; ci < constKeys.length; ci++) { var ck = constKeys[ci]; @@ -309,6 +311,32 @@ zlibConstants[ck] = result[ck]; } } + // Add Z_* constants that esbuild may strip from the browserify-zlib bundle. + if (typeof zlibConstants.Z_NO_FLUSH !== 'number') zlibConstants.Z_NO_FLUSH = 0; + if (typeof zlibConstants.Z_PARTIAL_FLUSH !== 'number') zlibConstants.Z_PARTIAL_FLUSH = 1; + if (typeof zlibConstants.Z_SYNC_FLUSH !== 'number') zlibConstants.Z_SYNC_FLUSH = 2; + if (typeof zlibConstants.Z_FULL_FLUSH !== 'number') zlibConstants.Z_FULL_FLUSH = 3; + if (typeof zlibConstants.Z_FINISH !== 'number') zlibConstants.Z_FINISH = 4; + if (typeof zlibConstants.Z_BLOCK !== 'number') zlibConstants.Z_BLOCK = 5; + if (typeof zlibConstants.Z_TREES !== 'number') zlibConstants.Z_TREES = 6; + if (typeof zlibConstants.Z_OK !== 'number') zlibConstants.Z_OK = 0; + if (typeof zlibConstants.Z_STREAM_END !== 'number') zlibConstants.Z_STREAM_END = 1; + if (typeof zlibConstants.Z_NEED_DICT !== 'number') zlibConstants.Z_NEED_DICT = 2; + if (typeof zlibConstants.Z_ERRNO !== 'number') zlibConstants.Z_ERRNO = -1; + if (typeof zlibConstants.Z_STREAM_ERROR !== 'number') zlibConstants.Z_STREAM_ERROR = -2; + if (typeof zlibConstants.Z_DATA_ERROR !== 'number') zlibConstants.Z_DATA_ERROR = -3; + if (typeof zlibConstants.Z_MEM_ERROR !== 'number') zlibConstants.Z_MEM_ERROR = -4; + if (typeof zlibConstants.Z_BUF_ERROR !== 'number') zlibConstants.Z_BUF_ERROR = -5; + if (typeof zlibConstants.Z_VERSION_ERROR !== 'number') zlibConstants.Z_VERSION_ERROR = -6; + if (typeof zlibConstants.Z_NO_COMPRESSION !== 'number') zlibConstants.Z_NO_COMPRESSION = 0; + if (typeof zlibConstants.Z_BEST_SPEED !== 'number') zlibConstants.Z_BEST_SPEED = 1; + if (typeof zlibConstants.Z_BEST_COMPRESSION !== 'number') zlibConstants.Z_BEST_COMPRESSION = 9; + if (typeof zlibConstants.Z_DEFAULT_COMPRESSION !== 'number') zlibConstants.Z_DEFAULT_COMPRESSION = -1; + if (typeof zlibConstants.Z_FILTERED !== 'number') zlibConstants.Z_FILTERED = 1; + if (typeof zlibConstants.Z_HUFFMAN_ONLY !== 'number') zlibConstants.Z_HUFFMAN_ONLY = 2; + if (typeof zlibConstants.Z_RLE !== 'number') zlibConstants.Z_RLE = 3; + if (typeof zlibConstants.Z_FIXED !== 'number') zlibConstants.Z_FIXED = 4; + if (typeof zlibConstants.Z_DEFAULT_STRATEGY !== 'number') zlibConstants.Z_DEFAULT_STRATEGY = 0; // Add mode constants that Node.js exposes but browserify-zlib does not. if (typeof zlibConstants.DEFLATE !== 'number') zlibConstants.DEFLATE = 1; if (typeof zlibConstants.INFLATE !== 'number') zlibConstants.INFLATE = 2; @@ -317,8 +345,8 @@ if (typeof zlibConstants.INFLATERAW !== 'number') zlibConstants.INFLATERAW = 5; if (typeof zlibConstants.UNZIP !== 'number') zlibConstants.UNZIP = 6; if (typeof zlibConstants.GUNZIP !== 'number') zlibConstants.GUNZIP = 7; - result.constants = zlibConstants; } + result.constants = zlibConstants; return result; } diff --git a/packages/core/src/generated/isolate-runtime.ts b/packages/core/src/generated/isolate-runtime.ts index ce9ef270..38fe0491 100644 --- a/packages/core/src/generated/isolate-runtime.ts +++ b/packages/core/src/generated/isolate-runtime.ts @@ -11,7 +11,7 @@ export const ISOLATE_RUNTIME_SOURCES = { "initCommonjsModuleGlobals": "\"use strict\";\n(() => {\n // ../core/isolate-runtime/src/common/global-exposure.ts\n function defineRuntimeGlobalBinding(name, value, mutable) {\n Object.defineProperty(globalThis, name, {\n value,\n writable: mutable,\n configurable: mutable,\n enumerable: true\n });\n }\n function createRuntimeGlobalExposer(mutable) {\n return (name, value) => {\n defineRuntimeGlobalBinding(name, value, mutable);\n };\n }\n function getRuntimeExposeMutableGlobal() {\n if (typeof globalThis.__runtimeExposeMutableGlobal === \"function\") {\n return globalThis.__runtimeExposeMutableGlobal;\n }\n return createRuntimeGlobalExposer(true);\n }\n\n // ../core/isolate-runtime/src/inject/init-commonjs-module-globals.ts\n var __runtimeExposeMutableGlobal = getRuntimeExposeMutableGlobal();\n __runtimeExposeMutableGlobal(\"module\", { exports: {} });\n __runtimeExposeMutableGlobal(\"exports\", globalThis.module.exports);\n})();\n", "overrideProcessCwd": "\"use strict\";\n(() => {\n // ../core/isolate-runtime/src/inject/override-process-cwd.ts\n var __cwd = globalThis.__runtimeProcessCwdOverride;\n if (typeof __cwd === \"string\") {\n process.cwd = () => __cwd;\n }\n})();\n", "overrideProcessEnv": "\"use strict\";\n(() => {\n // ../core/isolate-runtime/src/inject/override-process-env.ts\n var __envPatch = globalThis.__runtimeProcessEnvOverride;\n if (__envPatch && typeof __envPatch === \"object\") {\n Object.assign(process.env, __envPatch);\n }\n})();\n", - "requireSetup": "\"use strict\";\n(() => {\n // ../core/isolate-runtime/src/inject/require-setup.ts\n var __requireExposeCustomGlobal = typeof globalThis.__runtimeExposeCustomGlobal === \"function\" ? globalThis.__runtimeExposeCustomGlobal : function exposeCustomGlobal(name2, value) {\n Object.defineProperty(globalThis, name2, {\n value,\n writable: false,\n configurable: false,\n enumerable: true\n });\n };\n if (typeof globalThis.AbortController === \"undefined\" || typeof globalThis.AbortSignal === \"undefined\") {\n class AbortSignal {\n constructor() {\n this.aborted = false;\n this.reason = void 0;\n this.onabort = null;\n this._listeners = [];\n }\n addEventListener(type, listener) {\n if (type !== \"abort\" || typeof listener !== \"function\") return;\n this._listeners.push(listener);\n }\n removeEventListener(type, listener) {\n if (type !== \"abort\" || typeof listener !== \"function\") return;\n const index = this._listeners.indexOf(listener);\n if (index !== -1) {\n this._listeners.splice(index, 1);\n }\n }\n dispatchEvent(event) {\n if (!event || event.type !== \"abort\") return false;\n if (typeof this.onabort === \"function\") {\n try {\n this.onabort.call(this, event);\n } catch {\n }\n }\n const listeners = this._listeners.slice();\n for (const listener of listeners) {\n try {\n listener.call(this, event);\n } catch {\n }\n }\n return true;\n }\n }\n class AbortController {\n constructor() {\n this.signal = new AbortSignal();\n }\n abort(reason) {\n if (this.signal.aborted) return;\n this.signal.aborted = true;\n this.signal.reason = reason;\n this.signal.dispatchEvent({ type: \"abort\" });\n }\n }\n __requireExposeCustomGlobal(\"AbortSignal\", AbortSignal);\n __requireExposeCustomGlobal(\"AbortController\", AbortController);\n }\n if (typeof globalThis.structuredClone !== \"function\") {\n let structuredClonePolyfill = function(value) {\n if (value === null || typeof value !== \"object\") {\n return value;\n }\n if (value instanceof ArrayBuffer) {\n return value.slice(0);\n }\n if (ArrayBuffer.isView(value)) {\n if (value instanceof Uint8Array) {\n return new Uint8Array(value);\n }\n return new value.constructor(value);\n }\n return JSON.parse(JSON.stringify(value));\n };\n structuredClonePolyfill2 = structuredClonePolyfill;\n __requireExposeCustomGlobal(\"structuredClone\", structuredClonePolyfill);\n }\n var structuredClonePolyfill2;\n if (typeof globalThis.SharedArrayBuffer === \"undefined\") {\n globalThis.SharedArrayBuffer = ArrayBuffer;\n __requireExposeCustomGlobal(\"SharedArrayBuffer\", ArrayBuffer);\n }\n if (typeof globalThis.btoa !== \"function\") {\n __requireExposeCustomGlobal(\"btoa\", function btoa(input) {\n return Buffer.from(String(input), \"binary\").toString(\"base64\");\n });\n }\n if (typeof globalThis.atob !== \"function\") {\n __requireExposeCustomGlobal(\"atob\", function atob(input) {\n return Buffer.from(String(input), \"base64\").toString(\"binary\");\n });\n }\n function _dirname(p) {\n const lastSlash = p.lastIndexOf(\"/\");\n if (lastSlash === -1) return \".\";\n if (lastSlash === 0) return \"/\";\n return p.slice(0, lastSlash);\n }\n if (typeof globalThis.TextDecoder === \"function\") {\n _OrigTextDecoder = globalThis.TextDecoder;\n _utf8Aliases = {\n \"utf-8\": true,\n \"utf8\": true,\n \"unicode-1-1-utf-8\": true,\n \"ascii\": true,\n \"us-ascii\": true,\n \"iso-8859-1\": true,\n \"latin1\": true,\n \"binary\": true,\n \"windows-1252\": true,\n \"utf-16le\": true,\n \"utf-16\": true,\n \"ucs-2\": true,\n \"ucs2\": true\n };\n globalThis.TextDecoder = function TextDecoder(encoding, options) {\n var label = encoding !== void 0 ? String(encoding).toLowerCase().replace(/\\s/g, \"\") : \"utf-8\";\n if (_utf8Aliases[label]) {\n return new _OrigTextDecoder(\"utf-8\", options);\n }\n return new _OrigTextDecoder(encoding, options);\n };\n globalThis.TextDecoder.prototype = _OrigTextDecoder.prototype;\n }\n var _OrigTextDecoder;\n var _utf8Aliases;\n function _patchPolyfill(name2, result2) {\n if (typeof result2 !== \"object\" && typeof result2 !== \"function\" || result2 === null) {\n return result2;\n }\n if (name2 === \"buffer\") {\n const maxLength = typeof result2.kMaxLength === \"number\" ? result2.kMaxLength : 2147483647;\n const maxStringLength = typeof result2.kStringMaxLength === \"number\" ? result2.kStringMaxLength : 536870888;\n if (typeof result2.constants !== \"object\" || result2.constants === null) {\n result2.constants = {};\n }\n if (typeof result2.constants.MAX_LENGTH !== \"number\") {\n result2.constants.MAX_LENGTH = maxLength;\n }\n if (typeof result2.constants.MAX_STRING_LENGTH !== \"number\") {\n result2.constants.MAX_STRING_LENGTH = maxStringLength;\n }\n if (typeof result2.kMaxLength !== \"number\") {\n result2.kMaxLength = maxLength;\n }\n if (typeof result2.kStringMaxLength !== \"number\") {\n result2.kStringMaxLength = maxStringLength;\n }\n const BufferCtor = result2.Buffer;\n if ((typeof BufferCtor === \"function\" || typeof BufferCtor === \"object\") && BufferCtor !== null) {\n if (typeof BufferCtor.kMaxLength !== \"number\") {\n BufferCtor.kMaxLength = maxLength;\n }\n if (typeof BufferCtor.kStringMaxLength !== \"number\") {\n BufferCtor.kStringMaxLength = maxStringLength;\n }\n if (typeof BufferCtor.constants !== \"object\" || BufferCtor.constants === null) {\n BufferCtor.constants = result2.constants;\n }\n var proto = BufferCtor.prototype;\n if (proto && typeof proto.utf8Slice !== \"function\") {\n var encodings = [\"utf8\", \"latin1\", \"ascii\", \"hex\", \"base64\", \"ucs2\", \"utf16le\"];\n for (var ei = 0; ei < encodings.length; ei++) {\n var enc = encodings[ei];\n (function(e) {\n if (typeof proto[e + \"Slice\"] !== \"function\") {\n proto[e + \"Slice\"] = function(start, end) {\n return this.toString(e, start, end);\n };\n }\n if (typeof proto[e + \"Write\"] !== \"function\") {\n proto[e + \"Write\"] = function(string, offset, length) {\n return this.write(string, offset, length, e);\n };\n }\n })(enc);\n }\n }\n }\n return result2;\n }\n if (name2 === \"util\" && typeof result2.formatWithOptions === \"undefined\" && typeof result2.format === \"function\") {\n result2.formatWithOptions = function formatWithOptions(inspectOptions, ...args) {\n return result2.format.apply(null, args);\n };\n }\n if (name2 === \"util\") {\n return result2;\n }\n if (name2 === \"url\") {\n const OriginalURL = result2.URL;\n if (typeof OriginalURL !== \"function\" || OriginalURL._patched) {\n return result2;\n }\n const PatchedURL = function PatchedURL2(url, base) {\n if (typeof url === \"string\" && url.startsWith(\"file:\") && !url.startsWith(\"file://\") && base === void 0) {\n if (typeof process !== \"undefined\" && typeof process.cwd === \"function\") {\n const cwd = process.cwd();\n if (cwd) {\n try {\n return new OriginalURL(url, \"file://\" + cwd + \"/\");\n } catch (e) {\n }\n }\n }\n }\n return base !== void 0 ? new OriginalURL(url, base) : new OriginalURL(url);\n };\n Object.keys(OriginalURL).forEach(function(key) {\n try {\n PatchedURL[key] = OriginalURL[key];\n } catch {\n }\n });\n Object.setPrototypeOf(PatchedURL, OriginalURL);\n PatchedURL.prototype = OriginalURL.prototype;\n PatchedURL._patched = true;\n const descriptor = Object.getOwnPropertyDescriptor(result2, \"URL\");\n if (descriptor && descriptor.configurable !== true && descriptor.writable !== true && typeof descriptor.set !== \"function\") {\n return result2;\n }\n try {\n result2.URL = PatchedURL;\n } catch {\n try {\n Object.defineProperty(result2, \"URL\", {\n value: PatchedURL,\n writable: true,\n configurable: true,\n enumerable: descriptor?.enumerable ?? true\n });\n } catch {\n }\n }\n return result2;\n }\n if (name2 === \"zlib\") {\n if (typeof result2.constants !== \"object\" || result2.constants === null) {\n var zlibConstants = {};\n var constKeys = Object.keys(result2);\n for (var ci = 0; ci < constKeys.length; ci++) {\n var ck = constKeys[ci];\n if (ck.indexOf(\"Z_\") === 0 && typeof result2[ck] === \"number\") {\n zlibConstants[ck] = result2[ck];\n }\n }\n if (typeof zlibConstants.DEFLATE !== \"number\") zlibConstants.DEFLATE = 1;\n if (typeof zlibConstants.INFLATE !== \"number\") zlibConstants.INFLATE = 2;\n if (typeof zlibConstants.GZIP !== \"number\") zlibConstants.GZIP = 3;\n if (typeof zlibConstants.DEFLATERAW !== \"number\") zlibConstants.DEFLATERAW = 4;\n if (typeof zlibConstants.INFLATERAW !== \"number\") zlibConstants.INFLATERAW = 5;\n if (typeof zlibConstants.UNZIP !== \"number\") zlibConstants.UNZIP = 6;\n if (typeof zlibConstants.GUNZIP !== \"number\") zlibConstants.GUNZIP = 7;\n result2.constants = zlibConstants;\n }\n return result2;\n }\n if (name2 === \"crypto\") {\n let createCryptoRangeError2 = function(name3, message) {\n var error = new RangeError(message);\n error.code = \"ERR_OUT_OF_RANGE\";\n error.name = \"RangeError\";\n return error;\n }, createCryptoError2 = function(code, message) {\n var error = new Error(message);\n error.code = code;\n return error;\n }, encodeCryptoResult2 = function(buffer, encoding) {\n if (!encoding || encoding === \"buffer\") return buffer;\n return buffer.toString(encoding);\n }, isSharedArrayBufferInstance2 = function(value) {\n return typeof SharedArrayBuffer !== \"undefined\" && value instanceof SharedArrayBuffer;\n }, isBinaryLike2 = function(value) {\n return Buffer.isBuffer(value) || ArrayBuffer.isView(value) || value instanceof ArrayBuffer || isSharedArrayBufferInstance2(value);\n }, normalizeByteSource2 = function(value, name3, options) {\n var allowNull = options && options.allowNull;\n if (allowNull && value === null) {\n return null;\n }\n if (typeof value === \"string\") {\n return Buffer.from(value, \"utf8\");\n }\n if (Buffer.isBuffer(value)) {\n return Buffer.from(value);\n }\n if (ArrayBuffer.isView(value)) {\n return Buffer.from(value.buffer, value.byteOffset, value.byteLength);\n }\n if (value instanceof ArrayBuffer || isSharedArrayBufferInstance2(value)) {\n return Buffer.from(value);\n }\n throw createInvalidArgTypeError(\n name3,\n \"of type string or an instance of ArrayBuffer, Buffer, TypedArray, or DataView\",\n value\n );\n }, serializeCipherBridgeOptions2 = function(options) {\n if (!options) {\n return \"\";\n }\n var serialized = {};\n if (options.authTagLength !== void 0) {\n serialized.authTagLength = options.authTagLength;\n }\n if (options.authTag) {\n serialized.authTag = options.authTag.toString(\"base64\");\n }\n if (options.aad) {\n serialized.aad = options.aad.toString(\"base64\");\n }\n if (options.aadOptions !== void 0) {\n serialized.aadOptions = options.aadOptions;\n }\n if (options.autoPadding !== void 0) {\n serialized.autoPadding = options.autoPadding;\n }\n if (options.validateOnly !== void 0) {\n serialized.validateOnly = options.validateOnly;\n }\n return JSON.stringify(serialized);\n };\n var createCryptoRangeError = createCryptoRangeError2, createCryptoError = createCryptoError2, encodeCryptoResult = encodeCryptoResult2, isSharedArrayBufferInstance = isSharedArrayBufferInstance2, isBinaryLike = isBinaryLike2, normalizeByteSource = normalizeByteSource2, serializeCipherBridgeOptions = serializeCipherBridgeOptions2;\n var _runtimeRequire = globalThis.require;\n var _streamModule = _runtimeRequire && _runtimeRequire(\"stream\");\n var _utilModule = _runtimeRequire && _runtimeRequire(\"util\");\n var _Transform = _streamModule && _streamModule.Transform;\n var _inherits = _utilModule && _utilModule.inherits;\n if (typeof _cryptoHashDigest !== \"undefined\") {\n let SandboxHash2 = function(algorithm, options) {\n if (!(this instanceof SandboxHash2)) {\n return new SandboxHash2(algorithm, options);\n }\n if (!_Transform || !_inherits) {\n throw new Error(\"stream.Transform is required for crypto.Hash\");\n }\n if (typeof algorithm !== \"string\") {\n throw createInvalidArgTypeError(\"algorithm\", \"of type string\", algorithm);\n }\n _Transform.call(this, options);\n this._algorithm = algorithm;\n this._chunks = [];\n this._finalized = false;\n this._cachedDigest = null;\n this._allowCachedDigest = false;\n };\n var SandboxHash = SandboxHash2;\n _inherits(SandboxHash2, _Transform);\n SandboxHash2.prototype.update = function update(data, inputEncoding) {\n if (this._finalized) {\n throw createCryptoError2(\"ERR_CRYPTO_HASH_FINALIZED\", \"Digest already called\");\n }\n if (typeof data === \"string\") {\n this._chunks.push(Buffer.from(data, inputEncoding || \"utf8\"));\n } else if (isBinaryLike2(data)) {\n this._chunks.push(Buffer.from(data));\n } else {\n throw createInvalidArgTypeError(\n \"data\",\n \"one of type string, Buffer, TypedArray, or DataView\",\n data\n );\n }\n return this;\n };\n SandboxHash2.prototype._finishDigest = function _finishDigest() {\n if (this._cachedDigest) {\n return this._cachedDigest;\n }\n var combined = Buffer.concat(this._chunks);\n var resultBase64 = _cryptoHashDigest.applySync(void 0, [\n this._algorithm,\n combined.toString(\"base64\")\n ]);\n this._cachedDigest = Buffer.from(resultBase64, \"base64\");\n this._finalized = true;\n return this._cachedDigest;\n };\n SandboxHash2.prototype.digest = function digest(encoding) {\n if (this._finalized && !this._allowCachedDigest) {\n throw createCryptoError2(\"ERR_CRYPTO_HASH_FINALIZED\", \"Digest already called\");\n }\n var resultBuffer = this._finishDigest();\n this._allowCachedDigest = false;\n return encodeCryptoResult2(resultBuffer, encoding);\n };\n SandboxHash2.prototype.copy = function copy() {\n if (this._finalized) {\n throw createCryptoError2(\"ERR_CRYPTO_HASH_FINALIZED\", \"Digest already called\");\n }\n var c = new SandboxHash2(this._algorithm);\n c._chunks = this._chunks.slice();\n return c;\n };\n SandboxHash2.prototype._transform = function _transform(chunk, encoding, callback) {\n try {\n this.update(chunk, encoding === \"buffer\" ? void 0 : encoding);\n callback();\n } catch (error) {\n callback(normalizeCryptoBridgeError(error));\n }\n };\n SandboxHash2.prototype._flush = function _flush(callback) {\n try {\n var output = this._finishDigest();\n this._allowCachedDigest = true;\n this.push(output);\n callback();\n } catch (error) {\n callback(normalizeCryptoBridgeError(error));\n }\n };\n result2.createHash = function createHash(algorithm, options) {\n return new SandboxHash2(algorithm, options);\n };\n result2.Hash = SandboxHash2;\n }\n if (typeof _cryptoHmacDigest !== \"undefined\") {\n let SandboxHmac2 = function(algorithm, key) {\n this._algorithm = algorithm;\n if (typeof key === \"string\") {\n this._key = Buffer.from(key, \"utf8\");\n } else if (key && typeof key === \"object\" && key._raw !== void 0) {\n this._key = Buffer.from(key._raw, \"base64\");\n } else if (key && typeof key === \"object\" && key._pem !== void 0) {\n this._key = Buffer.from(key._pem, \"utf8\");\n } else {\n this._key = Buffer.from(key);\n }\n this._chunks = [];\n };\n var SandboxHmac = SandboxHmac2;\n SandboxHmac2.prototype.update = function update(data, inputEncoding) {\n if (typeof data === \"string\") {\n this._chunks.push(Buffer.from(data, inputEncoding || \"utf8\"));\n } else {\n this._chunks.push(Buffer.from(data));\n }\n return this;\n };\n SandboxHmac2.prototype.digest = function digest(encoding) {\n var combined = Buffer.concat(this._chunks);\n var resultBase64 = _cryptoHmacDigest.applySync(void 0, [\n this._algorithm,\n this._key.toString(\"base64\"),\n combined.toString(\"base64\")\n ]);\n var resultBuffer = Buffer.from(resultBase64, \"base64\");\n if (!encoding || encoding === \"buffer\") return resultBuffer;\n return resultBuffer.toString(encoding);\n };\n SandboxHmac2.prototype.copy = function copy() {\n var c = new SandboxHmac2(this._algorithm, this._key);\n c._chunks = this._chunks.slice();\n return c;\n };\n SandboxHmac2.prototype.write = function write(data, encoding) {\n this.update(data, encoding);\n return true;\n };\n SandboxHmac2.prototype.end = function end(data, encoding) {\n if (data) this.update(data, encoding);\n };\n result2.createHmac = function createHmac(algorithm, key) {\n return new SandboxHmac2(algorithm, key);\n };\n result2.Hmac = SandboxHmac2;\n }\n if (typeof _cryptoRandomFill !== \"undefined\") {\n result2.randomBytes = function randomBytes(size, callback) {\n if (typeof size !== \"number\" || size < 0 || size !== (size | 0)) {\n var err = new TypeError('The \"size\" argument must be of type number. Received type ' + typeof size);\n if (typeof callback === \"function\") {\n callback(err);\n return;\n }\n throw err;\n }\n if (size > 2147483647) {\n var rangeErr = new RangeError('The value of \"size\" is out of range. It must be >= 0 && <= 2147483647. Received ' + size);\n if (typeof callback === \"function\") {\n callback(rangeErr);\n return;\n }\n throw rangeErr;\n }\n var buf = Buffer.alloc(size);\n var offset = 0;\n while (offset < size) {\n var chunk = Math.min(size - offset, 65536);\n var base64 = _cryptoRandomFill.applySync(void 0, [chunk]);\n var hostBytes = Buffer.from(base64, \"base64\");\n hostBytes.copy(buf, offset);\n offset += chunk;\n }\n if (typeof callback === \"function\") {\n callback(null, buf);\n return;\n }\n return buf;\n };\n result2.randomFillSync = function randomFillSync(buffer, offset, size) {\n if (offset === void 0) offset = 0;\n var byteLength = buffer.byteLength !== void 0 ? buffer.byteLength : buffer.length;\n if (size === void 0) size = byteLength - offset;\n if (offset < 0 || size < 0 || offset + size > byteLength) {\n throw new RangeError('The value of \"offset + size\" is out of range.');\n }\n var bytes = new Uint8Array(buffer.buffer || buffer, buffer.byteOffset ? buffer.byteOffset + offset : offset, size);\n var filled = 0;\n while (filled < size) {\n var chunk = Math.min(size - filled, 65536);\n var base64 = _cryptoRandomFill.applySync(void 0, [chunk]);\n var hostBytes = Buffer.from(base64, \"base64\");\n bytes.set(hostBytes, filled);\n filled += chunk;\n }\n return buffer;\n };\n result2.randomFill = function randomFill(buffer, offsetOrCb, sizeOrCb, callback) {\n var offset = 0;\n var size;\n var cb;\n if (typeof offsetOrCb === \"function\") {\n cb = offsetOrCb;\n } else if (typeof sizeOrCb === \"function\") {\n offset = offsetOrCb || 0;\n cb = sizeOrCb;\n } else {\n offset = offsetOrCb || 0;\n size = sizeOrCb;\n cb = callback;\n }\n if (typeof cb !== \"function\") {\n throw new TypeError(\"Callback must be a function\");\n }\n try {\n result2.randomFillSync(buffer, offset, size);\n cb(null, buffer);\n } catch (e) {\n cb(e);\n }\n };\n result2.randomInt = function randomInt(minOrMax, maxOrCb, callback) {\n var min, max, cb;\n if (typeof maxOrCb === \"function\" || maxOrCb === void 0) {\n min = 0;\n max = minOrMax;\n cb = maxOrCb;\n } else {\n min = minOrMax;\n max = maxOrCb;\n cb = callback;\n }\n if (!Number.isSafeInteger(min)) {\n var minErr = new TypeError('The \"min\" argument must be a safe integer');\n if (typeof cb === \"function\") {\n cb(minErr);\n return;\n }\n throw minErr;\n }\n if (!Number.isSafeInteger(max)) {\n var maxErr = new TypeError('The \"max\" argument must be a safe integer');\n if (typeof cb === \"function\") {\n cb(maxErr);\n return;\n }\n throw maxErr;\n }\n if (max <= min) {\n var rangeErr2 = new RangeError('The value of \"max\" is out of range. It must be greater than the value of \"min\" (' + min + \")\");\n if (typeof cb === \"function\") {\n cb(rangeErr2);\n return;\n }\n throw rangeErr2;\n }\n var range = max - min;\n var bytes = 6;\n var maxValid = Math.pow(2, 48) - Math.pow(2, 48) % range;\n var val;\n do {\n var base64 = _cryptoRandomFill.applySync(void 0, [bytes]);\n var buf = Buffer.from(base64, \"base64\");\n val = buf.readUIntBE(0, bytes);\n } while (val >= maxValid);\n var result22 = min + val % range;\n if (typeof cb === \"function\") {\n cb(null, result22);\n return;\n }\n return result22;\n };\n }\n if (typeof _cryptoPbkdf2 !== \"undefined\") {\n let createPbkdf2ArgTypeError2 = function(name3, value) {\n var received;\n if (value == null) {\n received = \" Received \" + value;\n } else if (typeof value === \"object\") {\n received = value.constructor && value.constructor.name ? \" Received an instance of \" + value.constructor.name : \" Received [object Object]\";\n } else {\n var inspected = typeof value === \"string\" ? \"'\" + value + \"'\" : String(value);\n received = \" Received type \" + typeof value + \" (\" + inspected + \")\";\n }\n var error = new TypeError('The \"' + name3 + '\" argument must be of type number.' + received);\n error.code = \"ERR_INVALID_ARG_TYPE\";\n return error;\n }, validatePbkdf2Args2 = function(password, salt, iterations, keylen, digest) {\n var pwBuf = normalizeByteSource2(password, \"password\");\n var saltBuf = normalizeByteSource2(salt, \"salt\");\n if (typeof iterations !== \"number\") {\n throw createPbkdf2ArgTypeError2(\"iterations\", iterations);\n }\n if (!Number.isInteger(iterations)) {\n throw createCryptoRangeError2(\n \"iterations\",\n 'The value of \"iterations\" is out of range. It must be an integer. Received ' + iterations\n );\n }\n if (iterations < 1 || iterations > 2147483647) {\n throw createCryptoRangeError2(\n \"iterations\",\n 'The value of \"iterations\" is out of range. It must be >= 1 && <= 2147483647. Received ' + iterations\n );\n }\n if (typeof keylen !== \"number\") {\n throw createPbkdf2ArgTypeError2(\"keylen\", keylen);\n }\n if (!Number.isInteger(keylen)) {\n throw createCryptoRangeError2(\n \"keylen\",\n 'The value of \"keylen\" is out of range. It must be an integer. Received ' + keylen\n );\n }\n if (keylen < 0 || keylen > 2147483647) {\n throw createCryptoRangeError2(\n \"keylen\",\n 'The value of \"keylen\" is out of range. It must be >= 0 && <= 2147483647. Received ' + keylen\n );\n }\n if (typeof digest !== \"string\") {\n throw createInvalidArgTypeError(\"digest\", \"of type string\", digest);\n }\n return {\n password: pwBuf,\n salt: saltBuf\n };\n };\n var createPbkdf2ArgTypeError = createPbkdf2ArgTypeError2, validatePbkdf2Args = validatePbkdf2Args2;\n result2.pbkdf2Sync = function pbkdf2Sync(password, salt, iterations, keylen, digest) {\n var normalized = validatePbkdf2Args2(password, salt, iterations, keylen, digest);\n try {\n var resultBase64 = _cryptoPbkdf2.applySync(void 0, [\n normalized.password.toString(\"base64\"),\n normalized.salt.toString(\"base64\"),\n iterations,\n keylen,\n digest\n ]);\n return Buffer.from(resultBase64, \"base64\");\n } catch (error) {\n throw normalizeCryptoBridgeError(error);\n }\n };\n result2.pbkdf2 = function pbkdf2(password, salt, iterations, keylen, digest, callback) {\n if (typeof digest === \"function\" && callback === void 0) {\n callback = digest;\n digest = void 0;\n }\n if (typeof callback !== \"function\") {\n throw createInvalidArgTypeError(\"callback\", \"of type function\", callback);\n }\n try {\n var derived = result2.pbkdf2Sync(password, salt, iterations, keylen, digest);\n scheduleCryptoCallback(callback, [null, derived]);\n } catch (e) {\n throw normalizeCryptoBridgeError(e);\n }\n };\n }\n if (typeof _cryptoScrypt !== \"undefined\") {\n result2.scryptSync = function scryptSync(password, salt, keylen, options) {\n var pwBuf = typeof password === \"string\" ? Buffer.from(password, \"utf8\") : Buffer.from(password);\n var saltBuf = typeof salt === \"string\" ? Buffer.from(salt, \"utf8\") : Buffer.from(salt);\n var opts = {};\n if (options) {\n if (options.N !== void 0) opts.N = options.N;\n if (options.r !== void 0) opts.r = options.r;\n if (options.p !== void 0) opts.p = options.p;\n if (options.maxmem !== void 0) opts.maxmem = options.maxmem;\n if (options.cost !== void 0) opts.N = options.cost;\n if (options.blockSize !== void 0) opts.r = options.blockSize;\n if (options.parallelization !== void 0) opts.p = options.parallelization;\n }\n var resultBase64 = _cryptoScrypt.applySync(void 0, [\n pwBuf.toString(\"base64\"),\n saltBuf.toString(\"base64\"),\n keylen,\n JSON.stringify(opts)\n ]);\n return Buffer.from(resultBase64, \"base64\");\n };\n result2.scrypt = function scrypt(password, salt, keylen, optionsOrCb, callback) {\n var opts = optionsOrCb;\n var cb = callback;\n if (typeof optionsOrCb === \"function\") {\n opts = void 0;\n cb = optionsOrCb;\n }\n try {\n var derived = result2.scryptSync(password, salt, keylen, opts);\n cb(null, derived);\n } catch (e) {\n cb(e);\n }\n };\n }\n if (typeof _cryptoCipheriv !== \"undefined\") {\n let SandboxCipher2 = function(algorithm, key, iv, options) {\n if (!(this instanceof SandboxCipher2)) {\n return new SandboxCipher2(algorithm, key, iv, options);\n }\n if (typeof algorithm !== \"string\") {\n throw createInvalidArgTypeError(\"cipher\", \"of type string\", algorithm);\n }\n _Transform.call(this);\n this._algorithm = algorithm;\n this._key = normalizeByteSource2(key, \"key\");\n this._iv = normalizeByteSource2(iv, \"iv\", { allowNull: true });\n this._options = options || void 0;\n this._authTag = null;\n this._finalized = false;\n this._sessionCreated = false;\n this._sessionId = void 0;\n this._aad = null;\n this._aadOptions = void 0;\n this._autoPadding = void 0;\n this._chunks = [];\n this._bufferedMode = !_useSessionCipher || !!options;\n if (!this._bufferedMode) {\n this._ensureSession();\n } else if (!options) {\n _cryptoCipheriv.applySync(void 0, [\n this._algorithm,\n this._key.toString(\"base64\"),\n this._iv === null ? null : this._iv.toString(\"base64\"),\n \"\",\n serializeCipherBridgeOptions2({ validateOnly: true })\n ]);\n }\n };\n var SandboxCipher = SandboxCipher2;\n var _useSessionCipher = typeof _cryptoCipherivCreate !== \"undefined\";\n _inherits(SandboxCipher2, _Transform);\n SandboxCipher2.prototype._ensureSession = function _ensureSession() {\n if (this._bufferedMode || this._sessionCreated) {\n return;\n }\n this._sessionCreated = true;\n this._sessionId = _cryptoCipherivCreate.applySync(void 0, [\n \"cipher\",\n this._algorithm,\n this._key.toString(\"base64\"),\n this._iv === null ? null : this._iv.toString(\"base64\"),\n serializeCipherBridgeOptions2(this._getBridgeOptions())\n ]);\n };\n SandboxCipher2.prototype._getBridgeOptions = function _getBridgeOptions() {\n var options = {};\n if (this._options && this._options.authTagLength !== void 0) {\n options.authTagLength = this._options.authTagLength;\n }\n if (this._aad) {\n options.aad = this._aad;\n }\n if (this._aadOptions !== void 0) {\n options.aadOptions = this._aadOptions;\n }\n if (this._autoPadding !== void 0) {\n options.autoPadding = this._autoPadding;\n }\n return Object.keys(options).length === 0 ? null : options;\n };\n SandboxCipher2.prototype.update = function update(data, inputEncoding, outputEncoding) {\n if (this._finalized) {\n throw new Error(\"Attempting to call update() after final()\");\n }\n var buf;\n if (typeof data === \"string\") {\n buf = Buffer.from(data, inputEncoding || \"utf8\");\n } else {\n buf = normalizeByteSource2(data, \"data\");\n }\n if (!this._bufferedMode) {\n this._ensureSession();\n var resultBase64 = _cryptoCipherivUpdate.applySync(void 0, [this._sessionId, buf.toString(\"base64\")]);\n var resultBuffer = Buffer.from(resultBase64, \"base64\");\n return encodeCryptoResult2(resultBuffer, outputEncoding);\n }\n this._chunks.push(buf);\n return encodeCryptoResult2(Buffer.alloc(0), outputEncoding);\n };\n SandboxCipher2.prototype.final = function final(outputEncoding) {\n if (this._finalized) throw new Error(\"Attempting to call final() after already finalized\");\n this._finalized = true;\n var parsed;\n if (!this._bufferedMode) {\n this._ensureSession();\n var resultJson = _cryptoCipherivFinal.applySync(void 0, [this._sessionId]);\n parsed = JSON.parse(resultJson);\n } else {\n var combined = Buffer.concat(this._chunks);\n var resultJson2 = _cryptoCipheriv.applySync(void 0, [\n this._algorithm,\n this._key.toString(\"base64\"),\n this._iv === null ? null : this._iv.toString(\"base64\"),\n combined.toString(\"base64\"),\n serializeCipherBridgeOptions2(this._getBridgeOptions())\n ]);\n parsed = JSON.parse(resultJson2);\n }\n if (parsed.authTag) {\n this._authTag = Buffer.from(parsed.authTag, \"base64\");\n }\n var resultBuffer = Buffer.from(parsed.data, \"base64\");\n return encodeCryptoResult2(resultBuffer, outputEncoding);\n };\n SandboxCipher2.prototype.getAuthTag = function getAuthTag() {\n if (!this._finalized) throw new Error(\"Cannot call getAuthTag before final()\");\n if (!this._authTag) throw new Error(\"Auth tag is not available\");\n return this._authTag;\n };\n SandboxCipher2.prototype.setAAD = function setAAD(aad, options) {\n this._bufferedMode = true;\n this._aad = normalizeByteSource2(aad, \"buffer\");\n this._aadOptions = options;\n return this;\n };\n SandboxCipher2.prototype.setAutoPadding = function setAutoPadding(autoPadding) {\n this._bufferedMode = true;\n this._autoPadding = autoPadding !== false;\n return this;\n };\n SandboxCipher2.prototype._transform = function _transform(chunk, encoding, callback) {\n try {\n var output = this.update(chunk, encoding === \"buffer\" ? void 0 : encoding);\n if (output.length) {\n this.push(output);\n }\n callback();\n } catch (error) {\n callback(normalizeCryptoBridgeError(error));\n }\n };\n SandboxCipher2.prototype._flush = function _flush(callback) {\n try {\n var output = this.final();\n if (output.length) {\n this.push(output);\n }\n callback();\n } catch (error) {\n callback(normalizeCryptoBridgeError(error));\n }\n };\n result2.createCipheriv = function createCipheriv(algorithm, key, iv, options) {\n return new SandboxCipher2(algorithm, key, iv, options);\n };\n result2.Cipheriv = SandboxCipher2;\n }\n if (typeof _cryptoDecipheriv !== \"undefined\") {\n let SandboxDecipher2 = function(algorithm, key, iv, options) {\n if (!(this instanceof SandboxDecipher2)) {\n return new SandboxDecipher2(algorithm, key, iv, options);\n }\n if (typeof algorithm !== \"string\") {\n throw createInvalidArgTypeError(\"cipher\", \"of type string\", algorithm);\n }\n _Transform.call(this);\n this._algorithm = algorithm;\n this._key = normalizeByteSource2(key, \"key\");\n this._iv = normalizeByteSource2(iv, \"iv\", { allowNull: true });\n this._options = options || void 0;\n this._authTag = null;\n this._finalized = false;\n this._sessionCreated = false;\n this._aad = null;\n this._aadOptions = void 0;\n this._autoPadding = void 0;\n this._chunks = [];\n this._bufferedMode = !_useSessionCipher || !!options;\n if (!this._bufferedMode) {\n this._ensureSession();\n } else if (!options) {\n _cryptoDecipheriv.applySync(void 0, [\n this._algorithm,\n this._key.toString(\"base64\"),\n this._iv === null ? null : this._iv.toString(\"base64\"),\n \"\",\n serializeCipherBridgeOptions2({ validateOnly: true })\n ]);\n }\n };\n var SandboxDecipher = SandboxDecipher2;\n _inherits(SandboxDecipher2, _Transform);\n SandboxDecipher2.prototype._ensureSession = function _ensureSession() {\n if (!this._bufferedMode && !this._sessionCreated) {\n this._sessionCreated = true;\n this._sessionId = _cryptoCipherivCreate.applySync(void 0, [\n \"decipher\",\n this._algorithm,\n this._key.toString(\"base64\"),\n this._iv === null ? null : this._iv.toString(\"base64\"),\n serializeCipherBridgeOptions2(this._getBridgeOptions())\n ]);\n }\n };\n SandboxDecipher2.prototype._getBridgeOptions = function _getBridgeOptions() {\n var options = {};\n if (this._options && this._options.authTagLength !== void 0) {\n options.authTagLength = this._options.authTagLength;\n }\n if (this._authTag) {\n options.authTag = this._authTag;\n }\n if (this._aad) {\n options.aad = this._aad;\n }\n if (this._aadOptions !== void 0) {\n options.aadOptions = this._aadOptions;\n }\n if (this._autoPadding !== void 0) {\n options.autoPadding = this._autoPadding;\n }\n return Object.keys(options).length === 0 ? null : options;\n };\n SandboxDecipher2.prototype.update = function update(data, inputEncoding, outputEncoding) {\n if (this._finalized) {\n throw new Error(\"Attempting to call update() after final()\");\n }\n var buf;\n if (typeof data === \"string\") {\n buf = Buffer.from(data, inputEncoding || \"utf8\");\n } else {\n buf = normalizeByteSource2(data, \"data\");\n }\n if (!this._bufferedMode) {\n this._ensureSession();\n var resultBase64 = _cryptoCipherivUpdate.applySync(void 0, [this._sessionId, buf.toString(\"base64\")]);\n var resultBuffer = Buffer.from(resultBase64, \"base64\");\n return encodeCryptoResult2(resultBuffer, outputEncoding);\n }\n this._chunks.push(buf);\n return encodeCryptoResult2(Buffer.alloc(0), outputEncoding);\n };\n SandboxDecipher2.prototype.final = function final(outputEncoding) {\n if (this._finalized) throw new Error(\"Attempting to call final() after already finalized\");\n this._finalized = true;\n var resultBuffer;\n if (!this._bufferedMode) {\n this._ensureSession();\n var resultJson = _cryptoCipherivFinal.applySync(void 0, [this._sessionId]);\n var parsed = JSON.parse(resultJson);\n resultBuffer = Buffer.from(parsed.data, \"base64\");\n } else {\n var combined = Buffer.concat(this._chunks);\n var options = {};\n var resultBase64 = _cryptoDecipheriv.applySync(void 0, [\n this._algorithm,\n this._key.toString(\"base64\"),\n this._iv === null ? null : this._iv.toString(\"base64\"),\n combined.toString(\"base64\"),\n serializeCipherBridgeOptions2(this._getBridgeOptions())\n ]);\n resultBuffer = Buffer.from(resultBase64, \"base64\");\n }\n return encodeCryptoResult2(resultBuffer, outputEncoding);\n };\n SandboxDecipher2.prototype.setAuthTag = function setAuthTag(tag) {\n this._bufferedMode = true;\n this._authTag = typeof tag === \"string\" ? Buffer.from(tag, \"base64\") : normalizeByteSource2(tag, \"buffer\");\n return this;\n };\n SandboxDecipher2.prototype.setAAD = function setAAD(aad, options) {\n this._bufferedMode = true;\n this._aad = normalizeByteSource2(aad, \"buffer\");\n this._aadOptions = options;\n return this;\n };\n SandboxDecipher2.prototype.setAutoPadding = function setAutoPadding(autoPadding) {\n this._bufferedMode = true;\n this._autoPadding = autoPadding !== false;\n return this;\n };\n SandboxDecipher2.prototype._transform = function _transform(chunk, encoding, callback) {\n try {\n var output = this.update(chunk, encoding === \"buffer\" ? void 0 : encoding);\n if (output.length) {\n this.push(output);\n }\n callback();\n } catch (error) {\n callback(normalizeCryptoBridgeError(error));\n }\n };\n SandboxDecipher2.prototype._flush = function _flush(callback) {\n try {\n var output = this.final();\n if (output.length) {\n this.push(output);\n }\n callback();\n } catch (error) {\n callback(normalizeCryptoBridgeError(error));\n }\n };\n result2.createDecipheriv = function createDecipheriv(algorithm, key, iv, options) {\n return new SandboxDecipher2(algorithm, key, iv, options);\n };\n result2.Decipheriv = SandboxDecipher2;\n }\n if (typeof _cryptoSign !== \"undefined\") {\n result2.sign = function sign(algorithm, data, key) {\n var dataBuf = typeof data === \"string\" ? Buffer.from(data, \"utf8\") : Buffer.from(data);\n var sigBase64;\n try {\n sigBase64 = _cryptoSign.applySync(void 0, [\n algorithm === void 0 ? null : algorithm,\n dataBuf.toString(\"base64\"),\n JSON.stringify(serializeBridgeValue(key))\n ]);\n } catch (error) {\n throw normalizeCryptoBridgeError(error);\n }\n return Buffer.from(sigBase64, \"base64\");\n };\n }\n if (typeof _cryptoVerify !== \"undefined\") {\n result2.verify = function verify(algorithm, data, key, signature) {\n var dataBuf = typeof data === \"string\" ? Buffer.from(data, \"utf8\") : Buffer.from(data);\n var sigBuf = typeof signature === \"string\" ? Buffer.from(signature, \"base64\") : Buffer.from(signature);\n try {\n return _cryptoVerify.applySync(void 0, [\n algorithm === void 0 ? null : algorithm,\n dataBuf.toString(\"base64\"),\n JSON.stringify(serializeBridgeValue(key)),\n sigBuf.toString(\"base64\")\n ]);\n } catch (error) {\n throw normalizeCryptoBridgeError(error);\n }\n };\n }\n if (typeof _cryptoAsymmetricOp !== \"undefined\") {\n let asymmetricBridgeCall2 = function(operation, key, data) {\n var dataBuf = toRawBuffer(data);\n var resultBase64;\n try {\n resultBase64 = _cryptoAsymmetricOp.applySync(void 0, [\n operation,\n JSON.stringify(serializeBridgeValue(key)),\n dataBuf.toString(\"base64\")\n ]);\n } catch (error) {\n throw normalizeCryptoBridgeError(error);\n }\n return Buffer.from(resultBase64, \"base64\");\n };\n var asymmetricBridgeCall = asymmetricBridgeCall2;\n result2.publicEncrypt = function publicEncrypt(key, data) {\n return asymmetricBridgeCall2(\"publicEncrypt\", key, data);\n };\n result2.privateDecrypt = function privateDecrypt(key, data) {\n return asymmetricBridgeCall2(\"privateDecrypt\", key, data);\n };\n result2.privateEncrypt = function privateEncrypt(key, data) {\n return asymmetricBridgeCall2(\"privateEncrypt\", key, data);\n };\n result2.publicDecrypt = function publicDecrypt(key, data) {\n return asymmetricBridgeCall2(\"publicDecrypt\", key, data);\n };\n }\n if (typeof _cryptoDiffieHellmanSessionCreate !== \"undefined\" && typeof _cryptoDiffieHellmanSessionCall !== \"undefined\") {\n let serializeDhKeyObject2 = function(value) {\n if (value.type === \"secret\") {\n return {\n type: \"secret\",\n raw: Buffer.from(value.export()).toString(\"base64\")\n };\n }\n return {\n type: value.type,\n pem: value._pem || value.export({\n type: value.type === \"private\" ? \"pkcs8\" : \"spki\",\n format: \"pem\"\n })\n };\n }, serializeDhValue2 = function(value) {\n if (value === null || typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n return value;\n }\n if (Buffer.isBuffer(value)) {\n return {\n __type: \"buffer\",\n value: Buffer.from(value).toString(\"base64\")\n };\n }\n if (value instanceof ArrayBuffer) {\n return {\n __type: \"buffer\",\n value: Buffer.from(new Uint8Array(value)).toString(\"base64\")\n };\n }\n if (ArrayBuffer.isView(value)) {\n return {\n __type: \"buffer\",\n value: Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString(\"base64\")\n };\n }\n if (typeof value === \"bigint\") {\n return {\n __type: \"bigint\",\n value: value.toString()\n };\n }\n if (value && typeof value === \"object\" && (value.type === \"public\" || value.type === \"private\" || value.type === \"secret\") && typeof value.export === \"function\") {\n return {\n __type: \"keyObject\",\n value: serializeDhKeyObject2(value)\n };\n }\n if (Array.isArray(value)) {\n return value.map(serializeDhValue2);\n }\n if (value && typeof value === \"object\") {\n var output = {};\n var keys = Object.keys(value);\n for (var i = 0; i < keys.length; i++) {\n if (value[keys[i]] !== void 0) {\n output[keys[i]] = serializeDhValue2(value[keys[i]]);\n }\n }\n return output;\n }\n return String(value);\n }, restoreDhValue2 = function(value) {\n if (!value || typeof value !== \"object\") {\n return value;\n }\n if (value.__type === \"buffer\") {\n return Buffer.from(value.value, \"base64\");\n }\n if (value.__type === \"bigint\") {\n return BigInt(value.value);\n }\n if (Array.isArray(value)) {\n return value.map(restoreDhValue2);\n }\n var output = {};\n var keys = Object.keys(value);\n for (var i = 0; i < keys.length; i++) {\n output[keys[i]] = restoreDhValue2(value[keys[i]]);\n }\n return output;\n }, createDhSession2 = function(type, name3, argsLike) {\n var args = [];\n for (var i = 0; i < argsLike.length; i++) {\n args.push(serializeDhValue2(argsLike[i]));\n }\n return _cryptoDiffieHellmanSessionCreate.applySync(void 0, [\n JSON.stringify({\n type,\n name: name3,\n args\n })\n ]);\n }, callDhSession2 = function(sessionId, method, argsLike) {\n var args = [];\n for (var i = 0; i < argsLike.length; i++) {\n args.push(serializeDhValue2(argsLike[i]));\n }\n var response = JSON.parse(_cryptoDiffieHellmanSessionCall.applySync(void 0, [\n sessionId,\n JSON.stringify({\n method,\n args\n })\n ]));\n if (response && response.hasResult === false) {\n return void 0;\n }\n return restoreDhValue2(response && response.result);\n }, SandboxDiffieHellman2 = function(sessionId) {\n this._sessionId = sessionId;\n }, SandboxECDH2 = function(sessionId) {\n SandboxDiffieHellman2.call(this, sessionId);\n };\n var serializeDhKeyObject = serializeDhKeyObject2, serializeDhValue = serializeDhValue2, restoreDhValue = restoreDhValue2, createDhSession = createDhSession2, callDhSession = callDhSession2, SandboxDiffieHellman = SandboxDiffieHellman2, SandboxECDH = SandboxECDH2;\n Object.defineProperty(SandboxDiffieHellman2.prototype, \"verifyError\", {\n get: function getVerifyError() {\n return callDhSession2(this._sessionId, \"verifyError\", []);\n }\n });\n SandboxDiffieHellman2.prototype.generateKeys = function generateKeys(encoding) {\n if (arguments.length === 0) return callDhSession2(this._sessionId, \"generateKeys\", []);\n return callDhSession2(this._sessionId, \"generateKeys\", [encoding]);\n };\n SandboxDiffieHellman2.prototype.computeSecret = function computeSecret(key, inputEncoding, outputEncoding) {\n return callDhSession2(this._sessionId, \"computeSecret\", Array.prototype.slice.call(arguments));\n };\n SandboxDiffieHellman2.prototype.getPrime = function getPrime(encoding) {\n if (arguments.length === 0) return callDhSession2(this._sessionId, \"getPrime\", []);\n return callDhSession2(this._sessionId, \"getPrime\", [encoding]);\n };\n SandboxDiffieHellman2.prototype.getGenerator = function getGenerator(encoding) {\n if (arguments.length === 0) return callDhSession2(this._sessionId, \"getGenerator\", []);\n return callDhSession2(this._sessionId, \"getGenerator\", [encoding]);\n };\n SandboxDiffieHellman2.prototype.getPublicKey = function getPublicKey(encoding) {\n if (arguments.length === 0) return callDhSession2(this._sessionId, \"getPublicKey\", []);\n return callDhSession2(this._sessionId, \"getPublicKey\", [encoding]);\n };\n SandboxDiffieHellman2.prototype.getPrivateKey = function getPrivateKey(encoding) {\n if (arguments.length === 0) return callDhSession2(this._sessionId, \"getPrivateKey\", []);\n return callDhSession2(this._sessionId, \"getPrivateKey\", [encoding]);\n };\n SandboxDiffieHellman2.prototype.setPublicKey = function setPublicKey(key, encoding) {\n return callDhSession2(this._sessionId, \"setPublicKey\", Array.prototype.slice.call(arguments));\n };\n SandboxDiffieHellman2.prototype.setPrivateKey = function setPrivateKey(key, encoding) {\n return callDhSession2(this._sessionId, \"setPrivateKey\", Array.prototype.slice.call(arguments));\n };\n SandboxECDH2.prototype = Object.create(SandboxDiffieHellman2.prototype);\n SandboxECDH2.prototype.constructor = SandboxECDH2;\n SandboxECDH2.prototype.getPublicKey = function getPublicKey(encoding, format) {\n return callDhSession2(this._sessionId, \"getPublicKey\", Array.prototype.slice.call(arguments));\n };\n result2.createDiffieHellman = function createDiffieHellman() {\n return new SandboxDiffieHellman2(createDhSession2(\"dh\", void 0, arguments));\n };\n result2.getDiffieHellman = function getDiffieHellman(name3) {\n return new SandboxDiffieHellman2(createDhSession2(\"group\", name3, []));\n };\n result2.createDiffieHellmanGroup = result2.getDiffieHellman;\n result2.createECDH = function createECDH(curve) {\n return new SandboxECDH2(createDhSession2(\"ecdh\", curve, []));\n };\n if (typeof _cryptoDiffieHellman !== \"undefined\") {\n result2.diffieHellman = function diffieHellman(options) {\n var resultJson = _cryptoDiffieHellman.applySync(void 0, [\n JSON.stringify(serializeDhValue2(options))\n ]);\n return restoreDhValue2(JSON.parse(resultJson));\n };\n }\n result2.DiffieHellman = SandboxDiffieHellman2;\n result2.DiffieHellmanGroup = SandboxDiffieHellman2;\n result2.ECDH = SandboxECDH2;\n }\n if (typeof _cryptoGenerateKeyPairSync !== \"undefined\") {\n let restoreBridgeValue2 = function(value) {\n if (!value || typeof value !== \"object\") {\n return value;\n }\n if (value.__type === \"buffer\") {\n return Buffer.from(value.value, \"base64\");\n }\n if (value.__type === \"bigint\") {\n return BigInt(value.value);\n }\n if (Array.isArray(value)) {\n return value.map(restoreBridgeValue2);\n }\n var output = {};\n var keys = Object.keys(value);\n for (var i = 0; i < keys.length; i++) {\n output[keys[i]] = restoreBridgeValue2(value[keys[i]]);\n }\n return output;\n }, cloneObject2 = function(value) {\n if (!value || typeof value !== \"object\") {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map(cloneObject2);\n }\n var output = {};\n var keys = Object.keys(value);\n for (var i = 0; i < keys.length; i++) {\n output[keys[i]] = cloneObject2(value[keys[i]]);\n }\n return output;\n }, createDomException2 = function(message, name3) {\n if (typeof DOMException === \"function\") {\n return new DOMException(message, name3);\n }\n var error = new Error(message);\n error.name = name3;\n return error;\n }, toRawBuffer2 = function(data, encoding) {\n if (Buffer.isBuffer(data)) {\n return Buffer.from(data);\n }\n if (data instanceof ArrayBuffer) {\n return Buffer.from(new Uint8Array(data));\n }\n if (ArrayBuffer.isView(data)) {\n return Buffer.from(data.buffer, data.byteOffset, data.byteLength);\n }\n if (typeof data === \"string\") {\n return Buffer.from(data, encoding || \"utf8\");\n }\n return Buffer.from(data);\n }, serializeBridgeValue2 = function(value) {\n if (value === null) {\n return null;\n }\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n return value;\n }\n if (typeof value === \"bigint\") {\n return {\n __type: \"bigint\",\n value: value.toString()\n };\n }\n if (Buffer.isBuffer(value)) {\n return {\n __type: \"buffer\",\n value: Buffer.from(value).toString(\"base64\")\n };\n }\n if (value instanceof ArrayBuffer) {\n return {\n __type: \"buffer\",\n value: Buffer.from(new Uint8Array(value)).toString(\"base64\")\n };\n }\n if (ArrayBuffer.isView(value)) {\n return {\n __type: \"buffer\",\n value: Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString(\"base64\")\n };\n }\n if (Array.isArray(value)) {\n return value.map(serializeBridgeValue2);\n }\n if (value && typeof value === \"object\" && (value.type === \"public\" || value.type === \"private\" || value.type === \"secret\") && typeof value.export === \"function\") {\n if (value.type === \"secret\") {\n return {\n __type: \"keyObject\",\n value: {\n type: \"secret\",\n raw: Buffer.from(value.export()).toString(\"base64\")\n }\n };\n }\n return {\n __type: \"keyObject\",\n value: {\n type: value.type,\n pem: value._pem\n }\n };\n }\n if (value && typeof value === \"object\") {\n var output = {};\n var keys = Object.keys(value);\n for (var i = 0; i < keys.length; i++) {\n var entry = value[keys[i]];\n if (entry !== void 0) {\n output[keys[i]] = serializeBridgeValue2(entry);\n }\n }\n return output;\n }\n return String(value);\n }, normalizeCryptoBridgeError2 = function(error) {\n if (!error || typeof error !== \"object\") {\n return error;\n }\n if (error.code === void 0 && error.message === \"error:07880109:common libcrypto routines::interrupted or cancelled\") {\n error.code = \"ERR_OSSL_CRYPTO_INTERRUPTED_OR_CANCELLED\";\n }\n return error;\n }, deserializeGeneratedKeyValue2 = function(value) {\n if (!value || typeof value !== \"object\") {\n return value;\n }\n if (value.kind === \"string\") {\n return value.value;\n }\n if (value.kind === \"buffer\") {\n return Buffer.from(value.value, \"base64\");\n }\n if (value.kind === \"keyObject\") {\n return createGeneratedKeyObject2(value.value);\n }\n if (value.kind === \"object\") {\n return value.value;\n }\n return value;\n }, serializeBridgeOptions2 = function(options) {\n return JSON.stringify({\n hasOptions: options !== void 0,\n options: options === void 0 ? null : serializeBridgeValue2(options)\n });\n }, createInvalidArgTypeError2 = function(name3, expected, value) {\n var received;\n if (value == null) {\n received = \" Received \" + value;\n } else if (typeof value === \"function\") {\n received = \" Received function \" + (value.name || \"anonymous\");\n } else if (typeof value === \"object\") {\n if (value.constructor && value.constructor.name) {\n received = \" Received an instance of \" + value.constructor.name;\n } else {\n received = \" Received [object Object]\";\n }\n } else {\n var inspected = typeof value === \"string\" ? \"'\" + value + \"'\" : String(value);\n if (inspected.length > 28) {\n inspected = inspected.slice(0, 25) + \"...\";\n }\n received = \" Received type \" + typeof value + \" (\" + inspected + \")\";\n }\n var error = new TypeError('The \"' + name3 + '\" argument must be ' + expected + \".\" + received);\n error.code = \"ERR_INVALID_ARG_TYPE\";\n return error;\n }, scheduleCryptoCallback2 = function(callback, args) {\n var invoke = function() {\n callback.apply(void 0, args);\n };\n if (typeof process !== \"undefined\" && process && typeof process.nextTick === \"function\") {\n process.nextTick(invoke);\n return;\n }\n if (typeof queueMicrotask === \"function\") {\n queueMicrotask(invoke);\n return;\n }\n Promise.resolve().then(invoke);\n }, shouldThrowCryptoValidationError2 = function(error) {\n if (!error || typeof error !== \"object\") {\n return false;\n }\n if (error.name === \"TypeError\" || error.name === \"RangeError\") {\n return true;\n }\n var code = error.code;\n 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;\n }, ensureCryptoCallback2 = function(callback, syncValidator) {\n if (typeof callback === \"function\") {\n return callback;\n }\n if (typeof syncValidator === \"function\") {\n syncValidator();\n }\n throw createInvalidArgTypeError2(\"callback\", \"of type function\", callback);\n }, SandboxKeyObject2 = function(type, handle) {\n this.type = type;\n this._pem = handle && handle.pem !== void 0 ? handle.pem : void 0;\n this._raw = handle && handle.raw !== void 0 ? handle.raw : void 0;\n this._jwk = handle && handle.jwk !== void 0 ? cloneObject2(handle.jwk) : void 0;\n this.asymmetricKeyType = handle && handle.asymmetricKeyType !== void 0 ? handle.asymmetricKeyType : void 0;\n this.asymmetricKeyDetails = handle && handle.asymmetricKeyDetails !== void 0 ? restoreBridgeValue2(handle.asymmetricKeyDetails) : void 0;\n this.symmetricKeySize = type === \"secret\" && handle && handle.raw !== void 0 ? Buffer.from(handle.raw, \"base64\").byteLength : void 0;\n }, normalizeNamedCurve2 = function(namedCurve) {\n if (!namedCurve) {\n return namedCurve;\n }\n var upper = String(namedCurve).toUpperCase();\n if (upper === \"PRIME256V1\" || upper === \"SECP256R1\") return \"P-256\";\n if (upper === \"SECP384R1\") return \"P-384\";\n if (upper === \"SECP521R1\") return \"P-521\";\n return namedCurve;\n }, normalizeAlgorithmInput2 = function(algorithm) {\n if (typeof algorithm === \"string\") {\n return { name: algorithm };\n }\n return Object.assign({}, algorithm);\n }, createCompatibleCryptoKey2 = function(keyData) {\n var key;\n if (globalThis.CryptoKey && globalThis.CryptoKey.prototype && globalThis.CryptoKey.prototype !== SandboxCryptoKey.prototype) {\n key = Object.create(globalThis.CryptoKey.prototype);\n key.type = keyData.type;\n key.extractable = keyData.extractable;\n key.algorithm = keyData.algorithm;\n key.usages = keyData.usages;\n key._keyData = keyData;\n key._pem = keyData._pem;\n key._jwk = keyData._jwk;\n key._raw = keyData._raw;\n key._sourceKeyObjectData = keyData._sourceKeyObjectData;\n return key;\n }\n return new SandboxCryptoKey(keyData);\n }, buildCryptoKeyFromKeyObject2 = function(keyObject, algorithm, extractable, usages) {\n var algo = normalizeAlgorithmInput2(algorithm);\n var name3 = algo.name;\n if (keyObject.type === \"secret\") {\n var secretBytes = Buffer.from(keyObject._raw || \"\", \"base64\");\n if (name3 === \"PBKDF2\") {\n if (extractable) {\n throw new SyntaxError(\"PBKDF2 keys are not extractable\");\n }\n if (usages.some(function(usage) {\n return usage !== \"deriveBits\" && usage !== \"deriveKey\";\n })) {\n throw new SyntaxError(\"Unsupported key usage for a PBKDF2 key\");\n }\n return createCompatibleCryptoKey2({\n type: \"secret\",\n extractable,\n algorithm: { name: name3 },\n usages: Array.from(usages),\n _raw: keyObject._raw,\n _sourceKeyObjectData: {\n type: \"secret\",\n raw: keyObject._raw\n }\n });\n }\n if (name3 === \"HMAC\") {\n if (!secretBytes.byteLength || algo.length === 0) {\n throw createDomException2(\"Zero-length key is not supported\", \"DataError\");\n }\n if (!usages.length) {\n throw new SyntaxError(\"Usages cannot be empty when importing a secret key.\");\n }\n return createCompatibleCryptoKey2({\n type: \"secret\",\n extractable,\n algorithm: {\n name: name3,\n hash: typeof algo.hash === \"string\" ? { name: algo.hash } : cloneObject2(algo.hash),\n length: secretBytes.byteLength * 8\n },\n usages: Array.from(usages),\n _raw: keyObject._raw,\n _sourceKeyObjectData: {\n type: \"secret\",\n raw: keyObject._raw\n }\n });\n }\n return createCompatibleCryptoKey2({\n type: \"secret\",\n extractable,\n algorithm: {\n name: name3,\n length: secretBytes.byteLength * 8\n },\n usages: Array.from(usages),\n _raw: keyObject._raw,\n _sourceKeyObjectData: {\n type: \"secret\",\n raw: keyObject._raw\n }\n });\n }\n var keyType = String(keyObject.asymmetricKeyType || \"\").toLowerCase();\n var algorithmName = String(name3 || \"\");\n if ((keyType === \"ed25519\" || keyType === \"ed448\" || keyType === \"x25519\" || keyType === \"x448\") && keyType !== algorithmName.toLowerCase()) {\n throw createDomException2(\"Invalid key type\", \"DataError\");\n }\n if (algorithmName === \"ECDH\") {\n if (keyObject.type === \"private\" && !usages.length) {\n throw new SyntaxError(\"Usages cannot be empty when importing a private key.\");\n }\n var actualCurve = normalizeNamedCurve2(\n keyObject.asymmetricKeyDetails && keyObject.asymmetricKeyDetails.namedCurve\n );\n if (algo.namedCurve && actualCurve && normalizeNamedCurve2(algo.namedCurve) !== actualCurve) {\n throw createDomException2(\"Named curve mismatch\", \"DataError\");\n }\n }\n var normalizedAlgo = cloneObject2(algo);\n if (typeof normalizedAlgo.hash === \"string\") {\n normalizedAlgo.hash = { name: normalizedAlgo.hash };\n }\n return createCompatibleCryptoKey2({\n type: keyObject.type,\n extractable,\n algorithm: normalizedAlgo,\n usages: Array.from(usages),\n _pem: keyObject._pem,\n _jwk: cloneObject2(keyObject._jwk),\n _sourceKeyObjectData: {\n type: keyObject.type,\n pem: keyObject._pem,\n jwk: cloneObject2(keyObject._jwk),\n asymmetricKeyType: keyObject.asymmetricKeyType,\n asymmetricKeyDetails: cloneObject2(keyObject.asymmetricKeyDetails)\n }\n });\n }, createAsymmetricKeyObject2 = function(type, key) {\n if (typeof key === \"string\") {\n if (key.indexOf(\"-----BEGIN\") === -1) {\n throw new TypeError(\"error:0900006e:PEM routines:OPENSSL_internal:NO_START_LINE\");\n }\n return new SandboxKeyObject2(type, { pem: key });\n }\n if (key && typeof key === \"object\" && key._pem) {\n return new SandboxKeyObject2(type, {\n pem: key._pem,\n jwk: key._jwk,\n asymmetricKeyType: key.asymmetricKeyType,\n asymmetricKeyDetails: key.asymmetricKeyDetails\n });\n }\n if (key && typeof key === \"object\" && key.key) {\n var keyData = typeof key.key === \"string\" ? key.key : key.key.toString(\"utf8\");\n return new SandboxKeyObject2(type, { pem: keyData });\n }\n if (Buffer.isBuffer(key)) {\n var keyStr = key.toString(\"utf8\");\n if (keyStr.indexOf(\"-----BEGIN\") === -1) {\n throw new TypeError(\"error:0900006e:PEM routines:OPENSSL_internal:NO_START_LINE\");\n }\n return new SandboxKeyObject2(type, { pem: keyStr });\n }\n return new SandboxKeyObject2(type, { pem: String(key) });\n }, createGeneratedKeyObject2 = function(value) {\n return new SandboxKeyObject2(value.type, {\n pem: value.pem,\n raw: value.raw,\n jwk: value.jwk,\n asymmetricKeyType: value.asymmetricKeyType,\n asymmetricKeyDetails: value.asymmetricKeyDetails\n });\n };\n 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;\n Object.defineProperty(SandboxKeyObject2.prototype, Symbol.toStringTag, {\n value: \"KeyObject\",\n configurable: true\n });\n SandboxKeyObject2.prototype.export = function exportKey(options) {\n if (this.type === \"secret\") {\n return Buffer.from(this._raw || \"\", \"base64\");\n }\n if (!options || typeof options !== \"object\") {\n throw new TypeError('The \"options\" argument must be of type object.');\n }\n if (options.format === \"jwk\") {\n return cloneObject2(this._jwk);\n }\n if (options.format === \"der\") {\n var lines = String(this._pem || \"\").split(\"\\n\").filter(function(l) {\n return l && l.indexOf(\"-----\") !== 0;\n });\n return Buffer.from(lines.join(\"\"), \"base64\");\n }\n return this._pem;\n };\n SandboxKeyObject2.prototype.toString = function() {\n return \"[object KeyObject]\";\n };\n SandboxKeyObject2.prototype.equals = function equals(other) {\n if (!(other instanceof SandboxKeyObject2)) {\n return false;\n }\n if (this.type !== other.type) {\n return false;\n }\n if (this.type === \"secret\") {\n return (this._raw || \"\") === (other._raw || \"\");\n }\n return (this._pem || \"\") === (other._pem || \"\") && this.asymmetricKeyType === other.asymmetricKeyType;\n };\n SandboxKeyObject2.prototype.toCryptoKey = function toCryptoKey(algorithm, extractable, usages) {\n return buildCryptoKeyFromKeyObject2(this, algorithm, extractable, Array.from(usages || []));\n };\n result2.generateKeyPairSync = function generateKeyPairSync(type, options) {\n var resultJson = _cryptoGenerateKeyPairSync.applySync(void 0, [\n type,\n serializeBridgeOptions2(options)\n ]);\n var parsed = JSON.parse(resultJson);\n if (parsed.publicKey && parsed.publicKey.kind) {\n return {\n publicKey: deserializeGeneratedKeyValue2(parsed.publicKey),\n privateKey: deserializeGeneratedKeyValue2(parsed.privateKey)\n };\n }\n return {\n publicKey: createGeneratedKeyObject2(parsed.publicKey),\n privateKey: createGeneratedKeyObject2(parsed.privateKey)\n };\n };\n result2.generateKeyPair = function generateKeyPair(type, options, callback) {\n if (typeof options === \"function\") {\n callback = options;\n options = void 0;\n }\n callback = ensureCryptoCallback2(callback, function() {\n result2.generateKeyPairSync(type, options);\n });\n try {\n var pair = result2.generateKeyPairSync(type, options);\n scheduleCryptoCallback2(callback, [null, pair.publicKey, pair.privateKey]);\n } catch (e) {\n if (shouldThrowCryptoValidationError2(e)) {\n throw e;\n }\n scheduleCryptoCallback2(callback, [e]);\n }\n };\n if (typeof _cryptoGenerateKeySync !== \"undefined\") {\n result2.generateKeySync = function generateKeySync(type, options) {\n var resultJson;\n try {\n resultJson = _cryptoGenerateKeySync.applySync(void 0, [\n type,\n serializeBridgeOptions2(options)\n ]);\n } catch (error) {\n throw normalizeCryptoBridgeError2(error);\n }\n return createGeneratedKeyObject2(JSON.parse(resultJson));\n };\n result2.generateKey = function generateKey(type, options, callback) {\n callback = ensureCryptoCallback2(callback, function() {\n result2.generateKeySync(type, options);\n });\n try {\n var key = result2.generateKeySync(type, options);\n scheduleCryptoCallback2(callback, [null, key]);\n } catch (e) {\n if (shouldThrowCryptoValidationError2(e)) {\n throw e;\n }\n scheduleCryptoCallback2(callback, [e]);\n }\n };\n }\n if (typeof _cryptoGeneratePrimeSync !== \"undefined\") {\n result2.generatePrimeSync = function generatePrimeSync(size, options) {\n var resultJson;\n try {\n resultJson = _cryptoGeneratePrimeSync.applySync(void 0, [\n size,\n serializeBridgeOptions2(options)\n ]);\n } catch (error) {\n throw normalizeCryptoBridgeError2(error);\n }\n return restoreBridgeValue2(JSON.parse(resultJson));\n };\n result2.generatePrime = function generatePrime(size, options, callback) {\n if (typeof options === \"function\") {\n callback = options;\n options = void 0;\n }\n callback = ensureCryptoCallback2(callback, function() {\n result2.generatePrimeSync(size, options);\n });\n try {\n var prime = result2.generatePrimeSync(size, options);\n scheduleCryptoCallback2(callback, [null, prime]);\n } catch (e) {\n if (shouldThrowCryptoValidationError2(e)) {\n throw e;\n }\n scheduleCryptoCallback2(callback, [e]);\n }\n };\n }\n result2.createPublicKey = function createPublicKey(key) {\n if (typeof _cryptoCreateKeyObject !== \"undefined\") {\n var resultJson;\n try {\n resultJson = _cryptoCreateKeyObject.applySync(void 0, [\n \"createPublicKey\",\n JSON.stringify(serializeBridgeValue2(key))\n ]);\n } catch (error) {\n throw normalizeCryptoBridgeError2(error);\n }\n return createGeneratedKeyObject2(JSON.parse(resultJson));\n }\n return createAsymmetricKeyObject2(\"public\", key);\n };\n result2.createPrivateKey = function createPrivateKey(key) {\n if (typeof _cryptoCreateKeyObject !== \"undefined\") {\n var resultJson;\n try {\n resultJson = _cryptoCreateKeyObject.applySync(void 0, [\n \"createPrivateKey\",\n JSON.stringify(serializeBridgeValue2(key))\n ]);\n } catch (error) {\n throw normalizeCryptoBridgeError2(error);\n }\n return createGeneratedKeyObject2(JSON.parse(resultJson));\n }\n return createAsymmetricKeyObject2(\"private\", key);\n };\n result2.createSecretKey = function createSecretKey(key, encoding) {\n return new SandboxKeyObject2(\"secret\", {\n raw: toRawBuffer2(key, encoding).toString(\"base64\")\n });\n };\n SandboxKeyObject2.from = function from(key) {\n if (!key || typeof key !== \"object\" || key[Symbol.toStringTag] !== \"CryptoKey\") {\n throw new TypeError('The \"key\" argument must be an instance of CryptoKey.');\n }\n if (key._sourceKeyObjectData && key._sourceKeyObjectData.type === \"secret\") {\n return new SandboxKeyObject2(\"secret\", {\n raw: key._sourceKeyObjectData.raw\n });\n }\n return new SandboxKeyObject2(key.type, {\n pem: key._pem,\n jwk: key._jwk,\n asymmetricKeyType: key._sourceKeyObjectData && key._sourceKeyObjectData.asymmetricKeyType,\n asymmetricKeyDetails: key._sourceKeyObjectData && key._sourceKeyObjectData.asymmetricKeyDetails\n });\n };\n result2.KeyObject = SandboxKeyObject2;\n }\n if (typeof _cryptoSubtle !== \"undefined\") {\n let SandboxCryptoKey2 = function(keyData) {\n this.type = keyData.type;\n this.extractable = keyData.extractable;\n this.algorithm = keyData.algorithm;\n this.usages = keyData.usages;\n this._keyData = keyData;\n this._pem = keyData._pem;\n this._jwk = keyData._jwk;\n this._raw = keyData._raw;\n this._sourceKeyObjectData = keyData._sourceKeyObjectData;\n }, toBase642 = function(data) {\n if (typeof data === \"string\") return Buffer.from(data).toString(\"base64\");\n if (data instanceof ArrayBuffer) return Buffer.from(new Uint8Array(data)).toString(\"base64\");\n if (ArrayBuffer.isView(data)) return Buffer.from(new Uint8Array(data.buffer, data.byteOffset, data.byteLength)).toString(\"base64\");\n return Buffer.from(data).toString(\"base64\");\n }, subtleCall2 = function(reqObj) {\n return _cryptoSubtle.applySync(void 0, [JSON.stringify(reqObj)]);\n }, normalizeAlgo2 = function(algorithm) {\n if (typeof algorithm === \"string\") return { name: algorithm };\n return algorithm;\n };\n var SandboxCryptoKey = SandboxCryptoKey2, toBase64 = toBase642, subtleCall = subtleCall2, normalizeAlgo = normalizeAlgo2;\n Object.defineProperty(SandboxCryptoKey2.prototype, Symbol.toStringTag, {\n value: \"CryptoKey\",\n configurable: true\n });\n Object.defineProperty(SandboxCryptoKey2, Symbol.hasInstance, {\n value: function(candidate) {\n return !!(candidate && typeof candidate === \"object\" && (candidate._keyData || candidate[Symbol.toStringTag] === \"CryptoKey\"));\n },\n configurable: true\n });\n if (globalThis.CryptoKey && globalThis.CryptoKey.prototype && globalThis.CryptoKey.prototype !== SandboxCryptoKey2.prototype) {\n Object.setPrototypeOf(SandboxCryptoKey2.prototype, globalThis.CryptoKey.prototype);\n }\n if (typeof globalThis.CryptoKey === \"undefined\") {\n __requireExposeCustomGlobal(\"CryptoKey\", SandboxCryptoKey2);\n } else if (globalThis.CryptoKey !== SandboxCryptoKey2) {\n globalThis.CryptoKey = SandboxCryptoKey2;\n }\n var SandboxSubtle = {};\n SandboxSubtle.digest = function digest(algorithm, data) {\n return Promise.resolve().then(function() {\n var algo = normalizeAlgo2(algorithm);\n var result22 = JSON.parse(subtleCall2({\n op: \"digest\",\n algorithm: algo.name,\n data: toBase642(data)\n }));\n var buf = Buffer.from(result22.data, \"base64\");\n return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);\n });\n };\n SandboxSubtle.generateKey = function generateKey(algorithm, extractable, keyUsages) {\n return Promise.resolve().then(function() {\n var algo = normalizeAlgo2(algorithm);\n var reqAlgo = Object.assign({}, algo);\n if (reqAlgo.hash) reqAlgo.hash = normalizeAlgo2(reqAlgo.hash);\n if (reqAlgo.publicExponent) {\n reqAlgo.publicExponent = Buffer.from(new Uint8Array(reqAlgo.publicExponent.buffer || reqAlgo.publicExponent)).toString(\"base64\");\n }\n var result22 = JSON.parse(subtleCall2({\n op: \"generateKey\",\n algorithm: reqAlgo,\n extractable,\n usages: Array.from(keyUsages)\n }));\n if (result22.publicKey && result22.privateKey) {\n return {\n publicKey: new SandboxCryptoKey2(result22.publicKey),\n privateKey: new SandboxCryptoKey2(result22.privateKey)\n };\n }\n return new SandboxCryptoKey2(result22.key);\n });\n };\n SandboxSubtle.importKey = function importKey(format, keyData, algorithm, extractable, keyUsages) {\n return Promise.resolve().then(function() {\n var algo = normalizeAlgo2(algorithm);\n var reqAlgo = Object.assign({}, algo);\n if (reqAlgo.hash) reqAlgo.hash = normalizeAlgo2(reqAlgo.hash);\n var serializedKeyData;\n if (format === \"jwk\") {\n serializedKeyData = keyData;\n } else if (format === \"raw\") {\n serializedKeyData = toBase642(keyData);\n } else {\n serializedKeyData = toBase642(keyData);\n }\n var result22 = JSON.parse(subtleCall2({\n op: \"importKey\",\n format,\n keyData: serializedKeyData,\n algorithm: reqAlgo,\n extractable,\n usages: Array.from(keyUsages)\n }));\n return new SandboxCryptoKey2(result22.key);\n });\n };\n SandboxSubtle.exportKey = function exportKey(format, key) {\n return Promise.resolve().then(function() {\n var result22 = JSON.parse(subtleCall2({\n op: \"exportKey\",\n format,\n key: key._keyData\n }));\n if (format === \"jwk\") return result22.jwk;\n var buf = Buffer.from(result22.data, \"base64\");\n return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);\n });\n };\n SandboxSubtle.encrypt = function encrypt(algorithm, key, data) {\n return Promise.resolve().then(function() {\n var algo = normalizeAlgo2(algorithm);\n var reqAlgo = Object.assign({}, algo);\n if (reqAlgo.iv) reqAlgo.iv = toBase642(reqAlgo.iv);\n if (reqAlgo.additionalData) reqAlgo.additionalData = toBase642(reqAlgo.additionalData);\n var result22 = JSON.parse(subtleCall2({\n op: \"encrypt\",\n algorithm: reqAlgo,\n key: key._keyData,\n data: toBase642(data)\n }));\n var buf = Buffer.from(result22.data, \"base64\");\n return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);\n });\n };\n SandboxSubtle.decrypt = function decrypt(algorithm, key, data) {\n return Promise.resolve().then(function() {\n var algo = normalizeAlgo2(algorithm);\n var reqAlgo = Object.assign({}, algo);\n if (reqAlgo.iv) reqAlgo.iv = toBase642(reqAlgo.iv);\n if (reqAlgo.additionalData) reqAlgo.additionalData = toBase642(reqAlgo.additionalData);\n var result22 = JSON.parse(subtleCall2({\n op: \"decrypt\",\n algorithm: reqAlgo,\n key: key._keyData,\n data: toBase642(data)\n }));\n var buf = Buffer.from(result22.data, \"base64\");\n return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);\n });\n };\n SandboxSubtle.sign = function sign(algorithm, key, data) {\n return Promise.resolve().then(function() {\n var result22 = JSON.parse(subtleCall2({\n op: \"sign\",\n algorithm: normalizeAlgo2(algorithm),\n key: key._keyData,\n data: toBase642(data)\n }));\n var buf = Buffer.from(result22.data, \"base64\");\n return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);\n });\n };\n SandboxSubtle.verify = function verify(algorithm, key, signature, data) {\n return Promise.resolve().then(function() {\n var result22 = JSON.parse(subtleCall2({\n op: \"verify\",\n algorithm: normalizeAlgo2(algorithm),\n key: key._keyData,\n signature: toBase642(signature),\n data: toBase642(data)\n }));\n return result22.result;\n });\n };\n SandboxSubtle.deriveBits = function deriveBits(algorithm, baseKey, length) {\n return Promise.resolve().then(function() {\n var algo = normalizeAlgo2(algorithm);\n var reqAlgo = Object.assign({}, algo);\n if (reqAlgo.salt) reqAlgo.salt = toBase642(reqAlgo.salt);\n if (reqAlgo.info) reqAlgo.info = toBase642(reqAlgo.info);\n var result22 = JSON.parse(subtleCall2({\n op: \"deriveBits\",\n algorithm: reqAlgo,\n baseKey: baseKey._keyData,\n length\n }));\n return Buffer.from(result22.data, \"base64\").buffer;\n });\n };\n SandboxSubtle.deriveKey = function deriveKey(algorithm, baseKey, derivedKeyAlgorithm, extractable, keyUsages) {\n return Promise.resolve().then(function() {\n var algo = normalizeAlgo2(algorithm);\n var reqAlgo = Object.assign({}, algo);\n if (reqAlgo.salt) reqAlgo.salt = toBase642(reqAlgo.salt);\n if (reqAlgo.info) reqAlgo.info = toBase642(reqAlgo.info);\n var result22 = JSON.parse(subtleCall2({\n op: \"deriveKey\",\n algorithm: reqAlgo,\n baseKey: baseKey._keyData,\n derivedKeyAlgorithm: normalizeAlgo2(derivedKeyAlgorithm),\n extractable,\n usages: keyUsages\n }));\n return new SandboxCryptoKey2(result22.key);\n });\n };\n if (globalThis.crypto && globalThis.crypto.subtle && typeof globalThis.crypto.subtle.importKey === \"function\") {\n result2.subtle = globalThis.crypto.subtle;\n result2.webcrypto = globalThis.crypto;\n } else {\n result2.subtle = SandboxSubtle;\n result2.webcrypto = { subtle: SandboxSubtle, getRandomValues: result2.randomFillSync };\n }\n }\n if (typeof result2.getCurves !== \"function\") {\n result2.getCurves = function getCurves() {\n return [\n \"prime256v1\",\n \"secp256r1\",\n \"secp384r1\",\n \"secp521r1\",\n \"secp256k1\",\n \"secp224r1\",\n \"secp192k1\"\n ];\n };\n }\n if (typeof result2.getCiphers !== \"function\") {\n result2.getCiphers = function getCiphers() {\n return [\n \"aes-128-cbc\",\n \"aes-128-gcm\",\n \"aes-192-cbc\",\n \"aes-192-gcm\",\n \"aes-256-cbc\",\n \"aes-256-gcm\",\n \"aes-128-ctr\",\n \"aes-192-ctr\",\n \"aes-256-ctr\"\n ];\n };\n }\n if (typeof result2.getHashes !== \"function\") {\n result2.getHashes = function getHashes() {\n return [\"md5\", \"sha1\", \"sha256\", \"sha384\", \"sha512\"];\n };\n }\n if (typeof result2.timingSafeEqual !== \"function\") {\n result2.timingSafeEqual = function timingSafeEqual(a, b) {\n if (a.length !== b.length) {\n throw new RangeError(\"Input buffers must have the same byte length\");\n }\n var out = 0;\n for (var i = 0; i < a.length; i++) {\n out |= a[i] ^ b[i];\n }\n return out === 0;\n };\n }\n if (typeof result2.getFips !== \"function\") {\n result2.getFips = function getFips() {\n return 0;\n };\n }\n if (typeof result2.setFips !== \"function\") {\n result2.setFips = function setFips() {\n throw new Error(\"FIPS mode is not supported in sandbox\");\n };\n }\n return result2;\n }\n if (name2 === \"stream\") {\n if (typeof result2 === \"function\" && result2.prototype && typeof result2.Readable === \"function\") {\n var readableProto = result2.Readable.prototype;\n var streamProto = result2.prototype;\n if (readableProto && streamProto && !(readableProto instanceof result2)) {\n var currentParent = Object.getPrototypeOf(readableProto);\n Object.setPrototypeOf(streamProto, currentParent);\n Object.setPrototypeOf(readableProto, streamProto);\n }\n }\n return result2;\n }\n if (name2 === \"path\") {\n if (result2.win32 === null || result2.win32 === void 0) {\n result2.win32 = result2.posix || result2;\n }\n if (result2.posix === null || result2.posix === void 0) {\n result2.posix = result2;\n }\n const hasAbsoluteSegment = function(args) {\n return args.some(function(arg) {\n return typeof arg === \"string\" && arg.length > 0 && arg.charAt(0) === \"/\";\n });\n };\n const prependCwd = function(args) {\n if (hasAbsoluteSegment(args)) return;\n if (typeof process !== \"undefined\" && typeof process.cwd === \"function\") {\n const cwd = process.cwd();\n if (cwd && cwd.charAt(0) === \"/\") {\n args.unshift(cwd);\n }\n }\n };\n const originalResolve = result2.resolve;\n if (typeof originalResolve === \"function\" && !originalResolve._patchedForCwd) {\n const patchedResolve = function resolve2() {\n const args = Array.from(arguments);\n prependCwd(args);\n return originalResolve.apply(this, args);\n };\n patchedResolve._patchedForCwd = true;\n result2.resolve = patchedResolve;\n }\n if (result2.posix && typeof result2.posix.resolve === \"function\" && !result2.posix.resolve._patchedForCwd) {\n const originalPosixResolve = result2.posix.resolve;\n const patchedPosixResolve = function resolve2() {\n const args = Array.from(arguments);\n prependCwd(args);\n return originalPosixResolve.apply(this, args);\n };\n patchedPosixResolve._patchedForCwd = true;\n result2.posix.resolve = patchedPosixResolve;\n }\n }\n return result2;\n }\n var _deferredCoreModules = /* @__PURE__ */ new Set([\n \"readline\",\n \"perf_hooks\",\n \"async_hooks\",\n \"worker_threads\",\n \"diagnostics_channel\"\n ]);\n var _unsupportedCoreModules = /* @__PURE__ */ new Set([\n \"dgram\",\n \"cluster\",\n \"wasi\",\n \"inspector\",\n \"repl\",\n \"trace_events\",\n \"domain\"\n ]);\n function _unsupportedApiError(moduleName2, apiName) {\n return new Error(moduleName2 + \".\" + apiName + \" is not supported in sandbox\");\n }\n function _createDeferredModuleStub(moduleName2) {\n const methodCache = {};\n let stub = null;\n stub = new Proxy({}, {\n get(_target, prop) {\n if (prop === \"__esModule\") return false;\n if (prop === \"default\") return stub;\n if (prop === Symbol.toStringTag) return \"Module\";\n if (prop === \"then\") return void 0;\n if (typeof prop !== \"string\") return void 0;\n if (!methodCache[prop]) {\n methodCache[prop] = function deferredApiStub() {\n throw _unsupportedApiError(moduleName2, prop);\n };\n }\n return methodCache[prop];\n }\n });\n return stub;\n }\n var __internalModuleCache = _moduleCache;\n var __require = function require2(moduleName2) {\n return _requireFrom(moduleName2, _currentModule.dirname);\n };\n __requireExposeCustomGlobal(\"require\", __require);\n function _resolveFrom(moduleName2, fromDir2) {\n var resolved2;\n if (typeof _resolveModuleSync !== \"undefined\") {\n resolved2 = _resolveModuleSync.applySync(void 0, [moduleName2, fromDir2]);\n }\n if (resolved2 === null || resolved2 === void 0) {\n resolved2 = _resolveModule.applySyncPromise(void 0, [moduleName2, fromDir2, \"require\"]);\n }\n if (resolved2 === null) {\n const err = new Error(\"Cannot find module '\" + moduleName2 + \"'\");\n err.code = \"MODULE_NOT_FOUND\";\n throw err;\n }\n return resolved2;\n }\n globalThis.require.resolve = function resolve(moduleName2) {\n return _resolveFrom(moduleName2, _currentModule.dirname);\n };\n function _debugRequire(phase, moduleName2, extra) {\n if (globalThis.__sandboxRequireDebug !== true) {\n return;\n }\n if (moduleName2 !== \"rivetkit\" && moduleName2 !== \"@rivetkit/traces\" && moduleName2 !== \"@rivetkit/on-change\" && moduleName2 !== \"async_hooks\" && !moduleName2.startsWith(\"rivetkit/\") && !moduleName2.startsWith(\"@rivetkit/\")) {\n return;\n }\n if (typeof console !== \"undefined\" && typeof console.log === \"function\") {\n console.log(\n \"[sandbox.require] \" + phase + \" \" + moduleName2 + (extra ? \" \" + extra : \"\")\n );\n }\n }\n function _requireFrom(moduleName, fromDir) {\n _debugRequire(\"start\", moduleName, fromDir);\n const name = moduleName.replace(/^node:/, \"\");\n let cacheKey = name;\n let resolved = null;\n const isRelative = name.startsWith(\"./\") || name.startsWith(\"../\");\n if (!isRelative && __internalModuleCache[name]) {\n _debugRequire(\"cache-hit\", name, name);\n return __internalModuleCache[name];\n }\n if (name === \"fs\") {\n if (__internalModuleCache[\"fs\"]) return __internalModuleCache[\"fs\"];\n const fsModule = globalThis.bridge?.fs || globalThis.bridge?.default || globalThis._fsModule || {};\n __internalModuleCache[\"fs\"] = fsModule;\n _debugRequire(\"loaded\", name, \"fs-special\");\n return fsModule;\n }\n if (name === \"fs/promises\") {\n if (__internalModuleCache[\"fs/promises\"]) return __internalModuleCache[\"fs/promises\"];\n const fsModule = _requireFrom(\"fs\", fromDir);\n __internalModuleCache[\"fs/promises\"] = fsModule.promises;\n _debugRequire(\"loaded\", name, \"fs-promises-special\");\n return fsModule.promises;\n }\n if (name === \"stream/promises\") {\n if (__internalModuleCache[\"stream/promises\"]) return __internalModuleCache[\"stream/promises\"];\n const streamModule = _requireFrom(\"stream\", fromDir);\n const promisesModule = {\n finished(stream, options) {\n return new Promise(function(resolve2, reject) {\n if (typeof streamModule.finished !== \"function\") {\n resolve2();\n return;\n }\n if (options && typeof options === \"object\" && !Array.isArray(options)) {\n streamModule.finished(stream, options, function(error) {\n if (error) {\n reject(error);\n return;\n }\n resolve2();\n });\n return;\n }\n streamModule.finished(stream, function(error) {\n if (error) {\n reject(error);\n return;\n }\n resolve2();\n });\n });\n },\n pipeline() {\n const args = Array.prototype.slice.call(arguments);\n return new Promise(function(resolve2, reject) {\n if (typeof streamModule.pipeline !== \"function\") {\n reject(new Error(\"stream.pipeline is not supported in sandbox\"));\n return;\n }\n args.push(function(error) {\n if (error) {\n reject(error);\n return;\n }\n resolve2();\n });\n streamModule.pipeline.apply(streamModule, args);\n });\n }\n };\n __internalModuleCache[\"stream/promises\"] = promisesModule;\n _debugRequire(\"loaded\", name, \"stream-promises-special\");\n return promisesModule;\n }\n if (name === \"child_process\") {\n if (__internalModuleCache[\"child_process\"]) return __internalModuleCache[\"child_process\"];\n __internalModuleCache[\"child_process\"] = _childProcessModule;\n _debugRequire(\"loaded\", name, \"child-process-special\");\n return _childProcessModule;\n }\n if (name === \"net\") {\n if (__internalModuleCache[\"net\"]) return __internalModuleCache[\"net\"];\n __internalModuleCache[\"net\"] = _netModule;\n _debugRequire(\"loaded\", name, \"net-special\");\n return _netModule;\n }\n if (name === \"tls\") {\n if (__internalModuleCache[\"tls\"]) return __internalModuleCache[\"tls\"];\n __internalModuleCache[\"tls\"] = _tlsModule;\n _debugRequire(\"loaded\", name, \"tls-special\");\n return _tlsModule;\n }\n if (name === \"http\") {\n if (__internalModuleCache[\"http\"]) return __internalModuleCache[\"http\"];\n __internalModuleCache[\"http\"] = _httpModule;\n _debugRequire(\"loaded\", name, \"http-special\");\n return _httpModule;\n }\n if (name === \"_http_agent\") {\n if (__internalModuleCache[\"_http_agent\"]) return __internalModuleCache[\"_http_agent\"];\n const httpAgentModule = {\n Agent: _httpModule.Agent,\n globalAgent: _httpModule.globalAgent\n };\n __internalModuleCache[\"_http_agent\"] = httpAgentModule;\n _debugRequire(\"loaded\", name, \"http-agent-special\");\n return httpAgentModule;\n }\n if (name === \"https\") {\n if (__internalModuleCache[\"https\"]) return __internalModuleCache[\"https\"];\n __internalModuleCache[\"https\"] = _httpsModule;\n _debugRequire(\"loaded\", name, \"https-special\");\n return _httpsModule;\n }\n if (name === \"http2\") {\n if (__internalModuleCache[\"http2\"]) return __internalModuleCache[\"http2\"];\n __internalModuleCache[\"http2\"] = _http2Module;\n _debugRequire(\"loaded\", name, \"http2-special\");\n return _http2Module;\n }\n if (name === \"dns\") {\n if (__internalModuleCache[\"dns\"]) return __internalModuleCache[\"dns\"];\n __internalModuleCache[\"dns\"] = _dnsModule;\n _debugRequire(\"loaded\", name, \"dns-special\");\n return _dnsModule;\n }\n if (name === \"os\") {\n if (__internalModuleCache[\"os\"]) return __internalModuleCache[\"os\"];\n __internalModuleCache[\"os\"] = _osModule;\n _debugRequire(\"loaded\", name, \"os-special\");\n return _osModule;\n }\n if (name === \"module\") {\n if (__internalModuleCache[\"module\"]) return __internalModuleCache[\"module\"];\n __internalModuleCache[\"module\"] = _moduleModule;\n _debugRequire(\"loaded\", name, \"module-special\");\n return _moduleModule;\n }\n if (name === \"process\") {\n _debugRequire(\"loaded\", name, \"process-special\");\n return globalThis.process;\n }\n if (name === \"async_hooks\") {\n if (__internalModuleCache[\"async_hooks\"]) return __internalModuleCache[\"async_hooks\"];\n class AsyncLocalStorage {\n constructor() {\n this._store = void 0;\n }\n run(store, callback) {\n const previousStore = this._store;\n this._store = store;\n try {\n const args = Array.prototype.slice.call(arguments, 2);\n return callback.apply(void 0, args);\n } finally {\n this._store = previousStore;\n }\n }\n enterWith(store) {\n this._store = store;\n }\n getStore() {\n return this._store;\n }\n disable() {\n this._store = void 0;\n }\n exit(callback) {\n const previousStore = this._store;\n this._store = void 0;\n try {\n const args = Array.prototype.slice.call(arguments, 1);\n return callback.apply(void 0, args);\n } finally {\n this._store = previousStore;\n }\n }\n }\n class AsyncResource {\n constructor(type) {\n this.type = type;\n }\n runInAsyncScope(callback, thisArg) {\n const args = Array.prototype.slice.call(arguments, 2);\n return callback.apply(thisArg, args);\n }\n emitDestroy() {\n }\n }\n const asyncHooksModule = {\n AsyncLocalStorage,\n AsyncResource,\n createHook() {\n return {\n enable() {\n return this;\n },\n disable() {\n return this;\n }\n };\n },\n executionAsyncId() {\n return 1;\n },\n triggerAsyncId() {\n return 0;\n },\n executionAsyncResource() {\n return null;\n }\n };\n __internalModuleCache[\"async_hooks\"] = asyncHooksModule;\n _debugRequire(\"loaded\", name, \"async-hooks-special\");\n return asyncHooksModule;\n }\n if (name === \"diagnostics_channel\") {\n let _createChannel2 = function() {\n return {\n hasSubscribers: false,\n publish: function() {\n },\n subscribe: function() {\n },\n unsubscribe: function() {\n }\n };\n };\n var _createChannel = _createChannel2;\n if (__internalModuleCache[name]) return __internalModuleCache[name];\n const dcModule = {\n channel: function() {\n return _createChannel2();\n },\n hasSubscribers: function() {\n return false;\n },\n tracingChannel: function() {\n return {\n start: _createChannel2(),\n end: _createChannel2(),\n asyncStart: _createChannel2(),\n asyncEnd: _createChannel2(),\n error: _createChannel2(),\n traceSync: function(fn, context, thisArg) {\n var args = Array.prototype.slice.call(arguments, 3);\n return fn.apply(thisArg, args);\n },\n tracePromise: function(fn, context, thisArg) {\n var args = Array.prototype.slice.call(arguments, 3);\n return fn.apply(thisArg, args);\n },\n traceCallback: function(fn, context, thisArg) {\n var args = Array.prototype.slice.call(arguments, 3);\n return fn.apply(thisArg, args);\n }\n };\n },\n Channel: function Channel(name2) {\n this.hasSubscribers = false;\n this.publish = function() {\n };\n this.subscribe = function() {\n };\n this.unsubscribe = function() {\n };\n }\n };\n __internalModuleCache[name] = dcModule;\n _debugRequire(\"loaded\", name, \"diagnostics-channel-special\");\n return dcModule;\n }\n if (_deferredCoreModules.has(name)) {\n if (__internalModuleCache[name]) return __internalModuleCache[name];\n const deferredStub = _createDeferredModuleStub(name);\n __internalModuleCache[name] = deferredStub;\n _debugRequire(\"loaded\", name, \"deferred-stub\");\n return deferredStub;\n }\n if (_unsupportedCoreModules.has(name)) {\n throw new Error(name + \" is not supported in sandbox\");\n }\n const polyfillCode = _loadPolyfill.applySyncPromise(void 0, [name]);\n if (polyfillCode !== null) {\n if (__internalModuleCache[name]) return __internalModuleCache[name];\n const moduleObj = { exports: {} };\n _pendingModules[name] = moduleObj;\n let result = eval(polyfillCode);\n result = _patchPolyfill(name, result);\n if (typeof result === \"object\" && result !== null) {\n Object.assign(moduleObj.exports, result);\n } else {\n moduleObj.exports = result;\n }\n __internalModuleCache[name] = moduleObj.exports;\n delete _pendingModules[name];\n _debugRequire(\"loaded\", name, \"polyfill\");\n return __internalModuleCache[name];\n }\n resolved = _resolveFrom(name, fromDir);\n cacheKey = resolved;\n if (__internalModuleCache[cacheKey]) {\n _debugRequire(\"cache-hit\", name, cacheKey);\n return __internalModuleCache[cacheKey];\n }\n if (_pendingModules[cacheKey]) {\n _debugRequire(\"pending-hit\", name, cacheKey);\n return _pendingModules[cacheKey].exports;\n }\n var source;\n if (typeof _loadFileSync !== \"undefined\") {\n source = _loadFileSync.applySync(void 0, [resolved]);\n }\n if (source === null || source === void 0) {\n source = _loadFile.applySyncPromise(void 0, [resolved, \"require\"]);\n }\n if (source === null) {\n const err = new Error(\"Cannot find module '\" + resolved + \"'\");\n err.code = \"MODULE_NOT_FOUND\";\n throw err;\n }\n if (resolved.endsWith(\".json\")) {\n const parsed = JSON.parse(source);\n __internalModuleCache[cacheKey] = parsed;\n return parsed;\n }\n const normalizedSource = typeof source === \"string\" ? source.replace(/import\\.meta\\.url/g, \"__filename\").replace(/fileURLToPath\\(__filename\\)/g, \"__filename\").replace(/url\\.fileURLToPath\\(__filename\\)/g, \"__filename\").replace(/fileURLToPath\\.call\\(void 0, __filename\\)/g, \"__filename\") : source;\n const module = {\n exports: {},\n filename: resolved,\n dirname: _dirname(resolved),\n id: resolved,\n loaded: false\n };\n _pendingModules[cacheKey] = module;\n const prevModule = _currentModule;\n _currentModule = module;\n try {\n let wrapper;\n try {\n wrapper = new Function(\n \"exports\",\n \"require\",\n \"module\",\n \"__filename\",\n \"__dirname\",\n \"__dynamicImport\",\n normalizedSource + \"\\n//# sourceURL=\" + resolved\n );\n } catch (error) {\n const details = error && error.stack ? error.stack : String(error);\n throw new Error(\"failed to compile module \" + resolved + \": \" + details);\n }\n const moduleRequire = function(request) {\n return _requireFrom(request, module.dirname);\n };\n moduleRequire.resolve = function(request) {\n return _resolveFrom(request, module.dirname);\n };\n const moduleDynamicImport = function(specifier) {\n if (typeof globalThis.__dynamicImport === \"function\") {\n return globalThis.__dynamicImport(specifier, module.dirname);\n }\n return Promise.reject(new Error(\"Dynamic import is not initialized\"));\n };\n wrapper(\n module.exports,\n moduleRequire,\n module,\n resolved,\n module.dirname,\n moduleDynamicImport\n );\n module.loaded = true;\n } catch (error) {\n const details = error && error.stack ? error.stack : String(error);\n throw new Error(\"failed to execute module \" + resolved + \": \" + details);\n } finally {\n _currentModule = prevModule;\n }\n __internalModuleCache[cacheKey] = module.exports;\n delete _pendingModules[cacheKey];\n _debugRequire(\"loaded\", name, cacheKey);\n return module.exports;\n }\n __requireExposeCustomGlobal(\"_requireFrom\", _requireFrom);\n var __moduleCacheProxy = new Proxy(__internalModuleCache, {\n get(target, prop, receiver) {\n return Reflect.get(target, prop, receiver);\n },\n set(_target, prop) {\n throw new TypeError(\"Cannot set require.cache['\" + String(prop) + \"']\");\n },\n deleteProperty(_target, prop) {\n throw new TypeError(\"Cannot delete require.cache['\" + String(prop) + \"']\");\n },\n defineProperty(_target, prop) {\n throw new TypeError(\"Cannot define property '\" + String(prop) + \"' on require.cache\");\n },\n has(target, prop) {\n return Reflect.has(target, prop);\n },\n ownKeys(target) {\n return Reflect.ownKeys(target);\n },\n getOwnPropertyDescriptor(target, prop) {\n return Reflect.getOwnPropertyDescriptor(target, prop);\n }\n });\n globalThis.require.cache = __moduleCacheProxy;\n Object.defineProperty(globalThis, \"_moduleCache\", {\n value: __moduleCacheProxy,\n writable: false,\n configurable: true,\n enumerable: false\n });\n if (typeof _moduleModule !== \"undefined\") {\n if (_moduleModule.Module) {\n _moduleModule.Module._cache = __moduleCacheProxy;\n }\n _moduleModule._cache = __moduleCacheProxy;\n }\n})();\n", + "requireSetup": "\"use strict\";\n(() => {\n // ../core/isolate-runtime/src/inject/require-setup.ts\n var __requireExposeCustomGlobal = typeof globalThis.__runtimeExposeCustomGlobal === \"function\" ? globalThis.__runtimeExposeCustomGlobal : function exposeCustomGlobal(name2, value) {\n Object.defineProperty(globalThis, name2, {\n value,\n writable: false,\n configurable: false,\n enumerable: true\n });\n };\n if (typeof globalThis.AbortController === \"undefined\" || typeof globalThis.AbortSignal === \"undefined\") {\n class AbortSignal {\n constructor() {\n this.aborted = false;\n this.reason = void 0;\n this.onabort = null;\n this._listeners = [];\n }\n addEventListener(type, listener) {\n if (type !== \"abort\" || typeof listener !== \"function\") return;\n this._listeners.push(listener);\n }\n removeEventListener(type, listener) {\n if (type !== \"abort\" || typeof listener !== \"function\") return;\n const index = this._listeners.indexOf(listener);\n if (index !== -1) {\n this._listeners.splice(index, 1);\n }\n }\n dispatchEvent(event) {\n if (!event || event.type !== \"abort\") return false;\n if (typeof this.onabort === \"function\") {\n try {\n this.onabort.call(this, event);\n } catch {\n }\n }\n const listeners = this._listeners.slice();\n for (const listener of listeners) {\n try {\n listener.call(this, event);\n } catch {\n }\n }\n return true;\n }\n }\n class AbortController {\n constructor() {\n this.signal = new AbortSignal();\n }\n abort(reason) {\n if (this.signal.aborted) return;\n this.signal.aborted = true;\n this.signal.reason = reason;\n this.signal.dispatchEvent({ type: \"abort\" });\n }\n }\n __requireExposeCustomGlobal(\"AbortSignal\", AbortSignal);\n __requireExposeCustomGlobal(\"AbortController\", AbortController);\n }\n if (typeof globalThis.structuredClone !== \"function\") {\n let structuredClonePolyfill = function(value) {\n if (value === null || typeof value !== \"object\") {\n return value;\n }\n if (value instanceof ArrayBuffer) {\n return value.slice(0);\n }\n if (ArrayBuffer.isView(value)) {\n if (value instanceof Uint8Array) {\n return new Uint8Array(value);\n }\n return new value.constructor(value);\n }\n return JSON.parse(JSON.stringify(value));\n };\n structuredClonePolyfill2 = structuredClonePolyfill;\n __requireExposeCustomGlobal(\"structuredClone\", structuredClonePolyfill);\n }\n var structuredClonePolyfill2;\n if (typeof globalThis.SharedArrayBuffer === \"undefined\") {\n globalThis.SharedArrayBuffer = ArrayBuffer;\n __requireExposeCustomGlobal(\"SharedArrayBuffer\", ArrayBuffer);\n }\n if (typeof globalThis.btoa !== \"function\") {\n __requireExposeCustomGlobal(\"btoa\", function btoa(input) {\n return Buffer.from(String(input), \"binary\").toString(\"base64\");\n });\n }\n if (typeof globalThis.atob !== \"function\") {\n __requireExposeCustomGlobal(\"atob\", function atob(input) {\n return Buffer.from(String(input), \"base64\").toString(\"binary\");\n });\n }\n function _dirname(p) {\n const lastSlash = p.lastIndexOf(\"/\");\n if (lastSlash === -1) return \".\";\n if (lastSlash === 0) return \"/\";\n return p.slice(0, lastSlash);\n }\n if (typeof globalThis.TextDecoder === \"function\") {\n _OrigTextDecoder = globalThis.TextDecoder;\n _utf8Aliases = {\n \"utf-8\": true,\n \"utf8\": true,\n \"unicode-1-1-utf-8\": true,\n \"ascii\": true,\n \"us-ascii\": true,\n \"iso-8859-1\": true,\n \"latin1\": true,\n \"binary\": true,\n \"windows-1252\": true,\n \"utf-16le\": true,\n \"utf-16\": true,\n \"ucs-2\": true,\n \"ucs2\": true\n };\n globalThis.TextDecoder = function TextDecoder(encoding, options) {\n var label = encoding !== void 0 ? String(encoding).toLowerCase().replace(/\\s/g, \"\") : \"utf-8\";\n if (_utf8Aliases[label]) {\n return new _OrigTextDecoder(\"utf-8\", options);\n }\n return new _OrigTextDecoder(encoding, options);\n };\n globalThis.TextDecoder.prototype = _OrigTextDecoder.prototype;\n }\n var _OrigTextDecoder;\n var _utf8Aliases;\n function _patchPolyfill(name2, result2) {\n if (typeof result2 !== \"object\" && typeof result2 !== \"function\" || result2 === null) {\n return result2;\n }\n if (name2 === \"buffer\") {\n const maxLength = typeof result2.kMaxLength === \"number\" ? result2.kMaxLength : 2147483647;\n const maxStringLength = typeof result2.kStringMaxLength === \"number\" ? result2.kStringMaxLength : 536870888;\n if (typeof result2.constants !== \"object\" || result2.constants === null) {\n result2.constants = {};\n }\n if (typeof result2.constants.MAX_LENGTH !== \"number\") {\n result2.constants.MAX_LENGTH = maxLength;\n }\n if (typeof result2.constants.MAX_STRING_LENGTH !== \"number\") {\n result2.constants.MAX_STRING_LENGTH = maxStringLength;\n }\n if (typeof result2.kMaxLength !== \"number\") {\n result2.kMaxLength = maxLength;\n }\n if (typeof result2.kStringMaxLength !== \"number\") {\n result2.kStringMaxLength = maxStringLength;\n }\n const BufferCtor = result2.Buffer;\n if ((typeof BufferCtor === \"function\" || typeof BufferCtor === \"object\") && BufferCtor !== null) {\n if (typeof BufferCtor.kMaxLength !== \"number\") {\n BufferCtor.kMaxLength = maxLength;\n }\n if (typeof BufferCtor.kStringMaxLength !== \"number\") {\n BufferCtor.kStringMaxLength = maxStringLength;\n }\n if (typeof BufferCtor.constants !== \"object\" || BufferCtor.constants === null) {\n BufferCtor.constants = result2.constants;\n }\n var proto = BufferCtor.prototype;\n if (proto && typeof proto.utf8Slice !== \"function\") {\n var encodings = [\"utf8\", \"latin1\", \"ascii\", \"hex\", \"base64\", \"ucs2\", \"utf16le\"];\n for (var ei = 0; ei < encodings.length; ei++) {\n var enc = encodings[ei];\n (function(e) {\n if (typeof proto[e + \"Slice\"] !== \"function\") {\n proto[e + \"Slice\"] = function(start, end) {\n return this.toString(e, start, end);\n };\n }\n if (typeof proto[e + \"Write\"] !== \"function\") {\n proto[e + \"Write\"] = function(string, offset, length) {\n return this.write(string, offset, length, e);\n };\n }\n })(enc);\n }\n }\n }\n return result2;\n }\n if (name2 === \"util\" && typeof result2.formatWithOptions === \"undefined\" && typeof result2.format === \"function\") {\n result2.formatWithOptions = function formatWithOptions(inspectOptions, ...args) {\n return result2.format.apply(null, args);\n };\n }\n if (name2 === \"util\") {\n return result2;\n }\n if (name2 === \"url\") {\n const OriginalURL = result2.URL;\n if (typeof OriginalURL !== \"function\" || OriginalURL._patched) {\n return result2;\n }\n const PatchedURL = function PatchedURL2(url, base) {\n if (typeof url === \"string\" && url.startsWith(\"file:\") && !url.startsWith(\"file://\") && base === void 0) {\n if (typeof process !== \"undefined\" && typeof process.cwd === \"function\") {\n const cwd = process.cwd();\n if (cwd) {\n try {\n return new OriginalURL(url, \"file://\" + cwd + \"/\");\n } catch (e) {\n }\n }\n }\n }\n return base !== void 0 ? new OriginalURL(url, base) : new OriginalURL(url);\n };\n Object.keys(OriginalURL).forEach(function(key) {\n try {\n PatchedURL[key] = OriginalURL[key];\n } catch {\n }\n });\n Object.setPrototypeOf(PatchedURL, OriginalURL);\n PatchedURL.prototype = OriginalURL.prototype;\n PatchedURL._patched = true;\n const descriptor = Object.getOwnPropertyDescriptor(result2, \"URL\");\n if (descriptor && descriptor.configurable !== true && descriptor.writable !== true && typeof descriptor.set !== \"function\") {\n return result2;\n }\n try {\n result2.URL = PatchedURL;\n } catch {\n try {\n Object.defineProperty(result2, \"URL\", {\n value: PatchedURL,\n writable: true,\n configurable: true,\n enumerable: descriptor?.enumerable ?? true\n });\n } catch {\n }\n }\n return result2;\n }\n if (name2 === \"zlib\") {\n var zlibConstants = typeof result2.constants === \"object\" && result2.constants !== null ? result2.constants : {};\n if (typeof result2.constants !== \"object\" || result2.constants === null) {\n var constKeys = Object.keys(result2);\n for (var ci = 0; ci < constKeys.length; ci++) {\n var ck = constKeys[ci];\n if (ck.indexOf(\"Z_\") === 0 && typeof result2[ck] === \"number\") {\n zlibConstants[ck] = result2[ck];\n }\n }\n if (typeof zlibConstants.Z_NO_FLUSH !== \"number\") zlibConstants.Z_NO_FLUSH = 0;\n if (typeof zlibConstants.Z_PARTIAL_FLUSH !== \"number\") zlibConstants.Z_PARTIAL_FLUSH = 1;\n if (typeof zlibConstants.Z_SYNC_FLUSH !== \"number\") zlibConstants.Z_SYNC_FLUSH = 2;\n if (typeof zlibConstants.Z_FULL_FLUSH !== \"number\") zlibConstants.Z_FULL_FLUSH = 3;\n if (typeof zlibConstants.Z_FINISH !== \"number\") zlibConstants.Z_FINISH = 4;\n if (typeof zlibConstants.Z_BLOCK !== \"number\") zlibConstants.Z_BLOCK = 5;\n if (typeof zlibConstants.Z_TREES !== \"number\") zlibConstants.Z_TREES = 6;\n if (typeof zlibConstants.Z_OK !== \"number\") zlibConstants.Z_OK = 0;\n if (typeof zlibConstants.Z_STREAM_END !== \"number\") zlibConstants.Z_STREAM_END = 1;\n if (typeof zlibConstants.Z_NEED_DICT !== \"number\") zlibConstants.Z_NEED_DICT = 2;\n if (typeof zlibConstants.Z_ERRNO !== \"number\") zlibConstants.Z_ERRNO = -1;\n if (typeof zlibConstants.Z_STREAM_ERROR !== \"number\") zlibConstants.Z_STREAM_ERROR = -2;\n if (typeof zlibConstants.Z_DATA_ERROR !== \"number\") zlibConstants.Z_DATA_ERROR = -3;\n if (typeof zlibConstants.Z_MEM_ERROR !== \"number\") zlibConstants.Z_MEM_ERROR = -4;\n if (typeof zlibConstants.Z_BUF_ERROR !== \"number\") zlibConstants.Z_BUF_ERROR = -5;\n if (typeof zlibConstants.Z_VERSION_ERROR !== \"number\") zlibConstants.Z_VERSION_ERROR = -6;\n if (typeof zlibConstants.Z_NO_COMPRESSION !== \"number\") zlibConstants.Z_NO_COMPRESSION = 0;\n if (typeof zlibConstants.Z_BEST_SPEED !== \"number\") zlibConstants.Z_BEST_SPEED = 1;\n if (typeof zlibConstants.Z_BEST_COMPRESSION !== \"number\") zlibConstants.Z_BEST_COMPRESSION = 9;\n if (typeof zlibConstants.Z_DEFAULT_COMPRESSION !== \"number\") zlibConstants.Z_DEFAULT_COMPRESSION = -1;\n if (typeof zlibConstants.Z_FILTERED !== \"number\") zlibConstants.Z_FILTERED = 1;\n if (typeof zlibConstants.Z_HUFFMAN_ONLY !== \"number\") zlibConstants.Z_HUFFMAN_ONLY = 2;\n if (typeof zlibConstants.Z_RLE !== \"number\") zlibConstants.Z_RLE = 3;\n if (typeof zlibConstants.Z_FIXED !== \"number\") zlibConstants.Z_FIXED = 4;\n if (typeof zlibConstants.Z_DEFAULT_STRATEGY !== \"number\") zlibConstants.Z_DEFAULT_STRATEGY = 0;\n if (typeof zlibConstants.DEFLATE !== \"number\") zlibConstants.DEFLATE = 1;\n if (typeof zlibConstants.INFLATE !== \"number\") zlibConstants.INFLATE = 2;\n if (typeof zlibConstants.GZIP !== \"number\") zlibConstants.GZIP = 3;\n if (typeof zlibConstants.DEFLATERAW !== \"number\") zlibConstants.DEFLATERAW = 4;\n if (typeof zlibConstants.INFLATERAW !== \"number\") zlibConstants.INFLATERAW = 5;\n if (typeof zlibConstants.UNZIP !== \"number\") zlibConstants.UNZIP = 6;\n if (typeof zlibConstants.GUNZIP !== \"number\") zlibConstants.GUNZIP = 7;\n }\n result2.constants = zlibConstants;\n return result2;\n }\n if (name2 === \"crypto\") {\n let createCryptoRangeError2 = function(name3, message) {\n var error = new RangeError(message);\n error.code = \"ERR_OUT_OF_RANGE\";\n error.name = \"RangeError\";\n return error;\n }, createCryptoError2 = function(code, message) {\n var error = new Error(message);\n error.code = code;\n return error;\n }, encodeCryptoResult2 = function(buffer, encoding) {\n if (!encoding || encoding === \"buffer\") return buffer;\n return buffer.toString(encoding);\n }, isSharedArrayBufferInstance2 = function(value) {\n return typeof SharedArrayBuffer !== \"undefined\" && value instanceof SharedArrayBuffer;\n }, isBinaryLike2 = function(value) {\n return Buffer.isBuffer(value) || ArrayBuffer.isView(value) || value instanceof ArrayBuffer || isSharedArrayBufferInstance2(value);\n }, normalizeByteSource2 = function(value, name3, options) {\n var allowNull = options && options.allowNull;\n if (allowNull && value === null) {\n return null;\n }\n if (typeof value === \"string\") {\n return Buffer.from(value, \"utf8\");\n }\n if (Buffer.isBuffer(value)) {\n return Buffer.from(value);\n }\n if (ArrayBuffer.isView(value)) {\n return Buffer.from(value.buffer, value.byteOffset, value.byteLength);\n }\n if (value instanceof ArrayBuffer || isSharedArrayBufferInstance2(value)) {\n return Buffer.from(value);\n }\n throw createInvalidArgTypeError(\n name3,\n \"of type string or an instance of ArrayBuffer, Buffer, TypedArray, or DataView\",\n value\n );\n }, serializeCipherBridgeOptions2 = function(options) {\n if (!options) {\n return \"\";\n }\n var serialized = {};\n if (options.authTagLength !== void 0) {\n serialized.authTagLength = options.authTagLength;\n }\n if (options.authTag) {\n serialized.authTag = options.authTag.toString(\"base64\");\n }\n if (options.aad) {\n serialized.aad = options.aad.toString(\"base64\");\n }\n if (options.aadOptions !== void 0) {\n serialized.aadOptions = options.aadOptions;\n }\n if (options.autoPadding !== void 0) {\n serialized.autoPadding = options.autoPadding;\n }\n if (options.validateOnly !== void 0) {\n serialized.validateOnly = options.validateOnly;\n }\n return JSON.stringify(serialized);\n };\n var createCryptoRangeError = createCryptoRangeError2, createCryptoError = createCryptoError2, encodeCryptoResult = encodeCryptoResult2, isSharedArrayBufferInstance = isSharedArrayBufferInstance2, isBinaryLike = isBinaryLike2, normalizeByteSource = normalizeByteSource2, serializeCipherBridgeOptions = serializeCipherBridgeOptions2;\n var _runtimeRequire = globalThis.require;\n var _streamModule = _runtimeRequire && _runtimeRequire(\"stream\");\n var _utilModule = _runtimeRequire && _runtimeRequire(\"util\");\n var _Transform = _streamModule && _streamModule.Transform;\n var _inherits = _utilModule && _utilModule.inherits;\n if (typeof _cryptoHashDigest !== \"undefined\") {\n let SandboxHash2 = function(algorithm, options) {\n if (!(this instanceof SandboxHash2)) {\n return new SandboxHash2(algorithm, options);\n }\n if (!_Transform || !_inherits) {\n throw new Error(\"stream.Transform is required for crypto.Hash\");\n }\n if (typeof algorithm !== \"string\") {\n throw createInvalidArgTypeError(\"algorithm\", \"of type string\", algorithm);\n }\n _Transform.call(this, options);\n this._algorithm = algorithm;\n this._chunks = [];\n this._finalized = false;\n this._cachedDigest = null;\n this._allowCachedDigest = false;\n };\n var SandboxHash = SandboxHash2;\n _inherits(SandboxHash2, _Transform);\n SandboxHash2.prototype.update = function update(data, inputEncoding) {\n if (this._finalized) {\n throw createCryptoError2(\"ERR_CRYPTO_HASH_FINALIZED\", \"Digest already called\");\n }\n if (typeof data === \"string\") {\n this._chunks.push(Buffer.from(data, inputEncoding || \"utf8\"));\n } else if (isBinaryLike2(data)) {\n this._chunks.push(Buffer.from(data));\n } else {\n throw createInvalidArgTypeError(\n \"data\",\n \"one of type string, Buffer, TypedArray, or DataView\",\n data\n );\n }\n return this;\n };\n SandboxHash2.prototype._finishDigest = function _finishDigest() {\n if (this._cachedDigest) {\n return this._cachedDigest;\n }\n var combined = Buffer.concat(this._chunks);\n var resultBase64 = _cryptoHashDigest.applySync(void 0, [\n this._algorithm,\n combined.toString(\"base64\")\n ]);\n this._cachedDigest = Buffer.from(resultBase64, \"base64\");\n this._finalized = true;\n return this._cachedDigest;\n };\n SandboxHash2.prototype.digest = function digest(encoding) {\n if (this._finalized && !this._allowCachedDigest) {\n throw createCryptoError2(\"ERR_CRYPTO_HASH_FINALIZED\", \"Digest already called\");\n }\n var resultBuffer = this._finishDigest();\n this._allowCachedDigest = false;\n return encodeCryptoResult2(resultBuffer, encoding);\n };\n SandboxHash2.prototype.copy = function copy() {\n if (this._finalized) {\n throw createCryptoError2(\"ERR_CRYPTO_HASH_FINALIZED\", \"Digest already called\");\n }\n var c = new SandboxHash2(this._algorithm);\n c._chunks = this._chunks.slice();\n return c;\n };\n SandboxHash2.prototype._transform = function _transform(chunk, encoding, callback) {\n try {\n this.update(chunk, encoding === \"buffer\" ? void 0 : encoding);\n callback();\n } catch (error) {\n callback(normalizeCryptoBridgeError(error));\n }\n };\n SandboxHash2.prototype._flush = function _flush(callback) {\n try {\n var output = this._finishDigest();\n this._allowCachedDigest = true;\n this.push(output);\n callback();\n } catch (error) {\n callback(normalizeCryptoBridgeError(error));\n }\n };\n result2.createHash = function createHash(algorithm, options) {\n return new SandboxHash2(algorithm, options);\n };\n result2.Hash = SandboxHash2;\n }\n if (typeof _cryptoHmacDigest !== \"undefined\") {\n let SandboxHmac2 = function(algorithm, key) {\n this._algorithm = algorithm;\n if (typeof key === \"string\") {\n this._key = Buffer.from(key, \"utf8\");\n } else if (key && typeof key === \"object\" && key._raw !== void 0) {\n this._key = Buffer.from(key._raw, \"base64\");\n } else if (key && typeof key === \"object\" && key._pem !== void 0) {\n this._key = Buffer.from(key._pem, \"utf8\");\n } else {\n this._key = Buffer.from(key);\n }\n this._chunks = [];\n };\n var SandboxHmac = SandboxHmac2;\n SandboxHmac2.prototype.update = function update(data, inputEncoding) {\n if (typeof data === \"string\") {\n this._chunks.push(Buffer.from(data, inputEncoding || \"utf8\"));\n } else {\n this._chunks.push(Buffer.from(data));\n }\n return this;\n };\n SandboxHmac2.prototype.digest = function digest(encoding) {\n var combined = Buffer.concat(this._chunks);\n var resultBase64 = _cryptoHmacDigest.applySync(void 0, [\n this._algorithm,\n this._key.toString(\"base64\"),\n combined.toString(\"base64\")\n ]);\n var resultBuffer = Buffer.from(resultBase64, \"base64\");\n if (!encoding || encoding === \"buffer\") return resultBuffer;\n return resultBuffer.toString(encoding);\n };\n SandboxHmac2.prototype.copy = function copy() {\n var c = new SandboxHmac2(this._algorithm, this._key);\n c._chunks = this._chunks.slice();\n return c;\n };\n SandboxHmac2.prototype.write = function write(data, encoding) {\n this.update(data, encoding);\n return true;\n };\n SandboxHmac2.prototype.end = function end(data, encoding) {\n if (data) this.update(data, encoding);\n };\n result2.createHmac = function createHmac(algorithm, key) {\n return new SandboxHmac2(algorithm, key);\n };\n result2.Hmac = SandboxHmac2;\n }\n if (typeof _cryptoRandomFill !== \"undefined\") {\n result2.randomBytes = function randomBytes(size, callback) {\n if (typeof size !== \"number\" || size < 0 || size !== (size | 0)) {\n var err = new TypeError('The \"size\" argument must be of type number. Received type ' + typeof size);\n if (typeof callback === \"function\") {\n callback(err);\n return;\n }\n throw err;\n }\n if (size > 2147483647) {\n var rangeErr = new RangeError('The value of \"size\" is out of range. It must be >= 0 && <= 2147483647. Received ' + size);\n if (typeof callback === \"function\") {\n callback(rangeErr);\n return;\n }\n throw rangeErr;\n }\n var buf = Buffer.alloc(size);\n var offset = 0;\n while (offset < size) {\n var chunk = Math.min(size - offset, 65536);\n var base64 = _cryptoRandomFill.applySync(void 0, [chunk]);\n var hostBytes = Buffer.from(base64, \"base64\");\n hostBytes.copy(buf, offset);\n offset += chunk;\n }\n if (typeof callback === \"function\") {\n callback(null, buf);\n return;\n }\n return buf;\n };\n result2.randomFillSync = function randomFillSync(buffer, offset, size) {\n if (offset === void 0) offset = 0;\n var byteLength = buffer.byteLength !== void 0 ? buffer.byteLength : buffer.length;\n if (size === void 0) size = byteLength - offset;\n if (offset < 0 || size < 0 || offset + size > byteLength) {\n throw new RangeError('The value of \"offset + size\" is out of range.');\n }\n var bytes = new Uint8Array(buffer.buffer || buffer, buffer.byteOffset ? buffer.byteOffset + offset : offset, size);\n var filled = 0;\n while (filled < size) {\n var chunk = Math.min(size - filled, 65536);\n var base64 = _cryptoRandomFill.applySync(void 0, [chunk]);\n var hostBytes = Buffer.from(base64, \"base64\");\n bytes.set(hostBytes, filled);\n filled += chunk;\n }\n return buffer;\n };\n result2.randomFill = function randomFill(buffer, offsetOrCb, sizeOrCb, callback) {\n var offset = 0;\n var size;\n var cb;\n if (typeof offsetOrCb === \"function\") {\n cb = offsetOrCb;\n } else if (typeof sizeOrCb === \"function\") {\n offset = offsetOrCb || 0;\n cb = sizeOrCb;\n } else {\n offset = offsetOrCb || 0;\n size = sizeOrCb;\n cb = callback;\n }\n if (typeof cb !== \"function\") {\n throw new TypeError(\"Callback must be a function\");\n }\n try {\n result2.randomFillSync(buffer, offset, size);\n cb(null, buffer);\n } catch (e) {\n cb(e);\n }\n };\n result2.randomInt = function randomInt(minOrMax, maxOrCb, callback) {\n var min, max, cb;\n if (typeof maxOrCb === \"function\" || maxOrCb === void 0) {\n min = 0;\n max = minOrMax;\n cb = maxOrCb;\n } else {\n min = minOrMax;\n max = maxOrCb;\n cb = callback;\n }\n if (!Number.isSafeInteger(min)) {\n var minErr = new TypeError('The \"min\" argument must be a safe integer');\n if (typeof cb === \"function\") {\n cb(minErr);\n return;\n }\n throw minErr;\n }\n if (!Number.isSafeInteger(max)) {\n var maxErr = new TypeError('The \"max\" argument must be a safe integer');\n if (typeof cb === \"function\") {\n cb(maxErr);\n return;\n }\n throw maxErr;\n }\n if (max <= min) {\n var rangeErr2 = new RangeError('The value of \"max\" is out of range. It must be greater than the value of \"min\" (' + min + \")\");\n if (typeof cb === \"function\") {\n cb(rangeErr2);\n return;\n }\n throw rangeErr2;\n }\n var range = max - min;\n var bytes = 6;\n var maxValid = Math.pow(2, 48) - Math.pow(2, 48) % range;\n var val;\n do {\n var base64 = _cryptoRandomFill.applySync(void 0, [bytes]);\n var buf = Buffer.from(base64, \"base64\");\n val = buf.readUIntBE(0, bytes);\n } while (val >= maxValid);\n var result22 = min + val % range;\n if (typeof cb === \"function\") {\n cb(null, result22);\n return;\n }\n return result22;\n };\n }\n if (typeof _cryptoPbkdf2 !== \"undefined\") {\n let createPbkdf2ArgTypeError2 = function(name3, value) {\n var received;\n if (value == null) {\n received = \" Received \" + value;\n } else if (typeof value === \"object\") {\n received = value.constructor && value.constructor.name ? \" Received an instance of \" + value.constructor.name : \" Received [object Object]\";\n } else {\n var inspected = typeof value === \"string\" ? \"'\" + value + \"'\" : String(value);\n received = \" Received type \" + typeof value + \" (\" + inspected + \")\";\n }\n var error = new TypeError('The \"' + name3 + '\" argument must be of type number.' + received);\n error.code = \"ERR_INVALID_ARG_TYPE\";\n return error;\n }, validatePbkdf2Args2 = function(password, salt, iterations, keylen, digest) {\n var pwBuf = normalizeByteSource2(password, \"password\");\n var saltBuf = normalizeByteSource2(salt, \"salt\");\n if (typeof iterations !== \"number\") {\n throw createPbkdf2ArgTypeError2(\"iterations\", iterations);\n }\n if (!Number.isInteger(iterations)) {\n throw createCryptoRangeError2(\n \"iterations\",\n 'The value of \"iterations\" is out of range. It must be an integer. Received ' + iterations\n );\n }\n if (iterations < 1 || iterations > 2147483647) {\n throw createCryptoRangeError2(\n \"iterations\",\n 'The value of \"iterations\" is out of range. It must be >= 1 && <= 2147483647. Received ' + iterations\n );\n }\n if (typeof keylen !== \"number\") {\n throw createPbkdf2ArgTypeError2(\"keylen\", keylen);\n }\n if (!Number.isInteger(keylen)) {\n throw createCryptoRangeError2(\n \"keylen\",\n 'The value of \"keylen\" is out of range. It must be an integer. Received ' + keylen\n );\n }\n if (keylen < 0 || keylen > 2147483647) {\n throw createCryptoRangeError2(\n \"keylen\",\n 'The value of \"keylen\" is out of range. It must be >= 0 && <= 2147483647. Received ' + keylen\n );\n }\n if (typeof digest !== \"string\") {\n throw createInvalidArgTypeError(\"digest\", \"of type string\", digest);\n }\n return {\n password: pwBuf,\n salt: saltBuf\n };\n };\n var createPbkdf2ArgTypeError = createPbkdf2ArgTypeError2, validatePbkdf2Args = validatePbkdf2Args2;\n result2.pbkdf2Sync = function pbkdf2Sync(password, salt, iterations, keylen, digest) {\n var normalized = validatePbkdf2Args2(password, salt, iterations, keylen, digest);\n try {\n var resultBase64 = _cryptoPbkdf2.applySync(void 0, [\n normalized.password.toString(\"base64\"),\n normalized.salt.toString(\"base64\"),\n iterations,\n keylen,\n digest\n ]);\n return Buffer.from(resultBase64, \"base64\");\n } catch (error) {\n throw normalizeCryptoBridgeError(error);\n }\n };\n result2.pbkdf2 = function pbkdf2(password, salt, iterations, keylen, digest, callback) {\n if (typeof digest === \"function\" && callback === void 0) {\n callback = digest;\n digest = void 0;\n }\n if (typeof callback !== \"function\") {\n throw createInvalidArgTypeError(\"callback\", \"of type function\", callback);\n }\n try {\n var derived = result2.pbkdf2Sync(password, salt, iterations, keylen, digest);\n scheduleCryptoCallback(callback, [null, derived]);\n } catch (e) {\n throw normalizeCryptoBridgeError(e);\n }\n };\n }\n if (typeof _cryptoScrypt !== \"undefined\") {\n result2.scryptSync = function scryptSync(password, salt, keylen, options) {\n var pwBuf = typeof password === \"string\" ? Buffer.from(password, \"utf8\") : Buffer.from(password);\n var saltBuf = typeof salt === \"string\" ? Buffer.from(salt, \"utf8\") : Buffer.from(salt);\n var opts = {};\n if (options) {\n if (options.N !== void 0) opts.N = options.N;\n if (options.r !== void 0) opts.r = options.r;\n if (options.p !== void 0) opts.p = options.p;\n if (options.maxmem !== void 0) opts.maxmem = options.maxmem;\n if (options.cost !== void 0) opts.N = options.cost;\n if (options.blockSize !== void 0) opts.r = options.blockSize;\n if (options.parallelization !== void 0) opts.p = options.parallelization;\n }\n var resultBase64 = _cryptoScrypt.applySync(void 0, [\n pwBuf.toString(\"base64\"),\n saltBuf.toString(\"base64\"),\n keylen,\n JSON.stringify(opts)\n ]);\n return Buffer.from(resultBase64, \"base64\");\n };\n result2.scrypt = function scrypt(password, salt, keylen, optionsOrCb, callback) {\n var opts = optionsOrCb;\n var cb = callback;\n if (typeof optionsOrCb === \"function\") {\n opts = void 0;\n cb = optionsOrCb;\n }\n try {\n var derived = result2.scryptSync(password, salt, keylen, opts);\n cb(null, derived);\n } catch (e) {\n cb(e);\n }\n };\n }\n if (typeof _cryptoCipheriv !== \"undefined\") {\n let SandboxCipher2 = function(algorithm, key, iv, options) {\n if (!(this instanceof SandboxCipher2)) {\n return new SandboxCipher2(algorithm, key, iv, options);\n }\n if (typeof algorithm !== \"string\") {\n throw createInvalidArgTypeError(\"cipher\", \"of type string\", algorithm);\n }\n _Transform.call(this);\n this._algorithm = algorithm;\n this._key = normalizeByteSource2(key, \"key\");\n this._iv = normalizeByteSource2(iv, \"iv\", { allowNull: true });\n this._options = options || void 0;\n this._authTag = null;\n this._finalized = false;\n this._sessionCreated = false;\n this._sessionId = void 0;\n this._aad = null;\n this._aadOptions = void 0;\n this._autoPadding = void 0;\n this._chunks = [];\n this._bufferedMode = !_useSessionCipher || !!options;\n if (!this._bufferedMode) {\n this._ensureSession();\n } else if (!options) {\n _cryptoCipheriv.applySync(void 0, [\n this._algorithm,\n this._key.toString(\"base64\"),\n this._iv === null ? null : this._iv.toString(\"base64\"),\n \"\",\n serializeCipherBridgeOptions2({ validateOnly: true })\n ]);\n }\n };\n var SandboxCipher = SandboxCipher2;\n var _useSessionCipher = typeof _cryptoCipherivCreate !== \"undefined\";\n _inherits(SandboxCipher2, _Transform);\n SandboxCipher2.prototype._ensureSession = function _ensureSession() {\n if (this._bufferedMode || this._sessionCreated) {\n return;\n }\n this._sessionCreated = true;\n this._sessionId = _cryptoCipherivCreate.applySync(void 0, [\n \"cipher\",\n this._algorithm,\n this._key.toString(\"base64\"),\n this._iv === null ? null : this._iv.toString(\"base64\"),\n serializeCipherBridgeOptions2(this._getBridgeOptions())\n ]);\n };\n SandboxCipher2.prototype._getBridgeOptions = function _getBridgeOptions() {\n var options = {};\n if (this._options && this._options.authTagLength !== void 0) {\n options.authTagLength = this._options.authTagLength;\n }\n if (this._aad) {\n options.aad = this._aad;\n }\n if (this._aadOptions !== void 0) {\n options.aadOptions = this._aadOptions;\n }\n if (this._autoPadding !== void 0) {\n options.autoPadding = this._autoPadding;\n }\n return Object.keys(options).length === 0 ? null : options;\n };\n SandboxCipher2.prototype.update = function update(data, inputEncoding, outputEncoding) {\n if (this._finalized) {\n throw new Error(\"Attempting to call update() after final()\");\n }\n var buf;\n if (typeof data === \"string\") {\n buf = Buffer.from(data, inputEncoding || \"utf8\");\n } else {\n buf = normalizeByteSource2(data, \"data\");\n }\n if (!this._bufferedMode) {\n this._ensureSession();\n var resultBase64 = _cryptoCipherivUpdate.applySync(void 0, [this._sessionId, buf.toString(\"base64\")]);\n var resultBuffer = Buffer.from(resultBase64, \"base64\");\n return encodeCryptoResult2(resultBuffer, outputEncoding);\n }\n this._chunks.push(buf);\n return encodeCryptoResult2(Buffer.alloc(0), outputEncoding);\n };\n SandboxCipher2.prototype.final = function final(outputEncoding) {\n if (this._finalized) throw new Error(\"Attempting to call final() after already finalized\");\n this._finalized = true;\n var parsed;\n if (!this._bufferedMode) {\n this._ensureSession();\n var resultJson = _cryptoCipherivFinal.applySync(void 0, [this._sessionId]);\n parsed = JSON.parse(resultJson);\n } else {\n var combined = Buffer.concat(this._chunks);\n var resultJson2 = _cryptoCipheriv.applySync(void 0, [\n this._algorithm,\n this._key.toString(\"base64\"),\n this._iv === null ? null : this._iv.toString(\"base64\"),\n combined.toString(\"base64\"),\n serializeCipherBridgeOptions2(this._getBridgeOptions())\n ]);\n parsed = JSON.parse(resultJson2);\n }\n if (parsed.authTag) {\n this._authTag = Buffer.from(parsed.authTag, \"base64\");\n }\n var resultBuffer = Buffer.from(parsed.data, \"base64\");\n return encodeCryptoResult2(resultBuffer, outputEncoding);\n };\n SandboxCipher2.prototype.getAuthTag = function getAuthTag() {\n if (!this._finalized) throw new Error(\"Cannot call getAuthTag before final()\");\n if (!this._authTag) throw new Error(\"Auth tag is not available\");\n return this._authTag;\n };\n SandboxCipher2.prototype.setAAD = function setAAD(aad, options) {\n this._bufferedMode = true;\n this._aad = normalizeByteSource2(aad, \"buffer\");\n this._aadOptions = options;\n return this;\n };\n SandboxCipher2.prototype.setAutoPadding = function setAutoPadding(autoPadding) {\n this._bufferedMode = true;\n this._autoPadding = autoPadding !== false;\n return this;\n };\n SandboxCipher2.prototype._transform = function _transform(chunk, encoding, callback) {\n try {\n var output = this.update(chunk, encoding === \"buffer\" ? void 0 : encoding);\n if (output.length) {\n this.push(output);\n }\n callback();\n } catch (error) {\n callback(normalizeCryptoBridgeError(error));\n }\n };\n SandboxCipher2.prototype._flush = function _flush(callback) {\n try {\n var output = this.final();\n if (output.length) {\n this.push(output);\n }\n callback();\n } catch (error) {\n callback(normalizeCryptoBridgeError(error));\n }\n };\n result2.createCipheriv = function createCipheriv(algorithm, key, iv, options) {\n return new SandboxCipher2(algorithm, key, iv, options);\n };\n result2.Cipheriv = SandboxCipher2;\n }\n if (typeof _cryptoDecipheriv !== \"undefined\") {\n let SandboxDecipher2 = function(algorithm, key, iv, options) {\n if (!(this instanceof SandboxDecipher2)) {\n return new SandboxDecipher2(algorithm, key, iv, options);\n }\n if (typeof algorithm !== \"string\") {\n throw createInvalidArgTypeError(\"cipher\", \"of type string\", algorithm);\n }\n _Transform.call(this);\n this._algorithm = algorithm;\n this._key = normalizeByteSource2(key, \"key\");\n this._iv = normalizeByteSource2(iv, \"iv\", { allowNull: true });\n this._options = options || void 0;\n this._authTag = null;\n this._finalized = false;\n this._sessionCreated = false;\n this._aad = null;\n this._aadOptions = void 0;\n this._autoPadding = void 0;\n this._chunks = [];\n this._bufferedMode = !_useSessionCipher || !!options;\n if (!this._bufferedMode) {\n this._ensureSession();\n } else if (!options) {\n _cryptoDecipheriv.applySync(void 0, [\n this._algorithm,\n this._key.toString(\"base64\"),\n this._iv === null ? null : this._iv.toString(\"base64\"),\n \"\",\n serializeCipherBridgeOptions2({ validateOnly: true })\n ]);\n }\n };\n var SandboxDecipher = SandboxDecipher2;\n _inherits(SandboxDecipher2, _Transform);\n SandboxDecipher2.prototype._ensureSession = function _ensureSession() {\n if (!this._bufferedMode && !this._sessionCreated) {\n this._sessionCreated = true;\n this._sessionId = _cryptoCipherivCreate.applySync(void 0, [\n \"decipher\",\n this._algorithm,\n this._key.toString(\"base64\"),\n this._iv === null ? null : this._iv.toString(\"base64\"),\n serializeCipherBridgeOptions2(this._getBridgeOptions())\n ]);\n }\n };\n SandboxDecipher2.prototype._getBridgeOptions = function _getBridgeOptions() {\n var options = {};\n if (this._options && this._options.authTagLength !== void 0) {\n options.authTagLength = this._options.authTagLength;\n }\n if (this._authTag) {\n options.authTag = this._authTag;\n }\n if (this._aad) {\n options.aad = this._aad;\n }\n if (this._aadOptions !== void 0) {\n options.aadOptions = this._aadOptions;\n }\n if (this._autoPadding !== void 0) {\n options.autoPadding = this._autoPadding;\n }\n return Object.keys(options).length === 0 ? null : options;\n };\n SandboxDecipher2.prototype.update = function update(data, inputEncoding, outputEncoding) {\n if (this._finalized) {\n throw new Error(\"Attempting to call update() after final()\");\n }\n var buf;\n if (typeof data === \"string\") {\n buf = Buffer.from(data, inputEncoding || \"utf8\");\n } else {\n buf = normalizeByteSource2(data, \"data\");\n }\n if (!this._bufferedMode) {\n this._ensureSession();\n var resultBase64 = _cryptoCipherivUpdate.applySync(void 0, [this._sessionId, buf.toString(\"base64\")]);\n var resultBuffer = Buffer.from(resultBase64, \"base64\");\n return encodeCryptoResult2(resultBuffer, outputEncoding);\n }\n this._chunks.push(buf);\n return encodeCryptoResult2(Buffer.alloc(0), outputEncoding);\n };\n SandboxDecipher2.prototype.final = function final(outputEncoding) {\n if (this._finalized) throw new Error(\"Attempting to call final() after already finalized\");\n this._finalized = true;\n var resultBuffer;\n if (!this._bufferedMode) {\n this._ensureSession();\n var resultJson = _cryptoCipherivFinal.applySync(void 0, [this._sessionId]);\n var parsed = JSON.parse(resultJson);\n resultBuffer = Buffer.from(parsed.data, \"base64\");\n } else {\n var combined = Buffer.concat(this._chunks);\n var options = {};\n var resultBase64 = _cryptoDecipheriv.applySync(void 0, [\n this._algorithm,\n this._key.toString(\"base64\"),\n this._iv === null ? null : this._iv.toString(\"base64\"),\n combined.toString(\"base64\"),\n serializeCipherBridgeOptions2(this._getBridgeOptions())\n ]);\n resultBuffer = Buffer.from(resultBase64, \"base64\");\n }\n return encodeCryptoResult2(resultBuffer, outputEncoding);\n };\n SandboxDecipher2.prototype.setAuthTag = function setAuthTag(tag) {\n this._bufferedMode = true;\n this._authTag = typeof tag === \"string\" ? Buffer.from(tag, \"base64\") : normalizeByteSource2(tag, \"buffer\");\n return this;\n };\n SandboxDecipher2.prototype.setAAD = function setAAD(aad, options) {\n this._bufferedMode = true;\n this._aad = normalizeByteSource2(aad, \"buffer\");\n this._aadOptions = options;\n return this;\n };\n SandboxDecipher2.prototype.setAutoPadding = function setAutoPadding(autoPadding) {\n this._bufferedMode = true;\n this._autoPadding = autoPadding !== false;\n return this;\n };\n SandboxDecipher2.prototype._transform = function _transform(chunk, encoding, callback) {\n try {\n var output = this.update(chunk, encoding === \"buffer\" ? void 0 : encoding);\n if (output.length) {\n this.push(output);\n }\n callback();\n } catch (error) {\n callback(normalizeCryptoBridgeError(error));\n }\n };\n SandboxDecipher2.prototype._flush = function _flush(callback) {\n try {\n var output = this.final();\n if (output.length) {\n this.push(output);\n }\n callback();\n } catch (error) {\n callback(normalizeCryptoBridgeError(error));\n }\n };\n result2.createDecipheriv = function createDecipheriv(algorithm, key, iv, options) {\n return new SandboxDecipher2(algorithm, key, iv, options);\n };\n result2.Decipheriv = SandboxDecipher2;\n }\n if (typeof _cryptoSign !== \"undefined\") {\n result2.sign = function sign(algorithm, data, key) {\n var dataBuf = typeof data === \"string\" ? Buffer.from(data, \"utf8\") : Buffer.from(data);\n var sigBase64;\n try {\n sigBase64 = _cryptoSign.applySync(void 0, [\n algorithm === void 0 ? null : algorithm,\n dataBuf.toString(\"base64\"),\n JSON.stringify(serializeBridgeValue(key))\n ]);\n } catch (error) {\n throw normalizeCryptoBridgeError(error);\n }\n return Buffer.from(sigBase64, \"base64\");\n };\n }\n if (typeof _cryptoVerify !== \"undefined\") {\n result2.verify = function verify(algorithm, data, key, signature) {\n var dataBuf = typeof data === \"string\" ? Buffer.from(data, \"utf8\") : Buffer.from(data);\n var sigBuf = typeof signature === \"string\" ? Buffer.from(signature, \"base64\") : Buffer.from(signature);\n try {\n return _cryptoVerify.applySync(void 0, [\n algorithm === void 0 ? null : algorithm,\n dataBuf.toString(\"base64\"),\n JSON.stringify(serializeBridgeValue(key)),\n sigBuf.toString(\"base64\")\n ]);\n } catch (error) {\n throw normalizeCryptoBridgeError(error);\n }\n };\n }\n if (typeof _cryptoAsymmetricOp !== \"undefined\") {\n let asymmetricBridgeCall2 = function(operation, key, data) {\n var dataBuf = toRawBuffer(data);\n var resultBase64;\n try {\n resultBase64 = _cryptoAsymmetricOp.applySync(void 0, [\n operation,\n JSON.stringify(serializeBridgeValue(key)),\n dataBuf.toString(\"base64\")\n ]);\n } catch (error) {\n throw normalizeCryptoBridgeError(error);\n }\n return Buffer.from(resultBase64, \"base64\");\n };\n var asymmetricBridgeCall = asymmetricBridgeCall2;\n result2.publicEncrypt = function publicEncrypt(key, data) {\n return asymmetricBridgeCall2(\"publicEncrypt\", key, data);\n };\n result2.privateDecrypt = function privateDecrypt(key, data) {\n return asymmetricBridgeCall2(\"privateDecrypt\", key, data);\n };\n result2.privateEncrypt = function privateEncrypt(key, data) {\n return asymmetricBridgeCall2(\"privateEncrypt\", key, data);\n };\n result2.publicDecrypt = function publicDecrypt(key, data) {\n return asymmetricBridgeCall2(\"publicDecrypt\", key, data);\n };\n }\n if (typeof _cryptoDiffieHellmanSessionCreate !== \"undefined\" && typeof _cryptoDiffieHellmanSessionCall !== \"undefined\") {\n let serializeDhKeyObject2 = function(value) {\n if (value.type === \"secret\") {\n return {\n type: \"secret\",\n raw: Buffer.from(value.export()).toString(\"base64\")\n };\n }\n return {\n type: value.type,\n pem: value._pem || value.export({\n type: value.type === \"private\" ? \"pkcs8\" : \"spki\",\n format: \"pem\"\n })\n };\n }, serializeDhValue2 = function(value) {\n if (value === null || typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n return value;\n }\n if (Buffer.isBuffer(value)) {\n return {\n __type: \"buffer\",\n value: Buffer.from(value).toString(\"base64\")\n };\n }\n if (value instanceof ArrayBuffer) {\n return {\n __type: \"buffer\",\n value: Buffer.from(new Uint8Array(value)).toString(\"base64\")\n };\n }\n if (ArrayBuffer.isView(value)) {\n return {\n __type: \"buffer\",\n value: Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString(\"base64\")\n };\n }\n if (typeof value === \"bigint\") {\n return {\n __type: \"bigint\",\n value: value.toString()\n };\n }\n if (value && typeof value === \"object\" && (value.type === \"public\" || value.type === \"private\" || value.type === \"secret\") && typeof value.export === \"function\") {\n return {\n __type: \"keyObject\",\n value: serializeDhKeyObject2(value)\n };\n }\n if (Array.isArray(value)) {\n return value.map(serializeDhValue2);\n }\n if (value && typeof value === \"object\") {\n var output = {};\n var keys = Object.keys(value);\n for (var i = 0; i < keys.length; i++) {\n if (value[keys[i]] !== void 0) {\n output[keys[i]] = serializeDhValue2(value[keys[i]]);\n }\n }\n return output;\n }\n return String(value);\n }, restoreDhValue2 = function(value) {\n if (!value || typeof value !== \"object\") {\n return value;\n }\n if (value.__type === \"buffer\") {\n return Buffer.from(value.value, \"base64\");\n }\n if (value.__type === \"bigint\") {\n return BigInt(value.value);\n }\n if (Array.isArray(value)) {\n return value.map(restoreDhValue2);\n }\n var output = {};\n var keys = Object.keys(value);\n for (var i = 0; i < keys.length; i++) {\n output[keys[i]] = restoreDhValue2(value[keys[i]]);\n }\n return output;\n }, createDhSession2 = function(type, name3, argsLike) {\n var args = [];\n for (var i = 0; i < argsLike.length; i++) {\n args.push(serializeDhValue2(argsLike[i]));\n }\n return _cryptoDiffieHellmanSessionCreate.applySync(void 0, [\n JSON.stringify({\n type,\n name: name3,\n args\n })\n ]);\n }, callDhSession2 = function(sessionId, method, argsLike) {\n var args = [];\n for (var i = 0; i < argsLike.length; i++) {\n args.push(serializeDhValue2(argsLike[i]));\n }\n var response = JSON.parse(_cryptoDiffieHellmanSessionCall.applySync(void 0, [\n sessionId,\n JSON.stringify({\n method,\n args\n })\n ]));\n if (response && response.hasResult === false) {\n return void 0;\n }\n return restoreDhValue2(response && response.result);\n }, SandboxDiffieHellman2 = function(sessionId) {\n this._sessionId = sessionId;\n }, SandboxECDH2 = function(sessionId) {\n SandboxDiffieHellman2.call(this, sessionId);\n };\n var serializeDhKeyObject = serializeDhKeyObject2, serializeDhValue = serializeDhValue2, restoreDhValue = restoreDhValue2, createDhSession = createDhSession2, callDhSession = callDhSession2, SandboxDiffieHellman = SandboxDiffieHellman2, SandboxECDH = SandboxECDH2;\n Object.defineProperty(SandboxDiffieHellman2.prototype, \"verifyError\", {\n get: function getVerifyError() {\n return callDhSession2(this._sessionId, \"verifyError\", []);\n }\n });\n SandboxDiffieHellman2.prototype.generateKeys = function generateKeys(encoding) {\n if (arguments.length === 0) return callDhSession2(this._sessionId, \"generateKeys\", []);\n return callDhSession2(this._sessionId, \"generateKeys\", [encoding]);\n };\n SandboxDiffieHellman2.prototype.computeSecret = function computeSecret(key, inputEncoding, outputEncoding) {\n return callDhSession2(this._sessionId, \"computeSecret\", Array.prototype.slice.call(arguments));\n };\n SandboxDiffieHellman2.prototype.getPrime = function getPrime(encoding) {\n if (arguments.length === 0) return callDhSession2(this._sessionId, \"getPrime\", []);\n return callDhSession2(this._sessionId, \"getPrime\", [encoding]);\n };\n SandboxDiffieHellman2.prototype.getGenerator = function getGenerator(encoding) {\n if (arguments.length === 0) return callDhSession2(this._sessionId, \"getGenerator\", []);\n return callDhSession2(this._sessionId, \"getGenerator\", [encoding]);\n };\n SandboxDiffieHellman2.prototype.getPublicKey = function getPublicKey(encoding) {\n if (arguments.length === 0) return callDhSession2(this._sessionId, \"getPublicKey\", []);\n return callDhSession2(this._sessionId, \"getPublicKey\", [encoding]);\n };\n SandboxDiffieHellman2.prototype.getPrivateKey = function getPrivateKey(encoding) {\n if (arguments.length === 0) return callDhSession2(this._sessionId, \"getPrivateKey\", []);\n return callDhSession2(this._sessionId, \"getPrivateKey\", [encoding]);\n };\n SandboxDiffieHellman2.prototype.setPublicKey = function setPublicKey(key, encoding) {\n return callDhSession2(this._sessionId, \"setPublicKey\", Array.prototype.slice.call(arguments));\n };\n SandboxDiffieHellman2.prototype.setPrivateKey = function setPrivateKey(key, encoding) {\n return callDhSession2(this._sessionId, \"setPrivateKey\", Array.prototype.slice.call(arguments));\n };\n SandboxECDH2.prototype = Object.create(SandboxDiffieHellman2.prototype);\n SandboxECDH2.prototype.constructor = SandboxECDH2;\n SandboxECDH2.prototype.getPublicKey = function getPublicKey(encoding, format) {\n return callDhSession2(this._sessionId, \"getPublicKey\", Array.prototype.slice.call(arguments));\n };\n result2.createDiffieHellman = function createDiffieHellman() {\n return new SandboxDiffieHellman2(createDhSession2(\"dh\", void 0, arguments));\n };\n result2.getDiffieHellman = function getDiffieHellman(name3) {\n return new SandboxDiffieHellman2(createDhSession2(\"group\", name3, []));\n };\n result2.createDiffieHellmanGroup = result2.getDiffieHellman;\n result2.createECDH = function createECDH(curve) {\n return new SandboxECDH2(createDhSession2(\"ecdh\", curve, []));\n };\n if (typeof _cryptoDiffieHellman !== \"undefined\") {\n result2.diffieHellman = function diffieHellman(options) {\n var resultJson = _cryptoDiffieHellman.applySync(void 0, [\n JSON.stringify(serializeDhValue2(options))\n ]);\n return restoreDhValue2(JSON.parse(resultJson));\n };\n }\n result2.DiffieHellman = SandboxDiffieHellman2;\n result2.DiffieHellmanGroup = SandboxDiffieHellman2;\n result2.ECDH = SandboxECDH2;\n }\n if (typeof _cryptoGenerateKeyPairSync !== \"undefined\") {\n let restoreBridgeValue2 = function(value) {\n if (!value || typeof value !== \"object\") {\n return value;\n }\n if (value.__type === \"buffer\") {\n return Buffer.from(value.value, \"base64\");\n }\n if (value.__type === \"bigint\") {\n return BigInt(value.value);\n }\n if (Array.isArray(value)) {\n return value.map(restoreBridgeValue2);\n }\n var output = {};\n var keys = Object.keys(value);\n for (var i = 0; i < keys.length; i++) {\n output[keys[i]] = restoreBridgeValue2(value[keys[i]]);\n }\n return output;\n }, cloneObject2 = function(value) {\n if (!value || typeof value !== \"object\") {\n return value;\n }\n if (Array.isArray(value)) {\n return value.map(cloneObject2);\n }\n var output = {};\n var keys = Object.keys(value);\n for (var i = 0; i < keys.length; i++) {\n output[keys[i]] = cloneObject2(value[keys[i]]);\n }\n return output;\n }, createDomException2 = function(message, name3) {\n if (typeof DOMException === \"function\") {\n return new DOMException(message, name3);\n }\n var error = new Error(message);\n error.name = name3;\n return error;\n }, toRawBuffer2 = function(data, encoding) {\n if (Buffer.isBuffer(data)) {\n return Buffer.from(data);\n }\n if (data instanceof ArrayBuffer) {\n return Buffer.from(new Uint8Array(data));\n }\n if (ArrayBuffer.isView(data)) {\n return Buffer.from(data.buffer, data.byteOffset, data.byteLength);\n }\n if (typeof data === \"string\") {\n return Buffer.from(data, encoding || \"utf8\");\n }\n return Buffer.from(data);\n }, serializeBridgeValue2 = function(value) {\n if (value === null) {\n return null;\n }\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") {\n return value;\n }\n if (typeof value === \"bigint\") {\n return {\n __type: \"bigint\",\n value: value.toString()\n };\n }\n if (Buffer.isBuffer(value)) {\n return {\n __type: \"buffer\",\n value: Buffer.from(value).toString(\"base64\")\n };\n }\n if (value instanceof ArrayBuffer) {\n return {\n __type: \"buffer\",\n value: Buffer.from(new Uint8Array(value)).toString(\"base64\")\n };\n }\n if (ArrayBuffer.isView(value)) {\n return {\n __type: \"buffer\",\n value: Buffer.from(value.buffer, value.byteOffset, value.byteLength).toString(\"base64\")\n };\n }\n if (Array.isArray(value)) {\n return value.map(serializeBridgeValue2);\n }\n if (value && typeof value === \"object\" && (value.type === \"public\" || value.type === \"private\" || value.type === \"secret\") && typeof value.export === \"function\") {\n if (value.type === \"secret\") {\n return {\n __type: \"keyObject\",\n value: {\n type: \"secret\",\n raw: Buffer.from(value.export()).toString(\"base64\")\n }\n };\n }\n return {\n __type: \"keyObject\",\n value: {\n type: value.type,\n pem: value._pem\n }\n };\n }\n if (value && typeof value === \"object\") {\n var output = {};\n var keys = Object.keys(value);\n for (var i = 0; i < keys.length; i++) {\n var entry = value[keys[i]];\n if (entry !== void 0) {\n output[keys[i]] = serializeBridgeValue2(entry);\n }\n }\n return output;\n }\n return String(value);\n }, normalizeCryptoBridgeError2 = function(error) {\n if (!error || typeof error !== \"object\") {\n return error;\n }\n if (error.code === void 0 && error.message === \"error:07880109:common libcrypto routines::interrupted or cancelled\") {\n error.code = \"ERR_OSSL_CRYPTO_INTERRUPTED_OR_CANCELLED\";\n }\n return error;\n }, deserializeGeneratedKeyValue2 = function(value) {\n if (!value || typeof value !== \"object\") {\n return value;\n }\n if (value.kind === \"string\") {\n return value.value;\n }\n if (value.kind === \"buffer\") {\n return Buffer.from(value.value, \"base64\");\n }\n if (value.kind === \"keyObject\") {\n return createGeneratedKeyObject2(value.value);\n }\n if (value.kind === \"object\") {\n return value.value;\n }\n return value;\n }, serializeBridgeOptions2 = function(options) {\n return JSON.stringify({\n hasOptions: options !== void 0,\n options: options === void 0 ? null : serializeBridgeValue2(options)\n });\n }, createInvalidArgTypeError2 = function(name3, expected, value) {\n var received;\n if (value == null) {\n received = \" Received \" + value;\n } else if (typeof value === \"function\") {\n received = \" Received function \" + (value.name || \"anonymous\");\n } else if (typeof value === \"object\") {\n if (value.constructor && value.constructor.name) {\n received = \" Received an instance of \" + value.constructor.name;\n } else {\n received = \" Received [object Object]\";\n }\n } else {\n var inspected = typeof value === \"string\" ? \"'\" + value + \"'\" : String(value);\n if (inspected.length > 28) {\n inspected = inspected.slice(0, 25) + \"...\";\n }\n received = \" Received type \" + typeof value + \" (\" + inspected + \")\";\n }\n var error = new TypeError('The \"' + name3 + '\" argument must be ' + expected + \".\" + received);\n error.code = \"ERR_INVALID_ARG_TYPE\";\n return error;\n }, scheduleCryptoCallback2 = function(callback, args) {\n var invoke = function() {\n callback.apply(void 0, args);\n };\n if (typeof process !== \"undefined\" && process && typeof process.nextTick === \"function\") {\n process.nextTick(invoke);\n return;\n }\n if (typeof queueMicrotask === \"function\") {\n queueMicrotask(invoke);\n return;\n }\n Promise.resolve().then(invoke);\n }, shouldThrowCryptoValidationError2 = function(error) {\n if (!error || typeof error !== \"object\") {\n return false;\n }\n if (error.name === \"TypeError\" || error.name === \"RangeError\") {\n return true;\n }\n var code = error.code;\n 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;\n }, ensureCryptoCallback2 = function(callback, syncValidator) {\n if (typeof callback === \"function\") {\n return callback;\n }\n if (typeof syncValidator === \"function\") {\n syncValidator();\n }\n throw createInvalidArgTypeError2(\"callback\", \"of type function\", callback);\n }, SandboxKeyObject2 = function(type, handle) {\n this.type = type;\n this._pem = handle && handle.pem !== void 0 ? handle.pem : void 0;\n this._raw = handle && handle.raw !== void 0 ? handle.raw : void 0;\n this._jwk = handle && handle.jwk !== void 0 ? cloneObject2(handle.jwk) : void 0;\n this.asymmetricKeyType = handle && handle.asymmetricKeyType !== void 0 ? handle.asymmetricKeyType : void 0;\n this.asymmetricKeyDetails = handle && handle.asymmetricKeyDetails !== void 0 ? restoreBridgeValue2(handle.asymmetricKeyDetails) : void 0;\n this.symmetricKeySize = type === \"secret\" && handle && handle.raw !== void 0 ? Buffer.from(handle.raw, \"base64\").byteLength : void 0;\n }, normalizeNamedCurve2 = function(namedCurve) {\n if (!namedCurve) {\n return namedCurve;\n }\n var upper = String(namedCurve).toUpperCase();\n if (upper === \"PRIME256V1\" || upper === \"SECP256R1\") return \"P-256\";\n if (upper === \"SECP384R1\") return \"P-384\";\n if (upper === \"SECP521R1\") return \"P-521\";\n return namedCurve;\n }, normalizeAlgorithmInput2 = function(algorithm) {\n if (typeof algorithm === \"string\") {\n return { name: algorithm };\n }\n return Object.assign({}, algorithm);\n }, createCompatibleCryptoKey2 = function(keyData) {\n var key;\n if (globalThis.CryptoKey && globalThis.CryptoKey.prototype && globalThis.CryptoKey.prototype !== SandboxCryptoKey.prototype) {\n key = Object.create(globalThis.CryptoKey.prototype);\n key.type = keyData.type;\n key.extractable = keyData.extractable;\n key.algorithm = keyData.algorithm;\n key.usages = keyData.usages;\n key._keyData = keyData;\n key._pem = keyData._pem;\n key._jwk = keyData._jwk;\n key._raw = keyData._raw;\n key._sourceKeyObjectData = keyData._sourceKeyObjectData;\n return key;\n }\n return new SandboxCryptoKey(keyData);\n }, buildCryptoKeyFromKeyObject2 = function(keyObject, algorithm, extractable, usages) {\n var algo = normalizeAlgorithmInput2(algorithm);\n var name3 = algo.name;\n if (keyObject.type === \"secret\") {\n var secretBytes = Buffer.from(keyObject._raw || \"\", \"base64\");\n if (name3 === \"PBKDF2\") {\n if (extractable) {\n throw new SyntaxError(\"PBKDF2 keys are not extractable\");\n }\n if (usages.some(function(usage) {\n return usage !== \"deriveBits\" && usage !== \"deriveKey\";\n })) {\n throw new SyntaxError(\"Unsupported key usage for a PBKDF2 key\");\n }\n return createCompatibleCryptoKey2({\n type: \"secret\",\n extractable,\n algorithm: { name: name3 },\n usages: Array.from(usages),\n _raw: keyObject._raw,\n _sourceKeyObjectData: {\n type: \"secret\",\n raw: keyObject._raw\n }\n });\n }\n if (name3 === \"HMAC\") {\n if (!secretBytes.byteLength || algo.length === 0) {\n throw createDomException2(\"Zero-length key is not supported\", \"DataError\");\n }\n if (!usages.length) {\n throw new SyntaxError(\"Usages cannot be empty when importing a secret key.\");\n }\n return createCompatibleCryptoKey2({\n type: \"secret\",\n extractable,\n algorithm: {\n name: name3,\n hash: typeof algo.hash === \"string\" ? { name: algo.hash } : cloneObject2(algo.hash),\n length: secretBytes.byteLength * 8\n },\n usages: Array.from(usages),\n _raw: keyObject._raw,\n _sourceKeyObjectData: {\n type: \"secret\",\n raw: keyObject._raw\n }\n });\n }\n return createCompatibleCryptoKey2({\n type: \"secret\",\n extractable,\n algorithm: {\n name: name3,\n length: secretBytes.byteLength * 8\n },\n usages: Array.from(usages),\n _raw: keyObject._raw,\n _sourceKeyObjectData: {\n type: \"secret\",\n raw: keyObject._raw\n }\n });\n }\n var keyType = String(keyObject.asymmetricKeyType || \"\").toLowerCase();\n var algorithmName = String(name3 || \"\");\n if ((keyType === \"ed25519\" || keyType === \"ed448\" || keyType === \"x25519\" || keyType === \"x448\") && keyType !== algorithmName.toLowerCase()) {\n throw createDomException2(\"Invalid key type\", \"DataError\");\n }\n if (algorithmName === \"ECDH\") {\n if (keyObject.type === \"private\" && !usages.length) {\n throw new SyntaxError(\"Usages cannot be empty when importing a private key.\");\n }\n var actualCurve = normalizeNamedCurve2(\n keyObject.asymmetricKeyDetails && keyObject.asymmetricKeyDetails.namedCurve\n );\n if (algo.namedCurve && actualCurve && normalizeNamedCurve2(algo.namedCurve) !== actualCurve) {\n throw createDomException2(\"Named curve mismatch\", \"DataError\");\n }\n }\n var normalizedAlgo = cloneObject2(algo);\n if (typeof normalizedAlgo.hash === \"string\") {\n normalizedAlgo.hash = { name: normalizedAlgo.hash };\n }\n return createCompatibleCryptoKey2({\n type: keyObject.type,\n extractable,\n algorithm: normalizedAlgo,\n usages: Array.from(usages),\n _pem: keyObject._pem,\n _jwk: cloneObject2(keyObject._jwk),\n _sourceKeyObjectData: {\n type: keyObject.type,\n pem: keyObject._pem,\n jwk: cloneObject2(keyObject._jwk),\n asymmetricKeyType: keyObject.asymmetricKeyType,\n asymmetricKeyDetails: cloneObject2(keyObject.asymmetricKeyDetails)\n }\n });\n }, createAsymmetricKeyObject2 = function(type, key) {\n if (typeof key === \"string\") {\n if (key.indexOf(\"-----BEGIN\") === -1) {\n throw new TypeError(\"error:0900006e:PEM routines:OPENSSL_internal:NO_START_LINE\");\n }\n return new SandboxKeyObject2(type, { pem: key });\n }\n if (key && typeof key === \"object\" && key._pem) {\n return new SandboxKeyObject2(type, {\n pem: key._pem,\n jwk: key._jwk,\n asymmetricKeyType: key.asymmetricKeyType,\n asymmetricKeyDetails: key.asymmetricKeyDetails\n });\n }\n if (key && typeof key === \"object\" && key.key) {\n var keyData = typeof key.key === \"string\" ? key.key : key.key.toString(\"utf8\");\n return new SandboxKeyObject2(type, { pem: keyData });\n }\n if (Buffer.isBuffer(key)) {\n var keyStr = key.toString(\"utf8\");\n if (keyStr.indexOf(\"-----BEGIN\") === -1) {\n throw new TypeError(\"error:0900006e:PEM routines:OPENSSL_internal:NO_START_LINE\");\n }\n return new SandboxKeyObject2(type, { pem: keyStr });\n }\n return new SandboxKeyObject2(type, { pem: String(key) });\n }, createGeneratedKeyObject2 = function(value) {\n return new SandboxKeyObject2(value.type, {\n pem: value.pem,\n raw: value.raw,\n jwk: value.jwk,\n asymmetricKeyType: value.asymmetricKeyType,\n asymmetricKeyDetails: value.asymmetricKeyDetails\n });\n };\n 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;\n Object.defineProperty(SandboxKeyObject2.prototype, Symbol.toStringTag, {\n value: \"KeyObject\",\n configurable: true\n });\n SandboxKeyObject2.prototype.export = function exportKey(options) {\n if (this.type === \"secret\") {\n return Buffer.from(this._raw || \"\", \"base64\");\n }\n if (!options || typeof options !== \"object\") {\n throw new TypeError('The \"options\" argument must be of type object.');\n }\n if (options.format === \"jwk\") {\n return cloneObject2(this._jwk);\n }\n if (options.format === \"der\") {\n var lines = String(this._pem || \"\").split(\"\\n\").filter(function(l) {\n return l && l.indexOf(\"-----\") !== 0;\n });\n return Buffer.from(lines.join(\"\"), \"base64\");\n }\n return this._pem;\n };\n SandboxKeyObject2.prototype.toString = function() {\n return \"[object KeyObject]\";\n };\n SandboxKeyObject2.prototype.equals = function equals(other) {\n if (!(other instanceof SandboxKeyObject2)) {\n return false;\n }\n if (this.type !== other.type) {\n return false;\n }\n if (this.type === \"secret\") {\n return (this._raw || \"\") === (other._raw || \"\");\n }\n return (this._pem || \"\") === (other._pem || \"\") && this.asymmetricKeyType === other.asymmetricKeyType;\n };\n SandboxKeyObject2.prototype.toCryptoKey = function toCryptoKey(algorithm, extractable, usages) {\n return buildCryptoKeyFromKeyObject2(this, algorithm, extractable, Array.from(usages || []));\n };\n result2.generateKeyPairSync = function generateKeyPairSync(type, options) {\n var resultJson = _cryptoGenerateKeyPairSync.applySync(void 0, [\n type,\n serializeBridgeOptions2(options)\n ]);\n var parsed = JSON.parse(resultJson);\n if (parsed.publicKey && parsed.publicKey.kind) {\n return {\n publicKey: deserializeGeneratedKeyValue2(parsed.publicKey),\n privateKey: deserializeGeneratedKeyValue2(parsed.privateKey)\n };\n }\n return {\n publicKey: createGeneratedKeyObject2(parsed.publicKey),\n privateKey: createGeneratedKeyObject2(parsed.privateKey)\n };\n };\n result2.generateKeyPair = function generateKeyPair(type, options, callback) {\n if (typeof options === \"function\") {\n callback = options;\n options = void 0;\n }\n callback = ensureCryptoCallback2(callback, function() {\n result2.generateKeyPairSync(type, options);\n });\n try {\n var pair = result2.generateKeyPairSync(type, options);\n scheduleCryptoCallback2(callback, [null, pair.publicKey, pair.privateKey]);\n } catch (e) {\n if (shouldThrowCryptoValidationError2(e)) {\n throw e;\n }\n scheduleCryptoCallback2(callback, [e]);\n }\n };\n if (typeof _cryptoGenerateKeySync !== \"undefined\") {\n result2.generateKeySync = function generateKeySync(type, options) {\n var resultJson;\n try {\n resultJson = _cryptoGenerateKeySync.applySync(void 0, [\n type,\n serializeBridgeOptions2(options)\n ]);\n } catch (error) {\n throw normalizeCryptoBridgeError2(error);\n }\n return createGeneratedKeyObject2(JSON.parse(resultJson));\n };\n result2.generateKey = function generateKey(type, options, callback) {\n callback = ensureCryptoCallback2(callback, function() {\n result2.generateKeySync(type, options);\n });\n try {\n var key = result2.generateKeySync(type, options);\n scheduleCryptoCallback2(callback, [null, key]);\n } catch (e) {\n if (shouldThrowCryptoValidationError2(e)) {\n throw e;\n }\n scheduleCryptoCallback2(callback, [e]);\n }\n };\n }\n if (typeof _cryptoGeneratePrimeSync !== \"undefined\") {\n result2.generatePrimeSync = function generatePrimeSync(size, options) {\n var resultJson;\n try {\n resultJson = _cryptoGeneratePrimeSync.applySync(void 0, [\n size,\n serializeBridgeOptions2(options)\n ]);\n } catch (error) {\n throw normalizeCryptoBridgeError2(error);\n }\n return restoreBridgeValue2(JSON.parse(resultJson));\n };\n result2.generatePrime = function generatePrime(size, options, callback) {\n if (typeof options === \"function\") {\n callback = options;\n options = void 0;\n }\n callback = ensureCryptoCallback2(callback, function() {\n result2.generatePrimeSync(size, options);\n });\n try {\n var prime = result2.generatePrimeSync(size, options);\n scheduleCryptoCallback2(callback, [null, prime]);\n } catch (e) {\n if (shouldThrowCryptoValidationError2(e)) {\n throw e;\n }\n scheduleCryptoCallback2(callback, [e]);\n }\n };\n }\n result2.createPublicKey = function createPublicKey(key) {\n if (typeof _cryptoCreateKeyObject !== \"undefined\") {\n var resultJson;\n try {\n resultJson = _cryptoCreateKeyObject.applySync(void 0, [\n \"createPublicKey\",\n JSON.stringify(serializeBridgeValue2(key))\n ]);\n } catch (error) {\n throw normalizeCryptoBridgeError2(error);\n }\n return createGeneratedKeyObject2(JSON.parse(resultJson));\n }\n return createAsymmetricKeyObject2(\"public\", key);\n };\n result2.createPrivateKey = function createPrivateKey(key) {\n if (typeof _cryptoCreateKeyObject !== \"undefined\") {\n var resultJson;\n try {\n resultJson = _cryptoCreateKeyObject.applySync(void 0, [\n \"createPrivateKey\",\n JSON.stringify(serializeBridgeValue2(key))\n ]);\n } catch (error) {\n throw normalizeCryptoBridgeError2(error);\n }\n return createGeneratedKeyObject2(JSON.parse(resultJson));\n }\n return createAsymmetricKeyObject2(\"private\", key);\n };\n result2.createSecretKey = function createSecretKey(key, encoding) {\n return new SandboxKeyObject2(\"secret\", {\n raw: toRawBuffer2(key, encoding).toString(\"base64\")\n });\n };\n SandboxKeyObject2.from = function from(key) {\n if (!key || typeof key !== \"object\" || key[Symbol.toStringTag] !== \"CryptoKey\") {\n throw new TypeError('The \"key\" argument must be an instance of CryptoKey.');\n }\n if (key._sourceKeyObjectData && key._sourceKeyObjectData.type === \"secret\") {\n return new SandboxKeyObject2(\"secret\", {\n raw: key._sourceKeyObjectData.raw\n });\n }\n return new SandboxKeyObject2(key.type, {\n pem: key._pem,\n jwk: key._jwk,\n asymmetricKeyType: key._sourceKeyObjectData && key._sourceKeyObjectData.asymmetricKeyType,\n asymmetricKeyDetails: key._sourceKeyObjectData && key._sourceKeyObjectData.asymmetricKeyDetails\n });\n };\n result2.KeyObject = SandboxKeyObject2;\n }\n if (typeof _cryptoSubtle !== \"undefined\") {\n let SandboxCryptoKey2 = function(keyData) {\n this.type = keyData.type;\n this.extractable = keyData.extractable;\n this.algorithm = keyData.algorithm;\n this.usages = keyData.usages;\n this._keyData = keyData;\n this._pem = keyData._pem;\n this._jwk = keyData._jwk;\n this._raw = keyData._raw;\n this._sourceKeyObjectData = keyData._sourceKeyObjectData;\n }, toBase642 = function(data) {\n if (typeof data === \"string\") return Buffer.from(data).toString(\"base64\");\n if (data instanceof ArrayBuffer) return Buffer.from(new Uint8Array(data)).toString(\"base64\");\n if (ArrayBuffer.isView(data)) return Buffer.from(new Uint8Array(data.buffer, data.byteOffset, data.byteLength)).toString(\"base64\");\n return Buffer.from(data).toString(\"base64\");\n }, subtleCall2 = function(reqObj) {\n return _cryptoSubtle.applySync(void 0, [JSON.stringify(reqObj)]);\n }, normalizeAlgo2 = function(algorithm) {\n if (typeof algorithm === \"string\") return { name: algorithm };\n return algorithm;\n };\n var SandboxCryptoKey = SandboxCryptoKey2, toBase64 = toBase642, subtleCall = subtleCall2, normalizeAlgo = normalizeAlgo2;\n Object.defineProperty(SandboxCryptoKey2.prototype, Symbol.toStringTag, {\n value: \"CryptoKey\",\n configurable: true\n });\n Object.defineProperty(SandboxCryptoKey2, Symbol.hasInstance, {\n value: function(candidate) {\n return !!(candidate && typeof candidate === \"object\" && (candidate._keyData || candidate[Symbol.toStringTag] === \"CryptoKey\"));\n },\n configurable: true\n });\n if (globalThis.CryptoKey && globalThis.CryptoKey.prototype && globalThis.CryptoKey.prototype !== SandboxCryptoKey2.prototype) {\n Object.setPrototypeOf(SandboxCryptoKey2.prototype, globalThis.CryptoKey.prototype);\n }\n if (typeof globalThis.CryptoKey === \"undefined\") {\n __requireExposeCustomGlobal(\"CryptoKey\", SandboxCryptoKey2);\n } else if (globalThis.CryptoKey !== SandboxCryptoKey2) {\n globalThis.CryptoKey = SandboxCryptoKey2;\n }\n var SandboxSubtle = {};\n SandboxSubtle.digest = function digest(algorithm, data) {\n return Promise.resolve().then(function() {\n var algo = normalizeAlgo2(algorithm);\n var result22 = JSON.parse(subtleCall2({\n op: \"digest\",\n algorithm: algo.name,\n data: toBase642(data)\n }));\n var buf = Buffer.from(result22.data, \"base64\");\n return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);\n });\n };\n SandboxSubtle.generateKey = function generateKey(algorithm, extractable, keyUsages) {\n return Promise.resolve().then(function() {\n var algo = normalizeAlgo2(algorithm);\n var reqAlgo = Object.assign({}, algo);\n if (reqAlgo.hash) reqAlgo.hash = normalizeAlgo2(reqAlgo.hash);\n if (reqAlgo.publicExponent) {\n reqAlgo.publicExponent = Buffer.from(new Uint8Array(reqAlgo.publicExponent.buffer || reqAlgo.publicExponent)).toString(\"base64\");\n }\n var result22 = JSON.parse(subtleCall2({\n op: \"generateKey\",\n algorithm: reqAlgo,\n extractable,\n usages: Array.from(keyUsages)\n }));\n if (result22.publicKey && result22.privateKey) {\n return {\n publicKey: new SandboxCryptoKey2(result22.publicKey),\n privateKey: new SandboxCryptoKey2(result22.privateKey)\n };\n }\n return new SandboxCryptoKey2(result22.key);\n });\n };\n SandboxSubtle.importKey = function importKey(format, keyData, algorithm, extractable, keyUsages) {\n return Promise.resolve().then(function() {\n var algo = normalizeAlgo2(algorithm);\n var reqAlgo = Object.assign({}, algo);\n if (reqAlgo.hash) reqAlgo.hash = normalizeAlgo2(reqAlgo.hash);\n var serializedKeyData;\n if (format === \"jwk\") {\n serializedKeyData = keyData;\n } else if (format === \"raw\") {\n serializedKeyData = toBase642(keyData);\n } else {\n serializedKeyData = toBase642(keyData);\n }\n var result22 = JSON.parse(subtleCall2({\n op: \"importKey\",\n format,\n keyData: serializedKeyData,\n algorithm: reqAlgo,\n extractable,\n usages: Array.from(keyUsages)\n }));\n return new SandboxCryptoKey2(result22.key);\n });\n };\n SandboxSubtle.exportKey = function exportKey(format, key) {\n return Promise.resolve().then(function() {\n var result22 = JSON.parse(subtleCall2({\n op: \"exportKey\",\n format,\n key: key._keyData\n }));\n if (format === \"jwk\") return result22.jwk;\n var buf = Buffer.from(result22.data, \"base64\");\n return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);\n });\n };\n SandboxSubtle.encrypt = function encrypt(algorithm, key, data) {\n return Promise.resolve().then(function() {\n var algo = normalizeAlgo2(algorithm);\n var reqAlgo = Object.assign({}, algo);\n if (reqAlgo.iv) reqAlgo.iv = toBase642(reqAlgo.iv);\n if (reqAlgo.additionalData) reqAlgo.additionalData = toBase642(reqAlgo.additionalData);\n var result22 = JSON.parse(subtleCall2({\n op: \"encrypt\",\n algorithm: reqAlgo,\n key: key._keyData,\n data: toBase642(data)\n }));\n var buf = Buffer.from(result22.data, \"base64\");\n return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);\n });\n };\n SandboxSubtle.decrypt = function decrypt(algorithm, key, data) {\n return Promise.resolve().then(function() {\n var algo = normalizeAlgo2(algorithm);\n var reqAlgo = Object.assign({}, algo);\n if (reqAlgo.iv) reqAlgo.iv = toBase642(reqAlgo.iv);\n if (reqAlgo.additionalData) reqAlgo.additionalData = toBase642(reqAlgo.additionalData);\n var result22 = JSON.parse(subtleCall2({\n op: \"decrypt\",\n algorithm: reqAlgo,\n key: key._keyData,\n data: toBase642(data)\n }));\n var buf = Buffer.from(result22.data, \"base64\");\n return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);\n });\n };\n SandboxSubtle.sign = function sign(algorithm, key, data) {\n return Promise.resolve().then(function() {\n var result22 = JSON.parse(subtleCall2({\n op: \"sign\",\n algorithm: normalizeAlgo2(algorithm),\n key: key._keyData,\n data: toBase642(data)\n }));\n var buf = Buffer.from(result22.data, \"base64\");\n return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);\n });\n };\n SandboxSubtle.verify = function verify(algorithm, key, signature, data) {\n return Promise.resolve().then(function() {\n var result22 = JSON.parse(subtleCall2({\n op: \"verify\",\n algorithm: normalizeAlgo2(algorithm),\n key: key._keyData,\n signature: toBase642(signature),\n data: toBase642(data)\n }));\n return result22.result;\n });\n };\n SandboxSubtle.deriveBits = function deriveBits(algorithm, baseKey, length) {\n return Promise.resolve().then(function() {\n var algo = normalizeAlgo2(algorithm);\n var reqAlgo = Object.assign({}, algo);\n if (reqAlgo.salt) reqAlgo.salt = toBase642(reqAlgo.salt);\n if (reqAlgo.info) reqAlgo.info = toBase642(reqAlgo.info);\n var result22 = JSON.parse(subtleCall2({\n op: \"deriveBits\",\n algorithm: reqAlgo,\n baseKey: baseKey._keyData,\n length\n }));\n return Buffer.from(result22.data, \"base64\").buffer;\n });\n };\n SandboxSubtle.deriveKey = function deriveKey(algorithm, baseKey, derivedKeyAlgorithm, extractable, keyUsages) {\n return Promise.resolve().then(function() {\n var algo = normalizeAlgo2(algorithm);\n var reqAlgo = Object.assign({}, algo);\n if (reqAlgo.salt) reqAlgo.salt = toBase642(reqAlgo.salt);\n if (reqAlgo.info) reqAlgo.info = toBase642(reqAlgo.info);\n var result22 = JSON.parse(subtleCall2({\n op: \"deriveKey\",\n algorithm: reqAlgo,\n baseKey: baseKey._keyData,\n derivedKeyAlgorithm: normalizeAlgo2(derivedKeyAlgorithm),\n extractable,\n usages: keyUsages\n }));\n return new SandboxCryptoKey2(result22.key);\n });\n };\n if (globalThis.crypto && globalThis.crypto.subtle && typeof globalThis.crypto.subtle.importKey === \"function\") {\n result2.subtle = globalThis.crypto.subtle;\n result2.webcrypto = globalThis.crypto;\n } else {\n result2.subtle = SandboxSubtle;\n result2.webcrypto = { subtle: SandboxSubtle, getRandomValues: result2.randomFillSync };\n }\n }\n if (typeof result2.getCurves !== \"function\") {\n result2.getCurves = function getCurves() {\n return [\n \"prime256v1\",\n \"secp256r1\",\n \"secp384r1\",\n \"secp521r1\",\n \"secp256k1\",\n \"secp224r1\",\n \"secp192k1\"\n ];\n };\n }\n if (typeof result2.getCiphers !== \"function\") {\n result2.getCiphers = function getCiphers() {\n return [\n \"aes-128-cbc\",\n \"aes-128-gcm\",\n \"aes-192-cbc\",\n \"aes-192-gcm\",\n \"aes-256-cbc\",\n \"aes-256-gcm\",\n \"aes-128-ctr\",\n \"aes-192-ctr\",\n \"aes-256-ctr\"\n ];\n };\n }\n if (typeof result2.getHashes !== \"function\") {\n result2.getHashes = function getHashes() {\n return [\"md5\", \"sha1\", \"sha256\", \"sha384\", \"sha512\"];\n };\n }\n if (typeof result2.timingSafeEqual !== \"function\") {\n result2.timingSafeEqual = function timingSafeEqual(a, b) {\n if (a.length !== b.length) {\n throw new RangeError(\"Input buffers must have the same byte length\");\n }\n var out = 0;\n for (var i = 0; i < a.length; i++) {\n out |= a[i] ^ b[i];\n }\n return out === 0;\n };\n }\n if (typeof result2.getFips !== \"function\") {\n result2.getFips = function getFips() {\n return 0;\n };\n }\n if (typeof result2.setFips !== \"function\") {\n result2.setFips = function setFips() {\n throw new Error(\"FIPS mode is not supported in sandbox\");\n };\n }\n return result2;\n }\n if (name2 === \"stream\") {\n if (typeof result2 === \"function\" && result2.prototype && typeof result2.Readable === \"function\") {\n var readableProto = result2.Readable.prototype;\n var streamProto = result2.prototype;\n if (readableProto && streamProto && !(readableProto instanceof result2)) {\n var currentParent = Object.getPrototypeOf(readableProto);\n Object.setPrototypeOf(streamProto, currentParent);\n Object.setPrototypeOf(readableProto, streamProto);\n }\n }\n return result2;\n }\n if (name2 === \"path\") {\n if (result2.win32 === null || result2.win32 === void 0) {\n result2.win32 = result2.posix || result2;\n }\n if (result2.posix === null || result2.posix === void 0) {\n result2.posix = result2;\n }\n const hasAbsoluteSegment = function(args) {\n return args.some(function(arg) {\n return typeof arg === \"string\" && arg.length > 0 && arg.charAt(0) === \"/\";\n });\n };\n const prependCwd = function(args) {\n if (hasAbsoluteSegment(args)) return;\n if (typeof process !== \"undefined\" && typeof process.cwd === \"function\") {\n const cwd = process.cwd();\n if (cwd && cwd.charAt(0) === \"/\") {\n args.unshift(cwd);\n }\n }\n };\n const originalResolve = result2.resolve;\n if (typeof originalResolve === \"function\" && !originalResolve._patchedForCwd) {\n const patchedResolve = function resolve2() {\n const args = Array.from(arguments);\n prependCwd(args);\n return originalResolve.apply(this, args);\n };\n patchedResolve._patchedForCwd = true;\n result2.resolve = patchedResolve;\n }\n if (result2.posix && typeof result2.posix.resolve === \"function\" && !result2.posix.resolve._patchedForCwd) {\n const originalPosixResolve = result2.posix.resolve;\n const patchedPosixResolve = function resolve2() {\n const args = Array.from(arguments);\n prependCwd(args);\n return originalPosixResolve.apply(this, args);\n };\n patchedPosixResolve._patchedForCwd = true;\n result2.posix.resolve = patchedPosixResolve;\n }\n }\n return result2;\n }\n var _deferredCoreModules = /* @__PURE__ */ new Set([\n \"readline\",\n \"perf_hooks\",\n \"async_hooks\",\n \"worker_threads\",\n \"diagnostics_channel\"\n ]);\n var _unsupportedCoreModules = /* @__PURE__ */ new Set([\n \"dgram\",\n \"cluster\",\n \"wasi\",\n \"inspector\",\n \"repl\",\n \"trace_events\",\n \"domain\"\n ]);\n function _unsupportedApiError(moduleName2, apiName) {\n return new Error(moduleName2 + \".\" + apiName + \" is not supported in sandbox\");\n }\n function _createDeferredModuleStub(moduleName2) {\n const methodCache = {};\n let stub = null;\n stub = new Proxy({}, {\n get(_target, prop) {\n if (prop === \"__esModule\") return false;\n if (prop === \"default\") return stub;\n if (prop === Symbol.toStringTag) return \"Module\";\n if (prop === \"then\") return void 0;\n if (typeof prop !== \"string\") return void 0;\n if (!methodCache[prop]) {\n methodCache[prop] = function deferredApiStub() {\n throw _unsupportedApiError(moduleName2, prop);\n };\n }\n return methodCache[prop];\n }\n });\n return stub;\n }\n var __internalModuleCache = _moduleCache;\n var __require = function require2(moduleName2) {\n return _requireFrom(moduleName2, _currentModule.dirname);\n };\n __requireExposeCustomGlobal(\"require\", __require);\n function _resolveFrom(moduleName2, fromDir2) {\n var resolved2;\n if (typeof _resolveModuleSync !== \"undefined\") {\n resolved2 = _resolveModuleSync.applySync(void 0, [moduleName2, fromDir2]);\n }\n if (resolved2 === null || resolved2 === void 0) {\n resolved2 = _resolveModule.applySyncPromise(void 0, [moduleName2, fromDir2, \"require\"]);\n }\n if (resolved2 === null) {\n const err = new Error(\"Cannot find module '\" + moduleName2 + \"'\");\n err.code = \"MODULE_NOT_FOUND\";\n throw err;\n }\n return resolved2;\n }\n globalThis.require.resolve = function resolve(moduleName2) {\n return _resolveFrom(moduleName2, _currentModule.dirname);\n };\n function _debugRequire(phase, moduleName2, extra) {\n if (globalThis.__sandboxRequireDebug !== true) {\n return;\n }\n if (moduleName2 !== \"rivetkit\" && moduleName2 !== \"@rivetkit/traces\" && moduleName2 !== \"@rivetkit/on-change\" && moduleName2 !== \"async_hooks\" && !moduleName2.startsWith(\"rivetkit/\") && !moduleName2.startsWith(\"@rivetkit/\")) {\n return;\n }\n if (typeof console !== \"undefined\" && typeof console.log === \"function\") {\n console.log(\n \"[sandbox.require] \" + phase + \" \" + moduleName2 + (extra ? \" \" + extra : \"\")\n );\n }\n }\n function _requireFrom(moduleName, fromDir) {\n _debugRequire(\"start\", moduleName, fromDir);\n const name = moduleName.replace(/^node:/, \"\");\n let cacheKey = name;\n let resolved = null;\n const isRelative = name.startsWith(\"./\") || name.startsWith(\"../\");\n if (!isRelative && __internalModuleCache[name]) {\n _debugRequire(\"cache-hit\", name, name);\n return __internalModuleCache[name];\n }\n if (name === \"fs\") {\n if (__internalModuleCache[\"fs\"]) return __internalModuleCache[\"fs\"];\n const fsModule = globalThis.bridge?.fs || globalThis.bridge?.default || globalThis._fsModule || {};\n __internalModuleCache[\"fs\"] = fsModule;\n _debugRequire(\"loaded\", name, \"fs-special\");\n return fsModule;\n }\n if (name === \"fs/promises\") {\n if (__internalModuleCache[\"fs/promises\"]) return __internalModuleCache[\"fs/promises\"];\n const fsModule = _requireFrom(\"fs\", fromDir);\n __internalModuleCache[\"fs/promises\"] = fsModule.promises;\n _debugRequire(\"loaded\", name, \"fs-promises-special\");\n return fsModule.promises;\n }\n if (name === \"stream/promises\") {\n if (__internalModuleCache[\"stream/promises\"]) return __internalModuleCache[\"stream/promises\"];\n const streamModule = _requireFrom(\"stream\", fromDir);\n const promisesModule = {\n finished(stream, options) {\n return new Promise(function(resolve2, reject) {\n if (typeof streamModule.finished !== \"function\") {\n resolve2();\n return;\n }\n if (options && typeof options === \"object\" && !Array.isArray(options)) {\n streamModule.finished(stream, options, function(error) {\n if (error) {\n reject(error);\n return;\n }\n resolve2();\n });\n return;\n }\n streamModule.finished(stream, function(error) {\n if (error) {\n reject(error);\n return;\n }\n resolve2();\n });\n });\n },\n pipeline() {\n const args = Array.prototype.slice.call(arguments);\n return new Promise(function(resolve2, reject) {\n if (typeof streamModule.pipeline !== \"function\") {\n reject(new Error(\"stream.pipeline is not supported in sandbox\"));\n return;\n }\n args.push(function(error) {\n if (error) {\n reject(error);\n return;\n }\n resolve2();\n });\n streamModule.pipeline.apply(streamModule, args);\n });\n }\n };\n __internalModuleCache[\"stream/promises\"] = promisesModule;\n _debugRequire(\"loaded\", name, \"stream-promises-special\");\n return promisesModule;\n }\n if (name === \"child_process\") {\n if (__internalModuleCache[\"child_process\"]) return __internalModuleCache[\"child_process\"];\n __internalModuleCache[\"child_process\"] = _childProcessModule;\n _debugRequire(\"loaded\", name, \"child-process-special\");\n return _childProcessModule;\n }\n if (name === \"net\") {\n if (__internalModuleCache[\"net\"]) return __internalModuleCache[\"net\"];\n __internalModuleCache[\"net\"] = _netModule;\n _debugRequire(\"loaded\", name, \"net-special\");\n return _netModule;\n }\n if (name === \"tls\") {\n if (__internalModuleCache[\"tls\"]) return __internalModuleCache[\"tls\"];\n __internalModuleCache[\"tls\"] = _tlsModule;\n _debugRequire(\"loaded\", name, \"tls-special\");\n return _tlsModule;\n }\n if (name === \"http\") {\n if (__internalModuleCache[\"http\"]) return __internalModuleCache[\"http\"];\n __internalModuleCache[\"http\"] = _httpModule;\n _debugRequire(\"loaded\", name, \"http-special\");\n return _httpModule;\n }\n if (name === \"_http_agent\") {\n if (__internalModuleCache[\"_http_agent\"]) return __internalModuleCache[\"_http_agent\"];\n const httpAgentModule = {\n Agent: _httpModule.Agent,\n globalAgent: _httpModule.globalAgent\n };\n __internalModuleCache[\"_http_agent\"] = httpAgentModule;\n _debugRequire(\"loaded\", name, \"http-agent-special\");\n return httpAgentModule;\n }\n if (name === \"https\") {\n if (__internalModuleCache[\"https\"]) return __internalModuleCache[\"https\"];\n __internalModuleCache[\"https\"] = _httpsModule;\n _debugRequire(\"loaded\", name, \"https-special\");\n return _httpsModule;\n }\n if (name === \"http2\") {\n if (__internalModuleCache[\"http2\"]) return __internalModuleCache[\"http2\"];\n __internalModuleCache[\"http2\"] = _http2Module;\n _debugRequire(\"loaded\", name, \"http2-special\");\n return _http2Module;\n }\n if (name === \"dns\") {\n if (__internalModuleCache[\"dns\"]) return __internalModuleCache[\"dns\"];\n __internalModuleCache[\"dns\"] = _dnsModule;\n _debugRequire(\"loaded\", name, \"dns-special\");\n return _dnsModule;\n }\n if (name === \"os\") {\n if (__internalModuleCache[\"os\"]) return __internalModuleCache[\"os\"];\n __internalModuleCache[\"os\"] = _osModule;\n _debugRequire(\"loaded\", name, \"os-special\");\n return _osModule;\n }\n if (name === \"module\") {\n if (__internalModuleCache[\"module\"]) return __internalModuleCache[\"module\"];\n __internalModuleCache[\"module\"] = _moduleModule;\n _debugRequire(\"loaded\", name, \"module-special\");\n return _moduleModule;\n }\n if (name === \"process\") {\n _debugRequire(\"loaded\", name, \"process-special\");\n return globalThis.process;\n }\n if (name === \"async_hooks\") {\n if (__internalModuleCache[\"async_hooks\"]) return __internalModuleCache[\"async_hooks\"];\n class AsyncLocalStorage {\n constructor() {\n this._store = void 0;\n }\n run(store, callback) {\n const previousStore = this._store;\n this._store = store;\n try {\n const args = Array.prototype.slice.call(arguments, 2);\n return callback.apply(void 0, args);\n } finally {\n this._store = previousStore;\n }\n }\n enterWith(store) {\n this._store = store;\n }\n getStore() {\n return this._store;\n }\n disable() {\n this._store = void 0;\n }\n exit(callback) {\n const previousStore = this._store;\n this._store = void 0;\n try {\n const args = Array.prototype.slice.call(arguments, 1);\n return callback.apply(void 0, args);\n } finally {\n this._store = previousStore;\n }\n }\n }\n class AsyncResource {\n constructor(type) {\n this.type = type;\n }\n runInAsyncScope(callback, thisArg) {\n const args = Array.prototype.slice.call(arguments, 2);\n return callback.apply(thisArg, args);\n }\n emitDestroy() {\n }\n }\n const asyncHooksModule = {\n AsyncLocalStorage,\n AsyncResource,\n createHook() {\n return {\n enable() {\n return this;\n },\n disable() {\n return this;\n }\n };\n },\n executionAsyncId() {\n return 1;\n },\n triggerAsyncId() {\n return 0;\n },\n executionAsyncResource() {\n return null;\n }\n };\n __internalModuleCache[\"async_hooks\"] = asyncHooksModule;\n _debugRequire(\"loaded\", name, \"async-hooks-special\");\n return asyncHooksModule;\n }\n if (name === \"diagnostics_channel\") {\n let _createChannel2 = function() {\n return {\n hasSubscribers: false,\n publish: function() {\n },\n subscribe: function() {\n },\n unsubscribe: function() {\n }\n };\n };\n var _createChannel = _createChannel2;\n if (__internalModuleCache[name]) return __internalModuleCache[name];\n const dcModule = {\n channel: function() {\n return _createChannel2();\n },\n hasSubscribers: function() {\n return false;\n },\n tracingChannel: function() {\n return {\n start: _createChannel2(),\n end: _createChannel2(),\n asyncStart: _createChannel2(),\n asyncEnd: _createChannel2(),\n error: _createChannel2(),\n traceSync: function(fn, context, thisArg) {\n var args = Array.prototype.slice.call(arguments, 3);\n return fn.apply(thisArg, args);\n },\n tracePromise: function(fn, context, thisArg) {\n var args = Array.prototype.slice.call(arguments, 3);\n return fn.apply(thisArg, args);\n },\n traceCallback: function(fn, context, thisArg) {\n var args = Array.prototype.slice.call(arguments, 3);\n return fn.apply(thisArg, args);\n }\n };\n },\n Channel: function Channel(name2) {\n this.hasSubscribers = false;\n this.publish = function() {\n };\n this.subscribe = function() {\n };\n this.unsubscribe = function() {\n };\n }\n };\n __internalModuleCache[name] = dcModule;\n _debugRequire(\"loaded\", name, \"diagnostics-channel-special\");\n return dcModule;\n }\n if (_deferredCoreModules.has(name)) {\n if (__internalModuleCache[name]) return __internalModuleCache[name];\n const deferredStub = _createDeferredModuleStub(name);\n __internalModuleCache[name] = deferredStub;\n _debugRequire(\"loaded\", name, \"deferred-stub\");\n return deferredStub;\n }\n if (_unsupportedCoreModules.has(name)) {\n throw new Error(name + \" is not supported in sandbox\");\n }\n const polyfillCode = _loadPolyfill.applySyncPromise(void 0, [name]);\n if (polyfillCode !== null) {\n if (__internalModuleCache[name]) return __internalModuleCache[name];\n const moduleObj = { exports: {} };\n _pendingModules[name] = moduleObj;\n let result = eval(polyfillCode);\n result = _patchPolyfill(name, result);\n if (typeof result === \"object\" && result !== null) {\n Object.assign(moduleObj.exports, result);\n } else {\n moduleObj.exports = result;\n }\n __internalModuleCache[name] = moduleObj.exports;\n delete _pendingModules[name];\n _debugRequire(\"loaded\", name, \"polyfill\");\n return __internalModuleCache[name];\n }\n resolved = _resolveFrom(name, fromDir);\n cacheKey = resolved;\n if (__internalModuleCache[cacheKey]) {\n _debugRequire(\"cache-hit\", name, cacheKey);\n return __internalModuleCache[cacheKey];\n }\n if (_pendingModules[cacheKey]) {\n _debugRequire(\"pending-hit\", name, cacheKey);\n return _pendingModules[cacheKey].exports;\n }\n var source;\n if (typeof _loadFileSync !== \"undefined\") {\n source = _loadFileSync.applySync(void 0, [resolved]);\n }\n if (source === null || source === void 0) {\n source = _loadFile.applySyncPromise(void 0, [resolved, \"require\"]);\n }\n if (source === null) {\n const err = new Error(\"Cannot find module '\" + resolved + \"'\");\n err.code = \"MODULE_NOT_FOUND\";\n throw err;\n }\n if (resolved.endsWith(\".json\")) {\n const parsed = JSON.parse(source);\n __internalModuleCache[cacheKey] = parsed;\n return parsed;\n }\n const normalizedSource = typeof source === \"string\" ? source.replace(/import\\.meta\\.url/g, \"__filename\").replace(/fileURLToPath\\(__filename\\)/g, \"__filename\").replace(/url\\.fileURLToPath\\(__filename\\)/g, \"__filename\").replace(/fileURLToPath\\.call\\(void 0, __filename\\)/g, \"__filename\") : source;\n const module = {\n exports: {},\n filename: resolved,\n dirname: _dirname(resolved),\n id: resolved,\n loaded: false\n };\n _pendingModules[cacheKey] = module;\n const prevModule = _currentModule;\n _currentModule = module;\n try {\n let wrapper;\n try {\n wrapper = new Function(\n \"exports\",\n \"require\",\n \"module\",\n \"__filename\",\n \"__dirname\",\n \"__dynamicImport\",\n normalizedSource + \"\\n//# sourceURL=\" + resolved\n );\n } catch (error) {\n const details = error && error.stack ? error.stack : String(error);\n throw new Error(\"failed to compile module \" + resolved + \": \" + details);\n }\n const moduleRequire = function(request) {\n return _requireFrom(request, module.dirname);\n };\n moduleRequire.resolve = function(request) {\n return _resolveFrom(request, module.dirname);\n };\n const moduleDynamicImport = function(specifier) {\n if (typeof globalThis.__dynamicImport === \"function\") {\n return globalThis.__dynamicImport(specifier, module.dirname);\n }\n return Promise.reject(new Error(\"Dynamic import is not initialized\"));\n };\n wrapper(\n module.exports,\n moduleRequire,\n module,\n resolved,\n module.dirname,\n moduleDynamicImport\n );\n module.loaded = true;\n } catch (error) {\n const details = error && error.stack ? error.stack : String(error);\n throw new Error(\"failed to execute module \" + resolved + \": \" + details);\n } finally {\n _currentModule = prevModule;\n }\n __internalModuleCache[cacheKey] = module.exports;\n delete _pendingModules[cacheKey];\n _debugRequire(\"loaded\", name, cacheKey);\n return module.exports;\n }\n __requireExposeCustomGlobal(\"_requireFrom\", _requireFrom);\n var __moduleCacheProxy = new Proxy(__internalModuleCache, {\n get(target, prop, receiver) {\n return Reflect.get(target, prop, receiver);\n },\n set(_target, prop) {\n throw new TypeError(\"Cannot set require.cache['\" + String(prop) + \"']\");\n },\n deleteProperty(_target, prop) {\n throw new TypeError(\"Cannot delete require.cache['\" + String(prop) + \"']\");\n },\n defineProperty(_target, prop) {\n throw new TypeError(\"Cannot define property '\" + String(prop) + \"' on require.cache\");\n },\n has(target, prop) {\n return Reflect.has(target, prop);\n },\n ownKeys(target) {\n return Reflect.ownKeys(target);\n },\n getOwnPropertyDescriptor(target, prop) {\n return Reflect.getOwnPropertyDescriptor(target, prop);\n }\n });\n globalThis.require.cache = __moduleCacheProxy;\n Object.defineProperty(globalThis, \"_moduleCache\", {\n value: __moduleCacheProxy,\n writable: false,\n configurable: true,\n enumerable: false\n });\n if (typeof _moduleModule !== \"undefined\") {\n if (_moduleModule.Module) {\n _moduleModule.Module._cache = __moduleCacheProxy;\n }\n _moduleModule._cache = __moduleCacheProxy;\n }\n})();\n", "setCommonjsFileGlobals": "\"use strict\";\n(() => {\n // ../core/isolate-runtime/src/common/global-exposure.ts\n function defineRuntimeGlobalBinding(name, value, mutable) {\n Object.defineProperty(globalThis, name, {\n value,\n writable: mutable,\n configurable: mutable,\n enumerable: true\n });\n }\n function createRuntimeGlobalExposer(mutable) {\n return (name, value) => {\n defineRuntimeGlobalBinding(name, value, mutable);\n };\n }\n function getRuntimeExposeMutableGlobal() {\n if (typeof globalThis.__runtimeExposeMutableGlobal === \"function\") {\n return globalThis.__runtimeExposeMutableGlobal;\n }\n return createRuntimeGlobalExposer(true);\n }\n\n // ../core/isolate-runtime/src/inject/set-commonjs-file-globals.ts\n var __runtimeExposeMutableGlobal = getRuntimeExposeMutableGlobal();\n var __commonJsFileConfig = globalThis.__runtimeCommonJsFileConfig ?? {};\n var __filePath = typeof __commonJsFileConfig.filePath === \"string\" ? __commonJsFileConfig.filePath : \"/.js\";\n var __dirname = typeof __commonJsFileConfig.dirname === \"string\" ? __commonJsFileConfig.dirname : \"/\";\n __runtimeExposeMutableGlobal(\"__filename\", __filePath);\n __runtimeExposeMutableGlobal(\"__dirname\", __dirname);\n var __currentModule = globalThis._currentModule;\n if (__currentModule) {\n __currentModule.dirname = __dirname;\n __currentModule.filename = __filePath;\n }\n})();\n", "setStdinData": "\"use strict\";\n(() => {\n // ../core/isolate-runtime/src/inject/set-stdin-data.ts\n if (typeof globalThis._stdinData !== \"undefined\") {\n globalThis._stdinData = globalThis.__runtimeStdinData;\n globalThis._stdinPosition = 0;\n globalThis._stdinEnded = false;\n globalThis._stdinFlowMode = false;\n }\n})();\n", "setupDynamicImport": "\"use strict\";\n(() => {\n // ../core/isolate-runtime/src/common/global-access.ts\n function isObjectLike(value) {\n return value !== null && (typeof value === \"object\" || typeof value === \"function\");\n }\n\n // ../core/isolate-runtime/src/common/global-exposure.ts\n function defineRuntimeGlobalBinding(name, value, mutable) {\n Object.defineProperty(globalThis, name, {\n value,\n writable: mutable,\n configurable: mutable,\n enumerable: true\n });\n }\n function createRuntimeGlobalExposer(mutable) {\n return (name, value) => {\n defineRuntimeGlobalBinding(name, value, mutable);\n };\n }\n function getRuntimeExposeCustomGlobal() {\n if (typeof globalThis.__runtimeExposeCustomGlobal === \"function\") {\n return globalThis.__runtimeExposeCustomGlobal;\n }\n return createRuntimeGlobalExposer(false);\n }\n\n // ../core/isolate-runtime/src/inject/setup-dynamic-import.ts\n var __runtimeExposeCustomGlobal = getRuntimeExposeCustomGlobal();\n var __dynamicImportConfig = globalThis.__runtimeDynamicImportConfig ?? {};\n var __fallbackReferrer = typeof __dynamicImportConfig.referrerPath === \"string\" && __dynamicImportConfig.referrerPath.length > 0 ? __dynamicImportConfig.referrerPath : \"/\";\n var __dynamicImportCache = /* @__PURE__ */ new Map();\n var __resolveDynamicImportPath = function(request, referrer) {\n if (!request.startsWith(\"./\") && !request.startsWith(\"../\") && !request.startsWith(\"/\")) {\n return request;\n }\n const baseDir = referrer.endsWith(\"/\") ? referrer : referrer.slice(0, referrer.lastIndexOf(\"/\")) || \"/\";\n const segments = baseDir.split(\"/\").filter(Boolean);\n for (const part of request.split(\"/\")) {\n if (part === \".\" || part.length === 0) continue;\n if (part === \"..\") {\n segments.pop();\n continue;\n }\n segments.push(part);\n }\n return `/${segments.join(\"/\")}`;\n };\n var __dynamicImportHandler = function(specifier, fromPath) {\n const request = String(specifier);\n const referrer = typeof fromPath === \"string\" && fromPath.length > 0 ? fromPath : __fallbackReferrer;\n let resolved = null;\n if (typeof globalThis._resolveModuleSync !== \"undefined\") {\n resolved = globalThis._resolveModuleSync.applySync(\n void 0,\n [request, referrer, \"import\"]\n );\n }\n const resolvedPath = typeof resolved === \"string\" && resolved.length > 0 ? resolved : __resolveDynamicImportPath(request, referrer);\n const cacheKey = typeof resolved === \"string\" && resolved.length > 0 ? resolved : `${referrer}\\0${request}`;\n const cached = __dynamicImportCache.get(cacheKey);\n if (cached) return Promise.resolve(cached);\n if (typeof globalThis._requireFrom !== \"function\") {\n throw new Error(\"Cannot load module: \" + resolvedPath);\n }\n let mod;\n try {\n mod = globalThis._requireFrom(resolved ?? request, referrer);\n } catch (error) {\n const message = error instanceof Error ? error.message : String(error);\n if (error && typeof error === \"object\" && \"code\" in error && error.code === \"MODULE_NOT_FOUND\") {\n throw new Error(\"Cannot load module: \" + resolvedPath);\n }\n if (message.startsWith(\"Cannot find module \")) {\n throw new Error(\"Cannot load module: \" + resolvedPath);\n }\n throw error;\n }\n const namespaceFallback = { default: mod };\n if (isObjectLike(mod)) {\n for (const key of Object.keys(mod)) {\n if (!(key in namespaceFallback)) {\n namespaceFallback[key] = mod[key];\n }\n }\n }\n __dynamicImportCache.set(cacheKey, namespaceFallback);\n return Promise.resolve(namespaceFallback);\n };\n __runtimeExposeCustomGlobal(\"__dynamicImport\", __dynamicImportHandler);\n})();\n", diff --git a/packages/secure-exec/tests/test-suite/node/polyfills.ts b/packages/secure-exec/tests/test-suite/node/polyfills.ts index bd42a337..1e4b2167 100644 --- a/packages/secure-exec/tests/test-suite/node/polyfills.ts +++ b/packages/secure-exec/tests/test-suite/node/polyfills.ts @@ -26,6 +26,69 @@ export function runNodePolyfillSuite(context: NodeSuiteContext): void { }); }); + it("zlib.constants has flush, return-code, level, and strategy constants", async () => { + const runtime = await context.createRuntime(); + const result = await runtime.run(` + const zlib = require('zlib'); + const c = zlib.constants; + module.exports = { + Z_NO_FLUSH: c.Z_NO_FLUSH, + Z_PARTIAL_FLUSH: c.Z_PARTIAL_FLUSH, + Z_SYNC_FLUSH: c.Z_SYNC_FLUSH, + Z_FULL_FLUSH: c.Z_FULL_FLUSH, + Z_FINISH: c.Z_FINISH, + Z_BLOCK: c.Z_BLOCK, + Z_TREES: c.Z_TREES, + Z_OK: c.Z_OK, + Z_STREAM_END: c.Z_STREAM_END, + Z_NEED_DICT: c.Z_NEED_DICT, + Z_ERRNO: c.Z_ERRNO, + Z_STREAM_ERROR: c.Z_STREAM_ERROR, + Z_DATA_ERROR: c.Z_DATA_ERROR, + Z_MEM_ERROR: c.Z_MEM_ERROR, + Z_BUF_ERROR: c.Z_BUF_ERROR, + Z_VERSION_ERROR: c.Z_VERSION_ERROR, + Z_NO_COMPRESSION: c.Z_NO_COMPRESSION, + Z_BEST_SPEED: c.Z_BEST_SPEED, + Z_BEST_COMPRESSION: c.Z_BEST_COMPRESSION, + Z_DEFAULT_COMPRESSION: c.Z_DEFAULT_COMPRESSION, + Z_FILTERED: c.Z_FILTERED, + Z_HUFFMAN_ONLY: c.Z_HUFFMAN_ONLY, + Z_RLE: c.Z_RLE, + Z_FIXED: c.Z_FIXED, + Z_DEFAULT_STRATEGY: c.Z_DEFAULT_STRATEGY, + }; + `); + expect(result.code).toBe(0); + expect(result.exports).toEqual({ + Z_NO_FLUSH: 0, + Z_PARTIAL_FLUSH: 1, + Z_SYNC_FLUSH: 2, + Z_FULL_FLUSH: 3, + Z_FINISH: 4, + Z_BLOCK: 5, + Z_TREES: 6, + Z_OK: 0, + Z_STREAM_END: 1, + Z_NEED_DICT: 2, + Z_ERRNO: -1, + Z_STREAM_ERROR: -2, + Z_DATA_ERROR: -3, + Z_MEM_ERROR: -4, + Z_BUF_ERROR: -5, + Z_VERSION_ERROR: -6, + Z_NO_COMPRESSION: 0, + Z_BEST_SPEED: 1, + Z_BEST_COMPRESSION: 9, + Z_DEFAULT_COMPRESSION: -1, + Z_FILTERED: 1, + Z_HUFFMAN_ONLY: 2, + Z_RLE: 3, + Z_FIXED: 4, + Z_DEFAULT_STRATEGY: 0, + }); + }); + it("zlib.constants has mode constants (DEFLATE=1..GUNZIP=7)", async () => { const runtime = await context.createRuntime(); const result = await runtime.run(`