@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
|
@@ -3,7 +3,7 @@ import { rpcErrors } from "@metamask/rpc-errors";
|
|
|
3
3
|
import { enumValue, NotificationType, union, ContentType, getErrorMessage, ComponentOrElementStruct } from "@metamask/snaps-sdk";
|
|
4
4
|
import { createUnion, validateLink, validateTextLinks } from "@metamask/snaps-utils";
|
|
5
5
|
import { object, string, optional } from "@metamask/superstruct";
|
|
6
|
-
import { hasProperty, isObject } from "@metamask/utils";
|
|
6
|
+
import { assertExhaustive, hasProperty, isObject } from "@metamask/utils";
|
|
7
7
|
const methodName = 'snap_notify';
|
|
8
8
|
const NativeNotificationStruct = object({
|
|
9
9
|
type: enumValue(NotificationType.Native),
|
|
@@ -34,25 +34,22 @@ const NotificationParametersStruct = union([
|
|
|
34
34
|
*
|
|
35
35
|
* @param options - The specification builder options.
|
|
36
36
|
* @param options.allowedCaveats - The optional allowed caveats for the permission.
|
|
37
|
+
* @param options.messenger - The messenger.
|
|
37
38
|
* @param options.methodHooks - The RPC method hooks needed by the method implementation.
|
|
38
39
|
* @returns The specification for the `snap_notify` permission.
|
|
39
40
|
*/
|
|
40
|
-
export const specificationBuilder = ({ allowedCaveats = null, methodHooks }) => {
|
|
41
|
+
export const specificationBuilder = ({ allowedCaveats = null, methodHooks, messenger, }) => {
|
|
41
42
|
return {
|
|
42
43
|
permissionType: PermissionType.RestrictedMethod,
|
|
43
44
|
targetName: methodName,
|
|
44
45
|
allowedCaveats,
|
|
45
|
-
methodImplementation: getImplementation(methodHooks),
|
|
46
|
+
methodImplementation: getImplementation({ methodHooks, messenger }),
|
|
46
47
|
subjectTypes: [SubjectType.Snap],
|
|
47
48
|
};
|
|
48
49
|
};
|
|
49
50
|
const methodHooks = {
|
|
50
|
-
showNativeNotification: true,
|
|
51
|
-
showInAppNotification: true,
|
|
52
51
|
isOnPhishingList: true,
|
|
53
52
|
maybeUpdatePhishingList: true,
|
|
54
|
-
createInterface: true,
|
|
55
|
-
getSnap: true,
|
|
56
53
|
};
|
|
57
54
|
/**
|
|
58
55
|
* Display a
|
|
@@ -132,38 +129,47 @@ export const notifyBuilder = Object.freeze({
|
|
|
132
129
|
targetName: methodName,
|
|
133
130
|
specificationBuilder,
|
|
134
131
|
methodHooks,
|
|
132
|
+
actionNames: [
|
|
133
|
+
'RateLimitController:call',
|
|
134
|
+
'SnapController:getSnap',
|
|
135
|
+
'SnapInterfaceController:createInterface',
|
|
136
|
+
],
|
|
135
137
|
});
|
|
136
138
|
/**
|
|
137
139
|
* Builds the method implementation for `snap_notify`.
|
|
138
140
|
*
|
|
139
|
-
* @param
|
|
140
|
-
* @param
|
|
141
|
-
* @param
|
|
142
|
-
* @param
|
|
143
|
-
* @param
|
|
144
|
-
* @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.
|
|
145
|
-
* @param hooks.getSnap - A function that checks if a snap is installed.
|
|
141
|
+
* @param options - The options.
|
|
142
|
+
* @param options.messenger - The messenger.
|
|
143
|
+
* @param options.methodHooks - The RPC method hooks.
|
|
144
|
+
* @param options.methodHooks.isOnPhishingList - A function that checks for links against the phishing list.
|
|
145
|
+
* @param options.methodHooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.
|
|
146
146
|
* @returns The method implementation which returns `null` on success.
|
|
147
147
|
* @throws If the params are invalid.
|
|
148
148
|
*/
|
|
149
|
-
export function getImplementation({
|
|
149
|
+
export function getImplementation({ methodHooks: { isOnPhishingList, maybeUpdatePhishingList }, messenger, }) {
|
|
150
150
|
return async function implementation(args) {
|
|
151
151
|
const { params, context: { origin }, } = args;
|
|
152
152
|
await maybeUpdatePhishingList();
|
|
153
|
-
const validatedParams = getValidatedParams(params, isOnPhishingList,
|
|
153
|
+
const validatedParams = getValidatedParams(params, isOnPhishingList, messenger);
|
|
154
154
|
if (hasProperty(validatedParams, 'content')) {
|
|
155
|
-
const id =
|
|
155
|
+
const id = messenger.call('SnapInterfaceController:createInterface', origin, validatedParams.content, undefined, ContentType.Notification);
|
|
156
156
|
validatedParams.content = id;
|
|
157
157
|
}
|
|
158
158
|
switch (validatedParams.type) {
|
|
159
159
|
case NotificationType.Native:
|
|
160
|
-
return await
|
|
161
|
-
case NotificationType.InApp:
|
|
162
|
-
|
|
160
|
+
return (await messenger.call('RateLimitController:call', origin, 'showNativeNotification', origin, validatedParams.message));
|
|
161
|
+
case NotificationType.InApp: {
|
|
162
|
+
const { content, message, title, footerLink } = validatedParams;
|
|
163
|
+
return (await messenger.call('RateLimitController:call', origin, 'showInAppNotification', origin, {
|
|
164
|
+
interfaceId: content,
|
|
165
|
+
message,
|
|
166
|
+
title,
|
|
167
|
+
footerLink,
|
|
168
|
+
}));
|
|
169
|
+
}
|
|
170
|
+
/* istanbul ignore next */
|
|
163
171
|
default:
|
|
164
|
-
|
|
165
|
-
message: 'Must specify a valid notification "type".',
|
|
166
|
-
});
|
|
172
|
+
return assertExhaustive(validatedParams.type);
|
|
167
173
|
}
|
|
168
174
|
};
|
|
169
175
|
}
|
|
@@ -173,11 +179,11 @@ export function getImplementation({ showNativeNotification, showInAppNotificatio
|
|
|
173
179
|
*
|
|
174
180
|
* @param params - The unvalidated params object from the method request.
|
|
175
181
|
* @param isOnPhishingList - The function that checks for links against the phishing list.
|
|
176
|
-
* @param
|
|
182
|
+
* @param messenger - The messenger.
|
|
177
183
|
* @returns The validated method parameter object.
|
|
178
184
|
* @throws If the params are invalid.
|
|
179
185
|
*/
|
|
180
|
-
export function getValidatedParams(params, isOnPhishingList,
|
|
186
|
+
export function getValidatedParams(params, isOnPhishingList, messenger) {
|
|
181
187
|
if (!isObject(params)) {
|
|
182
188
|
throw rpcErrors.invalidParams({
|
|
183
189
|
message: 'Expected params to be a single object.',
|
|
@@ -207,6 +213,7 @@ export function getValidatedParams(params, isOnPhishingList, getSnap) {
|
|
|
207
213
|
}
|
|
208
214
|
try {
|
|
209
215
|
const validatedParams = createUnion(params, NotificationParametersStruct, 'type');
|
|
216
|
+
const getSnap = (snapId) => messenger.call('SnapController:getSnap', snapId);
|
|
210
217
|
validateTextLinks(validatedParams.message, isOnPhishingList, getSnap);
|
|
211
218
|
if (hasProperty(validatedParams, 'footerLink')) {
|
|
212
219
|
validateLink(validatedParams.footerLink.href, isOnPhishingList, getSnap);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"notify.mjs","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAOjD,OAAO,EACL,SAAS,EACT,gBAAgB,EAChB,KAAK,EACL,WAAW,EACX,eAAe,EACf,wBAAwB,EACzB,4BAA4B;AAC7B,OAAO,EACL,WAAW,EACX,YAAY,EACZ,iBAAiB,EAClB,8BAA8B;AAE/B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,8BAA8B;AAEjE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,wBAAwB;AAIxD,MAAM,UAAU,GAAG,aAAa,CAAC;AAEjC,MAAM,wBAAwB,GAAG,MAAM,CAAC;IACtC,IAAI,EAAE,SAAS,CAAC,gBAAgB,CAAC,MAAM,CAAC;IACxC,OAAO,EAAE,MAAM,EAAE;CAClB,CAAC,CAAC;AAEH,MAAM,uBAAuB,GAAG,MAAM,CAAC;IACrC,IAAI,EAAE,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC;IACvC,OAAO,EAAE,MAAM,EAAE;CAClB,CAAC,CAAC;AAEH,MAAM,kCAAkC,GAAG,MAAM,CAAC;IAChD,IAAI,EAAE,SAAS,CAAC,gBAAgB,CAAC,KAAK,CAAC;IACvC,OAAO,EAAE,MAAM,EAAE;IACjB,OAAO,EAAE,wBAAwB;IACjC,KAAK,EAAE,MAAM,EAAE;IACf,UAAU,EAAE,QA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CAAC,CAAC;IACL,CAAC;IAED,MAAM,WAAW,GAAG,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC;IAC5D,+DAA+D;IAC/D,IACE,IAAI,KAAK,gBAAgB,CAAC,MAAM;QAChC,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,EACrC,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,yEAAyE;SAC5E,CAAC,CAAC;IACL,CAAC;IAED,IACE,IAAI,KAAK,gBAAgB,CAAC,KAAK;QAC/B,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC,EACtC,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,0EAA0E;SAC7E,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,WAAW,CACjC,MAAM,EACN,4BAA4B,EAC5B,MAAM,CACP,CAAC;QAEF,iBAAiB,CAAC,eAAe,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAEtE,IAAI,WAAW,CAAC,eAAe,EAAE,YAAY,CAAC,EAAE,CAAC;YAC/C,YAAY,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAC3E,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,eAAe,CAAC,KAAK,CAAC,EAAE;SACrD,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n NotifyParams,\n NotifyResult,\n InterfaceContext,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport {\n enumValue,\n NotificationType,\n union,\n ContentType,\n getErrorMessage,\n ComponentOrElementStruct,\n} from '@metamask/snaps-sdk';\nimport {\n createUnion,\n validateLink,\n validateTextLinks,\n} from '@metamask/snaps-utils';\nimport type { InferMatching, Snap } from '@metamask/snaps-utils';\nimport { object, string, optional } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_notify';\n\nconst NativeNotificationStruct = object({\n type: enumValue(NotificationType.Native),\n message: string(),\n});\n\nconst InAppNotificationStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n});\n\nconst InAppNotificationWithDetailsStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n content: ComponentOrElementStruct,\n title: string(),\n footerLink: optional(\n object({\n href: string(),\n text: string(),\n }),\n ),\n});\n\nconst NotificationParametersStruct = union([\n InAppNotificationStruct,\n InAppNotificationWithDetailsStruct,\n NativeNotificationStruct,\n]);\n\nexport type NotificationArgs = InferMatching<\n typeof NotificationParametersStruct,\n NotifyParams\n>;\n\nexport type NotifyMethodHooks = {\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showNativeNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n /**\n * @param snapId - The ID of the Snap that created the notification.\n * @param args - The notification arguments.\n */\n showInAppNotification: (\n snapId: string,\n args: NotificationArgs,\n ) => Promise<null>;\n\n isOnPhishingList: (url: string) => boolean;\n\n maybeUpdatePhishingList: () => Promise<void>;\n\n createInterface: (\n origin: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) => Promise<string>;\n getSnap: (snapId: string) => Snap | null;\n};\n\ntype SpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: NotifyMethodHooks;\n};\n\ntype Specification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_notify` permission.\n * `snap_notify` allows snaps to send multiple types of notifications to its users.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_notify` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n SpecificationBuilderOptions,\n Specification\n> = ({ allowedCaveats = null, methodHooks }: SpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<NotifyMethodHooks> = {\n showNativeNotification: true,\n showInAppNotification: true,\n isOnPhishingList: true,\n maybeUpdatePhishingList: true,\n createInterface: true,\n getSnap: true,\n};\n\n/**\n * Display a\n * [notification](https://docs.metamask.io/snaps/features/notifications/) in\n * MetaMask or natively in the OS. Snaps can trigger a short (up to 80\n * characters) notification message for actionable or time sensitive\n * information. `inApp` notifications can also include an optional\n * [expanded view](https://docs.metamask.io/snaps/features/notifications/#expanded-view).\n * The expanded view has a title, content, and optional footer link shown when\n * a user clicks on the notification.\n *\n * @example Basic in app notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'inApp',\n * message: 'This is an in-app notification',\n * },\n * });\n * ```\n *\n * @example Expandable in app notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'inApp',\n * message: 'This is an in-app notification',\n * title: 'Notification Title',\n * content: (\n * <Box>\n * <Text>This is the expanded content of the notification.</Text>\n * </Box>\n * ),\n * footerLink: {\n * href: 'https://example.com',\n * text: 'Click here for more info',\n * },\n * },\n * });\n * ```\n *\n * @example Native notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'native',\n * message: 'This is a native notification',\n * },\n * });\n * ```\n */\nexport const notifyBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `snap_notify`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.showNativeNotification - A function that shows a native browser notification.\n * @param hooks.showInAppNotification - A function that shows a notification in the MetaMask UI.\n * @param hooks.isOnPhishingList - A function that checks for links against the phishing list.\n * @param hooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getSnap - A function that checks if a snap is installed.\n * @returns The method implementation which returns `null` on success.\n * @throws If the params are invalid.\n */\nexport function getImplementation({\n showNativeNotification,\n showInAppNotification,\n isOnPhishingList,\n maybeUpdatePhishingList,\n createInterface,\n getSnap,\n}: NotifyMethodHooks) {\n return async function implementation(\n args: RestrictedMethodOptions<NotifyParams>,\n ): Promise<NotifyResult> {\n const {\n params,\n context: { origin },\n } = args;\n\n await maybeUpdatePhishingList();\n\n const validatedParams = getValidatedParams(\n params,\n isOnPhishingList,\n getSnap,\n );\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as ComponentOrElement,\n undefined,\n ContentType.Notification,\n );\n validatedParams.content = id;\n }\n\n switch (validatedParams.type) {\n case NotificationType.Native:\n return await showNativeNotification(origin, validatedParams);\n case NotificationType.InApp:\n return await showInAppNotification(origin, validatedParams);\n default:\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n };\n}\n\n/**\n * Validates the notify 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 * @param isOnPhishingList - The function that checks for links against the phishing list.\n * @param getSnap - A function that checks if a snap is installed.\n * @returns The validated method parameter object.\n * @throws If the params are invalid.\n */\nexport function getValidatedParams(\n params: unknown,\n isOnPhishingList: NotifyMethodHooks['isOnPhishingList'],\n getSnap: NotifyMethodHooks['getSnap'],\n): NotifyParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { type, message } = params;\n\n if (\n !type ||\n typeof type !== 'string' ||\n !Object.values(NotificationType).includes(type as NotificationType)\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n\n const isNotString = !message || typeof message !== 'string';\n // Set to the max message length on a Mac notification for now.\n if (\n type === NotificationType.Native &&\n (isNotString || message.length >= 50)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 50 characters long.',\n });\n }\n\n if (\n type === NotificationType.InApp &&\n (isNotString || message.length >= 500)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 500 characters long.',\n });\n }\n\n try {\n const validatedParams = createUnion(\n params,\n NotificationParametersStruct,\n 'type',\n );\n\n validateTextLinks(validatedParams.message, isOnPhishingList, getSnap);\n\n if (hasProperty(validatedParams, 'footerLink')) {\n validateLink(validatedParams.footerLink.href, isOnPhishingList, getSnap);\n }\n\n return validatedParams;\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${getErrorMessage(error)}`,\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"notify.mjs","sourceRoot":"","sources":["../../src/restricted/notify.ts"],"names":[],"mappings":"AAMA,OAAO,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,MAAM,WAAW,GAAG,CAAC,OAAO,IAAI,OAAO,OAAO,KAAK,QAAQ,CAAC;IAC5D,+DAA+D;IAC/D,IACE,IAAI,KAAK,gBAAgB,CAAC,MAAM;QAChC,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,EACrC,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,yEAAyE;SAC5E,CAAC,CAAC;IACL,CAAC;IAED,IACE,IAAI,KAAK,gBAAgB,CAAC,KAAK;QAC/B,CAAC,WAAW,IAAI,OAAO,CAAC,MAAM,IAAI,GAAG,CAAC,EACtC,CAAC;QACD,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EACL,0EAA0E;SAC7E,CAAC,CAAC;IACL,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,WAAW,CACjC,MAAM,EACN,4BAA4B,EAC5B,MAAM,CACP,CAAC;QAEF,MAAM,OAAO,GAAG,CAAC,MAAc,EAAE,EAAE,CACjC,SAAS,CAAC,IAAI,CAAC,wBAAwB,EAAE,MAAM,CAAC,CAAC;QAEnD,iBAAiB,CAAC,eAAe,CAAC,OAAO,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAEtE,IAAI,WAAW,CAAC,eAAe,EAAE,YAAY,CAAC,EAAE,CAAC;YAC/C,YAAY,CAAC,eAAe,CAAC,UAAU,CAAC,IAAI,EAAE,gBAAgB,EAAE,OAAO,CAAC,CAAC;QAC3E,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,eAAe,CAAC,KAAK,CAAC,EAAE;SACrD,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type { Messenger } from '@metamask/messenger';\nimport type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n NotifyParams,\n NotifyResult,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport {\n enumValue,\n NotificationType,\n union,\n ContentType,\n getErrorMessage,\n ComponentOrElementStruct,\n} from '@metamask/snaps-sdk';\nimport {\n createUnion,\n validateLink,\n validateTextLinks,\n} from '@metamask/snaps-utils';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport { object, string, optional } from '@metamask/superstruct';\nimport type { NonEmptyArray } from '@metamask/utils';\nimport { assertExhaustive, hasProperty, isObject } from '@metamask/utils';\n\nimport type {\n RateLimitControllerCallAction,\n SnapControllerGetSnapAction,\n SnapInterfaceControllerCreateInterfaceAction,\n} from '../types';\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_notify';\n\nconst NativeNotificationStruct = object({\n type: enumValue(NotificationType.Native),\n message: string(),\n});\n\nconst InAppNotificationStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n});\n\nconst InAppNotificationWithDetailsStruct = object({\n type: enumValue(NotificationType.InApp),\n message: string(),\n content: ComponentOrElementStruct,\n title: string(),\n footerLink: optional(\n object({\n href: string(),\n text: string(),\n }),\n ),\n});\n\nconst NotificationParametersStruct = union([\n InAppNotificationStruct,\n InAppNotificationWithDetailsStruct,\n NativeNotificationStruct,\n]);\n\nexport type NotificationArgs = InferMatching<\n typeof NotificationParametersStruct,\n NotifyParams\n>;\n\nexport type NotifyMethodHooks = {\n isOnPhishingList: (url: string) => boolean;\n\n maybeUpdatePhishingList: () => Promise<void>;\n};\n\nexport type NotifyMessengerActions =\n | RateLimitControllerCallAction\n | SnapControllerGetSnapAction\n | SnapInterfaceControllerCreateInterfaceAction;\n\ntype SpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: NotifyMethodHooks;\n messenger: Messenger<string, NotifyMessengerActions>;\n};\n\ntype Specification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_notify` permission.\n * `snap_notify` allows snaps to send multiple types of notifications to its users.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.messenger - The messenger.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_notify` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n SpecificationBuilderOptions,\n Specification\n> = ({\n allowedCaveats = null,\n methodHooks,\n messenger,\n}: SpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getImplementation({ methodHooks, messenger }),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<NotifyMethodHooks> = {\n isOnPhishingList: true,\n maybeUpdatePhishingList: true,\n};\n\n/**\n * Display a\n * [notification](https://docs.metamask.io/snaps/features/notifications/) in\n * MetaMask or natively in the OS. Snaps can trigger a short (up to 80\n * characters) notification message for actionable or time sensitive\n * information. `inApp` notifications can also include an optional\n * [expanded view](https://docs.metamask.io/snaps/features/notifications/#expanded-view).\n * The expanded view has a title, content, and optional footer link shown when\n * a user clicks on the notification.\n *\n * @example Basic in app notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'inApp',\n * message: 'This is an in-app notification',\n * },\n * });\n * ```\n *\n * @example Expandable in app notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'inApp',\n * message: 'This is an in-app notification',\n * title: 'Notification Title',\n * content: (\n * <Box>\n * <Text>This is the expanded content of the notification.</Text>\n * </Box>\n * ),\n * footerLink: {\n * href: 'https://example.com',\n * text: 'Click here for more info',\n * },\n * },\n * });\n * ```\n *\n * @example Native notification\n * ```json name=\"Manifest\"\n * {\n * \"initialPermissions\": {\n * \"snap_notify\": {}\n * }\n * }\n * ```\n * ```ts name=\"Usage\"\n * snap.request({\n * method: 'snap_notify',\n * params: {\n * type: 'native',\n * message: 'This is a native notification',\n * },\n * });\n * ```\n */\nexport const notifyBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n actionNames: [\n 'RateLimitController:call',\n 'SnapController:getSnap',\n 'SnapInterfaceController:createInterface',\n ],\n} as const);\n\n/**\n * Builds the method implementation for `snap_notify`.\n *\n * @param options - The options.\n * @param options.messenger - The messenger.\n * @param options.methodHooks - The RPC method hooks.\n * @param options.methodHooks.isOnPhishingList - A function that checks for links against the phishing list.\n * @param options.methodHooks.maybeUpdatePhishingList - A function that updates the phishing list if needed.\n * @returns The method implementation which returns `null` on success.\n * @throws If the params are invalid.\n */\nexport function getImplementation({\n methodHooks: { isOnPhishingList, maybeUpdatePhishingList },\n messenger,\n}: SpecificationBuilderOptions) {\n return async function implementation(\n args: RestrictedMethodOptions<NotifyParams>,\n ): Promise<NotifyResult> {\n const {\n params,\n context: { origin },\n } = args;\n\n await maybeUpdatePhishingList();\n\n const validatedParams = getValidatedParams(\n params,\n isOnPhishingList,\n messenger,\n );\n\n if (hasProperty(validatedParams, 'content')) {\n const id = messenger.call(\n 'SnapInterfaceController:createInterface',\n origin,\n validatedParams.content as ComponentOrElement,\n undefined,\n ContentType.Notification,\n );\n validatedParams.content = id;\n }\n\n switch (validatedParams.type) {\n case NotificationType.Native:\n return (await messenger.call(\n 'RateLimitController:call',\n origin,\n 'showNativeNotification',\n origin,\n validatedParams.message,\n )) as NotifyResult;\n case NotificationType.InApp: {\n const { content, message, title, footerLink } =\n validatedParams as NotificationArgs & {\n content?: string;\n title?: string;\n footerLink?: { href: string; text: string };\n };\n return (await messenger.call(\n 'RateLimitController:call',\n origin,\n 'showInAppNotification',\n origin,\n {\n interfaceId: content,\n message,\n title,\n footerLink,\n },\n )) as NotifyResult;\n }\n /* istanbul ignore next */\n default:\n return assertExhaustive(validatedParams.type as never);\n }\n };\n}\n\n/**\n * Validates the notify 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 * @param isOnPhishingList - The function that checks for links against the phishing list.\n * @param messenger - The messenger.\n * @returns The validated method parameter object.\n * @throws If the params are invalid.\n */\nexport function getValidatedParams(\n params: unknown,\n isOnPhishingList: NotifyMethodHooks['isOnPhishingList'],\n messenger: Messenger<string, NotifyMessengerActions>,\n): NotifyParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { type, message } = params;\n\n if (\n !type ||\n typeof type !== 'string' ||\n !Object.values(NotificationType).includes(type as NotificationType)\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid notification \"type\".',\n });\n }\n\n const isNotString = !message || typeof message !== 'string';\n // Set to the max message length on a Mac notification for now.\n if (\n type === NotificationType.Native &&\n (isNotString || message.length >= 50)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 50 characters long.',\n });\n }\n\n if (\n type === NotificationType.InApp &&\n (isNotString || message.length >= 500)\n ) {\n throw rpcErrors.invalidParams({\n message:\n 'Must specify a non-empty string \"message\" less than 500 characters long.',\n });\n }\n\n try {\n const validatedParams = createUnion(\n params,\n NotificationParametersStruct,\n 'type',\n );\n\n const getSnap = (snapId: string) =>\n messenger.call('SnapController:getSnap', snapId);\n\n validateTextLinks(validatedParams.message, isOnPhishingList, getSnap);\n\n if (hasProperty(validatedParams, 'footerLink')) {\n validateLink(validatedParams.footerLink.href, isOnPhishingList, getSnap);\n }\n\n return validatedParams;\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${getErrorMessage(error)}`,\n });\n }\n}\n"]}
|
package/dist/types.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.cjs","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"","sourcesContent":["import type {\n AuxiliaryFileEncoding,\n BackgroundEvent,\n ComponentOrElement,\n GetSnapsResult,\n GetWebSocketsResult,\n InterfaceContext,\n InterfaceState,\n RequestSnapsResult,\n ContentType,\n RequestSnapsParams,\n SnapId,\n} from '@metamask/snaps-sdk';\nimport type {\n Snap,\n SnapRpcHookArgs,\n TruncatedSnap,\n} from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nexport type JsonRpcRequestWithOrigin<\n Params extends JsonRpcParams = JsonRpcParams,\n> = JsonRpcRequest<Params> & { origin: string };\n\nexport type HdKeyring = {\n type: 'HD Key Tree';\n seed?: Uint8Array;\n mnemonic?: Uint8Array;\n};\n\nexport type KeyringControllerWithKeyringAction = {\n type: 'KeyringController:withKeyring';\n handler: (\n selector:\n | {\n type: string;\n index?: number;\n }\n | { id: string },\n operation: (args: { keyring: HdKeyring }) => Promise<unknown>,\n ) => Promise<unknown>;\n};\n\nexport type KeyringControllerGetStateAction = {\n type: `KeyringController:getState`;\n handler: () => {\n isUnlocked: boolean;\n keyrings: {\n type: string;\n metadata: { id: string; name: string };\n }[];\n };\n};\n\nexport type ApprovalControllerAddRequestAction = {\n type: 'ApprovalController:addRequest';\n handler: (\n opts: {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record<string, unknown>;\n requestState?: Record<string, Json>;\n },\n shouldShowRequest: boolean,\n ) => Promise<Json>;\n};\n\nexport type SnapInterfaceControllerCreateInterfaceAction = {\n type: 'SnapInterfaceController:createInterface';\n handler: (\n snapId: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) => string;\n};\n\nexport type SnapInterfaceControllerGetInterfaceAction = {\n type: 'SnapInterfaceController:getInterface';\n handler: (\n snapId: string,\n id: string,\n ) => {\n content: ComponentOrElement;\n snapId: SnapId;\n state: InterfaceState;\n context: InterfaceContext | null;\n };\n};\n\nexport type SnapInterfaceControllerSetInterfaceDisplayedAction = {\n type: 'SnapInterfaceController:setInterfaceDisplayed';\n handler: (snapId: string, id: string) => void;\n};\n\nexport type SnapInterfaceControllerGetInterfaceStateAction = {\n type: `SnapInterfaceController:getInterfaceState`;\n handler: (snapId: string, id: string) => InterfaceState;\n};\n\nexport type SnapInterfaceControllerUpdateInterfaceAction = {\n type: `SnapInterfaceController:updateInterface`;\n handler: (\n snapId: string,\n id: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n ) => void;\n};\n\nexport type SnapInterfaceControllerResolveInterfaceAction = {\n type: `SnapInterfaceController:resolveInterface`;\n handler: (snapId: string, id: string, value: Json) => Promise<void>;\n};\n\nexport type SnapControllerHandleRequestAction = {\n type: 'SnapController:handleRequest';\n handler: (args: SnapRpcHookArgs & { snapId: string }) => Promise<unknown>;\n};\n\nexport type SnapControllerGetSnapAction = {\n type: 'SnapController:getSnap';\n handler: (snapId: string) => Snap | null;\n};\n\nexport type SnapControllerClearSnapStateAction = {\n type: 'SnapController:clearSnapState';\n handler: (snapId: string, encrypted: boolean) => void;\n};\n\nexport type SnapControllerGetSnapStateAction = {\n type: 'SnapController:getSnapState';\n handler: (\n snapId: string,\n encrypted: boolean,\n ) => Promise<Record<string, Json> | null>;\n};\n\nexport type SnapControllerUpdateSnapStateAction = {\n type: 'SnapController:updateSnapState';\n handler: (\n snapId: string,\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n};\n\nexport type SnapControllerGetAllSnapsAction = {\n type: `SnapController:getAllSnaps`;\n handler: () => TruncatedSnap[];\n};\n\nexport type SnapControllerGetPermittedSnapsAction = {\n type: `SnapController:getPermittedSnaps`;\n handler: (origin: string) => GetSnapsResult;\n};\n\nexport type SnapControllerInstallSnapsAction = {\n type: `SnapController:installSnaps`;\n handler: (\n origin: string,\n requestedSnaps: RequestSnapsParams,\n ) => Promise<RequestSnapsResult>;\n};\n\nexport type SnapControllerGetSnapFileAction = {\n type: `SnapController:getSnapFile`;\n handler: (\n snapId: string,\n path: string,\n encoding?: AuxiliaryFileEncoding,\n ) => Promise<string | null>;\n};\n\nexport type RateLimitControllerCallAction = {\n type: 'RateLimitController:call';\n handler: (\n origin: string,\n type: string,\n ...args: unknown[]\n ) => Promise<unknown>;\n};\n\nexport type CronjobControllerCancelAction = {\n type: `CronjobController:cancel`;\n handler: (origin: string, id: string) => void;\n};\n\nexport type CronjobControllerScheduleAction = {\n type: `CronjobController:schedule`;\n handler: (event: {\n snapId: string;\n request: {\n method: string;\n jsonrpc?: '2.0';\n id?: string | number | null;\n params?: Json[] | Record<string, Json>;\n };\n schedule: string;\n id?: string;\n }) => string;\n};\n\nexport type CronjobControllerGetAction = {\n type: `CronjobController:get`;\n handler: (snapId: string) => BackgroundEvent[];\n};\n\nexport type WebSocketServiceOpenAction = {\n type: `WebSocketService:open`;\n handler: (\n snapId: string,\n url: string,\n protocols?: string[],\n ) => Promise<string>;\n};\n\nexport type WebSocketServiceCloseAction = {\n type: `WebSocketService:close`;\n handler: (snapId: string, id: string) => void;\n};\n\nexport type WebSocketServiceSendMessageAction = {\n type: `WebSocketService:sendMessage`;\n handler: (\n snapId: string,\n id: string,\n data: string | number[],\n ) => Promise<void>;\n};\n\nexport type WebSocketServiceGetAllAction = {\n type: `WebSocketService:getAll`;\n handler: (snapId: string) => GetWebSocketsResult;\n};\n"]}
|
package/dist/types.d.cts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { AuxiliaryFileEncoding, BackgroundEvent, ComponentOrElement, GetSnapsResult, GetWebSocketsResult, InterfaceContext, InterfaceState, RequestSnapsResult, ContentType, RequestSnapsParams, SnapId } from "@metamask/snaps-sdk";
|
|
2
|
+
import type { Snap, SnapRpcHookArgs, TruncatedSnap } from "@metamask/snaps-utils";
|
|
3
|
+
import type { Json, JsonRpcParams, JsonRpcRequest } from "@metamask/utils";
|
|
4
|
+
export type JsonRpcRequestWithOrigin<Params extends JsonRpcParams = JsonRpcParams> = JsonRpcRequest<Params> & {
|
|
5
|
+
origin: string;
|
|
6
|
+
};
|
|
7
|
+
export type HdKeyring = {
|
|
8
|
+
type: 'HD Key Tree';
|
|
9
|
+
seed?: Uint8Array;
|
|
10
|
+
mnemonic?: Uint8Array;
|
|
11
|
+
};
|
|
12
|
+
export type KeyringControllerWithKeyringAction = {
|
|
13
|
+
type: 'KeyringController:withKeyring';
|
|
14
|
+
handler: (selector: {
|
|
15
|
+
type: string;
|
|
16
|
+
index?: number;
|
|
17
|
+
} | {
|
|
18
|
+
id: string;
|
|
19
|
+
}, operation: (args: {
|
|
20
|
+
keyring: HdKeyring;
|
|
21
|
+
}) => Promise<unknown>) => Promise<unknown>;
|
|
22
|
+
};
|
|
23
|
+
export type KeyringControllerGetStateAction = {
|
|
24
|
+
type: `KeyringController:getState`;
|
|
25
|
+
handler: () => {
|
|
26
|
+
isUnlocked: boolean;
|
|
27
|
+
keyrings: {
|
|
28
|
+
type: string;
|
|
29
|
+
metadata: {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
};
|
|
33
|
+
}[];
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export type ApprovalControllerAddRequestAction = {
|
|
37
|
+
type: 'ApprovalController:addRequest';
|
|
38
|
+
handler: (opts: {
|
|
39
|
+
id?: string;
|
|
40
|
+
origin: string;
|
|
41
|
+
type: string;
|
|
42
|
+
requestData?: Record<string, unknown>;
|
|
43
|
+
requestState?: Record<string, Json>;
|
|
44
|
+
}, shouldShowRequest: boolean) => Promise<Json>;
|
|
45
|
+
};
|
|
46
|
+
export type SnapInterfaceControllerCreateInterfaceAction = {
|
|
47
|
+
type: 'SnapInterfaceController:createInterface';
|
|
48
|
+
handler: (snapId: string, content: ComponentOrElement, context?: InterfaceContext, contentType?: ContentType) => string;
|
|
49
|
+
};
|
|
50
|
+
export type SnapInterfaceControllerGetInterfaceAction = {
|
|
51
|
+
type: 'SnapInterfaceController:getInterface';
|
|
52
|
+
handler: (snapId: string, id: string) => {
|
|
53
|
+
content: ComponentOrElement;
|
|
54
|
+
snapId: SnapId;
|
|
55
|
+
state: InterfaceState;
|
|
56
|
+
context: InterfaceContext | null;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export type SnapInterfaceControllerSetInterfaceDisplayedAction = {
|
|
60
|
+
type: 'SnapInterfaceController:setInterfaceDisplayed';
|
|
61
|
+
handler: (snapId: string, id: string) => void;
|
|
62
|
+
};
|
|
63
|
+
export type SnapInterfaceControllerGetInterfaceStateAction = {
|
|
64
|
+
type: `SnapInterfaceController:getInterfaceState`;
|
|
65
|
+
handler: (snapId: string, id: string) => InterfaceState;
|
|
66
|
+
};
|
|
67
|
+
export type SnapInterfaceControllerUpdateInterfaceAction = {
|
|
68
|
+
type: `SnapInterfaceController:updateInterface`;
|
|
69
|
+
handler: (snapId: string, id: string, content: ComponentOrElement, context?: InterfaceContext) => void;
|
|
70
|
+
};
|
|
71
|
+
export type SnapInterfaceControllerResolveInterfaceAction = {
|
|
72
|
+
type: `SnapInterfaceController:resolveInterface`;
|
|
73
|
+
handler: (snapId: string, id: string, value: Json) => Promise<void>;
|
|
74
|
+
};
|
|
75
|
+
export type SnapControllerHandleRequestAction = {
|
|
76
|
+
type: 'SnapController:handleRequest';
|
|
77
|
+
handler: (args: SnapRpcHookArgs & {
|
|
78
|
+
snapId: string;
|
|
79
|
+
}) => Promise<unknown>;
|
|
80
|
+
};
|
|
81
|
+
export type SnapControllerGetSnapAction = {
|
|
82
|
+
type: 'SnapController:getSnap';
|
|
83
|
+
handler: (snapId: string) => Snap | null;
|
|
84
|
+
};
|
|
85
|
+
export type SnapControllerClearSnapStateAction = {
|
|
86
|
+
type: 'SnapController:clearSnapState';
|
|
87
|
+
handler: (snapId: string, encrypted: boolean) => void;
|
|
88
|
+
};
|
|
89
|
+
export type SnapControllerGetSnapStateAction = {
|
|
90
|
+
type: 'SnapController:getSnapState';
|
|
91
|
+
handler: (snapId: string, encrypted: boolean) => Promise<Record<string, Json> | null>;
|
|
92
|
+
};
|
|
93
|
+
export type SnapControllerUpdateSnapStateAction = {
|
|
94
|
+
type: 'SnapController:updateSnapState';
|
|
95
|
+
handler: (snapId: string, newState: Record<string, Json>, encrypted: boolean) => Promise<void>;
|
|
96
|
+
};
|
|
97
|
+
export type SnapControllerGetAllSnapsAction = {
|
|
98
|
+
type: `SnapController:getAllSnaps`;
|
|
99
|
+
handler: () => TruncatedSnap[];
|
|
100
|
+
};
|
|
101
|
+
export type SnapControllerGetPermittedSnapsAction = {
|
|
102
|
+
type: `SnapController:getPermittedSnaps`;
|
|
103
|
+
handler: (origin: string) => GetSnapsResult;
|
|
104
|
+
};
|
|
105
|
+
export type SnapControllerInstallSnapsAction = {
|
|
106
|
+
type: `SnapController:installSnaps`;
|
|
107
|
+
handler: (origin: string, requestedSnaps: RequestSnapsParams) => Promise<RequestSnapsResult>;
|
|
108
|
+
};
|
|
109
|
+
export type SnapControllerGetSnapFileAction = {
|
|
110
|
+
type: `SnapController:getSnapFile`;
|
|
111
|
+
handler: (snapId: string, path: string, encoding?: AuxiliaryFileEncoding) => Promise<string | null>;
|
|
112
|
+
};
|
|
113
|
+
export type RateLimitControllerCallAction = {
|
|
114
|
+
type: 'RateLimitController:call';
|
|
115
|
+
handler: (origin: string, type: string, ...args: unknown[]) => Promise<unknown>;
|
|
116
|
+
};
|
|
117
|
+
export type CronjobControllerCancelAction = {
|
|
118
|
+
type: `CronjobController:cancel`;
|
|
119
|
+
handler: (origin: string, id: string) => void;
|
|
120
|
+
};
|
|
121
|
+
export type CronjobControllerScheduleAction = {
|
|
122
|
+
type: `CronjobController:schedule`;
|
|
123
|
+
handler: (event: {
|
|
124
|
+
snapId: string;
|
|
125
|
+
request: {
|
|
126
|
+
method: string;
|
|
127
|
+
jsonrpc?: '2.0';
|
|
128
|
+
id?: string | number | null;
|
|
129
|
+
params?: Json[] | Record<string, Json>;
|
|
130
|
+
};
|
|
131
|
+
schedule: string;
|
|
132
|
+
id?: string;
|
|
133
|
+
}) => string;
|
|
134
|
+
};
|
|
135
|
+
export type CronjobControllerGetAction = {
|
|
136
|
+
type: `CronjobController:get`;
|
|
137
|
+
handler: (snapId: string) => BackgroundEvent[];
|
|
138
|
+
};
|
|
139
|
+
export type WebSocketServiceOpenAction = {
|
|
140
|
+
type: `WebSocketService:open`;
|
|
141
|
+
handler: (snapId: string, url: string, protocols?: string[]) => Promise<string>;
|
|
142
|
+
};
|
|
143
|
+
export type WebSocketServiceCloseAction = {
|
|
144
|
+
type: `WebSocketService:close`;
|
|
145
|
+
handler: (snapId: string, id: string) => void;
|
|
146
|
+
};
|
|
147
|
+
export type WebSocketServiceSendMessageAction = {
|
|
148
|
+
type: `WebSocketService:sendMessage`;
|
|
149
|
+
handler: (snapId: string, id: string, data: string | number[]) => Promise<void>;
|
|
150
|
+
};
|
|
151
|
+
export type WebSocketServiceGetAllAction = {
|
|
152
|
+
type: `WebSocketService:getAll`;
|
|
153
|
+
handler: (snapId: string) => GetWebSocketsResult;
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=types.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,MAAM,EACP,4BAA4B;AAC7B,OAAO,KAAK,EACV,IAAI,EACJ,eAAe,EACf,aAAa,EACd,8BAA8B;AAC/B,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,cAAc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C5B,MAAM,CAAC,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;SACxC,CAAC;QACF,QAAQ,EAAE,MAAM,CAAC;QACjB,EAAE,CAAC,EAAE,MAAM,CAAC;KACb,KAAK,MAAM,CAAC;CACd,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,eAAe,EAAE,CAAC;CAChD,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,IAAI,EAAE,uBAAuB,CAAC;IAC9B,OAAO,EAAE,CACP,MAAM,EAAE,MAAM,EACd,GAAG,EAAE,MAAM,EACX,SAAS,CAAC,EAAE,MAAM,EAAE,KACjB,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IACxC,IAAI,EAAE,wBAAwB,CAAC;IAC/B,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/C,CAAC;AAEF,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,CACP,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,MAAM,EACV,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,KACpB,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,4BAA4B,GAAG;IACzC,IAAI,EAAE,yBAAyB,CAAC;IAChC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,mBAAmB,CAAC;CAClD,CAAC"}
|
package/dist/types.d.mts
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import type { AuxiliaryFileEncoding, BackgroundEvent, ComponentOrElement, GetSnapsResult, GetWebSocketsResult, InterfaceContext, InterfaceState, RequestSnapsResult, ContentType, RequestSnapsParams, SnapId } from "@metamask/snaps-sdk";
|
|
2
|
+
import type { Snap, SnapRpcHookArgs, TruncatedSnap } from "@metamask/snaps-utils";
|
|
3
|
+
import type { Json, JsonRpcParams, JsonRpcRequest } from "@metamask/utils";
|
|
4
|
+
export type JsonRpcRequestWithOrigin<Params extends JsonRpcParams = JsonRpcParams> = JsonRpcRequest<Params> & {
|
|
5
|
+
origin: string;
|
|
6
|
+
};
|
|
7
|
+
export type HdKeyring = {
|
|
8
|
+
type: 'HD Key Tree';
|
|
9
|
+
seed?: Uint8Array;
|
|
10
|
+
mnemonic?: Uint8Array;
|
|
11
|
+
};
|
|
12
|
+
export type KeyringControllerWithKeyringAction = {
|
|
13
|
+
type: 'KeyringController:withKeyring';
|
|
14
|
+
handler: (selector: {
|
|
15
|
+
type: string;
|
|
16
|
+
index?: number;
|
|
17
|
+
} | {
|
|
18
|
+
id: string;
|
|
19
|
+
}, operation: (args: {
|
|
20
|
+
keyring: HdKeyring;
|
|
21
|
+
}) => Promise<unknown>) => Promise<unknown>;
|
|
22
|
+
};
|
|
23
|
+
export type KeyringControllerGetStateAction = {
|
|
24
|
+
type: `KeyringController:getState`;
|
|
25
|
+
handler: () => {
|
|
26
|
+
isUnlocked: boolean;
|
|
27
|
+
keyrings: {
|
|
28
|
+
type: string;
|
|
29
|
+
metadata: {
|
|
30
|
+
id: string;
|
|
31
|
+
name: string;
|
|
32
|
+
};
|
|
33
|
+
}[];
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export type ApprovalControllerAddRequestAction = {
|
|
37
|
+
type: 'ApprovalController:addRequest';
|
|
38
|
+
handler: (opts: {
|
|
39
|
+
id?: string;
|
|
40
|
+
origin: string;
|
|
41
|
+
type: string;
|
|
42
|
+
requestData?: Record<string, unknown>;
|
|
43
|
+
requestState?: Record<string, Json>;
|
|
44
|
+
}, shouldShowRequest: boolean) => Promise<Json>;
|
|
45
|
+
};
|
|
46
|
+
export type SnapInterfaceControllerCreateInterfaceAction = {
|
|
47
|
+
type: 'SnapInterfaceController:createInterface';
|
|
48
|
+
handler: (snapId: string, content: ComponentOrElement, context?: InterfaceContext, contentType?: ContentType) => string;
|
|
49
|
+
};
|
|
50
|
+
export type SnapInterfaceControllerGetInterfaceAction = {
|
|
51
|
+
type: 'SnapInterfaceController:getInterface';
|
|
52
|
+
handler: (snapId: string, id: string) => {
|
|
53
|
+
content: ComponentOrElement;
|
|
54
|
+
snapId: SnapId;
|
|
55
|
+
state: InterfaceState;
|
|
56
|
+
context: InterfaceContext | null;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
export type SnapInterfaceControllerSetInterfaceDisplayedAction = {
|
|
60
|
+
type: 'SnapInterfaceController:setInterfaceDisplayed';
|
|
61
|
+
handler: (snapId: string, id: string) => void;
|
|
62
|
+
};
|
|
63
|
+
export type SnapInterfaceControllerGetInterfaceStateAction = {
|
|
64
|
+
type: `SnapInterfaceController:getInterfaceState`;
|
|
65
|
+
handler: (snapId: string, id: string) => InterfaceState;
|
|
66
|
+
};
|
|
67
|
+
export type SnapInterfaceControllerUpdateInterfaceAction = {
|
|
68
|
+
type: `SnapInterfaceController:updateInterface`;
|
|
69
|
+
handler: (snapId: string, id: string, content: ComponentOrElement, context?: InterfaceContext) => void;
|
|
70
|
+
};
|
|
71
|
+
export type SnapInterfaceControllerResolveInterfaceAction = {
|
|
72
|
+
type: `SnapInterfaceController:resolveInterface`;
|
|
73
|
+
handler: (snapId: string, id: string, value: Json) => Promise<void>;
|
|
74
|
+
};
|
|
75
|
+
export type SnapControllerHandleRequestAction = {
|
|
76
|
+
type: 'SnapController:handleRequest';
|
|
77
|
+
handler: (args: SnapRpcHookArgs & {
|
|
78
|
+
snapId: string;
|
|
79
|
+
}) => Promise<unknown>;
|
|
80
|
+
};
|
|
81
|
+
export type SnapControllerGetSnapAction = {
|
|
82
|
+
type: 'SnapController:getSnap';
|
|
83
|
+
handler: (snapId: string) => Snap | null;
|
|
84
|
+
};
|
|
85
|
+
export type SnapControllerClearSnapStateAction = {
|
|
86
|
+
type: 'SnapController:clearSnapState';
|
|
87
|
+
handler: (snapId: string, encrypted: boolean) => void;
|
|
88
|
+
};
|
|
89
|
+
export type SnapControllerGetSnapStateAction = {
|
|
90
|
+
type: 'SnapController:getSnapState';
|
|
91
|
+
handler: (snapId: string, encrypted: boolean) => Promise<Record<string, Json> | null>;
|
|
92
|
+
};
|
|
93
|
+
export type SnapControllerUpdateSnapStateAction = {
|
|
94
|
+
type: 'SnapController:updateSnapState';
|
|
95
|
+
handler: (snapId: string, newState: Record<string, Json>, encrypted: boolean) => Promise<void>;
|
|
96
|
+
};
|
|
97
|
+
export type SnapControllerGetAllSnapsAction = {
|
|
98
|
+
type: `SnapController:getAllSnaps`;
|
|
99
|
+
handler: () => TruncatedSnap[];
|
|
100
|
+
};
|
|
101
|
+
export type SnapControllerGetPermittedSnapsAction = {
|
|
102
|
+
type: `SnapController:getPermittedSnaps`;
|
|
103
|
+
handler: (origin: string) => GetSnapsResult;
|
|
104
|
+
};
|
|
105
|
+
export type SnapControllerInstallSnapsAction = {
|
|
106
|
+
type: `SnapController:installSnaps`;
|
|
107
|
+
handler: (origin: string, requestedSnaps: RequestSnapsParams) => Promise<RequestSnapsResult>;
|
|
108
|
+
};
|
|
109
|
+
export type SnapControllerGetSnapFileAction = {
|
|
110
|
+
type: `SnapController:getSnapFile`;
|
|
111
|
+
handler: (snapId: string, path: string, encoding?: AuxiliaryFileEncoding) => Promise<string | null>;
|
|
112
|
+
};
|
|
113
|
+
export type RateLimitControllerCallAction = {
|
|
114
|
+
type: 'RateLimitController:call';
|
|
115
|
+
handler: (origin: string, type: string, ...args: unknown[]) => Promise<unknown>;
|
|
116
|
+
};
|
|
117
|
+
export type CronjobControllerCancelAction = {
|
|
118
|
+
type: `CronjobController:cancel`;
|
|
119
|
+
handler: (origin: string, id: string) => void;
|
|
120
|
+
};
|
|
121
|
+
export type CronjobControllerScheduleAction = {
|
|
122
|
+
type: `CronjobController:schedule`;
|
|
123
|
+
handler: (event: {
|
|
124
|
+
snapId: string;
|
|
125
|
+
request: {
|
|
126
|
+
method: string;
|
|
127
|
+
jsonrpc?: '2.0';
|
|
128
|
+
id?: string | number | null;
|
|
129
|
+
params?: Json[] | Record<string, Json>;
|
|
130
|
+
};
|
|
131
|
+
schedule: string;
|
|
132
|
+
id?: string;
|
|
133
|
+
}) => string;
|
|
134
|
+
};
|
|
135
|
+
export type CronjobControllerGetAction = {
|
|
136
|
+
type: `CronjobController:get`;
|
|
137
|
+
handler: (snapId: string) => BackgroundEvent[];
|
|
138
|
+
};
|
|
139
|
+
export type WebSocketServiceOpenAction = {
|
|
140
|
+
type: `WebSocketService:open`;
|
|
141
|
+
handler: (snapId: string, url: string, protocols?: string[]) => Promise<string>;
|
|
142
|
+
};
|
|
143
|
+
export type WebSocketServiceCloseAction = {
|
|
144
|
+
type: `WebSocketService:close`;
|
|
145
|
+
handler: (snapId: string, id: string) => void;
|
|
146
|
+
};
|
|
147
|
+
export type WebSocketServiceSendMessageAction = {
|
|
148
|
+
type: `WebSocketService:sendMessage`;
|
|
149
|
+
handler: (snapId: string, id: string, data: string | number[]) => Promise<void>;
|
|
150
|
+
};
|
|
151
|
+
export type WebSocketServiceGetAllAction = {
|
|
152
|
+
type: `WebSocketService:getAll`;
|
|
153
|
+
handler: (snapId: string) => GetWebSocketsResult;
|
|
154
|
+
};
|
|
155
|
+
//# sourceMappingURL=types.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.mts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,qBAAqB,EACrB,eAAe,EACf,kBAAkB,EAClB,cAAc,EACd,mBAAmB,EACnB,gBAAgB,EAChB,cAAc,EACd,kBAAkB,EAClB,WAAW,EACX,kBAAkB,EAClB,MAAM,EACP,4BAA4B;AAC7B,OAAO,KAAK,EACV,IAAI,EACJ,eAAe,EACf,aAAa,EACd,8BAA8B;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"names":[],"mappings":"","sourcesContent":["import type {\n AuxiliaryFileEncoding,\n BackgroundEvent,\n ComponentOrElement,\n GetSnapsResult,\n GetWebSocketsResult,\n InterfaceContext,\n InterfaceState,\n RequestSnapsResult,\n ContentType,\n RequestSnapsParams,\n SnapId,\n} from '@metamask/snaps-sdk';\nimport type {\n Snap,\n SnapRpcHookArgs,\n TruncatedSnap,\n} from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams, JsonRpcRequest } from '@metamask/utils';\n\nexport type JsonRpcRequestWithOrigin<\n Params extends JsonRpcParams = JsonRpcParams,\n> = JsonRpcRequest<Params> & { origin: string };\n\nexport type HdKeyring = {\n type: 'HD Key Tree';\n seed?: Uint8Array;\n mnemonic?: Uint8Array;\n};\n\nexport type KeyringControllerWithKeyringAction = {\n type: 'KeyringController:withKeyring';\n handler: (\n selector:\n | {\n type: string;\n index?: number;\n }\n | { id: string },\n operation: (args: { keyring: HdKeyring }) => Promise<unknown>,\n ) => Promise<unknown>;\n};\n\nexport type KeyringControllerGetStateAction = {\n type: `KeyringController:getState`;\n handler: () => {\n isUnlocked: boolean;\n keyrings: {\n type: string;\n metadata: { id: string; name: string };\n }[];\n };\n};\n\nexport type ApprovalControllerAddRequestAction = {\n type: 'ApprovalController:addRequest';\n handler: (\n opts: {\n id?: string;\n origin: string;\n type: string;\n requestData?: Record<string, unknown>;\n requestState?: Record<string, Json>;\n },\n shouldShowRequest: boolean,\n ) => Promise<Json>;\n};\n\nexport type SnapInterfaceControllerCreateInterfaceAction = {\n type: 'SnapInterfaceController:createInterface';\n handler: (\n snapId: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) => string;\n};\n\nexport type SnapInterfaceControllerGetInterfaceAction = {\n type: 'SnapInterfaceController:getInterface';\n handler: (\n snapId: string,\n id: string,\n ) => {\n content: ComponentOrElement;\n snapId: SnapId;\n state: InterfaceState;\n context: InterfaceContext | null;\n };\n};\n\nexport type SnapInterfaceControllerSetInterfaceDisplayedAction = {\n type: 'SnapInterfaceController:setInterfaceDisplayed';\n handler: (snapId: string, id: string) => void;\n};\n\nexport type SnapInterfaceControllerGetInterfaceStateAction = {\n type: `SnapInterfaceController:getInterfaceState`;\n handler: (snapId: string, id: string) => InterfaceState;\n};\n\nexport type SnapInterfaceControllerUpdateInterfaceAction = {\n type: `SnapInterfaceController:updateInterface`;\n handler: (\n snapId: string,\n id: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n ) => void;\n};\n\nexport type SnapInterfaceControllerResolveInterfaceAction = {\n type: `SnapInterfaceController:resolveInterface`;\n handler: (snapId: string, id: string, value: Json) => Promise<void>;\n};\n\nexport type SnapControllerHandleRequestAction = {\n type: 'SnapController:handleRequest';\n handler: (args: SnapRpcHookArgs & { snapId: string }) => Promise<unknown>;\n};\n\nexport type SnapControllerGetSnapAction = {\n type: 'SnapController:getSnap';\n handler: (snapId: string) => Snap | null;\n};\n\nexport type SnapControllerClearSnapStateAction = {\n type: 'SnapController:clearSnapState';\n handler: (snapId: string, encrypted: boolean) => void;\n};\n\nexport type SnapControllerGetSnapStateAction = {\n type: 'SnapController:getSnapState';\n handler: (\n snapId: string,\n encrypted: boolean,\n ) => Promise<Record<string, Json> | null>;\n};\n\nexport type SnapControllerUpdateSnapStateAction = {\n type: 'SnapController:updateSnapState';\n handler: (\n snapId: string,\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n};\n\nexport type SnapControllerGetAllSnapsAction = {\n type: `SnapController:getAllSnaps`;\n handler: () => TruncatedSnap[];\n};\n\nexport type SnapControllerGetPermittedSnapsAction = {\n type: `SnapController:getPermittedSnaps`;\n handler: (origin: string) => GetSnapsResult;\n};\n\nexport type SnapControllerInstallSnapsAction = {\n type: `SnapController:installSnaps`;\n handler: (\n origin: string,\n requestedSnaps: RequestSnapsParams,\n ) => Promise<RequestSnapsResult>;\n};\n\nexport type SnapControllerGetSnapFileAction = {\n type: `SnapController:getSnapFile`;\n handler: (\n snapId: string,\n path: string,\n encoding?: AuxiliaryFileEncoding,\n ) => Promise<string | null>;\n};\n\nexport type RateLimitControllerCallAction = {\n type: 'RateLimitController:call';\n handler: (\n origin: string,\n type: string,\n ...args: unknown[]\n ) => Promise<unknown>;\n};\n\nexport type CronjobControllerCancelAction = {\n type: `CronjobController:cancel`;\n handler: (origin: string, id: string) => void;\n};\n\nexport type CronjobControllerScheduleAction = {\n type: `CronjobController:schedule`;\n handler: (event: {\n snapId: string;\n request: {\n method: string;\n jsonrpc?: '2.0';\n id?: string | number | null;\n params?: Json[] | Record<string, Json>;\n };\n schedule: string;\n id?: string;\n }) => string;\n};\n\nexport type CronjobControllerGetAction = {\n type: `CronjobController:get`;\n handler: (snapId: string) => BackgroundEvent[];\n};\n\nexport type WebSocketServiceOpenAction = {\n type: `WebSocketService:open`;\n handler: (\n snapId: string,\n url: string,\n protocols?: string[],\n ) => Promise<string>;\n};\n\nexport type WebSocketServiceCloseAction = {\n type: `WebSocketService:close`;\n handler: (snapId: string, id: string) => void;\n};\n\nexport type WebSocketServiceSendMessageAction = {\n type: `WebSocketService:sendMessage`;\n handler: (\n snapId: string,\n id: string,\n data: string | number[],\n ) => Promise<void>;\n};\n\nexport type WebSocketServiceGetAllAction = {\n type: `WebSocketService:getAll`;\n handler: (snapId: string) => GetWebSocketsResult;\n};\n"]}
|