@metamask/snaps-rpc-methods 11.5.0 → 11.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +15 -1
- package/dist/permitted/createInterface.cjs.map +1 -1
- package/dist/permitted/createInterface.d.cts +4 -16
- package/dist/permitted/createInterface.d.cts.map +1 -1
- package/dist/permitted/createInterface.d.mts +4 -16
- package/dist/permitted/createInterface.d.mts.map +1 -1
- package/dist/permitted/createInterface.mjs.map +1 -1
- package/dist/permitted/getInterfaceContext.cjs +62 -0
- package/dist/permitted/getInterfaceContext.cjs.map +1 -0
- package/dist/permitted/getInterfaceContext.d.cts +19 -0
- package/dist/permitted/getInterfaceContext.d.cts.map +1 -0
- package/dist/permitted/getInterfaceContext.d.mts +19 -0
- package/dist/permitted/getInterfaceContext.d.mts.map +1 -0
- package/dist/permitted/getInterfaceContext.mjs +59 -0
- package/dist/permitted/getInterfaceContext.mjs.map +1 -0
- package/dist/permitted/handlers.cjs +2 -0
- package/dist/permitted/handlers.cjs.map +1 -1
- package/dist/permitted/handlers.d.cts +2 -1
- package/dist/permitted/handlers.d.cts.map +1 -1
- package/dist/permitted/handlers.d.mts +2 -1
- package/dist/permitted/handlers.d.mts.map +1 -1
- package/dist/permitted/handlers.mjs +2 -0
- package/dist/permitted/handlers.mjs.map +1 -1
- package/dist/restricted/dialog.cjs.map +1 -1
- package/dist/restricted/dialog.d.cts +58 -58
- package/dist/restricted/dialog.d.cts.map +1 -1
- package/dist/restricted/dialog.d.mts +58 -58
- package/dist/restricted/dialog.d.mts.map +1 -1
- package/dist/restricted/dialog.mjs.map +1 -1
- package/package.json +8 -8
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,18 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [11.6.0]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- Add `snap_getInterfaceContext` JSON-RPC method ([#2902](https://github.com/MetaMask/snaps/pull/2902))
|
|
15
|
+
|
|
16
|
+
## [11.5.1]
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- Bump MetaMask dependencies ([#2853](https://github.com/MetaMask/snaps/pull/2853))
|
|
21
|
+
|
|
10
22
|
## [11.5.0]
|
|
11
23
|
|
|
12
24
|
### Removed
|
|
@@ -323,7 +335,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
323
335
|
- The version of the package no longer needs to match the version of all other
|
|
324
336
|
MetaMask Snaps packages.
|
|
325
337
|
|
|
326
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.
|
|
338
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.6.0...HEAD
|
|
339
|
+
[11.6.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.5.1...@metamask/snaps-rpc-methods@11.6.0
|
|
340
|
+
[11.5.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.5.0...@metamask/snaps-rpc-methods@11.5.1
|
|
327
341
|
[11.5.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.4.0...@metamask/snaps-rpc-methods@11.5.0
|
|
328
342
|
[11.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.3.0...@metamask/snaps-rpc-methods@11.4.0
|
|
329
343
|
[11.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.2.0...@metamask/snaps-rpc-methods@11.3.0
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createInterface.cjs","sourceRoot":"","sources":["../../src/permitted/createInterface.ts"],"names":[],"mappings":";;;AAEA,qDAAiD;
|
|
1
|
+
{"version":3,"file":"createInterface.cjs","sourceRoot":"","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O,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,sBAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n CreateInterfaceParams,\n CreateInterfaceResult,\n JsonRpcRequest,\n ComponentOrElement,\n InterfaceContext,\n ContentType,\n} from '@metamask/snaps-sdk';\nimport {\n ComponentOrElementStruct,\n InterfaceContextStruct,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport { StructError, create, object, optional } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<CreateInterfaceMethodHooks> = {\n createInterface: true,\n};\n\nexport type CreateInterfaceMethodHooks = {\n /**\n * @param ui - The UI components.\n * @returns The unique identifier of the interface.\n */\n createInterface: (\n ui: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) => Promise<string>;\n};\n\nexport const createInterfaceHandler: PermittedHandlerExport<\n CreateInterfaceMethodHooks,\n CreateInterfaceParameters,\n CreateInterfaceResult\n> = {\n methodNames: ['snap_createInterface'],\n implementation: getCreateInterfaceImplementation,\n hookNames,\n};\n\nconst CreateInterfaceParametersStruct = object({\n ui: ComponentOrElementStruct,\n context: optional(InterfaceContextStruct),\n});\n\nexport type CreateInterfaceParameters = InferMatching<\n typeof CreateInterfaceParametersStruct,\n CreateInterfaceParams\n>;\n\n/**\n * The `snap_createInterface` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.createInterface - The function to create the interface.\n * @returns Nothing.\n */\nasync function getCreateInterfaceImplementation(\n req: JsonRpcRequest<CreateInterfaceParameters>,\n res: PendingJsonRpcResponse<CreateInterfaceResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { createInterface }: CreateInterfaceMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { ui, context } = validatedParams;\n\n res.result = await createInterface(ui, context);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the createInterface method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated createInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): CreateInterfaceParameters {\n try {\n return create(params, CreateInterfaceParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { PermittedHandlerExport } from "@metamask/permission-controller";
|
|
2
|
-
import type { CreateInterfaceParams, CreateInterfaceResult, ComponentOrElement, InterfaceContext } from "@metamask/snaps-sdk";
|
|
2
|
+
import type { CreateInterfaceParams, CreateInterfaceResult, ComponentOrElement, InterfaceContext, ContentType } from "@metamask/snaps-sdk";
|
|
3
3
|
import { type InferMatching } from "@metamask/snaps-utils";
|
|
4
4
|
export type CreateInterfaceMethodHooks = {
|
|
5
5
|
/**
|
|
6
6
|
* @param ui - The UI components.
|
|
7
7
|
* @returns The unique identifier of the interface.
|
|
8
8
|
*/
|
|
9
|
-
createInterface: (ui: ComponentOrElement, context?: InterfaceContext) => Promise<string>;
|
|
9
|
+
createInterface: (ui: ComponentOrElement, context?: InterfaceContext, contentType?: ContentType) => Promise<string>;
|
|
10
10
|
};
|
|
11
11
|
export declare const createInterfaceHandler: PermittedHandlerExport<CreateInterfaceMethodHooks, CreateInterfaceParameters, CreateInterfaceResult>;
|
|
12
12
|
declare const CreateInterfaceParametersStruct: import("@metamask/superstruct").Struct<{
|
|
@@ -44,13 +44,7 @@ declare const CreateInterfaceParametersStruct: import("@metamask/superstruct").S
|
|
|
44
44
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
45
45
|
value: `0x${string}`;
|
|
46
46
|
};
|
|
47
|
-
label: string;
|
|
48
|
-
* Validate the createInterface method `params` and returns them cast to the correct
|
|
49
|
-
* type. Throws if validation fails.
|
|
50
|
-
*
|
|
51
|
-
* @param params - The unvalidated params object from the method request.
|
|
52
|
-
* @returns The validated createInterface method parameter object.
|
|
53
|
-
*/
|
|
47
|
+
label: string;
|
|
54
48
|
variant?: "default" | "warning" | "critical" | undefined;
|
|
55
49
|
} | {
|
|
56
50
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
@@ -134,13 +128,7 @@ declare const CreateInterfaceParametersStruct: import("@metamask/superstruct").S
|
|
|
134
128
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
135
129
|
value: `0x${string}`;
|
|
136
130
|
};
|
|
137
|
-
label: string;
|
|
138
|
-
* Validate the createInterface method `params` and returns them cast to the correct
|
|
139
|
-
* type. Throws if validation fails.
|
|
140
|
-
*
|
|
141
|
-
* @param params - The unvalidated params object from the method request.
|
|
142
|
-
* @returns The validated createInterface method parameter object.
|
|
143
|
-
*/
|
|
131
|
+
label: string;
|
|
144
132
|
variant?: "default" | "warning" | "critical" | undefined;
|
|
145
133
|
} | {
|
|
146
134
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createInterface.d.cts","sourceRoot":"","sources":["../../src/permitted/createInterface.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EAErB,kBAAkB,EAClB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"createInterface.d.cts","sourceRoot":"","sources":["../../src/permitted/createInterface.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EAErB,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACZ,4BAA4B;AAK7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAU3D,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;OAGG;IACH,eAAe,EAAE,CACf,EAAE,EAAE,kBAAkB,EACtB,OAAO,CAAC,EAAE,gBAAgB,EAC1B,WAAW,CAAC,EAAE,WAAW,KACtB,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,CAKtB,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGnC,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,aAAa,CACnD,OAAO,+BAA+B,EACtC,qBAAqB,CACtB,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import type { PermittedHandlerExport } from "@metamask/permission-controller";
|
|
2
|
-
import type { CreateInterfaceParams, CreateInterfaceResult, ComponentOrElement, InterfaceContext } from "@metamask/snaps-sdk";
|
|
2
|
+
import type { CreateInterfaceParams, CreateInterfaceResult, ComponentOrElement, InterfaceContext, ContentType } from "@metamask/snaps-sdk";
|
|
3
3
|
import { type InferMatching } from "@metamask/snaps-utils";
|
|
4
4
|
export type CreateInterfaceMethodHooks = {
|
|
5
5
|
/**
|
|
6
6
|
* @param ui - The UI components.
|
|
7
7
|
* @returns The unique identifier of the interface.
|
|
8
8
|
*/
|
|
9
|
-
createInterface: (ui: ComponentOrElement, context?: InterfaceContext) => Promise<string>;
|
|
9
|
+
createInterface: (ui: ComponentOrElement, context?: InterfaceContext, contentType?: ContentType) => Promise<string>;
|
|
10
10
|
};
|
|
11
11
|
export declare const createInterfaceHandler: PermittedHandlerExport<CreateInterfaceMethodHooks, CreateInterfaceParameters, CreateInterfaceResult>;
|
|
12
12
|
declare const CreateInterfaceParametersStruct: import("@metamask/superstruct").Struct<{
|
|
@@ -44,13 +44,7 @@ declare const CreateInterfaceParametersStruct: import("@metamask/superstruct").S
|
|
|
44
44
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
45
45
|
value: `0x${string}`;
|
|
46
46
|
};
|
|
47
|
-
label: string;
|
|
48
|
-
* Validate the createInterface method `params` and returns them cast to the correct
|
|
49
|
-
* type. Throws if validation fails.
|
|
50
|
-
*
|
|
51
|
-
* @param params - The unvalidated params object from the method request.
|
|
52
|
-
* @returns The validated createInterface method parameter object.
|
|
53
|
-
*/
|
|
47
|
+
label: string;
|
|
54
48
|
variant?: "default" | "warning" | "critical" | undefined;
|
|
55
49
|
} | {
|
|
56
50
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
@@ -134,13 +128,7 @@ declare const CreateInterfaceParametersStruct: import("@metamask/superstruct").S
|
|
|
134
128
|
type: import("@metamask/snaps-sdk").NodeType.Address;
|
|
135
129
|
value: `0x${string}`;
|
|
136
130
|
};
|
|
137
|
-
label: string;
|
|
138
|
-
* Validate the createInterface method `params` and returns them cast to the correct
|
|
139
|
-
* type. Throws if validation fails.
|
|
140
|
-
*
|
|
141
|
-
* @param params - The unvalidated params object from the method request.
|
|
142
|
-
* @returns The validated createInterface method parameter object.
|
|
143
|
-
*/
|
|
131
|
+
label: string;
|
|
144
132
|
variant?: "default" | "warning" | "critical" | undefined;
|
|
145
133
|
} | {
|
|
146
134
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createInterface.d.mts","sourceRoot":"","sources":["../../src/permitted/createInterface.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EAErB,kBAAkB,EAClB,gBAAgB,
|
|
1
|
+
{"version":3,"file":"createInterface.d.mts","sourceRoot":"","sources":["../../src/permitted/createInterface.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EAErB,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACZ,4BAA4B;AAK7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAU3D,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;OAGG;IACH,eAAe,EAAE,CACf,EAAE,EAAE,kBAAkB,EACtB,OAAO,CAAC,EAAE,gBAAgB,EAC1B,WAAW,CAAC,EAAE,WAAW,KACtB,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,CAKtB,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAGnC,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,aAAa,CACnD,OAAO,+BAA+B,EACtC,qBAAqB,CACtB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createInterface.mjs","sourceRoot":"","sources":["../../src/permitted/createInterface.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,6BAA6B;
|
|
1
|
+
{"version":3,"file":"createInterface.mjs","sourceRoot":"","sources":["../../src/permitted/createInterface.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AASjD,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACvB,4BAA4B;AAE7B,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,8BAA8B;AAK9E,MAAM,SAAS,GAAkD;IAC/D,eAAe,EAAE,IAAI;CACtB,CAAC;AAcF,MAAM,CAAC,MAAM,sBAAsB,GAI/B;IACF,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrC,cAAc,EAAE,gCAAgC;IAChD,SAAS;CACV,CAAC;AAEF,MAAM,+BAA+B,GAAG,MAAM,CAAC;IAC7C,EAAE,EAAE,wBAAwB;IAC5B,OAAO,EAAE,QAAQ,CAAC,sBAAsB,CAAC;CAC1C,CAAC,CAAC;AAOH;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,gCAAgC,CAC7C,GAA8C,EAC9C,GAAkD,EAClD,KAAc,EACd,GAA6B,EAC7B,EAAE,eAAe,EAA8B;IAE/C,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEvB,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;QAExC,GAAG,CAAC,MAAM,GAAG,MAAM,eAAe,CAAC,EAAE,EAAE,OAAO,CAAC,CAAC;IAClD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,+BAA+B,CAAC,CAAC;IACzD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n CreateInterfaceParams,\n CreateInterfaceResult,\n JsonRpcRequest,\n ComponentOrElement,\n InterfaceContext,\n ContentType,\n} from '@metamask/snaps-sdk';\nimport {\n ComponentOrElementStruct,\n InterfaceContextStruct,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport { StructError, create, object, optional } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<CreateInterfaceMethodHooks> = {\n createInterface: true,\n};\n\nexport type CreateInterfaceMethodHooks = {\n /**\n * @param ui - The UI components.\n * @returns The unique identifier of the interface.\n */\n createInterface: (\n ui: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n ) => Promise<string>;\n};\n\nexport const createInterfaceHandler: PermittedHandlerExport<\n CreateInterfaceMethodHooks,\n CreateInterfaceParameters,\n CreateInterfaceResult\n> = {\n methodNames: ['snap_createInterface'],\n implementation: getCreateInterfaceImplementation,\n hookNames,\n};\n\nconst CreateInterfaceParametersStruct = object({\n ui: ComponentOrElementStruct,\n context: optional(InterfaceContextStruct),\n});\n\nexport type CreateInterfaceParameters = InferMatching<\n typeof CreateInterfaceParametersStruct,\n CreateInterfaceParams\n>;\n\n/**\n * The `snap_createInterface` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.createInterface - The function to create the interface.\n * @returns Nothing.\n */\nasync function getCreateInterfaceImplementation(\n req: JsonRpcRequest<CreateInterfaceParameters>,\n res: PendingJsonRpcResponse<CreateInterfaceResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { createInterface }: CreateInterfaceMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { ui, context } = validatedParams;\n\n res.result = await createInterface(ui, context);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the createInterface method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated createInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): CreateInterfaceParameters {\n try {\n return create(params, CreateInterfaceParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getInterfaceContextHandler = void 0;
|
|
4
|
+
const rpc_errors_1 = require("@metamask/rpc-errors");
|
|
5
|
+
const superstruct_1 = require("@metamask/superstruct");
|
|
6
|
+
const hookNames = {
|
|
7
|
+
getInterfaceContext: true,
|
|
8
|
+
};
|
|
9
|
+
exports.getInterfaceContextHandler = {
|
|
10
|
+
methodNames: ['snap_getInterfaceContext'],
|
|
11
|
+
implementation: getInterfaceContextImplementation,
|
|
12
|
+
hookNames,
|
|
13
|
+
};
|
|
14
|
+
const GetInterfaceContextParametersStruct = (0, superstruct_1.object)({
|
|
15
|
+
id: (0, superstruct_1.string)(),
|
|
16
|
+
});
|
|
17
|
+
/**
|
|
18
|
+
* The `snap_getInterfaceContext` method implementation.
|
|
19
|
+
*
|
|
20
|
+
* @param req - The JSON-RPC request object.
|
|
21
|
+
* @param res - The JSON-RPC response object.
|
|
22
|
+
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
23
|
+
* function.
|
|
24
|
+
* @param end - The `json-rpc-engine` "end" callback.
|
|
25
|
+
* @param hooks - The RPC method hooks.
|
|
26
|
+
* @param hooks.getInterfaceContext - The function to get the interface context.
|
|
27
|
+
* @returns Noting.
|
|
28
|
+
*/
|
|
29
|
+
function getInterfaceContextImplementation(req, res, _next, end, { getInterfaceContext }) {
|
|
30
|
+
const { params } = req;
|
|
31
|
+
try {
|
|
32
|
+
const validatedParams = getValidatedParams(params);
|
|
33
|
+
const { id } = validatedParams;
|
|
34
|
+
res.result = getInterfaceContext(id);
|
|
35
|
+
}
|
|
36
|
+
catch (error) {
|
|
37
|
+
return end(error);
|
|
38
|
+
}
|
|
39
|
+
return end();
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Validate the getInterfaceContext method `params` and returns them cast to the correct
|
|
43
|
+
* type. Throws if validation fails.
|
|
44
|
+
*
|
|
45
|
+
* @param params - The unvalidated params object from the method request.
|
|
46
|
+
* @returns The validated getInterfaceContext method parameter object.
|
|
47
|
+
*/
|
|
48
|
+
function getValidatedParams(params) {
|
|
49
|
+
try {
|
|
50
|
+
return (0, superstruct_1.create)(params, GetInterfaceContextParametersStruct);
|
|
51
|
+
}
|
|
52
|
+
catch (error) {
|
|
53
|
+
if (error instanceof superstruct_1.StructError) {
|
|
54
|
+
throw rpc_errors_1.rpcErrors.invalidParams({
|
|
55
|
+
message: `Invalid params: ${error.message}.`,
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
/* istanbul ignore next */
|
|
59
|
+
throw rpc_errors_1.rpcErrors.internal();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
//# sourceMappingURL=getInterfaceContext.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getInterfaceContext.cjs","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":";;;AAEA,qDAAiD;AAQjD,uDAA4E;AAK5E,MAAM,SAAS,GAAsD;IACnE,mBAAmB,EAAE,IAAI;CAC1B,CAAC;AAUW,QAAA,0BAA0B,GAInC;IACF,WAAW,EAAE,CAAC,0BAA0B,CAAC;IACzC,cAAc,EAAE,iCAAiC;IACjD,SAAS;CACV,CAAC;AAEF,MAAM,mCAAmC,GAAG,IAAA,oBAAM,EAAC;IACjD,EAAE,EAAE,IAAA,oBAAM,GAAE;CACb,CAAC,CAAC;AAOH;;;;;;;;;;;GAWG;AACH,SAAS,iCAAiC,CACxC,GAAkD,EAClD,GAAsD,EACtD,KAAc,EACd,GAA6B,EAC7B,EAAE,mBAAmB,EAAkC;IAEvD,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEvB,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,EAAE,EAAE,GAAG,eAAe,CAAC;QAE/B,GAAG,CAAC,MAAM,GAAG,mBAAmB,CAAC,EAAE,CAAC,CAAC;IACvC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,mCAAmC,CAAC,CAAC;IAC7D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,yBAAW,EAAE,CAAC;YACjC,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,sBAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetInterfaceContextParams,\n GetInterfaceContextResult,\n InterfaceContext,\n JsonRpcRequest,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport { StructError, create, object, string } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetInterfaceContextMethodHooks> = {\n getInterfaceContext: true,\n};\n\nexport type GetInterfaceContextMethodHooks = {\n /**\n * @param id - The interface ID.\n * @returns The interface context.\n */\n getInterfaceContext: (id: string) => InterfaceContext | null;\n};\n\nexport const getInterfaceContextHandler: PermittedHandlerExport<\n GetInterfaceContextMethodHooks,\n GetInterfaceContextParameters,\n GetInterfaceContextResult\n> = {\n methodNames: ['snap_getInterfaceContext'],\n implementation: getInterfaceContextImplementation,\n hookNames,\n};\n\nconst GetInterfaceContextParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceContextParameters = InferMatching<\n typeof GetInterfaceContextParametersStruct,\n GetInterfaceContextParams\n>;\n\n/**\n * The `snap_getInterfaceContext` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getInterfaceContext - The function to get the interface context.\n * @returns Noting.\n */\nfunction getInterfaceContextImplementation(\n req: JsonRpcRequest<GetInterfaceContextParameters>,\n res: PendingJsonRpcResponse<GetInterfaceContextResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getInterfaceContext }: GetInterfaceContextMethodHooks,\n): void {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n res.result = getInterfaceContext(id);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceContext method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated getInterfaceContext method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceContextParameters {\n try {\n return create(params, GetInterfaceContextParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PermittedHandlerExport } from "@metamask/permission-controller";
|
|
2
|
+
import type { GetInterfaceContextParams, GetInterfaceContextResult, InterfaceContext } from "@metamask/snaps-sdk";
|
|
3
|
+
import { type InferMatching } from "@metamask/snaps-utils";
|
|
4
|
+
export type GetInterfaceContextMethodHooks = {
|
|
5
|
+
/**
|
|
6
|
+
* @param id - The interface ID.
|
|
7
|
+
* @returns The interface context.
|
|
8
|
+
*/
|
|
9
|
+
getInterfaceContext: (id: string) => InterfaceContext | null;
|
|
10
|
+
};
|
|
11
|
+
export declare const getInterfaceContextHandler: PermittedHandlerExport<GetInterfaceContextMethodHooks, GetInterfaceContextParameters, GetInterfaceContextResult>;
|
|
12
|
+
declare const GetInterfaceContextParametersStruct: import("@metamask/superstruct").Struct<{
|
|
13
|
+
id: string;
|
|
14
|
+
}, {
|
|
15
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
|
16
|
+
}>;
|
|
17
|
+
export type GetInterfaceContextParameters = InferMatching<typeof GetInterfaceContextParametersStruct, GetInterfaceContextParams>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=getInterfaceContext.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getInterfaceContext.d.cts","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,yBAAyB,EACzB,yBAAyB,EACzB,gBAAgB,EAEjB,4BAA4B;AAC7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAU3D,MAAM,MAAM,8BAA8B,GAAG;IAC3C;;;OAGG;IACH,mBAAmB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,gBAAgB,GAAG,IAAI,CAAC;CAC9D,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,sBAAsB,CAC7D,8BAA8B,EAC9B,6BAA6B,EAC7B,yBAAyB,CAK1B,CAAC;AAEF,QAAA,MAAM,mCAAmC;;;;EAEvC,CAAC;AAEH,MAAM,MAAM,6BAA6B,GAAG,aAAa,CACvD,OAAO,mCAAmC,EAC1C,yBAAyB,CAC1B,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { PermittedHandlerExport } from "@metamask/permission-controller";
|
|
2
|
+
import type { GetInterfaceContextParams, GetInterfaceContextResult, InterfaceContext } from "@metamask/snaps-sdk";
|
|
3
|
+
import { type InferMatching } from "@metamask/snaps-utils";
|
|
4
|
+
export type GetInterfaceContextMethodHooks = {
|
|
5
|
+
/**
|
|
6
|
+
* @param id - The interface ID.
|
|
7
|
+
* @returns The interface context.
|
|
8
|
+
*/
|
|
9
|
+
getInterfaceContext: (id: string) => InterfaceContext | null;
|
|
10
|
+
};
|
|
11
|
+
export declare const getInterfaceContextHandler: PermittedHandlerExport<GetInterfaceContextMethodHooks, GetInterfaceContextParameters, GetInterfaceContextResult>;
|
|
12
|
+
declare const GetInterfaceContextParametersStruct: import("@metamask/superstruct").Struct<{
|
|
13
|
+
id: string;
|
|
14
|
+
}, {
|
|
15
|
+
id: import("@metamask/superstruct").Struct<string, null>;
|
|
16
|
+
}>;
|
|
17
|
+
export type GetInterfaceContextParameters = InferMatching<typeof GetInterfaceContextParametersStruct, GetInterfaceContextParams>;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=getInterfaceContext.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getInterfaceContext.d.mts","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,yBAAyB,EACzB,yBAAyB,EACzB,gBAAgB,EAEjB,4BAA4B;AAC7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAU3D,MAAM,MAAM,8BAA8B,GAAG;IAC3C;;;OAGG;IACH,mBAAmB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,gBAAgB,GAAG,IAAI,CAAC;CAC9D,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,sBAAsB,CAC7D,8BAA8B,EAC9B,6BAA6B,EAC7B,yBAAyB,CAK1B,CAAC;AAEF,QAAA,MAAM,mCAAmC;;;;EAEvC,CAAC;AAEH,MAAM,MAAM,6BAA6B,GAAG,aAAa,CACvD,OAAO,mCAAmC,EAC1C,yBAAyB,CAC1B,CAAC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { rpcErrors } from "@metamask/rpc-errors";
|
|
2
|
+
import { StructError, create, object, string } from "@metamask/superstruct";
|
|
3
|
+
const hookNames = {
|
|
4
|
+
getInterfaceContext: true,
|
|
5
|
+
};
|
|
6
|
+
export const getInterfaceContextHandler = {
|
|
7
|
+
methodNames: ['snap_getInterfaceContext'],
|
|
8
|
+
implementation: getInterfaceContextImplementation,
|
|
9
|
+
hookNames,
|
|
10
|
+
};
|
|
11
|
+
const GetInterfaceContextParametersStruct = object({
|
|
12
|
+
id: string(),
|
|
13
|
+
});
|
|
14
|
+
/**
|
|
15
|
+
* The `snap_getInterfaceContext` method implementation.
|
|
16
|
+
*
|
|
17
|
+
* @param req - The JSON-RPC request object.
|
|
18
|
+
* @param res - The JSON-RPC response object.
|
|
19
|
+
* @param _next - The `json-rpc-engine` "next" callback. Not used by this
|
|
20
|
+
* function.
|
|
21
|
+
* @param end - The `json-rpc-engine` "end" callback.
|
|
22
|
+
* @param hooks - The RPC method hooks.
|
|
23
|
+
* @param hooks.getInterfaceContext - The function to get the interface context.
|
|
24
|
+
* @returns Noting.
|
|
25
|
+
*/
|
|
26
|
+
function getInterfaceContextImplementation(req, res, _next, end, { getInterfaceContext }) {
|
|
27
|
+
const { params } = req;
|
|
28
|
+
try {
|
|
29
|
+
const validatedParams = getValidatedParams(params);
|
|
30
|
+
const { id } = validatedParams;
|
|
31
|
+
res.result = getInterfaceContext(id);
|
|
32
|
+
}
|
|
33
|
+
catch (error) {
|
|
34
|
+
return end(error);
|
|
35
|
+
}
|
|
36
|
+
return end();
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Validate the getInterfaceContext method `params` and returns them cast to the correct
|
|
40
|
+
* type. Throws if validation fails.
|
|
41
|
+
*
|
|
42
|
+
* @param params - The unvalidated params object from the method request.
|
|
43
|
+
* @returns The validated getInterfaceContext method parameter object.
|
|
44
|
+
*/
|
|
45
|
+
function getValidatedParams(params) {
|
|
46
|
+
try {
|
|
47
|
+
return create(params, GetInterfaceContextParametersStruct);
|
|
48
|
+
}
|
|
49
|
+
catch (error) {
|
|
50
|
+
if (error instanceof StructError) {
|
|
51
|
+
throw rpcErrors.invalidParams({
|
|
52
|
+
message: `Invalid params: ${error.message}.`,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
/* istanbul ignore next */
|
|
56
|
+
throw rpcErrors.internal();
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=getInterfaceContext.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getInterfaceContext.mjs","sourceRoot":"","sources":["../../src/permitted/getInterfaceContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAQjD,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,8BAA8B;AAK5E,MAAM,SAAS,GAAsD;IACnE,mBAAmB,EAAE,IAAI;CAC1B,CAAC;AAUF,MAAM,CAAC,MAAM,0BAA0B,GAInC;IACF,WAAW,EAAE,CAAC,0BAA0B,CAAC;IACzC,cAAc,EAAE,iCAAiC;IACjD,SAAS;CACV,CAAC;AAEF,MAAM,mCAAmC,GAAG,MAAM,CAAC;IACjD,EAAE,EAAE,MAAM,EAAE;CACb,CAAC,CAAC;AAOH;;;;;;;;;;;GAWG;AACH,SAAS,iCAAiC,CACxC,GAAkD,EAClD,GAAsD,EACtD,KAAc,EACd,GAA6B,EAC7B,EAAE,mBAAmB,EAAkC;IAEvD,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEvB,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,EAAE,EAAE,GAAG,eAAe,CAAC;QAE/B,GAAG,CAAC,MAAM,GAAG,mBAAmB,CAAC,EAAE,CAAC,CAAC;IACvC,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,mCAAmC,CAAC,CAAC;IAC7D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n GetInterfaceContextParams,\n GetInterfaceContextResult,\n InterfaceContext,\n JsonRpcRequest,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport { StructError, create, object, string } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetInterfaceContextMethodHooks> = {\n getInterfaceContext: true,\n};\n\nexport type GetInterfaceContextMethodHooks = {\n /**\n * @param id - The interface ID.\n * @returns The interface context.\n */\n getInterfaceContext: (id: string) => InterfaceContext | null;\n};\n\nexport const getInterfaceContextHandler: PermittedHandlerExport<\n GetInterfaceContextMethodHooks,\n GetInterfaceContextParameters,\n GetInterfaceContextResult\n> = {\n methodNames: ['snap_getInterfaceContext'],\n implementation: getInterfaceContextImplementation,\n hookNames,\n};\n\nconst GetInterfaceContextParametersStruct = object({\n id: string(),\n});\n\nexport type GetInterfaceContextParameters = InferMatching<\n typeof GetInterfaceContextParametersStruct,\n GetInterfaceContextParams\n>;\n\n/**\n * The `snap_getInterfaceContext` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getInterfaceContext - The function to get the interface context.\n * @returns Noting.\n */\nfunction getInterfaceContextImplementation(\n req: JsonRpcRequest<GetInterfaceContextParameters>,\n res: PendingJsonRpcResponse<GetInterfaceContextResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getInterfaceContext }: GetInterfaceContextMethodHooks,\n): void {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id } = validatedParams;\n\n res.result = getInterfaceContext(id);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getInterfaceContext method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated getInterfaceContext method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetInterfaceContextParameters {\n try {\n return create(params, GetInterfaceContextParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -7,6 +7,7 @@ const getAllSnaps_1 = require("./getAllSnaps.cjs");
|
|
|
7
7
|
const getClientStatus_1 = require("./getClientStatus.cjs");
|
|
8
8
|
const getCurrencyRate_1 = require("./getCurrencyRate.cjs");
|
|
9
9
|
const getFile_1 = require("./getFile.cjs");
|
|
10
|
+
const getInterfaceContext_1 = require("./getInterfaceContext.cjs");
|
|
10
11
|
const getInterfaceState_1 = require("./getInterfaceState.cjs");
|
|
11
12
|
const getSnaps_1 = require("./getSnaps.cjs");
|
|
12
13
|
const invokeKeyring_1 = require("./invokeKeyring.cjs");
|
|
@@ -26,6 +27,7 @@ exports.methodHandlers = {
|
|
|
26
27
|
snap_createInterface: createInterface_1.createInterfaceHandler,
|
|
27
28
|
snap_updateInterface: updateInterface_1.updateInterfaceHandler,
|
|
28
29
|
snap_getInterfaceState: getInterfaceState_1.getInterfaceStateHandler,
|
|
30
|
+
snap_getInterfaceContext: getInterfaceContext_1.getInterfaceContextHandler,
|
|
29
31
|
snap_resolveInterface: resolveInterface_1.resolveInterfaceHandler,
|
|
30
32
|
snap_getCurrencyRate: getCurrencyRate_1.getCurrencyRateHandler,
|
|
31
33
|
snap_experimentalProviderRequest: experimentalProviderRequest_1.providerRequestHandler,
|
|
@@ -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,+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,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 { 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_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,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"]}
|
|
@@ -19,6 +19,7 @@ export declare const methodHandlers: {
|
|
|
19
19
|
contentType: string;
|
|
20
20
|
contents: string;
|
|
21
21
|
} | null> | null>>;
|
|
22
|
+
snap_getInterfaceContext: import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.cjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult>;
|
|
22
23
|
snap_resolveInterface: import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.cjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null>;
|
|
23
24
|
snap_getCurrencyRate: import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.cjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult>;
|
|
24
25
|
snap_experimentalProviderRequest: import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.cjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json>;
|
|
@@ -33,5 +34,5 @@ export declare const handlers: (import("@metamask/permission-controller").Permit
|
|
|
33
34
|
size: number;
|
|
34
35
|
contentType: string;
|
|
35
36
|
contents: string;
|
|
36
|
-
} | 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("./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>)[];
|
|
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>)[];
|
|
37
38
|
//# sourceMappingURL=handlers.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.cts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"
|
|
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"}
|
|
@@ -19,6 +19,7 @@ export declare const methodHandlers: {
|
|
|
19
19
|
contentType: string;
|
|
20
20
|
contents: string;
|
|
21
21
|
} | null> | null>>;
|
|
22
|
+
snap_getInterfaceContext: import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.mjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult>;
|
|
22
23
|
snap_resolveInterface: import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.mjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null>;
|
|
23
24
|
snap_getCurrencyRate: import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.mjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult>;
|
|
24
25
|
snap_experimentalProviderRequest: import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.mjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json>;
|
|
@@ -33,5 +34,5 @@ export declare const handlers: (import("@metamask/permission-controller").Permit
|
|
|
33
34
|
size: number;
|
|
34
35
|
contentType: string;
|
|
35
36
|
contents: string;
|
|
36
|
-
} | 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("./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>)[];
|
|
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>)[];
|
|
37
38
|
//# sourceMappingURL=handlers.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.mts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"
|
|
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"}
|
|
@@ -4,6 +4,7 @@ import { getAllSnapsHandler } from "./getAllSnaps.mjs";
|
|
|
4
4
|
import { getClientStatusHandler } from "./getClientStatus.mjs";
|
|
5
5
|
import { getCurrencyRateHandler } from "./getCurrencyRate.mjs";
|
|
6
6
|
import { getFileHandler } from "./getFile.mjs";
|
|
7
|
+
import { getInterfaceContextHandler } from "./getInterfaceContext.mjs";
|
|
7
8
|
import { getInterfaceStateHandler } from "./getInterfaceState.mjs";
|
|
8
9
|
import { getSnapsHandler } from "./getSnaps.mjs";
|
|
9
10
|
import { invokeKeyringHandler } from "./invokeKeyring.mjs";
|
|
@@ -23,6 +24,7 @@ export const methodHandlers = {
|
|
|
23
24
|
snap_createInterface: createInterfaceHandler,
|
|
24
25
|
snap_updateInterface: updateInterfaceHandler,
|
|
25
26
|
snap_getInterfaceState: getInterfaceStateHandler,
|
|
27
|
+
snap_getInterfaceContext: getInterfaceContextHandler,
|
|
26
28
|
snap_resolveInterface: resolveInterfaceHandler,
|
|
27
29
|
snap_getCurrencyRate: getCurrencyRateHandler,
|
|
28
30
|
snap_experimentalProviderRequest: providerRequestHandler,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.mjs","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,sBAAsB,EAAE,0CAAsC;AACvE,OAAO,EAAE,kBAAkB,EAAE,0BAAsB;AACnD,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,cAAc,EAAE,sBAAkB;AAC3C,OAAO,EAAE,wBAAwB,EAAE,gCAA4B;AAC/D,OAAO,EAAE,eAAe,EAAE,uBAAmB;AAC7C,OAAO,EAAE,oBAAoB,EAAE,4BAAwB;AACvD,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,mBAAmB,EAAE,2BAAuB;AACrD,OAAO,EAAE,uBAAuB,EAAE,+BAA2B;AAC7D,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAE3D,yDAAyD;AACzD,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,kBAAkB,EAAE,kBAAkB;IACtC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,mBAAmB;IACxC,iBAAiB,EAAE,sBAAsB;IACzC,oBAAoB,EAAE,oBAAoB;IAC1C,oBAAoB,EAAE,sBAAsB;IAC5C,YAAY,EAAE,cAAc;IAC5B,oBAAoB,EAAE,sBAAsB;IAC5C,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;IAChD,qBAAqB,EAAE,uBAAuB;IAC9C,oBAAoB,EAAE,sBAAsB;IAC5C,gCAAgC,EAAE,sBAAsB;CACzD,CAAC;AACF,wDAAwD;AAExD,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,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 { 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_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.mjs","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,sBAAsB,EAAE,0CAAsC;AACvE,OAAO,EAAE,kBAAkB,EAAE,0BAAsB;AACnD,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,cAAc,EAAE,sBAAkB;AAC3C,OAAO,EAAE,0BAA0B,EAAE,kCAA8B;AACnE,OAAO,EAAE,wBAAwB,EAAE,gCAA4B;AAC/D,OAAO,EAAE,eAAe,EAAE,uBAAmB;AAC7C,OAAO,EAAE,oBAAoB,EAAE,4BAAwB;AACvD,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,mBAAmB,EAAE,2BAAuB;AACrD,OAAO,EAAE,uBAAuB,EAAE,+BAA2B;AAC7D,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAE3D,yDAAyD;AACzD,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,kBAAkB,EAAE,kBAAkB;IACtC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,mBAAmB;IACxC,iBAAiB,EAAE,sBAAsB;IACzC,oBAAoB,EAAE,oBAAoB;IAC1C,oBAAoB,EAAE,sBAAsB;IAC5C,YAAY,EAAE,cAAc;IAC5B,oBAAoB,EAAE,sBAAsB;IAC5C,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;IAChD,wBAAwB,EAAE,0BAA0B;IACpD,qBAAqB,EAAE,uBAAuB;IAC9C,oBAAoB,EAAE,sBAAsB;IAC5C,gCAAgC,EAAE,sBAAsB;CACzD,CAAC;AACF,wDAAwD;AAExD,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog.cjs","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":";;;AAKA,2EAA8E;AAC9E,qDAAiD;AACjD,mDAK6B;AAW7B,uDAA+E;AAE/E,2CAAuE;AAIvE,MAAM,UAAU,GAAG,aAAa,CAAC;AAMpB,QAAA,qBAAqB,GAAG;IACnC,CAAC,sBAAU,CAAC,KAAK,CAAC,EAAE,GAAG,UAAU,QAAQ;IACzC,CAAC,sBAAU,CAAC,YAAY,CAAC,EAAE,GAAG,UAAU,eAAe;IACvD,CAAC,sBAAU,CAAC,MAAM,CAAC,EAAE,GAAG,UAAU,SAAS;IAC3C,OAAO,EAAE,UAAU;CACpB,CAAC;AAEF,MAAM,iBAAiB,GAAG,IAAA,sBAAQ,EAAC,IAAA,kBAAI,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAgE1D;;;;;;;;;;;;;GAaG;AACH,MAAM,oBAAoB,GAItB,CAAC,EAC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EAAU,EACV,YAA0B;IAE1B,IAAI,CAAC;QACH,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,MAAwB;IAC7C,OAAO,IAAA,mBAAW,EAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAE,MAAM,CAAC,IAAmB,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/E,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,MAAwB;IAC9C,OAAO,aAAa,CAAC,MAAM,CAAC,KAAK,sBAAU,CAAC,MAAM,CAAC;AACrD,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport {\n DialogType,\n enumValue,\n ComponentOrElementStruct,\n selectiveUnion,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n Component,\n InterfaceState,\n SnapId,\n PromptDialog,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { create, object, optional, size, string } from '@metamask/superstruct';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject, isPlainObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nexport type DialogApprovalTypes = Record<DialogType, string> & {\n default: string;\n};\n\nexport const DIALOG_APPROVAL_TYPES = {\n [DialogType.Alert]: `${methodName}:alert`,\n [DialogType.Confirmation]: `${methodName}:confirmation`,\n [DialogType.Prompt]: `${methodName}:prompt`,\n default: methodName,\n};\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype RequestUserApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData: {\n id: string;\n placeholder?: string;\n };\n};\n\ntype RequestUserApproval = (\n opts: RequestUserApprovalOptions,\n) => Promise<boolean | null | string | Json>;\n\ntype CreateInterface = (\n snapId: string,\n content: ComponentOrElement,\n) => Promise<string>;\n\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: ComponentOrElement; snapId: SnapId; state: InterfaceState };\n\nexport type DialogMethodHooks = {\n /**\n * @param opts - The `requestUserApproval` options.\n * @param opts.id - The approval ID. If not provided, a new approval ID will be generated.\n * @param opts.origin - The origin of the request. In this case, the Snap ID.\n * @param opts.type - The type of the approval request.\n * @param opts.requestData - The data of the approval request.\n * @param opts.requestData.id - The ID of the interface.\n * @param opts.requestData.placeholder - The placeholder of the `Prompt` dialog.\n */\n requestUserApproval: RequestUserApproval;\n\n /**\n * @param snapId - The Snap ID creating the interface.\n * @param content - The content of the interface.\n */\n createInterface: CreateInterface;\n /**\n * @param snapId - The SnapId requesting the interface.\n * @param id - The interface ID.\n */\n getInterface: GetInterface;\n};\n\ntype DialogSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: DialogMethodHooks;\n};\n\ntype DialogSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getDialogImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_dialog` permission. `snap_dialog`\n * lets the Snap display one of the following dialogs to the user:\n * - An alert, for displaying information.\n * - A confirmation, for accepting or rejecting some action.\n * - A prompt, for inputting some information.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the\n * permission.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_dialog` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n DialogSpecificationBuilderOptions,\n DialogSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: DialogSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getDialogImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<DialogMethodHooks> = {\n requestUserApproval: true,\n createInterface: true,\n getInterface: true,\n};\n\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentOrElementStruct,\n});\n\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return AlertParametersWithIdStruct;\n }\n return AlertParametersWithContentStruct;\n});\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentOrElementStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return ConfirmationParametersWithIdStruct;\n }\n return ConfirmationParametersWithContentStruct;\n});\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentOrElementStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return PromptParametersWithIdStruct;\n }\n return PromptParametersWithContentStruct;\n});\n\nconst DefaultParametersWithContentStruct = object({\n content: ComponentOrElementStruct,\n});\n\nconst DefaultParametersWithIdStruct = object({\n id: string(),\n});\n\nconst DefaultParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return DefaultParametersWithIdStruct;\n }\n return DefaultParametersWithContentStruct;\n});\n\nconst DialogParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'type')) {\n switch (value.type) {\n // We cannot use typedUnion here unfortunately.\n case DialogType.Alert:\n return AlertParametersStruct;\n case DialogType.Confirmation:\n return ConfirmationParametersStruct;\n case DialogType.Prompt:\n return PromptParametersStruct;\n default:\n throw new Error(\n `The \"type\" property must be one of: ${Object.values(DialogType).join(\n ', ',\n )}.`,\n );\n }\n }\n return DefaultParametersStruct;\n});\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.\n * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.\n * @returns The method implementation which return value depends on the dialog\n * type, valid return types are: string, boolean, null.\n */\nexport function getDialogImplementation({\n requestUserApproval,\n createInterface,\n getInterface,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<boolean | null | string | Json> {\n const {\n params,\n context: { origin },\n } = args;\n\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Invalid params: Expected params to be a single object.',\n });\n }\n\n const validatedParams = getValidatedParams(params);\n const placeholder = isPromptDialog(validatedParams)\n ? validatedParams.placeholder\n : undefined;\n\n const validatedType = hasProperty(validatedParams, 'type')\n ? validatedParams.type\n : 'default';\n\n const approvalType =\n DIALOG_APPROVAL_TYPES[\n validatedType as keyof typeof DIALOG_APPROVAL_TYPES\n ];\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as Component,\n );\n\n return requestUserApproval({\n id: approvalType === DIALOG_APPROVAL_TYPES.default ? id : undefined,\n origin,\n type: approvalType,\n requestData: { id, placeholder },\n });\n }\n\n validateInterface(origin, validatedParams.id, getInterface);\n\n return requestUserApproval({\n id:\n approvalType === DIALOG_APPROVAL_TYPES.default\n ? validatedParams.id\n : undefined,\n origin,\n type: approvalType,\n requestData: { id: validatedParams.id, placeholder },\n });\n };\n}\n/**\n * Validate that the interface ID is valid.\n *\n * @param origin - The origin of the request.\n * @param id - The interface ID.\n * @param getInterface - The function to get the interface.\n */\nfunction validateInterface(\n origin: string,\n id: string,\n getInterface: GetInterface,\n) {\n try {\n getInterface(origin, id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n\n/**\n * Gets the dialog type from the dialog parameters.\n *\n * @param params - The dialog parameters.\n * @returns The dialog type.\n */\nfunction getDialogType(params: DialogParameters): DialogType | undefined {\n return hasProperty(params, 'type') ? (params.type as DialogType) : undefined;\n}\n\n/**\n * Checks if the dialog parameters are for a prompt dialog.\n *\n * @param params - The dialog parameters.\n * @returns `true` if the dialog parameters are for a prompt dialog, `false` otherwise.\n */\nfunction isPromptDialog(params: DialogParameters): params is PromptDialog {\n return getDialogType(params) === DialogType.Prompt;\n}\n\n/**\n * Validates the confirm method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated confirm method parameter object.\n */\nfunction getValidatedParams(params: unknown): DialogParameters {\n try {\n return create(params, DialogParametersStruct);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dialog.cjs","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":";;;AAKA,2EAA8E;AAC9E,qDAAiD;AACjD,mDAK6B;AAa7B,uDAA+E;AAE/E,2CAAuE;AAIvE,MAAM,UAAU,GAAG,aAAa,CAAC;AAMpB,QAAA,qBAAqB,GAAG;IACnC,CAAC,sBAAU,CAAC,KAAK,CAAC,EAAE,GAAG,UAAU,QAAQ;IACzC,CAAC,sBAAU,CAAC,YAAY,CAAC,EAAE,GAAG,UAAU,eAAe;IACvD,CAAC,sBAAU,CAAC,MAAM,CAAC,EAAE,GAAG,UAAU,SAAS;IAC3C,OAAO,EAAE,UAAU;CACpB,CAAC;AAEF,MAAM,iBAAiB,GAAG,IAAA,sBAAQ,EAAC,IAAA,kBAAI,EAAC,IAAA,oBAAM,GAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;AAkE1D;;;;;;;;;;;;;GAaG;AACH,MAAM,oBAAoB,GAItB,CAAC,EACH,cAAc,GAAG,IAAI,EACrB,WAAW,GACuB,EAAE,EAAE;IACtC,OAAO;QACL,cAAc,EAAE,sCAAc,CAAC,gBAAgB;QAC/C,UAAU,EAAE,UAAU;QACtB,cAAc;QACd,oBAAoB,EAAE,uBAAuB,CAAC,WAAW,CAAC;QAC1D,YAAY,EAAE,CAAC,mCAAW,CAAC,IAAI,CAAC;KACjC,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,WAAW,GAAyC;IACxD,mBAAmB,EAAE,IAAI;IACzB,eAAe,EAAE,IAA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M,EAAE,MAAM,CAAC,CAAC,CAAC,CAAE,MAAM,CAAC,IAAmB,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/E,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,MAAwB;IAC9C,OAAO,aAAa,CAAC,MAAM,CAAC,KAAK,sBAAU,CAAC,MAAM,CAAC;AACrD,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,sBAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport {\n DialogType,\n enumValue,\n ComponentOrElementStruct,\n selectiveUnion,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n Component,\n InterfaceState,\n SnapId,\n PromptDialog,\n ComponentOrElement,\n InterfaceContext,\n ContentType,\n} from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { create, object, optional, size, string } from '@metamask/superstruct';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject, isPlainObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nexport type DialogApprovalTypes = Record<DialogType, string> & {\n default: string;\n};\n\nexport const DIALOG_APPROVAL_TYPES = {\n [DialogType.Alert]: `${methodName}:alert`,\n [DialogType.Confirmation]: `${methodName}:confirmation`,\n [DialogType.Prompt]: `${methodName}:prompt`,\n default: methodName,\n};\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype RequestUserApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData: {\n id: string;\n placeholder?: string;\n };\n};\n\ntype RequestUserApproval = (\n opts: RequestUserApprovalOptions,\n) => Promise<boolean | null | string | Json>;\n\ntype CreateInterface = (\n snapId: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n) => Promise<string>;\n\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: ComponentOrElement; snapId: SnapId; state: InterfaceState };\n\nexport type DialogMethodHooks = {\n /**\n * @param opts - The `requestUserApproval` options.\n * @param opts.id - The approval ID. If not provided, a new approval ID will be generated.\n * @param opts.origin - The origin of the request. In this case, the Snap ID.\n * @param opts.type - The type of the approval request.\n * @param opts.requestData - The data of the approval request.\n * @param opts.requestData.id - The ID of the interface.\n * @param opts.requestData.placeholder - The placeholder of the `Prompt` dialog.\n */\n requestUserApproval: RequestUserApproval;\n\n /**\n * @param snapId - The Snap ID creating the interface.\n * @param content - The content of the interface.\n */\n createInterface: CreateInterface;\n /**\n * @param snapId - The SnapId requesting the interface.\n * @param id - The interface ID.\n */\n getInterface: GetInterface;\n};\n\ntype DialogSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: DialogMethodHooks;\n};\n\ntype DialogSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getDialogImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_dialog` permission. `snap_dialog`\n * lets the Snap display one of the following dialogs to the user:\n * - An alert, for displaying information.\n * - A confirmation, for accepting or rejecting some action.\n * - A prompt, for inputting some information.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the\n * permission.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_dialog` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n DialogSpecificationBuilderOptions,\n DialogSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: DialogSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getDialogImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<DialogMethodHooks> = {\n requestUserApproval: true,\n createInterface: true,\n getInterface: true,\n};\n\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentOrElementStruct,\n});\n\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return AlertParametersWithIdStruct;\n }\n return AlertParametersWithContentStruct;\n});\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentOrElementStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return ConfirmationParametersWithIdStruct;\n }\n return ConfirmationParametersWithContentStruct;\n});\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentOrElementStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return PromptParametersWithIdStruct;\n }\n return PromptParametersWithContentStruct;\n});\n\nconst DefaultParametersWithContentStruct = object({\n content: ComponentOrElementStruct,\n});\n\nconst DefaultParametersWithIdStruct = object({\n id: string(),\n});\n\nconst DefaultParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return DefaultParametersWithIdStruct;\n }\n return DefaultParametersWithContentStruct;\n});\n\nconst DialogParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'type')) {\n switch (value.type) {\n // We cannot use typedUnion here unfortunately.\n case DialogType.Alert:\n return AlertParametersStruct;\n case DialogType.Confirmation:\n return ConfirmationParametersStruct;\n case DialogType.Prompt:\n return PromptParametersStruct;\n default:\n throw new Error(\n `The \"type\" property must be one of: ${Object.values(DialogType).join(\n ', ',\n )}.`,\n );\n }\n }\n return DefaultParametersStruct;\n});\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.\n * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.\n * @returns The method implementation which return value depends on the dialog\n * type, valid return types are: string, boolean, null.\n */\nexport function getDialogImplementation({\n requestUserApproval,\n createInterface,\n getInterface,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<boolean | null | string | Json> {\n const {\n params,\n context: { origin },\n } = args;\n\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Invalid params: Expected params to be a single object.',\n });\n }\n\n const validatedParams = getValidatedParams(params);\n const placeholder = isPromptDialog(validatedParams)\n ? validatedParams.placeholder\n : undefined;\n\n const validatedType = hasProperty(validatedParams, 'type')\n ? validatedParams.type\n : 'default';\n\n const approvalType =\n DIALOG_APPROVAL_TYPES[\n validatedType as keyof typeof DIALOG_APPROVAL_TYPES\n ];\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as Component,\n );\n\n return requestUserApproval({\n id: approvalType === DIALOG_APPROVAL_TYPES.default ? id : undefined,\n origin,\n type: approvalType,\n requestData: { id, placeholder },\n });\n }\n\n validateInterface(origin, validatedParams.id, getInterface);\n\n return requestUserApproval({\n id:\n approvalType === DIALOG_APPROVAL_TYPES.default\n ? validatedParams.id\n : undefined,\n origin,\n type: approvalType,\n requestData: { id: validatedParams.id, placeholder },\n });\n };\n}\n/**\n * Validate that the interface ID is valid.\n *\n * @param origin - The origin of the request.\n * @param id - The interface ID.\n * @param getInterface - The function to get the interface.\n */\nfunction validateInterface(\n origin: string,\n id: string,\n getInterface: GetInterface,\n) {\n try {\n getInterface(origin, id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n\n/**\n * Gets the dialog type from the dialog parameters.\n *\n * @param params - The dialog parameters.\n * @returns The dialog type.\n */\nfunction getDialogType(params: DialogParameters): DialogType | undefined {\n return hasProperty(params, 'type') ? (params.type as DialogType) : undefined;\n}\n\n/**\n * Checks if the dialog parameters are for a prompt dialog.\n *\n * @param params - The dialog parameters.\n * @returns `true` if the dialog parameters are for a prompt dialog, `false` otherwise.\n */\nfunction isPromptDialog(params: DialogParameters): params is PromptDialog {\n return getDialogType(params) === DialogType.Prompt;\n}\n\n/**\n * Validates the confirm method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated confirm method parameter object.\n */\nfunction getValidatedParams(params: unknown): DialogParameters {\n try {\n return create(params, DialogParametersStruct);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { PermissionSpecificationBuilder, RestrictedMethodOptions } from "@metamask/permission-controller";
|
|
2
2
|
import { PermissionType } from "@metamask/permission-controller";
|
|
3
3
|
import { DialogType } from "@metamask/snaps-sdk";
|
|
4
|
-
import type { DialogParams, InterfaceState, SnapId, ComponentOrElement } from "@metamask/snaps-sdk";
|
|
4
|
+
import type { DialogParams, InterfaceState, SnapId, ComponentOrElement, InterfaceContext, ContentType } from "@metamask/snaps-sdk";
|
|
5
5
|
import type { InferMatching } from "@metamask/snaps-utils";
|
|
6
6
|
import type { Infer } from "@metamask/superstruct";
|
|
7
7
|
import type { Json, NonEmptyArray } from "@metamask/utils";
|
|
@@ -28,7 +28,7 @@ type RequestUserApprovalOptions = {
|
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
type RequestUserApproval = (opts: RequestUserApprovalOptions) => Promise<boolean | null | string | Json>;
|
|
31
|
-
type CreateInterface = (snapId: string, content: ComponentOrElement) => Promise<string>;
|
|
31
|
+
type CreateInterface = (snapId: string, content: ComponentOrElement, context?: InterfaceContext, contentType?: ContentType) => Promise<string>;
|
|
32
32
|
type GetInterface = (snapId: string, id: string) => {
|
|
33
33
|
content: ComponentOrElement;
|
|
34
34
|
snapId: SnapId;
|
|
@@ -128,23 +128,23 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
128
128
|
} | {
|
|
129
129
|
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
130
130
|
name: string;
|
|
131
|
-
/**
|
|
132
|
-
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
133
|
-
* lets the Snap display one of the following dialogs to the user:
|
|
134
|
-
* - An alert, for displaying information.
|
|
135
|
-
* - A confirmation, for accepting or rejecting some action.
|
|
136
|
-
* - A prompt, for inputting some information.
|
|
137
|
-
*
|
|
138
|
-
* @param options - The specification builder options.
|
|
139
|
-
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
140
|
-
* permission.
|
|
141
|
-
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
142
|
-
* implementation.
|
|
143
|
-
* @returns The specification for the `snap_dialog` permission.
|
|
144
|
-
*/
|
|
145
131
|
children: ({
|
|
146
132
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
147
133
|
name: string;
|
|
134
|
+
/**
|
|
135
|
+
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
136
|
+
* lets the Snap display one of the following dialogs to the user:
|
|
137
|
+
* - An alert, for displaying information.
|
|
138
|
+
* - A confirmation, for accepting or rejecting some action.
|
|
139
|
+
* - A prompt, for inputting some information.
|
|
140
|
+
*
|
|
141
|
+
* @param options - The specification builder options.
|
|
142
|
+
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
143
|
+
* permission.
|
|
144
|
+
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
145
|
+
* implementation.
|
|
146
|
+
* @returns The specification for the `snap_dialog` permission.
|
|
147
|
+
*/
|
|
148
148
|
error?: string | undefined;
|
|
149
149
|
inputType?: "number" | "text" | "password" | undefined;
|
|
150
150
|
value?: string | undefined;
|
|
@@ -229,23 +229,23 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
229
229
|
} | {
|
|
230
230
|
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
231
231
|
name: string;
|
|
232
|
-
/**
|
|
233
|
-
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
234
|
-
* lets the Snap display one of the following dialogs to the user:
|
|
235
|
-
* - An alert, for displaying information.
|
|
236
|
-
* - A confirmation, for accepting or rejecting some action.
|
|
237
|
-
* - A prompt, for inputting some information.
|
|
238
|
-
*
|
|
239
|
-
* @param options - The specification builder options.
|
|
240
|
-
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
241
|
-
* permission.
|
|
242
|
-
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
243
|
-
* implementation.
|
|
244
|
-
* @returns The specification for the `snap_dialog` permission.
|
|
245
|
-
*/
|
|
246
232
|
children: ({
|
|
247
233
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
248
234
|
name: string;
|
|
235
|
+
/**
|
|
236
|
+
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
237
|
+
* lets the Snap display one of the following dialogs to the user:
|
|
238
|
+
* - An alert, for displaying information.
|
|
239
|
+
* - A confirmation, for accepting or rejecting some action.
|
|
240
|
+
* - A prompt, for inputting some information.
|
|
241
|
+
*
|
|
242
|
+
* @param options - The specification builder options.
|
|
243
|
+
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
244
|
+
* permission.
|
|
245
|
+
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
246
|
+
* implementation.
|
|
247
|
+
* @returns The specification for the `snap_dialog` permission.
|
|
248
|
+
*/
|
|
249
249
|
error?: string | undefined;
|
|
250
250
|
inputType?: "number" | "text" | "password" | undefined;
|
|
251
251
|
value?: string | undefined;
|
|
@@ -331,23 +331,23 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
331
331
|
} | {
|
|
332
332
|
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
333
333
|
name: string;
|
|
334
|
-
/**
|
|
335
|
-
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
336
|
-
* lets the Snap display one of the following dialogs to the user:
|
|
337
|
-
* - An alert, for displaying information.
|
|
338
|
-
* - A confirmation, for accepting or rejecting some action.
|
|
339
|
-
* - A prompt, for inputting some information.
|
|
340
|
-
*
|
|
341
|
-
* @param options - The specification builder options.
|
|
342
|
-
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
343
|
-
* permission.
|
|
344
|
-
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
345
|
-
* implementation.
|
|
346
|
-
* @returns The specification for the `snap_dialog` permission.
|
|
347
|
-
*/
|
|
348
334
|
children: ({
|
|
349
335
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
350
336
|
name: string;
|
|
337
|
+
/**
|
|
338
|
+
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
339
|
+
* lets the Snap display one of the following dialogs to the user:
|
|
340
|
+
* - An alert, for displaying information.
|
|
341
|
+
* - A confirmation, for accepting or rejecting some action.
|
|
342
|
+
* - A prompt, for inputting some information.
|
|
343
|
+
*
|
|
344
|
+
* @param options - The specification builder options.
|
|
345
|
+
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
346
|
+
* permission.
|
|
347
|
+
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
348
|
+
* implementation.
|
|
349
|
+
* @returns The specification for the `snap_dialog` permission.
|
|
350
|
+
*/
|
|
351
351
|
error?: string | undefined;
|
|
352
352
|
inputType?: "number" | "text" | "password" | undefined;
|
|
353
353
|
value?: string | undefined;
|
|
@@ -431,23 +431,23 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
431
431
|
} | {
|
|
432
432
|
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
433
433
|
name: string;
|
|
434
|
-
/**
|
|
435
|
-
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
436
|
-
* lets the Snap display one of the following dialogs to the user:
|
|
437
|
-
* - An alert, for displaying information.
|
|
438
|
-
* - A confirmation, for accepting or rejecting some action.
|
|
439
|
-
* - A prompt, for inputting some information.
|
|
440
|
-
*
|
|
441
|
-
* @param options - The specification builder options.
|
|
442
|
-
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
443
|
-
* permission.
|
|
444
|
-
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
445
|
-
* implementation.
|
|
446
|
-
* @returns The specification for the `snap_dialog` permission.
|
|
447
|
-
*/
|
|
448
434
|
children: ({
|
|
449
435
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
450
436
|
name: string;
|
|
437
|
+
/**
|
|
438
|
+
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
439
|
+
* lets the Snap display one of the following dialogs to the user:
|
|
440
|
+
* - An alert, for displaying information.
|
|
441
|
+
* - A confirmation, for accepting or rejecting some action.
|
|
442
|
+
* - A prompt, for inputting some information.
|
|
443
|
+
*
|
|
444
|
+
* @param options - The specification builder options.
|
|
445
|
+
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
446
|
+
* permission.
|
|
447
|
+
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
448
|
+
* implementation.
|
|
449
|
+
* @returns The specification for the `snap_dialog` permission.
|
|
450
|
+
*/
|
|
451
451
|
error?: string | undefined;
|
|
452
452
|
inputType?: "number" | "text" | "password" | undefined;
|
|
453
453
|
value?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog.d.cts","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,EACL,UAAU,EAIX,4BAA4B;AAC7B,OAAO,KAAK,EACV,YAAY,EAEZ,cAAc,EACd,MAAM,EAEN,kBAAkB,
|
|
1
|
+
{"version":3,"file":"dialog.d.cts","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,EACL,UAAU,EAIX,4BAA4B;AAC7B,OAAO,KAAK,EACV,YAAY,EAEZ,cAAc,EACd,MAAM,EAEN,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACZ,4BAA4B;AAC7B,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA8B;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAG3D,OAAO,EAAE,KAAK,iBAAiB,EAAE,qBAAiB;AAElD,QAAA,MAAM,UAAU,gBAAgB,CA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} from "@metamask/permission-controller";
|
|
3
3
|
import { DialogType } from "@metamask/snaps-sdk";
|
|
4
|
-
import type { DialogParams, InterfaceState, SnapId, ComponentOrElement } from "@metamask/snaps-sdk";
|
|
4
|
+
import type { DialogParams, InterfaceState, SnapId, ComponentOrElement, InterfaceContext, ContentType } from "@metamask/snaps-sdk";
|
|
5
5
|
import type { InferMatching } from "@metamask/snaps-utils";
|
|
6
6
|
import type { Infer } from "@metamask/superstruct";
|
|
7
7
|
import type { Json, NonEmptyArray } from "@metamask/utils";
|
|
@@ -28,7 +28,7 @@ type RequestUserApprovalOptions = {
|
|
|
28
28
|
};
|
|
29
29
|
};
|
|
30
30
|
type RequestUserApproval = (opts: RequestUserApprovalOptions) => Promise<boolean | null | string | Json>;
|
|
31
|
-
type CreateInterface = (snapId: string, content: ComponentOrElement) => Promise<string>;
|
|
31
|
+
type CreateInterface = (snapId: string, content: ComponentOrElement, context?: InterfaceContext, contentType?: ContentType) => Promise<string>;
|
|
32
32
|
type GetInterface = (snapId: string, id: string) => {
|
|
33
33
|
content: ComponentOrElement;
|
|
34
34
|
snapId: SnapId;
|
|
@@ -128,23 +128,23 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
128
128
|
} | {
|
|
129
129
|
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
130
130
|
name: string;
|
|
131
|
-
/**
|
|
132
|
-
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
133
|
-
* lets the Snap display one of the following dialogs to the user:
|
|
134
|
-
* - An alert, for displaying information.
|
|
135
|
-
* - A confirmation, for accepting or rejecting some action.
|
|
136
|
-
* - A prompt, for inputting some information.
|
|
137
|
-
*
|
|
138
|
-
* @param options - The specification builder options.
|
|
139
|
-
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
140
|
-
* permission.
|
|
141
|
-
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
142
|
-
* implementation.
|
|
143
|
-
* @returns The specification for the `snap_dialog` permission.
|
|
144
|
-
*/
|
|
145
131
|
children: ({
|
|
146
132
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
147
133
|
name: string;
|
|
134
|
+
/**
|
|
135
|
+
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
136
|
+
* lets the Snap display one of the following dialogs to the user:
|
|
137
|
+
* - An alert, for displaying information.
|
|
138
|
+
* - A confirmation, for accepting or rejecting some action.
|
|
139
|
+
* - A prompt, for inputting some information.
|
|
140
|
+
*
|
|
141
|
+
* @param options - The specification builder options.
|
|
142
|
+
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
143
|
+
* permission.
|
|
144
|
+
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
145
|
+
* implementation.
|
|
146
|
+
* @returns The specification for the `snap_dialog` permission.
|
|
147
|
+
*/
|
|
148
148
|
error?: string | undefined;
|
|
149
149
|
inputType?: "number" | "text" | "password" | undefined;
|
|
150
150
|
value?: string | undefined;
|
|
@@ -229,23 +229,23 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
229
229
|
} | {
|
|
230
230
|
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
231
231
|
name: string;
|
|
232
|
-
/**
|
|
233
|
-
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
234
|
-
* lets the Snap display one of the following dialogs to the user:
|
|
235
|
-
* - An alert, for displaying information.
|
|
236
|
-
* - A confirmation, for accepting or rejecting some action.
|
|
237
|
-
* - A prompt, for inputting some information.
|
|
238
|
-
*
|
|
239
|
-
* @param options - The specification builder options.
|
|
240
|
-
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
241
|
-
* permission.
|
|
242
|
-
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
243
|
-
* implementation.
|
|
244
|
-
* @returns The specification for the `snap_dialog` permission.
|
|
245
|
-
*/
|
|
246
232
|
children: ({
|
|
247
233
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
248
234
|
name: string;
|
|
235
|
+
/**
|
|
236
|
+
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
237
|
+
* lets the Snap display one of the following dialogs to the user:
|
|
238
|
+
* - An alert, for displaying information.
|
|
239
|
+
* - A confirmation, for accepting or rejecting some action.
|
|
240
|
+
* - A prompt, for inputting some information.
|
|
241
|
+
*
|
|
242
|
+
* @param options - The specification builder options.
|
|
243
|
+
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
244
|
+
* permission.
|
|
245
|
+
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
246
|
+
* implementation.
|
|
247
|
+
* @returns The specification for the `snap_dialog` permission.
|
|
248
|
+
*/
|
|
249
249
|
error?: string | undefined;
|
|
250
250
|
inputType?: "number" | "text" | "password" | undefined;
|
|
251
251
|
value?: string | undefined;
|
|
@@ -331,23 +331,23 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
331
331
|
} | {
|
|
332
332
|
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
333
333
|
name: string;
|
|
334
|
-
/**
|
|
335
|
-
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
336
|
-
* lets the Snap display one of the following dialogs to the user:
|
|
337
|
-
* - An alert, for displaying information.
|
|
338
|
-
* - A confirmation, for accepting or rejecting some action.
|
|
339
|
-
* - A prompt, for inputting some information.
|
|
340
|
-
*
|
|
341
|
-
* @param options - The specification builder options.
|
|
342
|
-
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
343
|
-
* permission.
|
|
344
|
-
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
345
|
-
* implementation.
|
|
346
|
-
* @returns The specification for the `snap_dialog` permission.
|
|
347
|
-
*/
|
|
348
334
|
children: ({
|
|
349
335
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
350
336
|
name: string;
|
|
337
|
+
/**
|
|
338
|
+
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
339
|
+
* lets the Snap display one of the following dialogs to the user:
|
|
340
|
+
* - An alert, for displaying information.
|
|
341
|
+
* - A confirmation, for accepting or rejecting some action.
|
|
342
|
+
* - A prompt, for inputting some information.
|
|
343
|
+
*
|
|
344
|
+
* @param options - The specification builder options.
|
|
345
|
+
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
346
|
+
* permission.
|
|
347
|
+
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
348
|
+
* implementation.
|
|
349
|
+
* @returns The specification for the `snap_dialog` permission.
|
|
350
|
+
*/
|
|
351
351
|
error?: string | undefined;
|
|
352
352
|
inputType?: "number" | "text" | "password" | undefined;
|
|
353
353
|
value?: string | undefined;
|
|
@@ -431,23 +431,23 @@ declare const DialogParametersStruct: import("@metamask/superstruct").Struct<{
|
|
|
431
431
|
} | {
|
|
432
432
|
type: import("@metamask/snaps-sdk").NodeType.Form;
|
|
433
433
|
name: string;
|
|
434
|
-
/**
|
|
435
|
-
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
436
|
-
* lets the Snap display one of the following dialogs to the user:
|
|
437
|
-
* - An alert, for displaying information.
|
|
438
|
-
* - A confirmation, for accepting or rejecting some action.
|
|
439
|
-
* - A prompt, for inputting some information.
|
|
440
|
-
*
|
|
441
|
-
* @param options - The specification builder options.
|
|
442
|
-
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
443
|
-
* permission.
|
|
444
|
-
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
445
|
-
* implementation.
|
|
446
|
-
* @returns The specification for the `snap_dialog` permission.
|
|
447
|
-
*/
|
|
448
434
|
children: ({
|
|
449
435
|
type: import("@metamask/snaps-sdk").NodeType.Input;
|
|
450
436
|
name: string;
|
|
437
|
+
/**
|
|
438
|
+
* The specification builder for the `snap_dialog` permission. `snap_dialog`
|
|
439
|
+
* lets the Snap display one of the following dialogs to the user:
|
|
440
|
+
* - An alert, for displaying information.
|
|
441
|
+
* - A confirmation, for accepting or rejecting some action.
|
|
442
|
+
* - A prompt, for inputting some information.
|
|
443
|
+
*
|
|
444
|
+
* @param options - The specification builder options.
|
|
445
|
+
* @param options.allowedCaveats - The optional allowed caveats for the
|
|
446
|
+
* permission.
|
|
447
|
+
* @param options.methodHooks - The RPC method hooks needed by the method
|
|
448
|
+
* implementation.
|
|
449
|
+
* @returns The specification for the `snap_dialog` permission.
|
|
450
|
+
*/
|
|
451
451
|
error?: string | undefined;
|
|
452
452
|
inputType?: "number" | "text" | "password" | undefined;
|
|
453
453
|
value?: string | undefined;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dialog.d.mts","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,EACL,UAAU,EAIX,4BAA4B;AAC7B,OAAO,KAAK,EACV,YAAY,EAEZ,cAAc,EACd,MAAM,EAEN,kBAAkB,
|
|
1
|
+
{"version":3,"file":"dialog.d.mts","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,8BAA8B,EAC9B,uBAAuB,EAExB,wCAAwC;AACzC,OAAO,EAAE,cAAc,EAAe,wCAAwC;AAE9E,OAAO,EACL,UAAU,EAIX,4BAA4B;AAC7B,OAAO,KAAK,EACV,YAAY,EAEZ,cAAc,EACd,MAAM,EAEN,kBAAkB,EAClB,gBAAgB,EAChB,WAAW,EACZ,4BAA4B;AAC7B,OAAO,KAAK,EAAE,aAAa,EAAE,8BAA8B;AAC3D,OAAO,KAAK,EAAE,KAAK,EAAE,8BAA8B;AAEnD,OAAO,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,wBAAwB;AAG3D,OAAO,EAAE,KAAK,iBAAiB,EAAE,qBAAiB;AAElD,QAAA,MAAM,UAAU,gBAAgB,CAAC;AAEjC,MAAM,MAAM,mBAAmB,GAAG,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,GAAG;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,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport {\n DialogType,\n enumValue,\n ComponentOrElementStruct,\n selectiveUnion,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n Component,\n InterfaceState,\n SnapId,\n PromptDialog,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { create, object, optional, size, string } from '@metamask/superstruct';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject, isPlainObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nexport type DialogApprovalTypes = Record<DialogType, string> & {\n default: string;\n};\n\nexport const DIALOG_APPROVAL_TYPES = {\n [DialogType.Alert]: `${methodName}:alert`,\n [DialogType.Confirmation]: `${methodName}:confirmation`,\n [DialogType.Prompt]: `${methodName}:prompt`,\n default: methodName,\n};\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype RequestUserApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData: {\n id: string;\n placeholder?: string;\n };\n};\n\ntype RequestUserApproval = (\n opts: RequestUserApprovalOptions,\n) => Promise<boolean | null | string | Json>;\n\ntype CreateInterface = (\n snapId: string,\n content: ComponentOrElement,\n) => Promise<string>;\n\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: ComponentOrElement; snapId: SnapId; state: InterfaceState };\n\nexport type DialogMethodHooks = {\n /**\n * @param opts - The `requestUserApproval` options.\n * @param opts.id - The approval ID. If not provided, a new approval ID will be generated.\n * @param opts.origin - The origin of the request. In this case, the Snap ID.\n * @param opts.type - The type of the approval request.\n * @param opts.requestData - The data of the approval request.\n * @param opts.requestData.id - The ID of the interface.\n * @param opts.requestData.placeholder - The placeholder of the `Prompt` dialog.\n */\n requestUserApproval: RequestUserApproval;\n\n /**\n * @param snapId - The Snap ID creating the interface.\n * @param content - The content of the interface.\n */\n createInterface: CreateInterface;\n /**\n * @param snapId - The SnapId requesting the interface.\n * @param id - The interface ID.\n */\n getInterface: GetInterface;\n};\n\ntype DialogSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: DialogMethodHooks;\n};\n\ntype DialogSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getDialogImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_dialog` permission. `snap_dialog`\n * lets the Snap display one of the following dialogs to the user:\n * - An alert, for displaying information.\n * - A confirmation, for accepting or rejecting some action.\n * - A prompt, for inputting some information.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the\n * permission.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_dialog` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n DialogSpecificationBuilderOptions,\n DialogSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: DialogSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getDialogImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<DialogMethodHooks> = {\n requestUserApproval: true,\n createInterface: true,\n getInterface: true,\n};\n\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentOrElementStruct,\n});\n\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return AlertParametersWithIdStruct;\n }\n return AlertParametersWithContentStruct;\n});\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentOrElementStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return ConfirmationParametersWithIdStruct;\n }\n return ConfirmationParametersWithContentStruct;\n});\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentOrElementStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return PromptParametersWithIdStruct;\n }\n return PromptParametersWithContentStruct;\n});\n\nconst DefaultParametersWithContentStruct = object({\n content: ComponentOrElementStruct,\n});\n\nconst DefaultParametersWithIdStruct = object({\n id: string(),\n});\n\nconst DefaultParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return DefaultParametersWithIdStruct;\n }\n return DefaultParametersWithContentStruct;\n});\n\nconst DialogParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'type')) {\n switch (value.type) {\n // We cannot use typedUnion here unfortunately.\n case DialogType.Alert:\n return AlertParametersStruct;\n case DialogType.Confirmation:\n return ConfirmationParametersStruct;\n case DialogType.Prompt:\n return PromptParametersStruct;\n default:\n throw new Error(\n `The \"type\" property must be one of: ${Object.values(DialogType).join(\n ', ',\n )}.`,\n );\n }\n }\n return DefaultParametersStruct;\n});\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.\n * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.\n * @returns The method implementation which return value depends on the dialog\n * type, valid return types are: string, boolean, null.\n */\nexport function getDialogImplementation({\n requestUserApproval,\n createInterface,\n getInterface,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<boolean | null | string | Json> {\n const {\n params,\n context: { origin },\n } = args;\n\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Invalid params: Expected params to be a single object.',\n });\n }\n\n const validatedParams = getValidatedParams(params);\n const placeholder = isPromptDialog(validatedParams)\n ? validatedParams.placeholder\n : undefined;\n\n const validatedType = hasProperty(validatedParams, 'type')\n ? validatedParams.type\n : 'default';\n\n const approvalType =\n DIALOG_APPROVAL_TYPES[\n validatedType as keyof typeof DIALOG_APPROVAL_TYPES\n ];\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as Component,\n );\n\n return requestUserApproval({\n id: approvalType === DIALOG_APPROVAL_TYPES.default ? id : undefined,\n origin,\n type: approvalType,\n requestData: { id, placeholder },\n });\n }\n\n validateInterface(origin, validatedParams.id, getInterface);\n\n return requestUserApproval({\n id:\n approvalType === DIALOG_APPROVAL_TYPES.default\n ? validatedParams.id\n : undefined,\n origin,\n type: approvalType,\n requestData: { id: validatedParams.id, placeholder },\n });\n };\n}\n/**\n * Validate that the interface ID is valid.\n *\n * @param origin - The origin of the request.\n * @param id - The interface ID.\n * @param getInterface - The function to get the interface.\n */\nfunction validateInterface(\n origin: string,\n id: string,\n getInterface: GetInterface,\n) {\n try {\n getInterface(origin, id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n\n/**\n * Gets the dialog type from the dialog parameters.\n *\n * @param params - The dialog parameters.\n * @returns The dialog type.\n */\nfunction getDialogType(params: DialogParameters): DialogType | undefined {\n return hasProperty(params, 'type') ? (params.type as DialogType) : undefined;\n}\n\n/**\n * Checks if the dialog parameters are for a prompt dialog.\n *\n * @param params - The dialog parameters.\n * @returns `true` if the dialog parameters are for a prompt dialog, `false` otherwise.\n */\nfunction isPromptDialog(params: DialogParameters): params is PromptDialog {\n return getDialogType(params) === DialogType.Prompt;\n}\n\n/**\n * Validates the confirm method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated confirm method parameter object.\n */\nfunction getValidatedParams(params: unknown): DialogParameters {\n try {\n return create(params, DialogParametersStruct);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"dialog.mjs","sourceRoot":"","sources":["../../src/restricted/dialog.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,wCAAwC;AAC9E,OAAO,EAAE,SAAS,EAAE,6BAA6B;AACjD,OAAO,EACL,UAAU,EACV,SAAS,EACT,wBAAwB,EACxB,cAAc,EACf,4BAA4B;AAa7B,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAE,8BAA8B;AAE/E,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,wBAAwB;AAIvE,MAAM,UAAU,GAAG,aAAa,CAAC;AAMjC,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE,GAAG,UAAU,QAAQ;IACzC,CAAC,UAAU,CAAC,YAAY,CAAC,E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xB,MAAc,EACd,EAAU,EACV,YAA0B;IAE1B,IAAI,CAAC;QACH,YAAY,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;IAC3B,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;AACH,CAAC;AAED;;;;;GAKG;AACH,SAAS,aAAa,CAAC,MAAwB;IAC7C,OAAO,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAAE,MAAM,CAAC,IAAmB,CAAC,CAAC,CAAC,SAAS,CAAC;AAC/E,CAAC;AAED;;;;;GAKG;AACH,SAAS,cAAc,CAAC,MAAwB;IAC9C,OAAO,aAAa,CAAC,MAAM,CAAC,KAAK,UAAU,CAAC,MAAM,CAAC;AACrD,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,sBAAsB,CAAC,CAAC;IAChD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,SAAS,CAAC,aAAa,CAAC;YAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,EAAE;SAC5C,CAAC,CAAC;IACL,CAAC;AACH,CAAC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport {\n DialogType,\n enumValue,\n ComponentOrElementStruct,\n selectiveUnion,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n Component,\n InterfaceState,\n SnapId,\n PromptDialog,\n ComponentOrElement,\n InterfaceContext,\n ContentType,\n} from '@metamask/snaps-sdk';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport type { Infer } from '@metamask/superstruct';\nimport { create, object, optional, size, string } from '@metamask/superstruct';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { hasProperty, isObject, isPlainObject } from '@metamask/utils';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nexport type DialogApprovalTypes = Record<DialogType, string> & {\n default: string;\n};\n\nexport const DIALOG_APPROVAL_TYPES = {\n [DialogType.Alert]: `${methodName}:alert`,\n [DialogType.Confirmation]: `${methodName}:confirmation`,\n [DialogType.Prompt]: `${methodName}:prompt`,\n default: methodName,\n};\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype RequestUserApprovalOptions = {\n id?: string;\n origin: string;\n type: string;\n requestData: {\n id: string;\n placeholder?: string;\n };\n};\n\ntype RequestUserApproval = (\n opts: RequestUserApprovalOptions,\n) => Promise<boolean | null | string | Json>;\n\ntype CreateInterface = (\n snapId: string,\n content: ComponentOrElement,\n context?: InterfaceContext,\n contentType?: ContentType,\n) => Promise<string>;\n\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: ComponentOrElement; snapId: SnapId; state: InterfaceState };\n\nexport type DialogMethodHooks = {\n /**\n * @param opts - The `requestUserApproval` options.\n * @param opts.id - The approval ID. If not provided, a new approval ID will be generated.\n * @param opts.origin - The origin of the request. In this case, the Snap ID.\n * @param opts.type - The type of the approval request.\n * @param opts.requestData - The data of the approval request.\n * @param opts.requestData.id - The ID of the interface.\n * @param opts.requestData.placeholder - The placeholder of the `Prompt` dialog.\n */\n requestUserApproval: RequestUserApproval;\n\n /**\n * @param snapId - The Snap ID creating the interface.\n * @param content - The content of the interface.\n */\n createInterface: CreateInterface;\n /**\n * @param snapId - The SnapId requesting the interface.\n * @param id - The interface ID.\n */\n getInterface: GetInterface;\n};\n\ntype DialogSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: DialogMethodHooks;\n};\n\ntype DialogSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getDialogImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_dialog` permission. `snap_dialog`\n * lets the Snap display one of the following dialogs to the user:\n * - An alert, for displaying information.\n * - A confirmation, for accepting or rejecting some action.\n * - A prompt, for inputting some information.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the\n * permission.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_dialog` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n DialogSpecificationBuilderOptions,\n DialogSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: DialogSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getDialogImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<DialogMethodHooks> = {\n requestUserApproval: true,\n createInterface: true,\n getInterface: true,\n};\n\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentOrElementStruct,\n});\n\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return AlertParametersWithIdStruct;\n }\n return AlertParametersWithContentStruct;\n});\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentOrElementStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return ConfirmationParametersWithIdStruct;\n }\n return ConfirmationParametersWithContentStruct;\n});\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentOrElementStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return PromptParametersWithIdStruct;\n }\n return PromptParametersWithContentStruct;\n});\n\nconst DefaultParametersWithContentStruct = object({\n content: ComponentOrElementStruct,\n});\n\nconst DefaultParametersWithIdStruct = object({\n id: string(),\n});\n\nconst DefaultParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'id')) {\n return DefaultParametersWithIdStruct;\n }\n return DefaultParametersWithContentStruct;\n});\n\nconst DialogParametersStruct = selectiveUnion((value) => {\n if (isPlainObject(value) && hasProperty(value, 'type')) {\n switch (value.type) {\n // We cannot use typedUnion here unfortunately.\n case DialogType.Alert:\n return AlertParametersStruct;\n case DialogType.Confirmation:\n return ConfirmationParametersStruct;\n case DialogType.Prompt:\n return PromptParametersStruct;\n default:\n throw new Error(\n `The \"type\" property must be one of: ${Object.values(DialogType).join(\n ', ',\n )}.`,\n );\n }\n }\n return DefaultParametersStruct;\n});\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.requestUserApproval - A function that creates a new Approval in the ApprovalController.\n * This function should return a Promise that resolves with the appropriate value when the user has approved or rejected the request.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.\n * @returns The method implementation which return value depends on the dialog\n * type, valid return types are: string, boolean, null.\n */\nexport function getDialogImplementation({\n requestUserApproval,\n createInterface,\n getInterface,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<boolean | null | string | Json> {\n const {\n params,\n context: { origin },\n } = args;\n\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Invalid params: Expected params to be a single object.',\n });\n }\n\n const validatedParams = getValidatedParams(params);\n const placeholder = isPromptDialog(validatedParams)\n ? validatedParams.placeholder\n : undefined;\n\n const validatedType = hasProperty(validatedParams, 'type')\n ? validatedParams.type\n : 'default';\n\n const approvalType =\n DIALOG_APPROVAL_TYPES[\n validatedType as keyof typeof DIALOG_APPROVAL_TYPES\n ];\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as Component,\n );\n\n return requestUserApproval({\n id: approvalType === DIALOG_APPROVAL_TYPES.default ? id : undefined,\n origin,\n type: approvalType,\n requestData: { id, placeholder },\n });\n }\n\n validateInterface(origin, validatedParams.id, getInterface);\n\n return requestUserApproval({\n id:\n approvalType === DIALOG_APPROVAL_TYPES.default\n ? validatedParams.id\n : undefined,\n origin,\n type: approvalType,\n requestData: { id: validatedParams.id, placeholder },\n });\n };\n}\n/**\n * Validate that the interface ID is valid.\n *\n * @param origin - The origin of the request.\n * @param id - The interface ID.\n * @param getInterface - The function to get the interface.\n */\nfunction validateInterface(\n origin: string,\n id: string,\n getInterface: GetInterface,\n) {\n try {\n getInterface(origin, id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n\n/**\n * Gets the dialog type from the dialog parameters.\n *\n * @param params - The dialog parameters.\n * @returns The dialog type.\n */\nfunction getDialogType(params: DialogParameters): DialogType | undefined {\n return hasProperty(params, 'type') ? (params.type as DialogType) : undefined;\n}\n\n/**\n * Checks if the dialog parameters are for a prompt dialog.\n *\n * @param params - The dialog parameters.\n * @returns `true` if the dialog parameters are for a prompt dialog, `false` otherwise.\n */\nfunction isPromptDialog(params: DialogParameters): params is PromptDialog {\n return getDialogType(params) === DialogType.Prompt;\n}\n\n/**\n * Validates the confirm method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated confirm method parameter object.\n */\nfunction getValidatedParams(params: unknown): DialogParameters {\n try {\n return create(params, DialogParametersStruct);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-rpc-methods",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.6.0",
|
|
4
4
|
"description": "MetaMask Snaps JSON-RPC method implementations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -56,12 +56,12 @@
|
|
|
56
56
|
},
|
|
57
57
|
"dependencies": {
|
|
58
58
|
"@metamask/key-tree": "^9.1.2",
|
|
59
|
-
"@metamask/permission-controller": "^11.0.
|
|
60
|
-
"@metamask/rpc-errors": "^
|
|
61
|
-
"@metamask/snaps-sdk": "^6.
|
|
62
|
-
"@metamask/snaps-utils": "^8.
|
|
59
|
+
"@metamask/permission-controller": "^11.0.3",
|
|
60
|
+
"@metamask/rpc-errors": "^7.0.1",
|
|
61
|
+
"@metamask/snaps-sdk": "^6.12.0",
|
|
62
|
+
"@metamask/snaps-utils": "^8.6.0",
|
|
63
63
|
"@metamask/superstruct": "^3.1.0",
|
|
64
|
-
"@metamask/utils": "^
|
|
64
|
+
"@metamask/utils": "^10.0.0",
|
|
65
65
|
"@noble/hashes": "^1.3.1"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|
|
@@ -71,10 +71,10 @@
|
|
|
71
71
|
"@metamask/eslint-config-jest": "^12.1.0",
|
|
72
72
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|
|
73
73
|
"@metamask/eslint-config-typescript": "^12.1.0",
|
|
74
|
-
"@metamask/json-rpc-engine": "^
|
|
74
|
+
"@metamask/json-rpc-engine": "^10.0.1",
|
|
75
75
|
"@swc/core": "1.3.78",
|
|
76
76
|
"@swc/jest": "^0.2.26",
|
|
77
|
-
"@ts-bridge/cli": "^0.
|
|
77
|
+
"@ts-bridge/cli": "^0.6.0",
|
|
78
78
|
"@types/node": "18.14.2",
|
|
79
79
|
"@typescript-eslint/eslint-plugin": "^5.42.1",
|
|
80
80
|
"@typescript-eslint/parser": "^6.21.0",
|