@metamask/snaps-controllers 8.4.0 → 9.0.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 +11 -1
- package/dist/{chunk-YIQM6ZKA.mjs → chunk-4M2FX2AT.mjs} +9 -2
- package/dist/{chunk-YIQM6ZKA.mjs.map → chunk-4M2FX2AT.mjs.map} +1 -1
- package/dist/chunk-6ERB63FH.js +58 -0
- package/dist/chunk-6ERB63FH.js.map +1 -0
- package/dist/{chunk-LLA2BJYO.js → chunk-6VGMRXGY.js} +7 -7
- package/dist/{chunk-VSDMYMJK.mjs → chunk-7CZDBXIY.mjs} +2 -2
- package/dist/chunk-7CZDBXIY.mjs.map +1 -0
- package/dist/chunk-CIFVYFJW.mjs +58 -0
- package/dist/chunk-CIFVYFJW.mjs.map +1 -0
- package/dist/{chunk-5YBORD3A.js → chunk-JQ54YYLU.js} +9 -2
- package/dist/chunk-JQ54YYLU.js.map +1 -0
- package/dist/{chunk-TSPPQQHW.mjs → chunk-RVWBSSZM.mjs} +7 -4
- package/dist/chunk-RVWBSSZM.mjs.map +1 -0
- package/dist/{chunk-TII2PO6O.js → chunk-WCDDYBFW.js} +2 -2
- package/dist/chunk-WCDDYBFW.js.map +1 -0
- package/dist/{chunk-TMJA2PSY.mjs → chunk-YAZ55WUL.mjs} +2 -2
- package/dist/{chunk-IKD6PUV7.js → chunk-ZBSBCWWM.js} +7 -4
- package/dist/chunk-ZBSBCWWM.js.map +1 -0
- package/dist/cronjob/CronjobController.js +5 -5
- package/dist/cronjob/CronjobController.mjs +5 -5
- package/dist/cronjob/index.js +5 -5
- package/dist/cronjob/index.mjs +5 -5
- package/dist/index.js +6 -6
- package/dist/index.mjs +5 -5
- package/dist/interface/SnapInterfaceController.js +3 -3
- package/dist/interface/SnapInterfaceController.mjs +2 -2
- package/dist/interface/index.js +3 -3
- package/dist/interface/index.mjs +2 -2
- package/dist/interface/utils.js +2 -2
- package/dist/interface/utils.mjs +1 -1
- package/dist/node.js +6 -6
- package/dist/node.mjs +5 -5
- package/dist/react-native.js +6 -6
- package/dist/react-native.mjs +5 -5
- package/dist/services/browser.js +2 -2
- package/dist/services/browser.mjs +1 -1
- package/dist/services/index.js +2 -2
- package/dist/services/index.mjs +1 -1
- package/dist/services/node-js/NodeProcessExecutionService.js +1 -1
- package/dist/services/node-js/NodeProcessExecutionService.mjs +1 -1
- package/dist/services/node-js/NodeThreadExecutionService.js +1 -1
- package/dist/services/node-js/NodeThreadExecutionService.mjs +1 -1
- package/dist/services/node-js/index.js +1 -1
- package/dist/services/node-js/index.mjs +1 -1
- package/dist/services/node.js +2 -2
- package/dist/services/node.mjs +1 -1
- package/dist/services/offscreen/OffscreenExecutionService.js +2 -2
- package/dist/services/offscreen/OffscreenExecutionService.mjs +1 -1
- package/dist/services/offscreen/index.js +2 -2
- package/dist/services/offscreen/index.mjs +1 -1
- package/dist/services/react-native.js +2 -2
- package/dist/services/react-native.mjs +1 -1
- package/dist/snaps/SnapController.js +3 -3
- package/dist/snaps/SnapController.mjs +2 -2
- package/dist/snaps/constants.js +4 -2
- package/dist/snaps/constants.mjs +5 -3
- package/dist/snaps/index.js +3 -3
- package/dist/snaps/index.mjs +2 -2
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/services/offscreen/OffscreenExecutionService.d.ts +8 -9
- package/dist/types/snaps/constants.d.ts +6 -0
- package/package.json +11 -11
- package/dist/chunk-3OJFF5CK.mjs +0 -72
- package/dist/chunk-3OJFF5CK.mjs.map +0 -1
- package/dist/chunk-5YBORD3A.js.map +0 -1
- package/dist/chunk-HK4OAMJT.js +0 -72
- package/dist/chunk-HK4OAMJT.js.map +0 -1
- package/dist/chunk-IKD6PUV7.js.map +0 -1
- package/dist/chunk-TII2PO6O.js.map +0 -1
- package/dist/chunk-TSPPQQHW.mjs.map +0 -1
- package/dist/chunk-VSDMYMJK.mjs.map +0 -1
- /package/dist/{chunk-LLA2BJYO.js.map → chunk-6VGMRXGY.js.map} +0 -0
- /package/dist/{chunk-TMJA2PSY.mjs.map → chunk-YAZ55WUL.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
|
+
## [9.0.0]
|
|
10
|
+
### Changed
|
|
11
|
+
- **BREAKING:** Defer creation of offscreen document in `OffscreenExecutionService` ([#2473](https://github.com/MetaMask/snaps/pull/2473))
|
|
12
|
+
- Update `onNameLookup` response to include `domainName` ([#2484](https://github.com/MetaMask/snaps/pull/2484))
|
|
13
|
+
- Bump MetaMask dependencies ([#2460](https://github.com/MetaMask/snaps/pull/2460))
|
|
14
|
+
|
|
15
|
+
### Fixed
|
|
16
|
+
- Properly decrypt legacy state blobs ([#2472](https://github.com/MetaMask/snaps/pull/2472))
|
|
17
|
+
|
|
9
18
|
## [8.4.0]
|
|
10
19
|
### Added
|
|
11
20
|
- Add `hidden` flag for preinstalled Snaps ([#2463](https://github.com/MetaMask/snaps/pull/2463))
|
|
@@ -288,7 +297,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
288
297
|
- The version of the package no longer needs to match the version of all other
|
|
289
298
|
MetaMask Snaps packages.
|
|
290
299
|
|
|
291
|
-
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@
|
|
300
|
+
[Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@9.0.0...HEAD
|
|
301
|
+
[9.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.4.0...@metamask/snaps-controllers@9.0.0
|
|
292
302
|
[8.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.3.1...@metamask/snaps-controllers@8.4.0
|
|
293
303
|
[8.3.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.3.0...@metamask/snaps-controllers@8.3.1
|
|
294
304
|
[8.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.2.0...@metamask/snaps-controllers@8.3.0
|
|
@@ -12,8 +12,15 @@ var ALLOWED_PERMISSIONS = Object.freeze([
|
|
|
12
12
|
SnapEndowments.TransactionInsight,
|
|
13
13
|
SnapEndowments.SignatureInsight
|
|
14
14
|
]);
|
|
15
|
+
var LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS = {
|
|
16
|
+
algorithm: "PBKDF2",
|
|
17
|
+
params: {
|
|
18
|
+
iterations: 1e4
|
|
19
|
+
}
|
|
20
|
+
};
|
|
15
21
|
|
|
16
22
|
export {
|
|
17
|
-
ALLOWED_PERMISSIONS
|
|
23
|
+
ALLOWED_PERMISSIONS,
|
|
24
|
+
LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS
|
|
18
25
|
};
|
|
19
|
-
//# sourceMappingURL=chunk-
|
|
26
|
+
//# sourceMappingURL=chunk-4M2FX2AT.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/snaps/constants.ts"],"sourcesContent":["import { SnapEndowments } from '@metamask/snaps-rpc-methods';\n\n// These permissions are allowed without being on the allowlist.\nexport const ALLOWED_PERMISSIONS = Object.freeze([\n 'snap_dialog',\n 'snap_manageState',\n 'snap_notify',\n 'snap_getLocale',\n SnapEndowments.Cronjob,\n SnapEndowments.HomePage,\n SnapEndowments.LifecycleHooks,\n SnapEndowments.EthereumProvider,\n SnapEndowments.TransactionInsight,\n SnapEndowments.SignatureInsight,\n]);\n"],"mappings":";AAAA,SAAS,sBAAsB;AAGxB,IAAM,sBAAsB,OAAO,OAAO;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AACjB,CAAC;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/snaps/constants.ts"],"sourcesContent":["import { SnapEndowments } from '@metamask/snaps-rpc-methods';\n\n// These permissions are allowed without being on the allowlist.\nexport const ALLOWED_PERMISSIONS = Object.freeze([\n 'snap_dialog',\n 'snap_manageState',\n 'snap_notify',\n 'snap_getLocale',\n SnapEndowments.Cronjob,\n SnapEndowments.HomePage,\n SnapEndowments.LifecycleHooks,\n SnapEndowments.EthereumProvider,\n SnapEndowments.TransactionInsight,\n SnapEndowments.SignatureInsight,\n]);\n\nexport const LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS = {\n algorithm: 'PBKDF2' as const,\n params: {\n iterations: 10_000,\n },\n};\n"],"mappings":";AAAA,SAAS,sBAAsB;AAGxB,IAAM,sBAAsB,OAAO,OAAO;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AACjB,CAAC;AAEM,IAAM,2CAA2C;AAAA,EACtD,WAAW;AAAA,EACX,QAAQ;AAAA,IACN,YAAY;AAAA,EACd;AACF;","names":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
var _chunkKH72WRHRjs = require('./chunk-KH72WRHR.js');
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
var _chunkEXN2TFDJjs = require('./chunk-EXN2TFDJ.js');
|
|
9
|
+
|
|
10
|
+
// src/services/offscreen/OffscreenExecutionService.ts
|
|
11
|
+
var _postmessagestream = require('@metamask/post-message-stream');
|
|
12
|
+
var _offscreenPromise;
|
|
13
|
+
var OffscreenExecutionService = class extends _chunkKH72WRHRjs.ProxyExecutionService {
|
|
14
|
+
/**
|
|
15
|
+
* Create a new offscreen execution service.
|
|
16
|
+
*
|
|
17
|
+
* @param args - The constructor arguments.
|
|
18
|
+
* @param args.messenger - The messenger to use for communication with the
|
|
19
|
+
* `SnapController`.
|
|
20
|
+
* @param args.setupSnapProvider - The function to use to set up the snap
|
|
21
|
+
* provider.
|
|
22
|
+
* @param args.offscreenPromise - A promise that resolves when the offscreen
|
|
23
|
+
* environment is ready.
|
|
24
|
+
*/
|
|
25
|
+
constructor({
|
|
26
|
+
messenger,
|
|
27
|
+
setupSnapProvider,
|
|
28
|
+
offscreenPromise
|
|
29
|
+
}) {
|
|
30
|
+
super({
|
|
31
|
+
messenger,
|
|
32
|
+
setupSnapProvider,
|
|
33
|
+
stream: new (0, _postmessagestream.BrowserRuntimePostMessageStream)({
|
|
34
|
+
name: "parent",
|
|
35
|
+
target: "child"
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
_chunkEXN2TFDJjs.__privateAdd.call(void 0, this, _offscreenPromise, void 0);
|
|
39
|
+
_chunkEXN2TFDJjs.__privateSet.call(void 0, this, _offscreenPromise, offscreenPromise);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a new stream for the given job ID. This will wait for the offscreen
|
|
43
|
+
* environment to be ready before creating the stream.
|
|
44
|
+
*
|
|
45
|
+
* @param jobId - The job ID to create a stream for.
|
|
46
|
+
* @returns The stream for the given job ID.
|
|
47
|
+
*/
|
|
48
|
+
async initEnvStream(jobId) {
|
|
49
|
+
await _chunkEXN2TFDJjs.__privateGet.call(void 0, this, _offscreenPromise);
|
|
50
|
+
return await super.initEnvStream(jobId);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
_offscreenPromise = new WeakMap();
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
exports.OffscreenExecutionService = OffscreenExecutionService;
|
|
58
|
+
//# sourceMappingURL=chunk-6ERB63FH.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/offscreen/OffscreenExecutionService.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,SAAS,uCAAuC;AAAhD;AASO,IAAM,4BAAN,cAAwC,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcnE,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAA6C;AAC3C,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,QAAQ,IAAI,gCAAgC;AAAA,QAC1C,MAAM;AAAA,QACN,QAAQ;AAAA,MACV,CAAC;AAAA,IACH,CAAC;AAzBH,uBAAS,mBAAT;AA2BE,uBAAK,mBAAoB;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAgB,cAAc,OAAe;AAC3C,UAAM,mBAAK;AAEX,WAAO,MAAM,MAAM,cAAc,KAAK;AAAA,EACxC;AACF;AA1CW","sourcesContent":["import { BrowserRuntimePostMessageStream } from '@metamask/post-message-stream';\n\nimport type { ExecutionServiceArgs } from '../AbstractExecutionService';\nimport { ProxyExecutionService } from '../proxy/ProxyExecutionService';\n\ntype OffscreenExecutionEnvironmentServiceArgs = {\n offscreenPromise: Promise<unknown>;\n} & ExecutionServiceArgs;\n\nexport class OffscreenExecutionService extends ProxyExecutionService {\n readonly #offscreenPromise: Promise<unknown>;\n\n /**\n * Create a new offscreen execution service.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger to use for communication with the\n * `SnapController`.\n * @param args.setupSnapProvider - The function to use to set up the snap\n * provider.\n * @param args.offscreenPromise - A promise that resolves when the offscreen\n * environment is ready.\n */\n constructor({\n messenger,\n setupSnapProvider,\n offscreenPromise,\n }: OffscreenExecutionEnvironmentServiceArgs) {\n super({\n messenger,\n setupSnapProvider,\n stream: new BrowserRuntimePostMessageStream({\n name: 'parent',\n target: 'child',\n }),\n });\n\n this.#offscreenPromise = offscreenPromise;\n }\n\n /**\n * Create a new stream for the given job ID. This will wait for the offscreen\n * environment to be ready before creating the stream.\n *\n * @param jobId - The job ID to create a stream for.\n * @returns The stream for the given job ID.\n */\n protected async initEnvStream(jobId: string) {\n await this.#offscreenPromise;\n\n return await super.initEnvStream(jobId);\n }\n}\n"]}
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
|
|
5
|
-
var
|
|
5
|
+
var _chunkWCDDYBFWjs = require('./chunk-WCDDYBFW.js');
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
|
|
@@ -67,11 +67,11 @@ var SnapInterfaceController = class extends _basecontroller.BaseController {
|
|
|
67
67
|
* @returns The newly interface id.
|
|
68
68
|
*/
|
|
69
69
|
async createInterface(snapId, content, context) {
|
|
70
|
-
const element =
|
|
70
|
+
const element = _chunkWCDDYBFWjs.getJsxInterface.call(void 0, content);
|
|
71
71
|
await _chunkEXN2TFDJjs.__privateMethod.call(void 0, this, _validateContent, validateContent_fn).call(this, element);
|
|
72
|
-
|
|
72
|
+
_chunkWCDDYBFWjs.validateInterfaceContext.call(void 0, context);
|
|
73
73
|
const id = _nanoid.nanoid.call(void 0, );
|
|
74
|
-
const componentState =
|
|
74
|
+
const componentState = _chunkWCDDYBFWjs.constructState.call(void 0, {}, element);
|
|
75
75
|
this.update((draftState) => {
|
|
76
76
|
draftState.interfaces[id] = {
|
|
77
77
|
snapId,
|
|
@@ -102,10 +102,10 @@ var SnapInterfaceController = class extends _basecontroller.BaseController {
|
|
|
102
102
|
*/
|
|
103
103
|
async updateInterface(snapId, id, content) {
|
|
104
104
|
_chunkEXN2TFDJjs.__privateMethod.call(void 0, this, _validateArgs, validateArgs_fn).call(this, snapId, id);
|
|
105
|
-
const element =
|
|
105
|
+
const element = _chunkWCDDYBFWjs.getJsxInterface.call(void 0, content);
|
|
106
106
|
await _chunkEXN2TFDJjs.__privateMethod.call(void 0, this, _validateContent, validateContent_fn).call(this, element);
|
|
107
107
|
const oldState = this.state.interfaces[id].state;
|
|
108
|
-
const newState =
|
|
108
|
+
const newState = _chunkWCDDYBFWjs.constructState.call(void 0, oldState, element);
|
|
109
109
|
this.update((draftState) => {
|
|
110
110
|
draftState.interfaces[id].state = newState;
|
|
111
111
|
draftState.interfaces[id].content = element;
|
|
@@ -190,4 +190,4 @@ validateContent_fn = async function(element) {
|
|
|
190
190
|
|
|
191
191
|
|
|
192
192
|
exports.SnapInterfaceController = SnapInterfaceController;
|
|
193
|
-
//# sourceMappingURL=chunk-
|
|
193
|
+
//# sourceMappingURL=chunk-6VGMRXGY.js.map
|
|
@@ -21,7 +21,7 @@ function assertNameIsUnique(state, name) {
|
|
|
21
21
|
function constructComponentSpecificDefaultState(element) {
|
|
22
22
|
if (element.type === "Dropdown") {
|
|
23
23
|
const children = getJsxChildren(element);
|
|
24
|
-
return children[0]
|
|
24
|
+
return children[0]?.props.value;
|
|
25
25
|
}
|
|
26
26
|
return null;
|
|
27
27
|
}
|
|
@@ -97,4 +97,4 @@ export {
|
|
|
97
97
|
constructState,
|
|
98
98
|
validateInterfaceContext
|
|
99
99
|
};
|
|
100
|
-
//# sourceMappingURL=chunk-
|
|
100
|
+
//# sourceMappingURL=chunk-7CZDBXIY.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/interface/utils.ts"],"sourcesContent":["import { assert } from '@metamask/snaps-sdk';\nimport type {\n FormState,\n InterfaceState,\n ComponentOrElement,\n InterfaceContext,\n} from '@metamask/snaps-sdk';\nimport type {\n ButtonElement,\n DropdownElement,\n FieldElement,\n InputElement,\n JSXElement,\n OptionElement,\n} from '@metamask/snaps-sdk/jsx';\nimport { isJSXElementUnsafe } from '@metamask/snaps-sdk/jsx';\nimport {\n getJsonSizeUnsafe,\n getJsxChildren,\n getJsxElementFromComponent,\n} from '@metamask/snaps-utils';\n\n/**\n * Get a JSX element from a component or JSX element. If the component is a\n * JSX element, it is returned as is. Otherwise, the component is converted to\n * a JSX element.\n *\n * @param component - The component to convert.\n * @returns The JSX element.\n */\nexport function getJsxInterface(component: ComponentOrElement): JSXElement {\n if (isJSXElementUnsafe(component)) {\n return component;\n }\n\n return getJsxElementFromComponent(component);\n}\n\n/**\n * Assert that the component name is unique in state.\n *\n * @param state - The interface state to verify against.\n * @param name - The component name to verify.\n */\nexport function assertNameIsUnique(state: InterfaceState, name: string) {\n assert(\n state[name] === undefined,\n `Duplicate component names are not allowed, found multiple instances of: \"${name}\".`,\n );\n}\n\n/**\n * Construct default state for a component.\n *\n * This function is meant to be used inside constructInputState to account\n * for component specific defaults and will not override the component value or existing form state.\n *\n * @param element - The input element.\n * @returns The default state for the specific component, if any.\n */\nfunction constructComponentSpecificDefaultState(\n element: InputElement | DropdownElement,\n) {\n if (element.type === 'Dropdown') {\n const children = getJsxChildren(element) as OptionElement[];\n return children[0]?.props.value;\n }\n\n return null;\n}\n\n/**\n * Construct the state for an input field.\n *\n * @param oldState - The previous state.\n * @param element - The input element.\n * @returns The input state.\n */\nfunction constructInputState(\n oldState: InterfaceState,\n element: InputElement | DropdownElement,\n) {\n return (\n element.props.value ??\n oldState[element.props.name] ??\n constructComponentSpecificDefaultState(element) ??\n null\n );\n}\n\n/**\n * Construct the state for a form input.\n *\n * @param oldState - The previous state.\n * @param component - The input element.\n * @param form - The parent form name of the input.\n * @returns The input state.\n */\nfunction constructFormInputState(\n oldState: InterfaceState,\n component: InputElement | DropdownElement,\n form: string,\n) {\n const oldFormState = oldState[form] as FormState;\n const oldInputState = oldFormState?.[component.props.name];\n return (\n component.props.value ??\n oldInputState ??\n constructComponentSpecificDefaultState(component) ??\n null\n );\n}\n\n/**\n * Get the input field from a field element.\n *\n * @param element - The field element.\n * @returns The input element.\n */\nfunction getFieldInput(element: FieldElement) {\n if (Array.isArray(element.props.children)) {\n return element.props.children[0];\n }\n\n return element.props.children;\n}\n\n/**\n * Construct the state for a form input.\n *\n * @param oldState - The previous state.\n * @param component - The field element.\n * @param form - The parent form name of the input.\n * @param newState - The new state.\n * @returns The input state.\n */\nfunction constructFormState(\n oldState: InterfaceState,\n component: FieldElement | ButtonElement,\n form: string,\n newState: FormState,\n): FormState {\n if (component.type === 'Button') {\n return newState;\n }\n\n const input = getFieldInput(component);\n assertNameIsUnique(newState, input.props.name);\n\n newState[input.props.name] = constructFormInputState(oldState, input, form);\n\n return newState;\n}\n\n/**\n * Construct the interface state for a given component tree.\n *\n * @param oldState - The previous state.\n * @param component - The UI component to construct state from.\n * @param newState - The state that is being constructed.\n * @returns The interface state of the passed component.\n */\nexport function constructState(\n oldState: InterfaceState,\n component: JSXElement,\n newState: InterfaceState = {},\n): InterfaceState {\n if (component.type === 'Box') {\n const children = getJsxChildren(component);\n return children.reduce(\n (accumulator, node) =>\n constructState(oldState, node as JSXElement, accumulator),\n newState,\n );\n }\n\n if (component.type === 'Form') {\n assertNameIsUnique(newState, component.props.name);\n\n const children = getJsxChildren(component);\n newState[component.props.name] = children.reduce<FormState>(\n (accumulator, node) => {\n return constructFormState(\n oldState,\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion\n node as FieldElement | ButtonElement,\n component.props.name,\n accumulator,\n );\n },\n {},\n );\n\n return newState;\n }\n\n if (component.type === 'Input' || component.type === 'Dropdown') {\n assertNameIsUnique(newState, component.props.name);\n newState[component.props.name] = constructInputState(oldState, component);\n }\n\n return newState;\n}\n\nconst MAX_CONTEXT_SIZE = 1_000_000; // 1 mb\n\n/**\n * Validate a JSON blob to be used as the interface context.\n *\n * @param context - The JSON blob.\n * @throws If the JSON blob is too large.\n */\nexport function validateInterfaceContext(context?: InterfaceContext) {\n if (!context) {\n return;\n }\n\n // We assume the validity of this JSON to be validated by the caller.\n // E.g., in the RPC method implementation.\n const size = getJsonSizeUnsafe(context);\n assert(\n size <= MAX_CONTEXT_SIZE,\n `A Snap interface context may not be larger than ${\n MAX_CONTEXT_SIZE / 1000000\n } MB.`,\n );\n}\n"],"mappings":";AAAA,SAAS,cAAc;AAevB,SAAS,0BAA0B;AACnC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAUA,SAAS,gBAAgB,WAA2C;AACzE,MAAI,mBAAmB,SAAS,GAAG;AACjC,WAAO;AAAA,EACT;AAEA,SAAO,2BAA2B,SAAS;AAC7C;AAQO,SAAS,mBAAmB,OAAuB,MAAc;AACtE;AAAA,IACE,MAAM,IAAI,MAAM;AAAA,IAChB,4EAA4E,IAAI;AAAA,EAClF;AACF;AAWA,SAAS,uCACP,SACA;AACA,MAAI,QAAQ,SAAS,YAAY;AAC/B,UAAM,WAAW,eAAe,OAAO;AACvC,WAAO,SAAS,CAAC,GAAG,MAAM;AAAA,EAC5B;AAEA,SAAO;AACT;AASA,SAAS,oBACP,UACA,SACA;AACA,SACE,QAAQ,MAAM,SACd,SAAS,QAAQ,MAAM,IAAI,KAC3B,uCAAuC,OAAO,KAC9C;AAEJ;AAUA,SAAS,wBACP,UACA,WACA,MACA;AACA,QAAM,eAAe,SAAS,IAAI;AAClC,QAAM,gBAAgB,eAAe,UAAU,MAAM,IAAI;AACzD,SACE,UAAU,MAAM,SAChB,iBACA,uCAAuC,SAAS,KAChD;AAEJ;AAQA,SAAS,cAAc,SAAuB;AAC5C,MAAI,MAAM,QAAQ,QAAQ,MAAM,QAAQ,GAAG;AACzC,WAAO,QAAQ,MAAM,SAAS,CAAC;AAAA,EACjC;AAEA,SAAO,QAAQ,MAAM;AACvB;AAWA,SAAS,mBACP,UACA,WACA,MACA,UACW;AACX,MAAI,UAAU,SAAS,UAAU;AAC/B,WAAO;AAAA,EACT;AAEA,QAAM,QAAQ,cAAc,SAAS;AACrC,qBAAmB,UAAU,MAAM,MAAM,IAAI;AAE7C,WAAS,MAAM,MAAM,IAAI,IAAI,wBAAwB,UAAU,OAAO,IAAI;AAE1E,SAAO;AACT;AAUO,SAAS,eACd,UACA,WACA,WAA2B,CAAC,GACZ;AAChB,MAAI,UAAU,SAAS,OAAO;AAC5B,UAAM,WAAW,eAAe,SAAS;AACzC,WAAO,SAAS;AAAA,MACd,CAAC,aAAa,SACZ,eAAe,UAAU,MAAoB,WAAW;AAAA,MAC1D;AAAA,IACF;AAAA,EACF;AAEA,MAAI,UAAU,SAAS,QAAQ;AAC7B,uBAAmB,UAAU,UAAU,MAAM,IAAI;AAEjD,UAAM,WAAW,eAAe,SAAS;AACzC,aAAS,UAAU,MAAM,IAAI,IAAI,SAAS;AAAA,MACxC,CAAC,aAAa,SAAS;AACrB,eAAO;AAAA,UACL;AAAA;AAAA,UAEA;AAAA,UACA,UAAU,MAAM;AAAA,UAChB;AAAA,QACF;AAAA,MACF;AAAA,MACA,CAAC;AAAA,IACH;AAEA,WAAO;AAAA,EACT;AAEA,MAAI,UAAU,SAAS,WAAW,UAAU,SAAS,YAAY;AAC/D,uBAAmB,UAAU,UAAU,MAAM,IAAI;AACjD,aAAS,UAAU,MAAM,IAAI,IAAI,oBAAoB,UAAU,SAAS;AAAA,EAC1E;AAEA,SAAO;AACT;AAEA,IAAM,mBAAmB;AAQlB,SAAS,yBAAyB,SAA4B;AACnE,MAAI,CAAC,SAAS;AACZ;AAAA,EACF;AAIA,QAAM,OAAO,kBAAkB,OAAO;AACtC;AAAA,IACE,QAAQ;AAAA,IACR,mDACE,mBAAmB,GACrB;AAAA,EACF;AACF;","names":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ProxyExecutionService
|
|
3
|
+
} from "./chunk-3A72M4GC.mjs";
|
|
4
|
+
import {
|
|
5
|
+
__privateAdd,
|
|
6
|
+
__privateGet,
|
|
7
|
+
__privateSet
|
|
8
|
+
} from "./chunk-YRZVIDCF.mjs";
|
|
9
|
+
|
|
10
|
+
// src/services/offscreen/OffscreenExecutionService.ts
|
|
11
|
+
import { BrowserRuntimePostMessageStream } from "@metamask/post-message-stream";
|
|
12
|
+
var _offscreenPromise;
|
|
13
|
+
var OffscreenExecutionService = class extends ProxyExecutionService {
|
|
14
|
+
/**
|
|
15
|
+
* Create a new offscreen execution service.
|
|
16
|
+
*
|
|
17
|
+
* @param args - The constructor arguments.
|
|
18
|
+
* @param args.messenger - The messenger to use for communication with the
|
|
19
|
+
* `SnapController`.
|
|
20
|
+
* @param args.setupSnapProvider - The function to use to set up the snap
|
|
21
|
+
* provider.
|
|
22
|
+
* @param args.offscreenPromise - A promise that resolves when the offscreen
|
|
23
|
+
* environment is ready.
|
|
24
|
+
*/
|
|
25
|
+
constructor({
|
|
26
|
+
messenger,
|
|
27
|
+
setupSnapProvider,
|
|
28
|
+
offscreenPromise
|
|
29
|
+
}) {
|
|
30
|
+
super({
|
|
31
|
+
messenger,
|
|
32
|
+
setupSnapProvider,
|
|
33
|
+
stream: new BrowserRuntimePostMessageStream({
|
|
34
|
+
name: "parent",
|
|
35
|
+
target: "child"
|
|
36
|
+
})
|
|
37
|
+
});
|
|
38
|
+
__privateAdd(this, _offscreenPromise, void 0);
|
|
39
|
+
__privateSet(this, _offscreenPromise, offscreenPromise);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a new stream for the given job ID. This will wait for the offscreen
|
|
43
|
+
* environment to be ready before creating the stream.
|
|
44
|
+
*
|
|
45
|
+
* @param jobId - The job ID to create a stream for.
|
|
46
|
+
* @returns The stream for the given job ID.
|
|
47
|
+
*/
|
|
48
|
+
async initEnvStream(jobId) {
|
|
49
|
+
await __privateGet(this, _offscreenPromise);
|
|
50
|
+
return await super.initEnvStream(jobId);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
_offscreenPromise = new WeakMap();
|
|
54
|
+
|
|
55
|
+
export {
|
|
56
|
+
OffscreenExecutionService
|
|
57
|
+
};
|
|
58
|
+
//# sourceMappingURL=chunk-CIFVYFJW.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/services/offscreen/OffscreenExecutionService.ts"],"sourcesContent":["import { BrowserRuntimePostMessageStream } from '@metamask/post-message-stream';\n\nimport type { ExecutionServiceArgs } from '../AbstractExecutionService';\nimport { ProxyExecutionService } from '../proxy/ProxyExecutionService';\n\ntype OffscreenExecutionEnvironmentServiceArgs = {\n offscreenPromise: Promise<unknown>;\n} & ExecutionServiceArgs;\n\nexport class OffscreenExecutionService extends ProxyExecutionService {\n readonly #offscreenPromise: Promise<unknown>;\n\n /**\n * Create a new offscreen execution service.\n *\n * @param args - The constructor arguments.\n * @param args.messenger - The messenger to use for communication with the\n * `SnapController`.\n * @param args.setupSnapProvider - The function to use to set up the snap\n * provider.\n * @param args.offscreenPromise - A promise that resolves when the offscreen\n * environment is ready.\n */\n constructor({\n messenger,\n setupSnapProvider,\n offscreenPromise,\n }: OffscreenExecutionEnvironmentServiceArgs) {\n super({\n messenger,\n setupSnapProvider,\n stream: new BrowserRuntimePostMessageStream({\n name: 'parent',\n target: 'child',\n }),\n });\n\n this.#offscreenPromise = offscreenPromise;\n }\n\n /**\n * Create a new stream for the given job ID. This will wait for the offscreen\n * environment to be ready before creating the stream.\n *\n * @param jobId - The job ID to create a stream for.\n * @returns The stream for the given job ID.\n */\n protected async initEnvStream(jobId: string) {\n await this.#offscreenPromise;\n\n return await super.initEnvStream(jobId);\n }\n}\n"],"mappings":";;;;;;;;;;AAAA,SAAS,uCAAuC;AAAhD;AASO,IAAM,4BAAN,cAAwC,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAcnE,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA;AAAA,EACF,GAA6C;AAC3C,UAAM;AAAA,MACJ;AAAA,MACA;AAAA,MACA,QAAQ,IAAI,gCAAgC;AAAA,QAC1C,MAAM;AAAA,QACN,QAAQ;AAAA,MACV,CAAC;AAAA,IACH,CAAC;AAzBH,uBAAS,mBAAT;AA2BE,uBAAK,mBAAoB;AAAA,EAC3B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EASA,MAAgB,cAAc,OAAe;AAC3C,UAAM,mBAAK;AAEX,WAAO,MAAM,MAAM,cAAc,KAAK;AAAA,EACxC;AACF;AA1CW;","names":[]}
|
|
@@ -12,8 +12,15 @@ var ALLOWED_PERMISSIONS = Object.freeze([
|
|
|
12
12
|
_snapsrpcmethods.SnapEndowments.TransactionInsight,
|
|
13
13
|
_snapsrpcmethods.SnapEndowments.SignatureInsight
|
|
14
14
|
]);
|
|
15
|
+
var LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS = {
|
|
16
|
+
algorithm: "PBKDF2",
|
|
17
|
+
params: {
|
|
18
|
+
iterations: 1e4
|
|
19
|
+
}
|
|
20
|
+
};
|
|
15
21
|
|
|
16
22
|
|
|
17
23
|
|
|
18
|
-
|
|
19
|
-
|
|
24
|
+
|
|
25
|
+
exports.ALLOWED_PERMISSIONS = ALLOWED_PERMISSIONS; exports.LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS = LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS;
|
|
26
|
+
//# sourceMappingURL=chunk-JQ54YYLU.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/snaps/constants.ts"],"names":[],"mappings":";AAAA,SAAS,sBAAsB;AAGxB,IAAM,sBAAsB,OAAO,OAAO;AAAA,EAC/C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AAAA,EACf,eAAe;AACjB,CAAC;AAEM,IAAM,2CAA2C;AAAA,EACtD,WAAW;AAAA,EACX,QAAQ;AAAA,IACN,YAAY;AAAA,EACd;AACF","sourcesContent":["import { SnapEndowments } from '@metamask/snaps-rpc-methods';\n\n// These permissions are allowed without being on the allowlist.\nexport const ALLOWED_PERMISSIONS = Object.freeze([\n 'snap_dialog',\n 'snap_manageState',\n 'snap_notify',\n 'snap_getLocale',\n SnapEndowments.Cronjob,\n SnapEndowments.HomePage,\n SnapEndowments.LifecycleHooks,\n SnapEndowments.EthereumProvider,\n SnapEndowments.TransactionInsight,\n SnapEndowments.SignatureInsight,\n]);\n\nexport const LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS = {\n algorithm: 'PBKDF2' as const,\n params: {\n iterations: 10_000,\n },\n};\n"]}
|
|
@@ -5,8 +5,9 @@ import {
|
|
|
5
5
|
RequestQueue
|
|
6
6
|
} from "./chunk-NC5PBDKD.mjs";
|
|
7
7
|
import {
|
|
8
|
-
ALLOWED_PERMISSIONS
|
|
9
|
-
|
|
8
|
+
ALLOWED_PERMISSIONS,
|
|
9
|
+
LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS
|
|
10
|
+
} from "./chunk-4M2FX2AT.mjs";
|
|
10
11
|
import {
|
|
11
12
|
forceStrict,
|
|
12
13
|
validateMachine
|
|
@@ -1806,7 +1807,9 @@ decryptSnapState_fn = async function(snapId, state) {
|
|
|
1806
1807
|
snapId,
|
|
1807
1808
|
salt,
|
|
1808
1809
|
useCache,
|
|
1809
|
-
|
|
1810
|
+
// When decrypting state we expect key metadata to be present.
|
|
1811
|
+
// If it isn't present, we assume that the Snap state we are decrypting is old enough to use the legacy encryption params.
|
|
1812
|
+
keyMetadata: keyMetadata ?? LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS
|
|
1810
1813
|
});
|
|
1811
1814
|
const decryptedState = await __privateGet(this, _encryptor).decryptWithKey(key, parsed);
|
|
1812
1815
|
assert(isValidJson(decryptedState));
|
|
@@ -2493,4 +2496,4 @@ export {
|
|
|
2493
2496
|
SNAP_APPROVAL_RESULT,
|
|
2494
2497
|
SnapController
|
|
2495
2498
|
};
|
|
2496
|
-
//# sourceMappingURL=chunk-
|
|
2499
|
+
//# sourceMappingURL=chunk-RVWBSSZM.mjs.map
|