@metamask/snaps-rpc-methods 4.0.2 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [4.0.3]
|
|
10
|
+
### Changed
|
|
11
|
+
- Use prototype `startsWith` for RPC method middleware ([#2035](https://github.com/MetaMask/snaps/pull/2035))
|
|
12
|
+
|
|
9
13
|
## [4.0.2]
|
|
10
14
|
### Changed
|
|
11
15
|
- Bump several MetaMask dependencies ([#1989](https://github.com/MetaMask/snaps/pull/1989))
|
|
@@ -80,7 +84,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
80
84
|
- The version of the package no longer needs to match the version of all other
|
|
81
85
|
MetaMask Snaps packages.
|
|
82
86
|
|
|
83
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@4.0.
|
|
87
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@4.0.3...HEAD
|
|
88
|
+
[4.0.3]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@4.0.2...@metamask/snaps-rpc-methods@4.0.3
|
|
84
89
|
[4.0.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@4.0.1...@metamask/snaps-rpc-methods@4.0.2
|
|
85
90
|
[4.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@4.0.0...@metamask/snaps-rpc-methods@4.0.1
|
|
86
91
|
[4.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@3.3.0...@metamask/snaps-rpc-methods@4.0.0
|
|
@@ -18,7 +18,7 @@ function createSnapsMethodMiddleware(isSnap, hooks) {
|
|
|
18
18
|
return async function methodMiddleware(request, response, next, end) {
|
|
19
19
|
const handler = _handlers.methodHandlers[request.method];
|
|
20
20
|
if (handler) {
|
|
21
|
-
if (
|
|
21
|
+
if (String.prototype.startsWith.call(request.method, 'snap_') && !isSnap) {
|
|
22
22
|
return end(_rpcerrors.rpcErrors.methodNotFound());
|
|
23
23
|
}
|
|
24
24
|
// TODO: Once json-rpc-engine types are up to date, we should type this correctly
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/permitted/middleware.ts"],"sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport { selectHooks } from '../utils';\nimport { methodHandlers } from './handlers';\n\n/**\n * Creates a middleware that handles permitted snap RPC methods.\n *\n * @param isSnap - A flag that should indicate whether the requesting origin is a snap or not.\n * @param hooks - An object containing the hooks made available to the permitted RPC methods.\n * @returns The middleware.\n */\nexport function createSnapsMethodMiddleware(\n isSnap: boolean,\n hooks: Record<string, unknown>,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n // This is not actually a misused promise, the type is just wrong\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return async function methodMiddleware(request, response, next, end) {\n const handler =\n methodHandlers[request.method as keyof typeof methodHandlers];\n if (handler) {\n if (
|
|
1
|
+
{"version":3,"sources":["../../../src/permitted/middleware.ts"],"sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport { selectHooks } from '../utils';\nimport { methodHandlers } from './handlers';\n\n/**\n * Creates a middleware that handles permitted snap RPC methods.\n *\n * @param isSnap - A flag that should indicate whether the requesting origin is a snap or not.\n * @param hooks - An object containing the hooks made available to the permitted RPC methods.\n * @returns The middleware.\n */\nexport function createSnapsMethodMiddleware(\n isSnap: boolean,\n hooks: Record<string, unknown>,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n // This is not actually a misused promise, the type is just wrong\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return async function methodMiddleware(request, response, next, end) {\n const handler =\n methodHandlers[request.method as keyof typeof methodHandlers];\n if (handler) {\n if (\n String.prototype.startsWith.call(request.method, 'snap_') &&\n !isSnap\n ) {\n return end(rpcErrors.methodNotFound());\n }\n\n // TODO: Once json-rpc-engine types are up to date, we should type this correctly\n const { implementation, hookNames } = handler as any;\n try {\n // Implementations may or may not be async, so we must await them.\n return await implementation(\n request,\n response,\n next,\n end,\n selectHooks(hooks, hookNames),\n );\n } catch (error) {\n logError(error);\n return end(error);\n }\n }\n\n return next();\n };\n}\n"],"names":["createSnapsMethodMiddleware","isSnap","hooks","methodMiddleware","request","response","next","end","handler","methodHandlers","method","String","prototype","startsWith","call","rpcErrors","methodNotFound","implementation","hookNames","selectHooks","error","logError"],"mappings":";;;;+BAegBA;;;eAAAA;;;2BAdU;4BACD;uBAGG;0BACG;AASxB,SAASA,4BACdC,MAAe,EACfC,KAA8B;IAE9B,iEAAiE;IACjE,kEAAkE;IAClE,OAAO,eAAeC,iBAAiBC,OAAO,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,GAAG;QACjE,MAAMC,UACJC,wBAAc,CAACL,QAAQM,MAAM,CAAgC;QAC/D,IAAIF,SAAS;YACX,IACEG,OAAOC,SAAS,CAACC,UAAU,CAACC,IAAI,CAACV,QAAQM,MAAM,EAAE,YACjD,CAACT,QACD;gBACA,OAAOM,IAAIQ,oBAAS,CAACC,cAAc;YACrC;YAEA,iFAAiF;YACjF,MAAM,EAAEC,cAAc,EAAEC,SAAS,EAAE,GAAGV;YACtC,IAAI;gBACF,kEAAkE;gBAClE,OAAO,MAAMS,eACXb,SACAC,UACAC,MACAC,KACAY,IAAAA,kBAAW,EAACjB,OAAOgB;YAEvB,EAAE,OAAOE,OAAO;gBACdC,IAAAA,oBAAQ,EAACD;gBACT,OAAOb,IAAIa;YACb;QACF;QAEA,OAAOd;IACT;AACF"}
|
|
@@ -14,7 +14,7 @@ import { methodHandlers } from './handlers';
|
|
|
14
14
|
return async function methodMiddleware(request, response, next, end) {
|
|
15
15
|
const handler = methodHandlers[request.method];
|
|
16
16
|
if (handler) {
|
|
17
|
-
if (
|
|
17
|
+
if (String.prototype.startsWith.call(request.method, 'snap_') && !isSnap) {
|
|
18
18
|
return end(rpcErrors.methodNotFound());
|
|
19
19
|
}
|
|
20
20
|
// TODO: Once json-rpc-engine types are up to date, we should type this correctly
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/permitted/middleware.ts"],"sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport { selectHooks } from '../utils';\nimport { methodHandlers } from './handlers';\n\n/**\n * Creates a middleware that handles permitted snap RPC methods.\n *\n * @param isSnap - A flag that should indicate whether the requesting origin is a snap or not.\n * @param hooks - An object containing the hooks made available to the permitted RPC methods.\n * @returns The middleware.\n */\nexport function createSnapsMethodMiddleware(\n isSnap: boolean,\n hooks: Record<string, unknown>,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n // This is not actually a misused promise, the type is just wrong\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return async function methodMiddleware(request, response, next, end) {\n const handler =\n methodHandlers[request.method as keyof typeof methodHandlers];\n if (handler) {\n if (
|
|
1
|
+
{"version":3,"sources":["../../../src/permitted/middleware.ts"],"sourcesContent":["import type { JsonRpcMiddleware } from '@metamask/json-rpc-engine';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport { logError } from '@metamask/snaps-utils';\nimport type { Json, JsonRpcParams } from '@metamask/utils';\n\nimport { selectHooks } from '../utils';\nimport { methodHandlers } from './handlers';\n\n/**\n * Creates a middleware that handles permitted snap RPC methods.\n *\n * @param isSnap - A flag that should indicate whether the requesting origin is a snap or not.\n * @param hooks - An object containing the hooks made available to the permitted RPC methods.\n * @returns The middleware.\n */\nexport function createSnapsMethodMiddleware(\n isSnap: boolean,\n hooks: Record<string, unknown>,\n): JsonRpcMiddleware<JsonRpcParams, Json> {\n // This is not actually a misused promise, the type is just wrong\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n return async function methodMiddleware(request, response, next, end) {\n const handler =\n methodHandlers[request.method as keyof typeof methodHandlers];\n if (handler) {\n if (\n String.prototype.startsWith.call(request.method, 'snap_') &&\n !isSnap\n ) {\n return end(rpcErrors.methodNotFound());\n }\n\n // TODO: Once json-rpc-engine types are up to date, we should type this correctly\n const { implementation, hookNames } = handler as any;\n try {\n // Implementations may or may not be async, so we must await them.\n return await implementation(\n request,\n response,\n next,\n end,\n selectHooks(hooks, hookNames),\n );\n } catch (error) {\n logError(error);\n return end(error);\n }\n }\n\n return next();\n };\n}\n"],"names":["rpcErrors","logError","selectHooks","methodHandlers","createSnapsMethodMiddleware","isSnap","hooks","methodMiddleware","request","response","next","end","handler","method","String","prototype","startsWith","call","methodNotFound","implementation","hookNames","error"],"mappings":"AACA,SAASA,SAAS,QAAQ,uBAAuB;AACjD,SAASC,QAAQ,QAAQ,wBAAwB;AAGjD,SAASC,WAAW,QAAQ,WAAW;AACvC,SAASC,cAAc,QAAQ,aAAa;AAE5C;;;;;;CAMC,GACD,OAAO,SAASC,4BACdC,MAAe,EACfC,KAA8B;IAE9B,iEAAiE;IACjE,kEAAkE;IAClE,OAAO,eAAeC,iBAAiBC,OAAO,EAAEC,QAAQ,EAAEC,IAAI,EAAEC,GAAG;QACjE,MAAMC,UACJT,cAAc,CAACK,QAAQK,MAAM,CAAgC;QAC/D,IAAID,SAAS;YACX,IACEE,OAAOC,SAAS,CAACC,UAAU,CAACC,IAAI,CAACT,QAAQK,MAAM,EAAE,YACjD,CAACR,QACD;gBACA,OAAOM,IAAIX,UAAUkB,cAAc;YACrC;YAEA,iFAAiF;YACjF,MAAM,EAAEC,cAAc,EAAEC,SAAS,EAAE,GAAGR;YACtC,IAAI;gBACF,kEAAkE;gBAClE,OAAO,MAAMO,eACXX,SACAC,UACAC,MACAC,KACAT,YAAYI,OAAOc;YAEvB,EAAE,OAAOC,OAAO;gBACdpB,SAASoB;gBACT,OAAOV,IAAIU;YACb;QACF;QAEA,OAAOX;IACT;AACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/snaps-rpc-methods",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "MetaMask Snaps JSON-RPC method implementations.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@metamask/permission-controller": "^6.0.0",
|
|
41
41
|
"@metamask/rpc-errors": "^6.1.0",
|
|
42
42
|
"@metamask/snaps-sdk": "^1.3.0",
|
|
43
|
-
"@metamask/snaps-utils": "^5.0
|
|
43
|
+
"@metamask/snaps-utils": "^5.1.0",
|
|
44
44
|
"@metamask/utils": "^8.2.1",
|
|
45
45
|
"@noble/hashes": "^1.3.1",
|
|
46
46
|
"superstruct": "^1.0.3"
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@lavamoat/allow-scripts": "^2.5.1",
|
|
50
50
|
"@metamask/auto-changelog": "^3.4.3",
|
|
51
|
-
"@metamask/browser-passworder": "^4.
|
|
51
|
+
"@metamask/browser-passworder": "^4.3.0",
|
|
52
52
|
"@metamask/eslint-config": "^12.1.0",
|
|
53
53
|
"@metamask/eslint-config-jest": "^12.1.0",
|
|
54
54
|
"@metamask/eslint-config-nodejs": "^12.1.0",
|