@metamask/snaps-controllers 3.1.1 → 3.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 +9 -1
- package/dist/cjs/snaps/SnapController.js +22 -2
- package/dist/cjs/snaps/SnapController.js.map +1 -1
- package/dist/esm/snaps/SnapController.js +24 -4
- package/dist/esm/snaps/SnapController.js.map +1 -1
- package/dist/types/snaps/SnapController.d.ts +2 -1
- package/package.json +5 -3
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [3.2.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Add support for links in custom UI and notifications ([#1814](https://github.com/MetaMask/snaps/pull/1814))
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
- Fix an issue where snaps throwing a `SnapError` would be allowed to run for longer than expected ([#1897](https://github.com/MetaMask/snaps/pull/1897))
|
|
15
|
+
|
|
9
16
|
## [3.1.1]
|
|
10
17
|
### Fixed
|
|
11
18
|
- Fix a few issues with allowlist version resolving ([#1888](https://github.com/MetaMask/snaps/pull/1888))
|
|
@@ -94,7 +101,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
94
101
|
- The version of the package no longer needs to match the version of all other
|
|
95
102
|
MetaMask Snaps packages.
|
|
96
103
|
|
|
97
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@3.
|
|
104
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@3.2.0...HEAD
|
|
105
|
+
[3.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@3.1.1...@metamask/snaps-controllers@3.2.0
|
|
98
106
|
[3.1.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@3.1.0...@metamask/snaps-controllers@3.1.1
|
|
99
107
|
[3.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@3.0.0...@metamask/snaps-controllers@3.1.0
|
|
100
108
|
[3.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@2.0.2...@metamask/snaps-controllers@3.0.0
|
|
@@ -29,6 +29,7 @@ const _basecontroller = require("@metamask/base-controller");
|
|
|
29
29
|
const _permissioncontroller = require("@metamask/permission-controller");
|
|
30
30
|
const _rpcerrors = require("@metamask/rpc-errors");
|
|
31
31
|
const _snapsrpcmethods = require("@metamask/snaps-rpc-methods");
|
|
32
|
+
const _snapsui = require("@metamask/snaps-ui");
|
|
32
33
|
const _snapsutils = require("@metamask/snaps-utils");
|
|
33
34
|
const _utils = require("@metamask/utils");
|
|
34
35
|
const _fsm = require("@xstate/fsm");
|
|
@@ -192,7 +193,7 @@ _initializeStateMachine = /*#__PURE__*/ new WeakSet(), /**
|
|
|
192
193
|
*
|
|
193
194
|
* @param snapId - The id of the Snap whose message handler to get.
|
|
194
195
|
* @returns The RPC handler for the given snap.
|
|
195
|
-
*/ _getRpcRequestHandler = /*#__PURE__*/ new WeakSet(), _executeWithTimeout = /*#__PURE__*/ new WeakSet(), _recordSnapRpcRequestStart = /*#__PURE__*/ new WeakSet(), _recordSnapRpcRequestFinish = /*#__PURE__*/ new WeakSet(), /**
|
|
196
|
+
*/ _getRpcRequestHandler = /*#__PURE__*/ new WeakSet(), _assertSnapRpcRequestResult = /*#__PURE__*/ new WeakSet(), _executeWithTimeout = /*#__PURE__*/ new WeakSet(), _recordSnapRpcRequestStart = /*#__PURE__*/ new WeakSet(), _recordSnapRpcRequestFinish = /*#__PURE__*/ new WeakSet(), /**
|
|
196
197
|
* Retrieves the rollback snapshot of a snap.
|
|
197
198
|
*
|
|
198
199
|
* @param snapId - The snap id.
|
|
@@ -1021,6 +1022,12 @@ class SnapController extends _basecontroller.BaseControllerV2 {
|
|
|
1021
1022
|
_class_private_method_init(this, _validateSnapPermissions);
|
|
1022
1023
|
_class_private_method_init(this, _getRpcRequestHandler);
|
|
1023
1024
|
/**
|
|
1025
|
+
* Asserts that the returned result of a Snap RPC call is the expected shape.
|
|
1026
|
+
*
|
|
1027
|
+
* @param handlerType - The handler type of the RPC Request.
|
|
1028
|
+
* @param result - The result of the RPC request.
|
|
1029
|
+
*/ _class_private_method_init(this, _assertSnapRpcRequestResult);
|
|
1030
|
+
/**
|
|
1024
1031
|
* Awaits the specified promise and rejects if the promise doesn't resolve
|
|
1025
1032
|
* before the timeout.
|
|
1026
1033
|
*
|
|
@@ -1561,7 +1568,7 @@ function getRpcRequestHandler(snapId) {
|
|
|
1561
1568
|
// This will either get the result or reject due to the timeout.
|
|
1562
1569
|
try {
|
|
1563
1570
|
const result = await _class_private_method_get(this, _executeWithTimeout, executeWithTimeout).call(this, handleRpcRequestPromise, timer);
|
|
1564
|
-
_class_private_method_get(this,
|
|
1571
|
+
await _class_private_method_get(this, _assertSnapRpcRequestResult, assertSnapRpcRequestResult).call(this, handlerType, result);
|
|
1565
1572
|
return result;
|
|
1566
1573
|
} catch (error) {
|
|
1567
1574
|
const [jsonRpcError, handled] = (0, _snapsutils.unwrapError)(error);
|
|
@@ -1569,11 +1576,24 @@ function getRpcRequestHandler(snapId) {
|
|
|
1569
1576
|
await this.stopSnap(snapId, _snapsutils.SnapStatusEvents.Crash);
|
|
1570
1577
|
}
|
|
1571
1578
|
throw jsonRpcError;
|
|
1579
|
+
} finally{
|
|
1580
|
+
_class_private_method_get(this, _recordSnapRpcRequestFinish, recordSnapRpcRequestFinish).call(this, snapId, request.id);
|
|
1572
1581
|
}
|
|
1573
1582
|
};
|
|
1574
1583
|
runtime.rpcHandler = rpcHandler;
|
|
1575
1584
|
return rpcHandler;
|
|
1576
1585
|
}
|
|
1586
|
+
async function assertSnapRpcRequestResult(handlerType, result) {
|
|
1587
|
+
switch(handlerType){
|
|
1588
|
+
case _snapsutils.HandlerType.OnTransaction:
|
|
1589
|
+
(0, _utils.assertStruct)(result, _snapsutils.OnTransactionResponseStruct);
|
|
1590
|
+
await this.messagingSystem.call('PhishingController:maybeUpdateState');
|
|
1591
|
+
await (0, _snapsui.assertUILinksAreSafe)(result.content, (url)=>this.messagingSystem.call('PhishingController:testOrigin', url).result);
|
|
1592
|
+
break;
|
|
1593
|
+
default:
|
|
1594
|
+
break;
|
|
1595
|
+
}
|
|
1596
|
+
}
|
|
1577
1597
|
async function executeWithTimeout(promise, timer) {
|
|
1578
1598
|
const result = await (0, _utils1.withTimeout)(promise, timer ?? this.maxRequestTime);
|
|
1579
1599
|
if (result === _utils1.hasTimedOut) {
|