@metamask/snaps-rpc-methods 13.5.3 → 14.1.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 CHANGED
@@ -7,6 +7,25 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [14.1.0]
11
+
12
+ ### Changed
13
+
14
+ - Include client and platform versions in `snap_getClientStatus` ([#3724](https://github.com/MetaMask/snaps/pull/3724))
15
+ - Bump `@metamask/permission-controller` from `12.0.0` to `12.1.0` ([#3714](https://github.com/MetaMask/snaps/pull/3714))
16
+
17
+ ## [14.0.0]
18
+
19
+ ### Changed
20
+
21
+ - **BREAKING**: `handleSnapInstall` now accepts a `messenger` parameter of type `Messenger` instead of a `messagingSystem` parameter of type `RestrictedMessenger` ([#3611](https://github.com/MetaMask/snaps/pull/3611))
22
+ - **BREAKING**: `MockControllerMessenger` now extends `Messenger` from `@metamask/messenger` instead of from `@metamask/base-controller` ([#3611](https://github.com/MetaMask/snaps/pull/3611))
23
+ - Bump `@metamask/permission-controller` from `^11.0.6` to `^12.0.0`(([#3611](https://github.com/MetaMask/snaps/pull/3611))
24
+
25
+ ### Removed
26
+
27
+ - Remove `@metamask/base-controller` dependency ([#3611](https://github.com/MetaMask/snaps/pull/3611))
28
+
10
29
  ## [13.5.3]
11
30
 
12
31
  ### Fixed
@@ -516,7 +535,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
516
535
  - The version of the package no longer needs to match the version of all other
517
536
  MetaMask Snaps packages.
518
537
 
519
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@13.5.3...HEAD
538
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@14.1.0...HEAD
539
+ [14.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@14.0.0...@metamask/snaps-rpc-methods@14.1.0
540
+ [14.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@13.5.3...@metamask/snaps-rpc-methods@14.0.0
520
541
  [13.5.3]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@13.5.2...@metamask/snaps-rpc-methods@13.5.3
521
542
  [13.5.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@13.5.1...@metamask/snaps-rpc-methods@13.5.2
522
543
  [13.5.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@13.5.0...@metamask/snaps-rpc-methods@13.5.1
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getClientStatusHandler = void 0;
4
+ const snaps_utils_1 = require("@metamask/snaps-utils");
4
5
  const hookNames = {
5
6
  getIsLocked: true,
6
7
  getIsActive: true,
8
+ getVersion: true,
7
9
  };
8
10
  /**
9
11
  * `snap_getClientStatus` returns useful information about the client running the snap.
@@ -25,10 +27,16 @@ exports.getClientStatusHandler = {
25
27
  * @param hooks - The RPC method hooks.
26
28
  * @param hooks.getIsLocked - A function that returns whether the client is locked or not.
27
29
  * @param hooks.getIsActive - A function that returns whether the client is opened or not.
30
+ * @param hooks.getVersion - A function that returns the client version.
28
31
  * @returns Nothing.
29
32
  */
30
- async function getClientStatusImplementation(_request, response, _next, end, { getIsLocked, getIsActive }) {
31
- response.result = { locked: getIsLocked(), active: getIsActive() };
33
+ async function getClientStatusImplementation(_request, response, _next, end, { getIsLocked, getIsActive, getVersion }) {
34
+ response.result = {
35
+ locked: getIsLocked(),
36
+ active: getIsActive(),
37
+ clientVersion: getVersion(),
38
+ platformVersion: (0, snaps_utils_1.getPlatformVersion)(),
39
+ };
32
40
  return end();
33
41
  }
34
42
  //# sourceMappingURL=getClientStatus.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getClientStatus.cjs","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":";;;AAWA,MAAM,SAAS,GAA4C;IACzD,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;GAEG;AACU,QAAA,sBAAsB,GAI/B;IACF,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrC,cAAc,EAAE,6BAA6B;IAC7C,SAAS;CACV,CAAC;AAcF;;;;;;;;;;;;;GAaG;AACH,KAAK,UAAU,6BAA6B,CAC1C,QAAwB,EACxB,QAAuD,EACvD,KAAc,EACd,GAA6B,EAC7B,EAAE,WAAW,EAAE,WAAW,EAAwB;IAElD,QAAQ,CAAC,MAAM,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC;IACnE,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport type { GetClientStatusResult } from '@metamask/snaps-sdk';\nimport type {\n JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetClientStatusHooks> = {\n getIsLocked: true,\n getIsActive: true,\n};\n\n/**\n * `snap_getClientStatus` returns useful information about the client running the snap.\n */\nexport const getClientStatusHandler: PermittedHandlerExport<\n GetClientStatusHooks,\n JsonRpcParams,\n GetClientStatusResult\n> = {\n methodNames: ['snap_getClientStatus'],\n implementation: getClientStatusImplementation,\n hookNames,\n};\n\nexport type GetClientStatusHooks = {\n /**\n * @returns Whether the client is locked or not.\n */\n getIsLocked: () => boolean;\n\n /**\n * @returns Whether the client is active or not.\n */\n getIsActive: () => boolean;\n};\n\n/**\n * The `snap_getClientStatus` method implementation.\n * Returns useful information about the client running the snap.\n *\n * @param _request - The JSON-RPC request object. Not used by this function.\n * @param response - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getIsLocked - A function that returns whether the client is locked or not.\n * @param hooks.getIsActive - A function that returns whether the client is opened or not.\n * @returns Nothing.\n */\nasync function getClientStatusImplementation(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<GetClientStatusResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getIsLocked, getIsActive }: GetClientStatusHooks,\n): Promise<void> {\n response.result = { locked: getIsLocked(), active: getIsActive() };\n return end();\n}\n"]}
1
+ {"version":3,"file":"getClientStatus.cjs","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":";;;AAGA,uDAA2D;AAS3D,MAAM,SAAS,GAA4C;IACzD,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,IAAI;CACjB,CAAC;AAEF;;GAEG;AACU,QAAA,sBAAsB,GAI/B;IACF,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrC,cAAc,EAAE,6BAA6B;IAC7C,SAAS;CACV,CAAC;AAmBF;;;;;;;;;;;;;;GAcG;AACH,KAAK,UAAU,6BAA6B,CAC1C,QAAwB,EACxB,QAAuD,EACvD,KAAc,EACd,GAA6B,EAC7B,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAwB;IAE9D,QAAQ,CAAC,MAAM,GAAG;QAChB,MAAM,EAAE,WAAW,EAAE;QACrB,MAAM,EAAE,WAAW,EAAE;QACrB,aAAa,EAAE,UAAU,EAAE;QAC3B,eAAe,EAAE,IAAA,gCAAkB,GAAE;KACtC,CAAC;IACF,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport type { GetClientStatusResult } from '@metamask/snaps-sdk';\nimport { getPlatformVersion } from '@metamask/snaps-utils';\nimport type {\n JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetClientStatusHooks> = {\n getIsLocked: true,\n getIsActive: true,\n getVersion: true,\n};\n\n/**\n * `snap_getClientStatus` returns useful information about the client running the snap.\n */\nexport const getClientStatusHandler: PermittedHandlerExport<\n GetClientStatusHooks,\n JsonRpcParams,\n GetClientStatusResult\n> = {\n methodNames: ['snap_getClientStatus'],\n implementation: getClientStatusImplementation,\n hookNames,\n};\n\nexport type GetClientStatusHooks = {\n /**\n * @returns Whether the client is locked or not.\n */\n getIsLocked: () => boolean;\n\n /**\n * @returns Whether the client is active or not.\n */\n getIsActive: () => boolean;\n\n /**\n * @returns The version string for the client.\n */\n getVersion: () => string;\n};\n\n/**\n * The `snap_getClientStatus` method implementation.\n * Returns useful information about the client running the snap.\n *\n * @param _request - The JSON-RPC request object. Not used by this function.\n * @param response - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getIsLocked - A function that returns whether the client is locked or not.\n * @param hooks.getIsActive - A function that returns whether the client is opened or not.\n * @param hooks.getVersion - A function that returns the client version.\n * @returns Nothing.\n */\nasync function getClientStatusImplementation(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<GetClientStatusResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getIsLocked, getIsActive, getVersion }: GetClientStatusHooks,\n): Promise<void> {\n response.result = {\n locked: getIsLocked(),\n active: getIsActive(),\n clientVersion: getVersion(),\n platformVersion: getPlatformVersion(),\n };\n return end();\n}\n"]}
@@ -14,5 +14,9 @@ export type GetClientStatusHooks = {
14
14
  * @returns Whether the client is active or not.
15
15
  */
16
16
  getIsActive: () => boolean;
17
+ /**
18
+ * @returns The version string for the client.
19
+ */
20
+ getVersion: () => string;
17
21
  };
18
22
  //# sourceMappingURL=getClientStatus.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getClientStatus.d.cts","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,4BAA4B;AACjE,OAAO,KAAK,EACV,aAAa,EAGd,wBAAwB;AASzB;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,oBAAoB,EACpB,aAAa,EACb,qBAAqB,CAKtB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC;IAE3B;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC;CAC5B,CAAC"}
1
+ {"version":3,"file":"getClientStatus.d.cts","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,4BAA4B;AAEjE,OAAO,KAAK,EACV,aAAa,EAGd,wBAAwB;AAUzB;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,oBAAoB,EACpB,aAAa,EACb,qBAAqB,CAKtB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC;IAE3B;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC;IAE3B;;OAEG;IACH,UAAU,EAAE,MAAM,MAAM,CAAC;CAC1B,CAAC"}
@@ -14,5 +14,9 @@ export type GetClientStatusHooks = {
14
14
  * @returns Whether the client is active or not.
15
15
  */
16
16
  getIsActive: () => boolean;
17
+ /**
18
+ * @returns The version string for the client.
19
+ */
20
+ getVersion: () => string;
17
21
  };
18
22
  //# sourceMappingURL=getClientStatus.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"getClientStatus.d.mts","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,4BAA4B;AACjE,OAAO,KAAK,EACV,aAAa,EAGd,wBAAwB;AASzB;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,oBAAoB,EACpB,aAAa,EACb,qBAAqB,CAKtB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC;IAE3B;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC;CAC5B,CAAC"}
1
+ {"version":3,"file":"getClientStatus.d.mts","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAC9E,OAAO,KAAK,EAAE,qBAAqB,EAAE,4BAA4B;AAEjE,OAAO,KAAK,EACV,aAAa,EAGd,wBAAwB;AAUzB;;GAEG;AACH,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,oBAAoB,EACpB,aAAa,EACb,qBAAqB,CAKtB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC;IAE3B;;OAEG;IACH,WAAW,EAAE,MAAM,OAAO,CAAC;IAE3B;;OAEG;IACH,UAAU,EAAE,MAAM,MAAM,CAAC;CAC1B,CAAC"}
@@ -1,6 +1,8 @@
1
+ import { getPlatformVersion } from "@metamask/snaps-utils";
1
2
  const hookNames = {
2
3
  getIsLocked: true,
3
4
  getIsActive: true,
5
+ getVersion: true,
4
6
  };
5
7
  /**
6
8
  * `snap_getClientStatus` returns useful information about the client running the snap.
@@ -22,10 +24,16 @@ export const getClientStatusHandler = {
22
24
  * @param hooks - The RPC method hooks.
23
25
  * @param hooks.getIsLocked - A function that returns whether the client is locked or not.
24
26
  * @param hooks.getIsActive - A function that returns whether the client is opened or not.
27
+ * @param hooks.getVersion - A function that returns the client version.
25
28
  * @returns Nothing.
26
29
  */
27
- async function getClientStatusImplementation(_request, response, _next, end, { getIsLocked, getIsActive }) {
28
- response.result = { locked: getIsLocked(), active: getIsActive() };
30
+ async function getClientStatusImplementation(_request, response, _next, end, { getIsLocked, getIsActive, getVersion }) {
31
+ response.result = {
32
+ locked: getIsLocked(),
33
+ active: getIsActive(),
34
+ clientVersion: getVersion(),
35
+ platformVersion: getPlatformVersion(),
36
+ };
29
37
  return end();
30
38
  }
31
39
  //# sourceMappingURL=getClientStatus.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"getClientStatus.mjs","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":"AAWA,MAAM,SAAS,GAA4C;IACzD,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;CAClB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAI/B;IACF,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrC,cAAc,EAAE,6BAA6B;IAC7C,SAAS;CACV,CAAC;AAcF;;;;;;;;;;;;;GAaG;AACH,KAAK,UAAU,6BAA6B,CAC1C,QAAwB,EACxB,QAAuD,EACvD,KAAc,EACd,GAA6B,EAC7B,EAAE,WAAW,EAAE,WAAW,EAAwB;IAElD,QAAQ,CAAC,MAAM,GAAG,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC;IACnE,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport type { GetClientStatusResult } from '@metamask/snaps-sdk';\nimport type {\n JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetClientStatusHooks> = {\n getIsLocked: true,\n getIsActive: true,\n};\n\n/**\n * `snap_getClientStatus` returns useful information about the client running the snap.\n */\nexport const getClientStatusHandler: PermittedHandlerExport<\n GetClientStatusHooks,\n JsonRpcParams,\n GetClientStatusResult\n> = {\n methodNames: ['snap_getClientStatus'],\n implementation: getClientStatusImplementation,\n hookNames,\n};\n\nexport type GetClientStatusHooks = {\n /**\n * @returns Whether the client is locked or not.\n */\n getIsLocked: () => boolean;\n\n /**\n * @returns Whether the client is active or not.\n */\n getIsActive: () => boolean;\n};\n\n/**\n * The `snap_getClientStatus` method implementation.\n * Returns useful information about the client running the snap.\n *\n * @param _request - The JSON-RPC request object. Not used by this function.\n * @param response - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getIsLocked - A function that returns whether the client is locked or not.\n * @param hooks.getIsActive - A function that returns whether the client is opened or not.\n * @returns Nothing.\n */\nasync function getClientStatusImplementation(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<GetClientStatusResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getIsLocked, getIsActive }: GetClientStatusHooks,\n): Promise<void> {\n response.result = { locked: getIsLocked(), active: getIsActive() };\n return end();\n}\n"]}
1
+ {"version":3,"file":"getClientStatus.mjs","sourceRoot":"","sources":["../../src/permitted/getClientStatus.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,8BAA8B;AAS3D,MAAM,SAAS,GAA4C;IACzD,WAAW,EAAE,IAAI;IACjB,WAAW,EAAE,IAAI;IACjB,UAAU,EAAE,IAAI;CACjB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,sBAAsB,GAI/B;IACF,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrC,cAAc,EAAE,6BAA6B;IAC7C,SAAS;CACV,CAAC;AAmBF;;;;;;;;;;;;;;GAcG;AACH,KAAK,UAAU,6BAA6B,CAC1C,QAAwB,EACxB,QAAuD,EACvD,KAAc,EACd,GAA6B,EAC7B,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAwB;IAE9D,QAAQ,CAAC,MAAM,GAAG;QAChB,MAAM,EAAE,WAAW,EAAE;QACrB,MAAM,EAAE,WAAW,EAAE;QACrB,aAAa,EAAE,UAAU,EAAE;QAC3B,eAAe,EAAE,kBAAkB,EAAE;KACtC,CAAC;IACF,OAAO,GAAG,EAAE,CAAC;AACf,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport type { GetClientStatusResult } from '@metamask/snaps-sdk';\nimport { getPlatformVersion } from '@metamask/snaps-utils';\nimport type {\n JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetClientStatusHooks> = {\n getIsLocked: true,\n getIsActive: true,\n getVersion: true,\n};\n\n/**\n * `snap_getClientStatus` returns useful information about the client running the snap.\n */\nexport const getClientStatusHandler: PermittedHandlerExport<\n GetClientStatusHooks,\n JsonRpcParams,\n GetClientStatusResult\n> = {\n methodNames: ['snap_getClientStatus'],\n implementation: getClientStatusImplementation,\n hookNames,\n};\n\nexport type GetClientStatusHooks = {\n /**\n * @returns Whether the client is locked or not.\n */\n getIsLocked: () => boolean;\n\n /**\n * @returns Whether the client is active or not.\n */\n getIsActive: () => boolean;\n\n /**\n * @returns The version string for the client.\n */\n getVersion: () => string;\n};\n\n/**\n * The `snap_getClientStatus` method implementation.\n * Returns useful information about the client running the snap.\n *\n * @param _request - The JSON-RPC request object. Not used by this function.\n * @param response - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getIsLocked - A function that returns whether the client is locked or not.\n * @param hooks.getIsActive - A function that returns whether the client is opened or not.\n * @param hooks.getVersion - A function that returns the client version.\n * @returns Nothing.\n */\nasync function getClientStatusImplementation(\n _request: JsonRpcRequest,\n response: PendingJsonRpcResponse<GetClientStatusResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getIsLocked, getIsActive, getVersion }: GetClientStatusHooks,\n): Promise<void> {\n response.result = {\n locked: getIsLocked(),\n active: getIsActive(),\n clientVersion: getVersion(),\n platformVersion: getPlatformVersion(),\n };\n return end();\n}\n"]}
@@ -10,20 +10,20 @@ exports.WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';
10
10
  *
11
11
  * @param params - The side-effect params.
12
12
  * @param params.requestData - The request data associated to the requested permission.
13
- * @param params.messagingSystem - The messenger to call an action.
13
+ * @param params.messenger - The messenger to call an action.
14
14
  * @returns The result of the Snap installation.
15
15
  */
16
- const handleSnapInstall = async ({ requestData, messagingSystem }) => {
16
+ const handleSnapInstall = async ({ requestData, messenger }) => {
17
17
  const snaps = requestData.permissions[exports.WALLET_SNAP_PERMISSION_KEY].caveats?.[0]
18
18
  .value;
19
- const permittedSnaps = messagingSystem.call(`SnapController:getPermitted`, requestData.metadata.origin);
19
+ const permittedSnaps = messenger.call(`SnapController:getPermitted`, requestData.metadata.origin);
20
20
  const dedupedSnaps = Object.keys(snaps).reduce((filteredSnaps, snap) => {
21
21
  if (!permittedSnaps[snap]) {
22
22
  filteredSnaps[snap] = snaps[snap];
23
23
  }
24
24
  return filteredSnaps;
25
25
  }, {});
26
- return messagingSystem.call(`SnapController:install`, requestData.metadata.origin, dedupedSnaps);
26
+ return messenger.call(`SnapController:install`, requestData.metadata.origin, dedupedSnaps);
27
27
  };
28
28
  exports.handleSnapInstall = handleSnapInstall;
29
29
  /**
@@ -1 +1 @@
1
- {"version":3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AC,EAAE,OAAO,EAAE,EAAE,EAAE;YACzB,IAAI,OAAO,EAAE,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,4BAAc,CAAC,OAAO,EAAE,CAAC;gBACxE,MAAM,sBAAS,CAAC,aAAa,CAAC;oBAC5B,OAAO,EAAE,sBAAsB,4BAAc,CAAC,OAAO,WAAW;iBACjE,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,UAAU,EAAE;YACV,WAAW,EAAE,yBAAiB;SAC/B;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,WAAW,GAA6C;IAC5D,oBAAoB,EAAE,IAAI;CAC3B,CAAC;AAEW,QAAA,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7C,UAAU,EAAE,kCAA0B;IACtC,oBAAoB;IACpB,WAAW;CACH,CAAC,CAAC;AAEZ;;;;;;;GAOG;AACH,SAAgB,2BAA2B,CAAC,EAC1C,oBAAoB,GACE;IACtB,OAAO,KAAK,UAAU,UAAU,CAC9B,OAAkD;QAElD,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAEzC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAA0B,CAAC;QAEvD,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAE3B,OAAO,CAAC,MAAM,oBAAoB,CAAC;YACjC,MAAM;YACN,MAAM;YACN,OAAO;YACP,OAAO,EAAE,yBAAW,CAAC,YAAY;SAClC,CAAC,CAAS,CAAC;IACd,CAAC,CAAC;AACJ,CAAC;AAnBD,kEAmBC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionSideEffect,\n} from '@metamask/permission-controller';\nimport { PermissionType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n InvokeSnapResult,\n RequestSnapsParams,\n RequestSnapsResult,\n} from '@metamask/snaps-sdk';\nimport type { SnapRpcHookArgs } from '@metamask/snaps-utils';\nimport { HandlerType, SnapCaveatType } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\n// Redeclare installSnaps action type to avoid circular dependencies\nexport type InstallSnaps = {\n type: `SnapController:install`;\n handler: (\n origin: string,\n requestedSnaps: RequestSnapsParams,\n ) => Promise<RequestSnapsResult>;\n};\n\nexport type GetPermittedSnaps = {\n type: `SnapController:getPermitted`;\n handler: (origin: string) => RequestSnapsResult;\n};\n\ntype AllowedActions = InstallSnaps | GetPermittedSnaps;\n\nexport type InvokeSnapMethodHooks = {\n handleSnapRpcRequest: ({\n snapId,\n origin,\n handler,\n request,\n }: SnapRpcHookArgs & { snapId: string }) => Promise<unknown>;\n};\n\ntype InvokeSnapSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: InvokeSnapMethodHooks;\n};\n\ntype InvokeSnapSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof WALLET_SNAP_PERMISSION_KEY;\n methodImplementation: ReturnType<typeof getInvokeSnapImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n sideEffect: {\n onPermitted: PermissionSideEffect<AllowedActions, never>['onPermitted'];\n };\n}>;\n\nexport type InvokeSnapParams = {\n snapId: string;\n request: Record<string, Json>;\n};\n\n/**\n * The side-effect method to handle the snap install.\n *\n * @param params - The side-effect params.\n * @param params.requestData - The request data associated to the requested permission.\n * @param params.messagingSystem - The messenger to call an action.\n * @returns The result of the Snap installation.\n */\nexport const handleSnapInstall: PermissionSideEffect<\n AllowedActions,\n never\n>['onPermitted'] = async ({ requestData, messagingSystem }) => {\n const snaps = requestData.permissions[WALLET_SNAP_PERMISSION_KEY].caveats?.[0]\n .value as RequestSnapsParams;\n\n const permittedSnaps = messagingSystem.call(\n `SnapController:getPermitted`,\n requestData.metadata.origin,\n );\n\n const dedupedSnaps = Object.keys(snaps).reduce<RequestSnapsParams>(\n (filteredSnaps, snap) => {\n if (!permittedSnaps[snap]) {\n filteredSnaps[snap] = snaps[snap];\n }\n return filteredSnaps;\n },\n {},\n );\n\n return messagingSystem.call(\n `SnapController:install`,\n requestData.metadata.origin,\n dedupedSnaps,\n );\n};\n/**\n * The specification builder for the `wallet_snap_*` permission.\n *\n * `wallet_snap_*` attempts to invoke an RPC method of the specified Snap.\n *\n * Requesting its corresponding permission will attempt to connect to the Snap,\n * and install it if it's not available yet.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `wallet_snap_*` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n InvokeSnapSpecificationBuilderOptions,\n InvokeSnapSpecification\n> = ({ methodHooks }: InvokeSnapSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: WALLET_SNAP_PERMISSION_KEY,\n allowedCaveats: [SnapCaveatType.SnapIds],\n methodImplementation: getInvokeSnapImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (caveats?.length !== 1 || caveats[0].type !== SnapCaveatType.SnapIds) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.SnapIds}\" caveat.`,\n });\n }\n },\n sideEffect: {\n onPermitted: handleSnapInstall,\n },\n };\n};\n\nconst methodHooks: MethodHooksObject<InvokeSnapMethodHooks> = {\n handleSnapRpcRequest: true,\n};\n\nexport const invokeSnapBuilder = Object.freeze({\n targetName: WALLET_SNAP_PERMISSION_KEY,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `wallet_snap_*`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.handleSnapRpcRequest - A function that sends an RPC request to a snap's RPC handler or throws if that fails.\n * @returns The method implementation which returns the result of `handleSnapRpcRequest`.\n * @throws If the params are invalid.\n */\nexport function getInvokeSnapImplementation({\n handleSnapRpcRequest,\n}: InvokeSnapMethodHooks) {\n return async function invokeSnap(\n options: RestrictedMethodOptions<InvokeSnapParams>,\n ): Promise<InvokeSnapResult> {\n const { params = {}, context } = options;\n\n const { snapId, request } = params as InvokeSnapParams;\n\n const { origin } = context;\n\n return (await handleSnapRpcRequest({\n snapId,\n origin,\n request,\n handler: HandlerType.OnRpcRequest,\n })) as Json;\n };\n}\n"]}
1
+ {"version":3,"file":"invokeSnap.cjs","sourceRoot":"","sources":["../../src/restricted/invokeSnap.ts"],"names":[],"mappings":";;;AAOA,2EAAiE;AACjE,qDAAiD;AAOjD,uDAAoE;AAKvD,QAAA,0BAA0B,GAAG,aAAa,CAAC;AAgDxD;;;;;;;GAOG;AACI,MAAM,iBAAiB,GAGX,KAAK,EAAE,EAAE,WAAW,EAAE,SAAS,EAAE,EAAE,EAAE;IACtD,MAAM,KAAK,GAAG,WAAW,CAAC,WAAW,CAAC,kCAA0B,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC;SAC3E,KAA2B,CAAC;IAE/B,MAAM,cAAc,GAAG,SAAS,CAAC,IAAI,CACnC,6BAA6B,EAC7B,WAAW,CAAC,QAAQ,CAAC,MAAM,CAC5B,CAAC;IAEF,MAAM,YAAY,GAAG,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,MAAM,CAC5C,CAAC,aAAa,EAAE,IAAI,EAAE,EAAE;QACtB,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,EAAE,CAAC;YAC1B,aAAa,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC;QACpC,CAAC;QACD,OAAO,aAAa,CAAC;IACvB,CAAC,EACD,EAAE,CACH,CAAC;IAEF,OAAO,SAAS,CAAC,IAAI,CACnB,wBAAwB,EACxB,WAAW,CA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E3B,OAAO,CAAC,MAAM,oBAAoB,CAAC;YACjC,MAAM;YACN,MAAM;YACN,OAAO;YACP,OAAO,EAAE,yBAAW,CAAC,YAAY;SAClC,CAAC,CAAS,CAAC;IACd,CAAC,CAAC;AACJ,CAAC;AAnBD,kEAmBC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionSideEffect,\n} from '@metamask/permission-controller';\nimport { PermissionType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n InvokeSnapResult,\n RequestSnapsParams,\n RequestSnapsResult,\n} from '@metamask/snaps-sdk';\nimport type { SnapRpcHookArgs } from '@metamask/snaps-utils';\nimport { HandlerType, SnapCaveatType } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\n// Redeclare installSnaps action type to avoid circular dependencies\nexport type InstallSnaps = {\n type: `SnapController:install`;\n handler: (\n origin: string,\n requestedSnaps: RequestSnapsParams,\n ) => Promise<RequestSnapsResult>;\n};\n\nexport type GetPermittedSnaps = {\n type: `SnapController:getPermitted`;\n handler: (origin: string) => RequestSnapsResult;\n};\n\ntype AllowedActions = InstallSnaps | GetPermittedSnaps;\n\nexport type InvokeSnapMethodHooks = {\n handleSnapRpcRequest: ({\n snapId,\n origin,\n handler,\n request,\n }: SnapRpcHookArgs & { snapId: string }) => Promise<unknown>;\n};\n\ntype InvokeSnapSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: InvokeSnapMethodHooks;\n};\n\ntype InvokeSnapSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof WALLET_SNAP_PERMISSION_KEY;\n methodImplementation: ReturnType<typeof getInvokeSnapImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n sideEffect: {\n onPermitted: PermissionSideEffect<AllowedActions, never>['onPermitted'];\n };\n}>;\n\nexport type InvokeSnapParams = {\n snapId: string;\n request: Record<string, Json>;\n};\n\n/**\n * The side-effect method to handle the snap install.\n *\n * @param params - The side-effect params.\n * @param params.requestData - The request data associated to the requested permission.\n * @param params.messenger - The messenger to call an action.\n * @returns The result of the Snap installation.\n */\nexport const handleSnapInstall: PermissionSideEffect<\n AllowedActions,\n never\n>['onPermitted'] = async ({ requestData, messenger }) => {\n const snaps = requestData.permissions[WALLET_SNAP_PERMISSION_KEY].caveats?.[0]\n .value as RequestSnapsParams;\n\n const permittedSnaps = messenger.call(\n `SnapController:getPermitted`,\n requestData.metadata.origin,\n );\n\n const dedupedSnaps = Object.keys(snaps).reduce<RequestSnapsParams>(\n (filteredSnaps, snap) => {\n if (!permittedSnaps[snap]) {\n filteredSnaps[snap] = snaps[snap];\n }\n return filteredSnaps;\n },\n {},\n );\n\n return messenger.call(\n `SnapController:install`,\n requestData.metadata.origin,\n dedupedSnaps,\n );\n};\n/**\n * The specification builder for the `wallet_snap_*` permission.\n *\n * `wallet_snap_*` attempts to invoke an RPC method of the specified Snap.\n *\n * Requesting its corresponding permission will attempt to connect to the Snap,\n * and install it if it's not available yet.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `wallet_snap_*` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n InvokeSnapSpecificationBuilderOptions,\n InvokeSnapSpecification\n> = ({ methodHooks }: InvokeSnapSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: WALLET_SNAP_PERMISSION_KEY,\n allowedCaveats: [SnapCaveatType.SnapIds],\n methodImplementation: getInvokeSnapImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (caveats?.length !== 1 || caveats[0].type !== SnapCaveatType.SnapIds) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.SnapIds}\" caveat.`,\n });\n }\n },\n sideEffect: {\n onPermitted: handleSnapInstall,\n },\n };\n};\n\nconst methodHooks: MethodHooksObject<InvokeSnapMethodHooks> = {\n handleSnapRpcRequest: true,\n};\n\nexport const invokeSnapBuilder = Object.freeze({\n targetName: WALLET_SNAP_PERMISSION_KEY,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `wallet_snap_*`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.handleSnapRpcRequest - A function that sends an RPC request to a snap's RPC handler or throws if that fails.\n * @returns The method implementation which returns the result of `handleSnapRpcRequest`.\n * @throws If the params are invalid.\n */\nexport function getInvokeSnapImplementation({\n handleSnapRpcRequest,\n}: InvokeSnapMethodHooks) {\n return async function invokeSnap(\n options: RestrictedMethodOptions<InvokeSnapParams>,\n ): Promise<InvokeSnapResult> {\n const { params = {}, context } = options;\n\n const { snapId, request } = params as InvokeSnapParams;\n\n const { origin } = context;\n\n return (await handleSnapRpcRequest({\n snapId,\n origin,\n request,\n handler: HandlerType.OnRpcRequest,\n })) as Json;\n };\n}\n"]}
@@ -32,7 +32,7 @@ export type InvokeSnapParams = {
32
32
  *
33
33
  * @param params - The side-effect params.
34
34
  * @param params.requestData - The request data associated to the requested permission.
35
- * @param params.messagingSystem - The messenger to call an action.
35
+ * @param params.messenger - The messenger to call an action.
36
36
  * @returns The result of the Snap installation.
37
37
  */
38
38
  export declare const handleSnapInstall: PermissionSideEffect<AllowedActions, never>['onPermitted'];
@@ -32,7 +32,7 @@ export type InvokeSnapParams = {
32
32
  *
33
33
  * @param params - The side-effect params.
34
34
  * @param params.requestData - The request data associated to the requested permission.
35
- * @param params.messagingSystem - The messenger to call an action.
35
+ * @param params.messenger - The messenger to call an action.
36
36
  * @returns The result of the Snap installation.
37
37
  */
38
38
  export declare const handleSnapInstall: PermissionSideEffect<AllowedActions, never>['onPermitted'];
@@ -7,20 +7,20 @@ export const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';
7
7
  *
8
8
  * @param params - The side-effect params.
9
9
  * @param params.requestData - The request data associated to the requested permission.
10
- * @param params.messagingSystem - The messenger to call an action.
10
+ * @param params.messenger - The messenger to call an action.
11
11
  * @returns The result of the Snap installation.
12
12
  */
13
- export const handleSnapInstall = async ({ requestData, messagingSystem }) => {
13
+ export const handleSnapInstall = async ({ requestData, messenger }) => {
14
14
  const snaps = requestData.permissions[WALLET_SNAP_PERMISSION_KEY].caveats?.[0]
15
15
  .value;
16
- const permittedSnaps = messagingSystem.call(`SnapController:getPermitted`, requestData.metadata.origin);
16
+ const permittedSnaps = messenger.call(`SnapController:getPermitted`, requestData.metadata.origin);
17
17
  const dedupedSnaps = Object.keys(snaps).reduce((filteredSnaps, snap) => {
18
18
  if (!permittedSnaps[snap]) {
19
19
  filteredSnaps[snap] = snaps[snap];
20
20
  }
21
21
  return filteredSnaps;
22
22
  }, {});
23
- return messagingSystem.call(`SnapController:install`, requestData.metadata.origin, dedupedSnaps);
23
+ return messenger.call(`SnapController:install`, requestData.metadata.origin, dedupedSnaps);
24
24
  };
25
25
  /**
26
26
  * The specification builder for the `wallet_snap_*` permission.
@@ -1 +1 @@
1
- {"version":3,"file":"invokeSnap.mjs","sourceRoot":"","sources":["../../src/restricted/invokeSnap.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,cAAc,EAAE,wCAAwC;AACjE,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAOjD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,8BAA8B;AAKpE,MAAM,CAAC,MAAM,0BAA0B,GAAG,aAAa,CAAC;AAgDxD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,iBAAiB,GAGX,KAAK,EAAE,EAAE,WAAW,EAAE,eAAe,EAAE,EAAE,EAAE;IAC5D,MAAM,KAAK,GAAG,WAAW,CAAC,WAAW,CAAC,0BAA0B,CAAC,CAAC,OAAO,EAAE,CAAC,C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GAA6C;IAC5D,oBAAoB,EAAE,IAAI;CAC3B,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7C,UAAU,EAAE,0BAA0B;IACtC,oBAAoB;IACpB,WAAW;CACH,CAAC,CAAC;AAEZ;;;;;;;GAOG;AACH,MAAM,UAAU,2BAA2B,CAAC,EAC1C,oBAAoB,GACE;IACtB,OAAO,KAAK,UAAU,UAAU,CAC9B,OAAkD;QAElD,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAEzC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAA0B,CAAC;QAEvD,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAE3B,OAAO,CAAC,MAAM,oBAAoB,CAAC;YACjC,MAAM;YACN,MAAM;YACN,OAAO;YACP,OAAO,EAAE,WAAW,CAAC,YAAY;SAClC,CAAC,CAAS,CAAC;IACd,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionSideEffect,\n} from '@metamask/permission-controller';\nimport { PermissionType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n InvokeSnapResult,\n RequestSnapsParams,\n RequestSnapsResult,\n} from '@metamask/snaps-sdk';\nimport type { SnapRpcHookArgs } from '@metamask/snaps-utils';\nimport { HandlerType, SnapCaveatType } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\n// Redeclare installSnaps action type to avoid circular dependencies\nexport type InstallSnaps = {\n type: `SnapController:install`;\n handler: (\n origin: string,\n requestedSnaps: RequestSnapsParams,\n ) => Promise<RequestSnapsResult>;\n};\n\nexport type GetPermittedSnaps = {\n type: `SnapController:getPermitted`;\n handler: (origin: string) => RequestSnapsResult;\n};\n\ntype AllowedActions = InstallSnaps | GetPermittedSnaps;\n\nexport type InvokeSnapMethodHooks = {\n handleSnapRpcRequest: ({\n snapId,\n origin,\n handler,\n request,\n }: SnapRpcHookArgs & { snapId: string }) => Promise<unknown>;\n};\n\ntype InvokeSnapSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: InvokeSnapMethodHooks;\n};\n\ntype InvokeSnapSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof WALLET_SNAP_PERMISSION_KEY;\n methodImplementation: ReturnType<typeof getInvokeSnapImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n sideEffect: {\n onPermitted: PermissionSideEffect<AllowedActions, never>['onPermitted'];\n };\n}>;\n\nexport type InvokeSnapParams = {\n snapId: string;\n request: Record<string, Json>;\n};\n\n/**\n * The side-effect method to handle the snap install.\n *\n * @param params - The side-effect params.\n * @param params.requestData - The request data associated to the requested permission.\n * @param params.messagingSystem - The messenger to call an action.\n * @returns The result of the Snap installation.\n */\nexport const handleSnapInstall: PermissionSideEffect<\n AllowedActions,\n never\n>['onPermitted'] = async ({ requestData, messagingSystem }) => {\n const snaps = requestData.permissions[WALLET_SNAP_PERMISSION_KEY].caveats?.[0]\n .value as RequestSnapsParams;\n\n const permittedSnaps = messagingSystem.call(\n `SnapController:getPermitted`,\n requestData.metadata.origin,\n );\n\n const dedupedSnaps = Object.keys(snaps).reduce<RequestSnapsParams>(\n (filteredSnaps, snap) => {\n if (!permittedSnaps[snap]) {\n filteredSnaps[snap] = snaps[snap];\n }\n return filteredSnaps;\n },\n {},\n );\n\n return messagingSystem.call(\n `SnapController:install`,\n requestData.metadata.origin,\n dedupedSnaps,\n );\n};\n/**\n * The specification builder for the `wallet_snap_*` permission.\n *\n * `wallet_snap_*` attempts to invoke an RPC method of the specified Snap.\n *\n * Requesting its corresponding permission will attempt to connect to the Snap,\n * and install it if it's not available yet.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `wallet_snap_*` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n InvokeSnapSpecificationBuilderOptions,\n InvokeSnapSpecification\n> = ({ methodHooks }: InvokeSnapSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: WALLET_SNAP_PERMISSION_KEY,\n allowedCaveats: [SnapCaveatType.SnapIds],\n methodImplementation: getInvokeSnapImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (caveats?.length !== 1 || caveats[0].type !== SnapCaveatType.SnapIds) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.SnapIds}\" caveat.`,\n });\n }\n },\n sideEffect: {\n onPermitted: handleSnapInstall,\n },\n };\n};\n\nconst methodHooks: MethodHooksObject<InvokeSnapMethodHooks> = {\n handleSnapRpcRequest: true,\n};\n\nexport const invokeSnapBuilder = Object.freeze({\n targetName: WALLET_SNAP_PERMISSION_KEY,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `wallet_snap_*`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.handleSnapRpcRequest - A function that sends an RPC request to a snap's RPC handler or throws if that fails.\n * @returns The method implementation which returns the result of `handleSnapRpcRequest`.\n * @throws If the params are invalid.\n */\nexport function getInvokeSnapImplementation({\n handleSnapRpcRequest,\n}: InvokeSnapMethodHooks) {\n return async function invokeSnap(\n options: RestrictedMethodOptions<InvokeSnapParams>,\n ): Promise<InvokeSnapResult> {\n const { params = {}, context } = options;\n\n const { snapId, request } = params as InvokeSnapParams;\n\n const { origin } = context;\n\n return (await handleSnapRpcRequest({\n snapId,\n origin,\n request,\n handler: HandlerType.OnRpcRequest,\n })) as Json;\n };\n}\n"]}
1
+ {"version":3,"file":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xC,oBAAoB,EAAE,2BAA2B,CAAC,WAAW,CAAC;QAC9D,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;YACzB,IAAI,OAAO,EAAE,MAAM,KAAK,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,cAAc,CAAC,OAAO,EAAE,CAAC;gBACxE,MAAM,SAAS,CAAC,aAAa,CAAC;oBAC5B,OAAO,EAAE,sBAAsB,cAAc,CAAC,OAAO,WAAW;iBACjE,CAAC,CAAC;YACL,CAAC;QACH,CAAC;QACD,UAAU,EAAE;YACV,WAAW,EAAE,iBAAiB;SAC/B;KACF,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,WAAW,GAA6C;IAC5D,oBAAoB,EAAE,IAAI;CAC3B,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC;IAC7C,UAAU,EAAE,0BAA0B;IACtC,oBAAoB;IACpB,WAAW;CACH,CAAC,CAAC;AAEZ;;;;;;;GAOG;AACH,MAAM,UAAU,2BAA2B,CAAC,EAC1C,oBAAoB,GACE;IACtB,OAAO,KAAK,UAAU,UAAU,CAC9B,OAAkD;QAElD,MAAM,EAAE,MAAM,GAAG,EAAE,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;QAEzC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,MAA0B,CAAC;QAEvD,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;QAE3B,OAAO,CAAC,MAAM,oBAAoB,CAAC;YACjC,MAAM;YACN,MAAM;YACN,OAAO;YACP,OAAO,EAAE,WAAW,CAAC,YAAY;SAClC,CAAC,CAAS,CAAC;IACd,CAAC,CAAC;AACJ,CAAC","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n PermissionValidatorConstraint,\n PermissionSideEffect,\n} from '@metamask/permission-controller';\nimport { PermissionType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n InvokeSnapResult,\n RequestSnapsParams,\n RequestSnapsResult,\n} from '@metamask/snaps-sdk';\nimport type { SnapRpcHookArgs } from '@metamask/snaps-utils';\nimport { HandlerType, SnapCaveatType } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nexport const WALLET_SNAP_PERMISSION_KEY = 'wallet_snap';\n\n// Redeclare installSnaps action type to avoid circular dependencies\nexport type InstallSnaps = {\n type: `SnapController:install`;\n handler: (\n origin: string,\n requestedSnaps: RequestSnapsParams,\n ) => Promise<RequestSnapsResult>;\n};\n\nexport type GetPermittedSnaps = {\n type: `SnapController:getPermitted`;\n handler: (origin: string) => RequestSnapsResult;\n};\n\ntype AllowedActions = InstallSnaps | GetPermittedSnaps;\n\nexport type InvokeSnapMethodHooks = {\n handleSnapRpcRequest: ({\n snapId,\n origin,\n handler,\n request,\n }: SnapRpcHookArgs & { snapId: string }) => Promise<unknown>;\n};\n\ntype InvokeSnapSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: InvokeSnapMethodHooks;\n};\n\ntype InvokeSnapSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof WALLET_SNAP_PERMISSION_KEY;\n methodImplementation: ReturnType<typeof getInvokeSnapImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n validator: PermissionValidatorConstraint;\n sideEffect: {\n onPermitted: PermissionSideEffect<AllowedActions, never>['onPermitted'];\n };\n}>;\n\nexport type InvokeSnapParams = {\n snapId: string;\n request: Record<string, Json>;\n};\n\n/**\n * The side-effect method to handle the snap install.\n *\n * @param params - The side-effect params.\n * @param params.requestData - The request data associated to the requested permission.\n * @param params.messenger - The messenger to call an action.\n * @returns The result of the Snap installation.\n */\nexport const handleSnapInstall: PermissionSideEffect<\n AllowedActions,\n never\n>['onPermitted'] = async ({ requestData, messenger }) => {\n const snaps = requestData.permissions[WALLET_SNAP_PERMISSION_KEY].caveats?.[0]\n .value as RequestSnapsParams;\n\n const permittedSnaps = messenger.call(\n `SnapController:getPermitted`,\n requestData.metadata.origin,\n );\n\n const dedupedSnaps = Object.keys(snaps).reduce<RequestSnapsParams>(\n (filteredSnaps, snap) => {\n if (!permittedSnaps[snap]) {\n filteredSnaps[snap] = snaps[snap];\n }\n return filteredSnaps;\n },\n {},\n );\n\n return messenger.call(\n `SnapController:install`,\n requestData.metadata.origin,\n dedupedSnaps,\n );\n};\n/**\n * The specification builder for the `wallet_snap_*` permission.\n *\n * `wallet_snap_*` attempts to invoke an RPC method of the specified Snap.\n *\n * Requesting its corresponding permission will attempt to connect to the Snap,\n * and install it if it's not available yet.\n *\n * @param options - The specification builder options.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `wallet_snap_*` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n InvokeSnapSpecificationBuilderOptions,\n InvokeSnapSpecification\n> = ({ methodHooks }: InvokeSnapSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: WALLET_SNAP_PERMISSION_KEY,\n allowedCaveats: [SnapCaveatType.SnapIds],\n methodImplementation: getInvokeSnapImplementation(methodHooks),\n validator: ({ caveats }) => {\n if (caveats?.length !== 1 || caveats[0].type !== SnapCaveatType.SnapIds) {\n throw rpcErrors.invalidParams({\n message: `Expected a single \"${SnapCaveatType.SnapIds}\" caveat.`,\n });\n }\n },\n sideEffect: {\n onPermitted: handleSnapInstall,\n },\n };\n};\n\nconst methodHooks: MethodHooksObject<InvokeSnapMethodHooks> = {\n handleSnapRpcRequest: true,\n};\n\nexport const invokeSnapBuilder = Object.freeze({\n targetName: WALLET_SNAP_PERMISSION_KEY,\n specificationBuilder,\n methodHooks,\n} as const);\n\n/**\n * Builds the method implementation for `wallet_snap_*`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.handleSnapRpcRequest - A function that sends an RPC request to a snap's RPC handler or throws if that fails.\n * @returns The method implementation which returns the result of `handleSnapRpcRequest`.\n * @throws If the params are invalid.\n */\nexport function getInvokeSnapImplementation({\n handleSnapRpcRequest,\n}: InvokeSnapMethodHooks) {\n return async function invokeSnap(\n options: RestrictedMethodOptions<InvokeSnapParams>,\n ): Promise<InvokeSnapResult> {\n const { params = {}, context } = options;\n\n const { snapId, request } = params as InvokeSnapParams;\n\n const { origin } = context;\n\n return (await handleSnapRpcRequest({\n snapId,\n origin,\n request,\n handler: HandlerType.OnRpcRequest,\n })) as Json;\n };\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/snaps-rpc-methods",
3
- "version": "13.5.3",
3
+ "version": "14.1.0",
4
4
  "description": "MetaMask Snaps JSON-RPC method implementations",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -56,10 +56,10 @@
56
56
  },
57
57
  "dependencies": {
58
58
  "@metamask/key-tree": "^10.1.1",
59
- "@metamask/permission-controller": "^11.0.6",
59
+ "@metamask/permission-controller": "^12.1.0",
60
60
  "@metamask/rpc-errors": "^7.0.3",
61
- "@metamask/snaps-sdk": "^10.0.0",
62
- "@metamask/snaps-utils": "^11.6.0",
61
+ "@metamask/snaps-sdk": "^10.1.0",
62
+ "@metamask/snaps-utils": "^11.6.1",
63
63
  "@metamask/superstruct": "^3.2.1",
64
64
  "@metamask/utils": "^11.8.1",
65
65
  "@noble/hashes": "^1.7.1"
@@ -68,6 +68,7 @@
68
68
  "@lavamoat/allow-scripts": "^3.4.0",
69
69
  "@metamask/auto-changelog": "^5.0.2",
70
70
  "@metamask/json-rpc-engine": "^10.1.0",
71
+ "@metamask/messenger": "^0.3.0",
71
72
  "@swc/core": "1.11.31",
72
73
  "@swc/jest": "^0.2.38",
73
74
  "@ts-bridge/cli": "^0.6.1",