@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,154 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.set = exports.setStateHandler = 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
+ updateSnapState: true,
14
+ };
15
+ /**
16
+ * `snap_setState` sets the state of the Snap.
17
+ */
18
+ exports.setStateHandler = {
19
+ methodNames: ['snap_setState'],
20
+ implementation: setStateImplementation,
21
+ hookNames,
22
+ };
23
+ const SetStateParametersStruct = (0, superstruct_1.object)({
24
+ key: (0, superstruct_1.optional)(utils_2.StateKeyStruct),
25
+ value: utils_1.JsonStruct,
26
+ encrypted: (0, superstruct_1.optional)((0, superstruct_1.boolean)()),
27
+ });
28
+ /**
29
+ * The `snap_setState` method implementation.
30
+ *
31
+ * @param request - The JSON-RPC request object.
32
+ * @param response - The JSON-RPC response object.
33
+ * @param _next - The `json-rpc-engine` "next" callback. Not used by this
34
+ * function.
35
+ * @param end - The `json-rpc-engine` "end" callback.
36
+ * @param hooks - The RPC method hooks.
37
+ * @param hooks.hasPermission - Check whether a given origin has a given
38
+ * permission.
39
+ * @param hooks.getSnapState - Get the state of the requesting Snap.
40
+ * @param hooks.getUnlockPromise - Wait for the extension to be unlocked.
41
+ * @param hooks.updateSnapState - Update the state of the requesting Snap.
42
+ * @returns Nothing.
43
+ */
44
+ async function setStateImplementation(request, response, _next, end, { hasPermission, getSnapState, getUnlockPromise, updateSnapState, }) {
45
+ const { params } = request;
46
+ if (!hasPermission(manageState_1.manageStateBuilder.targetName)) {
47
+ return end(rpc_errors_1.providerErrors.unauthorized());
48
+ }
49
+ try {
50
+ const validatedParams = getValidatedParams(params);
51
+ const { key, value, encrypted = true } = validatedParams;
52
+ if (key === undefined && !(0, utils_1.isObject)(value)) {
53
+ return end(rpc_errors_1.rpcErrors.invalidParams('Invalid params: Value must be an object if key is not provided.'));
54
+ }
55
+ if (encrypted) {
56
+ await getUnlockPromise(true);
57
+ }
58
+ const newState = await getNewState(key, value, encrypted, getSnapState);
59
+ await updateSnapState(newState, encrypted);
60
+ response.result = null;
61
+ }
62
+ catch (error) {
63
+ return end(error);
64
+ }
65
+ return end();
66
+ }
67
+ /**
68
+ * Validate the parameters of the `snap_setState` method.
69
+ *
70
+ * @param params - The parameters to validate.
71
+ * @returns The validated parameters.
72
+ */
73
+ function getValidatedParams(params) {
74
+ try {
75
+ return (0, superstruct_1.create)(params, SetStateParametersStruct);
76
+ }
77
+ catch (error) {
78
+ if (error instanceof superstruct_1.StructError) {
79
+ throw rpc_errors_1.rpcErrors.invalidParams({
80
+ message: `Invalid params: ${error.message}.`,
81
+ });
82
+ }
83
+ /* istanbul ignore next */
84
+ throw rpc_errors_1.rpcErrors.internal();
85
+ }
86
+ }
87
+ /**
88
+ * Get the new state of the Snap.
89
+ *
90
+ * If the key is `undefined`, the value is expected to be an object. In this
91
+ * case, the value is returned as the new state.
92
+ *
93
+ * If the key is not `undefined`, the value is set in the state at the key. If
94
+ * the key does not exist, it is created (and any missing intermediate keys are
95
+ * created as well).
96
+ *
97
+ * @param key - The key to set.
98
+ * @param value - The value to set the key to.
99
+ * @param encrypted - Whether the state is encrypted.
100
+ * @param getSnapState - The `getSnapState` hook.
101
+ * @returns The new state of the Snap.
102
+ */
103
+ async function getNewState(key, value, encrypted, getSnapState) {
104
+ if (key === undefined) {
105
+ (0, utils_1.assert)((0, utils_1.isObject)(value));
106
+ return value;
107
+ }
108
+ const state = await getSnapState(encrypted);
109
+ return set(state, key, value);
110
+ }
111
+ /**
112
+ * Set the value of a key in an object. The key may contain Lodash-style path
113
+ * syntax, e.g., `a.b.c` (with the exception of array syntax). If the key does
114
+ * not exist, it is created (and any missing intermediate keys are created as
115
+ * well).
116
+ *
117
+ * This is a simplified version of Lodash's `set` function, but Lodash doesn't
118
+ * seem to be maintained anymore, so we're using our own implementation.
119
+ *
120
+ * @param object - The object to get the key from.
121
+ * @param key - The key to set.
122
+ * @param value - The value to set the key to.
123
+ * @returns The new object with the key set to the value.
124
+ */
125
+ function set(
126
+ // eslint-disable-next-line @typescript-eslint/default-param-last
127
+ object, key, value) {
128
+ const keys = key.split('.');
129
+ const requiredObject = object ?? {};
130
+ let currentObject = requiredObject;
131
+ for (let i = 0; i < keys.length; i++) {
132
+ const currentKey = keys[i];
133
+ if (utils_2.FORBIDDEN_KEYS.includes(currentKey)) {
134
+ throw rpc_errors_1.rpcErrors.invalidParams('Invalid params: Key contains forbidden characters.');
135
+ }
136
+ if (i === keys.length - 1) {
137
+ currentObject[currentKey] = value;
138
+ return requiredObject;
139
+ }
140
+ if (!(0, utils_1.hasProperty)(currentObject, currentKey) ||
141
+ currentObject[currentKey] === null) {
142
+ currentObject[currentKey] = {};
143
+ }
144
+ else if (!(0, utils_1.isObject)(currentObject[currentKey])) {
145
+ throw rpc_errors_1.rpcErrors.invalidParams('Invalid params: Cannot overwrite non-object value.');
146
+ }
147
+ currentObject = currentObject[currentKey];
148
+ }
149
+ // This should never be reached.
150
+ /* istanbul ignore next */
151
+ throw new Error('Unexpected error while setting the state.');
152
+ }
153
+ exports.set = set;
154
+ //# sourceMappingURL=setState.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setState.cjs","sourceRoot":"","sources":["../../src/permitted/setState.ts"],"names":[],"mappings":";;;AAEA,qDAAiE;AAIjE,uDAM+B;AAE/B,2CAMyB;AAEzB,+DAA+D;AAE/D,wCAA0D;AAE1D,MAAM,SAAS,GAAqC;IAClD,aAAa,EAAE,IAAI;IACnB,YAAY,EAAE,IAAI;IAClB,gBAAgB,EAAE,IAAI;IACtB,eAAe,EAAE,IAAI;CACtB,CAAC;AAEF;;GAEG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,cAAc,CAAC;IAEzD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,sBAAc,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YACxC,MAAM,sBAAS,CAAC,aAAa,CAC3B,oDAAoD,CACrD,CAAC;QACJ,CAAC;QAED,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;YAC1B,aAAa,CAAC,UAAU,CAAC,GAAG,KAAK,CAAC;YAClC,OAAO,cAAc,CAAC;QACxB,CAAC;QAED,IACE,CAAC,IAAA,mBAAW,EAAC,aAAa,EAAE,UAAU,CAAC;YACvC,aAAa,CAAC,UAAU,CAAC,KAAK,IAAI,EAClC,CAAC;YACD,aAAa,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC;QACjC,CAAC;aAAM,IAAI,CAAC,IAAA,gBAAQ,EAAC,aAAa,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC;YAChD,MAAM,sBAAS,CAAC,aAAa,CAC3B,oDAAoD,CACrD,CAAC;QACJ,CAAC;QAED,aAAa,GAAG,aAAa,CAAC,UAAU,CAAyB,CAAC;IACpE,CAAC;IAED,gCAAgC;IAChC,0BAA0B;IAC1B,MAAM,IAAI,KAAK,CAAC,2CAA2C,CAAC,CAAC;AAC/D,CAAC;AAxCD,kBAwCC","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 { SetStateParams, SetStateResult } from '@metamask/snaps-sdk';\nimport type { JsonObject } from '@metamask/snaps-sdk/jsx';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n boolean,\n create,\n object as objectStruct,\n optional,\n StructError,\n} from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse, JsonRpcRequest } from '@metamask/utils';\nimport {\n hasProperty,\n isObject,\n assert,\n JsonStruct,\n type Json,\n} from '@metamask/utils';\n\nimport { manageStateBuilder } from '../restricted/manageState';\nimport type { MethodHooksObject } from '../utils';\nimport { FORBIDDEN_KEYS, StateKeyStruct } from '../utils';\n\nconst hookNames: MethodHooksObject<SetStateHooks> = {\n hasPermission: true,\n getSnapState: true,\n getUnlockPromise: true,\n updateSnapState: true,\n};\n\n/**\n * `snap_setState` sets the state of the Snap.\n */\nexport const setStateHandler: PermittedHandlerExport<\n SetStateHooks,\n SetStateParameters,\n SetStateResult\n> = {\n methodNames: ['snap_setState'],\n implementation: setStateImplementation,\n hookNames,\n};\n\nexport type SetStateHooks = {\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 * @param encrypted - Whether the state is encrypted.\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 /**\n * Update the state of the requesting Snap.\n *\n * @param newState - The new state of the Snap.\n * @param encrypted - Whether the state should be encrypted.\n */\n updateSnapState: (\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n};\n\nconst SetStateParametersStruct = objectStruct({\n key: optional(StateKeyStruct),\n value: JsonStruct,\n encrypted: optional(boolean()),\n});\n\nexport type SetStateParameters = InferMatching<\n typeof SetStateParametersStruct,\n SetStateParams\n>;\n\n/**\n * The `snap_setState` 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 * @param hooks.updateSnapState - Update the state of the requesting Snap.\n * @returns Nothing.\n */\nasync function setStateImplementation(\n request: JsonRpcRequest<SetStateParameters>,\n response: PendingJsonRpcResponse<SetStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n {\n hasPermission,\n getSnapState,\n getUnlockPromise,\n updateSnapState,\n }: SetStateHooks,\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, value, encrypted = true } = validatedParams;\n\n if (key === undefined && !isObject(value)) {\n return end(\n rpcErrors.invalidParams(\n 'Invalid params: Value must be an object if key is not provided.',\n ),\n );\n }\n\n if (encrypted) {\n await getUnlockPromise(true);\n }\n\n const newState = await getNewState(key, value, encrypted, getSnapState);\n await updateSnapState(newState, encrypted);\n response.result = null;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the parameters of the `snap_setState` 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, SetStateParametersStruct);\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 new state of the Snap.\n *\n * If the key is `undefined`, the value is expected to be an object. In this\n * case, the value is returned as the new state.\n *\n * If the key is not `undefined`, the value is set in the state at the key. If\n * the key does not exist, it is created (and any missing intermediate keys are\n * created as well).\n *\n * @param key - The key to set.\n * @param value - The value to set the key to.\n * @param encrypted - Whether the state is encrypted.\n * @param getSnapState - The `getSnapState` hook.\n * @returns The new state of the Snap.\n */\nasync function getNewState(\n key: string | undefined,\n value: Json,\n encrypted: boolean,\n getSnapState: SetStateHooks['getSnapState'],\n) {\n if (key === undefined) {\n assert(isObject(value));\n return value;\n }\n\n const state = await getSnapState(encrypted);\n return set(state, key, value);\n}\n\n/**\n * Set 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, it is created (and any missing intermediate keys are created as\n * well).\n *\n * This is a simplified version of Lodash's `set` function, but Lodash doesn't\n * seem to be maintained anymore, so we're using our own implementation.\n *\n * @param object - The object to get the key from.\n * @param key - The key to set.\n * @param value - The value to set the key to.\n * @returns The new object with the key set to the value.\n */\nexport function set(\n // eslint-disable-next-line @typescript-eslint/default-param-last\n object: Record<string, Json> | null,\n key: string,\n value: Json,\n): JsonObject {\n const keys = key.split('.');\n const requiredObject = object ?? {};\n let currentObject: Record<string, Json> = requiredObject;\n\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 (i === keys.length - 1) {\n currentObject[currentKey] = value;\n return requiredObject;\n }\n\n if (\n !hasProperty(currentObject, currentKey) ||\n currentObject[currentKey] === null\n ) {\n currentObject[currentKey] = {};\n } else if (!isObject(currentObject[currentKey])) {\n throw rpcErrors.invalidParams(\n 'Invalid params: Cannot overwrite non-object value.',\n );\n }\n\n currentObject = currentObject[currentKey] as Record<string, Json>;\n }\n\n // This should never be reached.\n /* istanbul ignore next */\n throw new Error('Unexpected error while setting the state.');\n}\n"]}
@@ -0,0 +1,65 @@
1
+ import type { PermittedHandlerExport } from "@metamask/permission-controller";
2
+ import type { SetStateParams, SetStateResult } from "@metamask/snaps-sdk";
3
+ import type { JsonObject } from "@metamask/snaps-sdk/jsx";
4
+ import { type InferMatching } from "@metamask/snaps-utils";
5
+ import { type Json } from "@metamask/utils";
6
+ /**
7
+ * `snap_setState` sets the state of the Snap.
8
+ */
9
+ export declare const setStateHandler: PermittedHandlerExport<SetStateHooks, SetStateParameters, SetStateResult>;
10
+ export type SetStateHooks = {
11
+ /**
12
+ * Check if the requesting origin has a given permission.
13
+ *
14
+ * @param permissionName - The name of the permission to check.
15
+ * @returns Whether the origin has the permission.
16
+ */
17
+ hasPermission: (permissionName: string) => boolean;
18
+ /**
19
+ * Get the state of the requesting Snap.
20
+ *
21
+ * @param encrypted - Whether the state is encrypted.
22
+ * @returns The current state of the Snap.
23
+ */
24
+ getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;
25
+ /**
26
+ * Wait for the extension to be unlocked.
27
+ *
28
+ * @returns A promise that resolves once the extension is unlocked.
29
+ */
30
+ getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
31
+ /**
32
+ * Update the state of the requesting Snap.
33
+ *
34
+ * @param newState - The new state of the Snap.
35
+ * @param encrypted - Whether the state should be encrypted.
36
+ */
37
+ updateSnapState: (newState: Record<string, Json>, encrypted: boolean) => Promise<void>;
38
+ };
39
+ declare const SetStateParametersStruct: import("@metamask/superstruct").Struct<{
40
+ value: Json;
41
+ key?: string | undefined;
42
+ encrypted?: boolean | undefined;
43
+ }, {
44
+ key: import("@metamask/superstruct").Struct<string | undefined, null>;
45
+ value: import("@metamask/superstruct").Struct<Json, unknown>;
46
+ encrypted: import("@metamask/superstruct").Struct<boolean | undefined, null>;
47
+ }>;
48
+ export type SetStateParameters = InferMatching<typeof SetStateParametersStruct, SetStateParams>;
49
+ /**
50
+ * Set the value of a key in an object. The key may contain Lodash-style path
51
+ * syntax, e.g., `a.b.c` (with the exception of array syntax). If the key does
52
+ * not exist, it is created (and any missing intermediate keys are created as
53
+ * well).
54
+ *
55
+ * This is a simplified version of Lodash's `set` function, but Lodash doesn't
56
+ * seem to be maintained anymore, so we're using our own implementation.
57
+ *
58
+ * @param object - The object to get the key from.
59
+ * @param key - The key to set.
60
+ * @param value - The value to set the key to.
61
+ * @returns The new object with the key set to the value.
62
+ */
63
+ export declare function set(object: Record<string, Json> | null, key: string, value: Json): JsonObject;
64
+ export {};
65
+ //# sourceMappingURL=setState.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setState.d.cts","sourceRoot":"","sources":["../../src/permitted/setState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,4BAA4B;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAC1D,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAS3D,OAAO,EAKL,KAAK,IAAI,EACV,wBAAwB;AAazB;;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;;;;;OAKG;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;IAEtE;;;;;OAKG;IACH,eAAe,EAAE,CACf,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EAC9B,SAAS,EAAE,OAAO,KACf,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF,QAAA,MAAM,wBAAwB;;;;;;;;EAI5B,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,aAAa,CAC5C,OAAO,wBAAwB,EAC/B,cAAc,CACf,CAAC;AAkHF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,GAAG,CAEjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,EACnC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,IAAI,GACV,UAAU,CAmCZ"}
@@ -0,0 +1,65 @@
1
+ import type { PermittedHandlerExport } from "@metamask/permission-controller";
2
+ import type { SetStateParams, SetStateResult } from "@metamask/snaps-sdk";
3
+ import type { JsonObject } from "@metamask/snaps-sdk/jsx";
4
+ import { type InferMatching } from "@metamask/snaps-utils";
5
+ import { type Json } from "@metamask/utils";
6
+ /**
7
+ * `snap_setState` sets the state of the Snap.
8
+ */
9
+ export declare const setStateHandler: PermittedHandlerExport<SetStateHooks, SetStateParameters, SetStateResult>;
10
+ export type SetStateHooks = {
11
+ /**
12
+ * Check if the requesting origin has a given permission.
13
+ *
14
+ * @param permissionName - The name of the permission to check.
15
+ * @returns Whether the origin has the permission.
16
+ */
17
+ hasPermission: (permissionName: string) => boolean;
18
+ /**
19
+ * Get the state of the requesting Snap.
20
+ *
21
+ * @param encrypted - Whether the state is encrypted.
22
+ * @returns The current state of the Snap.
23
+ */
24
+ getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;
25
+ /**
26
+ * Wait for the extension to be unlocked.
27
+ *
28
+ * @returns A promise that resolves once the extension is unlocked.
29
+ */
30
+ getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
31
+ /**
32
+ * Update the state of the requesting Snap.
33
+ *
34
+ * @param newState - The new state of the Snap.
35
+ * @param encrypted - Whether the state should be encrypted.
36
+ */
37
+ updateSnapState: (newState: Record<string, Json>, encrypted: boolean) => Promise<void>;
38
+ };
39
+ declare const SetStateParametersStruct: import("@metamask/superstruct").Struct<{
40
+ value: Json;
41
+ key?: string | undefined;
42
+ encrypted?: boolean | undefined;
43
+ }, {
44
+ key: import("@metamask/superstruct").Struct<string | undefined, null>;
45
+ value: import("@metamask/superstruct").Struct<Json, unknown>;
46
+ encrypted: import("@metamask/superstruct").Struct<boolean | undefined, null>;
47
+ }>;
48
+ export type SetStateParameters = InferMatching<typeof SetStateParametersStruct, SetStateParams>;
49
+ /**
50
+ * Set the value of a key in an object. The key may contain Lodash-style path
51
+ * syntax, e.g., `a.b.c` (with the exception of array syntax). If the key does
52
+ * not exist, it is created (and any missing intermediate keys are created as
53
+ * well).
54
+ *
55
+ * This is a simplified version of Lodash's `set` function, but Lodash doesn't
56
+ * seem to be maintained anymore, so we're using our own implementation.
57
+ *
58
+ * @param object - The object to get the key from.
59
+ * @param key - The key to set.
60
+ * @param value - The value to set the key to.
61
+ * @returns The new object with the key set to the value.
62
+ */
63
+ export declare function set(object: Record<string, Json> | null, key: string, value: Json): JsonObject;
64
+ export {};
65
+ //# sourceMappingURL=setState.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setState.d.mts","sourceRoot":"","sources":["../../src/permitted/setState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,4BAA4B;AAC1E,OAAO,KAAK,EAAE,UAAU,EAAE,gCAAgC;AAC1D,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAS3D,OAAO,EAKL,KAAK,IAAI,EACV,wBAAwB;AAazB;;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;;;;;OAKG;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;IAEtE;;;;;OAKG;IACH,eAAe,EAAE,CACf,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,EAC9B,SAAS,EAAE,OAAO,KACf,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF,QAAA,MAAM,wBAAwB;;;;;;;;EAI5B,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,aAAa,CAC5C,OAAO,wBAAwB,EAC/B,cAAc,CACf,CAAC;AAkHF;;;;;;;;;;;;;GAaG;AACH,wBAAgB,GAAG,CAEjB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,EACnC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,IAAI,GACV,UAAU,CAmCZ"}
@@ -0,0 +1,150 @@
1
+ import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
2
+ import { boolean, create, object as objectStruct, optional, StructError } from "@metamask/superstruct";
3
+ import { hasProperty, isObject, assert, JsonStruct } 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
+ updateSnapState: true,
11
+ };
12
+ /**
13
+ * `snap_setState` sets the state of the Snap.
14
+ */
15
+ export const setStateHandler = {
16
+ methodNames: ['snap_setState'],
17
+ implementation: setStateImplementation,
18
+ hookNames,
19
+ };
20
+ const SetStateParametersStruct = objectStruct({
21
+ key: optional(StateKeyStruct),
22
+ value: JsonStruct,
23
+ encrypted: optional(boolean()),
24
+ });
25
+ /**
26
+ * The `snap_setState` method implementation.
27
+ *
28
+ * @param request - The JSON-RPC request object.
29
+ * @param response - The JSON-RPC response object.
30
+ * @param _next - The `json-rpc-engine` "next" callback. Not used by this
31
+ * function.
32
+ * @param end - The `json-rpc-engine` "end" callback.
33
+ * @param hooks - The RPC method hooks.
34
+ * @param hooks.hasPermission - Check whether a given origin has a given
35
+ * permission.
36
+ * @param hooks.getSnapState - Get the state of the requesting Snap.
37
+ * @param hooks.getUnlockPromise - Wait for the extension to be unlocked.
38
+ * @param hooks.updateSnapState - Update the state of the requesting Snap.
39
+ * @returns Nothing.
40
+ */
41
+ async function setStateImplementation(request, response, _next, end, { hasPermission, getSnapState, getUnlockPromise, updateSnapState, }) {
42
+ const { params } = request;
43
+ if (!hasPermission(manageStateBuilder.targetName)) {
44
+ return end(providerErrors.unauthorized());
45
+ }
46
+ try {
47
+ const validatedParams = getValidatedParams(params);
48
+ const { key, value, encrypted = true } = validatedParams;
49
+ if (key === undefined && !isObject(value)) {
50
+ return end(rpcErrors.invalidParams('Invalid params: Value must be an object if key is not provided.'));
51
+ }
52
+ if (encrypted) {
53
+ await getUnlockPromise(true);
54
+ }
55
+ const newState = await getNewState(key, value, encrypted, getSnapState);
56
+ await updateSnapState(newState, encrypted);
57
+ response.result = null;
58
+ }
59
+ catch (error) {
60
+ return end(error);
61
+ }
62
+ return end();
63
+ }
64
+ /**
65
+ * Validate the parameters of the `snap_setState` method.
66
+ *
67
+ * @param params - The parameters to validate.
68
+ * @returns The validated parameters.
69
+ */
70
+ function getValidatedParams(params) {
71
+ try {
72
+ return create(params, SetStateParametersStruct);
73
+ }
74
+ catch (error) {
75
+ if (error instanceof StructError) {
76
+ throw rpcErrors.invalidParams({
77
+ message: `Invalid params: ${error.message}.`,
78
+ });
79
+ }
80
+ /* istanbul ignore next */
81
+ throw rpcErrors.internal();
82
+ }
83
+ }
84
+ /**
85
+ * Get the new state of the Snap.
86
+ *
87
+ * If the key is `undefined`, the value is expected to be an object. In this
88
+ * case, the value is returned as the new state.
89
+ *
90
+ * If the key is not `undefined`, the value is set in the state at the key. If
91
+ * the key does not exist, it is created (and any missing intermediate keys are
92
+ * created as well).
93
+ *
94
+ * @param key - The key to set.
95
+ * @param value - The value to set the key to.
96
+ * @param encrypted - Whether the state is encrypted.
97
+ * @param getSnapState - The `getSnapState` hook.
98
+ * @returns The new state of the Snap.
99
+ */
100
+ async function getNewState(key, value, encrypted, getSnapState) {
101
+ if (key === undefined) {
102
+ assert(isObject(value));
103
+ return value;
104
+ }
105
+ const state = await getSnapState(encrypted);
106
+ return set(state, key, value);
107
+ }
108
+ /**
109
+ * Set the value of a key in an object. The key may contain Lodash-style path
110
+ * syntax, e.g., `a.b.c` (with the exception of array syntax). If the key does
111
+ * not exist, it is created (and any missing intermediate keys are created as
112
+ * well).
113
+ *
114
+ * This is a simplified version of Lodash's `set` function, but Lodash doesn't
115
+ * seem to be maintained anymore, so we're using our own implementation.
116
+ *
117
+ * @param object - The object to get the key from.
118
+ * @param key - The key to set.
119
+ * @param value - The value to set the key to.
120
+ * @returns The new object with the key set to the value.
121
+ */
122
+ export function set(
123
+ // eslint-disable-next-line @typescript-eslint/default-param-last
124
+ object, key, value) {
125
+ const keys = key.split('.');
126
+ const requiredObject = object ?? {};
127
+ let currentObject = requiredObject;
128
+ for (let i = 0; i < keys.length; i++) {
129
+ const currentKey = keys[i];
130
+ if (FORBIDDEN_KEYS.includes(currentKey)) {
131
+ throw rpcErrors.invalidParams('Invalid params: Key contains forbidden characters.');
132
+ }
133
+ if (i === keys.length - 1) {
134
+ currentObject[currentKey] = value;
135
+ return requiredObject;
136
+ }
137
+ if (!hasProperty(currentObject, currentKey) ||
138
+ currentObject[currentKey] === null) {
139
+ currentObject[currentKey] = {};
140
+ }
141
+ else if (!isObject(currentObject[currentKey])) {
142
+ throw rpcErrors.invalidParams('Invalid params: Cannot overwrite non-object value.');
143
+ }
144
+ currentObject = currentObject[currentKey];
145
+ }
146
+ // This should never be reached.
147
+ /* istanbul ignore next */
148
+ throw new Error('Unexpected error while setting the state.');
149
+ }
150
+ //# sourceMappingURL=setState.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"setState.mjs","sourceRoot":"","sources":["../../src/permitted/setState.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAIjE,OAAO,EACL,OAAO,EACP,MAAM,E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/D,CAAC","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 { SetStateParams, SetStateResult } from '@metamask/snaps-sdk';\nimport type { JsonObject } from '@metamask/snaps-sdk/jsx';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n boolean,\n create,\n object as objectStruct,\n optional,\n StructError,\n} from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse, JsonRpcRequest } from '@metamask/utils';\nimport {\n hasProperty,\n isObject,\n assert,\n JsonStruct,\n type Json,\n} from '@metamask/utils';\n\nimport { manageStateBuilder } from '../restricted/manageState';\nimport type { MethodHooksObject } from '../utils';\nimport { FORBIDDEN_KEYS, StateKeyStruct } from '../utils';\n\nconst hookNames: MethodHooksObject<SetStateHooks> = {\n hasPermission: true,\n getSnapState: true,\n getUnlockPromise: true,\n updateSnapState: true,\n};\n\n/**\n * `snap_setState` sets the state of the Snap.\n */\nexport const setStateHandler: PermittedHandlerExport<\n SetStateHooks,\n SetStateParameters,\n SetStateResult\n> = {\n methodNames: ['snap_setState'],\n implementation: setStateImplementation,\n hookNames,\n};\n\nexport type SetStateHooks = {\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 * @param encrypted - Whether the state is encrypted.\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 /**\n * Update the state of the requesting Snap.\n *\n * @param newState - The new state of the Snap.\n * @param encrypted - Whether the state should be encrypted.\n */\n updateSnapState: (\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n};\n\nconst SetStateParametersStruct = objectStruct({\n key: optional(StateKeyStruct),\n value: JsonStruct,\n encrypted: optional(boolean()),\n});\n\nexport type SetStateParameters = InferMatching<\n typeof SetStateParametersStruct,\n SetStateParams\n>;\n\n/**\n * The `snap_setState` 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 * @param hooks.updateSnapState - Update the state of the requesting Snap.\n * @returns Nothing.\n */\nasync function setStateImplementation(\n request: JsonRpcRequest<SetStateParameters>,\n response: PendingJsonRpcResponse<SetStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n {\n hasPermission,\n getSnapState,\n getUnlockPromise,\n updateSnapState,\n }: SetStateHooks,\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, value, encrypted = true } = validatedParams;\n\n if (key === undefined && !isObject(value)) {\n return end(\n rpcErrors.invalidParams(\n 'Invalid params: Value must be an object if key is not provided.',\n ),\n );\n }\n\n if (encrypted) {\n await getUnlockPromise(true);\n }\n\n const newState = await getNewState(key, value, encrypted, getSnapState);\n await updateSnapState(newState, encrypted);\n response.result = null;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the parameters of the `snap_setState` 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, SetStateParametersStruct);\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 new state of the Snap.\n *\n * If the key is `undefined`, the value is expected to be an object. In this\n * case, the value is returned as the new state.\n *\n * If the key is not `undefined`, the value is set in the state at the key. If\n * the key does not exist, it is created (and any missing intermediate keys are\n * created as well).\n *\n * @param key - The key to set.\n * @param value - The value to set the key to.\n * @param encrypted - Whether the state is encrypted.\n * @param getSnapState - The `getSnapState` hook.\n * @returns The new state of the Snap.\n */\nasync function getNewState(\n key: string | undefined,\n value: Json,\n encrypted: boolean,\n getSnapState: SetStateHooks['getSnapState'],\n) {\n if (key === undefined) {\n assert(isObject(value));\n return value;\n }\n\n const state = await getSnapState(encrypted);\n return set(state, key, value);\n}\n\n/**\n * Set 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, it is created (and any missing intermediate keys are created as\n * well).\n *\n * This is a simplified version of Lodash's `set` function, but Lodash doesn't\n * seem to be maintained anymore, so we're using our own implementation.\n *\n * @param object - The object to get the key from.\n * @param key - The key to set.\n * @param value - The value to set the key to.\n * @returns The new object with the key set to the value.\n */\nexport function set(\n // eslint-disable-next-line @typescript-eslint/default-param-last\n object: Record<string, Json> | null,\n key: string,\n value: Json,\n): JsonObject {\n const keys = key.split('.');\n const requiredObject = object ?? {};\n let currentObject: Record<string, Json> = requiredObject;\n\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 (i === keys.length - 1) {\n currentObject[currentKey] = value;\n return requiredObject;\n }\n\n if (\n !hasProperty(currentObject, currentKey) ||\n currentObject[currentKey] === null\n ) {\n currentObject[currentKey] = {};\n } else if (!isObject(currentObject[currentKey])) {\n throw rpcErrors.invalidParams(\n 'Invalid params: Cannot overwrite non-object value.',\n );\n }\n\n currentObject = currentObject[currentKey] as Record<string, Json>;\n }\n\n // This should never be reached.\n /* istanbul ignore next */\n throw new Error('Unexpected error while setting the state.');\n}\n"]}
@@ -12,7 +12,7 @@ export type UpdateInterfaceMethodHooks = {
12
12
  export declare const updateInterfaceHandler: PermittedHandlerExport<UpdateInterfaceMethodHooks, UpdateInterfaceParameters, UpdateInterfaceResult>;
13
13
  declare const UpdateInterfaceParametersStruct: import("@metamask/superstruct").Struct<{
14
14
  id: string;
15
- ui: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FieldProps, "Field"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
15
+ ui: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FieldProps, "Field"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BannerProps, "Banner"> | {
16
16
  type: import("@metamask/snaps-sdk").NodeType.Copyable;
17
17
  value: string;
18
18
  sensitive?: boolean | undefined;
@@ -97,7 +97,7 @@ declare const UpdateInterfaceParametersStruct: import("@metamask/superstruct").S
97
97
  context?: Record<string, import("@metamask/snaps-sdk").Json> | undefined;
98
98
  }, {
99
99
  id: import("@metamask/superstruct").Struct<string, null>;
100
- ui: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FieldProps, "Field"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
100
+ ui: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FieldProps, "Field"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BannerProps, "Banner"> | {
101
101
  type: import("@metamask/snaps-sdk").NodeType.Copyable;
102
102
  value: string;
103
103
  sensitive?: boolean | undefined;
@@ -12,7 +12,7 @@ export type UpdateInterfaceMethodHooks = {
12
12
  export declare const updateInterfaceHandler: PermittedHandlerExport<UpdateInterfaceMethodHooks, UpdateInterfaceParameters, UpdateInterfaceResult>;
13
13
  declare const UpdateInterfaceParametersStruct: import("@metamask/superstruct").Struct<{
14
14
  id: string;
15
- ui: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FieldProps, "Field"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
15
+ ui: import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FieldProps, "Field"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BannerProps, "Banner"> | {
16
16
  type: import("@metamask/snaps-sdk").NodeType.Copyable;
17
17
  value: string;
18
18
  sensitive?: boolean | undefined;
@@ -97,7 +97,7 @@ declare const UpdateInterfaceParametersStruct: import("@metamask/superstruct").S
97
97
  context?: Record<string, import("@metamask/snaps-sdk").Json> | undefined;
98
98
  }, {
99
99
  id: import("@metamask/superstruct").Struct<string, null>;
100
- ui: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FieldProps, "Field"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
100
+ ui: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FieldProps, "Field"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AvatarProps, "Avatar"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BannerProps, "Banner"> | {
101
101
  type: import("@metamask/snaps-sdk").NodeType.Copyable;
102
102
  value: string;
103
103
  sensitive?: boolean | undefined;