@metamask/snaps-rpc-methods 11.3.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.
- package/CHANGELOG.md +19 -1
- package/dist/permitted/experimentalProviderRequest.cjs +146 -0
- package/dist/permitted/experimentalProviderRequest.cjs.map +1 -0
- package/dist/permitted/experimentalProviderRequest.d.cts +39 -0
- package/dist/permitted/experimentalProviderRequest.d.cts.map +1 -0
- package/dist/permitted/experimentalProviderRequest.d.mts +39 -0
- package/dist/permitted/experimentalProviderRequest.d.mts.map +1 -0
- package/dist/permitted/experimentalProviderRequest.mjs +143 -0
- package/dist/permitted/experimentalProviderRequest.mjs.map +1 -0
- package/dist/permitted/handlers.cjs +2 -0
- package/dist/permitted/handlers.cjs.map +1 -1
- package/dist/permitted/handlers.d.cts +2 -1
- package/dist/permitted/handlers.d.cts.map +1 -1
- package/dist/permitted/handlers.d.mts +2 -1
- package/dist/permitted/handlers.d.mts.map +1 -1
- package/dist/permitted/handlers.mjs +2 -0
- package/dist/permitted/handlers.mjs.map +1 -1
- package/dist/permitted/index.cjs.map +1 -1
- package/dist/permitted/index.d.cts +2 -1
- package/dist/permitted/index.d.cts.map +1 -1
- package/dist/permitted/index.d.mts +2 -1
- package/dist/permitted/index.d.mts.map +1 -1
- package/dist/permitted/index.mjs.map +1 -1
- package/dist/permitted/updateInterface.cjs +3 -2
- package/dist/permitted/updateInterface.cjs.map +1 -1
- package/dist/permitted/updateInterface.d.cts +5 -2
- package/dist/permitted/updateInterface.d.cts.map +1 -1
- package/dist/permitted/updateInterface.d.mts +5 -2
- package/dist/permitted/updateInterface.d.mts.map +1 -1
- package/dist/permitted/updateInterface.mjs +5 -4
- package/dist/permitted/updateInterface.mjs.map +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,23 @@ 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
|
+
|
|
10
27
|
## [11.3.0]
|
|
11
28
|
|
|
12
29
|
### Added
|
|
@@ -297,7 +314,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
297
314
|
- The version of the package no longer needs to match the version of all other
|
|
298
315
|
MetaMask Snaps packages.
|
|
299
316
|
|
|
300
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.
|
|
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
|
|
301
319
|
[11.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.2.0...@metamask/snaps-rpc-methods@11.3.0
|
|
302
320
|
[11.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.1.1...@metamask/snaps-rpc-methods@11.2.0
|
|
303
321
|
[11.1.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@11.1.0...@metamask/snaps-rpc-methods@11.1.1
|
|
@@ -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"]}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.handlers = exports.methodHandlers = void 0;
|
|
4
4
|
const createInterface_1 = require("./createInterface.cjs");
|
|
5
|
+
const experimentalProviderRequest_1 = require("./experimentalProviderRequest.cjs");
|
|
5
6
|
const getAllSnaps_1 = require("./getAllSnaps.cjs");
|
|
6
7
|
const getClientStatus_1 = require("./getClientStatus.cjs");
|
|
7
8
|
const getCurrencyRate_1 = require("./getCurrencyRate.cjs");
|
|
@@ -27,6 +28,7 @@ exports.methodHandlers = {
|
|
|
27
28
|
snap_getInterfaceState: getInterfaceState_1.getInterfaceStateHandler,
|
|
28
29
|
snap_resolveInterface: resolveInterface_1.resolveInterfaceHandler,
|
|
29
30
|
snap_getCurrencyRate: getCurrencyRate_1.getCurrencyRateHandler,
|
|
31
|
+
snap_experimentalProviderRequest: experimentalProviderRequest_1.providerRequestHandler,
|
|
30
32
|
};
|
|
31
33
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
32
34
|
exports.handlers = Object.values(exports.methodHandlers);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.cjs","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":";;;AAAA,2DAA2D;AAC3D,mDAAmD;AACnD,2DAA2D;AAC3D,2DAA2D;AAC3D,2CAA2C;AAC3C,+DAA+D;AAC/D,6CAA6C;AAC7C,uDAAuD;AACvD,2DAA2D;AAC3D,qDAAqD;AACrD,6DAA6D;AAC7D,2DAA2D;AAE3D,yDAAyD;AAC5C,QAAA,cAAc,GAAG;IAC5B,kBAAkB,EAAE,gCAAkB;IACtC,eAAe,EAAE,0BAAe;IAChC,mBAAmB,EAAE,kCAAmB;IACxC,iBAAiB,EAAE,wCAAsB;IACzC,oBAAoB,EAAE,oCAAoB;IAC1C,oBAAoB,EAAE,wCAAsB;IAC5C,YAAY,EAAE,wBAAc;IAC5B,oBAAoB,EAAE,wCAAsB;IAC5C,oBAAoB,EAAE,wCAAsB;IAC5C,sBAAsB,EAAE,4CAAwB;IAChD,qBAAqB,EAAE,0CAAuB;IAC9C,oBAAoB,EAAE,wCAAsB;
|
|
1
|
+
{"version":3,"file":"handlers.cjs","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":";;;AAAA,2DAA2D;AAC3D,mFAAuE;AACvE,mDAAmD;AACnD,2DAA2D;AAC3D,2DAA2D;AAC3D,2CAA2C;AAC3C,+DAA+D;AAC/D,6CAA6C;AAC7C,uDAAuD;AACvD,2DAA2D;AAC3D,qDAAqD;AACrD,6DAA6D;AAC7D,2DAA2D;AAE3D,yDAAyD;AAC5C,QAAA,cAAc,GAAG;IAC5B,kBAAkB,EAAE,gCAAkB;IACtC,eAAe,EAAE,0BAAe;IAChC,mBAAmB,EAAE,kCAAmB;IACxC,iBAAiB,EAAE,wCAAsB;IACzC,oBAAoB,EAAE,oCAAoB;IAC1C,oBAAoB,EAAE,wCAAsB;IAC5C,YAAY,EAAE,wBAAc;IAC5B,oBAAoB,EAAE,wCAAsB;IAC5C,oBAAoB,EAAE,wCAAsB;IAC5C,sBAAsB,EAAE,4CAAwB;IAChD,qBAAqB,EAAE,0CAAuB;IAC9C,oBAAoB,EAAE,wCAAsB;IAC5C,gCAAgC,EAAE,oDAAsB;CACzD,CAAC;AACF,wDAAwD;AAE3C,QAAA,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAc,CAAC,CAAC","sourcesContent":["import { createInterfaceHandler } from './createInterface';\nimport { providerRequestHandler } from './experimentalProviderRequest';\nimport { getAllSnapsHandler } from './getAllSnaps';\nimport { getClientStatusHandler } from './getClientStatus';\nimport { getCurrencyRateHandler } from './getCurrencyRate';\nimport { getFileHandler } from './getFile';\nimport { getInterfaceStateHandler } from './getInterfaceState';\nimport { getSnapsHandler } from './getSnaps';\nimport { invokeKeyringHandler } from './invokeKeyring';\nimport { invokeSnapSugarHandler } from './invokeSnapSugar';\nimport { requestSnapsHandler } from './requestSnaps';\nimport { resolveInterfaceHandler } from './resolveInterface';\nimport { updateInterfaceHandler } from './updateInterface';\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const methodHandlers = {\n wallet_getAllSnaps: getAllSnapsHandler,\n wallet_getSnaps: getSnapsHandler,\n wallet_requestSnaps: requestSnapsHandler,\n wallet_invokeSnap: invokeSnapSugarHandler,\n wallet_invokeKeyring: invokeKeyringHandler,\n snap_getClientStatus: getClientStatusHandler,\n snap_getFile: getFileHandler,\n snap_createInterface: createInterfaceHandler,\n snap_updateInterface: updateInterfaceHandler,\n snap_getInterfaceState: getInterfaceStateHandler,\n snap_resolveInterface: resolveInterfaceHandler,\n snap_getCurrencyRate: getCurrencyRateHandler,\n snap_experimentalProviderRequest: providerRequestHandler,\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const handlers = Object.values(methodHandlers);\n"]}
|
|
@@ -21,8 +21,9 @@ export declare const methodHandlers: {
|
|
|
21
21
|
} | null> | null>>;
|
|
22
22
|
snap_resolveInterface: import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.cjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null>;
|
|
23
23
|
snap_getCurrencyRate: import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.cjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult>;
|
|
24
|
+
snap_experimentalProviderRequest: import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.cjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json>;
|
|
24
25
|
};
|
|
25
|
-
export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.cjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getAllSnaps.cjs").GetAllSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | 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 | {
|
|
26
|
+
export declare const handlers: (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("./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 | {
|
|
26
27
|
name: string;
|
|
27
28
|
size: number;
|
|
28
29
|
contentType: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.cts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handlers.d.cts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;CAc1B,CAAC;AAGF,eAAO,MAAM,QAAQ;;;;;;;;;;qzCAAgC,CAAC"}
|
|
@@ -21,8 +21,9 @@ export declare const methodHandlers: {
|
|
|
21
21
|
} | null> | null>>;
|
|
22
22
|
snap_resolveInterface: import("@metamask/permission-controller").PermittedHandlerExport<import("./resolveInterface.mjs").ResolveInterfaceMethodHooks, import("@metamask/snaps-sdk").ResolveInterfaceParams, null>;
|
|
23
23
|
snap_getCurrencyRate: import("@metamask/permission-controller").PermittedHandlerExport<import("./getCurrencyRate.mjs").GetCurrencyRateMethodHooks, import("@metamask/snaps-sdk").GetCurrencyRateParams, import("@metamask/snaps-sdk").GetCurrencyRateResult>;
|
|
24
|
+
snap_experimentalProviderRequest: import("@metamask/permission-controller").PermittedHandlerExport<import("./experimentalProviderRequest.mjs").ProviderRequestMethodHooks, import("@metamask/snaps-sdk").ProviderRequestParams, import("@metamask/utils").Json>;
|
|
24
25
|
};
|
|
25
|
-
export declare const handlers: (import("@metamask/permission-controller").PermittedHandlerExport<import("./createInterface.mjs").CreateInterfaceMethodHooks, import("@metamask/snaps-sdk").CreateInterfaceParams, string> | import("@metamask/permission-controller").PermittedHandlerExport<import("./getAllSnaps.mjs").GetAllSnapsHooks, import("@metamask/utils").JsonRpcParams, import("@metamask/snaps-sdk").GetSnapsResult> | 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 | {
|
|
26
|
+
export declare const handlers: (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("./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 | {
|
|
26
27
|
name: string;
|
|
27
28
|
size: number;
|
|
28
29
|
contentType: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handlers.d.mts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"handlers.d.mts","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;;;;;;;;;CAc1B,CAAC;AAGF,eAAO,MAAM,QAAQ;;;;;;;;;;qzCAAgC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createInterfaceHandler } from "./createInterface.mjs";
|
|
2
|
+
import { providerRequestHandler } from "./experimentalProviderRequest.mjs";
|
|
2
3
|
import { getAllSnapsHandler } from "./getAllSnaps.mjs";
|
|
3
4
|
import { getClientStatusHandler } from "./getClientStatus.mjs";
|
|
4
5
|
import { getCurrencyRateHandler } from "./getCurrencyRate.mjs";
|
|
@@ -24,6 +25,7 @@ export const methodHandlers = {
|
|
|
24
25
|
snap_getInterfaceState: getInterfaceStateHandler,
|
|
25
26
|
snap_resolveInterface: resolveInterfaceHandler,
|
|
26
27
|
snap_getCurrencyRate: getCurrencyRateHandler,
|
|
28
|
+
snap_experimentalProviderRequest: providerRequestHandler,
|
|
27
29
|
};
|
|
28
30
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
29
31
|
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,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,kBAAkB,EAAE,0BAAsB;AACnD,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,cAAc,EAAE,sBAAkB;AAC3C,OAAO,EAAE,wBAAwB,EAAE,gCAA4B;AAC/D,OAAO,EAAE,eAAe,EAAE,uBAAmB;AAC7C,OAAO,EAAE,oBAAoB,EAAE,4BAAwB;AACvD,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,mBAAmB,EAAE,2BAAuB;AACrD,OAAO,EAAE,uBAAuB,EAAE,+BAA2B;AAC7D,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAE3D,yDAAyD;AACzD,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,kBAAkB,EAAE,kBAAkB;IACtC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,mBAAmB;IACxC,iBAAiB,EAAE,sBAAsB;IACzC,oBAAoB,EAAE,oBAAoB;IAC1C,oBAAoB,EAAE,sBAAsB;IAC5C,YAAY,EAAE,cAAc;IAC5B,oBAAoB,EAAE,sBAAsB;IAC5C,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;IAChD,qBAAqB,EAAE,uBAAuB;IAC9C,oBAAoB,EAAE,sBAAsB;
|
|
1
|
+
{"version":3,"file":"handlers.mjs","sourceRoot":"","sources":["../../src/permitted/handlers.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,sBAAsB,EAAE,0CAAsC;AACvE,OAAO,EAAE,kBAAkB,EAAE,0BAAsB;AACnD,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,cAAc,EAAE,sBAAkB;AAC3C,OAAO,EAAE,wBAAwB,EAAE,gCAA4B;AAC/D,OAAO,EAAE,eAAe,EAAE,uBAAmB;AAC7C,OAAO,EAAE,oBAAoB,EAAE,4BAAwB;AACvD,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAC3D,OAAO,EAAE,mBAAmB,EAAE,2BAAuB;AACrD,OAAO,EAAE,uBAAuB,EAAE,+BAA2B;AAC7D,OAAO,EAAE,sBAAsB,EAAE,8BAA0B;AAE3D,yDAAyD;AACzD,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,kBAAkB,EAAE,kBAAkB;IACtC,eAAe,EAAE,eAAe;IAChC,mBAAmB,EAAE,mBAAmB;IACxC,iBAAiB,EAAE,sBAAsB;IACzC,oBAAoB,EAAE,oBAAoB;IAC1C,oBAAoB,EAAE,sBAAsB;IAC5C,YAAY,EAAE,cAAc;IAC5B,oBAAoB,EAAE,sBAAsB;IAC5C,oBAAoB,EAAE,sBAAsB;IAC5C,sBAAsB,EAAE,wBAAwB;IAChD,qBAAqB,EAAE,uBAAuB;IAC9C,oBAAoB,EAAE,sBAAsB;IAC5C,gCAAgC,EAAE,sBAAsB;CACzD,CAAC;AACF,wDAAwD;AAExD,MAAM,CAAC,MAAM,QAAQ,GAAG,MAAM,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC","sourcesContent":["import { createInterfaceHandler } from './createInterface';\nimport { providerRequestHandler } from './experimentalProviderRequest';\nimport { getAllSnapsHandler } from './getAllSnaps';\nimport { getClientStatusHandler } from './getClientStatus';\nimport { getCurrencyRateHandler } from './getCurrencyRate';\nimport { getFileHandler } from './getFile';\nimport { getInterfaceStateHandler } from './getInterfaceState';\nimport { getSnapsHandler } from './getSnaps';\nimport { invokeKeyringHandler } from './invokeKeyring';\nimport { invokeSnapSugarHandler } from './invokeSnapSugar';\nimport { requestSnapsHandler } from './requestSnaps';\nimport { resolveInterfaceHandler } from './resolveInterface';\nimport { updateInterfaceHandler } from './updateInterface';\n\n/* eslint-disable @typescript-eslint/naming-convention */\nexport const methodHandlers = {\n wallet_getAllSnaps: getAllSnapsHandler,\n wallet_getSnaps: getSnapsHandler,\n wallet_requestSnaps: requestSnapsHandler,\n wallet_invokeSnap: invokeSnapSugarHandler,\n wallet_invokeKeyring: invokeKeyringHandler,\n snap_getClientStatus: getClientStatusHandler,\n snap_getFile: getFileHandler,\n snap_createInterface: createInterfaceHandler,\n snap_updateInterface: updateInterfaceHandler,\n snap_getInterfaceState: getInterfaceStateHandler,\n snap_resolveInterface: resolveInterfaceHandler,\n snap_getCurrencyRate: getCurrencyRateHandler,\n snap_experimentalProviderRequest: providerRequestHandler,\n};\n/* eslint-enable @typescript-eslint/naming-convention */\n\nexport const handlers = Object.values(methodHandlers);\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/permitted/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../src/permitted/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAsBA,iDAA2B;AAC3B,mDAA6B","sourcesContent":["import type { CreateInterfaceMethodHooks } from './createInterface';\nimport type { ProviderRequestMethodHooks } from './experimentalProviderRequest';\nimport type { GetAllSnapsHooks } from './getAllSnaps';\nimport type { GetClientStatusHooks } from './getClientStatus';\nimport type { GetCurrencyRateMethodHooks } from './getCurrencyRate';\nimport type { GetInterfaceStateMethodHooks } from './getInterfaceState';\nimport type { GetSnapsHooks } from './getSnaps';\nimport type { RequestSnapsHooks } from './requestSnaps';\nimport type { ResolveInterfaceMethodHooks } from './resolveInterface';\nimport type { UpdateInterfaceMethodHooks } from './updateInterface';\n\nexport type PermittedRpcMethodHooks = GetAllSnapsHooks &\n GetClientStatusHooks &\n GetSnapsHooks &\n RequestSnapsHooks &\n CreateInterfaceMethodHooks &\n UpdateInterfaceMethodHooks &\n GetInterfaceStateMethodHooks &\n ResolveInterfaceMethodHooks &\n GetCurrencyRateMethodHooks &\n ProviderRequestMethodHooks;\n\nexport * from './handlers';\nexport * from './middleware';\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CreateInterfaceMethodHooks } from "./createInterface.cjs";
|
|
2
|
+
import type { ProviderRequestMethodHooks } from "./experimentalProviderRequest.cjs";
|
|
2
3
|
import type { GetAllSnapsHooks } from "./getAllSnaps.cjs";
|
|
3
4
|
import type { GetClientStatusHooks } from "./getClientStatus.cjs";
|
|
4
5
|
import type { GetCurrencyRateMethodHooks } from "./getCurrencyRate.cjs";
|
|
@@ -7,7 +8,7 @@ import type { GetSnapsHooks } from "./getSnaps.cjs";
|
|
|
7
8
|
import type { RequestSnapsHooks } from "./requestSnaps.cjs";
|
|
8
9
|
import type { ResolveInterfaceMethodHooks } from "./resolveInterface.cjs";
|
|
9
10
|
import type { UpdateInterfaceMethodHooks } from "./updateInterface.cjs";
|
|
10
|
-
export type PermittedRpcMethodHooks = GetAllSnapsHooks & GetClientStatusHooks & GetSnapsHooks & RequestSnapsHooks & CreateInterfaceMethodHooks & UpdateInterfaceMethodHooks & GetInterfaceStateMethodHooks & ResolveInterfaceMethodHooks & GetCurrencyRateMethodHooks;
|
|
11
|
+
export type PermittedRpcMethodHooks = GetAllSnapsHooks & GetClientStatusHooks & GetSnapsHooks & RequestSnapsHooks & CreateInterfaceMethodHooks & UpdateInterfaceMethodHooks & GetInterfaceStateMethodHooks & ResolveInterfaceMethodHooks & GetCurrencyRateMethodHooks & ProviderRequestMethodHooks;
|
|
11
12
|
export * from "./handlers.cjs";
|
|
12
13
|
export * from "./middleware.cjs";
|
|
13
14
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/permitted/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,0BAAsB;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,8BAA0B;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AACpE,OAAO,KAAK,EAAE,4BAA4B,EAAE,gCAA4B;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAmB;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,2BAAuB;AACxD,OAAO,KAAK,EAAE,2BAA2B,EAAE,+BAA2B;AACtE,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AAEpE,MAAM,MAAM,uBAAuB,GAAG,gBAAgB,GACpD,oBAAoB,GACpB,aAAa,GACb,iBAAiB,GACjB,0BAA0B,GAC1B,0BAA0B,GAC1B,4BAA4B,GAC5B,2BAA2B,GAC3B,0BAA0B,CAAC;AAE7B,+BAA2B;AAC3B,iCAA6B"}
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/permitted/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AACpE,OAAO,KAAK,EAAE,0BAA0B,EAAE,0CAAsC;AAChF,OAAO,KAAK,EAAE,gBAAgB,EAAE,0BAAsB;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,8BAA0B;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AACpE,OAAO,KAAK,EAAE,4BAA4B,EAAE,gCAA4B;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAmB;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,2BAAuB;AACxD,OAAO,KAAK,EAAE,2BAA2B,EAAE,+BAA2B;AACtE,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AAEpE,MAAM,MAAM,uBAAuB,GAAG,gBAAgB,GACpD,oBAAoB,GACpB,aAAa,GACb,iBAAiB,GACjB,0BAA0B,GAC1B,0BAA0B,GAC1B,4BAA4B,GAC5B,2BAA2B,GAC3B,0BAA0B,GAC1B,0BAA0B,CAAC;AAE7B,+BAA2B;AAC3B,iCAA6B"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { CreateInterfaceMethodHooks } from "./createInterface.mjs";
|
|
2
|
+
import type { ProviderRequestMethodHooks } from "./experimentalProviderRequest.mjs";
|
|
2
3
|
import type { GetAllSnapsHooks } from "./getAllSnaps.mjs";
|
|
3
4
|
import type { GetClientStatusHooks } from "./getClientStatus.mjs";
|
|
4
5
|
import type { GetCurrencyRateMethodHooks } from "./getCurrencyRate.mjs";
|
|
@@ -7,7 +8,7 @@ import type { GetSnapsHooks } from "./getSnaps.mjs";
|
|
|
7
8
|
import type { RequestSnapsHooks } from "./requestSnaps.mjs";
|
|
8
9
|
import type { ResolveInterfaceMethodHooks } from "./resolveInterface.mjs";
|
|
9
10
|
import type { UpdateInterfaceMethodHooks } from "./updateInterface.mjs";
|
|
10
|
-
export type PermittedRpcMethodHooks = GetAllSnapsHooks & GetClientStatusHooks & GetSnapsHooks & RequestSnapsHooks & CreateInterfaceMethodHooks & UpdateInterfaceMethodHooks & GetInterfaceStateMethodHooks & ResolveInterfaceMethodHooks & GetCurrencyRateMethodHooks;
|
|
11
|
+
export type PermittedRpcMethodHooks = GetAllSnapsHooks & GetClientStatusHooks & GetSnapsHooks & RequestSnapsHooks & CreateInterfaceMethodHooks & UpdateInterfaceMethodHooks & GetInterfaceStateMethodHooks & ResolveInterfaceMethodHooks & GetCurrencyRateMethodHooks & ProviderRequestMethodHooks;
|
|
11
12
|
export * from "./handlers.mjs";
|
|
12
13
|
export * from "./middleware.mjs";
|
|
13
14
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/permitted/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AACpE,OAAO,KAAK,EAAE,gBAAgB,EAAE,0BAAsB;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,8BAA0B;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AACpE,OAAO,KAAK,EAAE,4BAA4B,EAAE,gCAA4B;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAmB;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,2BAAuB;AACxD,OAAO,KAAK,EAAE,2BAA2B,EAAE,+BAA2B;AACtE,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AAEpE,MAAM,MAAM,uBAAuB,GAAG,gBAAgB,GACpD,oBAAoB,GACpB,aAAa,GACb,iBAAiB,GACjB,0BAA0B,GAC1B,0BAA0B,GAC1B,4BAA4B,GAC5B,2BAA2B,GAC3B,0BAA0B,CAAC;AAE7B,+BAA2B;AAC3B,iCAA6B"}
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/permitted/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AACpE,OAAO,KAAK,EAAE,0BAA0B,EAAE,0CAAsC;AAChF,OAAO,KAAK,EAAE,gBAAgB,EAAE,0BAAsB;AACtD,OAAO,KAAK,EAAE,oBAAoB,EAAE,8BAA0B;AAC9D,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AACpE,OAAO,KAAK,EAAE,4BAA4B,EAAE,gCAA4B;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,uBAAmB;AAChD,OAAO,KAAK,EAAE,iBAAiB,EAAE,2BAAuB;AACxD,OAAO,KAAK,EAAE,2BAA2B,EAAE,+BAA2B;AACtE,OAAO,KAAK,EAAE,0BAA0B,EAAE,8BAA0B;AAEpE,MAAM,MAAM,uBAAuB,GAAG,gBAAgB,GACpD,oBAAoB,GACpB,aAAa,GACb,iBAAiB,GACjB,0BAA0B,GAC1B,0BAA0B,GAC1B,4BAA4B,GAC5B,2BAA2B,GAC3B,0BAA0B,GAC1B,0BAA0B,CAAC;AAE7B,+BAA2B;AAC3B,iCAA6B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/permitted/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../src/permitted/index.ts"],"names":[],"mappings":"AAsBA,+BAA2B;AAC3B,iCAA6B","sourcesContent":["import type { CreateInterfaceMethodHooks } from './createInterface';\nimport type { ProviderRequestMethodHooks } from './experimentalProviderRequest';\nimport type { GetAllSnapsHooks } from './getAllSnaps';\nimport type { GetClientStatusHooks } from './getClientStatus';\nimport type { GetCurrencyRateMethodHooks } from './getCurrencyRate';\nimport type { GetInterfaceStateMethodHooks } from './getInterfaceState';\nimport type { GetSnapsHooks } from './getSnaps';\nimport type { RequestSnapsHooks } from './requestSnaps';\nimport type { ResolveInterfaceMethodHooks } from './resolveInterface';\nimport type { UpdateInterfaceMethodHooks } from './updateInterface';\n\nexport type PermittedRpcMethodHooks = GetAllSnapsHooks &\n GetClientStatusHooks &\n GetSnapsHooks &\n RequestSnapsHooks &\n CreateInterfaceMethodHooks &\n UpdateInterfaceMethodHooks &\n GetInterfaceStateMethodHooks &\n ResolveInterfaceMethodHooks &\n GetCurrencyRateMethodHooks &\n ProviderRequestMethodHooks;\n\nexport * from './handlers';\nexport * from './middleware';\n"]}
|
|
@@ -15,6 +15,7 @@ exports.updateInterfaceHandler = {
|
|
|
15
15
|
const UpdateInterfaceParametersStruct = (0, superstruct_1.object)({
|
|
16
16
|
id: (0, superstruct_1.string)(),
|
|
17
17
|
ui: snaps_sdk_1.ComponentOrElementStruct,
|
|
18
|
+
context: (0, superstruct_1.optional)(snaps_sdk_1.InterfaceContextStruct),
|
|
18
19
|
});
|
|
19
20
|
/**
|
|
20
21
|
* The `snap_updateInterface` method implementation.
|
|
@@ -32,8 +33,8 @@ async function getUpdateInterfaceImplementation(req, res, _next, end, { updateIn
|
|
|
32
33
|
const { params } = req;
|
|
33
34
|
try {
|
|
34
35
|
const validatedParams = getValidatedParams(params);
|
|
35
|
-
const { id, ui } = validatedParams;
|
|
36
|
-
await updateInterface(id, ui);
|
|
36
|
+
const { id, ui, context } = validatedParams;
|
|
37
|
+
await updateInterface(id, ui, context);
|
|
37
38
|
res.result = null;
|
|
38
39
|
}
|
|
39
40
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateInterface.cjs","sourceRoot":"","sources":["../../src/permitted/updateInterface.ts"],"names":[],"mappings":";;;AAEA,qDAAiD;
|
|
1
|
+
{"version":3,"file":"updateInterface.cjs","sourceRoot":"","sources":["../../src/permitted/updateInterface.ts"],"names":[],"mappings":";;;AAEA,qDAAiD;AAQjD,mDAG6B;AAE7B,uDAM+B;AAK/B,MAAM,SAAS,GAAkD;IAC/D,eAAe,EAAE,IAAI;CACtB,CAAC;AAeW,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,EAAE,EAAE,IAAA,oBAAM,GAAE;IACZ,EAAE,EAAE,oCAAwB;IAC5B,OAAO,EAAE,IAAA,sBAAQ,EAAC,kCAAsB,CAAC;CAC1C,CAAC,CAAC;AAOH;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,gCAAgC,CAC7C,GAA8C,EAC9C,GAAkD,EAClD,KAAc,EACd,GAA6B,EAC7B,EAAE,eAAe,EAA8B;IAE/C,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEvB,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;QAE5C,MAAM,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QACvC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC;IACpB,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 UpdateInterfaceParams,\n UpdateInterfaceResult,\n JsonRpcRequest,\n ComponentOrElement,\n InterfaceContext,\n} from '@metamask/snaps-sdk';\nimport {\n ComponentOrElementStruct,\n InterfaceContextStruct,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n StructError,\n create,\n object,\n optional,\n string,\n} from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<UpdateInterfaceMethodHooks> = {\n updateInterface: true,\n};\n\nexport type UpdateInterfaceMethodHooks = {\n /**\n * @param id - The interface ID.\n * @param ui - The UI components.\n * @param context - The optional interface context object.\n */\n updateInterface: (\n id: string,\n ui: ComponentOrElement,\n context?: InterfaceContext,\n ) => Promise<void>;\n};\n\nexport const updateInterfaceHandler: PermittedHandlerExport<\n UpdateInterfaceMethodHooks,\n UpdateInterfaceParameters,\n UpdateInterfaceResult\n> = {\n methodNames: ['snap_updateInterface'],\n implementation: getUpdateInterfaceImplementation,\n hookNames,\n};\n\nconst UpdateInterfaceParametersStruct = object({\n id: string(),\n ui: ComponentOrElementStruct,\n context: optional(InterfaceContextStruct),\n});\n\nexport type UpdateInterfaceParameters = InferMatching<\n typeof UpdateInterfaceParametersStruct,\n UpdateInterfaceParams\n>;\n\n/**\n * The `snap_updateInterface` 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.updateInterface - The function to update the interface.\n * @returns Nothing.\n */\nasync function getUpdateInterfaceImplementation(\n req: JsonRpcRequest<UpdateInterfaceParameters>,\n res: PendingJsonRpcResponse<UpdateInterfaceResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { updateInterface }: UpdateInterfaceMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id, ui, context } = validatedParams;\n\n await updateInterface(id, ui, context);\n res.result = null;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the updateInterface 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): UpdateInterfaceParameters {\n try {\n return create(params, UpdateInterfaceParametersStruct);\n } catch (error) {\n if (error instanceof StructError) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}.`,\n });\n }\n /* istanbul ignore next */\n throw rpcErrors.internal();\n }\n}\n"]}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { PermittedHandlerExport } from "@metamask/permission-controller";
|
|
2
|
-
import type { UpdateInterfaceParams, UpdateInterfaceResult, ComponentOrElement } from "@metamask/snaps-sdk";
|
|
2
|
+
import type { UpdateInterfaceParams, UpdateInterfaceResult, ComponentOrElement, InterfaceContext } from "@metamask/snaps-sdk";
|
|
3
3
|
import { type InferMatching } from "@metamask/snaps-utils";
|
|
4
4
|
export type UpdateInterfaceMethodHooks = {
|
|
5
5
|
/**
|
|
6
6
|
* @param id - The interface ID.
|
|
7
7
|
* @param ui - The UI components.
|
|
8
|
+
* @param context - The optional interface context object.
|
|
8
9
|
*/
|
|
9
|
-
updateInterface: (id: string, ui: ComponentOrElement) => Promise<void>;
|
|
10
|
+
updateInterface: (id: string, ui: ComponentOrElement, context?: InterfaceContext) => Promise<void>;
|
|
10
11
|
};
|
|
11
12
|
export declare const updateInterfaceHandler: PermittedHandlerExport<UpdateInterfaceMethodHooks, UpdateInterfaceParameters, UpdateInterfaceResult>;
|
|
12
13
|
declare const UpdateInterfaceParametersStruct: import("@metamask/superstruct").Struct<{
|
|
@@ -93,6 +94,7 @@ declare const UpdateInterfaceParametersStruct: import("@metamask/superstruct").S
|
|
|
93
94
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
94
95
|
size?: "md" | "lg" | undefined;
|
|
95
96
|
}, "Heading">;
|
|
97
|
+
context?: Record<string, import("@metamask/snaps-sdk").Json> | undefined;
|
|
96
98
|
}, {
|
|
97
99
|
id: import("@metamask/superstruct").Struct<string, null>;
|
|
98
100
|
ui: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
|
|
@@ -177,6 +179,7 @@ declare const UpdateInterfaceParametersStruct: import("@metamask/superstruct").S
|
|
|
177
179
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
178
180
|
size?: "md" | "lg" | undefined;
|
|
179
181
|
}, "Heading">, null>;
|
|
182
|
+
context: import("@metamask/superstruct").Struct<Record<string, import("@metamask/snaps-sdk").Json> | undefined, null>;
|
|
180
183
|
}>;
|
|
181
184
|
export type UpdateInterfaceParameters = InferMatching<typeof UpdateInterfaceParametersStruct, UpdateInterfaceParams>;
|
|
182
185
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateInterface.d.cts","sourceRoot":"","sources":["../../src/permitted/updateInterface.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EAErB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"updateInterface.d.cts","sourceRoot":"","sources":["../../src/permitted/updateInterface.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;AAgB3D,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;OAIG;IACH,eAAe,EAAE,CACf,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,kBAAkB,EACtB,OAAO,CAAC,EAAE,gBAAgB,KACvB,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,CAKtB,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAInC,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,aAAa,CACnD,OAAO,+BAA+B,EACtC,qBAAqB,CACtB,CAAC"}
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import type { PermittedHandlerExport } from "@metamask/permission-controller";
|
|
2
|
-
import type { UpdateInterfaceParams, UpdateInterfaceResult, ComponentOrElement } from "@metamask/snaps-sdk";
|
|
2
|
+
import type { UpdateInterfaceParams, UpdateInterfaceResult, ComponentOrElement, InterfaceContext } from "@metamask/snaps-sdk";
|
|
3
3
|
import { type InferMatching } from "@metamask/snaps-utils";
|
|
4
4
|
export type UpdateInterfaceMethodHooks = {
|
|
5
5
|
/**
|
|
6
6
|
* @param id - The interface ID.
|
|
7
7
|
* @param ui - The UI components.
|
|
8
|
+
* @param context - The optional interface context object.
|
|
8
9
|
*/
|
|
9
|
-
updateInterface: (id: string, ui: ComponentOrElement) => Promise<void>;
|
|
10
|
+
updateInterface: (id: string, ui: ComponentOrElement, context?: InterfaceContext) => Promise<void>;
|
|
10
11
|
};
|
|
11
12
|
export declare const updateInterfaceHandler: PermittedHandlerExport<UpdateInterfaceMethodHooks, UpdateInterfaceParameters, UpdateInterfaceResult>;
|
|
12
13
|
declare const UpdateInterfaceParametersStruct: import("@metamask/superstruct").Struct<{
|
|
@@ -93,6 +94,7 @@ declare const UpdateInterfaceParametersStruct: import("@metamask/superstruct").S
|
|
|
93
94
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
94
95
|
size?: "md" | "lg" | undefined;
|
|
95
96
|
}, "Heading">;
|
|
97
|
+
context?: Record<string, import("@metamask/snaps-sdk").Json> | undefined;
|
|
96
98
|
}, {
|
|
97
99
|
id: import("@metamask/superstruct").Struct<string, null>;
|
|
98
100
|
ui: import("@metamask/superstruct").Struct<import("@metamask/snaps-sdk").Panel | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ButtonProps, "Button"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CheckboxProps, "Checkbox"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FormProps, "Form"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").FileInputProps, "FileInput"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").InputProps, "Input"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").DropdownProps, "Dropdown"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SelectorProps, "Selector"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoldProps, "Bold"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ItalicProps, "Italic"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").AddressProps, "Address"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").BoxProps, "Box"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CardProps, "Card"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").ContainerProps, "Container"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").CopyableProps, "Copyable"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Divider"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").IconProps, "Icon"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").LinkProps, "Link"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").RowProps, "Row"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").SectionProps, "Section"> | import("@metamask/snaps-sdk/jsx").SnapElement<Record<string, never>, "Spinner"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TextProps, "Text"> | import("@metamask/snaps-sdk/jsx").SnapElement<import("@metamask/snaps-sdk/jsx").TooltipProps, "Tooltip"> | {
|
|
@@ -177,6 +179,7 @@ declare const UpdateInterfaceParametersStruct: import("@metamask/superstruct").S
|
|
|
177
179
|
children: import("@metamask/snaps-sdk/jsx").StringElement;
|
|
178
180
|
size?: "md" | "lg" | undefined;
|
|
179
181
|
}, "Heading">, null>;
|
|
182
|
+
context: import("@metamask/superstruct").Struct<Record<string, import("@metamask/snaps-sdk").Json> | undefined, null>;
|
|
180
183
|
}>;
|
|
181
184
|
export type UpdateInterfaceParameters = InferMatching<typeof UpdateInterfaceParametersStruct, UpdateInterfaceParams>;
|
|
182
185
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateInterface.d.mts","sourceRoot":"","sources":["../../src/permitted/updateInterface.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wCAAwC;AAE9E,OAAO,KAAK,EACV,qBAAqB,EACrB,qBAAqB,EAErB,kBAAkB,
|
|
1
|
+
{"version":3,"file":"updateInterface.d.mts","sourceRoot":"","sources":["../../src/permitted/updateInterface.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;AAgB3D,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;OAIG;IACH,eAAe,EAAE,CACf,EAAE,EAAE,MAAM,EACV,EAAE,EAAE,kBAAkB,EACtB,OAAO,CAAC,EAAE,gBAAgB,KACvB,OAAO,CAAC,IAAI,CAAC,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,sBAAsB,EAAE,sBAAsB,CACzD,0BAA0B,EAC1B,yBAAyB,EACzB,qBAAqB,CAKtB,CAAC;AAEF,QAAA,MAAM,+BAA+B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAInC,CAAC;AAEH,MAAM,MAAM,yBAAyB,GAAG,aAAa,CACnD,OAAO,+BAA+B,EACtC,qBAAqB,CACtB,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { rpcErrors } from "@metamask/rpc-errors";
|
|
2
|
-
import { ComponentOrElementStruct } from "@metamask/snaps-sdk";
|
|
3
|
-
import { StructError, create, object, string } from "@metamask/superstruct";
|
|
2
|
+
import { ComponentOrElementStruct, InterfaceContextStruct } from "@metamask/snaps-sdk";
|
|
3
|
+
import { StructError, create, object, optional, string } from "@metamask/superstruct";
|
|
4
4
|
const hookNames = {
|
|
5
5
|
updateInterface: true,
|
|
6
6
|
};
|
|
@@ -12,6 +12,7 @@ export const updateInterfaceHandler = {
|
|
|
12
12
|
const UpdateInterfaceParametersStruct = object({
|
|
13
13
|
id: string(),
|
|
14
14
|
ui: ComponentOrElementStruct,
|
|
15
|
+
context: optional(InterfaceContextStruct),
|
|
15
16
|
});
|
|
16
17
|
/**
|
|
17
18
|
* The `snap_updateInterface` method implementation.
|
|
@@ -29,8 +30,8 @@ async function getUpdateInterfaceImplementation(req, res, _next, end, { updateIn
|
|
|
29
30
|
const { params } = req;
|
|
30
31
|
try {
|
|
31
32
|
const validatedParams = getValidatedParams(params);
|
|
32
|
-
const { id, ui } = validatedParams;
|
|
33
|
-
await updateInterface(id, ui);
|
|
33
|
+
const { id, ui, context } = validatedParams;
|
|
34
|
+
await updateInterface(id, ui, context);
|
|
34
35
|
res.result = null;
|
|
35
36
|
}
|
|
36
37
|
catch (error) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"updateInterface.mjs","sourceRoot":"","sources":["../../src/permitted/updateInterface.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,6BAA6B;
|
|
1
|
+
{"version":3,"file":"updateInterface.mjs","sourceRoot":"","sources":["../../src/permitted/updateInterface.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,6BAA6B;AAQjD,OAAO,EACL,wBAAwB,EACxB,sBAAsB,EACvB,4BAA4B;AAE7B,OAAO,EACL,WAAW,EACX,MAAM,EACN,MAAM,EACN,QAAQ,EACR,MAAM,EACP,8BAA8B;AAK/B,MAAM,SAAS,GAAkD;IAC/D,eAAe,EAAE,IAAI;CACtB,CAAC;AAeF,MAAM,CAAC,MAAM,sBAAsB,GAI/B;IACF,WAAW,EAAE,CAAC,sBAAsB,CAAC;IACrC,cAAc,EAAE,gCAAgC;IAChD,SAAS;CACV,CAAC;AAEF,MAAM,+BAA+B,GAAG,MAAM,CAAC;IAC7C,EAAE,EAAE,MAAM,EAAE;IACZ,EAAE,EAAE,wBAAwB;IAC5B,OAAO,EAAE,QAAQ,CAAC,sBAAsB,CAAC;CAC1C,CAAC,CAAC;AAOH;;;;;;;;;;;GAWG;AACH,KAAK,UAAU,gCAAgC,CAC7C,GAA8C,EAC9C,GAAkD,EAClD,KAAc,EACd,GAA6B,EAC7B,EAAE,eAAe,EAA8B;IAE/C,MAAM,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC;IAEvB,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,kBAAkB,CAAC,MAAM,CAAC,CAAC;QAEnD,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,GAAG,eAAe,CAAC;QAE5C,MAAM,eAAe,CAAC,EAAE,EAAE,EAAE,EAAE,OAAO,CAAC,CAAC;QACvC,GAAG,CAAC,MAAM,GAAG,IAAI,CAAC;IACpB,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 UpdateInterfaceParams,\n UpdateInterfaceResult,\n JsonRpcRequest,\n ComponentOrElement,\n InterfaceContext,\n} from '@metamask/snaps-sdk';\nimport {\n ComponentOrElementStruct,\n InterfaceContextStruct,\n} from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport {\n StructError,\n create,\n object,\n optional,\n string,\n} from '@metamask/superstruct';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<UpdateInterfaceMethodHooks> = {\n updateInterface: true,\n};\n\nexport type UpdateInterfaceMethodHooks = {\n /**\n * @param id - The interface ID.\n * @param ui - The UI components.\n * @param context - The optional interface context object.\n */\n updateInterface: (\n id: string,\n ui: ComponentOrElement,\n context?: InterfaceContext,\n ) => Promise<void>;\n};\n\nexport const updateInterfaceHandler: PermittedHandlerExport<\n UpdateInterfaceMethodHooks,\n UpdateInterfaceParameters,\n UpdateInterfaceResult\n> = {\n methodNames: ['snap_updateInterface'],\n implementation: getUpdateInterfaceImplementation,\n hookNames,\n};\n\nconst UpdateInterfaceParametersStruct = object({\n id: string(),\n ui: ComponentOrElementStruct,\n context: optional(InterfaceContextStruct),\n});\n\nexport type UpdateInterfaceParameters = InferMatching<\n typeof UpdateInterfaceParametersStruct,\n UpdateInterfaceParams\n>;\n\n/**\n * The `snap_updateInterface` 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.updateInterface - The function to update the interface.\n * @returns Nothing.\n */\nasync function getUpdateInterfaceImplementation(\n req: JsonRpcRequest<UpdateInterfaceParameters>,\n res: PendingJsonRpcResponse<UpdateInterfaceResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { updateInterface }: UpdateInterfaceMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { id, ui, context } = validatedParams;\n\n await updateInterface(id, ui, context);\n res.result = null;\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the updateInterface 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): UpdateInterfaceParameters {\n try {\n return create(params, UpdateInterfaceParametersStruct);\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"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-rpc-methods",
|
|
3
|
-
"version": "11.
|
|
3
|
+
"version": "11.4.0",
|
|
4
4
|
"description": "MetaMask Snaps JSON-RPC method implementations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -58,8 +58,8 @@
|
|
|
58
58
|
"@metamask/key-tree": "^9.1.2",
|
|
59
59
|
"@metamask/permission-controller": "^11.0.0",
|
|
60
60
|
"@metamask/rpc-errors": "^6.3.1",
|
|
61
|
-
"@metamask/snaps-sdk": "^6.
|
|
62
|
-
"@metamask/snaps-utils": "^8.
|
|
61
|
+
"@metamask/snaps-sdk": "^6.8.0",
|
|
62
|
+
"@metamask/snaps-utils": "^8.4.0",
|
|
63
63
|
"@metamask/superstruct": "^3.1.0",
|
|
64
64
|
"@metamask/utils": "^9.2.1",
|
|
65
65
|
"@noble/hashes": "^1.3.1"
|