@metamask/snaps-execution-environments 6.6.2 → 6.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -1
- package/dist/common/BaseSnapExecutor.cjs +436 -0
- package/dist/common/BaseSnapExecutor.cjs.map +1 -0
- package/dist/{types/common/BaseSnapExecutor.d.ts → common/BaseSnapExecutor.d.cts} +8 -6
- package/dist/common/BaseSnapExecutor.d.cts.map +1 -0
- package/dist/common/BaseSnapExecutor.d.mts +70 -0
- package/dist/common/BaseSnapExecutor.d.mts.map +1 -0
- package/dist/common/BaseSnapExecutor.mjs +430 -24
- package/dist/common/BaseSnapExecutor.mjs.map +1 -1
- package/dist/common/commands.cjs +95 -0
- package/dist/common/commands.cjs.map +1 -0
- package/dist/{types/common/commands.d.ts → common/commands.d.cts} +5 -4
- package/dist/common/commands.d.cts.map +1 -0
- package/dist/common/commands.d.mts +31 -0
- package/dist/common/commands.d.mts.map +1 -0
- package/dist/common/commands.mjs +89 -10
- package/dist/common/commands.mjs.map +1 -1
- package/dist/common/endowments/commonEndowmentFactory.cjs +76 -0
- package/dist/common/endowments/commonEndowmentFactory.cjs.map +1 -0
- package/dist/{types/common/endowments/commonEndowmentFactory.d.ts → common/endowments/commonEndowmentFactory.d.cts} +5 -4
- package/dist/common/endowments/commonEndowmentFactory.d.cts.map +1 -0
- package/dist/common/endowments/commonEndowmentFactory.d.mts +26 -0
- package/dist/common/endowments/commonEndowmentFactory.d.mts.map +1 -0
- package/dist/common/endowments/commonEndowmentFactory.mjs +69 -18
- package/dist/common/endowments/commonEndowmentFactory.mjs.map +1 -1
- package/dist/common/endowments/console.cjs +103 -0
- package/dist/common/endowments/console.cjs.map +1 -0
- package/dist/{types/common/endowments/console.d.ts → common/endowments/console.d.cts} +2 -1
- package/dist/common/endowments/console.d.cts.map +1 -0
- package/dist/common/endowments/console.d.mts +46 -0
- package/dist/common/endowments/console.d.mts.map +1 -0
- package/dist/common/endowments/console.mjs +98 -11
- package/dist/common/endowments/console.mjs.map +1 -1
- package/dist/common/endowments/crypto.cjs +30 -0
- package/dist/common/endowments/crypto.cjs.map +1 -0
- package/dist/{types/common/endowments/crypto.d.ts → common/endowments/crypto.d.cts} +1 -0
- package/dist/common/endowments/crypto.d.cts.map +1 -0
- package/dist/common/endowments/crypto.d.mts +13 -0
- package/dist/common/endowments/crypto.d.mts.map +1 -0
- package/dist/common/endowments/crypto.mjs +24 -9
- package/dist/common/endowments/crypto.mjs.map +1 -1
- package/dist/common/endowments/date.cjs +39 -0
- package/dist/common/endowments/date.cjs.map +1 -0
- package/dist/{types/common/endowments/date.d.ts → common/endowments/date.d.cts} +1 -0
- package/dist/common/endowments/date.d.cts.map +1 -0
- package/dist/common/endowments/date.d.mts +16 -0
- package/dist/common/endowments/date.d.mts.map +1 -0
- package/dist/common/endowments/date.mjs +35 -7
- package/dist/common/endowments/date.mjs.map +1 -1
- package/dist/common/endowments/index.cjs +93 -0
- package/dist/common/endowments/index.cjs.map +1 -0
- package/dist/{types/common/endowments/index.d.ts → common/endowments/index.d.cts} +4 -3
- package/dist/common/endowments/index.d.cts.map +1 -0
- package/dist/common/endowments/index.d.mts +29 -0
- package/dist/common/endowments/index.d.mts.map +1 -0
- package/dist/common/endowments/index.mjs +85 -20
- package/dist/common/endowments/index.mjs.map +1 -1
- package/dist/common/endowments/interval.cjs +51 -0
- package/dist/common/endowments/interval.cjs.map +1 -0
- package/dist/{types/common/endowments/interval.d.ts → common/endowments/interval.d.cts} +1 -0
- package/dist/common/endowments/interval.d.cts.map +1 -0
- package/dist/common/endowments/interval.d.mts +10 -0
- package/dist/common/endowments/interval.d.mts.map +1 -0
- package/dist/common/endowments/interval.mjs +47 -6
- package/dist/common/endowments/interval.mjs.map +1 -1
- package/dist/common/endowments/math.cjs +54 -0
- package/dist/common/endowments/math.cjs.map +1 -0
- package/dist/{types/common/endowments/math.d.ts → common/endowments/math.d.cts} +1 -0
- package/dist/common/endowments/math.d.cts.map +1 -0
- package/dist/common/endowments/math.d.mts +61 -0
- package/dist/common/endowments/math.d.mts.map +1 -0
- package/dist/common/endowments/math.mjs +50 -8
- package/dist/common/endowments/math.mjs.map +1 -1
- package/dist/common/endowments/network.cjs +255 -0
- package/dist/common/endowments/network.cjs.map +1 -0
- package/dist/{types/common/endowments/network.d.ts → common/endowments/network.d.cts} +4 -2
- package/dist/common/endowments/network.d.cts.map +1 -0
- package/dist/common/endowments/network.d.mts +25 -0
- package/dist/common/endowments/network.d.mts.map +1 -0
- package/dist/common/endowments/network.mjs +251 -8
- package/dist/common/endowments/network.mjs.map +1 -1
- package/dist/common/endowments/textDecoder.cjs +18 -0
- package/dist/common/endowments/textDecoder.cjs.map +1 -0
- package/dist/{types/common/endowments/textDecoder.d.ts → common/endowments/textDecoder.d.cts} +1 -0
- package/dist/common/endowments/textDecoder.d.cts.map +1 -0
- package/dist/common/endowments/textDecoder.d.mts +11 -0
- package/dist/common/endowments/textDecoder.d.mts.map +1 -0
- package/dist/common/endowments/textDecoder.mjs +14 -6
- package/dist/common/endowments/textDecoder.mjs.map +1 -1
- package/dist/common/endowments/textEncoder.cjs +18 -0
- package/dist/common/endowments/textEncoder.cjs.map +1 -0
- package/dist/{types/common/endowments/textEncoder.d.ts → common/endowments/textEncoder.d.cts} +1 -0
- package/dist/common/endowments/textEncoder.d.cts.map +1 -0
- package/dist/common/endowments/textEncoder.d.mts +11 -0
- package/dist/common/endowments/textEncoder.d.mts.map +1 -0
- package/dist/common/endowments/textEncoder.mjs +14 -6
- package/dist/common/endowments/textEncoder.mjs.map +1 -1
- package/dist/common/endowments/timeout.cjs +53 -0
- package/dist/common/endowments/timeout.cjs.map +1 -0
- package/dist/{types/common/endowments/timeout.d.ts → common/endowments/timeout.d.cts} +1 -0
- package/dist/common/endowments/timeout.d.cts.map +1 -0
- package/dist/common/endowments/timeout.d.mts +10 -0
- package/dist/common/endowments/timeout.d.mts.map +1 -0
- package/dist/common/endowments/timeout.mjs +49 -6
- package/dist/common/endowments/timeout.mjs.map +1 -1
- package/dist/common/globalEvents.cjs +48 -0
- package/dist/common/globalEvents.cjs.map +1 -0
- package/dist/{types/common/globalEvents.d.ts → common/globalEvents.d.cts} +1 -0
- package/dist/common/globalEvents.d.cts.map +1 -0
- package/dist/common/globalEvents.d.mts +21 -0
- package/dist/common/globalEvents.d.mts.map +1 -0
- package/dist/common/globalEvents.mjs +42 -10
- package/dist/common/globalEvents.mjs.map +1 -1
- package/dist/common/globalObject.cjs +50 -0
- package/dist/common/globalObject.cjs.map +1 -0
- package/dist/{types/common/globalObject.d.ts → common/globalObject.d.cts} +1 -0
- package/dist/common/globalObject.d.cts.map +1 -0
- package/dist/common/globalObject.d.mts +10 -0
- package/dist/common/globalObject.d.mts.map +1 -0
- package/dist/common/globalObject.mjs +45 -9
- package/dist/common/globalObject.mjs.map +1 -1
- package/dist/common/lockdown/lockdown-events.cjs +60 -0
- package/dist/common/lockdown/lockdown-events.cjs.map +1 -0
- package/dist/{types/common/lockdown/lockdown-events.d.ts → common/lockdown/lockdown-events.d.cts} +1 -0
- package/dist/common/lockdown/lockdown-events.d.cts.map +1 -0
- package/dist/common/lockdown/lockdown-events.d.mts +5 -0
- package/dist/common/lockdown/lockdown-events.d.mts.map +1 -0
- package/dist/common/lockdown/lockdown-events.mjs +55 -7
- package/dist/common/lockdown/lockdown-events.mjs.map +1 -1
- package/dist/common/lockdown/lockdown-more.cjs +89 -0
- package/dist/common/lockdown/lockdown-more.cjs.map +1 -0
- package/dist/{types/common/lockdown/lockdown-more.d.ts → common/lockdown/lockdown-more.d.cts} +1 -0
- package/dist/common/lockdown/lockdown-more.d.cts.map +1 -0
- package/dist/common/lockdown/lockdown-more.d.mts +23 -0
- package/dist/common/lockdown/lockdown-more.d.mts.map +1 -0
- package/dist/common/lockdown/lockdown-more.mjs +84 -7
- package/dist/common/lockdown/lockdown-more.mjs.map +1 -1
- package/dist/common/lockdown/lockdown.cjs +29 -0
- package/dist/common/lockdown/lockdown.cjs.map +1 -0
- package/dist/{types/common/lockdown/lockdown.d.ts → common/lockdown/lockdown.d.cts} +1 -0
- package/dist/common/lockdown/lockdown.d.cts.map +1 -0
- package/dist/common/lockdown/lockdown.d.mts +8 -0
- package/dist/common/lockdown/lockdown.d.mts.map +1 -0
- package/dist/common/lockdown/lockdown.mjs +22 -19
- package/dist/common/lockdown/lockdown.mjs.map +1 -1
- package/dist/common/sortParams.cjs +35 -0
- package/dist/common/sortParams.cjs.map +1 -0
- package/dist/{types/common/sortParams.d.ts → common/sortParams.d.cts} +2 -1
- package/dist/common/sortParams.d.cts.map +1 -0
- package/dist/common/sortParams.d.mts +17 -0
- package/dist/common/sortParams.d.mts.map +1 -0
- package/dist/common/sortParams.mjs +29 -6
- package/dist/common/sortParams.mjs.map +1 -1
- package/dist/common/utils.cjs +156 -0
- package/dist/common/utils.cjs.map +1 -0
- package/dist/{types/common/utils.d.ts → common/utils.d.cts} +2 -1
- package/dist/common/utils.d.cts.map +1 -0
- package/dist/common/utils.d.mts +50 -0
- package/dist/common/utils.d.mts.map +1 -0
- package/dist/common/utils.mjs +146 -20
- package/dist/common/utils.mjs.map +1 -1
- package/dist/common/validation.cjs +137 -0
- package/dist/common/validation.cjs.map +1 -0
- package/dist/{types/common/validation.d.ts → common/validation.d.cts} +37 -36
- package/dist/common/validation.d.cts.map +1 -0
- package/dist/common/validation.d.mts +199 -0
- package/dist/common/validation.d.mts.map +1 -0
- package/dist/common/validation.mjs +127 -37
- package/dist/common/validation.mjs.map +1 -1
- package/dist/iframe/IFrameSnapExecutor.cjs +42 -0
- package/dist/iframe/IFrameSnapExecutor.cjs.map +1 -0
- package/dist/{types/iframe/IFrameSnapExecutor.d.ts → iframe/IFrameSnapExecutor.d.cts} +3 -2
- package/dist/iframe/IFrameSnapExecutor.d.cts.map +1 -0
- package/dist/iframe/IFrameSnapExecutor.d.mts +14 -0
- package/dist/iframe/IFrameSnapExecutor.d.mts.map +1 -0
- package/dist/iframe/IFrameSnapExecutor.mjs +42 -26
- package/dist/iframe/IFrameSnapExecutor.mjs.map +1 -1
- package/dist/iframe/index.cjs +10 -0
- package/dist/iframe/index.cjs.map +1 -0
- package/dist/iframe/index.d.cts +2 -0
- package/dist/iframe/index.d.cts.map +1 -0
- package/dist/iframe/index.d.mts +2 -0
- package/dist/iframe/index.d.mts.map +1 -0
- package/dist/iframe/index.mjs +4 -31
- package/dist/iframe/index.mjs.map +1 -1
- package/dist/index.cjs +18 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1 -8
- package/dist/index.mjs.map +1 -1
- package/dist/logging.cjs +13 -0
- package/dist/logging.cjs.map +1 -0
- package/dist/{types/logging.d.ts → logging.d.cts} +1 -0
- package/dist/logging.d.cts.map +1 -0
- package/dist/logging.d.mts +9 -0
- package/dist/logging.d.mts.map +1 -0
- package/dist/logging.mjs +9 -7
- package/dist/logging.mjs.map +1 -1
- package/dist/node-process/ChildProcessSnapExecutor.cjs +30 -0
- package/dist/node-process/ChildProcessSnapExecutor.cjs.map +1 -0
- package/dist/{types/node-process/ChildProcessSnapExecutor.d.ts → node-process/ChildProcessSnapExecutor.d.cts} +2 -1
- package/dist/node-process/ChildProcessSnapExecutor.d.cts.map +1 -0
- package/dist/node-process/ChildProcessSnapExecutor.d.mts +5 -0
- package/dist/node-process/ChildProcessSnapExecutor.d.mts.map +1 -0
- package/dist/node-process/ChildProcessSnapExecutor.mjs +30 -26
- package/dist/node-process/ChildProcessSnapExecutor.mjs.map +1 -1
- package/dist/node-process/index.cjs +8 -0
- package/dist/node-process/index.cjs.map +1 -0
- package/dist/node-process/index.d.cts +2 -0
- package/dist/node-process/index.d.cts.map +1 -0
- package/dist/node-process/index.d.mts +2 -0
- package/dist/node-process/index.d.mts.map +1 -0
- package/dist/node-process/index.mjs +3 -28
- package/dist/node-process/index.mjs.map +1 -1
- package/dist/node-thread/ThreadSnapExecutor.cjs +30 -0
- package/dist/node-thread/ThreadSnapExecutor.cjs.map +1 -0
- package/dist/node-thread/ThreadSnapExecutor.d.cts +5 -0
- package/dist/node-thread/ThreadSnapExecutor.d.cts.map +1 -0
- package/dist/node-thread/ThreadSnapExecutor.d.mts +5 -0
- package/dist/node-thread/ThreadSnapExecutor.d.mts.map +1 -0
- package/dist/node-thread/ThreadSnapExecutor.mjs +30 -26
- package/dist/node-thread/ThreadSnapExecutor.mjs.map +1 -1
- package/dist/node-thread/index.cjs +8 -0
- package/dist/node-thread/index.cjs.map +1 -0
- package/dist/node-thread/index.d.cts +2 -0
- package/dist/node-thread/index.d.cts.map +1 -0
- package/dist/node-thread/index.d.mts +2 -0
- package/dist/node-thread/index.d.mts.map +1 -0
- package/dist/node-thread/index.mjs +3 -28
- package/dist/node-thread/index.mjs.map +1 -1
- package/dist/proxy/ProxySnapExecutor.cjs +112 -0
- package/dist/proxy/ProxySnapExecutor.cjs.map +1 -0
- package/dist/{types/proxy/ProxySnapExecutor.d.ts → proxy/ProxySnapExecutor.d.cts} +4 -3
- package/dist/proxy/ProxySnapExecutor.d.cts.map +1 -0
- package/dist/proxy/ProxySnapExecutor.d.mts +36 -0
- package/dist/proxy/ProxySnapExecutor.d.mts.map +1 -0
- package/dist/proxy/ProxySnapExecutor.mjs +104 -6
- package/dist/proxy/ProxySnapExecutor.mjs.map +1 -1
- package/dist/proxy/index.cjs +18 -0
- package/dist/proxy/index.cjs.map +1 -0
- package/dist/proxy/index.d.cts +2 -0
- package/dist/proxy/index.d.cts.map +1 -0
- package/dist/proxy/index.d.mts +2 -0
- package/dist/proxy/index.d.mts.map +1 -0
- package/dist/proxy/index.mjs +1 -8
- package/dist/proxy/index.mjs.map +1 -1
- package/dist/webview/WebViewExecutorStream.cjs +79 -0
- package/dist/webview/WebViewExecutorStream.cjs.map +1 -0
- package/dist/{types/webview/WebViewExecutorStream.d.ts → webview/WebViewExecutorStream.d.cts} +3 -2
- package/dist/webview/WebViewExecutorStream.d.cts.map +1 -0
- package/dist/webview/WebViewExecutorStream.d.mts +33 -0
- package/dist/webview/WebViewExecutorStream.d.mts.map +1 -0
- package/dist/webview/WebViewExecutorStream.mjs +74 -6
- package/dist/webview/WebViewExecutorStream.mjs.map +1 -1
- package/dist/webview/index.cjs +16 -0
- package/dist/webview/index.cjs.map +1 -0
- package/dist/webview/index.d.cts +2 -0
- package/dist/webview/index.d.cts.map +1 -0
- package/dist/webview/index.d.mts +2 -0
- package/dist/webview/index.d.mts.map +1 -0
- package/dist/webview/index.mjs +9 -21
- package/dist/webview/index.mjs.map +1 -1
- package/dist/webworker/executor/WebWorkerSnapExecutor.cjs +37 -0
- package/dist/webworker/executor/WebWorkerSnapExecutor.cjs.map +1 -0
- package/dist/{types/webworker/executor/WebWorkerSnapExecutor.d.ts → webworker/executor/WebWorkerSnapExecutor.d.cts} +3 -2
- package/dist/webworker/executor/WebWorkerSnapExecutor.d.cts.map +1 -0
- package/dist/webworker/executor/WebWorkerSnapExecutor.d.mts +14 -0
- package/dist/webworker/executor/WebWorkerSnapExecutor.d.mts.map +1 -0
- package/dist/webworker/executor/WebWorkerSnapExecutor.mjs +37 -26
- package/dist/webworker/executor/WebWorkerSnapExecutor.mjs.map +1 -1
- package/dist/webworker/executor/index.cjs +10 -0
- package/dist/webworker/executor/index.cjs.map +1 -0
- package/dist/webworker/executor/index.d.cts +2 -0
- package/dist/webworker/executor/index.d.cts.map +1 -0
- package/dist/webworker/executor/index.d.mts +2 -0
- package/dist/webworker/executor/index.d.mts.map +1 -0
- package/dist/webworker/executor/index.mjs +4 -31
- package/dist/webworker/executor/index.mjs.map +1 -1
- package/dist/webworker/pool/WebWorkerPool.cjs +168 -0
- package/dist/webworker/pool/WebWorkerPool.cjs.map +1 -0
- package/dist/{types/webworker/pool/WebWorkerPool.d.ts → webworker/pool/WebWorkerPool.d.cts} +4 -3
- package/dist/webworker/pool/WebWorkerPool.d.cts.map +1 -0
- package/dist/webworker/pool/WebWorkerPool.d.mts +24 -0
- package/dist/webworker/pool/WebWorkerPool.d.mts.map +1 -0
- package/dist/webworker/pool/WebWorkerPool.mjs +163 -6
- package/dist/webworker/pool/WebWorkerPool.mjs.map +1 -1
- package/dist/webworker/pool/index.cjs +10 -0
- package/dist/webworker/pool/index.cjs.map +1 -0
- package/dist/webworker/pool/index.d.cts +2 -0
- package/dist/webworker/pool/index.d.cts.map +1 -0
- package/dist/webworker/pool/index.d.mts +2 -0
- package/dist/webworker/pool/index.d.mts.map +1 -0
- package/dist/webworker/pool/index.mjs +4 -12
- package/dist/webworker/pool/index.mjs.map +1 -1
- package/package.json +21 -18
- package/dist/browserify/iframe/bundle.js +0 -9
- package/dist/browserify/iframe/index.html +0 -13394
- package/dist/browserify/node-process/bundle.js +0 -13390
- package/dist/browserify/node-thread/bundle.js +0 -13390
- package/dist/browserify/webview/index.html +0 -13402
- package/dist/browserify/worker-executor/bundle.js +0 -13392
- package/dist/browserify/worker-pool/bundle.js +0 -9
- package/dist/browserify/worker-pool/index.html +0 -13394
- package/dist/chunk-2VA6RAEE.js +0 -30
- package/dist/chunk-2VA6RAEE.js.map +0 -1
- package/dist/chunk-3JCT4MWT.js +0 -108
- package/dist/chunk-3JCT4MWT.js.map +0 -1
- package/dist/chunk-46LW37FK.js +0 -144
- package/dist/chunk-46LW37FK.js.map +0 -1
- package/dist/chunk-4COIRXF5.js +0 -86
- package/dist/chunk-4COIRXF5.js.map +0 -1
- package/dist/chunk-4XRZLEKU.js +0 -49
- package/dist/chunk-4XRZLEKU.js.map +0 -1
- package/dist/chunk-53ZULHPK.mjs +0 -16
- package/dist/chunk-53ZULHPK.mjs.map +0 -1
- package/dist/chunk-5DEV3QQU.mjs +0 -12
- package/dist/chunk-5DEV3QQU.mjs.map +0 -1
- package/dist/chunk-5LGIS4VY.js +0 -33
- package/dist/chunk-5LGIS4VY.js.map +0 -1
- package/dist/chunk-5STN3QCA.js +0 -183
- package/dist/chunk-5STN3QCA.js.map +0 -1
- package/dist/chunk-75RCH4ZX.mjs +0 -151
- package/dist/chunk-75RCH4ZX.mjs.map +0 -1
- package/dist/chunk-7AJWXSDQ.mjs +0 -73
- package/dist/chunk-7AJWXSDQ.mjs.map +0 -1
- package/dist/chunk-7MMUJJQ2.js +0 -151
- package/dist/chunk-7MMUJJQ2.js.map +0 -1
- package/dist/chunk-BCBKEUCG.mjs +0 -38
- package/dist/chunk-BCBKEUCG.mjs.map +0 -1
- package/dist/chunk-BTEAZZKP.mjs +0 -24
- package/dist/chunk-BTEAZZKP.mjs.map +0 -1
- package/dist/chunk-BVRVUIJB.mjs +0 -67
- package/dist/chunk-BVRVUIJB.mjs.map +0 -1
- package/dist/chunk-CV5LC4PP.js +0 -24
- package/dist/chunk-CV5LC4PP.js.map +0 -1
- package/dist/chunk-DAG7NWEU.mjs +0 -33
- package/dist/chunk-DAG7NWEU.mjs.map +0 -1
- package/dist/chunk-DKDTGAFK.js +0 -67
- package/dist/chunk-DKDTGAFK.js.map +0 -1
- package/dist/chunk-DLLLH5HN.js +0 -26
- package/dist/chunk-DLLLH5HN.js.map +0 -1
- package/dist/chunk-EXN2TFDJ.js +0 -38
- package/dist/chunk-EXN2TFDJ.js.map +0 -1
- package/dist/chunk-FJT65CXB.js +0 -472
- package/dist/chunk-FJT65CXB.js.map +0 -1
- package/dist/chunk-FOEAIF5U.js +0 -16
- package/dist/chunk-FOEAIF5U.js.map +0 -1
- package/dist/chunk-FUPEJT7B.js +0 -82
- package/dist/chunk-FUPEJT7B.js.map +0 -1
- package/dist/chunk-HCJZG6W7.mjs +0 -45
- package/dist/chunk-HCJZG6W7.mjs.map +0 -1
- package/dist/chunk-HGLRZZ56.js +0 -32
- package/dist/chunk-HGLRZZ56.js.map +0 -1
- package/dist/chunk-HL2TTKF3.mjs +0 -144
- package/dist/chunk-HL2TTKF3.mjs.map +0 -1
- package/dist/chunk-HWS4QSOC.mjs +0 -16
- package/dist/chunk-HWS4QSOC.mjs.map +0 -1
- package/dist/chunk-HXKBUIYS.js +0 -262
- package/dist/chunk-HXKBUIYS.js.map +0 -1
- package/dist/chunk-I5G4YFHM.js +0 -73
- package/dist/chunk-I5G4YFHM.js.map +0 -1
- package/dist/chunk-IX5S3V47.mjs +0 -26
- package/dist/chunk-IX5S3V47.mjs.map +0 -1
- package/dist/chunk-JOT5JH42.js +0 -52
- package/dist/chunk-JOT5JH42.js.map +0 -1
- package/dist/chunk-KEAB7ZVV.js +0 -50
- package/dist/chunk-KEAB7ZVV.js.map +0 -1
- package/dist/chunk-LAKWJYBO.js +0 -33
- package/dist/chunk-LAKWJYBO.js.map +0 -1
- package/dist/chunk-LO5ORVRC.js +0 -16
- package/dist/chunk-LO5ORVRC.js.map +0 -1
- package/dist/chunk-MCXWFCGV.js +0 -1
- package/dist/chunk-MCXWFCGV.js.map +0 -1
- package/dist/chunk-MIWGLICQ.mjs +0 -108
- package/dist/chunk-MIWGLICQ.mjs.map +0 -1
- package/dist/chunk-MMYM63NH.mjs +0 -82
- package/dist/chunk-MMYM63NH.mjs.map +0 -1
- package/dist/chunk-MS2LQQYH.js +0 -38
- package/dist/chunk-MS2LQQYH.js.map +0 -1
- package/dist/chunk-MXNMMTJW.mjs +0 -51
- package/dist/chunk-MXNMMTJW.mjs.map +0 -1
- package/dist/chunk-OBT45IWW.js +0 -92
- package/dist/chunk-OBT45IWW.js.map +0 -1
- package/dist/chunk-OCNPLHS2.js +0 -51
- package/dist/chunk-OCNPLHS2.js.map +0 -1
- package/dist/chunk-ODICKSGZ.mjs +0 -86
- package/dist/chunk-ODICKSGZ.mjs.map +0 -1
- package/dist/chunk-OIN7VU4G.mjs +0 -33
- package/dist/chunk-OIN7VU4G.mjs.map +0 -1
- package/dist/chunk-Q42NNJFY.mjs +0 -32
- package/dist/chunk-Q42NNJFY.mjs.map +0 -1
- package/dist/chunk-Q42WB3ZO.js +0 -40
- package/dist/chunk-Q42WB3ZO.js.map +0 -1
- package/dist/chunk-QZC2X6NG.js +0 -44
- package/dist/chunk-QZC2X6NG.js.map +0 -1
- package/dist/chunk-S5NWI5Z7.mjs +0 -50
- package/dist/chunk-S5NWI5Z7.mjs.map +0 -1
- package/dist/chunk-S7257EN3.mjs +0 -49
- package/dist/chunk-S7257EN3.mjs.map +0 -1
- package/dist/chunk-TSEAPB7L.mjs +0 -1
- package/dist/chunk-TSEAPB7L.mjs.map +0 -1
- package/dist/chunk-TZAPZE45.mjs +0 -472
- package/dist/chunk-TZAPZE45.mjs.map +0 -1
- package/dist/chunk-UOPIRTJX.mjs +0 -44
- package/dist/chunk-UOPIRTJX.mjs.map +0 -1
- package/dist/chunk-V76DI2XM.mjs +0 -183
- package/dist/chunk-V76DI2XM.mjs.map +0 -1
- package/dist/chunk-VFQ5CRZS.mjs +0 -40
- package/dist/chunk-VFQ5CRZS.mjs.map +0 -1
- package/dist/chunk-W7EDURT5.mjs +0 -92
- package/dist/chunk-W7EDURT5.mjs.map +0 -1
- package/dist/chunk-WZDVTU5C.js +0 -45
- package/dist/chunk-WZDVTU5C.js.map +0 -1
- package/dist/chunk-XPCW7TKM.mjs +0 -262
- package/dist/chunk-XPCW7TKM.mjs.map +0 -1
- package/dist/chunk-Y7AK2VVC.mjs +0 -52
- package/dist/chunk-Y7AK2VVC.mjs.map +0 -1
- package/dist/chunk-YRZVIDCF.mjs +0 -38
- package/dist/chunk-YRZVIDCF.mjs.map +0 -1
- package/dist/chunk-Z7BOREC4.js +0 -12
- package/dist/chunk-Z7BOREC4.js.map +0 -1
- package/dist/chunk-ZNTCZK7J.mjs +0 -30
- package/dist/chunk-ZNTCZK7J.mjs.map +0 -1
- package/dist/common/BaseSnapExecutor.js +0 -26
- package/dist/common/BaseSnapExecutor.js.map +0 -1
- package/dist/common/commands.js +0 -11
- package/dist/common/commands.js.map +0 -1
- package/dist/common/endowments/commonEndowmentFactory.js +0 -20
- package/dist/common/endowments/commonEndowmentFactory.js.map +0 -1
- package/dist/common/endowments/console.js +0 -13
- package/dist/common/endowments/console.js.map +0 -1
- package/dist/common/endowments/crypto.js +0 -11
- package/dist/common/endowments/crypto.js.map +0 -1
- package/dist/common/endowments/date.js +0 -9
- package/dist/common/endowments/date.js.map +0 -1
- package/dist/common/endowments/index.js +0 -21
- package/dist/common/endowments/index.js.map +0 -1
- package/dist/common/endowments/interval.js +0 -8
- package/dist/common/endowments/interval.js.map +0 -1
- package/dist/common/endowments/math.js +0 -10
- package/dist/common/endowments/math.js.map +0 -1
- package/dist/common/endowments/network.js +0 -10
- package/dist/common/endowments/network.js.map +0 -1
- package/dist/common/endowments/textDecoder.js +0 -8
- package/dist/common/endowments/textDecoder.js.map +0 -1
- package/dist/common/endowments/textEncoder.js +0 -8
- package/dist/common/endowments/textEncoder.js.map +0 -1
- package/dist/common/endowments/timeout.js +0 -8
- package/dist/common/endowments/timeout.js.map +0 -1
- package/dist/common/globalEvents.js +0 -11
- package/dist/common/globalEvents.js.map +0 -1
- package/dist/common/globalObject.js +0 -10
- package/dist/common/globalObject.js.map +0 -1
- package/dist/common/lockdown/lockdown-events.js +0 -8
- package/dist/common/lockdown/lockdown-events.js.map +0 -1
- package/dist/common/lockdown/lockdown-more.js +0 -8
- package/dist/common/lockdown/lockdown-more.js.map +0 -1
- package/dist/common/lockdown/lockdown.js +0 -22
- package/dist/common/lockdown/lockdown.js.map +0 -1
- package/dist/common/sortParams.js +0 -8
- package/dist/common/sortParams.js.map +0 -1
- package/dist/common/utils.js +0 -21
- package/dist/common/utils.js.map +0 -1
- package/dist/common/validation.js +0 -38
- package/dist/common/validation.js.map +0 -1
- package/dist/globals.d.js +0 -1
- package/dist/globals.d.js.map +0 -1
- package/dist/globals.d.mjs +0 -1
- package/dist/globals.d.mjs.map +0 -1
- package/dist/iframe/IFrameSnapExecutor.js +0 -27
- package/dist/iframe/IFrameSnapExecutor.js.map +0 -1
- package/dist/iframe/index.js +0 -35
- package/dist/iframe/index.js.map +0 -1
- package/dist/index.js +0 -9
- package/dist/index.js.map +0 -1
- package/dist/logging.js +0 -8
- package/dist/logging.js.map +0 -1
- package/dist/node-process/ChildProcessSnapExecutor.js +0 -27
- package/dist/node-process/ChildProcessSnapExecutor.js.map +0 -1
- package/dist/node-process/index.js +0 -31
- package/dist/node-process/index.js.map +0 -1
- package/dist/node-thread/ThreadSnapExecutor.js +0 -27
- package/dist/node-thread/ThreadSnapExecutor.js.map +0 -1
- package/dist/node-thread/index.js +0 -31
- package/dist/node-thread/index.js.map +0 -1
- package/dist/proxy/ProxySnapExecutor.js +0 -8
- package/dist/proxy/ProxySnapExecutor.js.map +0 -1
- package/dist/proxy/index.js +0 -9
- package/dist/proxy/index.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/iframe/index.d.ts +0 -1
- package/dist/types/index.d.ts +0 -1
- package/dist/types/node-process/index.d.ts +0 -1
- package/dist/types/node-thread/ThreadSnapExecutor.d.ts +0 -4
- package/dist/types/node-thread/index.d.ts +0 -1
- package/dist/types/proxy/index.d.ts +0 -1
- package/dist/types/vendor/global.d.js +0 -1
- package/dist/types/vendor/global.d.js.map +0 -1
- package/dist/types/vendor/global.d.mjs +0 -1
- package/dist/types/vendor/global.d.mjs.map +0 -1
- package/dist/types/vendor/providers.d.js +0 -1
- package/dist/types/vendor/providers.d.js.map +0 -1
- package/dist/types/vendor/providers.d.mjs +0 -1
- package/dist/types/vendor/providers.d.mjs.map +0 -1
- package/dist/types/vendor/readable-stream.d.js +0 -1
- package/dist/types/vendor/readable-stream.d.js.map +0 -1
- package/dist/types/vendor/readable-stream.d.mjs +0 -1
- package/dist/types/vendor/readable-stream.d.mjs.map +0 -1
- package/dist/types/webview/index.d.ts +0 -1
- package/dist/types/webworker/executor/index.d.ts +0 -1
- package/dist/types/webworker/pool/index.d.ts +0 -1
- package/dist/webview/WebViewExecutorStream.js +0 -8
- package/dist/webview/WebViewExecutorStream.js.map +0 -1
- package/dist/webview/index.js +0 -26
- package/dist/webview/index.js.map +0 -1
- package/dist/webworker/executor/WebWorkerSnapExecutor.js +0 -27
- package/dist/webworker/executor/WebWorkerSnapExecutor.js.map +0 -1
- package/dist/webworker/executor/index.js +0 -35
- package/dist/webworker/executor/index.js.map +0 -1
- package/dist/webworker/pool/WebWorkerPool.js +0 -8
- package/dist/webworker/pool/WebWorkerPool.js.map +0 -1
- package/dist/webworker/pool/index.js +0 -16
- package/dist/webworker/pool/index.js.map +0 -1
|
@@ -1,21 +1,86 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
} from "
|
|
4
|
-
import "
|
|
5
|
-
import "
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
};
|
|
1
|
+
import { rpcErrors } from "@metamask/rpc-errors";
|
|
2
|
+
import { logWarning } from "@metamask/snaps-utils";
|
|
3
|
+
import { hasProperty } from "@metamask/utils";
|
|
4
|
+
import { rootRealmGlobal } from "../globalObject.mjs";
|
|
5
|
+
import buildCommonEndowments from "./commonEndowmentFactory.mjs";
|
|
6
|
+
/**
|
|
7
|
+
* Retrieve consolidated endowment factories for common endowments.
|
|
8
|
+
*/
|
|
9
|
+
const registeredEndowments = buildCommonEndowments();
|
|
10
|
+
/**
|
|
11
|
+
* A map of endowment names to their factory functions. Some endowments share
|
|
12
|
+
* the same factory function, but we only call each factory once for each snap.
|
|
13
|
+
* See {@link createEndowments} for details.
|
|
14
|
+
*/
|
|
15
|
+
const endowmentFactories = registeredEndowments.reduce((factories, builder) => {
|
|
16
|
+
builder.names.forEach((name) => {
|
|
17
|
+
factories.set(name, builder.factory);
|
|
18
|
+
});
|
|
19
|
+
return factories;
|
|
20
|
+
}, new Map());
|
|
21
|
+
/**
|
|
22
|
+
* Gets the endowments for a particular Snap. Some endowments, like `setTimeout`
|
|
23
|
+
* and `clearTimeout`, must be attenuated so that they can only affect behavior
|
|
24
|
+
* within the Snap's own realm. Therefore, we use factory functions to create
|
|
25
|
+
* such attenuated / modified endowments. Otherwise, the value that's on the
|
|
26
|
+
* root realm global will be used.
|
|
27
|
+
*
|
|
28
|
+
* @param options - An options bag.
|
|
29
|
+
* @param options.snap - The Snaps global API object.
|
|
30
|
+
* @param options.ethereum - The Snap's EIP-1193 provider object.
|
|
31
|
+
* @param options.snapId - The id of the snap that will use the created endowments.
|
|
32
|
+
* @param options.endowments - The list of endowments to provide to the snap.
|
|
33
|
+
* @param options.notify - A reference to the notify function of the snap executor.
|
|
34
|
+
* @returns An object containing the Snap's endowments.
|
|
35
|
+
*/
|
|
36
|
+
export function createEndowments({ snap, ethereum, snapId, endowments, notify, }) {
|
|
37
|
+
const attenuatedEndowments = {};
|
|
38
|
+
// TODO: All endowments should be hardened to prevent covert communication
|
|
39
|
+
// channels. Hardening the returned objects breaks tests elsewhere in the
|
|
40
|
+
// monorepo, so further research is needed.
|
|
41
|
+
const result = endowments.reduce(({ allEndowments, teardowns }, endowmentName) => {
|
|
42
|
+
// First, check if the endowment has a factory, and default to that.
|
|
43
|
+
if (endowmentFactories.has(endowmentName)) {
|
|
44
|
+
if (!hasProperty(attenuatedEndowments, endowmentName)) {
|
|
45
|
+
// Call the endowment factory for the current endowment. If the factory
|
|
46
|
+
// creates multiple endowments, they will all be assigned to the
|
|
47
|
+
// `attenuatedEndowments` object, but will only be passed on to the snap
|
|
48
|
+
// if explicitly listed among its endowment.
|
|
49
|
+
// This may not have an actual use case, but, safety first.
|
|
50
|
+
// We just confirmed that endowmentFactories has the specified key.
|
|
51
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
52
|
+
const { teardownFunction, ...endowment } = endowmentFactories.get(endowmentName)({ snapId, notify });
|
|
53
|
+
Object.assign(attenuatedEndowments, endowment);
|
|
54
|
+
if (teardownFunction) {
|
|
55
|
+
teardowns.push(teardownFunction);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
allEndowments[endowmentName] = attenuatedEndowments[endowmentName];
|
|
59
|
+
}
|
|
60
|
+
else if (endowmentName === 'ethereum') {
|
|
61
|
+
// Special case for adding the EIP-1193 provider.
|
|
62
|
+
allEndowments[endowmentName] = ethereum;
|
|
63
|
+
}
|
|
64
|
+
else if (endowmentName in rootRealmGlobal) {
|
|
65
|
+
logWarning(`Access to unhardened global ${endowmentName}.`);
|
|
66
|
+
// If the endowment doesn't have a factory, just use whatever is on the
|
|
67
|
+
// global object.
|
|
68
|
+
const globalValue = rootRealmGlobal[endowmentName];
|
|
69
|
+
allEndowments[endowmentName] = globalValue;
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
// If we get to this point, we've been passed an endowment that doesn't
|
|
73
|
+
// exist in our current environment.
|
|
74
|
+
throw rpcErrors.internal(`Unknown endowment: "${endowmentName}".`);
|
|
75
|
+
}
|
|
76
|
+
return { allEndowments, teardowns };
|
|
77
|
+
}, {
|
|
78
|
+
allEndowments: { snap },
|
|
79
|
+
teardowns: [],
|
|
80
|
+
});
|
|
81
|
+
const teardown = async () => {
|
|
82
|
+
await Promise.all(result.teardowns.map((teardownFunction) => teardownFunction()));
|
|
83
|
+
};
|
|
84
|
+
return { endowments: result.allEndowments, teardown };
|
|
85
|
+
}
|
|
21
86
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/common/endowments/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAEjD,OAAO,EAAE,UAAU,EAAE,8BAA8B;AACnD,OAAO,EAAE,WAAW,EAAE,wBAAwB;AAG9C,OAAO,EAAE,eAAe,EAAE,4BAAwB;AAElD,OAAO,qBAAqB,qCAAiC;AAe7D;;GAEG;AACH,MAAM,oBAAoB,GAAG,qBAAqB,EAAE,CAAC;AAErD;;;;GAIG;AACH,MAAM,kBAAkB,GAAG,oBAAoB,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,OAAO,EAAE,EAAE;IAC5E,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC7B,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,OAAO,CAAC,CAAC;IACvC,CAAC,CAAC,CAAC;IACH,OAAO,SAAS,CAAC;AACnB,CAAC,EAAE,IAAI,GAAG,EAAyE,CAAC,CAAC;AAErF;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,gBAAgB,CAAC,EAC/B,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,UAAU,EACV,MAAM,GAOP;IACC,MAAM,oBAAoB,GAA4B,EAAE,CAAC;IAEzD,0EAA0E;IAC1E,yEAAyE;IACzE,2CAA2C;IAC3C,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAI9B,CAAC,EAAE,aAAa,EAAE,SAAS,EAAE,EAAE,aAAa,EAAE,EAAE;QAC9C,oEAAoE;QACpE,IAAI,kBAAkB,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAAC;YAC1C,IAAI,CAAC,WAAW,CAAC,oBAAoB,EAAE,aAAa,CAAC,EAAE,CAAC;gBACtD,uEAAuE;gBACvE,gEAAgE;gBAChE,wEAAwE;gBACxE,4CAA4C;gBAC5C,2DAA2D;gBAE3D,mEAAmE;gBACnE,oEAAoE;gBACpE,MAAM,EAAE,gBAAgB,EAAE,GAAG,SAAS,EAAE,GAAG,kBAAkB,CAAC,GAAG,CAC/D,aAAa,CACb,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;gBACvB,MAAM,CAAC,MAAM,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAC;gBAC/C,IAAI,gBAAgB,EAAE,CAAC;oBACrB,SAAS,CAAC,IAAI,CAAC,gBAAgB,CAAC,CAAC;gBACnC,CAAC;YACH,CAAC;YACD,aAAa,CAAC,aAAa,CAAC,GAAG,oBAAoB,CAAC,aAAa,CAAC,CAAC;QACrE,CAAC;aAAM,IAAI,aAAa,KAAK,UAAU,EAAE,CAAC;YACxC,iDAAiD;YACjD,aAAa,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC;QAC1C,CAAC;aAAM,IAAI,aAAa,IAAI,eAAe,EAAE,CAAC;YAC5C,UAAU,CAAC,+BAA+B,aAAa,GAAG,CAAC,CAAC;YAC5D,uEAAuE;YACvE,iBAAiB;YACjB,MAAM,WAAW,GAAI,eAA2C,CAC9D,aAAa,CACd,CAAC;YACF,aAAa,CAAC,aAAa,CAAC,GAAG,WAAW,CAAC;QAC7C,CAAC;aAAM,CAAC;YACN,uEAAuE;YACvE,oCAAoC;YACpC,MAAM,SAAS,CAAC,QAAQ,CAAC,uBAAuB,aAAa,IAAI,CAAC,CAAC;QACrE,CAAC;QACD,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,CAAC;IACtC,CAAC,EACD;QACE,aAAa,EAAE,EAAE,IAAI,EAAE;QACvB,SAAS,EAAE,EAAE;KACd,CACF,CAAC;IAEF,MAAM,QAAQ,GAAG,KAAK,IAAI,EAAE;QAC1B,MAAM,OAAO,CAAC,GAAG,CACf,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,gBAAgB,EAAE,EAAE,CAAC,gBAAgB,EAAE,CAAC,CAC/D,CAAC;IACJ,CAAC,CAAC;IACF,OAAO,EAAE,UAAU,EAAE,MAAM,CAAC,aAAa,EAAE,QAAQ,EAAE,CAAC;AACxD,CAAC","sourcesContent":["import type { StreamProvider } from '@metamask/providers';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { SnapsProvider } from '@metamask/snaps-sdk';\nimport { logWarning } from '@metamask/snaps-utils';\nimport { hasProperty } from '@metamask/utils';\n\nimport type { NotifyFunction } from '../BaseSnapExecutor';\nimport { rootRealmGlobal } from '../globalObject';\nimport type { EndowmentFactoryOptions } from './commonEndowmentFactory';\nimport buildCommonEndowments from './commonEndowmentFactory';\n\ntype EndowmentFactoryResult = {\n /**\n * A function that performs any necessary teardown when the snap becomes idle.\n *\n * NOTE:** The endowments are not reconstructed if the snap is re-invoked\n * before being terminated, so the teardown operation must not render the\n * endowments unusable; it should simply restore the endowments to their\n * original state.\n */\n teardownFunction?: () => Promise<void> | void;\n [key: string]: unknown;\n};\n\n/**\n * Retrieve consolidated endowment factories for common endowments.\n */\nconst registeredEndowments = buildCommonEndowments();\n\n/**\n * A map of endowment names to their factory functions. Some endowments share\n * the same factory function, but we only call each factory once for each snap.\n * See {@link createEndowments} for details.\n */\nconst endowmentFactories = registeredEndowments.reduce((factories, builder) => {\n builder.names.forEach((name) => {\n factories.set(name, builder.factory);\n });\n return factories;\n}, new Map<string, (options?: EndowmentFactoryOptions) => EndowmentFactoryResult>());\n\n/**\n * Gets the endowments for a particular Snap. Some endowments, like `setTimeout`\n * and `clearTimeout`, must be attenuated so that they can only affect behavior\n * within the Snap's own realm. Therefore, we use factory functions to create\n * such attenuated / modified endowments. Otherwise, the value that's on the\n * root realm global will be used.\n *\n * @param options - An options bag.\n * @param options.snap - The Snaps global API object.\n * @param options.ethereum - The Snap's EIP-1193 provider object.\n * @param options.snapId - The id of the snap that will use the created endowments.\n * @param options.endowments - The list of endowments to provide to the snap.\n * @param options.notify - A reference to the notify function of the snap executor.\n * @returns An object containing the Snap's endowments.\n */\nexport function createEndowments({\n snap,\n ethereum,\n snapId,\n endowments,\n notify,\n}: {\n snap: SnapsProvider;\n ethereum: StreamProvider;\n snapId: string;\n endowments: string[];\n notify: NotifyFunction;\n}): { endowments: Record<string, unknown>; teardown: () => Promise<void> } {\n const attenuatedEndowments: Record<string, unknown> = {};\n\n // TODO: All endowments should be hardened to prevent covert communication\n // channels. Hardening the returned objects breaks tests elsewhere in the\n // monorepo, so further research is needed.\n const result = endowments.reduce<{\n allEndowments: Record<string, unknown>;\n teardowns: (() => Promise<void> | void)[];\n }>(\n ({ allEndowments, teardowns }, endowmentName) => {\n // First, check if the endowment has a factory, and default to that.\n if (endowmentFactories.has(endowmentName)) {\n if (!hasProperty(attenuatedEndowments, endowmentName)) {\n // Call the endowment factory for the current endowment. If the factory\n // creates multiple endowments, they will all be assigned to the\n // `attenuatedEndowments` object, but will only be passed on to the snap\n // if explicitly listed among its endowment.\n // This may not have an actual use case, but, safety first.\n\n // We just confirmed that endowmentFactories has the specified key.\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n const { teardownFunction, ...endowment } = endowmentFactories.get(\n endowmentName,\n )!({ snapId, notify });\n Object.assign(attenuatedEndowments, endowment);\n if (teardownFunction) {\n teardowns.push(teardownFunction);\n }\n }\n allEndowments[endowmentName] = attenuatedEndowments[endowmentName];\n } else if (endowmentName === 'ethereum') {\n // Special case for adding the EIP-1193 provider.\n allEndowments[endowmentName] = ethereum;\n } else if (endowmentName in rootRealmGlobal) {\n logWarning(`Access to unhardened global ${endowmentName}.`);\n // If the endowment doesn't have a factory, just use whatever is on the\n // global object.\n const globalValue = (rootRealmGlobal as Record<string, unknown>)[\n endowmentName\n ];\n allEndowments[endowmentName] = globalValue;\n } else {\n // If we get to this point, we've been passed an endowment that doesn't\n // exist in our current environment.\n throw rpcErrors.internal(`Unknown endowment: \"${endowmentName}\".`);\n }\n return { allEndowments, teardowns };\n },\n {\n allEndowments: { snap },\n teardowns: [],\n },\n );\n\n const teardown = async () => {\n await Promise.all(\n result.teardowns.map((teardownFunction) => teardownFunction()),\n );\n };\n return { endowments: result.allEndowments, teardown };\n}\n"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
4
|
+
const MINIMUM_INTERVAL = 10;
|
|
5
|
+
/**
|
|
6
|
+
* Creates a pair of `setInterval` and `clearInterval` functions attenuated such
|
|
7
|
+
* that:
|
|
8
|
+
* - `setInterval` throws if its "handler" parameter is not a function.
|
|
9
|
+
* - `clearInterval` only clears timeouts created by its sibling `setInterval`,
|
|
10
|
+
* or else no-ops.
|
|
11
|
+
*
|
|
12
|
+
* @returns An object with the attenuated `setInterval` and `clearInterval`
|
|
13
|
+
* functions.
|
|
14
|
+
*/
|
|
15
|
+
const createInterval = () => {
|
|
16
|
+
const registeredHandles = new Map();
|
|
17
|
+
const _setInterval = (handler, timeout, ...args) => {
|
|
18
|
+
if (typeof handler !== 'function') {
|
|
19
|
+
throw rpc_errors_1.rpcErrors.invalidInput(`The interval handler must be a function. Received: ${typeof handler}.`);
|
|
20
|
+
}
|
|
21
|
+
harden(handler);
|
|
22
|
+
const handle = Object.freeze(Object.create(null));
|
|
23
|
+
const platformHandle = setInterval(handler, Math.max(MINIMUM_INTERVAL, timeout ?? 0), ...args);
|
|
24
|
+
registeredHandles.set(handle, platformHandle);
|
|
25
|
+
return handle;
|
|
26
|
+
};
|
|
27
|
+
const _clearInterval = (handle) => {
|
|
28
|
+
harden(handle);
|
|
29
|
+
const platformHandle = registeredHandles.get(handle);
|
|
30
|
+
if (platformHandle !== undefined) {
|
|
31
|
+
clearInterval(platformHandle);
|
|
32
|
+
registeredHandles.delete(handle);
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
const teardownFunction = () => {
|
|
36
|
+
for (const handle of registeredHandles.keys()) {
|
|
37
|
+
_clearInterval(handle);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
return {
|
|
41
|
+
setInterval: harden(_setInterval),
|
|
42
|
+
clearInterval: harden(_clearInterval),
|
|
43
|
+
teardownFunction,
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
const endowmentModule = {
|
|
47
|
+
names: ['setInterval', 'clearInterval'],
|
|
48
|
+
factory: createInterval,
|
|
49
|
+
};
|
|
50
|
+
exports.default = endowmentModule;
|
|
51
|
+
//# sourceMappingURL=interval.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interval.cjs","sourceRoot":"","sources":["../../../src/common/endowments/interval.ts"],"names":[],"mappings":";;AAAA,qDAAiD;AAEjD,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B;;;;;;;;;GASG;AACH,MAAM,cAAc,GAAG,GAAG,EAAE;IAC1B,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAoB,CAAC;IAEtD,MAAM,YAAY,GAAG,CACnB,OAAqB,EACrB,OAAgB,EAChB,GAAG,IAAW,EACL,EAAE;QACX,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;YAClC,MAAM,sBAAS,CAAC,YAAY,CAC1B,sDAAsD,OAAO,OAAO,GAAG,CACxE,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,OAAO,CAAC,CAAC;QAChB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAClD,MAAM,cAAc,GAAG,WAAW,CAChC,OAAO,EACP,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,OAAO,IAAI,CAAC,CAAC,EACxC,GAAG,IAAI,CACR,CAAC;QACF,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;QAC9C,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,MAAM,cAAc,GAAG,CAAC,MAAe,EAAQ,EAAE;QAC/C,MAAM,CAAC,MAAM,CAAC,CAAC;QACf,MAAM,cAAc,GAAG,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACrD,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;YACjC,aAAa,CAAC,cAAqB,CAAC,CAAC;YACrC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,gBAAgB,GAAG,GAAS,EAAE;QAClC,KAAK,MAAM,MAAM,IAAI,iBAAiB,CAAC,IAAI,EAAE,EAAE,CAAC;YAC9C,cAAc,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,YAAY,CAAC;QACjC,aAAa,EAAE,MAAM,CAAC,cAAc,CAAC;QACrC,gBAAgB;KACR,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,aAAa,EAAE,eAAe,CAAU;IAChD,OAAO,EAAE,cAAc;CACxB,CAAC;AACF,kBAAe,eAAe,CAAC","sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\n\nconst MINIMUM_INTERVAL = 10;\n\n/**\n * Creates a pair of `setInterval` and `clearInterval` functions attenuated such\n * that:\n * - `setInterval` throws if its \"handler\" parameter is not a function.\n * - `clearInterval` only clears timeouts created by its sibling `setInterval`,\n * or else no-ops.\n *\n * @returns An object with the attenuated `setInterval` and `clearInterval`\n * functions.\n */\nconst createInterval = () => {\n const registeredHandles = new Map<unknown, unknown>();\n\n const _setInterval = (\n handler: TimerHandler,\n timeout?: number,\n ...args: any[]\n ): unknown => {\n if (typeof handler !== 'function') {\n throw rpcErrors.invalidInput(\n `The interval handler must be a function. Received: ${typeof handler}.`,\n );\n }\n harden(handler);\n const handle = Object.freeze(Object.create(null));\n const platformHandle = setInterval(\n handler,\n Math.max(MINIMUM_INTERVAL, timeout ?? 0),\n ...args,\n );\n registeredHandles.set(handle, platformHandle);\n return handle;\n };\n\n const _clearInterval = (handle: unknown): void => {\n harden(handle);\n const platformHandle = registeredHandles.get(handle);\n if (platformHandle !== undefined) {\n clearInterval(platformHandle as any);\n registeredHandles.delete(handle);\n }\n };\n\n const teardownFunction = (): void => {\n for (const handle of registeredHandles.keys()) {\n _clearInterval(handle);\n }\n };\n\n return {\n setInterval: harden(_setInterval),\n clearInterval: harden(_clearInterval),\n teardownFunction,\n } as const;\n};\n\nconst endowmentModule = {\n names: ['setInterval', 'clearInterval'] as const,\n factory: createInterval,\n};\nexport default endowmentModule;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interval.d.cts","sourceRoot":"","sources":["../../../src/common/endowments/interval.ts"],"names":[],"mappings":"AA4DA,QAAA,MAAM,eAAe;;;wCA1CR,YAAY,YACX,MAAM,WACP,GAAG,EAAE,KACb,OAAO;yCAiBsB,OAAO,KAAG,IAAI;yCASjB,IAAI;;CAgBlC,CAAC;AACF,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare const endowmentModule: {
|
|
2
|
+
names: readonly ["setInterval", "clearInterval"];
|
|
3
|
+
factory: () => {
|
|
4
|
+
readonly setInterval: (handler: TimerHandler, timeout?: number, ...args: any[]) => unknown;
|
|
5
|
+
readonly clearInterval: (handle: unknown) => void;
|
|
6
|
+
readonly teardownFunction: () => void;
|
|
7
|
+
};
|
|
8
|
+
};
|
|
9
|
+
export default endowmentModule;
|
|
10
|
+
//# sourceMappingURL=interval.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"interval.d.mts","sourceRoot":"","sources":["../../../src/common/endowments/interval.ts"],"names":[],"mappings":"AA4DA,QAAA,MAAM,eAAe;;;wCA1CR,YAAY,YACX,MAAM,WACP,GAAG,EAAE,KACb,OAAO;yCAiBsB,OAAO,KAAG,IAAI;yCASjB,IAAI;;CAgBlC,CAAC;AACF,eAAe,eAAe,CAAC"}
|
|
@@ -1,8 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import { rpcErrors } from "@metamask/rpc-errors";
|
|
2
|
+
const MINIMUM_INTERVAL = 10;
|
|
3
|
+
/**
|
|
4
|
+
* Creates a pair of `setInterval` and `clearInterval` functions attenuated such
|
|
5
|
+
* that:
|
|
6
|
+
* - `setInterval` throws if its "handler" parameter is not a function.
|
|
7
|
+
* - `clearInterval` only clears timeouts created by its sibling `setInterval`,
|
|
8
|
+
* or else no-ops.
|
|
9
|
+
*
|
|
10
|
+
* @returns An object with the attenuated `setInterval` and `clearInterval`
|
|
11
|
+
* functions.
|
|
12
|
+
*/
|
|
13
|
+
const createInterval = () => {
|
|
14
|
+
const registeredHandles = new Map();
|
|
15
|
+
const _setInterval = (handler, timeout, ...args) => {
|
|
16
|
+
if (typeof handler !== 'function') {
|
|
17
|
+
throw rpcErrors.invalidInput(`The interval handler must be a function. Received: ${typeof handler}.`);
|
|
18
|
+
}
|
|
19
|
+
harden(handler);
|
|
20
|
+
const handle = Object.freeze(Object.create(null));
|
|
21
|
+
const platformHandle = setInterval(handler, Math.max(MINIMUM_INTERVAL, timeout ?? 0), ...args);
|
|
22
|
+
registeredHandles.set(handle, platformHandle);
|
|
23
|
+
return handle;
|
|
24
|
+
};
|
|
25
|
+
const _clearInterval = (handle) => {
|
|
26
|
+
harden(handle);
|
|
27
|
+
const platformHandle = registeredHandles.get(handle);
|
|
28
|
+
if (platformHandle !== undefined) {
|
|
29
|
+
clearInterval(platformHandle);
|
|
30
|
+
registeredHandles.delete(handle);
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
const teardownFunction = () => {
|
|
34
|
+
for (const handle of registeredHandles.keys()) {
|
|
35
|
+
_clearInterval(handle);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
setInterval: harden(_setInterval),
|
|
40
|
+
clearInterval: harden(_clearInterval),
|
|
41
|
+
teardownFunction,
|
|
42
|
+
};
|
|
7
43
|
};
|
|
44
|
+
const endowmentModule = {
|
|
45
|
+
names: ['setInterval', 'clearInterval'],
|
|
46
|
+
factory: createInterval,
|
|
47
|
+
};
|
|
48
|
+
export default endowmentModule;
|
|
8
49
|
//# sourceMappingURL=interval.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"interval.mjs","sourceRoot":"","sources":["../../../src/common/endowments/interval.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAEjD,MAAM,gBAAgB,GAAG,EAAE,CAAC;AAE5B;;;;;;;;;GASG;AACH,MAAM,cAAc,GAAG,GAAG,EAAE;IAC1B,MAAM,iBAAiB,GAAG,IAAI,GAAG,EAAoB,CAAC;IAEtD,MAAM,YAAY,GAAG,CACnB,OAAqB,EACrB,OAAgB,EAChB,GAAG,IAAW,EACL,EAAE;QACX,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;YAClC,MAAM,SAAS,CAAC,YAAY,CAC1B,sDAAsD,OAAO,OAAO,GAAG,CACxE,CAAC;QACJ,CAAC;QACD,MAAM,CAAC,OAAO,CAAC,CAAC;QAChB,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAClD,MAAM,cAAc,GAAG,WAAW,CAChC,OAAO,EACP,IAAI,CAAC,GAAG,CAAC,gBAAgB,EAAE,OAAO,IAAI,CAAC,CAAC,EACxC,GAAG,IAAI,CACR,CAAC;QACF,iBAAiB,CAAC,GAAG,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;QAC9C,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;IAEF,MAAM,cAAc,GAAG,CAAC,MAAe,EAAQ,EAAE;QAC/C,MAAM,CAAC,MAAM,CAAC,CAAC;QACf,MAAM,cAAc,GAAG,iBAAiB,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;QACrD,IAAI,cAAc,KAAK,SAAS,EAAE,CAAC;YACjC,aAAa,CAAC,cAAqB,CAAC,CAAC;YACrC,iBAAiB,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;QACnC,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,gBAAgB,GAAG,GAAS,EAAE;QAClC,KAAK,MAAM,MAAM,IAAI,iBAAiB,CAAC,IAAI,EAAE,EAAE,CAAC;YAC9C,cAAc,CAAC,MAAM,CAAC,CAAC;QACzB,CAAC;IACH,CAAC,CAAC;IAEF,OAAO;QACL,WAAW,EAAE,MAAM,CAAC,YAAY,CAAC;QACjC,aAAa,EAAE,MAAM,CAAC,cAAc,CAAC;QACrC,gBAAgB;KACR,CAAC;AACb,CAAC,CAAC;AAEF,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,aAAa,EAAE,eAAe,CAAU;IAChD,OAAO,EAAE,cAAc;CACxB,CAAC;AACF,eAAe,eAAe,CAAC","sourcesContent":["import { rpcErrors } from '@metamask/rpc-errors';\n\nconst MINIMUM_INTERVAL = 10;\n\n/**\n * Creates a pair of `setInterval` and `clearInterval` functions attenuated such\n * that:\n * - `setInterval` throws if its \"handler\" parameter is not a function.\n * - `clearInterval` only clears timeouts created by its sibling `setInterval`,\n * or else no-ops.\n *\n * @returns An object with the attenuated `setInterval` and `clearInterval`\n * functions.\n */\nconst createInterval = () => {\n const registeredHandles = new Map<unknown, unknown>();\n\n const _setInterval = (\n handler: TimerHandler,\n timeout?: number,\n ...args: any[]\n ): unknown => {\n if (typeof handler !== 'function') {\n throw rpcErrors.invalidInput(\n `The interval handler must be a function. Received: ${typeof handler}.`,\n );\n }\n harden(handler);\n const handle = Object.freeze(Object.create(null));\n const platformHandle = setInterval(\n handler,\n Math.max(MINIMUM_INTERVAL, timeout ?? 0),\n ...args,\n );\n registeredHandles.set(handle, platformHandle);\n return handle;\n };\n\n const _clearInterval = (handle: unknown): void => {\n harden(handle);\n const platformHandle = registeredHandles.get(handle);\n if (platformHandle !== undefined) {\n clearInterval(platformHandle as any);\n registeredHandles.delete(handle);\n }\n };\n\n const teardownFunction = (): void => {\n for (const handle of registeredHandles.keys()) {\n _clearInterval(handle);\n }\n };\n\n return {\n setInterval: harden(_setInterval),\n clearInterval: harden(_clearInterval),\n teardownFunction,\n } as const;\n};\n\nconst endowmentModule = {\n names: ['setInterval', 'clearInterval'] as const,\n factory: createInterval,\n};\nexport default endowmentModule;\n"]}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const globalObject_1 = require("../globalObject.cjs");
|
|
4
|
+
const crypto_1 = require("./crypto.cjs");
|
|
5
|
+
/**
|
|
6
|
+
* Create a {@link Math} object, with the same properties as the global
|
|
7
|
+
* {@link Math} object, but with the {@link Math.random} method replaced.
|
|
8
|
+
*
|
|
9
|
+
* @returns The {@link Math} object with the {@link Math.random} method
|
|
10
|
+
* replaced.
|
|
11
|
+
*/
|
|
12
|
+
function createMath() {
|
|
13
|
+
// `Math` does not work with `Object.keys`, `Object.entries`, etc., so we
|
|
14
|
+
// need to create a new object with the same properties.
|
|
15
|
+
const keys = Object.getOwnPropertyNames(globalObject_1.rootRealmGlobal.Math);
|
|
16
|
+
const math = keys.reduce((target, key) => {
|
|
17
|
+
if (key === 'random') {
|
|
18
|
+
return target;
|
|
19
|
+
}
|
|
20
|
+
return { ...target, [key]: globalObject_1.rootRealmGlobal.Math[key] };
|
|
21
|
+
}, {});
|
|
22
|
+
// Since the math endowment requires crypto, we can leverage the crypto endowment factory to get a hardened and platform agnostic instance of webcrypto
|
|
23
|
+
const { crypto: hardenedCrypto } = (0, crypto_1.createCrypto)();
|
|
24
|
+
return harden({
|
|
25
|
+
Math: {
|
|
26
|
+
...math,
|
|
27
|
+
random: () => {
|
|
28
|
+
// NOTE: This is not intended to be a secure replacement for the weak
|
|
29
|
+
// random number generator used by `Math.random`. It is only intended to
|
|
30
|
+
// prevent side channel attacks of `Math.random` by replacing it with an
|
|
31
|
+
// alternative implementation that is not vulnerable to the same
|
|
32
|
+
// attacks.
|
|
33
|
+
//
|
|
34
|
+
// This does not mean that this implementation is secure. It is not
|
|
35
|
+
// intended to be used in a security context, and this implementation
|
|
36
|
+
// may change at any time.
|
|
37
|
+
//
|
|
38
|
+
// To securely generate random numbers, use a cryptographically secure
|
|
39
|
+
// random number generator, such as the one provided by the Web Crypto
|
|
40
|
+
// API:
|
|
41
|
+
//
|
|
42
|
+
// - https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey
|
|
43
|
+
// - https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
|
|
44
|
+
return hardenedCrypto.getRandomValues(new Uint32Array(1))[0] / 2 ** 32;
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
const endowmentModule = {
|
|
50
|
+
names: ['Math'],
|
|
51
|
+
factory: createMath,
|
|
52
|
+
};
|
|
53
|
+
exports.default = endowmentModule;
|
|
54
|
+
//# sourceMappingURL=math.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.cjs","sourceRoot":"","sources":["../../../src/common/endowments/math.ts"],"names":[],"mappings":";;AAAA,sDAAkD;AAClD,yCAAwC;AAExC;;;;;;GAMG;AACH,SAAS,UAAU;IACjB,yEAAyE;IACzE,wDAAwD;IACxD,MAAM,IAAI,GAAG,MAAM,CAAC,mBAAmB,CACrC,8BAAe,CAAC,IAAI,CACI,CAAC;IAE3B,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QACtD,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;YACrB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,8BAAe,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACzD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,uJAAuJ;IACvJ,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,IAAA,qBAAY,GAAE,CAAC;IAElD,OAAO,MAAM,CAAC;QACZ,IAAI,EAAE;YACJ,GAAG,IAAI;YACP,MAAM,EAAE,GAAG,EAAE;gBACX,qEAAqE;gBACrE,wEAAwE;gBACxE,wEAAwE;gBACxE,gEAAgE;gBAChE,WAAW;gBACX,EAAE;gBACF,mEAAmE;gBACnE,qEAAqE;gBACrE,0BAA0B;gBAC1B,EAAE;gBACF,sEAAsE;gBACtE,sEAAsE;gBACtE,OAAO;gBACP,EAAE;gBACF,8EAA8E;gBAC9E,4EAA4E;gBAC5E,OAAO,cAAc,CAAC,eAAe,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YACzE,CAAC;SACF;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,MAAM,CAAU;IACxB,OAAO,EAAE,UAAU;CACpB,CAAC;AAEF,kBAAe,eAAe,CAAC","sourcesContent":["import { rootRealmGlobal } from '../globalObject';\nimport { createCrypto } from './crypto';\n\n/**\n * Create a {@link Math} object, with the same properties as the global\n * {@link Math} object, but with the {@link Math.random} method replaced.\n *\n * @returns The {@link Math} object with the {@link Math.random} method\n * replaced.\n */\nfunction createMath() {\n // `Math` does not work with `Object.keys`, `Object.entries`, etc., so we\n // need to create a new object with the same properties.\n const keys = Object.getOwnPropertyNames(\n rootRealmGlobal.Math,\n ) as (keyof typeof Math)[];\n\n const math = keys.reduce<Partial<Math>>((target, key) => {\n if (key === 'random') {\n return target;\n }\n\n return { ...target, [key]: rootRealmGlobal.Math[key] };\n }, {});\n\n // Since the math endowment requires crypto, we can leverage the crypto endowment factory to get a hardened and platform agnostic instance of webcrypto\n const { crypto: hardenedCrypto } = createCrypto();\n\n return harden({\n Math: {\n ...math,\n random: () => {\n // NOTE: This is not intended to be a secure replacement for the weak\n // random number generator used by `Math.random`. It is only intended to\n // prevent side channel attacks of `Math.random` by replacing it with an\n // alternative implementation that is not vulnerable to the same\n // attacks.\n //\n // This does not mean that this implementation is secure. It is not\n // intended to be used in a security context, and this implementation\n // may change at any time.\n //\n // To securely generate random numbers, use a cryptographically secure\n // random number generator, such as the one provided by the Web Crypto\n // API:\n //\n // - https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey\n // - https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues\n return hardenedCrypto.getRandomValues(new Uint32Array(1))[0] / 2 ** 32;\n },\n },\n });\n}\n\nconst endowmentModule = {\n names: ['Math'] as const,\n factory: createMath,\n};\n\nexport default endowmentModule;\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.cts","sourceRoot":"","sources":["../../../src/common/endowments/math.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,iBAAS,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0ClB;AAED,QAAA,MAAM,eAAe;;;CAGpB,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a {@link Math} object, with the same properties as the global
|
|
3
|
+
* {@link Math} object, but with the {@link Math.random} method replaced.
|
|
4
|
+
*
|
|
5
|
+
* @returns The {@link Math} object with the {@link Math.random} method
|
|
6
|
+
* replaced.
|
|
7
|
+
*/
|
|
8
|
+
declare function createMath(): {
|
|
9
|
+
Math: {
|
|
10
|
+
random: () => number;
|
|
11
|
+
E?: number | undefined;
|
|
12
|
+
LN10?: number | undefined;
|
|
13
|
+
LN2?: number | undefined;
|
|
14
|
+
LOG2E?: number | undefined;
|
|
15
|
+
LOG10E?: number | undefined;
|
|
16
|
+
PI?: number | undefined;
|
|
17
|
+
SQRT1_2?: number | undefined;
|
|
18
|
+
SQRT2?: number | undefined;
|
|
19
|
+
abs?: ((x: number) => number) | undefined;
|
|
20
|
+
acos?: ((x: number) => number) | undefined;
|
|
21
|
+
asin?: ((x: number) => number) | undefined;
|
|
22
|
+
atan?: ((x: number) => number) | undefined;
|
|
23
|
+
atan2?: ((y: number, x: number) => number) | undefined;
|
|
24
|
+
ceil?: ((x: number) => number) | undefined;
|
|
25
|
+
cos?: ((x: number) => number) | undefined;
|
|
26
|
+
exp?: ((x: number) => number) | undefined;
|
|
27
|
+
floor?: ((x: number) => number) | undefined;
|
|
28
|
+
log?: ((x: number) => number) | undefined;
|
|
29
|
+
max?: ((...values: number[]) => number) | undefined;
|
|
30
|
+
min?: ((...values: number[]) => number) | undefined;
|
|
31
|
+
pow?: ((x: number, y: number) => number) | undefined;
|
|
32
|
+
round?: ((x: number) => number) | undefined;
|
|
33
|
+
sin?: ((x: number) => number) | undefined;
|
|
34
|
+
sqrt?: ((x: number) => number) | undefined;
|
|
35
|
+
tan?: ((x: number) => number) | undefined;
|
|
36
|
+
clz32?: ((x: number) => number) | undefined;
|
|
37
|
+
imul?: ((x: number, y: number) => number) | undefined;
|
|
38
|
+
sign?: ((x: number) => number) | undefined;
|
|
39
|
+
log10?: ((x: number) => number) | undefined;
|
|
40
|
+
log2?: ((x: number) => number) | undefined;
|
|
41
|
+
log1p?: ((x: number) => number) | undefined;
|
|
42
|
+
expm1?: ((x: number) => number) | undefined;
|
|
43
|
+
cosh?: ((x: number) => number) | undefined;
|
|
44
|
+
sinh?: ((x: number) => number) | undefined;
|
|
45
|
+
tanh?: ((x: number) => number) | undefined;
|
|
46
|
+
acosh?: ((x: number) => number) | undefined;
|
|
47
|
+
asinh?: ((x: number) => number) | undefined;
|
|
48
|
+
atanh?: ((x: number) => number) | undefined;
|
|
49
|
+
hypot?: ((...values: number[]) => number) | undefined;
|
|
50
|
+
trunc?: ((x: number) => number) | undefined;
|
|
51
|
+
fround?: ((x: number) => number) | undefined;
|
|
52
|
+
cbrt?: ((x: number) => number) | undefined;
|
|
53
|
+
[Symbol.toStringTag]?: string | undefined;
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
declare const endowmentModule: {
|
|
57
|
+
names: readonly ["Math"];
|
|
58
|
+
factory: typeof createMath;
|
|
59
|
+
};
|
|
60
|
+
export default endowmentModule;
|
|
61
|
+
//# sourceMappingURL=math.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math.d.mts","sourceRoot":"","sources":["../../../src/common/endowments/math.ts"],"names":[],"mappings":"AAGA;;;;;;GAMG;AACH,iBAAS,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA0ClB;AAED,QAAA,MAAM,eAAe;;;CAGpB,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
|
@@ -1,10 +1,52 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { rootRealmGlobal } from "../globalObject.mjs";
|
|
2
|
+
import { createCrypto } from "./crypto.mjs";
|
|
3
|
+
/**
|
|
4
|
+
* Create a {@link Math} object, with the same properties as the global
|
|
5
|
+
* {@link Math} object, but with the {@link Math.random} method replaced.
|
|
6
|
+
*
|
|
7
|
+
* @returns The {@link Math} object with the {@link Math.random} method
|
|
8
|
+
* replaced.
|
|
9
|
+
*/
|
|
10
|
+
function createMath() {
|
|
11
|
+
// `Math` does not work with `Object.keys`, `Object.entries`, etc., so we
|
|
12
|
+
// need to create a new object with the same properties.
|
|
13
|
+
const keys = Object.getOwnPropertyNames(rootRealmGlobal.Math);
|
|
14
|
+
const math = keys.reduce((target, key) => {
|
|
15
|
+
if (key === 'random') {
|
|
16
|
+
return target;
|
|
17
|
+
}
|
|
18
|
+
return { ...target, [key]: rootRealmGlobal.Math[key] };
|
|
19
|
+
}, {});
|
|
20
|
+
// Since the math endowment requires crypto, we can leverage the crypto endowment factory to get a hardened and platform agnostic instance of webcrypto
|
|
21
|
+
const { crypto: hardenedCrypto } = createCrypto();
|
|
22
|
+
return harden({
|
|
23
|
+
Math: {
|
|
24
|
+
...math,
|
|
25
|
+
random: () => {
|
|
26
|
+
// NOTE: This is not intended to be a secure replacement for the weak
|
|
27
|
+
// random number generator used by `Math.random`. It is only intended to
|
|
28
|
+
// prevent side channel attacks of `Math.random` by replacing it with an
|
|
29
|
+
// alternative implementation that is not vulnerable to the same
|
|
30
|
+
// attacks.
|
|
31
|
+
//
|
|
32
|
+
// This does not mean that this implementation is secure. It is not
|
|
33
|
+
// intended to be used in a security context, and this implementation
|
|
34
|
+
// may change at any time.
|
|
35
|
+
//
|
|
36
|
+
// To securely generate random numbers, use a cryptographically secure
|
|
37
|
+
// random number generator, such as the one provided by the Web Crypto
|
|
38
|
+
// API:
|
|
39
|
+
//
|
|
40
|
+
// - https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey
|
|
41
|
+
// - https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues
|
|
42
|
+
return hardenedCrypto.getRandomValues(new Uint32Array(1))[0] / 2 ** 32;
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
const endowmentModule = {
|
|
48
|
+
names: ['Math'],
|
|
49
|
+
factory: createMath,
|
|
9
50
|
};
|
|
51
|
+
export default endowmentModule;
|
|
10
52
|
//# sourceMappingURL=math.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":[],"
|
|
1
|
+
{"version":3,"file":"math.mjs","sourceRoot":"","sources":["../../../src/common/endowments/math.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,4BAAwB;AAClD,OAAO,EAAE,YAAY,EAAE,qBAAiB;AAExC;;;;;;GAMG;AACH,SAAS,UAAU;IACjB,yEAAyE;IACzE,wDAAwD;IACxD,MAAM,IAAI,GAAG,MAAM,CAAC,mBAAmB,CACrC,eAAe,CAAC,IAAI,CACI,CAAC;IAE3B,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAgB,CAAC,MAAM,EAAE,GAAG,EAAE,EAAE;QACtD,IAAI,GAAG,KAAK,QAAQ,EAAE,CAAC;YACrB,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,OAAO,EAAE,GAAG,MAAM,EAAE,CAAC,GAAG,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC;IACzD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,uJAAuJ;IACvJ,MAAM,EAAE,MAAM,EAAE,cAAc,EAAE,GAAG,YAAY,EAAE,CAAC;IAElD,OAAO,MAAM,CAAC;QACZ,IAAI,EAAE;YACJ,GAAG,IAAI;YACP,MAAM,EAAE,GAAG,EAAE;gBACX,qEAAqE;gBACrE,wEAAwE;gBACxE,wEAAwE;gBACxE,gEAAgE;gBAChE,WAAW;gBACX,EAAE;gBACF,mEAAmE;gBACnE,qEAAqE;gBACrE,0BAA0B;gBAC1B,EAAE;gBACF,sEAAsE;gBACtE,sEAAsE;gBACtE,OAAO;gBACP,EAAE;gBACF,8EAA8E;gBAC9E,4EAA4E;gBAC5E,OAAO,cAAc,CAAC,eAAe,CAAC,IAAI,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YACzE,CAAC;SACF;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,eAAe,GAAG;IACtB,KAAK,EAAE,CAAC,MAAM,CAAU;IACxB,OAAO,EAAE,UAAU;CACpB,CAAC;AAEF,eAAe,eAAe,CAAC","sourcesContent":["import { rootRealmGlobal } from '../globalObject';\nimport { createCrypto } from './crypto';\n\n/**\n * Create a {@link Math} object, with the same properties as the global\n * {@link Math} object, but with the {@link Math.random} method replaced.\n *\n * @returns The {@link Math} object with the {@link Math.random} method\n * replaced.\n */\nfunction createMath() {\n // `Math` does not work with `Object.keys`, `Object.entries`, etc., so we\n // need to create a new object with the same properties.\n const keys = Object.getOwnPropertyNames(\n rootRealmGlobal.Math,\n ) as (keyof typeof Math)[];\n\n const math = keys.reduce<Partial<Math>>((target, key) => {\n if (key === 'random') {\n return target;\n }\n\n return { ...target, [key]: rootRealmGlobal.Math[key] };\n }, {});\n\n // Since the math endowment requires crypto, we can leverage the crypto endowment factory to get a hardened and platform agnostic instance of webcrypto\n const { crypto: hardenedCrypto } = createCrypto();\n\n return harden({\n Math: {\n ...math,\n random: () => {\n // NOTE: This is not intended to be a secure replacement for the weak\n // random number generator used by `Math.random`. It is only intended to\n // prevent side channel attacks of `Math.random` by replacing it with an\n // alternative implementation that is not vulnerable to the same\n // attacks.\n //\n // This does not mean that this implementation is secure. It is not\n // intended to be used in a security context, and this implementation\n // may change at any time.\n //\n // To securely generate random numbers, use a cryptographically secure\n // random number generator, such as the one provided by the Web Crypto\n // API:\n //\n // - https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey\n // - https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues\n return hardenedCrypto.getRandomValues(new Uint32Array(1))[0] / 2 ** 32;\n },\n },\n });\n}\n\nconst endowmentModule = {\n names: ['Math'] as const,\n factory: createMath,\n};\n\nexport default endowmentModule;\n"]}
|