@metamask/snaps-controllers 6.0.4 → 7.0.1

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 (60) hide show
  1. package/CHANGELOG.md +16 -1
  2. package/dist/{chunk-B67RDBZ4.mjs → chunk-42ODFZSH.mjs} +4 -4
  3. package/dist/{chunk-AXXQZJBW.mjs → chunk-5MVIYRYL.mjs} +138 -19
  4. package/dist/chunk-5MVIYRYL.mjs.map +1 -0
  5. package/dist/{chunk-APQVOL5T.js → chunk-CJN25EXL.js} +137 -18
  6. package/dist/chunk-CJN25EXL.js.map +1 -0
  7. package/dist/chunk-HP6S5IOB.js +1 -0
  8. package/dist/chunk-HP6S5IOB.js.map +1 -0
  9. package/dist/chunk-NZOUFWUN.mjs +1 -0
  10. package/dist/chunk-NZOUFWUN.mjs.map +1 -0
  11. package/dist/{chunk-7WOG63YY.js → chunk-PT22IXNS.js} +3 -3
  12. package/dist/cronjob/CronjobController.js +6 -6
  13. package/dist/cronjob/CronjobController.mjs +6 -6
  14. package/dist/cronjob/index.js +6 -6
  15. package/dist/cronjob/index.mjs +6 -6
  16. package/dist/index.js +10 -10
  17. package/dist/index.mjs +12 -12
  18. package/dist/node.js +10 -10
  19. package/dist/node.mjs +12 -12
  20. package/dist/react-native.js +10 -10
  21. package/dist/react-native.mjs +12 -12
  22. package/dist/services/browser.js +1 -1
  23. package/dist/services/browser.mjs +1 -1
  24. package/dist/services/index.js +1 -1
  25. package/dist/services/index.mjs +1 -1
  26. package/dist/services/node-js/NodeProcessExecutionService.js +1 -1
  27. package/dist/services/node-js/NodeProcessExecutionService.mjs +1 -1
  28. package/dist/services/node-js/NodeThreadExecutionService.js +1 -1
  29. package/dist/services/node-js/NodeThreadExecutionService.mjs +1 -1
  30. package/dist/services/node-js/index.js +1 -1
  31. package/dist/services/node-js/index.mjs +1 -1
  32. package/dist/services/node.js +1 -1
  33. package/dist/services/node.mjs +1 -1
  34. package/dist/services/react-native.js +1 -1
  35. package/dist/services/react-native.mjs +1 -1
  36. package/dist/snaps/SnapController.js +6 -6
  37. package/dist/snaps/SnapController.mjs +5 -5
  38. package/dist/snaps/index.js +9 -9
  39. package/dist/snaps/index.mjs +11 -11
  40. package/dist/snaps/location/index.js +4 -4
  41. package/dist/snaps/location/index.mjs +4 -4
  42. package/dist/snaps/location/location.js +3 -3
  43. package/dist/snaps/location/location.mjs +2 -2
  44. package/dist/tsconfig.build.tsbuildinfo +1 -1
  45. package/dist/types/encryptor.js +2 -0
  46. package/dist/types/encryptor.js.map +1 -0
  47. package/dist/types/encryptor.mjs +2 -0
  48. package/dist/types/encryptor.mjs.map +1 -0
  49. package/dist/types/index.js +2 -0
  50. package/dist/types/index.js.map +1 -0
  51. package/dist/types/index.mjs +2 -0
  52. package/dist/types/index.mjs.map +1 -0
  53. package/dist/types/snaps/SnapController.d.ts +22 -3
  54. package/dist/types/types/encryptor.d.ts +98 -0
  55. package/dist/types/types/index.d.ts +1 -0
  56. package/package.json +7 -6
  57. package/dist/chunk-APQVOL5T.js.map +0 -1
  58. package/dist/chunk-AXXQZJBW.mjs.map +0 -1
  59. /package/dist/{chunk-B67RDBZ4.mjs.map → chunk-42ODFZSH.mjs.map} +0 -0
  60. /package/dist/{chunk-7WOG63YY.js.map → chunk-PT22IXNS.js.map} +0 -0
package/CHANGELOG.md CHANGED
@@ -6,6 +6,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
6
 
7
7
  ## [Unreleased]
8
8
 
9
+ ## [7.0.1]
10
+ ### Fixed
11
+ - Fix encryption key caching issues ([#2326](https://github.com/MetaMask/snaps/pull/2326))
12
+
13
+ ## [7.0.0]
14
+ ### Changed
15
+ - **BREAKING:** Refactor encryption to enable caching ([#2316](https://github.com/MetaMask/snaps/pull/2316))
16
+ - New required constructor arguments `encryptor` and `getMnemonic` have been added.
17
+ - Include `initialConnections` in approval `requestState` ([#2322](https://github.com/MetaMask/snaps/pull/2322))
18
+
19
+ ### Fixed
20
+ - Delete unencrypted state when uninstalling a Snap ([#2311](https://github.com/MetaMask/snaps/pull/2311))
21
+
9
22
  ## [6.0.4]
10
23
  ### Changed
11
24
  - Bump MetaMask dependencies ([#2270](https://github.com/MetaMask/snaps/pull/2270))
@@ -221,7 +234,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
221
234
  - The version of the package no longer needs to match the version of all other
222
235
  MetaMask Snaps packages.
223
236
 
224
- [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@6.0.4...HEAD
237
+ [Unreleased]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@7.0.1...HEAD
238
+ [7.0.1]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@7.0.0...@metamask/snaps-controllers@7.0.1
239
+ [7.0.0]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@6.0.4...@metamask/snaps-controllers@7.0.0
225
240
  [6.0.4]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@6.0.3...@metamask/snaps-controllers@6.0.4
226
241
  [6.0.3]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@6.0.2...@metamask/snaps-controllers@6.0.3
227
242
  [6.0.2]: https://github.com/MetaMask/snaps/compare/@metamask/snaps-controllers@6.0.1...@metamask/snaps-controllers@6.0.2
@@ -1,9 +1,9 @@
1
- import {
2
- NpmLocation
3
- } from "./chunk-WKQRCGUW.mjs";
4
1
  import {
5
2
  LocalLocation
6
3
  } from "./chunk-B3UTLNYS.mjs";
4
+ import {
5
+ NpmLocation
6
+ } from "./chunk-WKQRCGUW.mjs";
7
7
  import {
8
8
  HttpLocation
9
9
  } from "./chunk-6GMWL4JR.mjs";
@@ -37,4 +37,4 @@ function detectSnapLocation(location, opts) {
37
37
  export {
38
38
  detectSnapLocation
39
39
  };
40
- //# sourceMappingURL=chunk-B67RDBZ4.mjs.map
40
+ //# sourceMappingURL=chunk-42ODFZSH.mjs.map
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  detectSnapLocation
3
- } from "./chunk-B67RDBZ4.mjs";
3
+ } from "./chunk-42ODFZSH.mjs";
4
4
  import {
5
5
  RequestQueue
6
6
  } from "./chunk-NC5PBDKD.mjs";
@@ -41,7 +41,8 @@ import {
41
41
  SnapEndowments,
42
42
  getKeyringCaveatOrigins,
43
43
  getRpcCaveatOrigins,
44
- processSnapPermissions
44
+ processSnapPermissions,
45
+ getEncryptionEntropy
45
46
  } from "@metamask/snaps-rpc-methods";
46
47
  import { AuxiliaryFileEncoding, getErrorMessage } from "@metamask/snaps-sdk";
47
48
  import {
@@ -66,7 +67,8 @@ import {
66
67
  VirtualFile,
67
68
  NpmSnapFileNames,
68
69
  OnNameLookupResponseStruct,
69
- getLocalizedSnapManifest
70
+ getLocalizedSnapManifest,
71
+ parseJson
70
72
  } from "@metamask/snaps-utils";
71
73
  import {
72
74
  assert,
@@ -78,6 +80,7 @@ import {
78
80
  hasProperty,
79
81
  inMilliseconds,
80
82
  isNonEmptyArray,
83
+ isValidJson,
81
84
  isValidSemVerRange,
82
85
  satisfiesVersionRange,
83
86
  timeSince
@@ -113,7 +116,7 @@ function truncateSnap(snap) {
113
116
  return truncatedSnap;
114
117
  }
115
118
  var name = "SnapController";
116
- var _closeAllConnections, _dynamicPermissions, _environmentEndowmentPermissions, _excludedPermissions, _featureFlags, _fetchFunction, _idleTimeCheckInterval, _maxIdleTime, _maxInitTime, _detectSnapLocation, _snapsRuntimeData, _rollbackSnapshots, _timeoutForLastRequestStatus, _statusMachine, _initializeStateMachine, initializeStateMachine_fn, _registerMessageHandlers, registerMessageHandlers_fn, _handlePreinstalledSnaps, handlePreinstalledSnaps_fn, _pollForLastRequestStatus, pollForLastRequestStatus_fn, _blockSnap, blockSnap_fn, _unblockSnap, unblockSnap_fn, _assertIsInstallAllowed, assertIsInstallAllowed_fn, _stopSnapsLastRequestPastMax, stopSnapsLastRequestPastMax_fn, _transition, transition_fn, _terminateSnap, terminateSnap_fn, _handleInitialConnections, handleInitialConnections_fn, _addSnapToSubject, addSnapToSubject_fn, _removeSnapFromSubjects, removeSnapFromSubjects_fn, _revokeAllSnapPermissions, revokeAllSnapPermissions_fn, _createApproval, createApproval_fn, _updateApproval, updateApproval_fn, _resolveAllowlistVersion, resolveAllowlistVersion_fn, _add, add_fn, _startSnap, startSnap_fn, _getEndowments, getEndowments_fn, _set, set_fn, _validateSnapPermissions, validateSnapPermissions_fn, _getExecutionTimeout, getExecutionTimeout_fn, _getRpcRequestHandler, getRpcRequestHandler_fn, _createInterface, createInterface_fn, _assertInterfaceExists, assertInterfaceExists_fn, _transformSnapRpcRequestResult, transformSnapRpcRequestResult_fn, _assertSnapRpcRequestResult, assertSnapRpcRequestResult_fn, _recordSnapRpcRequestStart, recordSnapRpcRequestStart_fn, _recordSnapRpcRequestFinish, recordSnapRpcRequestFinish_fn, _getRollbackSnapshot, getRollbackSnapshot_fn, _createRollbackSnapshot, createRollbackSnapshot_fn, _rollbackSnap, rollbackSnap_fn, _rollbackSnaps, rollbackSnaps_fn, _getRuntime, getRuntime_fn, _getRuntimeExpect, getRuntimeExpect_fn, _setupRuntime, setupRuntime_fn, _calculatePermissionsChange, calculatePermissionsChange_fn, _updatePermissions, updatePermissions_fn, _isValidUpdate, isValidUpdate_fn, _callLifecycleHook, callLifecycleHook_fn;
119
+ var _closeAllConnections, _dynamicPermissions, _environmentEndowmentPermissions, _excludedPermissions, _featureFlags, _fetchFunction, _idleTimeCheckInterval, _maxIdleTime, _maxInitTime, _encryptor, _getMnemonic, _detectSnapLocation, _snapsRuntimeData, _rollbackSnapshots, _timeoutForLastRequestStatus, _statusMachine, _initializeStateMachine, initializeStateMachine_fn, _registerMessageHandlers, registerMessageHandlers_fn, _handlePreinstalledSnaps, handlePreinstalledSnaps_fn, _pollForLastRequestStatus, pollForLastRequestStatus_fn, _blockSnap, blockSnap_fn, _unblockSnap, unblockSnap_fn, _assertIsInstallAllowed, assertIsInstallAllowed_fn, _stopSnapsLastRequestPastMax, stopSnapsLastRequestPastMax_fn, _transition, transition_fn, _terminateSnap, terminateSnap_fn, _getSnapEncryptionKey, getSnapEncryptionKey_fn, _decryptSnapState, decryptSnapState_fn, _encryptSnapState, encryptSnapState_fn, _handleInitialConnections, handleInitialConnections_fn, _addSnapToSubject, addSnapToSubject_fn, _removeSnapFromSubjects, removeSnapFromSubjects_fn, _revokeAllSnapPermissions, revokeAllSnapPermissions_fn, _createApproval, createApproval_fn, _updateApproval, updateApproval_fn, _resolveAllowlistVersion, resolveAllowlistVersion_fn, _add, add_fn, _startSnap, startSnap_fn, _getEndowments, getEndowments_fn, _set, set_fn, _validateSnapPermissions, validateSnapPermissions_fn, _getExecutionTimeout, getExecutionTimeout_fn, _getRpcRequestHandler, getRpcRequestHandler_fn, _createInterface, createInterface_fn, _assertInterfaceExists, assertInterfaceExists_fn, _transformSnapRpcRequestResult, transformSnapRpcRequestResult_fn, _assertSnapRpcRequestResult, assertSnapRpcRequestResult_fn, _recordSnapRpcRequestStart, recordSnapRpcRequestStart_fn, _recordSnapRpcRequestFinish, recordSnapRpcRequestFinish_fn, _getRollbackSnapshot, getRollbackSnapshot_fn, _createRollbackSnapshot, createRollbackSnapshot_fn, _rollbackSnap, rollbackSnap_fn, _rollbackSnaps, rollbackSnaps_fn, _getRuntime, getRuntime_fn, _getRuntimeExpect, getRuntimeExpect_fn, _setupRuntime, setupRuntime_fn, _calculatePermissionsChange, calculatePermissionsChange_fn, _updatePermissions, updatePermissions_fn, _isValidUpdate, isValidUpdate_fn, _callLifecycleHook, callLifecycleHook_fn;
117
120
  var SnapController = class extends BaseController {
118
121
  constructor({
119
122
  closeAllConnections,
@@ -129,7 +132,9 @@ var SnapController = class extends BaseController {
129
132
  fetchFunction = globalThis.fetch.bind(globalThis),
130
133
  featureFlags = {},
131
134
  detectSnapLocation: detectSnapLocationFunction = detectSnapLocation,
132
- preinstalledSnaps
135
+ preinstalledSnaps,
136
+ encryptor,
137
+ getMnemonic
133
138
  }) {
134
139
  super({
135
140
  messenger,
@@ -218,6 +223,37 @@ var SnapController = class extends BaseController {
218
223
  * @param snapId - The snap to terminate.
219
224
  */
220
225
  __privateAdd(this, _terminateSnap);
226
+ /**
227
+ * Generate an encryption key to be used for state encryption for a given Snap.
228
+ *
229
+ * @param options - An options bag.
230
+ * @param options.snapId - The Snap ID.
231
+ * @param options.salt - A salt to be used for the encryption key.
232
+ * @param options.useCache - Whether to use caching or not.
233
+ * @param options.keyMetadata - Optional metadata about how to derive the encryption key.
234
+ * @returns An encryption key.
235
+ */
236
+ __privateAdd(this, _getSnapEncryptionKey);
237
+ /**
238
+ * Decrypt the encrypted state for a given Snap.
239
+ *
240
+ * @param snapId - The Snap ID.
241
+ * @param state - The encrypted state as a string.
242
+ * @returns A valid JSON object derived from the encrypted state.
243
+ * @throws If the decryption fails or the decrypted state is not valid JSON.
244
+ */
245
+ __privateAdd(this, _decryptSnapState);
246
+ /**
247
+ * Encrypt a JSON state object for a given Snap.
248
+ *
249
+ * Note: This function does not assert the validity of the object,
250
+ * please ensure only valid JSON is passed to it.
251
+ *
252
+ * @param snapId - The Snap ID.
253
+ * @param state - The state object.
254
+ * @returns A string containing the encrypted JSON object.
255
+ */
256
+ __privateAdd(this, _encryptSnapState);
221
257
  __privateAdd(this, _handleInitialConnections);
222
258
  __privateAdd(this, _addSnapToSubject);
223
259
  /**
@@ -406,6 +442,8 @@ var SnapController = class extends BaseController {
406
442
  __privateAdd(this, _idleTimeCheckInterval, void 0);
407
443
  __privateAdd(this, _maxIdleTime, void 0);
408
444
  __privateAdd(this, _maxInitTime, void 0);
445
+ __privateAdd(this, _encryptor, void 0);
446
+ __privateAdd(this, _getMnemonic, void 0);
409
447
  __privateAdd(this, _detectSnapLocation, void 0);
410
448
  __privateAdd(this, _snapsRuntimeData, void 0);
411
449
  __privateAdd(this, _rollbackSnapshots, void 0);
@@ -422,6 +460,8 @@ var SnapController = class extends BaseController {
422
460
  this.maxRequestTime = maxRequestTime;
423
461
  __privateSet(this, _maxInitTime, maxInitTime);
424
462
  __privateSet(this, _detectSnapLocation, detectSnapLocationFunction);
463
+ __privateSet(this, _encryptor, encryptor);
464
+ __privateSet(this, _getMnemonic, getMnemonic);
425
465
  this._onUnhandledSnapError = this._onUnhandledSnapError.bind(this);
426
466
  this._onOutboundRequest = this._onOutboundRequest.bind(this);
427
467
  this._onOutboundResponse = this._onOutboundResponse.bind(this);
@@ -674,14 +714,17 @@ var SnapController = class extends BaseController {
674
714
  * @param newSnapState - The new state of the snap.
675
715
  * @param encrypted - A flag to indicate whether to use encrypted storage or not.
676
716
  */
677
- updateSnapState(snapId, newSnapState, encrypted) {
678
- this.update((state) => {
679
- if (encrypted) {
680
- state.snapStates[snapId] = newSnapState;
681
- } else {
682
- state.unencryptedSnapStates[snapId] = newSnapState;
683
- }
684
- });
717
+ async updateSnapState(snapId, newSnapState, encrypted) {
718
+ if (encrypted) {
719
+ const encryptedState = await __privateMethod(this, _encryptSnapState, encryptSnapState_fn).call(this, snapId, newSnapState);
720
+ this.update((state) => {
721
+ state.snapStates[snapId] = encryptedState;
722
+ });
723
+ } else {
724
+ this.update((state) => {
725
+ state.unencryptedSnapStates[snapId] = JSON.stringify(newSnapState);
726
+ });
727
+ }
685
728
  }
686
729
  /**
687
730
  * Clears the state of the snap with the given id.
@@ -707,9 +750,16 @@ var SnapController = class extends BaseController {
707
750
  * @param encrypted - A flag to indicate whether to use encrypted storage or not.
708
751
  * @returns The requested snap state or null if no state exists.
709
752
  */
710
- getSnapState(snapId, encrypted) {
753
+ async getSnapState(snapId, encrypted) {
711
754
  const state = encrypted ? this.state.snapStates[snapId] : this.state.unencryptedSnapStates[snapId];
712
- return state ?? null;
755
+ if (state === null || state === void 0) {
756
+ return null;
757
+ }
758
+ if (!encrypted) {
759
+ return parseJson(state);
760
+ }
761
+ const decrypted = await __privateMethod(this, _decryptSnapState, decryptSnapState_fn).call(this, snapId, state);
762
+ return decrypted;
713
763
  }
714
764
  /**
715
765
  * Gets a static auxiliary snap file in a chosen file encoding.
@@ -784,6 +834,7 @@ var SnapController = class extends BaseController {
784
834
  this.update((state) => {
785
835
  delete state.snaps[snapId];
786
836
  delete state.snapStates[snapId];
837
+ delete state.unencryptedSnapStates[snapId];
787
838
  });
788
839
  if (snap.status !== SnapStatus.Installing) {
789
840
  this.messagingSystem.publish(
@@ -1136,6 +1187,7 @@ var SnapController = class extends BaseController {
1136
1187
  __privateMethod(this, _validateSnapPermissions, validateSnapPermissions_fn).call(this, processedPermissions);
1137
1188
  const { newPermissions, unusedPermissions, approvedPermissions } = __privateMethod(this, _calculatePermissionsChange, calculatePermissionsChange_fn).call(this, snapId, processedPermissions);
1138
1189
  __privateMethod(this, _updateApproval, updateApproval_fn).call(this, pendingApproval.id, {
1190
+ connections: manifest.initialConnections ?? {},
1139
1191
  permissions: newPermissions,
1140
1192
  newVersion: manifest.version,
1141
1193
  newPermissions,
@@ -1240,12 +1292,13 @@ var SnapController = class extends BaseController {
1240
1292
  log(`Authorizing snap: ${snapId}`);
1241
1293
  const snapsState = this.state.snaps;
1242
1294
  const snap = snapsState[snapId];
1243
- const { initialPermissions } = snap;
1295
+ const { initialPermissions, initialConnections } = snap;
1244
1296
  try {
1245
1297
  const processedPermissions = processSnapPermissions(initialPermissions);
1246
1298
  __privateMethod(this, _validateSnapPermissions, validateSnapPermissions_fn).call(this, processedPermissions);
1247
1299
  __privateMethod(this, _updateApproval, updateApproval_fn).call(this, pendingApproval.id, {
1248
1300
  loading: false,
1301
+ connections: initialConnections ?? {},
1249
1302
  permissions: processedPermissions
1250
1303
  });
1251
1304
  const { permissions: approvedPermissions, ...requestData } = await pendingApproval.promise;
@@ -1358,6 +1411,8 @@ _fetchFunction = new WeakMap();
1358
1411
  _idleTimeCheckInterval = new WeakMap();
1359
1412
  _maxIdleTime = new WeakMap();
1360
1413
  _maxInitTime = new WeakMap();
1414
+ _encryptor = new WeakMap();
1415
+ _getMnemonic = new WeakMap();
1361
1416
  _detectSnapLocation = new WeakMap();
1362
1417
  _snapsRuntimeData = new WeakMap();
1363
1418
  _rollbackSnapshots = new WeakMap();
@@ -1429,7 +1484,7 @@ registerMessageHandlers_fn = function() {
1429
1484
  );
1430
1485
  this.messagingSystem.registerActionHandler(
1431
1486
  `${controllerName}:getSnapState`,
1432
- (...args) => this.getSnapState(...args)
1487
+ async (...args) => this.getSnapState(...args)
1433
1488
  );
1434
1489
  this.messagingSystem.registerActionHandler(
1435
1490
  `${controllerName}:handleRequest`,
@@ -1445,7 +1500,7 @@ registerMessageHandlers_fn = function() {
1445
1500
  );
1446
1501
  this.messagingSystem.registerActionHandler(
1447
1502
  `${controllerName}:updateSnapState`,
1448
- (...args) => this.updateSnapState(...args)
1503
+ async (...args) => this.updateSnapState(...args)
1449
1504
  );
1450
1505
  this.messagingSystem.registerActionHandler(
1451
1506
  `${controllerName}:enable`,
@@ -1648,6 +1703,67 @@ terminateSnap_fn = async function(snapId) {
1648
1703
  this.getTruncatedExpect(snapId)
1649
1704
  );
1650
1705
  };
1706
+ _getSnapEncryptionKey = new WeakSet();
1707
+ getSnapEncryptionKey_fn = async function({
1708
+ snapId,
1709
+ salt: passedSalt,
1710
+ useCache,
1711
+ keyMetadata
1712
+ }) {
1713
+ const runtime = __privateMethod(this, _getRuntimeExpect, getRuntimeExpect_fn).call(this, snapId);
1714
+ if (runtime.encryptionKey && runtime.encryptionSalt && useCache) {
1715
+ return {
1716
+ key: await __privateGet(this, _encryptor).importKey(runtime.encryptionKey),
1717
+ salt: runtime.encryptionSalt
1718
+ };
1719
+ }
1720
+ const salt = passedSalt ?? __privateGet(this, _encryptor).generateSalt();
1721
+ const mnemonicPhrase = await __privateGet(this, _getMnemonic).call(this);
1722
+ const entropy = await getEncryptionEntropy({ snapId, mnemonicPhrase });
1723
+ const encryptionKey = await __privateGet(this, _encryptor).keyFromPassword(
1724
+ entropy,
1725
+ salt,
1726
+ true,
1727
+ keyMetadata
1728
+ );
1729
+ const exportedKey = await __privateGet(this, _encryptor).exportKey(encryptionKey);
1730
+ if (useCache) {
1731
+ runtime.encryptionKey = exportedKey;
1732
+ runtime.encryptionSalt = salt;
1733
+ }
1734
+ return { key: encryptionKey, salt };
1735
+ };
1736
+ _decryptSnapState = new WeakSet();
1737
+ decryptSnapState_fn = async function(snapId, state) {
1738
+ try {
1739
+ const parsed = parseJson(state);
1740
+ const { salt, keyMetadata } = parsed;
1741
+ const useCache = __privateGet(this, _encryptor).isVaultUpdated(state);
1742
+ const { key } = await __privateMethod(this, _getSnapEncryptionKey, getSnapEncryptionKey_fn).call(this, {
1743
+ snapId,
1744
+ salt,
1745
+ useCache,
1746
+ keyMetadata
1747
+ });
1748
+ const decryptedState = await __privateGet(this, _encryptor).decryptWithKey(key, parsed);
1749
+ assert(isValidJson(decryptedState));
1750
+ return decryptedState;
1751
+ } catch {
1752
+ throw rpcErrors.internal({
1753
+ message: "Failed to decrypt snap state, the state must be corrupted."
1754
+ });
1755
+ }
1756
+ };
1757
+ _encryptSnapState = new WeakSet();
1758
+ encryptSnapState_fn = async function(snapId, state) {
1759
+ const { key, salt } = await __privateMethod(this, _getSnapEncryptionKey, getSnapEncryptionKey_fn).call(this, {
1760
+ snapId,
1761
+ useCache: true
1762
+ });
1763
+ const encryptedState = await __privateGet(this, _encryptor).encryptWithKey(key, state);
1764
+ encryptedState.salt = salt;
1765
+ return JSON.stringify(encryptedState);
1766
+ };
1651
1767
  _handleInitialConnections = new WeakSet();
1652
1768
  handleInitialConnections_fn = function(snapId, previousInitialConnections, initialConnections) {
1653
1769
  if (previousInitialConnections) {
@@ -1913,6 +2029,7 @@ set_fn = function(args) {
1913
2029
  removable,
1914
2030
  preinstalled,
1915
2031
  id: snapId,
2032
+ initialConnections: manifest.result.initialConnections,
1916
2033
  initialPermissions: manifest.result.initialPermissions,
1917
2034
  manifest: manifest.result,
1918
2035
  status: __privateGet(this, _statusMachine).config.initial,
@@ -2222,6 +2339,8 @@ setupRuntime_fn = function(snapId) {
2222
2339
  lastRequest: null,
2223
2340
  rpcHandler: null,
2224
2341
  installPromise: null,
2342
+ encryptionKey: null,
2343
+ encryptionSalt: null,
2225
2344
  activeReferences: 0,
2226
2345
  pendingInboundRequests: [],
2227
2346
  pendingOutboundRequests: 0,
@@ -2301,4 +2420,4 @@ export {
2301
2420
  SNAP_APPROVAL_RESULT,
2302
2421
  SnapController
2303
2422
  };
2304
- //# sourceMappingURL=chunk-AXXQZJBW.mjs.map
2423
+ //# sourceMappingURL=chunk-5MVIYRYL.mjs.map