@metamask/snaps-rpc-methods 7.0.2 → 8.1.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 +12 -1
- package/dist/{chunk-JQ456NCC.mjs → chunk-3W4SMZFD.mjs} +3 -3
- package/dist/{chunk-WLDEPJGG.mjs → chunk-634BK2VP.mjs} +3 -3
- package/dist/chunk-634BK2VP.mjs.map +1 -0
- package/dist/{chunk-GP5KW5FU.js → chunk-D5WQBUZB.js} +2 -2
- package/dist/chunk-D5WQBUZB.js.map +1 -0
- package/dist/{chunk-6UY23OOZ.js → chunk-GP6TDVNT.js} +3 -3
- package/dist/{chunk-YS6TYXCP.mjs → chunk-GVJLWGSI.mjs} +3 -3
- package/dist/chunk-GVJLWGSI.mjs.map +1 -0
- package/dist/{chunk-GYZV5UBD.js → chunk-I7DR6BFO.js} +4 -4
- package/dist/chunk-I7DR6BFO.js.map +1 -0
- package/dist/{chunk-D6MUXDVI.js → chunk-INB4AX37.js} +5 -5
- package/dist/{chunk-AKRFLGOS.mjs → chunk-L675SYPP.mjs} +2 -2
- package/dist/{chunk-7NBRKDKJ.mjs → chunk-NESDQ4PF.mjs} +9 -54
- package/dist/chunk-NESDQ4PF.mjs.map +1 -0
- package/dist/{chunk-3S7DJI4I.mjs → chunk-PG32JMWC.mjs} +3 -3
- package/dist/chunk-PG32JMWC.mjs.map +1 -0
- package/dist/{chunk-KO4MKRYZ.js → chunk-R2M4YLJ7.js} +7 -52
- package/dist/chunk-R2M4YLJ7.js.map +1 -0
- package/dist/{chunk-LVTN25J2.js → chunk-RIALLTR7.js} +5 -5
- package/dist/{chunk-LVTN25J2.js.map → chunk-RIALLTR7.js.map} +1 -1
- package/dist/{chunk-FBOZCV3C.js → chunk-RX7WZZ32.js} +3 -3
- package/dist/{chunk-3LPBU737.js → chunk-UDB4MUXI.js} +2 -2
- package/dist/chunk-UDB4MUXI.js.map +1 -0
- package/dist/{chunk-7OMVZR5X.mjs → chunk-VNH2GKLV.mjs} +2 -2
- package/dist/{chunk-4SQWLI2S.mjs → chunk-X247BMMW.mjs} +6 -6
- package/dist/chunk-X247BMMW.mjs.map +1 -0
- package/dist/index.js +9 -9
- package/dist/index.mjs +10 -10
- package/dist/permissions.js +5 -5
- package/dist/permissions.mjs +4 -4
- package/dist/permitted/createInterface.js +2 -2
- package/dist/permitted/createInterface.mjs +1 -1
- package/dist/permitted/handlers.js +4 -4
- package/dist/permitted/handlers.mjs +3 -3
- package/dist/permitted/index.js +5 -5
- package/dist/permitted/index.mjs +4 -4
- package/dist/permitted/middleware.js +5 -5
- package/dist/permitted/middleware.mjs +4 -4
- package/dist/permitted/updateInterface.js +2 -2
- package/dist/permitted/updateInterface.mjs +1 -1
- package/dist/restricted/dialog.js +2 -2
- package/dist/restricted/dialog.mjs +1 -1
- package/dist/restricted/index.js +4 -4
- package/dist/restricted/index.mjs +5 -5
- package/dist/restricted/manageState.js +2 -2
- package/dist/restricted/manageState.mjs +3 -3
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/permitted/createInterface.d.ts +8 -8
- package/dist/types/permitted/updateInterface.d.ts +8 -8
- package/dist/types/restricted/dialog.d.ts +207 -39
- package/dist/types/restricted/index.d.ts +1 -1
- package/dist/types/restricted/manageAccounts.d.ts +1 -1
- package/dist/types/restricted/manageState.d.ts +5 -31
- package/package.json +3 -4
- package/dist/chunk-3LPBU737.js.map +0 -1
- package/dist/chunk-3S7DJI4I.mjs.map +0 -1
- package/dist/chunk-4SQWLI2S.mjs.map +0 -1
- package/dist/chunk-7NBRKDKJ.mjs.map +0 -1
- package/dist/chunk-GP5KW5FU.js.map +0 -1
- package/dist/chunk-GYZV5UBD.js.map +0 -1
- package/dist/chunk-KO4MKRYZ.js.map +0 -1
- package/dist/chunk-WLDEPJGG.mjs.map +0 -1
- package/dist/chunk-YS6TYXCP.mjs.map +0 -1
- /package/dist/{chunk-JQ456NCC.mjs.map → chunk-3W4SMZFD.mjs.map} +0 -0
- /package/dist/{chunk-6UY23OOZ.js.map → chunk-GP6TDVNT.js.map} +0 -0
- /package/dist/{chunk-D6MUXDVI.js.map → chunk-INB4AX37.js.map} +0 -0
- /package/dist/{chunk-AKRFLGOS.mjs.map → chunk-L675SYPP.mjs.map} +0 -0
- /package/dist/{chunk-FBOZCV3C.js.map → chunk-RX7WZZ32.js.map} +0 -0
- /package/dist/{chunk-7OMVZR5X.mjs.map → chunk-VNH2GKLV.mjs.map} +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [8.1.0]
|
|
10
|
+
### Added
|
|
11
|
+
- Add JSX support for custom UI ([#2258](https://github.com/MetaMask/snaps/pull/2258))
|
|
12
|
+
|
|
13
|
+
## [8.0.0]
|
|
14
|
+
### Changed
|
|
15
|
+
- **BREAKING:** Refactor to support changes to encryption ([#2316](https://github.com/MetaMask/snaps/pull/2316))
|
|
16
|
+
- No longer expects `encrypt` or `decrypt`, instead expects `updateSnapState` and `getSnapState` to be asynchronous
|
|
17
|
+
|
|
9
18
|
## [7.0.2]
|
|
10
19
|
### Changed
|
|
11
20
|
- Bump MetaMask dependencies ([#2270](https://github.com/MetaMask/snaps/pull/2270))
|
|
@@ -125,7 +134,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
125
134
|
- The version of the package no longer needs to match the version of all other
|
|
126
135
|
MetaMask Snaps packages.
|
|
127
136
|
|
|
128
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@
|
|
137
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@8.1.0...HEAD
|
|
138
|
+
[8.1.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@8.0.0...@metamask/snaps-rpc-methods@8.1.0
|
|
139
|
+
[8.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@7.0.2...@metamask/snaps-rpc-methods@8.0.0
|
|
129
140
|
[7.0.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@7.0.1...@metamask/snaps-rpc-methods@7.0.2
|
|
130
141
|
[7.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@7.0.0...@metamask/snaps-rpc-methods@7.0.1
|
|
131
142
|
[7.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-rpc-methods@6.0.0...@metamask/snaps-rpc-methods@7.0.0
|
|
@@ -9,10 +9,10 @@ import {
|
|
|
9
9
|
} from "./chunk-MXPVC2XP.mjs";
|
|
10
10
|
import {
|
|
11
11
|
updateInterfaceHandler
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-GVJLWGSI.mjs";
|
|
13
13
|
import {
|
|
14
14
|
createInterfaceHandler
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-634BK2VP.mjs";
|
|
16
16
|
import {
|
|
17
17
|
getAllSnapsHandler
|
|
18
18
|
} from "./chunk-UB3733UY.mjs";
|
|
@@ -48,4 +48,4 @@ export {
|
|
|
48
48
|
methodHandlers,
|
|
49
49
|
handlers
|
|
50
50
|
};
|
|
51
|
-
//# sourceMappingURL=chunk-
|
|
51
|
+
//# sourceMappingURL=chunk-3W4SMZFD.mjs.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/permitted/createInterface.ts
|
|
2
2
|
import { rpcErrors } from "@metamask/rpc-errors";
|
|
3
|
-
import {
|
|
3
|
+
import { ComponentOrElementStruct } from "@metamask/snaps-sdk";
|
|
4
4
|
import { StructError, create, object } from "superstruct";
|
|
5
5
|
var hookNames = {
|
|
6
6
|
createInterface: true
|
|
@@ -11,7 +11,7 @@ var createInterfaceHandler = {
|
|
|
11
11
|
hookNames
|
|
12
12
|
};
|
|
13
13
|
var CreateInterfaceParametersStruct = object({
|
|
14
|
-
ui:
|
|
14
|
+
ui: ComponentOrElementStruct
|
|
15
15
|
});
|
|
16
16
|
async function getCreateInterfaceImplementation(req, res, _next, end, { createInterface }) {
|
|
17
17
|
const { params } = req;
|
|
@@ -40,4 +40,4 @@ function getValidatedParams(params) {
|
|
|
40
40
|
export {
|
|
41
41
|
createInterfaceHandler
|
|
42
42
|
};
|
|
43
|
-
//# sourceMappingURL=chunk-
|
|
43
|
+
//# sourceMappingURL=chunk-634BK2VP.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/permitted/createInterface.ts"],"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 CreateInterfaceParams,\n CreateInterfaceResult,\n JsonRpcRequest,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport { ComponentOrElementStruct } from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { StructError, create, object } from 'superstruct';\n\nimport type { MethodHooksObject } from '../utils';\n\nconst hookNames: MethodHooksObject<CreateInterfaceMethodHooks> = {\n createInterface: true,\n};\n\nexport type CreateInterfaceMethodHooks = {\n /**\n * @param ui - The UI components.\n * @returns The unique identifier of the interface.\n */\n createInterface: (ui: ComponentOrElement) => Promise<string>;\n};\n\nexport const createInterfaceHandler: PermittedHandlerExport<\n CreateInterfaceMethodHooks,\n CreateInterfaceParameters,\n CreateInterfaceResult\n> = {\n methodNames: ['snap_createInterface'],\n implementation: getCreateInterfaceImplementation,\n hookNames,\n};\n\nconst CreateInterfaceParametersStruct = object({\n ui: ComponentOrElementStruct,\n});\n\nexport type CreateInterfaceParameters = InferMatching<\n typeof CreateInterfaceParametersStruct,\n CreateInterfaceParams\n>;\n\n/**\n * The `snap_createInterface` 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.createInterface - The function to create the interface.\n * @returns Nothing.\n */\nasync function getCreateInterfaceImplementation(\n req: JsonRpcRequest<CreateInterfaceParameters>,\n res: PendingJsonRpcResponse<CreateInterfaceResult>,\n _next: unknown,\n end: JsonRpcEngineEndCallback,\n { createInterface }: CreateInterfaceMethodHooks,\n): Promise<void> {\n const { params } = req;\n\n try {\n const validatedParams = getValidatedParams(params);\n\n const { ui } = validatedParams;\n\n res.result = await createInterface(ui);\n } catch (error) {\n return end(error);\n }\n\n return end();\n}\n\n/**\n * Validate the createInterface 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 createInterface method parameter object.\n */\nfunction getValidatedParams(params: unknown): CreateInterfaceParameters {\n try {\n return create(params, CreateInterfaceParametersStruct);\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"],"mappings":";AAEA,SAAS,iBAAiB;AAO1B,SAAS,gCAAgC;AAGzC,SAAS,aAAa,QAAQ,cAAc;AAI5C,IAAM,YAA2D;AAAA,EAC/D,iBAAiB;AACnB;AAUO,IAAM,yBAIT;AAAA,EACF,aAAa,CAAC,sBAAsB;AAAA,EACpC,gBAAgB;AAAA,EAChB;AACF;AAEA,IAAM,kCAAkC,OAAO;AAAA,EAC7C,IAAI;AACN,CAAC;AAmBD,eAAe,iCACb,KACA,KACA,OACA,KACA,EAAE,gBAAgB,GACH;AACf,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI;AACF,UAAM,kBAAkB,mBAAmB,MAAM;AAEjD,UAAM,EAAE,GAAG,IAAI;AAEf,QAAI,SAAS,MAAM,gBAAgB,EAAE;AAAA,EACvC,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;AASA,SAAS,mBAAmB,QAA4C;AACtE,MAAI;AACF,WAAO,OAAO,QAAQ,+BAA+B;AAAA,EACvD,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,UAAU,cAAc;AAAA,QAC5B,SAAS,mBAAmB,MAAM,OAAO;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,SAAS;AAAA,EAC3B;AACF;","names":[]}
|
|
@@ -12,7 +12,7 @@ var updateInterfaceHandler = {
|
|
|
12
12
|
};
|
|
13
13
|
var UpdateInterfaceParametersStruct = _superstruct.object.call(void 0, {
|
|
14
14
|
id: _superstruct.string.call(void 0, ),
|
|
15
|
-
ui: _snapssdk.
|
|
15
|
+
ui: _snapssdk.ComponentOrElementStruct
|
|
16
16
|
});
|
|
17
17
|
async function getUpdateInterfaceImplementation(req, res, _next, end, { updateInterface }) {
|
|
18
18
|
const { params } = req;
|
|
@@ -42,4 +42,4 @@ function getValidatedParams(params) {
|
|
|
42
42
|
|
|
43
43
|
|
|
44
44
|
exports.updateInterfaceHandler = updateInterfaceHandler;
|
|
45
|
-
//# sourceMappingURL=chunk-
|
|
45
|
+
//# sourceMappingURL=chunk-D5WQBUZB.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/permitted/updateInterface.ts"],"names":[],"mappings":";AAEA,SAAS,iBAAiB;AAO1B,SAAS,gCAAgC;AAGzC,SAAS,aAAa,QAAQ,QAAQ,cAAc;AAIpD,IAAM,YAA2D;AAAA,EAC/D,iBAAiB;AACnB;AAUO,IAAM,yBAIT;AAAA,EACF,aAAa,CAAC,sBAAsB;AAAA,EACpC,gBAAgB;AAAA,EAChB;AACF;AAEA,IAAM,kCAAkC,OAAO;AAAA,EAC7C,IAAI,OAAO;AAAA,EACX,IAAI;AACN,CAAC;AAmBD,eAAe,iCACb,KACA,KACA,OACA,KACA,EAAE,gBAAgB,GACH;AACf,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI;AACF,UAAM,kBAAkB,mBAAmB,MAAM;AAEjD,UAAM,EAAE,IAAI,GAAG,IAAI;AAEnB,UAAM,gBAAgB,IAAI,EAAE;AAC5B,QAAI,SAAS;AAAA,EACf,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;AASA,SAAS,mBAAmB,QAA4C;AACtE,MAAI;AACF,WAAO,OAAO,QAAQ,+BAA+B;AAAA,EACvD,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,UAAU,cAAc;AAAA,QAC5B,SAAS,mBAAmB,MAAM,OAAO;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,SAAS;AAAA,EAC3B;AACF","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} from '@metamask/snaps-sdk';\nimport { ComponentOrElementStruct } from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { StructError, create, object, string } from 'superstruct';\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 */\n updateInterface: (id: string, ui: ComponentOrElement) => 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});\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 } = validatedParams;\n\n await updateInterface(id, ui);\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,6 +1,6 @@
|
|
|
1
1
|
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var _chunkINB4AX37js = require('./chunk-INB4AX37.js');
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
var _chunkYG7W4CDTjs = require('./chunk-YG7W4CDT.js');
|
|
@@ -10,7 +10,7 @@ var _rpcerrors = require('@metamask/rpc-errors');
|
|
|
10
10
|
var _snapsutils = require('@metamask/snaps-utils');
|
|
11
11
|
function createSnapsMethodMiddleware(isSnap, hooks) {
|
|
12
12
|
return async function methodMiddleware(request, response, next, end) {
|
|
13
|
-
const handler =
|
|
13
|
+
const handler = _chunkINB4AX37js.methodHandlers[request.method];
|
|
14
14
|
if (handler) {
|
|
15
15
|
if (String.prototype.startsWith.call(request.method, "snap_") && !isSnap) {
|
|
16
16
|
return end(_rpcerrors.rpcErrors.methodNotFound());
|
|
@@ -36,4 +36,4 @@ function createSnapsMethodMiddleware(isSnap, hooks) {
|
|
|
36
36
|
|
|
37
37
|
|
|
38
38
|
exports.createSnapsMethodMiddleware = createSnapsMethodMiddleware;
|
|
39
|
-
//# sourceMappingURL=chunk-
|
|
39
|
+
//# sourceMappingURL=chunk-GP6TDVNT.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/permitted/updateInterface.ts
|
|
2
2
|
import { rpcErrors } from "@metamask/rpc-errors";
|
|
3
|
-
import {
|
|
3
|
+
import { ComponentOrElementStruct } from "@metamask/snaps-sdk";
|
|
4
4
|
import { StructError, create, object, string } from "superstruct";
|
|
5
5
|
var hookNames = {
|
|
6
6
|
updateInterface: true
|
|
@@ -12,7 +12,7 @@ var updateInterfaceHandler = {
|
|
|
12
12
|
};
|
|
13
13
|
var UpdateInterfaceParametersStruct = object({
|
|
14
14
|
id: string(),
|
|
15
|
-
ui:
|
|
15
|
+
ui: ComponentOrElementStruct
|
|
16
16
|
});
|
|
17
17
|
async function getUpdateInterfaceImplementation(req, res, _next, end, { updateInterface }) {
|
|
18
18
|
const { params } = req;
|
|
@@ -42,4 +42,4 @@ function getValidatedParams(params) {
|
|
|
42
42
|
export {
|
|
43
43
|
updateInterfaceHandler
|
|
44
44
|
};
|
|
45
|
-
//# sourceMappingURL=chunk-
|
|
45
|
+
//# sourceMappingURL=chunk-GVJLWGSI.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/permitted/updateInterface.ts"],"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} from '@metamask/snaps-sdk';\nimport { ComponentOrElementStruct } from '@metamask/snaps-sdk';\nimport { type InferMatching } from '@metamask/snaps-utils';\nimport type { PendingJsonRpcResponse } from '@metamask/utils';\nimport { StructError, create, object, string } from 'superstruct';\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 */\n updateInterface: (id: string, ui: ComponentOrElement) => 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});\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 } = validatedParams;\n\n await updateInterface(id, ui);\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"],"mappings":";AAEA,SAAS,iBAAiB;AAO1B,SAAS,gCAAgC;AAGzC,SAAS,aAAa,QAAQ,QAAQ,cAAc;AAIpD,IAAM,YAA2D;AAAA,EAC/D,iBAAiB;AACnB;AAUO,IAAM,yBAIT;AAAA,EACF,aAAa,CAAC,sBAAsB;AAAA,EACpC,gBAAgB;AAAA,EAChB;AACF;AAEA,IAAM,kCAAkC,OAAO;AAAA,EAC7C,IAAI,OAAO;AAAA,EACX,IAAI;AACN,CAAC;AAmBD,eAAe,iCACb,KACA,KACA,OACA,KACA,EAAE,gBAAgB,GACH;AACf,QAAM,EAAE,OAAO,IAAI;AAEnB,MAAI;AACF,UAAM,kBAAkB,mBAAmB,MAAM;AAEjD,UAAM,EAAE,IAAI,GAAG,IAAI;AAEnB,UAAM,gBAAgB,IAAI,EAAE;AAC5B,QAAI,SAAS;AAAA,EACf,SAAS,OAAO;AACd,WAAO,IAAI,KAAK;AAAA,EAClB;AAEA,SAAO,IAAI;AACb;AASA,SAAS,mBAAmB,QAA4C;AACtE,MAAI;AACF,WAAO,OAAO,QAAQ,+BAA+B;AAAA,EACvD,SAAS,OAAO;AACd,QAAI,iBAAiB,aAAa;AAChC,YAAM,UAAU,cAAc;AAAA,QAC5B,SAAS,mBAAmB,MAAM,OAAO;AAAA,MAC3C,CAAC;AAAA,IACH;AAEA,UAAM,UAAU,SAAS;AAAA,EAC3B;AACF;","names":[]}
|
|
@@ -47,7 +47,7 @@ var BaseParamsStruct = _superstruct.type.call(void 0, {
|
|
|
47
47
|
});
|
|
48
48
|
var AlertParametersWithContentStruct = _superstruct.object.call(void 0, {
|
|
49
49
|
type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Alert),
|
|
50
|
-
content: _snapssdk.
|
|
50
|
+
content: _snapssdk.ComponentOrElementStruct
|
|
51
51
|
});
|
|
52
52
|
var AlertParametersWithIdStruct = _superstruct.object.call(void 0, {
|
|
53
53
|
type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Alert),
|
|
@@ -59,7 +59,7 @@ var AlertParametersStruct = _snapssdk.union.call(void 0, [
|
|
|
59
59
|
]);
|
|
60
60
|
var ConfirmationParametersWithContentStruct = _superstruct.object.call(void 0, {
|
|
61
61
|
type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Confirmation),
|
|
62
|
-
content: _snapssdk.
|
|
62
|
+
content: _snapssdk.ComponentOrElementStruct
|
|
63
63
|
});
|
|
64
64
|
var ConfirmationParametersWithIdStruct = _superstruct.object.call(void 0, {
|
|
65
65
|
type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Confirmation),
|
|
@@ -71,7 +71,7 @@ var ConfirmationParametersStruct = _snapssdk.union.call(void 0, [
|
|
|
71
71
|
]);
|
|
72
72
|
var PromptParametersWithContentStruct = _superstruct.object.call(void 0, {
|
|
73
73
|
type: _snapssdk.enumValue.call(void 0, _snapssdk.DialogType.Prompt),
|
|
74
|
-
content: _snapssdk.
|
|
74
|
+
content: _snapssdk.ComponentOrElementStruct,
|
|
75
75
|
placeholder: PlaceholderStruct
|
|
76
76
|
});
|
|
77
77
|
var PromptParametersWithIdStruct = _superstruct.object.call(void 0, {
|
|
@@ -148,4 +148,4 @@ function getValidatedParams(params, struct) {
|
|
|
148
148
|
|
|
149
149
|
|
|
150
150
|
exports.dialogBuilder = dialogBuilder; exports.getDialogImplementation = getDialogImplementation;
|
|
151
|
-
//# sourceMappingURL=chunk-
|
|
151
|
+
//# sourceMappingURL=chunk-I7DR6BFO.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/restricted/dialog.ts"],"names":["methodHooks"],"mappings":"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","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport {\n DialogType,\n enumValue,\n union,\n ComponentOrElementStruct,\n} from '@metamask/snaps-sdk';\nimport type {\n DialogParams,\n EnumToUnion,\n Component,\n InterfaceState,\n SnapId,\n ComponentOrElement,\n} from '@metamask/snaps-sdk';\nimport { createUnion } from '@metamask/snaps-utils';\nimport type { InferMatching } from '@metamask/snaps-utils';\nimport { hasProperty, type NonEmptyArray } from '@metamask/utils';\nimport type { Infer, Struct } from 'superstruct';\nimport {\n create,\n enums,\n object,\n optional,\n size,\n string,\n type,\n} from 'superstruct';\n\nimport { type MethodHooksObject } from '../utils';\n\nconst methodName = 'snap_dialog';\n\nconst PlaceholderStruct = optional(size(string(), 1, 40));\n\nexport type Placeholder = Infer<typeof PlaceholderStruct>;\n\ntype ShowDialog = (\n snapId: string,\n type: EnumToUnion<DialogType>,\n id: string,\n placeholder?: Placeholder,\n) => Promise<null | boolean | string>;\n\ntype CreateInterface = (\n snapId: string,\n content: ComponentOrElement,\n) => Promise<string>;\n\ntype GetInterface = (\n snapId: string,\n id: string,\n) => { content: ComponentOrElement; snapId: SnapId; state: InterfaceState };\n\nexport type DialogMethodHooks = {\n /**\n * @param snapId - The ID of the Snap that created the alert.\n * @param type - The dialog type.\n * @param id - The interface ID.\n * @param placeholder - The placeholder for the Prompt dialog input.\n */\n showDialog: ShowDialog;\n\n /**\n * @param snapId - The Snap ID creating the interface.\n * @param content - The content of the interface.\n */\n createInterface: CreateInterface;\n /**\n * @param snapId - The SnapId requesting the interface.\n * @param id - The interface ID.\n */\n getInterface: GetInterface;\n};\n\ntype DialogSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: DialogMethodHooks;\n};\n\ntype DialogSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getDialogImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_dialog` permission. `snap_dialog`\n * lets the Snap display one of the following dialogs to the user:\n * - An alert, for displaying information.\n * - A confirmation, for accepting or rejecting some action.\n * - A prompt, for inputting some information.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the\n * permission.\n * @param options.methodHooks - The RPC method hooks needed by the method\n * implementation.\n * @returns The specification for the `snap_dialog` permission.\n */\nconst specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n DialogSpecificationBuilderOptions,\n DialogSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: DialogSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getDialogImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<DialogMethodHooks> = {\n showDialog: true,\n createInterface: true,\n getInterface: true,\n};\n\nexport const dialogBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\n// Note: We use `type` here instead of `object` because `type` does not validate\n// the keys of the object, which is what we want.\nconst BaseParamsStruct = type({\n type: enums([DialogType.Alert, DialogType.Confirmation, DialogType.Prompt]),\n});\n\nconst AlertParametersWithContentStruct = object({\n type: enumValue(DialogType.Alert),\n content: ComponentOrElementStruct,\n});\nconst AlertParametersWithIdStruct = object({\n type: enumValue(DialogType.Alert),\n id: string(),\n});\n\nconst AlertParametersStruct = union([\n AlertParametersWithContentStruct,\n AlertParametersWithIdStruct,\n]);\n\nconst ConfirmationParametersWithContentStruct = object({\n type: enumValue(DialogType.Confirmation),\n content: ComponentOrElementStruct,\n});\n\nconst ConfirmationParametersWithIdStruct = object({\n type: enumValue(DialogType.Confirmation),\n id: string(),\n});\n\nconst ConfirmationParametersStruct = union([\n ConfirmationParametersWithContentStruct,\n ConfirmationParametersWithIdStruct,\n]);\n\nconst PromptParametersWithContentStruct = object({\n type: enumValue(DialogType.Prompt),\n content: ComponentOrElementStruct,\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersWithIdStruct = object({\n type: enumValue(DialogType.Prompt),\n id: string(),\n placeholder: PlaceholderStruct,\n});\n\nconst PromptParametersStruct = union([\n PromptParametersWithContentStruct,\n PromptParametersWithIdStruct,\n]);\n\nconst DialogParametersStruct = union([\n AlertParametersStruct,\n ConfirmationParametersStruct,\n PromptParametersStruct,\n]);\n\nexport type DialogParameters = InferMatching<\n typeof DialogParametersStruct,\n DialogParams\n>;\n\nconst structs = {\n [DialogType.Alert]: AlertParametersStruct,\n [DialogType.Confirmation]: ConfirmationParametersStruct,\n [DialogType.Prompt]: PromptParametersStruct,\n};\n\n/**\n * Builds the method implementation for `snap_dialog`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.showDialog - A function that shows the specified dialog in the\n * MetaMask UI and returns the appropriate value for the dialog type.\n * @param hooks.createInterface - A function that creates the interface in SnapInterfaceController.\n * @param hooks.getInterface - A function that gets an interface from SnapInterfaceController.\n * @returns The method implementation which return value depends on the dialog\n * type, valid return types are: string, boolean, null.\n */\nexport function getDialogImplementation({\n showDialog,\n createInterface,\n getInterface,\n}: DialogMethodHooks) {\n return async function dialogImplementation(\n args: RestrictedMethodOptions<DialogParameters>,\n ): Promise<boolean | null | string> {\n const {\n params,\n context: { origin },\n } = args;\n\n const validatedType = getValidatedType(params);\n const validatedParams = getValidatedParams(params, structs[validatedType]);\n\n const placeholder =\n validatedParams.type === DialogType.Prompt\n ? validatedParams.placeholder\n : undefined;\n\n if (hasProperty(validatedParams, 'content')) {\n const id = await createInterface(\n origin,\n validatedParams.content as Component,\n );\n return showDialog(origin, validatedType, id, placeholder);\n }\n\n // Verify that the passed interface ID is valid.\n // This will throw if the interface ID is invalid (not created by the snap or doesn't exist)\n try {\n getInterface(origin, validatedParams.id);\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n\n return showDialog(origin, validatedType, validatedParams.id, placeholder);\n };\n}\n\n/**\n * Get the validated type of the dialog parameters. Throws an error if the type\n * is invalid.\n *\n * @param params - The parameters to validate.\n * @returns The validated type of the dialog parameters.\n */\nfunction getValidatedType(params: unknown): DialogType {\n try {\n return create(params, BaseParamsStruct).type;\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `The \"type\" property must be one of: ${Object.values(\n DialogType,\n ).join(', ')}.`,\n });\n }\n}\n\n/**\n * Validates the confirm 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 * @param struct - The struct to validate the params against.\n * @returns The validated confirm method parameter object.\n */\nfunction getValidatedParams(\n params: unknown,\n struct: Struct<any, any>,\n): DialogParameters {\n try {\n return createUnion(params, struct, 'type');\n } catch (error) {\n throw rpcErrors.invalidParams({\n message: `Invalid params: ${error.message}`,\n });\n }\n}\n"]}
|
|
@@ -9,10 +9,10 @@ var _chunkIDZGMGIBjs = require('./chunk-IDZGMGIB.js');
|
|
|
9
9
|
var _chunkPS6OEQXLjs = require('./chunk-PS6OEQXL.js');
|
|
10
10
|
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _chunkD5WQBUZBjs = require('./chunk-D5WQBUZB.js');
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkUDB4MUXIjs = require('./chunk-UDB4MUXI.js');
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
var _chunk4LSOS7SMjs = require('./chunk-4LSOS7SM.js');
|
|
@@ -38,8 +38,8 @@ var methodHandlers = {
|
|
|
38
38
|
wallet_invokeKeyring: _chunkAOWUGDERjs.invokeKeyringHandler,
|
|
39
39
|
snap_getClientStatus: _chunk3UAWEHMFjs.getClientStatusHandler,
|
|
40
40
|
snap_getFile: _chunkNP3KGMVCjs.getFileHandler,
|
|
41
|
-
snap_createInterface:
|
|
42
|
-
snap_updateInterface:
|
|
41
|
+
snap_createInterface: _chunkUDB4MUXIjs.createInterfaceHandler,
|
|
42
|
+
snap_updateInterface: _chunkD5WQBUZBjs.updateInterfaceHandler,
|
|
43
43
|
snap_getInterfaceState: _chunk4W7U4OH6js.getInterfaceStateHandler
|
|
44
44
|
};
|
|
45
45
|
var handlers = Object.values(methodHandlers);
|
|
@@ -48,4 +48,4 @@ var handlers = Object.values(methodHandlers);
|
|
|
48
48
|
|
|
49
49
|
|
|
50
50
|
exports.methodHandlers = methodHandlers; exports.handlers = handlers;
|
|
51
|
-
//# sourceMappingURL=chunk-
|
|
51
|
+
//# sourceMappingURL=chunk-INB4AX37.js.map
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
restrictedMethodPermissionBuilders
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-PG32JMWC.mjs";
|
|
4
4
|
import {
|
|
5
5
|
caveatMappers
|
|
6
6
|
} from "./chunk-Y4LNTDZ2.mjs";
|
|
@@ -56,4 +56,4 @@ export {
|
|
|
56
56
|
buildSnapEndowmentSpecifications,
|
|
57
57
|
buildSnapRestrictedMethodSpecifications
|
|
58
58
|
};
|
|
59
|
-
//# sourceMappingURL=chunk-
|
|
59
|
+
//# sourceMappingURL=chunk-L675SYPP.mjs.map
|
|
@@ -6,8 +6,8 @@ import {
|
|
|
6
6
|
import { PermissionType, SubjectType } from "@metamask/permission-controller";
|
|
7
7
|
import { rpcErrors } from "@metamask/rpc-errors";
|
|
8
8
|
import { ManageStateOperation } from "@metamask/snaps-sdk";
|
|
9
|
-
import { STATE_ENCRYPTION_MAGIC_VALUE
|
|
10
|
-
import { isObject, getJsonSize
|
|
9
|
+
import { STATE_ENCRYPTION_MAGIC_VALUE } from "@metamask/snaps-utils";
|
|
10
|
+
import { isObject, getJsonSize } from "@metamask/utils";
|
|
11
11
|
var STATE_ENCRYPTION_SALT = "snap_manageState encryption";
|
|
12
12
|
var methodName = "snap_manageState";
|
|
13
13
|
var specificationBuilder = ({
|
|
@@ -23,13 +23,10 @@ var specificationBuilder = ({
|
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
var methodHooks = {
|
|
26
|
-
getMnemonic: true,
|
|
27
26
|
getUnlockPromise: true,
|
|
28
27
|
clearSnapState: true,
|
|
29
28
|
getSnapState: true,
|
|
30
|
-
updateSnapState: true
|
|
31
|
-
encrypt: true,
|
|
32
|
-
decrypt: true
|
|
29
|
+
updateSnapState: true
|
|
33
30
|
};
|
|
34
31
|
var manageStateBuilder = Object.freeze({
|
|
35
32
|
targetName: methodName,
|
|
@@ -37,7 +34,7 @@ var manageStateBuilder = Object.freeze({
|
|
|
37
34
|
methodHooks
|
|
38
35
|
});
|
|
39
36
|
var STORAGE_SIZE_LIMIT = 104857600;
|
|
40
|
-
async function
|
|
37
|
+
async function getEncryptionEntropy({
|
|
41
38
|
mnemonicPhrase,
|
|
42
39
|
snapId
|
|
43
40
|
}) {
|
|
@@ -48,38 +45,11 @@ async function getEncryptionKey({
|
|
|
48
45
|
magic: STATE_ENCRYPTION_MAGIC_VALUE
|
|
49
46
|
});
|
|
50
47
|
}
|
|
51
|
-
async function encryptState({
|
|
52
|
-
state,
|
|
53
|
-
encryptFunction,
|
|
54
|
-
...keyArgs
|
|
55
|
-
}) {
|
|
56
|
-
const encryptionKey = await getEncryptionKey(keyArgs);
|
|
57
|
-
return await encryptFunction(encryptionKey, state);
|
|
58
|
-
}
|
|
59
|
-
async function decryptState({
|
|
60
|
-
state,
|
|
61
|
-
decryptFunction,
|
|
62
|
-
...keyArgs
|
|
63
|
-
}) {
|
|
64
|
-
try {
|
|
65
|
-
const encryptionKey = await getEncryptionKey(keyArgs);
|
|
66
|
-
const decryptedState = await decryptFunction(encryptionKey, state);
|
|
67
|
-
assert(isValidJson(decryptedState));
|
|
68
|
-
return decryptedState;
|
|
69
|
-
} catch {
|
|
70
|
-
throw rpcErrors.internal({
|
|
71
|
-
message: "Failed to decrypt snap state, the state must be corrupted."
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
48
|
function getManageStateImplementation({
|
|
76
|
-
getMnemonic,
|
|
77
49
|
getUnlockPromise,
|
|
78
50
|
clearSnapState,
|
|
79
51
|
getSnapState,
|
|
80
|
-
updateSnapState
|
|
81
|
-
encrypt,
|
|
82
|
-
decrypt
|
|
52
|
+
updateSnapState
|
|
83
53
|
}) {
|
|
84
54
|
return async function manageState(options) {
|
|
85
55
|
const {
|
|
@@ -97,25 +67,10 @@ function getManageStateImplementation({
|
|
|
97
67
|
clearSnapState(origin, shouldEncrypt);
|
|
98
68
|
return null;
|
|
99
69
|
case ManageStateOperation.GetState: {
|
|
100
|
-
|
|
101
|
-
if (state === null) {
|
|
102
|
-
return state;
|
|
103
|
-
}
|
|
104
|
-
return shouldEncrypt ? await decryptState({
|
|
105
|
-
state,
|
|
106
|
-
decryptFunction: decrypt,
|
|
107
|
-
mnemonicPhrase: await getMnemonic(),
|
|
108
|
-
snapId: origin
|
|
109
|
-
}) : parseJson(state);
|
|
70
|
+
return await getSnapState(origin, shouldEncrypt);
|
|
110
71
|
}
|
|
111
72
|
case ManageStateOperation.UpdateState: {
|
|
112
|
-
|
|
113
|
-
state: validatedParams.newState,
|
|
114
|
-
encryptFunction: encrypt,
|
|
115
|
-
mnemonicPhrase: await getMnemonic(),
|
|
116
|
-
snapId: origin
|
|
117
|
-
}) : JSON.stringify(validatedParams.newState);
|
|
118
|
-
updateSnapState(origin, finalizedState, shouldEncrypt);
|
|
73
|
+
await updateSnapState(origin, validatedParams.newState, shouldEncrypt);
|
|
119
74
|
return null;
|
|
120
75
|
}
|
|
121
76
|
default:
|
|
@@ -181,8 +136,8 @@ export {
|
|
|
181
136
|
specificationBuilder,
|
|
182
137
|
manageStateBuilder,
|
|
183
138
|
STORAGE_SIZE_LIMIT,
|
|
184
|
-
|
|
139
|
+
getEncryptionEntropy,
|
|
185
140
|
getManageStateImplementation,
|
|
186
141
|
getValidatedParams
|
|
187
142
|
};
|
|
188
|
-
//# sourceMappingURL=chunk-
|
|
143
|
+
//# sourceMappingURL=chunk-NESDQ4PF.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/restricted/manageState.ts"],"sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { ManageStateParams, ManageStateResult } from '@metamask/snaps-sdk';\nimport { ManageStateOperation } from '@metamask/snaps-sdk';\nimport { STATE_ENCRYPTION_MAGIC_VALUE } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { isObject, getJsonSize } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { deriveEntropy } from '../utils';\n\n// The salt used for SIP-6-based entropy derivation.\nexport const STATE_ENCRYPTION_SALT = 'snap_manageState encryption';\n\nconst methodName = 'snap_manageState';\n\nexport type ManageStateMethodHooks = {\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * A function that clears the state of the requesting Snap.\n */\n clearSnapState: (snapId: string, encrypted: boolean) => void;\n\n /**\n * A function that gets the encrypted state of the requesting Snap.\n *\n * @returns The current state of the Snap.\n */\n getSnapState: (\n snapId: string,\n encrypted: boolean,\n ) => Promise<Record<string, Json>>;\n\n /**\n * A function that updates the state of the requesting Snap.\n *\n * @param newState - The new state of the Snap.\n */\n updateSnapState: (\n snapId: string,\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n};\n\ntype ManageStateSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: ManageStateMethodHooks;\n};\n\ntype ManageStateSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getManageStateImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_manageState` permission.\n * `snap_manageState` lets the Snap store and manage some of its state on\n * your device.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_manageState` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n ManageStateSpecificationBuilderOptions,\n ManageStateSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: ManageStateSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getManageStateImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<ManageStateMethodHooks> = {\n getUnlockPromise: true,\n clearSnapState: true,\n getSnapState: true,\n updateSnapState: true,\n};\n\nexport const manageStateBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nexport const STORAGE_SIZE_LIMIT = 104857600; // In bytes (100MB)\n\ntype GetEncryptionKeyArgs = {\n snapId: string;\n mnemonicPhrase: Uint8Array;\n};\n\n/**\n * Get a deterministic encryption key to use for encrypting and decrypting the\n * state.\n *\n * This key should only be used for state encryption using `snap_manageState`.\n * To get other encryption keys, a different salt can be used.\n *\n * @param args - The encryption key args.\n * @param args.snapId - The ID of the snap to get the encryption key for.\n * @param args.mnemonicPhrase - The mnemonic phrase to derive the encryption key\n * from.\n * @returns The state encryption key.\n */\nexport async function getEncryptionEntropy({\n mnemonicPhrase,\n snapId,\n}: GetEncryptionKeyArgs) {\n return await deriveEntropy({\n mnemonicPhrase,\n input: snapId,\n salt: STATE_ENCRYPTION_SALT,\n magic: STATE_ENCRYPTION_MAGIC_VALUE,\n });\n}\n\n/**\n * Builds the method implementation for `snap_manageState`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.clearSnapState - A function that clears the state stored for a\n * snap.\n * @param hooks.getSnapState - A function that fetches the persisted decrypted\n * state for a snap.\n * @param hooks.updateSnapState - A function that updates the state stored for a\n * snap.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask\n * extension is unlocked and prompts the user to unlock their MetaMask if it is\n * locked.\n * @returns The method implementation which either returns `null` for a\n * successful state update/deletion or returns the decrypted state.\n * @throws If the params are invalid.\n */\nexport function getManageStateImplementation({\n getUnlockPromise,\n clearSnapState,\n getSnapState,\n updateSnapState,\n}: ManageStateMethodHooks) {\n return async function manageState(\n options: RestrictedMethodOptions<ManageStateParams>,\n ): Promise<ManageStateResult> {\n const {\n params = {},\n method,\n context: { origin },\n } = options;\n const validatedParams = getValidatedParams(params, method);\n\n // If the encrypted param is undefined or null we default to true.\n const shouldEncrypt = validatedParams.encrypted ?? true;\n\n // We only need to prompt the user when the mnemonic is needed\n // which it isn't for the clear operation or unencrypted storage.\n if (\n shouldEncrypt &&\n validatedParams.operation !== ManageStateOperation.ClearState\n ) {\n await getUnlockPromise(true);\n }\n\n switch (validatedParams.operation) {\n case ManageStateOperation.ClearState:\n clearSnapState(origin, shouldEncrypt);\n return null;\n\n case ManageStateOperation.GetState: {\n return await getSnapState(origin, shouldEncrypt);\n }\n\n case ManageStateOperation.UpdateState: {\n await updateSnapState(origin, validatedParams.newState, shouldEncrypt);\n return null;\n }\n\n default:\n throw rpcErrors.invalidParams(\n `Invalid ${method} operation: \"${\n validatedParams.operation as string\n }\"`,\n );\n }\n };\n}\n\n/**\n * Validates the manageState 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 * @param method - RPC method name used for debugging errors.\n * @param storageSizeLimit - Maximum allowed size (in bytes) of a new state object.\n * @returns The validated method parameter object.\n */\nexport function getValidatedParams(\n params: unknown,\n method: string,\n storageSizeLimit = STORAGE_SIZE_LIMIT,\n): ManageStateParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { operation, newState, encrypted } = params;\n\n if (\n !operation ||\n typeof operation !== 'string' ||\n !Object.values(ManageStateOperation).includes(\n operation as ManageStateOperation,\n )\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid manage state \"operation\".',\n });\n }\n\n if (encrypted !== undefined && typeof encrypted !== 'boolean') {\n throw rpcErrors.invalidParams({\n message: '\"encrypted\" parameter must be a boolean if specified.',\n });\n }\n\n if (operation === ManageStateOperation.UpdateState) {\n if (!isObject(newState)) {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"updateState\" parameter: The new state must be a plain object.`,\n data: {\n receivedNewState:\n typeof newState === 'undefined' ? 'undefined' : newState,\n },\n });\n }\n\n let size;\n try {\n // `getJsonSize` will throw if the state is not JSON serializable.\n size = getJsonSize(newState);\n } catch {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"updateState\" parameter: The new state must be JSON serializable.`,\n data: {\n receivedNewState:\n typeof newState === 'undefined' ? 'undefined' : newState,\n },\n });\n }\n\n if (size > storageSizeLimit) {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"updateState\" parameter: The new state must not exceed ${storageSizeLimit} bytes in size.`,\n data: {\n receivedNewState:\n typeof newState === 'undefined' ? 'undefined' : newState,\n },\n });\n }\n }\n\n return params as ManageStateParams;\n}\n"],"mappings":"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","names":["methodHooks"]}
|
|
@@ -12,13 +12,13 @@ import {
|
|
|
12
12
|
} from "./chunk-E6WUMFQT.mjs";
|
|
13
13
|
import {
|
|
14
14
|
manageStateBuilder
|
|
15
|
-
} from "./chunk-
|
|
15
|
+
} from "./chunk-NESDQ4PF.mjs";
|
|
16
16
|
import {
|
|
17
17
|
notifyBuilder
|
|
18
18
|
} from "./chunk-JWDQUKKU.mjs";
|
|
19
19
|
import {
|
|
20
20
|
dialogBuilder
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-X247BMMW.mjs";
|
|
22
22
|
import {
|
|
23
23
|
getBip32EntropyBuilder
|
|
24
24
|
} from "./chunk-TNRH2LRU.mjs";
|
|
@@ -46,4 +46,4 @@ var restrictedMethodPermissionBuilders = {
|
|
|
46
46
|
export {
|
|
47
47
|
restrictedMethodPermissionBuilders
|
|
48
48
|
};
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
49
|
+
//# sourceMappingURL=chunk-PG32JMWC.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/restricted/index.ts"],"sourcesContent":["import type { DialogMethodHooks } from './dialog';\nimport { dialogBuilder } from './dialog';\nimport type { GetBip32EntropyMethodHooks } from './getBip32Entropy';\nimport { getBip32EntropyBuilder } from './getBip32Entropy';\nimport type { GetBip32PublicKeyMethodHooks } from './getBip32PublicKey';\nimport { getBip32PublicKeyBuilder } from './getBip32PublicKey';\nimport type { GetBip44EntropyMethodHooks } from './getBip44Entropy';\nimport { getBip44EntropyBuilder } from './getBip44Entropy';\nimport type { GetEntropyHooks } from './getEntropy';\nimport { getEntropyBuilder } from './getEntropy';\nimport type { GetLocaleMethodHooks } from './getLocale';\nimport { getLocaleBuilder } from './getLocale';\nimport type { InvokeSnapMethodHooks } from './invokeSnap';\nimport { invokeSnapBuilder } from './invokeSnap';\nimport type { ManageAccountsMethodHooks } from './manageAccounts';\nimport { manageAccountsBuilder } from './manageAccounts';\nimport type { ManageStateMethodHooks } from './manageState';\nimport { manageStateBuilder } from './manageState';\nimport type { NotifyMethodHooks } from './notify';\nimport { notifyBuilder } from './notify';\n\nexport { WALLET_SNAP_PERMISSION_KEY } from './invokeSnap';\nexport { getEncryptionEntropy } from './manageState';\n\nexport type RestrictedMethodHooks = DialogMethodHooks &\n GetBip32EntropyMethodHooks &\n GetBip32PublicKeyMethodHooks &\n GetBip44EntropyMethodHooks &\n GetEntropyHooks &\n InvokeSnapMethodHooks &\n ManageStateMethodHooks &\n NotifyMethodHooks &\n ManageAccountsMethodHooks &\n GetLocaleMethodHooks;\n\nexport const restrictedMethodPermissionBuilders = {\n [dialogBuilder.targetName]: dialogBuilder,\n [getBip32EntropyBuilder.targetName]: getBip32EntropyBuilder,\n [getBip32PublicKeyBuilder.targetName]: getBip32PublicKeyBuilder,\n [getBip44EntropyBuilder.targetName]: getBip44EntropyBuilder,\n [getEntropyBuilder.targetName]: getEntropyBuilder,\n [invokeSnapBuilder.targetName]: invokeSnapBuilder,\n [manageStateBuilder.targetName]: manageStateBuilder,\n [notifyBuilder.targetName]: notifyBuilder,\n [manageAccountsBuilder.targetName]: manageAccountsBuilder,\n [getLocaleBuilder.targetName]: getLocaleBuilder,\n} as const;\n\nexport * from './caveats';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCO,IAAM,qCAAqC;AAAA,EAChD,CAAC,cAAc,UAAU,GAAG;AAAA,EAC5B,CAAC,uBAAuB,UAAU,GAAG;AAAA,EACrC,CAAC,yBAAyB,UAAU,GAAG;AAAA,EACvC,CAAC,uBAAuB,UAAU,GAAG;AAAA,EACrC,CAAC,kBAAkB,UAAU,GAAG;AAAA,EAChC,CAAC,kBAAkB,UAAU,GAAG;AAAA,EAChC,CAAC,mBAAmB,UAAU,GAAG;AAAA,EACjC,CAAC,cAAc,UAAU,GAAG;AAAA,EAC5B,CAAC,sBAAsB,UAAU,GAAG;AAAA,EACpC,CAAC,iBAAiB,UAAU,GAAG;AACjC;","names":[]}
|
|
@@ -23,13 +23,10 @@ var specificationBuilder = ({
|
|
|
23
23
|
};
|
|
24
24
|
};
|
|
25
25
|
var methodHooks = {
|
|
26
|
-
getMnemonic: true,
|
|
27
26
|
getUnlockPromise: true,
|
|
28
27
|
clearSnapState: true,
|
|
29
28
|
getSnapState: true,
|
|
30
|
-
updateSnapState: true
|
|
31
|
-
encrypt: true,
|
|
32
|
-
decrypt: true
|
|
29
|
+
updateSnapState: true
|
|
33
30
|
};
|
|
34
31
|
var manageStateBuilder = Object.freeze({
|
|
35
32
|
targetName: methodName,
|
|
@@ -37,7 +34,7 @@ var manageStateBuilder = Object.freeze({
|
|
|
37
34
|
methodHooks
|
|
38
35
|
});
|
|
39
36
|
var STORAGE_SIZE_LIMIT = 104857600;
|
|
40
|
-
async function
|
|
37
|
+
async function getEncryptionEntropy({
|
|
41
38
|
mnemonicPhrase,
|
|
42
39
|
snapId
|
|
43
40
|
}) {
|
|
@@ -48,38 +45,11 @@ async function getEncryptionKey({
|
|
|
48
45
|
magic: _snapsutils.STATE_ENCRYPTION_MAGIC_VALUE
|
|
49
46
|
});
|
|
50
47
|
}
|
|
51
|
-
async function encryptState({
|
|
52
|
-
state,
|
|
53
|
-
encryptFunction,
|
|
54
|
-
...keyArgs
|
|
55
|
-
}) {
|
|
56
|
-
const encryptionKey = await getEncryptionKey(keyArgs);
|
|
57
|
-
return await encryptFunction(encryptionKey, state);
|
|
58
|
-
}
|
|
59
|
-
async function decryptState({
|
|
60
|
-
state,
|
|
61
|
-
decryptFunction,
|
|
62
|
-
...keyArgs
|
|
63
|
-
}) {
|
|
64
|
-
try {
|
|
65
|
-
const encryptionKey = await getEncryptionKey(keyArgs);
|
|
66
|
-
const decryptedState = await decryptFunction(encryptionKey, state);
|
|
67
|
-
_utils.assert.call(void 0, _utils.isValidJson.call(void 0, decryptedState));
|
|
68
|
-
return decryptedState;
|
|
69
|
-
} catch {
|
|
70
|
-
throw _rpcerrors.rpcErrors.internal({
|
|
71
|
-
message: "Failed to decrypt snap state, the state must be corrupted."
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
48
|
function getManageStateImplementation({
|
|
76
|
-
getMnemonic,
|
|
77
49
|
getUnlockPromise,
|
|
78
50
|
clearSnapState,
|
|
79
51
|
getSnapState,
|
|
80
|
-
updateSnapState
|
|
81
|
-
encrypt,
|
|
82
|
-
decrypt
|
|
52
|
+
updateSnapState
|
|
83
53
|
}) {
|
|
84
54
|
return async function manageState(options) {
|
|
85
55
|
const {
|
|
@@ -97,25 +67,10 @@ function getManageStateImplementation({
|
|
|
97
67
|
clearSnapState(origin, shouldEncrypt);
|
|
98
68
|
return null;
|
|
99
69
|
case _snapssdk.ManageStateOperation.GetState: {
|
|
100
|
-
|
|
101
|
-
if (state === null) {
|
|
102
|
-
return state;
|
|
103
|
-
}
|
|
104
|
-
return shouldEncrypt ? await decryptState({
|
|
105
|
-
state,
|
|
106
|
-
decryptFunction: decrypt,
|
|
107
|
-
mnemonicPhrase: await getMnemonic(),
|
|
108
|
-
snapId: origin
|
|
109
|
-
}) : _snapsutils.parseJson.call(void 0, state);
|
|
70
|
+
return await getSnapState(origin, shouldEncrypt);
|
|
110
71
|
}
|
|
111
72
|
case _snapssdk.ManageStateOperation.UpdateState: {
|
|
112
|
-
|
|
113
|
-
state: validatedParams.newState,
|
|
114
|
-
encryptFunction: encrypt,
|
|
115
|
-
mnemonicPhrase: await getMnemonic(),
|
|
116
|
-
snapId: origin
|
|
117
|
-
}) : JSON.stringify(validatedParams.newState);
|
|
118
|
-
updateSnapState(origin, finalizedState, shouldEncrypt);
|
|
73
|
+
await updateSnapState(origin, validatedParams.newState, shouldEncrypt);
|
|
119
74
|
return null;
|
|
120
75
|
}
|
|
121
76
|
default:
|
|
@@ -184,5 +139,5 @@ function getValidatedParams(params, method, storageSizeLimit = STORAGE_SIZE_LIMI
|
|
|
184
139
|
|
|
185
140
|
|
|
186
141
|
|
|
187
|
-
exports.STATE_ENCRYPTION_SALT = STATE_ENCRYPTION_SALT; exports.specificationBuilder = specificationBuilder; exports.manageStateBuilder = manageStateBuilder; exports.STORAGE_SIZE_LIMIT = STORAGE_SIZE_LIMIT; exports.
|
|
188
|
-
//# sourceMappingURL=chunk-
|
|
142
|
+
exports.STATE_ENCRYPTION_SALT = STATE_ENCRYPTION_SALT; exports.specificationBuilder = specificationBuilder; exports.manageStateBuilder = manageStateBuilder; exports.STORAGE_SIZE_LIMIT = STORAGE_SIZE_LIMIT; exports.getEncryptionEntropy = getEncryptionEntropy; exports.getManageStateImplementation = getManageStateImplementation; exports.getValidatedParams = getValidatedParams;
|
|
143
|
+
//# sourceMappingURL=chunk-R2M4YLJ7.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/restricted/manageState.ts"],"names":["methodHooks"],"mappings":"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","sourcesContent":["import type {\n PermissionSpecificationBuilder,\n RestrictedMethodOptions,\n ValidPermissionSpecification,\n} from '@metamask/permission-controller';\nimport { PermissionType, SubjectType } from '@metamask/permission-controller';\nimport { rpcErrors } from '@metamask/rpc-errors';\nimport type { ManageStateParams, ManageStateResult } from '@metamask/snaps-sdk';\nimport { ManageStateOperation } from '@metamask/snaps-sdk';\nimport { STATE_ENCRYPTION_MAGIC_VALUE } from '@metamask/snaps-utils';\nimport type { Json, NonEmptyArray } from '@metamask/utils';\nimport { isObject, getJsonSize } from '@metamask/utils';\n\nimport type { MethodHooksObject } from '../utils';\nimport { deriveEntropy } from '../utils';\n\n// The salt used for SIP-6-based entropy derivation.\nexport const STATE_ENCRYPTION_SALT = 'snap_manageState encryption';\n\nconst methodName = 'snap_manageState';\n\nexport type ManageStateMethodHooks = {\n /**\n * Waits for the extension to be unlocked.\n *\n * @returns A promise that resolves once the extension is unlocked.\n */\n getUnlockPromise: (shouldShowUnlockRequest: boolean) => Promise<void>;\n\n /**\n * A function that clears the state of the requesting Snap.\n */\n clearSnapState: (snapId: string, encrypted: boolean) => void;\n\n /**\n * A function that gets the encrypted state of the requesting Snap.\n *\n * @returns The current state of the Snap.\n */\n getSnapState: (\n snapId: string,\n encrypted: boolean,\n ) => Promise<Record<string, Json>>;\n\n /**\n * A function that updates the state of the requesting Snap.\n *\n * @param newState - The new state of the Snap.\n */\n updateSnapState: (\n snapId: string,\n newState: Record<string, Json>,\n encrypted: boolean,\n ) => Promise<void>;\n};\n\ntype ManageStateSpecificationBuilderOptions = {\n allowedCaveats?: Readonly<NonEmptyArray<string>> | null;\n methodHooks: ManageStateMethodHooks;\n};\n\ntype ManageStateSpecification = ValidPermissionSpecification<{\n permissionType: PermissionType.RestrictedMethod;\n targetName: typeof methodName;\n methodImplementation: ReturnType<typeof getManageStateImplementation>;\n allowedCaveats: Readonly<NonEmptyArray<string>> | null;\n}>;\n\n/**\n * The specification builder for the `snap_manageState` permission.\n * `snap_manageState` lets the Snap store and manage some of its state on\n * your device.\n *\n * @param options - The specification builder options.\n * @param options.allowedCaveats - The optional allowed caveats for the permission.\n * @param options.methodHooks - The RPC method hooks needed by the method implementation.\n * @returns The specification for the `snap_manageState` permission.\n */\nexport const specificationBuilder: PermissionSpecificationBuilder<\n PermissionType.RestrictedMethod,\n ManageStateSpecificationBuilderOptions,\n ManageStateSpecification\n> = ({\n allowedCaveats = null,\n methodHooks,\n}: ManageStateSpecificationBuilderOptions) => {\n return {\n permissionType: PermissionType.RestrictedMethod,\n targetName: methodName,\n allowedCaveats,\n methodImplementation: getManageStateImplementation(methodHooks),\n subjectTypes: [SubjectType.Snap],\n };\n};\n\nconst methodHooks: MethodHooksObject<ManageStateMethodHooks> = {\n getUnlockPromise: true,\n clearSnapState: true,\n getSnapState: true,\n updateSnapState: true,\n};\n\nexport const manageStateBuilder = Object.freeze({\n targetName: methodName,\n specificationBuilder,\n methodHooks,\n} as const);\n\nexport const STORAGE_SIZE_LIMIT = 104857600; // In bytes (100MB)\n\ntype GetEncryptionKeyArgs = {\n snapId: string;\n mnemonicPhrase: Uint8Array;\n};\n\n/**\n * Get a deterministic encryption key to use for encrypting and decrypting the\n * state.\n *\n * This key should only be used for state encryption using `snap_manageState`.\n * To get other encryption keys, a different salt can be used.\n *\n * @param args - The encryption key args.\n * @param args.snapId - The ID of the snap to get the encryption key for.\n * @param args.mnemonicPhrase - The mnemonic phrase to derive the encryption key\n * from.\n * @returns The state encryption key.\n */\nexport async function getEncryptionEntropy({\n mnemonicPhrase,\n snapId,\n}: GetEncryptionKeyArgs) {\n return await deriveEntropy({\n mnemonicPhrase,\n input: snapId,\n salt: STATE_ENCRYPTION_SALT,\n magic: STATE_ENCRYPTION_MAGIC_VALUE,\n });\n}\n\n/**\n * Builds the method implementation for `snap_manageState`.\n *\n * @param hooks - The RPC method hooks.\n * @param hooks.clearSnapState - A function that clears the state stored for a\n * snap.\n * @param hooks.getSnapState - A function that fetches the persisted decrypted\n * state for a snap.\n * @param hooks.updateSnapState - A function that updates the state stored for a\n * snap.\n * @param hooks.getUnlockPromise - A function that resolves once the MetaMask\n * extension is unlocked and prompts the user to unlock their MetaMask if it is\n * locked.\n * @returns The method implementation which either returns `null` for a\n * successful state update/deletion or returns the decrypted state.\n * @throws If the params are invalid.\n */\nexport function getManageStateImplementation({\n getUnlockPromise,\n clearSnapState,\n getSnapState,\n updateSnapState,\n}: ManageStateMethodHooks) {\n return async function manageState(\n options: RestrictedMethodOptions<ManageStateParams>,\n ): Promise<ManageStateResult> {\n const {\n params = {},\n method,\n context: { origin },\n } = options;\n const validatedParams = getValidatedParams(params, method);\n\n // If the encrypted param is undefined or null we default to true.\n const shouldEncrypt = validatedParams.encrypted ?? true;\n\n // We only need to prompt the user when the mnemonic is needed\n // which it isn't for the clear operation or unencrypted storage.\n if (\n shouldEncrypt &&\n validatedParams.operation !== ManageStateOperation.ClearState\n ) {\n await getUnlockPromise(true);\n }\n\n switch (validatedParams.operation) {\n case ManageStateOperation.ClearState:\n clearSnapState(origin, shouldEncrypt);\n return null;\n\n case ManageStateOperation.GetState: {\n return await getSnapState(origin, shouldEncrypt);\n }\n\n case ManageStateOperation.UpdateState: {\n await updateSnapState(origin, validatedParams.newState, shouldEncrypt);\n return null;\n }\n\n default:\n throw rpcErrors.invalidParams(\n `Invalid ${method} operation: \"${\n validatedParams.operation as string\n }\"`,\n );\n }\n };\n}\n\n/**\n * Validates the manageState 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 * @param method - RPC method name used for debugging errors.\n * @param storageSizeLimit - Maximum allowed size (in bytes) of a new state object.\n * @returns The validated method parameter object.\n */\nexport function getValidatedParams(\n params: unknown,\n method: string,\n storageSizeLimit = STORAGE_SIZE_LIMIT,\n): ManageStateParams {\n if (!isObject(params)) {\n throw rpcErrors.invalidParams({\n message: 'Expected params to be a single object.',\n });\n }\n\n const { operation, newState, encrypted } = params;\n\n if (\n !operation ||\n typeof operation !== 'string' ||\n !Object.values(ManageStateOperation).includes(\n operation as ManageStateOperation,\n )\n ) {\n throw rpcErrors.invalidParams({\n message: 'Must specify a valid manage state \"operation\".',\n });\n }\n\n if (encrypted !== undefined && typeof encrypted !== 'boolean') {\n throw rpcErrors.invalidParams({\n message: '\"encrypted\" parameter must be a boolean if specified.',\n });\n }\n\n if (operation === ManageStateOperation.UpdateState) {\n if (!isObject(newState)) {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"updateState\" parameter: The new state must be a plain object.`,\n data: {\n receivedNewState:\n typeof newState === 'undefined' ? 'undefined' : newState,\n },\n });\n }\n\n let size;\n try {\n // `getJsonSize` will throw if the state is not JSON serializable.\n size = getJsonSize(newState);\n } catch {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"updateState\" parameter: The new state must be JSON serializable.`,\n data: {\n receivedNewState:\n typeof newState === 'undefined' ? 'undefined' : newState,\n },\n });\n }\n\n if (size > storageSizeLimit) {\n throw rpcErrors.invalidParams({\n message: `Invalid ${method} \"updateState\" parameter: The new state must not exceed ${storageSizeLimit} bytes in size.`,\n data: {\n receivedNewState:\n typeof newState === 'undefined' ? 'undefined' : newState,\n },\n });\n }\n }\n\n return params as ManageStateParams;\n}\n"]}
|
|
@@ -12,13 +12,13 @@ var _chunkSYUGPLEPjs = require('./chunk-SYUGPLEP.js');
|
|
|
12
12
|
var _chunkP74WXDY4js = require('./chunk-P74WXDY4.js');
|
|
13
13
|
|
|
14
14
|
|
|
15
|
-
var
|
|
15
|
+
var _chunkR2M4YLJ7js = require('./chunk-R2M4YLJ7.js');
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
var _chunkQDZAWH6Fjs = require('./chunk-QDZAWH6F.js');
|
|
19
19
|
|
|
20
20
|
|
|
21
|
-
var
|
|
21
|
+
var _chunkI7DR6BFOjs = require('./chunk-I7DR6BFO.js');
|
|
22
22
|
|
|
23
23
|
|
|
24
24
|
var _chunkS7AR3ROHjs = require('./chunk-S7AR3ROH.js');
|
|
@@ -31,13 +31,13 @@ var _chunkFFHVA6PPjs = require('./chunk-FFHVA6PP.js');
|
|
|
31
31
|
|
|
32
32
|
// src/restricted/index.ts
|
|
33
33
|
var restrictedMethodPermissionBuilders = {
|
|
34
|
-
[
|
|
34
|
+
[_chunkI7DR6BFOjs.dialogBuilder.targetName]: _chunkI7DR6BFOjs.dialogBuilder,
|
|
35
35
|
[_chunkS7AR3ROHjs.getBip32EntropyBuilder.targetName]: _chunkS7AR3ROHjs.getBip32EntropyBuilder,
|
|
36
36
|
[_chunkLGUJMQC7js.getBip32PublicKeyBuilder.targetName]: _chunkLGUJMQC7js.getBip32PublicKeyBuilder,
|
|
37
37
|
[_chunkVUA6ICJOjs.getBip44EntropyBuilder.targetName]: _chunkVUA6ICJOjs.getBip44EntropyBuilder,
|
|
38
38
|
[_chunkQ5W3YGEBjs.getEntropyBuilder.targetName]: _chunkQ5W3YGEBjs.getEntropyBuilder,
|
|
39
39
|
[_chunkFFHVA6PPjs.invokeSnapBuilder.targetName]: _chunkFFHVA6PPjs.invokeSnapBuilder,
|
|
40
|
-
[
|
|
40
|
+
[_chunkR2M4YLJ7js.manageStateBuilder.targetName]: _chunkR2M4YLJ7js.manageStateBuilder,
|
|
41
41
|
[_chunkQDZAWH6Fjs.notifyBuilder.targetName]: _chunkQDZAWH6Fjs.notifyBuilder,
|
|
42
42
|
[_chunkP74WXDY4js.manageAccountsBuilder.targetName]: _chunkP74WXDY4js.manageAccountsBuilder,
|
|
43
43
|
[_chunkSYUGPLEPjs.getLocaleBuilder.targetName]: _chunkSYUGPLEPjs.getLocaleBuilder
|
|
@@ -46,4 +46,4 @@ var restrictedMethodPermissionBuilders = {
|
|
|
46
46
|
|
|
47
47
|
|
|
48
48
|
exports.restrictedMethodPermissionBuilders = restrictedMethodPermissionBuilders;
|
|
49
|
-
//# sourceMappingURL=chunk-
|
|
49
|
+
//# sourceMappingURL=chunk-RIALLTR7.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/restricted/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCO,IAAM,qCAAqC;AAAA,EAChD,CAAC,cAAc,UAAU,GAAG;AAAA,EAC5B,CAAC,uBAAuB,UAAU,GAAG;AAAA,EACrC,CAAC,yBAAyB,UAAU,GAAG;AAAA,EACvC,CAAC,uBAAuB,UAAU,GAAG;AAAA,EACrC,CAAC,kBAAkB,UAAU,GAAG;AAAA,EAChC,CAAC,kBAAkB,UAAU,GAAG;AAAA,EAChC,CAAC,mBAAmB,UAAU,GAAG;AAAA,EACjC,CAAC,cAAc,UAAU,GAAG;AAAA,EAC5B,CAAC,sBAAsB,UAAU,GAAG;AAAA,EACpC,CAAC,iBAAiB,UAAU,GAAG;AACjC","sourcesContent":["import type { DialogMethodHooks } from './dialog';\nimport { dialogBuilder } from './dialog';\nimport type { GetBip32EntropyMethodHooks } from './getBip32Entropy';\nimport { getBip32EntropyBuilder } from './getBip32Entropy';\nimport type { GetBip32PublicKeyMethodHooks } from './getBip32PublicKey';\nimport { getBip32PublicKeyBuilder } from './getBip32PublicKey';\nimport type { GetBip44EntropyMethodHooks } from './getBip44Entropy';\nimport { getBip44EntropyBuilder } from './getBip44Entropy';\nimport type { GetEntropyHooks } from './getEntropy';\nimport { getEntropyBuilder } from './getEntropy';\nimport type { GetLocaleMethodHooks } from './getLocale';\nimport { getLocaleBuilder } from './getLocale';\nimport type { InvokeSnapMethodHooks } from './invokeSnap';\nimport { invokeSnapBuilder } from './invokeSnap';\nimport type { ManageAccountsMethodHooks } from './manageAccounts';\nimport { manageAccountsBuilder } from './manageAccounts';\nimport type { ManageStateMethodHooks } from './manageState';\nimport { manageStateBuilder } from './manageState';\nimport type { NotifyMethodHooks } from './notify';\nimport { notifyBuilder } from './notify';\n\nexport { WALLET_SNAP_PERMISSION_KEY } from './invokeSnap';\nexport {
|
|
1
|
+
{"version":3,"sources":["../src/restricted/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmCO,IAAM,qCAAqC;AAAA,EAChD,CAAC,cAAc,UAAU,GAAG;AAAA,EAC5B,CAAC,uBAAuB,UAAU,GAAG;AAAA,EACrC,CAAC,yBAAyB,UAAU,GAAG;AAAA,EACvC,CAAC,uBAAuB,UAAU,GAAG;AAAA,EACrC,CAAC,kBAAkB,UAAU,GAAG;AAAA,EAChC,CAAC,kBAAkB,UAAU,GAAG;AAAA,EAChC,CAAC,mBAAmB,UAAU,GAAG;AAAA,EACjC,CAAC,cAAc,UAAU,GAAG;AAAA,EAC5B,CAAC,sBAAsB,UAAU,GAAG;AAAA,EACpC,CAAC,iBAAiB,UAAU,GAAG;AACjC","sourcesContent":["import type { DialogMethodHooks } from './dialog';\nimport { dialogBuilder } from './dialog';\nimport type { GetBip32EntropyMethodHooks } from './getBip32Entropy';\nimport { getBip32EntropyBuilder } from './getBip32Entropy';\nimport type { GetBip32PublicKeyMethodHooks } from './getBip32PublicKey';\nimport { getBip32PublicKeyBuilder } from './getBip32PublicKey';\nimport type { GetBip44EntropyMethodHooks } from './getBip44Entropy';\nimport { getBip44EntropyBuilder } from './getBip44Entropy';\nimport type { GetEntropyHooks } from './getEntropy';\nimport { getEntropyBuilder } from './getEntropy';\nimport type { GetLocaleMethodHooks } from './getLocale';\nimport { getLocaleBuilder } from './getLocale';\nimport type { InvokeSnapMethodHooks } from './invokeSnap';\nimport { invokeSnapBuilder } from './invokeSnap';\nimport type { ManageAccountsMethodHooks } from './manageAccounts';\nimport { manageAccountsBuilder } from './manageAccounts';\nimport type { ManageStateMethodHooks } from './manageState';\nimport { manageStateBuilder } from './manageState';\nimport type { NotifyMethodHooks } from './notify';\nimport { notifyBuilder } from './notify';\n\nexport { WALLET_SNAP_PERMISSION_KEY } from './invokeSnap';\nexport { getEncryptionEntropy } from './manageState';\n\nexport type RestrictedMethodHooks = DialogMethodHooks &\n GetBip32EntropyMethodHooks &\n GetBip32PublicKeyMethodHooks &\n GetBip44EntropyMethodHooks &\n GetEntropyHooks &\n InvokeSnapMethodHooks &\n ManageStateMethodHooks &\n NotifyMethodHooks &\n ManageAccountsMethodHooks &\n GetLocaleMethodHooks;\n\nexport const restrictedMethodPermissionBuilders = {\n [dialogBuilder.targetName]: dialogBuilder,\n [getBip32EntropyBuilder.targetName]: getBip32EntropyBuilder,\n [getBip32PublicKeyBuilder.targetName]: getBip32PublicKeyBuilder,\n [getBip44EntropyBuilder.targetName]: getBip44EntropyBuilder,\n [getEntropyBuilder.targetName]: getEntropyBuilder,\n [invokeSnapBuilder.targetName]: invokeSnapBuilder,\n [manageStateBuilder.targetName]: manageStateBuilder,\n [notifyBuilder.targetName]: notifyBuilder,\n [manageAccountsBuilder.targetName]: manageAccountsBuilder,\n [getLocaleBuilder.targetName]: getLocaleBuilder,\n} as const;\n\nexport * from './caveats';\n"]}
|