@metamask-previews/profile-sync-controller 5.0.0-preview-0adfc600 → 5.0.0-preview-99939da3
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 +0 -6
- package/dist/controllers/user-storage/UserStorageController.cjs +34 -5
- package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.cts +10 -1
- package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.mts +10 -1
- package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.mjs +34 -5
- package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.cjs +14 -0
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.cjs.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.cts +4 -2
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.cts.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.mts +4 -2
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.mts.map +1 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.mjs +14 -0
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts +3 -1
- 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 +3 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts.map +1 -1
- package/package.json +6 -6
|
@@ -9,7 +9,7 @@ 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, _UserStorageController_isUnlocked, _UserStorageController_keyringController, _UserStorageController_nativeScryptCrypto, _UserStorageController_registerMessageHandlers, _UserStorageController_getStorageOptions, _UserStorageController_getStorageKeyAndBearerToken, _UserStorageController_createStorageKey, _UserStorageController__snapSignMessageCache, _UserStorageController_snapSignMessage, _UserStorageController_setIsProfileSyncingUpdateLoading;
|
|
12
|
+
var _UserStorageController_instances, _UserStorageController_env, _UserStorageController_auth, _UserStorageController_config, _UserStorageController_notificationServices, _UserStorageController_isUnlocked, _UserStorageController_keyringController, _UserStorageController_nativeScryptCrypto, _UserStorageController_registerMessageHandlers, _UserStorageController_getStorageOptions, _UserStorageController_assertProfileSyncingEnabled, _UserStorageController_getStorageKeyAndBearerToken, _UserStorageController_createStorageKey, _UserStorageController__snapSignMessageCache, _UserStorageController_snapSignMessage, _UserStorageController_setIsProfileSyncingUpdateLoading;
|
|
13
13
|
import { BaseController } from "@metamask/base-controller";
|
|
14
14
|
import { saveInternalAccountToUserStorage, syncInternalAccountsWithUserStorage } from "./account-syncing/controller-integration.mjs";
|
|
15
15
|
import { setupAccountSyncingSubscriptions } from "./account-syncing/setup-subscriptions.mjs";
|
|
@@ -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
|
+
isAuthEnabled: () => {
|
|
86
86
|
return this.messagingSystem.call('AuthenticationController:isSignedIn');
|
|
87
87
|
},
|
|
88
88
|
signIn: async () => {
|
|
@@ -93,6 +93,14 @@ 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
|
+
});
|
|
96
104
|
_UserStorageController_isUnlocked.set(this, false);
|
|
97
105
|
_UserStorageController_keyringController.set(this, {
|
|
98
106
|
setupLockedStateSubscriptions: () => {
|
|
@@ -134,8 +142,8 @@ class UserStorageController extends BaseController {
|
|
|
134
142
|
async enableProfileSyncing() {
|
|
135
143
|
try {
|
|
136
144
|
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_setIsProfileSyncingUpdateLoading).call(this, true);
|
|
137
|
-
const
|
|
138
|
-
if (!
|
|
145
|
+
const authEnabled = __classPrivateFieldGet(this, _UserStorageController_auth, "f").isAuthEnabled();
|
|
146
|
+
if (!authEnabled) {
|
|
139
147
|
await __classPrivateFieldGet(this, _UserStorageController_auth, "f").signIn();
|
|
140
148
|
}
|
|
141
149
|
this.update((state) => {
|
|
@@ -149,6 +157,11 @@ class UserStorageController extends BaseController {
|
|
|
149
157
|
throw new Error(`${controllerName} - failed to enable profile syncing - ${errorMessage}`);
|
|
150
158
|
}
|
|
151
159
|
}
|
|
160
|
+
async setIsProfileSyncingEnabled(isProfileSyncingEnabled) {
|
|
161
|
+
this.update((state) => {
|
|
162
|
+
state.isProfileSyncingEnabled = isProfileSyncingEnabled;
|
|
163
|
+
});
|
|
164
|
+
}
|
|
152
165
|
async disableProfileSyncing() {
|
|
153
166
|
const isAlreadyDisabled = !this.state.isProfileSyncingEnabled;
|
|
154
167
|
if (isAlreadyDisabled) {
|
|
@@ -156,6 +169,10 @@ class UserStorageController extends BaseController {
|
|
|
156
169
|
}
|
|
157
170
|
try {
|
|
158
171
|
__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
|
+
}
|
|
159
176
|
const isMetaMetricsParticipation = this.getMetaMetricsState();
|
|
160
177
|
if (!isMetaMetricsParticipation) {
|
|
161
178
|
await __classPrivateFieldGet(this, _UserStorageController_auth, "f").signOut();
|
|
@@ -179,6 +196,7 @@ class UserStorageController extends BaseController {
|
|
|
179
196
|
* @returns the decrypted string contents found from user storage (or null if not found)
|
|
180
197
|
*/
|
|
181
198
|
async performGetStorage(path) {
|
|
199
|
+
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
182
200
|
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageKeyAndBearerToken).call(this);
|
|
183
201
|
const result = await getUserStorage({
|
|
184
202
|
path,
|
|
@@ -196,6 +214,7 @@ class UserStorageController extends BaseController {
|
|
|
196
214
|
* @returns the array of decrypted string contents found from user storage (or null if not found)
|
|
197
215
|
*/
|
|
198
216
|
async performGetStorageAllFeatureEntries(path) {
|
|
217
|
+
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
199
218
|
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageKeyAndBearerToken).call(this);
|
|
200
219
|
const result = await getUserStorageAllFeatureEntries({
|
|
201
220
|
path,
|
|
@@ -214,6 +233,7 @@ class UserStorageController extends BaseController {
|
|
|
214
233
|
* @returns nothing. NOTE that an error is thrown if fails to store data.
|
|
215
234
|
*/
|
|
216
235
|
async performSetStorage(path, value) {
|
|
236
|
+
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
217
237
|
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageKeyAndBearerToken).call(this);
|
|
218
238
|
await upsertUserStorage(value, {
|
|
219
239
|
path,
|
|
@@ -231,6 +251,7 @@ class UserStorageController extends BaseController {
|
|
|
231
251
|
* @returns nothing. NOTE that an error is thrown if fails to store data.
|
|
232
252
|
*/
|
|
233
253
|
async performBatchSetStorage(path, values) {
|
|
254
|
+
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
234
255
|
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageKeyAndBearerToken).call(this);
|
|
235
256
|
await batchUpsertUserStorage(values, {
|
|
236
257
|
path,
|
|
@@ -246,6 +267,7 @@ class UserStorageController extends BaseController {
|
|
|
246
267
|
* @returns nothing. NOTE that an error is thrown if fails to delete data.
|
|
247
268
|
*/
|
|
248
269
|
async performDeleteStorage(path) {
|
|
270
|
+
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
249
271
|
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageKeyAndBearerToken).call(this);
|
|
250
272
|
await deleteUserStorage({
|
|
251
273
|
path,
|
|
@@ -261,6 +283,7 @@ class UserStorageController extends BaseController {
|
|
|
261
283
|
* @returns nothing. NOTE that an error is thrown if fails to delete data.
|
|
262
284
|
*/
|
|
263
285
|
async performDeleteStorageAllFeatureEntries(path) {
|
|
286
|
+
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
264
287
|
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageKeyAndBearerToken).call(this);
|
|
265
288
|
await deleteUserStorageAllFeatureEntries({
|
|
266
289
|
path,
|
|
@@ -277,6 +300,7 @@ class UserStorageController extends BaseController {
|
|
|
277
300
|
* @returns nothing. NOTE that an error is thrown if fails to store data.
|
|
278
301
|
*/
|
|
279
302
|
async performBatchDeleteStorage(path, values) {
|
|
303
|
+
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
280
304
|
const { bearerToken, storageKey } = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_getStorageKeyAndBearerToken).call(this);
|
|
281
305
|
await batchDeleteUserStorage(values, {
|
|
282
306
|
path,
|
|
@@ -291,6 +315,7 @@ class UserStorageController extends BaseController {
|
|
|
291
315
|
* @returns the storage key
|
|
292
316
|
*/
|
|
293
317
|
async getStorageKey() {
|
|
318
|
+
__classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_assertProfileSyncingEnabled).call(this);
|
|
294
319
|
const storageKey = await __classPrivateFieldGet(this, _UserStorageController_instances, "m", _UserStorageController_createStorageKey).call(this);
|
|
295
320
|
return storageKey;
|
|
296
321
|
}
|
|
@@ -358,7 +383,7 @@ class UserStorageController extends BaseController {
|
|
|
358
383
|
});
|
|
359
384
|
}
|
|
360
385
|
}
|
|
361
|
-
_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
|
+
_UserStorageController_env = new WeakMap(), _UserStorageController_auth = new WeakMap(), _UserStorageController_config = new WeakMap(), _UserStorageController_notificationServices = 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() {
|
|
362
387
|
this.messagingSystem.registerActionHandler('UserStorageController:performGetStorage', this.performGetStorage.bind(this));
|
|
363
388
|
this.messagingSystem.registerActionHandler('UserStorageController:performGetStorageAllFeatureEntries', this.performGetStorageAllFeatureEntries.bind(this));
|
|
364
389
|
this.messagingSystem.registerActionHandler('UserStorageController:performSetStorage', this.performSetStorage.bind(this));
|
|
@@ -377,6 +402,10 @@ _UserStorageController_env = new WeakMap(), _UserStorageController_auth = new We
|
|
|
377
402
|
bearerToken,
|
|
378
403
|
nativeScryptCrypto: __classPrivateFieldGet(this, _UserStorageController_nativeScryptCrypto, "f"),
|
|
379
404
|
};
|
|
405
|
+
}, _UserStorageController_assertProfileSyncingEnabled = function _UserStorageController_assertProfileSyncingEnabled() {
|
|
406
|
+
if (!this.state.isProfileSyncingEnabled) {
|
|
407
|
+
throw new Error(`${controllerName}: Unable to call method, user is not authenticated`);
|
|
408
|
+
}
|
|
380
409
|
}, _UserStorageController_getStorageKeyAndBearerToken =
|
|
381
410
|
/**
|
|
382
411
|
* Utility to get the bearer token and storage key
|
|
@@ -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,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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AC9B,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;eArdkB,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 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 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 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 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"]}
|
|
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,EACjB,kCAAkC,EAClC,cAAc,EACd,+BAA+B,EAC/B,iBAAiB,EAClB,uBAAmB;AACpB,OAAO,EAAE,gBAAgB,EAAE,0CAAgC;AAO3D,OAAO,EAAE,4BAA4B,EAAE,iDAA6C;AAsBpF,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,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AAkB,MAAtB,IAAI,CAAoB,CAAC;IAElD,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,CAAC;AACrC,CAAC;AAED;;;;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;eAxgBkB,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\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 *\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 // 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 = 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 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 readonly #config?: ControllerConfig;\n\n readonly #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 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 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 * @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"]}
|
|
@@ -24,6 +24,8 @@ function createCustomUserStorageMessenger(props) {
|
|
|
24
24
|
'AuthenticationController:isSignedIn',
|
|
25
25
|
'AuthenticationController:performSignOut',
|
|
26
26
|
'AuthenticationController:performSignIn',
|
|
27
|
+
'NotificationServicesController:disableNotificationServices',
|
|
28
|
+
'NotificationServicesController:selectIsNotificationServicesEnabled',
|
|
27
29
|
'AccountsController:listAccounts',
|
|
28
30
|
'AccountsController:updateAccountMetadata',
|
|
29
31
|
'NetworkController:getState',
|
|
@@ -65,6 +67,8 @@ function mockUserStorageMessenger(overrideMessengers) {
|
|
|
65
67
|
const mockAuthPerformSignIn = typedMockFn('AuthenticationController:performSignIn').mockResolvedValue('New Access Token');
|
|
66
68
|
const mockAuthIsSignedIn = typedMockFn('AuthenticationController:isSignedIn').mockReturnValue(true);
|
|
67
69
|
const mockAuthPerformSignOut = typedMockFn('AuthenticationController:performSignOut');
|
|
70
|
+
const mockNotificationServicesIsEnabled = typedMockFn('NotificationServicesController:selectIsNotificationServicesEnabled').mockReturnValue(true);
|
|
71
|
+
const mockNotificationServicesDisableNotifications = typedMockFn('NotificationServicesController:disableNotificationServices').mockResolvedValue();
|
|
68
72
|
const mockKeyringAddNewAccount = typedMockFn('KeyringController:addNewAccount');
|
|
69
73
|
// Untyped mock as there is a TS(2742) issue.
|
|
70
74
|
// This will return `InternalAccount[]`
|
|
@@ -103,6 +107,14 @@ function mockUserStorageMessenger(overrideMessengers) {
|
|
|
103
107
|
if (actionType === 'AuthenticationController:isSignedIn') {
|
|
104
108
|
return mockAuthIsSignedIn();
|
|
105
109
|
}
|
|
110
|
+
if (actionType ===
|
|
111
|
+
'NotificationServicesController:selectIsNotificationServicesEnabled') {
|
|
112
|
+
return mockNotificationServicesIsEnabled();
|
|
113
|
+
}
|
|
114
|
+
if (actionType ===
|
|
115
|
+
'NotificationServicesController:disableNotificationServices') {
|
|
116
|
+
return mockNotificationServicesDisableNotifications();
|
|
117
|
+
}
|
|
106
118
|
if (actionType === 'AuthenticationController:performSignOut') {
|
|
107
119
|
return mockAuthPerformSignOut();
|
|
108
120
|
}
|
|
@@ -145,6 +157,8 @@ function mockUserStorageMessenger(overrideMessengers) {
|
|
|
145
157
|
mockAuthGetSessionProfile,
|
|
146
158
|
mockAuthPerformSignIn,
|
|
147
159
|
mockAuthIsSignedIn,
|
|
160
|
+
mockNotificationServicesIsEnabled,
|
|
161
|
+
mockNotificationServicesDisableNotifications,
|
|
148
162
|
mockAuthPerformSignOut,
|
|
149
163
|
mockKeyringAddNewAccount,
|
|
150
164
|
mockAccountsUpdateAccountMetadata,
|
|
@@ -1 +1 @@
|
|
|
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,EAAE;YACd,4BAA4B;YAC5B,iCAAiC;YACjC,8BAA8B;YAC9B,yCAAyC;YACzC,4CAA4C;YAC5C,qCAAqC;YACrC,yCAAyC;YACzC,wCAAwC;YACxC,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;AAnCD,4EAmCC;AAOD;;;;;GAKG;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,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D,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,SAAS,CAAC;YAChC,OAAO,iCAAiC,CAAC,GAAG,MAAM,CAAC,CAAC;SACrD;QAED,IAAI,UAAU,KAAK,4BAA4B,EAAE;YAC/C,OAAO,6BAA6B,EAAE,CAAC;SACxC;QAED,IAAI,UAAU,KAAK,8BAA8B,EAAE;YACjD,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,SAAS,CAAC;YAChC,OAAO,+BAA+B,CAAC,GAAG,MAAM,CAAC,CAAC;SACnD;QAED,IAAI,UAAU,KAAK,iCAAiC,EAAE;YACpD,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,SAAS,CAAC;YAChC,OAAO,kCAAkC,CAAC,GAAG,MAAM,CAAC,CAAC;SACtD;QAED,IAAI,UAAU,KAAK,iCAAiC,EAAE;YACpD,MAAM,CAAC,EAAE,GAAG,MAAM,CAAC,GAAG,SAAS,CAAC;YAChC,OAAO,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"]}
|
|
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,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;AArCD,4EAqCC;AAOD;;;;;GAKG;AACH,SAAgB,wBAAwB,CACtC,kBAAuC;IAEvC,MAAM,EAAE,aAAa,EAAE,SAAS,EAAE,GAChC,kBAAkB,IAAI,gCAAgC,EAAE,CAAC;IAE3D,MAAM,oBAAoB,GAAG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jC,4CAA4C;QAC5C,sBAAsB;QACtB,wBAAwB;QACxB,iCAAiC;QACjC,wBAAwB;QACxB,6BAA6B;QAC7B,+BAA+B;QAC/B,kCAAkC;QAClC,kCAAkC;KACnC,CAAC;AACJ,CAAC;AA9LD,4DA8LC","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 '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: 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 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"]}
|
|
@@ -32,7 +32,7 @@ export declare function createCustomUserStorageMessenger(props?: {
|
|
|
32
32
|
identifierId: string;
|
|
33
33
|
profileId: string;
|
|
34
34
|
}>;
|
|
35
|
-
} | import("@metamask/keyring-controller").KeyringControllerGetStateAction | import("@metamask/accounts-controller").AccountsControllerListAccountsAction | import("@metamask/accounts-controller").AccountsControllerUpdateAccountMetadataAction | import("@metamask/keyring-controller").KeyringControllerAddNewAccountAction | import("@metamask/network-controller").NetworkControllerGetStateAction | import("@metamask/network-controller").NetworkControllerAddNetworkAction | import("@metamask/network-controller").NetworkControllerRemoveNetworkAction | import("@metamask/network-controller").NetworkControllerUpdateNetworkAction, import("@metamask/keyring-controller").KeyringControllerLockEvent | import("@metamask/keyring-controller").KeyringControllerUnlockEvent | import("../index.cjs").UserStorageControllerStateChangeEvent | import("../index.cjs").UserStorageControllerAccountSyncingInProgress | import("../index.cjs").UserStorageControllerAccountSyncingComplete | import("@metamask/accounts-controller").AccountsControllerAccountAddedEvent | import("@metamask/accounts-controller").AccountsControllerAccountRenamedEvent | import("@metamask/network-controller").NetworkControllerNetworkRemovedEvent, "SnapController:handleRequest" | "KeyringController:getState" | "AuthenticationController:isSignedIn" | "AuthenticationController:performSignIn" | "AuthenticationController:performSignOut" | "AuthenticationController:getBearerToken" | "AuthenticationController:getSessionProfile" | "AccountsController:listAccounts" | "AccountsController:updateAccountMetadata" | "KeyringController:addNewAccount" | "NetworkController:getState" | "NetworkController:addNetwork" | "NetworkController:removeNetwork" | "NetworkController:updateNetwork", "KeyringController:lock" | "KeyringController:unlock" | "AccountsController:accountAdded" | "AccountsController:accountRenamed" | "NetworkController:networkRemoved">;
|
|
35
|
+
} | import("@metamask/keyring-controller").KeyringControllerGetStateAction | import("../index.cjs").NotificationServicesControllerDisableNotificationServices | import("../index.cjs").NotificationServicesControllerSelectIsNotificationServicesEnabled | import("@metamask/accounts-controller").AccountsControllerListAccountsAction | import("@metamask/accounts-controller").AccountsControllerUpdateAccountMetadataAction | import("@metamask/keyring-controller").KeyringControllerAddNewAccountAction | import("@metamask/network-controller").NetworkControllerGetStateAction | import("@metamask/network-controller").NetworkControllerAddNetworkAction | import("@metamask/network-controller").NetworkControllerRemoveNetworkAction | import("@metamask/network-controller").NetworkControllerUpdateNetworkAction, import("@metamask/keyring-controller").KeyringControllerLockEvent | import("@metamask/keyring-controller").KeyringControllerUnlockEvent | import("../index.cjs").UserStorageControllerStateChangeEvent | import("../index.cjs").UserStorageControllerAccountSyncingInProgress | import("../index.cjs").UserStorageControllerAccountSyncingComplete | import("@metamask/accounts-controller").AccountsControllerAccountAddedEvent | import("@metamask/accounts-controller").AccountsControllerAccountRenamedEvent | import("@metamask/network-controller").NetworkControllerNetworkRemovedEvent, "SnapController:handleRequest" | "KeyringController:getState" | "AuthenticationController:isSignedIn" | "AuthenticationController:performSignIn" | "AuthenticationController:performSignOut" | "AuthenticationController:getBearerToken" | "AuthenticationController:getSessionProfile" | "NotificationServicesController:disableNotificationServices" | "NotificationServicesController:selectIsNotificationServicesEnabled" | "AccountsController:listAccounts" | "AccountsController:updateAccountMetadata" | "KeyringController:addNewAccount" | "NetworkController:getState" | "NetworkController:addNetwork" | "NetworkController:removeNetwork" | "NetworkController:updateNetwork", "KeyringController:lock" | "KeyringController:unlock" | "AccountsController:accountAdded" | "AccountsController:accountRenamed" | "NetworkController:networkRemoved">;
|
|
36
36
|
};
|
|
37
37
|
type OverrideMessengers = {
|
|
38
38
|
baseMessenger: Messenger<AllowedActions, AllowedEvents>;
|
|
@@ -64,7 +64,7 @@ export declare function mockUserStorageMessenger(overrideMessengers?: OverrideMe
|
|
|
64
64
|
identifierId: string;
|
|
65
65
|
profileId: string;
|
|
66
66
|
}>;
|
|
67
|
-
} | import("@metamask/keyring-controller").KeyringControllerGetStateAction | import("@metamask/accounts-controller").AccountsControllerListAccountsAction | import("@metamask/accounts-controller").AccountsControllerUpdateAccountMetadataAction | import("@metamask/keyring-controller").KeyringControllerAddNewAccountAction | import("@metamask/network-controller").NetworkControllerGetStateAction | import("@metamask/network-controller").NetworkControllerAddNetworkAction | import("@metamask/network-controller").NetworkControllerRemoveNetworkAction | import("@metamask/network-controller").NetworkControllerUpdateNetworkAction, import("@metamask/keyring-controller").KeyringControllerLockEvent | import("@metamask/keyring-controller").KeyringControllerUnlockEvent | import("../index.cjs").UserStorageControllerStateChangeEvent | import("../index.cjs").UserStorageControllerAccountSyncingInProgress | import("../index.cjs").UserStorageControllerAccountSyncingComplete | import("@metamask/accounts-controller").AccountsControllerAccountAddedEvent | import("@metamask/accounts-controller").AccountsControllerAccountRenamedEvent | import("@metamask/network-controller").NetworkControllerNetworkRemovedEvent, "SnapController:handleRequest" | "KeyringController:getState" | "AuthenticationController:isSignedIn" | "AuthenticationController:performSignIn" | "AuthenticationController:performSignOut" | "AuthenticationController:getBearerToken" | "AuthenticationController:getSessionProfile" | "AccountsController:listAccounts" | "AccountsController:updateAccountMetadata" | "KeyringController:addNewAccount" | "NetworkController:getState" | "NetworkController:addNetwork" | "NetworkController:removeNetwork" | "NetworkController:updateNetwork", "KeyringController:lock" | "KeyringController:unlock" | "AccountsController:accountAdded" | "AccountsController:accountRenamed" | "NetworkController:networkRemoved">;
|
|
67
|
+
} | import("@metamask/keyring-controller").KeyringControllerGetStateAction | import("../index.cjs").NotificationServicesControllerDisableNotificationServices | import("../index.cjs").NotificationServicesControllerSelectIsNotificationServicesEnabled | import("@metamask/accounts-controller").AccountsControllerListAccountsAction | import("@metamask/accounts-controller").AccountsControllerUpdateAccountMetadataAction | import("@metamask/keyring-controller").KeyringControllerAddNewAccountAction | import("@metamask/network-controller").NetworkControllerGetStateAction | import("@metamask/network-controller").NetworkControllerAddNetworkAction | import("@metamask/network-controller").NetworkControllerRemoveNetworkAction | import("@metamask/network-controller").NetworkControllerUpdateNetworkAction, import("@metamask/keyring-controller").KeyringControllerLockEvent | import("@metamask/keyring-controller").KeyringControllerUnlockEvent | import("../index.cjs").UserStorageControllerStateChangeEvent | import("../index.cjs").UserStorageControllerAccountSyncingInProgress | import("../index.cjs").UserStorageControllerAccountSyncingComplete | import("@metamask/accounts-controller").AccountsControllerAccountAddedEvent | import("@metamask/accounts-controller").AccountsControllerAccountRenamedEvent | import("@metamask/network-controller").NetworkControllerNetworkRemovedEvent, "SnapController:handleRequest" | "KeyringController:getState" | "AuthenticationController:isSignedIn" | "AuthenticationController:performSignIn" | "AuthenticationController:performSignOut" | "AuthenticationController:getBearerToken" | "AuthenticationController:getSessionProfile" | "NotificationServicesController:disableNotificationServices" | "NotificationServicesController:selectIsNotificationServicesEnabled" | "AccountsController:listAccounts" | "AccountsController:updateAccountMetadata" | "KeyringController:addNewAccount" | "NetworkController:getState" | "NetworkController:addNetwork" | "NetworkController:removeNetwork" | "NetworkController:updateNetwork", "KeyringController:lock" | "KeyringController:unlock" | "AccountsController:accountAdded" | "AccountsController:accountRenamed" | "NetworkController:networkRemoved">;
|
|
68
68
|
mockSnapGetPublicKey: jest.Mock<any, any>;
|
|
69
69
|
mockSnapSignMessage: jest.Mock<any, any>;
|
|
70
70
|
mockAuthGetBearerToken: jest.Mock<Promise<string>, []>;
|
|
@@ -74,6 +74,8 @@ export declare function mockUserStorageMessenger(overrideMessengers?: OverrideMe
|
|
|
74
74
|
}>, []>;
|
|
75
75
|
mockAuthPerformSignIn: jest.Mock<Promise<string>, []>;
|
|
76
76
|
mockAuthIsSignedIn: jest.Mock<boolean, []>;
|
|
77
|
+
mockNotificationServicesIsEnabled: jest.Mock<boolean, []>;
|
|
78
|
+
mockNotificationServicesDisableNotifications: jest.Mock<Promise<void>, []>;
|
|
77
79
|
mockAuthPerformSignOut: jest.Mock<void, []>;
|
|
78
80
|
mockKeyringAddNewAccount: jest.Mock<Promise<string>, [accountCount?: number | undefined]>;
|
|
79
81
|
mockAccountsUpdateAccountMetadata: jest.Mock<void, [accountId: string, metadata: Partial<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mockMessenger.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/__fixtures__/mockMessenger.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,kCAAkC;AACjE,OAAO,EAAE,SAAS,EAAE,kCAAkC;AAGtD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,8BAA8B,EAC/B,qBAAW;AAyBZ,KAAK,cAAc,GAAG,eAAe,CACnC,uBAAuB,EACvB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,KAAK,CAAC,EAAE;IACvD,cAAc,CAAC,EAAE,cAAc,EAAE,CAAC;CACnC;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"mockMessenger.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/__fixtures__/mockMessenger.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,kCAAkC;AACjE,OAAO,EAAE,SAAS,EAAE,kCAAkC;AAGtD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,8BAA8B,EAC/B,qBAAW;AAyBZ,KAAK,cAAc,GAAG,eAAe,CACnC,uBAAuB,EACvB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,KAAK,CAAC,EAAE;IACvD,cAAc,CAAC,EAAE,cAAc,EAAE,CAAC;CACnC;;;;;;;;;;;;;;;;;;;;;EAmCA;AAED,KAAK,kBAAkB,GAAG;IACxB,aAAa,EAAE,SAAS,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;IACxD,SAAS,EAAE,8BAA8B,CAAC;CAC3C,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,kBAAkB,CAAC,EAAE,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6LxC"}
|
|
@@ -32,7 +32,7 @@ export declare function createCustomUserStorageMessenger(props?: {
|
|
|
32
32
|
identifierId: string;
|
|
33
33
|
profileId: string;
|
|
34
34
|
}>;
|
|
35
|
-
} | import("@metamask/keyring-controller").KeyringControllerGetStateAction | import("@metamask/accounts-controller").AccountsControllerListAccountsAction | import("@metamask/accounts-controller").AccountsControllerUpdateAccountMetadataAction | import("@metamask/keyring-controller").KeyringControllerAddNewAccountAction | import("@metamask/network-controller").NetworkControllerGetStateAction | import("@metamask/network-controller").NetworkControllerAddNetworkAction | import("@metamask/network-controller").NetworkControllerRemoveNetworkAction | import("@metamask/network-controller").NetworkControllerUpdateNetworkAction, import("@metamask/keyring-controller").KeyringControllerLockEvent | import("@metamask/keyring-controller").KeyringControllerUnlockEvent | import("../index.mjs").UserStorageControllerStateChangeEvent | import("../index.mjs").UserStorageControllerAccountSyncingInProgress | import("../index.mjs").UserStorageControllerAccountSyncingComplete | import("@metamask/accounts-controller").AccountsControllerAccountAddedEvent | import("@metamask/accounts-controller").AccountsControllerAccountRenamedEvent | import("@metamask/network-controller").NetworkControllerNetworkRemovedEvent, "SnapController:handleRequest" | "KeyringController:getState" | "AuthenticationController:isSignedIn" | "AuthenticationController:performSignIn" | "AuthenticationController:performSignOut" | "AuthenticationController:getBearerToken" | "AuthenticationController:getSessionProfile" | "AccountsController:listAccounts" | "AccountsController:updateAccountMetadata" | "KeyringController:addNewAccount" | "NetworkController:getState" | "NetworkController:addNetwork" | "NetworkController:removeNetwork" | "NetworkController:updateNetwork", "KeyringController:lock" | "KeyringController:unlock" | "AccountsController:accountAdded" | "AccountsController:accountRenamed" | "NetworkController:networkRemoved">;
|
|
35
|
+
} | import("@metamask/keyring-controller").KeyringControllerGetStateAction | import("../index.mjs").NotificationServicesControllerDisableNotificationServices | import("../index.mjs").NotificationServicesControllerSelectIsNotificationServicesEnabled | import("@metamask/accounts-controller").AccountsControllerListAccountsAction | import("@metamask/accounts-controller").AccountsControllerUpdateAccountMetadataAction | import("@metamask/keyring-controller").KeyringControllerAddNewAccountAction | import("@metamask/network-controller").NetworkControllerGetStateAction | import("@metamask/network-controller").NetworkControllerAddNetworkAction | import("@metamask/network-controller").NetworkControllerRemoveNetworkAction | import("@metamask/network-controller").NetworkControllerUpdateNetworkAction, import("@metamask/keyring-controller").KeyringControllerLockEvent | import("@metamask/keyring-controller").KeyringControllerUnlockEvent | import("../index.mjs").UserStorageControllerStateChangeEvent | import("../index.mjs").UserStorageControllerAccountSyncingInProgress | import("../index.mjs").UserStorageControllerAccountSyncingComplete | import("@metamask/accounts-controller").AccountsControllerAccountAddedEvent | import("@metamask/accounts-controller").AccountsControllerAccountRenamedEvent | import("@metamask/network-controller").NetworkControllerNetworkRemovedEvent, "SnapController:handleRequest" | "KeyringController:getState" | "AuthenticationController:isSignedIn" | "AuthenticationController:performSignIn" | "AuthenticationController:performSignOut" | "AuthenticationController:getBearerToken" | "AuthenticationController:getSessionProfile" | "NotificationServicesController:disableNotificationServices" | "NotificationServicesController:selectIsNotificationServicesEnabled" | "AccountsController:listAccounts" | "AccountsController:updateAccountMetadata" | "KeyringController:addNewAccount" | "NetworkController:getState" | "NetworkController:addNetwork" | "NetworkController:removeNetwork" | "NetworkController:updateNetwork", "KeyringController:lock" | "KeyringController:unlock" | "AccountsController:accountAdded" | "AccountsController:accountRenamed" | "NetworkController:networkRemoved">;
|
|
36
36
|
};
|
|
37
37
|
type OverrideMessengers = {
|
|
38
38
|
baseMessenger: Messenger<AllowedActions, AllowedEvents>;
|
|
@@ -64,7 +64,7 @@ export declare function mockUserStorageMessenger(overrideMessengers?: OverrideMe
|
|
|
64
64
|
identifierId: string;
|
|
65
65
|
profileId: string;
|
|
66
66
|
}>;
|
|
67
|
-
} | import("@metamask/keyring-controller").KeyringControllerGetStateAction | import("@metamask/accounts-controller").AccountsControllerListAccountsAction | import("@metamask/accounts-controller").AccountsControllerUpdateAccountMetadataAction | import("@metamask/keyring-controller").KeyringControllerAddNewAccountAction | import("@metamask/network-controller").NetworkControllerGetStateAction | import("@metamask/network-controller").NetworkControllerAddNetworkAction | import("@metamask/network-controller").NetworkControllerRemoveNetworkAction | import("@metamask/network-controller").NetworkControllerUpdateNetworkAction, import("@metamask/keyring-controller").KeyringControllerLockEvent | import("@metamask/keyring-controller").KeyringControllerUnlockEvent | import("../index.mjs").UserStorageControllerStateChangeEvent | import("../index.mjs").UserStorageControllerAccountSyncingInProgress | import("../index.mjs").UserStorageControllerAccountSyncingComplete | import("@metamask/accounts-controller").AccountsControllerAccountAddedEvent | import("@metamask/accounts-controller").AccountsControllerAccountRenamedEvent | import("@metamask/network-controller").NetworkControllerNetworkRemovedEvent, "SnapController:handleRequest" | "KeyringController:getState" | "AuthenticationController:isSignedIn" | "AuthenticationController:performSignIn" | "AuthenticationController:performSignOut" | "AuthenticationController:getBearerToken" | "AuthenticationController:getSessionProfile" | "AccountsController:listAccounts" | "AccountsController:updateAccountMetadata" | "KeyringController:addNewAccount" | "NetworkController:getState" | "NetworkController:addNetwork" | "NetworkController:removeNetwork" | "NetworkController:updateNetwork", "KeyringController:lock" | "KeyringController:unlock" | "AccountsController:accountAdded" | "AccountsController:accountRenamed" | "NetworkController:networkRemoved">;
|
|
67
|
+
} | import("@metamask/keyring-controller").KeyringControllerGetStateAction | import("../index.mjs").NotificationServicesControllerDisableNotificationServices | import("../index.mjs").NotificationServicesControllerSelectIsNotificationServicesEnabled | import("@metamask/accounts-controller").AccountsControllerListAccountsAction | import("@metamask/accounts-controller").AccountsControllerUpdateAccountMetadataAction | import("@metamask/keyring-controller").KeyringControllerAddNewAccountAction | import("@metamask/network-controller").NetworkControllerGetStateAction | import("@metamask/network-controller").NetworkControllerAddNetworkAction | import("@metamask/network-controller").NetworkControllerRemoveNetworkAction | import("@metamask/network-controller").NetworkControllerUpdateNetworkAction, import("@metamask/keyring-controller").KeyringControllerLockEvent | import("@metamask/keyring-controller").KeyringControllerUnlockEvent | import("../index.mjs").UserStorageControllerStateChangeEvent | import("../index.mjs").UserStorageControllerAccountSyncingInProgress | import("../index.mjs").UserStorageControllerAccountSyncingComplete | import("@metamask/accounts-controller").AccountsControllerAccountAddedEvent | import("@metamask/accounts-controller").AccountsControllerAccountRenamedEvent | import("@metamask/network-controller").NetworkControllerNetworkRemovedEvent, "SnapController:handleRequest" | "KeyringController:getState" | "AuthenticationController:isSignedIn" | "AuthenticationController:performSignIn" | "AuthenticationController:performSignOut" | "AuthenticationController:getBearerToken" | "AuthenticationController:getSessionProfile" | "NotificationServicesController:disableNotificationServices" | "NotificationServicesController:selectIsNotificationServicesEnabled" | "AccountsController:listAccounts" | "AccountsController:updateAccountMetadata" | "KeyringController:addNewAccount" | "NetworkController:getState" | "NetworkController:addNetwork" | "NetworkController:removeNetwork" | "NetworkController:updateNetwork", "KeyringController:lock" | "KeyringController:unlock" | "AccountsController:accountAdded" | "AccountsController:accountRenamed" | "NetworkController:networkRemoved">;
|
|
68
68
|
mockSnapGetPublicKey: jest.Mock<any, any>;
|
|
69
69
|
mockSnapSignMessage: jest.Mock<any, any>;
|
|
70
70
|
mockAuthGetBearerToken: jest.Mock<Promise<string>, []>;
|
|
@@ -74,6 +74,8 @@ export declare function mockUserStorageMessenger(overrideMessengers?: OverrideMe
|
|
|
74
74
|
}>, []>;
|
|
75
75
|
mockAuthPerformSignIn: jest.Mock<Promise<string>, []>;
|
|
76
76
|
mockAuthIsSignedIn: jest.Mock<boolean, []>;
|
|
77
|
+
mockNotificationServicesIsEnabled: jest.Mock<boolean, []>;
|
|
78
|
+
mockNotificationServicesDisableNotifications: jest.Mock<Promise<void>, []>;
|
|
77
79
|
mockAuthPerformSignOut: jest.Mock<void, []>;
|
|
78
80
|
mockKeyringAddNewAccount: jest.Mock<Promise<string>, [accountCount?: number | undefined]>;
|
|
79
81
|
mockAccountsUpdateAccountMetadata: jest.Mock<void, [accountId: string, metadata: Partial<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mockMessenger.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/__fixtures__/mockMessenger.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,kCAAkC;AACjE,OAAO,EAAE,SAAS,EAAE,kCAAkC;AAGtD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,8BAA8B,EAC/B,qBAAW;AAyBZ,KAAK,cAAc,GAAG,eAAe,CACnC,uBAAuB,EACvB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,KAAK,CAAC,EAAE;IACvD,cAAc,CAAC,EAAE,cAAc,EAAE,CAAC;CACnC;;;;;;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"mockMessenger.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/__fixtures__/mockMessenger.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,kCAAkC;AACjE,OAAO,EAAE,SAAS,EAAE,kCAAkC;AAGtD,OAAO,KAAK,EACV,cAAc,EACd,aAAa,EACb,8BAA8B,EAC/B,qBAAW;AAyBZ,KAAK,cAAc,GAAG,eAAe,CACnC,uBAAuB,EACvB,aAAa,CAAC,MAAM,CAAC,CACtB,CAAC;AAEF;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,KAAK,CAAC,EAAE;IACvD,cAAc,CAAC,EAAE,cAAc,EAAE,CAAC;CACnC;;;;;;;;;;;;;;;;;;;;;EAmCA;AAED,KAAK,kBAAkB,GAAG;IACxB,aAAa,EAAE,SAAS,CAAC,cAAc,EAAE,aAAa,CAAC,CAAC;IACxD,SAAS,EAAE,8BAA8B,CAAC;CAC3C,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,wBAAwB,CACtC,kBAAkB,CAAC,EAAE,kBAAkB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA6LxC"}
|
|
@@ -21,6 +21,8 @@ export function createCustomUserStorageMessenger(props) {
|
|
|
21
21
|
'AuthenticationController:isSignedIn',
|
|
22
22
|
'AuthenticationController:performSignOut',
|
|
23
23
|
'AuthenticationController:performSignIn',
|
|
24
|
+
'NotificationServicesController:disableNotificationServices',
|
|
25
|
+
'NotificationServicesController:selectIsNotificationServicesEnabled',
|
|
24
26
|
'AccountsController:listAccounts',
|
|
25
27
|
'AccountsController:updateAccountMetadata',
|
|
26
28
|
'NetworkController:getState',
|
|
@@ -61,6 +63,8 @@ export function mockUserStorageMessenger(overrideMessengers) {
|
|
|
61
63
|
const mockAuthPerformSignIn = typedMockFn('AuthenticationController:performSignIn').mockResolvedValue('New Access Token');
|
|
62
64
|
const mockAuthIsSignedIn = typedMockFn('AuthenticationController:isSignedIn').mockReturnValue(true);
|
|
63
65
|
const mockAuthPerformSignOut = typedMockFn('AuthenticationController:performSignOut');
|
|
66
|
+
const mockNotificationServicesIsEnabled = typedMockFn('NotificationServicesController:selectIsNotificationServicesEnabled').mockReturnValue(true);
|
|
67
|
+
const mockNotificationServicesDisableNotifications = typedMockFn('NotificationServicesController:disableNotificationServices').mockResolvedValue();
|
|
64
68
|
const mockKeyringAddNewAccount = typedMockFn('KeyringController:addNewAccount');
|
|
65
69
|
// Untyped mock as there is a TS(2742) issue.
|
|
66
70
|
// This will return `InternalAccount[]`
|
|
@@ -99,6 +103,14 @@ export function mockUserStorageMessenger(overrideMessengers) {
|
|
|
99
103
|
if (actionType === 'AuthenticationController:isSignedIn') {
|
|
100
104
|
return mockAuthIsSignedIn();
|
|
101
105
|
}
|
|
106
|
+
if (actionType ===
|
|
107
|
+
'NotificationServicesController:selectIsNotificationServicesEnabled') {
|
|
108
|
+
return mockNotificationServicesIsEnabled();
|
|
109
|
+
}
|
|
110
|
+
if (actionType ===
|
|
111
|
+
'NotificationServicesController:disableNotificationServices') {
|
|
112
|
+
return mockNotificationServicesDisableNotifications();
|
|
113
|
+
}
|
|
102
114
|
if (actionType === 'AuthenticationController:performSignOut') {
|
|
103
115
|
return mockAuthPerformSignOut();
|
|
104
116
|
}
|
|
@@ -141,6 +153,8 @@ export function mockUserStorageMessenger(overrideMessengers) {
|
|
|
141
153
|
mockAuthGetSessionProfile,
|
|
142
154
|
mockAuthPerformSignIn,
|
|
143
155
|
mockAuthIsSignedIn,
|
|
156
|
+
mockNotificationServicesIsEnabled,
|
|
157
|
+
mockNotificationServicesDisableNotifications,
|
|
144
158
|
mockAuthPerformSignOut,
|
|
145
159
|
mockKeyringAddNewAccount,
|
|
146
160
|
mockAccountsUpdateAccountMetadata,
|