@metamask/profile-sync-controller 4.1.1 → 6.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 +28 -1
- package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.cts +2 -2
- package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.mts +2 -2
- package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
- package/dist/controllers/authentication/__fixtures__/mockResponses.cjs +0 -5
- package/dist/controllers/authentication/__fixtures__/mockResponses.cjs.map +1 -1
- package/dist/controllers/authentication/__fixtures__/mockResponses.d.cts.map +1 -1
- package/dist/controllers/authentication/__fixtures__/mockResponses.d.mts.map +1 -1
- package/dist/controllers/authentication/__fixtures__/mockResponses.mjs +0 -5
- package/dist/controllers/authentication/__fixtures__/mockResponses.mjs.map +1 -1
- package/dist/controllers/authentication/services.cjs +0 -2
- package/dist/controllers/authentication/services.cjs.map +1 -1
- package/dist/controllers/authentication/services.d.cts +5 -3
- package/dist/controllers/authentication/services.d.cts.map +1 -1
- package/dist/controllers/authentication/services.d.mts +5 -3
- package/dist/controllers/authentication/services.d.mts.map +1 -1
- package/dist/controllers/authentication/services.mjs +0 -2
- package/dist/controllers/authentication/services.mjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.cjs +11 -42
- package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.cts +8 -15
- package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.mts +8 -15
- package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.mjs +11 -42
- package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.cjs +3 -15
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.cjs.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.cts +10 -10
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.cts.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.mts +10 -10
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.mts.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.mjs +4 -16
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.mjs.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.cjs +5 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.cjs.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.d.cts +4 -0
- package/dist/controllers/user-storage/__fixtures__/mockResponses.d.cts.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.d.mts +4 -0
- package/dist/controllers/user-storage/__fixtures__/mockResponses.d.mts.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.mjs +5 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.mjs.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockServices.cjs +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockServices.cjs.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockServices.d.cts.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockServices.d.mts.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockServices.mjs +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockServices.mjs.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.cjs +5 -2
- package/dist/controllers/user-storage/__fixtures__/test-utils.cjs.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts +3 -0
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts +3 -0
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.mjs +5 -2
- package/dist/controllers/user-storage/__fixtures__/test-utils.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.cjs +2 -0
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.cts +1 -0
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.cts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.mts +1 -0
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.mts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.mjs +2 -0
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs +3 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts +5 -5
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts +5 -5
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs +3 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +4 -2
- package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts +3 -0
- package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts +3 -0
- package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +4 -2
- package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs +3 -6
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts +1 -0
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.cts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts +1 -0
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.d.mts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs +3 -6
- package/dist/controllers/user-storage/account-syncing/setup-subscriptions.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.cjs +6 -2
- package/dist/controllers/user-storage/account-syncing/sync-utils.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts +5 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts +5 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.mjs +6 -2
- package/dist/controllers/user-storage/account-syncing/sync-utils.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/types.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/types.d.cts +1 -1
- package/dist/controllers/user-storage/account-syncing/types.d.cts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/types.d.mts +1 -1
- package/dist/controllers/user-storage/account-syncing/types.d.mts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/types.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/utils.cjs +3 -1
- package/dist/controllers/user-storage/account-syncing/utils.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/utils.d.cts +2 -0
- package/dist/controllers/user-storage/account-syncing/utils.d.cts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/utils.d.mts +2 -0
- package/dist/controllers/user-storage/account-syncing/utils.d.mts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/utils.mjs +3 -1
- package/dist/controllers/user-storage/account-syncing/utils.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/add-network-utils.cjs +1 -0
- package/dist/controllers/user-storage/network-syncing/add-network-utils.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/add-network-utils.d.cts +1 -0
- package/dist/controllers/user-storage/network-syncing/add-network-utils.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/add-network-utils.d.mts +1 -0
- package/dist/controllers/user-storage/network-syncing/add-network-utils.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/add-network-utils.mjs +1 -0
- package/dist/controllers/user-storage/network-syncing/add-network-utils.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.cjs +3 -3
- package/dist/controllers/user-storage/network-syncing/controller-integration.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts +2 -0
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts +2 -0
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.mjs +3 -3
- package/dist/controllers/user-storage/network-syncing/controller-integration.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.cjs +5 -0
- package/dist/controllers/user-storage/network-syncing/services.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.d.cts +5 -1
- package/dist/controllers/user-storage/network-syncing/services.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.d.mts +5 -1
- package/dist/controllers/user-storage/network-syncing/services.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.mjs +5 -0
- package/dist/controllers/user-storage/network-syncing/services.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-all.cjs +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-all.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-all.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-all.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-all.mjs +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-all.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/update-network-utils.cjs +3 -0
- package/dist/controllers/user-storage/network-syncing/update-network-utils.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/update-network-utils.d.cts +3 -0
- package/dist/controllers/user-storage/network-syncing/update-network-utils.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/update-network-utils.d.mts +3 -0
- package/dist/controllers/user-storage/network-syncing/update-network-utils.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/update-network-utils.mjs +3 -0
- package/dist/controllers/user-storage/network-syncing/update-network-utils.mjs.map +1 -1
- package/dist/controllers/user-storage/services.cjs +0 -1
- package/dist/controllers/user-storage/services.cjs.map +1 -1
- package/dist/controllers/user-storage/services.d.cts.map +1 -1
- package/dist/controllers/user-storage/services.d.mts.map +1 -1
- package/dist/controllers/user-storage/services.mjs +0 -1
- package/dist/controllers/user-storage/services.mjs.map +1 -1
- package/dist/controllers/user-storage/utils.cjs +2 -0
- package/dist/controllers/user-storage/utils.cjs.map +1 -1
- package/dist/controllers/user-storage/utils.d.cts +2 -0
- package/dist/controllers/user-storage/utils.d.cts.map +1 -1
- package/dist/controllers/user-storage/utils.d.mts +2 -0
- package/dist/controllers/user-storage/utils.d.mts.map +1 -1
- package/dist/controllers/user-storage/utils.mjs +2 -0
- package/dist/controllers/user-storage/utils.mjs.map +1 -1
- package/dist/sdk/__fixtures__/mock-auth.cjs +0 -15
- package/dist/sdk/__fixtures__/mock-auth.cjs.map +1 -1
- package/dist/sdk/__fixtures__/mock-auth.mjs +0 -15
- package/dist/sdk/__fixtures__/mock-auth.mjs.map +1 -1
- package/dist/sdk/__fixtures__/mock-userstorage.cjs +0 -2
- package/dist/sdk/__fixtures__/mock-userstorage.cjs.map +1 -1
- package/dist/sdk/__fixtures__/mock-userstorage.d.cts.map +1 -1
- package/dist/sdk/__fixtures__/mock-userstorage.d.mts.map +1 -1
- package/dist/sdk/__fixtures__/mock-userstorage.mjs +0 -2
- package/dist/sdk/__fixtures__/mock-userstorage.mjs.map +1 -1
- package/dist/sdk/__fixtures__/test-utils.cjs +2 -1
- package/dist/sdk/__fixtures__/test-utils.cjs.map +1 -1
- package/dist/sdk/__fixtures__/test-utils.d.cts +1 -0
- package/dist/sdk/__fixtures__/test-utils.d.cts.map +1 -1
- package/dist/sdk/__fixtures__/test-utils.d.mts +1 -0
- package/dist/sdk/__fixtures__/test-utils.d.mts.map +1 -1
- package/dist/sdk/__fixtures__/test-utils.mjs +2 -1
- package/dist/sdk/__fixtures__/test-utils.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.cjs +1 -2
- package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.cts +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.mts +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.mjs +1 -2
- package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -1
- package/dist/sdk/authentication.cjs +0 -3
- package/dist/sdk/authentication.cjs.map +1 -1
- package/dist/sdk/authentication.d.cts.map +1 -1
- package/dist/sdk/authentication.d.mts.map +1 -1
- package/dist/sdk/authentication.mjs +0 -3
- package/dist/sdk/authentication.mjs.map +1 -1
- package/dist/sdk/user-storage.cjs +1 -3
- package/dist/sdk/user-storage.cjs.map +1 -1
- package/dist/sdk/user-storage.d.cts +1 -1
- package/dist/sdk/user-storage.d.cts.map +1 -1
- package/dist/sdk/user-storage.d.mts +1 -1
- package/dist/sdk/user-storage.d.mts.map +1 -1
- package/dist/sdk/user-storage.mjs +1 -3
- package/dist/sdk/user-storage.mjs.map +1 -1
- package/dist/sdk/utils/eip-6963-metamask-provider.cjs +4 -4
- package/dist/sdk/utils/eip-6963-metamask-provider.cjs.map +1 -1
- package/dist/sdk/utils/eip-6963-metamask-provider.mjs +4 -4
- package/dist/sdk/utils/eip-6963-metamask-provider.mjs.map +1 -1
- package/dist/shared/encryption/constants.cjs +0 -2
- package/dist/shared/encryption/constants.cjs.map +1 -1
- package/dist/shared/encryption/constants.d.cts.map +1 -1
- package/dist/shared/encryption/constants.d.mts.map +1 -1
- package/dist/shared/encryption/constants.mjs +0 -2
- package/dist/shared/encryption/constants.mjs.map +1 -1
- package/dist/shared/encryption/encryption.cjs +1 -0
- package/dist/shared/encryption/encryption.cjs.map +1 -1
- package/dist/shared/encryption/encryption.d.cts +1 -0
- package/dist/shared/encryption/encryption.d.cts.map +1 -1
- package/dist/shared/encryption/encryption.d.mts +1 -0
- package/dist/shared/encryption/encryption.d.mts.map +1 -1
- package/dist/shared/encryption/encryption.mjs +1 -0
- package/dist/shared/encryption/encryption.mjs.map +1 -1
- package/package.json +11 -11
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserStorageController.d.mts","sourceRoot":"","sources":["../../../src/controllers/user-storage/UserStorageController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oCAAoC,EACpC,6CAA6C,EAC7C,qCAAqC,EACrC,mCAAmC,EACpC,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,
|
|
1
|
+
{"version":3,"file":"UserStorageController.d.mts","sourceRoot":"","sources":["../../../src/controllers/user-storage/UserStorageController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,oCAAoC,EACpC,6CAA6C,EAC7C,qCAAqC,EACrC,mCAAmC,EACpC,sCAAsC;AACvC,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EAEpB,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EACL,KAAK,+BAA+B,EACpC,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,EACjC,KAAK,oCAAoC,EAC1C,qCAAqC;AACtC,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AACtE,OAAO,KAAK,EACV,iCAAiC,EACjC,+BAA+B,EAC/B,oCAAoC,EACpC,oCAAoC,EACpC,oCAAoC,EACrC,qCAAqC;AACtC,OAAO,KAAK,EAAE,iBAAiB,EAAE,oCAAoC;AAqBrE,OAAO,KAAK,EA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AE,sBAAsB,CAAC,WAAW,CAAC,EAAE,GAC5C,OAAO,CAAC,IAAI,CAAC;IAYhB;;;;OAIG;IACU,aAAa,IAAI,OAAO,CAAC,MAAM,CAAC;IA4EvC,qCAAqC,CACzC,kCAAkC,EAAE,OAAO,GAC1C,OAAO,CAAC,IAAI,CAAC;IAOV,sCAAsC,CAC1C,mCAAmC,EAAE,OAAO,GAC3C,OAAO,CAAC,IAAI,CAAC;IAOV,6BAA6B,CACjC,0BAA0B,EAAE,OAAO,GAClC,OAAO,CAAC,IAAI,CAAC;IAMhB;;;;OAIG;IACG,mCAAmC,IAAI,OAAO,CAAC,IAAI,CAAC;IA0B1D;;;;OAIG;IACG,gCAAgC,CACpC,eAAe,EAAE,eAAe,GAC/B,OAAO,CAAC,IAAI,CAAC;IAWV,YAAY;CAuBnB"}
|
|
@@ -9,14 +9,14 @@ var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (
|
|
|
9
9
|
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
10
10
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
11
11
|
};
|
|
12
|
-
var _UserStorageController_instances, _UserStorageController_env, _UserStorageController_auth, _UserStorageController_config,
|
|
12
|
+
var _UserStorageController_instances, _UserStorageController_env, _UserStorageController_auth, _UserStorageController_config, _UserStorageController_isUnlocked, _UserStorageController_keyringController, _UserStorageController_nativeScryptCrypto, _UserStorageController_registerMessageHandlers, _UserStorageController_getStorageOptions, _UserStorageController_getStorageKeyAndBearerToken, _UserStorageController_createStorageKey, _UserStorageController__snapSignMessageCache, _UserStorageController_snapSignMessage, _UserStorageController_setIsProfileSyncingUpdateLoading;
|
|
13
13
|
import { BaseController } from "@metamask/base-controller";
|
|
14
|
-
import { createSHA256Hash } from "../../shared/encryption/index.mjs";
|
|
15
|
-
import { createSnapSignMessageRequest } from "../authentication/auth-snap-requests.mjs";
|
|
16
14
|
import { saveInternalAccountToUserStorage, syncInternalAccountsWithUserStorage } from "./account-syncing/controller-integration.mjs";
|
|
17
15
|
import { setupAccountSyncingSubscriptions } from "./account-syncing/setup-subscriptions.mjs";
|
|
18
16
|
import { performMainNetworkSync, startNetworkSyncing } from "./network-syncing/controller-integration.mjs";
|
|
19
17
|
import { batchDeleteUserStorage, batchUpsertUserStorage, deleteUserStorage, deleteUserStorageAllFeatureEntries, getUserStorage, getUserStorageAllFeatureEntries, upsertUserStorage } from "./services.mjs";
|
|
18
|
+
import { createSHA256Hash } from "../../shared/encryption/index.mjs";
|
|
19
|
+
import { createSnapSignMessageRequest } from "../authentication/auth-snap-requests.mjs";
|
|
20
20
|
const controllerName = 'UserStorageController';
|
|
21
21
|
export const defaultState = {
|
|
22
22
|
isProfileSyncingEnabled: true,
|
|
@@ -60,7 +60,7 @@ const metadata = {
|
|
|
60
60
|
* - No one can access this data unless they are have the SRP and are able to run the signing snap.
|
|
61
61
|
*/
|
|
62
62
|
class UserStorageController extends BaseController {
|
|
63
|
-
constructor({ messenger, state, env, config,
|
|
63
|
+
constructor({ messenger, state, env, config, nativeScryptCrypto, }) {
|
|
64
64
|
super({
|
|
65
65
|
messenger,
|
|
66
66
|
metadata,
|
|
@@ -82,7 +82,7 @@ class UserStorageController extends BaseController {
|
|
|
82
82
|
const sessionProfile = await this.messagingSystem.call('AuthenticationController:getSessionProfile');
|
|
83
83
|
return sessionProfile?.profileId;
|
|
84
84
|
},
|
|
85
|
-
|
|
85
|
+
isSignedIn: () => {
|
|
86
86
|
return this.messagingSystem.call('AuthenticationController:isSignedIn');
|
|
87
87
|
},
|
|
88
88
|
signIn: async () => {
|
|
@@ -93,14 +93,6 @@ class UserStorageController extends BaseController {
|
|
|
93
93
|
},
|
|
94
94
|
});
|
|
95
95
|
_UserStorageController_config.set(this, void 0);
|
|
96
|
-
_UserStorageController_notificationServices.set(this, {
|
|
97
|
-
disableNotificationServices: async () => {
|
|
98
|
-
return await this.messagingSystem.call('NotificationServicesController:disableNotificationServices');
|
|
99
|
-
},
|
|
100
|
-
selectIsNotificationServicesEnabled: async () => {
|
|
101
|
-
return this.messagingSystem.call('NotificationServicesController:selectIsNotificationServicesEnabled');
|
|
102
|
-
},
|
|
103
|
-
});
|
|
104
96
|
_UserStorageController_isUnlocked.set(this, false);
|
|
105
97
|
_UserStorageController_keyringController.set(this, {
|
|
106
98
|
setupLockedStateSubscriptions: () => {
|
|
@@ -119,7 +111,6 @@ class UserStorageController extends BaseController {
|
|
|
119
111
|
__classPrivateFieldGet(this, _UserStorageController_env, "f").isAccountSyncingEnabled = Boolean(env?.isAccountSyncingEnabled);
|
|
120
112
|
__classPrivateFieldGet(this, _UserStorageController_env, "f").isNetworkSyncingEnabled = Boolean(env?.isNetworkSyncingEnabled);
|
|
121
113
|
__classPrivateFieldSet(this, _UserStorageController_config, config, "f");
|
|
122
|
-
this.getMetaMetricsState = getMetaMetricsState;
|
|
123
114
|
__classPrivateFieldGet(this, _UserStorageController_keyringController, "f").setupLockedStateSubscriptions();
|
|
124
115
|
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_registerMessageHandlers).call(this);
|
|
125
116
|
__classPrivateFieldSet(this, _UserStorageController_nativeScryptCrypto, nativeScryptCrypto, "f");
|
|
@@ -142,8 +133,8 @@ class UserStorageController extends BaseController {
|
|
|
142
133
|
async enableProfileSyncing() {
|
|
143
134
|
try {
|
|
144
135
|
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_setIsProfileSyncingUpdateLoading).call(this, true);
|
|
145
|
-
const
|
|
146
|
-
if (!
|
|
136
|
+
const isSignedIn = __classPrivateFieldGet(this, _UserStorageController_auth, "f").isSignedIn();
|
|
137
|
+
if (!isSignedIn) {
|
|
147
138
|
await __classPrivateFieldGet(this, _UserStorageController_auth, "f").signIn();
|
|
148
139
|
}
|
|
149
140
|
this.update((state) => {
|
|
@@ -157,11 +148,6 @@ class UserStorageController extends BaseController {
|
|
|
157
148
|
throw new Error(`${controllerName} - failed to enable profile syncing - ${errorMessage}`);
|
|
158
149
|
}
|
|
159
150
|
}
|
|
160
|
-
async setIsProfileSyncingEnabled(isProfileSyncingEnabled) {
|
|
161
|
-
this.update((state) => {
|
|
162
|
-
state.isProfileSyncingEnabled = isProfileSyncingEnabled;
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
151
|
async disableProfileSyncing() {
|
|
166
152
|
const isAlreadyDisabled = !this.state.isProfileSyncingEnabled;
|
|
167
153
|
if (isAlreadyDisabled) {
|
|
@@ -169,14 +155,6 @@ class UserStorageController extends BaseController {
|
|
|
169
155
|
}
|
|
170
156
|
try {
|
|
171
157
|
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_setIsProfileSyncingUpdateLoading).call(this, true);
|
|
172
|
-
const isNotificationServicesEnabled = await __classPrivateFieldGet(this, _UserStorageController_notificationServices, "f").selectIsNotificationServicesEnabled();
|
|
173
|
-
if (isNotificationServicesEnabled) {
|
|
174
|
-
await __classPrivateFieldGet(this, _UserStorageController_notificationServices, "f").disableNotificationServices();
|
|
175
|
-
}
|
|
176
|
-
const isMetaMetricsParticipation = this.getMetaMetricsState();
|
|
177
|
-
if (!isMetaMetricsParticipation) {
|
|
178
|
-
await __classPrivateFieldGet(this, _UserStorageController_auth, "f").signOut();
|
|
179
|
-
}
|
|
180
158
|
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_setIsProfileSyncingUpdateLoading).call(this, false);
|
|
181
159
|
this.update((state) => {
|
|
182
160
|
state.isProfileSyncingEnabled = false;
|
|
@@ -196,7 +174,6 @@ class UserStorageController extends BaseController {
|
|
|
196
174
|
* @returns the decrypted string contents found from user storage (or null if not found)
|
|
197
175
|
*/
|
|
198
176
|
async performGetStorage(path) {
|
|
199
|
-
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
200
177
|
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageKeyAndBearerToken).call(this);
|
|
201
178
|
const result = await getUserStorage({
|
|
202
179
|
path,
|
|
@@ -214,7 +191,6 @@ class UserStorageController extends BaseController {
|
|
|
214
191
|
* @returns the array of decrypted string contents found from user storage (or null if not found)
|
|
215
192
|
*/
|
|
216
193
|
async performGetStorageAllFeatureEntries(path) {
|
|
217
|
-
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
218
194
|
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageKeyAndBearerToken).call(this);
|
|
219
195
|
const result = await getUserStorageAllFeatureEntries({
|
|
220
196
|
path,
|
|
@@ -233,7 +209,6 @@ class UserStorageController extends BaseController {
|
|
|
233
209
|
* @returns nothing. NOTE that an error is thrown if fails to store data.
|
|
234
210
|
*/
|
|
235
211
|
async performSetStorage(path, value) {
|
|
236
|
-
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
237
212
|
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageKeyAndBearerToken).call(this);
|
|
238
213
|
await upsertUserStorage(value, {
|
|
239
214
|
path,
|
|
@@ -251,7 +226,6 @@ class UserStorageController extends BaseController {
|
|
|
251
226
|
* @returns nothing. NOTE that an error is thrown if fails to store data.
|
|
252
227
|
*/
|
|
253
228
|
async performBatchSetStorage(path, values) {
|
|
254
|
-
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
255
229
|
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageKeyAndBearerToken).call(this);
|
|
256
230
|
await batchUpsertUserStorage(values, {
|
|
257
231
|
path,
|
|
@@ -267,7 +241,6 @@ class UserStorageController extends BaseController {
|
|
|
267
241
|
* @returns nothing. NOTE that an error is thrown if fails to delete data.
|
|
268
242
|
*/
|
|
269
243
|
async performDeleteStorage(path) {
|
|
270
|
-
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
271
244
|
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageKeyAndBearerToken).call(this);
|
|
272
245
|
await deleteUserStorage({
|
|
273
246
|
path,
|
|
@@ -283,7 +256,6 @@ class UserStorageController extends BaseController {
|
|
|
283
256
|
* @returns nothing. NOTE that an error is thrown if fails to delete data.
|
|
284
257
|
*/
|
|
285
258
|
async performDeleteStorageAllFeatureEntries(path) {
|
|
286
|
-
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
287
259
|
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageKeyAndBearerToken).call(this);
|
|
288
260
|
await deleteUserStorageAllFeatureEntries({
|
|
289
261
|
path,
|
|
@@ -300,7 +272,6 @@ class UserStorageController extends BaseController {
|
|
|
300
272
|
* @returns nothing. NOTE that an error is thrown if fails to store data.
|
|
301
273
|
*/
|
|
302
274
|
async performBatchDeleteStorage(path, values) {
|
|
303
|
-
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
304
275
|
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageKeyAndBearerToken).call(this);
|
|
305
276
|
await batchDeleteUserStorage(values, {
|
|
306
277
|
path,
|
|
@@ -315,7 +286,6 @@ class UserStorageController extends BaseController {
|
|
|
315
286
|
* @returns the storage key
|
|
316
287
|
*/
|
|
317
288
|
async getStorageKey() {
|
|
318
|
-
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
319
289
|
const storageKey = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_createStorageKey).call(this);
|
|
320
290
|
return storageKey;
|
|
321
291
|
}
|
|
@@ -356,6 +326,7 @@ class UserStorageController extends BaseController {
|
|
|
356
326
|
}
|
|
357
327
|
/**
|
|
358
328
|
* Saves an individual internal account to the user storage.
|
|
329
|
+
*
|
|
359
330
|
* @param internalAccount - The internal account to save
|
|
360
331
|
*/
|
|
361
332
|
async saveInternalAccountToUserStorage(internalAccount) {
|
|
@@ -382,7 +353,7 @@ class UserStorageController extends BaseController {
|
|
|
382
353
|
});
|
|
383
354
|
}
|
|
384
355
|
}
|
|
385
|
-
_UserStorageController_env = new WeakMap(), _UserStorageController_auth = new WeakMap(), _UserStorageController_config = new WeakMap(),
|
|
356
|
+
_UserStorageController_env = new WeakMap(), _UserStorageController_auth = new WeakMap(), _UserStorageController_config = new WeakMap(), _UserStorageController_isUnlocked = new WeakMap(), _UserStorageController_keyringController = new WeakMap(), _UserStorageController_nativeScryptCrypto = new WeakMap(), _UserStorageController__snapSignMessageCache = new WeakMap(), _UserStorageController_instances = new WeakSet(), _UserStorageController_registerMessageHandlers = function _UserStorageController_registerMessageHandlers() {
|
|
386
357
|
this.messagingSystem.registerActionHandler('UserStorageController:performGetStorage', this.performGetStorage.bind(this));
|
|
387
358
|
this.messagingSystem.registerActionHandler('UserStorageController:performGetStorageAllFeatureEntries', this.performGetStorageAllFeatureEntries.bind(this));
|
|
388
359
|
this.messagingSystem.registerActionHandler('UserStorageController:performSetStorage', this.performSetStorage.bind(this));
|
|
@@ -401,13 +372,11 @@ _UserStorageController_env = new WeakMap(), _UserStorageController_auth = new We
|
|
|
401
372
|
bearerToken,
|
|
402
373
|
nativeScryptCrypto: __classPrivateFieldGet(this, _UserStorageController_nativeScryptCrypto, "f"),
|
|
403
374
|
};
|
|
404
|
-
}, _UserStorageController_assertProfileSyncingEnabled = function _UserStorageController_assertProfileSyncingEnabled() {
|
|
405
|
-
if (!this.state.isProfileSyncingEnabled) {
|
|
406
|
-
throw new Error(`${controllerName}: Unable to call method, user is not authenticated`);
|
|
407
|
-
}
|
|
408
375
|
}, _UserStorageController_getStorageKeyAndBearerToken =
|
|
409
376
|
/**
|
|
410
377
|
* Utility to get the bearer token and storage key
|
|
378
|
+
*
|
|
379
|
+
* @returns the bearer token and storage key
|
|
411
380
|
*/
|
|
412
381
|
async function _UserStorageController_getStorageKeyAndBearerToken() {
|
|
413
382
|
const bearerToken = await __classPrivateFieldGet(this, _UserStorageController_auth, "f").getBearerToken();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"UserStorageController.mjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/UserStorageController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAYA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAiB3D,OAAO,EAAE,gBAAgB,EAAE,0CAAgC;AAO3D,OAAO,EAAE,4BAA4B,EAAE,iDAA6C;AAQpF,OAAO,EACL,gCAAgC,EAChC,mCAAmC,EACpC,qDAAiD;AAClD,OAAO,EAAE,gCAAgC,EAAE,kDAA8C;AACzF,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACpB,qDAAiD;AAClD,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EACjB,kCAAkC,EAClC,cAAc,EACd,+BAA+B,EAC/B,iBAAiB,EAClB,uBAAmB;AAepB,MAAM,cAAc,GAAG,uBAAuB,CAAC;AA8B/C,MAAM,CAAC,MAAM,YAAY,GAA+B;IACtD,uBAAuB,EAAE,IAAI;IAC7B,6BAA6B,EAAE,KAAK;IACpC,kCAAkC,EAAE,KAAK;IACzC,mCAAmC,EAAE,KAAK;IAC1C,0BAA0B,EAAE,KAAK;CAClC,CAAC;AAEF,MAAM,QAAQ,GAA8C;IAC1D,uBAAuB,EAAE;QACvB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,IAAI;KAChB;IACD,6BAA6B,EAAE;QAC7B,OAAO,EAAE,KAAK;QAC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;;GAIG;AACH,KAAK;IACH,MAAM,EAAE,GAAW,MAAM,uBAAA,IAAI,mCAAM,CAAC,YAAY,EAAE,CAAC;IACnD,IAAI,CAAC,EAAE,EAAE;QACP,MAAM,IAAI,KAAK,CAAC,sDAAsD,CAAC,CAAC;KACzE;IAED,MAAM,mBAAmB,GAAG,MAAM,uBAAA,IAAI,gFAAiB,MAArB,IAAI,EAAkB,YAAY,EAAE,EAAE,CAAC,CAAC;IAC1E,MAAM,UAAU,GAAG,gBAAgB,CAAC,mBAAmB,CAAC,CAAC;IACzD,OAAO,UAAU,CAAC;AACpB,CAAC;AAID;;;;;GAKG;AACH,KAAK,iDAAkB,OAA6B;IAClD,IAAI,uBAAA,IAAI,oDAAuB,CAAC,OAAO,CAAC,EAAE;QACxC,OAAO,uBAAA,IAAI,oDAAuB,CAAC,OAAO,CAAC,CAAC;KAC7C;IAED,IAAI,CAAC,uBAAA,IAAI,yCAAY,EAAE;QACrB,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;KACH;IAED,MAAM,MAAM,GAAG,CAAC,MAAM,IAAI,CAAC,eAAe,CAAC,IAAI,CAC7C,8BAA8B,EAC9B,4BAA4B,CAAC,OAAO,CAAC,CACtC,CAAW,CAAC;IAEb,uBAAA,IAAI,oDAAuB,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC;IAE9C,OAAO,MAAM,CAAC;AAChB,CAAC,6HAGC,6BAAsC;IAEtC,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QACpB,KAAK,CAAC,6BAA6B,GAAG,6BAA6B,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC;eAtgBkB,qBAAqB","sourcesContent":["import type {\n AccountsControllerListAccountsAction,\n AccountsControllerUpdateAccountMetadataAction,\n AccountsControllerAccountRenamedEvent,\n AccountsControllerAccountAddedEvent,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport {\n type KeyringControllerGetStateAction,\n type KeyringControllerLockEvent,\n type KeyringControllerUnlockEvent,\n type KeyringControllerAddNewAccountAction,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type {\n NetworkControllerAddNetworkAction,\n NetworkControllerGetStateAction,\n NetworkControllerNetworkRemovedEvent,\n NetworkControllerRemoveNetworkAction,\n NetworkControllerUpdateNetworkAction,\n} from '@metamask/network-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\nimport { createSHA256Hash } from '../../shared/encryption';\nimport type { UserStorageFeatureKeys } from '../../shared/storage-schema';\nimport {\n type UserStoragePathWithFeatureAndKey,\n type UserStoragePathWithFeatureOnly,\n} from '../../shared/storage-schema';\nimport type { NativeScrypt } from '../../shared/types/encryption';\nimport { createSnapSignMessageRequest } from '../authentication/auth-snap-requests';\nimport type {\n AuthenticationControllerGetBearerToken,\n AuthenticationControllerGetSessionProfile,\n AuthenticationControllerIsSignedIn,\n AuthenticationControllerPerformSignIn,\n AuthenticationControllerPerformSignOut,\n} from '../authentication/AuthenticationController';\nimport {\n saveInternalAccountToUserStorage,\n syncInternalAccountsWithUserStorage,\n} from './account-syncing/controller-integration';\nimport { setupAccountSyncingSubscriptions } from './account-syncing/setup-subscriptions';\nimport {\n performMainNetworkSync,\n startNetworkSyncing,\n} from './network-syncing/controller-integration';\nimport {\n batchDeleteUserStorage,\n batchUpsertUserStorage,\n deleteUserStorage,\n deleteUserStorageAllFeatureEntries,\n getUserStorage,\n getUserStorageAllFeatureEntries,\n upsertUserStorage,\n} from './services';\n\n// TODO: fix external dependencies\nexport declare type NotificationServicesControllerDisableNotificationServices =\n {\n type: `NotificationServicesController:disableNotificationServices`;\n handler: () => Promise<void>;\n };\n\nexport declare type NotificationServicesControllerSelectIsNotificationServicesEnabled =\n {\n type: `NotificationServicesController:selectIsNotificationServicesEnabled`;\n handler: () => boolean;\n };\n\nconst controllerName = 'UserStorageController';\n\n// State\nexport type UserStorageControllerState = {\n /**\n * Condition used by UI and to determine if we can use some of the User Storage methods.\n */\n isProfileSyncingEnabled: boolean | null;\n /**\n * Loading state for the profile syncing update\n */\n isProfileSyncingUpdateLoading: boolean;\n /**\n * Condition used by E2E tests to determine if account syncing has been dispatched at least once.\n */\n hasAccountSyncingSyncedAtLeastOnce: boolean;\n /**\n * Condition used by UI to determine if account syncing is ready to be dispatched.\n */\n isAccountSyncingReadyToBeDispatched: boolean;\n /**\n * Condition used by UI to determine if account syncing is in progress.\n */\n isAccountSyncingInProgress: boolean;\n /**\n * Condition used to ensure that we do not perform any network sync mutations until we have synced at least once\n */\n hasNetworkSyncingSyncedAtLeastOnce?: boolean;\n};\n\nexport const defaultState: UserStorageControllerState = {\n isProfileSyncingEnabled: true,\n isProfileSyncingUpdateLoading: false,\n hasAccountSyncingSyncedAtLeastOnce: false,\n isAccountSyncingReadyToBeDispatched: false,\n isAccountSyncingInProgress: false,\n};\n\nconst metadata: StateMetadata<UserStorageControllerState> = {\n isProfileSyncingEnabled: {\n persist: true,\n anonymous: true,\n },\n isProfileSyncingUpdateLoading: {\n persist: false,\n anonymous: false,\n },\n hasAccountSyncingSyncedAtLeastOnce: {\n persist: true,\n anonymous: false,\n },\n isAccountSyncingReadyToBeDispatched: {\n persist: true,\n anonymous: false,\n },\n isAccountSyncingInProgress: {\n persist: false,\n anonymous: false,\n },\n hasNetworkSyncingSyncedAtLeastOnce: {\n persist: true,\n anonymous: false,\n },\n};\n\ntype ControllerConfig = {\n accountSyncing?: {\n maxNumberOfAccountsToAdd?: number;\n /**\n * Callback that fires when account sync adds an account.\n * This is used for analytics.\n */\n onAccountAdded?: (profileId: string) => void;\n\n /**\n * Callback that fires when account sync updates the name of an account.\n * This is used for analytics.\n */\n onAccountNameUpdated?: (profileId: string) => void;\n\n /**\n * Callback that fires when an erroneous situation happens during account sync.\n * This is used for analytics.\n */\n onAccountSyncErroneousSituation?: (\n profileId: string,\n situationMessage: string,\n sentryContext?: Record<string, unknown>,\n ) => void;\n };\n\n networkSyncing?: {\n maxNumberOfNetworksToAdd?: number;\n /**\n * Callback that fires when network sync adds a network\n * This is used for analytics.\n * @param profileId - ID for a given User (shared cross devices once authenticated)\n * @param chainId - Chain ID for the network added (in hex)\n */\n onNetworkAdded?: (profileId: string, chainId: string) => void;\n /**\n * Callback that fires when network sync updates a network\n * This is used for analytics.\n * @param profileId - ID for a given User (shared cross devices once authenticated)\n * @param chainId - Chain ID for the network added (in hex)\n */\n onNetworkUpdated?: (profileId: string, chainId: string) => void;\n /**\n * Callback that fires when network sync deletes a network\n * This is used for analytics.\n * @param profileId - ID for a given User (shared cross devices once authenticated)\n * @param chainId - Chain ID for the network added (in hex)\n */\n onNetworkRemoved?: (profileId: string, chainId: string) => void;\n };\n};\n\n// Messenger Actions\ntype CreateActionsObj<Controller extends keyof UserStorageController> = {\n [K in Controller]: {\n type: `${typeof controllerName}:${K}`;\n handler: UserStorageController[K];\n };\n};\ntype ActionsObj = CreateActionsObj<\n | 'performGetStorage'\n | 'performGetStorageAllFeatureEntries'\n | 'performSetStorage'\n | 'getStorageKey'\n | 'enableProfileSyncing'\n | 'disableProfileSyncing'\n | 'syncInternalAccountsWithUserStorage'\n | 'saveInternalAccountToUserStorage'\n>;\nexport type UserStorageControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n UserStorageControllerState\n>;\nexport type Actions =\n | ActionsObj[keyof ActionsObj]\n | UserStorageControllerGetStateAction;\nexport type UserStorageControllerPerformGetStorage =\n ActionsObj['performGetStorage'];\nexport type UserStorageControllerPerformGetStorageAllFeatureEntries =\n ActionsObj['performGetStorageAllFeatureEntries'];\nexport type UserStorageControllerPerformSetStorage =\n ActionsObj['performSetStorage'];\nexport type UserStorageControllerGetStorageKey = ActionsObj['getStorageKey'];\nexport type UserStorageControllerEnableProfileSyncing =\n ActionsObj['enableProfileSyncing'];\nexport type UserStorageControllerDisableProfileSyncing =\n ActionsObj['disableProfileSyncing'];\nexport type UserStorageControllerSyncInternalAccountsWithUserStorage =\n ActionsObj['syncInternalAccountsWithUserStorage'];\nexport type UserStorageControllerSaveInternalAccountToUserStorage =\n ActionsObj['saveInternalAccountToUserStorage'];\n\nexport type AllowedActions =\n // Keyring Requests\n | KeyringControllerGetStateAction\n // Snap Requests\n | HandleSnapRequest\n // Auth Requests\n | AuthenticationControllerGetBearerToken\n | AuthenticationControllerGetSessionProfile\n | AuthenticationControllerPerformSignIn\n | AuthenticationControllerIsSignedIn\n | AuthenticationControllerPerformSignOut\n // Metamask Notifications\n | NotificationServicesControllerDisableNotificationServices\n | NotificationServicesControllerSelectIsNotificationServicesEnabled\n // Account Syncing\n | AccountsControllerListAccountsAction\n | AccountsControllerUpdateAccountMetadataAction\n | KeyringControllerAddNewAccountAction\n // Network Syncing\n | NetworkControllerGetStateAction\n | NetworkControllerAddNetworkAction\n | NetworkControllerRemoveNetworkAction\n | NetworkControllerUpdateNetworkAction;\n\n// Messenger events\nexport type UserStorageControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n UserStorageControllerState\n>;\nexport type UserStorageControllerAccountSyncingInProgress = {\n type: `${typeof controllerName}:accountSyncingInProgress`;\n payload: [boolean];\n};\nexport type UserStorageControllerAccountSyncingComplete = {\n type: `${typeof controllerName}:accountSyncingComplete`;\n payload: [boolean];\n};\nexport type Events =\n | UserStorageControllerStateChangeEvent\n | UserStorageControllerAccountSyncingInProgress\n | UserStorageControllerAccountSyncingComplete;\n\nexport type AllowedEvents =\n | UserStorageControllerStateChangeEvent\n | UserStorageControllerAccountSyncingInProgress\n | UserStorageControllerAccountSyncingComplete\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent\n // Account Syncing Events\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRenamedEvent\n // Network Syncing Events\n | NetworkControllerNetworkRemovedEvent;\n\n// Messenger\nexport type UserStorageControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Reusable controller that allows any team to store synchronized data for a given user.\n * These can be settings shared cross MetaMask clients, or data we want to persist when uninstalling/reinstalling.\n *\n * NOTE:\n * - data stored on UserStorage is FULLY encrypted, with the only keys stored/managed on the client.\n * - No one can access this data unless they are have the SRP and are able to run the signing snap.\n */\nexport default class UserStorageController extends BaseController<\n typeof controllerName,\n UserStorageControllerState,\n UserStorageControllerMessenger\n> {\n // This is replaced with the actual value in the constructor\n // We will remove this once the feature will be released\n #env = {\n isAccountSyncingEnabled: false,\n isNetworkSyncingEnabled: false,\n };\n\n #auth = {\n getBearerToken: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:getBearerToken',\n );\n },\n getProfileId: async () => {\n const sessionProfile = await this.messagingSystem.call(\n 'AuthenticationController:getSessionProfile',\n );\n return sessionProfile?.profileId;\n },\n isAuthEnabled: () => {\n return this.messagingSystem.call('AuthenticationController:isSignedIn');\n },\n signIn: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:performSignIn',\n );\n },\n signOut: async () => {\n return this.messagingSystem.call(\n 'AuthenticationController:performSignOut',\n );\n },\n };\n\n #config?: ControllerConfig;\n\n #notificationServices = {\n disableNotificationServices: async () => {\n return await this.messagingSystem.call(\n 'NotificationServicesController:disableNotificationServices',\n );\n },\n selectIsNotificationServicesEnabled: async () => {\n return this.messagingSystem.call(\n 'NotificationServicesController:selectIsNotificationServicesEnabled',\n );\n },\n };\n\n #isUnlocked = false;\n\n #keyringController = {\n setupLockedStateSubscriptions: () => {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#isUnlocked = isUnlocked;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.#isUnlocked = true;\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#isUnlocked = false;\n });\n },\n };\n\n #nativeScryptCrypto: NativeScrypt | undefined = undefined;\n\n getMetaMetricsState: () => boolean;\n\n constructor({\n messenger,\n state,\n env,\n config,\n getMetaMetricsState,\n nativeScryptCrypto,\n }: {\n messenger: UserStorageControllerMessenger;\n state?: UserStorageControllerState;\n config?: ControllerConfig;\n env?: {\n isAccountSyncingEnabled?: boolean;\n isNetworkSyncingEnabled?: boolean;\n };\n getMetaMetricsState: () => boolean;\n nativeScryptCrypto?: NativeScrypt;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n this.#env.isAccountSyncingEnabled = Boolean(env?.isAccountSyncingEnabled);\n this.#env.isNetworkSyncingEnabled = Boolean(env?.isNetworkSyncingEnabled);\n this.#config = config;\n\n this.getMetaMetricsState = getMetaMetricsState;\n this.#keyringController.setupLockedStateSubscriptions();\n this.#registerMessageHandlers();\n this.#nativeScryptCrypto = nativeScryptCrypto;\n\n // Account Syncing\n if (this.#env.isAccountSyncingEnabled) {\n setupAccountSyncingSubscriptions(\n { isAccountSyncingEnabled: true },\n {\n getUserStorageControllerInstance: () => this,\n getMessenger: () => this.messagingSystem,\n },\n );\n }\n\n // Network Syncing\n if (this.#env.isNetworkSyncingEnabled) {\n startNetworkSyncing({\n messenger,\n getStorageConfig: () => this.#getStorageOptions(),\n isMutationSyncBlocked: () =>\n !this.state.hasNetworkSyncingSyncedAtLeastOnce,\n });\n }\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performGetStorage',\n this.performGetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performGetStorageAllFeatureEntries',\n this.performGetStorageAllFeatureEntries.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performSetStorage',\n this.performSetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:getStorageKey',\n this.getStorageKey.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:enableProfileSyncing',\n this.enableProfileSyncing.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:disableProfileSyncing',\n this.disableProfileSyncing.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:syncInternalAccountsWithUserStorage',\n this.syncInternalAccountsWithUserStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:saveInternalAccountToUserStorage',\n this.saveInternalAccountToUserStorage.bind(this),\n );\n }\n\n async #getStorageOptions() {\n if (!this.state.isProfileSyncingEnabled) {\n return null;\n }\n\n const { storageKey, bearerToken } =\n await this.#getStorageKeyAndBearerToken();\n return {\n storageKey,\n bearerToken,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n };\n }\n\n public async enableProfileSyncing(): Promise<void> {\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n const authEnabled = this.#auth.isAuthEnabled();\n if (!authEnabled) {\n await this.#auth.signIn();\n }\n\n this.update((state) => {\n state.isProfileSyncingEnabled = true;\n });\n\n this.#setIsProfileSyncingUpdateLoading(false);\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to enable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n public async setIsProfileSyncingEnabled(\n isProfileSyncingEnabled: boolean,\n ): Promise<void> {\n this.update((state) => {\n state.isProfileSyncingEnabled = isProfileSyncingEnabled;\n });\n }\n\n public async disableProfileSyncing(): Promise<void> {\n const isAlreadyDisabled = !this.state.isProfileSyncingEnabled;\n if (isAlreadyDisabled) {\n return;\n }\n\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n const isNotificationServicesEnabled =\n await this.#notificationServices.selectIsNotificationServicesEnabled();\n\n if (isNotificationServicesEnabled) {\n await this.#notificationServices.disableNotificationServices();\n }\n\n const isMetaMetricsParticipation = this.getMetaMetricsState();\n\n if (!isMetaMetricsParticipation) {\n await this.#auth.signOut();\n }\n\n this.#setIsProfileSyncingUpdateLoading(false);\n\n this.update((state) => {\n state.isProfileSyncingEnabled = false;\n });\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to disable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n /**\n * Allows retrieval of stored data. Data stored is string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @returns the decrypted string contents found from user storage (or null if not found)\n */\n public async performGetStorage(\n path: UserStoragePathWithFeatureAndKey,\n ): Promise<string | null> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n const result = await getUserStorage({\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n\n return result;\n }\n\n /**\n * Allows retrieval of all stored data for a specific feature. Data stored is formatted as an array of strings.\n * Developers can extend the entry path through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}` that matches schema\n * @returns the array of decrypted string contents found from user storage (or null if not found)\n */\n public async performGetStorageAllFeatureEntries(\n path: UserStoragePathWithFeatureOnly,\n ): Promise<string[] | null> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n const result = await getUserStorageAllFeatureEntries({\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n\n return result;\n }\n\n /**\n * Allows storage of user data. Data stored must be string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param value - The string data you want to store.\n * @returns nothing. NOTE that an error is thrown if fails to store data.\n */\n public async performSetStorage(\n path: UserStoragePathWithFeatureAndKey,\n value: string,\n ): Promise<void> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await upsertUserStorage(value, {\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n }\n\n /**\n * Allows storage of multiple user data entries for one specific feature. Data stored must be string formatted.\n * Developers can extend the entry path through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}` that matches schema\n * @param values - data to store, in the form of an array of `[entryKey, entryValue]` pairs\n * @returns nothing. NOTE that an error is thrown if fails to store data.\n */\n public async performBatchSetStorage<\n FeatureName extends UserStoragePathWithFeatureOnly,\n >(\n path: FeatureName,\n values: [UserStorageFeatureKeys<FeatureName>, string][],\n ): Promise<void> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await batchUpsertUserStorage(values, {\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n }\n\n /**\n * Allows deletion of user data. Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @returns nothing. NOTE that an error is thrown if fails to delete data.\n */\n public async performDeleteStorage(\n path: UserStoragePathWithFeatureAndKey,\n ): Promise<void> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await deleteUserStorage({\n path,\n bearerToken,\n storageKey,\n });\n }\n\n /**\n * Allows deletion of all user data entries for a specific feature.\n * Developers can extend the entry path through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}` that matches schema\n * @returns nothing. NOTE that an error is thrown if fails to delete data.\n */\n public async performDeleteStorageAllFeatureEntries(\n path: UserStoragePathWithFeatureOnly,\n ): Promise<void> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await deleteUserStorageAllFeatureEntries({\n path,\n bearerToken,\n storageKey,\n });\n }\n\n /**\n * Allows delete of multiple user data entries for one specific feature. Data deleted must be string formatted.\n * Developers can extend the entry path through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}` that matches schema\n * @param values - data to store, in the form of an array of entryKey[]\n * @returns nothing. NOTE that an error is thrown if fails to store data.\n */\n public async performBatchDeleteStorage<\n FeatureName extends UserStoragePathWithFeatureOnly,\n >(\n path: FeatureName,\n values: UserStorageFeatureKeys<FeatureName>[],\n ): Promise<void> {\n this.#assertProfileSyncingEnabled();\n\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await batchDeleteUserStorage(values, {\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n }\n\n /**\n * Retrieves the storage key, for internal use only!\n *\n * @returns the storage key\n */\n public async getStorageKey(): Promise<string> {\n this.#assertProfileSyncingEnabled();\n const storageKey = await this.#createStorageKey();\n return storageKey;\n }\n\n #assertProfileSyncingEnabled(): void {\n if (!this.state.isProfileSyncingEnabled) {\n throw new Error(\n `${controllerName}: Unable to call method, user is not authenticated`,\n );\n }\n }\n\n /**\n * Utility to get the bearer token and storage key\n */\n async #getStorageKeyAndBearerToken(): Promise<{\n bearerToken: string;\n storageKey: string;\n }> {\n const bearerToken = await this.#auth.getBearerToken();\n if (!bearerToken) {\n throw new Error('UserStorageController - unable to get bearer token');\n }\n const storageKey = await this.#createStorageKey();\n\n return { bearerToken, storageKey };\n }\n\n /**\n * Rather than storing the storage key, we can compute the storage key when needed.\n *\n * @returns the storage key\n */\n async #createStorageKey(): Promise<string> {\n const id: string = await this.#auth.getProfileId();\n if (!id) {\n throw new Error('UserStorageController - unable to create storage key');\n }\n\n const storageKeySignature = await this.#snapSignMessage(`metamask:${id}`);\n const storageKey = createSHA256Hash(storageKeySignature);\n return storageKey;\n }\n\n #_snapSignMessageCache: Record<`metamask:${string}`, string> = {};\n\n /**\n * Signs a specific message using an underlying auth snap.\n *\n * @param message - A specific tagged message to sign.\n * @returns A Signature created by the snap.\n */\n async #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapSignMessage - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n )) as string;\n\n this.#_snapSignMessageCache[message] = result;\n\n return result;\n }\n\n #setIsProfileSyncingUpdateLoading(\n isProfileSyncingUpdateLoading: boolean,\n ): void {\n this.update((state) => {\n state.isProfileSyncingUpdateLoading = isProfileSyncingUpdateLoading;\n });\n }\n\n async setHasAccountSyncingSyncedAtLeastOnce(\n hasAccountSyncingSyncedAtLeastOnce: boolean,\n ): Promise<void> {\n this.update((state) => {\n state.hasAccountSyncingSyncedAtLeastOnce =\n hasAccountSyncingSyncedAtLeastOnce;\n });\n }\n\n async setIsAccountSyncingReadyToBeDispatched(\n isAccountSyncingReadyToBeDispatched: boolean,\n ): Promise<void> {\n this.update((state) => {\n state.isAccountSyncingReadyToBeDispatched =\n isAccountSyncingReadyToBeDispatched;\n });\n }\n\n async setIsAccountSyncingInProgress(\n isAccountSyncingInProgress: boolean,\n ): Promise<void> {\n this.update((state) => {\n state.isAccountSyncingInProgress = isAccountSyncingInProgress;\n });\n }\n\n /**\n * Syncs the internal accounts list with the user storage accounts list.\n * This method is used to make sure that the internal accounts list is up-to-date with the user storage accounts list and vice-versa.\n * It will add new accounts to the internal accounts list, update/merge conflicting names and re-upload the results in some cases to the user storage.\n */\n async syncInternalAccountsWithUserStorage(): Promise<void> {\n const profileId = await this.#auth.getProfileId();\n\n await syncInternalAccountsWithUserStorage(\n {\n isAccountSyncingEnabled: this.#env.isAccountSyncingEnabled,\n maxNumberOfAccountsToAdd:\n this.#config?.accountSyncing?.maxNumberOfAccountsToAdd,\n onAccountAdded: () =>\n this.#config?.accountSyncing?.onAccountAdded?.(profileId),\n onAccountNameUpdated: () =>\n this.#config?.accountSyncing?.onAccountNameUpdated?.(profileId),\n onAccountSyncErroneousSituation: (situationMessage, sentryContext) =>\n this.#config?.accountSyncing?.onAccountSyncErroneousSituation?.(\n profileId,\n situationMessage,\n sentryContext,\n ),\n },\n {\n getMessenger: () => this.messagingSystem,\n getUserStorageControllerInstance: () => this,\n },\n );\n }\n\n /**\n * Saves an individual internal account to the user storage.\n * @param internalAccount - The internal account to save\n */\n async saveInternalAccountToUserStorage(\n internalAccount: InternalAccount,\n ): Promise<void> {\n await saveInternalAccountToUserStorage(\n internalAccount,\n { isAccountSyncingEnabled: this.#env.isAccountSyncingEnabled },\n {\n getMessenger: () => this.messagingSystem,\n getUserStorageControllerInstance: () => this,\n },\n );\n }\n\n async syncNetworks() {\n if (!this.#env.isNetworkSyncingEnabled) {\n return;\n }\n\n const profileId = await this.#auth.getProfileId();\n\n await performMainNetworkSync({\n messenger: this.messagingSystem,\n getStorageConfig: () => this.#getStorageOptions(),\n maxNetworksToAdd: this.#config?.networkSyncing?.maxNumberOfNetworksToAdd,\n onNetworkAdded: (cId) =>\n this.#config?.networkSyncing?.onNetworkAdded?.(profileId, cId),\n onNetworkUpdated: (cId) =>\n this.#config?.networkSyncing?.onNetworkUpdated?.(profileId, cId),\n onNetworkRemoved: (cId) =>\n this.#config?.networkSyncing?.onNetworkRemoved?.(profileId, cId),\n });\n\n this.update((s) => {\n s.hasNetworkSyncingSyncedAtLeastOnce = true;\n });\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"UserStorageController.mjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/UserStorageController.ts"],"names":[],"mappings":";;;;;;;;;;;;AAYA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAiB3D,OAAO,EACL,gCAAgC,EAChC,mCAAmC,EACpC,qDAAiD;AAClD,OAAO,EAAE,gCAAgC,EAAE,kDAA8C;AACzF,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACpB,qDAAiD;AAClD,OAAO,EACL,sBAAsB,EACtB,sBAAsB,EACtB,iBAAiB,EAC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I,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;QACpB,KAAK,CAAC,6BAA6B,GAAG,6BAA6B,CAAC;IACtE,CAAC,CAAC,CAAC;AACL,CAAC;eA1ckB,qBAAqB","sourcesContent":["import type {\n AccountsControllerListAccountsAction,\n AccountsControllerUpdateAccountMetadataAction,\n AccountsControllerAccountRenamedEvent,\n AccountsControllerAccountAddedEvent,\n} from '@metamask/accounts-controller';\nimport type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n StateMetadata,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport {\n type KeyringControllerGetStateAction,\n type KeyringControllerLockEvent,\n type KeyringControllerUnlockEvent,\n type KeyringControllerAddNewAccountAction,\n} from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\nimport type {\n NetworkControllerAddNetworkAction,\n NetworkControllerGetStateAction,\n NetworkControllerNetworkRemovedEvent,\n NetworkControllerRemoveNetworkAction,\n NetworkControllerUpdateNetworkAction,\n} from '@metamask/network-controller';\nimport type { HandleSnapRequest } from '@metamask/snaps-controllers';\n\nimport {\n saveInternalAccountToUserStorage,\n syncInternalAccountsWithUserStorage,\n} from './account-syncing/controller-integration';\nimport { setupAccountSyncingSubscriptions } from './account-syncing/setup-subscriptions';\nimport {\n performMainNetworkSync,\n startNetworkSyncing,\n} from './network-syncing/controller-integration';\nimport {\n batchDeleteUserStorage,\n batchUpsertUserStorage,\n deleteUserStorage,\n deleteUserStorageAllFeatureEntries,\n getUserStorage,\n getUserStorageAllFeatureEntries,\n upsertUserStorage,\n} from './services';\nimport { createSHA256Hash } from '../../shared/encryption';\nimport type { UserStorageFeatureKeys } from '../../shared/storage-schema';\nimport {\n type UserStoragePathWithFeatureAndKey,\n type UserStoragePathWithFeatureOnly,\n} from '../../shared/storage-schema';\nimport type { NativeScrypt } from '../../shared/types/encryption';\nimport { createSnapSignMessageRequest } from '../authentication/auth-snap-requests';\nimport type {\n AuthenticationControllerGetBearerToken,\n AuthenticationControllerGetSessionProfile,\n AuthenticationControllerIsSignedIn,\n AuthenticationControllerPerformSignIn,\n AuthenticationControllerPerformSignOut,\n} from '../authentication/AuthenticationController';\n\nconst controllerName = 'UserStorageController';\n\n// State\nexport type UserStorageControllerState = {\n /**\n * Condition used by UI and to determine if we can use some of the User Storage methods.\n */\n isProfileSyncingEnabled: boolean | null;\n /**\n * Loading state for the profile syncing update\n */\n isProfileSyncingUpdateLoading: boolean;\n /**\n * Condition used by E2E tests to determine if account syncing has been dispatched at least once.\n */\n hasAccountSyncingSyncedAtLeastOnce: boolean;\n /**\n * Condition used by UI to determine if account syncing is ready to be dispatched.\n */\n isAccountSyncingReadyToBeDispatched: boolean;\n /**\n * Condition used by UI to determine if account syncing is in progress.\n */\n isAccountSyncingInProgress: boolean;\n /**\n * Condition used to ensure that we do not perform any network sync mutations until we have synced at least once\n */\n hasNetworkSyncingSyncedAtLeastOnce?: boolean;\n};\n\nexport const defaultState: UserStorageControllerState = {\n isProfileSyncingEnabled: true,\n isProfileSyncingUpdateLoading: false,\n hasAccountSyncingSyncedAtLeastOnce: false,\n isAccountSyncingReadyToBeDispatched: false,\n isAccountSyncingInProgress: false,\n};\n\nconst metadata: StateMetadata<UserStorageControllerState> = {\n isProfileSyncingEnabled: {\n persist: true,\n anonymous: true,\n },\n isProfileSyncingUpdateLoading: {\n persist: false,\n anonymous: false,\n },\n hasAccountSyncingSyncedAtLeastOnce: {\n persist: true,\n anonymous: false,\n },\n isAccountSyncingReadyToBeDispatched: {\n persist: true,\n anonymous: false,\n },\n isAccountSyncingInProgress: {\n persist: false,\n anonymous: false,\n },\n hasNetworkSyncingSyncedAtLeastOnce: {\n persist: true,\n anonymous: false,\n },\n};\n\ntype ControllerConfig = {\n accountSyncing?: {\n maxNumberOfAccountsToAdd?: number;\n /**\n * Callback that fires when account sync adds an account.\n * This is used for analytics.\n */\n onAccountAdded?: (profileId: string) => void;\n\n /**\n * Callback that fires when account sync updates the name of an account.\n * This is used for analytics.\n */\n onAccountNameUpdated?: (profileId: string) => void;\n\n /**\n * Callback that fires when an erroneous situation happens during account sync.\n * This is used for analytics.\n */\n onAccountSyncErroneousSituation?: (\n profileId: string,\n situationMessage: string,\n sentryContext?: Record<string, unknown>,\n ) => void;\n };\n\n networkSyncing?: {\n maxNumberOfNetworksToAdd?: number;\n /**\n * Callback that fires when network sync adds a network\n * This is used for analytics.\n *\n * @param profileId - ID for a given User (shared cross devices once authenticated)\n * @param chainId - Chain ID for the network added (in hex)\n */\n onNetworkAdded?: (profileId: string, chainId: string) => void;\n /**\n * Callback that fires when network sync updates a network\n * This is used for analytics.\n *\n * @param profileId - ID for a given User (shared cross devices once authenticated)\n * @param chainId - Chain ID for the network added (in hex)\n */\n onNetworkUpdated?: (profileId: string, chainId: string) => void;\n /**\n * Callback that fires when network sync deletes a network\n * This is used for analytics.\n *\n * @param profileId - ID for a given User (shared cross devices once authenticated)\n * @param chainId - Chain ID for the network added (in hex)\n */\n onNetworkRemoved?: (profileId: string, chainId: string) => void;\n };\n};\n\n// Messenger Actions\ntype CreateActionsObj<Controller extends keyof UserStorageController> = {\n [K in Controller]: {\n type: `${typeof controllerName}:${K}`;\n handler: UserStorageController[K];\n };\n};\ntype ActionsObj = CreateActionsObj<\n | 'performGetStorage'\n | 'performGetStorageAllFeatureEntries'\n | 'performSetStorage'\n | 'getStorageKey'\n | 'enableProfileSyncing'\n | 'disableProfileSyncing'\n | 'syncInternalAccountsWithUserStorage'\n | 'saveInternalAccountToUserStorage'\n>;\nexport type UserStorageControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n UserStorageControllerState\n>;\nexport type Actions =\n | ActionsObj[keyof ActionsObj]\n | UserStorageControllerGetStateAction;\nexport type UserStorageControllerPerformGetStorage =\n ActionsObj['performGetStorage'];\nexport type UserStorageControllerPerformGetStorageAllFeatureEntries =\n ActionsObj['performGetStorageAllFeatureEntries'];\nexport type UserStorageControllerPerformSetStorage =\n ActionsObj['performSetStorage'];\nexport type UserStorageControllerGetStorageKey = ActionsObj['getStorageKey'];\nexport type UserStorageControllerEnableProfileSyncing =\n ActionsObj['enableProfileSyncing'];\nexport type UserStorageControllerDisableProfileSyncing =\n ActionsObj['disableProfileSyncing'];\nexport type UserStorageControllerSyncInternalAccountsWithUserStorage =\n ActionsObj['syncInternalAccountsWithUserStorage'];\nexport type UserStorageControllerSaveInternalAccountToUserStorage =\n ActionsObj['saveInternalAccountToUserStorage'];\n\nexport type AllowedActions =\n // Keyring Requests\n | KeyringControllerGetStateAction\n // Snap Requests\n | HandleSnapRequest\n // Auth Requests\n | AuthenticationControllerGetBearerToken\n | AuthenticationControllerGetSessionProfile\n | AuthenticationControllerPerformSignIn\n | AuthenticationControllerIsSignedIn\n | AuthenticationControllerPerformSignOut\n // Account Syncing\n | AccountsControllerListAccountsAction\n | AccountsControllerUpdateAccountMetadataAction\n | KeyringControllerAddNewAccountAction\n // Network Syncing\n | NetworkControllerGetStateAction\n | NetworkControllerAddNetworkAction\n | NetworkControllerRemoveNetworkAction\n | NetworkControllerUpdateNetworkAction;\n\n// Messenger events\nexport type UserStorageControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n UserStorageControllerState\n>;\nexport type UserStorageControllerAccountSyncingInProgress = {\n type: `${typeof controllerName}:accountSyncingInProgress`;\n payload: [boolean];\n};\nexport type UserStorageControllerAccountSyncingComplete = {\n type: `${typeof controllerName}:accountSyncingComplete`;\n payload: [boolean];\n};\nexport type Events =\n | UserStorageControllerStateChangeEvent\n | UserStorageControllerAccountSyncingInProgress\n | UserStorageControllerAccountSyncingComplete;\n\nexport type AllowedEvents =\n | UserStorageControllerStateChangeEvent\n | UserStorageControllerAccountSyncingInProgress\n | UserStorageControllerAccountSyncingComplete\n | KeyringControllerLockEvent\n | KeyringControllerUnlockEvent\n // Account Syncing Events\n | AccountsControllerAccountAddedEvent\n | AccountsControllerAccountRenamedEvent\n // Network Syncing Events\n | NetworkControllerNetworkRemovedEvent;\n\n// Messenger\nexport type UserStorageControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n Actions | AllowedActions,\n Events | AllowedEvents,\n AllowedActions['type'],\n AllowedEvents['type']\n>;\n\n/**\n * Reusable controller that allows any team to store synchronized data for a given user.\n * These can be settings shared cross MetaMask clients, or data we want to persist when uninstalling/reinstalling.\n *\n * NOTE:\n * - data stored on UserStorage is FULLY encrypted, with the only keys stored/managed on the client.\n * - No one can access this data unless they are have the SRP and are able to run the signing snap.\n */\nexport default class UserStorageController extends BaseController<\n typeof controllerName,\n UserStorageControllerState,\n UserStorageControllerMessenger\n> {\n // This is replaced with the actual value in the constructor\n // We will remove this once the feature will be released\n readonly #env = {\n isAccountSyncingEnabled: false,\n isNetworkSyncingEnabled: false,\n };\n\n readonly #auth = {\n getBearerToken: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:getBearerToken',\n );\n },\n getProfileId: async () => {\n const sessionProfile = await this.messagingSystem.call(\n 'AuthenticationController:getSessionProfile',\n );\n return sessionProfile?.profileId;\n },\n isSignedIn: () => {\n return this.messagingSystem.call('AuthenticationController:isSignedIn');\n },\n signIn: async () => {\n return await this.messagingSystem.call(\n 'AuthenticationController:performSignIn',\n );\n },\n signOut: async () => {\n return this.messagingSystem.call(\n 'AuthenticationController:performSignOut',\n );\n },\n };\n\n readonly #config?: ControllerConfig;\n\n #isUnlocked = false;\n\n readonly #keyringController = {\n setupLockedStateSubscriptions: () => {\n const { isUnlocked } = this.messagingSystem.call(\n 'KeyringController:getState',\n );\n this.#isUnlocked = isUnlocked;\n\n this.messagingSystem.subscribe('KeyringController:unlock', () => {\n this.#isUnlocked = true;\n });\n\n this.messagingSystem.subscribe('KeyringController:lock', () => {\n this.#isUnlocked = false;\n });\n },\n };\n\n readonly #nativeScryptCrypto: NativeScrypt | undefined = undefined;\n\n constructor({\n messenger,\n state,\n env,\n config,\n nativeScryptCrypto,\n }: {\n messenger: UserStorageControllerMessenger;\n state?: UserStorageControllerState;\n config?: ControllerConfig;\n env?: {\n isAccountSyncingEnabled?: boolean;\n isNetworkSyncingEnabled?: boolean;\n };\n nativeScryptCrypto?: NativeScrypt;\n }) {\n super({\n messenger,\n metadata,\n name: controllerName,\n state: { ...defaultState, ...state },\n });\n\n this.#env.isAccountSyncingEnabled = Boolean(env?.isAccountSyncingEnabled);\n this.#env.isNetworkSyncingEnabled = Boolean(env?.isNetworkSyncingEnabled);\n this.#config = config;\n\n this.#keyringController.setupLockedStateSubscriptions();\n this.#registerMessageHandlers();\n this.#nativeScryptCrypto = nativeScryptCrypto;\n\n // Account Syncing\n if (this.#env.isAccountSyncingEnabled) {\n setupAccountSyncingSubscriptions(\n { isAccountSyncingEnabled: true },\n {\n getUserStorageControllerInstance: () => this,\n getMessenger: () => this.messagingSystem,\n },\n );\n }\n\n // Network Syncing\n if (this.#env.isNetworkSyncingEnabled) {\n startNetworkSyncing({\n messenger,\n getStorageConfig: () => this.#getStorageOptions(),\n isMutationSyncBlocked: () =>\n !this.state.hasNetworkSyncingSyncedAtLeastOnce,\n });\n }\n }\n\n /**\n * Constructor helper for registering this controller's messaging system\n * actions.\n */\n #registerMessageHandlers(): void {\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performGetStorage',\n this.performGetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performGetStorageAllFeatureEntries',\n this.performGetStorageAllFeatureEntries.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:performSetStorage',\n this.performSetStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:getStorageKey',\n this.getStorageKey.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:enableProfileSyncing',\n this.enableProfileSyncing.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:disableProfileSyncing',\n this.disableProfileSyncing.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:syncInternalAccountsWithUserStorage',\n this.syncInternalAccountsWithUserStorage.bind(this),\n );\n\n this.messagingSystem.registerActionHandler(\n 'UserStorageController:saveInternalAccountToUserStorage',\n this.saveInternalAccountToUserStorage.bind(this),\n );\n }\n\n async #getStorageOptions() {\n if (!this.state.isProfileSyncingEnabled) {\n return null;\n }\n\n const { storageKey, bearerToken } =\n await this.#getStorageKeyAndBearerToken();\n return {\n storageKey,\n bearerToken,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n };\n }\n\n public async enableProfileSyncing(): Promise<void> {\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n const isSignedIn = this.#auth.isSignedIn();\n if (!isSignedIn) {\n await this.#auth.signIn();\n }\n\n this.update((state) => {\n state.isProfileSyncingEnabled = true;\n });\n\n this.#setIsProfileSyncingUpdateLoading(false);\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to enable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n public async disableProfileSyncing(): Promise<void> {\n const isAlreadyDisabled = !this.state.isProfileSyncingEnabled;\n if (isAlreadyDisabled) {\n return;\n }\n\n try {\n this.#setIsProfileSyncingUpdateLoading(true);\n\n this.#setIsProfileSyncingUpdateLoading(false);\n\n this.update((state) => {\n state.isProfileSyncingEnabled = false;\n });\n } catch (e) {\n this.#setIsProfileSyncingUpdateLoading(false);\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `${controllerName} - failed to disable profile syncing - ${errorMessage}`,\n );\n }\n }\n\n /**\n * Allows retrieval of stored data. Data stored is string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @returns the decrypted string contents found from user storage (or null if not found)\n */\n public async performGetStorage(\n path: UserStoragePathWithFeatureAndKey,\n ): Promise<string | null> {\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n const result = await getUserStorage({\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n\n return result;\n }\n\n /**\n * Allows retrieval of all stored data for a specific feature. Data stored is formatted as an array of strings.\n * Developers can extend the entry path through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}` that matches schema\n * @returns the array of decrypted string contents found from user storage (or null if not found)\n */\n public async performGetStorageAllFeatureEntries(\n path: UserStoragePathWithFeatureOnly,\n ): Promise<string[] | null> {\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n const result = await getUserStorageAllFeatureEntries({\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n\n return result;\n }\n\n /**\n * Allows storage of user data. Data stored must be string formatted.\n * Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @param value - The string data you want to store.\n * @returns nothing. NOTE that an error is thrown if fails to store data.\n */\n public async performSetStorage(\n path: UserStoragePathWithFeatureAndKey,\n value: string,\n ): Promise<void> {\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await upsertUserStorage(value, {\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n }\n\n /**\n * Allows storage of multiple user data entries for one specific feature. Data stored must be string formatted.\n * Developers can extend the entry path through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}` that matches schema\n * @param values - data to store, in the form of an array of `[entryKey, entryValue]` pairs\n * @returns nothing. NOTE that an error is thrown if fails to store data.\n */\n public async performBatchSetStorage<\n FeatureName extends UserStoragePathWithFeatureOnly,\n >(\n path: FeatureName,\n values: [UserStorageFeatureKeys<FeatureName>, string][],\n ): Promise<void> {\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await batchUpsertUserStorage(values, {\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n }\n\n /**\n * Allows deletion of user data. Developers can extend the entry path and entry name through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}.${key}` that matches schema\n * @returns nothing. NOTE that an error is thrown if fails to delete data.\n */\n public async performDeleteStorage(\n path: UserStoragePathWithFeatureAndKey,\n ): Promise<void> {\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await deleteUserStorage({\n path,\n bearerToken,\n storageKey,\n });\n }\n\n /**\n * Allows deletion of all user data entries for a specific feature.\n * Developers can extend the entry path through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}` that matches schema\n * @returns nothing. NOTE that an error is thrown if fails to delete data.\n */\n public async performDeleteStorageAllFeatureEntries(\n path: UserStoragePathWithFeatureOnly,\n ): Promise<void> {\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await deleteUserStorageAllFeatureEntries({\n path,\n bearerToken,\n storageKey,\n });\n }\n\n /**\n * Allows delete of multiple user data entries for one specific feature. Data deleted must be string formatted.\n * Developers can extend the entry path through the `schema.ts` file.\n *\n * @param path - string in the form of `${feature}` that matches schema\n * @param values - data to store, in the form of an array of entryKey[]\n * @returns nothing. NOTE that an error is thrown if fails to store data.\n */\n public async performBatchDeleteStorage<\n FeatureName extends UserStoragePathWithFeatureOnly,\n >(\n path: FeatureName,\n values: UserStorageFeatureKeys<FeatureName>[],\n ): Promise<void> {\n const { bearerToken, storageKey } =\n await this.#getStorageKeyAndBearerToken();\n\n await batchDeleteUserStorage(values, {\n path,\n bearerToken,\n storageKey,\n nativeScryptCrypto: this.#nativeScryptCrypto,\n });\n }\n\n /**\n * Retrieves the storage key, for internal use only!\n *\n * @returns the storage key\n */\n public async getStorageKey(): Promise<string> {\n const storageKey = await this.#createStorageKey();\n return storageKey;\n }\n\n /**\n * Utility to get the bearer token and storage key\n *\n * @returns the bearer token and storage key\n */\n async #getStorageKeyAndBearerToken(): Promise<{\n bearerToken: string;\n storageKey: string;\n }> {\n const bearerToken = await this.#auth.getBearerToken();\n if (!bearerToken) {\n throw new Error('UserStorageController - unable to get bearer token');\n }\n const storageKey = await this.#createStorageKey();\n\n return { bearerToken, storageKey };\n }\n\n /**\n * Rather than storing the storage key, we can compute the storage key when needed.\n *\n * @returns the storage key\n */\n async #createStorageKey(): Promise<string> {\n const id: string = await this.#auth.getProfileId();\n if (!id) {\n throw new Error('UserStorageController - unable to create storage key');\n }\n\n const storageKeySignature = await this.#snapSignMessage(`metamask:${id}`);\n const storageKey = createSHA256Hash(storageKeySignature);\n return storageKey;\n }\n\n #_snapSignMessageCache: Record<`metamask:${string}`, string> = {};\n\n /**\n * Signs a specific message using an underlying auth snap.\n *\n * @param message - A specific tagged message to sign.\n * @returns A Signature created by the snap.\n */\n async #snapSignMessage(message: `metamask:${string}`): Promise<string> {\n if (this.#_snapSignMessageCache[message]) {\n return this.#_snapSignMessageCache[message];\n }\n\n if (!this.#isUnlocked) {\n throw new Error(\n '#snapSignMessage - unable to call snap, wallet is locked',\n );\n }\n\n const result = (await this.messagingSystem.call(\n 'SnapController:handleRequest',\n createSnapSignMessageRequest(message),\n )) as string;\n\n this.#_snapSignMessageCache[message] = result;\n\n return result;\n }\n\n #setIsProfileSyncingUpdateLoading(\n isProfileSyncingUpdateLoading: boolean,\n ): void {\n this.update((state) => {\n state.isProfileSyncingUpdateLoading = isProfileSyncingUpdateLoading;\n });\n }\n\n async setHasAccountSyncingSyncedAtLeastOnce(\n hasAccountSyncingSyncedAtLeastOnce: boolean,\n ): Promise<void> {\n this.update((state) => {\n state.hasAccountSyncingSyncedAtLeastOnce =\n hasAccountSyncingSyncedAtLeastOnce;\n });\n }\n\n async setIsAccountSyncingReadyToBeDispatched(\n isAccountSyncingReadyToBeDispatched: boolean,\n ): Promise<void> {\n this.update((state) => {\n state.isAccountSyncingReadyToBeDispatched =\n isAccountSyncingReadyToBeDispatched;\n });\n }\n\n async setIsAccountSyncingInProgress(\n isAccountSyncingInProgress: boolean,\n ): Promise<void> {\n this.update((state) => {\n state.isAccountSyncingInProgress = isAccountSyncingInProgress;\n });\n }\n\n /**\n * Syncs the internal accounts list with the user storage accounts list.\n * This method is used to make sure that the internal accounts list is up-to-date with the user storage accounts list and vice-versa.\n * It will add new accounts to the internal accounts list, update/merge conflicting names and re-upload the results in some cases to the user storage.\n */\n async syncInternalAccountsWithUserStorage(): Promise<void> {\n const profileId = await this.#auth.getProfileId();\n\n await syncInternalAccountsWithUserStorage(\n {\n isAccountSyncingEnabled: this.#env.isAccountSyncingEnabled,\n maxNumberOfAccountsToAdd:\n this.#config?.accountSyncing?.maxNumberOfAccountsToAdd,\n onAccountAdded: () =>\n this.#config?.accountSyncing?.onAccountAdded?.(profileId),\n onAccountNameUpdated: () =>\n this.#config?.accountSyncing?.onAccountNameUpdated?.(profileId),\n onAccountSyncErroneousSituation: (situationMessage, sentryContext) =>\n this.#config?.accountSyncing?.onAccountSyncErroneousSituation?.(\n profileId,\n situationMessage,\n sentryContext,\n ),\n },\n {\n getMessenger: () => this.messagingSystem,\n getUserStorageControllerInstance: () => this,\n },\n );\n }\n\n /**\n * Saves an individual internal account to the user storage.\n *\n * @param internalAccount - The internal account to save\n */\n async saveInternalAccountToUserStorage(\n internalAccount: InternalAccount,\n ): Promise<void> {\n await saveInternalAccountToUserStorage(\n internalAccount,\n { isAccountSyncingEnabled: this.#env.isAccountSyncingEnabled },\n {\n getMessenger: () => this.messagingSystem,\n getUserStorageControllerInstance: () => this,\n },\n );\n }\n\n async syncNetworks() {\n if (!this.#env.isNetworkSyncingEnabled) {\n return;\n }\n\n const profileId = await this.#auth.getProfileId();\n\n await performMainNetworkSync({\n messenger: this.messagingSystem,\n getStorageConfig: () => this.#getStorageOptions(),\n maxNetworksToAdd: this.#config?.networkSyncing?.maxNumberOfNetworksToAdd,\n onNetworkAdded: (cId) =>\n this.#config?.networkSyncing?.onNetworkAdded?.(profileId, cId),\n onNetworkUpdated: (cId) =>\n this.#config?.networkSyncing?.onNetworkUpdated?.(profileId, cId),\n onNetworkRemoved: (cId) =>\n this.#config?.networkSyncing?.onNetworkRemoved?.(profileId, cId),\n });\n\n this.update((s) => {\n s.hasNetworkSyncingSyncedAtLeastOnce = true;\n });\n }\n}\n"]}
|
|
@@ -6,12 +6,13 @@ const _1 = require("./index.cjs");
|
|
|
6
6
|
const typedMockFn = (_type) => jest.fn();
|
|
7
7
|
/**
|
|
8
8
|
* creates a custom user storage messenger, in case tests need different permissions
|
|
9
|
+
*
|
|
9
10
|
* @param props - overrides
|
|
10
11
|
* @param props.overrideEvents - override events
|
|
11
12
|
* @returns base messenger, and messenger. You can pass this into the mocks below to mock messenger calls
|
|
12
13
|
*/
|
|
13
14
|
function createCustomUserStorageMessenger(props) {
|
|
14
|
-
const baseMessenger = new base_controller_1.
|
|
15
|
+
const baseMessenger = new base_controller_1.Messenger();
|
|
15
16
|
const messenger = baseMessenger.getRestricted({
|
|
16
17
|
name: 'UserStorageController',
|
|
17
18
|
allowedActions: [
|
|
@@ -23,8 +24,6 @@ function createCustomUserStorageMessenger(props) {
|
|
|
23
24
|
'AuthenticationController:isSignedIn',
|
|
24
25
|
'AuthenticationController:performSignOut',
|
|
25
26
|
'AuthenticationController:performSignIn',
|
|
26
|
-
'NotificationServicesController:disableNotificationServices',
|
|
27
|
-
'NotificationServicesController:selectIsNotificationServicesEnabled',
|
|
28
27
|
'AccountsController:listAccounts',
|
|
29
28
|
'AccountsController:updateAccountMetadata',
|
|
30
29
|
'NetworkController:getState',
|
|
@@ -48,6 +47,7 @@ function createCustomUserStorageMessenger(props) {
|
|
|
48
47
|
exports.createCustomUserStorageMessenger = createCustomUserStorageMessenger;
|
|
49
48
|
/**
|
|
50
49
|
* Jest Mock Utility to generate a mock User Storage Messenger
|
|
50
|
+
*
|
|
51
51
|
* @param overrideMessengers - override messengers if need to modify the underlying permissions
|
|
52
52
|
* @returns series of mocks to actions that can be called
|
|
53
53
|
*/
|
|
@@ -65,8 +65,6 @@ function mockUserStorageMessenger(overrideMessengers) {
|
|
|
65
65
|
const mockAuthPerformSignIn = typedMockFn('AuthenticationController:performSignIn').mockResolvedValue('New Access Token');
|
|
66
66
|
const mockAuthIsSignedIn = typedMockFn('AuthenticationController:isSignedIn').mockReturnValue(true);
|
|
67
67
|
const mockAuthPerformSignOut = typedMockFn('AuthenticationController:performSignOut');
|
|
68
|
-
const mockNotificationServicesIsEnabled = typedMockFn('NotificationServicesController:selectIsNotificationServicesEnabled').mockReturnValue(true);
|
|
69
|
-
const mockNotificationServicesDisableNotifications = typedMockFn('NotificationServicesController:disableNotificationServices').mockResolvedValue();
|
|
70
68
|
const mockKeyringAddNewAccount = typedMockFn('KeyringController:addNewAccount');
|
|
71
69
|
// Untyped mock as there is a TS(2742) issue.
|
|
72
70
|
// This will return `InternalAccount[]`
|
|
@@ -105,14 +103,6 @@ function mockUserStorageMessenger(overrideMessengers) {
|
|
|
105
103
|
if (actionType === 'AuthenticationController:isSignedIn') {
|
|
106
104
|
return mockAuthIsSignedIn();
|
|
107
105
|
}
|
|
108
|
-
if (actionType ===
|
|
109
|
-
'NotificationServicesController:selectIsNotificationServicesEnabled') {
|
|
110
|
-
return mockNotificationServicesIsEnabled();
|
|
111
|
-
}
|
|
112
|
-
if (actionType ===
|
|
113
|
-
'NotificationServicesController:disableNotificationServices') {
|
|
114
|
-
return mockNotificationServicesDisableNotifications();
|
|
115
|
-
}
|
|
116
106
|
if (actionType === 'AuthenticationController:performSignOut') {
|
|
117
107
|
return mockAuthPerformSignOut();
|
|
118
108
|
}
|
|
@@ -155,8 +145,6 @@ function mockUserStorageMessenger(overrideMessengers) {
|
|
|
155
145
|
mockAuthGetSessionProfile,
|
|
156
146
|
mockAuthPerformSignIn,
|
|
157
147
|
mockAuthIsSignedIn,
|
|
158
|
-
mockNotificationServicesIsEnabled,
|
|
159
|
-
mockNotificationServicesDisableNotifications,
|
|
160
148
|
mockAuthPerformSignOut,
|
|
161
149
|
mockKeyringAddNewAccount,
|
|
162
150
|
mockAccountsUpdateAccountMetadata,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mockMessenger.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/__fixtures__/mockMessenger.ts"],"names":[],"mappings":";;;AACA,+DAAgE;AAEhE,kCAA+C;AAmB/C,MAAM,WAAW,GAAG,CAQlB,KAAiB,EACjB,EAAE,CAAC,IAAI,CAAC,EAAE,EAAsC,CAAC;AAOnD;;;;;GAKG;AACH,SAAgB,gCAAgC,CAAC,KAEhD;IACC,MAAM,aAAa,GAAG,IAAI,qCAAmB,EAG1C,CAAC;IACJ,MAAM,SAAS,GAAG,aAAa,CAAC,aAAa,CAAC;QAC5C,IAAI,EAAE,uBAAuB;QAC7B,cAAc,EAAE;YACd,4BAA4B;YAC5B,iCAAiC;YACjC,8BAA8B;YAC9B,yCAAyC;YACzC,4CAA4C;YAC5C,qCAAqC;YACrC,yCAAyC;YACzC,wCAAwC;YACxC,4DAA4D;YAC5D,oEAAoE;YACpE,iCAAiC;YACjC,0CAA0C;YAC1C,4BAA4B;YAC5B,8BAA8B;YAC9B,iCAAiC;YACjC,iCAAiC;SAClC;QACD,aAAa,EAAE,KAAK,EAAE,cAAc,IAAI;YACtC,wBAAwB;YACxB,0BAA0B;YAC1B,iCAAiC;YACjC,mCAAmC;YACnC,kCAAkC;SACnC;KACF,CAAC,CAAC;IAEH,OAAO;QACL,aAAa;QACb,SAAS;KACV,CAAC;AACJ,CAAC;AAxCD,4EAwCC;AAOD;;;;GAIG;AACH,SAAgB,wBAAwB,CACtC,kBAAuC;IAEvC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,GAChC,kBAAkB,IAAI,gCAAgC,EAAE,CAAC;IAE3D,MAAM,oBAAoB,GAAG,IAAI,CAAC,EAAE,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAAC;IAC5E,MAAM,mBAAmB,GAAG,IAAI;SAC7B,EAAE,EAAE;SACJ,iBAAiB,CAAC,6BAA0B,CAAC,CAAC;IAEjD,MAAM,sBAAsB,GAAG,WAAW,CACxC,yCAAyC,CAC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nimport { ControllerMessenger } from '@metamask/base-controller';\n\nimport { MOCK_STORAGE_KEY_SIGNATURE } from '.';\nimport type {\n AllowedActions,\n AllowedEvents,\n UserStorageControllerMessenger,\n} from '..';\n\ntype GetHandler<ActionType extends AllowedActions['type']> = Extract<\n AllowedActions,\n { type: ActionType }\n>['handler'];\n\ntype CallParams = {\n [K in AllowedActions['type']]: [\n K,\n ...Parameters<Extract<AllowedActions, { type: K }>['handler']>,\n ];\n}[AllowedActions['type']];\n\nconst typedMockFn = <\n ActionType extends AllowedActions['type'],\n Handler = GetHandler<ActionType>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Func extends (...args: any) => any = Handler extends (...args: any[]) => any\n ? Handler\n : never,\n>(\n _type: ActionType,\n) => jest.fn<ReturnType<Func>, Parameters<Func>>();\n\ntype ExternalEvents = NotNamespacedBy<\n 'UserStorageController',\n AllowedEvents['type']\n>;\n\n/**\n * creates a custom user storage messenger, in case tests need different permissions\n * @param props - overrides\n * @param props.overrideEvents - override events\n * @returns base messenger, and messenger. You can pass this into the mocks below to mock messenger calls\n */\nexport function createCustomUserStorageMessenger(props?: {\n overrideEvents?: ExternalEvents[];\n}) {\n const baseMessenger = new ControllerMessenger<\n AllowedActions,\n AllowedEvents\n >();\n const messenger = baseMessenger.getRestricted({\n name: 'UserStorageController',\n allowedActions: [\n 'KeyringController:getState',\n 'KeyringController:addNewAccount',\n 'SnapController:handleRequest',\n 'AuthenticationController:getBearerToken',\n 'AuthenticationController:getSessionProfile',\n 'AuthenticationController:isSignedIn',\n 'AuthenticationController:performSignOut',\n 'AuthenticationController:performSignIn',\n 'NotificationServicesController:disableNotificationServices',\n 'NotificationServicesController:selectIsNotificationServicesEnabled',\n 'AccountsController:listAccounts',\n 'AccountsController:updateAccountMetadata',\n 'NetworkController:getState',\n 'NetworkController:addNetwork',\n 'NetworkController:updateNetwork',\n 'NetworkController:removeNetwork',\n ],\n allowedEvents: props?.overrideEvents ?? [\n 'KeyringController:lock',\n 'KeyringController:unlock',\n 'AccountsController:accountAdded',\n 'AccountsController:accountRenamed',\n 'NetworkController:networkRemoved',\n ],\n });\n\n return {\n baseMessenger,\n messenger,\n };\n}\n\ntype OverrideMessengers = {\n baseMessenger: ControllerMessenger<AllowedActions, AllowedEvents>;\n messenger: UserStorageControllerMessenger;\n};\n\n/**\n * Jest Mock Utility to generate a mock User Storage Messenger\n * @param overrideMessengers - override messengers if need to modify the underlying permissions\n * @returns series of mocks to actions that can be called\n */\nexport function mockUserStorageMessenger(\n overrideMessengers?: OverrideMessengers,\n) {\n const { baseMessenger, messenger } =\n overrideMessengers ?? createCustomUserStorageMessenger();\n\n const mockSnapGetPublicKey = jest.fn().mockResolvedValue('MOCK_PUBLIC_KEY');\n const mockSnapSignMessage = jest\n .fn()\n .mockResolvedValue(MOCK_STORAGE_KEY_SIGNATURE);\n\n const mockAuthGetBearerToken = typedMockFn(\n 'AuthenticationController:getBearerToken',\n ).mockResolvedValue('MOCK_BEARER_TOKEN');\n\n const mockAuthGetSessionProfile = typedMockFn(\n 'AuthenticationController:getSessionProfile',\n ).mockResolvedValue({\n identifierId: '',\n profileId: 'MOCK_PROFILE_ID',\n });\n\n const mockAuthPerformSignIn = typedMockFn(\n 'AuthenticationController:performSignIn',\n ).mockResolvedValue('New Access Token');\n\n const mockAuthIsSignedIn = typedMockFn(\n 'AuthenticationController:isSignedIn',\n ).mockReturnValue(true);\n\n const mockAuthPerformSignOut = typedMockFn(\n 'AuthenticationController:performSignOut',\n );\n\n const mockNotificationServicesIsEnabled = typedMockFn(\n 'NotificationServicesController:selectIsNotificationServicesEnabled',\n ).mockReturnValue(true);\n\n const mockNotificationServicesDisableNotifications = typedMockFn(\n 'NotificationServicesController:disableNotificationServices',\n ).mockResolvedValue();\n\n const mockKeyringAddNewAccount = typedMockFn(\n 'KeyringController:addNewAccount',\n );\n\n // Untyped mock as there is a TS(2742) issue.\n // This will return `InternalAccount[]`\n const mockAccountsListAccounts = jest.fn();\n\n const mockAccountsUpdateAccountMetadata = typedMockFn(\n 'AccountsController:updateAccountMetadata',\n ).mockResolvedValue(true as never);\n\n const mockNetworkControllerGetState = typedMockFn(\n 'NetworkController:getState',\n ).mockReturnValue({\n selectedNetworkClientId: '',\n networksMetadata: {},\n networkConfigurationsByChainId: {},\n });\n\n const mockNetworkControllerAddNetwork = typedMockFn(\n 'NetworkController:addNetwork',\n );\n\n const mockNetworkControllerRemoveNetwork = typedMockFn(\n 'NetworkController:removeNetwork',\n );\n\n const mockNetworkControllerUpdateNetwork = typedMockFn(\n 'NetworkController:updateNetwork',\n );\n\n jest.spyOn(messenger, 'call').mockImplementation((...args) => {\n const typedArgs = args as unknown as CallParams;\n const [actionType] = typedArgs;\n\n if (actionType === 'SnapController:handleRequest') {\n const [, params] = typedArgs;\n if (params.request.method === 'getPublicKey') {\n return mockSnapGetPublicKey();\n }\n\n if (params.request.method === 'signMessage') {\n return mockSnapSignMessage();\n }\n\n throw new Error(\n `MOCK_FAIL - unsupported SnapController:handleRequest call: ${\n params.request.method as string\n }`,\n );\n }\n\n if (actionType === 'AuthenticationController:getBearerToken') {\n return mockAuthGetBearerToken();\n }\n\n if (actionType === 'AuthenticationController:getSessionProfile') {\n return mockAuthGetSessionProfile();\n }\n\n if (actionType === 'AuthenticationController:performSignIn') {\n return mockAuthPerformSignIn();\n }\n\n if (actionType === 'AuthenticationController:isSignedIn') {\n return mockAuthIsSignedIn();\n }\n\n if (\n actionType ===\n 'NotificationServicesController:selectIsNotificationServicesEnabled'\n ) {\n return mockNotificationServicesIsEnabled();\n }\n\n if (\n actionType ===\n 'NotificationServicesController:disableNotificationServices'\n ) {\n return mockNotificationServicesDisableNotifications();\n }\n\n if (actionType === 'AuthenticationController:performSignOut') {\n return mockAuthPerformSignOut();\n }\n\n if (actionType === 'KeyringController:getState') {\n return { isUnlocked: true };\n }\n\n if (actionType === 'KeyringController:addNewAccount') {\n return mockKeyringAddNewAccount();\n }\n\n if (actionType === 'AccountsController:listAccounts') {\n return mockAccountsListAccounts();\n }\n\n if (typedArgs[0] === 'AccountsController:updateAccountMetadata') {\n const [, ...params] = typedArgs;\n return mockAccountsUpdateAccountMetadata(...params);\n }\n\n if (actionType === 'NetworkController:getState') {\n return mockNetworkControllerGetState();\n }\n\n if (actionType === 'NetworkController:addNetwork') {\n const [, ...params] = typedArgs;\n return mockNetworkControllerAddNetwork(...params);\n }\n\n if (actionType === 'NetworkController:removeNetwork') {\n const [, ...params] = typedArgs;\n return mockNetworkControllerRemoveNetwork(...params);\n }\n\n if (actionType === 'NetworkController:updateNetwork') {\n const [, ...params] = typedArgs;\n return mockNetworkControllerUpdateNetwork(...params);\n }\n\n throw new Error(\n `MOCK_FAIL - unsupported messenger call: ${actionType as string}`,\n );\n });\n\n return {\n baseMessenger,\n messenger,\n mockSnapGetPublicKey,\n mockSnapSignMessage,\n mockAuthGetBearerToken,\n mockAuthGetSessionProfile,\n mockAuthPerformSignIn,\n mockAuthIsSignedIn,\n mockNotificationServicesIsEnabled,\n mockNotificationServicesDisableNotifications,\n mockAuthPerformSignOut,\n mockKeyringAddNewAccount,\n mockAccountsUpdateAccountMetadata,\n mockAccountsListAccounts,\n mockNetworkControllerGetState,\n mockNetworkControllerAddNetwork,\n mockNetworkControllerRemoveNetwork,\n mockNetworkControllerUpdateNetwork,\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mockMessenger.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/__fixtures__/mockMessenger.ts"],"names":[],"mappings":";;;AACA,+DAAsD;AAEtD,kCAA+C;AAmB/C,MAAM,WAAW,GAAG,CAQlB,KAAiB,EACjB,EAAE,CAAC,IAAI,CAAC,EAAE,EAAsC,CAAC;AAOnD;;;;;;GAMG;AACH,SAAgB,gCAAgC,CAAC,KAEhD;IACC,MAAM,aAAa,GAAG,IAAI,2BAAS,EAAiC,CAAC;IACrE,MAAM,SAAS,GAAG,aAAa,CAAC,aAAa,CAAC;QAC5C,IAAI,EAAE,uBAAuB;QAC7B,cAAc,EA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AAO,kCAAkC,CAAC,GAAG,MAAM,CAAC,CAAC;SACtD;QAED,MAAM,IAAI,KAAK,CACb,2CAA2C,UAAoB,EAAE,CAClE,CAAC;IACJ,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,aAAa;QACb,SAAS;QACT,oBAAoB;QACpB,mBAAmB;QACnB,sBAAsB;QACtB,yBAAyB;QACzB,qBAAqB;QACrB,kBAAkB;QAClB,sBAAsB;QACtB,wBAAwB;QACxB,iCAAiC;QACjC,wBAAwB;QACxB,6BAA6B;QAC7B,+BAA+B;QAC/B,kCAAkC;QAClC,kCAAkC;KACnC,CAAC;AACJ,CAAC;AAtKD,4DAsKC","sourcesContent":["import type { NotNamespacedBy } from '@metamask/base-controller';\nimport { Messenger } from '@metamask/base-controller';\n\nimport { MOCK_STORAGE_KEY_SIGNATURE } from '.';\nimport type {\n AllowedActions,\n AllowedEvents,\n UserStorageControllerMessenger,\n} from '..';\n\ntype GetHandler<ActionType extends AllowedActions['type']> = Extract<\n AllowedActions,\n { type: ActionType }\n>['handler'];\n\ntype CallParams = {\n [K in AllowedActions['type']]: [\n K,\n ...Parameters<Extract<AllowedActions, { type: K }>['handler']>,\n ];\n}[AllowedActions['type']];\n\nconst typedMockFn = <\n ActionType extends AllowedActions['type'],\n Handler = GetHandler<ActionType>,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n Func extends (...args: any) => any = Handler extends (...args: any[]) => any\n ? Handler\n : never,\n>(\n _type: ActionType,\n) => jest.fn<ReturnType<Func>, Parameters<Func>>();\n\ntype ExternalEvents = NotNamespacedBy<\n 'UserStorageController',\n AllowedEvents['type']\n>;\n\n/**\n * creates a custom user storage messenger, in case tests need different permissions\n *\n * @param props - overrides\n * @param props.overrideEvents - override events\n * @returns base messenger, and messenger. You can pass this into the mocks below to mock messenger calls\n */\nexport function createCustomUserStorageMessenger(props?: {\n overrideEvents?: ExternalEvents[];\n}) {\n const baseMessenger = new Messenger<AllowedActions, AllowedEvents>();\n const messenger = baseMessenger.getRestricted({\n name: 'UserStorageController',\n allowedActions: [\n 'KeyringController:getState',\n 'KeyringController:addNewAccount',\n 'SnapController:handleRequest',\n 'AuthenticationController:getBearerToken',\n 'AuthenticationController:getSessionProfile',\n 'AuthenticationController:isSignedIn',\n 'AuthenticationController:performSignOut',\n 'AuthenticationController:performSignIn',\n 'AccountsController:listAccounts',\n 'AccountsController:updateAccountMetadata',\n 'NetworkController:getState',\n 'NetworkController:addNetwork',\n 'NetworkController:updateNetwork',\n 'NetworkController:removeNetwork',\n ],\n allowedEvents: props?.overrideEvents ?? [\n 'KeyringController:lock',\n 'KeyringController:unlock',\n 'AccountsController:accountAdded',\n 'AccountsController:accountRenamed',\n 'NetworkController:networkRemoved',\n ],\n });\n\n return {\n baseMessenger,\n messenger,\n };\n}\n\ntype OverrideMessengers = {\n baseMessenger: Messenger<AllowedActions, AllowedEvents>;\n messenger: UserStorageControllerMessenger;\n};\n\n/**\n * Jest Mock Utility to generate a mock User Storage Messenger\n *\n * @param overrideMessengers - override messengers if need to modify the underlying permissions\n * @returns series of mocks to actions that can be called\n */\nexport function mockUserStorageMessenger(\n overrideMessengers?: OverrideMessengers,\n) {\n const { baseMessenger, messenger } =\n overrideMessengers ?? createCustomUserStorageMessenger();\n\n const mockSnapGetPublicKey = jest.fn().mockResolvedValue('MOCK_PUBLIC_KEY');\n const mockSnapSignMessage = jest\n .fn()\n .mockResolvedValue(MOCK_STORAGE_KEY_SIGNATURE);\n\n const mockAuthGetBearerToken = typedMockFn(\n 'AuthenticationController:getBearerToken',\n ).mockResolvedValue('MOCK_BEARER_TOKEN');\n\n const mockAuthGetSessionProfile = typedMockFn(\n 'AuthenticationController:getSessionProfile',\n ).mockResolvedValue({\n identifierId: '',\n profileId: 'MOCK_PROFILE_ID',\n });\n\n const mockAuthPerformSignIn = typedMockFn(\n 'AuthenticationController:performSignIn',\n ).mockResolvedValue('New Access Token');\n\n const mockAuthIsSignedIn = typedMockFn(\n 'AuthenticationController:isSignedIn',\n ).mockReturnValue(true);\n\n const mockAuthPerformSignOut = typedMockFn(\n 'AuthenticationController:performSignOut',\n );\n\n const mockKeyringAddNewAccount = typedMockFn(\n 'KeyringController:addNewAccount',\n );\n\n // Untyped mock as there is a TS(2742) issue.\n // This will return `InternalAccount[]`\n const mockAccountsListAccounts = jest.fn();\n\n const mockAccountsUpdateAccountMetadata = typedMockFn(\n 'AccountsController:updateAccountMetadata',\n ).mockResolvedValue(true as never);\n\n const mockNetworkControllerGetState = typedMockFn(\n 'NetworkController:getState',\n ).mockReturnValue({\n selectedNetworkClientId: '',\n networksMetadata: {},\n networkConfigurationsByChainId: {},\n });\n\n const mockNetworkControllerAddNetwork = typedMockFn(\n 'NetworkController:addNetwork',\n );\n\n const mockNetworkControllerRemoveNetwork = typedMockFn(\n 'NetworkController:removeNetwork',\n );\n\n const mockNetworkControllerUpdateNetwork = typedMockFn(\n 'NetworkController:updateNetwork',\n );\n\n jest.spyOn(messenger, 'call').mockImplementation((...args) => {\n const typedArgs = args as unknown as CallParams;\n const [actionType] = typedArgs;\n\n if (actionType === 'SnapController:handleRequest') {\n const [, params] = typedArgs;\n if (params.request.method === 'getPublicKey') {\n return mockSnapGetPublicKey();\n }\n\n if (params.request.method === 'signMessage') {\n return mockSnapSignMessage();\n }\n\n throw new Error(\n `MOCK_FAIL - unsupported SnapController:handleRequest call: ${\n params.request.method as string\n }`,\n );\n }\n\n if (actionType === 'AuthenticationController:getBearerToken') {\n return mockAuthGetBearerToken();\n }\n\n if (actionType === 'AuthenticationController:getSessionProfile') {\n return mockAuthGetSessionProfile();\n }\n\n if (actionType === 'AuthenticationController:performSignIn') {\n return mockAuthPerformSignIn();\n }\n\n if (actionType === 'AuthenticationController:isSignedIn') {\n return mockAuthIsSignedIn();\n }\n\n if (actionType === 'AuthenticationController:performSignOut') {\n return mockAuthPerformSignOut();\n }\n\n if (actionType === 'KeyringController:getState') {\n return { isUnlocked: true };\n }\n\n if (actionType === 'KeyringController:addNewAccount') {\n return mockKeyringAddNewAccount();\n }\n\n if (actionType === 'AccountsController:listAccounts') {\n return mockAccountsListAccounts();\n }\n\n if (typedArgs[0] === 'AccountsController:updateAccountMetadata') {\n const [, ...params] = typedArgs;\n return mockAccountsUpdateAccountMetadata(...params);\n }\n\n if (actionType === 'NetworkController:getState') {\n return mockNetworkControllerGetState();\n }\n\n if (actionType === 'NetworkController:addNetwork') {\n const [, ...params] = typedArgs;\n return mockNetworkControllerAddNetwork(...params);\n }\n\n if (actionType === 'NetworkController:removeNetwork') {\n const [, ...params] = typedArgs;\n return mockNetworkControllerRemoveNetwork(...params);\n }\n\n if (actionType === 'NetworkController:updateNetwork') {\n const [, ...params] = typedArgs;\n return mockNetworkControllerUpdateNetwork(...params);\n }\n\n throw new Error(\n `MOCK_FAIL - unsupported messenger call: ${actionType as string}`,\n );\n });\n\n return {\n baseMessenger,\n messenger,\n mockSnapGetPublicKey,\n mockSnapSignMessage,\n mockAuthGetBearerToken,\n mockAuthGetSessionProfile,\n mockAuthPerformSignIn,\n mockAuthIsSignedIn,\n mockAuthPerformSignOut,\n mockKeyringAddNewAccount,\n mockAccountsUpdateAccountMetadata,\n mockAccountsListAccounts,\n mockNetworkControllerGetState,\n mockNetworkControllerAddNetwork,\n mockNetworkControllerRemoveNetwork,\n mockNetworkControllerUpdateNetwork,\n };\n}\n"]}
|