@metamask/snaps-controllers 8.3.1 → 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.
Files changed (75) hide show
  1. package/CHANGELOG.md +19 -1
  2. package/dist/{chunk-YIQM6ZKA.mjs → chunk-4M2FX2AT.mjs} +9 -2
  3. package/dist/{chunk-YIQM6ZKA.mjs.map → chunk-4M2FX2AT.mjs.map} +1 -1
  4. package/dist/chunk-6ERB63FH.js +58 -0
  5. package/dist/chunk-6ERB63FH.js.map +1 -0
  6. package/dist/{chunk-PIQFC66N.js → chunk-6VGMRXGY.js} +7 -7
  7. package/dist/{chunk-UJJCRV7W.mjs → chunk-7CZDBXIY.mjs} +10 -3
  8. package/dist/chunk-7CZDBXIY.mjs.map +1 -0
  9. package/dist/chunk-CIFVYFJW.mjs +58 -0
  10. package/dist/chunk-CIFVYFJW.mjs.map +1 -0
  11. package/dist/{chunk-5YBORD3A.js → chunk-JQ54YYLU.js} +9 -2
  12. package/dist/chunk-JQ54YYLU.js.map +1 -0
  13. package/dist/{chunk-JCQR3I2Q.mjs → chunk-RVWBSSZM.mjs} +18 -6
  14. package/dist/chunk-RVWBSSZM.mjs.map +1 -0
  15. package/dist/{chunk-7TYZZFHZ.js → chunk-WCDDYBFW.js} +10 -3
  16. package/dist/chunk-WCDDYBFW.js.map +1 -0
  17. package/dist/{chunk-QLWR3M4Q.mjs → chunk-YAZ55WUL.mjs} +2 -2
  18. package/dist/{chunk-NRZEYYBQ.js → chunk-ZBSBCWWM.js} +18 -6
  19. package/dist/chunk-ZBSBCWWM.js.map +1 -0
  20. package/dist/cronjob/CronjobController.js +5 -5
  21. package/dist/cronjob/CronjobController.mjs +5 -5
  22. package/dist/cronjob/index.js +5 -5
  23. package/dist/cronjob/index.mjs +5 -5
  24. package/dist/index.js +6 -6
  25. package/dist/index.mjs +5 -5
  26. package/dist/interface/SnapInterfaceController.js +3 -3
  27. package/dist/interface/SnapInterfaceController.mjs +2 -2
  28. package/dist/interface/index.js +3 -3
  29. package/dist/interface/index.mjs +2 -2
  30. package/dist/interface/utils.js +2 -2
  31. package/dist/interface/utils.mjs +1 -1
  32. package/dist/node.js +6 -6
  33. package/dist/node.mjs +5 -5
  34. package/dist/react-native.js +6 -6
  35. package/dist/react-native.mjs +5 -5
  36. package/dist/services/browser.js +2 -2
  37. package/dist/services/browser.mjs +1 -1
  38. package/dist/services/index.js +2 -2
  39. package/dist/services/index.mjs +1 -1
  40. package/dist/services/node-js/NodeProcessExecutionService.js +1 -1
  41. package/dist/services/node-js/NodeProcessExecutionService.mjs +1 -1
  42. package/dist/services/node-js/NodeThreadExecutionService.js +1 -1
  43. package/dist/services/node-js/NodeThreadExecutionService.mjs +1 -1
  44. package/dist/services/node-js/index.js +1 -1
  45. package/dist/services/node-js/index.mjs +1 -1
  46. package/dist/services/node.js +2 -2
  47. package/dist/services/node.mjs +1 -1
  48. package/dist/services/offscreen/OffscreenExecutionService.js +2 -2
  49. package/dist/services/offscreen/OffscreenExecutionService.mjs +1 -1
  50. package/dist/services/offscreen/index.js +2 -2
  51. package/dist/services/offscreen/index.mjs +1 -1
  52. package/dist/services/react-native.js +2 -2
  53. package/dist/services/react-native.mjs +1 -1
  54. package/dist/snaps/SnapController.js +3 -3
  55. package/dist/snaps/SnapController.mjs +2 -2
  56. package/dist/snaps/constants.js +4 -2
  57. package/dist/snaps/constants.mjs +5 -3
  58. package/dist/snaps/index.js +3 -3
  59. package/dist/snaps/index.mjs +2 -2
  60. package/dist/tsconfig.build.tsbuildinfo +1 -1
  61. package/dist/types/services/offscreen/OffscreenExecutionService.d.ts +8 -9
  62. package/dist/types/snaps/SnapController.d.ts +1 -0
  63. package/dist/types/snaps/constants.d.ts +6 -0
  64. package/package.json +11 -11
  65. package/dist/chunk-3OJFF5CK.mjs +0 -72
  66. package/dist/chunk-3OJFF5CK.mjs.map +0 -1
  67. package/dist/chunk-5YBORD3A.js.map +0 -1
  68. package/dist/chunk-7TYZZFHZ.js.map +0 -1
  69. package/dist/chunk-HK4OAMJT.js +0 -72
  70. package/dist/chunk-HK4OAMJT.js.map +0 -1
  71. package/dist/chunk-JCQR3I2Q.mjs.map +0 -1
  72. package/dist/chunk-NRZEYYBQ.js.map +0 -1
  73. package/dist/chunk-UJJCRV7W.mjs.map +0 -1
  74. /package/dist/{chunk-PIQFC66N.js.map → chunk-6VGMRXGY.js.map} +0 -0
  75. /package/dist/{chunk-QLWR3M4Q.mjs.map → chunk-YAZ55WUL.mjs.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -6,6 +6,22 @@ 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
+
18
+ ## [8.4.0]
19
+ ### Added
20
+ - Add `hidden` flag for preinstalled Snaps ([#2463](https://github.com/MetaMask/snaps/pull/2463))
21
+
22
+ ### Fixed
23
+ - Use first Dropdown option as the default value ([#2465](https://github.com/MetaMask/snaps/pull/2465))
24
+
9
25
  ## [8.3.1]
10
26
  ### Fixed
11
27
  - Fix `react-native` export for tools that don't support `package.json` exports ([#2451](https://github.com/MetaMask/snaps/pull/2451))
@@ -281,7 +297,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
281
297
  - The version of the package no longer needs to match the version of all other
282
298
  MetaMask Snaps packages.
283
299
 
284
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.3.1...HEAD
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
302
+ [8.4.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.3.1...@metamask/snaps-controllers@8.4.0
285
303
  [8.3.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.3.0...@metamask/snaps-controllers@8.3.1
286
304
  [8.3.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.2.0...@metamask/snaps-controllers@8.3.0
287
305
  [8.2.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@8.1.1...@metamask/snaps-controllers@8.2.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-YIQM6ZKA.mjs.map
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 _chunk7TYZZFHZjs = require('./chunk-7TYZZFHZ.js');
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 = _chunk7TYZZFHZjs.getJsxInterface.call(void 0, content);
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
- _chunk7TYZZFHZjs.validateInterfaceContext.call(void 0, context);
72
+ _chunkWCDDYBFWjs.validateInterfaceContext.call(void 0, context);
73
73
  const id = _nanoid.nanoid.call(void 0, );
74
- const componentState = _chunk7TYZZFHZjs.constructState.call(void 0, {}, element);
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 = _chunk7TYZZFHZjs.getJsxInterface.call(void 0, content);
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 = _chunk7TYZZFHZjs.constructState.call(void 0, oldState, element);
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-PIQFC66N.js.map
193
+ //# sourceMappingURL=chunk-6VGMRXGY.js.map
@@ -18,13 +18,20 @@ function assertNameIsUnique(state, name) {
18
18
  `Duplicate component names are not allowed, found multiple instances of: "${name}".`
19
19
  );
20
20
  }
21
+ function constructComponentSpecificDefaultState(element) {
22
+ if (element.type === "Dropdown") {
23
+ const children = getJsxChildren(element);
24
+ return children[0]?.props.value;
25
+ }
26
+ return null;
27
+ }
21
28
  function constructInputState(oldState, element) {
22
- return element.props.value ?? oldState[element.props.name] ?? null;
29
+ return element.props.value ?? oldState[element.props.name] ?? constructComponentSpecificDefaultState(element) ?? null;
23
30
  }
24
31
  function constructFormInputState(oldState, component, form) {
25
32
  const oldFormState = oldState[form];
26
33
  const oldInputState = oldFormState?.[component.props.name];
27
- return component.props.value ?? oldInputState ?? null;
34
+ return component.props.value ?? oldInputState ?? constructComponentSpecificDefaultState(component) ?? null;
28
35
  }
29
36
  function getFieldInput(element) {
30
37
  if (Array.isArray(element.props.children)) {
@@ -90,4 +97,4 @@ export {
90
97
  constructState,
91
98
  validateInterfaceContext
92
99
  };
93
- //# sourceMappingURL=chunk-UJJCRV7W.mjs.map
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
- exports.ALLOWED_PERMISSIONS = ALLOWED_PERMISSIONS;
19
- //# sourceMappingURL=chunk-5YBORD3A.js.map
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
- } from "./chunk-YIQM6ZKA.mjs";
8
+ ALLOWED_PERMISSIONS,
9
+ LEGACY_ENCRYPTION_KEY_DERIVATION_OPTIONS
10
+ } from "./chunk-4M2FX2AT.mjs";
10
11
  import {
11
12
  forceStrict,
12
13
  validateMachine
@@ -1597,7 +1598,13 @@ registerMessageHandlers_fn = function() {
1597
1598
  };
1598
1599
  _handlePreinstalledSnaps = new WeakSet();
1599
1600
  handlePreinstalledSnaps_fn = function(preinstalledSnaps) {
1600
- for (const { snapId, manifest, files, removable } of preinstalledSnaps) {
1601
+ for (const {
1602
+ snapId,
1603
+ manifest,
1604
+ files,
1605
+ removable,
1606
+ hidden
1607
+ } of preinstalledSnaps) {
1601
1608
  const existingSnap = this.get(snapId);
1602
1609
  const isAlreadyInstalled = existingSnap !== void 0;
1603
1610
  const isUpdate = isAlreadyInstalled && gtVersion(manifest.version, existingSnap.version);
@@ -1646,6 +1653,7 @@ handlePreinstalledSnaps_fn = function(preinstalledSnaps) {
1646
1653
  origin: "metamask",
1647
1654
  files: filesObject,
1648
1655
  removable,
1656
+ hidden,
1649
1657
  preinstalled: true
1650
1658
  });
1651
1659
  const processedPermissions = processSnapPermissions(
@@ -1799,7 +1807,9 @@ decryptSnapState_fn = async function(snapId, state) {
1799
1807
  snapId,
1800
1808
  salt,
1801
1809
  useCache,
1802
- keyMetadata
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
1803
1813
  });
1804
1814
  const decryptedState = await __privateGet(this, _encryptor).decryptWithKey(key, parsed);
1805
1815
  assert(isValidJson(decryptedState));
@@ -2037,7 +2047,8 @@ set_fn = function(args) {
2037
2047
  files,
2038
2048
  isUpdate = false,
2039
2049
  removable,
2040
- preinstalled
2050
+ preinstalled,
2051
+ hidden
2041
2052
  } = args;
2042
2053
  const {
2043
2054
  manifest,
@@ -2081,6 +2092,7 @@ set_fn = function(args) {
2081
2092
  enabled: true,
2082
2093
  removable,
2083
2094
  preinstalled,
2095
+ hidden,
2084
2096
  id: snapId,
2085
2097
  initialConnections: manifest.result.initialConnections,
2086
2098
  initialPermissions: manifest.result.initialPermissions,
@@ -2484,4 +2496,4 @@ export {
2484
2496
  SNAP_APPROVAL_RESULT,
2485
2497
  SnapController
2486
2498
  };
2487
- //# sourceMappingURL=chunk-JCQR3I2Q.mjs.map
2499
+ //# sourceMappingURL=chunk-RVWBSSZM.mjs.map