@metamask/snaps-rpc-methods 15.1.0 → 16.0.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 +34 -4
- package/dist/endowments/keyring.cjs +2 -5
- package/dist/endowments/keyring.cjs.map +1 -1
- package/dist/endowments/keyring.d.cts +0 -2
- package/dist/endowments/keyring.d.cts.map +1 -1
- package/dist/endowments/keyring.d.mts +0 -2
- package/dist/endowments/keyring.d.mts.map +1 -1
- package/dist/endowments/keyring.mjs +3 -6
- package/dist/endowments/keyring.mjs.map +1 -1
- package/dist/index.cjs +1 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1 -2
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +1 -2
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +1 -2
- package/dist/index.mjs.map +1 -1
- package/dist/permissions.cjs +18 -8
- package/dist/permissions.cjs.map +1 -1
- package/dist/permissions.d.cts +3 -2
- package/dist/permissions.d.cts.map +1 -1
- package/dist/permissions.d.mts +3 -2
- package/dist/permissions.d.mts.map +1 -1
- package/dist/permissions.mjs +17 -7
- package/dist/permissions.mjs.map +1 -1
- package/dist/permitted/cancelBackgroundEvent.cjs +10 -14
- package/dist/permitted/cancelBackgroundEvent.cjs.map +1 -1
- package/dist/permitted/cancelBackgroundEvent.d.cts +9 -12
- package/dist/permitted/cancelBackgroundEvent.d.cts.map +1 -1
- package/dist/permitted/cancelBackgroundEvent.d.mts +9 -12
- package/dist/permitted/cancelBackgroundEvent.d.mts.map +1 -1
- package/dist/permitted/cancelBackgroundEvent.mjs +10 -14
- package/dist/permitted/cancelBackgroundEvent.mjs.map +1 -1
- package/dist/permitted/clearState.cjs +10 -16
- package/dist/permitted/clearState.cjs.map +1 -1
- package/dist/permitted/clearState.d.cts +9 -23
- package/dist/permitted/clearState.d.cts.map +1 -1
- package/dist/permitted/clearState.d.mts +9 -23
- package/dist/permitted/clearState.d.mts.map +1 -1
- package/dist/permitted/clearState.mjs +10 -16
- package/dist/permitted/clearState.mjs.map +1 -1
- package/dist/permitted/closeWebSocket.cjs +7 -14
- package/dist/permitted/closeWebSocket.cjs.map +1 -1
- package/dist/permitted/closeWebSocket.d.cts +9 -12
- package/dist/permitted/closeWebSocket.d.cts.map +1 -1
- package/dist/permitted/closeWebSocket.d.mts +9 -12
- package/dist/permitted/closeWebSocket.d.mts.map +1 -1
- package/dist/permitted/closeWebSocket.mjs +7 -14
- package/dist/permitted/closeWebSocket.mjs.map +1 -1
- package/dist/permitted/createInterface.cjs +11 -15
- package/dist/permitted/createInterface.cjs.map +1 -1
- package/dist/permitted/createInterface.d.cts +23 -37
- package/dist/permitted/createInterface.d.cts.map +1 -1
- package/dist/permitted/createInterface.d.mts +23 -37
- package/dist/permitted/createInterface.d.mts.map +1 -1
- package/dist/permitted/createInterface.mjs +11 -15
- package/dist/permitted/createInterface.mjs.map +1 -1
- package/dist/permitted/endTrace.cjs +4 -6
- package/dist/permitted/endTrace.cjs.map +1 -1
- package/dist/permitted/endTrace.d.cts +8 -11
- package/dist/permitted/endTrace.d.cts.map +1 -1
- package/dist/permitted/endTrace.d.mts +8 -11
- package/dist/permitted/endTrace.d.mts.map +1 -1
- package/dist/permitted/endTrace.mjs +4 -6
- package/dist/permitted/endTrace.mjs.map +1 -1
- package/dist/permitted/getAllSnaps.cjs +5 -11
- package/dist/permitted/getAllSnaps.cjs.map +1 -1
- package/dist/permitted/getAllSnaps.d.cts +10 -14
- package/dist/permitted/getAllSnaps.d.cts.map +1 -1
- package/dist/permitted/getAllSnaps.d.mts +10 -14
- package/dist/permitted/getAllSnaps.d.mts.map +1 -1
- package/dist/permitted/getAllSnaps.mjs +5 -11
- package/dist/permitted/getAllSnaps.mjs.map +1 -1
- package/dist/permitted/getBackgroundEvents.cjs +8 -15
- package/dist/permitted/getBackgroundEvents.cjs.map +1 -1
- package/dist/permitted/getBackgroundEvents.d.cts +10 -13
- package/dist/permitted/getBackgroundEvents.d.cts.map +1 -1
- package/dist/permitted/getBackgroundEvents.d.mts +10 -13
- package/dist/permitted/getBackgroundEvents.d.mts.map +1 -1
- package/dist/permitted/getBackgroundEvents.mjs +8 -15
- package/dist/permitted/getBackgroundEvents.mjs.map +1 -1
- package/dist/permitted/getClientStatus.cjs +5 -6
- package/dist/permitted/getClientStatus.cjs.map +1 -1
- package/dist/permitted/getClientStatus.d.cts +17 -18
- package/dist/permitted/getClientStatus.d.cts.map +1 -1
- package/dist/permitted/getClientStatus.d.mts +17 -18
- package/dist/permitted/getClientStatus.d.mts.map +1 -1
- package/dist/permitted/getClientStatus.mjs +5 -6
- package/dist/permitted/getClientStatus.mjs.map +1 -1
- package/dist/permitted/getFile.cjs +7 -11
- package/dist/permitted/getFile.cjs.map +1 -1
- package/dist/permitted/getFile.d.cts +8 -10
- package/dist/permitted/getFile.d.cts.map +1 -1
- package/dist/permitted/getFile.d.mts +8 -10
- package/dist/permitted/getFile.d.mts.map +1 -1
- package/dist/permitted/getFile.mjs +7 -11
- package/dist/permitted/getFile.mjs.map +1 -1
- package/dist/permitted/getInterfaceContext.cjs +12 -15
- package/dist/permitted/getInterfaceContext.cjs.map +1 -1
- package/dist/permitted/getInterfaceContext.d.cts +9 -21
- package/dist/permitted/getInterfaceContext.d.cts.map +1 -1
- package/dist/permitted/getInterfaceContext.d.mts +9 -21
- package/dist/permitted/getInterfaceContext.d.mts.map +1 -1
- package/dist/permitted/getInterfaceContext.mjs +12 -15
- package/dist/permitted/getInterfaceContext.mjs.map +1 -1
- package/dist/permitted/getInterfaceState.cjs +11 -15
- package/dist/permitted/getInterfaceState.cjs.map +1 -1
- package/dist/permitted/getInterfaceState.d.cts +9 -21
- package/dist/permitted/getInterfaceState.d.cts.map +1 -1
- package/dist/permitted/getInterfaceState.d.mts +9 -21
- package/dist/permitted/getInterfaceState.d.mts.map +1 -1
- package/dist/permitted/getInterfaceState.mjs +11 -15
- package/dist/permitted/getInterfaceState.mjs.map +1 -1
- package/dist/permitted/getSnaps.cjs +6 -12
- package/dist/permitted/getSnaps.cjs.map +1 -1
- package/dist/permitted/getSnaps.d.cts +11 -14
- package/dist/permitted/getSnaps.d.cts.map +1 -1
- package/dist/permitted/getSnaps.d.mts +11 -14
- package/dist/permitted/getSnaps.d.mts.map +1 -1
- package/dist/permitted/getSnaps.mjs +6 -12
- package/dist/permitted/getSnaps.mjs.map +1 -1
- package/dist/permitted/getState.cjs +9 -11
- package/dist/permitted/getState.cjs.map +1 -1
- package/dist/permitted/getState.d.cts +17 -28
- package/dist/permitted/getState.d.cts.map +1 -1
- package/dist/permitted/getState.d.mts +17 -28
- package/dist/permitted/getState.d.mts.map +1 -1
- package/dist/permitted/getState.mjs +9 -11
- package/dist/permitted/getState.mjs.map +1 -1
- package/dist/permitted/getWebSockets.cjs +11 -14
- package/dist/permitted/getWebSockets.cjs.map +1 -1
- package/dist/permitted/getWebSockets.d.cts +10 -13
- package/dist/permitted/getWebSockets.d.cts.map +1 -1
- package/dist/permitted/getWebSockets.d.mts +10 -13
- package/dist/permitted/getWebSockets.d.mts.map +1 -1
- package/dist/permitted/getWebSockets.mjs +11 -14
- package/dist/permitted/getWebSockets.mjs.map +1 -1
- package/dist/permitted/index.cjs +0 -1
- package/dist/permitted/index.cjs.map +1 -1
- package/dist/permitted/index.d.cts +29 -25
- package/dist/permitted/index.d.cts.map +1 -1
- package/dist/permitted/index.d.mts +29 -25
- package/dist/permitted/index.d.mts.map +1 -1
- package/dist/permitted/index.mjs +0 -1
- package/dist/permitted/index.mjs.map +1 -1
- package/dist/permitted/invokeKeyring.cjs +12 -13
- package/dist/permitted/invokeKeyring.cjs.map +1 -1
- package/dist/permitted/invokeKeyring.d.cts +17 -16
- package/dist/permitted/invokeKeyring.d.cts.map +1 -1
- package/dist/permitted/invokeKeyring.d.mts +17 -16
- package/dist/permitted/invokeKeyring.d.mts.map +1 -1
- package/dist/permitted/invokeKeyring.mjs +12 -13
- package/dist/permitted/invokeKeyring.mjs.map +1 -1
- package/dist/permitted/invokeSnapSugar.cjs +6 -10
- package/dist/permitted/invokeSnapSugar.cjs.map +1 -1
- package/dist/permitted/invokeSnapSugar.d.cts +9 -12
- package/dist/permitted/invokeSnapSugar.d.cts.map +1 -1
- package/dist/permitted/invokeSnapSugar.d.mts +9 -12
- package/dist/permitted/invokeSnapSugar.d.mts.map +1 -1
- package/dist/permitted/invokeSnapSugar.mjs +6 -10
- package/dist/permitted/invokeSnapSugar.mjs.map +1 -1
- package/dist/permitted/listEntropySources.cjs +28 -12
- package/dist/permitted/listEntropySources.cjs.map +1 -1
- package/dist/permitted/listEntropySources.d.cts +12 -23
- package/dist/permitted/listEntropySources.d.cts.map +1 -1
- package/dist/permitted/listEntropySources.d.mts +12 -23
- package/dist/permitted/listEntropySources.d.mts.map +1 -1
- package/dist/permitted/listEntropySources.mjs +28 -12
- package/dist/permitted/listEntropySources.mjs.map +1 -1
- package/dist/permitted/middleware.cjs +70 -20
- package/dist/permitted/middleware.cjs.map +1 -1
- package/dist/permitted/middleware.d.cts +5 -2
- package/dist/permitted/middleware.d.cts.map +1 -1
- package/dist/permitted/middleware.d.mts +5 -2
- package/dist/permitted/middleware.d.mts.map +1 -1
- package/dist/permitted/middleware.mjs +70 -20
- package/dist/permitted/middleware.mjs.map +1 -1
- package/dist/permitted/openWebSocket.cjs +7 -14
- package/dist/permitted/openWebSocket.cjs.map +1 -1
- package/dist/permitted/openWebSocket.d.cts +9 -12
- package/dist/permitted/openWebSocket.d.cts.map +1 -1
- package/dist/permitted/openWebSocket.d.mts +9 -12
- package/dist/permitted/openWebSocket.d.mts.map +1 -1
- package/dist/permitted/openWebSocket.mjs +7 -14
- package/dist/permitted/openWebSocket.mjs.map +1 -1
- package/dist/permitted/requestSnaps.cjs +14 -19
- package/dist/permitted/requestSnaps.cjs.map +1 -1
- package/dist/permitted/requestSnaps.d.cts +9 -36
- package/dist/permitted/requestSnaps.d.cts.map +1 -1
- package/dist/permitted/requestSnaps.d.mts +9 -36
- package/dist/permitted/requestSnaps.d.mts.map +1 -1
- package/dist/permitted/requestSnaps.mjs +15 -20
- package/dist/permitted/requestSnaps.mjs.map +1 -1
- package/dist/permitted/resolveInterface.cjs +11 -15
- package/dist/permitted/resolveInterface.cjs.map +1 -1
- package/dist/permitted/resolveInterface.d.cts +12 -24
- package/dist/permitted/resolveInterface.d.cts.map +1 -1
- package/dist/permitted/resolveInterface.d.mts +12 -24
- package/dist/permitted/resolveInterface.d.mts.map +1 -1
- package/dist/permitted/resolveInterface.mjs +11 -15
- package/dist/permitted/resolveInterface.mjs.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.cjs +11 -14
- package/dist/permitted/scheduleBackgroundEvent.cjs.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.d.cts +10 -17
- package/dist/permitted/scheduleBackgroundEvent.d.cts.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.d.mts +10 -17
- package/dist/permitted/scheduleBackgroundEvent.d.mts.map +1 -1
- package/dist/permitted/scheduleBackgroundEvent.mjs +11 -14
- package/dist/permitted/scheduleBackgroundEvent.mjs.map +1 -1
- package/dist/permitted/sendWebSocketMessage.cjs +10 -14
- package/dist/permitted/sendWebSocketMessage.cjs.map +1 -1
- package/dist/permitted/sendWebSocketMessage.d.cts +9 -12
- package/dist/permitted/sendWebSocketMessage.d.cts.map +1 -1
- package/dist/permitted/sendWebSocketMessage.d.mts +9 -12
- package/dist/permitted/sendWebSocketMessage.d.mts.map +1 -1
- package/dist/permitted/sendWebSocketMessage.mjs +10 -14
- package/dist/permitted/sendWebSocketMessage.mjs.map +1 -1
- package/dist/permitted/setState.cjs +18 -21
- package/dist/permitted/setState.cjs.map +1 -1
- package/dist/permitted/setState.d.cts +18 -45
- package/dist/permitted/setState.d.cts.map +1 -1
- package/dist/permitted/setState.d.mts +18 -45
- package/dist/permitted/setState.d.mts.map +1 -1
- package/dist/permitted/setState.mjs +18 -21
- package/dist/permitted/setState.mjs.map +1 -1
- package/dist/permitted/startTrace.cjs +4 -6
- package/dist/permitted/startTrace.cjs.map +1 -1
- package/dist/permitted/startTrace.d.cts +8 -11
- package/dist/permitted/startTrace.d.cts.map +1 -1
- package/dist/permitted/startTrace.d.mts +8 -11
- package/dist/permitted/startTrace.d.mts.map +1 -1
- package/dist/permitted/startTrace.mjs +4 -6
- package/dist/permitted/startTrace.mjs.map +1 -1
- package/dist/permitted/trackError.cjs +4 -6
- package/dist/permitted/trackError.cjs.map +1 -1
- package/dist/permitted/trackError.d.cts +8 -11
- package/dist/permitted/trackError.d.cts.map +1 -1
- package/dist/permitted/trackError.d.mts +8 -11
- package/dist/permitted/trackError.d.mts.map +1 -1
- package/dist/permitted/trackError.mjs +4 -6
- package/dist/permitted/trackError.mjs.map +1 -1
- package/dist/permitted/trackEvent.cjs +4 -6
- package/dist/permitted/trackEvent.cjs.map +1 -1
- package/dist/permitted/trackEvent.d.cts +8 -11
- package/dist/permitted/trackEvent.d.cts.map +1 -1
- package/dist/permitted/trackEvent.d.mts +8 -11
- package/dist/permitted/trackEvent.d.mts.map +1 -1
- package/dist/permitted/trackEvent.mjs +4 -6
- package/dist/permitted/trackEvent.mjs.map +1 -1
- package/dist/permitted/updateInterface.cjs +11 -15
- package/dist/permitted/updateInterface.cjs.map +1 -1
- package/dist/permitted/updateInterface.d.cts +9 -22
- package/dist/permitted/updateInterface.d.cts.map +1 -1
- package/dist/permitted/updateInterface.d.mts +9 -22
- package/dist/permitted/updateInterface.d.mts.map +1 -1
- package/dist/permitted/updateInterface.mjs +11 -15
- package/dist/permitted/updateInterface.mjs.map +1 -1
- package/dist/restricted/dialog.cjs +23 -30
- package/dist/restricted/dialog.cjs.map +1 -1
- package/dist/restricted/dialog.d.cts +10 -58
- package/dist/restricted/dialog.d.cts.map +1 -1
- package/dist/restricted/dialog.d.mts +10 -58
- package/dist/restricted/dialog.d.mts.map +1 -1
- package/dist/restricted/dialog.mjs +23 -30
- package/dist/restricted/dialog.mjs.map +1 -1
- package/dist/restricted/getBip32Entropy.cjs +15 -12
- package/dist/restricted/getBip32Entropy.cjs.map +1 -1
- package/dist/restricted/getBip32Entropy.d.cts +11 -24
- package/dist/restricted/getBip32Entropy.d.cts.map +1 -1
- package/dist/restricted/getBip32Entropy.d.mts +11 -24
- package/dist/restricted/getBip32Entropy.d.mts.map +1 -1
- package/dist/restricted/getBip32Entropy.mjs +16 -13
- package/dist/restricted/getBip32Entropy.mjs.map +1 -1
- package/dist/restricted/getBip32PublicKey.cjs +15 -12
- package/dist/restricted/getBip32PublicKey.cjs.map +1 -1
- package/dist/restricted/getBip32PublicKey.d.cts +11 -24
- package/dist/restricted/getBip32PublicKey.d.cts.map +1 -1
- package/dist/restricted/getBip32PublicKey.d.mts +11 -24
- package/dist/restricted/getBip32PublicKey.d.mts.map +1 -1
- package/dist/restricted/getBip32PublicKey.mjs +16 -13
- package/dist/restricted/getBip32PublicKey.mjs.map +1 -1
- package/dist/restricted/getBip44Entropy.cjs +14 -10
- package/dist/restricted/getBip44Entropy.cjs.map +1 -1
- package/dist/restricted/getBip44Entropy.d.cts +11 -15
- package/dist/restricted/getBip44Entropy.d.cts.map +1 -1
- package/dist/restricted/getBip44Entropy.d.mts +11 -15
- package/dist/restricted/getBip44Entropy.d.mts.map +1 -1
- package/dist/restricted/getBip44Entropy.mjs +15 -11
- package/dist/restricted/getBip44Entropy.mjs.map +1 -1
- package/dist/restricted/getEntropy.cjs +10 -10
- package/dist/restricted/getEntropy.cjs.map +1 -1
- package/dist/restricted/getEntropy.d.cts +11 -15
- package/dist/restricted/getEntropy.d.cts.map +1 -1
- package/dist/restricted/getEntropy.d.mts +11 -15
- package/dist/restricted/getEntropy.d.mts.map +1 -1
- package/dist/restricted/getEntropy.mjs +11 -11
- package/dist/restricted/getEntropy.mjs.map +1 -1
- package/dist/restricted/index.cjs.map +1 -1
- package/dist/restricted/index.d.cts +20 -160
- package/dist/restricted/index.d.cts.map +1 -1
- package/dist/restricted/index.d.mts +20 -160
- package/dist/restricted/index.d.mts.map +1 -1
- package/dist/restricted/index.mjs.map +1 -1
- package/dist/restricted/invokeSnap.cjs +11 -12
- package/dist/restricted/invokeSnap.cjs.map +1 -1
- package/dist/restricted/invokeSnap.d.cts +9 -13
- package/dist/restricted/invokeSnap.d.cts.map +1 -1
- package/dist/restricted/invokeSnap.d.mts +9 -13
- package/dist/restricted/invokeSnap.d.mts.map +1 -1
- package/dist/restricted/invokeSnap.mjs +11 -12
- package/dist/restricted/invokeSnap.mjs.map +1 -1
- package/dist/restricted/manageState.cjs +21 -20
- package/dist/restricted/manageState.cjs.map +1 -1
- package/dist/restricted/manageState.d.cts +12 -34
- package/dist/restricted/manageState.d.cts.map +1 -1
- package/dist/restricted/manageState.d.mts +12 -34
- package/dist/restricted/manageState.d.mts.map +1 -1
- package/dist/restricted/manageState.mjs +21 -20
- package/dist/restricted/manageState.mjs.map +1 -1
- package/dist/restricted/notify.cjs +31 -24
- package/dist/restricted/notify.cjs.map +1 -1
- package/dist/restricted/notify.d.cts +16 -25
- package/dist/restricted/notify.d.cts.map +1 -1
- package/dist/restricted/notify.d.mts +16 -25
- package/dist/restricted/notify.d.mts.map +1 -1
- package/dist/restricted/notify.mjs +32 -25
- package/dist/restricted/notify.mjs.map +1 -1
- package/dist/types.cjs +3 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +155 -0
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +155 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +2 -0
- package/dist/types.mjs.map +1 -0
- package/dist/utils.cjs +78 -24
- package/dist/utils.cjs.map +1 -1
- package/dist/utils.d.cts +21 -13
- package/dist/utils.d.cts.map +1 -1
- package/dist/utils.d.mts +21 -13
- package/dist/utils.d.mts.map +1 -1
- package/dist/utils.mjs +75 -22
- package/dist/utils.mjs.map +1 -1
- package/package.json +6 -6
- package/dist/permitted/handlers.cjs +0 -63
- package/dist/permitted/handlers.cjs.map +0 -1
- package/dist/permitted/handlers.d.cts +0 -299
- package/dist/permitted/handlers.d.cts.map +0 -1
- package/dist/permitted/handlers.d.mts +0 -299
- package/dist/permitted/handlers.d.mts.map +0 -1
- package/dist/permitted/handlers.mjs +0 -60
- package/dist/permitted/handlers.mjs.map +0 -1
|
@@ -4,7 +4,6 @@ exports.trackEventHandler = void 0;
|
|
|
4
4
|
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
5
5
|
const superstruct_1 = require("@metamask/superstruct");
|
|
6
6
|
const utils_1 = require("@metamask/utils");
|
|
7
|
-
const methodName = 'snap_trackEvent';
|
|
8
7
|
const PropertiesStruct = (0, superstruct_1.optional)((0, superstruct_1.record)((0, superstruct_1.string)(), utils_1.JsonStruct));
|
|
9
8
|
const snakeCaseRegex = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/u;
|
|
10
9
|
const SnakeCasePropertiesStruct = (0, superstruct_1.refine)(PropertiesStruct, 'snake_case_keys', (value) => {
|
|
@@ -15,7 +14,6 @@ const SnakeCasePropertiesStruct = (0, superstruct_1.refine)(PropertiesStruct, 's
|
|
|
15
14
|
});
|
|
16
15
|
const hookNames = {
|
|
17
16
|
trackEvent: true,
|
|
18
|
-
getSnap: true,
|
|
19
17
|
};
|
|
20
18
|
const TrackEventParametersStruct = (0, superstruct_1.object)({
|
|
21
19
|
event: (0, superstruct_1.object)({
|
|
@@ -30,9 +28,9 @@ const TrackEventParametersStruct = (0, superstruct_1.object)({
|
|
|
30
28
|
* @internal
|
|
31
29
|
*/
|
|
32
30
|
exports.trackEventHandler = {
|
|
33
|
-
methodNames: [methodName],
|
|
34
31
|
implementation: getTrackEventImplementation,
|
|
35
32
|
hookNames,
|
|
33
|
+
actionNames: ['SnapController:getSnap'],
|
|
36
34
|
};
|
|
37
35
|
/**
|
|
38
36
|
* The `snap_trackEvent` method implementation.
|
|
@@ -44,11 +42,11 @@ exports.trackEventHandler = {
|
|
|
44
42
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
45
43
|
* @param hooks - The RPC method hooks.
|
|
46
44
|
* @param hooks.trackEvent - The function to track the event.
|
|
47
|
-
* @param
|
|
45
|
+
* @param messenger - The messenger used to call controller actions.
|
|
48
46
|
* @returns Nothing.
|
|
49
47
|
*/
|
|
50
|
-
function getTrackEventImplementation(req, res, _next, end, { trackEvent,
|
|
51
|
-
const snap = getSnap
|
|
48
|
+
function getTrackEventImplementation(req, res, _next, end, { trackEvent }, messenger) {
|
|
49
|
+
const snap = messenger.call('SnapController:getSnap', req.origin);
|
|
52
50
|
if (!snap?.preinstalled) {
|
|
53
51
|
return end(rpc_errors_1.rpcErrors.methodNotFound());
|
|
54
52
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trackEvent.cjs","sourceRoot":"","sources":["../../src/permitted/trackEvent.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"trackEvent.cjs","sourceRoot":"","sources":["../../src/permitted/trackEvent.ts"],"names":[],"mappings":";;;AAKA,qDAAiD;AAGjD,uDAQ+B;AAE/B,2CAA6C;AAQ7C,MAAM,gBAAgB,GAAG,IAAA,sBAAQ,EAAC,IAAA,oBAAM,EAAC,IAAA,oBAAM,GAAE,EAAE,kBAAU,CAAC,CAAC,CAAC;AAEhE,MAAM,cAAc,GAAG,kCAAkC,CAAC;AAE1D,MAAM,yBAAyB,GAAG,IAAA,oBAAM,EACtC,gBAAgB,EAChB,iBAAiB,EACjB,CAAC,KAAK,EAAE,EAAE;IACR,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AACrE,CAAC,CACF,CAAC;AAEF,MAAM,SAAS,GAA6C;IAC1D,UAAU,EAAE,IAAI;CACjB,CAAC;AAmBF,MAAM,0BAA0B,GAAG,IAAA,oBAAM,EAAC;IACxC,KAAK,E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EAAE,CAAC;gBAC3C,MAAM,sBAAS,CAAC,aAAa,CAAC;oBAC5B,OAAO,EAAE,mHAAmH,KAAK,CAAC,GAAG,IAAI;iBAC1I,CAAC,CAAC;YACL,CAAC;YAED,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,sBAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type { Messenger } from '@metamask/messenger';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { TrackEventParams, TrackEventResult } from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport {\n create,\n object,\n optional,\n record,\n refine,\n string,\n StructError,\n} from '@metamask/superstruct';\nimport type { Json, PendingJsonRpcResponse } from '@metamask/utils';\nimport { JsonStruct } from '@metamask/utils';\n\nimport type {\n JsonRpcRequestWithOrigin,\n SnapControllerGetSnapAction,\n} from '../types';\nimport type { MethodHooksObject } from '../utils';\n\nconst PropertiesStruct = optional(record(string(), JsonStruct));\n\nconst snakeCaseRegex = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/u;\n\nconst SnakeCasePropertiesStruct = refine(\n PropertiesStruct,\n 'snake_case_keys',\n (value) => {\n if (!value) {\n return true;\n }\n\n return Object.keys(value).every((key) => snakeCaseRegex.test(key));\n },\n);\n\nconst hookNames: MethodHooksObject<TrackEventMethodHooks> = {\n trackEvent: true,\n};\n\nexport type TrackEventMethodHooks = {\n /**\n * Track an event.\n *\n * @param event - The event object containing event details and properties.\n */\n trackEvent: (event: TrackEventObject) => void;\n};\n\nexport type TrackEventMethodActions = SnapControllerGetSnapAction;\n\nexport type TrackEventObject = {\n event: string;\n properties?: Record<string, Json>;\n sensitiveProperties?: Record<string, Json>;\n};\n\nconst TrackEventParametersStruct = object({\n event: object({\n event: string(),\n properties: SnakeCasePropertiesStruct,\n sensitiveProperties: SnakeCasePropertiesStruct,\n }),\n});\n\nexport type TrackEventParameters = InferMatching<\n typeof TrackEventParametersStruct,\n TrackEventParams\n>;\n\n/**\n * Handler for the `snap_trackEvent` method.\n *\n * @internal\n */\nexport const trackEventHandler = {\n implementation: getTrackEventImplementation,\n hookNames,\n actionNames: ['SnapController:getSnap'],\n} satisfies MethodHandler<\n TrackEventMethodHooks,\n TrackEventMethodActions,\n TrackEventParameters,\n TrackEventResult,\n { origin: string }\n>;\n\n/**\n * The `snap_trackEvent` method implementation.\n * This method allows pre-installed Snaps to submit tracking events to the client.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.trackEvent - The function to track the event.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n */\nfunction getTrackEventImplementation(\n req: JsonRpcRequestWithOrigin<TrackEventParameters>,\n res: PendingJsonRpcResponse<TrackEventResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { trackEvent }: TrackEventMethodHooks,\n messenger: Messenger<string, TrackEventMethodActions>,\n): void {\n const snap = messenger.call('SnapController:getSnap', req.origin);\n\n if (!snap?.preinstalled) {\n return end(rpcErrors.methodNotFound());\n }\n\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n trackEvent(validatedParams.event);\n res.result = null;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validates the parameters for the snap_trackEvent method.\n *\n * @param params - Parameters to validate.\n * @returns Validated parameters.\n * @throws Throws RPC error if validation fails.\n */\nfunction getValidatedParams(params: unknown): TrackEventParameters {\n try {\n return create(params, TrackEventParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n if (error.refinement === 'snake_case_keys') {\n throw rpcErrors.invalidParams({\n message: `Invalid params: All property keys must be in snake_case format. The following key contains invalid properties: \"${error.key}\".`,\n });\n }\n\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { Messenger } from "@metamask/messenger";
|
|
3
|
+
import type { TrackEventParams, TrackEventResult } from "@metamask/snaps-sdk";
|
|
4
|
+
import type { InferMatching } from "@metamask/snaps-utils";
|
|
4
5
|
import type { Json, PendingJsonRpcResponse } from "@metamask/utils";
|
|
6
|
+
import type { JsonRpcRequestWithOrigin, SnapControllerGetSnapAction } from "../types.cjs";
|
|
5
7
|
import type { MethodHooksObject } from "../utils.cjs";
|
|
6
8
|
export type TrackEventMethodHooks = {
|
|
7
9
|
/**
|
|
@@ -10,13 +12,8 @@ export type TrackEventMethodHooks = {
|
|
|
10
12
|
* @param event - The event object containing event details and properties.
|
|
11
13
|
*/
|
|
12
14
|
trackEvent: (event: TrackEventObject) => void;
|
|
13
|
-
/**
|
|
14
|
-
* Get Snap metadata.
|
|
15
|
-
*
|
|
16
|
-
* @param snapId - The ID of a Snap.
|
|
17
|
-
*/
|
|
18
|
-
getSnap: (snapId: string) => Snap | undefined;
|
|
19
15
|
};
|
|
16
|
+
export type TrackEventMethodActions = SnapControllerGetSnapAction;
|
|
20
17
|
export type TrackEventObject = {
|
|
21
18
|
event: string;
|
|
22
19
|
properties?: Record<string, Json>;
|
|
@@ -46,9 +43,9 @@ export type TrackEventParameters = InferMatching<typeof TrackEventParametersStru
|
|
|
46
43
|
* @internal
|
|
47
44
|
*/
|
|
48
45
|
export declare const trackEventHandler: {
|
|
49
|
-
methodNames: ["snap_trackEvent"];
|
|
50
46
|
implementation: typeof getTrackEventImplementation;
|
|
51
47
|
hookNames: MethodHooksObject<TrackEventMethodHooks>;
|
|
48
|
+
actionNames: "SnapController:getSnap"[];
|
|
52
49
|
};
|
|
53
50
|
/**
|
|
54
51
|
* The `snap_trackEvent` method implementation.
|
|
@@ -60,9 +57,9 @@ export declare const trackEventHandler: {
|
|
|
60
57
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
61
58
|
* @param hooks - The RPC method hooks.
|
|
62
59
|
* @param hooks.trackEvent - The function to track the event.
|
|
63
|
-
* @param
|
|
60
|
+
* @param messenger - The messenger used to call controller actions.
|
|
64
61
|
* @returns Nothing.
|
|
65
62
|
*/
|
|
66
|
-
declare function getTrackEventImplementation(req:
|
|
63
|
+
declare function getTrackEventImplementation(req: JsonRpcRequestWithOrigin<TrackEventParameters>, res: PendingJsonRpcResponse<TrackEventResult>, _next: unknown, end: JsonRpcEngineEndCallback, { trackEvent }: TrackEventMethodHooks, messenger: Messenger<string, TrackEventMethodActions>): void;
|
|
67
64
|
export {};
|
|
68
65
|
//# sourceMappingURL=trackEvent.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trackEvent.d.cts","sourceRoot":"","sources":["../../src/permitted/trackEvent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"trackEvent.d.cts","sourceRoot":"","sources":["../../src/permitted/trackEvent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,4BAA4B;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA8B;AAU3D,OAAO,KAAK,EAAE,IAAI,EAAE,sBAAsB,EAAE,wBAAwB;AAGpE,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAC5B,qBAAiB;AAClB,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAsBlD,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;;OAIG;IACH,UAAU,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,2BAA2B,CAAC;AAElE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAClC,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CAC5C,CAAC;AAEF,QAAA,MAAM,0BAA0B;;;;;;;;;;;;;;;;EAM9B,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAC9C,OAAO,0BAA0B,EACjC,gBAAgB,CACjB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB;;;;CAU7B,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,iBAAS,2BAA2B,CAClC,GAAG,EAAE,wBAAwB,CAAC,oBAAoB,CAAC,EACnD,GAAG,EAAE,sBAAsB,CAAC,gBAAgB,CAAC,EAC7C,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,EAAE,UAAU,EAAE,EAAE,qBAAqB,EACrC,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,uBAAuB,CAAC,GACpD,IAAI,CAkBN"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
2
|
+
import type { Messenger } from "@metamask/messenger";
|
|
3
|
+
import type { TrackEventParams, TrackEventResult } from "@metamask/snaps-sdk";
|
|
4
|
+
import type { InferMatching } from "@metamask/snaps-utils";
|
|
4
5
|
import type { Json, PendingJsonRpcResponse } from "@metamask/utils";
|
|
6
|
+
import type { JsonRpcRequestWithOrigin, SnapControllerGetSnapAction } from "../types.mjs";
|
|
5
7
|
import type { MethodHooksObject } from "../utils.mjs";
|
|
6
8
|
export type TrackEventMethodHooks = {
|
|
7
9
|
/**
|
|
@@ -10,13 +12,8 @@ export type TrackEventMethodHooks = {
|
|
|
10
12
|
* @param event - The event object containing event details and properties.
|
|
11
13
|
*/
|
|
12
14
|
trackEvent: (event: TrackEventObject) => void;
|
|
13
|
-
/**
|
|
14
|
-
* Get Snap metadata.
|
|
15
|
-
*
|
|
16
|
-
* @param snapId - The ID of a Snap.
|
|
17
|
-
*/
|
|
18
|
-
getSnap: (snapId: string) => Snap | undefined;
|
|
19
15
|
};
|
|
16
|
+
export type TrackEventMethodActions = SnapControllerGetSnapAction;
|
|
20
17
|
export type TrackEventObject = {
|
|
21
18
|
event: string;
|
|
22
19
|
properties?: Record<string, Json>;
|
|
@@ -46,9 +43,9 @@ export type TrackEventParameters = InferMatching<typeof TrackEventParametersStru
|
|
|
46
43
|
* @internal
|
|
47
44
|
*/
|
|
48
45
|
export declare const trackEventHandler: {
|
|
49
|
-
methodNames: ["snap_trackEvent"];
|
|
50
46
|
implementation: typeof getTrackEventImplementation;
|
|
51
47
|
hookNames: MethodHooksObject<TrackEventMethodHooks>;
|
|
48
|
+
actionNames: "SnapController:getSnap"[];
|
|
52
49
|
};
|
|
53
50
|
/**
|
|
54
51
|
* The `snap_trackEvent` method implementation.
|
|
@@ -60,9 +57,9 @@ export declare const trackEventHandler: {
|
|
|
60
57
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
61
58
|
* @param hooks - The RPC method hooks.
|
|
62
59
|
* @param hooks.trackEvent - The function to track the event.
|
|
63
|
-
* @param
|
|
60
|
+
* @param messenger - The messenger used to call controller actions.
|
|
64
61
|
* @returns Nothing.
|
|
65
62
|
*/
|
|
66
|
-
declare function getTrackEventImplementation(req:
|
|
63
|
+
declare function getTrackEventImplementation(req: JsonRpcRequestWithOrigin<TrackEventParameters>, res: PendingJsonRpcResponse<TrackEventResult>, _next: unknown, end: JsonRpcEngineEndCallback, { trackEvent }: TrackEventMethodHooks, messenger: Messenger<string, TrackEventMethodActions>): void;
|
|
67
64
|
export {};
|
|
68
65
|
//# sourceMappingURL=trackEvent.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trackEvent.d.mts","sourceRoot":"","sources":["../../src/permitted/trackEvent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"trackEvent.d.mts","sourceRoot":"","sources":["../../src/permitted/trackEvent.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AAErD,OAAO,KAAK,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,4BAA4B;AAC9E,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA8B;AAU3D,OAAO,KAAK,EAAE,IAAI,EAAE,sBAAsB,EAAE,wBAAwB;AAGpE,OAAO,KAAK,EACV,wBAAwB,EACxB,2BAA2B,EAC5B,qBAAiB;AAClB,OAAO,KAAK,EAAE,iBAAiB,EAAE,qBAAiB;AAsBlD,MAAM,MAAM,qBAAqB,GAAG;IAClC;;;;OAIG;IACH,UAAU,EAAE,CAAC,KAAK,EAAE,gBAAgB,KAAK,IAAI,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,2BAA2B,CAAC;AAElE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAClC,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;CAC5C,CAAC;AAEF,QAAA,MAAM,0BAA0B;;;;;;;;;;;;;;;;EAM9B,CAAC;AAEH,MAAM,MAAM,oBAAoB,GAAG,aAAa,CAC9C,OAAO,0BAA0B,EACjC,gBAAgB,CACjB,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB;;;;CAU7B,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,iBAAS,2BAA2B,CAClC,GAAG,EAAE,wBAAwB,CAAC,oBAAoB,CAAC,EACnD,GAAG,EAAE,sBAAsB,CAAC,gBAAgB,CAAC,EAC7C,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,EAAE,UAAU,EAAE,EAAE,qBAAqB,EACrC,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,uBAAuB,CAAC,GACpD,IAAI,CAkBN"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { rpcErrors } from "@metamask/rpc-errors";
|
|
2
2
|
import { create, object, optional, record, refine, string, StructError } from "@metamask/superstruct";
|
|
3
3
|
import { JsonStruct } from "@metamask/utils";
|
|
4
|
-
const methodName = 'snap_trackEvent';
|
|
5
4
|
const PropertiesStruct = optional(record(string(), JsonStruct));
|
|
6
5
|
const snakeCaseRegex = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/u;
|
|
7
6
|
const SnakeCasePropertiesStruct = refine(PropertiesStruct, 'snake_case_keys', (value) => {
|
|
@@ -12,7 +11,6 @@ const SnakeCasePropertiesStruct = refine(PropertiesStruct, 'snake_case_keys', (v
|
|
|
12
11
|
});
|
|
13
12
|
const hookNames = {
|
|
14
13
|
trackEvent: true,
|
|
15
|
-
getSnap: true,
|
|
16
14
|
};
|
|
17
15
|
const TrackEventParametersStruct = object({
|
|
18
16
|
event: object({
|
|
@@ -27,9 +25,9 @@ const TrackEventParametersStruct = object({
|
|
|
27
25
|
* @internal
|
|
28
26
|
*/
|
|
29
27
|
export const trackEventHandler = {
|
|
30
|
-
methodNames: [methodName],
|
|
31
28
|
implementation: getTrackEventImplementation,
|
|
32
29
|
hookNames,
|
|
30
|
+
actionNames: ['SnapController:getSnap'],
|
|
33
31
|
};
|
|
34
32
|
/**
|
|
35
33
|
* The `snap_trackEvent` method implementation.
|
|
@@ -41,11 +39,11 @@ export const trackEventHandler = {
|
|
|
41
39
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
42
40
|
* @param hooks - The RPC method hooks.
|
|
43
41
|
* @param hooks.trackEvent - The function to track the event.
|
|
44
|
-
* @param
|
|
42
|
+
* @param messenger - The messenger used to call controller actions.
|
|
45
43
|
* @returns Nothing.
|
|
46
44
|
*/
|
|
47
|
-
function getTrackEventImplementation(req, res, _next, end, { trackEvent,
|
|
48
|
-
const snap = getSnap
|
|
45
|
+
function getTrackEventImplementation(req, res, _next, end, { trackEvent }, messenger) {
|
|
46
|
+
const snap = messenger.call('SnapController:getSnap', req.origin);
|
|
49
47
|
if (!snap?.preinstalled) {
|
|
50
48
|
return end(rpcErrors.methodNotFound());
|
|
51
49
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"trackEvent.mjs","sourceRoot":"","sources":["../../src/permitted/trackEvent.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"trackEvent.mjs","sourceRoot":"","sources":["../../src/permitted/trackEvent.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAGjD,OAAO,EACL,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,EACN,MAAM,EACN,MAAM,EACN,WAAW,EACZ,8BAA8B;AAE/B,OAAO,EAAE,UAAU,EAAE,wBAAwB;AAQ7C,MAAM,gBAAgB,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC;AAEhE,MAAM,cAAc,GAAG,kCAAkC,CAAC;AAE1D,MAAM,yBAAyB,GAAG,MAAM,CACtC,gBAAgB,EAChB,iBAAiB,EACjB,CAAC,KAAK,EAAE,EAAE;IACR,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CA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BAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,0BAA0B,CAAC,CAAC;IACpD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,IAAI,KAAK,CAAC,UAAU,KAAK,iBAAiB,EAAE,CAAC;gBAC3C,MAAM,SAAS,CAAC,aAAa,CAAC;oBAC5B,OAAO,EAAE,mHAAmH,KAAK,CAAC,GAAG,IAAI;iBAC1I,CAAC,CAAC;YACL,CAAC;YAED,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type { Messenger } from '@metamask/messenger';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { TrackEventParams, TrackEventResult } from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport {\n create,\n object,\n optional,\n record,\n refine,\n string,\n StructError,\n} from '@metamask/superstruct';\nimport type { Json, PendingJsonRpcResponse } from '@metamask/utils';\nimport { JsonStruct } from '@metamask/utils';\n\nimport type {\n JsonRpcRequestWithOrigin,\n SnapControllerGetSnapAction,\n} from '../types';\nimport type { MethodHooksObject } from '../utils';\n\nconst PropertiesStruct = optional(record(string(), JsonStruct));\n\nconst snakeCaseRegex = /^[a-z][a-z0-9]*(?:_[a-z0-9]+)*$/u;\n\nconst SnakeCasePropertiesStruct = refine(\n PropertiesStruct,\n 'snake_case_keys',\n (value) => {\n if (!value) {\n return true;\n }\n\n return Object.keys(value).every((key) => snakeCaseRegex.test(key));\n },\n);\n\nconst hookNames: MethodHooksObject<TrackEventMethodHooks> = {\n trackEvent: true,\n};\n\nexport type TrackEventMethodHooks = {\n /**\n * Track an event.\n *\n * @param event - The event object containing event details and properties.\n */\n trackEvent: (event: TrackEventObject) => void;\n};\n\nexport type TrackEventMethodActions = SnapControllerGetSnapAction;\n\nexport type TrackEventObject = {\n event: string;\n properties?: Record<string, Json>;\n sensitiveProperties?: Record<string, Json>;\n};\n\nconst TrackEventParametersStruct = object({\n event: object({\n event: string(),\n properties: SnakeCasePropertiesStruct,\n sensitiveProperties: SnakeCasePropertiesStruct,\n }),\n});\n\nexport type TrackEventParameters = InferMatching<\n typeof TrackEventParametersStruct,\n TrackEventParams\n>;\n\n/**\n * Handler for the `snap_trackEvent` method.\n *\n * @internal\n */\nexport const trackEventHandler = {\n implementation: getTrackEventImplementation,\n hookNames,\n actionNames: ['SnapController:getSnap'],\n} satisfies MethodHandler<\n TrackEventMethodHooks,\n TrackEventMethodActions,\n TrackEventParameters,\n TrackEventResult,\n { origin: string }\n>;\n\n/**\n * The `snap_trackEvent` method implementation.\n * This method allows pre-installed Snaps to submit tracking events to the client.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.trackEvent - The function to track the event.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n */\nfunction getTrackEventImplementation(\n req: JsonRpcRequestWithOrigin<TrackEventParameters>,\n res: PendingJsonRpcResponse<TrackEventResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { trackEvent }: TrackEventMethodHooks,\n messenger: Messenger<string, TrackEventMethodActions>,\n): void {\n const snap = messenger.call('SnapController:getSnap', req.origin);\n\n if (!snap?.preinstalled) {\n return end(rpcErrors.methodNotFound());\n }\n\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n trackEvent(validatedParams.event);\n res.result = null;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validates the parameters for the snap_trackEvent method.\n *\n * @param params - Parameters to validate.\n * @returns Validated parameters.\n * @throws Throws RPC error if validation fails.\n */\nfunction getValidatedParams(params: unknown): TrackEventParameters {\n try {\n return create(params, TrackEventParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n if (error.refinement === 'snake_case_keys') {\n throw rpcErrors.invalidParams({\n message: `Invalid params: All property keys must be in snake_case format. The following key contains invalid properties: \"${error.key}\".`,\n });\n }\n\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -5,11 +5,6 @@ const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
|
5
5
|
const snaps_sdk_1 = require("@metamask/snaps-sdk");
|
|
6
6
|
const superstruct_1 = require("@metamask/superstruct");
|
|
7
7
|
const utils_1 = require("../utils.cjs");
|
|
8
|
-
const methodName = 'snap_updateInterface';
|
|
9
|
-
const hookNames = {
|
|
10
|
-
hasPermission: true,
|
|
11
|
-
updateInterface: true,
|
|
12
|
-
};
|
|
13
8
|
/**
|
|
14
9
|
* Update an interactive interface. For use in
|
|
15
10
|
* [interactive UI](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/).
|
|
@@ -46,9 +41,11 @@ const hookNames = {
|
|
|
46
41
|
* ```
|
|
47
42
|
*/
|
|
48
43
|
exports.updateInterfaceHandler = {
|
|
49
|
-
methodNames: [methodName],
|
|
50
44
|
implementation: getUpdateInterfaceImplementation,
|
|
51
|
-
|
|
45
|
+
actionNames: [
|
|
46
|
+
'PermissionController:hasPermission',
|
|
47
|
+
'SnapInterfaceController:updateInterface',
|
|
48
|
+
],
|
|
52
49
|
};
|
|
53
50
|
const UpdateInterfaceParametersStruct = (0, superstruct_1.object)({
|
|
54
51
|
id: (0, superstruct_1.string)(),
|
|
@@ -63,23 +60,22 @@ const UpdateInterfaceParametersStruct = (0, superstruct_1.object)({
|
|
|
63
60
|
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
64
61
|
* function.
|
|
65
62
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
66
|
-
* @param
|
|
67
|
-
* @param
|
|
68
|
-
* permission.
|
|
69
|
-
* @param hooks.updateInterface - The function to update the interface.
|
|
63
|
+
* @param _hooks - The RPC method hooks. Not used by this function.
|
|
64
|
+
* @param messenger - The messenger used to call controller actions.
|
|
70
65
|
* @returns Nothing.
|
|
71
66
|
*/
|
|
72
|
-
function getUpdateInterfaceImplementation(req, res, _next, end,
|
|
73
|
-
|
|
67
|
+
function getUpdateInterfaceImplementation(req, res, _next, end, _hooks, messenger) {
|
|
68
|
+
const { params, origin } = req;
|
|
69
|
+
const isPermitted = utils_1.UI_PERMISSIONS.some((permission) => messenger.call('PermissionController:hasPermission', origin, permission));
|
|
70
|
+
if (!isPermitted) {
|
|
74
71
|
return end(rpc_errors_1.providerErrors.unauthorized({
|
|
75
72
|
message: `This method can only be used if the Snap has one of the following permissions: ${utils_1.UI_PERMISSIONS.join(', ')}.`,
|
|
76
73
|
}));
|
|
77
74
|
}
|
|
78
|
-
const { params } = req;
|
|
79
75
|
try {
|
|
80
76
|
const validatedParams = getValidatedParams(params);
|
|
81
77
|
const { id, ui, context } = validatedParams;
|
|
82
|
-
updateInterface
|
|
78
|
+
messenger.call('SnapInterfaceController:updateInterface', origin, id, ui, context);
|
|
83
79
|
res.result = null;
|
|
84
80
|
}
|
|
85
81
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateInterface.cjs","sourceRoot":"","sources":["../../src/permitted/updateInterface.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"updateInterface.cjs","sourceRoot":"","sources":["../../src/permitted/updateInterface.ts"],"names":[],"mappings":";;;AAMA,qDAAiE;AAKjE,mDAG6B;AAE7B,uDAM+B;AAO/B,wCAA0C;AAM1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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AAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,+BAA+B,CAAC,CAAC;IACzD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,yBAAW,EAAE,CAAC;YACjC,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,sBAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type { Messenger } from '@metamask/messenger';\nimport type { PermissionControllerHasPermissionAction } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n UpdateInterfaceParams,\n UpdateInterfaceResult,\n} from '@metamask/snaps-sdk';\nimport {\n ComponentOrElementStruct,\n InterfaceContextStruct,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n StructError,\n create,\n object,\n optional,\n string,\n} from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type {\n JsonRpcRequestWithOrigin,\n SnapInterfaceControllerUpdateInterfaceAction,\n} from '../types';\nimport { UI_PERMISSIONS } from '../utils';\n\nexport type UpdateInterfaceMethodActions =\n | PermissionControllerHasPermissionAction\n | SnapInterfaceControllerUpdateInterfaceAction;\n\n/**\n * Update an interactive interface. For use in\n * [interactive UI](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/).\n *\n * @example\n * ```tsx\n * import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx';\n *\n * // First, create an interface and get its ID.\n * const id = await snap.request({\n * method: 'snap_createInterface',\n * params: {\n * ui: (\n * <Box>\n * ...\n * </Box>\n * ),\n * },\n * });\n *\n * // Later, update the interface with new content using the ID.\n * snap.request({\n * method: 'snap_updateInterface',\n * params: {\n * id: 'interface-id',\n * ui: (\n * <Box>\n * <Heading>Updated Interface</Heading>\n * <Text>This interface has been updated.</Text>\n * </Box>\n * ),\n * },\n * });\n * ```\n */\nexport const updateInterfaceHandler = {\n implementation: getUpdateInterfaceImplementation,\n actionNames: [\n 'PermissionController:hasPermission',\n 'SnapInterfaceController:updateInterface',\n ],\n} satisfies MethodHandler<\n never,\n UpdateInterfaceMethodActions,\n UpdateInterfaceParameters,\n UpdateInterfaceResult,\n { origin: string }\n>;\n\nconst UpdateInterfaceParametersStruct = object({\n id: string(),\n ui: ComponentOrElementStruct,\n context: optional(InterfaceContextStruct),\n});\n\nexport type UpdateInterfaceParameters = InferMatching<\n typeof UpdateInterfaceParametersStruct,\n UpdateInterfaceParams\n>;\n\n/**\n * The `snap_updateInterface` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param _hooks - The RPC method hooks. Not used by this function.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n */\nfunction getUpdateInterfaceImplementation(\n req: JsonRpcRequestWithOrigin<UpdateInterfaceParameters>,\n res: PendingJsonRpcResponse<UpdateInterfaceResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n _hooks: never,\n messenger: Messenger<string, UpdateInterfaceMethodActions>,\n): void {\n const { params, origin } = req;\n\n const isPermitted = UI_PERMISSIONS.some((permission) =>\n messenger.call('PermissionController:hasPermission', origin, permission),\n );\n\n if (!isPermitted) {\n return end(\n providerErrors.unauthorized({\n message: `This method can only be used if the Snap has one of the following permissions: ${UI_PERMISSIONS.join(', ')}.`,\n }),\n );\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id, ui, context } = validatedParams;\n\n messenger.call(\n 'SnapInterfaceController:updateInterface',\n origin,\n id,\n ui,\n context,\n );\n res.result = null;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the updateInterface method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated updateInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): UpdateInterfaceParameters {\n try {\n return create(params, UpdateInterfaceParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Messenger } from "@metamask/messenger";
|
|
3
|
+
import type { PermissionControllerHasPermissionAction } from "@metamask/permission-controller";
|
|
4
|
+
import type { UpdateInterfaceParams, UpdateInterfaceResult } from "@metamask/snaps-sdk";
|
|
3
5
|
import { type InferMatching } from "@metamask/snaps-utils";
|
|
4
6
|
import type { PendingJsonRpcResponse } from "@metamask/utils";
|
|
5
|
-
import type {
|
|
6
|
-
export type
|
|
7
|
-
/**
|
|
8
|
-
* @param permissionName - The name of the permission to check.
|
|
9
|
-
* @returns Whether the Snap has the permission.
|
|
10
|
-
*/
|
|
11
|
-
hasPermission: (permissionName: string) => boolean;
|
|
12
|
-
/**
|
|
13
|
-
* @param id - The interface ID.
|
|
14
|
-
* @param ui - The UI components.
|
|
15
|
-
* @param context - The optional interface context object.
|
|
16
|
-
*/
|
|
17
|
-
updateInterface: (id: string, ui: ComponentOrElement, context?: InterfaceContext) => void;
|
|
18
|
-
};
|
|
7
|
+
import type { JsonRpcRequestWithOrigin, SnapInterfaceControllerUpdateInterfaceAction } from "../types.cjs";
|
|
8
|
+
export type UpdateInterfaceMethodActions = PermissionControllerHasPermissionAction | SnapInterfaceControllerUpdateInterfaceAction;
|
|
19
9
|
/**
|
|
20
10
|
* Update an interactive interface. For use in
|
|
21
11
|
* [interactive UI](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/).
|
|
@@ -52,9 +42,8 @@ export type UpdateInterfaceMethodHooks = {
|
|
|
52
42
|
* ```
|
|
53
43
|
*/
|
|
54
44
|
export declare const updateInterfaceHandler: {
|
|
55
|
-
methodNames: ["snap_updateInterface"];
|
|
56
45
|
implementation: typeof getUpdateInterfaceImplementation;
|
|
57
|
-
|
|
46
|
+
actionNames: ("SnapInterfaceController:updateInterface" | "PermissionController:hasPermission")[];
|
|
58
47
|
};
|
|
59
48
|
declare const UpdateInterfaceParametersStruct: import("@metamask/superstruct").Struct<{
|
|
60
49
|
id: string;
|
|
@@ -246,12 +235,10 @@ export type UpdateInterfaceParameters = InferMatching<typeof UpdateInterfacePara
|
|
|
246
235
|
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
247
236
|
* function.
|
|
248
237
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
249
|
-
* @param
|
|
250
|
-
* @param
|
|
251
|
-
* permission.
|
|
252
|
-
* @param hooks.updateInterface - The function to update the interface.
|
|
238
|
+
* @param _hooks - The RPC method hooks. Not used by this function.
|
|
239
|
+
* @param messenger - The messenger used to call controller actions.
|
|
253
240
|
* @returns Nothing.
|
|
254
241
|
*/
|
|
255
|
-
declare function getUpdateInterfaceImplementation(req:
|
|
242
|
+
declare function getUpdateInterfaceImplementation(req: JsonRpcRequestWithOrigin<UpdateInterfaceParameters>, res: PendingJsonRpcResponse<UpdateInterfaceResult>, _next: unknown, end: JsonRpcEngineEndCallback, _hooks: never, messenger: Messenger<string, UpdateInterfaceMethodActions>): void;
|
|
256
243
|
export {};
|
|
257
244
|
//# sourceMappingURL=updateInterface.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateInterface.d.cts","sourceRoot":"","sources":["../../src/permitted/updateInterface.ts"],"names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B,CAAC,GACzD,IAAI,CAiCN"}
|
|
@@ -1,21 +1,11 @@
|
|
|
1
1
|
import type { JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
|
|
2
|
-
import type {
|
|
2
|
+
import type { Messenger } from "@metamask/messenger";
|
|
3
|
+
import type { PermissionControllerHasPermissionAction } from "@metamask/permission-controller";
|
|
4
|
+
import type { UpdateInterfaceParams, UpdateInterfaceResult } from "@metamask/snaps-sdk";
|
|
3
5
|
import { type InferMatching } from "@metamask/snaps-utils";
|
|
4
6
|
import type { PendingJsonRpcResponse } from "@metamask/utils";
|
|
5
|
-
import type {
|
|
6
|
-
export type
|
|
7
|
-
/**
|
|
8
|
-
* @param permissionName - The name of the permission to check.
|
|
9
|
-
* @returns Whether the Snap has the permission.
|
|
10
|
-
*/
|
|
11
|
-
hasPermission: (permissionName: string) => boolean;
|
|
12
|
-
/**
|
|
13
|
-
* @param id - The interface ID.
|
|
14
|
-
* @param ui - The UI components.
|
|
15
|
-
* @param context - The optional interface context object.
|
|
16
|
-
*/
|
|
17
|
-
updateInterface: (id: string, ui: ComponentOrElement, context?: InterfaceContext) => void;
|
|
18
|
-
};
|
|
7
|
+
import type { JsonRpcRequestWithOrigin, SnapInterfaceControllerUpdateInterfaceAction } from "../types.mjs";
|
|
8
|
+
export type UpdateInterfaceMethodActions = PermissionControllerHasPermissionAction | SnapInterfaceControllerUpdateInterfaceAction;
|
|
19
9
|
/**
|
|
20
10
|
* Update an interactive interface. For use in
|
|
21
11
|
* [interactive UI](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/).
|
|
@@ -52,9 +42,8 @@ export type UpdateInterfaceMethodHooks = {
|
|
|
52
42
|
* ```
|
|
53
43
|
*/
|
|
54
44
|
export declare const updateInterfaceHandler: {
|
|
55
|
-
methodNames: ["snap_updateInterface"];
|
|
56
45
|
implementation: typeof getUpdateInterfaceImplementation;
|
|
57
|
-
|
|
46
|
+
actionNames: ("SnapInterfaceController:updateInterface" | "PermissionController:hasPermission")[];
|
|
58
47
|
};
|
|
59
48
|
declare const UpdateInterfaceParametersStruct: import("@metamask/superstruct").Struct<{
|
|
60
49
|
id: string;
|
|
@@ -246,12 +235,10 @@ export type UpdateInterfaceParameters = InferMatching<typeof UpdateInterfacePara
|
|
|
246
235
|
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
247
236
|
* function.
|
|
248
237
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
249
|
-
* @param
|
|
250
|
-
* @param
|
|
251
|
-
* permission.
|
|
252
|
-
* @param hooks.updateInterface - The function to update the interface.
|
|
238
|
+
* @param _hooks - The RPC method hooks. Not used by this function.
|
|
239
|
+
* @param messenger - The messenger used to call controller actions.
|
|
253
240
|
* @returns Nothing.
|
|
254
241
|
*/
|
|
255
|
-
declare function getUpdateInterfaceImplementation(req:
|
|
242
|
+
declare function getUpdateInterfaceImplementation(req: JsonRpcRequestWithOrigin<UpdateInterfaceParameters>, res: PendingJsonRpcResponse<UpdateInterfaceResult>, _next: unknown, end: JsonRpcEngineEndCallback, _hooks: never, messenger: Messenger<string, UpdateInterfaceMethodActions>): void;
|
|
256
243
|
export {};
|
|
257
244
|
//# sourceMappingURL=updateInterface.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateInterface.d.mts","sourceRoot":"","sources":["../../src/permitted/updateInterface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"updateInterface.d.mts","sourceRoot":"","sources":["../../src/permitted/updateInterface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EAEzB,kCAAkC;AACnC,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,uCAAuC,EAAE,wCAAwC;AAE/F,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAK7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAQ3D,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB;AAE9D,OAAO,KAAK,EACV,wBAAwB,EACxB,4CAA4C,EAC7C,qBAAiB;AAGlB,MAAM,MAAM,4BAA4B,GACpC,uCAAuC,GACvC,4CAA4C,CAAC;AAEjD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,eAAO,MAAM,sBAAsB;;;CAYlC,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAInC,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,aAAa,CACnD,OAAO,+BAA+B,EACtC,qBAAqB,CACtB,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,iBAAS,gCAAgC,CACvC,GAAG,EAAE,wBAAwB,CAAC,yBAAyB,CAAC,EACxD,GAAG,EAAE,sBAAsB,CAAC,qBAAqB,CAAC,EAClD,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,wBAAwB,EAC7B,MAAM,EAAE,KAAK,EACb,SAAS,EAAE,SAAS,CAAC,MAAM,EAAE,4BAA4B,CAAC,GACzD,IAAI,CAiCN"}
|
|
@@ -2,11 +2,6 @@ import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
|
|
|
2
2
|
import { ComponentOrElementStruct, InterfaceContextStruct } from "@metamask/snaps-sdk";
|
|
3
3
|
import { StructError, create, object, optional, string } from "@metamask/superstruct";
|
|
4
4
|
import { UI_PERMISSIONS } from "../utils.mjs";
|
|
5
|
-
const methodName = 'snap_updateInterface';
|
|
6
|
-
const hookNames = {
|
|
7
|
-
hasPermission: true,
|
|
8
|
-
updateInterface: true,
|
|
9
|
-
};
|
|
10
5
|
/**
|
|
11
6
|
* Update an interactive interface. For use in
|
|
12
7
|
* [interactive UI](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/).
|
|
@@ -43,9 +38,11 @@ const hookNames = {
|
|
|
43
38
|
* ```
|
|
44
39
|
*/
|
|
45
40
|
export const updateInterfaceHandler = {
|
|
46
|
-
methodNames: [methodName],
|
|
47
41
|
implementation: getUpdateInterfaceImplementation,
|
|
48
|
-
|
|
42
|
+
actionNames: [
|
|
43
|
+
'PermissionController:hasPermission',
|
|
44
|
+
'SnapInterfaceController:updateInterface',
|
|
45
|
+
],
|
|
49
46
|
};
|
|
50
47
|
const UpdateInterfaceParametersStruct = object({
|
|
51
48
|
id: string(),
|
|
@@ -60,23 +57,22 @@ const UpdateInterfaceParametersStruct = object({
|
|
|
60
57
|
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
61
58
|
* function.
|
|
62
59
|
* @param end - The `json-rpc-engine` "end" callback.
|
|
63
|
-
* @param
|
|
64
|
-
* @param
|
|
65
|
-
* permission.
|
|
66
|
-
* @param hooks.updateInterface - The function to update the interface.
|
|
60
|
+
* @param _hooks - The RPC method hooks. Not used by this function.
|
|
61
|
+
* @param messenger - The messenger used to call controller actions.
|
|
67
62
|
* @returns Nothing.
|
|
68
63
|
*/
|
|
69
|
-
function getUpdateInterfaceImplementation(req, res, _next, end,
|
|
70
|
-
|
|
64
|
+
function getUpdateInterfaceImplementation(req, res, _next, end, _hooks, messenger) {
|
|
65
|
+
const { params, origin } = req;
|
|
66
|
+
const isPermitted = UI_PERMISSIONS.some((permission) => messenger.call('PermissionController:hasPermission', origin, permission));
|
|
67
|
+
if (!isPermitted) {
|
|
71
68
|
return end(providerErrors.unauthorized({
|
|
72
69
|
message: `This method can only be used if the Snap has one of the following permissions: ${UI_PERMISSIONS.join(', ')}.`,
|
|
73
70
|
}));
|
|
74
71
|
}
|
|
75
|
-
const { params } = req;
|
|
76
72
|
try {
|
|
77
73
|
const validatedParams = getValidatedParams(params);
|
|
78
74
|
const { id, ui, context } = validatedParams;
|
|
79
|
-
updateInterface
|
|
75
|
+
messenger.call('SnapInterfaceController:updateInterface', origin, id, ui, context);
|
|
80
76
|
res.result = null;
|
|
81
77
|
}
|
|
82
78
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateInterface.mjs","sourceRoot":"","sources":["../../src/permitted/updateInterface.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"updateInterface.mjs","sourceRoot":"","sources":["../../src/permitted/updateInterface.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAKjE,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACvB,4BAA4B;AAE7B,OAAO,EACL,WAAW,EACX,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,EACP,8BAA8B;AAO/B,OAAO,EAAE,cAAc,EAAE,qBAAiB;AAM1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAAG;IACpC,cAAc,EAAE,gCAAgC;IAChD,WAAW,EAAE;QACX,oCAAoC;QACpC,yCAAyC;KAC1C;CAOF,CAAC;AAEF,MAAM,+BAA+B,GAAG,MAAM,CAAC;IAC7C,EAAE,EAAE,MAAM,EAAE;IACZ,EAAE,EAAE,wBAAwB;IAC5B,OAAO,EAAE,QAAQ,CAAC,sBAAsB,CAAC;CAC1C,CAAC,CAAC;AAOH;;;;;;;;;;;GAWG;AACH,SAAS,gCAAgC,CACvC,GAAwD,EACxD,GAAkD,EAClD,KAAc,EACd,GAA6B,EAC7B,MAAa,EACb,SAA0D;IAE1D,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAE/B,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CACrD,SAAS,CAAC,IAAI,CAAC,oCAAoC,EAAE,MAAM,EAAE,UAAU,CAAC,CACzE,CAAC;IAEF,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,OAAO,GAAG,CACR,cAAc,CAAC,YAAY,CAAC;YAC1B,OAAO,EAAE,kFAAkF,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;SACxH,CAAC,CACH,CAAC;IACJ,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;QAE5C,SAAS,CAAC,IAAI,CACZ,yCAAyC,EACzC,MAAM,EACN,EAAE,EACF,EAAE,EACF,OAAO,CACR,CAAC;QACF,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC;IACpB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,+BAA+B,CAAC,CAAC;IACzD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type {\n JsonRpcEngineEndCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type { Messenger } from '@metamask/messenger';\nimport type { PermissionControllerHasPermissionAction } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n UpdateInterfaceParams,\n UpdateInterfaceResult,\n} from '@metamask/snaps-sdk';\nimport {\n ComponentOrElementStruct,\n InterfaceContextStruct,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n StructError,\n create,\n object,\n optional,\n string,\n} from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type {\n JsonRpcRequestWithOrigin,\n SnapInterfaceControllerUpdateInterfaceAction,\n} from '../types';\nimport { UI_PERMISSIONS } from '../utils';\n\nexport type UpdateInterfaceMethodActions =\n | PermissionControllerHasPermissionAction\n | SnapInterfaceControllerUpdateInterfaceAction;\n\n/**\n * Update an interactive interface. For use in\n * [interactive UI](https://docs.metamask.io/snaps/features/custom-ui/interactive-ui/).\n *\n * @example\n * ```tsx\n * import { Box, Heading, Text } from '@metamask/snaps-sdk/jsx';\n *\n * // First, create an interface and get its ID.\n * const id = await snap.request({\n * method: 'snap_createInterface',\n * params: {\n * ui: (\n * <Box>\n * ...\n * </Box>\n * ),\n * },\n * });\n *\n * // Later, update the interface with new content using the ID.\n * snap.request({\n * method: 'snap_updateInterface',\n * params: {\n * id: 'interface-id',\n * ui: (\n * <Box>\n * <Heading>Updated Interface</Heading>\n * <Text>This interface has been updated.</Text>\n * </Box>\n * ),\n * },\n * });\n * ```\n */\nexport const updateInterfaceHandler = {\n implementation: getUpdateInterfaceImplementation,\n actionNames: [\n 'PermissionController:hasPermission',\n 'SnapInterfaceController:updateInterface',\n ],\n} satisfies MethodHandler<\n never,\n UpdateInterfaceMethodActions,\n UpdateInterfaceParameters,\n UpdateInterfaceResult,\n { origin: string }\n>;\n\nconst UpdateInterfaceParametersStruct = object({\n id: string(),\n ui: ComponentOrElementStruct,\n context: optional(InterfaceContextStruct),\n});\n\nexport type UpdateInterfaceParameters = InferMatching<\n typeof UpdateInterfaceParametersStruct,\n UpdateInterfaceParams\n>;\n\n/**\n * The `snap_updateInterface` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param _hooks - The RPC method hooks. Not used by this function.\n * @param messenger - The messenger used to call controller actions.\n * @returns Nothing.\n */\nfunction getUpdateInterfaceImplementation(\n req: JsonRpcRequestWithOrigin<UpdateInterfaceParameters>,\n res: PendingJsonRpcResponse<UpdateInterfaceResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n _hooks: never,\n messenger: Messenger<string, UpdateInterfaceMethodActions>,\n): void {\n const { params, origin } = req;\n\n const isPermitted = UI_PERMISSIONS.some((permission) =>\n messenger.call('PermissionController:hasPermission', origin, permission),\n );\n\n if (!isPermitted) {\n return end(\n providerErrors.unauthorized({\n message: `This method can only be used if the Snap has one of the following permissions: ${UI_PERMISSIONS.join(', ')}.`,\n }),\n );\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id, ui, context } = validatedParams;\n\n messenger.call(\n 'SnapInterfaceController:updateInterface',\n origin,\n id,\n ui,\n context,\n );\n res.result = null;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the updateInterface method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated updateInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): UpdateInterfaceParameters {\n try {\n return create(params, UpdateInterfaceParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|