@metamask/snaps-rpc-methods 12.0.0 → 12.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/dist/endowments/index.cjs +1 -0
  3. package/dist/endowments/index.cjs.map +1 -1
  4. package/dist/endowments/index.d.cts.map +1 -1
  5. package/dist/endowments/index.d.mts.map +1 -1
  6. package/dist/endowments/index.mjs +1 -0
  7. package/dist/endowments/index.mjs.map +1 -1
  8. package/dist/permitted/createInterface.d.cts +44 -44
  9. package/dist/permitted/createInterface.d.mts +44 -44
  10. package/dist/permitted/experimentalProviderRequest.cjs +7 -1
  11. package/dist/permitted/experimentalProviderRequest.cjs.map +1 -1
  12. package/dist/permitted/experimentalProviderRequest.d.cts +3 -3
  13. package/dist/permitted/experimentalProviderRequest.d.mts +3 -3
  14. package/dist/permitted/experimentalProviderRequest.mjs +7 -1
  15. package/dist/permitted/experimentalProviderRequest.mjs.map +1 -1
  16. package/dist/permitted/getFile.d.cts +2 -2
  17. package/dist/permitted/getFile.d.mts +2 -2
  18. package/dist/permitted/getState.cjs +7 -1
  19. package/dist/permitted/getState.cjs.map +1 -1
  20. package/dist/permitted/getState.d.cts +1 -1
  21. package/dist/permitted/getState.d.cts.map +1 -1
  22. package/dist/permitted/getState.d.mts +1 -1
  23. package/dist/permitted/getState.d.mts.map +1 -1
  24. package/dist/permitted/getState.mjs +7 -1
  25. package/dist/permitted/getState.mjs.map +1 -1
  26. package/dist/permitted/handlers.cjs +2 -0
  27. package/dist/permitted/handlers.cjs.map +1 -1
  28. package/dist/permitted/handlers.d.cts +18 -1
  29. package/dist/permitted/handlers.d.cts.map +1 -1
  30. package/dist/permitted/handlers.d.mts +18 -1
  31. package/dist/permitted/handlers.d.mts.map +1 -1
  32. package/dist/permitted/handlers.mjs +2 -0
  33. package/dist/permitted/handlers.mjs.map +1 -1
  34. package/dist/permitted/invokeKeyring.cjs +7 -1
  35. package/dist/permitted/invokeKeyring.cjs.map +1 -1
  36. package/dist/permitted/invokeKeyring.mjs +7 -1
  37. package/dist/permitted/invokeKeyring.mjs.map +1 -1
  38. package/dist/permitted/invokeSnapSugar.cjs +7 -1
  39. package/dist/permitted/invokeSnapSugar.cjs.map +1 -1
  40. package/dist/permitted/invokeSnapSugar.d.cts.map +1 -1
  41. package/dist/permitted/invokeSnapSugar.d.mts.map +1 -1
  42. package/dist/permitted/invokeSnapSugar.mjs +7 -1
  43. package/dist/permitted/invokeSnapSugar.mjs.map +1 -1
  44. package/dist/permitted/scheduleBackgroundEvent.cjs +2 -19
  45. package/dist/permitted/scheduleBackgroundEvent.cjs.map +1 -1
  46. package/dist/permitted/scheduleBackgroundEvent.d.cts +4 -4
  47. package/dist/permitted/scheduleBackgroundEvent.d.cts.map +1 -1
  48. package/dist/permitted/scheduleBackgroundEvent.d.mts +4 -4
  49. package/dist/permitted/scheduleBackgroundEvent.d.mts.map +1 -1
  50. package/dist/permitted/scheduleBackgroundEvent.mjs +4 -21
  51. package/dist/permitted/scheduleBackgroundEvent.mjs.map +1 -1
  52. package/dist/permitted/setState.d.cts +1 -1
  53. package/dist/permitted/setState.d.mts +1 -1
  54. package/dist/permitted/trackEvent.cjs +89 -0
  55. package/dist/permitted/trackEvent.cjs.map +1 -0
  56. package/dist/permitted/trackEvent.d.cts +47 -0
  57. package/dist/permitted/trackEvent.d.cts.map +1 -0
  58. package/dist/permitted/trackEvent.d.mts +47 -0
  59. package/dist/permitted/trackEvent.d.mts.map +1 -0
  60. package/dist/permitted/trackEvent.mjs +86 -0
  61. package/dist/permitted/trackEvent.mjs.map +1 -0
  62. package/dist/permitted/updateInterface.d.cts +44 -44
  63. package/dist/permitted/updateInterface.d.mts +44 -44
  64. package/dist/restricted/dialog.d.cts +91 -147
  65. package/dist/restricted/dialog.d.cts.map +1 -1
  66. package/dist/restricted/dialog.d.mts +91 -147
  67. package/dist/restricted/dialog.d.mts.map +1 -1
  68. package/dist/restricted/getBip32PublicKey.d.cts +2 -2
  69. package/dist/restricted/getBip32PublicKey.d.mts +2 -2
  70. package/dist/restricted/getEntropy.d.cts +1 -1
  71. package/dist/restricted/getEntropy.d.mts +1 -1
  72. package/dist/restricted/manageAccounts.d.cts +1 -1
  73. package/dist/restricted/manageAccounts.d.mts +1 -1
  74. package/dist/restricted/notify.d.cts +74 -74
  75. package/dist/restricted/notify.d.mts +74 -74
  76. package/package.json +8 -8
@@ -89,7 +89,13 @@ const ProviderRequestParametersStruct = (0, superstruct_1.object)({
89
89
  * @param hooks.getNetworkClientById - Get a network client for a given ID.
90
90
  * @returns Nothing.
91
91
  */
92
- async function providerRequestImplementation(req, res, _next, end, { hasPermission, getNetworkConfigurationByChainId, getNetworkClientById, }) {
92
+ async function providerRequestImplementation(req,
93
+ // `ProviderRequestResult` is an alias for `Json` (which is the default type
94
+ // argument for `PendingJsonRpcResponse`), but that may not be the case in the
95
+ // future. We use `ProviderRequestResult` here to make it clear that this is
96
+ // the expected type of the result.
97
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments
98
+ res, _next, end, { hasPermission, getNetworkConfigurationByChainId, getNetworkClientById, }) {
93
99
  if (!hasPermission(endowments_1.SnapEndowments.EthereumProvider)) {
94
100
  return end(rpc_errors_1.rpcErrors.methodNotFound());
95
101
  }
@@ -1 +1 @@
1
- {"version":3,"file":"experimentalProviderRequest.cjs","sourceRoot":"","sources":["../../src/permitted/experimentalProviderRequest.ts"],"names":[],"mappings":";;;AAEA,qDAAiD;AAOjD,uDAO+B;AAC/B,2CAOyB;AAEzB,wDAA+C;AAG/C,oEAAoE;AACpE,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,iBAAiB;IACjB,UAAU;IACV,aAAa;IACb,cAAc;IACd,iBAAiB;IACjB,gBAAgB;IAChB,cAAc;IACd,gBAAgB;IAChB,oBAAoB;IACpB,sBAAsB;IACtB,oCAAoC;IACpC,sCAAsC;IACtC,aAAa;IACb,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;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,+BAA+B,CAAC,CAAC;IACzD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,yBAAW,EAAE,CAAC;YACjC,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,sBAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n JsonRpcRequest,\n ProviderRequestParams,\n ProviderRequestResult,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n StructError,\n create,\n object,\n optional,\n string,\n type,\n} from '@metamask/superstruct';\nimport {\n bigIntToHex,\n parseCaipChainId,\n type PendingJsonRpcResponse,\n type Json,\n CaipChainIdStruct,\n JsonRpcParamsStruct,\n} from '@metamask/utils';\n\nimport { SnapEndowments } from '../endowments';\nimport type { MethodHooksObject } from '../utils';\n\n// Read-only methods that are currently allowed for this RPC method.\nconst METHOD_ALLOWLIST = Object.freeze([\n 'eth_blockNumber',\n 'eth_call',\n 'eth_chainId',\n 'eth_coinbase',\n 'eth_estimateGas',\n 'eth_feeHistory',\n 'eth_gasPrice',\n 'eth_getBalance',\n 'eth_getBlockByHash',\n 'eth_getBlockByNumber',\n 'eth_getBlockTransactionCountByHash',\n 'eth_getBlockTransactionCountByNumber',\n 'eth_getCode',\n 'eth_getFilterChanges',\n 'eth_getFilterLogs',\n 'eth_getLogs',\n 'eth_getProof',\n 'eth_getStorageAt',\n 'eth_getTransactionByBlockHashAndIndex',\n 'eth_getTransactionByBlockNumberAndIndex',\n 'eth_getTransactionByHash',\n 'eth_getTransactionCount',\n 'eth_getTransactionReceipt',\n 'eth_getUncleByBlockHashAndIndex',\n 'eth_getUncleByBlockNumberAndIndex',\n 'eth_getUncleCountByBlockHash',\n 'eth_getUncleCountByBlockNumber',\n 'eth_getWork',\n 'eth_hashrate',\n 'eth_mining',\n 'eth_newBlockFilter',\n 'eth_newFilter',\n 'eth_newPendingTransactionFilter',\n 'eth_protocolVersion',\n 'eth_sendRawTransaction',\n 'eth_submitHashrate',\n 'eth_submitWork',\n 'eth_syncing',\n 'eth_uninstallFilter',\n 'net_listening',\n 'net_peerCount',\n 'net_version',\n 'web3_clientVersion',\n 'web3_sha3',\n]);\n\nconst hookNames: MethodHooksObject<ProviderRequestMethodHooks> = {\n hasPermission: true,\n getNetworkConfigurationByChainId: true,\n getNetworkClientById: true,\n};\n\ntype NetworkConfiguration = {\n defaultRpcEndpointIndex: number;\n rpcEndpoints: { networkClientId: string }[];\n};\n\nexport type ProviderRequestMethodHooks = {\n hasPermission: (permissionName: string) => boolean;\n\n getNetworkConfigurationByChainId: (\n chainId: string,\n ) => NetworkConfiguration | undefined;\n\n getNetworkClientById: (id: string) => {\n provider: { request: (request: Json) => Promise<Json> };\n };\n};\n\nexport const providerRequestHandler: PermittedHandlerExport<\n ProviderRequestMethodHooks,\n ProviderRequestParameters,\n ProviderRequestResult\n> = {\n methodNames: ['snap_experimentalProviderRequest'],\n implementation: providerRequestImplementation,\n hookNames,\n};\n\nconst ProviderRequestParametersStruct = object({\n chainId: CaipChainIdStruct,\n request: type({\n method: string(),\n params: optional(JsonRpcParamsStruct),\n }),\n});\n\nexport type ProviderRequestParameters = InferMatching<\n typeof ProviderRequestParametersStruct,\n ProviderRequestParams\n>;\n\n/**\n * The `snap_experimentalProviderRequest` method implementation.\n *\n * This RPC method lets Snaps make requests to MetaMask networks that are not currently selected in the UI.\n *\n * The RPC method requires the caller to have the endowment:ethereum-provider permission.\n *\n * NOTE: This implementation is experimental and may be removed or changed without warning.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.hasPermission - Checks whether a given origin has a given permission.\n * @param hooks.getNetworkConfigurationByChainId - Get a network configuration for a given chain ID.\n * @param hooks.getNetworkClientById - Get a network client for a given ID.\n * @returns Nothing.\n */\nasync function providerRequestImplementation(\n req: JsonRpcRequest<ProviderRequestParams>,\n res: PendingJsonRpcResponse<ProviderRequestResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n {\n hasPermission,\n getNetworkConfigurationByChainId,\n getNetworkClientById,\n }: ProviderRequestMethodHooks,\n): Promise<void> {\n if (!hasPermission(SnapEndowments.EthereumProvider)) {\n return end(rpcErrors.methodNotFound());\n }\n\n const { params } = req;\n\n try {\n const { chainId, request } = getValidatedParams(params);\n\n if (!METHOD_ALLOWLIST.includes(request.method)) {\n return end(rpcErrors.methodNotFound());\n }\n\n const parsedChainId = parseCaipChainId(chainId);\n\n if (parsedChainId.namespace !== 'eip155') {\n return end(\n rpcErrors.invalidParams({\n message: 'Only EVM networks are currently supported.',\n }),\n );\n }\n\n const numericalChainId = BigInt(parsedChainId.reference);\n\n const networkConfiguration = getNetworkConfigurationByChainId(\n bigIntToHex(numericalChainId),\n );\n\n if (!networkConfiguration) {\n return end(\n rpcErrors.invalidParams({\n message: 'The requested network is not available.',\n }),\n );\n }\n\n const rpc =\n networkConfiguration.rpcEndpoints[\n networkConfiguration.defaultRpcEndpointIndex\n ];\n\n const networkClient = getNetworkClientById(rpc.networkClientId);\n\n const { provider } = networkClient;\n\n res.result = await provider.request(request);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated updateInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): ProviderRequestParameters {\n try {\n return create(params, ProviderRequestParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
1
+ {"version":3,"file":"experimentalProviderRequest.cjs","sourceRoot":"","sources":["../../src/permitted/experimentalProviderRequest.ts"],"names":[],"mappings":";;;AAEA,qDAAiD;AAOjD,uDAO+B;AAC/B,2CAOyB;AAEzB,wDAA+C;AAG/C,oEAAoE;AACpE,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,iBAAiB;IACjB,UAAU;IACV,aAAa;IACb,cAAc;IACd,iBAAiB;IACjB,gBAAgB;IAChB,cAAc;IACd,gBAAgB;IAChB,oBAAoB;IACpB,sBAAsB;IACtB,oCAAoC;IACpC,sCAAsC;IACtC,aAAa;IACb,sBAAsB;IACtB,mBAAmB;IACnB,aAAa;IACb,cAAc;IACd,kBAAkB;IAClB,uCAAuC;IACvC,yCAAyC;IACzC,0BAA0B;IAC1B,yBAAyB;IACzB,2BAA2B;IAC3B,iCAAiC;IACjC,mCAAmC;IACnC,8BAA8B;IAC9B,gCAAgC;IAChC,aAAa;IACb,cAAc;IACd,YAAY;IACZ,oBAAoB;IACpB,eAAe;IACf,iCAAiC;IACjC,qBAAqB;IACrB,wBAAwB;IACxB,oBAAoB;IACpB,gBAAgB;IAChB,aAAa;IACb,qBAAqB;IACrB,eAAe;IACf,eAAe;IACf,aAAa;IACb,oBAAoB;IACpB,WAAW;CACZ,CAAC,CAAC;AAEH,MAAM,SAAS,GAAkD;IAC/D,aAAa,EAAE,IAAI;IACnB,gCAAgC,EAAE,IAAI;IACtC,oBAAoB,EAAE,IAAI;CAC3B,CAAC;AAmBW,QAAA,sBAAsB,GAI/B;IACF,WAAW,EAAE,CAAC,kCAAkC,CAAC;IACjD,cAAc,EAAE,6BAA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AC,CAAC;QAEzD,MAAM,oBAAoB,GAAG,gCAAgC,CAC3D,IAAA,mBAAW,EAAC,gBAAgB,CAAC,CAC9B,CAAC;QAEF,IAAI,CAAC,oBAAoB,EAAE,CAAC;YAC1B,OAAO,GAAG,CACR,sBAAS,CAAC,aAAa,CAAC;gBACtB,OAAO,EAAE,yCAAyC;aACnD,CAAC,CACH,CAAC;QACJ,CAAC;QAED,MAAM,GAAG,GACP,oBAAoB,CAAC,YAAY,CAC/B,oBAAoB,CAAC,uBAAuB,CAC7C,CAAC;QAEJ,MAAM,aAAa,GAAG,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAEhE,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAa,CAAC;QAEnC,GAAG,CAAC,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,IAAA,oBAAM,EAAC,MAAM,EAAE,+BAA+B,CAAC,CAAC;IACzD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,yBAAW,EAAE,CAAC;YACjC,MAAM,sBAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,sBAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n JsonRpcRequest,\n ProviderRequestParams,\n ProviderRequestResult,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n StructError,\n create,\n object,\n optional,\n string,\n type,\n} from '@metamask/superstruct';\nimport {\n bigIntToHex,\n parseCaipChainId,\n type PendingJsonRpcResponse,\n type Json,\n CaipChainIdStruct,\n JsonRpcParamsStruct,\n} from '@metamask/utils';\n\nimport { SnapEndowments } from '../endowments';\nimport type { MethodHooksObject } from '../utils';\n\n// Read-only methods that are currently allowed for this RPC method.\nconst METHOD_ALLOWLIST = Object.freeze([\n 'eth_blockNumber',\n 'eth_call',\n 'eth_chainId',\n 'eth_coinbase',\n 'eth_estimateGas',\n 'eth_feeHistory',\n 'eth_gasPrice',\n 'eth_getBalance',\n 'eth_getBlockByHash',\n 'eth_getBlockByNumber',\n 'eth_getBlockTransactionCountByHash',\n 'eth_getBlockTransactionCountByNumber',\n 'eth_getCode',\n 'eth_getFilterChanges',\n 'eth_getFilterLogs',\n 'eth_getLogs',\n 'eth_getProof',\n 'eth_getStorageAt',\n 'eth_getTransactionByBlockHashAndIndex',\n 'eth_getTransactionByBlockNumberAndIndex',\n 'eth_getTransactionByHash',\n 'eth_getTransactionCount',\n 'eth_getTransactionReceipt',\n 'eth_getUncleByBlockHashAndIndex',\n 'eth_getUncleByBlockNumberAndIndex',\n 'eth_getUncleCountByBlockHash',\n 'eth_getUncleCountByBlockNumber',\n 'eth_getWork',\n 'eth_hashrate',\n 'eth_mining',\n 'eth_newBlockFilter',\n 'eth_newFilter',\n 'eth_newPendingTransactionFilter',\n 'eth_protocolVersion',\n 'eth_sendRawTransaction',\n 'eth_submitHashrate',\n 'eth_submitWork',\n 'eth_syncing',\n 'eth_uninstallFilter',\n 'net_listening',\n 'net_peerCount',\n 'net_version',\n 'web3_clientVersion',\n 'web3_sha3',\n]);\n\nconst hookNames: MethodHooksObject<ProviderRequestMethodHooks> = {\n hasPermission: true,\n getNetworkConfigurationByChainId: true,\n getNetworkClientById: true,\n};\n\ntype NetworkConfiguration = {\n defaultRpcEndpointIndex: number;\n rpcEndpoints: { networkClientId: string }[];\n};\n\nexport type ProviderRequestMethodHooks = {\n hasPermission: (permissionName: string) => boolean;\n\n getNetworkConfigurationByChainId: (\n chainId: string,\n ) => NetworkConfiguration | undefined;\n\n getNetworkClientById: (id: string) => {\n provider: { request: (request: Json) => Promise<Json> };\n };\n};\n\nexport const providerRequestHandler: PermittedHandlerExport<\n ProviderRequestMethodHooks,\n ProviderRequestParameters,\n ProviderRequestResult\n> = {\n methodNames: ['snap_experimentalProviderRequest'],\n implementation: providerRequestImplementation,\n hookNames,\n};\n\nconst ProviderRequestParametersStruct = object({\n chainId: CaipChainIdStruct,\n request: type({\n method: string(),\n params: optional(JsonRpcParamsStruct),\n }),\n});\n\nexport type ProviderRequestParameters = InferMatching<\n typeof ProviderRequestParametersStruct,\n ProviderRequestParams\n>;\n\n/**\n * The `snap_experimentalProviderRequest` method implementation.\n *\n * This RPC method lets Snaps make requests to MetaMask networks that are not currently selected in the UI.\n *\n * The RPC method requires the caller to have the endowment:ethereum-provider permission.\n *\n * NOTE: This implementation is experimental and may be removed or changed without warning.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.hasPermission - Checks whether a given origin has a given permission.\n * @param hooks.getNetworkConfigurationByChainId - Get a network configuration for a given chain ID.\n * @param hooks.getNetworkClientById - Get a network client for a given ID.\n * @returns Nothing.\n */\nasync function providerRequestImplementation(\n req: JsonRpcRequest<ProviderRequestParams>,\n // `ProviderRequestResult` is an alias for `Json` (which is the default type\n // argument for `PendingJsonRpcResponse`), but that may not be the case in the\n // future. We use `ProviderRequestResult` here to make it clear that this is\n // the expected type of the result.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\n res: PendingJsonRpcResponse<ProviderRequestResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n {\n hasPermission,\n getNetworkConfigurationByChainId,\n getNetworkClientById,\n }: ProviderRequestMethodHooks,\n): Promise<void> {\n if (!hasPermission(SnapEndowments.EthereumProvider)) {\n return end(rpcErrors.methodNotFound());\n }\n\n const { params } = req;\n\n try {\n const { chainId, request } = getValidatedParams(params);\n\n if (!METHOD_ALLOWLIST.includes(request.method)) {\n return end(rpcErrors.methodNotFound());\n }\n\n const parsedChainId = parseCaipChainId(chainId);\n\n if (parsedChainId.namespace !== 'eip155') {\n return end(\n rpcErrors.invalidParams({\n message: 'Only EVM networks are currently supported.',\n }),\n );\n }\n\n const numericalChainId = BigInt(parsedChainId.reference);\n\n const networkConfiguration = getNetworkConfigurationByChainId(\n bigIntToHex(numericalChainId),\n );\n\n if (!networkConfiguration) {\n return end(\n rpcErrors.invalidParams({\n message: 'The requested network is not available.',\n }),\n );\n }\n\n const rpc =\n networkConfiguration.rpcEndpoints[\n networkConfiguration.defaultRpcEndpointIndex\n ];\n\n const networkClient = getNetworkClientById(rpc.networkClientId);\n\n const { provider } = networkClient;\n\n res.result = await provider.request(request);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated updateInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): ProviderRequestParameters {\n try {\n return create(params, ProviderRequestParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
@@ -21,17 +21,17 @@ export declare const providerRequestHandler: PermittedHandlerExport<ProviderRequ
21
21
  declare const ProviderRequestParametersStruct: import("@metamask/superstruct").Struct<{
22
22
  request: {
23
23
  method: string;
24
- params?: Record<string, Json> | Json[] | undefined;
24
+ params?: Json[] | Record<string, Json> | undefined;
25
25
  };
26
26
  chainId: `${string}:${string}`;
27
27
  }, {
28
28
  chainId: import("@metamask/superstruct").Struct<`${string}:${string}`, null>;
29
29
  request: import("@metamask/superstruct").Struct<{
30
30
  method: string;
31
- params?: Record<string, Json> | Json[] | undefined;
31
+ params?: Json[] | Record<string, Json> | undefined;
32
32
  }, {
33
33
  method: import("@metamask/superstruct").Struct<string, null>;
34
- params: import("@metamask/superstruct").Struct<Record<string, Json> | Json[] | undefined, null>;
34
+ params: import("@metamask/superstruct").Struct<Json[] | Record<string, Json> | undefined, null>;
35
35
  }>;
36
36
  }>;
37
37
  export type ProviderRequestParameters = InferMatching<typeof ProviderRequestParametersStruct, ProviderRequestParams>;
@@ -21,17 +21,17 @@ export declare const providerRequestHandler: PermittedHandlerExport<ProviderRequ
21
21
  declare const ProviderRequestParametersStruct: import("@metamask/superstruct").Struct<{
22
22
  request: {
23
23
  method: string;
24
- params?: Record<string, Json> | Json[] | undefined;
24
+ params?: Json[] | Record<string, Json> | undefined;
25
25
  };
26
26
  chainId: `${string}:${string}`;
27
27
  }, {
28
28
  chainId: import("@metamask/superstruct").Struct<`${string}:${string}`, null>;
29
29
  request: import("@metamask/superstruct").Struct<{
30
30
  method: string;
31
- params?: Record<string, Json> | Json[] | undefined;
31
+ params?: Json[] | Record<string, Json> | undefined;
32
32
  }, {
33
33
  method: import("@metamask/superstruct").Struct<string, null>;
34
- params: import("@metamask/superstruct").Struct<Record<string, Json> | Json[] | undefined, null>;
34
+ params: import("@metamask/superstruct").Struct<Json[] | Record<string, Json> | undefined, null>;
35
35
  }>;
36
36
  }>;
37
37
  export type ProviderRequestParameters = InferMatching<typeof ProviderRequestParametersStruct, ProviderRequestParams>;
@@ -86,7 +86,13 @@ const ProviderRequestParametersStruct = object({
86
86
  * @param hooks.getNetworkClientById - Get a network client for a given ID.
87
87
  * @returns Nothing.
88
88
  */
89
- async function providerRequestImplementation(req, res, _next, end, { hasPermission, getNetworkConfigurationByChainId, getNetworkClientById, }) {
89
+ async function providerRequestImplementation(req,
90
+ // `ProviderRequestResult` is an alias for `Json` (which is the default type
91
+ // argument for `PendingJsonRpcResponse`), but that may not be the case in the
92
+ // future. We use `ProviderRequestResult` here to make it clear that this is
93
+ // the expected type of the result.
94
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments
95
+ res, _next, end, { hasPermission, getNetworkConfigurationByChainId, getNetworkClientById, }) {
90
96
  if (!hasPermission(SnapEndowments.EthereumProvider)) {
91
97
  return end(rpcErrors.methodNotFound());
92
98
  }
@@ -1 +1 @@
1
- {"version":3,"file":"experimentalProviderRequest.mjs","sourceRoot":"","sources":["../../src/permitted/experimentalProviderRequest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAOjD,OAAO,EACL,WAAW,EACX,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,EACN,IAAI,EACL,8BAA8B;AAC/B,OAAO,EACL,WAAW,EACX,gBAAgB,EAGhB,iBAAiB,EACjB,mBAAmB,EACpB,wBAAwB;AAEzB,OAAO,EAAE,cAAc,EAAE,gCAAsB;AAG/C,oEAAoE;AACpE,MAAM,gBAAgB,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,iBAAiB;IACjB,UAAU;IACV,aAAa;IACb,cAAc;IACd,iBAAiB;IACjB,gBAAgB;IAChB,cAAc;IACd,gBAAgB;IAChB,oBAAoB;IACpB,sBAAsB;IACtB,oCAAoC;IACpC,sCAAsC;IACtC,aAAa;IACb,sBAAsB;IACtB,mBAAmB;IACnB,aAAa;IACb,cAAc;IACd,kBAAkB;IAClB,uCAAuC;IACvC,yCAAyC;IACzC,0BAA0B;IAC1B,yBAAyB;IACzB,2BAA2B;IAC3B,iCAAiC;IACjC,mCAAmC;IACnC,8BAA8B;IAC9B,gCAAgC;IAChC,aAAa;IACb,cAAc;IACd,YAAY;IACZ,oBAAoB;IACpB,eAAe;IACf,iCAAiC;IACjC,qBAAqB;IACrB,wBAAwB;IACxB,oBAAoB;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SAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n JsonRpcRequest,\n ProviderRequestParams,\n ProviderRequestResult,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n StructError,\n create,\n object,\n optional,\n string,\n type,\n} from '@metamask/superstruct';\nimport {\n bigIntToHex,\n parseCaipChainId,\n type PendingJsonRpcResponse,\n type Json,\n CaipChainIdStruct,\n JsonRpcParamsStruct,\n} from '@metamask/utils';\n\nimport { SnapEndowments } from '../endowments';\nimport type { MethodHooksObject } from '../utils';\n\n// Read-only methods that are currently allowed for this RPC method.\nconst METHOD_ALLOWLIST = Object.freeze([\n 'eth_blockNumber',\n 'eth_call',\n 'eth_chainId',\n 'eth_coinbase',\n 'eth_estimateGas',\n 'eth_feeHistory',\n 'eth_gasPrice',\n 'eth_getBalance',\n 'eth_getBlockByHash',\n 'eth_getBlockByNumber',\n 'eth_getBlockTransactionCountByHash',\n 'eth_getBlockTransactionCountByNumber',\n 'eth_getCode',\n 'eth_getFilterChanges',\n 'eth_getFilterLogs',\n 'eth_getLogs',\n 'eth_getProof',\n 'eth_getStorageAt',\n 'eth_getTransactionByBlockHashAndIndex',\n 'eth_getTransactionByBlockNumberAndIndex',\n 'eth_getTransactionByHash',\n 'eth_getTransactionCount',\n 'eth_getTransactionReceipt',\n 'eth_getUncleByBlockHashAndIndex',\n 'eth_getUncleByBlockNumberAndIndex',\n 'eth_getUncleCountByBlockHash',\n 'eth_getUncleCountByBlockNumber',\n 'eth_getWork',\n 'eth_hashrate',\n 'eth_mining',\n 'eth_newBlockFilter',\n 'eth_newFilter',\n 'eth_newPendingTransactionFilter',\n 'eth_protocolVersion',\n 'eth_sendRawTransaction',\n 'eth_submitHashrate',\n 'eth_submitWork',\n 'eth_syncing',\n 'eth_uninstallFilter',\n 'net_listening',\n 'net_peerCount',\n 'net_version',\n 'web3_clientVersion',\n 'web3_sha3',\n]);\n\nconst hookNames: MethodHooksObject<ProviderRequestMethodHooks> = {\n hasPermission: true,\n getNetworkConfigurationByChainId: true,\n getNetworkClientById: true,\n};\n\ntype NetworkConfiguration = {\n defaultRpcEndpointIndex: number;\n rpcEndpoints: { networkClientId: string }[];\n};\n\nexport type ProviderRequestMethodHooks = {\n hasPermission: (permissionName: string) => boolean;\n\n getNetworkConfigurationByChainId: (\n chainId: string,\n ) => NetworkConfiguration | undefined;\n\n getNetworkClientById: (id: string) => {\n provider: { request: (request: Json) => Promise<Json> };\n };\n};\n\nexport const providerRequestHandler: PermittedHandlerExport<\n ProviderRequestMethodHooks,\n ProviderRequestParameters,\n ProviderRequestResult\n> = {\n methodNames: ['snap_experimentalProviderRequest'],\n implementation: providerRequestImplementation,\n hookNames,\n};\n\nconst ProviderRequestParametersStruct = object({\n chainId: CaipChainIdStruct,\n request: type({\n method: string(),\n params: optional(JsonRpcParamsStruct),\n }),\n});\n\nexport type ProviderRequestParameters = InferMatching<\n typeof ProviderRequestParametersStruct,\n ProviderRequestParams\n>;\n\n/**\n * The `snap_experimentalProviderRequest` method implementation.\n *\n * This RPC method lets Snaps make requests to MetaMask networks that are not currently selected in the UI.\n *\n * The RPC method requires the caller to have the endowment:ethereum-provider permission.\n *\n * NOTE: This implementation is experimental and may be removed or changed without warning.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.hasPermission - Checks whether a given origin has a given permission.\n * @param hooks.getNetworkConfigurationByChainId - Get a network configuration for a given chain ID.\n * @param hooks.getNetworkClientById - Get a network client for a given ID.\n * @returns Nothing.\n */\nasync function providerRequestImplementation(\n req: JsonRpcRequest<ProviderRequestParams>,\n res: PendingJsonRpcResponse<ProviderRequestResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n {\n hasPermission,\n getNetworkConfigurationByChainId,\n getNetworkClientById,\n }: ProviderRequestMethodHooks,\n): Promise<void> {\n if (!hasPermission(SnapEndowments.EthereumProvider)) {\n return end(rpcErrors.methodNotFound());\n }\n\n const { params } = req;\n\n try {\n const { chainId, request } = getValidatedParams(params);\n\n if (!METHOD_ALLOWLIST.includes(request.method)) {\n return end(rpcErrors.methodNotFound());\n }\n\n const parsedChainId = parseCaipChainId(chainId);\n\n if (parsedChainId.namespace !== 'eip155') {\n return end(\n rpcErrors.invalidParams({\n message: 'Only EVM networks are currently supported.',\n }),\n );\n }\n\n const numericalChainId = BigInt(parsedChainId.reference);\n\n const networkConfiguration = getNetworkConfigurationByChainId(\n bigIntToHex(numericalChainId),\n );\n\n if (!networkConfiguration) {\n return end(\n rpcErrors.invalidParams({\n message: 'The requested network is not available.',\n }),\n );\n }\n\n const rpc =\n networkConfiguration.rpcEndpoints[\n networkConfiguration.defaultRpcEndpointIndex\n ];\n\n const networkClient = getNetworkClientById(rpc.networkClientId);\n\n const { provider } = networkClient;\n\n res.result = await provider.request(request);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated updateInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): ProviderRequestParameters {\n try {\n return create(params, ProviderRequestParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
1
+ {"version":3,"file":"experimentalProviderRequest.mjs","sourceRoot":"","sources":["../../src/permitted/experimentalProviderRequest.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAOjD,OAAO,EACL,WAAW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AE,yCAAyC;aACnD,CAAC,CACH,CAAC;QACJ,CAAC;QAED,MAAM,GAAG,GACP,oBAAoB,CAAC,YAAY,CAC/B,oBAAoB,CAAC,uBAAuB,CAC7C,CAAC;QAEJ,MAAM,aAAa,GAAG,oBAAoB,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC;QAEhE,MAAM,EAAE,QAAQ,EAAE,GAAG,aAAa,CAAC;QAEnC,GAAG,CAAC,MAAM,GAAG,MAAM,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;IAC/C,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,OAAO,GAAG,CAAC,KAAK,CAAC,CAAC;IACpB,CAAC;IAED,OAAO,GAAG,EAAE,CAAC;AACf,CAAC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CAAC,MAAe;IACzC,IAAI,CAAC;QACH,OAAO,MAAM,CAAC,MAAM,EAAE,+BAA+B,CAAC,CAAC;IACzD,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,IAAI,KAAK,YAAY,WAAW,EAAE,CAAC;YACjC,MAAM,SAAS,CAAC,aAAa,CAAC;gBAC5B,OAAO,EAAE,mBAAmB,KAAK,CAAC,OAAO,GAAG;aAC7C,CAAC,CAAC;QACL,CAAC;QACD,0BAA0B;QAC1B,MAAM,SAAS,CAAC,QAAQ,EAAE,CAAC;IAC7B,CAAC;AACH,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type {\n JsonRpcRequest,\n ProviderRequestParams,\n ProviderRequestResult,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n StructError,\n create,\n object,\n optional,\n string,\n type,\n} from '@metamask/superstruct';\nimport {\n bigIntToHex,\n parseCaipChainId,\n type PendingJsonRpcResponse,\n type Json,\n CaipChainIdStruct,\n JsonRpcParamsStruct,\n} from '@metamask/utils';\n\nimport { SnapEndowments } from '../endowments';\nimport type { MethodHooksObject } from '../utils';\n\n// Read-only methods that are currently allowed for this RPC method.\nconst METHOD_ALLOWLIST = Object.freeze([\n 'eth_blockNumber',\n 'eth_call',\n 'eth_chainId',\n 'eth_coinbase',\n 'eth_estimateGas',\n 'eth_feeHistory',\n 'eth_gasPrice',\n 'eth_getBalance',\n 'eth_getBlockByHash',\n 'eth_getBlockByNumber',\n 'eth_getBlockTransactionCountByHash',\n 'eth_getBlockTransactionCountByNumber',\n 'eth_getCode',\n 'eth_getFilterChanges',\n 'eth_getFilterLogs',\n 'eth_getLogs',\n 'eth_getProof',\n 'eth_getStorageAt',\n 'eth_getTransactionByBlockHashAndIndex',\n 'eth_getTransactionByBlockNumberAndIndex',\n 'eth_getTransactionByHash',\n 'eth_getTransactionCount',\n 'eth_getTransactionReceipt',\n 'eth_getUncleByBlockHashAndIndex',\n 'eth_getUncleByBlockNumberAndIndex',\n 'eth_getUncleCountByBlockHash',\n 'eth_getUncleCountByBlockNumber',\n 'eth_getWork',\n 'eth_hashrate',\n 'eth_mining',\n 'eth_newBlockFilter',\n 'eth_newFilter',\n 'eth_newPendingTransactionFilter',\n 'eth_protocolVersion',\n 'eth_sendRawTransaction',\n 'eth_submitHashrate',\n 'eth_submitWork',\n 'eth_syncing',\n 'eth_uninstallFilter',\n 'net_listening',\n 'net_peerCount',\n 'net_version',\n 'web3_clientVersion',\n 'web3_sha3',\n]);\n\nconst hookNames: MethodHooksObject<ProviderRequestMethodHooks> = {\n hasPermission: true,\n getNetworkConfigurationByChainId: true,\n getNetworkClientById: true,\n};\n\ntype NetworkConfiguration = {\n defaultRpcEndpointIndex: number;\n rpcEndpoints: { networkClientId: string }[];\n};\n\nexport type ProviderRequestMethodHooks = {\n hasPermission: (permissionName: string) => boolean;\n\n getNetworkConfigurationByChainId: (\n chainId: string,\n ) => NetworkConfiguration | undefined;\n\n getNetworkClientById: (id: string) => {\n provider: { request: (request: Json) => Promise<Json> };\n };\n};\n\nexport const providerRequestHandler: PermittedHandlerExport<\n ProviderRequestMethodHooks,\n ProviderRequestParameters,\n ProviderRequestResult\n> = {\n methodNames: ['snap_experimentalProviderRequest'],\n implementation: providerRequestImplementation,\n hookNames,\n};\n\nconst ProviderRequestParametersStruct = object({\n chainId: CaipChainIdStruct,\n request: type({\n method: string(),\n params: optional(JsonRpcParamsStruct),\n }),\n});\n\nexport type ProviderRequestParameters = InferMatching<\n typeof ProviderRequestParametersStruct,\n ProviderRequestParams\n>;\n\n/**\n * The `snap_experimentalProviderRequest` method implementation.\n *\n * This RPC method lets Snaps make requests to MetaMask networks that are not currently selected in the UI.\n *\n * The RPC method requires the caller to have the endowment:ethereum-provider permission.\n *\n * NOTE: This implementation is experimental and may be removed or changed without warning.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.hasPermission - Checks whether a given origin has a given permission.\n * @param hooks.getNetworkConfigurationByChainId - Get a network configuration for a given chain ID.\n * @param hooks.getNetworkClientById - Get a network client for a given ID.\n * @returns Nothing.\n */\nasync function providerRequestImplementation(\n req: JsonRpcRequest<ProviderRequestParams>,\n // `ProviderRequestResult` is an alias for `Json` (which is the default type\n // argument for `PendingJsonRpcResponse`), but that may not be the case in the\n // future. We use `ProviderRequestResult` here to make it clear that this is\n // the expected type of the result.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\n res: PendingJsonRpcResponse<ProviderRequestResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n {\n hasPermission,\n getNetworkConfigurationByChainId,\n getNetworkClientById,\n }: ProviderRequestMethodHooks,\n): Promise<void> {\n if (!hasPermission(SnapEndowments.EthereumProvider)) {\n return end(rpcErrors.methodNotFound());\n }\n\n const { params } = req;\n\n try {\n const { chainId, request } = getValidatedParams(params);\n\n if (!METHOD_ALLOWLIST.includes(request.method)) {\n return end(rpcErrors.methodNotFound());\n }\n\n const parsedChainId = parseCaipChainId(chainId);\n\n if (parsedChainId.namespace !== 'eip155') {\n return end(\n rpcErrors.invalidParams({\n message: 'Only EVM networks are currently supported.',\n }),\n );\n }\n\n const numericalChainId = BigInt(parsedChainId.reference);\n\n const networkConfiguration = getNetworkConfigurationByChainId(\n bigIntToHex(numericalChainId),\n );\n\n if (!networkConfiguration) {\n return end(\n rpcErrors.invalidParams({\n message: 'The requested network is not available.',\n }),\n );\n }\n\n const rpc =\n networkConfiguration.rpcEndpoints[\n networkConfiguration.defaultRpcEndpointIndex\n ];\n\n const networkClient = getNetworkClientById(rpc.networkClientId);\n\n const { provider } = networkClient;\n\n res.result = await provider.request(request);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the method `params` and returns them cast to the correct\n * type. Throws if validation fails.\n *\n * @param params - The unvalidated params object from the method request.\n * @returns The validated updateInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): ProviderRequestParameters {\n try {\n return create(params, ProviderRequestParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
@@ -3,10 +3,10 @@ import type { GetFileParams } from "@metamask/snaps-sdk";
3
3
  import type { InferMatching } from "@metamask/snaps-utils";
4
4
  export declare const GetFileArgsStruct: import("@metamask/superstruct").Struct<{
5
5
  path: string;
6
- encoding?: "base64" | "utf8" | "hex" | undefined;
6
+ encoding?: "base64" | "hex" | "utf8" | undefined;
7
7
  }, {
8
8
  path: import("@metamask/superstruct").Struct<string, null>;
9
- encoding: import("@metamask/superstruct").Struct<"base64" | "utf8" | "hex" | undefined, null>;
9
+ encoding: import("@metamask/superstruct").Struct<"base64" | "hex" | "utf8" | undefined, null>;
10
10
  }>;
11
11
  export type InferredGetFileParams = InferMatching<typeof GetFileArgsStruct, GetFileParams>;
12
12
  export declare const getFileHandler: PermittedHandlerExport<GetFileHooks, InferredGetFileParams, string>;
@@ -3,10 +3,10 @@ import type { GetFileParams } from "@metamask/snaps-sdk";
3
3
  import type { InferMatching } from "@metamask/snaps-utils";
4
4
  export declare const GetFileArgsStruct: import("@metamask/superstruct").Struct<{
5
5
  path: string;
6
- encoding?: "base64" | "utf8" | "hex" | undefined;
6
+ encoding?: "base64" | "hex" | "utf8" | undefined;
7
7
  }, {
8
8
  path: import("@metamask/superstruct").Struct<string, null>;
9
- encoding: import("@metamask/superstruct").Struct<"base64" | "utf8" | "hex" | undefined, null>;
9
+ encoding: import("@metamask/superstruct").Struct<"base64" | "hex" | "utf8" | undefined, null>;
10
10
  }>;
11
11
  export type InferredGetFileParams = InferMatching<typeof GetFileArgsStruct, GetFileParams>;
12
12
  export declare const getFileHandler: PermittedHandlerExport<GetFileHooks, InferredGetFileParams, string>;
@@ -38,7 +38,13 @@ const GetStateParametersStruct = (0, superstruct_1.object)({
38
38
  * @param hooks.getUnlockPromise - Wait for the extension to be unlocked.
39
39
  * @returns Nothing.
40
40
  */
41
- async function getStateImplementation(request, response, _next, end, { hasPermission, getSnapState, getUnlockPromise }) {
41
+ async function getStateImplementation(request,
42
+ // `GetStateResult` is an alias for `Json` (which is the default type argument
43
+ // for `PendingJsonRpcResponse`), but that may not be the case in the future.
44
+ // We use `GetStateResult` here to make it clear that this is the expected
45
+ // type of the result.
46
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments
47
+ response, _next, end, { hasPermission, getSnapState, getUnlockPromise }) {
42
48
  const { params } = request;
43
49
  if (!hasPermission(manageState_1.manageStateBuilder.targetName)) {
44
50
  return end(rpc_errors_1.providerErrors.unauthorized());
@@ -1 +1 @@
1
- {"version":3,"file":"getState.cjs","sourceRoot":"","sources":["../../src/permitted/getState.ts"],"names":[],"mappings":";;;AAEA,qDAAiE;AAGjE,uDAM+B;AAM/B,2CAAwD;A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AG,MAAM,CAAC,UAAU,CAAC,CAAC;YAC5B,SAAS;QACX,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAlCD,kBAkCC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { GetStateParams, GetStateResult } from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n boolean,\n create,\n object,\n optional,\n StructError,\n} from '@metamask/superstruct';\nimport type {\n PendingJsonRpcResponse,\n Json,\n JsonRpcRequest,\n} from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n\nimport { manageStateBuilder } from '../restricted/manageState';\nimport type { MethodHooksObject } from '../utils';\nimport { FORBIDDEN_KEYS, StateKeyStruct } from '../utils';\n\nconst hookNames: MethodHooksObject<GetStateHooks> = {\n hasPermission: true,\n getSnapState: true,\n getUnlockPromise: true,\n};\n\n/**\n * `snap_getState` gets the state of the Snap.\n */\nexport const getStateHandler: PermittedHandlerExport<\n GetStateHooks,\n GetStateParameters,\n GetStateResult\n> = {\n methodNames: ['snap_getState'],\n implementation: getStateImplementation,\n hookNames,\n};\n\nexport type GetStateHooks = {\n /**\n * Check if the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * Get the state of the requesting Snap.\n *\n * @returns The current state of the Snap.\n */\n getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;\n\n /**\n * Wait for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n};\n\nconst GetStateParametersStruct = object({\n key: optional(StateKeyStruct),\n encrypted: optional(boolean()),\n});\n\nexport type GetStateParameters = InferMatching<\n typeof GetStateParametersStruct,\n GetStateParams\n>;\n\n/**\n * The `snap_getState` method implementation.\n *\n * @param request - The JSON-RPC request object.\n * @param response - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.hasPermission - Check whether a given origin has a given\n * permission.\n * @param hooks.getSnapState - Get the state of the requesting Snap.\n * @param hooks.getUnlockPromise - Wait for the extension to be unlocked.\n * @returns Nothing.\n */\nasync function getStateImplementation(\n request: JsonRpcRequest<GetStateParameters>,\n response: PendingJsonRpcResponse<GetStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { hasPermission, getSnapState, getUnlockPromise }: GetStateHooks,\n): Promise<void> {\n const { params } = request;\n\n if (!hasPermission(manageStateBuilder.targetName)) {\n return end(providerErrors.unauthorized());\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n const { key, encrypted = true } = validatedParams;\n\n if (encrypted) {\n await getUnlockPromise(true);\n }\n\n const state = await getSnapState(encrypted);\n response.result = get(state, key);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the parameters of the `snap_getState` method.\n *\n * @param params - The parameters to validate.\n * @returns The validated parameters.\n */\nfunction getValidatedParams(params?: unknown) {\n try {\n return create(params, GetStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n\n/**\n * Get the value of a key in an object. The key may contain Lodash-style path\n * syntax, e.g., `a.b.c` (with the exception of array syntax). If the key does\n * not exist, `null` is returned.\n *\n * This is a simplified version of Lodash's `get` function, but Lodash doesn't\n * seem to be maintained anymore, so we're using our own implementation.\n *\n * @param value - The object to get the key from.\n * @param key - The key to get.\n * @returns The value of the key in the object, or `null` if the key does not\n * exist.\n */\nexport function get(\n value: Record<string, Json> | null,\n key?: string | undefined,\n): Json {\n if (key === undefined) {\n return value;\n }\n\n const keys = key.split('.');\n let result: Json = value;\n\n // Intentionally using a classic for loop here for performance reasons.\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < keys.length; i++) {\n const currentKey = keys[i];\n if (FORBIDDEN_KEYS.includes(currentKey)) {\n throw rpcErrors.invalidParams(\n 'Invalid params: Key contains forbidden characters.',\n );\n }\n\n if (isObject(result)) {\n if (!hasProperty(result, currentKey)) {\n return null;\n }\n\n result = result[currentKey];\n continue;\n }\n\n return null;\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"getState.cjs","sourceRoot":"","sources":["../../src/permitted/getState.ts"],"names":[],"mappings":";;;AAEA,qDAAiE;AAGjE,uDAM+B;AAM/B,2CAAwD;AAExD,+DAA+D;AAE/D,wCAA0D;AAE1D,MAAM,SAAS,GAAqC;IAClD,aAAa,EAAE,IAAI;IACnB,YAAY,EAAE,IAAI;IAClB,gBAAgB,EAAE,IAAI;CACvB,CAAC;AAEF;;GAEG;AACU,QAAA,eAAe,GAIxB;IACF,WAAW,EAAE,CAAC,eAAe,CAAC;IAC9B,cAAc,EAAE,sBAAsB;IACtC,SAAS;CACV,CAAC;AA0BF,MAAM,wBAAwB,GAAG,IAAA,oBAAM,EAAC;IACtC,GAAG,EAAE,IAAA,sBAAQ,EAAC,sBAAc,CAAC;IAC7B,SAAS,EAAE,IAAA,sBAAQ,EAAC,IAAA,qBAAO,GAAE,CAAC;CAC/B,CAAC,CAAC;AAOH;;;;;;;;;;;;;;GAcG;AACH,KAAK,UAAU,sBAAsB,CACnC,OAA2C;AAC3C,8EAA8E;AAC9E,6EAA6E;AAC7E,0EAA0E;AAC1E,sBAAsB;AACtB,4EAA4E;AAC5E,QAAgD,EAChD,KAAc,EACd,GAA6B,EAC7B,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAiB;IAEhE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAE3B,IA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KAAK,CAAC,GAAG,CAAC,CAAC;IAC5B,IAAI,MAAM,GAAS,KAAK,CAAC;IAEzB,uEAAuE;IACvE,4DAA4D;IAC5D,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACrC,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,sBAAc,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YACxC,MAAM,sBAAS,CAAC,aAAa,CAC3B,oDAAoD,CACrD,CAAC;QACJ,CAAC;QAED,IAAI,IAAA,gBAAQ,EAAC,MAAM,CAAC,EAAE,CAAC;YACrB,IAAI,CAAC,IAAA,mBAAW,EAAC,MAAM,EAAE,UAAU,CAAC,EAAE,CAAC;gBACrC,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;YAC5B,SAAS;QACX,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC;AAlCD,kBAkCC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { GetStateParams, GetStateResult } from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n boolean,\n create,\n object,\n optional,\n StructError,\n} from '@metamask/superstruct';\nimport type {\n PendingJsonRpcResponse,\n Json,\n JsonRpcRequest,\n} from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n\nimport { manageStateBuilder } from '../restricted/manageState';\nimport type { MethodHooksObject } from '../utils';\nimport { FORBIDDEN_KEYS, StateKeyStruct } from '../utils';\n\nconst hookNames: MethodHooksObject<GetStateHooks> = {\n hasPermission: true,\n getSnapState: true,\n getUnlockPromise: true,\n};\n\n/**\n * `snap_getState` gets the state of the Snap.\n */\nexport const getStateHandler: PermittedHandlerExport<\n GetStateHooks,\n GetStateParameters,\n GetStateResult\n> = {\n methodNames: ['snap_getState'],\n implementation: getStateImplementation,\n hookNames,\n};\n\nexport type GetStateHooks = {\n /**\n * Check if the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * Get the state of the requesting Snap.\n *\n * @returns The current state of the Snap.\n */\n getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;\n\n /**\n * Wait for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n};\n\nconst GetStateParametersStruct = object({\n key: optional(StateKeyStruct),\n encrypted: optional(boolean()),\n});\n\nexport type GetStateParameters = InferMatching<\n typeof GetStateParametersStruct,\n GetStateParams\n>;\n\n/**\n * The `snap_getState` method implementation.\n *\n * @param request - The JSON-RPC request object.\n * @param response - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.hasPermission - Check whether a given origin has a given\n * permission.\n * @param hooks.getSnapState - Get the state of the requesting Snap.\n * @param hooks.getUnlockPromise - Wait for the extension to be unlocked.\n * @returns Nothing.\n */\nasync function getStateImplementation(\n request: JsonRpcRequest<GetStateParameters>,\n // `GetStateResult` is an alias for `Json` (which is the default type argument\n // for `PendingJsonRpcResponse`), but that may not be the case in the future.\n // We use `GetStateResult` here to make it clear that this is the expected\n // type of the result.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\n response: PendingJsonRpcResponse<GetStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { hasPermission, getSnapState, getUnlockPromise }: GetStateHooks,\n): Promise<void> {\n const { params } = request;\n\n if (!hasPermission(manageStateBuilder.targetName)) {\n return end(providerErrors.unauthorized());\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n const { key, encrypted = true } = validatedParams;\n\n if (encrypted) {\n await getUnlockPromise(true);\n }\n\n const state = await getSnapState(encrypted);\n response.result = get(state, key);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the parameters of the `snap_getState` method.\n *\n * @param params - The parameters to validate.\n * @returns The validated parameters.\n */\nfunction getValidatedParams(params?: unknown) {\n try {\n return create(params, GetStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n\n/**\n * Get the value of a key in an object. The key may contain Lodash-style path\n * syntax, e.g., `a.b.c` (with the exception of array syntax). If the key does\n * not exist, `null` is returned.\n *\n * This is a simplified version of Lodash's `get` function, but Lodash doesn't\n * seem to be maintained anymore, so we're using our own implementation.\n *\n * @param value - The object to get the key from.\n * @param key - The key to get.\n * @returns The value of the key in the object, or `null` if the key does not\n * exist.\n */\nexport function get(\n value: Record<string, Json> | null,\n key?: string | undefined,\n): Json {\n if (key === undefined) {\n return value;\n }\n\n const keys = key.split('.');\n let result: Json = value;\n\n // Intentionally using a classic for loop here for performance reasons.\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < keys.length; i++) {\n const currentKey = keys[i];\n if (FORBIDDEN_KEYS.includes(currentKey)) {\n throw rpcErrors.invalidParams(\n 'Invalid params: Key contains forbidden characters.',\n );\n }\n\n if (isObject(result)) {\n if (!hasProperty(result, currentKey)) {\n return null;\n }\n\n result = result[currentKey];\n continue;\n }\n\n return null;\n }\n\n return result;\n}\n"]}
@@ -28,8 +28,8 @@ export type GetStateHooks = {
28
28
  getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
29
29
  };
30
30
  declare const GetStateParametersStruct: import("@metamask/superstruct").Struct<{
31
- key?: string | undefined;
32
31
  encrypted?: boolean | undefined;
32
+ key?: string | undefined;
33
33
  }, {
34
34
  key: import("@metamask/superstruct").Struct<string | undefined, null>;
35
35
  encrypted: import("@metamask/superstruct").Struct<boolean | undefined, null>;
@@ -1 +1 @@
1
- {"version":3,"file":"getState.d.cts","sourceRoot":"","sources":["../../src/permitted/getState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,4BAA4B;AAC1E,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAQ3D,OAAO,KAAK,EAEV,IAAI,EAEL,wBAAwB;AAazB;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,sBAAsB,CAClD,aAAa,EACb,kBAAkB,EAClB,cAAc,CAKf,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;OAKG;IACH,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnD;;;;OAIG;IACH,YAAY,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAEpE;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE,CAAC;AAEF,QAAA,MAAM,wBAAwB;;;;;;EAG5B,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,aAAa,CAC5C,OAAO,wBAAwB,EAC/B,cAAc,CACf,CAAC;AAoEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,EAClC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,GACvB,IAAI,CA+BN"}
1
+ {"version":3,"file":"getState.d.cts","sourceRoot":"","sources":["../../src/permitted/getState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,4BAA4B;AAC1E,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAQ3D,OAAO,KAAK,EAEV,IAAI,EAEL,wBAAwB;AAazB;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,sBAAsB,CAClD,aAAa,EACb,kBAAkB,EAClB,cAAc,CAKf,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;OAKG;IACH,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnD;;;;OAIG;IACH,YAAY,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAEpE;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE,CAAC;AAEF,QAAA,MAAM,wBAAwB;;;;;;EAG5B,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,aAAa,CAC5C,OAAO,wBAAwB,EAC/B,cAAc,CACf,CAAC;AAyEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,EAClC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,GACvB,IAAI,CA+BN"}
@@ -28,8 +28,8 @@ export type GetStateHooks = {
28
28
  getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;
29
29
  };
30
30
  declare const GetStateParametersStruct: import("@metamask/superstruct").Struct<{
31
- key?: string | undefined;
32
31
  encrypted?: boolean | undefined;
32
+ key?: string | undefined;
33
33
  }, {
34
34
  key: import("@metamask/superstruct").Struct<string | undefined, null>;
35
35
  encrypted: import("@metamask/superstruct").Struct<boolean | undefined, null>;
@@ -1 +1 @@
1
- {"version":3,"file":"getState.d.mts","sourceRoot":"","sources":["../../src/permitted/getState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,4BAA4B;AAC1E,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAQ3D,OAAO,KAAK,EAEV,IAAI,EAEL,wBAAwB;AAazB;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,sBAAsB,CAClD,aAAa,EACb,kBAAkB,EAClB,cAAc,CAKf,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;OAKG;IACH,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnD;;;;OAIG;IACH,YAAY,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAEpE;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE,CAAC;AAEF,QAAA,MAAM,wBAAwB;;;;;;EAG5B,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,aAAa,CAC5C,OAAO,wBAAwB,EAC/B,cAAc,CACf,CAAC;AAoEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,EAClC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,GACvB,IAAI,CA+BN"}
1
+ {"version":3,"file":"getState.d.mts","sourceRoot":"","sources":["../../src/permitted/getState.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,4BAA4B;AAC1E,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAQ3D,OAAO,KAAK,EAEV,IAAI,EAEL,wBAAwB;AAazB;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,sBAAsB,CAClD,aAAa,EACb,kBAAkB,EAClB,cAAc,CAKf,CAAC;AAEF,MAAM,MAAM,aAAa,GAAG;IAC1B;;;;;OAKG;IACH,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnD;;;;OAIG;IACH,YAAY,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC;IAEpE;;;;OAIG;IACH,gBAAgB,EAAE,CAAC,uBAAuB,EAAE,OAAO,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;CACvE,CAAC;AAEF,QAAA,MAAM,wBAAwB;;;;;;EAG5B,CAAC;AAEH,MAAM,MAAM,kBAAkB,GAAG,aAAa,CAC5C,OAAO,wBAAwB,EAC/B,cAAc,CACf,CAAC;AAyEF;;;;;;;;;;;;GAYG;AACH,wBAAgB,GAAG,CACjB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,GAAG,IAAI,EAClC,GAAG,CAAC,EAAE,MAAM,GAAG,SAAS,GACvB,IAAI,CA+BN"}
@@ -35,7 +35,13 @@ const GetStateParametersStruct = object({
35
35
  * @param hooks.getUnlockPromise - Wait for the extension to be unlocked.
36
36
  * @returns Nothing.
37
37
  */
38
- async function getStateImplementation(request, response, _next, end, { hasPermission, getSnapState, getUnlockPromise }) {
38
+ async function getStateImplementation(request,
39
+ // `GetStateResult` is an alias for `Json` (which is the default type argument
40
+ // for `PendingJsonRpcResponse`), but that may not be the case in the future.
41
+ // We use `GetStateResult` here to make it clear that this is the expected
42
+ // type of the result.
43
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments
44
+ response, _next, end, { hasPermission, getSnapState, getUnlockPromise }) {
39
45
  const { params } = request;
40
46
  if (!hasPermission(manageStateBuilder.targetName)) {
41
47
  return end(providerErrors.unauthorized());
@@ -1 +1 @@
1
- {"version":3,"file":"getState.mjs","sourceRoot":"","sources":["../../src/permitted/getState.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAGjE,OAAO,EACL,OAAO,EACP,MAAM,EACN,MAAM,EACN,QAAQ,EACR,WAAW,EACZ,8BAA8B;AAM/B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,wBAAwB;AAExD,OAAO,EAAE,kBAAkB,EAAE,sCAAkC;AAE/D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,qBAAiB;AAE1D,MAAM,SAAS,GAAqC;IAClD,aAAa,EAAE,IAAI;IACnB,YAAY,EAAE,IAAI;IAClB,gBAAgB,EAAE,IAAI;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAIxB;IACF,WAAW,EAAE,CAAC,eAAe,CAAC;IAC9B,cAAc,EAAE,sBAAsB;IACtC,SAAS;CACV,CAAC;AA0BF,MAAM,wBAAwB,GAAG,MAAM,CAAC;IACtC,GAAG,EAAE,QAAQ,CAAC,cAAc,CAAC;IAC7B,SAAS,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;CAC/B,CAAC,CAAC;AAOH;;;;;;;;;;;;;;GAcG;AACH,KAAK,UAAU,sBAAsB,CACnC,OAA2C,EAC3C,QAAgD,EAChD,KAAc,EACd,GAA6B,EAC7B,EAAE,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAiB;IAEhE,MAAM,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC;IAE3B,IAAI,CAAC,aAAa,CAAC,kBAAkB,CAAC,UAAU,CAAC,EAAE,CAAC;QAClD,OAAO,GAAG,CAAC,cAAc,CAAC,YAAY,EAAE,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBA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AAE,EAAE,CAAC;QACrC,MAAM,UAAU,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAC3B,IAAI,cAAc,CAAC,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC;YACxC,MAAM,SAAS,CAAC,aAAa,CAC3B,oDAAoD,CACrD,CAAC;QACJ,CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC;YACrB,IAAI,CAAC,WAAW,CAAC,MAAM,EAAE,UAAU,CAAC,EAAE,CAAC;gBACrC,OAAO,IAAI,CAAC;YACd,CAAC;YAED,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;YAC5B,SAAS;QACX,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import type { JsonRpcEngineEndCallback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { GetStateParams, GetStateResult } from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n boolean,\n create,\n object,\n optional,\n StructError,\n} from '@metamask/superstruct';\nimport type {\n PendingJsonRpcResponse,\n Json,\n JsonRpcRequest,\n} from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n\nimport { manageStateBuilder } from '../restricted/manageState';\nimport type { MethodHooksObject } from '../utils';\nimport { FORBIDDEN_KEYS, StateKeyStruct } from '../utils';\n\nconst hookNames: MethodHooksObject<GetStateHooks> = {\n hasPermission: true,\n getSnapState: true,\n getUnlockPromise: true,\n};\n\n/**\n * `snap_getState` gets the state of the Snap.\n */\nexport const getStateHandler: PermittedHandlerExport<\n GetStateHooks,\n GetStateParameters,\n GetStateResult\n> = {\n methodNames: ['snap_getState'],\n implementation: getStateImplementation,\n hookNames,\n};\n\nexport type GetStateHooks = {\n /**\n * Check if the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * Get the state of the requesting Snap.\n *\n * @returns The current state of the Snap.\n */\n getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;\n\n /**\n * Wait for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n};\n\nconst GetStateParametersStruct = object({\n key: optional(StateKeyStruct),\n encrypted: optional(boolean()),\n});\n\nexport type GetStateParameters = InferMatching<\n typeof GetStateParametersStruct,\n GetStateParams\n>;\n\n/**\n * The `snap_getState` method implementation.\n *\n * @param request - The JSON-RPC request object.\n * @param response - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.hasPermission - Check whether a given origin has a given\n * permission.\n * @param hooks.getSnapState - Get the state of the requesting Snap.\n * @param hooks.getUnlockPromise - Wait for the extension to be unlocked.\n * @returns Nothing.\n */\nasync function getStateImplementation(\n request: JsonRpcRequest<GetStateParameters>,\n response: PendingJsonRpcResponse<GetStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { hasPermission, getSnapState, getUnlockPromise }: GetStateHooks,\n): Promise<void> {\n const { params } = request;\n\n if (!hasPermission(manageStateBuilder.targetName)) {\n return end(providerErrors.unauthorized());\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n const { key, encrypted = true } = validatedParams;\n\n if (encrypted) {\n await getUnlockPromise(true);\n }\n\n const state = await getSnapState(encrypted);\n response.result = get(state, key);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the parameters of the `snap_getState` method.\n *\n * @param params - The parameters to validate.\n * @returns The validated parameters.\n */\nfunction getValidatedParams(params?: unknown) {\n try {\n return create(params, GetStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n\n/**\n * Get the value of a key in an object. The key may contain Lodash-style path\n * syntax, e.g., `a.b.c` (with the exception of array syntax). If the key does\n * not exist, `null` is returned.\n *\n * This is a simplified version of Lodash's `get` function, but Lodash doesn't\n * seem to be maintained anymore, so we're using our own implementation.\n *\n * @param value - The object to get the key from.\n * @param key - The key to get.\n * @returns The value of the key in the object, or `null` if the key does not\n * exist.\n */\nexport function get(\n value: Record<string, Json> | null,\n key?: string | undefined,\n): Json {\n if (key === undefined) {\n return value;\n }\n\n const keys = key.split('.');\n let result: Json = value;\n\n // Intentionally using a classic for loop here for performance reasons.\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < keys.length; i++) {\n const currentKey = keys[i];\n if (FORBIDDEN_KEYS.includes(currentKey)) {\n throw rpcErrors.invalidParams(\n 'Invalid params: Key contains forbidden characters.',\n );\n }\n\n if (isObject(result)) {\n if (!hasProperty(result, currentKey)) {\n return null;\n }\n\n result = result[currentKey];\n continue;\n }\n\n return null;\n }\n\n return result;\n}\n"]}
1
+ {"version":3,"file":"getState.mjs","sourceRoot":"","sources":["../../src/permitted/getState.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,SAAS,EAAE,6BAA6B;AAGjE,OAAO,EACL,OAAO,EACP,MAAM,EACN,MAAM,EACN,QAAQ,EACR,WAAW,EACZ,8BAA8B;AAM/B,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,wBAAwB;AAExD,OAAO,EAAE,kBAAkB,EAAE,sCAAkC;AAE/D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,qBAAiB;AAE1D,MAAM,SAAS,GAAqC;IAClD,aAAa,EAAE,IAAI;IACnB,YAAY,EAAE,IAAI;IAClB,gBAAgB,EAAE,IAAI;CACvB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,MAAM,eAAe,GAIx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allback } from '@metamask/json-rpc-engine';\nimport type { PermittedHandlerExport } from '@metamask/permission-controller';\nimport { providerErrors, rpcErrors } from '@metamask/rpc-errors';\nimport type { GetStateParams, GetStateResult } from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n boolean,\n create,\n object,\n optional,\n StructError,\n} from '@metamask/superstruct';\nimport type {\n PendingJsonRpcResponse,\n Json,\n JsonRpcRequest,\n} from '@metamask/utils';\nimport { hasProperty, isObject } from '@metamask/utils';\n\nimport { manageStateBuilder } from '../restricted/manageState';\nimport type { MethodHooksObject } from '../utils';\nimport { FORBIDDEN_KEYS, StateKeyStruct } from '../utils';\n\nconst hookNames: MethodHooksObject<GetStateHooks> = {\n hasPermission: true,\n getSnapState: true,\n getUnlockPromise: true,\n};\n\n/**\n * `snap_getState` gets the state of the Snap.\n */\nexport const getStateHandler: PermittedHandlerExport<\n GetStateHooks,\n GetStateParameters,\n GetStateResult\n> = {\n methodNames: ['snap_getState'],\n implementation: getStateImplementation,\n hookNames,\n};\n\nexport type GetStateHooks = {\n /**\n * Check if the requesting origin has a given permission.\n *\n * @param permissionName - The name of the permission to check.\n * @returns Whether the origin has the permission.\n */\n hasPermission: (permissionName: string) => boolean;\n\n /**\n * Get the state of the requesting Snap.\n *\n * @returns The current state of the Snap.\n */\n getSnapState: (encrypted: boolean) => Promise<Record<string, Json>>;\n\n /**\n * Wait for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n};\n\nconst GetStateParametersStruct = object({\n key: optional(StateKeyStruct),\n encrypted: optional(boolean()),\n});\n\nexport type GetStateParameters = InferMatching<\n typeof GetStateParametersStruct,\n GetStateParams\n>;\n\n/**\n * The `snap_getState` method implementation.\n *\n * @param request - The JSON-RPC request object.\n * @param response - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.hasPermission - Check whether a given origin has a given\n * permission.\n * @param hooks.getSnapState - Get the state of the requesting Snap.\n * @param hooks.getUnlockPromise - Wait for the extension to be unlocked.\n * @returns Nothing.\n */\nasync function getStateImplementation(\n request: JsonRpcRequest<GetStateParameters>,\n // `GetStateResult` is an alias for `Json` (which is the default type argument\n // for `PendingJsonRpcResponse`), but that may not be the case in the future.\n // We use `GetStateResult` here to make it clear that this is the expected\n // type of the result.\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-arguments\n response: PendingJsonRpcResponse<GetStateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { hasPermission, getSnapState, getUnlockPromise }: GetStateHooks,\n): Promise<void> {\n const { params } = request;\n\n if (!hasPermission(manageStateBuilder.targetName)) {\n return end(providerErrors.unauthorized());\n }\n\n try {\n const validatedParams = getValidatedParams(params);\n const { key, encrypted = true } = validatedParams;\n\n if (encrypted) {\n await getUnlockPromise(true);\n }\n\n const state = await getSnapState(encrypted);\n response.result = get(state, key);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the parameters of the `snap_getState` method.\n *\n * @param params - The parameters to validate.\n * @returns The validated parameters.\n */\nfunction getValidatedParams(params?: unknown) {\n try {\n return create(params, GetStateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n\n/**\n * Get the value of a key in an object. The key may contain Lodash-style path\n * syntax, e.g., `a.b.c` (with the exception of array syntax). If the key does\n * not exist, `null` is returned.\n *\n * This is a simplified version of Lodash's `get` function, but Lodash doesn't\n * seem to be maintained anymore, so we're using our own implementation.\n *\n * @param value - The object to get the key from.\n * @param key - The key to get.\n * @returns The value of the key in the object, or `null` if the key does not\n * exist.\n */\nexport function get(\n value: Record<string, Json> | null,\n key?: string | undefined,\n): Json {\n if (key === undefined) {\n return value;\n }\n\n const keys = key.split('.');\n let result: Json = value;\n\n // Intentionally using a classic for loop here for performance reasons.\n // eslint-disable-next-line @typescript-eslint/prefer-for-of\n for (let i = 0; i < keys.length; i++) {\n const currentKey = keys[i];\n if (FORBIDDEN_KEYS.includes(currentKey)) {\n throw rpcErrors.invalidParams(\n 'Invalid params: Key contains forbidden characters.',\n );\n }\n\n if (isObject(result)) {\n if (!hasProperty(result, currentKey)) {\n return null;\n }\n\n result = result[currentKey];\n continue;\n }\n\n return null;\n }\n\n return result;\n}\n"]}
@@ -21,6 +21,7 @@ const requestSnaps_1 = require("./requestSnaps.cjs");
21
21
  const resolveInterface_1 = require("./resolveInterface.cjs");
22
22
  const scheduleBackgroundEvent_1 = require("./scheduleBackgroundEvent.cjs");
23
23
  const setState_1 = require("./setState.cjs");
24
+ const trackEvent_1 = require("./trackEvent.cjs");
24
25
  const updateInterface_1 = require("./updateInterface.cjs");
25
26
  /* eslint-disable @typescript-eslint/naming-convention */
26
27
  exports.methodHandlers = {
@@ -45,6 +46,7 @@ exports.methodHandlers = {
45
46
  snap_cancelBackgroundEvent: cancelBackgroundEvent_1.cancelBackgroundEventHandler,
46
47
  snap_getBackgroundEvents: getBackgroundEvents_1.getBackgroundEventsHandler,
47
48
  snap_setState: setState_1.setStateHandler,
49
+ snap_trackEvent: trackEvent_1.trackEventHandler,
48
50
  };
49
51
  /* eslint-enable @typescript-eslint/naming-convention */
50
52
  exports.handlers = Object.values(exports.methodHandlers);
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.cjs","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":";;;AAAA,uEAAuE;AACvE,iDAAiD;AACjD,2DAA2D;AAC3D,mFAAuE;AACvE,mDAAmD;AACnD,mEAAmE;AACnE,2DAA2D;AAC3D,2DAA2D;AAC3D,2CAA2C;AAC3C,mEAAmE;AACnE,+DAA+D;AAC/D,6CAA6C;AAC7C,6CAA6C;AAC7C,uDAAuD;AACvD,2DAA2D;AAC3D,iEAAiE;AACjE,qDAAqD;AACrD,6DAA6D;AAC7D,2EAA2E;AAC3E,6CAA6C;AAC7C,2DAA2D;AAE3D,yDAAyD;AAC5C,QAAA,cAAc,GAAG;IAC5B,kBAAkB,EAAE,gCAAkB;IACtC,eAAe,EAAE,0BAAe;IAChC,mBAAmB,EAAE,kCAAmB;IACxC,iBAAiB,EAAE,wCAAsB;IACzC,oBAAoB,EAAE,oCAAoB;IAC1C,eAAe,EAAE,8BAAiB;IAClC,oBAAoB,EAAE,wCAAsB;IAC5C,YAAY,EAAE,wBAAc;IAC5B,aAAa,EAAE,0BAAe;IAC9B,oBAAoB,EAAE,wCAAsB;IAC5C,oBAAoB,EAAE,wCAAsB;IAC5C,sBAAsB,EAAE,4CAAwB;IAChD,wBAAwB,EAAE,gDAA0B;IACpD,uBAAuB,EAAE,8CAAyB;IAClD,qBAAqB,EAAE,0CAAuB;IAC9C,oBAAoB,EAAE,wCAAsB;IAC5C,gCAAgC,EAAE,oDAAsB;IACxD,4BAA4B,EAAE,wDAA8B;IAC5D,0BAA0B,EAAE,oDAA4B;IACxD,wBAAwB,EAAE,gDAA0B;IACpD,aAAa,EAAE,0BAAe;CAC/B,CAAC;AACF,wDAAwD;AAE3C,QAAA,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAc,CAAC,CAAC","sourcesContent":["import { cancelBackgroundEventHandler } from './cancelBackgroundEvent';\nimport { clearStateHandler } from './clearState';\nimport { createInterfaceHandler } from './createInterface';\nimport { providerRequestHandler } from './experimentalProviderRequest';\nimport { getAllSnapsHandler } from './getAllSnaps';\nimport { getBackgroundEventsHandler } from './getBackgroundEvents';\nimport { getClientStatusHandler } from './getClientStatus';\nimport { getCurrencyRateHandler } from './getCurrencyRate';\nimport { getFileHandler } from './getFile';\nimport { getInterfaceContextHandler } from './getInterfaceContext';\nimport { getInterfaceStateHandler } from './getInterfaceState';\nimport { getSnapsHandler } from './getSnaps';\nimport { getStateHandler } from './getState';\nimport { invokeKeyringHandler } from './invokeKeyring';\nimport { invokeSnapSugarHandler } from './invokeSnapSugar';\nimport { listEntropySourcesHandler } from './listEntropySources';\nimport { requestSnapsHandler } from './requestSnaps';\nimport { resolveInterfaceHandler } from './resolveInterface';\nimport { scheduleBackgroundEventHandler } from './scheduleBackgroundEvent';\nimport { setStateHandler } from './setState';\nimport { updateInterfaceHandler } from './updateInterface';\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const methodHandlers = {\n wallet_getAllSnaps: getAllSnapsHandler,\n wallet_getSnaps: getSnapsHandler,\n wallet_requestSnaps: requestSnapsHandler,\n wallet_invokeSnap: invokeSnapSugarHandler,\n wallet_invokeKeyring: invokeKeyringHandler,\n snap_clearState: clearStateHandler,\n snap_getClientStatus: getClientStatusHandler,\n snap_getFile: getFileHandler,\n snap_getState: getStateHandler,\n snap_createInterface: createInterfaceHandler,\n snap_updateInterface: updateInterfaceHandler,\n snap_getInterfaceState: getInterfaceStateHandler,\n snap_getInterfaceContext: getInterfaceContextHandler,\n snap_listEntropySources: listEntropySourcesHandler,\n snap_resolveInterface: resolveInterfaceHandler,\n snap_getCurrencyRate: getCurrencyRateHandler,\n snap_experimentalProviderRequest: providerRequestHandler,\n snap_scheduleBackgroundEvent: scheduleBackgroundEventHandler,\n snap_cancelBackgroundEvent: cancelBackgroundEventHandler,\n snap_getBackgroundEvents: getBackgroundEventsHandler,\n snap_setState: setStateHandler,\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const handlers = Object.values(methodHandlers);\n"]}
1
+ {"version":3,"file":"handlers.cjs","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":";;;AAAA,uEAAuE;AACvE,iDAAiD;AACjD,2DAA2D;AAC3D,mFAAuE;AACvE,mDAAmD;AACnD,mEAAmE;AACnE,2DAA2D;AAC3D,2DAA2D;AAC3D,2CAA2C;AAC3C,mEAAmE;AACnE,+DAA+D;AAC/D,6CAA6C;AAC7C,6CAA6C;AAC7C,uDAAuD;AACvD,2DAA2D;AAC3D,iEAAiE;AACjE,qDAAqD;AACrD,6DAA6D;AAC7D,2EAA2E;AAC3E,6CAA6C;AAC7C,iDAAiD;AACjD,2DAA2D;AAE3D,yDAAyD;AAC5C,QAAA,cAAc,GAAG;IAC5B,kBAAkB,EAAE,gCAAkB;IACtC,eAAe,EAAE,0BAAe;IAChC,mBAAmB,EAAE,kCAAmB;IACxC,iBAAiB,EAAE,wCAAsB;IACzC,oBAAoB,EAAE,oCAAoB;IAC1C,eAAe,EAAE,8BAAiB;IAClC,oBAAoB,EAAE,wCAAsB;IAC5C,YAAY,EAAE,wBAAc;IAC5B,aAAa,EAAE,0BAAe;IAC9B,oBAAoB,EAAE,wCAAsB;IAC5C,oBAAoB,EAAE,wCAAsB;IAC5C,sBAAsB,EAAE,4CAAwB;IAChD,wBAAwB,EAAE,gDAA0B;IACpD,uBAAuB,EAAE,8CAAyB;IAClD,qBAAqB,EAAE,0CAAuB;IAC9C,oBAAoB,EAAE,wCAAsB;IAC5C,gCAAgC,EAAE,oDAAsB;IACxD,4BAA4B,EAAE,wDAA8B;IAC5D,0BAA0B,EAAE,oDAA4B;IACxD,wBAAwB,EAAE,gDAA0B;IACpD,aAAa,EAAE,0BAAe;IAC9B,eAAe,EAAE,8BAAiB;CACnC,CAAC;AACF,wDAAwD;AAE3C,QAAA,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAc,CAAC,CAAC","sourcesContent":["import { cancelBackgroundEventHandler } from './cancelBackgroundEvent';\nimport { clearStateHandler } from './clearState';\nimport { createInterfaceHandler } from './createInterface';\nimport { providerRequestHandler } from './experimentalProviderRequest';\nimport { getAllSnapsHandler } from './getAllSnaps';\nimport { getBackgroundEventsHandler } from './getBackgroundEvents';\nimport { getClientStatusHandler } from './getClientStatus';\nimport { getCurrencyRateHandler } from './getCurrencyRate';\nimport { getFileHandler } from './getFile';\nimport { getInterfaceContextHandler } from './getInterfaceContext';\nimport { getInterfaceStateHandler } from './getInterfaceState';\nimport { getSnapsHandler } from './getSnaps';\nimport { getStateHandler } from './getState';\nimport { invokeKeyringHandler } from './invokeKeyring';\nimport { invokeSnapSugarHandler } from './invokeSnapSugar';\nimport { listEntropySourcesHandler } from './listEntropySources';\nimport { requestSnapsHandler } from './requestSnaps';\nimport { resolveInterfaceHandler } from './resolveInterface';\nimport { scheduleBackgroundEventHandler } from './scheduleBackgroundEvent';\nimport { setStateHandler } from './setState';\nimport { trackEventHandler } from './trackEvent';\nimport { updateInterfaceHandler } from './updateInterface';\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const methodHandlers = {\n wallet_getAllSnaps: getAllSnapsHandler,\n wallet_getSnaps: getSnapsHandler,\n wallet_requestSnaps: requestSnapsHandler,\n wallet_invokeSnap: invokeSnapSugarHandler,\n wallet_invokeKeyring: invokeKeyringHandler,\n snap_clearState: clearStateHandler,\n snap_getClientStatus: getClientStatusHandler,\n snap_getFile: getFileHandler,\n snap_getState: getStateHandler,\n snap_createInterface: createInterfaceHandler,\n snap_updateInterface: updateInterfaceHandler,\n snap_getInterfaceState: getInterfaceStateHandler,\n snap_getInterfaceContext: getInterfaceContextHandler,\n snap_listEntropySources: listEntropySourcesHandler,\n snap_resolveInterface: resolveInterfaceHandler,\n snap_getCurrencyRate: getCurrencyRateHandler,\n snap_experimentalProviderRequest: providerRequestHandler,\n snap_scheduleBackgroundEvent: scheduleBackgroundEventHandler,\n snap_cancelBackgroundEvent: cancelBackgroundEventHandler,\n snap_getBackgroundEvents: getBackgroundEventsHandler,\n snap_setState: setStateHandler,\n snap_trackEvent: trackEventHandler,\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const handlers = Object.values(methodHandlers);\n"]}
@@ -15,11 +15,19 @@ export declare const methodHandlers: {
15
15
  size: number;
16
16
  contentType: string;
17
17
  contents: string;
18
+ } | {
19
+ symbol: string;
20
+ name: string;
21
+ asset: `${string}:${string}/${string}:${string}`;
18
22
  } | Record<string, string | boolean | {
19
23
  name: string;
20
24
  size: number;
21
25
  contentType: string;
22
26
  contents: string;
27
+ } | {
28
+ symbol: string;
29
+ name: string;
30
+ asset: `${string}:${string}/${string}:${string}`;
23
31
  } | null> | null>>;
24
32
  snap_getInterfaceContext: import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.cjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult>;
25
33
  snap_listEntropySources: import("@metamask/permission-controller").PermittedHandlerExport<import("./listEntropySources.cjs").ListEntropySourcesHooks, never, import("@metamask/snaps-sdk").ListEntropySourcesResult>;
@@ -30,16 +38,25 @@ export declare const methodHandlers: {
30
38
  snap_cancelBackgroundEvent: import("@metamask/permission-controller").PermittedHandlerExport<import("./cancelBackgroundEvent.cjs").CancelBackgroundEventMethodHooks, import("@metamask/snaps-sdk").CancelBackgroundEventParams, null>;
31
39
  snap_getBackgroundEvents: import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.cjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult>;
32
40
  snap_setState: import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.cjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null>;
41
+ snap_trackEvent: import("@metamask/permission-controller").PermittedHandlerExport<import("./trackEvent.cjs").TrackEventMethodHooks, import("@metamask/snaps-sdk").TrackEventParams, null>;
33
42
  };
34
43
  export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./cancelBackgroundEvent.cjs").CancelBackgroundEventMethodHooks, import("@metamask/snaps-sdk").CancelBackgroundEventParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./clearState.cjs").ClearStateHooks, import("@metamask/snaps-sdk").ClearStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.cjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.cjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getAllSnaps.cjs").GetAllSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.cjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getClientStatus.cjs").GetClientStatusHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetClientStatusResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.cjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.cjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
35
44
  name: string;
36
45
  size: number;
37
46
  contentType: string;
38
47
  contents: string;
48
+ } | {
49
+ symbol: string;
50
+ name: string;
51
+ asset: `${string}:${string}/${string}:${string}`;
39
52
  } | Record<string, string | boolean | {
40
53
  name: string;
41
54
  size: number;
42
55
  contentType: string;
43
56
  contents: string;
44
- } | null> | null>> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps.cjs").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getState.cjs").GetStateHooks, import("@metamask/snaps-sdk").GetStateParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./listEntropySources.cjs").ListEntropySourcesHooks, never, import("@metamask/snaps-sdk").ListEntropySourcesResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps.cjs").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.cjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./scheduleBackgroundEvent.cjs").ScheduleBackgroundEventMethodHooks, import("@metamask/snaps-sdk").ScheduleBackgroundEventParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.cjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.cjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile.cjs").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.cjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeSnapSugar.cjs").InvokeSnapSugarHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring.cjs").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json>)[];
57
+ } | {
58
+ symbol: string;
59
+ name: string;
60
+ asset: `${string}:${string}/${string}:${string}`;
61
+ } | null> | null>> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps.cjs").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getState.cjs").GetStateHooks, import("@metamask/snaps-sdk").GetStateParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./listEntropySources.cjs").ListEntropySourcesHooks, never, import("@metamask/snaps-sdk").ListEntropySourcesResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps.cjs").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.cjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./scheduleBackgroundEvent.cjs").ScheduleBackgroundEventMethodHooks, import("@metamask/snaps-sdk").ScheduleBackgroundEventParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.cjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.cjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile.cjs").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.cjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeSnapSugar.cjs").InvokeSnapSugarHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring.cjs").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./trackEvent.cjs").TrackEventMethodHooks, import("@metamask/snaps-sdk").TrackEventParams, null>)[];
45
62
  //# sourceMappingURL=handlers.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.d.cts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAuBA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsB1B,CAAC;AAGF,eAAO,MAAM,QAAQ;;;;;;;;;;owEAAgC,CAAC"}
1
+ {"version":3,"file":"handlers.d.cts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAwBA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuB1B,CAAC;AAGF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;26EAAgC,CAAC"}
@@ -15,11 +15,19 @@ export declare const methodHandlers: {
15
15
  size: number;
16
16
  contentType: string;
17
17
  contents: string;
18
+ } | {
19
+ symbol: string;
20
+ name: string;
21
+ asset: `${string}:${string}/${string}:${string}`;
18
22
  } | Record<string, string | boolean | {
19
23
  name: string;
20
24
  size: number;
21
25
  contentType: string;
22
26
  contents: string;
27
+ } | {
28
+ symbol: string;
29
+ name: string;
30
+ asset: `${string}:${string}/${string}:${string}`;
23
31
  } | null> | null>>;
24
32
  snap_getInterfaceContext: import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.mjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult>;
25
33
  snap_listEntropySources: import("@metamask/permission-controller").PermittedHandlerExport<import("./listEntropySources.mjs").ListEntropySourcesHooks, never, import("@metamask/snaps-sdk").ListEntropySourcesResult>;
@@ -30,16 +38,25 @@ export declare const methodHandlers: {
30
38
  snap_cancelBackgroundEvent: import("@metamask/permission-controller").PermittedHandlerExport<import("./cancelBackgroundEvent.mjs").CancelBackgroundEventMethodHooks, import("@metamask/snaps-sdk").CancelBackgroundEventParams, null>;
31
39
  snap_getBackgroundEvents: import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.mjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult>;
32
40
  snap_setState: import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.mjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null>;
41
+ snap_trackEvent: import("@metamask/permission-controller").PermittedHandlerExport<import("./trackEvent.mjs").TrackEventMethodHooks, import("@metamask/snaps-sdk").TrackEventParams, null>;
33
42
  };
34
43
  export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./cancelBackgroundEvent.mjs").CancelBackgroundEventMethodHooks, import("@metamask/snaps-sdk").CancelBackgroundEventParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./clearState.mjs").ClearStateHooks, import("@metamask/snaps-sdk").ClearStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.mjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.mjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getAllSnaps.mjs").GetAllSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getBackgroundEvents.mjs").GetBackgroundEventsMethodHooks, never, import("@metamask/snaps-sdk").GetBackgroundEventsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getClientStatus.mjs").GetClientStatusHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetClientStatusResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.mjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceState.mjs").GetInterfaceStateMethodHooks, import("@metamask/snaps-sdk").GetInterfaceStateParams, Record<string, string | boolean | {
35
44
  name: string;
36
45
  size: number;
37
46
  contentType: string;
38
47
  contents: string;
48
+ } | {
49
+ symbol: string;
50
+ name: string;
51
+ asset: `${string}:${string}/${string}:${string}`;
39
52
  } | Record<string, string | boolean | {
40
53
  name: string;
41
54
  size: number;
42
55
  contentType: string;
43
56
  contents: string;
44
- } | null> | null>> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps.mjs").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getState.mjs").GetStateHooks, import("@metamask/snaps-sdk").GetStateParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./listEntropySources.mjs").ListEntropySourcesHooks, never, import("@metamask/snaps-sdk").ListEntropySourcesResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps.mjs").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.mjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./scheduleBackgroundEvent.mjs").ScheduleBackgroundEventMethodHooks, import("@metamask/snaps-sdk").ScheduleBackgroundEventParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.mjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.mjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile.mjs").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.mjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeSnapSugar.mjs").InvokeSnapSugarHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring.mjs").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json>)[];
57
+ } | {
58
+ symbol: string;
59
+ name: string;
60
+ asset: `${string}:${string}/${string}:${string}`;
61
+ } | null> | null>> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getSnaps.mjs").GetSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getState.mjs").GetStateHooks, import("@metamask/snaps-sdk").GetStateParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./listEntropySources.mjs").ListEntropySourcesHooks, never, import("@metamask/snaps-sdk").ListEntropySourcesResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./requestSnaps.mjs").RequestSnapsHooks, import("@metamask/snaps-sdk").RequestSnapsParams, import("@metamask/snaps-sdk").RequestSnapsResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.mjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./scheduleBackgroundEvent.mjs").ScheduleBackgroundEventMethodHooks, import("@metamask/snaps-sdk").ScheduleBackgroundEventParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./setState.mjs").SetStateHooks, import("@metamask/snaps-sdk").SetStateParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./updateInterface.mjs").UpdateInterfaceMethodHooks, import("@metamask/snaps-sdk").UpdateInterfaceParams, null> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getFile.mjs").GetFileHooks, import("@metamask/snaps-sdk").GetFileParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getInterfaceContext.mjs").GetInterfaceContextMethodHooks, import("@metamask/snaps-sdk").GetInterfaceContextParams, import("@metamask/snaps-sdk").GetInterfaceContextResult> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeSnapSugar.mjs").InvokeSnapSugarHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./invokeKeyring.mjs").InvokeKeyringHooks, import("@metamask/snaps-sdk").InvokeSnapParams, import("@metamask/utils").Json> | import("@metamask/permission-controller").PermittedHandlerExport<import("./trackEvent.mjs").TrackEventMethodHooks, import("@metamask/snaps-sdk").TrackEventParams, null>)[];
45
62
  //# sourceMappingURL=handlers.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.d.mts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAuBA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsB1B,CAAC;AAGF,eAAO,MAAM,QAAQ;;;;;;;;;;owEAAgC,CAAC"}
1
+ {"version":3,"file":"handlers.d.mts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAwBA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAuB1B,CAAC;AAGF,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;26EAAgC,CAAC"}
@@ -18,6 +18,7 @@ import { requestSnapsHandler } from "./requestSnaps.mjs";
18
18
  import { resolveInterfaceHandler } from "./resolveInterface.mjs";
19
19
  import { scheduleBackgroundEventHandler } from "./scheduleBackgroundEvent.mjs";
20
20
  import { setStateHandler } from "./setState.mjs";
21
+ import { trackEventHandler } from "./trackEvent.mjs";
21
22
  import { updateInterfaceHandler } from "./updateInterface.mjs";
22
23
  /* eslint-disable @typescript-eslint/naming-convention */
23
24
  export const methodHandlers = {
@@ -42,6 +43,7 @@ export const methodHandlers = {
42
43
  snap_cancelBackgroundEvent: cancelBackgroundEventHandler,
43
44
  snap_getBackgroundEvents: getBackgroundEventsHandler,
44
45
  snap_setState: setStateHandler,
46
+ snap_trackEvent: trackEventHandler,
45
47
  };
46
48
  /* eslint-enable @typescript-eslint/naming-convention */
47
49
  export const handlers = Object.values(methodHandlers);
@@ -1 +1 @@
1
- {"version":3,"file":"handlers.mjs","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,oCAAgC;AACvE,OAAO,EAAE,iBAAiB,EAAE,yBAAqB;AACjD,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,sBAAsB,EAAE,0CAAsC;AACvE,OAAO,EAAE,kBAAkB,EAAE,0BAAsB;AACnD,OAAO,EAAE,0BAA0B,EAAE,kCAA8B;AACnE,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,cAAc,EAAE,sBAAkB;AAC3C,OAAO,EAAE,0BAA0B,EAAE,kCAA8B;AACnE,OAAO,EAAE,wBAAwB,EAAE,gCAA4B;AAC/D,OAAO,EAAE,eAAe,EAAE,uBAAmB;AAC7C,OAAO,EAAE,eAAe,EAAE,uBAAmB;AAC7C,OAAO,EAAE,oBAAoB,EAAE,4BAAwB;AACvD,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,yBAAyB,EAAE,iCAA6B;AACjE,OAAO,EAAE,mBAAmB,EAAE,2BAAuB;AACrD,OAAO,EAAE,uBAAuB,EAAE,+BAA2B;AAC7D,OAAO,EAAE,8BAA8B,EAAE,sCAAkC;AAC3E,OAAO,EAAE,eAAe,EAAE,uBAAmB;AAC7C,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAE3D,yDAAyD;AACzD,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,kBAAkB,EAAE,kBAAkB;IACtC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,mBAAmB;IACxC,iBAAiB,EAAE,sBAAsB;IACzC,oBAAoB,EAAE,oBAAoB;IAC1C,eAAe,EAAE,iBAAiB;IAClC,oBAAoB,EAAE,sBAAsB;IAC5C,YAAY,EAAE,cAAc;IAC5B,aAAa,EAAE,eAAe;IAC9B,oBAAoB,EAAE,sBAAsB;IAC5C,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;IAChD,wBAAwB,EAAE,0BAA0B;IACpD,uBAAuB,EAAE,yBAAyB;IAClD,qBAAqB,EAAE,uBAAuB;IAC9C,oBAAoB,EAAE,sBAAsB;IAC5C,gCAAgC,EAAE,sBAAsB;IACxD,4BAA4B,EAAE,8BAA8B;IAC5D,0BAA0B,EAAE,4BAA4B;IACxD,wBAAwB,EAAE,0BAA0B;IACpD,aAAa,EAAE,eAAe;CAC/B,CAAC;AACF,wDAAwD;AAExD,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC","sourcesContent":["import { cancelBackgroundEventHandler } from './cancelBackgroundEvent';\nimport { clearStateHandler } from './clearState';\nimport { createInterfaceHandler } from './createInterface';\nimport { providerRequestHandler } from './experimentalProviderRequest';\nimport { getAllSnapsHandler } from './getAllSnaps';\nimport { getBackgroundEventsHandler } from './getBackgroundEvents';\nimport { getClientStatusHandler } from './getClientStatus';\nimport { getCurrencyRateHandler } from './getCurrencyRate';\nimport { getFileHandler } from './getFile';\nimport { getInterfaceContextHandler } from './getInterfaceContext';\nimport { getInterfaceStateHandler } from './getInterfaceState';\nimport { getSnapsHandler } from './getSnaps';\nimport { getStateHandler } from './getState';\nimport { invokeKeyringHandler } from './invokeKeyring';\nimport { invokeSnapSugarHandler } from './invokeSnapSugar';\nimport { listEntropySourcesHandler } from './listEntropySources';\nimport { requestSnapsHandler } from './requestSnaps';\nimport { resolveInterfaceHandler } from './resolveInterface';\nimport { scheduleBackgroundEventHandler } from './scheduleBackgroundEvent';\nimport { setStateHandler } from './setState';\nimport { updateInterfaceHandler } from './updateInterface';\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const methodHandlers = {\n wallet_getAllSnaps: getAllSnapsHandler,\n wallet_getSnaps: getSnapsHandler,\n wallet_requestSnaps: requestSnapsHandler,\n wallet_invokeSnap: invokeSnapSugarHandler,\n wallet_invokeKeyring: invokeKeyringHandler,\n snap_clearState: clearStateHandler,\n snap_getClientStatus: getClientStatusHandler,\n snap_getFile: getFileHandler,\n snap_getState: getStateHandler,\n snap_createInterface: createInterfaceHandler,\n snap_updateInterface: updateInterfaceHandler,\n snap_getInterfaceState: getInterfaceStateHandler,\n snap_getInterfaceContext: getInterfaceContextHandler,\n snap_listEntropySources: listEntropySourcesHandler,\n snap_resolveInterface: resolveInterfaceHandler,\n snap_getCurrencyRate: getCurrencyRateHandler,\n snap_experimentalProviderRequest: providerRequestHandler,\n snap_scheduleBackgroundEvent: scheduleBackgroundEventHandler,\n snap_cancelBackgroundEvent: cancelBackgroundEventHandler,\n snap_getBackgroundEvents: getBackgroundEventsHandler,\n snap_setState: setStateHandler,\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const handlers = Object.values(methodHandlers);\n"]}
1
+ {"version":3,"file":"handlers.mjs","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,4BAA4B,EAAE,oCAAgC;AACvE,OAAO,EAAE,iBAAiB,EAAE,yBAAqB;AACjD,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,sBAAsB,EAAE,0CAAsC;AACvE,OAAO,EAAE,kBAAkB,EAAE,0BAAsB;AACnD,OAAO,EAAE,0BAA0B,EAAE,kCAA8B;AACnE,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,cAAc,EAAE,sBAAkB;AAC3C,O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,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC","sourcesContent":["import { cancelBackgroundEventHandler } from './cancelBackgroundEvent';\nimport { clearStateHandler } from './clearState';\nimport { createInterfaceHandler } from './createInterface';\nimport { providerRequestHandler } from './experimentalProviderRequest';\nimport { getAllSnapsHandler } from './getAllSnaps';\nimport { getBackgroundEventsHandler } from './getBackgroundEvents';\nimport { getClientStatusHandler } from './getClientStatus';\nimport { getCurrencyRateHandler } from './getCurrencyRate';\nimport { getFileHandler } from './getFile';\nimport { getInterfaceContextHandler } from './getInterfaceContext';\nimport { getInterfaceStateHandler } from './getInterfaceState';\nimport { getSnapsHandler } from './getSnaps';\nimport { getStateHandler } from './getState';\nimport { invokeKeyringHandler } from './invokeKeyring';\nimport { invokeSnapSugarHandler } from './invokeSnapSugar';\nimport { listEntropySourcesHandler } from './listEntropySources';\nimport { requestSnapsHandler } from './requestSnaps';\nimport { resolveInterfaceHandler } from './resolveInterface';\nimport { scheduleBackgroundEventHandler } from './scheduleBackgroundEvent';\nimport { setStateHandler } from './setState';\nimport { trackEventHandler } from './trackEvent';\nimport { updateInterfaceHandler } from './updateInterface';\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const methodHandlers = {\n wallet_getAllSnaps: getAllSnapsHandler,\n wallet_getSnaps: getSnapsHandler,\n wallet_requestSnaps: requestSnapsHandler,\n wallet_invokeSnap: invokeSnapSugarHandler,\n wallet_invokeKeyring: invokeKeyringHandler,\n snap_clearState: clearStateHandler,\n snap_getClientStatus: getClientStatusHandler,\n snap_getFile: getFileHandler,\n snap_getState: getStateHandler,\n snap_createInterface: createInterfaceHandler,\n snap_updateInterface: updateInterfaceHandler,\n snap_getInterfaceState: getInterfaceStateHandler,\n snap_getInterfaceContext: getInterfaceContextHandler,\n snap_listEntropySources: listEntropySourcesHandler,\n snap_resolveInterface: resolveInterfaceHandler,\n snap_getCurrencyRate: getCurrencyRateHandler,\n snap_experimentalProviderRequest: providerRequestHandler,\n snap_scheduleBackgroundEvent: scheduleBackgroundEventHandler,\n snap_cancelBackgroundEvent: cancelBackgroundEventHandler,\n snap_getBackgroundEvents: getBackgroundEventsHandler,\n snap_setState: setStateHandler,\n snap_trackEvent: trackEventHandler,\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const handlers = Object.values(methodHandlers);\n"]}