@metamask/snaps-rpc-methods 11.2.0 → 11.4.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 (48) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/dist/permitted/createInterface.d.cts +2 -0
  3. package/dist/permitted/createInterface.d.cts.map +1 -1
  4. package/dist/permitted/createInterface.d.mts +2 -0
  5. package/dist/permitted/createInterface.d.mts.map +1 -1
  6. package/dist/permitted/experimentalProviderRequest.cjs +146 -0
  7. package/dist/permitted/experimentalProviderRequest.cjs.map +1 -0
  8. package/dist/permitted/experimentalProviderRequest.d.cts +39 -0
  9. package/dist/permitted/experimentalProviderRequest.d.cts.map +1 -0
  10. package/dist/permitted/experimentalProviderRequest.d.mts +39 -0
  11. package/dist/permitted/experimentalProviderRequest.d.mts.map +1 -0
  12. package/dist/permitted/experimentalProviderRequest.mjs +143 -0
  13. package/dist/permitted/experimentalProviderRequest.mjs.map +1 -0
  14. package/dist/permitted/getCurrencyRate.cjs +63 -0
  15. package/dist/permitted/getCurrencyRate.cjs.map +1 -0
  16. package/dist/permitted/getCurrencyRate.d.cts +20 -0
  17. package/dist/permitted/getCurrencyRate.d.cts.map +1 -0
  18. package/dist/permitted/getCurrencyRate.d.mts +20 -0
  19. package/dist/permitted/getCurrencyRate.d.mts.map +1 -0
  20. package/dist/permitted/getCurrencyRate.mjs +60 -0
  21. package/dist/permitted/getCurrencyRate.mjs.map +1 -0
  22. package/dist/permitted/handlers.cjs +4 -0
  23. package/dist/permitted/handlers.cjs.map +1 -1
  24. package/dist/permitted/handlers.d.cts +3 -1
  25. package/dist/permitted/handlers.d.cts.map +1 -1
  26. package/dist/permitted/handlers.d.mts +3 -1
  27. package/dist/permitted/handlers.d.mts.map +1 -1
  28. package/dist/permitted/handlers.mjs +4 -0
  29. package/dist/permitted/handlers.mjs.map +1 -1
  30. package/dist/permitted/index.cjs.map +1 -1
  31. package/dist/permitted/index.d.cts +3 -1
  32. package/dist/permitted/index.d.cts.map +1 -1
  33. package/dist/permitted/index.d.mts +3 -1
  34. package/dist/permitted/index.d.mts.map +1 -1
  35. package/dist/permitted/index.mjs.map +1 -1
  36. package/dist/permitted/updateInterface.cjs +3 -2
  37. package/dist/permitted/updateInterface.cjs.map +1 -1
  38. package/dist/permitted/updateInterface.d.cts +7 -2
  39. package/dist/permitted/updateInterface.d.cts.map +1 -1
  40. package/dist/permitted/updateInterface.d.mts +7 -2
  41. package/dist/permitted/updateInterface.d.mts.map +1 -1
  42. package/dist/permitted/updateInterface.mjs +5 -4
  43. package/dist/permitted/updateInterface.mjs.map +1 -1
  44. package/dist/restricted/dialog.d.cts +4 -0
  45. package/dist/restricted/dialog.d.cts.map +1 -1
  46. package/dist/restricted/dialog.d.mts +4 -0
  47. package/dist/restricted/dialog.d.mts.map +1 -1
  48. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -7,6 +7,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [11.4.0]
11
+
12
+ ### Added
13
+
14
+ - Add `snap_experimentalProviderRequest` JSON-RPC method ([#2773](https://github.com/MetaMask/snaps/pull/2773))
15
+ - This method is experimental and will likely be removed in a future release.
16
+
17
+ ### Changed
18
+
19
+ - Allow updating interface context ([#2809](https://github.com/MetaMask/snaps/pull/2809))
20
+ - `snap_updateInterface` now accepts a `context` parameter to update the
21
+ context of an interface.
22
+
23
+ ### Fixed
24
+
25
+ - Use `BigInt` to parse chain IDs ([#2781](https://github.com/MetaMask/snaps/pull/2781))
26
+
27
+ ## [11.3.0]
28
+
29
+ ### Added
30
+
31
+ - Add `snap_getCurrencyRate` JSON-RPC method ([#2763](https://github.com/MetaMask/snaps/pull/2763))
32
+
10
33
  ## [11.2.0]
11
34
 
12
35
  ### Added
@@ -291,7 +314,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
291
314
  - The version of the package no longer needs to match the version of all other
292
315
  MetaMask Snaps packages.
293
316
 
294
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.2.0...HEAD
317
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.4.0...HEAD
318
+ [11.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.3.0...@metamask/snaps-rpc-methods@11.4.0
319
+ [11.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.2.0...@metamask/snaps-rpc-methods@11.3.0
295
320
  [11.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.1.1...@metamask/snaps-rpc-methods@11.2.0
296
321
  [11.1.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.1.0...@metamask/snaps-rpc-methods@11.1.1
297
322
  [11.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.0.0...@metamask/snaps-rpc-methods@11.1.0
@@ -96,6 +96,7 @@ declare const CreateInterfaceParametersStruct: import("@metamask/superstruct").S
96
96
  }, "Radio">>;
97
97
  }, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
98
98
  children: import("@metamask/snaps-sdk/jsx").StringElement;
99
+ size?: "md" | "lg" | undefined;
99
100
  }, "Heading">;
100
101
  context?: Record<string, import("@metamask/snaps-sdk").Json> | undefined;
101
102
  }, {
@@ -185,6 +186,7 @@ declare const CreateInterfaceParametersStruct: import("@metamask/superstruct").S
185
186
  }, "Radio">>;
186
187
  }, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
187
188
  children: import("@metamask/snaps-sdk/jsx").StringElement;
189
+ size?: "md" | "lg" | undefined;
188
190
  }, "Heading">, null>;
189
191
  context: import("@metamask/superstruct").Struct<Record<string, import("@metamask/snaps-sdk").Json> | undefined, null>;
190
192
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"createInterface.d.cts","sourceRoot":"","sources":["../../src/permitted/createInterface.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EAErB,kBAAkB,EAClB,gBAAgB,EACjB,4BAA4B;AAK7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAU3D,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;OAGG;IACH,eAAe,EAAE,CACf,EAAE,EAAE,kBAAkB,EACtB,OAAO,CAAC,EAAE,gBAAgB,KACvB,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,CAKtB,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBA4CrC;;;;;;WAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBANH;;;;;;WAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA/CD,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,aAAa,CACnD,OAAO,+BAA+B,EACtC,qBAAqB,CACtB,CAAC"}
1
+ {"version":3,"file":"createInterface.d.cts","sourceRoot":"","sources":["../../src/permitted/createInterface.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EAErB,kBAAkB,EAClB,gBAAgB,EACjB,4BAA4B;AAK7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAU3D,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;OAGG;IACH,eAAe,EAAE,CACf,EAAE,EAAE,kBAAkB,EACtB,OAAO,CAAC,EAAE,gBAAgB,KACvB,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,CAKtB,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBA4CrC;;;;;;WAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBANH;;;;;;WAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA/CD,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,aAAa,CACnD,OAAO,+BAA+B,EACtC,qBAAqB,CACtB,CAAC"}
@@ -96,6 +96,7 @@ declare const CreateInterfaceParametersStruct: import("@metamask/superstruct").S
96
96
  }, "Radio">>;
97
97
  }, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
98
98
  children: import("@metamask/snaps-sdk/jsx").StringElement;
99
+ size?: "md" | "lg" | undefined;
99
100
  }, "Heading">;
100
101
  context?: Record<string, import("@metamask/snaps-sdk").Json> | undefined;
101
102
  }, {
@@ -185,6 +186,7 @@ declare const CreateInterfaceParametersStruct: import("@metamask/superstruct").S
185
186
  }, "Radio">>;
186
187
  }, "RadioGroup"> | import("@metamask/snaps-sdk/jsx").SnapElement<{
187
188
  children: import("@metamask/snaps-sdk/jsx").StringElement;
189
+ size?: "md" | "lg" | undefined;
188
190
  }, "Heading">, null>;
189
191
  context: import("@metamask/superstruct").Struct<Record<string, import("@metamask/snaps-sdk").Json> | undefined, null>;
190
192
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"createInterface.d.mts","sourceRoot":"","sources":["../../src/permitted/createInterface.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EAErB,kBAAkB,EAClB,gBAAgB,EACjB,4BAA4B;AAK7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAU3D,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;OAGG;IACH,eAAe,EAAE,CACf,EAAE,EAAE,kBAAkB,EACtB,OAAO,CAAC,EAAE,gBAAgB,KACvB,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,CAKtB,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBA4CrC;;;;;;WAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBANH;;;;;;WAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA/CD,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,aAAa,CACnD,OAAO,+BAA+B,EACtC,qBAAqB,CACtB,CAAC"}
1
+ {"version":3,"file":"createInterface.d.mts","sourceRoot":"","sources":["../../src/permitted/createInterface.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EAErB,kBAAkB,EAClB,gBAAgB,EACjB,4BAA4B;AAK7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAU3D,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;OAGG;IACH,eAAe,EAAE,CACf,EAAE,EAAE,kBAAkB,EACtB,OAAO,CAAC,EAAE,gBAAgB,KACvB,OAAO,CAAC,MAAM,CAAC,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,CAKtB,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBA4CrC;;;;;;WAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;uBANH;;;;;;WAMG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA/CD,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,aAAa,CACnD,OAAO,+BAA+B,EACtC,qBAAqB,CACtB,CAAC"}
@@ -0,0 +1,146 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.providerRequestHandler = void 0;
4
+ const rpc_errors_1 = require("@metamask/rpc-errors");
5
+ const superstruct_1 = require("@metamask/superstruct");
6
+ const utils_1 = require("@metamask/utils");
7
+ const endowments_1 = require("../endowments/index.cjs");
8
+ // Read-only methods that are currently allowed for this RPC method.
9
+ const METHOD_ALLOWLIST = Object.freeze([
10
+ 'eth_blockNumber',
11
+ 'eth_call',
12
+ 'eth_chainId',
13
+ 'eth_coinbase',
14
+ 'eth_estimateGas',
15
+ 'eth_feeHistory',
16
+ 'eth_gasPrice',
17
+ 'eth_getBalance',
18
+ 'eth_getBlockByHash',
19
+ 'eth_getBlockByNumber',
20
+ 'eth_getBlockTransactionCountByHash',
21
+ 'eth_getBlockTransactionCountByNumber',
22
+ 'eth_getCode',
23
+ 'eth_getFilterChanges',
24
+ 'eth_getFilterLogs',
25
+ 'eth_getLogs',
26
+ 'eth_getProof',
27
+ 'eth_getStorageAt',
28
+ 'eth_getTransactionByBlockHashAndIndex',
29
+ 'eth_getTransactionByBlockNumberAndIndex',
30
+ 'eth_getTransactionByHash',
31
+ 'eth_getTransactionCount',
32
+ 'eth_getTransactionReceipt',
33
+ 'eth_getUncleByBlockHashAndIndex',
34
+ 'eth_getUncleByBlockNumberAndIndex',
35
+ 'eth_getUncleCountByBlockHash',
36
+ 'eth_getUncleCountByBlockNumber',
37
+ 'eth_getWork',
38
+ 'eth_hashrate',
39
+ 'eth_mining',
40
+ 'eth_newBlockFilter',
41
+ 'eth_newFilter',
42
+ 'eth_newPendingTransactionFilter',
43
+ 'eth_protocolVersion',
44
+ 'eth_sendRawTransaction',
45
+ 'eth_submitHashrate',
46
+ 'eth_submitWork',
47
+ 'eth_syncing',
48
+ 'eth_uninstallFilter',
49
+ 'net_listening',
50
+ 'net_peerCount',
51
+ 'net_version',
52
+ 'web3_clientVersion',
53
+ 'web3_sha3',
54
+ ]);
55
+ const hookNames = {
56
+ hasPermission: true,
57
+ getNetworkConfigurationByChainId: true,
58
+ getNetworkClientById: true,
59
+ };
60
+ exports.providerRequestHandler = {
61
+ methodNames: ['snap_experimentalProviderRequest'],
62
+ implementation: providerRequestImplementation,
63
+ hookNames,
64
+ };
65
+ const ProviderRequestParametersStruct = (0, superstruct_1.object)({
66
+ chainId: utils_1.CaipChainIdStruct,
67
+ request: (0, superstruct_1.type)({
68
+ method: (0, superstruct_1.string)(),
69
+ params: (0, superstruct_1.optional)(utils_1.JsonRpcParamsStruct),
70
+ }),
71
+ });
72
+ /**
73
+ * The `snap_experimentalProviderRequest` method implementation.
74
+ *
75
+ * This RPC method lets Snaps make requests to MetaMask networks that are not currently selected in the UI.
76
+ *
77
+ * The RPC method requires the caller to have the endowment:ethereum-provider permission.
78
+ *
79
+ * NOTE: This implementation is experimental and may be removed or changed without warning.
80
+ *
81
+ * @param req - The JSON-RPC request object.
82
+ * @param res - The JSON-RPC response object.
83
+ * @param _next - The `json-rpc-engine` "next" callback. Not used by this
84
+ * function.
85
+ * @param end - The `json-rpc-engine` "end" callback.
86
+ * @param hooks - The RPC method hooks.
87
+ * @param hooks.hasPermission - Checks whether a given origin has a given permission.
88
+ * @param hooks.getNetworkConfigurationByChainId - Get a network configuration for a given chain ID.
89
+ * @param hooks.getNetworkClientById - Get a network client for a given ID.
90
+ * @returns Nothing.
91
+ */
92
+ async function providerRequestImplementation(req, res, _next, end, { hasPermission, getNetworkConfigurationByChainId, getNetworkClientById, }) {
93
+ if (!hasPermission(endowments_1.SnapEndowments.EthereumProvider)) {
94
+ return end(rpc_errors_1.rpcErrors.methodNotFound());
95
+ }
96
+ const { params } = req;
97
+ try {
98
+ const { chainId, request } = getValidatedParams(params);
99
+ if (!METHOD_ALLOWLIST.includes(request.method)) {
100
+ return end(rpc_errors_1.rpcErrors.methodNotFound());
101
+ }
102
+ const parsedChainId = (0, utils_1.parseCaipChainId)(chainId);
103
+ if (parsedChainId.namespace !== 'eip155') {
104
+ return end(rpc_errors_1.rpcErrors.invalidParams({
105
+ message: 'Only EVM networks are currently supported.',
106
+ }));
107
+ }
108
+ const numericalChainId = BigInt(parsedChainId.reference);
109
+ const networkConfiguration = getNetworkConfigurationByChainId((0, utils_1.bigIntToHex)(numericalChainId));
110
+ if (!networkConfiguration) {
111
+ return end(rpc_errors_1.rpcErrors.invalidParams({
112
+ message: 'The requested network is not available.',
113
+ }));
114
+ }
115
+ const rpc = networkConfiguration.rpcEndpoints[networkConfiguration.defaultRpcEndpointIndex];
116
+ const networkClient = getNetworkClientById(rpc.networkClientId);
117
+ const { provider } = networkClient;
118
+ res.result = await provider.request(request);
119
+ }
120
+ catch (error) {
121
+ return end(error);
122
+ }
123
+ return end();
124
+ }
125
+ /**
126
+ * Validate the method `params` and returns them cast to the correct
127
+ * type. Throws if validation fails.
128
+ *
129
+ * @param params - The unvalidated params object from the method request.
130
+ * @returns The validated updateInterface method parameter object.
131
+ */
132
+ function getValidatedParams(params) {
133
+ try {
134
+ return (0, superstruct_1.create)(params, ProviderRequestParametersStruct);
135
+ }
136
+ catch (error) {
137
+ if (error instanceof superstruct_1.StructError) {
138
+ throw rpc_errors_1.rpcErrors.invalidParams({
139
+ message: `Invalid params: ${error.message}.`,
140
+ });
141
+ }
142
+ /* istanbul ignore next */
143
+ throw rpc_errors_1.rpcErrors.internal();
144
+ }
145
+ }
146
+ //# sourceMappingURL=experimentalProviderRequest.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"experimentalProviderRequest.cjs","sourceRoot":"","sources":["../../src/permitted/experimentalProviderRequest.ts"],"names":[],"mappings":"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","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"]}
@@ -0,0 +1,39 @@
1
+ import type { PermittedHandlerExport } from "@metamask/permission-controller";
2
+ import type { ProviderRequestParams, ProviderRequestResult } from "@metamask/snaps-sdk";
3
+ import { type InferMatching } from "@metamask/snaps-utils";
4
+ import { type Json } from "@metamask/utils";
5
+ type NetworkConfiguration = {
6
+ defaultRpcEndpointIndex: number;
7
+ rpcEndpoints: {
8
+ networkClientId: string;
9
+ }[];
10
+ };
11
+ export type ProviderRequestMethodHooks = {
12
+ hasPermission: (permissionName: string) => boolean;
13
+ getNetworkConfigurationByChainId: (chainId: string) => NetworkConfiguration | undefined;
14
+ getNetworkClientById: (id: string) => {
15
+ provider: {
16
+ request: (request: Json) => Promise<Json>;
17
+ };
18
+ };
19
+ };
20
+ export declare const providerRequestHandler: PermittedHandlerExport<ProviderRequestMethodHooks, ProviderRequestParameters, ProviderRequestResult>;
21
+ declare const ProviderRequestParametersStruct: import("@metamask/superstruct").Struct<{
22
+ request: {
23
+ method: string;
24
+ params?: Record<string, Json> | Json[] | undefined;
25
+ };
26
+ chainId: `${string}:${string}`;
27
+ }, {
28
+ chainId: import("@metamask/superstruct").Struct<`${string}:${string}`, null>;
29
+ request: import("@metamask/superstruct").Struct<{
30
+ method: string;
31
+ params?: Record<string, Json> | Json[] | undefined;
32
+ }, {
33
+ method: import("@metamask/superstruct").Struct<string, null>;
34
+ params: import("@metamask/superstruct").Struct<Record<string, Json> | Json[] | undefined, null>;
35
+ }>;
36
+ }>;
37
+ export type ProviderRequestParameters = InferMatching<typeof ProviderRequestParametersStruct, ProviderRequestParams>;
38
+ export {};
39
+ //# sourceMappingURL=experimentalProviderRequest.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"experimentalProviderRequest.d.cts","sourceRoot":"","sources":["../../src/permitted/experimentalProviderRequest.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EAEV,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAC7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAS3D,OAAO,EAIL,KAAK,IAAI,EAGV,wBAAwB;AA2DzB,KAAK,oBAAoB,GAAG;IAC1B,uBAAuB,EAAE,MAAM,CAAC;IAChC,YAAY,EAAE;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnD,gCAAgC,EAAE,CAChC,OAAO,EAAE,MAAM,KACZ,oBAAoB,GAAG,SAAS,CAAC;IAEtC,oBAAoB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK;QACpC,QAAQ,EAAE;YAAE,OAAO,EAAE,CAAC,OAAO,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;SAAE,CAAC;KACzD,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,CAKtB,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;;;;;;;;;;;;EAMnC,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,aAAa,CACnD,OAAO,+BAA+B,EACtC,qBAAqB,CACtB,CAAC"}
@@ -0,0 +1,39 @@
1
+ import type { PermittedHandlerExport } from "@metamask/permission-controller";
2
+ import type { ProviderRequestParams, ProviderRequestResult } from "@metamask/snaps-sdk";
3
+ import { type InferMatching } from "@metamask/snaps-utils";
4
+ import { type Json } from "@metamask/utils";
5
+ type NetworkConfiguration = {
6
+ defaultRpcEndpointIndex: number;
7
+ rpcEndpoints: {
8
+ networkClientId: string;
9
+ }[];
10
+ };
11
+ export type ProviderRequestMethodHooks = {
12
+ hasPermission: (permissionName: string) => boolean;
13
+ getNetworkConfigurationByChainId: (chainId: string) => NetworkConfiguration | undefined;
14
+ getNetworkClientById: (id: string) => {
15
+ provider: {
16
+ request: (request: Json) => Promise<Json>;
17
+ };
18
+ };
19
+ };
20
+ export declare const providerRequestHandler: PermittedHandlerExport<ProviderRequestMethodHooks, ProviderRequestParameters, ProviderRequestResult>;
21
+ declare const ProviderRequestParametersStruct: import("@metamask/superstruct").Struct<{
22
+ request: {
23
+ method: string;
24
+ params?: Record<string, Json> | Json[] | undefined;
25
+ };
26
+ chainId: `${string}:${string}`;
27
+ }, {
28
+ chainId: import("@metamask/superstruct").Struct<`${string}:${string}`, null>;
29
+ request: import("@metamask/superstruct").Struct<{
30
+ method: string;
31
+ params?: Record<string, Json> | Json[] | undefined;
32
+ }, {
33
+ method: import("@metamask/superstruct").Struct<string, null>;
34
+ params: import("@metamask/superstruct").Struct<Record<string, Json> | Json[] | undefined, null>;
35
+ }>;
36
+ }>;
37
+ export type ProviderRequestParameters = InferMatching<typeof ProviderRequestParametersStruct, ProviderRequestParams>;
38
+ export {};
39
+ //# sourceMappingURL=experimentalProviderRequest.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"experimentalProviderRequest.d.mts","sourceRoot":"","sources":["../../src/permitted/experimentalProviderRequest.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EAEV,qBAAqB,EACrB,qBAAqB,EACtB,4BAA4B;AAC7B,OAAO,EAAE,KAAK,aAAa,EAAE,8BAA8B;AAS3D,OAAO,EAIL,KAAK,IAAI,EAGV,wBAAwB;AA2DzB,KAAK,oBAAoB,GAAG;IAC1B,uBAAuB,EAAE,MAAM,CAAC;IAChC,YAAY,EAAE;QAAE,eAAe,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,0BAA0B,GAAG;IACvC,aAAa,EAAE,CAAC,cAAc,EAAE,MAAM,KAAK,OAAO,CAAC;IAEnD,gCAAgC,EAAE,CAChC,OAAO,EAAE,MAAM,KACZ,oBAAoB,GAAG,SAAS,CAAC;IAEtC,oBAAoB,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK;QACpC,QAAQ,EAAE;YAAE,OAAO,EAAE,CAAC,OAAO,EAAE,IAAI,KAAK,OAAO,CAAC,IAAI,CAAC,CAAA;SAAE,CAAC;KACzD,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,CAKtB,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;;;;;;;;;;;;EAMnC,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,aAAa,CACnD,OAAO,+BAA+B,EACtC,qBAAqB,CACtB,CAAC"}
@@ -0,0 +1,143 @@
1
+ import { rpcErrors } from "@metamask/rpc-errors";
2
+ import { StructError, create, object, optional, string, type } from "@metamask/superstruct";
3
+ import { bigIntToHex, parseCaipChainId, CaipChainIdStruct, JsonRpcParamsStruct } from "@metamask/utils";
4
+ import { SnapEndowments } from "../endowments/index.mjs";
5
+ // Read-only methods that are currently allowed for this RPC method.
6
+ const METHOD_ALLOWLIST = Object.freeze([
7
+ 'eth_blockNumber',
8
+ 'eth_call',
9
+ 'eth_chainId',
10
+ 'eth_coinbase',
11
+ 'eth_estimateGas',
12
+ 'eth_feeHistory',
13
+ 'eth_gasPrice',
14
+ 'eth_getBalance',
15
+ 'eth_getBlockByHash',
16
+ 'eth_getBlockByNumber',
17
+ 'eth_getBlockTransactionCountByHash',
18
+ 'eth_getBlockTransactionCountByNumber',
19
+ 'eth_getCode',
20
+ 'eth_getFilterChanges',
21
+ 'eth_getFilterLogs',
22
+ 'eth_getLogs',
23
+ 'eth_getProof',
24
+ 'eth_getStorageAt',
25
+ 'eth_getTransactionByBlockHashAndIndex',
26
+ 'eth_getTransactionByBlockNumberAndIndex',
27
+ 'eth_getTransactionByHash',
28
+ 'eth_getTransactionCount',
29
+ 'eth_getTransactionReceipt',
30
+ 'eth_getUncleByBlockHashAndIndex',
31
+ 'eth_getUncleByBlockNumberAndIndex',
32
+ 'eth_getUncleCountByBlockHash',
33
+ 'eth_getUncleCountByBlockNumber',
34
+ 'eth_getWork',
35
+ 'eth_hashrate',
36
+ 'eth_mining',
37
+ 'eth_newBlockFilter',
38
+ 'eth_newFilter',
39
+ 'eth_newPendingTransactionFilter',
40
+ 'eth_protocolVersion',
41
+ 'eth_sendRawTransaction',
42
+ 'eth_submitHashrate',
43
+ 'eth_submitWork',
44
+ 'eth_syncing',
45
+ 'eth_uninstallFilter',
46
+ 'net_listening',
47
+ 'net_peerCount',
48
+ 'net_version',
49
+ 'web3_clientVersion',
50
+ 'web3_sha3',
51
+ ]);
52
+ const hookNames = {
53
+ hasPermission: true,
54
+ getNetworkConfigurationByChainId: true,
55
+ getNetworkClientById: true,
56
+ };
57
+ export const providerRequestHandler = {
58
+ methodNames: ['snap_experimentalProviderRequest'],
59
+ implementation: providerRequestImplementation,
60
+ hookNames,
61
+ };
62
+ const ProviderRequestParametersStruct = object({
63
+ chainId: CaipChainIdStruct,
64
+ request: type({
65
+ method: string(),
66
+ params: optional(JsonRpcParamsStruct),
67
+ }),
68
+ });
69
+ /**
70
+ * The `snap_experimentalProviderRequest` method implementation.
71
+ *
72
+ * This RPC method lets Snaps make requests to MetaMask networks that are not currently selected in the UI.
73
+ *
74
+ * The RPC method requires the caller to have the endowment:ethereum-provider permission.
75
+ *
76
+ * NOTE: This implementation is experimental and may be removed or changed without warning.
77
+ *
78
+ * @param req - The JSON-RPC request object.
79
+ * @param res - The JSON-RPC response object.
80
+ * @param _next - The `json-rpc-engine` "next" callback. Not used by this
81
+ * function.
82
+ * @param end - The `json-rpc-engine` "end" callback.
83
+ * @param hooks - The RPC method hooks.
84
+ * @param hooks.hasPermission - Checks whether a given origin has a given permission.
85
+ * @param hooks.getNetworkConfigurationByChainId - Get a network configuration for a given chain ID.
86
+ * @param hooks.getNetworkClientById - Get a network client for a given ID.
87
+ * @returns Nothing.
88
+ */
89
+ async function providerRequestImplementation(req, res, _next, end, { hasPermission, getNetworkConfigurationByChainId, getNetworkClientById, }) {
90
+ if (!hasPermission(SnapEndowments.EthereumProvider)) {
91
+ return end(rpcErrors.methodNotFound());
92
+ }
93
+ const { params } = req;
94
+ try {
95
+ const { chainId, request } = getValidatedParams(params);
96
+ if (!METHOD_ALLOWLIST.includes(request.method)) {
97
+ return end(rpcErrors.methodNotFound());
98
+ }
99
+ const parsedChainId = parseCaipChainId(chainId);
100
+ if (parsedChainId.namespace !== 'eip155') {
101
+ return end(rpcErrors.invalidParams({
102
+ message: 'Only EVM networks are currently supported.',
103
+ }));
104
+ }
105
+ const numericalChainId = BigInt(parsedChainId.reference);
106
+ const networkConfiguration = getNetworkConfigurationByChainId(bigIntToHex(numericalChainId));
107
+ if (!networkConfiguration) {
108
+ return end(rpcErrors.invalidParams({
109
+ message: 'The requested network is not available.',
110
+ }));
111
+ }
112
+ const rpc = networkConfiguration.rpcEndpoints[networkConfiguration.defaultRpcEndpointIndex];
113
+ const networkClient = getNetworkClientById(rpc.networkClientId);
114
+ const { provider } = networkClient;
115
+ res.result = await provider.request(request);
116
+ }
117
+ catch (error) {
118
+ return end(error);
119
+ }
120
+ return end();
121
+ }
122
+ /**
123
+ * Validate the method `params` and returns them cast to the correct
124
+ * type. Throws if validation fails.
125
+ *
126
+ * @param params - The unvalidated params object from the method request.
127
+ * @returns The validated updateInterface method parameter object.
128
+ */
129
+ function getValidatedParams(params) {
130
+ try {
131
+ return create(params, ProviderRequestParametersStruct);
132
+ }
133
+ catch (error) {
134
+ if (error instanceof StructError) {
135
+ throw rpcErrors.invalidParams({
136
+ message: `Invalid params: ${error.message}.`,
137
+ });
138
+ }
139
+ /* istanbul ignore next */
140
+ throw rpcErrors.internal();
141
+ }
142
+ }
143
+ //# sourceMappingURL=experimentalProviderRequest.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"experimentalProviderRequest.mjs","sourceRoot":"","sources":["../../src/permitted/experimentalProviderRequest.ts"],"names":[],"mappings":"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","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"]}
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCurrencyRateHandler = void 0;
4
+ const rpc_errors_1 = require("@metamask/rpc-errors");
5
+ const snaps_utils_1 = require("@metamask/snaps-utils");
6
+ const superstruct_1 = require("@metamask/superstruct");
7
+ const hookNames = {
8
+ getCurrencyRate: true,
9
+ };
10
+ exports.getCurrencyRateHandler = {
11
+ methodNames: ['snap_getCurrencyRate'],
12
+ implementation: getGetCurrencyRateImplementation,
13
+ hookNames,
14
+ };
15
+ const GetCurrencyRateParametersStruct = (0, superstruct_1.object)({
16
+ currency: (0, superstruct_1.union)([(0, snaps_utils_1.currency)('btc')]),
17
+ });
18
+ /**
19
+ * The `snap_getCurrencyRate` method implementation.
20
+ *
21
+ * @param req - The JSON-RPC request object.
22
+ * @param res - The JSON-RPC response object.
23
+ * @param _next - The `json-rpc-engine` "next" callback. Not used by this
24
+ * function.
25
+ * @param end - The `json-rpc-engine` "end" callback.
26
+ * @param hooks - The RPC method hooks.
27
+ * @param hooks.getCurrencyRate - The function to get the rate.
28
+ * @returns Nothing.
29
+ */
30
+ function getGetCurrencyRateImplementation(req, res, _next, end, { getCurrencyRate }) {
31
+ const { params } = req;
32
+ try {
33
+ const validatedParams = getValidatedParams(params);
34
+ const { currency: selectedCurrency } = validatedParams;
35
+ res.result = getCurrencyRate(selectedCurrency) ?? null;
36
+ }
37
+ catch (error) {
38
+ return end(error);
39
+ }
40
+ return end();
41
+ }
42
+ /**
43
+ * Validate the getCurrencyRate method `params` and returns them cast to the correct
44
+ * type. Throws if validation fails.
45
+ *
46
+ * @param params - The unvalidated params object from the method request.
47
+ * @returns The validated getCurrencyRate method parameter object.
48
+ */
49
+ function getValidatedParams(params) {
50
+ try {
51
+ return (0, superstruct_1.create)(params, GetCurrencyRateParametersStruct);
52
+ }
53
+ catch (error) {
54
+ if (error instanceof superstruct_1.StructError) {
55
+ throw rpc_errors_1.rpcErrors.invalidParams({
56
+ message: `Invalid params: ${error.message}.`,
57
+ });
58
+ }
59
+ /* istanbul ignore next */
60
+ throw rpc_errors_1.rpcErrors.internal();
61
+ }
62
+ }
63
+ //# sourceMappingURL=getCurrencyRate.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCurrencyRate.cjs","sourceRoot":"","sources":["../../src/permitted/getCurrencyRate.ts"],"names":[],"mappings":";;;AAEA,qDAAiD;AAQjD,uDAAqE;AACrE,uDAA2E;AAK3E,MAAM,SAAS,GAAkD;IAC/D,eAAe,EAAE,IAAI;CACtB,CAAC;AAWW,QAAA,sBAAsB,GAI/B;IACF,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrC,cAAc,EAAE,gCAAgC;IAChD,SAAS;CACV,CAAC;AAEF,MAAM,+BAA+B,GAAG,IAAA,oBAAM,EAAC;IAC7C,QAAQ,EAAE,IAAA,mBAAK,EAAC,CAAC,IAAA,sBAAQ,EAAC,KAAK,CAAC,CAAC,CAAC;CACnC,CAAC,CAAC;AAOH;;;;;;;;;;;GAWG;AACH,SAAS,gCAAgC,CACvC,GAA8C,EAC9C,GAAkD,EAClD,KAAc,EACd,GAA6B,EAC7B,EAAE,eAAe,EAA8B;IAE/C,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEvB,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,GAAG,eAAe,CAAC;QAEvD,GAAG,CAAC,MAAM,GAAG,eAAe,CAAC,gBAAgB,CAAC,IAAI,IAAI,CAAC;IACzD,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 AvailableCurrency,\n CurrencyRate,\n GetCurrencyRateParams,\n GetCurrencyRateResult,\n JsonRpcRequest,\n} from '@metamask/snaps-sdk';\nimport { currency, type InferMatching } from '@metamask/snaps-utils';\nimport { StructError, create, object, union } from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<GetCurrencyRateMethodHooks> = {\n getCurrencyRate: true,\n};\n\nexport type GetCurrencyRateMethodHooks = {\n /**\n * @param currency - The currency symbol.\n * Currently only 'btc' is supported.\n * @returns The {@link CurrencyRate} object.\n */\n getCurrencyRate: (currency: AvailableCurrency) => CurrencyRate | undefined;\n};\n\nexport const getCurrencyRateHandler: PermittedHandlerExport<\n GetCurrencyRateMethodHooks,\n GetCurrencyRateParameters,\n GetCurrencyRateResult\n> = {\n methodNames: ['snap_getCurrencyRate'],\n implementation: getGetCurrencyRateImplementation,\n hookNames,\n};\n\nconst GetCurrencyRateParametersStruct = object({\n currency: union([currency('btc')]),\n});\n\nexport type GetCurrencyRateParameters = InferMatching<\n typeof GetCurrencyRateParametersStruct,\n GetCurrencyRateParams\n>;\n\n/**\n * The `snap_getCurrencyRate` method implementation.\n *\n * @param req - The JSON-RPC request object.\n * @param res - The JSON-RPC response object.\n * @param _next - The `json-rpc-engine` \"next\" callback. Not used by this\n * function.\n * @param end - The `json-rpc-engine` \"end\" callback.\n * @param hooks - The RPC method hooks.\n * @param hooks.getCurrencyRate - The function to get the rate.\n * @returns Nothing.\n */\nfunction getGetCurrencyRateImplementation(\n req: JsonRpcRequest<GetCurrencyRateParameters>,\n res: PendingJsonRpcResponse<GetCurrencyRateResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { getCurrencyRate }: GetCurrencyRateMethodHooks,\n): void {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { currency: selectedCurrency } = validatedParams;\n\n res.result = getCurrencyRate(selectedCurrency) ?? null;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the getCurrencyRate 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 getCurrencyRate method parameter object.\n */\nfunction getValidatedParams(params: unknown): GetCurrencyRateParameters {\n try {\n return create(params, GetCurrencyRateParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
@@ -0,0 +1,20 @@
1
+ import type { PermittedHandlerExport } from "@metamask/permission-controller";
2
+ import type { AvailableCurrency, CurrencyRate, GetCurrencyRateParams, GetCurrencyRateResult } from "@metamask/snaps-sdk";
3
+ import { type InferMatching } from "@metamask/snaps-utils";
4
+ export type GetCurrencyRateMethodHooks = {
5
+ /**
6
+ * @param currency - The currency symbol.
7
+ * Currently only 'btc' is supported.
8
+ * @returns The {@link CurrencyRate} object.
9
+ */
10
+ getCurrencyRate: (currency: AvailableCurrency) => CurrencyRate | undefined;
11
+ };
12
+ export declare const getCurrencyRateHandler: PermittedHandlerExport<GetCurrencyRateMethodHooks, GetCurrencyRateParameters, GetCurrencyRateResult>;
13
+ declare const GetCurrencyRateParametersStruct: import("@metamask/superstruct").Struct<{
14
+ currency: "btc" | "BTC";
15
+ }, {
16
+ currency: import("@metamask/superstruct").Struct<"btc" | "BTC", null>;
17
+ }>;
18
+ export type GetCurrencyRateParameters = InferMatching<typeof GetCurrencyRateParametersStruct, GetCurrencyRateParams>;
19
+ export {};
20
+ //# sourceMappingURL=getCurrencyRate.d.cts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCurrencyRate.d.cts","sourceRoot":"","sources":["../../src/permitted/getCurrencyRate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,qBAAqB,EACrB,qBAAqB,EAEtB,4BAA4B;AAC7B,OAAO,EAAY,KAAK,aAAa,EAAE,8BAA8B;AAUrE,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;OAIG;IACH,eAAe,EAAE,CAAC,QAAQ,EAAE,iBAAiB,KAAK,YAAY,GAAG,SAAS,CAAC;CAC5E,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,CAKtB,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;EAEnC,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,aAAa,CACnD,OAAO,+BAA+B,EACtC,qBAAqB,CACtB,CAAC"}
@@ -0,0 +1,20 @@
1
+ import type { PermittedHandlerExport } from "@metamask/permission-controller";
2
+ import type { AvailableCurrency, CurrencyRate, GetCurrencyRateParams, GetCurrencyRateResult } from "@metamask/snaps-sdk";
3
+ import { type InferMatching } from "@metamask/snaps-utils";
4
+ export type GetCurrencyRateMethodHooks = {
5
+ /**
6
+ * @param currency - The currency symbol.
7
+ * Currently only 'btc' is supported.
8
+ * @returns The {@link CurrencyRate} object.
9
+ */
10
+ getCurrencyRate: (currency: AvailableCurrency) => CurrencyRate | undefined;
11
+ };
12
+ export declare const getCurrencyRateHandler: PermittedHandlerExport<GetCurrencyRateMethodHooks, GetCurrencyRateParameters, GetCurrencyRateResult>;
13
+ declare const GetCurrencyRateParametersStruct: import("@metamask/superstruct").Struct<{
14
+ currency: "btc" | "BTC";
15
+ }, {
16
+ currency: import("@metamask/superstruct").Struct<"btc" | "BTC", null>;
17
+ }>;
18
+ export type GetCurrencyRateParameters = InferMatching<typeof GetCurrencyRateParametersStruct, GetCurrencyRateParams>;
19
+ export {};
20
+ //# sourceMappingURL=getCurrencyRate.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getCurrencyRate.d.mts","sourceRoot":"","sources":["../../src/permitted/getCurrencyRate.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,iBAAiB,EACjB,YAAY,EACZ,qBAAqB,EACrB,qBAAqB,EAEtB,4BAA4B;AAC7B,OAAO,EAAY,KAAK,aAAa,EAAE,8BAA8B;AAUrE,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;OAIG;IACH,eAAe,EAAE,CAAC,QAAQ,EAAE,iBAAiB,KAAK,YAAY,GAAG,SAAS,CAAC;CAC5E,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,CAKtB,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;EAEnC,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,aAAa,CACnD,OAAO,+BAA+B,EACtC,qBAAqB,CACtB,CAAC"}