@metamask/snaps-controllers 9.1.0 → 9.3.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 +31 -1
- package/dist/{chunk-WP3DAIFM.mjs → chunk-23PVLQFV.mjs} +62 -2
- package/dist/chunk-23PVLQFV.mjs.map +1 -0
- package/dist/chunk-272IFIK7.mjs +1 -0
- package/dist/chunk-272IFIK7.mjs.map +1 -0
- package/dist/{chunk-42ODFZSH.mjs → chunk-2AEM5R2M.mjs} +4 -4
- package/dist/{chunk-RVWBSSZM.mjs → chunk-2MH7QYBP.mjs} +60 -11
- package/dist/chunk-2MH7QYBP.mjs.map +1 -0
- package/dist/chunk-2XQD4P2S.mjs +1 -0
- package/dist/chunk-2XQD4P2S.mjs.map +1 -0
- package/dist/{chunk-XSFI32LB.mjs → chunk-33RRV7F4.mjs} +1 -1
- package/dist/{chunk-SAAURQ5A.mjs → chunk-6WGCLJGC.mjs} +2 -2
- package/dist/{chunk-FPGAQ6MT.js → chunk-7BUNUNUC.js} +3 -3
- package/dist/{chunk-CDTGUNSA.js → chunk-B6KTRDBK.js} +9 -9
- package/dist/chunk-B6KTRDBK.js.map +1 -0
- package/dist/{chunk-3AANDIXT.js → chunk-D66YLO7T.js} +3 -3
- package/dist/{chunk-ZBSBCWWM.js → chunk-FKQTV3LO.js} +68 -19
- package/dist/chunk-FKQTV3LO.js.map +1 -0
- package/dist/{chunk-KH72WRHR.js → chunk-FZOI4WPB.js} +3 -3
- package/dist/chunk-G245VWEY.mjs +275 -0
- package/dist/chunk-G245VWEY.mjs.map +1 -0
- package/dist/{chunk-7IJQGFT5.mjs → chunk-HLQQTAMM.mjs} +2 -2
- package/dist/chunk-IDCWJJCQ.js +1 -0
- package/dist/chunk-IDCWJJCQ.js.map +1 -0
- package/dist/{chunk-BUHS4M6F.js → chunk-JLIW4CNS.js} +62 -2
- package/dist/chunk-JLIW4CNS.js.map +1 -0
- package/dist/{chunk-RW7AYHRG.js → chunk-KELDSV7H.js} +3 -3
- package/dist/{chunk-567BFPSL.mjs → chunk-KRI4OKC3.mjs} +10 -10
- package/dist/chunk-KRI4OKC3.mjs.map +1 -0
- package/dist/{chunk-PMZXFAQI.mjs → chunk-KYRKZ3RH.mjs} +2 -2
- package/dist/{chunk-LRVK45HN.mjs → chunk-LDL6LJ3P.mjs} +2 -2
- package/dist/chunk-M7DWHPVM.js +1 -0
- package/dist/chunk-M7DWHPVM.js.map +1 -0
- package/dist/{chunk-6ERB63FH.js → chunk-OVATPF5I.js} +3 -3
- package/dist/{chunk-HQ6HMINL.js → chunk-P66VIDFG.js} +3 -3
- package/dist/{chunk-PT22IXNS.js → chunk-POQSARDG.js} +3 -3
- package/dist/{chunk-ZRC46TUF.js → chunk-PYSDWIVK.js} +3 -3
- package/dist/{chunk-S775IABY.js → chunk-QRISQRFI.js} +13 -14
- package/dist/{chunk-S775IABY.js.map → chunk-QRISQRFI.js.map} +1 -1
- package/dist/chunk-QYQLJCPR.js +275 -0
- package/dist/chunk-QYQLJCPR.js.map +1 -0
- package/dist/{chunk-QLFH3MC6.mjs → chunk-TSDUJNOP.mjs} +5 -6
- package/dist/chunk-TSDUJNOP.mjs.map +1 -0
- package/dist/{chunk-YUWYMNIX.mjs → chunk-VKMY6CKT.mjs} +2 -2
- package/dist/{chunk-CIFVYFJW.mjs → chunk-WR7CVDEY.mjs} +2 -2
- package/dist/{chunk-GRBWVPLF.js → chunk-XFUP7RFI.js} +1 -1
- package/dist/{chunk-3A72M4GC.mjs → chunk-XOSHP4J3.mjs} +2 -2
- package/dist/cronjob/CronjobController.js +19 -17
- package/dist/cronjob/CronjobController.mjs +18 -16
- package/dist/cronjob/index.js +19 -17
- package/dist/cronjob/index.mjs +18 -16
- package/dist/index.js +31 -28
- package/dist/index.mjs +31 -28
- package/dist/insights/SnapInsightsController.js +25 -0
- package/dist/insights/SnapInsightsController.js.map +1 -0
- package/dist/insights/SnapInsightsController.mjs +25 -0
- package/dist/insights/SnapInsightsController.mjs.map +1 -0
- package/dist/insights/index.js +26 -0
- package/dist/insights/index.js.map +1 -0
- package/dist/insights/index.mjs +26 -0
- package/dist/insights/index.mjs.map +1 -0
- package/dist/interface/SnapInterfaceController.js +2 -2
- package/dist/interface/SnapInterfaceController.mjs +1 -1
- package/dist/interface/index.js +2 -2
- package/dist/interface/index.mjs +1 -1
- package/dist/node.js +33 -30
- package/dist/node.mjs +35 -32
- package/dist/react-native.js +32 -29
- package/dist/react-native.mjs +32 -29
- package/dist/services/AbstractExecutionService.js +3 -3
- package/dist/services/AbstractExecutionService.mjs +2 -2
- package/dist/services/browser.js +10 -10
- package/dist/services/browser.mjs +10 -10
- 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 +9 -9
- package/dist/services/index.mjs +9 -9
- package/dist/services/node-js/NodeProcessExecutionService.js +9 -9
- package/dist/services/node-js/NodeProcessExecutionService.mjs +8 -8
- package/dist/services/node-js/NodeThreadExecutionService.js +9 -9
- package/dist/services/node-js/NodeThreadExecutionService.mjs +8 -8
- package/dist/services/node-js/index.js +10 -10
- package/dist/services/node-js/index.mjs +11 -11
- package/dist/services/node.js +11 -11
- package/dist/services/node.mjs +13 -13
- 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 +10 -10
- package/dist/services/react-native.mjs +10 -10
- 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 +5 -5
- package/dist/snaps/SnapController.mjs +4 -4
- package/dist/snaps/index.js +10 -10
- package/dist/snaps/index.mjs +9 -9
- package/dist/snaps/location/index.js +4 -4
- package/dist/snaps/location/index.mjs +4 -4
- package/dist/snaps/location/location.js +3 -3
- package/dist/snaps/location/location.mjs +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/controllers.js +2 -0
- package/dist/types/controllers.js.map +1 -0
- package/dist/types/controllers.mjs +2 -0
- package/dist/types/controllers.mjs.map +1 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.js +2 -1
- package/dist/types/index.mjs +1 -0
- package/dist/types/insights/SnapInsightsController.d.ts +33 -0
- package/dist/types/insights/index.d.ts +1 -0
- package/dist/types/interface/SnapInterfaceController.d.ts +17 -2
- package/dist/types/snaps/SnapController.d.ts +1 -0
- package/dist/types/types/controllers.d.ts +131 -0
- package/dist/types/types/index.d.ts +1 -0
- package/dist/types/utils.d.ts +0 -13
- package/dist/utils.js +2 -4
- package/dist/utils.mjs +1 -3
- package/package.json +10 -10
- package/dist/chunk-567BFPSL.mjs.map +0 -1
- package/dist/chunk-BUHS4M6F.js.map +0 -1
- package/dist/chunk-CDTGUNSA.js.map +0 -1
- package/dist/chunk-QLFH3MC6.mjs.map +0 -1
- package/dist/chunk-RVWBSSZM.mjs.map +0 -1
- package/dist/chunk-WP3DAIFM.mjs.map +0 -1
- package/dist/chunk-ZBSBCWWM.js.map +0 -1
- /package/dist/{chunk-42ODFZSH.mjs.map → chunk-2AEM5R2M.mjs.map} +0 -0
- /package/dist/{chunk-XSFI32LB.mjs.map → chunk-33RRV7F4.mjs.map} +0 -0
- /package/dist/{chunk-SAAURQ5A.mjs.map → chunk-6WGCLJGC.mjs.map} +0 -0
- /package/dist/{chunk-FPGAQ6MT.js.map → chunk-7BUNUNUC.js.map} +0 -0
- /package/dist/{chunk-3AANDIXT.js.map → chunk-D66YLO7T.js.map} +0 -0
- /package/dist/{chunk-KH72WRHR.js.map → chunk-FZOI4WPB.js.map} +0 -0
- /package/dist/{chunk-7IJQGFT5.mjs.map → chunk-HLQQTAMM.mjs.map} +0 -0
- /package/dist/{chunk-RW7AYHRG.js.map → chunk-KELDSV7H.js.map} +0 -0
- /package/dist/{chunk-PMZXFAQI.mjs.map → chunk-KYRKZ3RH.mjs.map} +0 -0
- /package/dist/{chunk-LRVK45HN.mjs.map → chunk-LDL6LJ3P.mjs.map} +0 -0
- /package/dist/{chunk-6ERB63FH.js.map → chunk-OVATPF5I.js.map} +0 -0
- /package/dist/{chunk-HQ6HMINL.js.map → chunk-P66VIDFG.js.map} +0 -0
- /package/dist/{chunk-PT22IXNS.js.map → chunk-POQSARDG.js.map} +0 -0
- /package/dist/{chunk-ZRC46TUF.js.map → chunk-PYSDWIVK.js.map} +0 -0
- /package/dist/{chunk-YUWYMNIX.mjs.map → chunk-VKMY6CKT.mjs.map} +0 -0
- /package/dist/{chunk-CIFVYFJW.mjs.map → chunk-WR7CVDEY.mjs.map} +0 -0
- /package/dist/{chunk-GRBWVPLF.js.map → chunk-XFUP7RFI.js.map} +0 -0
- /package/dist/{chunk-3A72M4GC.mjs.map → chunk-XOSHP4J3.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [9.3.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Add `snap_resolveInterface` RPC method to the `SnapInterfaceController` ([#2509](https://github.com/metamask/snaps/pull/2509))
|
|
12
|
+
- Add `SnapInsightsController` ([#2555](https://github.com/metamask/snaps/pull/2555))
|
|
13
|
+
|
|
14
|
+
### Changed
|
|
15
|
+
- Bump `@metamask/base-controller` from `^6.0.0` to `^6.0.1` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
|
|
16
|
+
- Bump `@metamask/permission-controller` from `^10.0.0` to `^10.0.1` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
|
|
17
|
+
- Bump `@metamask/rpc-errors` from `^6.2.1` to `^6.3.1` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
|
|
18
|
+
- Bump `@metamask/snaps-registry` from `^3.1.0` to `^3.2.1` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
|
|
19
|
+
- Bump `@metamask/snaps-rpc-methods` to `^10.0.0` ([#2589](https://github.com/MetaMask/snaps/pull/2589))
|
|
20
|
+
- Bump `@metamask/snaps-sdk` to `^6.1.0` ([#2589](https://github.com/MetaMask/snaps/pull/2589))
|
|
21
|
+
- Bump `@metamask/snaps-utils` to `^7.8.0` ([#2589](https://github.com/MetaMask/snaps/pull/2589))
|
|
22
|
+
- Bump `@metamask/utils` from `^8.3.0` to `^9.1.0` ([#2445](https://github.com/MetaMask/snaps/pull/2445))
|
|
23
|
+
- Bump peer dependency `@metamask/snaps-execution-environments` to `^6.6.1` ([#2589](https://github.com/MetaMask/snaps/pull/2589))
|
|
24
|
+
|
|
25
|
+
### Fixed
|
|
26
|
+
- Handle initial connections for preinstalled Snaps ([#2591](https://github.com/MetaMask/snaps/pull/2591))
|
|
27
|
+
- Account for revoked origins when calculating the difference in `initialConnections` ([#2535](https://github.com/metamask/snaps/pull/2535))
|
|
28
|
+
- Fixes issue of revoking permissions that are already revoked.
|
|
29
|
+
- Enables revoked connections to be highlighted as being re-added in the UI.
|
|
30
|
+
- Enforce stricter size limits for source code, static auxiliary files, and `snap_getFile` return values ([#2527](https://github.com/metamask/snaps/pull/2527))
|
|
31
|
+
- Prevent communication failures by enabling compliance with JSON-RPC extension message requirements.
|
|
32
|
+
|
|
33
|
+
## [9.2.0]
|
|
34
|
+
### Added
|
|
35
|
+
- Add feature flag to disable Snap installation ([#2521](https://github.com/MetaMask/snaps/pull/2521))
|
|
36
|
+
|
|
9
37
|
## [9.1.0]
|
|
10
38
|
### Added
|
|
11
39
|
- Add `Checkbox` component ([#2501](https://github.com/MetaMask/snaps/pull/2501))
|
|
@@ -303,7 +331,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
303
331
|
- The version of the package no longer needs to match the version of all other
|
|
304
332
|
MetaMask Snaps packages.
|
|
305
333
|
|
|
306
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.
|
|
334
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.3.0...HEAD
|
|
335
|
+
[9.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.2.0...@metamask/snaps-controllers@9.3.0
|
|
336
|
+
[9.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.1.0...@metamask/snaps-controllers@9.2.0
|
|
307
337
|
[9.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.0.0...@metamask/snaps-controllers@9.1.0
|
|
308
338
|
[9.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.4.0...@metamask/snaps-controllers@9.0.0
|
|
309
339
|
[8.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.3.1...@metamask/snaps-controllers@8.4.0
|
|
@@ -15,7 +15,7 @@ import { assert } from "@metamask/utils";
|
|
|
15
15
|
import { nanoid } from "nanoid";
|
|
16
16
|
var MAX_UI_CONTENT_SIZE = 1e7;
|
|
17
17
|
var controllerName = "SnapInterfaceController";
|
|
18
|
-
var _registerMessageHandlers, registerMessageHandlers_fn, _validateArgs, validateArgs_fn, _triggerPhishingListUpdate, triggerPhishingListUpdate_fn, _checkPhishingList, checkPhishingList_fn, _validateContent, validateContent_fn;
|
|
18
|
+
var _registerMessageHandlers, registerMessageHandlers_fn, _validateArgs, validateArgs_fn, _validateApproval, validateApproval_fn, _triggerPhishingListUpdate, triggerPhishingListUpdate_fn, _checkPhishingList, checkPhishingList_fn, _hasApprovalRequest, hasApprovalRequest_fn, _acceptApprovalRequest, acceptApprovalRequest_fn, _validateContent, validateContent_fn;
|
|
19
19
|
var SnapInterfaceController = class extends BaseController {
|
|
20
20
|
constructor({ messenger, state }) {
|
|
21
21
|
super({
|
|
@@ -38,6 +38,12 @@ var SnapInterfaceController = class extends BaseController {
|
|
|
38
38
|
* @param id - The interface id.
|
|
39
39
|
*/
|
|
40
40
|
__privateAdd(this, _validateArgs);
|
|
41
|
+
/**
|
|
42
|
+
* Utility function to validate that the approval request exists.
|
|
43
|
+
*
|
|
44
|
+
* @param id - The interface id.
|
|
45
|
+
*/
|
|
46
|
+
__privateAdd(this, _validateApproval);
|
|
41
47
|
/**
|
|
42
48
|
* Trigger a Phishing list update if needed.
|
|
43
49
|
*/
|
|
@@ -49,6 +55,21 @@ var SnapInterfaceController = class extends BaseController {
|
|
|
49
55
|
* @returns True if the origin is on the phishing list, otherwise false.
|
|
50
56
|
*/
|
|
51
57
|
__privateAdd(this, _checkPhishingList);
|
|
58
|
+
/**
|
|
59
|
+
* Check if an approval request exists for a given interface by looking up
|
|
60
|
+
* if the ApprovalController has a request with the given interface ID.
|
|
61
|
+
*
|
|
62
|
+
* @param id - The interface id.
|
|
63
|
+
* @returns True if an approval request exists, otherwise false.
|
|
64
|
+
*/
|
|
65
|
+
__privateAdd(this, _hasApprovalRequest);
|
|
66
|
+
/**
|
|
67
|
+
* Accept an approval request for a given interface.
|
|
68
|
+
*
|
|
69
|
+
* @param id - The interface id.
|
|
70
|
+
* @param value - The value to resolve the promise with.
|
|
71
|
+
*/
|
|
72
|
+
__privateAdd(this, _acceptApprovalRequest);
|
|
52
73
|
/**
|
|
53
74
|
* Utility function to validate the components of an interface.
|
|
54
75
|
* Throws if something is invalid.
|
|
@@ -132,6 +153,20 @@ var SnapInterfaceController = class extends BaseController {
|
|
|
132
153
|
draftState.interfaces[id].state = state;
|
|
133
154
|
});
|
|
134
155
|
}
|
|
156
|
+
/**
|
|
157
|
+
* Resolve the promise of a given interface approval request.
|
|
158
|
+
* The approval needs to have the same ID as the interface.
|
|
159
|
+
*
|
|
160
|
+
* @param snapId - The snap id.
|
|
161
|
+
* @param id - The interface id.
|
|
162
|
+
* @param value - The value to resolve the promise with.
|
|
163
|
+
*/
|
|
164
|
+
async resolveInterface(snapId, id, value) {
|
|
165
|
+
__privateMethod(this, _validateArgs, validateArgs_fn).call(this, snapId, id);
|
|
166
|
+
__privateMethod(this, _validateApproval, validateApproval_fn).call(this, id);
|
|
167
|
+
await __privateMethod(this, _acceptApprovalRequest, acceptApprovalRequest_fn).call(this, id, value);
|
|
168
|
+
this.deleteInterface(id);
|
|
169
|
+
}
|
|
135
170
|
};
|
|
136
171
|
_registerMessageHandlers = new WeakSet();
|
|
137
172
|
registerMessageHandlers_fn = function() {
|
|
@@ -155,6 +190,10 @@ registerMessageHandlers_fn = function() {
|
|
|
155
190
|
`${controllerName}:updateInterfaceState`,
|
|
156
191
|
this.updateInterfaceState.bind(this)
|
|
157
192
|
);
|
|
193
|
+
this.messagingSystem.registerActionHandler(
|
|
194
|
+
`${controllerName}:resolveInterface`,
|
|
195
|
+
this.resolveInterface.bind(this)
|
|
196
|
+
);
|
|
158
197
|
};
|
|
159
198
|
_validateArgs = new WeakSet();
|
|
160
199
|
validateArgs_fn = function(snapId, id) {
|
|
@@ -168,6 +207,13 @@ validateArgs_fn = function(snapId, id) {
|
|
|
168
207
|
`Interface not created by ${snapId}.`
|
|
169
208
|
);
|
|
170
209
|
};
|
|
210
|
+
_validateApproval = new WeakSet();
|
|
211
|
+
validateApproval_fn = function(id) {
|
|
212
|
+
assert(
|
|
213
|
+
__privateMethod(this, _hasApprovalRequest, hasApprovalRequest_fn).call(this, id),
|
|
214
|
+
`Approval request with id '${id}' not found.`
|
|
215
|
+
);
|
|
216
|
+
};
|
|
171
217
|
_triggerPhishingListUpdate = new WeakSet();
|
|
172
218
|
triggerPhishingListUpdate_fn = async function() {
|
|
173
219
|
await this.messagingSystem.call("PhishingController:maybeUpdateState");
|
|
@@ -176,6 +222,20 @@ _checkPhishingList = new WeakSet();
|
|
|
176
222
|
checkPhishingList_fn = function(origin) {
|
|
177
223
|
return this.messagingSystem.call("PhishingController:testOrigin", origin).result;
|
|
178
224
|
};
|
|
225
|
+
_hasApprovalRequest = new WeakSet();
|
|
226
|
+
hasApprovalRequest_fn = function(id) {
|
|
227
|
+
return this.messagingSystem.call("ApprovalController:hasRequest", {
|
|
228
|
+
id
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
_acceptApprovalRequest = new WeakSet();
|
|
232
|
+
acceptApprovalRequest_fn = async function(id, value) {
|
|
233
|
+
await this.messagingSystem.call(
|
|
234
|
+
"ApprovalController:acceptRequest",
|
|
235
|
+
id,
|
|
236
|
+
value
|
|
237
|
+
);
|
|
238
|
+
};
|
|
179
239
|
_validateContent = new WeakSet();
|
|
180
240
|
validateContent_fn = async function(element) {
|
|
181
241
|
const size = getJsonSizeUnsafe(element);
|
|
@@ -190,4 +250,4 @@ validateContent_fn = async function(element) {
|
|
|
190
250
|
export {
|
|
191
251
|
SnapInterfaceController
|
|
192
252
|
};
|
|
193
|
-
//# sourceMappingURL=chunk-
|
|
253
|
+
//# sourceMappingURL=chunk-23PVLQFV.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/interface/SnapInterfaceController.ts"],"sourcesContent":["import type {\n AcceptRequest,\n HasApprovalRequest,\n} from '@metamask/approval-controller';\nimport 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 type { Json } from '@metamask/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 ResolveInterface = {\n type: `${typeof controllerName}:resolveInterface`;\n handler: SnapInterfaceController['resolveInterface'];\n};\n\nexport type SnapInterfaceControllerAllowedActions =\n | TestOrigin\n | MaybeUpdateState\n | HasApprovalRequest\n | AcceptRequest;\n\nexport type SnapInterfaceControllerActions =\n | CreateInterface\n | GetInterface\n | UpdateInterface\n | DeleteInterface\n | UpdateInterfaceState\n | ResolveInterface;\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 this.messagingSystem.registerActionHandler(\n `${controllerName}:resolveInterface`,\n this.resolveInterface.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 * Resolve the promise of a given interface approval request.\n * The approval needs to have the same ID as the interface.\n *\n * @param snapId - The snap id.\n * @param id - The interface id.\n * @param value - The value to resolve the promise with.\n */\n async resolveInterface(snapId: SnapId, id: string, value: Json) {\n this.#validateArgs(snapId, id);\n this.#validateApproval(id);\n\n await this.#acceptApprovalRequest(id, value);\n\n this.deleteInterface(id);\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 * Utility function to validate that the approval request exists.\n *\n * @param id - The interface id.\n */\n #validateApproval(id: string) {\n assert(\n this.#hasApprovalRequest(id),\n `Approval request with id '${id}' not found.`,\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 * Check if an approval request exists for a given interface by looking up\n * if the ApprovalController has a request with the given interface ID.\n *\n * @param id - The interface id.\n * @returns True if an approval request exists, otherwise false.\n */\n #hasApprovalRequest(id: string) {\n return this.messagingSystem.call('ApprovalController:hasRequest', {\n id,\n });\n }\n\n /**\n * Accept an approval request for a given interface.\n *\n * @param id - The interface id.\n * @param value - The value to resolve the promise with.\n */\n async #acceptApprovalRequest(id: string, value: Json) {\n await this.messagingSystem.call(\n 'ApprovalController:acceptRequest',\n id,\n value,\n );\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":"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","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=chunk-272IFIK7.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import {
|
|
2
2
|
LocalLocation
|
|
3
3
|
} from "./chunk-B3UTLNYS.mjs";
|
|
4
|
-
import {
|
|
5
|
-
NpmLocation
|
|
6
|
-
} from "./chunk-WKQRCGUW.mjs";
|
|
7
4
|
import {
|
|
8
5
|
HttpLocation
|
|
9
6
|
} from "./chunk-6GMWL4JR.mjs";
|
|
7
|
+
import {
|
|
8
|
+
NpmLocation
|
|
9
|
+
} from "./chunk-WKQRCGUW.mjs";
|
|
10
10
|
|
|
11
11
|
// src/snaps/location/location.ts
|
|
12
12
|
import { assert } from "@metamask/utils";
|
|
@@ -37,4 +37,4 @@ function detectSnapLocation(location, opts) {
|
|
|
37
37
|
export {
|
|
38
38
|
detectSnapLocation
|
|
39
39
|
};
|
|
40
|
-
//# sourceMappingURL=chunk-
|
|
40
|
+
//# sourceMappingURL=chunk-2AEM5R2M.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
detectSnapLocation
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-2AEM5R2M.mjs";
|
|
4
4
|
import {
|
|
5
5
|
RequestQueue
|
|
6
6
|
} from "./chunk-NC5PBDKD.mjs";
|
|
@@ -16,13 +16,12 @@ import {
|
|
|
16
16
|
log
|
|
17
17
|
} from "./chunk-4HVWEABQ.mjs";
|
|
18
18
|
import {
|
|
19
|
-
calculateConnectionsChange,
|
|
20
19
|
fetchSnap,
|
|
21
20
|
hasTimedOut,
|
|
22
21
|
permissionsDiff,
|
|
23
22
|
setDiff,
|
|
24
23
|
withTimeout
|
|
25
|
-
} from "./chunk-
|
|
24
|
+
} from "./chunk-KRI4OKC3.mjs";
|
|
26
25
|
import {
|
|
27
26
|
Timer
|
|
28
27
|
} from "./chunk-XO7KDFBY.mjs";
|
|
@@ -71,7 +70,8 @@ import {
|
|
|
71
70
|
NpmSnapFileNames,
|
|
72
71
|
OnNameLookupResponseStruct,
|
|
73
72
|
getLocalizedSnapManifest,
|
|
74
|
-
parseJson
|
|
73
|
+
parseJson,
|
|
74
|
+
MAX_FILE_SIZE
|
|
75
75
|
} from "@metamask/snaps-utils";
|
|
76
76
|
import {
|
|
77
77
|
assert,
|
|
@@ -119,7 +119,7 @@ function truncateSnap(snap) {
|
|
|
119
119
|
return truncatedSnap;
|
|
120
120
|
}
|
|
121
121
|
var name = "SnapController";
|
|
122
|
-
var _closeAllConnections, _dynamicPermissions, _environmentEndowmentPermissions, _excludedPermissions, _featureFlags, _fetchFunction, _idleTimeCheckInterval, _maxIdleTime, _encryptor, _getMnemonic, _getFeatureFlags, _detectSnapLocation, _snapsRuntimeData, _rollbackSnapshots, _timeoutForLastRequestStatus, _statusMachine, _preinstalledSnaps, _initializeStateMachine, initializeStateMachine_fn, _registerMessageHandlers, registerMessageHandlers_fn, _handlePreinstalledSnaps, handlePreinstalledSnaps_fn, _pollForLastRequestStatus, pollForLastRequestStatus_fn, _blockSnap, blockSnap_fn, _unblockSnap, unblockSnap_fn, _assertIsInstallAllowed, assertIsInstallAllowed_fn, _assertCanUsePlatform, assertCanUsePlatform_fn, _stopSnapsLastRequestPastMax, stopSnapsLastRequestPastMax_fn, _transition, transition_fn, _terminateSnap, terminateSnap_fn, _getSnapEncryptionKey, getSnapEncryptionKey_fn, _decryptSnapState, decryptSnapState_fn, _encryptSnapState, encryptSnapState_fn, _handleInitialConnections, handleInitialConnections_fn, _addSnapToSubject, addSnapToSubject_fn, _removeSnapFromSubjects, removeSnapFromSubjects_fn, _revokeAllSnapPermissions, revokeAllSnapPermissions_fn, _createApproval, createApproval_fn, _updateApproval, updateApproval_fn, _resolveAllowlistVersion, resolveAllowlistVersion_fn, _add, add_fn, _startSnap, startSnap_fn, _getEndowments, getEndowments_fn, _set, set_fn, _validateSnapPermissions, validateSnapPermissions_fn, _getExecutionTimeout, getExecutionTimeout_fn, _getRpcRequestHandler, getRpcRequestHandler_fn, _createInterface, createInterface_fn, _assertInterfaceExists, assertInterfaceExists_fn, _transformSnapRpcRequestResult, transformSnapRpcRequestResult_fn, _assertSnapRpcRequestResult, assertSnapRpcRequestResult_fn, _recordSnapRpcRequestStart, recordSnapRpcRequestStart_fn, _recordSnapRpcRequestFinish, recordSnapRpcRequestFinish_fn, _getRollbackSnapshot, getRollbackSnapshot_fn, _createRollbackSnapshot, createRollbackSnapshot_fn, _rollbackSnap, rollbackSnap_fn, _rollbackSnaps, rollbackSnaps_fn, _getRuntime, getRuntime_fn, _getRuntimeExpect, getRuntimeExpect_fn, _setupRuntime, setupRuntime_fn, _calculatePermissionsChange, calculatePermissionsChange_fn, _updatePermissions, updatePermissions_fn, _isValidUpdate, isValidUpdate_fn, _callLifecycleHook, callLifecycleHook_fn;
|
|
122
|
+
var _closeAllConnections, _dynamicPermissions, _environmentEndowmentPermissions, _excludedPermissions, _featureFlags, _fetchFunction, _idleTimeCheckInterval, _maxIdleTime, _encryptor, _getMnemonic, _getFeatureFlags, _detectSnapLocation, _snapsRuntimeData, _rollbackSnapshots, _timeoutForLastRequestStatus, _statusMachine, _preinstalledSnaps, _initializeStateMachine, initializeStateMachine_fn, _registerMessageHandlers, registerMessageHandlers_fn, _handlePreinstalledSnaps, handlePreinstalledSnaps_fn, _pollForLastRequestStatus, pollForLastRequestStatus_fn, _blockSnap, blockSnap_fn, _unblockSnap, unblockSnap_fn, _assertIsInstallAllowed, assertIsInstallAllowed_fn, _assertCanInstallSnaps, assertCanInstallSnaps_fn, _assertCanUsePlatform, assertCanUsePlatform_fn, _stopSnapsLastRequestPastMax, stopSnapsLastRequestPastMax_fn, _transition, transition_fn, _terminateSnap, terminateSnap_fn, _getSnapEncryptionKey, getSnapEncryptionKey_fn, _decryptSnapState, decryptSnapState_fn, _encryptSnapState, encryptSnapState_fn, _handleInitialConnections, handleInitialConnections_fn, _addSnapToSubject, addSnapToSubject_fn, _removeSnapFromSubjects, removeSnapFromSubjects_fn, _revokeAllSnapPermissions, revokeAllSnapPermissions_fn, _createApproval, createApproval_fn, _updateApproval, updateApproval_fn, _resolveAllowlistVersion, resolveAllowlistVersion_fn, _add, add_fn, _startSnap, startSnap_fn, _getEndowments, getEndowments_fn, _set, set_fn, _validateSnapPermissions, validateSnapPermissions_fn, _getExecutionTimeout, getExecutionTimeout_fn, _getRpcRequestHandler, getRpcRequestHandler_fn, _createInterface, createInterface_fn, _assertInterfaceExists, assertInterfaceExists_fn, _transformSnapRpcRequestResult, transformSnapRpcRequestResult_fn, _assertSnapRpcRequestResult, assertSnapRpcRequestResult_fn, _recordSnapRpcRequestStart, recordSnapRpcRequestStart_fn, _recordSnapRpcRequestFinish, recordSnapRpcRequestFinish_fn, _getRollbackSnapshot, getRollbackSnapshot_fn, _createRollbackSnapshot, createRollbackSnapshot_fn, _rollbackSnap, rollbackSnap_fn, _rollbackSnaps, rollbackSnaps_fn, _getRuntime, getRuntime_fn, _getRuntimeExpect, getRuntimeExpect_fn, _setupRuntime, setupRuntime_fn, _calculatePermissionsChange, calculatePermissionsChange_fn, _isSubjectConnectedToSnap, isSubjectConnectedToSnap_fn, _calculateConnectionsChange, calculateConnectionsChange_fn, _updatePermissions, updatePermissions_fn, _isValidUpdate, isValidUpdate_fn, _callLifecycleHook, callLifecycleHook_fn;
|
|
123
123
|
var SnapController = class extends BaseController {
|
|
124
124
|
constructor({
|
|
125
125
|
closeAllConnections,
|
|
@@ -206,6 +206,10 @@ var SnapController = class extends BaseController {
|
|
|
206
206
|
*/
|
|
207
207
|
__privateAdd(this, _unblockSnap);
|
|
208
208
|
__privateAdd(this, _assertIsInstallAllowed);
|
|
209
|
+
/**
|
|
210
|
+
* Asserts whether new Snaps are allowed to be installed.
|
|
211
|
+
*/
|
|
212
|
+
__privateAdd(this, _assertCanInstallSnaps);
|
|
209
213
|
/**
|
|
210
214
|
* Asserts whether the Snaps platform is allowed to run.
|
|
211
215
|
*/
|
|
@@ -401,6 +405,8 @@ var SnapController = class extends BaseController {
|
|
|
401
405
|
__privateAdd(this, _getRuntimeExpect);
|
|
402
406
|
__privateAdd(this, _setupRuntime);
|
|
403
407
|
__privateAdd(this, _calculatePermissionsChange);
|
|
408
|
+
__privateAdd(this, _isSubjectConnectedToSnap);
|
|
409
|
+
__privateAdd(this, _calculateConnectionsChange);
|
|
404
410
|
/**
|
|
405
411
|
* Updates the permissions for a snap following an install, update or rollback.
|
|
406
412
|
*
|
|
@@ -805,7 +811,12 @@ var SnapController = class extends BaseController {
|
|
|
805
811
|
if (!value) {
|
|
806
812
|
return null;
|
|
807
813
|
}
|
|
808
|
-
|
|
814
|
+
const encoded = await encodeAuxiliaryFile(value, encoding);
|
|
815
|
+
assert(
|
|
816
|
+
encoded.length < MAX_FILE_SIZE,
|
|
817
|
+
`Failed to encode static file to "${encoding}": Static files must be less than 64 MB when encoded.`
|
|
818
|
+
);
|
|
819
|
+
return encoded;
|
|
809
820
|
}
|
|
810
821
|
/**
|
|
811
822
|
* Completely clear the controller's state: delete all associated data,
|
|
@@ -1100,6 +1111,7 @@ var SnapController = class extends BaseController {
|
|
|
1100
1111
|
false
|
|
1101
1112
|
);
|
|
1102
1113
|
}
|
|
1114
|
+
__privateMethod(this, _assertCanInstallSnaps, assertCanInstallSnaps_fn).call(this);
|
|
1103
1115
|
let pendingApproval = __privateMethod(this, _createApproval, createApproval_fn).call(this, {
|
|
1104
1116
|
origin,
|
|
1105
1117
|
snapId,
|
|
@@ -1178,6 +1190,7 @@ var SnapController = class extends BaseController {
|
|
|
1178
1190
|
* @returns The snap metadata if updated, `null` otherwise.
|
|
1179
1191
|
*/
|
|
1180
1192
|
async updateSnap(origin, snapId, location, newVersionRange = DEFAULT_REQUESTED_SNAP_VERSION, emitEvent = true) {
|
|
1193
|
+
__privateMethod(this, _assertCanInstallSnaps, assertCanInstallSnaps_fn).call(this);
|
|
1181
1194
|
__privateMethod(this, _assertCanUsePlatform, assertCanUsePlatform_fn).call(this);
|
|
1182
1195
|
if (!isValidSemVerRange(newVersionRange)) {
|
|
1183
1196
|
throw new Error(
|
|
@@ -1222,10 +1235,7 @@ var SnapController = class extends BaseController {
|
|
|
1222
1235
|
);
|
|
1223
1236
|
__privateMethod(this, _validateSnapPermissions, validateSnapPermissions_fn).call(this, processedPermissions);
|
|
1224
1237
|
const { newPermissions, unusedPermissions, approvedPermissions } = __privateMethod(this, _calculatePermissionsChange, calculatePermissionsChange_fn).call(this, snapId, processedPermissions);
|
|
1225
|
-
const { newConnections, unusedConnections, approvedConnections } =
|
|
1226
|
-
oldManifest.initialConnections ?? {},
|
|
1227
|
-
manifest.initialConnections ?? {}
|
|
1228
|
-
);
|
|
1238
|
+
const { newConnections, unusedConnections, approvedConnections } = __privateMethod(this, _calculateConnectionsChange, calculateConnectionsChange_fn).call(this, snapId, oldManifest.initialConnections ?? {}, manifest.initialConnections ?? {});
|
|
1229
1239
|
__privateMethod(this, _updateApproval, updateApproval_fn).call(this, pendingApproval.id, {
|
|
1230
1240
|
permissions: newPermissions,
|
|
1231
1241
|
newVersion: manifest.version,
|
|
@@ -1662,6 +1672,9 @@ handlePreinstalledSnaps_fn = function(preinstalledSnaps) {
|
|
|
1662
1672
|
__privateMethod(this, _validateSnapPermissions, validateSnapPermissions_fn).call(this, processedPermissions);
|
|
1663
1673
|
const { newPermissions, unusedPermissions } = __privateMethod(this, _calculatePermissionsChange, calculatePermissionsChange_fn).call(this, snapId, processedPermissions);
|
|
1664
1674
|
__privateMethod(this, _updatePermissions, updatePermissions_fn).call(this, { snapId, newPermissions, unusedPermissions });
|
|
1675
|
+
if (manifest.initialConnections) {
|
|
1676
|
+
__privateMethod(this, _handleInitialConnections, handleInitialConnections_fn).call(this, snapId, existingSnap?.initialConnections ?? null, manifest.initialConnections);
|
|
1677
|
+
}
|
|
1665
1678
|
this.update((state) => {
|
|
1666
1679
|
state.snaps[snapId].status = SnapStatus.Stopped;
|
|
1667
1680
|
});
|
|
@@ -1730,6 +1743,13 @@ assertIsInstallAllowed_fn = async function(snapId, snapInfo) {
|
|
|
1730
1743
|
);
|
|
1731
1744
|
}
|
|
1732
1745
|
};
|
|
1746
|
+
_assertCanInstallSnaps = new WeakSet();
|
|
1747
|
+
assertCanInstallSnaps_fn = function() {
|
|
1748
|
+
assert(
|
|
1749
|
+
__privateGet(this, _featureFlags).disableSnapInstallation !== true,
|
|
1750
|
+
"Installing Snaps is currently disabled in this version of MetaMask."
|
|
1751
|
+
);
|
|
1752
|
+
};
|
|
1733
1753
|
_assertCanUsePlatform = new WeakSet();
|
|
1734
1754
|
assertCanUsePlatform_fn = function() {
|
|
1735
1755
|
const flags = __privateGet(this, _getFeatureFlags).call(this);
|
|
@@ -2434,6 +2454,35 @@ calculatePermissionsChange_fn = function(snapId, desiredPermissionsSet) {
|
|
|
2434
2454
|
);
|
|
2435
2455
|
return { newPermissions, unusedPermissions, approvedPermissions };
|
|
2436
2456
|
};
|
|
2457
|
+
_isSubjectConnectedToSnap = new WeakSet();
|
|
2458
|
+
isSubjectConnectedToSnap_fn = function(snapId, origin) {
|
|
2459
|
+
const subjectPermissions = this.messagingSystem.call(
|
|
2460
|
+
"PermissionController:getPermissions",
|
|
2461
|
+
origin
|
|
2462
|
+
);
|
|
2463
|
+
const existingCaveat = subjectPermissions?.[WALLET_SNAP_PERMISSION_KEY]?.caveats?.find((caveat) => caveat.type === SnapCaveatType.SnapIds);
|
|
2464
|
+
return Boolean(existingCaveat?.value?.[snapId]);
|
|
2465
|
+
};
|
|
2466
|
+
_calculateConnectionsChange = new WeakSet();
|
|
2467
|
+
calculateConnectionsChange_fn = function(snapId, oldConnectionsSet, desiredConnectionsSet) {
|
|
2468
|
+
const filteredOldConnections = Object.keys(oldConnectionsSet).filter((origin) => __privateMethod(this, _isSubjectConnectedToSnap, isSubjectConnectedToSnap_fn).call(this, snapId, origin)).reduce((accumulator, origin) => {
|
|
2469
|
+
accumulator[origin] = oldConnectionsSet[origin];
|
|
2470
|
+
return accumulator;
|
|
2471
|
+
}, {});
|
|
2472
|
+
const newConnections = setDiff(
|
|
2473
|
+
desiredConnectionsSet,
|
|
2474
|
+
filteredOldConnections
|
|
2475
|
+
);
|
|
2476
|
+
const unusedConnections = setDiff(
|
|
2477
|
+
filteredOldConnections,
|
|
2478
|
+
desiredConnectionsSet
|
|
2479
|
+
);
|
|
2480
|
+
const approvedConnections = setDiff(
|
|
2481
|
+
filteredOldConnections,
|
|
2482
|
+
unusedConnections
|
|
2483
|
+
);
|
|
2484
|
+
return { newConnections, unusedConnections, approvedConnections };
|
|
2485
|
+
};
|
|
2437
2486
|
_updatePermissions = new WeakSet();
|
|
2438
2487
|
updatePermissions_fn = function({
|
|
2439
2488
|
snapId,
|
|
@@ -2496,4 +2545,4 @@ export {
|
|
|
2496
2545
|
SNAP_APPROVAL_RESULT,
|
|
2497
2546
|
SnapController
|
|
2498
2547
|
};
|
|
2499
|
-
//# sourceMappingURL=chunk-
|
|
2548
|
+
//# sourceMappingURL=chunk-2MH7QYBP.mjs.map
|