@metamask/snaps-controllers 8.1.0 → 8.2.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 +17 -1
- package/dist/{chunk-TO6ZEBIA.mjs → chunk-3A72M4GC.mjs} +2 -2
- package/dist/{chunk-ZVGZG25U.js → chunk-3AANDIXT.js} +3 -3
- package/dist/{chunk-X5MFC3VX.mjs → chunk-3OJFF5CK.mjs} +2 -2
- package/dist/{chunk-GTDDODNP.mjs → chunk-567BFPSL.mjs} +9 -2
- package/dist/chunk-567BFPSL.mjs.map +1 -0
- package/dist/{chunk-RS3WN6D3.mjs → chunk-7IJQGFT5.mjs} +2 -2
- package/dist/{chunk-U4DZUKNN.js → chunk-7TYZZFHZ.js} +16 -3
- package/dist/chunk-7TYZZFHZ.js.map +1 -0
- package/dist/{chunk-4DPX4O3T.js → chunk-CDTGUNSA.js} +9 -2
- package/dist/chunk-CDTGUNSA.js.map +1 -0
- package/dist/{chunk-74GN6MIJ.js → chunk-FPGAQ6MT.js} +3 -3
- package/dist/{chunk-Y7ZOSPEN.js → chunk-HK4OAMJT.js} +3 -3
- package/dist/{chunk-E5RRFMGF.js → chunk-HQ6HMINL.js} +3 -3
- package/dist/{chunk-FCRPOA4I.js → chunk-KH72WRHR.js} +3 -3
- package/dist/{chunk-QLEQIXCE.mjs → chunk-LRVK45HN.mjs} +2 -2
- package/dist/{chunk-2UAU42DO.js → chunk-PIQFC66N.js} +12 -8
- package/dist/chunk-PIQFC66N.js.map +1 -0
- package/dist/{chunk-PXKCSAT6.mjs → chunk-PMZXFAQI.mjs} +2 -2
- package/dist/{chunk-FCCGRGQS.mjs → chunk-QLFH3MC6.mjs} +2 -2
- package/dist/{chunk-QP5LV734.mjs → chunk-QLWR3M4Q.mjs} +9 -5
- package/dist/chunk-QLWR3M4Q.mjs.map +1 -0
- package/dist/{chunk-G4S6UXQ2.js → chunk-RW7AYHRG.js} +3 -3
- package/dist/{chunk-IPYO7FKR.mjs → chunk-RXZGXJOS.mjs} +48 -9
- package/dist/chunk-RXZGXJOS.mjs.map +1 -0
- package/dist/{chunk-SIW7ZXQF.js → chunk-S775IABY.js} +10 -10
- package/dist/{chunk-P5MRZOGW.mjs → chunk-SAAURQ5A.mjs} +2 -2
- package/dist/{chunk-YP37KUG5.js → chunk-TEBNQ3AE.js} +56 -17
- package/dist/chunk-TEBNQ3AE.js.map +1 -0
- package/dist/{chunk-ZQNBP53T.mjs → chunk-UJJCRV7W.mjs} +16 -3
- package/dist/chunk-UJJCRV7W.mjs.map +1 -0
- package/dist/{chunk-3Y4IJKZY.mjs → chunk-YUWYMNIX.mjs} +2 -2
- package/dist/{chunk-PAFO2KIN.js → chunk-ZRC46TUF.js} +3 -3
- package/dist/cronjob/CronjobController.js +9 -9
- package/dist/cronjob/CronjobController.mjs +9 -9
- package/dist/cronjob/index.js +9 -9
- package/dist/cronjob/index.mjs +9 -9
- package/dist/index.js +12 -10
- package/dist/index.mjs +11 -9
- package/dist/interface/SnapInterfaceController.js +3 -3
- package/dist/interface/SnapInterfaceController.mjs +2 -2
- package/dist/interface/index.js +3 -3
- package/dist/interface/index.mjs +2 -2
- package/dist/interface/utils.js +4 -2
- package/dist/interface/utils.mjs +5 -3
- package/dist/node.js +14 -12
- package/dist/node.mjs +13 -11
- package/dist/react-native.js +13 -11
- package/dist/react-native.mjs +12 -10
- package/dist/services/AbstractExecutionService.js +3 -3
- package/dist/services/AbstractExecutionService.mjs +2 -2
- package/dist/services/browser.js +8 -8
- package/dist/services/browser.mjs +7 -7
- package/dist/services/iframe/IframeExecutionService.js +4 -4
- package/dist/services/iframe/IframeExecutionService.mjs +3 -3
- package/dist/services/iframe/index.js +4 -4
- package/dist/services/iframe/index.mjs +3 -3
- package/dist/services/index.js +7 -7
- package/dist/services/index.mjs +6 -6
- package/dist/services/node-js/NodeProcessExecutionService.js +8 -8
- package/dist/services/node-js/NodeProcessExecutionService.mjs +7 -7
- package/dist/services/node-js/NodeThreadExecutionService.js +8 -8
- package/dist/services/node-js/NodeThreadExecutionService.mjs +7 -7
- package/dist/services/node-js/index.js +9 -9
- package/dist/services/node-js/index.mjs +8 -8
- package/dist/services/node.js +9 -9
- package/dist/services/node.mjs +8 -8
- package/dist/services/offscreen/OffscreenExecutionService.js +5 -5
- package/dist/services/offscreen/OffscreenExecutionService.mjs +4 -4
- package/dist/services/offscreen/index.js +5 -5
- package/dist/services/offscreen/index.mjs +4 -4
- package/dist/services/proxy/ProxyExecutionService.js +4 -4
- package/dist/services/proxy/ProxyExecutionService.mjs +3 -3
- package/dist/services/react-native.js +8 -8
- package/dist/services/react-native.mjs +7 -7
- package/dist/services/webview/WebViewExecutionService.js +5 -5
- package/dist/services/webview/WebViewExecutionService.mjs +4 -4
- package/dist/services/webview/index.js +5 -5
- package/dist/services/webview/index.mjs +4 -4
- package/dist/services/webworker/WebWorkerExecutionService.js +4 -4
- package/dist/services/webworker/WebWorkerExecutionService.mjs +3 -3
- package/dist/services/webworker/index.js +4 -4
- package/dist/services/webworker/index.mjs +3 -3
- package/dist/snaps/SnapController.js +3 -3
- package/dist/snaps/SnapController.mjs +2 -2
- package/dist/snaps/index.js +3 -3
- package/dist/snaps/index.mjs +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/interface/SnapInterfaceController.d.ts +4 -2
- package/dist/types/interface/utils.d.ts +8 -1
- package/dist/types/snaps/SnapController.d.ts +11 -2
- package/dist/types/utils.d.ts +13 -0
- package/dist/utils.js +4 -2
- package/dist/utils.mjs +3 -1
- package/package.json +7 -7
- package/dist/chunk-2UAU42DO.js.map +0 -1
- package/dist/chunk-4DPX4O3T.js.map +0 -1
- package/dist/chunk-GTDDODNP.mjs.map +0 -1
- package/dist/chunk-IPYO7FKR.mjs.map +0 -1
- package/dist/chunk-QP5LV734.mjs.map +0 -1
- package/dist/chunk-U4DZUKNN.js.map +0 -1
- package/dist/chunk-YP37KUG5.js.map +0 -1
- package/dist/chunk-ZQNBP53T.mjs.map +0 -1
- /package/dist/{chunk-TO6ZEBIA.mjs.map → chunk-3A72M4GC.mjs.map} +0 -0
- /package/dist/{chunk-ZVGZG25U.js.map → chunk-3AANDIXT.js.map} +0 -0
- /package/dist/{chunk-X5MFC3VX.mjs.map → chunk-3OJFF5CK.mjs.map} +0 -0
- /package/dist/{chunk-RS3WN6D3.mjs.map → chunk-7IJQGFT5.mjs.map} +0 -0
- /package/dist/{chunk-74GN6MIJ.js.map → chunk-FPGAQ6MT.js.map} +0 -0
- /package/dist/{chunk-Y7ZOSPEN.js.map → chunk-HK4OAMJT.js.map} +0 -0
- /package/dist/{chunk-E5RRFMGF.js.map → chunk-HQ6HMINL.js.map} +0 -0
- /package/dist/{chunk-FCRPOA4I.js.map → chunk-KH72WRHR.js.map} +0 -0
- /package/dist/{chunk-QLEQIXCE.mjs.map → chunk-LRVK45HN.mjs.map} +0 -0
- /package/dist/{chunk-PXKCSAT6.mjs.map → chunk-PMZXFAQI.mjs.map} +0 -0
- /package/dist/{chunk-FCCGRGQS.mjs.map → chunk-QLFH3MC6.mjs.map} +0 -0
- /package/dist/{chunk-G4S6UXQ2.js.map → chunk-RW7AYHRG.js.map} +0 -0
- /package/dist/{chunk-SIW7ZXQF.js.map → chunk-S775IABY.js.map} +0 -0
- /package/dist/{chunk-P5MRZOGW.mjs.map → chunk-SAAURQ5A.mjs.map} +0 -0
- /package/dist/{chunk-3Y4IJKZY.mjs.map → chunk-YUWYMNIX.mjs.map} +0 -0
- /package/dist/{chunk-PAFO2KIN.js.map → chunk-ZRC46TUF.js.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [8.2.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Add `context` field to `snap_createInterface` ([#2413](https://github.com/MetaMask/snaps/pull/2413))
|
|
12
|
+
- Add feature flag to disable platform ([#2434](https://github.com/MetaMask/snaps/pull/2434))
|
|
13
|
+
- Add support for `Dropdown` component ([#2420](https://github.com/MetaMask/snaps/pull/2420))
|
|
14
|
+
- Add `initialConnections` diff calculations needed for Snap update ([#2424](https://github.com/MetaMask/snaps/pull/2424))
|
|
15
|
+
|
|
16
|
+
### Fixed
|
|
17
|
+
- Correctly merge caveats when using initial connections ([#2419](https://github.com/MetaMask/snaps/pull/2419))
|
|
18
|
+
|
|
19
|
+
## [8.1.1]
|
|
20
|
+
### Fixed
|
|
21
|
+
- Re-instantiate preinstalled Snaps after clearing state ([#2393](https://github.com/MetaMask/snaps/pull/2393))
|
|
22
|
+
|
|
9
23
|
## [8.1.0]
|
|
10
24
|
### Added
|
|
11
25
|
- Add JSX support for custom UI ([#2258](https://github.com/MetaMask/snaps/pull/2258))
|
|
@@ -257,7 +271,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
257
271
|
- The version of the package no longer needs to match the version of all other
|
|
258
272
|
MetaMask Snaps packages.
|
|
259
273
|
|
|
260
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.
|
|
274
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.2.0...HEAD
|
|
275
|
+
[8.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.1.1...@metamask/snaps-controllers@8.2.0
|
|
276
|
+
[8.1.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.1.0...@metamask/snaps-controllers@8.1.1
|
|
261
277
|
[8.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.0.0...@metamask/snaps-controllers@8.1.0
|
|
262
278
|
[8.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@7.0.1...@metamask/snaps-controllers@8.0.0
|
|
263
279
|
[7.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@7.0.0...@metamask/snaps-controllers@7.0.1
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AbstractExecutionService
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QLFH3MC6.mjs";
|
|
4
4
|
import {
|
|
5
5
|
ProxyPostMessageStream
|
|
6
6
|
} from "./chunk-ZVOYOZFT.mjs";
|
|
@@ -79,4 +79,4 @@ _stream = new WeakMap();
|
|
|
79
79
|
export {
|
|
80
80
|
ProxyExecutionService
|
|
81
81
|
};
|
|
82
|
-
//# sourceMappingURL=chunk-
|
|
82
|
+
//# sourceMappingURL=chunk-3A72M4GC.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkS775IABYjs = require('./chunk-S775IABY.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkEXN2TFDJjs = require('./chunk-EXN2TFDJ.js');
|
|
@@ -8,7 +8,7 @@ var _chunkEXN2TFDJjs = require('./chunk-EXN2TFDJ.js');
|
|
|
8
8
|
// src/services/node-js/NodeProcessExecutionService.ts
|
|
9
9
|
var _postmessagestream = require('@metamask/post-message-stream');
|
|
10
10
|
var _child_process = require('child_process');
|
|
11
|
-
var NodeProcessExecutionService = class extends
|
|
11
|
+
var NodeProcessExecutionService = class extends _chunkS775IABYjs.AbstractExecutionService {
|
|
12
12
|
async initEnvStream() {
|
|
13
13
|
const worker = _child_process.fork.call(void 0,
|
|
14
14
|
_chunkEXN2TFDJjs.__require.resolve(
|
|
@@ -35,4 +35,4 @@ var NodeProcessExecutionService = class extends _chunkSIW7ZXQFjs.AbstractExecuti
|
|
|
35
35
|
|
|
36
36
|
|
|
37
37
|
exports.NodeProcessExecutionService = NodeProcessExecutionService;
|
|
38
|
-
//# sourceMappingURL=chunk-
|
|
38
|
+
//# sourceMappingURL=chunk-3AANDIXT.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ProxyExecutionService
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-3A72M4GC.mjs";
|
|
4
4
|
import {
|
|
5
5
|
__privateAdd,
|
|
6
6
|
__privateMethod
|
|
@@ -69,4 +69,4 @@ createDocument_fn = async function() {
|
|
|
69
69
|
export {
|
|
70
70
|
OffscreenExecutionService
|
|
71
71
|
};
|
|
72
|
-
//# sourceMappingURL=chunk-
|
|
72
|
+
//# sourceMappingURL=chunk-3OJFF5CK.mjs.map
|
|
@@ -106,6 +106,12 @@ async function fetchSnap(snapId, location) {
|
|
|
106
106
|
);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
+
function calculateConnectionsChange(oldConnectionsSet, desiredConnectionsSet) {
|
|
110
|
+
const newConnections = setDiff(desiredConnectionsSet, oldConnectionsSet);
|
|
111
|
+
const unusedConnections = setDiff(oldConnectionsSet, desiredConnectionsSet);
|
|
112
|
+
const approvedConnections = setDiff(oldConnectionsSet, unusedConnections);
|
|
113
|
+
return { newConnections, unusedConnections, approvedConnections };
|
|
114
|
+
}
|
|
109
115
|
|
|
110
116
|
export {
|
|
111
117
|
setDiff,
|
|
@@ -115,6 +121,7 @@ export {
|
|
|
115
121
|
hasTimedOut,
|
|
116
122
|
withTimeout,
|
|
117
123
|
getSnapFiles,
|
|
118
|
-
fetchSnap
|
|
124
|
+
fetchSnap,
|
|
125
|
+
calculateConnectionsChange
|
|
119
126
|
};
|
|
120
|
-
//# sourceMappingURL=chunk-
|
|
127
|
+
//# sourceMappingURL=chunk-567BFPSL.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"sourcesContent":["import type { PermissionConstraint } from '@metamask/permission-controller';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { getErrorMessage } from '@metamask/snaps-sdk';\nimport {\n encodeBase64,\n getValidatedLocalizationFiles,\n validateFetchedSnap,\n} from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport deepEqual from 'fast-deep-equal';\n\nimport type { SnapLocation } from './snaps';\nimport { Timer } from './snaps/Timer';\n\n/**\n * Takes two objects and does a Set Difference of them.\n * Set Difference is generally defined as follows:\n * ```\n * 𝑥 ∈ A ∖ B ⟺ 𝑥 ∈ A ∧ 𝑥 ∉ B\n * ```\n * Meaning that the returned object contains all properties of A expect those that also\n * appear in B. Notice that properties that appear in B, but not in A, have no effect.\n *\n * @see [Set Difference]{@link https://proofwiki.org/wiki/Definition:Set_Difference}\n * @param objectA - The object on which the difference is being calculated.\n * @param objectB - The object whose properties will be removed from objectA.\n * @returns The objectA without properties from objectB.\n */\nexport function setDiff<\n ObjectA extends Record<any, unknown>,\n ObjectB extends Record<any, unknown>,\n>(objectA: ObjectA, objectB: ObjectB): Diff<ObjectA, ObjectB> {\n return Object.entries(objectA).reduce<Record<any, unknown>>(\n (acc, [key, value]) => {\n if (!(key in objectB)) {\n acc[key] = value;\n }\n return acc;\n },\n {},\n ) as Diff<ObjectA, ObjectB>;\n}\n\n/**\n * Calculate a difference between two permissions objects.\n *\n * Similar to `setDiff` except for one additional condition:\n * Permissions in B should be removed from A if they exist in both and have differing caveats.\n *\n * @param permissionsA - An object containing one or more partial permissions.\n * @param permissionsB - An object containing one or more partial permissions to be subtracted from A.\n * @returns The permissions set A without properties from B.\n */\nexport function permissionsDiff<\n PermissionsA extends Record<string, Pick<PermissionConstraint, 'caveats'>>,\n PermissionsB extends Record<string, Pick<PermissionConstraint, 'caveats'>>,\n>(\n permissionsA: PermissionsA,\n permissionsB: PermissionsB,\n): Diff<PermissionsA, PermissionsB> {\n return Object.entries(permissionsA).reduce<\n Record<string, Pick<PermissionConstraint, 'caveats'>>\n >((acc, [key, value]) => {\n const isIncluded = key in permissionsB;\n if (\n !isIncluded ||\n (isIncluded &&\n !deepEqual(value.caveats ?? [], permissionsB[key].caveats ?? []))\n ) {\n acc[key] = value;\n }\n return acc;\n }, {}) as Diff<PermissionsA, PermissionsB>;\n}\n\n/**\n * A Promise that delays its return for a given amount of milliseconds.\n *\n * @param ms - Milliseconds to delay the execution for.\n * @param result - The result to return from the Promise after delay.\n * @returns A promise that is void if no result provided, result otherwise.\n * @template Result - The `result`.\n */\nexport function delay<Result = void>(\n ms: number,\n result?: Result,\n): Promise<Result> & { cancel: () => void } {\n return delayWithTimer(new Timer(ms), result);\n}\n\n/**\n * A Promise that delays it's return by using a pausable Timer.\n *\n * @param timer - Timer used to control the delay.\n * @param result - The result to return from the Promise after delay.\n * @returns A promise that is void if no result provided, result otherwise.\n * @template Result - The `result`.\n */\nexport function delayWithTimer<Result = void>(\n timer: Timer,\n result?: Result,\n): Promise<Result> & { cancel: () => void } {\n let rejectFunc: (reason: Error) => void;\n const promise: any = new Promise<Result>((resolve: any, reject) => {\n timer.start(() => {\n result === undefined ? resolve() : resolve(result);\n });\n rejectFunc = reject;\n });\n\n promise.cancel = () => {\n if (timer.status !== 'finished') {\n timer.cancel();\n rejectFunc(new Error('The delay has been canceled.'));\n }\n };\n return promise;\n}\n\n/*\n * We use a Symbol instead of rejecting the promise so that Errors thrown\n * by the main promise will propagate.\n */\nexport const hasTimedOut = Symbol(\n 'Used to check if the requested promise has timeout (see withTimeout)',\n);\n\n/**\n * Executes the given Promise, if the Timer expires before the Promise settles, we return earlier.\n *\n * NOTE:** The given Promise is not cancelled or interrupted, and will continue to execute uninterrupted. We will just discard its result if it does not complete before the timeout.\n *\n * @param promise - The promise that you want to execute.\n * @param timerOrMs - The timer controlling the timeout or a ms value.\n * @returns The resolved `PromiseValue`, or the hasTimedOut symbol if\n * returning early.\n * @template PromiseValue - The value of the Promise.\n */\nexport async function withTimeout<PromiseValue = void>(\n promise: Promise<PromiseValue>,\n timerOrMs: Timer | number,\n): Promise<PromiseValue | typeof hasTimedOut> {\n const timer =\n typeof timerOrMs === 'number' ? new Timer(timerOrMs) : timerOrMs;\n const delayPromise = delayWithTimer(timer, hasTimedOut);\n try {\n return await Promise.race([promise, delayPromise]);\n } finally {\n delayPromise.cancel();\n }\n}\n\n/**\n * Checks whether the type is composed of literal types\n *\n * @returns @type {true} if whole type is composed of literals, @type {false} if whole type is not literals, @type {boolean} if mixed\n * @example\n * ```\n * type t1 = IsLiteral<1 | 2 | \"asd\" | true>;\n * // t1 = true\n *\n * type t2 = IsLiteral<number | string>;\n * // t2 = false\n *\n * type t3 = IsLiteral<1 | string>;\n * // t3 = boolean\n *\n * const s = Symbol();\n * type t4 = IsLiteral<typeof s>;\n * // t4 = true\n *\n * type t5 = IsLiteral<symbol>\n * // t5 = false;\n * ```\n */\ntype IsLiteral<Type> = Type extends string | number | boolean | symbol\n ? Extract<string | number | boolean | symbol, Type> extends never\n ? true\n : false\n : false;\n\n/**\n * Returns all keys of an object, that are literal, as an union\n *\n * @example\n * ```\n * type t1 = _LiteralKeys<{a: number, b: 0, c: 'foo', d: string}>\n * // t1 = 'b' | 'c'\n * ```\n * @see [Literal types]{@link https://www.typescriptlang.org/docs/handbook/literal-types.html}\n */\ntype LiteralKeys<Type> = NonNullable<\n {\n [Key in keyof Type]: IsLiteral<Key> extends true ? Key : never;\n }[keyof Type]\n>;\n\n/**\n * Returns all keys of an object, that are not literal, as an union\n *\n * @example\n * ```\n * type t1 = _NonLiteralKeys<{a: number, b: 0, c: 'foo', d: string}>\n * // t1 = 'a' | 'd'\n * ```\n * @see [Literal types]{@link https://www.typescriptlang.org/docs/handbook/literal-types.html}\n */\ntype NonLiteralKeys<Type> = NonNullable<\n {\n [Key in keyof Type]: IsLiteral<Key> extends false ? Key : never;\n }[keyof Type]\n>;\n\n/**\n * A set difference of two objects based on their keys\n *\n * @example\n * ```\n * type t1 = Diff<{a: string, b: string}, {a: number}>\n * // t1 = {b: string};\n * type t2 = Diff<{a: string, 0: string}, Record<string, unknown>>;\n * // t2 = { a?: string, 0: string};\n * type t3 = Diff<{a: string, 0: string, 1: string}, Record<1 | string, unknown>>;\n * // t3 = {a?: string, 0: string}\n * ```\n * @see {@link setDiff} for the main use-case\n */\nexport type Diff<First, Second> = Omit<First, LiteralKeys<Second>> &\n Partial<Pick<First, Extract<keyof First, NonLiteralKeys<Second>>>>;\n\n/**\n * Makes every specified property of the specified object type mutable.\n *\n * @template Type - The object whose readonly properties to make mutable.\n * @template TargetKey - The property key(s) to make mutable.\n */\nexport type Mutable<\n Type extends Record<string, unknown>,\n TargetKey extends string,\n> = {\n -readonly [Key in keyof Pick<Type, TargetKey>]: Type[Key];\n} & {\n [Key in keyof Omit<Type, TargetKey>]: Type[Key];\n};\n\n/**\n * Get all files in a Snap from an array of file paths.\n *\n * @param location - The location of the Snap.\n * @param files - The array of file paths.\n * @returns The array of files as {@link VirtualFile}s.\n */\nexport async function getSnapFiles(\n location: SnapLocation,\n files?: string[] | undefined,\n) {\n if (!files || files.length === 0) {\n return [];\n }\n\n return await Promise.all(\n files.map(async (filePath) => location.fetch(filePath)),\n );\n}\n\n/**\n * Fetch the Snap manifest, source code, and any other files from the given\n * location.\n *\n * @param snapId - The ID of the Snap to fetch.\n * @param location - The location of the Snap.\n * @returns The Snap files and location.\n * @throws If the Snap files are invalid, or if the Snap could not be fetched.\n */\nexport async function fetchSnap(snapId: SnapId, location: SnapLocation) {\n try {\n const manifest = await location.manifest();\n const sourceCode = await location.fetch(\n manifest.result.source.location.npm.filePath,\n );\n const { iconPath } = manifest.result.source.location.npm;\n const svgIcon = iconPath ? await location.fetch(iconPath) : undefined;\n\n const auxiliaryFiles = await getSnapFiles(\n location,\n manifest.result.source.files,\n );\n\n await Promise.all(\n auxiliaryFiles.map(async (file) => {\n // This should still be safe\n // eslint-disable-next-line require-atomic-updates\n file.data.base64 = await encodeBase64(file);\n }),\n );\n\n const localizationFiles = await getSnapFiles(\n location,\n manifest.result.source.locales,\n );\n\n const validatedLocalizationFiles =\n getValidatedLocalizationFiles(localizationFiles);\n\n const files = {\n manifest,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles: validatedLocalizationFiles,\n };\n\n await validateFetchedSnap(files);\n\n return files;\n } catch (error) {\n throw new Error(\n `Failed to fetch snap \"${snapId}\": ${getErrorMessage(error)}.`,\n );\n }\n}\n\n/**\n * Calculate change of initialConnections.\n *\n * @param oldConnectionsSet - Previously approved connections.\n * @param desiredConnectionsSet - New connections.\n * @returns Object containing newConnections, unusedConnections and approvedConnections.\n */\nexport function calculateConnectionsChange(\n oldConnectionsSet: Record<string, Json>,\n desiredConnectionsSet: Record<string, Json>,\n): {\n newConnections: Record<string, Json>;\n unusedConnections: Record<string, Json>;\n approvedConnections: Record<string, Json>;\n} {\n const newConnections = setDiff(desiredConnectionsSet, oldConnectionsSet);\n\n const unusedConnections = setDiff(oldConnectionsSet, desiredConnectionsSet);\n\n // It's a Set Intersection of oldConnections and desiredConnectionsSet\n // oldConnections ∖ (oldConnections ∖ desiredConnectionsSet) ⟺ oldConnections ∩ desiredConnectionsSet\n const approvedConnections = setDiff(oldConnectionsSet, unusedConnections);\n\n return { newConnections, unusedConnections, approvedConnections };\n}\n"],"mappings":";;;;;AAEA,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,OAAO,eAAe;AAmBf,SAAS,QAGd,SAAkB,SAA0C;AAC5D,SAAO,OAAO,QAAQ,OAAO,EAAE;AAAA,IAC7B,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AACrB,UAAI,EAAE,OAAO,UAAU;AACrB,YAAI,GAAG,IAAI;AAAA,MACb;AACA,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;AAYO,SAAS,gBAId,cACA,cACkC;AAClC,SAAO,OAAO,QAAQ,YAAY,EAAE,OAElC,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AACvB,UAAM,aAAa,OAAO;AAC1B,QACE,CAAC,cACA,cACC,CAAC,UAAU,MAAM,WAAW,CAAC,GAAG,aAAa,GAAG,EAAE,WAAW,CAAC,CAAC,GACjE;AACA,UAAI,GAAG,IAAI;AAAA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S,MAAM,QAAQ,IAAI;AAE5D,UAAM,iBAAiB,MAAM;AAAA,MAC3B;AAAA,MACA,SAAS,OAAO,OAAO;AAAA,IACzB;AAEA,UAAM,QAAQ;AAAA,MACZ,eAAe,IAAI,OAAO,SAAS;AAGjC,aAAK,KAAK,SAAS,MAAM,aAAa,IAAI;AAAA,MAC5C,CAAC;AAAA,IACH;AAEA,UAAM,oBAAoB,MAAM;AAAA,MAC9B;AAAA,MACA,SAAS,OAAO,OAAO;AAAA,IACzB;AAEA,UAAM,6BACJ,8BAA8B,iBAAiB;AAEjD,UAAM,QAAQ;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,mBAAmB;AAAA,IACrB;AAEA,UAAM,oBAAoB,KAAK;AAE/B,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI;AAAA,MACR,yBAAyB,MAAM,MAAM,gBAAgB,KAAK,CAAC;AAAA,IAC7D;AAAA,EACF;AACF;AASO,SAAS,2BACd,mBACA,uBAKA;AACA,QAAM,iBAAiB,QAAQ,uBAAuB,iBAAiB;AAEvE,QAAM,oBAAoB,QAAQ,mBAAmB,qBAAqB;AAI1E,QAAM,sBAAsB,QAAQ,mBAAmB,iBAAiB;AAExE,SAAO,EAAE,gBAAgB,mBAAmB,oBAAoB;AAClE;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AbstractExecutionService
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QLFH3MC6.mjs";
|
|
4
4
|
import {
|
|
5
5
|
ProxyPostMessageStream
|
|
6
6
|
} from "./chunk-ZVOYOZFT.mjs";
|
|
@@ -102,4 +102,4 @@ export {
|
|
|
102
102
|
WORKER_POOL_ID,
|
|
103
103
|
WebWorkerExecutionService
|
|
104
104
|
};
|
|
105
|
-
//# sourceMappingURL=chunk-
|
|
105
|
+
//# sourceMappingURL=chunk-7IJQGFT5.mjs.map
|
|
@@ -4,6 +4,7 @@ var _jsx = require('@metamask/snaps-sdk/jsx');
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
7
|
+
|
|
7
8
|
var _snapsutils = require('@metamask/snaps-utils');
|
|
8
9
|
function getJsxInterface(component) {
|
|
9
10
|
if (_jsx.isJSXElementUnsafe.call(void 0, component)) {
|
|
@@ -65,16 +66,28 @@ function constructState(oldState, component, newState = {}) {
|
|
|
65
66
|
);
|
|
66
67
|
return newState;
|
|
67
68
|
}
|
|
68
|
-
if (component.type === "Input") {
|
|
69
|
+
if (component.type === "Input" || component.type === "Dropdown") {
|
|
69
70
|
assertNameIsUnique(newState, component.props.name);
|
|
70
71
|
newState[component.props.name] = constructInputState(oldState, component);
|
|
71
72
|
}
|
|
72
73
|
return newState;
|
|
73
74
|
}
|
|
75
|
+
var MAX_CONTEXT_SIZE = 1e6;
|
|
76
|
+
function validateInterfaceContext(context) {
|
|
77
|
+
if (!context) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const size = _snapsutils.getJsonSizeUnsafe.call(void 0, context);
|
|
81
|
+
_snapssdk.assert.call(void 0,
|
|
82
|
+
size <= MAX_CONTEXT_SIZE,
|
|
83
|
+
`A Snap interface context may not be larger than ${MAX_CONTEXT_SIZE / 1e6} MB.`
|
|
84
|
+
);
|
|
85
|
+
}
|
|
86
|
+
|
|
74
87
|
|
|
75
88
|
|
|
76
89
|
|
|
77
90
|
|
|
78
91
|
|
|
79
|
-
exports.getJsxInterface = getJsxInterface; exports.assertNameIsUnique = assertNameIsUnique; exports.constructState = constructState;
|
|
80
|
-
//# sourceMappingURL=chunk-
|
|
92
|
+
exports.getJsxInterface = getJsxInterface; exports.assertNameIsUnique = assertNameIsUnique; exports.constructState = constructState; exports.validateInterfaceContext = validateInterfaceContext;
|
|
93
|
+
//# sourceMappingURL=chunk-7TYZZFHZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/interface/utils.ts"],"names":[],"mappings":";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AU,MAAM,IAAI;AAEjD,UAAM,WAAW,eAAe,SAAS;AACzC,aAAS,UAAU,MAAM,IAAI,IAAI,SAAS;AAAA,MACxC,CAAC,aAAa,SAAS;AACrB,eAAO;AAAA,UACL;AAAA;AAAA,UAEA;AAAA,UACA,UAAU,MAAM;AAAA,UAChB;AAAA,QACF;AAAA,MACF;AAAA,MACA,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,UAAU,SAAS,WAAW,UAAU,SAAS,YAAY;AAC/D,uBAAmB,UAAU,UAAU,MAAM,IAAI;AACjD,aAAS,UAAU,MAAM,IAAI,IAAI,oBAAoB,UAAU,SAAS;AAAA,EAC1E;AAEA,SAAO;AACT;AAEA,IAAM,mBAAmB;AAQlB,SAAS,yBAAyB,SAA4B;AACnE,MAAI,CAAC,SAAS;AACZ;AAAA,EACF;AAIA,QAAM,OAAO,kBAAkB,OAAO;AACtC;AAAA,IACE,QAAQ;AAAA,IACR,mDACE,mBAAmB,GACrB;AAAA,EACF;AACF","sourcesContent":["import { assert } from '@metamask/snaps-sdk';\nimport type {\n FormState,\n InterfaceState,\n ComponentOrElement,\n InterfaceContext,\n} from '@metamask/snaps-sdk';\nimport type {\n ButtonElement,\n DropdownElement,\n FieldElement,\n InputElement,\n JSXElement,\n} from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';\nimport {\n getJsonSizeUnsafe,\n getJsxChildren,\n getJsxElementFromComponent,\n} from '@metamask/snaps-utils';\n\n/**\n * Get a JSX element from a component or JSX element. If the component is a\n * JSX element, it is returned as is. Otherwise, the component is converted to\n * a JSX element.\n *\n * @param component - The component to convert.\n * @returns The JSX element.\n */\nexport function getJsxInterface(component: ComponentOrElement): JSXElement {\n if (isJSXElementUnsafe(component)) {\n return component;\n }\n\n return getJsxElementFromComponent(component);\n}\n\n/**\n * Assert that the component name is unique in state.\n *\n * @param state - The interface state to verify against.\n * @param name - The component name to verify.\n */\nexport function assertNameIsUnique(state: InterfaceState, name: string) {\n assert(\n state[name] === undefined,\n `Duplicate component names are not allowed, found multiple instances of: \"${name}\".`,\n );\n}\n\n/**\n * Construct the state for an input field.\n *\n * @param oldState - The previous state.\n * @param element - The input element.\n * @returns The input state.\n */\nfunction constructInputState(\n oldState: InterfaceState,\n element: InputElement | DropdownElement,\n) {\n return element.props.value ?? oldState[element.props.name] ?? null;\n}\n\n/**\n * Construct the state for a form input.\n *\n * @param oldState - The previous state.\n * @param component - The input element.\n * @param form - The parent form name of the input.\n * @returns The input state.\n */\nfunction constructFormInputState(\n oldState: InterfaceState,\n component: InputElement | DropdownElement,\n form: string,\n) {\n const oldFormState = oldState[form] as FormState;\n const oldInputState = oldFormState?.[component.props.name];\n return component.props.value ?? oldInputState ?? null;\n}\n\n/**\n * Get the input field from a field element.\n *\n * @param element - The field element.\n * @returns The input element.\n */\nfunction getFieldInput(element: FieldElement) {\n if (Array.isArray(element.props.children)) {\n return element.props.children[0];\n }\n\n return element.props.children;\n}\n\n/**\n * Construct the state for a form input.\n *\n * @param oldState - The previous state.\n * @param component - The field element.\n * @param form - The parent form name of the input.\n * @param newState - The new state.\n * @returns The input state.\n */\nfunction constructFormState(\n oldState: InterfaceState,\n component: FieldElement | ButtonElement,\n form: string,\n newState: FormState,\n): FormState {\n if (component.type === 'Button') {\n return newState;\n }\n\n const input = getFieldInput(component);\n assertNameIsUnique(newState, input.props.name);\n\n newState[input.props.name] = constructFormInputState(oldState, input, form);\n\n return newState;\n}\n\n/**\n * Construct the interface state for a given component tree.\n *\n * @param oldState - The previous state.\n * @param component - The UI component to construct state from.\n * @param newState - The state that is being constructed.\n * @returns The interface state of the passed component.\n */\nexport function constructState(\n oldState: InterfaceState,\n component: JSXElement,\n newState: InterfaceState = {},\n): InterfaceState {\n if (component.type === 'Box') {\n const children = getJsxChildren(component);\n return children.reduce(\n (accumulator, node) =>\n constructState(oldState, node as JSXElement, accumulator),\n newState,\n );\n }\n\n if (component.type === 'Form') {\n assertNameIsUnique(newState, component.props.name);\n\n const children = getJsxChildren(component);\n newState[component.props.name] = children.reduce<FormState>(\n (accumulator, node) => {\n return constructFormState(\n oldState,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n node as FieldElement | ButtonElement,\n component.props.name,\n accumulator,\n );\n },\n {},\n );\n\n return newState;\n }\n\n if (component.type === 'Input' || component.type === 'Dropdown') {\n assertNameIsUnique(newState, component.props.name);\n newState[component.props.name] = constructInputState(oldState, component);\n }\n\n return newState;\n}\n\nconst MAX_CONTEXT_SIZE = 1_000_000; // 1 mb\n\n/**\n * Validate a JSON blob to be used as the interface context.\n *\n * @param context - The JSON blob.\n * @throws If the JSON blob is too large.\n */\nexport function validateInterfaceContext(context?: InterfaceContext) {\n if (!context) {\n return;\n }\n\n // We assume the validity of this JSON to be validated by the caller.\n // E.g., in the RPC method implementation.\n const size = getJsonSizeUnsafe(context);\n assert(\n size <= MAX_CONTEXT_SIZE,\n `A Snap interface context may not be larger than ${\n MAX_CONTEXT_SIZE / 1000000\n } MB.`,\n );\n}\n"]}
|
|
@@ -106,6 +106,13 @@ async function fetchSnap(snapId, location) {
|
|
|
106
106
|
);
|
|
107
107
|
}
|
|
108
108
|
}
|
|
109
|
+
function calculateConnectionsChange(oldConnectionsSet, desiredConnectionsSet) {
|
|
110
|
+
const newConnections = setDiff(desiredConnectionsSet, oldConnectionsSet);
|
|
111
|
+
const unusedConnections = setDiff(oldConnectionsSet, desiredConnectionsSet);
|
|
112
|
+
const approvedConnections = setDiff(oldConnectionsSet, unusedConnections);
|
|
113
|
+
return { newConnections, unusedConnections, approvedConnections };
|
|
114
|
+
}
|
|
115
|
+
|
|
109
116
|
|
|
110
117
|
|
|
111
118
|
|
|
@@ -116,5 +123,5 @@ async function fetchSnap(snapId, location) {
|
|
|
116
123
|
|
|
117
124
|
|
|
118
125
|
|
|
119
|
-
exports.setDiff = setDiff; exports.permissionsDiff = permissionsDiff; exports.delay = delay; exports.delayWithTimer = delayWithTimer; exports.hasTimedOut = hasTimedOut; exports.withTimeout = withTimeout; exports.getSnapFiles = getSnapFiles; exports.fetchSnap = fetchSnap;
|
|
120
|
-
//# sourceMappingURL=chunk-
|
|
126
|
+
exports.setDiff = setDiff; exports.permissionsDiff = permissionsDiff; exports.delay = delay; exports.delayWithTimer = delayWithTimer; exports.hasTimedOut = hasTimedOut; exports.withTimeout = withTimeout; exports.getSnapFiles = getSnapFiles; exports.fetchSnap = fetchSnap; exports.calculateConnectionsChange = calculateConnectionsChange;
|
|
127
|
+
//# sourceMappingURL=chunk-CDTGUNSA.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/utils.ts"],"names":[],"mappings":";;;;;AAEA,SAAS,uBAAuB;AAChC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP,OAAO,eAAe;AAmBf,SAAS,QAGd,SAAkB,SAA0C;AAC5D,SAAO,OAAO,QAAQ,OAAO,EAAE;AAAA,IAC7B,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AACrB,UAAI,EAAE,OAAO,UAAU;AACrB,YAAI,GAAG,IAAI;AAAA,MACb;AACA,aAAO;AAAA,IACT;AAAA,IACA,CAAC;AAAA,EACH;AACF;AAYO,SAAS,gBAId,cACA,cACkC;AAClC,SAAO,OAAO,QAAQ,YAAY,EAAE,OAElC,CAAC,KAAK,CAAC,KAAK,KAAK,MAAM;AACvB,UAAM,aAAa,OAAO;AAC1B,QACE,CAAC,cACA,cACC,CAAC,UAAU,MAAM,WAAW,CAAC,GAAG,aAAa,GAAG,EAAE,WAAW,CAAC,CAAC,GACjE;AACA,UAAI,GAAG,IAAI;AAAA,IACb;AACA,WAAO;AAAA,EACT,GAAG,CAAC,CAAC;AACP;AAUO,SAAS,MACd,IACA,QAC0C;AAC1C,SAAO,eAAe,IAAI,MAAM,EAAE,GAAG,MAAM;AAC7C;AAUO,SAAS,eACd,OACA,QAC0C;AAC1C,MAAI;AACJ,QAAM,UAAe,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IAAI;AAAA,MAC5C,CAAC;AAAA,IACH;AAEA,UAAM,oBAAoB,MAAM;AAAA,MAC9B;AAAA,MACA,SAAS,OAAO,OAAO;AAAA,IACzB;AAEA,UAAM,6BACJ,8BAA8B,iBAAiB;AAEjD,UAAM,QAAQ;AAAA,MACZ;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,mBAAmB;AAAA,IACrB;AAEA,UAAM,oBAAoB,KAAK;AAE/B,WAAO;AAAA,EACT,SAAS,OAAO;AACd,UAAM,IAAI;AAAA,MACR,yBAAyB,MAAM,MAAM,gBAAgB,KAAK,CAAC;AAAA,IAC7D;AAAA,EACF;AACF;AASO,SAAS,2BACd,mBACA,uBAKA;AACA,QAAM,iBAAiB,QAAQ,uBAAuB,iBAAiB;AAEvE,QAAM,oBAAoB,QAAQ,mBAAmB,qBAAqB;AAI1E,QAAM,sBAAsB,QAAQ,mBAAmB,iBAAiB;AAExE,SAAO,EAAE,gBAAgB,mBAAmB,oBAAoB;AAClE","sourcesContent":["import type { PermissionConstraint } from '@metamask/permission-controller';\nimport type { SnapId } from '@metamask/snaps-sdk';\nimport { getErrorMessage } from '@metamask/snaps-sdk';\nimport {\n encodeBase64,\n getValidatedLocalizationFiles,\n validateFetchedSnap,\n} from '@metamask/snaps-utils';\nimport type { Json } from '@metamask/utils';\nimport deepEqual from 'fast-deep-equal';\n\nimport type { SnapLocation } from './snaps';\nimport { Timer } from './snaps/Timer';\n\n/**\n * Takes two objects and does a Set Difference of them.\n * Set Difference is generally defined as follows:\n * ```\n * 𝑥 ∈ A ∖ B ⟺ 𝑥 ∈ A ∧ 𝑥 ∉ B\n * ```\n * Meaning that the returned object contains all properties of A expect those that also\n * appear in B. Notice that properties that appear in B, but not in A, have no effect.\n *\n * @see [Set Difference]{@link https://proofwiki.org/wiki/Definition:Set_Difference}\n * @param objectA - The object on which the difference is being calculated.\n * @param objectB - The object whose properties will be removed from objectA.\n * @returns The objectA without properties from objectB.\n */\nexport function setDiff<\n ObjectA extends Record<any, unknown>,\n ObjectB extends Record<any, unknown>,\n>(objectA: ObjectA, objectB: ObjectB): Diff<ObjectA, ObjectB> {\n return Object.entries(objectA).reduce<Record<any, unknown>>(\n (acc, [key, value]) => {\n if (!(key in objectB)) {\n acc[key] = value;\n }\n return acc;\n },\n {},\n ) as Diff<ObjectA, ObjectB>;\n}\n\n/**\n * Calculate a difference between two permissions objects.\n *\n * Similar to `setDiff` except for one additional condition:\n * Permissions in B should be removed from A if they exist in both and have differing caveats.\n *\n * @param permissionsA - An object containing one or more partial permissions.\n * @param permissionsB - An object containing one or more partial permissions to be subtracted from A.\n * @returns The permissions set A without properties from B.\n */\nexport function permissionsDiff<\n PermissionsA extends Record<string, Pick<PermissionConstraint, 'caveats'>>,\n PermissionsB extends Record<string, Pick<PermissionConstraint, 'caveats'>>,\n>(\n permissionsA: PermissionsA,\n permissionsB: PermissionsB,\n): Diff<PermissionsA, PermissionsB> {\n return Object.entries(permissionsA).reduce<\n Record<string, Pick<PermissionConstraint, 'caveats'>>\n >((acc, [key, value]) => {\n const isIncluded = key in permissionsB;\n if (\n !isIncluded ||\n (isIncluded &&\n !deepEqual(value.caveats ?? [], permissionsB[key].caveats ?? []))\n ) {\n acc[key] = value;\n }\n return acc;\n }, {}) as Diff<PermissionsA, PermissionsB>;\n}\n\n/**\n * A Promise that delays its return for a given amount of milliseconds.\n *\n * @param ms - Milliseconds to delay the execution for.\n * @param result - The result to return from the Promise after delay.\n * @returns A promise that is void if no result provided, result otherwise.\n * @template Result - The `result`.\n */\nexport function delay<Result = void>(\n ms: number,\n result?: Result,\n): Promise<Result> & { cancel: () => void } {\n return delayWithTimer(new Timer(ms), result);\n}\n\n/**\n * A Promise that delays it's return by using a pausable Timer.\n *\n * @param timer - Timer used to control the delay.\n * @param result - The result to return from the Promise after delay.\n * @returns A promise that is void if no result provided, result otherwise.\n * @template Result - The `result`.\n */\nexport function delayWithTimer<Result = void>(\n timer: Timer,\n result?: Result,\n): Promise<Result> & { cancel: () => void } {\n let rejectFunc: (reason: Error) => void;\n const promise: any = new Promise<Result>((resolve: any, reject) => {\n timer.start(() => {\n result === undefined ? resolve() : resolve(result);\n });\n rejectFunc = reject;\n });\n\n promise.cancel = () => {\n if (timer.status !== 'finished') {\n timer.cancel();\n rejectFunc(new Error('The delay has been canceled.'));\n }\n };\n return promise;\n}\n\n/*\n * We use a Symbol instead of rejecting the promise so that Errors thrown\n * by the main promise will propagate.\n */\nexport const hasTimedOut = Symbol(\n 'Used to check if the requested promise has timeout (see withTimeout)',\n);\n\n/**\n * Executes the given Promise, if the Timer expires before the Promise settles, we return earlier.\n *\n * NOTE:** The given Promise is not cancelled or interrupted, and will continue to execute uninterrupted. We will just discard its result if it does not complete before the timeout.\n *\n * @param promise - The promise that you want to execute.\n * @param timerOrMs - The timer controlling the timeout or a ms value.\n * @returns The resolved `PromiseValue`, or the hasTimedOut symbol if\n * returning early.\n * @template PromiseValue - The value of the Promise.\n */\nexport async function withTimeout<PromiseValue = void>(\n promise: Promise<PromiseValue>,\n timerOrMs: Timer | number,\n): Promise<PromiseValue | typeof hasTimedOut> {\n const timer =\n typeof timerOrMs === 'number' ? new Timer(timerOrMs) : timerOrMs;\n const delayPromise = delayWithTimer(timer, hasTimedOut);\n try {\n return await Promise.race([promise, delayPromise]);\n } finally {\n delayPromise.cancel();\n }\n}\n\n/**\n * Checks whether the type is composed of literal types\n *\n * @returns @type {true} if whole type is composed of literals, @type {false} if whole type is not literals, @type {boolean} if mixed\n * @example\n * ```\n * type t1 = IsLiteral<1 | 2 | \"asd\" | true>;\n * // t1 = true\n *\n * type t2 = IsLiteral<number | string>;\n * // t2 = false\n *\n * type t3 = IsLiteral<1 | string>;\n * // t3 = boolean\n *\n * const s = Symbol();\n * type t4 = IsLiteral<typeof s>;\n * // t4 = true\n *\n * type t5 = IsLiteral<symbol>\n * // t5 = false;\n * ```\n */\ntype IsLiteral<Type> = Type extends string | number | boolean | symbol\n ? Extract<string | number | boolean | symbol, Type> extends never\n ? true\n : false\n : false;\n\n/**\n * Returns all keys of an object, that are literal, as an union\n *\n * @example\n * ```\n * type t1 = _LiteralKeys<{a: number, b: 0, c: 'foo', d: string}>\n * // t1 = 'b' | 'c'\n * ```\n * @see [Literal types]{@link https://www.typescriptlang.org/docs/handbook/literal-types.html}\n */\ntype LiteralKeys<Type> = NonNullable<\n {\n [Key in keyof Type]: IsLiteral<Key> extends true ? Key : never;\n }[keyof Type]\n>;\n\n/**\n * Returns all keys of an object, that are not literal, as an union\n *\n * @example\n * ```\n * type t1 = _NonLiteralKeys<{a: number, b: 0, c: 'foo', d: string}>\n * // t1 = 'a' | 'd'\n * ```\n * @see [Literal types]{@link https://www.typescriptlang.org/docs/handbook/literal-types.html}\n */\ntype NonLiteralKeys<Type> = NonNullable<\n {\n [Key in keyof Type]: IsLiteral<Key> extends false ? Key : never;\n }[keyof Type]\n>;\n\n/**\n * A set difference of two objects based on their keys\n *\n * @example\n * ```\n * type t1 = Diff<{a: string, b: string}, {a: number}>\n * // t1 = {b: string};\n * type t2 = Diff<{a: string, 0: string}, Record<string, unknown>>;\n * // t2 = { a?: string, 0: string};\n * type t3 = Diff<{a: string, 0: string, 1: string}, Record<1 | string, unknown>>;\n * // t3 = {a?: string, 0: string}\n * ```\n * @see {@link setDiff} for the main use-case\n */\nexport type Diff<First, Second> = Omit<First, LiteralKeys<Second>> &\n Partial<Pick<First, Extract<keyof First, NonLiteralKeys<Second>>>>;\n\n/**\n * Makes every specified property of the specified object type mutable.\n *\n * @template Type - The object whose readonly properties to make mutable.\n * @template TargetKey - The property key(s) to make mutable.\n */\nexport type Mutable<\n Type extends Record<string, unknown>,\n TargetKey extends string,\n> = {\n -readonly [Key in keyof Pick<Type, TargetKey>]: Type[Key];\n} & {\n [Key in keyof Omit<Type, TargetKey>]: Type[Key];\n};\n\n/**\n * Get all files in a Snap from an array of file paths.\n *\n * @param location - The location of the Snap.\n * @param files - The array of file paths.\n * @returns The array of files as {@link VirtualFile}s.\n */\nexport async function getSnapFiles(\n location: SnapLocation,\n files?: string[] | undefined,\n) {\n if (!files || files.length === 0) {\n return [];\n }\n\n return await Promise.all(\n files.map(async (filePath) => location.fetch(filePath)),\n );\n}\n\n/**\n * Fetch the Snap manifest, source code, and any other files from the given\n * location.\n *\n * @param snapId - The ID of the Snap to fetch.\n * @param location - The location of the Snap.\n * @returns The Snap files and location.\n * @throws If the Snap files are invalid, or if the Snap could not be fetched.\n */\nexport async function fetchSnap(snapId: SnapId, location: SnapLocation) {\n try {\n const manifest = await location.manifest();\n const sourceCode = await location.fetch(\n manifest.result.source.location.npm.filePath,\n );\n const { iconPath } = manifest.result.source.location.npm;\n const svgIcon = iconPath ? await location.fetch(iconPath) : undefined;\n\n const auxiliaryFiles = await getSnapFiles(\n location,\n manifest.result.source.files,\n );\n\n await Promise.all(\n auxiliaryFiles.map(async (file) => {\n // This should still be safe\n // eslint-disable-next-line require-atomic-updates\n file.data.base64 = await encodeBase64(file);\n }),\n );\n\n const localizationFiles = await getSnapFiles(\n location,\n manifest.result.source.locales,\n );\n\n const validatedLocalizationFiles =\n getValidatedLocalizationFiles(localizationFiles);\n\n const files = {\n manifest,\n sourceCode,\n svgIcon,\n auxiliaryFiles,\n localizationFiles: validatedLocalizationFiles,\n };\n\n await validateFetchedSnap(files);\n\n return files;\n } catch (error) {\n throw new Error(\n `Failed to fetch snap \"${snapId}\": ${getErrorMessage(error)}.`,\n );\n }\n}\n\n/**\n * Calculate change of initialConnections.\n *\n * @param oldConnectionsSet - Previously approved connections.\n * @param desiredConnectionsSet - New connections.\n * @returns Object containing newConnections, unusedConnections and approvedConnections.\n */\nexport function calculateConnectionsChange(\n oldConnectionsSet: Record<string, Json>,\n desiredConnectionsSet: Record<string, Json>,\n): {\n newConnections: Record<string, Json>;\n unusedConnections: Record<string, Json>;\n approvedConnections: Record<string, Json>;\n} {\n const newConnections = setDiff(desiredConnectionsSet, oldConnectionsSet);\n\n const unusedConnections = setDiff(oldConnectionsSet, desiredConnectionsSet);\n\n // It's a Set Intersection of oldConnections and desiredConnectionsSet\n // oldConnections ∖ (oldConnections ∖ desiredConnectionsSet) ⟺ oldConnections ∩ desiredConnectionsSet\n const approvedConnections = setDiff(oldConnectionsSet, unusedConnections);\n\n return { newConnections, unusedConnections, approvedConnections };\n}\n"]}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
var _chunkC4D6GBMYjs = require('./chunk-C4D6GBMY.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
var
|
|
6
|
+
var _chunkKH72WRHRjs = require('./chunk-KH72WRHR.js');
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
|
|
@@ -13,7 +13,7 @@ var _chunkEXN2TFDJjs = require('./chunk-EXN2TFDJ.js');
|
|
|
13
13
|
|
|
14
14
|
// src/services/webview/WebViewExecutionService.ts
|
|
15
15
|
var _getWebView, _ensureWebViewLoaded, ensureWebViewLoaded_fn;
|
|
16
|
-
var WebViewExecutionService = class extends
|
|
16
|
+
var WebViewExecutionService = class extends _chunkKH72WRHRjs.ProxyExecutionService {
|
|
17
17
|
constructor({
|
|
18
18
|
messenger,
|
|
19
19
|
setupSnapProvider,
|
|
@@ -55,4 +55,4 @@ ensureWebViewLoaded_fn = async function() {
|
|
|
55
55
|
|
|
56
56
|
|
|
57
57
|
exports.WebViewExecutionService = WebViewExecutionService;
|
|
58
|
-
//# sourceMappingURL=chunk-
|
|
58
|
+
//# sourceMappingURL=chunk-FPGAQ6MT.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkKH72WRHRjs = require('./chunk-KH72WRHR.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
|
|
@@ -9,7 +9,7 @@ var _chunkEXN2TFDJjs = require('./chunk-EXN2TFDJ.js');
|
|
|
9
9
|
// src/services/offscreen/OffscreenExecutionService.ts
|
|
10
10
|
var _postmessagestream = require('@metamask/post-message-stream');
|
|
11
11
|
var _createDocument, createDocument_fn;
|
|
12
|
-
var OffscreenExecutionService = class extends
|
|
12
|
+
var OffscreenExecutionService = class extends _chunkKH72WRHRjs.ProxyExecutionService {
|
|
13
13
|
/**
|
|
14
14
|
* Create a new offscreen execution service.
|
|
15
15
|
*
|
|
@@ -69,4 +69,4 @@ createDocument_fn = async function() {
|
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
exports.OffscreenExecutionService = OffscreenExecutionService;
|
|
72
|
-
//# sourceMappingURL=chunk-
|
|
72
|
+
//# sourceMappingURL=chunk-HK4OAMJT.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkS775IABYjs = require('./chunk-S775IABY.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunk7Y6P5FRNjs = require('./chunk-7Y6P5FRN.js');
|
|
@@ -17,7 +17,7 @@ var _utils = require('@metamask/utils');
|
|
|
17
17
|
var _nanoid = require('nanoid');
|
|
18
18
|
var WORKER_POOL_ID = "snaps-worker-pool";
|
|
19
19
|
var _documentUrl, _runtimeStream;
|
|
20
|
-
var WebWorkerExecutionService = class extends
|
|
20
|
+
var WebWorkerExecutionService = class extends _chunkS775IABYjs.AbstractExecutionService {
|
|
21
21
|
/**
|
|
22
22
|
* Create a new webworker execution service.
|
|
23
23
|
*
|
|
@@ -102,4 +102,4 @@ _runtimeStream = new WeakMap();
|
|
|
102
102
|
|
|
103
103
|
|
|
104
104
|
exports.WORKER_POOL_ID = WORKER_POOL_ID; exports.WebWorkerExecutionService = WebWorkerExecutionService;
|
|
105
|
-
//# sourceMappingURL=chunk-
|
|
105
|
+
//# sourceMappingURL=chunk-HQ6HMINL.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkS775IABYjs = require('./chunk-S775IABY.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunk7Y6P5FRNjs = require('./chunk-7Y6P5FRN.js');
|
|
@@ -13,7 +13,7 @@ var _chunkEXN2TFDJjs = require('./chunk-EXN2TFDJ.js');
|
|
|
13
13
|
// src/services/proxy/ProxyExecutionService.ts
|
|
14
14
|
var _nanoid = require('nanoid');
|
|
15
15
|
var _stream;
|
|
16
|
-
var ProxyExecutionService = class extends
|
|
16
|
+
var ProxyExecutionService = class extends _chunkS775IABYjs.AbstractExecutionService {
|
|
17
17
|
/**
|
|
18
18
|
* Create a new proxy execution service.
|
|
19
19
|
*
|
|
@@ -79,4 +79,4 @@ _stream = new WeakMap();
|
|
|
79
79
|
|
|
80
80
|
|
|
81
81
|
exports.ProxyExecutionService = ProxyExecutionService;
|
|
82
|
-
//# sourceMappingURL=chunk-
|
|
82
|
+
//# sourceMappingURL=chunk-KH72WRHR.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AbstractExecutionService
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QLFH3MC6.mjs";
|
|
4
4
|
|
|
5
5
|
// src/services/iframe/IframeExecutionService.ts
|
|
6
6
|
import { WindowPostMessageStream } from "@metamask/post-message-stream";
|
|
@@ -35,4 +35,4 @@ var IframeExecutionService = class extends AbstractExecutionService {
|
|
|
35
35
|
export {
|
|
36
36
|
IframeExecutionService
|
|
37
37
|
};
|
|
38
|
-
//# sourceMappingURL=chunk-
|
|
38
|
+
//# sourceMappingURL=chunk-LRVK45HN.mjs.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
|
|
5
|
+
var _chunk7TYZZFHZjs = require('./chunk-7TYZZFHZ.js');
|
|
5
6
|
|
|
6
7
|
|
|
7
8
|
|
|
@@ -62,18 +63,21 @@ var SnapInterfaceController = class extends _basecontroller.BaseController {
|
|
|
62
63
|
*
|
|
63
64
|
* @param snapId - The snap id that created the interface.
|
|
64
65
|
* @param content - The interface content.
|
|
66
|
+
* @param context - An optional interface context object.
|
|
65
67
|
* @returns The newly interface id.
|
|
66
68
|
*/
|
|
67
|
-
async createInterface(snapId, content) {
|
|
68
|
-
const element =
|
|
69
|
+
async createInterface(snapId, content, context) {
|
|
70
|
+
const element = _chunk7TYZZFHZjs.getJsxInterface.call(void 0, content);
|
|
69
71
|
await _chunkEXN2TFDJjs.__privateMethod.call(void 0, this, _validateContent, validateContent_fn).call(this, element);
|
|
72
|
+
_chunk7TYZZFHZjs.validateInterfaceContext.call(void 0, context);
|
|
70
73
|
const id = _nanoid.nanoid.call(void 0, );
|
|
71
|
-
const componentState =
|
|
74
|
+
const componentState = _chunk7TYZZFHZjs.constructState.call(void 0, {}, element);
|
|
72
75
|
this.update((draftState) => {
|
|
73
76
|
draftState.interfaces[id] = {
|
|
74
77
|
snapId,
|
|
75
78
|
content: element,
|
|
76
|
-
state: componentState
|
|
79
|
+
state: componentState,
|
|
80
|
+
context: context ?? null
|
|
77
81
|
};
|
|
78
82
|
});
|
|
79
83
|
return id;
|
|
@@ -98,10 +102,10 @@ var SnapInterfaceController = class extends _basecontroller.BaseController {
|
|
|
98
102
|
*/
|
|
99
103
|
async updateInterface(snapId, id, content) {
|
|
100
104
|
_chunkEXN2TFDJjs.__privateMethod.call(void 0, this, _validateArgs, validateArgs_fn).call(this, snapId, id);
|
|
101
|
-
const element =
|
|
105
|
+
const element = _chunk7TYZZFHZjs.getJsxInterface.call(void 0, content);
|
|
102
106
|
await _chunkEXN2TFDJjs.__privateMethod.call(void 0, this, _validateContent, validateContent_fn).call(this, element);
|
|
103
107
|
const oldState = this.state.interfaces[id].state;
|
|
104
|
-
const newState =
|
|
108
|
+
const newState = _chunk7TYZZFHZjs.constructState.call(void 0, oldState, element);
|
|
105
109
|
this.update((draftState) => {
|
|
106
110
|
draftState.interfaces[id].state = newState;
|
|
107
111
|
draftState.interfaces[id].content = element;
|
|
@@ -186,4 +190,4 @@ validateContent_fn = async function(element) {
|
|
|
186
190
|
|
|
187
191
|
|
|
188
192
|
exports.SnapInterfaceController = SnapInterfaceController;
|
|
189
|
-
//# sourceMappingURL=chunk-
|
|
193
|
+
//# sourceMappingURL=chunk-PIQFC66N.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/interface/SnapInterfaceController.ts"],"names":[],"mappings":";;;;;;;;;;;AACA,SAAS,sBAAsB;AAY/B,SAAS,mBAAmB,wBAAwB;AACpD,SAAS,cAAc;AACvB,SAAS,cAAc;AAQvB,IAAM,sBAAsB;AAE5B,IAAM,iBAAiB;AAzBvB;AA0FO,IAAM,0BAAN,cAAsC,eAI3C;AAAA,EACA,YAAY,EAAE,WAAW,MAAM,GAAgC;AAC7D,UAAM;AAAA,MACJ;AAAA,MACA,UAAU;AAAA,QACR,YAAY,EAAE,SAAS,OAAO,WAAW,MAAM;AAAA,MACjD;AAAA,MACA,MAAM;AAAA,MACN,OAAO,EAAE,YAAY,CAAC,GAAG,GAAG,MAAM;AAAA,IACpC,CAAC;AASH;AAAA;AAAA;AAAA;AAAA;AAgIA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA;AAAA;AAAA;AAAA,uBAAM;AAUN;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAWA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAAM;AA5KJ,0BAAK,sDAAL;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAyCA,MAAM,gBACJ,QACA,SACA,SACA;AACA,UAAM,UAAU,gBAAgB,OAAO;AACvC,UAAM,sBAAK,sCAAL,WAAsB;AAC5B,6BAAyB,OAAO;AAEhC,UAAM,KAAK,OAAO;AAClB,UAAM,iBAAiB,eAAe,CAAC,GAAG,OAA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,cAAc;AAAA,IACjB,KAAK,aAAa,KAAK,IAAI;AAAA,EAC7B;AAEA,OAAK,gBAAgB;AAAA,IACnB,GAAG,cAAc;AAAA,IACjB,KAAK,gBAAgB,KAAK,IAAI;AAAA,EAChC;AAEA,OAAK,gBAAgB;AAAA,IACnB,GAAG,cAAc;AAAA,IACjB,KAAK,gBAAgB,KAAK,IAAI;AAAA,EAChC;AAEA,OAAK,gBAAgB;AAAA,IACnB,GAAG,cAAc;AAAA,IACjB,KAAK,qBAAqB,KAAK,IAAI;AAAA,EACrC;AACF;AAuGA;AAAA,kBAAa,SAAC,QAAgB,IAAY;AACxC,QAAM,oBAAoB,KAAK,MAAM,WAAW,EAAE;AAElD;AAAA,IACE,sBAAsB;AAAA,IACtB,sBAAsB,EAAE;AAAA,EAC1B;AACA;AAAA,IACE,kBAAkB,WAAW;AAAA,IAC7B,4BAA4B,MAAM;AAAA,EACpC;AACF;AAKM;AAAA,+BAA0B,iBAAG;AACjC,QAAM,KAAK,gBAAgB,KAAK,qCAAqC;AACvE;AAQA;AAAA,uBAAkB,SAAC,QAAgB;AACjC,SAAO,KAAK,gBAAgB,KAAK,iCAAiC,MAAM,EACrE;AACL;AAQM;AAAA,qBAAgB,eAAC,SAAqB;AAG1C,QAAM,OAAO,kBAAkB,OAAO;AACtC;AAAA,IACE,QAAQ;AAAA,IACR,oCAAoC,sBAAsB,GAAO;AAAA,EACnE;AAEA,QAAM,sBAAK,0DAAL;AACN,mBAAiB,SAAS,sBAAK,0CAAmB,KAAK,IAAI,CAAC;AAC9D","sourcesContent":["import type { RestrictedControllerMessenger } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n MaybeUpdateState,\n TestOrigin,\n} from '@metamask/phishing-controller';\nimport type {\n InterfaceState,\n SnapId,\n ComponentOrElement,\n InterfaceContext,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport { getJsonSizeUnsafe, validateJsxLinks } from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport {\n constructState,\n getJsxInterface,\n validateInterfaceContext,\n} from './utils';\n\nconst MAX_UI_CONTENT_SIZE = 10_000_000; // 10 mb\n\nconst controllerName = 'SnapInterfaceController';\n\nexport type CreateInterface = {\n type: `${typeof controllerName}:createInterface`;\n handler: SnapInterfaceController['createInterface'];\n};\n\nexport type GetInterface = {\n type: `${typeof controllerName}:getInterface`;\n handler: SnapInterfaceController['getInterface'];\n};\n\nexport type UpdateInterface = {\n type: `${typeof controllerName}:updateInterface`;\n handler: SnapInterfaceController['updateInterface'];\n};\n\nexport type DeleteInterface = {\n type: `${typeof controllerName}:deleteInterface`;\n handler: SnapInterfaceController['deleteInterface'];\n};\n\nexport type UpdateInterfaceState = {\n type: `${typeof controllerName}:updateInterfaceState`;\n handler: SnapInterfaceController['updateInterfaceState'];\n};\n\nexport type SnapInterfaceControllerAllowedActions =\n | TestOrigin\n | MaybeUpdateState;\n\nexport type SnapInterfaceControllerActions =\n | CreateInterface\n | GetInterface\n | UpdateInterface\n | DeleteInterface\n | UpdateInterfaceState;\n\nexport type SnapInterfaceControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n SnapInterfaceControllerActions | SnapInterfaceControllerAllowedActions,\n never,\n SnapInterfaceControllerAllowedActions['type'],\n never\n>;\n\nexport type StoredInterface = {\n snapId: SnapId;\n content: JSXElement;\n state: InterfaceState;\n context: InterfaceContext | null;\n};\n\nexport type SnapInterfaceControllerState = {\n interfaces: Record<string, StoredInterface>;\n};\n\nexport type SnapInterfaceControllerArgs = {\n messenger: SnapInterfaceControllerMessenger;\n state?: SnapInterfaceControllerState;\n};\n\n/**\n * Use this controller to manage snaps UI interfaces using RPC method hooks.\n */\nexport class SnapInterfaceController extends BaseController<\n typeof controllerName,\n SnapInterfaceControllerState,\n SnapInterfaceControllerMessenger\n> {\n constructor({ messenger, state }: SnapInterfaceControllerArgs) {\n super({\n messenger,\n metadata: {\n interfaces: { persist: false, anonymous: false },\n },\n name: controllerName,\n state: { interfaces: {}, ...state },\n });\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:createInterface`,\n this.createInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getInterface`,\n this.getInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateInterface`,\n this.updateInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:deleteInterface`,\n this.deleteInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateInterfaceState`,\n this.updateInterfaceState.bind(this),\n );\n }\n\n /**\n * Create an interface in the controller state with the associated data.\n *\n * @param snapId - The snap id that created the interface.\n * @param content - The interface content.\n * @param context - An optional interface context object.\n * @returns The newly interface id.\n */\n async createInterface(\n snapId: SnapId,\n content: ComponentOrElement,\n context?: InterfaceContext,\n ) {\n const element = getJsxInterface(content);\n await this.#validateContent(element);\n validateInterfaceContext(context);\n\n const id = nanoid();\n const componentState = constructState({}, element);\n\n this.update((draftState) => {\n // @ts-expect-error - TS2589: Type instantiation is excessively deep and\n // possibly infinite.\n draftState.interfaces[id] = {\n snapId,\n content: element,\n state: componentState,\n context: context ?? null,\n };\n });\n\n return id;\n }\n\n /**\n * Get the data of a given interface id.\n *\n * @param snapId - The snap id requesting the interface data.\n * @param id - The interface id.\n * @returns The interface state.\n */\n getInterface(snapId: SnapId, id: string) {\n this.#validateArgs(snapId, id);\n\n return this.state.interfaces[id];\n }\n\n /**\n * Update the interface with the given content.\n *\n * @param snapId - The snap id requesting the update.\n * @param id - The interface id.\n * @param content - The new content.\n */\n async updateInterface(\n snapId: SnapId,\n id: string,\n content: ComponentOrElement,\n ) {\n this.#validateArgs(snapId, id);\n const element = getJsxInterface(content);\n await this.#validateContent(element);\n\n const oldState = this.state.interfaces[id].state;\n const newState = constructState(oldState, element);\n\n this.update((draftState) => {\n draftState.interfaces[id].state = newState;\n draftState.interfaces[id].content = element;\n });\n }\n\n /**\n * Delete an interface from state.\n *\n * @param id - The interface id.\n */\n deleteInterface(id: string) {\n this.update((draftState) => {\n delete draftState.interfaces[id];\n });\n }\n\n /**\n * Update the interface state.\n *\n * @param id - The interface id.\n * @param state - The new state.\n */\n updateInterfaceState(id: string, state: InterfaceState) {\n this.update((draftState) => {\n draftState.interfaces[id].state = state;\n });\n }\n\n /**\n * Utility function to validate the args passed to the other methods.\n *\n * @param snapId - The snap id.\n * @param id - The interface id.\n */\n #validateArgs(snapId: SnapId, id: string) {\n const existingInterface = this.state.interfaces[id];\n\n assert(\n existingInterface !== undefined,\n `Interface with id '${id}' not found.`,\n );\n assert(\n existingInterface.snapId === snapId,\n `Interface not created by ${snapId}.`,\n );\n }\n\n /**\n * Trigger a Phishing list update if needed.\n */\n async #triggerPhishingListUpdate() {\n await this.messagingSystem.call('PhishingController:maybeUpdateState');\n }\n\n /**\n * Check an origin against the phishing list.\n *\n * @param origin - The origin to check.\n * @returns True if the origin is on the phishing list, otherwise false.\n */\n #checkPhishingList(origin: string) {\n return this.messagingSystem.call('PhishingController:testOrigin', origin)\n .result;\n }\n\n /**\n * Utility function to validate the components of an interface.\n * Throws if something is invalid.\n *\n * @param element - The JSX element to verify.\n */\n async #validateContent(element: JSXElement) {\n // We assume the validity of this JSON to be validated by the caller.\n // E.g., in the RPC method implementation.\n const size = getJsonSizeUnsafe(element);\n assert(\n size <= MAX_UI_CONTENT_SIZE,\n `A Snap UI may not be larger than ${MAX_UI_CONTENT_SIZE / 1000000} MB.`,\n );\n\n await this.#triggerPhishingListUpdate();\n validateJsxLinks(element, this.#checkPhishingList.bind(this));\n }\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
AbstractExecutionService
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-QLFH3MC6.mjs";
|
|
4
4
|
import {
|
|
5
5
|
__require
|
|
6
6
|
} from "./chunk-YRZVIDCF.mjs";
|
|
@@ -35,4 +35,4 @@ var NodeProcessExecutionService = class extends AbstractExecutionService {
|
|
|
35
35
|
export {
|
|
36
36
|
NodeProcessExecutionService
|
|
37
37
|
};
|
|
38
|
-
//# sourceMappingURL=chunk-
|
|
38
|
+
//# sourceMappingURL=chunk-PMZXFAQI.mjs.map
|
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
hasTimedOut,
|
|
6
6
|
withTimeout
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-567BFPSL.mjs";
|
|
8
8
|
import {
|
|
9
9
|
Timer
|
|
10
10
|
} from "./chunk-XO7KDFBY.mjs";
|
|
@@ -397,4 +397,4 @@ export {
|
|
|
397
397
|
AbstractExecutionService,
|
|
398
398
|
setupMultiplex
|
|
399
399
|
};
|
|
400
|
-
//# sourceMappingURL=chunk-
|
|
400
|
+
//# sourceMappingURL=chunk-QLFH3MC6.mjs.map
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
2
|
constructState,
|
|
3
|
-
getJsxInterface
|
|
4
|
-
|
|
3
|
+
getJsxInterface,
|
|
4
|
+
validateInterfaceContext
|
|
5
|
+
} from "./chunk-UJJCRV7W.mjs";
|
|
5
6
|
import {
|
|
6
7
|
__privateAdd,
|
|
7
8
|
__privateMethod
|
|
@@ -62,18 +63,21 @@ var SnapInterfaceController = class extends BaseController {
|
|
|
62
63
|
*
|
|
63
64
|
* @param snapId - The snap id that created the interface.
|
|
64
65
|
* @param content - The interface content.
|
|
66
|
+
* @param context - An optional interface context object.
|
|
65
67
|
* @returns The newly interface id.
|
|
66
68
|
*/
|
|
67
|
-
async createInterface(snapId, content) {
|
|
69
|
+
async createInterface(snapId, content, context) {
|
|
68
70
|
const element = getJsxInterface(content);
|
|
69
71
|
await __privateMethod(this, _validateContent, validateContent_fn).call(this, element);
|
|
72
|
+
validateInterfaceContext(context);
|
|
70
73
|
const id = nanoid();
|
|
71
74
|
const componentState = constructState({}, element);
|
|
72
75
|
this.update((draftState) => {
|
|
73
76
|
draftState.interfaces[id] = {
|
|
74
77
|
snapId,
|
|
75
78
|
content: element,
|
|
76
|
-
state: componentState
|
|
79
|
+
state: componentState,
|
|
80
|
+
context: context ?? null
|
|
77
81
|
};
|
|
78
82
|
});
|
|
79
83
|
return id;
|
|
@@ -186,4 +190,4 @@ validateContent_fn = async function(element) {
|
|
|
186
190
|
export {
|
|
187
191
|
SnapInterfaceController
|
|
188
192
|
};
|
|
189
|
-
//# sourceMappingURL=chunk-
|
|
193
|
+
//# sourceMappingURL=chunk-QLWR3M4Q.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/interface/SnapInterfaceController.ts"],"sourcesContent":["import type { RestrictedControllerMessenger } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type {\n MaybeUpdateState,\n TestOrigin,\n} from '@metamask/phishing-controller';\nimport type {\n InterfaceState,\n SnapId,\n ComponentOrElement,\n InterfaceContext,\n} from '@metamask/snaps-sdk';\nimport type { JSXElement } from '@metamask/snaps-sdk/jsx';\nimport { getJsonSizeUnsafe, validateJsxLinks } from '@metamask/snaps-utils';\nimport { assert } from '@metamask/utils';\nimport { nanoid } from 'nanoid';\n\nimport {\n constructState,\n getJsxInterface,\n validateInterfaceContext,\n} from './utils';\n\nconst MAX_UI_CONTENT_SIZE = 10_000_000; // 10 mb\n\nconst controllerName = 'SnapInterfaceController';\n\nexport type CreateInterface = {\n type: `${typeof controllerName}:createInterface`;\n handler: SnapInterfaceController['createInterface'];\n};\n\nexport type GetInterface = {\n type: `${typeof controllerName}:getInterface`;\n handler: SnapInterfaceController['getInterface'];\n};\n\nexport type UpdateInterface = {\n type: `${typeof controllerName}:updateInterface`;\n handler: SnapInterfaceController['updateInterface'];\n};\n\nexport type DeleteInterface = {\n type: `${typeof controllerName}:deleteInterface`;\n handler: SnapInterfaceController['deleteInterface'];\n};\n\nexport type UpdateInterfaceState = {\n type: `${typeof controllerName}:updateInterfaceState`;\n handler: SnapInterfaceController['updateInterfaceState'];\n};\n\nexport type SnapInterfaceControllerAllowedActions =\n | TestOrigin\n | MaybeUpdateState;\n\nexport type SnapInterfaceControllerActions =\n | CreateInterface\n | GetInterface\n | UpdateInterface\n | DeleteInterface\n | UpdateInterfaceState;\n\nexport type SnapInterfaceControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n SnapInterfaceControllerActions | SnapInterfaceControllerAllowedActions,\n never,\n SnapInterfaceControllerAllowedActions['type'],\n never\n>;\n\nexport type StoredInterface = {\n snapId: SnapId;\n content: JSXElement;\n state: InterfaceState;\n context: InterfaceContext | null;\n};\n\nexport type SnapInterfaceControllerState = {\n interfaces: Record<string, StoredInterface>;\n};\n\nexport type SnapInterfaceControllerArgs = {\n messenger: SnapInterfaceControllerMessenger;\n state?: SnapInterfaceControllerState;\n};\n\n/**\n * Use this controller to manage snaps UI interfaces using RPC method hooks.\n */\nexport class SnapInterfaceController extends BaseController<\n typeof controllerName,\n SnapInterfaceControllerState,\n SnapInterfaceControllerMessenger\n> {\n constructor({ messenger, state }: SnapInterfaceControllerArgs) {\n super({\n messenger,\n metadata: {\n interfaces: { persist: false, anonymous: false },\n },\n name: controllerName,\n state: { interfaces: {}, ...state },\n });\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:createInterface`,\n this.createInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:getInterface`,\n this.getInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateInterface`,\n this.updateInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:deleteInterface`,\n this.deleteInterface.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n `${controllerName}:updateInterfaceState`,\n this.updateInterfaceState.bind(this),\n );\n }\n\n /**\n * Create an interface in the controller state with the associated data.\n *\n * @param snapId - The snap id that created the interface.\n * @param content - The interface content.\n * @param context - An optional interface context object.\n * @returns The newly interface id.\n */\n async createInterface(\n snapId: SnapId,\n content: ComponentOrElement,\n context?: InterfaceContext,\n ) {\n const element = getJsxInterface(content);\n await this.#validateContent(element);\n validateInterfaceContext(context);\n\n const id = nanoid();\n const componentState = constructState({}, element);\n\n this.update((draftState) => {\n // @ts-expect-error - TS2589: Type instantiation is excessively deep and\n // possibly infinite.\n draftState.interfaces[id] = {\n snapId,\n content: element,\n state: componentState,\n context: context ?? null,\n };\n });\n\n return id;\n }\n\n /**\n * Get the data of a given interface id.\n *\n * @param snapId - The snap id requesting the interface data.\n * @param id - The interface id.\n * @returns The interface state.\n */\n getInterface(snapId: SnapId, id: string) {\n this.#validateArgs(snapId, id);\n\n return this.state.interfaces[id];\n }\n\n /**\n * Update the interface with the given content.\n *\n * @param snapId - The snap id requesting the update.\n * @param id - The interface id.\n * @param content - The new content.\n */\n async updateInterface(\n snapId: SnapId,\n id: string,\n content: ComponentOrElement,\n ) {\n this.#validateArgs(snapId, id);\n const element = getJsxInterface(content);\n await this.#validateContent(element);\n\n const oldState = this.state.interfaces[id].state;\n const newState = constructState(oldState, element);\n\n this.update((draftState) => {\n draftState.interfaces[id].state = newState;\n draftState.interfaces[id].content = element;\n });\n }\n\n /**\n * Delete an interface from state.\n *\n * @param id - The interface id.\n */\n deleteInterface(id: string) {\n this.update((draftState) => {\n delete draftState.interfaces[id];\n });\n }\n\n /**\n * Update the interface state.\n *\n * @param id - The interface id.\n * @param state - The new state.\n */\n updateInterfaceState(id: string, state: InterfaceState) {\n this.update((draftState) => {\n draftState.interfaces[id].state = state;\n });\n }\n\n /**\n * Utility function to validate the args passed to the other methods.\n *\n * @param snapId - The snap id.\n * @param id - The interface id.\n */\n #validateArgs(snapId: SnapId, id: string) {\n const existingInterface = this.state.interfaces[id];\n\n assert(\n existingInterface !== undefined,\n `Interface with id '${id}' not found.`,\n );\n assert(\n existingInterface.snapId === snapId,\n `Interface not created by ${snapId}.`,\n );\n }\n\n /**\n * Trigger a Phishing list update if needed.\n */\n async #triggerPhishingListUpdate() {\n await this.messagingSystem.call('PhishingController:maybeUpdateState');\n }\n\n /**\n * Check an origin against the phishing list.\n *\n * @param origin - The origin to check.\n * @returns True if the origin is on the phishing list, otherwise false.\n */\n #checkPhishingList(origin: string) {\n return this.messagingSystem.call('PhishingController:testOrigin', origin)\n .result;\n }\n\n /**\n * Utility function to validate the components of an interface.\n * Throws if something is invalid.\n *\n * @param element - The JSX element to verify.\n */\n async #validateContent(element: JSXElement) {\n // We assume the validity of this JSON to be validated by the caller.\n // E.g., in the RPC method implementation.\n const size = getJsonSizeUnsafe(element);\n assert(\n size <= MAX_UI_CONTENT_SIZE,\n `A Snap UI may not be larger than ${MAX_UI_CONTENT_SIZE / 1000000} MB.`,\n );\n\n await this.#triggerPhishingListUpdate();\n validateJsxLinks(element, this.#checkPhishingList.bind(this));\n }\n}\n"],"mappings":";;;;;;;;;;;AACA,SAAS,sBAAsB;AAY/B,SAAS,mBAAmB,wBAAwB;AACpD,SAAS,cAAc;AACvB,SAAS,cAAc;AAQvB,IAAM,sBAAsB;AAE5B,IAAM,iBAAiB;AAzBvB;AA0FO,IAAM,0BAAN,cAAsC,eAI3C;AAAA,EACA,YAAY,EAAE,WAAW,MAAM,GAAgC;AAC7D,UAAM;AAAA,MACJ;AAAA,MACA,UAAU;AAAA,QACR,YAAY,EAAE,SAAS,OAAO,WAAW,MAAM;AAAA,MACjD;AAAA,MACA,MAAM;AAAA,MACN,OAAO,EAAE,YAAY,CAAC,GAAG,GAAG,MAAM;AAAA,IACpC,CAAC;AASH;AAAA;AAAA;AAAA;AAAA;AAgIA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBA;AAAA;AAAA;AAAA,uBAAM;AAUN;AAAA;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EA,QAAM,sBAAK,0DAAL;AACN,mBAAiB,SAAS,sBAAK,0CAAmB,KAAK,IAAI,CAAC;AAC9D;","names":[]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkS775IABYjs = require('./chunk-S775IABY.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkEXN2TFDJjs = require('./chunk-EXN2TFDJ.js');
|
|
@@ -8,7 +8,7 @@ var _chunkEXN2TFDJjs = require('./chunk-EXN2TFDJ.js');
|
|
|
8
8
|
// src/services/node-js/NodeThreadExecutionService.ts
|
|
9
9
|
var _postmessagestream = require('@metamask/post-message-stream');
|
|
10
10
|
var _worker_threads = require('worker_threads');
|
|
11
|
-
var NodeThreadExecutionService = class extends
|
|
11
|
+
var NodeThreadExecutionService = class extends _chunkS775IABYjs.AbstractExecutionService {
|
|
12
12
|
async initEnvStream() {
|
|
13
13
|
const worker = new (0, _worker_threads.Worker)(
|
|
14
14
|
_chunkEXN2TFDJjs.__require.resolve(
|
|
@@ -36,4 +36,4 @@ var NodeThreadExecutionService = class extends _chunkSIW7ZXQFjs.AbstractExecutio
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
exports.NodeThreadExecutionService = NodeThreadExecutionService;
|
|
39
|
-
//# sourceMappingURL=chunk-
|
|
39
|
+
//# sourceMappingURL=chunk-RW7AYHRG.js.map
|