@metamask/profile-sync-controller 4.1.0 → 5.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 +16 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.cjs +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.mjs +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.mjs.map +1 -1
- package/package.json +7 -7
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [5.0.0]
|
|
11
|
+
|
|
12
|
+
### Changed
|
|
13
|
+
|
|
14
|
+
- **BREAKING:** Bump `@metamask/accounts-controller` peer dependency from `^21.0.0` to `^22.0.0` ([#5218](https://github.com/MetaMask/core/pull/5218))
|
|
15
|
+
- Bump `@metamask/keyring-api` from `^14.0.0` to `^16.1.0` ([#5190](https://github.com/MetaMask/core/pull/5190)), ([#5208](https://github.com/MetaMask/core/pull/5208))
|
|
16
|
+
|
|
17
|
+
## [4.1.1]
|
|
18
|
+
|
|
19
|
+
### Changed
|
|
20
|
+
|
|
21
|
+
- Bump `@metamask/keyring-api` from `^13.0.0` to `^14.0.0` ([#5177](https://github.com/MetaMask/core/pull/5177))
|
|
22
|
+
|
|
10
23
|
## [4.1.0]
|
|
11
24
|
|
|
12
25
|
### Changed
|
|
@@ -422,7 +435,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
422
435
|
|
|
423
436
|
- Initial release
|
|
424
437
|
|
|
425
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@
|
|
438
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@5.0.0...HEAD
|
|
439
|
+
[5.0.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@4.1.1...@metamask/profile-sync-controller@5.0.0
|
|
440
|
+
[4.1.1]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@4.1.0...@metamask/profile-sync-controller@4.1.1
|
|
426
441
|
[4.1.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@4.0.1...@metamask/profile-sync-controller@4.1.0
|
|
427
442
|
[4.0.1]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@4.0.0...@metamask/profile-sync-controller@4.0.1
|
|
428
443
|
[4.0.0]: https://github.com/MetaMask/core/compare/@metamask/profile-sync-controller@3.3.0...@metamask/profile-sync-controller@4.0.0
|
|
@@ -15,7 +15,7 @@ const update_network_utils_1 = require("./update-network-utils.cjs");
|
|
|
15
15
|
* Ensures that listeners do not fire during main sync (prevent double requests)
|
|
16
16
|
*/
|
|
17
17
|
// Exported to help testing
|
|
18
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
18
|
+
// eslint-disable-next-line import-x/no-mutable-exports
|
|
19
19
|
exports.isMainNetworkSyncInProgress = false;
|
|
20
20
|
/**
|
|
21
21
|
* Initialize and setup events to listen to for network syncing
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-integration.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/controller-integration.ts"],"names":[],"mappings":";;;;;;AACA,wDAA2B;AAI3B,+DAA8D;AAC9D,6CAAkD;AAClD,6CAAkD;AAClD,yDAAsE;AACtE,qEAAkE;AAiBlE;;;GAGG;AACH,2BAA2B;AAC3B,qDAAqD;AAC1C,QAAA,2BAA2B,GAAG,KAAK,CAAC;AAE/C;;;;;;;;;GASG;AACH,SAAgB,mBAAmB,CAAC,KAA+B;IACjE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,GAAG,KAAK,CAAC;IACrE,IAAI;QACF,SAAS,CAAC,SAAS,CACjB,kCAAkC;Q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AE;gBACjD,IAAI;oBACF,SAAS,CAAC,IAAI,CAAC,iCAAiC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;oBAC7D,gBAAgB,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;iBAC/B;gBAAC,OAAO,CAAC,EAAE;oBACV,gEAAgE;oBAChE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;oBACf,yDAAyD;iBAC1D;YACH,CAAC,CAAC,CAAC;YAEH,+DAA+D;YAC/D,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;gBACrB,kBAAG,CAAC,KAAK,CACP,mEAAmE,EACnE,MAAM,CACP,CAAC;aACH;SACF;KACF;IAAC,OAAO,CAAC,EAAE;QACV,iEAAiE;QACjE,kBAAG,CAAC,KAAK,CAAC,iCAAiC,EAAE,CAAC,CAAC,CAAC;QAChD,qBAAqB;KACtB;YAAS;QACR,mCAA2B,GAAG,KAAK,CAAC;KACrC;AACH,CAAC;AAjJD,wDAiJC","sourcesContent":["import type { NetworkConfiguration } from '@metamask/network-controller';\nimport log from 'loglevel';\n\nimport type { UserStorageBaseOptions } from '../services';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport { getBoundedNetworksToAdd } from './add-network-utils';\nimport { getAllRemoteNetworks } from './services';\nimport { findNetworksToUpdate } from './sync-all';\nimport { batchUpdateNetworks, deleteNetwork } from './sync-mutations';\nimport { createUpdateNetworkProps } from './update-network-utils';\n\ntype StartNetworkSyncingProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n isMutationSyncBlocked: () => boolean;\n};\n\ntype PerformMainNetworkSyncProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n maxNetworksToAdd?: number;\n onNetworkAdded?: (chainId: string) => void;\n onNetworkUpdated?: (chainId: string) => void;\n onNetworkRemoved?: (chainId: string) => void;\n};\n\n/**\n * Global in-mem cache to signify that the network syncing is in progress\n * Ensures that listeners do not fire during main sync (prevent double requests)\n */\n// Exported to help testing\n// eslint-disable-next-line import/no-mutable-exports\nexport let isMainNetworkSyncInProgress = false;\n\n/**\n * Initialize and setup events to listen to for network syncing\n * We will be listening to:\n * - Remove Event, to indicate that we need to remote network from remote\n *\n * We will not be listening to:\n * - Add/Update events are not required, as we can sync these during the main sync\n *\n * @param props - parameters used for initializing and enabling network syncing\n */\nexport function startNetworkSyncing(props: StartNetworkSyncingProps) {\n const { messenger, getStorageConfig, isMutationSyncBlocked } = props;\n try {\n messenger.subscribe(\n 'NetworkController:networkRemoved',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (networkConfiguration) => {\n try {\n // If blocked (e.g. we have not yet performed a main-sync), then we should not perform any mutations\n if (isMutationSyncBlocked()) {\n return;\n }\n\n // As main sync is in progress, it will already local and remote networks\n // So no need to re-process again.\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n await deleteNetwork(networkConfiguration, opts);\n } catch {\n // Silently fail sync\n }\n },\n );\n } catch (e) {\n log.warn('NetworkSyncing, event subscription failed', e);\n }\n}\n\n/**\n * method that will dispatch the `NetworkController:updateNetwork` action.\n * transforms and corrects the network configuration (and RPCs) we pass through.\n * @param props - properties\n * @param props.messenger - messenger to call the action\n * @param props.originalNetworkConfiguration - original network config (from network controller state)\n * @param props.newNetworkConfiguration - new network config (from remote)\n * @param props.selectedNetworkClientId - currently selected network client id\n */\nexport const dispatchUpdateNetwork = async (props: {\n messenger: UserStorageControllerMessenger;\n originalNetworkConfiguration: NetworkConfiguration;\n newNetworkConfiguration: NetworkConfiguration;\n selectedNetworkClientId: string;\n}) => {\n const {\n messenger,\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n } = props;\n\n const { updateNetworkFields, newSelectedRpcEndpointIndex } =\n createUpdateNetworkProps({\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n });\n\n await messenger.call(\n 'NetworkController:updateNetwork',\n updateNetworkFields.chainId,\n updateNetworkFields,\n { replacementSelectedRpcEndpointIndex: newSelectedRpcEndpointIndex },\n );\n};\n\n/**\n * Action to perform the main network sync.\n * It will fetch local networks and remote networks, then determines which networks (local and remote) to add/update\n * @param props - parameters used for this main sync\n */\nexport async function performMainNetworkSync(\n props: PerformMainNetworkSyncProps,\n) {\n const {\n messenger,\n getStorageConfig,\n maxNetworksToAdd,\n onNetworkAdded,\n onNetworkRemoved,\n onNetworkUpdated,\n } = props;\n\n // Edge-Case, we do not want to re-run the main-sync if it already is in progress\n /* istanbul ignore if - this is not testable */\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n isMainNetworkSyncInProgress = true;\n try {\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n\n const networkControllerState = messenger.call('NetworkController:getState');\n const localNetworks = Object.values(\n networkControllerState.networkConfigurationsByChainId ?? {},\n );\n\n const remoteNetworks = await getAllRemoteNetworks(opts);\n const networkChanges = findNetworksToUpdate({\n localNetworks,\n remoteNetworks,\n });\n\n log.debug('performMainNetworkSync() - Network Syncing Started', {\n localNetworks,\n remoteNetworks,\n networkChanges,\n });\n\n // Update Remote\n if (\n networkChanges?.remoteNetworksToUpdate &&\n networkChanges.remoteNetworksToUpdate.length > 0\n ) {\n await batchUpdateNetworks(networkChanges?.remoteNetworksToUpdate, opts);\n }\n\n // Add missing local networks\n const boundedNetworkedToAdd =\n networkChanges?.missingLocalNetworks &&\n getBoundedNetworksToAdd(\n localNetworks,\n networkChanges.missingLocalNetworks,\n maxNetworksToAdd,\n );\n if (boundedNetworkedToAdd && boundedNetworkedToAdd.length > 0) {\n const errors: unknown[] = [];\n boundedNetworkedToAdd.forEach((n) => {\n try {\n messenger.call('NetworkController:addNetwork', n);\n onNetworkAdded?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:addNetwork failures',\n errors,\n );\n }\n }\n\n // Update local networks\n if (\n networkChanges?.localNetworksToUpdate &&\n networkChanges.localNetworksToUpdate.length > 0\n ) {\n const errors: unknown[] = [];\n for (const n of networkChanges.localNetworksToUpdate) {\n try {\n await dispatchUpdateNetwork({\n messenger,\n originalNetworkConfiguration:\n networkControllerState.networkConfigurationsByChainId[n.chainId],\n newNetworkConfiguration: n,\n selectedNetworkClientId:\n networkControllerState.selectedNetworkClientId,\n });\n onNetworkUpdated?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n }\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:updateNetwork failed',\n errors,\n );\n }\n }\n\n // Remove local networks\n if (\n networkChanges?.localNetworksToRemove &&\n networkChanges.localNetworksToRemove.length > 0\n ) {\n const errors: unknown[] = [];\n networkChanges.localNetworksToRemove.forEach((n) => {\n try {\n messenger.call('NetworkController:removeNetwork', n.chainId);\n onNetworkRemoved?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:removeNetwork failed',\n errors,\n );\n }\n }\n } catch (e) {\n /* istanbul ignore next - only logs errors, not useful to test */\n log.error('performMainNetworkSync() failed', e);\n // Silently fail sync\n } finally {\n isMainNetworkSyncInProgress = false;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"controller-integration.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/controller-integration.ts"],"names":[],"mappings":";;;;;;AACA,wDAA2B;AAI3B,+DAA8D;AAC9D,6CAAkD;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MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;gBACrB,kBAAG,CAAC,KAAK,CACP,mEAAmE,EACnE,MAAM,CACP,CAAC;aACH;SACF;QAED,wBAAwB;QACxB,IACE,cAAc,EAAE,qBAAqB;YACrC,cAAc,CAAC,qBAAqB,CAAC,MAAM,GAAG,CAAC,EAC/C;YACA,MAAM,MAAM,GAAc,EAAE,CAAC;YAC7B,cAAc,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;gBACjD,IAAI;oBACF,SAAS,CAAC,IAAI,CAAC,iCAAiC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;oBAC7D,gBAAgB,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;iBAC/B;gBAAC,OAAO,CAAC,EAAE;oBACV,gEAAgE;oBAChE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;oBACf,yDAAyD;iBAC1D;YACH,CAAC,CAAC,CAAC;YAEH,+DAA+D;YAC/D,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;gBACrB,kBAAG,CAAC,KAAK,CACP,mEAAmE,EACnE,MAAM,CACP,CAAC;aACH;SACF;KACF;IAAC,OAAO,CAAC,EAAE;QACV,iEAAiE;QACjE,kBAAG,CAAC,KAAK,CAAC,iCAAiC,EAAE,CAAC,CAAC,CAAC;QAChD,qBAAqB;KACtB;YAAS;QACR,mCAA2B,GAAG,KAAK,CAAC;KACrC;AACH,CAAC;AAjJD,wDAiJC","sourcesContent":["import type { NetworkConfiguration } from '@metamask/network-controller';\nimport log from 'loglevel';\n\nimport type { UserStorageBaseOptions } from '../services';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport { getBoundedNetworksToAdd } from './add-network-utils';\nimport { getAllRemoteNetworks } from './services';\nimport { findNetworksToUpdate } from './sync-all';\nimport { batchUpdateNetworks, deleteNetwork } from './sync-mutations';\nimport { createUpdateNetworkProps } from './update-network-utils';\n\ntype StartNetworkSyncingProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n isMutationSyncBlocked: () => boolean;\n};\n\ntype PerformMainNetworkSyncProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n maxNetworksToAdd?: number;\n onNetworkAdded?: (chainId: string) => void;\n onNetworkUpdated?: (chainId: string) => void;\n onNetworkRemoved?: (chainId: string) => void;\n};\n\n/**\n * Global in-mem cache to signify that the network syncing is in progress\n * Ensures that listeners do not fire during main sync (prevent double requests)\n */\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let isMainNetworkSyncInProgress = false;\n\n/**\n * Initialize and setup events to listen to for network syncing\n * We will be listening to:\n * - Remove Event, to indicate that we need to remote network from remote\n *\n * We will not be listening to:\n * - Add/Update events are not required, as we can sync these during the main sync\n *\n * @param props - parameters used for initializing and enabling network syncing\n */\nexport function startNetworkSyncing(props: StartNetworkSyncingProps) {\n const { messenger, getStorageConfig, isMutationSyncBlocked } = props;\n try {\n messenger.subscribe(\n 'NetworkController:networkRemoved',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (networkConfiguration) => {\n try {\n // If blocked (e.g. we have not yet performed a main-sync), then we should not perform any mutations\n if (isMutationSyncBlocked()) {\n return;\n }\n\n // As main sync is in progress, it will already local and remote networks\n // So no need to re-process again.\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n await deleteNetwork(networkConfiguration, opts);\n } catch {\n // Silently fail sync\n }\n },\n );\n } catch (e) {\n log.warn('NetworkSyncing, event subscription failed', e);\n }\n}\n\n/**\n * method that will dispatch the `NetworkController:updateNetwork` action.\n * transforms and corrects the network configuration (and RPCs) we pass through.\n * @param props - properties\n * @param props.messenger - messenger to call the action\n * @param props.originalNetworkConfiguration - original network config (from network controller state)\n * @param props.newNetworkConfiguration - new network config (from remote)\n * @param props.selectedNetworkClientId - currently selected network client id\n */\nexport const dispatchUpdateNetwork = async (props: {\n messenger: UserStorageControllerMessenger;\n originalNetworkConfiguration: NetworkConfiguration;\n newNetworkConfiguration: NetworkConfiguration;\n selectedNetworkClientId: string;\n}) => {\n const {\n messenger,\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n } = props;\n\n const { updateNetworkFields, newSelectedRpcEndpointIndex } =\n createUpdateNetworkProps({\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n });\n\n await messenger.call(\n 'NetworkController:updateNetwork',\n updateNetworkFields.chainId,\n updateNetworkFields,\n { replacementSelectedRpcEndpointIndex: newSelectedRpcEndpointIndex },\n );\n};\n\n/**\n * Action to perform the main network sync.\n * It will fetch local networks and remote networks, then determines which networks (local and remote) to add/update\n * @param props - parameters used for this main sync\n */\nexport async function performMainNetworkSync(\n props: PerformMainNetworkSyncProps,\n) {\n const {\n messenger,\n getStorageConfig,\n maxNetworksToAdd,\n onNetworkAdded,\n onNetworkRemoved,\n onNetworkUpdated,\n } = props;\n\n // Edge-Case, we do not want to re-run the main-sync if it already is in progress\n /* istanbul ignore if - this is not testable */\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n isMainNetworkSyncInProgress = true;\n try {\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n\n const networkControllerState = messenger.call('NetworkController:getState');\n const localNetworks = Object.values(\n networkControllerState.networkConfigurationsByChainId ?? {},\n );\n\n const remoteNetworks = await getAllRemoteNetworks(opts);\n const networkChanges = findNetworksToUpdate({\n localNetworks,\n remoteNetworks,\n });\n\n log.debug('performMainNetworkSync() - Network Syncing Started', {\n localNetworks,\n remoteNetworks,\n networkChanges,\n });\n\n // Update Remote\n if (\n networkChanges?.remoteNetworksToUpdate &&\n networkChanges.remoteNetworksToUpdate.length > 0\n ) {\n await batchUpdateNetworks(networkChanges?.remoteNetworksToUpdate, opts);\n }\n\n // Add missing local networks\n const boundedNetworkedToAdd =\n networkChanges?.missingLocalNetworks &&\n getBoundedNetworksToAdd(\n localNetworks,\n networkChanges.missingLocalNetworks,\n maxNetworksToAdd,\n );\n if (boundedNetworkedToAdd && boundedNetworkedToAdd.length > 0) {\n const errors: unknown[] = [];\n boundedNetworkedToAdd.forEach((n) => {\n try {\n messenger.call('NetworkController:addNetwork', n);\n onNetworkAdded?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:addNetwork failures',\n errors,\n );\n }\n }\n\n // Update local networks\n if (\n networkChanges?.localNetworksToUpdate &&\n networkChanges.localNetworksToUpdate.length > 0\n ) {\n const errors: unknown[] = [];\n for (const n of networkChanges.localNetworksToUpdate) {\n try {\n await dispatchUpdateNetwork({\n messenger,\n originalNetworkConfiguration:\n networkControllerState.networkConfigurationsByChainId[n.chainId],\n newNetworkConfiguration: n,\n selectedNetworkClientId:\n networkControllerState.selectedNetworkClientId,\n });\n onNetworkUpdated?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n }\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:updateNetwork failed',\n errors,\n );\n }\n }\n\n // Remove local networks\n if (\n networkChanges?.localNetworksToRemove &&\n networkChanges.localNetworksToRemove.length > 0\n ) {\n const errors: unknown[] = [];\n networkChanges.localNetworksToRemove.forEach((n) => {\n try {\n messenger.call('NetworkController:removeNetwork', n.chainId);\n onNetworkRemoved?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:removeNetwork failed',\n errors,\n );\n }\n }\n } catch (e) {\n /* istanbul ignore next - only logs errors, not useful to test */\n log.error('performMainNetworkSync() failed', e);\n // Silently fail sync\n } finally {\n isMainNetworkSyncInProgress = false;\n }\n}\n"]}
|
|
@@ -16,7 +16,7 @@ import { createUpdateNetworkProps } from "./update-network-utils.mjs";
|
|
|
16
16
|
* Ensures that listeners do not fire during main sync (prevent double requests)
|
|
17
17
|
*/
|
|
18
18
|
// Exported to help testing
|
|
19
|
-
// eslint-disable-next-line import/no-mutable-exports
|
|
19
|
+
// eslint-disable-next-line import-x/no-mutable-exports
|
|
20
20
|
export let isMainNetworkSyncInProgress = false;
|
|
21
21
|
/**
|
|
22
22
|
* Initialize and setup events to listen to for network syncing
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-integration.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/controller-integration.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,IAAG,iBAAiB;;AAI3B,OAAO,EAAE,uBAAuB,EAAE,gCAA4B;AAC9D,OAAO,EAAE,oBAAoB,EAAE,uBAAmB;AAClD,OAAO,EAAE,oBAAoB,EAAE,uBAAmB;AAClD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,6BAAyB;AACtE,OAAO,EAAE,wBAAwB,EAAE,mCAA+B;AAiBlE;;;GAGG;AACH,2BAA2B;AAC3B,qDAAqD;AACrD,MAAM,CAAC,IAAI,2BAA2B,GAAG,KAAK,CAAC;AAE/C;;;;;;;;;GASG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAA+B;IACjE,MAAM,EAAE,SAAS,EAAE,gBAAgB,EAAE,qBAAqB,EAAE,GAAG,KAAK,CAAC;IACrE,IAAI;QACF,SAAS,CAAC,SAAS,CACjB,kCAAkC;QAClC,kEAAkE;QAClE,KAAK,EAAE,oBAAoB,EAAE,EAAE;YAC7B,IAAI;gBACF,oGAAoG;gBACpG,IAAI,qBAAqB,E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AAC,EAAE;oBACV,gEAAgE;oBAChE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;oBACf,yDAAyD;iBAC1D;YACH,CAAC,CAAC,CAAC;YAEH,+DAA+D;YAC/D,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;gBACrB,GAAG,CAAC,KAAK,CACP,mEAAmE,EACnE,MAAM,CACP,CAAC;aACH;SACF;KACF;IAAC,OAAO,CAAC,EAAE;QACV,iEAAiE;QACjE,GAAG,CAAC,KAAK,CAAC,iCAAiC,EAAE,CAAC,CAAC,CAAC;QAChD,qBAAqB;KACtB;YAAS;QACR,2BAA2B,GAAG,KAAK,CAAC;KACrC;AACH,CAAC","sourcesContent":["import type { NetworkConfiguration } from '@metamask/network-controller';\nimport log from 'loglevel';\n\nimport type { UserStorageBaseOptions } from '../services';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport { getBoundedNetworksToAdd } from './add-network-utils';\nimport { getAllRemoteNetworks } from './services';\nimport { findNetworksToUpdate } from './sync-all';\nimport { batchUpdateNetworks, deleteNetwork } from './sync-mutations';\nimport { createUpdateNetworkProps } from './update-network-utils';\n\ntype StartNetworkSyncingProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n isMutationSyncBlocked: () => boolean;\n};\n\ntype PerformMainNetworkSyncProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n maxNetworksToAdd?: number;\n onNetworkAdded?: (chainId: string) => void;\n onNetworkUpdated?: (chainId: string) => void;\n onNetworkRemoved?: (chainId: string) => void;\n};\n\n/**\n * Global in-mem cache to signify that the network syncing is in progress\n * Ensures that listeners do not fire during main sync (prevent double requests)\n */\n// Exported to help testing\n// eslint-disable-next-line import/no-mutable-exports\nexport let isMainNetworkSyncInProgress = false;\n\n/**\n * Initialize and setup events to listen to for network syncing\n * We will be listening to:\n * - Remove Event, to indicate that we need to remote network from remote\n *\n * We will not be listening to:\n * - Add/Update events are not required, as we can sync these during the main sync\n *\n * @param props - parameters used for initializing and enabling network syncing\n */\nexport function startNetworkSyncing(props: StartNetworkSyncingProps) {\n const { messenger, getStorageConfig, isMutationSyncBlocked } = props;\n try {\n messenger.subscribe(\n 'NetworkController:networkRemoved',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (networkConfiguration) => {\n try {\n // If blocked (e.g. we have not yet performed a main-sync), then we should not perform any mutations\n if (isMutationSyncBlocked()) {\n return;\n }\n\n // As main sync is in progress, it will already local and remote networks\n // So no need to re-process again.\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n await deleteNetwork(networkConfiguration, opts);\n } catch {\n // Silently fail sync\n }\n },\n );\n } catch (e) {\n log.warn('NetworkSyncing, event subscription failed', e);\n }\n}\n\n/**\n * method that will dispatch the `NetworkController:updateNetwork` action.\n * transforms and corrects the network configuration (and RPCs) we pass through.\n * @param props - properties\n * @param props.messenger - messenger to call the action\n * @param props.originalNetworkConfiguration - original network config (from network controller state)\n * @param props.newNetworkConfiguration - new network config (from remote)\n * @param props.selectedNetworkClientId - currently selected network client id\n */\nexport const dispatchUpdateNetwork = async (props: {\n messenger: UserStorageControllerMessenger;\n originalNetworkConfiguration: NetworkConfiguration;\n newNetworkConfiguration: NetworkConfiguration;\n selectedNetworkClientId: string;\n}) => {\n const {\n messenger,\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n } = props;\n\n const { updateNetworkFields, newSelectedRpcEndpointIndex } =\n createUpdateNetworkProps({\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n });\n\n await messenger.call(\n 'NetworkController:updateNetwork',\n updateNetworkFields.chainId,\n updateNetworkFields,\n { replacementSelectedRpcEndpointIndex: newSelectedRpcEndpointIndex },\n );\n};\n\n/**\n * Action to perform the main network sync.\n * It will fetch local networks and remote networks, then determines which networks (local and remote) to add/update\n * @param props - parameters used for this main sync\n */\nexport async function performMainNetworkSync(\n props: PerformMainNetworkSyncProps,\n) {\n const {\n messenger,\n getStorageConfig,\n maxNetworksToAdd,\n onNetworkAdded,\n onNetworkRemoved,\n onNetworkUpdated,\n } = props;\n\n // Edge-Case, we do not want to re-run the main-sync if it already is in progress\n /* istanbul ignore if - this is not testable */\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n isMainNetworkSyncInProgress = true;\n try {\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n\n const networkControllerState = messenger.call('NetworkController:getState');\n const localNetworks = Object.values(\n networkControllerState.networkConfigurationsByChainId ?? {},\n );\n\n const remoteNetworks = await getAllRemoteNetworks(opts);\n const networkChanges = findNetworksToUpdate({\n localNetworks,\n remoteNetworks,\n });\n\n log.debug('performMainNetworkSync() - Network Syncing Started', {\n localNetworks,\n remoteNetworks,\n networkChanges,\n });\n\n // Update Remote\n if (\n networkChanges?.remoteNetworksToUpdate &&\n networkChanges.remoteNetworksToUpdate.length > 0\n ) {\n await batchUpdateNetworks(networkChanges?.remoteNetworksToUpdate, opts);\n }\n\n // Add missing local networks\n const boundedNetworkedToAdd =\n networkChanges?.missingLocalNetworks &&\n getBoundedNetworksToAdd(\n localNetworks,\n networkChanges.missingLocalNetworks,\n maxNetworksToAdd,\n );\n if (boundedNetworkedToAdd && boundedNetworkedToAdd.length > 0) {\n const errors: unknown[] = [];\n boundedNetworkedToAdd.forEach((n) => {\n try {\n messenger.call('NetworkController:addNetwork', n);\n onNetworkAdded?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:addNetwork failures',\n errors,\n );\n }\n }\n\n // Update local networks\n if (\n networkChanges?.localNetworksToUpdate &&\n networkChanges.localNetworksToUpdate.length > 0\n ) {\n const errors: unknown[] = [];\n for (const n of networkChanges.localNetworksToUpdate) {\n try {\n await dispatchUpdateNetwork({\n messenger,\n originalNetworkConfiguration:\n networkControllerState.networkConfigurationsByChainId[n.chainId],\n newNetworkConfiguration: n,\n selectedNetworkClientId:\n networkControllerState.selectedNetworkClientId,\n });\n onNetworkUpdated?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n }\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:updateNetwork failed',\n errors,\n );\n }\n }\n\n // Remove local networks\n if (\n networkChanges?.localNetworksToRemove &&\n networkChanges.localNetworksToRemove.length > 0\n ) {\n const errors: unknown[] = [];\n networkChanges.localNetworksToRemove.forEach((n) => {\n try {\n messenger.call('NetworkController:removeNetwork', n.chainId);\n onNetworkRemoved?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:removeNetwork failed',\n errors,\n );\n }\n }\n } catch (e) {\n /* istanbul ignore next - only logs errors, not useful to test */\n log.error('performMainNetworkSync() failed', e);\n // Silently fail sync\n } finally {\n isMainNetworkSyncInProgress = false;\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"controller-integration.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/network-syncing/controller-integration.ts"],"names":[],"mappings":";;;;;;AACA,OAAO,IAAG,iBAAiB;;AAI3B,OAAO,EAAE,uBAAuB,EAAE,gCAA4B;AAC9D,OAAO,EAAE,oBAAoB,EAAE,uBAAmB;AAClD,OAAO,EAAE,oBAAoB,EAAE,uBAAmB;AAClD,OAAO,EAAE,mBAAmB,EAAE,aAAa,EAAE,6BAAyB;AACtE,OAAO,EAAE,wBAAwB,EAAE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ACP,CAAC;aACH;SACF;QAED,wBAAwB;QACxB,IACE,cAAc,EAAE,qBAAqB;YACrC,cAAc,CAAC,qBAAqB,CAAC,MAAM,GAAG,CAAC,EAC/C;YACA,MAAM,MAAM,GAAc,EAAE,CAAC;YAC7B,cAAc,CAAC,qBAAqB,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE;gBACjD,IAAI;oBACF,SAAS,CAAC,IAAI,CAAC,iCAAiC,EAAE,CAAC,CAAC,OAAO,CAAC,CAAC;oBAC7D,gBAAgB,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;iBAC/B;gBAAC,OAAO,CAAC,EAAE;oBACV,gEAAgE;oBAChE,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;oBACf,yDAAyD;iBAC1D;YACH,CAAC,CAAC,CAAC;YAEH,+DAA+D;YAC/D,IAAI,MAAM,CAAC,MAAM,GAAG,CAAC,EAAE;gBACrB,GAAG,CAAC,KAAK,CACP,mEAAmE,EACnE,MAAM,CACP,CAAC;aACH;SACF;KACF;IAAC,OAAO,CAAC,EAAE;QACV,iEAAiE;QACjE,GAAG,CAAC,KAAK,CAAC,iCAAiC,EAAE,CAAC,CAAC,CAAC;QAChD,qBAAqB;KACtB;YAAS;QACR,2BAA2B,GAAG,KAAK,CAAC;KACrC;AACH,CAAC","sourcesContent":["import type { NetworkConfiguration } from '@metamask/network-controller';\nimport log from 'loglevel';\n\nimport type { UserStorageBaseOptions } from '../services';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport { getBoundedNetworksToAdd } from './add-network-utils';\nimport { getAllRemoteNetworks } from './services';\nimport { findNetworksToUpdate } from './sync-all';\nimport { batchUpdateNetworks, deleteNetwork } from './sync-mutations';\nimport { createUpdateNetworkProps } from './update-network-utils';\n\ntype StartNetworkSyncingProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n isMutationSyncBlocked: () => boolean;\n};\n\ntype PerformMainNetworkSyncProps = {\n messenger: UserStorageControllerMessenger;\n getStorageConfig: () => Promise<UserStorageBaseOptions | null>;\n maxNetworksToAdd?: number;\n onNetworkAdded?: (chainId: string) => void;\n onNetworkUpdated?: (chainId: string) => void;\n onNetworkRemoved?: (chainId: string) => void;\n};\n\n/**\n * Global in-mem cache to signify that the network syncing is in progress\n * Ensures that listeners do not fire during main sync (prevent double requests)\n */\n// Exported to help testing\n// eslint-disable-next-line import-x/no-mutable-exports\nexport let isMainNetworkSyncInProgress = false;\n\n/**\n * Initialize and setup events to listen to for network syncing\n * We will be listening to:\n * - Remove Event, to indicate that we need to remote network from remote\n *\n * We will not be listening to:\n * - Add/Update events are not required, as we can sync these during the main sync\n *\n * @param props - parameters used for initializing and enabling network syncing\n */\nexport function startNetworkSyncing(props: StartNetworkSyncingProps) {\n const { messenger, getStorageConfig, isMutationSyncBlocked } = props;\n try {\n messenger.subscribe(\n 'NetworkController:networkRemoved',\n // eslint-disable-next-line @typescript-eslint/no-misused-promises\n async (networkConfiguration) => {\n try {\n // If blocked (e.g. we have not yet performed a main-sync), then we should not perform any mutations\n if (isMutationSyncBlocked()) {\n return;\n }\n\n // As main sync is in progress, it will already local and remote networks\n // So no need to re-process again.\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n await deleteNetwork(networkConfiguration, opts);\n } catch {\n // Silently fail sync\n }\n },\n );\n } catch (e) {\n log.warn('NetworkSyncing, event subscription failed', e);\n }\n}\n\n/**\n * method that will dispatch the `NetworkController:updateNetwork` action.\n * transforms and corrects the network configuration (and RPCs) we pass through.\n * @param props - properties\n * @param props.messenger - messenger to call the action\n * @param props.originalNetworkConfiguration - original network config (from network controller state)\n * @param props.newNetworkConfiguration - new network config (from remote)\n * @param props.selectedNetworkClientId - currently selected network client id\n */\nexport const dispatchUpdateNetwork = async (props: {\n messenger: UserStorageControllerMessenger;\n originalNetworkConfiguration: NetworkConfiguration;\n newNetworkConfiguration: NetworkConfiguration;\n selectedNetworkClientId: string;\n}) => {\n const {\n messenger,\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n } = props;\n\n const { updateNetworkFields, newSelectedRpcEndpointIndex } =\n createUpdateNetworkProps({\n originalNetworkConfiguration,\n newNetworkConfiguration,\n selectedNetworkClientId,\n });\n\n await messenger.call(\n 'NetworkController:updateNetwork',\n updateNetworkFields.chainId,\n updateNetworkFields,\n { replacementSelectedRpcEndpointIndex: newSelectedRpcEndpointIndex },\n );\n};\n\n/**\n * Action to perform the main network sync.\n * It will fetch local networks and remote networks, then determines which networks (local and remote) to add/update\n * @param props - parameters used for this main sync\n */\nexport async function performMainNetworkSync(\n props: PerformMainNetworkSyncProps,\n) {\n const {\n messenger,\n getStorageConfig,\n maxNetworksToAdd,\n onNetworkAdded,\n onNetworkRemoved,\n onNetworkUpdated,\n } = props;\n\n // Edge-Case, we do not want to re-run the main-sync if it already is in progress\n /* istanbul ignore if - this is not testable */\n if (isMainNetworkSyncInProgress) {\n return;\n }\n\n isMainNetworkSyncInProgress = true;\n try {\n const opts = await getStorageConfig();\n if (!opts) {\n return;\n }\n\n const networkControllerState = messenger.call('NetworkController:getState');\n const localNetworks = Object.values(\n networkControllerState.networkConfigurationsByChainId ?? {},\n );\n\n const remoteNetworks = await getAllRemoteNetworks(opts);\n const networkChanges = findNetworksToUpdate({\n localNetworks,\n remoteNetworks,\n });\n\n log.debug('performMainNetworkSync() - Network Syncing Started', {\n localNetworks,\n remoteNetworks,\n networkChanges,\n });\n\n // Update Remote\n if (\n networkChanges?.remoteNetworksToUpdate &&\n networkChanges.remoteNetworksToUpdate.length > 0\n ) {\n await batchUpdateNetworks(networkChanges?.remoteNetworksToUpdate, opts);\n }\n\n // Add missing local networks\n const boundedNetworkedToAdd =\n networkChanges?.missingLocalNetworks &&\n getBoundedNetworksToAdd(\n localNetworks,\n networkChanges.missingLocalNetworks,\n maxNetworksToAdd,\n );\n if (boundedNetworkedToAdd && boundedNetworkedToAdd.length > 0) {\n const errors: unknown[] = [];\n boundedNetworkedToAdd.forEach((n) => {\n try {\n messenger.call('NetworkController:addNetwork', n);\n onNetworkAdded?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:addNetwork failures',\n errors,\n );\n }\n }\n\n // Update local networks\n if (\n networkChanges?.localNetworksToUpdate &&\n networkChanges.localNetworksToUpdate.length > 0\n ) {\n const errors: unknown[] = [];\n for (const n of networkChanges.localNetworksToUpdate) {\n try {\n await dispatchUpdateNetwork({\n messenger,\n originalNetworkConfiguration:\n networkControllerState.networkConfigurationsByChainId[n.chainId],\n newNetworkConfiguration: n,\n selectedNetworkClientId:\n networkControllerState.selectedNetworkClientId,\n });\n onNetworkUpdated?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n }\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:updateNetwork failed',\n errors,\n );\n }\n }\n\n // Remove local networks\n if (\n networkChanges?.localNetworksToRemove &&\n networkChanges.localNetworksToRemove.length > 0\n ) {\n const errors: unknown[] = [];\n networkChanges.localNetworksToRemove.forEach((n) => {\n try {\n messenger.call('NetworkController:removeNetwork', n.chainId);\n onNetworkRemoved?.(n.chainId);\n } catch (e) {\n /* istanbul ignore next - allocates logs, do not need to test */\n errors.push(e);\n // Silently fail, we can try this again on next main sync\n }\n });\n\n /* istanbul ignore if - only logs errors, not useful to test */\n if (errors.length > 0) {\n log.error(\n 'performMainNetworkSync() - NetworkController:removeNetwork failed',\n errors,\n );\n }\n }\n } catch (e) {\n /* istanbul ignore next - only logs errors, not useful to test */\n log.error('performMainNetworkSync() failed', e);\n // Silently fail sync\n } finally {\n isMainNetworkSyncInProgress = false;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/profile-sync-controller",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "5.0.0",
|
|
4
4
|
"description": "The profile sync helps developers synchronize data across multiple clients and devices in a privacy-preserving way. All data saved in the user storage database is encrypted client-side to preserve privacy. The user storage provides a modular design, giving developers the flexibility to construct and manage their storage spaces in a way that best suits their needs",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -101,11 +101,11 @@
|
|
|
101
101
|
},
|
|
102
102
|
"dependencies": {
|
|
103
103
|
"@metamask/base-controller": "^7.1.1",
|
|
104
|
-
"@metamask/keyring-api": "^
|
|
105
|
-
"@metamask/keyring-controller": "^19.0.
|
|
104
|
+
"@metamask/keyring-api": "^16.1.0",
|
|
105
|
+
"@metamask/keyring-controller": "^19.0.5",
|
|
106
106
|
"@metamask/network-controller": "^22.1.1",
|
|
107
107
|
"@metamask/snaps-sdk": "^6.7.0",
|
|
108
|
-
"@metamask/snaps-utils": "^8.
|
|
108
|
+
"@metamask/snaps-utils": "^8.9.0",
|
|
109
109
|
"@noble/ciphers": "^0.5.2",
|
|
110
110
|
"@noble/hashes": "^1.4.0",
|
|
111
111
|
"immer": "^9.0.6",
|
|
@@ -115,9 +115,9 @@
|
|
|
115
115
|
"devDependencies": {
|
|
116
116
|
"@lavamoat/allow-scripts": "^3.0.4",
|
|
117
117
|
"@lavamoat/preinstall-always-fail": "^2.1.0",
|
|
118
|
-
"@metamask/accounts-controller": "^
|
|
118
|
+
"@metamask/accounts-controller": "^22.0.0",
|
|
119
119
|
"@metamask/auto-changelog": "^3.4.4",
|
|
120
|
-
"@metamask/keyring-internal-api": "^
|
|
120
|
+
"@metamask/keyring-internal-api": "^4.0.1",
|
|
121
121
|
"@metamask/providers": "^18.1.1",
|
|
122
122
|
"@metamask/snaps-controllers": "^9.10.0",
|
|
123
123
|
"@types/jest": "^27.4.1",
|
|
@@ -133,7 +133,7 @@
|
|
|
133
133
|
"webextension-polyfill": "^0.12.0"
|
|
134
134
|
},
|
|
135
135
|
"peerDependencies": {
|
|
136
|
-
"@metamask/accounts-controller": "^
|
|
136
|
+
"@metamask/accounts-controller": "^22.0.0",
|
|
137
137
|
"@metamask/keyring-controller": "^19.0.0",
|
|
138
138
|
"@metamask/network-controller": "^22.0.0",
|
|
139
139
|
"@metamask/providers": "^18.1.0",
|