@metamask-previews/multichain-api-middleware 2.0.0-preview-45a82ea8e → 2.0.0-preview-d8ff44d

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. package/CHANGELOG.md +1 -4
  2. package/dist/handlers/wallet-createSession.cjs +4 -6
  3. package/dist/handlers/wallet-createSession.cjs.map +1 -1
  4. package/dist/handlers/wallet-createSession.d.cts +27 -44
  5. package/dist/handlers/wallet-createSession.d.cts.map +1 -1
  6. package/dist/handlers/wallet-createSession.d.mts +27 -44
  7. package/dist/handlers/wallet-createSession.d.mts.map +1 -1
  8. package/dist/handlers/wallet-createSession.mjs +3 -5
  9. package/dist/handlers/wallet-createSession.mjs.map +1 -1
  10. package/dist/handlers/wallet-getSession.cjs +4 -6
  11. package/dist/handlers/wallet-getSession.cjs.map +1 -1
  12. package/dist/handlers/wallet-getSession.d.cts +15 -26
  13. package/dist/handlers/wallet-getSession.d.cts.map +1 -1
  14. package/dist/handlers/wallet-getSession.d.mts +15 -26
  15. package/dist/handlers/wallet-getSession.d.mts.map +1 -1
  16. package/dist/handlers/wallet-getSession.mjs +3 -5
  17. package/dist/handlers/wallet-getSession.mjs.map +1 -1
  18. package/dist/handlers/wallet-invokeMethod.cjs +4 -9
  19. package/dist/handlers/wallet-invokeMethod.cjs.map +1 -1
  20. package/dist/handlers/wallet-invokeMethod.d.cts +25 -39
  21. package/dist/handlers/wallet-invokeMethod.d.cts.map +1 -1
  22. package/dist/handlers/wallet-invokeMethod.d.mts +25 -39
  23. package/dist/handlers/wallet-invokeMethod.d.mts.map +1 -1
  24. package/dist/handlers/wallet-invokeMethod.mjs +4 -9
  25. package/dist/handlers/wallet-invokeMethod.mjs.map +1 -1
  26. package/dist/handlers/wallet-revokeSession.cjs +4 -6
  27. package/dist/handlers/wallet-revokeSession.cjs.map +1 -1
  28. package/dist/handlers/wallet-revokeSession.d.cts +12 -21
  29. package/dist/handlers/wallet-revokeSession.d.cts.map +1 -1
  30. package/dist/handlers/wallet-revokeSession.d.mts +12 -21
  31. package/dist/handlers/wallet-revokeSession.d.mts.map +1 -1
  32. package/dist/handlers/wallet-revokeSession.mjs +3 -5
  33. package/dist/handlers/wallet-revokeSession.mjs.map +1 -1
  34. package/dist/index.cjs +9 -3
  35. package/dist/index.cjs.map +1 -1
  36. package/dist/index.d.cts +4 -1
  37. package/dist/index.d.cts.map +1 -1
  38. package/dist/index.d.mts +4 -1
  39. package/dist/index.d.mts.map +1 -1
  40. package/dist/index.mjs +4 -1
  41. package/dist/index.mjs.map +1 -1
  42. package/package.json +2 -2
  43. package/dist/handlers/index.cjs +0 -14
  44. package/dist/handlers/index.cjs.map +0 -1
  45. package/dist/handlers/index.d.cts +0 -8
  46. package/dist/handlers/index.d.cts.map +0 -1
  47. package/dist/handlers/index.d.mts +0 -8
  48. package/dist/handlers/index.d.mts.map +0 -1
  49. package/dist/handlers/index.mjs +0 -11
  50. package/dist/handlers/index.mjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-getSession.d.mts","sourceRoot":"","sources":["../../src/handlers/wallet-getSession.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,sBAAsB,EACvB,4CAA4C;AAC7C,OAAO,EACL,gBAAgB,EAGjB,4CAA4C;AAC7C,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAE1B,kCAAkC;AACnC,OAAO,KAAK,EAAE,MAAM,EAAE,wCAAwC;AAC9D,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EAEX,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,KAAK,sBAAsB,GAAG;IAAE,aAAa,EAAE,sBAAsB,CAAA;CAAE,CAAC;AAExE,KAAK,qBAAqB,GAAG;IAC3B,kBAAkB,EAAE,CAClB,uBAAuB,EAAE,MAAM,EAC/B,UAAU,EAAE,MAAM,KACf,MAAM,CAAC,OAAO,gBAAgB,EAAE,iBAAiB,CA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gBAAgB,EAAE,iBAAiB,CAAC,CAAC;IACxD,yBAAyB,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,EAAE,CAAC;IAC5D,4BAA4B,EAAE,CAC5B,QAAQ,EAAE,aAAa,EAAE,KACtB,aAAa,EAAE,CAAC;CACtB,iBAwBF;AAED,eAAO,MAAM,gBAAgB;;;;;;;;CAQ5B,CAAC"}
@@ -15,7 +15,7 @@ import { Caip25CaveatType, Caip25EndowmentPermissionName, getSessionScopes } fro
15
15
  * @param hooks.sortAccountIdsByLastSelected - A function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by corresponding last selected account in the wallet.
16
16
  * @returns Nothing.
17
17
  */
18
- async function handleWalletGetSession(_request, response, _next, end, hooks) {
18
+ async function walletGetSessionHandler(_request, response, _next, end, hooks) {
19
19
  let caveat;
20
20
  try {
21
21
  caveat = hooks.getCaveatForOrigin(Caip25EndowmentPermissionName, Caip25CaveatType);
@@ -36,14 +36,12 @@ async function handleWalletGetSession(_request, response, _next, end, hooks) {
36
36
  return end();
37
37
  }
38
38
  export const walletGetSession = {
39
- implementation: handleWalletGetSession,
39
+ methodNames: ['wallet_getSession'],
40
+ implementation: walletGetSessionHandler,
40
41
  hookNames: {
41
42
  getCaveatForOrigin: true,
42
43
  getNonEvmSupportedMethods: true,
43
44
  sortAccountIdsByLastSelected: true,
44
45
  },
45
46
  };
46
- export const walletGetSessionHandler = {
47
- wallet_getSession: walletGetSession,
48
- };
49
47
  //# sourceMappingURL=wallet-getSession.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-getSession.mjs","sourceRoot":"","sources":["../../src/handlers/wallet-getSession.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC7B,gBAAgB,EACjB,4CAA4C;AA0B7C;;;;;;;;;;;;;;;GAeG;AACH,KAAK,UAAU,sBAAsB,CACnC,QAA6C,EAC7C,QAAwD,EACxD,KAAgC,EAChC,GAA6B,EAC7B,KAA4B;IAE5B,IAAI,MAAM,CAAC;IACX,IAAI,CAAC;QACH,MAAM,GAAG,KAAK,CAAC,kBAAkB,CAC/B,6BAA6B,EAC7B,gBAAgB,CACjB,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;IACT,CAAC;IAED,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,QAAQ,CAAC,MAAM,GAAG,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC;QACxC,OAAO,GAAG,EAAE,CAAC;IACf,CAAC;IAED,QAAQ,CAAC,MAAM,GAAG;QAChB,aAAa,EAAE,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE;YAC5C,yBAAyB,EAAE,KAAK,CAAC,yBAAyB;YAC1D,4BAA4B,EAAE,KAAK,CAAC,4BAA4B;SACjE,CAAC;KACH,CAAC;IACF,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAUD,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,cAAc,EAAE,sBAAsB;IACtC,SAAS,EAAE;QACT,kBAAkB,EAAE,IAAI;QACxB,yBAAyB,EAAE,IAAI;QAC/B,4BAA4B,EAAE,IAAI;KACnC;CACsC,CAAC;AAE1C,MAAM,CAAC,MAAM,uBAAuB,GAAG;IACrC,iBAAiB,EAAE,gBAAgB;CACpC,CAAC","sourcesContent":["import type {\n Caip25CaveatValue,\n NormalizedScopesObject,\n} from '@metamask/chain-agnostic-permission';\nimport {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n getSessionScopes,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type { Caveat } from '@metamask/permission-controller';\nimport type {\n CaipAccountId,\n CaipChainId,\n JsonRpcParams,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\ntype WalletGetSessionResult = { sessionScopes: NormalizedScopesObject };\n\ntype WalletGetSessionHooks = {\n getCaveatForOrigin: (\n endowmentPermissionName: string,\n caveatType: string,\n ) => Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];\n};\n\n/**\n * Handler for the `wallet_getSession` RPC method as specified by [CAIP-312](https://chainagnostic.org/CAIPs/caip-312).\n * The implementation below deviates from the linked spec in that it ignores the `sessionId` param entirely,\n * and that an empty object is returned for the `sessionScopes` result rather than throwing an error if there\n * is no active session for the origin.\n *\n * @param _request - The request object.\n * @param response - The response object.\n * @param _next - The next middleware function. Unused.\n * @param end - The end function.\n * @param hooks - The hooks object.\n * @param hooks.getCaveatForOrigin - Function to retrieve a caveat for the origin.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @param hooks.sortAccountIdsByLastSelected - A function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by corresponding last selected account in the wallet.\n * @returns Nothing.\n */\nasync function handleWalletGetSession(\n _request: JsonRpcRequest & { origin: string },\n response: PendingJsonRpcResponse<WalletGetSessionResult>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: WalletGetSessionHooks,\n) {\n let caveat;\n try {\n caveat = hooks.getCaveatForOrigin(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n );\n } catch {\n // noop\n }\n\n if (!caveat) {\n response.result = { sessionScopes: {} };\n return end();\n }\n\n response.result = {\n sessionScopes: getSessionScopes(caveat.value, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,\n }),\n };\n return end();\n}\n\ntype WalletGetSessionMethodHandler = MethodHandler<\n WalletGetSessionHooks,\n never,\n JsonRpcParams,\n WalletGetSessionResult,\n { origin: string }\n>;\n\nexport const walletGetSession = {\n implementation: handleWalletGetSession,\n hookNames: {\n getCaveatForOrigin: true,\n getNonEvmSupportedMethods: true,\n sortAccountIdsByLastSelected: true,\n },\n} satisfies WalletGetSessionMethodHandler;\n\nexport const walletGetSessionHandler = {\n wallet_getSession: walletGetSession,\n};\n"]}
1
+ {"version":3,"file":"wallet-getSession.mjs","sourceRoot":"","sources":["../../src/handlers/wallet-getSession.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC7B,gBAAgB,EACjB,4CAA4C;AAS7C;;;;;;;;;;;;;;;GAeG;AACH,KAAK,UAAU,uBAAuB,CACpC,QAA6C,EAC7C,QAAmE,EACnE,KAAiB,EACjB,GAAe,EACf,KASC;IAED,IAAI,MAAM,CAAC;IACX,IAAI,CAAC;QACH,MAAM,GAAG,KAAK,CAAC,kBAAkB,CAC/B,6BAA6B,EAC7B,gBAAgB,CACjB,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;IACT,CAAC;IAED,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,QAAQ,CAAC,MAAM,GAAG,EAAE,aAAa,EAAE,EAAE,EAAE,CAAC;QACxC,OAAO,GAAG,EAAE,CAAC;IACf,CAAC;IAED,QAAQ,CAAC,MAAM,GAAG;QAChB,aAAa,EAAE,gBAAgB,CAAC,MAAM,CAAC,KAAK,EAAE;YAC5C,yBAAyB,EAAE,KAAK,CAAC,yBAAyB;YAC1D,4BAA4B,EAAE,KAAK,CAAC,4BAA4B;SACjE,CAAC;KACH,CAAC;IACF,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED,MAAM,CAAC,MAAM,gBAAgB,GAAG;IAC9B,WAAW,EAAE,CAAC,mBAAmB,CAAC;IAClC,cAAc,EAAE,uBAAuB;IACvC,SAAS,EAAE;QACT,kBAAkB,EAAE,IAAI;QACxB,yBAAyB,EAAE,IAAI;QAC/B,4BAA4B,EAAE,IAAI;KACnC;CACF,CAAC","sourcesContent":["import type {\n Caip25CaveatValue,\n NormalizedScopesObject,\n} from '@metamask/chain-agnostic-permission';\nimport {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n getSessionScopes,\n} from '@metamask/chain-agnostic-permission';\nimport type { Caveat } from '@metamask/permission-controller';\nimport type { CaipAccountId } from '@metamask/utils';\nimport type {\n CaipChainId,\n JsonRpcRequest,\n JsonRpcSuccess,\n} from '@metamask/utils';\n\n/**\n * Handler for the `wallet_getSession` RPC method as specified by [CAIP-312](https://chainagnostic.org/CAIPs/caip-312).\n * The implementation below deviates from the linked spec in that it ignores the `sessionId` param entirely,\n * and that an empty object is returned for the `sessionScopes` result rather than throwing an error if there\n * is no active session for the origin.\n *\n * @param _request - The request object.\n * @param response - The response object.\n * @param _next - The next middleware function. Unused.\n * @param end - The end function.\n * @param hooks - The hooks object.\n * @param hooks.getCaveatForOrigin - Function to retrieve a caveat for the origin.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @param hooks.sortAccountIdsByLastSelected - A function that accepts an array of CaipAccountId and returns an array of CaipAccountId sorted by corresponding last selected account in the wallet.\n * @returns Nothing.\n */\nasync function walletGetSessionHandler(\n _request: JsonRpcRequest & { origin: string },\n response: JsonRpcSuccess<{ sessionScopes: NormalizedScopesObject }>,\n _next: () => void,\n end: () => void,\n hooks: {\n getCaveatForOrigin: (\n endowmentPermissionName: string,\n caveatType: string,\n ) => Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n sortAccountIdsByLastSelected: (\n accounts: CaipAccountId[],\n ) => CaipAccountId[];\n },\n) {\n let caveat;\n try {\n caveat = hooks.getCaveatForOrigin(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n );\n } catch {\n // noop\n }\n\n if (!caveat) {\n response.result = { sessionScopes: {} };\n return end();\n }\n\n response.result = {\n sessionScopes: getSessionScopes(caveat.value, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,\n }),\n };\n return end();\n}\n\nexport const walletGetSession = {\n methodNames: ['wallet_getSession'],\n implementation: walletGetSessionHandler,\n hookNames: {\n getCaveatForOrigin: true,\n getNonEvmSupportedMethods: true,\n sortAccountIdsByLastSelected: true,\n },\n};\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.walletInvokeMethodHandler = exports.walletInvokeMethod = void 0;
3
+ exports.walletInvokeMethod = void 0;
4
4
  const chain_agnostic_permission_1 = require("@metamask/chain-agnostic-permission");
5
5
  const rpc_errors_1 = require("@metamask/rpc-errors");
6
6
  const utils_1 = require("@metamask/utils");
@@ -22,10 +22,7 @@ const utils_1 = require("@metamask/utils");
22
22
  * @param hooks.handleNonEvmRequestForOrigin - A function that sends a request to the MultichainRouter for processing.
23
23
  * @returns Nothing.
24
24
  */
25
- async function handleWalletInvokeMethod(request, response, next, end, hooks) {
26
- if (!(0, utils_1.isPlainObject)(request.params)) {
27
- return end(rpc_errors_1.rpcErrors.invalidParams({ data: { request } }));
28
- }
25
+ async function walletInvokeMethodHandler(request, response, next, end, hooks) {
29
26
  const { scope, request: wrappedRequest } = request.params;
30
27
  (0, chain_agnostic_permission_1.assertIsInternalScopeString)(scope);
31
28
  let caveat;
@@ -90,7 +87,8 @@ async function handleWalletInvokeMethod(request, response, next, end, hooks) {
90
87
  return end();
91
88
  }
92
89
  exports.walletInvokeMethod = {
93
- implementation: handleWalletInvokeMethod,
90
+ methodNames: ['wallet_invokeMethod'],
91
+ implementation: walletInvokeMethodHandler,
94
92
  hookNames: {
95
93
  getCaveatForOrigin: true,
96
94
  findNetworkClientIdByChainId: true,
@@ -100,7 +98,4 @@ exports.walletInvokeMethod = {
100
98
  handleNonEvmRequestForOrigin: true,
101
99
  },
102
100
  };
103
- exports.walletInvokeMethodHandler = {
104
- wallet_invokeMethod: exports.walletInvokeMethod,
105
- };
106
101
  //# sourceMappingURL=wallet-invokeMethod.cjs.map
@@ -1 +1 @@
1
-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ACxC,uEAAuE;YACvE,kCAAkC;YAClC,KAAK,EAAE,KAAoB;YAC3B,OAAO,EAAE,gBAAgB;SAC1B,CAAC,CAAC;IACL,CAAC;IAAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,GAAG,CAAC,GAAY,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAUY,QAAA,kBAAkB,GAAG;IAChC,cAAc,EAAE,wBAAwB;IACxC,SAAS,EAAE;QACT,kBAAkB,EAAE,IAAI;QACxB,4BAA4B,EAAE,IAAI;QAClC,0BAA0B,EAAE,IAAI;QAChC,yBAAyB,EAAE,IAAI;QAC/B,4BAA4B,EAAE,IAAI;QAClC,4BAA4B,EAAE,IAAI;KACnC;CACwC,CAAC;AAE/B,QAAA,yBAAyB,GAAG;IACvC,mBAAmB,EAAE,0BAAkB;CACxC,CAAC","sourcesContent":["import type {\n Caip25CaveatValue,\n ExternalScopeString,\n} from '@metamask/chain-agnostic-permission';\nimport {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n assertIsInternalScopeString,\n getSessionScopes,\n parseScopeString,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport type { Caveat } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport {\n isPlainObject,\n KnownCaipNamespace,\n numberToHex,\n} from '@metamask/utils';\nimport type {\n CaipAccountId,\n CaipChainId,\n Hex,\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nexport type WalletInvokeMethodParams = {\n scope: ExternalScopeString;\n request: Pick<JsonRpcRequest, 'method' | 'params'>;\n};\n\nexport type WalletInvokeMethodRequest =\n JsonRpcRequest<WalletInvokeMethodParams> & {\n origin: string;\n };\n\ntype WalletInvokeMethodHooks = {\n getCaveatForOrigin: (\n endowmentPermissionName: string,\n caveatType: string,\n ) => Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n getSelectedNetworkClientId: () => NetworkClientId;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];\n handleNonEvmRequestForOrigin: (params: {\n connectedAddresses: CaipAccountId[];\n scope: CaipChainId;\n request: JsonRpcRequest;\n }) => Promise<Json>;\n};\n\n/**\n * Handler for the `wallet_invokeMethod` RPC method as specified by [CAIP-27](https://chainagnostic.org/CAIPs/caip-27).\n * The implementation below deviates from the linked spec in that it ignores the `sessionId` param\n * and instead uses the singular session for the origin if available.\n *\n * @param request - The request object.\n * @param response - The response object. Unused.\n * @param next - The next middleware function.\n * @param end - The end function.\n * @param hooks - The hooks object.\n * @param hooks.getCaveatForOrigin - the hook for getting a caveat from a permission for an origin.\n * @param hooks.findNetworkClientIdByChainId - the hook for finding the networkClientId for a chainId.\n * @param hooks.getSelectedNetworkClientId - the hook for getting the current globally selected networkClientId.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @param hooks.sortAccountIdsByLastSelected - A function that sorts accounts by their last selected order.\n * @param hooks.handleNonEvmRequestForOrigin - A function that sends a request to the MultichainRouter for processing.\n * @returns Nothing.\n */\nasync function handleWalletInvokeMethod(\n request: WalletInvokeMethodRequest,\n response: PendingJsonRpcResponse<Json>,\n next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: WalletInvokeMethodHooks,\n) {\n if (!isPlainObject(request.params)) {\n return end(rpcErrors.invalidParams({ data: { request } }));\n }\n const { scope, request: wrappedRequest } = request.params;\n\n assertIsInternalScopeString(scope);\n\n let caveat;\n try {\n caveat = hooks.getCaveatForOrigin(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n );\n } catch {\n // noop\n }\n if (!caveat) {\n return end(providerErrors.unauthorized());\n }\n\n const scopeObject = getSessionScopes(caveat.value, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,\n })[scope];\n\n if (!scopeObject?.methods?.includes(wrappedRequest.method)) {\n return end(providerErrors.unauthorized());\n }\n\n const { namespace, reference } = parseScopeString(scope);\n\n const isEvmRequest =\n (namespace === KnownCaipNamespace.Wallet &&\n (!reference || reference === KnownCaipNamespace.Eip155)) ||\n namespace === KnownCaipNamespace.Eip155;\n\n const unwrappedRequest = {\n ...request,\n scope,\n method: wrappedRequest.method,\n params: wrappedRequest.params,\n };\n\n if (isEvmRequest) {\n let networkClientId;\n if (namespace === KnownCaipNamespace.Wallet) {\n networkClientId = hooks.getSelectedNetworkClientId();\n } else if (namespace === KnownCaipNamespace.Eip155) {\n if (reference) {\n networkClientId = hooks.findNetworkClientIdByChainId(\n numberToHex(parseInt(reference, 10)),\n );\n }\n }\n\n if (!networkClientId) {\n console.error(\n 'failed to resolve network client for wallet_invokeMethod',\n request,\n );\n return end(rpcErrors.internal());\n }\n\n Object.assign(request, {\n ...unwrappedRequest,\n networkClientId,\n });\n return next();\n }\n\n try {\n response.result = await hooks.handleNonEvmRequestForOrigin({\n connectedAddresses: scopeObject.accounts,\n // Type assertion: We know that scope is not \"wallet\" by now because it\n // is already being handled above.\n scope: scope as CaipChainId,\n request: unwrappedRequest,\n });\n } catch (err) {\n return end(err as Error);\n }\n return end();\n}\n\ntype WalletInvokeMethodMethodHandler = MethodHandler<\n WalletInvokeMethodHooks,\n never,\n WalletInvokeMethodParams,\n Json,\n { origin: string }\n>;\n\nexport const walletInvokeMethod = {\n implementation: handleWalletInvokeMethod,\n hookNames: {\n getCaveatForOrigin: true,\n findNetworkClientIdByChainId: true,\n getSelectedNetworkClientId: true,\n getNonEvmSupportedMethods: true,\n sortAccountIdsByLastSelected: true,\n handleNonEvmRequestForOrigin: true,\n },\n} satisfies WalletInvokeMethodMethodHandler;\n\nexport const walletInvokeMethodHandler = {\n wallet_invokeMethod: walletInvokeMethod,\n};\n"]}
1
+ {"version":3,"file":"wallet-invokeMethod.cjs","sourceRoot":"","sources":["../../src/handlers/wallet-invokeMethod.ts"],"names":[],"mappings":";;;AAIA,mFAM6C;AAG7C,qDAAiE;AASjE,2CAAkE;AAUlE;;;;;;;;;;;;;;;;;GAiBG;AACH,KAAK,UAAU,yBAAyB,CACtC,OAAkC,EAClC,QAAgC,EAChC,IAAgB,EAChB,GAA4B,EAC5B,KAgBC;IAED,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAE1D,IAAA,uDAA2B,EAAC,KAAK,CAAC,CAAC;IAEnC,IAAI,MAAM,CAAC;IACX,IAAI,CAAC;QACH,MAAM,GAAG,KAAK,CAAC,kBAAkB,CAC/B,yDAA6B,EAC7B,4CAAgB,CACjB,CAAC;IACJ,CAAC;IAAC,MAAM,CAAC;QACP,OAAO;IACT,CAAC;IACD,IAAI,CAAC,MAAM,EAAE,CAAC;QACZ,OAAO,GAAG,CAAC,2BAAc,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,WAAW,GAAG,IAAA,4CAAgB,EAAC,MAAM,CAAC,KAAK,EAAE;QACjD,yBAAyB,EAAE,KAAK,CAAC,yBAAyB;QAC1D,4BAA4B,EAAE,KAAK,CAAC,4BAA4B;KACjE,CAAC,CAAC,KAAK,CAAC,CAAC;IAEV,IAAI,CAAC,WAAW,EAAE,OAAO,EAAE,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,EAAE,CAAC;QAC3D,OAAO,GAAG,CAAC,2BAAc,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,IAAA,4CAAgB,EAAC,KAAK,CAAC,CAAC;IAEzD,MAAM,YAAY,GAChB,CAAC,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AAC,OAAO,GAAG,EAAE,CAAC;QACb,OAAO,GAAG,CAAC,GAAY,CAAC,CAAC;IAC3B,CAAC;IACD,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AACY,QAAA,kBAAkB,GAAG;IAChC,WAAW,EAAE,CAAC,qBAAqB,CAAC;IACpC,cAAc,EAAE,yBAAyB;IACzC,SAAS,EAAE;QACT,kBAAkB,EAAE,IAAI;QACxB,4BAA4B,EAAE,IAAI;QAClC,0BAA0B,EAAE,IAAI;QAChC,yBAAyB,EAAE,IAAI;QAC/B,4BAA4B,EAAE,IAAI;QAClC,4BAA4B,EAAE,IAAI;KACnC;CACF,CAAC","sourcesContent":["import type {\n Caip25CaveatValue,\n ExternalScopeString,\n} from '@metamask/chain-agnostic-permission';\nimport {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n assertIsInternalScopeString,\n getSessionScopes,\n parseScopeString,\n} from '@metamask/chain-agnostic-permission';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport type { Caveat } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n CaipAccountId,\n CaipChainId,\n Hex,\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\nimport { KnownCaipNamespace, numberToHex } from '@metamask/utils';\n\nexport type WalletInvokeMethodRequest = JsonRpcRequest & {\n origin: string;\n params: {\n scope: ExternalScopeString;\n request: Pick<JsonRpcRequest, 'method' | 'params'>;\n };\n};\n\n/**\n * Handler for the `wallet_invokeMethod` RPC method as specified by [CAIP-27](https://chainagnostic.org/CAIPs/caip-27).\n * The implementation below deviates from the linked spec in that it ignores the `sessionId` param\n * and instead uses the singular session for the origin if available.\n *\n * @param request - The request object.\n * @param response - The response object. Unused.\n * @param next - The next middleware function.\n * @param end - The end function.\n * @param hooks - The hooks object.\n * @param hooks.getCaveatForOrigin - the hook for getting a caveat from a permission for an origin.\n * @param hooks.findNetworkClientIdByChainId - the hook for finding the networkClientId for a chainId.\n * @param hooks.getSelectedNetworkClientId - the hook for getting the current globally selected networkClientId.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @param hooks.sortAccountIdsByLastSelected - A function that sorts accounts by their last selected order.\n * @param hooks.handleNonEvmRequestForOrigin - A function that sends a request to the MultichainRouter for processing.\n * @returns Nothing.\n */\nasync function walletInvokeMethodHandler(\n request: WalletInvokeMethodRequest,\n response: PendingJsonRpcResponse,\n next: () => void,\n end: (error?: Error) => void,\n hooks: {\n getCaveatForOrigin: (\n endowmentPermissionName: string,\n caveatType: string,\n ) => Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n getSelectedNetworkClientId: () => NetworkClientId;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n sortAccountIdsByLastSelected: (\n accounts: CaipAccountId[],\n ) => CaipAccountId[];\n handleNonEvmRequestForOrigin: (params: {\n connectedAddresses: CaipAccountId[];\n scope: CaipChainId;\n request: JsonRpcRequest;\n }) => Promise<Json>;\n },\n) {\n const { scope, request: wrappedRequest } = request.params;\n\n assertIsInternalScopeString(scope);\n\n let caveat;\n try {\n caveat = hooks.getCaveatForOrigin(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n );\n } catch {\n // noop\n }\n if (!caveat) {\n return end(providerErrors.unauthorized());\n }\n\n const scopeObject = getSessionScopes(caveat.value, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,\n })[scope];\n\n if (!scopeObject?.methods?.includes(wrappedRequest.method)) {\n return end(providerErrors.unauthorized());\n }\n\n const { namespace, reference } = parseScopeString(scope);\n\n const isEvmRequest =\n (namespace === KnownCaipNamespace.Wallet &&\n (!reference || reference === KnownCaipNamespace.Eip155)) ||\n namespace === KnownCaipNamespace.Eip155;\n\n const unwrappedRequest = {\n ...request,\n scope,\n method: wrappedRequest.method,\n params: wrappedRequest.params,\n };\n\n if (isEvmRequest) {\n let networkClientId;\n if (namespace === KnownCaipNamespace.Wallet) {\n networkClientId = hooks.getSelectedNetworkClientId();\n } else if (namespace === KnownCaipNamespace.Eip155) {\n if (reference) {\n networkClientId = hooks.findNetworkClientIdByChainId(\n numberToHex(parseInt(reference, 10)),\n );\n }\n }\n\n if (!networkClientId) {\n console.error(\n 'failed to resolve network client for wallet_invokeMethod',\n request,\n );\n return end(rpcErrors.internal());\n }\n\n Object.assign(request, {\n ...unwrappedRequest,\n networkClientId,\n });\n return next();\n }\n\n try {\n response.result = await hooks.handleNonEvmRequestForOrigin({\n connectedAddresses: scopeObject.accounts,\n // Type assertion: We know that scope is not \"wallet\" by now because it\n // is already being handled above.\n scope: scope as CaipChainId,\n request: unwrappedRequest,\n });\n } catch (err) {\n return end(err as Error);\n }\n return end();\n}\nexport const walletInvokeMethod = {\n methodNames: ['wallet_invokeMethod'],\n implementation: walletInvokeMethodHandler,\n hookNames: {\n getCaveatForOrigin: true,\n findNetworkClientIdByChainId: true,\n getSelectedNetworkClientId: true,\n getNonEvmSupportedMethods: true,\n sortAccountIdsByLastSelected: true,\n handleNonEvmRequestForOrigin: true,\n },\n};\n"]}
@@ -1,27 +1,14 @@
1
1
  import type { Caip25CaveatValue, ExternalScopeString } from "@metamask/chain-agnostic-permission";
2
2
  import { Caip25CaveatType } from "@metamask/chain-agnostic-permission";
3
- import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
4
3
  import type { NetworkClientId } from "@metamask/network-controller";
5
4
  import type { Caveat } from "@metamask/permission-controller";
6
5
  import type { CaipAccountId, CaipChainId, Hex, Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
7
- export type WalletInvokeMethodParams = {
8
- scope: ExternalScopeString;
9
- request: Pick<JsonRpcRequest, 'method' | 'params'>;
10
- };
11
- export type WalletInvokeMethodRequest = JsonRpcRequest<WalletInvokeMethodParams> & {
6
+ export type WalletInvokeMethodRequest = JsonRpcRequest & {
12
7
  origin: string;
13
- };
14
- type WalletInvokeMethodHooks = {
15
- getCaveatForOrigin: (endowmentPermissionName: string, caveatType: string) => Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;
16
- findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;
17
- getSelectedNetworkClientId: () => NetworkClientId;
18
- getNonEvmSupportedMethods: (scope: CaipChainId) => string[];
19
- sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];
20
- handleNonEvmRequestForOrigin: (params: {
21
- connectedAddresses: CaipAccountId[];
22
- scope: CaipChainId;
23
- request: JsonRpcRequest;
24
- }) => Promise<Json>;
8
+ params: {
9
+ scope: ExternalScopeString;
10
+ request: Pick<JsonRpcRequest, 'method' | 'params'>;
11
+ };
25
12
  };
26
13
  /**
27
14
  * Handler for the `wallet_invokeMethod` RPC method as specified by [CAIP-27](https://chainagnostic.org/CAIPs/caip-27).
@@ -41,29 +28,28 @@ type WalletInvokeMethodHooks = {
41
28
  * @param hooks.handleNonEvmRequestForOrigin - A function that sends a request to the MultichainRouter for processing.
42
29
  * @returns Nothing.
43
30
  */
44
- declare function handleWalletInvokeMethod(request: WalletInvokeMethodRequest, response: PendingJsonRpcResponse<Json>, next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: WalletInvokeMethodHooks): Promise<void>;
31
+ declare function walletInvokeMethodHandler(request: WalletInvokeMethodRequest, response: PendingJsonRpcResponse, next: () => void, end: (error?: Error) => void, hooks: {
32
+ getCaveatForOrigin: (endowmentPermissionName: string, caveatType: string) => Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;
33
+ findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;
34
+ getSelectedNetworkClientId: () => NetworkClientId;
35
+ getNonEvmSupportedMethods: (scope: CaipChainId) => string[];
36
+ sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];
37
+ handleNonEvmRequestForOrigin: (params: {
38
+ connectedAddresses: CaipAccountId[];
39
+ scope: CaipChainId;
40
+ request: JsonRpcRequest;
41
+ }) => Promise<Json>;
42
+ }): Promise<void>;
45
43
  export declare const walletInvokeMethod: {
46
- implementation: typeof handleWalletInvokeMethod;
44
+ methodNames: string[];
45
+ implementation: typeof walletInvokeMethodHandler;
47
46
  hookNames: {
48
- getCaveatForOrigin: true;
49
- findNetworkClientIdByChainId: true;
50
- getSelectedNetworkClientId: true;
51
- getNonEvmSupportedMethods: true;
52
- sortAccountIdsByLastSelected: true;
53
- handleNonEvmRequestForOrigin: true;
54
- };
55
- };
56
- export declare const walletInvokeMethodHandler: {
57
- wallet_invokeMethod: {
58
- implementation: typeof handleWalletInvokeMethod;
59
- hookNames: {
60
- getCaveatForOrigin: true;
61
- findNetworkClientIdByChainId: true;
62
- getSelectedNetworkClientId: true;
63
- getNonEvmSupportedMethods: true;
64
- sortAccountIdsByLastSelected: true;
65
- handleNonEvmRequestForOrigin: true;
66
- };
47
+ getCaveatForOrigin: boolean;
48
+ findNetworkClientIdByChainId: boolean;
49
+ getSelectedNetworkClientId: boolean;
50
+ getNonEvmSupportedMethods: boolean;
51
+ sortAccountIdsByLastSelected: boolean;
52
+ handleNonEvmRequestForOrigin: boolean;
67
53
  };
68
54
  };
69
55
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-invokeMethod.d.cts","sourceRoot":"","sources":["../../src/handlers/wallet-invokeMethod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EACpB,4CAA4C;AAC7C,OAAO,EACL,gBAAgB,EAKjB,4CAA4C;AAC7C,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAE1B,kCAAkC;AACnC,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AACpE,OAAO,KAAK,EAAE,MAAM,EAAE,wCAAwC;AAO9D,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,GAAG,EACH,I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A4B,EAAE,CAAC,MAAM,EAAE;QACrC,kBAAkB,EAAE,aAAa,EAAE,CAAC;QACpC,KAAK,EAAE,WAAW,CAAC;QACnB,OAAO,EAAE,cAAc,CAAC;KACzB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrB,iBAiFF;AACD,eAAO,MAAM,kBAAkB;;;;;;;;;;;CAW9B,CAAC"}
@@ -1,27 +1,14 @@
1
1
  import type { Caip25CaveatValue, ExternalScopeString } from "@metamask/chain-agnostic-permission";
2
2
  import { Caip25CaveatType } from "@metamask/chain-agnostic-permission";
3
- import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
4
3
  import type { NetworkClientId } from "@metamask/network-controller";
5
4
  import type { Caveat } from "@metamask/permission-controller";
6
5
  import type { CaipAccountId, CaipChainId, Hex, Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
7
- export type WalletInvokeMethodParams = {
8
- scope: ExternalScopeString;
9
- request: Pick<JsonRpcRequest, 'method' | 'params'>;
10
- };
11
- export type WalletInvokeMethodRequest = JsonRpcRequest<WalletInvokeMethodParams> & {
6
+ export type WalletInvokeMethodRequest = JsonRpcRequest & {
12
7
  origin: string;
13
- };
14
- type WalletInvokeMethodHooks = {
15
- getCaveatForOrigin: (endowmentPermissionName: string, caveatType: string) => Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;
16
- findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;
17
- getSelectedNetworkClientId: () => NetworkClientId;
18
- getNonEvmSupportedMethods: (scope: CaipChainId) => string[];
19
- sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];
20
- handleNonEvmRequestForOrigin: (params: {
21
- connectedAddresses: CaipAccountId[];
22
- scope: CaipChainId;
23
- request: JsonRpcRequest;
24
- }) => Promise<Json>;
8
+ params: {
9
+ scope: ExternalScopeString;
10
+ request: Pick<JsonRpcRequest, 'method' | 'params'>;
11
+ };
25
12
  };
26
13
  /**
27
14
  * Handler for the `wallet_invokeMethod` RPC method as specified by [CAIP-27](https://chainagnostic.org/CAIPs/caip-27).
@@ -41,29 +28,28 @@ type WalletInvokeMethodHooks = {
41
28
  * @param hooks.handleNonEvmRequestForOrigin - A function that sends a request to the MultichainRouter for processing.
42
29
  * @returns Nothing.
43
30
  */
44
- declare function handleWalletInvokeMethod(request: WalletInvokeMethodRequest, response: PendingJsonRpcResponse<Json>, next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: WalletInvokeMethodHooks): Promise<void>;
31
+ declare function walletInvokeMethodHandler(request: WalletInvokeMethodRequest, response: PendingJsonRpcResponse, next: () => void, end: (error?: Error) => void, hooks: {
32
+ getCaveatForOrigin: (endowmentPermissionName: string, caveatType: string) => Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;
33
+ findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;
34
+ getSelectedNetworkClientId: () => NetworkClientId;
35
+ getNonEvmSupportedMethods: (scope: CaipChainId) => string[];
36
+ sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];
37
+ handleNonEvmRequestForOrigin: (params: {
38
+ connectedAddresses: CaipAccountId[];
39
+ scope: CaipChainId;
40
+ request: JsonRpcRequest;
41
+ }) => Promise<Json>;
42
+ }): Promise<void>;
45
43
  export declare const walletInvokeMethod: {
46
- implementation: typeof handleWalletInvokeMethod;
44
+ methodNames: string[];
45
+ implementation: typeof walletInvokeMethodHandler;
47
46
  hookNames: {
48
- getCaveatForOrigin: true;
49
- findNetworkClientIdByChainId: true;
50
- getSelectedNetworkClientId: true;
51
- getNonEvmSupportedMethods: true;
52
- sortAccountIdsByLastSelected: true;
53
- handleNonEvmRequestForOrigin: true;
54
- };
55
- };
56
- export declare const walletInvokeMethodHandler: {
57
- wallet_invokeMethod: {
58
- implementation: typeof handleWalletInvokeMethod;
59
- hookNames: {
60
- getCaveatForOrigin: true;
61
- findNetworkClientIdByChainId: true;
62
- getSelectedNetworkClientId: true;
63
- getNonEvmSupportedMethods: true;
64
- sortAccountIdsByLastSelected: true;
65
- handleNonEvmRequestForOrigin: true;
66
- };
47
+ getCaveatForOrigin: boolean;
48
+ findNetworkClientIdByChainId: boolean;
49
+ getSelectedNetworkClientId: boolean;
50
+ getNonEvmSupportedMethods: boolean;
51
+ sortAccountIdsByLastSelected: boolean;
52
+ handleNonEvmRequestForOrigin: boolean;
67
53
  };
68
54
  };
69
55
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-invokeMethod.d.mts","sourceRoot":"","sources":["../../src/handlers/wallet-invokeMethod.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,mBAAmB,EACpB,4CAA4C;AAC7C,OAAO,EACL,gBAAgB,EAKjB,4CAA4C;AAC7C,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAE1B,kCAAkC;AACnC,OAAO,KAAK,EAAE,eAAe,EAAE,qCAAqC;AACpE,OAAO,KAAK,EAAE,MAAM,EAAE,wCAAwC;AAO9D,OAAO,KAAK,EACV,aAAa,EACb,WAAW,EACX,GAAG,EACH,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,MAAM,MAAM,wBAAwB,GAAG;IACrC,KAAK,EAAE,mBAAmB,CAAC;IAC3B,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,QAAQ,CAAC,CAAC;CACpD,CAAC;AAEF,MAAM,MAAM,yBAAyB,GACnC,cAAc,CAAC,wBAAwB,CAAC,GAAG;IACzC,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEJ,KAAK,uBAAuB,GAAG;IAC7B,kBAAkB,EAAE,CAClB,uBAAuB,EAAE,MAAM,EAC/B,UAAU,EAAE,MAAM,KACf,MAAM,CAAC,OAAO,gBAAgB,EAAE,iBAAiB,CAAC,CAAC;IACxD,4BAA4B,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,eAAe,G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B,OAAO,EAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,QAAQ,CAAC,CAAC;KACpD,CAAC;CACH,CAAC;AAEF;;;;;;;;;;;;;;;;;GAiBG;AACH,iBAAe,yBAAyB,CACtC,OAAO,EAAE,yBAAyB,EAClC,QAAQ,EAAE,sBAAsB,EAChC,IAAI,EAAE,MAAM,IAAI,EAChB,GAAG,EAAE,CAAC,KAAK,CAAC,EAAE,KAAK,KAAK,IAAI,EAC5B,KAAK,EAAE;IACL,kBAAkB,EAAE,CAClB,uBAAuB,EAAE,MAAM,EAC/B,UAAU,EAAE,MAAM,KACf,MAAM,CAAC,OAAO,gBAAgB,EAAE,iBAAiB,CAAC,CAAC;IACxD,4BAA4B,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,eAAe,GAAG,SAAS,CAAC;IAC5E,0BAA0B,EAAE,MAAM,eAAe,CAAC;IAClD,yBAAyB,EAAE,CAAC,KAAK,EAAE,WAAW,KAAK,MAAM,EAAE,CAAC;IAC5D,4BAA4B,EAAE,CAC5B,QAAQ,EAAE,aAAa,EAAE,KACtB,aAAa,EAAE,CAAC;IACrB,4BAA4B,EAAE,CAAC,MAAM,EAAE;QACrC,kBAAkB,EAAE,aAAa,EAAE,CAAC;QACpC,KAAK,EAAE,WAAW,CAAC;QACnB,OAAO,EAAE,cAAc,CAAC;KACzB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACrB,iBAiFF;AACD,eAAO,MAAM,kBAAkB;;;;;;;;;;;CAW9B,CAAC"}
@@ -1,6 +1,6 @@
1
1
  import { Caip25CaveatType, Caip25EndowmentPermissionName, assertIsInternalScopeString, getSessionScopes, parseScopeString } from "@metamask/chain-agnostic-permission";
2
2
  import { providerErrors, rpcErrors } from "@metamask/rpc-errors";
3
- import { isPlainObject, KnownCaipNamespace, numberToHex } from "@metamask/utils";
3
+ import { KnownCaipNamespace, numberToHex } from "@metamask/utils";
4
4
  /**
5
5
  * Handler for the `wallet_invokeMethod` RPC method as specified by [CAIP-27](https://chainagnostic.org/CAIPs/caip-27).
6
6
  * The implementation below deviates from the linked spec in that it ignores the `sessionId` param
@@ -19,10 +19,7 @@ import { isPlainObject, KnownCaipNamespace, numberToHex } from "@metamask/utils"
19
19
  * @param hooks.handleNonEvmRequestForOrigin - A function that sends a request to the MultichainRouter for processing.
20
20
  * @returns Nothing.
21
21
  */
22
- async function handleWalletInvokeMethod(request, response, next, end, hooks) {
23
- if (!isPlainObject(request.params)) {
24
- return end(rpcErrors.invalidParams({ data: { request } }));
25
- }
22
+ async function walletInvokeMethodHandler(request, response, next, end, hooks) {
26
23
  const { scope, request: wrappedRequest } = request.params;
27
24
  assertIsInternalScopeString(scope);
28
25
  let caveat;
@@ -87,7 +84,8 @@ async function handleWalletInvokeMethod(request, response, next, end, hooks) {
87
84
  return end();
88
85
  }
89
86
  export const walletInvokeMethod = {
90
- implementation: handleWalletInvokeMethod,
87
+ methodNames: ['wallet_invokeMethod'],
88
+ implementation: walletInvokeMethodHandler,
91
89
  hookNames: {
92
90
  getCaveatForOrigin: true,
93
91
  findNetworkClientIdByChainId: true,
@@ -97,7 +95,4 @@ export const walletInvokeMethod = {
97
95
  handleNonEvmRequestForOrigin: true,
98
96
  },
99
97
  };
100
- export const walletInvokeMethodHandler = {
101
- wallet_invokeMethod: walletInvokeMethod,
102
- };
103
98
  //# sourceMappingURL=wallet-invokeMethod.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-invokeMethod.mjs","sourceRoot":"","sources":["../../src/handlers/wallet-invokeMethod.ts"],"names":[],"mappings":"AAIA,OAAO,EACL,gBAAgB,EAChB,6BAA6B,EAC7B,2BAA2B,EAC3B,gBAAgB,EAChB,gBAAgB,EACjB,4CAA4C;AAQ7C,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AACjE,OAAO,EACL,aAAa,EACb,kBAAkB,EAClB,WAAW,EACZ,wBAAwB;AAoCzB;;;;;;;;;;;;;;;;;GAiBG;AACH,KAA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E,CAAC;AACf,CAAC;AAUD,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,cAAc,EAAE,wBAAwB;IACxC,SAAS,EAAE;QACT,kBAAkB,EAAE,IAAI;QACxB,4BAA4B,EAAE,IAAI;QAClC,0BAA0B,EAAE,IAAI;QAChC,yBAAyB,EAAE,IAAI;QAC/B,4BAA4B,EAAE,IAAI;QAClC,4BAA4B,EAAE,IAAI;KACnC;CACwC,CAAC;AAE5C,MAAM,CAAC,MAAM,yBAAyB,GAAG;IACvC,mBAAmB,EAAE,kBAAkB;CACxC,CAAC","sourcesContent":["import type {\n Caip25CaveatValue,\n ExternalScopeString,\n} from '@metamask/chain-agnostic-permission';\nimport {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n assertIsInternalScopeString,\n getSessionScopes,\n parseScopeString,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport type { Caveat } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport {\n isPlainObject,\n KnownCaipNamespace,\n numberToHex,\n} from '@metamask/utils';\nimport type {\n CaipAccountId,\n CaipChainId,\n Hex,\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nexport type WalletInvokeMethodParams = {\n scope: ExternalScopeString;\n request: Pick<JsonRpcRequest, 'method' | 'params'>;\n};\n\nexport type WalletInvokeMethodRequest =\n JsonRpcRequest<WalletInvokeMethodParams> & {\n origin: string;\n };\n\ntype WalletInvokeMethodHooks = {\n getCaveatForOrigin: (\n endowmentPermissionName: string,\n caveatType: string,\n ) => Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n getSelectedNetworkClientId: () => NetworkClientId;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n sortAccountIdsByLastSelected: (accounts: CaipAccountId[]) => CaipAccountId[];\n handleNonEvmRequestForOrigin: (params: {\n connectedAddresses: CaipAccountId[];\n scope: CaipChainId;\n request: JsonRpcRequest;\n }) => Promise<Json>;\n};\n\n/**\n * Handler for the `wallet_invokeMethod` RPC method as specified by [CAIP-27](https://chainagnostic.org/CAIPs/caip-27).\n * The implementation below deviates from the linked spec in that it ignores the `sessionId` param\n * and instead uses the singular session for the origin if available.\n *\n * @param request - The request object.\n * @param response - The response object. Unused.\n * @param next - The next middleware function.\n * @param end - The end function.\n * @param hooks - The hooks object.\n * @param hooks.getCaveatForOrigin - the hook for getting a caveat from a permission for an origin.\n * @param hooks.findNetworkClientIdByChainId - the hook for finding the networkClientId for a chainId.\n * @param hooks.getSelectedNetworkClientId - the hook for getting the current globally selected networkClientId.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @param hooks.sortAccountIdsByLastSelected - A function that sorts accounts by their last selected order.\n * @param hooks.handleNonEvmRequestForOrigin - A function that sends a request to the MultichainRouter for processing.\n * @returns Nothing.\n */\nasync function handleWalletInvokeMethod(\n request: WalletInvokeMethodRequest,\n response: PendingJsonRpcResponse<Json>,\n next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: WalletInvokeMethodHooks,\n) {\n if (!isPlainObject(request.params)) {\n return end(rpcErrors.invalidParams({ data: { request } }));\n }\n const { scope, request: wrappedRequest } = request.params;\n\n assertIsInternalScopeString(scope);\n\n let caveat;\n try {\n caveat = hooks.getCaveatForOrigin(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n );\n } catch {\n // noop\n }\n if (!caveat) {\n return end(providerErrors.unauthorized());\n }\n\n const scopeObject = getSessionScopes(caveat.value, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,\n })[scope];\n\n if (!scopeObject?.methods?.includes(wrappedRequest.method)) {\n return end(providerErrors.unauthorized());\n }\n\n const { namespace, reference } = parseScopeString(scope);\n\n const isEvmRequest =\n (namespace === KnownCaipNamespace.Wallet &&\n (!reference || reference === KnownCaipNamespace.Eip155)) ||\n namespace === KnownCaipNamespace.Eip155;\n\n const unwrappedRequest = {\n ...request,\n scope,\n method: wrappedRequest.method,\n params: wrappedRequest.params,\n };\n\n if (isEvmRequest) {\n let networkClientId;\n if (namespace === KnownCaipNamespace.Wallet) {\n networkClientId = hooks.getSelectedNetworkClientId();\n } else if (namespace === KnownCaipNamespace.Eip155) {\n if (reference) {\n networkClientId = hooks.findNetworkClientIdByChainId(\n numberToHex(parseInt(reference, 10)),\n );\n }\n }\n\n if (!networkClientId) {\n console.error(\n 'failed to resolve network client for wallet_invokeMethod',\n request,\n );\n return end(rpcErrors.internal());\n }\n\n Object.assign(request, {\n ...unwrappedRequest,\n networkClientId,\n });\n return next();\n }\n\n try {\n response.result = await hooks.handleNonEvmRequestForOrigin({\n connectedAddresses: scopeObject.accounts,\n // Type assertion: We know that scope is not \"wallet\" by now because it\n // is already being handled above.\n scope: scope as CaipChainId,\n request: unwrappedRequest,\n });\n } catch (err) {\n return end(err as Error);\n }\n return end();\n}\n\ntype WalletInvokeMethodMethodHandler = MethodHandler<\n WalletInvokeMethodHooks,\n never,\n WalletInvokeMethodParams,\n Json,\n { origin: string }\n>;\n\nexport const walletInvokeMethod = {\n implementation: handleWalletInvokeMethod,\n hookNames: {\n getCaveatForOrigin: true,\n findNetworkClientIdByChainId: true,\n getSelectedNetworkClientId: true,\n getNonEvmSupportedMethods: true,\n sortAccountIdsByLastSelected: true,\n handleNonEvmRequestForOrigin: true,\n },\n} satisfies WalletInvokeMethodMethodHandler;\n\nexport const walletInvokeMethodHandler = {\n wallet_invokeMethod: walletInvokeMethod,\n};\n"]}
1
+ {"version":3,"file":"wallet-invokeMethod.mjs","sourceRoot":"","sources":["../../src/handlers/wallet-invokeMethod.ts"],"names":[],"mappings":"AAIA,OAAO,EACL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,CAAC;IAC3B,CAAC;IACD,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AACD,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,WAAW,EAAE,CAAC,qBAAqB,CAAC;IACpC,cAAc,EAAE,yBAAyB;IACzC,SAAS,EAAE;QACT,kBAAkB,EAAE,IAAI;QACxB,4BAA4B,EAAE,IAAI;QAClC,0BAA0B,EAAE,IAAI;QAChC,yBAAyB,EAAE,IAAI;QAC/B,4BAA4B,EAAE,IAAI;QAClC,4BAA4B,EAAE,IAAI;KACnC;CACF,CAAC","sourcesContent":["import type {\n Caip25CaveatValue,\n ExternalScopeString,\n} from '@metamask/chain-agnostic-permission';\nimport {\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n assertIsInternalScopeString,\n getSessionScopes,\n parseScopeString,\n} from '@metamask/chain-agnostic-permission';\nimport type { NetworkClientId } from '@metamask/network-controller';\nimport type { Caveat } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type {\n CaipAccountId,\n CaipChainId,\n Hex,\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\nimport { KnownCaipNamespace, numberToHex } from '@metamask/utils';\n\nexport type WalletInvokeMethodRequest = JsonRpcRequest & {\n origin: string;\n params: {\n scope: ExternalScopeString;\n request: Pick<JsonRpcRequest, 'method' | 'params'>;\n };\n};\n\n/**\n * Handler for the `wallet_invokeMethod` RPC method as specified by [CAIP-27](https://chainagnostic.org/CAIPs/caip-27).\n * The implementation below deviates from the linked spec in that it ignores the `sessionId` param\n * and instead uses the singular session for the origin if available.\n *\n * @param request - The request object.\n * @param response - The response object. Unused.\n * @param next - The next middleware function.\n * @param end - The end function.\n * @param hooks - The hooks object.\n * @param hooks.getCaveatForOrigin - the hook for getting a caveat from a permission for an origin.\n * @param hooks.findNetworkClientIdByChainId - the hook for finding the networkClientId for a chainId.\n * @param hooks.getSelectedNetworkClientId - the hook for getting the current globally selected networkClientId.\n * @param hooks.getNonEvmSupportedMethods - A function that returns the supported methods for a non EVM scope.\n * @param hooks.sortAccountIdsByLastSelected - A function that sorts accounts by their last selected order.\n * @param hooks.handleNonEvmRequestForOrigin - A function that sends a request to the MultichainRouter for processing.\n * @returns Nothing.\n */\nasync function walletInvokeMethodHandler(\n request: WalletInvokeMethodRequest,\n response: PendingJsonRpcResponse,\n next: () => void,\n end: (error?: Error) => void,\n hooks: {\n getCaveatForOrigin: (\n endowmentPermissionName: string,\n caveatType: string,\n ) => Caveat<typeof Caip25CaveatType, Caip25CaveatValue>;\n findNetworkClientIdByChainId: (chainId: Hex) => NetworkClientId | undefined;\n getSelectedNetworkClientId: () => NetworkClientId;\n getNonEvmSupportedMethods: (scope: CaipChainId) => string[];\n sortAccountIdsByLastSelected: (\n accounts: CaipAccountId[],\n ) => CaipAccountId[];\n handleNonEvmRequestForOrigin: (params: {\n connectedAddresses: CaipAccountId[];\n scope: CaipChainId;\n request: JsonRpcRequest;\n }) => Promise<Json>;\n },\n) {\n const { scope, request: wrappedRequest } = request.params;\n\n assertIsInternalScopeString(scope);\n\n let caveat;\n try {\n caveat = hooks.getCaveatForOrigin(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n );\n } catch {\n // noop\n }\n if (!caveat) {\n return end(providerErrors.unauthorized());\n }\n\n const scopeObject = getSessionScopes(caveat.value, {\n getNonEvmSupportedMethods: hooks.getNonEvmSupportedMethods,\n sortAccountIdsByLastSelected: hooks.sortAccountIdsByLastSelected,\n })[scope];\n\n if (!scopeObject?.methods?.includes(wrappedRequest.method)) {\n return end(providerErrors.unauthorized());\n }\n\n const { namespace, reference } = parseScopeString(scope);\n\n const isEvmRequest =\n (namespace === KnownCaipNamespace.Wallet &&\n (!reference || reference === KnownCaipNamespace.Eip155)) ||\n namespace === KnownCaipNamespace.Eip155;\n\n const unwrappedRequest = {\n ...request,\n scope,\n method: wrappedRequest.method,\n params: wrappedRequest.params,\n };\n\n if (isEvmRequest) {\n let networkClientId;\n if (namespace === KnownCaipNamespace.Wallet) {\n networkClientId = hooks.getSelectedNetworkClientId();\n } else if (namespace === KnownCaipNamespace.Eip155) {\n if (reference) {\n networkClientId = hooks.findNetworkClientIdByChainId(\n numberToHex(parseInt(reference, 10)),\n );\n }\n }\n\n if (!networkClientId) {\n console.error(\n 'failed to resolve network client for wallet_invokeMethod',\n request,\n );\n return end(rpcErrors.internal());\n }\n\n Object.assign(request, {\n ...unwrappedRequest,\n networkClientId,\n });\n return next();\n }\n\n try {\n response.result = await hooks.handleNonEvmRequestForOrigin({\n connectedAddresses: scopeObject.accounts,\n // Type assertion: We know that scope is not \"wallet\" by now because it\n // is already being handled above.\n scope: scope as CaipChainId,\n request: unwrappedRequest,\n });\n } catch (err) {\n return end(err as Error);\n }\n return end();\n}\nexport const walletInvokeMethod = {\n methodNames: ['wallet_invokeMethod'],\n implementation: walletInvokeMethodHandler,\n hookNames: {\n getCaveatForOrigin: true,\n findNetworkClientIdByChainId: true,\n getSelectedNetworkClientId: true,\n getNonEvmSupportedMethods: true,\n sortAccountIdsByLastSelected: true,\n handleNonEvmRequestForOrigin: true,\n },\n};\n"]}
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.walletRevokeSessionHandler = exports.walletRevokeSession = void 0;
3
+ exports.walletRevokeSession = void 0;
4
4
  const chain_agnostic_permission_1 = require("@metamask/chain-agnostic-permission");
5
5
  const permission_controller_1 = require("@metamask/permission-controller");
6
6
  const rpc_errors_1 = require("@metamask/rpc-errors");
@@ -73,7 +73,7 @@ function partialRevokePermissions(scopes, hooks) {
73
73
  * @param hooks.getCaveatForOrigin - The hook to fetch an existing caveat for the origin of the request.
74
74
  * @returns Nothing.
75
75
  */
76
- async function handleWalletRevokeSession(request, response, _next, end, hooks) {
76
+ async function walletRevokeSessionHandler(request, response, _next, end, hooks) {
77
77
  try {
78
78
  if (request.params?.scopes?.length) {
79
79
  partialRevokePermissions(request.params.scopes, hooks);
@@ -92,14 +92,12 @@ async function handleWalletRevokeSession(request, response, _next, end, hooks) {
92
92
  return end();
93
93
  }
94
94
  exports.walletRevokeSession = {
95
- implementation: handleWalletRevokeSession,
95
+ methodNames: ['wallet_revokeSession'],
96
+ implementation: walletRevokeSessionHandler,
96
97
  hookNames: {
97
98
  revokePermissionForOrigin: true,
98
99
  updateCaveat: true,
99
100
  getCaveatForOrigin: true,
100
101
  },
101
102
  };
102
- exports.walletRevokeSessionHandler = {
103
- wallet_revokeSession: exports.walletRevokeSession,
104
- };
105
103
  //# sourceMappingURL=wallet-revokeSession.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-revokeSession.cjs","sourceRoot":"","sources":["../../src/handlers/wallet-revokeSession.ts"],"names":[],"mappings":";;;AAAA,mFAK6C;AAM7C,2EAIyC;AACzC,qDAAiD;AACjD,2CAA2C;AAW3C;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,KAAc;IACvC,IACE,CAAC,IAAA,gBAAQ,EAAC,KAAK,CAAC;QAChB,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC;QAClB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAC9B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO;QACL,gDAAwB,CAAC,IAAI;QAC7B,mDAA2B,CAAC,IAAI;KACjC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,wBAAwB,CAC/B,MAAgB,EAChB,KAA+B;IAE/B,IAAI,kBAAkB,GAAG,KAAK,CAAC,kBAAkB,CAC/C,yDAA6B,EAC7B,4CAAgB,CACjB,CAAC,KAAK,CAAC;IAER,KAAK,MAAM,WAAW,IAAI,MAAM,EAAE,CAAC;QACjC,MAAM,MAAM,GAAG,gDAAoB,CAAC,4CAAgB,CAAC,CAAC,WAAW,CAC/D,kBAAkB,EAClB,WAAW,CACZ,CAAC;QAEF,0H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AAG,EAAE,CAAC;AACf,CAAC;AAUY,QAAA,mBAAmB,GAAG;IACjC,cAAc,EAAE,yBAAyB;IACzC,SAAS,EAAE;QACT,yBAAyB,EAAE,IAAI;QAC/B,YAAY,EAAE,IAAI;QAClB,kBAAkB,EAAE,IAAI;KACzB;CACyC,CAAC;AAEhC,QAAA,0BAA0B,GAAG;IACxC,oBAAoB,EAAE,2BAAmB;CAC1C,CAAC","sourcesContent":["import {\n Caip25CaveatMutators,\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n getCaipAccountIdsFromCaip25CaveatValue,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n JsonRpcEngineEndCallback,\n JsonRpcEngineNextCallback,\n MethodHandler,\n} from '@metamask/json-rpc-engine';\nimport {\n CaveatMutatorOperation,\n PermissionDoesNotExistError,\n UnrecognizedSubjectError,\n} from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { isObject } from '@metamask/utils';\nimport type {\n Json,\n JsonRpcRequest,\n PendingJsonRpcResponse,\n} from '@metamask/utils';\n\nimport type { WalletRevokeSessionHooks } from './types';\n\ntype WalletRevokeSessionParams = { scopes?: string[] };\n\n/**\n * Check whether the given error is a permission error.\n *\n * @param error - The error to check.\n * @returns Whether the error is a permission error.\n */\nfunction isPermissionError(error: unknown) {\n if (\n !isObject(error) ||\n !('name' in error) ||\n typeof error.name !== 'string'\n ) {\n return false;\n }\n\n return [\n UnrecognizedSubjectError.name,\n PermissionDoesNotExistError.name,\n ].includes(error.name);\n}\n\n/**\n * Revokes specific session scopes from an existing caveat.\n * Fully revokes permission if no accounts remain permitted after iterating through scopes.\n *\n * @param scopes - Array of scope strings to remove from the caveat.\n * @param hooks - The hooks object.\n * @param hooks.revokePermissionForOrigin - The hook for revoking a permission for an origin function.\n * @param hooks.updateCaveat - The hook used to conditionally update the caveat rather than fully revoke the permission.\n * @param hooks.getCaveatForOrigin - The hook to fetch an existing caveat for the origin of the request.\n */\nfunction partialRevokePermissions(\n scopes: string[],\n hooks: WalletRevokeSessionHooks,\n) {\n let updatedCaveatValue = hooks.getCaveatForOrigin(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n ).value;\n\n for (const scopeString of scopes) {\n const result = Caip25CaveatMutators[Caip25CaveatType].removeScope(\n updatedCaveatValue,\n scopeString,\n );\n\n // If operation is a Noop, it means a scope was passed that was not present in the permission, so we proceed with the loop\n if (result.operation === CaveatMutatorOperation.Noop) {\n continue;\n }\n\n updatedCaveatValue = result?.value ?? {\n requiredScopes: {},\n optionalScopes: {},\n sessionProperties: {},\n isMultichainOrigin: true,\n };\n }\n\n const caipAccountIds =\n getCaipAccountIdsFromCaip25CaveatValue(updatedCaveatValue);\n\n // We fully revoke permission if no accounts are left after scope removal loop.\n if (!caipAccountIds.length) {\n hooks.revokePermissionForOrigin(Caip25EndowmentPermissionName);\n } else {\n hooks.updateCaveat(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n updatedCaveatValue,\n );\n }\n}\n\n/**\n * Handler for the `wallet_revokeSession` RPC method as specified by [CAIP-285](https://chainagnostic.org/CAIPs/caip-285).\n * The implementation below deviates from the linked spec in that it ignores the `sessionId` param\n * and instead revokes the singular session for the origin if available. Additionally,\n * the handler also does not return an error if there is currently no active session and instead\n * returns true which is the same result returned if an active session was actually revoked.\n *\n * @param request - The JSON-RPC request object. Unused.\n * @param response - The JSON-RPC response object.\n * @param _next - The next middleware function. Unused.\n * @param end - The end callback function.\n * @param hooks - The hooks object.\n * @param hooks.revokePermissionForOrigin - The hook for revoking a permission for an origin function.\n * @param hooks.updateCaveat - The hook used to conditionally update the caveat rather than fully revoke the permission.\n * @param hooks.getCaveatForOrigin - The hook to fetch an existing caveat for the origin of the request.\n * @returns Nothing.\n */\nasync function handleWalletRevokeSession(\n request: JsonRpcRequest<WalletRevokeSessionParams> & { origin: string },\n response: PendingJsonRpcResponse<Json>,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: WalletRevokeSessionHooks,\n) {\n try {\n if (request.params?.scopes?.length) {\n partialRevokePermissions(request.params.scopes, hooks);\n } else {\n hooks.revokePermissionForOrigin(Caip25EndowmentPermissionName);\n }\n } catch (err) {\n if (!isPermissionError(err)) {\n console.error(err);\n return end(rpcErrors.internal());\n }\n }\n\n response.result = true;\n return end();\n}\n\ntype WalletRevokeSessionMethodHandler = MethodHandler<\n WalletRevokeSessionHooks,\n never,\n WalletRevokeSessionParams,\n Json,\n { origin: string }\n>;\n\nexport const walletRevokeSession = {\n implementation: handleWalletRevokeSession,\n hookNames: {\n revokePermissionForOrigin: true,\n updateCaveat: true,\n getCaveatForOrigin: true,\n },\n} satisfies WalletRevokeSessionMethodHandler;\n\nexport const walletRevokeSessionHandler = {\n wallet_revokeSession: walletRevokeSession,\n};\n"]}
1
+ {"version":3,"file":"wallet-revokeSession.cjs","sourceRoot":"","sources":["../../src/handlers/wallet-revokeSession.ts"],"names":[],"mappings":";;;AAAA,mFAK6C;AAK7C,2EAIyC;AACzC,qDAAiD;AACjD,2CAA2C;AAK3C;;;;;GAKG;AACH,SAAS,iBAAiB,CAAC,KAAc;IACvC,IACE,CAAC,IAAA,gBAAQ,EAAC,KAAK,CAAC;QAChB,CAAC,CAAC,MAAM,IAAI,KAAK,CAAC;QAClB,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,EAC9B,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IAED,OAAO;QACL,gDAAwB,CAAC,IAAI;QAC7B,mDAA2B,CAAC,IAAI;KACjC,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,wBAAwB,CAC/B,MAAgB,EAChB,KAA+B;IAE/B,IAAI,kBAAkB,GAAG,KAAK,CAAC,kBAAkB,CAC/C,yDAA6B,EAC7B,4CAAgB,CACjB,CAAC,KAAK,CAAC;IAER,KAAK,MAAM,WAAW,IAAI,MAAM,EAAE,CAAC;QACjC,M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QAAQ,EAAE,CAAC,CAAC;QACnC,CAAC;IACH,CAAC;IAED,QAAQ,CAAC,MAAM,GAAG,IAAI,CAAC;IACvB,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AACY,QAAA,mBAAmB,GAAG;IACjC,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrC,cAAc,EAAE,0BAA0B;IAC1C,SAAS,EAAE;QACT,yBAAyB,EAAE,IAAI;QAC/B,YAAY,EAAE,IAAI;QAClB,kBAAkB,EAAE,IAAI;KACzB;CACF,CAAC","sourcesContent":["import {\n Caip25CaveatMutators,\n Caip25CaveatType,\n Caip25EndowmentPermissionName,\n getCaipAccountIdsFromCaip25CaveatValue,\n} from '@metamask/chain-agnostic-permission';\nimport type {\n JsonRpcEngineNextCallback,\n JsonRpcEngineEndCallback,\n} from '@metamask/json-rpc-engine';\nimport {\n CaveatMutatorOperation,\n PermissionDoesNotExistError,\n UnrecognizedSubjectError,\n} from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { isObject } from '@metamask/utils';\nimport type { JsonRpcSuccess, JsonRpcRequest } from '@metamask/utils';\n\nimport type { WalletRevokeSessionHooks } from './types';\n\n/**\n * Check whether the given error is a permission error.\n *\n * @param error - The error to check.\n * @returns Whether the error is a permission error.\n */\nfunction isPermissionError(error: unknown) {\n if (\n !isObject(error) ||\n !('name' in error) ||\n typeof error.name !== 'string'\n ) {\n return false;\n }\n\n return [\n UnrecognizedSubjectError.name,\n PermissionDoesNotExistError.name,\n ].includes(error.name);\n}\n\n/**\n * Revokes specific session scopes from an existing caveat.\n * Fully revokes permission if no accounts remain permitted after iterating through scopes.\n *\n * @param scopes - Array of scope strings to remove from the caveat.\n * @param hooks - The hooks object.\n * @param hooks.revokePermissionForOrigin - The hook for revoking a permission for an origin function.\n * @param hooks.updateCaveat - The hook used to conditionally update the caveat rather than fully revoke the permission.\n * @param hooks.getCaveatForOrigin - The hook to fetch an existing caveat for the origin of the request.\n */\nfunction partialRevokePermissions(\n scopes: string[],\n hooks: WalletRevokeSessionHooks,\n) {\n let updatedCaveatValue = hooks.getCaveatForOrigin(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n ).value;\n\n for (const scopeString of scopes) {\n const result = Caip25CaveatMutators[Caip25CaveatType].removeScope(\n updatedCaveatValue,\n scopeString,\n );\n\n // If operation is a Noop, it means a scope was passed that was not present in the permission, so we proceed with the loop\n if (result.operation === CaveatMutatorOperation.Noop) {\n continue;\n }\n\n updatedCaveatValue = result?.value ?? {\n requiredScopes: {},\n optionalScopes: {},\n sessionProperties: {},\n isMultichainOrigin: true,\n };\n }\n\n const caipAccountIds =\n getCaipAccountIdsFromCaip25CaveatValue(updatedCaveatValue);\n\n // We fully revoke permission if no accounts are left after scope removal loop.\n if (!caipAccountIds.length) {\n hooks.revokePermissionForOrigin(Caip25EndowmentPermissionName);\n } else {\n hooks.updateCaveat(\n Caip25EndowmentPermissionName,\n Caip25CaveatType,\n updatedCaveatValue,\n );\n }\n}\n\n/**\n * Handler for the `wallet_revokeSession` RPC method as specified by [CAIP-285](https://chainagnostic.org/CAIPs/caip-285).\n * The implementation below deviates from the linked spec in that it ignores the `sessionId` param\n * and instead revokes the singular session for the origin if available. Additionally,\n * the handler also does not return an error if there is currently no active session and instead\n * returns true which is the same result returned if an active session was actually revoked.\n *\n * @param request - The JSON-RPC request object. Unused.\n * @param response - The JSON-RPC response object.\n * @param _next - The next middleware function. Unused.\n * @param end - The end callback function.\n * @param hooks - The hooks object.\n * @param hooks.revokePermissionForOrigin - The hook for revoking a permission for an origin function.\n * @param hooks.updateCaveat - The hook used to conditionally update the caveat rather than fully revoke the permission.\n * @param hooks.getCaveatForOrigin - The hook to fetch an existing caveat for the origin of the request.\n * @returns Nothing.\n */\nasync function walletRevokeSessionHandler(\n request: JsonRpcRequest & {\n origin: string;\n params: { scopes?: string[] };\n },\n response: JsonRpcSuccess,\n _next: JsonRpcEngineNextCallback,\n end: JsonRpcEngineEndCallback,\n hooks: WalletRevokeSessionHooks,\n) {\n try {\n if (request.params?.scopes?.length) {\n partialRevokePermissions(request.params.scopes, hooks);\n } else {\n hooks.revokePermissionForOrigin(Caip25EndowmentPermissionName);\n }\n } catch (err) {\n if (!isPermissionError(err)) {\n console.error(err);\n return end(rpcErrors.internal());\n }\n }\n\n response.result = true;\n return end();\n}\nexport const walletRevokeSession = {\n methodNames: ['wallet_revokeSession'],\n implementation: walletRevokeSessionHandler,\n hookNames: {\n revokePermissionForOrigin: true,\n updateCaveat: true,\n getCaveatForOrigin: true,\n },\n};\n"]}
@@ -1,9 +1,6 @@
1
- import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
2
- import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
1
+ import type { JsonRpcEngineNextCallback, JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
2
+ import type { JsonRpcSuccess, JsonRpcRequest } from "@metamask/utils";
3
3
  import type { WalletRevokeSessionHooks } from "./types.cjs";
4
- type WalletRevokeSessionParams = {
5
- scopes?: string[];
6
- };
7
4
  /**
8
5
  * Handler for the `wallet_revokeSession` RPC method as specified by [CAIP-285](https://chainagnostic.org/CAIPs/caip-285).
9
6
  * The implementation below deviates from the linked spec in that it ignores the `sessionId` param
@@ -21,25 +18,19 @@ type WalletRevokeSessionParams = {
21
18
  * @param hooks.getCaveatForOrigin - The hook to fetch an existing caveat for the origin of the request.
22
19
  * @returns Nothing.
23
20
  */
24
- declare function handleWalletRevokeSession(request: JsonRpcRequest<WalletRevokeSessionParams> & {
21
+ declare function walletRevokeSessionHandler(request: JsonRpcRequest & {
25
22
  origin: string;
26
- }, response: PendingJsonRpcResponse<Json>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: WalletRevokeSessionHooks): Promise<void>;
23
+ params: {
24
+ scopes?: string[];
25
+ };
26
+ }, response: JsonRpcSuccess, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: WalletRevokeSessionHooks): Promise<void>;
27
27
  export declare const walletRevokeSession: {
28
- implementation: typeof handleWalletRevokeSession;
28
+ methodNames: string[];
29
+ implementation: typeof walletRevokeSessionHandler;
29
30
  hookNames: {
30
- revokePermissionForOrigin: true;
31
- updateCaveat: true;
32
- getCaveatForOrigin: true;
33
- };
34
- };
35
- export declare const walletRevokeSessionHandler: {
36
- wallet_revokeSession: {
37
- implementation: typeof handleWalletRevokeSession;
38
- hookNames: {
39
- revokePermissionForOrigin: true;
40
- updateCaveat: true;
41
- getCaveatForOrigin: true;
42
- };
31
+ revokePermissionForOrigin: boolean;
32
+ updateCaveat: boolean;
33
+ getCaveatForOrigin: boolean;
43
34
  };
44
35
  };
45
36
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-revokeSession.d.cts","sourceRoot":"","sources":["../../src/handlers/wallet-revokeSession.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAE1B,kCAAkC;AAQnC,OAAO,KAAK,EACV,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,OAAO,KAAK,EAAE,wBAAwB,EAAE,oBAAgB;AAExD,KAAK,yBAAyB,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AA4EvD;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAe,yBAAyB,CACtC,OAAO,EAAE,cAAc,CAAC,yBAAyB,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EACvE,QAAQ,EAAE,sBAAsB,CAAC,IAAI,CAAC,EACtC,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,wBAAwB,iBAiBhC;AAUD,eAAO,MAAM,mBAAmB;;;;;;;CAOY,CAAC;AAE7C,eAAO,MAAM,0BAA0B;;;;;;;;;CAEtC,CAAC"}
1
+ {"version":3,"file":"wallet-revokeSession.d.cts","sourceRoot":"","sources":["../../src/handlers/wallet-revokeSession.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,yBAAyB,EACzB,wBAAwB,EACzB,kCAAkC;AAQnC,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,wBAAwB;AAEtE,OAAO,KAAK,EAAE,wBAAwB,EAAE,oBAAgB;AA4ExD;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAe,0BAA0B,CACvC,OAAO,EAAE,cAAc,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE;QAAE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;KAAE,CAAC;CAC/B,EACD,QAAQ,EAAE,cAAc,EACxB,KAAK,EAAE,yBAAyB,EAChC,GAAG,EAAE,wBAAwB,EAC7B,KAAK,EAAE,wBAAwB,iBAiBhC;AACD,eAAO,MAAM,mBAAmB;;;;;;;;CAQ/B,CAAC"}
@@ -1,9 +1,6 @@
1
- import type { JsonRpcEngineEndCallback, JsonRpcEngineNextCallback } from "@metamask/json-rpc-engine";
2
- import type { Json, JsonRpcRequest, PendingJsonRpcResponse } from "@metamask/utils";
1
+ import type { JsonRpcEngineNextCallback, JsonRpcEngineEndCallback } from "@metamask/json-rpc-engine";
2
+ import type { JsonRpcSuccess, JsonRpcRequest } from "@metamask/utils";
3
3
  import type { WalletRevokeSessionHooks } from "./types.mjs";
4
- type WalletRevokeSessionParams = {
5
- scopes?: string[];
6
- };
7
4
  /**
8
5
  * Handler for the `wallet_revokeSession` RPC method as specified by [CAIP-285](https://chainagnostic.org/CAIPs/caip-285).
9
6
  * The implementation below deviates from the linked spec in that it ignores the `sessionId` param
@@ -21,25 +18,19 @@ type WalletRevokeSessionParams = {
21
18
  * @param hooks.getCaveatForOrigin - The hook to fetch an existing caveat for the origin of the request.
22
19
  * @returns Nothing.
23
20
  */
24
- declare function handleWalletRevokeSession(request: JsonRpcRequest<WalletRevokeSessionParams> & {
21
+ declare function walletRevokeSessionHandler(request: JsonRpcRequest & {
25
22
  origin: string;
26
- }, response: PendingJsonRpcResponse<Json>, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: WalletRevokeSessionHooks): Promise<void>;
23
+ params: {
24
+ scopes?: string[];
25
+ };
26
+ }, response: JsonRpcSuccess, _next: JsonRpcEngineNextCallback, end: JsonRpcEngineEndCallback, hooks: WalletRevokeSessionHooks): Promise<void>;
27
27
  export declare const walletRevokeSession: {
28
- implementation: typeof handleWalletRevokeSession;
28
+ methodNames: string[];
29
+ implementation: typeof walletRevokeSessionHandler;
29
30
  hookNames: {
30
- revokePermissionForOrigin: true;
31
- updateCaveat: true;
32
- getCaveatForOrigin: true;
33
- };
34
- };
35
- export declare const walletRevokeSessionHandler: {
36
- wallet_revokeSession: {
37
- implementation: typeof handleWalletRevokeSession;
38
- hookNames: {
39
- revokePermissionForOrigin: true;
40
- updateCaveat: true;
41
- getCaveatForOrigin: true;
42
- };
31
+ revokePermissionForOrigin: boolean;
32
+ updateCaveat: boolean;
33
+ getCaveatForOrigin: boolean;
43
34
  };
44
35
  };
45
36
  export {};
@@ -1 +1 @@
1
- {"version":3,"file":"wallet-revokeSession.d.mts","sourceRoot":"","sources":["../../src/handlers/wallet-revokeSession.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,wBAAwB,EACxB,yBAAyB,EAE1B,kCAAkC;AAQnC,OAAO,KAAK,EACV,IAAI,EACJ,cAAc,EACd,sBAAsB,EACvB,wBAAwB;AAEzB,OAAO,KAAK,EAAE,wBAAwB,EAAE,oBAAgB;AAExD,KAAK,yBAAyB,GAAG;IAAE,MAAM,CAAC,EAAE,MAAM,EAAE,CAAA;CAAE,CAAC;AA4EvD;;;;;;;;;;;;;;;;GAgBG;AACH,iBAAe,yBAAyB,CACtC,OAAO,EAAE,cAAc,CAAC,yBAAyB,CAAC,GAAG;IAAE,MAAM,EAAE,MAAM,CAAA;CAAE,EACvE,QAAQ,EAAE,sBAAsB,CAAC,IAAI,CAAC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