@metamask/snaps-rpc-methods 11.7.0 → 11.9.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.
Files changed (110) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/endowments/cronjob.cjs +8 -0
  3. package/dist/endowments/cronjob.cjs.map +1 -1
  4. package/dist/endowments/cronjob.d.cts.map +1 -1
  5. package/dist/endowments/cronjob.d.mts.map +1 -1
  6. package/dist/endowments/cronjob.mjs +9 -1
  7. package/dist/endowments/cronjob.mjs.map +1 -1
  8. package/dist/endowments/enum.cjs +1 -0
  9. package/dist/endowments/enum.cjs.map +1 -1
  10. package/dist/endowments/enum.d.cts +2 -1
  11. package/dist/endowments/enum.d.cts.map +1 -1
  12. package/dist/endowments/enum.d.mts +2 -1
  13. package/dist/endowments/enum.d.mts.map +1 -1
  14. package/dist/endowments/enum.mjs +1 -0
  15. package/dist/endowments/enum.mjs.map +1 -1
  16. package/dist/endowments/index.cjs +4 -0
  17. package/dist/endowments/index.cjs.map +1 -1
  18. package/dist/endowments/index.d.cts +9 -0
  19. package/dist/endowments/index.d.cts.map +1 -1
  20. package/dist/endowments/index.d.mts +9 -0
  21. package/dist/endowments/index.d.mts.map +1 -1
  22. package/dist/endowments/index.mjs +4 -0
  23. package/dist/endowments/index.mjs.map +1 -1
  24. package/dist/endowments/settings-page.cjs +28 -0
  25. package/dist/endowments/settings-page.cjs.map +1 -0
  26. package/dist/endowments/settings-page.d.cts +16 -0
  27. package/dist/endowments/settings-page.d.cts.map +1 -0
  28. package/dist/endowments/settings-page.d.mts +16 -0
  29. package/dist/endowments/settings-page.d.mts.map +1 -0
  30. package/dist/endowments/settings-page.mjs +25 -0
  31. package/dist/endowments/settings-page.mjs.map +1 -0
  32. package/dist/permitted/cancelBackgroundEvent.cjs +69 -0
  33. package/dist/permitted/cancelBackgroundEvent.cjs.map +1 -0
  34. package/dist/permitted/cancelBackgroundEvent.d.cts +16 -0
  35. package/dist/permitted/cancelBackgroundEvent.d.cts.map +1 -0
  36. package/dist/permitted/cancelBackgroundEvent.d.mts +16 -0
  37. package/dist/permitted/cancelBackgroundEvent.d.mts.map +1 -0
  38. package/dist/permitted/cancelBackgroundEvent.mjs +66 -0
  39. package/dist/permitted/cancelBackgroundEvent.mjs.map +1 -0
  40. package/dist/permitted/clearState.cjs +73 -0
  41. package/dist/permitted/clearState.cjs.map +1 -0
  42. package/dist/permitted/clearState.d.cts +28 -0
  43. package/dist/permitted/clearState.d.cts.map +1 -0
  44. package/dist/permitted/clearState.d.mts +28 -0
  45. package/dist/permitted/clearState.d.mts.map +1 -0
  46. package/dist/permitted/clearState.mjs +70 -0
  47. package/dist/permitted/clearState.mjs.map +1 -0
  48. package/dist/permitted/createInterface.d.cts +2 -2
  49. package/dist/permitted/createInterface.d.mts +2 -2
  50. package/dist/permitted/getBackgroundEvents.cjs +42 -0
  51. package/dist/permitted/getBackgroundEvents.cjs.map +1 -0
  52. package/dist/permitted/getBackgroundEvents.d.cts +8 -0
  53. package/dist/permitted/getBackgroundEvents.d.cts.map +1 -0
  54. package/dist/permitted/getBackgroundEvents.d.mts +8 -0
  55. package/dist/permitted/getBackgroundEvents.d.mts.map +1 -0
  56. package/dist/permitted/getBackgroundEvents.mjs +39 -0
  57. package/dist/permitted/getBackgroundEvents.mjs.map +1 -0
  58. package/dist/permitted/getState.cjs +118 -0
  59. package/dist/permitted/getState.cjs.map +1 -0
  60. package/dist/permitted/getState.d.cts +53 -0
  61. package/dist/permitted/getState.d.cts.map +1 -0
  62. package/dist/permitted/getState.d.mts +53 -0
  63. package/dist/permitted/getState.d.mts.map +1 -0
  64. package/dist/permitted/getState.mjs +114 -0
  65. package/dist/permitted/getState.mjs.map +1 -0
  66. package/dist/permitted/handlers.cjs +12 -0
  67. package/dist/permitted/handlers.cjs.map +1 -1
  68. package/dist/permitted/handlers.d.cts +8 -2
  69. package/dist/permitted/handlers.d.cts.map +1 -1
  70. package/dist/permitted/handlers.d.mts +8 -2
  71. package/dist/permitted/handlers.d.mts.map +1 -1
  72. package/dist/permitted/handlers.mjs +12 -0
  73. package/dist/permitted/handlers.mjs.map +1 -1
  74. package/dist/permitted/index.cjs.map +1 -1
  75. package/dist/permitted/index.d.cts +7 -1
  76. package/dist/permitted/index.d.cts.map +1 -1
  77. package/dist/permitted/index.d.mts +7 -1
  78. package/dist/permitted/index.d.mts.map +1 -1
  79. package/dist/permitted/index.mjs.map +1 -1
  80. package/dist/permitted/scheduleBackgroundEvent.cjs +122 -0
  81. package/dist/permitted/scheduleBackgroundEvent.cjs.map +1 -0
  82. package/dist/permitted/scheduleBackgroundEvent.d.cts +33 -0
  83. package/dist/permitted/scheduleBackgroundEvent.d.cts.map +1 -0
  84. package/dist/permitted/scheduleBackgroundEvent.d.mts +33 -0
  85. package/dist/permitted/scheduleBackgroundEvent.d.mts.map +1 -0
  86. package/dist/permitted/scheduleBackgroundEvent.mjs +119 -0
  87. package/dist/permitted/scheduleBackgroundEvent.mjs.map +1 -0
  88. package/dist/permitted/setState.cjs +154 -0
  89. package/dist/permitted/setState.cjs.map +1 -0
  90. package/dist/permitted/setState.d.cts +65 -0
  91. package/dist/permitted/setState.d.cts.map +1 -0
  92. package/dist/permitted/setState.d.mts +65 -0
  93. package/dist/permitted/setState.d.mts.map +1 -0
  94. package/dist/permitted/setState.mjs +150 -0
  95. package/dist/permitted/setState.mjs.map +1 -0
  96. package/dist/permitted/updateInterface.d.cts +2 -2
  97. package/dist/permitted/updateInterface.d.mts +2 -2
  98. package/dist/restricted/dialog.d.cts +4 -4
  99. package/dist/restricted/dialog.d.mts +4 -4
  100. package/dist/restricted/notify.d.cts +3 -3
  101. package/dist/restricted/notify.d.mts +3 -3
  102. package/dist/utils.cjs +22 -1
  103. package/dist/utils.cjs.map +1 -1
  104. package/dist/utils.d.cts +9 -0
  105. package/dist/utils.d.cts.map +1 -1
  106. package/dist/utils.d.mts +9 -0
  107. package/dist/utils.d.mts.map +1 -1
  108. package/dist/utils.mjs +20 -0
  109. package/dist/utils.mjs.map +1 -1
  110. package/package.json +11 -9
@@ -0,0 +1,39 @@
1
+ import { providerErrors } from "@metamask/rpc-errors";
2
+ import { SnapEndowments } from "../endowments/index.mjs";
3
+ const methodName = 'snap_getBackgroundEvents';
4
+ const hookNames = {
5
+ getBackgroundEvents: true,
6
+ hasPermission: true,
7
+ };
8
+ export const getBackgroundEventsHandler = {
9
+ methodNames: [methodName],
10
+ implementation: getGetBackgroundEventsImplementation,
11
+ hookNames,
12
+ };
13
+ /**
14
+ * The `snap_getBackgroundEvents` method implementation.
15
+ *
16
+ * @param _req - The JSON-RPC request object. Not used by this function.
17
+ * @param res - The JSON-RPC response object.
18
+ * @param _next - The `json-rpc-engine` "next" callback.
19
+ * Not used by this function.
20
+ * @param end - The `json-rpc-engine` "end" callback.
21
+ * @param hooks - The RPC method hooks.
22
+ * @param hooks.getBackgroundEvents - The function to get the background events.
23
+ * @param hooks.hasPermission - The function to check if a snap has the `endowment:cronjob` permission.
24
+ * @returns An array of background events.
25
+ */
26
+ async function getGetBackgroundEventsImplementation(_req, res, _next, end, { getBackgroundEvents, hasPermission }) {
27
+ if (!hasPermission(SnapEndowments.Cronjob)) {
28
+ return end(providerErrors.unauthorized());
29
+ }
30
+ try {
31
+ const events = getBackgroundEvents();
32
+ res.result = events;
33
+ }
34
+ catch (error) {
35
+ return end(error);
36
+ }
37
+ return end();
38
+ }
39
+ //# sourceMappingURL=getBackgroundEvents.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getBackgroundEvents.mjs","sourceRoot":"","sources":["../../src/permitted/getBackgroundEvents.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,6BAA6B;AAStD,OAAO,EAAE,cAAc,EAAE,gCAAsB;AAG/C,MAAM,UAAU,GAAG,0BAA0B,CAAC;AAE9C,MAAM,SAAS,GAAsD;IACnE,mBAAmB,EAAE,IAAI;IACzB,aAAa,EAAE,IAAI;CACpB,CAAC;AAOF,MAAM,CAAC,MAAM,0BAA0B,GAInC;IACF,WAAW,EAAE,CAAC,UAAU,CAAC;IACzB,cAAc,EAAE,oCAAoC;IACpD,SAAS;CACV,CAAC;AAEF;;;;;;;;;;;;GAYG;AACH,KAAK,UAAU,oCAAoC,CACjD,IAA+C,EAC/C,GAAsD,EACtD,KAAc,EACd,GAA6B,EAC7B,EAAE,mBAAmB,EAAE,aAAa,EAAkC;IAEtE,IAAI,CAAC,aAAa,CAAC,cAAc,CAAC,OAAO,CAAC,EAAE,CAAC;QAC3C,OAAO,GAAG,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5C,CAAC;IACD,IAAI,CAAC;QACH,MAAM,MAAM,GAAG,mBAAmB,EAAE,CAAC;QACrC,GAAG,CAAC,MAAM,GAAG,MAAM,CAAC;IACtB,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors } from '@metamask/rpc-errors';\nimport type {\n BackgroundEvent,\n GetBackgroundEventsParams,\n GetBackgroundEventsResult,\n JsonRpcRequest,\n} from '@metamask/snaps-sdk';\nimport { type PendingJsonRpcResponse } from '@metamask/utils';\n\nimport { SnapEndowments } from '../endowments';\nimport type { MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_getBackgroundEvents';\n\nconst hookNames: MethodHooksObject<GetBackgroundEventsMethodHooks> = {\n getBackgroundEvents: true,\n hasPermission: true,\n};\n\nexport type GetBackgroundEventsMethodHooks = {\n getBackgroundEvents: () => BackgroundEvent[];\n hasPermission: (permissionName: string) => boolean;\n};\n\nexport const getBackgroundEventsHandler: PermittedHandlerExport<\n GetBackgroundEventsMethodHooks,\n GetBackgroundEventsParams,\n GetBackgroundEventsResult\n> = {\n methodNames: [methodName],\n implementation: getGetBackgroundEventsImplementation,\n hookNames,\n};\n\n/**\n * The `snap_getBackgroundEvents` method implementation.\n *\n * @param _req - The JSON-RPC request object. Not used by this function.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback.\n * Not used by this function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getBackgroundEvents - The function to get the background events.\n * @param hooks.hasPermission - The function to check if a snap has the `endowment:cronjob` permission.\n * @returns An array of background events.\n */\nasync function getGetBackgroundEventsImplementation(\n _req: JsonRpcRequest<GetBackgroundEventsParams>,\n res: PendingJsonRpcResponse<GetBackgroundEventsResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getBackgroundEvents, hasPermission }: GetBackgroundEventsMethodHooks,\n): Promise<void> {\n if (!hasPermission(SnapEndowments.Cronjob)) {\n return end(providerErrors.unauthorized());\n }\n try {\n const events = getBackgroundEvents();\n res.result = events;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n"]}
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.get = exports.getStateHandler = void 0;
4
+ const rpc_errors_1 = require("@metamask/rpc-errors");
5
+ const superstruct_1 = require("@metamask/superstruct");
6
+ const utils_1 = require("@metamask/utils");
7
+ const manageState_1 = require("../restricted/manageState.cjs");
8
+ const utils_2 = require("../utils.cjs");
9
+ const hookNames = {
10
+ hasPermission: true,
11
+ getSnapState: true,
12
+ getUnlockPromise: true,
13
+ };
14
+ /**
15
+ * `snap_getState` gets the state of the Snap.
16
+ */
17
+ exports.getStateHandler = {
18
+ methodNames: ['snap_getState'],
19
+ implementation: getStateImplementation,
20
+ hookNames,
21
+ };
22
+ const GetStateParametersStruct = (0, superstruct_1.object)({
23
+ key: (0, superstruct_1.optional)(utils_2.StateKeyStruct),
24
+ encrypted: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
25
+ });
26
+ /**
27
+ * The `snap_getState` method implementation.
28
+ *
29
+ * @param request - The JSON-RPC request object.
30
+ * @param response - The JSON-RPC response object.
31
+ * @param _next - The `json-rpc-engine` "next" callback. Not used by this
32
+ * function.
33
+ * @param end - The `json-rpc-engine` "end" callback.
34
+ * @param hooks - The RPC method hooks.
35
+ * @param hooks.hasPermission - Check whether a given origin has a given
36
+ * permission.
37
+ * @param hooks.getSnapState - Get the state of the requesting Snap.
38
+ * @param hooks.getUnlockPromise - Wait for the extension to be unlocked.
39
+ * @returns Nothing.
40
+ */
41
+ async function getStateImplementation(request, response, _next, end, { hasPermission, getSnapState, getUnlockPromise }) {
42
+ const { params } = request;
43
+ if (!hasPermission(manageState_1.manageStateBuilder.targetName)) {
44
+ return end(rpc_errors_1.providerErrors.unauthorized());
45
+ }
46
+ try {
47
+ const validatedParams = getValidatedParams(params);
48
+ const { key, encrypted = true } = validatedParams;
49
+ if (encrypted) {
50
+ await getUnlockPromise(true);
51
+ }
52
+ const state = await getSnapState(encrypted);
53
+ response.result = get(state, key);
54
+ }
55
+ catch (error) {
56
+ return end(error);
57
+ }
58
+ return end();
59
+ }
60
+ /**
61
+ * Validate the parameters of the `snap_getState` method.
62
+ *
63
+ * @param params - The parameters to validate.
64
+ * @returns The validated parameters.
65
+ */
66
+ function getValidatedParams(params) {
67
+ try {
68
+ return (0, superstruct_1.create)(params, GetStateParametersStruct);
69
+ }
70
+ catch (error) {
71
+ if (error instanceof superstruct_1.StructError) {
72
+ throw rpc_errors_1.rpcErrors.invalidParams({
73
+ message: `Invalid params: ${error.message}.`,
74
+ });
75
+ }
76
+ /* istanbul ignore next */
77
+ throw rpc_errors_1.rpcErrors.internal();
78
+ }
79
+ }
80
+ /**
81
+ * Get the value of a key in an object. The key may contain Lodash-style path
82
+ * syntax, e.g., `a.b.c` (with the exception of array syntax). If the key does
83
+ * not exist, `null` is returned.
84
+ *
85
+ * This is a simplified version of Lodash's `get` function, but Lodash doesn't
86
+ * seem to be maintained anymore, so we're using our own implementation.
87
+ *
88
+ * @param value - The object to get the key from.
89
+ * @param key - The key to get.
90
+ * @returns The value of the key in the object, or `null` if the key does not
91
+ * exist.
92
+ */
93
+ function get(value, key) {
94
+ if (key === undefined) {
95
+ return value;
96
+ }
97
+ const keys = key.split('.');
98
+ let result = value;
99
+ // Intentionally using a classic for loop here for performance reasons.
100
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
101
+ for (let i = 0; i < keys.length; i++) {
102
+ const currentKey = keys[i];
103
+ if (utils_2.FORBIDDEN_KEYS.includes(currentKey)) {
104
+ throw rpc_errors_1.rpcErrors.invalidParams('Invalid params: Key contains forbidden characters.');
105
+ }
106
+ if ((0, utils_1.isObject)(result)) {
107
+ if (!(0, utils_1.hasProperty)(result, currentKey)) {
108
+ return null;
109
+ }
110
+ result = result[currentKey];
111
+ continue;
112
+ }
113
+ return null;
114
+ }
115
+ return result;
116
+ }
117
+ exports.get = get;
118
+ //# sourceMappingURL=getState.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getState.cjs","sourceRoot":"","sources":["../../src/permitted/getState.ts"],"names":[],"mappings":"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","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { GetStateParams, GetStateResult } from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n boolean,\n create,\n object,\n optional,\n StructError,\n} from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse, JsonRpcRequest } from '@metamask/utils';\nimport { hasProperty, isObject, type Json } from '@metamask/utils';\n\nimport { manageStateBuilder } from '../restricted/manageState';\nimport type { MethodHooksObject } from '../utils';\nimport { FORBIDDEN_KEYS, StateKeyStruct } from '../utils';\n\nconst hookNames: MethodHooksObject<GetStateHooks> = {\n hasPermission: true,\n getSnapState: true,\n getUnlockPromise: true,\n};\n\n/**\n * `snap_getState` gets the state of the Snap.\n */\nexport const getStateHandler: PermittedHandlerExport<\n GetStateHooks,\n GetStateParameters,\n GetStateResult\n> = {\n methodNames: ['snap_getState'],\n implementation: getStateImplementation,\n hookNames,\n};\n\nexport type GetStateHooks = {\n /**\n * Check if the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * Get the state of the requesting Snap.\n *\n * @returns The current state of the Snap.\n */\n getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;\n\n /**\n * Wait for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n};\n\nconst GetStateParametersStruct = object({\n key: optional(StateKeyStruct),\n encrypted: optional(boolean()),\n});\n\nexport type GetStateParameters = InferMatching<\n typeof GetStateParametersStruct,\n GetStateParams\n>;\n\n/**\n * The `snap_getState` method implementation.\n *\n * @param request - The JSON-RPC request object.\n * @param response - 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.\n * @param hooks.hasPermission - Check whether a given origin has a given\n * permission.\n * @param hooks.getSnapState - Get the state of the requesting Snap.\n * @param hooks.getUnlockPromise - Wait for the extension to be unlocked.\n * @returns Nothing.\n */\nasync function getStateImplementation(\n request: JsonRpcRequest<GetStateParameters>,\n response: PendingJsonRpcResponse<GetStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { hasPermission, getSnapState, getUnlockPromise }: GetStateHooks,\n): Promise<void> {\n const { params } = request;\n\n if (!hasPermission(manageStateBuilder.targetName)) {\n return end(providerErrors.unauthorized());\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n const { key, encrypted = true } = validatedParams;\n\n if (encrypted) {\n await getUnlockPromise(true);\n }\n\n const state = await getSnapState(encrypted);\n response.result = get(state, key);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the parameters of the `snap_getState` method.\n *\n * @param params - The parameters to validate.\n * @returns The validated parameters.\n */\nfunction getValidatedParams(params?: unknown) {\n try {\n return create(params, GetStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n\n/**\n * Get the value of a key in an object. The key may contain Lodash-style path\n * syntax, e.g., `a.b.c` (with the exception of array syntax). If the key does\n * not exist, `null` is returned.\n *\n * This is a simplified version of Lodash's `get` function, but Lodash doesn't\n * seem to be maintained anymore, so we're using our own implementation.\n *\n * @param value - The object to get the key from.\n * @param key - The key to get.\n * @returns The value of the key in the object, or `null` if the key does not\n * exist.\n */\nexport function get(\n value: Record<string, Json> | null,\n key?: string | undefined,\n): Json {\n if (key === undefined) {\n return value;\n }\n\n const keys = key.split('.');\n let result: Json = value;\n\n // Intentionally using a classic for loop here for performance reasons.\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < keys.length; i++) {\n const currentKey = keys[i];\n if (FORBIDDEN_KEYS.includes(currentKey)) {\n throw rpcErrors.invalidParams(\n 'Invalid params: Key contains forbidden characters.',\n );\n }\n\n if (isObject(result)) {\n if (!hasProperty(result, currentKey)) {\n return null;\n }\n\n result = result[currentKey];\n continue;\n }\n\n return null;\n }\n\n return result;\n}\n"]}
@@ -0,0 +1,53 @@
1
+ import type { PermittedHandlerExport } from "@metamask/permission-controller";
2
+ import type { GetStateParams, GetStateResult } from "@metamask/snaps-sdk";
3
+ import { type InferMatching } from "@metamask/snaps-utils";
4
+ import { type Json } from "@metamask/utils";
5
+ /**
6
+ * `snap_getState` gets the state of the Snap.
7
+ */
8
+ export declare const getStateHandler: PermittedHandlerExport<GetStateHooks, GetStateParameters, GetStateResult>;
9
+ export type GetStateHooks = {
10
+ /**
11
+ * Check if the requesting origin has a given permission.
12
+ *
13
+ * @param permissionName - The name of the permission to check.
14
+ * @returns Whether the origin has the permission.
15
+ */
16
+ hasPermission: (permissionName: string) => boolean;
17
+ /**
18
+ * Get the state of the requesting Snap.
19
+ *
20
+ * @returns The current state of the Snap.
21
+ */
22
+ getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;
23
+ /**
24
+ * Wait for the extension to be unlocked.
25
+ *
26
+ * @returns A promise that resolves once the extension is unlocked.
27
+ */
28
+ getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
29
+ };
30
+ declare const GetStateParametersStruct: import("@metamask/superstruct").Struct<{
31
+ key?: string | undefined;
32
+ encrypted?: boolean | undefined;
33
+ }, {
34
+ key: import("@metamask/superstruct").Struct<string | undefined, null>;
35
+ encrypted: import("@metamask/superstruct").Struct<boolean | undefined, null>;
36
+ }>;
37
+ export type GetStateParameters = InferMatching<typeof GetStateParametersStruct, GetStateParams>;
38
+ /**
39
+ * Get the value of a key in an object. The key may contain Lodash-style path
40
+ * syntax, e.g., `a.b.c` (with the exception of array syntax). If the key does
41
+ * not exist, `null` is returned.
42
+ *
43
+ * This is a simplified version of Lodash's `get` function, but Lodash doesn't
44
+ * seem to be maintained anymore, so we're using our own implementation.
45
+ *
46
+ * @param value - The object to get the key from.
47
+ * @param key - The key to get.
48
+ * @returns The value of the key in the object, or `null` if the key does not
49
+ * exist.
50
+ */
51
+ export declare function get(value: Record<string, Json> | null, key?: string | undefined): Json;
52
+ export {};
53
+ //# sourceMappingURL=getState.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getState.d.cts","sourceRoot":"","sources":["../../src/permitted/getState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,4BAA4B;AAC1E,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAS3D,OAAO,EAAyB,KAAK,IAAI,EAAE,wBAAwB;AAYnE;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,sBAAsB,CAClD,aAAa,EACb,kBAAkB,EAClB,cAAc,CAKf,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;OAKG;IACH,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnD;;;;OAIG;IACH,YAAY,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAEpE;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE,CAAC;AAEF,QAAA,MAAM,wBAAwB;;;;;;EAG5B,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,aAAa,CAC5C,OAAO,wBAAwB,EAC/B,cAAc,CACf,CAAC;AAoEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,EAClC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,GACvB,IAAI,CA+BN"}
@@ -0,0 +1,53 @@
1
+ import type { PermittedHandlerExport } from "@metamask/permission-controller";
2
+ import type { GetStateParams, GetStateResult } from "@metamask/snaps-sdk";
3
+ import { type InferMatching } from "@metamask/snaps-utils";
4
+ import { type Json } from "@metamask/utils";
5
+ /**
6
+ * `snap_getState` gets the state of the Snap.
7
+ */
8
+ export declare const getStateHandler: PermittedHandlerExport<GetStateHooks, GetStateParameters, GetStateResult>;
9
+ export type GetStateHooks = {
10
+ /**
11
+ * Check if the requesting origin has a given permission.
12
+ *
13
+ * @param permissionName - The name of the permission to check.
14
+ * @returns Whether the origin has the permission.
15
+ */
16
+ hasPermission: (permissionName: string) => boolean;
17
+ /**
18
+ * Get the state of the requesting Snap.
19
+ *
20
+ * @returns The current state of the Snap.
21
+ */
22
+ getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;
23
+ /**
24
+ * Wait for the extension to be unlocked.
25
+ *
26
+ * @returns A promise that resolves once the extension is unlocked.
27
+ */
28
+ getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
29
+ };
30
+ declare const GetStateParametersStruct: import("@metamask/superstruct").Struct<{
31
+ key?: string | undefined;
32
+ encrypted?: boolean | undefined;
33
+ }, {
34
+ key: import("@metamask/superstruct").Struct<string | undefined, null>;
35
+ encrypted: import("@metamask/superstruct").Struct<boolean | undefined, null>;
36
+ }>;
37
+ export type GetStateParameters = InferMatching<typeof GetStateParametersStruct, GetStateParams>;
38
+ /**
39
+ * Get the value of a key in an object. The key may contain Lodash-style path
40
+ * syntax, e.g., `a.b.c` (with the exception of array syntax). If the key does
41
+ * not exist, `null` is returned.
42
+ *
43
+ * This is a simplified version of Lodash's `get` function, but Lodash doesn't
44
+ * seem to be maintained anymore, so we're using our own implementation.
45
+ *
46
+ * @param value - The object to get the key from.
47
+ * @param key - The key to get.
48
+ * @returns The value of the key in the object, or `null` if the key does not
49
+ * exist.
50
+ */
51
+ export declare function get(value: Record<string, Json> | null, key?: string | undefined): Json;
52
+ export {};
53
+ //# sourceMappingURL=getState.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getState.d.mts","sourceRoot":"","sources":["../../src/permitted/getState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,4BAA4B;AAC1E,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAS3D,OAAO,EAAyB,KAAK,IAAI,EAAE,wBAAwB;AAYnE;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,sBAAsB,CAClD,aAAa,EACb,kBAAkB,EAClB,cAAc,CAKf,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;OAKG;IACH,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnD;;;;OAIG;IACH,YAAY,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAEpE;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE,CAAC;AAEF,QAAA,MAAM,wBAAwB;;;;;;EAG5B,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,aAAa,CAC5C,OAAO,wBAAwB,EAC/B,cAAc,CACf,CAAC;AAoEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,EAClC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,GACvB,IAAI,CA+BN"}
@@ -0,0 +1,114 @@
1
+ import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
2
+ import { boolean, create, object, optional, StructError } from "@metamask/superstruct";
3
+ import { hasProperty, isObject } from "@metamask/utils";
4
+ import { manageStateBuilder } from "../restricted/manageState.mjs";
5
+ import { FORBIDDEN_KEYS, StateKeyStruct } from "../utils.mjs";
6
+ const hookNames = {
7
+ hasPermission: true,
8
+ getSnapState: true,
9
+ getUnlockPromise: true,
10
+ };
11
+ /**
12
+ * `snap_getState` gets the state of the Snap.
13
+ */
14
+ export const getStateHandler = {
15
+ methodNames: ['snap_getState'],
16
+ implementation: getStateImplementation,
17
+ hookNames,
18
+ };
19
+ const GetStateParametersStruct = object({
20
+ key: optional(StateKeyStruct),
21
+ encrypted: optional(boolean()),
22
+ });
23
+ /**
24
+ * The `snap_getState` method implementation.
25
+ *
26
+ * @param request - The JSON-RPC request object.
27
+ * @param response - The JSON-RPC response object.
28
+ * @param _next - The `json-rpc-engine` "next" callback. Not used by this
29
+ * function.
30
+ * @param end - The `json-rpc-engine` "end" callback.
31
+ * @param hooks - The RPC method hooks.
32
+ * @param hooks.hasPermission - Check whether a given origin has a given
33
+ * permission.
34
+ * @param hooks.getSnapState - Get the state of the requesting Snap.
35
+ * @param hooks.getUnlockPromise - Wait for the extension to be unlocked.
36
+ * @returns Nothing.
37
+ */
38
+ async function getStateImplementation(request, response, _next, end, { hasPermission, getSnapState, getUnlockPromise }) {
39
+ const { params } = request;
40
+ if (!hasPermission(manageStateBuilder.targetName)) {
41
+ return end(providerErrors.unauthorized());
42
+ }
43
+ try {
44
+ const validatedParams = getValidatedParams(params);
45
+ const { key, encrypted = true } = validatedParams;
46
+ if (encrypted) {
47
+ await getUnlockPromise(true);
48
+ }
49
+ const state = await getSnapState(encrypted);
50
+ response.result = get(state, key);
51
+ }
52
+ catch (error) {
53
+ return end(error);
54
+ }
55
+ return end();
56
+ }
57
+ /**
58
+ * Validate the parameters of the `snap_getState` method.
59
+ *
60
+ * @param params - The parameters to validate.
61
+ * @returns The validated parameters.
62
+ */
63
+ function getValidatedParams(params) {
64
+ try {
65
+ return create(params, GetStateParametersStruct);
66
+ }
67
+ catch (error) {
68
+ if (error instanceof StructError) {
69
+ throw rpcErrors.invalidParams({
70
+ message: `Invalid params: ${error.message}.`,
71
+ });
72
+ }
73
+ /* istanbul ignore next */
74
+ throw rpcErrors.internal();
75
+ }
76
+ }
77
+ /**
78
+ * Get the value of a key in an object. The key may contain Lodash-style path
79
+ * syntax, e.g., `a.b.c` (with the exception of array syntax). If the key does
80
+ * not exist, `null` is returned.
81
+ *
82
+ * This is a simplified version of Lodash's `get` function, but Lodash doesn't
83
+ * seem to be maintained anymore, so we're using our own implementation.
84
+ *
85
+ * @param value - The object to get the key from.
86
+ * @param key - The key to get.
87
+ * @returns The value of the key in the object, or `null` if the key does not
88
+ * exist.
89
+ */
90
+ export function get(value, key) {
91
+ if (key === undefined) {
92
+ return value;
93
+ }
94
+ const keys = key.split('.');
95
+ let result = value;
96
+ // Intentionally using a classic for loop here for performance reasons.
97
+ // eslint-disable-next-line @typescript-eslint/prefer-for-of
98
+ for (let i = 0; i < keys.length; i++) {
99
+ const currentKey = keys[i];
100
+ if (FORBIDDEN_KEYS.includes(currentKey)) {
101
+ throw rpcErrors.invalidParams('Invalid params: Key contains forbidden characters.');
102
+ }
103
+ if (isObject(result)) {
104
+ if (!hasProperty(result, currentKey)) {
105
+ return null;
106
+ }
107
+ result = result[currentKey];
108
+ continue;
109
+ }
110
+ return null;
111
+ }
112
+ return result;
113
+ }
114
+ //# sourceMappingURL=getState.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getState.mjs","sourceRoot":"","sources":["../../src/permitted/getState.ts"],"names":[],"mappings":"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","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { GetStateParams, GetStateResult } from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n boolean,\n create,\n object,\n optional,\n StructError,\n} from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse, JsonRpcRequest } from '@metamask/utils';\nimport { hasProperty, isObject, type Json } from '@metamask/utils';\n\nimport { manageStateBuilder } from '../restricted/manageState';\nimport type { MethodHooksObject } from '../utils';\nimport { FORBIDDEN_KEYS, StateKeyStruct } from '../utils';\n\nconst hookNames: MethodHooksObject<GetStateHooks> = {\n hasPermission: true,\n getSnapState: true,\n getUnlockPromise: true,\n};\n\n/**\n * `snap_getState` gets the state of the Snap.\n */\nexport const getStateHandler: PermittedHandlerExport<\n GetStateHooks,\n GetStateParameters,\n GetStateResult\n> = {\n methodNames: ['snap_getState'],\n implementation: getStateImplementation,\n hookNames,\n};\n\nexport type GetStateHooks = {\n /**\n * Check if the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * Get the state of the requesting Snap.\n *\n * @returns The current state of the Snap.\n */\n getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;\n\n /**\n * Wait for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n};\n\nconst GetStateParametersStruct = object({\n key: optional(StateKeyStruct),\n encrypted: optional(boolean()),\n});\n\nexport type GetStateParameters = InferMatching<\n typeof GetStateParametersStruct,\n GetStateParams\n>;\n\n/**\n * The `snap_getState` method implementation.\n *\n * @param request - The JSON-RPC request object.\n * @param response - 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.\n * @param hooks.hasPermission - Check whether a given origin has a given\n * permission.\n * @param hooks.getSnapState - Get the state of the requesting Snap.\n * @param hooks.getUnlockPromise - Wait for the extension to be unlocked.\n * @returns Nothing.\n */\nasync function getStateImplementation(\n request: JsonRpcRequest<GetStateParameters>,\n response: PendingJsonRpcResponse<GetStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { hasPermission, getSnapState, getUnlockPromise }: GetStateHooks,\n): Promise<void> {\n const { params } = request;\n\n if (!hasPermission(manageStateBuilder.targetName)) {\n return end(providerErrors.unauthorized());\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n const { key, encrypted = true } = validatedParams;\n\n if (encrypted) {\n await getUnlockPromise(true);\n }\n\n const state = await getSnapState(encrypted);\n response.result = get(state, key);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the parameters of the `snap_getState` method.\n *\n * @param params - The parameters to validate.\n * @returns The validated parameters.\n */\nfunction getValidatedParams(params?: unknown) {\n try {\n return create(params, GetStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n\n/**\n * Get the value of a key in an object. The key may contain Lodash-style path\n * syntax, e.g., `a.b.c` (with the exception of array syntax). If the key does\n * not exist, `null` is returned.\n *\n * This is a simplified version of Lodash's `get` function, but Lodash doesn't\n * seem to be maintained anymore, so we're using our own implementation.\n *\n * @param value - The object to get the key from.\n * @param key - The key to get.\n * @returns The value of the key in the object, or `null` if the key does not\n * exist.\n */\nexport function get(\n value: Record<string, Json> | null,\n key?: string | undefined,\n): Json {\n if (key === undefined) {\n return value;\n }\n\n const keys = key.split('.');\n let result: Json = value;\n\n // Intentionally using a classic for loop here for performance reasons.\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < keys.length; i++) {\n const currentKey = keys[i];\n if (FORBIDDEN_KEYS.includes(currentKey)) {\n throw rpcErrors.invalidParams(\n 'Invalid params: Key contains forbidden characters.',\n );\n }\n\n if (isObject(result)) {\n if (!hasProperty(result, currentKey)) {\n return null;\n }\n\n result = result[currentKey];\n continue;\n }\n\n return null;\n }\n\n return result;\n}\n"]}
@@ -1,19 +1,25 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.handlers = exports.methodHandlers = void 0;
4
+ const cancelBackgroundEvent_1 = require("./cancelBackgroundEvent.cjs");
5
+ const clearState_1 = require("./clearState.cjs");
4
6
  const createInterface_1 = require("./createInterface.cjs");
5
7
  const experimentalProviderRequest_1 = require("./experimentalProviderRequest.cjs");
6
8
  const getAllSnaps_1 = require("./getAllSnaps.cjs");
9
+ const getBackgroundEvents_1 = require("./getBackgroundEvents.cjs");
7
10
  const getClientStatus_1 = require("./getClientStatus.cjs");
8
11
  const getCurrencyRate_1 = require("./getCurrencyRate.cjs");
9
12
  const getFile_1 = require("./getFile.cjs");
10
13
  const getInterfaceContext_1 = require("./getInterfaceContext.cjs");
11
14
  const getInterfaceState_1 = require("./getInterfaceState.cjs");
12
15
  const getSnaps_1 = require("./getSnaps.cjs");
16
+ const getState_1 = require("./getState.cjs");
13
17
  const invokeKeyring_1 = require("./invokeKeyring.cjs");
14
18
  const invokeSnapSugar_1 = require("./invokeSnapSugar.cjs");
15
19
  const requestSnaps_1 = require("./requestSnaps.cjs");
16
20
  const resolveInterface_1 = require("./resolveInterface.cjs");
21
+ const scheduleBackgroundEvent_1 = require("./scheduleBackgroundEvent.cjs");
22
+ const setState_1 = require("./setState.cjs");
17
23
  const updateInterface_1 = require("./updateInterface.cjs");
18
24
  /* eslint-disable @typescript-eslint/naming-convention */
19
25
  exports.methodHandlers = {
@@ -22,8 +28,10 @@ exports.methodHandlers = {
22
28
  wallet_requestSnaps: requestSnaps_1.requestSnapsHandler,
23
29
  wallet_invokeSnap: invokeSnapSugar_1.invokeSnapSugarHandler,
24
30
  wallet_invokeKeyring: invokeKeyring_1.invokeKeyringHandler,
31
+ snap_clearState: clearState_1.clearStateHandler,
25
32
  snap_getClientStatus: getClientStatus_1.getClientStatusHandler,
26
33
  snap_getFile: getFile_1.getFileHandler,
34
+ snap_getState: getState_1.getStateHandler,
27
35
  snap_createInterface: createInterface_1.createInterfaceHandler,
28
36
  snap_updateInterface: updateInterface_1.updateInterfaceHandler,
29
37
  snap_getInterfaceState: getInterfaceState_1.getInterfaceStateHandler,
@@ -31,6 +39,10 @@ exports.methodHandlers = {
31
39
  snap_resolveInterface: resolveInterface_1.resolveInterfaceHandler,
32
40
  snap_getCurrencyRate: getCurrencyRate_1.getCurrencyRateHandler,
33
41
  snap_experimentalProviderRequest: experimentalProviderRequest_1.providerRequestHandler,
42
+ snap_scheduleBackgroundEvent: scheduleBackgroundEvent_1.scheduleBackgroundEventHandler,
43
+ snap_cancelBackgroundEvent: cancelBackgroundEvent_1.cancelBackgroundEventHandler,
44
+ snap_getBackgroundEvents: getBackgroundEvents_1.getBackgroundEventsHandler,
45
+ snap_setState: setState_1.setStateHandler,
34
46
  };
35
47
  /* eslint-enable @typescript-eslint/naming-convention */
36
48
  exports.handlers = Object.values(exports.methodHandlers);
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.cjs","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":";;;AAAA,2DAA2D;AAC3D,mFAAuE;AACvE,mDAAmD;AACnD,2DAA2D;AAC3D,2DAA2D;AAC3D,2CAA2C;AAC3C,mEAAmE;AACnE,+DAA+D;AAC/D,6CAA6C;AAC7C,uDAAuD;AACvD,2DAA2D;AAC3D,qDAAqD;AACrD,6DAA6D;AAC7D,2DAA2D;AAE3D,yDAAyD;AAC5C,QAAA,cAAc,GAAG;IAC5B,kBAAkB,EAAE,gCAAkB;IACtC,eAAe,EAAE,0BAAe;IAChC,mBAAmB,EAAE,kCAAmB;IACxC,iBAAiB,EAAE,wCAAsB;IACzC,oBAAoB,EAAE,oCAAoB;IAC1C,oBAAoB,EAAE,wCAAsB;IAC5C,YAAY,EAAE,wBAAc;IAC5B,oBAAoB,EAAE,wCAAsB;IAC5C,oBAAoB,EAAE,wCAAsB;IAC5C,sBAAsB,EAAE,4CAAwB;IAChD,wBAAwB,EAAE,gDAA0B;IACpD,qBAAqB,EAAE,0CAAuB;IAC9C,oBAAoB,EAAE,wCAAsB;IAC5C,gCAAgC,EAAE,oDAAsB;CACzD,CAAC;AACF,wDAAwD;AAE3C,QAAA,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAc,CAAC,CAAC","sourcesContent":["import { createInterfaceHandler } from './createInterface';\nimport { providerRequestHandler } from './experimentalProviderRequest';\nimport { getAllSnapsHandler } from './getAllSnaps';\nimport { getClientStatusHandler } from './getClientStatus';\nimport { getCurrencyRateHandler } from './getCurrencyRate';\nimport { getFileHandler } from './getFile';\nimport { getInterfaceContextHandler } from './getInterfaceContext';\nimport { getInterfaceStateHandler } from './getInterfaceState';\nimport { getSnapsHandler } from './getSnaps';\nimport { invokeKeyringHandler } from './invokeKeyring';\nimport { invokeSnapSugarHandler } from './invokeSnapSugar';\nimport { requestSnapsHandler } from './requestSnaps';\nimport { resolveInterfaceHandler } from './resolveInterface';\nimport { updateInterfaceHandler } from './updateInterface';\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const methodHandlers = {\n wallet_getAllSnaps: getAllSnapsHandler,\n wallet_getSnaps: getSnapsHandler,\n wallet_requestSnaps: requestSnapsHandler,\n wallet_invokeSnap: invokeSnapSugarHandler,\n wallet_invokeKeyring: invokeKeyringHandler,\n snap_getClientStatus: getClientStatusHandler,\n snap_getFile: getFileHandler,\n snap_createInterface: createInterfaceHandler,\n snap_updateInterface: updateInterfaceHandler,\n snap_getInterfaceState: getInterfaceStateHandler,\n snap_getInterfaceContext: getInterfaceContextHandler,\n snap_resolveInterface: resolveInterfaceHandler,\n snap_getCurrencyRate: getCurrencyRateHandler,\n snap_experimentalProviderRequest: providerRequestHandler,\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const handlers = Object.values(methodHandlers);\n"]}
1
+ {"version":3,"file":"handlers.cjs","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":";;;AAAA,uEAAuE;AACvE,iDAAiD;AACjD,2DAA2D;AAC3D,mFAAuE;AACvE,mDAAmD;AACnD,mEAAmE;AACnE,2DAA2D;AAC3D,2DAA2D;AAC3D,2CAA2C;AAC3C,mEAAmE;AACnE,+DAA+D;AAC/D,6CAA6C;AAC7C,6CAA6C;AAC7C,uDAAuD;AACvD,2DAA2D;AAC3D,qDAAqD;AACrD,6DAA6D;AAC7D,2EAA2E;AAC3E,6CAA6C;AAC7C,2DAA2D;AAE3D,yDAAyD;AAC5C,QAAA,cAAc,GAAG;IAC5B,kBAAkB,EAAE,gCAAkB;IACtC,eAAe,EAAE,0BAAe;IAChC,mBAAmB,EAAE,kCAAmB;IACxC,iBAAiB,EAAE,wCAAsB;IACzC,oBAAoB,EAAE,oCAAoB;IAC1C,eAAe,EAAE,8BAAiB;IAClC,oBAAoB,EAAE,wCAAsB;IAC5C,YAAY,EAAE,wBAAc;IAC5B,aAAa,EAAE,0BAAe;IAC9B,oBAAoB,EAAE,wCAAsB;IAC5C,oBAAoB,EAAE,wCAAsB;IAC5C,sBAAsB,EAAE,4CAAwB;IAChD,wBAAwB,EAAE,gDAA0B;IACpD,qBAAqB,EAAE,0CAAuB;IAC9C,oBAAoB,EAAE,wCAAsB;IAC5C,gCAAgC,EAAE,oDAAsB;IACxD,4BAA4B,EAAE,wDAA8B;IAC5D,0BAA0B,EAAE,oDAA4B;IACxD,wBAAwB,EAAE,gDAA0B;IACpD,aAAa,EAAE,0BAAe;CAC/B,CAAC;AACF,wDAAwD;AAE3C,QAAA,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAc,CAAC,CAAC","sourcesContent":["import { cancelBackgroundEventHandler } from './cancelBackgroundEvent';\nimport { clearStateHandler } from './clearState';\nimport { createInterfaceHandler } from './createInterface';\nimport { providerRequestHandler } from './experimentalProviderRequest';\nimport { getAllSnapsHandler } from './getAllSnaps';\nimport { getBackgroundEventsHandler } from './getBackgroundEvents';\nimport { getClientStatusHandler } from './getClientStatus';\nimport { getCurrencyRateHandler } from './getCurrencyRate';\nimport { getFileHandler } from './getFile';\nimport { getInterfaceContextHandler } from './getInterfaceContext';\nimport { getInterfaceStateHandler } from './getInterfaceState';\nimport { getSnapsHandler } from './getSnaps';\nimport { getStateHandler } from './getState';\nimport { invokeKeyringHandler } from './invokeKeyring';\nimport { invokeSnapSugarHandler } from './invokeSnapSugar';\nimport { requestSnapsHandler } from './requestSnaps';\nimport { resolveInterfaceHandler } from './resolveInterface';\nimport { scheduleBackgroundEventHandler } from './scheduleBackgroundEvent';\nimport { setStateHandler } from './setState';\nimport { updateInterfaceHandler } from './updateInterface';\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const methodHandlers = {\n wallet_getAllSnaps: getAllSnapsHandler,\n wallet_getSnaps: getSnapsHandler,\n wallet_requestSnaps: requestSnapsHandler,\n wallet_invokeSnap: invokeSnapSugarHandler,\n wallet_invokeKeyring: invokeKeyringHandler,\n snap_clearState: clearStateHandler,\n snap_getClientStatus: getClientStatusHandler,\n snap_getFile: getFileHandler,\n snap_getState: getStateHandler,\n snap_createInterface: createInterfaceHandler,\n snap_updateInterface: updateInterfaceHandler,\n snap_getInterfaceState: getInterfaceStateHandler,\n snap_getInterfaceContext: getInterfaceContextHandler,\n snap_resolveInterface: resolveInterfaceHandler,\n snap_getCurrencyRate: getCurrencyRateHandler,\n snap_experimentalProviderRequest: providerRequestHandler,\n snap_scheduleBackgroundEvent: scheduleBackgroundEventHandler,\n snap_cancelBackgroundEvent: cancelBackgroundEventHandler,\n snap_getBackgroundEvents: getBackgroundEventsHandler,\n snap_setState: setStateHandler,\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const handlers = Object.values(methodHandlers);\n"]}
@@ -4,8 +4,10 @@ export declare const methodHandlers: {
4
4
  wallet_requestSnaps: import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps.cjs").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult>;
5
5
  wallet_invokeSnap: import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeSnapSugar.cjs").InvokeSnapSugarHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json>;
6
6
  wallet_invokeKeyring: import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring.cjs").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json>;
7
+ snap_clearState: import("@metamask/permission-controller").PermittedHandlerExport<import("./clearState.cjs").ClearStateHooks, import("@metamask/snaps-sdk").ClearStateParams, null>;
7
8
  snap_getClientStatus: import("@metamask/permission-controller").PermittedHandlerExport<import("./getClientStatus.cjs").GetClientStatusHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetClientStatusResult>;
8
9
  snap_getFile: import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile.cjs").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string>;
10
+ snap_getState: import("@metamask/permission-controller").PermittedHandlerExport<import("./getState.cjs").GetStateHooks, import("@metamask/snaps-sdk").GetStateParams, import("@metamask/utils").Json>;
9
11
  snap_createInterface: import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.cjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string>;
10
12
  snap_updateInterface: import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.cjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null>;
11
13
  snap_getInterfaceState: import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.cjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
@@ -23,8 +25,12 @@ export declare const methodHandlers: {
23
25
  snap_resolveInterface: import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.cjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null>;
24
26
  snap_getCurrencyRate: import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.cjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult>;
25
27
  snap_experimentalProviderRequest: import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.cjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json>;
28
+ snap_scheduleBackgroundEvent: import("@metamask/permission-controller").PermittedHandlerExport<import("./scheduleBackgroundEvent.cjs").ScheduleBackgroundEventMethodHooks, import("@metamask/snaps-sdk").ScheduleBackgroundEventParams, string>;
29
+ snap_cancelBackgroundEvent: import("@metamask/permission-controller").PermittedHandlerExport<import("./cancelBackgroundEvent.cjs").CancelBackgroundEventMethodHooks, import("@metamask/snaps-sdk").CancelBackgroundEventParams, null>;
30
+ snap_getBackgroundEvents: import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.cjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult>;
31
+ snap_setState: import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.cjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null>;
26
32
  };
27
- export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.cjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.cjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getAllSnaps.cjs").GetAllSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getClientStatus.cjs").GetClientStatusHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetClientStatusResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.cjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.cjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
33
+ export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./cancelBackgroundEvent.cjs").CancelBackgroundEventMethodHooks, import("@metamask/snaps-sdk").CancelBackgroundEventParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./clearState.cjs").ClearStateHooks, import("@metamask/snaps-sdk").ClearStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.cjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.cjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getAllSnaps.cjs").GetAllSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.cjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getClientStatus.cjs").GetClientStatusHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetClientStatusResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.cjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.cjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
28
34
  name: string;
29
35
  size: number;
30
36
  contentType: string;
@@ -34,5 +40,5 @@ export declare const handlers: (import("@metamask/permission-controller").Permit
34
40
  size: number;
35
41
  contentType: string;
36
42
  contents: string;
37
- } | null> | null>> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps.cjs").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps.cjs").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.cjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.cjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile.cjs").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.cjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeSnapSugar.cjs").InvokeSnapSugarHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring.cjs").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json>)[];
43
+ } | null> | null>> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps.cjs").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getState.cjs").GetStateHooks, import("@metamask/snaps-sdk").GetStateParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps.cjs").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.cjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./scheduleBackgroundEvent.cjs").ScheduleBackgroundEventMethodHooks, import("@metamask/snaps-sdk").ScheduleBackgroundEventParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.cjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.cjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile.cjs").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.cjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeSnapSugar.cjs").InvokeSnapSugarHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring.cjs").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json>)[];
38
44
  //# sourceMappingURL=handlers.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.d.cts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;CAe1B,CAAC;AAGF,eAAO,MAAM,QAAQ;;;;;;;;;;0iDAAgC,CAAC"}
1
+ {"version":3,"file":"handlers.d.cts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqB1B,CAAC;AAGF,eAAO,MAAM,QAAQ;;;;;;;;;;0kEAAgC,CAAC"}
@@ -4,8 +4,10 @@ export declare const methodHandlers: {
4
4
  wallet_requestSnaps: import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps.mjs").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult>;
5
5
  wallet_invokeSnap: import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeSnapSugar.mjs").InvokeSnapSugarHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json>;
6
6
  wallet_invokeKeyring: import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring.mjs").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json>;
7
+ snap_clearState: import("@metamask/permission-controller").PermittedHandlerExport<import("./clearState.mjs").ClearStateHooks, import("@metamask/snaps-sdk").ClearStateParams, null>;
7
8
  snap_getClientStatus: import("@metamask/permission-controller").PermittedHandlerExport<import("./getClientStatus.mjs").GetClientStatusHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetClientStatusResult>;
8
9
  snap_getFile: import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile.mjs").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string>;
10
+ snap_getState: import("@metamask/permission-controller").PermittedHandlerExport<import("./getState.mjs").GetStateHooks, import("@metamask/snaps-sdk").GetStateParams, import("@metamask/utils").Json>;
9
11
  snap_createInterface: import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.mjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string>;
10
12
  snap_updateInterface: import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.mjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null>;
11
13
  snap_getInterfaceState: import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.mjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
@@ -23,8 +25,12 @@ export declare const methodHandlers: {
23
25
  snap_resolveInterface: import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.mjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null>;
24
26
  snap_getCurrencyRate: import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.mjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult>;
25
27
  snap_experimentalProviderRequest: import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.mjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json>;
28
+ snap_scheduleBackgroundEvent: import("@metamask/permission-controller").PermittedHandlerExport<import("./scheduleBackgroundEvent.mjs").ScheduleBackgroundEventMethodHooks, import("@metamask/snaps-sdk").ScheduleBackgroundEventParams, string>;
29
+ snap_cancelBackgroundEvent: import("@metamask/permission-controller").PermittedHandlerExport<import("./cancelBackgroundEvent.mjs").CancelBackgroundEventMethodHooks, import("@metamask/snaps-sdk").CancelBackgroundEventParams, null>;
30
+ snap_getBackgroundEvents: import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.mjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult>;
31
+ snap_setState: import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.mjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null>;
26
32
  };
27
- export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.mjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.mjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getAllSnaps.mjs").GetAllSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getClientStatus.mjs").GetClientStatusHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetClientStatusResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.mjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.mjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
33
+ export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./cancelBackgroundEvent.mjs").CancelBackgroundEventMethodHooks, import("@metamask/snaps-sdk").CancelBackgroundEventParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./clearState.mjs").ClearStateHooks, import("@metamask/snaps-sdk").ClearStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.mjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.mjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getAllSnaps.mjs").GetAllSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.mjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getClientStatus.mjs").GetClientStatusHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetClientStatusResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.mjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.mjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
28
34
  name: string;
29
35
  size: number;
30
36
  contentType: string;
@@ -34,5 +40,5 @@ export declare const handlers: (import("@metamask/permission-controller").Permit
34
40
  size: number;
35
41
  contentType: string;
36
42
  contents: string;
37
- } | null> | null>> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps.mjs").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps.mjs").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.mjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.mjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile.mjs").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.mjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeSnapSugar.mjs").InvokeSnapSugarHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring.mjs").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json>)[];
43
+ } | null> | null>> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps.mjs").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getState.mjs").GetStateHooks, import("@metamask/snaps-sdk").GetStateParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps.mjs").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.mjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./scheduleBackgroundEvent.mjs").ScheduleBackgroundEventMethodHooks, import("@metamask/snaps-sdk").ScheduleBackgroundEventParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.mjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.mjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile.mjs").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.mjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeSnapSugar.mjs").InvokeSnapSugarHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring.mjs").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json>)[];
38
44
  //# sourceMappingURL=handlers.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.d.mts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;CAe1B,CAAC;AAGF,eAAO,MAAM,QAAQ;;;;;;;;;;0iDAAgC,CAAC"}
1
+ {"version":3,"file":"handlers.d.mts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqB1B,CAAC;AAGF,eAAO,MAAM,QAAQ;;;;;;;;;;0kEAAgC,CAAC"}