@metamask/profile-sync-controller 8.1.1 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +22 -1
- package/README.md +32 -0
- package/auth/mocks/package.json +2 -2
- package/dist/controllers/authentication/AuthenticationController.cjs +53 -86
- package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.cts +11 -23
- package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.d.mts +11 -23
- package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
- package/dist/controllers/authentication/AuthenticationController.mjs +53 -86
- package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
- package/dist/controllers/authentication/index.cjs +1 -1
- package/dist/controllers/authentication/index.cjs.map +1 -1
- package/dist/controllers/authentication/index.d.cts +1 -1
- package/dist/controllers/authentication/index.d.cts.map +1 -1
- package/dist/controllers/authentication/index.d.mts +1 -1
- package/dist/controllers/authentication/index.d.mts.map +1 -1
- package/dist/controllers/authentication/index.mjs +1 -1
- package/dist/controllers/authentication/index.mjs.map +1 -1
- package/dist/controllers/authentication/mocks/index.cjs.map +1 -0
- package/dist/controllers/authentication/mocks/index.d.cts.map +1 -0
- package/dist/controllers/authentication/mocks/index.d.mts.map +1 -0
- package/dist/controllers/authentication/mocks/index.mjs.map +1 -0
- package/dist/controllers/authentication/mocks/mockResponses.cjs +34 -0
- package/dist/controllers/authentication/mocks/mockResponses.cjs.map +1 -0
- package/dist/controllers/authentication/mocks/mockResponses.d.cts +55 -0
- package/dist/controllers/authentication/mocks/mockResponses.d.cts.map +1 -0
- package/dist/controllers/authentication/mocks/mockResponses.d.mts +55 -0
- package/dist/controllers/authentication/mocks/mockResponses.d.mts.map +1 -0
- package/dist/controllers/authentication/mocks/mockResponses.mjs +28 -0
- package/dist/controllers/authentication/mocks/mockResponses.mjs.map +1 -0
- package/dist/controllers/user-storage/UserStorageController.cjs +71 -127
- package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.cts +5 -4
- package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.d.mts +5 -4
- package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
- package/dist/controllers/user-storage/UserStorageController.mjs +71 -127
- package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +2 -2
- package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +2 -2
- package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.cjs +1 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.cts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.d.mts.map +1 -1
- package/dist/controllers/user-storage/account-syncing/sync-utils.mjs +1 -0
- package/dist/controllers/user-storage/account-syncing/sync-utils.mjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/utils.cjs +2 -2
- package/dist/controllers/user-storage/account-syncing/utils.cjs.map +1 -1
- package/dist/controllers/user-storage/account-syncing/utils.mjs +2 -2
- package/dist/controllers/user-storage/account-syncing/utils.mjs.map +1 -1
- package/dist/controllers/user-storage/index.cjs +1 -1
- package/dist/controllers/user-storage/index.cjs.map +1 -1
- package/dist/controllers/user-storage/index.d.cts +1 -1
- package/dist/controllers/user-storage/index.d.cts.map +1 -1
- package/dist/controllers/user-storage/index.d.mts +1 -1
- package/dist/controllers/user-storage/index.d.mts.map +1 -1
- package/dist/controllers/user-storage/index.mjs +1 -1
- package/dist/controllers/user-storage/index.mjs.map +1 -1
- package/dist/controllers/user-storage/mocks/index.cjs.map +1 -0
- package/dist/controllers/user-storage/mocks/index.d.cts.map +1 -0
- package/dist/controllers/user-storage/mocks/index.d.mts.map +1 -0
- package/dist/controllers/user-storage/mocks/index.mjs.map +1 -0
- package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockResponses.cjs +3 -3
- package/dist/controllers/user-storage/mocks/mockResponses.cjs.map +1 -0
- package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockResponses.d.cts +1 -1
- package/dist/controllers/user-storage/mocks/mockResponses.d.cts.map +1 -0
- package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockResponses.d.mts +1 -1
- package/dist/controllers/user-storage/mocks/mockResponses.d.mts.map +1 -0
- package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockResponses.mjs +3 -3
- package/dist/controllers/user-storage/mocks/mockResponses.mjs.map +1 -0
- package/dist/controllers/user-storage/mocks/mockStorage.cjs.map +1 -0
- package/dist/controllers/user-storage/mocks/mockStorage.d.cts.map +1 -0
- package/dist/controllers/user-storage/mocks/mockStorage.d.mts.map +1 -0
- package/dist/controllers/user-storage/mocks/mockStorage.mjs.map +1 -0
- package/dist/controllers/user-storage/network-syncing/controller-integration.cjs +14 -14
- package/dist/controllers/user-storage/network-syncing/controller-integration.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts +3 -3
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts +3 -3
- package/dist/controllers/user-storage/network-syncing/controller-integration.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/controller-integration.mjs +14 -14
- package/dist/controllers/user-storage/network-syncing/controller-integration.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.cjs +27 -23
- package/dist/controllers/user-storage/network-syncing/services.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.d.cts +16 -7
- package/dist/controllers/user-storage/network-syncing/services.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.d.mts +16 -7
- package/dist/controllers/user-storage/network-syncing/services.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/services.mjs +27 -23
- package/dist/controllers/user-storage/network-syncing/services.mjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.cjs.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts +13 -5
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.cts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts +13 -5
- package/dist/controllers/user-storage/network-syncing/sync-mutations.d.mts.map +1 -1
- package/dist/controllers/user-storage/network-syncing/sync-mutations.mjs.map +1 -1
- package/dist/controllers/user-storage/types.cjs +3 -0
- package/dist/controllers/user-storage/types.cjs.map +1 -0
- package/dist/controllers/user-storage/types.d.cts +23 -0
- package/dist/controllers/user-storage/types.d.cts.map +1 -0
- package/dist/controllers/user-storage/types.d.mts +23 -0
- package/dist/controllers/user-storage/types.d.mts.map +1 -0
- package/dist/controllers/user-storage/types.mjs +2 -0
- package/dist/controllers/user-storage/types.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +7 -8
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts +2 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +2 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +8 -9
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.cjs +10 -2
- package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.cts +3 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.mts +3 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/services.mjs +10 -2
- package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/types.cjs.map +1 -1
- package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -1
- package/dist/sdk/authentication.cjs.map +1 -1
- package/dist/sdk/authentication.d.cts +1 -1
- package/dist/sdk/authentication.d.cts.map +1 -1
- package/dist/sdk/authentication.d.mts +1 -1
- package/dist/sdk/authentication.d.mts.map +1 -1
- package/dist/sdk/authentication.mjs.map +1 -1
- package/dist/sdk/mocks/auth.cjs +44 -0
- package/dist/sdk/mocks/auth.cjs.map +1 -0
- package/dist/sdk/{__fixtures__/mock-auth.d.cts → mocks/auth.d.cts} +22 -25
- package/dist/sdk/mocks/auth.d.cts.map +1 -0
- package/dist/sdk/{__fixtures__/mock-auth.d.mts → mocks/auth.d.mts} +22 -25
- package/dist/sdk/mocks/auth.d.mts.map +1 -0
- package/dist/sdk/mocks/auth.mjs +41 -0
- package/dist/sdk/mocks/auth.mjs.map +1 -0
- package/dist/sdk/mocks/userstorage.cjs +43 -0
- package/dist/sdk/mocks/userstorage.cjs.map +1 -0
- package/dist/sdk/mocks/userstorage.d.cts +10 -0
- package/dist/sdk/mocks/userstorage.d.cts.map +1 -0
- package/dist/sdk/mocks/userstorage.d.mts +10 -0
- package/dist/sdk/mocks/userstorage.d.mts.map +1 -0
- package/dist/sdk/mocks/userstorage.mjs +15 -0
- package/dist/sdk/mocks/userstorage.mjs.map +1 -0
- package/dist/sdk/user-storage.cjs +34 -39
- package/dist/sdk/user-storage.cjs.map +1 -1
- package/dist/sdk/user-storage.d.cts +11 -6
- package/dist/sdk/user-storage.d.cts.map +1 -1
- package/dist/sdk/user-storage.d.mts +11 -6
- package/dist/sdk/user-storage.d.mts.map +1 -1
- package/dist/sdk/user-storage.mjs +34 -39
- package/dist/sdk/user-storage.mjs.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs +12 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.d.cts +6 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.d.cts.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts +6 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts.map +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs +10 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs.map +1 -1
- package/dist/shared/types/services.cjs +3 -0
- package/dist/shared/types/services.cjs.map +1 -0
- package/dist/shared/types/services.d.cts +10 -0
- package/dist/shared/types/services.d.cts.map +1 -0
- package/dist/shared/types/services.d.mts +10 -0
- package/dist/shared/types/services.d.mts.map +1 -0
- package/dist/shared/types/services.mjs +2 -0
- package/dist/shared/types/services.mjs.map +1 -0
- package/package.json +14 -14
- package/user-storage/mocks/package.json +2 -2
- package/dist/controllers/authentication/__fixtures__/index.cjs.map +0 -1
- package/dist/controllers/authentication/__fixtures__/index.d.cts.map +0 -1
- package/dist/controllers/authentication/__fixtures__/index.d.mts.map +0 -1
- package/dist/controllers/authentication/__fixtures__/index.mjs.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockResponses.cjs +0 -47
- package/dist/controllers/authentication/__fixtures__/mockResponses.cjs.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockResponses.d.cts +0 -23
- package/dist/controllers/authentication/__fixtures__/mockResponses.d.cts.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockResponses.d.mts +0 -23
- package/dist/controllers/authentication/__fixtures__/mockResponses.d.mts.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockResponses.mjs +0 -41
- package/dist/controllers/authentication/__fixtures__/mockResponses.mjs.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockServices.cjs +0 -37
- package/dist/controllers/authentication/__fixtures__/mockServices.cjs.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockServices.d.cts +0 -10
- package/dist/controllers/authentication/__fixtures__/mockServices.d.cts.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockServices.d.mts +0 -10
- package/dist/controllers/authentication/__fixtures__/mockServices.d.mts.map +0 -1
- package/dist/controllers/authentication/__fixtures__/mockServices.mjs +0 -35
- package/dist/controllers/authentication/__fixtures__/mockServices.mjs.map +0 -1
- package/dist/controllers/authentication/services.cjs +0 -132
- package/dist/controllers/authentication/services.cjs.map +0 -1
- package/dist/controllers/authentication/services.d.cts +0 -72
- package/dist/controllers/authentication/services.d.cts.map +0 -1
- package/dist/controllers/authentication/services.d.mts +0 -72
- package/dist/controllers/authentication/services.d.mts.map +0 -1
- package/dist/controllers/authentication/services.mjs +0 -129
- package/dist/controllers/authentication/services.mjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/index.cjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/index.d.cts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/index.d.mts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/index.mjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.cjs +0 -167
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.cjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.cts +0 -105
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.cts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.mts +0 -105
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.d.mts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.mjs +0 -162
- package/dist/controllers/user-storage/__fixtures__/mockMessenger.mjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.cjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.d.cts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.d.mts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockResponses.mjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockServices.cjs +0 -82
- package/dist/controllers/user-storage/__fixtures__/mockServices.cjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockServices.d.cts +0 -15
- package/dist/controllers/user-storage/__fixtures__/mockServices.d.cts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockServices.d.mts +0 -15
- package/dist/controllers/user-storage/__fixtures__/mockServices.d.mts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockServices.mjs +0 -76
- package/dist/controllers/user-storage/__fixtures__/mockServices.mjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockStorage.cjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockStorage.d.cts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockStorage.d.mts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/mockStorage.mjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.cjs +0 -78
- package/dist/controllers/user-storage/__fixtures__/test-utils.cjs.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts +0 -38
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.cts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts +0 -38
- package/dist/controllers/user-storage/__fixtures__/test-utils.d.mts.map +0 -1
- package/dist/controllers/user-storage/__fixtures__/test-utils.mjs +0 -68
- package/dist/controllers/user-storage/__fixtures__/test-utils.mjs.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.cjs +0 -178
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.cjs.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.cts +0 -91
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.cts.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.mts +0 -91
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.d.mts.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.mjs +0 -174
- package/dist/controllers/user-storage/account-syncing/__fixtures__/mockAccounts.mjs.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs +0 -58
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.cjs.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts +0 -87
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.cts.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts +0 -87
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.d.mts.map +0 -1
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs +0 -52
- package/dist/controllers/user-storage/account-syncing/__fixtures__/test-utils.mjs.map +0 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.cjs +0 -43
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.cjs.map +0 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.cts +0 -11
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.cts.map +0 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.mts +0 -11
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.d.mts.map +0 -1
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.mjs +0 -36
- package/dist/controllers/user-storage/network-syncing/__fixtures__/mockNetwork.mjs.map +0 -1
- package/dist/controllers/user-storage/services.cjs +0 -306
- package/dist/controllers/user-storage/services.cjs.map +0 -1
- package/dist/controllers/user-storage/services.d.cts +0 -85
- package/dist/controllers/user-storage/services.d.cts.map +0 -1
- package/dist/controllers/user-storage/services.d.mts +0 -85
- package/dist/controllers/user-storage/services.d.mts.map +0 -1
- package/dist/controllers/user-storage/services.mjs +0 -276
- package/dist/controllers/user-storage/services.mjs.map +0 -1
- package/dist/sdk/__fixtures__/mock-auth.cjs +0 -124
- package/dist/sdk/__fixtures__/mock-auth.cjs.map +0 -1
- package/dist/sdk/__fixtures__/mock-auth.d.cts.map +0 -1
- package/dist/sdk/__fixtures__/mock-auth.d.mts.map +0 -1
- package/dist/sdk/__fixtures__/mock-auth.mjs +0 -119
- package/dist/sdk/__fixtures__/mock-auth.mjs.map +0 -1
- package/dist/sdk/__fixtures__/mock-userstorage.cjs +0 -111
- package/dist/sdk/__fixtures__/mock-userstorage.cjs.map +0 -1
- package/dist/sdk/__fixtures__/mock-userstorage.d.cts +0 -20
- package/dist/sdk/__fixtures__/mock-userstorage.d.cts.map +0 -1
- package/dist/sdk/__fixtures__/mock-userstorage.d.mts +0 -20
- package/dist/sdk/__fixtures__/mock-userstorage.d.mts.map +0 -1
- package/dist/sdk/__fixtures__/mock-userstorage.mjs +0 -81
- package/dist/sdk/__fixtures__/mock-userstorage.mjs.map +0 -1
- package/dist/sdk/__fixtures__/test-utils.cjs +0 -90
- package/dist/sdk/__fixtures__/test-utils.cjs.map +0 -1
- package/dist/sdk/__fixtures__/test-utils.d.cts +0 -37
- package/dist/sdk/__fixtures__/test-utils.d.cts.map +0 -1
- package/dist/sdk/__fixtures__/test-utils.d.mts +0 -37
- package/dist/sdk/__fixtures__/test-utils.d.mts.map +0 -1
- package/dist/sdk/__fixtures__/test-utils.mjs +0 -84
- package/dist/sdk/__fixtures__/test-utils.mjs.map +0 -1
- /package/dist/controllers/authentication/{__fixtures__ → mocks}/index.cjs +0 -0
- /package/dist/controllers/authentication/{__fixtures__ → mocks}/index.d.cts +0 -0
- /package/dist/controllers/authentication/{__fixtures__ → mocks}/index.d.mts +0 -0
- /package/dist/controllers/authentication/{__fixtures__ → mocks}/index.mjs +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/index.cjs +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/index.d.cts +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/index.d.mts +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/index.mjs +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockStorage.cjs +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockStorage.d.cts +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockStorage.d.mts +0 -0
- /package/dist/controllers/user-storage/{__fixtures__ → mocks}/mockStorage.mjs +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-integration.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/controller-integration.ts"],"names":[],"mappings":";;;AAAA,uDAAyD;AACzD,qEAA4D;AAG5D,iDAIsB;AAEtB,uCAIiB;AACjB,uEAA4E;AAE5E;;;;;;GAMG;AACI,KAAK,UAAU,gCAAgC,CACpD,eAAgC,EAChC,MAA4B,EAC5B,OAA8B;IAE9B,MAAM,EAAE,uBAAuB,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,IACE,CAAC,uBAAuB;QACxB,CAAC,IAAA,qCAAwB,EAAC,MAAM,EAAE,OAAO,CAAC;QAC1C,CAAC,IAAA,8BAAgB,EAAC,eAAe,CAAC,IAAI,CAAC;QACvC,CAAC,CAAC,MAAM,IAAA,gDAAwC,EAAC,eAAe,EAAE,OAAO,CAAC,CAAC,EAC3E;QACA,OAAO;KACR;IAED,IAAI;QACF,8DAA8D;QAC9D,MAAM,aAAa,GACjB,IAAA,8CAAsC,EAAC,eAAe,CAAC,CAAC;QAE1D,MAAM,gCAAgC,EAAE,CAAC,iBAAiB;QACxD,2BAA2B;QAE3B,GAAG,2CAA0B,CAAC,QAAQ,IAAI,eAAe,CAAC,OAAO,EAAE,EACnE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAC9B,CAAC;KACH;IAAC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AAE,CACtF,CAAC;KACH;YAAS;QACR,MAAM,gCAAgC,EAAE,CAAC,6BAA6B,CACpE,KAAK,CACN,CAAC;KACH;AACH,CAAC;AAhSD,kFAgSC","sourcesContent":["import { isEvmAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport {\n canPerformAccountSyncing,\n getInternalAccountsList,\n getUserStorageAccountsList,\n} from './sync-utils';\nimport type { AccountSyncingConfig, AccountSyncingOptions } from './types';\nimport {\n isInternalAccountFromPrimarySRPHdKeyring,\n isNameDefaultAccountName,\n mapInternalAccountToUserStorageAccount,\n} from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Saves an individual internal account to the user storage.\n *\n * @param internalAccount - The internal account to save\n * @param config - parameters used for saving the internal account\n * @param options - parameters used for saving the internal account\n */\nexport async function saveInternalAccountToUserStorage(\n internalAccount: InternalAccount,\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { isAccountSyncingEnabled } = config;\n const { getUserStorageControllerInstance } = options;\n\n if (\n !isAccountSyncingEnabled ||\n !canPerformAccountSyncing(config, options) ||\n !isEvmAccountType(internalAccount.type) ||\n !(await isInternalAccountFromPrimarySRPHdKeyring(internalAccount, options))\n ) {\n return;\n }\n\n try {\n // Map the internal account to the user storage account schema\n const mappedAccount =\n mapInternalAccountToUserStorageAccount(internalAccount);\n\n await getUserStorageControllerInstance().performSetStorage(\n // ESLint is confused here.\n\n `${USER_STORAGE_FEATURE_NAMES.accounts}.${internalAccount.address}`,\n JSON.stringify(mappedAccount),\n );\n } catch (e) {\n // istanbul ignore next\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `UserStorageController - failed to save account to user storage - ${errorMessage}`,\n );\n }\n}\n\n/**\n * Saves the list of internal accounts to the user storage.\n *\n * @param config - parameters used for saving the list of internal accounts\n * @param options - parameters used for saving the list of internal accounts\n */\nexport async function saveInternalAccountsListToUserStorage(\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { isAccountSyncingEnabled } = config;\n const { getUserStorageControllerInstance } = options;\n\n if (!isAccountSyncingEnabled) {\n return;\n }\n\n const internalAccountsList = await getInternalAccountsList(options);\n\n if (!internalAccountsList?.length) {\n return;\n }\n\n const internalAccountsListFormattedForUserStorage = internalAccountsList.map(\n mapInternalAccountToUserStorageAccount,\n );\n\n await getUserStorageControllerInstance().performBatchSetStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n internalAccountsListFormattedForUserStorage.map((account) => [\n account.a,\n JSON.stringify(account),\n ]),\n );\n}\n\ntype SyncInternalAccountsWithUserStorageConfig = AccountSyncingConfig & {\n maxNumberOfAccountsToAdd?: number;\n onAccountAdded?: () => void;\n onAccountNameUpdated?: () => void;\n onAccountSyncErroneousSituation?: (\n errorMessage: string,\n sentryContext?: Record<string, unknown>,\n ) => void;\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 * @param config - parameters used for syncing the internal accounts list with the user storage accounts list\n * @param options - parameters used for syncing the internal accounts list with the user storage accounts list\n */\nexport async function syncInternalAccountsWithUserStorage(\n config: SyncInternalAccountsWithUserStorageConfig,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { isAccountSyncingEnabled } = config;\n\n if (!canPerformAccountSyncing(config, options) || !isAccountSyncingEnabled) {\n return;\n }\n\n const {\n maxNumberOfAccountsToAdd = Infinity,\n onAccountAdded,\n onAccountNameUpdated,\n onAccountSyncErroneousSituation,\n } = config;\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n try {\n await getUserStorageControllerInstance().setIsAccountSyncingInProgress(\n true,\n );\n\n const userStorageAccountsList = await getUserStorageAccountsList(options);\n\n if (!userStorageAccountsList || !userStorageAccountsList.length) {\n await saveInternalAccountsListToUserStorage(\n { isAccountSyncingEnabled },\n options,\n );\n await getUserStorageControllerInstance().setHasAccountSyncingSyncedAtLeastOnce(\n true,\n );\n return;\n }\n // Keep a record if erroneous situations are found during the sync\n // This is done so we can send the context to Sentry in case of an erroneous situation\n let erroneousSituationsFound = false;\n\n // Prepare an array of internal accounts to be saved to the user storage\n const internalAccountsToBeSavedToUserStorage: InternalAccount[] = [];\n\n // Compare internal accounts list with user storage accounts list\n // First step: compare lengths\n const internalAccountsList = await getInternalAccountsList(options);\n\n if (!internalAccountsList || !internalAccountsList.length) {\n throw new Error(`Failed to get internal accounts list`);\n }\n\n const hasMoreUserStorageAccountsThanInternalAccounts =\n userStorageAccountsList.length > internalAccountsList.length;\n\n // We don't want to remove existing accounts for a user\n // so we only add new accounts if the user has more accounts in user storage than internal accounts\n if (hasMoreUserStorageAccountsThanInternalAccounts) {\n const numberOfAccountsToAdd =\n Math.min(userStorageAccountsList.length, maxNumberOfAccountsToAdd) -\n internalAccountsList.length;\n\n // Create new accounts to match the user storage accounts list\n // NOTE: we only support the primary SRP HD keyring for now\n // This is why we are hardcoding the index to 0\n await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n type: KeyringTypes.hd,\n index: 0,\n },\n async (keyring) => {\n keyring.addAccounts(numberOfAccountsToAdd);\n },\n );\n\n // TODO: below code is kept for analytics but should probably be re-thought\n for (let i = 0; i < numberOfAccountsToAdd; i++) {\n onAccountAdded?.();\n }\n }\n\n // Second step: compare account names\n // Get the internal accounts list again since new accounts might have been added in the previous step\n const refreshedInternalAccountsList =\n await getInternalAccountsList(options);\n\n const newlyAddedAccounts = refreshedInternalAccountsList.filter(\n (account) =>\n !internalAccountsList.find((a) => a.address === account.address),\n );\n\n for (const internalAccount of refreshedInternalAccountsList) {\n const userStorageAccount = userStorageAccountsList.find(\n (account) => account.a === internalAccount.address,\n );\n\n // If the account is not present in user storage\n // istanbul ignore next\n if (!userStorageAccount) {\n // If the account was just added in the previous step, skip saving it, it's likely to be a bogus account\n if (newlyAddedAccounts.includes(internalAccount)) {\n erroneousSituationsFound = true;\n onAccountSyncErroneousSituation?.(\n 'An account was added to the internal accounts list but was not present in the user storage accounts list',\n {\n internalAccount,\n userStorageAccount,\n newlyAddedAccounts,\n userStorageAccountsList,\n internalAccountsList,\n refreshedInternalAccountsList,\n internalAccountsToBeSavedToUserStorage,\n },\n );\n continue;\n }\n // Otherwise, it means that this internal account was present before the sync, and needs to be saved to the user storage\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n\n // From this point on, we know that the account is present in\n // both the internal accounts list and the user storage accounts list\n\n // One or both accounts have default names\n const isInternalAccountNameDefault = isNameDefaultAccountName(\n internalAccount.metadata.name,\n );\n const isUserStorageAccountNameDefault = isNameDefaultAccountName(\n userStorageAccount.n,\n );\n\n // Internal account has default name\n if (isInternalAccountNameDefault) {\n if (!isUserStorageAccountNameDefault) {\n getMessenger().call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n },\n );\n\n onAccountNameUpdated?.();\n }\n continue;\n }\n\n // Internal account has custom name but user storage account has default name\n if (isUserStorageAccountNameDefault) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n\n // Both accounts have custom names\n\n // User storage account has a nameLastUpdatedAt timestamp\n // Note: not storing the undefined checks in constants to act as a type guard\n if (userStorageAccount.nlu !== undefined) {\n if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {\n const isInternalAccountNameNewer =\n internalAccount.metadata.nameLastUpdatedAt > userStorageAccount.nlu;\n\n if (isInternalAccountNameNewer) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n }\n\n getMessenger().call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n nameLastUpdatedAt: userStorageAccount.nlu,\n },\n );\n\n const areInternalAndUserStorageAccountNamesEqual =\n internalAccount.metadata.name === userStorageAccount.n;\n\n if (!areInternalAndUserStorageAccountNamesEqual) {\n onAccountNameUpdated?.();\n }\n\n continue;\n } else if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n }\n\n // Save the internal accounts list to the user storage\n if (internalAccountsToBeSavedToUserStorage.length) {\n await getUserStorageControllerInstance().performBatchSetStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n internalAccountsToBeSavedToUserStorage.map((account) => [\n account.address,\n JSON.stringify(mapInternalAccountToUserStorageAccount(account)),\n ]),\n );\n }\n\n // In case we have corrupted user storage with accounts that don't exist in the internal accounts list\n // Delete those accounts from the user storage\n const userStorageAccountsToBeDeleted = userStorageAccountsList.filter(\n (account) =>\n !refreshedInternalAccountsList.find((a) => a.address === account.a),\n );\n\n if (userStorageAccountsToBeDeleted.length) {\n await getUserStorageControllerInstance().performBatchDeleteStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n userStorageAccountsToBeDeleted.map((account) => account.a),\n );\n erroneousSituationsFound = true;\n onAccountSyncErroneousSituation?.(\n 'An account was present in the user storage accounts list but was not found in the internal accounts list after the sync',\n {\n userStorageAccountsToBeDeleted,\n internalAccountsList,\n refreshedInternalAccountsList,\n internalAccountsToBeSavedToUserStorage,\n userStorageAccountsList,\n },\n );\n }\n\n if (erroneousSituationsFound) {\n const [finalUserStorageAccountsList, finalInternalAccountsList] =\n await Promise.all([\n getUserStorageAccountsList(options),\n getInternalAccountsList(options),\n ]);\n\n const doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList =\n finalInternalAccountsList.every((account) =>\n finalUserStorageAccountsList?.some(\n (userStorageAccount) => userStorageAccount.a === account.address,\n ),\n );\n\n // istanbul ignore next\n const doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList =\n (finalUserStorageAccountsList?.length || 0) > maxNumberOfAccountsToAdd\n ? true\n : finalUserStorageAccountsList?.every((account) =>\n finalInternalAccountsList.some(\n (internalAccount) => internalAccount.address === account.a,\n ),\n );\n\n const doFinalListsMatch =\n doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList &&\n doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList;\n\n const context = {\n finalUserStorageAccountsList,\n finalInternalAccountsList,\n };\n if (doFinalListsMatch) {\n onAccountSyncErroneousSituation?.(\n 'Erroneous situations were found during the sync, but final state matches the expected state',\n context,\n );\n } else {\n onAccountSyncErroneousSituation?.(\n 'Erroneous situations were found during the sync, and final state does not match the expected state',\n context,\n );\n }\n }\n\n // We do this here and not in the finally statement because we want to make sure that\n // the accounts are saved / updated / deleted at least once before we set this flag\n await getUserStorageControllerInstance().setHasAccountSyncingSyncedAtLeastOnce(\n true,\n );\n } catch (e) {\n // istanbul ignore next\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `UserStorageController - failed to sync user storage accounts list - ${errorMessage}`,\n );\n } finally {\n await getUserStorageControllerInstance().setIsAccountSyncingInProgress(\n false,\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"controller-integration.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/controller-integration.ts"],"names":[],"mappings":";;;AAAA,uDAAyD;AACzD,qEAA4D;AAG5D,iDAIsB;AAEtB,uCAIiB;AACjB,uEAA4E;AAE5E;;;;;;GAMG;AACI,KAAK,UAAU,gCAAgC,CACpD,eAAgC,EAChC,MAA4B,EAC5B,OAA8B;IAE9B,MAAM,EAAE,uBAAuB,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,IACE,CAAC,uBAAuB;QACxB,CAAC,IAAA,qCAAwB,EAAC,MAAM,EAAE,OAAO,CAAC;QAC1C,CAAC,IAAA,8BAAgB,EAAC,eAAe,CAAC,IAAI,CAAC;QACvC,CAAC,CAAC,MAAM,IAAA,gDAAwC,EAAC,eAAe,EAAE,OAAO,CAAC,CAAC,EAC3E;QACA,OAAO;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AAmF;QACnF,MAAM,gCAAgC,EAAE,CAAC,qCAAqC,CAC5E,IAAI,CACL,CAAC;KACH;IAAC,OAAO,CAAC,EAAE;QACV,uBAAuB;QACvB,MAAM,YAAY,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACxE,MAAM,IAAI,KAAK,CACb,uEAAuE,YAAY,EAAE,CACtF,CAAC;KACH;YAAS;QACR,MAAM,gCAAgC,EAAE,CAAC,6BAA6B,CACpE,KAAK,CACN,CAAC;KACH;AACH,CAAC;AAhSD,kFAgSC","sourcesContent":["import { isEvmAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport {\n canPerformAccountSyncing,\n getInternalAccountsList,\n getUserStorageAccountsList,\n} from './sync-utils';\nimport type { AccountSyncingConfig, AccountSyncingOptions } from './types';\nimport {\n isInternalAccountFromPrimarySRPHdKeyring,\n isNameDefaultAccountName,\n mapInternalAccountToUserStorageAccount,\n} from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Saves an individual internal account to the user storage.\n *\n * @param internalAccount - The internal account to save\n * @param config - parameters used for saving the internal account\n * @param options - parameters used for saving the internal account\n */\nexport async function saveInternalAccountToUserStorage(\n internalAccount: InternalAccount,\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { isAccountSyncingEnabled } = config;\n const { getUserStorageControllerInstance } = options;\n\n if (\n !isAccountSyncingEnabled ||\n !canPerformAccountSyncing(config, options) ||\n !isEvmAccountType(internalAccount.type) ||\n !(await isInternalAccountFromPrimarySRPHdKeyring(internalAccount, options))\n ) {\n return;\n }\n\n try {\n // Map the internal account to the user storage account schema\n const mappedAccount =\n mapInternalAccountToUserStorageAccount(internalAccount);\n\n await getUserStorageControllerInstance().performSetStorage(\n // ESLint is confused here.\n\n `${USER_STORAGE_FEATURE_NAMES.accounts}.${internalAccount.address}`,\n JSON.stringify(mappedAccount),\n );\n } catch (e) {\n // istanbul ignore next\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `UserStorageController - failed to save account to user storage - ${errorMessage}`,\n );\n }\n}\n\n/**\n * Saves the list of internal accounts to the user storage.\n *\n * @param config - parameters used for saving the list of internal accounts\n * @param options - parameters used for saving the list of internal accounts\n */\nexport async function saveInternalAccountsListToUserStorage(\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { isAccountSyncingEnabled } = config;\n const { getUserStorageControllerInstance } = options;\n\n if (!isAccountSyncingEnabled) {\n return;\n }\n\n const internalAccountsList = await getInternalAccountsList(options);\n\n if (!internalAccountsList?.length) {\n return;\n }\n\n const internalAccountsListFormattedForUserStorage = internalAccountsList.map(\n mapInternalAccountToUserStorageAccount,\n );\n\n await getUserStorageControllerInstance().performBatchSetStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n internalAccountsListFormattedForUserStorage.map((account) => [\n account.a,\n JSON.stringify(account),\n ]),\n );\n}\n\ntype SyncInternalAccountsWithUserStorageConfig = AccountSyncingConfig & {\n maxNumberOfAccountsToAdd?: number;\n onAccountAdded?: () => void;\n onAccountNameUpdated?: () => void;\n onAccountSyncErroneousSituation?: (\n errorMessage: string,\n sentryContext?: Record<string, unknown>,\n ) => void;\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 * @param config - parameters used for syncing the internal accounts list with the user storage accounts list\n * @param options - parameters used for syncing the internal accounts list with the user storage accounts list\n */\nexport async function syncInternalAccountsWithUserStorage(\n config: SyncInternalAccountsWithUserStorageConfig,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { isAccountSyncingEnabled } = config;\n\n if (!canPerformAccountSyncing(config, options) || !isAccountSyncingEnabled) {\n return;\n }\n\n const {\n maxNumberOfAccountsToAdd = Infinity,\n onAccountAdded,\n onAccountNameUpdated,\n onAccountSyncErroneousSituation,\n } = config;\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n try {\n await getUserStorageControllerInstance().setIsAccountSyncingInProgress(\n true,\n );\n\n const userStorageAccountsList = await getUserStorageAccountsList(options);\n\n if (!userStorageAccountsList || !userStorageAccountsList.length) {\n await saveInternalAccountsListToUserStorage(\n { isAccountSyncingEnabled },\n options,\n );\n await getUserStorageControllerInstance().setHasAccountSyncingSyncedAtLeastOnce(\n true,\n );\n return;\n }\n // Keep a record if erroneous situations are found during the sync\n // This is done so we can send the context to Sentry in case of an erroneous situation\n let erroneousSituationsFound = false;\n\n // Prepare an array of internal accounts to be saved to the user storage\n const internalAccountsToBeSavedToUserStorage: InternalAccount[] = [];\n\n // Compare internal accounts list with user storage accounts list\n // First step: compare lengths\n const internalAccountsList = await getInternalAccountsList(options);\n\n if (!internalAccountsList || !internalAccountsList.length) {\n throw new Error(`Failed to get internal accounts list`);\n }\n\n const hasMoreUserStorageAccountsThanInternalAccounts =\n userStorageAccountsList.length > internalAccountsList.length;\n\n // We don't want to remove existing accounts for a user\n // so we only add new accounts if the user has more accounts in user storage than internal accounts\n if (hasMoreUserStorageAccountsThanInternalAccounts) {\n const numberOfAccountsToAdd =\n Math.min(userStorageAccountsList.length, maxNumberOfAccountsToAdd) -\n internalAccountsList.length;\n\n // Create new accounts to match the user storage accounts list\n // NOTE: we only support the primary SRP HD keyring for now\n // This is why we are hardcoding the index to 0\n await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n type: KeyringTypes.hd,\n index: 0,\n },\n async ({ keyring }) => {\n await keyring.addAccounts(numberOfAccountsToAdd);\n },\n );\n\n // TODO: below code is kept for analytics but should probably be re-thought\n for (let i = 0; i < numberOfAccountsToAdd; i++) {\n onAccountAdded?.();\n }\n }\n\n // Second step: compare account names\n // Get the internal accounts list again since new accounts might have been added in the previous step\n const refreshedInternalAccountsList =\n await getInternalAccountsList(options);\n\n const newlyAddedAccounts = refreshedInternalAccountsList.filter(\n (account) =>\n !internalAccountsList.find((a) => a.address === account.address),\n );\n\n for (const internalAccount of refreshedInternalAccountsList) {\n const userStorageAccount = userStorageAccountsList.find(\n (account) => account.a === internalAccount.address,\n );\n\n // If the account is not present in user storage\n // istanbul ignore next\n if (!userStorageAccount) {\n // If the account was just added in the previous step, skip saving it, it's likely to be a bogus account\n if (newlyAddedAccounts.includes(internalAccount)) {\n erroneousSituationsFound = true;\n onAccountSyncErroneousSituation?.(\n 'An account was added to the internal accounts list but was not present in the user storage accounts list',\n {\n internalAccount,\n userStorageAccount,\n newlyAddedAccounts,\n userStorageAccountsList,\n internalAccountsList,\n refreshedInternalAccountsList,\n internalAccountsToBeSavedToUserStorage,\n },\n );\n continue;\n }\n // Otherwise, it means that this internal account was present before the sync, and needs to be saved to the user storage\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n\n // From this point on, we know that the account is present in\n // both the internal accounts list and the user storage accounts list\n\n // One or both accounts have default names\n const isInternalAccountNameDefault = isNameDefaultAccountName(\n internalAccount.metadata.name,\n );\n const isUserStorageAccountNameDefault = isNameDefaultAccountName(\n userStorageAccount.n,\n );\n\n // Internal account has default name\n if (isInternalAccountNameDefault) {\n if (!isUserStorageAccountNameDefault) {\n getMessenger().call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n },\n );\n\n onAccountNameUpdated?.();\n }\n continue;\n }\n\n // Internal account has custom name but user storage account has default name\n if (isUserStorageAccountNameDefault) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n\n // Both accounts have custom names\n\n // User storage account has a nameLastUpdatedAt timestamp\n // Note: not storing the undefined checks in constants to act as a type guard\n if (userStorageAccount.nlu !== undefined) {\n if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {\n const isInternalAccountNameNewer =\n internalAccount.metadata.nameLastUpdatedAt > userStorageAccount.nlu;\n\n if (isInternalAccountNameNewer) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n }\n\n getMessenger().call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n nameLastUpdatedAt: userStorageAccount.nlu,\n },\n );\n\n const areInternalAndUserStorageAccountNamesEqual =\n internalAccount.metadata.name === userStorageAccount.n;\n\n if (!areInternalAndUserStorageAccountNamesEqual) {\n onAccountNameUpdated?.();\n }\n\n continue;\n } else if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n }\n\n // Save the internal accounts list to the user storage\n if (internalAccountsToBeSavedToUserStorage.length) {\n await getUserStorageControllerInstance().performBatchSetStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n internalAccountsToBeSavedToUserStorage.map((account) => [\n account.address,\n JSON.stringify(mapInternalAccountToUserStorageAccount(account)),\n ]),\n );\n }\n\n // In case we have corrupted user storage with accounts that don't exist in the internal accounts list\n // Delete those accounts from the user storage\n const userStorageAccountsToBeDeleted = userStorageAccountsList.filter(\n (account) =>\n !refreshedInternalAccountsList.find((a) => a.address === account.a),\n );\n\n if (userStorageAccountsToBeDeleted.length) {\n await getUserStorageControllerInstance().performBatchDeleteStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n userStorageAccountsToBeDeleted.map((account) => account.a),\n );\n erroneousSituationsFound = true;\n onAccountSyncErroneousSituation?.(\n 'An account was present in the user storage accounts list but was not found in the internal accounts list after the sync',\n {\n userStorageAccountsToBeDeleted,\n internalAccountsList,\n refreshedInternalAccountsList,\n internalAccountsToBeSavedToUserStorage,\n userStorageAccountsList,\n },\n );\n }\n\n if (erroneousSituationsFound) {\n const [finalUserStorageAccountsList, finalInternalAccountsList] =\n await Promise.all([\n getUserStorageAccountsList(options),\n getInternalAccountsList(options),\n ]);\n\n const doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList =\n finalInternalAccountsList.every((account) =>\n finalUserStorageAccountsList?.some(\n (userStorageAccount) => userStorageAccount.a === account.address,\n ),\n );\n\n // istanbul ignore next\n const doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList =\n (finalUserStorageAccountsList?.length || 0) > maxNumberOfAccountsToAdd\n ? true\n : finalUserStorageAccountsList?.every((account) =>\n finalInternalAccountsList.some(\n (internalAccount) => internalAccount.address === account.a,\n ),\n );\n\n const doFinalListsMatch =\n doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList &&\n doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList;\n\n const context = {\n finalUserStorageAccountsList,\n finalInternalAccountsList,\n };\n if (doFinalListsMatch) {\n onAccountSyncErroneousSituation?.(\n 'Erroneous situations were found during the sync, but final state matches the expected state',\n context,\n );\n } else {\n onAccountSyncErroneousSituation?.(\n 'Erroneous situations were found during the sync, and final state does not match the expected state',\n context,\n );\n }\n }\n\n // We do this here and not in the finally statement because we want to make sure that\n // the accounts are saved / updated / deleted at least once before we set this flag\n await getUserStorageControllerInstance().setHasAccountSyncingSyncedAtLeastOnce(\n true,\n );\n } catch (e) {\n // istanbul ignore next\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `UserStorageController - failed to sync user storage accounts list - ${errorMessage}`,\n );\n } finally {\n await getUserStorageControllerInstance().setIsAccountSyncingInProgress(\n false,\n );\n }\n}\n"]}
|
|
@@ -100,8 +100,8 @@ export async function syncInternalAccountsWithUserStorage(config, options) {
|
|
|
100
100
|
await getMessenger().call('KeyringController:withKeyring', {
|
|
101
101
|
type: KeyringTypes.hd,
|
|
102
102
|
index: 0,
|
|
103
|
-
}, async (keyring) => {
|
|
104
|
-
keyring.addAccounts(numberOfAccountsToAdd);
|
|
103
|
+
}, async ({ keyring }) => {
|
|
104
|
+
await keyring.addAccounts(numberOfAccountsToAdd);
|
|
105
105
|
});
|
|
106
106
|
// TODO: below code is kept for analytics but should probably be re-thought
|
|
107
107
|
for (let i = 0; i < numberOfAccountsToAdd; i++) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller-integration.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/controller-integration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,8BAA8B;AACzD,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAG5D,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC3B,yBAAqB;AAEtB,OAAO,EACL,wCAAwC,EACxC,wBAAwB,EACxB,sCAAsC,EACvC,oBAAgB;AACjB,OAAO,EAAE,0BAA0B,EAAE,2CAAuC;AAE5E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,eAAgC,EAChC,MAA4B,EAC5B,OAA8B;IAE9B,MAAM,EAAE,uBAAuB,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,IACE,CAAC,uBAAuB;QACxB,CAAC,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC;QAC1C,CAAC,gBAAgB,CAAC,eAAe,CAAC,IAAI,CAAC;QACvC,CAAC,CAAC,MAAM,wCAAwC,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC,EAC3E;QACA,OAAO;KACR;IAED,IAAI;QACF,8DAA8D;QAC9D,MAAM,aAAa,GACjB,sCAAsC,CAAC,eAAe,CAAC,CAAC;QAE1D,MAAM,gCAAgC,EAAE,CAAC,iBAAiB;QACxD,2BAA2B;QAE3B,GAAG,0BAA0B,CAAC,QAAQ,IAAI,eAAe,CAAC,OAAO,EAAE,EACnE,IAAI,CAAC,SAAS,CAAC,aAAa,CAAC,CAC9B,CAAC;KACH;IAAC,OAAO,CAAC,EAAE;QACV,uBAAuB;QACvB,MAAM,YAAY,GAAG,CAAC,YAAY,KAAK,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';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport {\n canPerformAccountSyncing,\n getInternalAccountsList,\n getUserStorageAccountsList,\n} from './sync-utils';\nimport type { AccountSyncingConfig, AccountSyncingOptions } from './types';\nimport {\n isInternalAccountFromPrimarySRPHdKeyring,\n isNameDefaultAccountName,\n mapInternalAccountToUserStorageAccount,\n} from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Saves an individual internal account to the user storage.\n *\n * @param internalAccount - The internal account to save\n * @param config - parameters used for saving the internal account\n * @param options - parameters used for saving the internal account\n */\nexport async function saveInternalAccountToUserStorage(\n internalAccount: InternalAccount,\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { isAccountSyncingEnabled } = config;\n const { getUserStorageControllerInstance } = options;\n\n if (\n !isAccountSyncingEnabled ||\n !canPerformAccountSyncing(config, options) ||\n !isEvmAccountType(internalAccount.type) ||\n !(await isInternalAccountFromPrimarySRPHdKeyring(internalAccount, options))\n ) {\n return;\n }\n\n try {\n // Map the internal account to the user storage account schema\n const mappedAccount =\n mapInternalAccountToUserStorageAccount(internalAccount);\n\n await getUserStorageControllerInstance().performSetStorage(\n // ESLint is confused here.\n\n `${USER_STORAGE_FEATURE_NAMES.accounts}.${internalAccount.address}`,\n JSON.stringify(mappedAccount),\n );\n } catch (e) {\n // istanbul ignore next\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `UserStorageController - failed to save account to user storage - ${errorMessage}`,\n );\n }\n}\n\n/**\n * Saves the list of internal accounts to the user storage.\n *\n * @param config - parameters used for saving the list of internal accounts\n * @param options - parameters used for saving the list of internal accounts\n */\nexport async function saveInternalAccountsListToUserStorage(\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { isAccountSyncingEnabled } = config;\n const { getUserStorageControllerInstance } = options;\n\n if (!isAccountSyncingEnabled) {\n return;\n }\n\n const internalAccountsList = await getInternalAccountsList(options);\n\n if (!internalAccountsList?.length) {\n return;\n }\n\n const internalAccountsListFormattedForUserStorage = internalAccountsList.map(\n mapInternalAccountToUserStorageAccount,\n );\n\n await getUserStorageControllerInstance().performBatchSetStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n internalAccountsListFormattedForUserStorage.map((account) => [\n account.a,\n JSON.stringify(account),\n ]),\n );\n}\n\ntype SyncInternalAccountsWithUserStorageConfig = AccountSyncingConfig & {\n maxNumberOfAccountsToAdd?: number;\n onAccountAdded?: () => void;\n onAccountNameUpdated?: () => void;\n onAccountSyncErroneousSituation?: (\n errorMessage: string,\n sentryContext?: Record<string, unknown>,\n ) => void;\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 * @param config - parameters used for syncing the internal accounts list with the user storage accounts list\n * @param options - parameters used for syncing the internal accounts list with the user storage accounts list\n */\nexport async function syncInternalAccountsWithUserStorage(\n config: SyncInternalAccountsWithUserStorageConfig,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { isAccountSyncingEnabled } = config;\n\n if (!canPerformAccountSyncing(config, options) || !isAccountSyncingEnabled) {\n return;\n }\n\n const {\n maxNumberOfAccountsToAdd = Infinity,\n onAccountAdded,\n onAccountNameUpdated,\n onAccountSyncErroneousSituation,\n } = config;\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n try {\n await getUserStorageControllerInstance().setIsAccountSyncingInProgress(\n true,\n );\n\n const userStorageAccountsList = await getUserStorageAccountsList(options);\n\n if (!userStorageAccountsList || !userStorageAccountsList.length) {\n await saveInternalAccountsListToUserStorage(\n { isAccountSyncingEnabled },\n options,\n );\n await getUserStorageControllerInstance().setHasAccountSyncingSyncedAtLeastOnce(\n true,\n );\n return;\n }\n // Keep a record if erroneous situations are found during the sync\n // This is done so we can send the context to Sentry in case of an erroneous situation\n let erroneousSituationsFound = false;\n\n // Prepare an array of internal accounts to be saved to the user storage\n const internalAccountsToBeSavedToUserStorage: InternalAccount[] = [];\n\n // Compare internal accounts list with user storage accounts list\n // First step: compare lengths\n const internalAccountsList = await getInternalAccountsList(options);\n\n if (!internalAccountsList || !internalAccountsList.length) {\n throw new Error(`Failed to get internal accounts list`);\n }\n\n const hasMoreUserStorageAccountsThanInternalAccounts =\n userStorageAccountsList.length > internalAccountsList.length;\n\n // We don't want to remove existing accounts for a user\n // so we only add new accounts if the user has more accounts in user storage than internal accounts\n if (hasMoreUserStorageAccountsThanInternalAccounts) {\n const numberOfAccountsToAdd =\n Math.min(userStorageAccountsList.length, maxNumberOfAccountsToAdd) -\n internalAccountsList.length;\n\n // Create new accounts to match the user storage accounts list\n // NOTE: we only support the primary SRP HD keyring for now\n // This is why we are hardcoding the index to 0\n await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n type: KeyringTypes.hd,\n index: 0,\n },\n async (keyring) => {\n keyring.addAccounts(numberOfAccountsToAdd);\n },\n );\n\n // TODO: below code is kept for analytics but should probably be re-thought\n for (let i = 0; i < numberOfAccountsToAdd; i++) {\n onAccountAdded?.();\n }\n }\n\n // Second step: compare account names\n // Get the internal accounts list again since new accounts might have been added in the previous step\n const refreshedInternalAccountsList =\n await getInternalAccountsList(options);\n\n const newlyAddedAccounts = refreshedInternalAccountsList.filter(\n (account) =>\n !internalAccountsList.find((a) => a.address === account.address),\n );\n\n for (const internalAccount of refreshedInternalAccountsList) {\n const userStorageAccount = userStorageAccountsList.find(\n (account) => account.a === internalAccount.address,\n );\n\n // If the account is not present in user storage\n // istanbul ignore next\n if (!userStorageAccount) {\n // If the account was just added in the previous step, skip saving it, it's likely to be a bogus account\n if (newlyAddedAccounts.includes(internalAccount)) {\n erroneousSituationsFound = true;\n onAccountSyncErroneousSituation?.(\n 'An account was added to the internal accounts list but was not present in the user storage accounts list',\n {\n internalAccount,\n userStorageAccount,\n newlyAddedAccounts,\n userStorageAccountsList,\n internalAccountsList,\n refreshedInternalAccountsList,\n internalAccountsToBeSavedToUserStorage,\n },\n );\n continue;\n }\n // Otherwise, it means that this internal account was present before the sync, and needs to be saved to the user storage\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n\n // From this point on, we know that the account is present in\n // both the internal accounts list and the user storage accounts list\n\n // One or both accounts have default names\n const isInternalAccountNameDefault = isNameDefaultAccountName(\n internalAccount.metadata.name,\n );\n const isUserStorageAccountNameDefault = isNameDefaultAccountName(\n userStorageAccount.n,\n );\n\n // Internal account has default name\n if (isInternalAccountNameDefault) {\n if (!isUserStorageAccountNameDefault) {\n getMessenger().call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n },\n );\n\n onAccountNameUpdated?.();\n }\n continue;\n }\n\n // Internal account has custom name but user storage account has default name\n if (isUserStorageAccountNameDefault) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n\n // Both accounts have custom names\n\n // User storage account has a nameLastUpdatedAt timestamp\n // Note: not storing the undefined checks in constants to act as a type guard\n if (userStorageAccount.nlu !== undefined) {\n if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {\n const isInternalAccountNameNewer =\n internalAccount.metadata.nameLastUpdatedAt > userStorageAccount.nlu;\n\n if (isInternalAccountNameNewer) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n }\n\n getMessenger().call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n nameLastUpdatedAt: userStorageAccount.nlu,\n },\n );\n\n const areInternalAndUserStorageAccountNamesEqual =\n internalAccount.metadata.name === userStorageAccount.n;\n\n if (!areInternalAndUserStorageAccountNamesEqual) {\n onAccountNameUpdated?.();\n }\n\n continue;\n } else if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n }\n\n // Save the internal accounts list to the user storage\n if (internalAccountsToBeSavedToUserStorage.length) {\n await getUserStorageControllerInstance().performBatchSetStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n internalAccountsToBeSavedToUserStorage.map((account) => [\n account.address,\n JSON.stringify(mapInternalAccountToUserStorageAccount(account)),\n ]),\n );\n }\n\n // In case we have corrupted user storage with accounts that don't exist in the internal accounts list\n // Delete those accounts from the user storage\n const userStorageAccountsToBeDeleted = userStorageAccountsList.filter(\n (account) =>\n !refreshedInternalAccountsList.find((a) => a.address === account.a),\n );\n\n if (userStorageAccountsToBeDeleted.length) {\n await getUserStorageControllerInstance().performBatchDeleteStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n userStorageAccountsToBeDeleted.map((account) => account.a),\n );\n erroneousSituationsFound = true;\n onAccountSyncErroneousSituation?.(\n 'An account was present in the user storage accounts list but was not found in the internal accounts list after the sync',\n {\n userStorageAccountsToBeDeleted,\n internalAccountsList,\n refreshedInternalAccountsList,\n internalAccountsToBeSavedToUserStorage,\n userStorageAccountsList,\n },\n );\n }\n\n if (erroneousSituationsFound) {\n const [finalUserStorageAccountsList, finalInternalAccountsList] =\n await Promise.all([\n getUserStorageAccountsList(options),\n getInternalAccountsList(options),\n ]);\n\n const doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList =\n finalInternalAccountsList.every((account) =>\n finalUserStorageAccountsList?.some(\n (userStorageAccount) => userStorageAccount.a === account.address,\n ),\n );\n\n // istanbul ignore next\n const doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList =\n (finalUserStorageAccountsList?.length || 0) > maxNumberOfAccountsToAdd\n ? true\n : finalUserStorageAccountsList?.every((account) =>\n finalInternalAccountsList.some(\n (internalAccount) => internalAccount.address === account.a,\n ),\n );\n\n const doFinalListsMatch =\n doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList &&\n doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList;\n\n const context = {\n finalUserStorageAccountsList,\n finalInternalAccountsList,\n };\n if (doFinalListsMatch) {\n onAccountSyncErroneousSituation?.(\n 'Erroneous situations were found during the sync, but final state matches the expected state',\n context,\n );\n } else {\n onAccountSyncErroneousSituation?.(\n 'Erroneous situations were found during the sync, and final state does not match the expected state',\n context,\n );\n }\n }\n\n // We do this here and not in the finally statement because we want to make sure that\n // the accounts are saved / updated / deleted at least once before we set this flag\n await getUserStorageControllerInstance().setHasAccountSyncingSyncedAtLeastOnce(\n true,\n );\n } catch (e) {\n // istanbul ignore next\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `UserStorageController - failed to sync user storage accounts list - ${errorMessage}`,\n );\n } finally {\n await getUserStorageControllerInstance().setIsAccountSyncingInProgress(\n false,\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"controller-integration.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/controller-integration.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,8BAA8B;AACzD,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAG5D,OAAO,EACL,wBAAwB,EACxB,uBAAuB,EACvB,0BAA0B,EAC3B,yBAAqB;AAEtB,OAAO,EACL,wCAAwC,EACxC,wBAAwB,EACxB,sCAAsC,EACvC,oBAAgB;AACjB,OAAO,EAAE,0BAA0B,EAAE,2CAAuC;AAE5E;;;;;;GAMG;AACH,MAAM,CAAC,KAAK,UAAU,gCAAgC,CACpD,eAAgC,EAChC,MAA4B,EAC5B,OAA8B;IAE9B,MAAM,EAAE,uBAAuB,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,IACE,CAAC,uBAAuB;QACxB,CAAC,wBAAwB,CAAC,MAAM,EAAE,OAAO,CAAC;QAC1C,CAAC,gBAAgB,CAAC,eAAe,CAAC,IAAI,CAAC;QACvC,CAAC,CAAC,MAAM,wCAAwC,CAAC,eAAe,EAAE,OAAO,CAAC,CAAC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AAI,CACL,CAAC;KACH;IAAC,OAAO,CAAC,EAAE;QACV,uBAAuB;QACvB,MAAM,YAAY,GAAG,CAAC,YAAY,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC;QACxE,MAAM,IAAI,KAAK,CACb,uEAAuE,YAAY,EAAE,CACtF,CAAC;KACH;YAAS;QACR,MAAM,gCAAgC,EAAE,CAAC,6BAA6B,CACpE,KAAK,CACN,CAAC;KACH;AACH,CAAC","sourcesContent":["import { isEvmAccountType } from '@metamask/keyring-api';\nimport { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport {\n canPerformAccountSyncing,\n getInternalAccountsList,\n getUserStorageAccountsList,\n} from './sync-utils';\nimport type { AccountSyncingConfig, AccountSyncingOptions } from './types';\nimport {\n isInternalAccountFromPrimarySRPHdKeyring,\n isNameDefaultAccountName,\n mapInternalAccountToUserStorageAccount,\n} from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Saves an individual internal account to the user storage.\n *\n * @param internalAccount - The internal account to save\n * @param config - parameters used for saving the internal account\n * @param options - parameters used for saving the internal account\n */\nexport async function saveInternalAccountToUserStorage(\n internalAccount: InternalAccount,\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { isAccountSyncingEnabled } = config;\n const { getUserStorageControllerInstance } = options;\n\n if (\n !isAccountSyncingEnabled ||\n !canPerformAccountSyncing(config, options) ||\n !isEvmAccountType(internalAccount.type) ||\n !(await isInternalAccountFromPrimarySRPHdKeyring(internalAccount, options))\n ) {\n return;\n }\n\n try {\n // Map the internal account to the user storage account schema\n const mappedAccount =\n mapInternalAccountToUserStorageAccount(internalAccount);\n\n await getUserStorageControllerInstance().performSetStorage(\n // ESLint is confused here.\n\n `${USER_STORAGE_FEATURE_NAMES.accounts}.${internalAccount.address}`,\n JSON.stringify(mappedAccount),\n );\n } catch (e) {\n // istanbul ignore next\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `UserStorageController - failed to save account to user storage - ${errorMessage}`,\n );\n }\n}\n\n/**\n * Saves the list of internal accounts to the user storage.\n *\n * @param config - parameters used for saving the list of internal accounts\n * @param options - parameters used for saving the list of internal accounts\n */\nexport async function saveInternalAccountsListToUserStorage(\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { isAccountSyncingEnabled } = config;\n const { getUserStorageControllerInstance } = options;\n\n if (!isAccountSyncingEnabled) {\n return;\n }\n\n const internalAccountsList = await getInternalAccountsList(options);\n\n if (!internalAccountsList?.length) {\n return;\n }\n\n const internalAccountsListFormattedForUserStorage = internalAccountsList.map(\n mapInternalAccountToUserStorageAccount,\n );\n\n await getUserStorageControllerInstance().performBatchSetStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n internalAccountsListFormattedForUserStorage.map((account) => [\n account.a,\n JSON.stringify(account),\n ]),\n );\n}\n\ntype SyncInternalAccountsWithUserStorageConfig = AccountSyncingConfig & {\n maxNumberOfAccountsToAdd?: number;\n onAccountAdded?: () => void;\n onAccountNameUpdated?: () => void;\n onAccountSyncErroneousSituation?: (\n errorMessage: string,\n sentryContext?: Record<string, unknown>,\n ) => void;\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 * @param config - parameters used for syncing the internal accounts list with the user storage accounts list\n * @param options - parameters used for syncing the internal accounts list with the user storage accounts list\n */\nexport async function syncInternalAccountsWithUserStorage(\n config: SyncInternalAccountsWithUserStorageConfig,\n options: AccountSyncingOptions,\n): Promise<void> {\n const { isAccountSyncingEnabled } = config;\n\n if (!canPerformAccountSyncing(config, options) || !isAccountSyncingEnabled) {\n return;\n }\n\n const {\n maxNumberOfAccountsToAdd = Infinity,\n onAccountAdded,\n onAccountNameUpdated,\n onAccountSyncErroneousSituation,\n } = config;\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n try {\n await getUserStorageControllerInstance().setIsAccountSyncingInProgress(\n true,\n );\n\n const userStorageAccountsList = await getUserStorageAccountsList(options);\n\n if (!userStorageAccountsList || !userStorageAccountsList.length) {\n await saveInternalAccountsListToUserStorage(\n { isAccountSyncingEnabled },\n options,\n );\n await getUserStorageControllerInstance().setHasAccountSyncingSyncedAtLeastOnce(\n true,\n );\n return;\n }\n // Keep a record if erroneous situations are found during the sync\n // This is done so we can send the context to Sentry in case of an erroneous situation\n let erroneousSituationsFound = false;\n\n // Prepare an array of internal accounts to be saved to the user storage\n const internalAccountsToBeSavedToUserStorage: InternalAccount[] = [];\n\n // Compare internal accounts list with user storage accounts list\n // First step: compare lengths\n const internalAccountsList = await getInternalAccountsList(options);\n\n if (!internalAccountsList || !internalAccountsList.length) {\n throw new Error(`Failed to get internal accounts list`);\n }\n\n const hasMoreUserStorageAccountsThanInternalAccounts =\n userStorageAccountsList.length > internalAccountsList.length;\n\n // We don't want to remove existing accounts for a user\n // so we only add new accounts if the user has more accounts in user storage than internal accounts\n if (hasMoreUserStorageAccountsThanInternalAccounts) {\n const numberOfAccountsToAdd =\n Math.min(userStorageAccountsList.length, maxNumberOfAccountsToAdd) -\n internalAccountsList.length;\n\n // Create new accounts to match the user storage accounts list\n // NOTE: we only support the primary SRP HD keyring for now\n // This is why we are hardcoding the index to 0\n await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n type: KeyringTypes.hd,\n index: 0,\n },\n async ({ keyring }) => {\n await keyring.addAccounts(numberOfAccountsToAdd);\n },\n );\n\n // TODO: below code is kept for analytics but should probably be re-thought\n for (let i = 0; i < numberOfAccountsToAdd; i++) {\n onAccountAdded?.();\n }\n }\n\n // Second step: compare account names\n // Get the internal accounts list again since new accounts might have been added in the previous step\n const refreshedInternalAccountsList =\n await getInternalAccountsList(options);\n\n const newlyAddedAccounts = refreshedInternalAccountsList.filter(\n (account) =>\n !internalAccountsList.find((a) => a.address === account.address),\n );\n\n for (const internalAccount of refreshedInternalAccountsList) {\n const userStorageAccount = userStorageAccountsList.find(\n (account) => account.a === internalAccount.address,\n );\n\n // If the account is not present in user storage\n // istanbul ignore next\n if (!userStorageAccount) {\n // If the account was just added in the previous step, skip saving it, it's likely to be a bogus account\n if (newlyAddedAccounts.includes(internalAccount)) {\n erroneousSituationsFound = true;\n onAccountSyncErroneousSituation?.(\n 'An account was added to the internal accounts list but was not present in the user storage accounts list',\n {\n internalAccount,\n userStorageAccount,\n newlyAddedAccounts,\n userStorageAccountsList,\n internalAccountsList,\n refreshedInternalAccountsList,\n internalAccountsToBeSavedToUserStorage,\n },\n );\n continue;\n }\n // Otherwise, it means that this internal account was present before the sync, and needs to be saved to the user storage\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n\n // From this point on, we know that the account is present in\n // both the internal accounts list and the user storage accounts list\n\n // One or both accounts have default names\n const isInternalAccountNameDefault = isNameDefaultAccountName(\n internalAccount.metadata.name,\n );\n const isUserStorageAccountNameDefault = isNameDefaultAccountName(\n userStorageAccount.n,\n );\n\n // Internal account has default name\n if (isInternalAccountNameDefault) {\n if (!isUserStorageAccountNameDefault) {\n getMessenger().call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n },\n );\n\n onAccountNameUpdated?.();\n }\n continue;\n }\n\n // Internal account has custom name but user storage account has default name\n if (isUserStorageAccountNameDefault) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n\n // Both accounts have custom names\n\n // User storage account has a nameLastUpdatedAt timestamp\n // Note: not storing the undefined checks in constants to act as a type guard\n if (userStorageAccount.nlu !== undefined) {\n if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {\n const isInternalAccountNameNewer =\n internalAccount.metadata.nameLastUpdatedAt > userStorageAccount.nlu;\n\n if (isInternalAccountNameNewer) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n }\n\n getMessenger().call(\n 'AccountsController:updateAccountMetadata',\n internalAccount.id,\n {\n name: userStorageAccount.n,\n nameLastUpdatedAt: userStorageAccount.nlu,\n },\n );\n\n const areInternalAndUserStorageAccountNamesEqual =\n internalAccount.metadata.name === userStorageAccount.n;\n\n if (!areInternalAndUserStorageAccountNamesEqual) {\n onAccountNameUpdated?.();\n }\n\n continue;\n } else if (internalAccount.metadata.nameLastUpdatedAt !== undefined) {\n internalAccountsToBeSavedToUserStorage.push(internalAccount);\n continue;\n }\n }\n\n // Save the internal accounts list to the user storage\n if (internalAccountsToBeSavedToUserStorage.length) {\n await getUserStorageControllerInstance().performBatchSetStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n internalAccountsToBeSavedToUserStorage.map((account) => [\n account.address,\n JSON.stringify(mapInternalAccountToUserStorageAccount(account)),\n ]),\n );\n }\n\n // In case we have corrupted user storage with accounts that don't exist in the internal accounts list\n // Delete those accounts from the user storage\n const userStorageAccountsToBeDeleted = userStorageAccountsList.filter(\n (account) =>\n !refreshedInternalAccountsList.find((a) => a.address === account.a),\n );\n\n if (userStorageAccountsToBeDeleted.length) {\n await getUserStorageControllerInstance().performBatchDeleteStorage(\n USER_STORAGE_FEATURE_NAMES.accounts,\n userStorageAccountsToBeDeleted.map((account) => account.a),\n );\n erroneousSituationsFound = true;\n onAccountSyncErroneousSituation?.(\n 'An account was present in the user storage accounts list but was not found in the internal accounts list after the sync',\n {\n userStorageAccountsToBeDeleted,\n internalAccountsList,\n refreshedInternalAccountsList,\n internalAccountsToBeSavedToUserStorage,\n userStorageAccountsList,\n },\n );\n }\n\n if (erroneousSituationsFound) {\n const [finalUserStorageAccountsList, finalInternalAccountsList] =\n await Promise.all([\n getUserStorageAccountsList(options),\n getInternalAccountsList(options),\n ]);\n\n const doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList =\n finalInternalAccountsList.every((account) =>\n finalUserStorageAccountsList?.some(\n (userStorageAccount) => userStorageAccount.a === account.address,\n ),\n );\n\n // istanbul ignore next\n const doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList =\n (finalUserStorageAccountsList?.length || 0) > maxNumberOfAccountsToAdd\n ? true\n : finalUserStorageAccountsList?.every((account) =>\n finalInternalAccountsList.some(\n (internalAccount) => internalAccount.address === account.a,\n ),\n );\n\n const doFinalListsMatch =\n doesEveryAccountInInternalAccountsListExistInUserStorageAccountsList &&\n doesEveryAccountInUserStorageAccountsListExistInInternalAccountsList;\n\n const context = {\n finalUserStorageAccountsList,\n finalInternalAccountsList,\n };\n if (doFinalListsMatch) {\n onAccountSyncErroneousSituation?.(\n 'Erroneous situations were found during the sync, but final state matches the expected state',\n context,\n );\n } else {\n onAccountSyncErroneousSituation?.(\n 'Erroneous situations were found during the sync, and final state does not match the expected state',\n context,\n );\n }\n }\n\n // We do this here and not in the finally statement because we want to make sure that\n // the accounts are saved / updated / deleted at least once before we set this flag\n await getUserStorageControllerInstance().setHasAccountSyncingSyncedAtLeastOnce(\n true,\n );\n } catch (e) {\n // istanbul ignore next\n const errorMessage = e instanceof Error ? e.message : JSON.stringify(e);\n throw new Error(\n `UserStorageController - failed to sync user storage accounts list - ${errorMessage}`,\n );\n } finally {\n await getUserStorageControllerInstance().setIsAccountSyncingInProgress(\n false,\n );\n }\n}\n"]}
|
|
@@ -34,6 +34,7 @@ exports.canPerformAccountSyncing = canPerformAccountSyncing;
|
|
|
34
34
|
*/
|
|
35
35
|
async function getInternalAccountsList(options) {
|
|
36
36
|
const { getMessenger } = options;
|
|
37
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
37
38
|
const internalAccountsList = await getMessenger().call('AccountsController:listAccounts');
|
|
38
39
|
return await (0, utils_1.mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList)(internalAccountsList, options);
|
|
39
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":";;;AAOA,uCAA2F;AAC3F,uEAA4E;AAE5E;;;;;;GAMG;AACH,SAAgB,wBAAwB,CACtC,MAA4B,EAC5B,OAA8B;IAE9B,MAAM,EAAE,uBAAuB,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,MAAM,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,GAC3D,gCAAgC,EAAE,CAAC,KAAK,CAAC;IAC3C,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC,IAAI,CACvC,qCAAqC,CACtC,CAAC;IAEF,IACE,CAAC,uBAAuB;QACxB,CAAC,aAAa;QACd,CAAC,uBAAuB;QACxB,0BAA0B,EAC1B;QACA,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAvBD,4DAuBC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,uBAAuB,CAC3C,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,MAAM,oBAAoB,GAAG,MAAM,YAAY,EAAE,CAAC,IAAI,CACpD,iCAAiC,CAClC,CAAC;IAEF,OAAO,MAAM,IAAA,wEAAgE,EAC3E,oBAAoB,EACpB,OAAO,CACR,CAAC;AACJ,CAAC;
|
|
1
|
+
{"version":3,"file":"sync-utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":";;;AAOA,uCAA2F;AAC3F,uEAA4E;AAE5E;;;;;;GAMG;AACH,SAAgB,wBAAwB,CACtC,MAA4B,EAC5B,OAA8B;IAE9B,MAAM,EAAE,uBAAuB,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,MAAM,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,GAC3D,gCAAgC,EAAE,CAAC,KAAK,CAAC;IAC3C,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC,IAAI,CACvC,qCAAqC,CACtC,CAAC;IAEF,IACE,CAAC,uBAAuB;QACxB,CAAC,aAAa;QACd,CAAC,uBAAuB;QACxB,0BAA0B,EAC1B;QACA,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAvBD,4DAuBC;AAED;;;;;;;GAOG;AACI,KAAK,UAAU,uBAAuB,CAC3C,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,6DAA6D;IAC7D,MAAM,oBAAoB,GAAG,MAAM,YAAY,EAAE,CAAC,IAAI,CACpD,iCAAiC,CAClC,CAAC;IAEF,OAAO,MAAM,IAAA,wEAAgE,EAC3E,oBAAoB,EACpB,OAAO,CACR,CAAC;AACJ,CAAC;AAdD,0DAcC;AAED;;;;;GAKG;AACI,KAAK,UAAU,0BAA0B,CAC9C,OAA8B;IAE9B,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,MAAM,uBAAuB,GAC3B,MAAM,gCAAgC,EAAE,CAAC,kCAAkC,CACzE,2CAA0B,CAAC,QAAQ,CACpC,CAAC;IAEJ,OAAO,CACL,uBAAuB,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,IAAI,CAC7E,CAAC;AACJ,CAAC;AAbD,gEAaC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type {\n AccountSyncingConfig,\n AccountSyncingOptions,\n UserStorageAccount,\n} from './types';\nimport { mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList } from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Checks if account syncing can be performed based on a set of conditions\n *\n * @param config - configuration parameters\n * @param options - parameters used for checking if account syncing can be performed\n * @returns Returns true if account syncing can be performed, false otherwise.\n */\nexport function canPerformAccountSyncing(\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): boolean {\n const { isAccountSyncingEnabled } = config;\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n const { isProfileSyncingEnabled, isAccountSyncingInProgress } =\n getUserStorageControllerInstance().state;\n const isAuthEnabled = getMessenger().call(\n 'AuthenticationController:isSignedIn',\n );\n\n if (\n !isProfileSyncingEnabled ||\n !isAuthEnabled ||\n !isAccountSyncingEnabled ||\n isAccountSyncingInProgress\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Get the list of internal accounts\n * This function returns only the internal accounts that are from the primary SRP\n * and are from the HD keyring\n *\n * @param options - parameters used for getting the list of internal accounts\n * @returns the list of internal accounts\n */\nexport async function getInternalAccountsList(\n options: AccountSyncingOptions,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n // eslint-disable-next-line @typescript-eslint/await-thenable\n const internalAccountsList = await getMessenger().call(\n 'AccountsController:listAccounts',\n );\n\n return await mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(\n internalAccountsList,\n options,\n );\n}\n\n/**\n * Get the list of user storage accounts\n *\n * @param options - parameters used for getting the list of user storage accounts\n * @returns the list of user storage accounts\n */\nexport async function getUserStorageAccountsList(\n options: AccountSyncingOptions,\n): Promise<UserStorageAccount[] | null> {\n const { getUserStorageControllerInstance } = options;\n\n const rawAccountsListResponse =\n await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(\n USER_STORAGE_FEATURE_NAMES.accounts,\n );\n\n return (\n rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null\n );\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-utils.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EACnB,oBAAgB;AAIjB;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAoBT;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"sync-utils.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EACnB,oBAAgB;AAIjB;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAoBT;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,EAAE,CAAC,CAY5B;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAWtC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-utils.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EACnB,oBAAgB;AAIjB;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAoBT;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"sync-utils.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,uCAAuC;AAEtE,OAAO,KAAK,EACV,oBAAoB,EACpB,qBAAqB,EACrB,kBAAkB,EACnB,oBAAgB;AAIjB;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,oBAAoB,EAC5B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAoBT;AAED;;;;;;;GAOG;AACH,wBAAsB,uBAAuB,CAC3C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,eAAe,EAAE,CAAC,CAY5B;AAED;;;;;GAKG;AACH,wBAAsB,0BAA0B,CAC9C,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,kBAAkB,EAAE,GAAG,IAAI,CAAC,CAWtC"}
|
|
@@ -30,6 +30,7 @@ export function canPerformAccountSyncing(config, options) {
|
|
|
30
30
|
*/
|
|
31
31
|
export async function getInternalAccountsList(options) {
|
|
32
32
|
const { getMessenger } = options;
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/await-thenable
|
|
33
34
|
const internalAccountsList = await getMessenger().call('AccountsController:listAccounts');
|
|
34
35
|
return await mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(internalAccountsList, options);
|
|
35
36
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sync-utils.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/sync-utils.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,gEAAgE,EAAE,oBAAgB;AAC3F,OAAO,EAAE,0BAA0B,EAAE,2CAAuC;AAE5E;;;;;;GAMG;AACH,MAAM,UAAU,wBAAwB,CACtC,MAA4B,EAC5B,OAA8B;IAE9B,MAAM,EAAE,uBAAuB,EAAE,GAAG,MAAM,CAAC;IAC3C,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAEnE,MAAM,EAAE,uBAAuB,EAAE,0BAA0B,EAAE,GAC3D,gCAAgC,EAAE,CAAC,KAAK,CAAC;IAC3C,MAAM,aAAa,GAAG,YAAY,EAAE,CAAC,IAAI,CACvC,qCAAqC,CACtC,CAAC;IAEF,IACE,CAAC,uBAAuB;QACxB,CAAC,aAAa;QACd,CAAC,uBAAuB;QACxB,0BAA0B,EAC1B;QACA,OAAO,KAAK,CAAC;KACd;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,uBAAuB,CAC3C,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,MAAM,oBAAoB,GAAG,MAAM,YAAY,EAAE,CAAC,IAAI,CACpD,iCAAiC,CAClC,CAAC;IAEF,OAAO,MAAM,gEAAgE,CAC3E,oBAAoB,EACpB,OAAO,CACR,CAAC;AACJ,CAAC;AAED;;;;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,0BAA0B,CAC9C,OAA8B;IAE9B,MAAM,EAAE,gCAAgC,EAAE,GAAG,OAAO,CAAC;IAErD,MAAM,uBAAuB,GAC3B,MAAM,gCAAgC,EAAE,CAAC,kCAAkC,CACzE,0BAA0B,CAAC,QAAQ,CACpC,CAAC;IAEJ,OAAO,CACL,uBAAuB,EAAE,GAAG,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,IAAI,CAC7E,CAAC;AACJ,CAAC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type {\n AccountSyncingConfig,\n AccountSyncingOptions,\n UserStorageAccount,\n} from './types';\nimport { mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList } from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Checks if account syncing can be performed based on a set of conditions\n *\n * @param config - configuration parameters\n * @param options - parameters used for checking if account syncing can be performed\n * @returns Returns true if account syncing can be performed, false otherwise.\n */\nexport function canPerformAccountSyncing(\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): boolean {\n const { isAccountSyncingEnabled } = config;\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n const { isProfileSyncingEnabled, isAccountSyncingInProgress } =\n getUserStorageControllerInstance().state;\n const isAuthEnabled = getMessenger().call(\n 'AuthenticationController:isSignedIn',\n );\n\n if (\n !isProfileSyncingEnabled ||\n !isAuthEnabled ||\n !isAccountSyncingEnabled ||\n isAccountSyncingInProgress\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Get the list of internal accounts\n * This function returns only the internal accounts that are from the primary SRP\n * and are from the HD keyring\n *\n * @param options - parameters used for getting the list of internal accounts\n * @returns the list of internal accounts\n */\nexport async function getInternalAccountsList(\n options: AccountSyncingOptions,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n const internalAccountsList = await getMessenger().call(\n 'AccountsController:listAccounts',\n );\n\n return await mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(\n internalAccountsList,\n options,\n );\n}\n\n/**\n * Get the list of user storage accounts\n *\n * @param options - parameters used for getting the list of user storage accounts\n * @returns the list of user storage accounts\n */\nexport async function getUserStorageAccountsList(\n options: AccountSyncingOptions,\n): Promise<UserStorageAccount[] | null> {\n const { getUserStorageControllerInstance } = options;\n\n const rawAccountsListResponse =\n await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(\n USER_STORAGE_FEATURE_NAMES.accounts,\n );\n\n return (\n rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null\n );\n}\n"]}
|
|
1
|
+
{"version":3,"file":"sync-utils.mjs","source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C,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,IAAI,IAAI,CAC7E,CAAC;AACJ,CAAC","sourcesContent":["import type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport type {\n AccountSyncingConfig,\n AccountSyncingOptions,\n UserStorageAccount,\n} from './types';\nimport { mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList } from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\n\n/**\n * Checks if account syncing can be performed based on a set of conditions\n *\n * @param config - configuration parameters\n * @param options - parameters used for checking if account syncing can be performed\n * @returns Returns true if account syncing can be performed, false otherwise.\n */\nexport function canPerformAccountSyncing(\n config: AccountSyncingConfig,\n options: AccountSyncingOptions,\n): boolean {\n const { isAccountSyncingEnabled } = config;\n const { getMessenger, getUserStorageControllerInstance } = options;\n\n const { isProfileSyncingEnabled, isAccountSyncingInProgress } =\n getUserStorageControllerInstance().state;\n const isAuthEnabled = getMessenger().call(\n 'AuthenticationController:isSignedIn',\n );\n\n if (\n !isProfileSyncingEnabled ||\n !isAuthEnabled ||\n !isAccountSyncingEnabled ||\n isAccountSyncingInProgress\n ) {\n return false;\n }\n\n return true;\n}\n\n/**\n * Get the list of internal accounts\n * This function returns only the internal accounts that are from the primary SRP\n * and are from the HD keyring\n *\n * @param options - parameters used for getting the list of internal accounts\n * @returns the list of internal accounts\n */\nexport async function getInternalAccountsList(\n options: AccountSyncingOptions,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n // eslint-disable-next-line @typescript-eslint/await-thenable\n const internalAccountsList = await getMessenger().call(\n 'AccountsController:listAccounts',\n );\n\n return await mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(\n internalAccountsList,\n options,\n );\n}\n\n/**\n * Get the list of user storage accounts\n *\n * @param options - parameters used for getting the list of user storage accounts\n * @returns the list of user storage accounts\n */\nexport async function getUserStorageAccountsList(\n options: AccountSyncingOptions,\n): Promise<UserStorageAccount[] | null> {\n const { getUserStorageControllerInstance } = options;\n\n const rawAccountsListResponse =\n await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(\n USER_STORAGE_FEATURE_NAMES.accounts,\n );\n\n return (\n rawAccountsListResponse?.map((rawAccount) => JSON.parse(rawAccount)) ?? null\n );\n}\n"]}
|
|
@@ -47,7 +47,7 @@ async function mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(
|
|
|
47
47
|
const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call('KeyringController:withKeyring', {
|
|
48
48
|
type: keyring_controller_1.KeyringTypes.hd,
|
|
49
49
|
index: 0,
|
|
50
|
-
}, async (keyring) => {
|
|
50
|
+
}, async ({ keyring }) => {
|
|
51
51
|
return await keyring.getAccounts();
|
|
52
52
|
}));
|
|
53
53
|
return internalAccountsList.filter((account) => primarySRPHdKeyringAccountsAddresses?.includes(account.address));
|
|
@@ -68,7 +68,7 @@ async function isInternalAccountFromPrimarySRPHdKeyring(account, options) {
|
|
|
68
68
|
const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call('KeyringController:withKeyring', {
|
|
69
69
|
type: keyring_controller_1.KeyringTypes.hd,
|
|
70
70
|
index: 0,
|
|
71
|
-
}, async (keyring) => {
|
|
71
|
+
}, async ({ keyring }) => {
|
|
72
72
|
return await keyring.getAccounts();
|
|
73
73
|
}));
|
|
74
74
|
return primarySRPHdKeyringAccountsAddresses.includes(account.address);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":";;;AAAA,qEAA4D;AAG5D,+CAIqB;AAGrB;;;;;;GAMG;AAEI,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IACvD,OAAO,2CAA+B,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACrD,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,YAAY,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAJW,QAAA,wBAAwB,4BAInC;AAEF;;;;;GAKG;AACI,MAAM,sCAAsC,GAAG,CACpD,eAAgC,EACZ,EAAE;IACtB,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC;IAClD,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,QAAQ,CAAC;IAE7C,OAAO;QACL,CAAC,oCAAwB,CAAC,EAAE,gCAAoB;QAChD,CAAC,EAAE,OAAO;QACV,CAAC,EAAE,EAAE;QACL,CAAC,EAAE,IAAI;QACP,GAAG,CAAC,IAAA,gCAAwB,EAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,iBAAiB,EAAE,CAAC;KACtE,CAAC;AACJ,CAAC,CAAC;AAbW,QAAA,sCAAsC,0CAajD;AAEF;;;;;;;GAOG;AACI,KAAK,UAAU,gEAAgE,CACpF,oBAAuC,EACvC,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,MAAM,oCAAoC,GAAG,CAAC,MAAM,YAAY,EAAE,CAAC,IAAI,CACrE,+BAA+B,EAC/B;QACE,IAAI,EAAE,iCAAY,CAAC,EAAE;QACrB,KAAK,EAAE,CAAC;KACT,EACD,KAAK,EAAE,OAAO,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":";;;AAAA,qEAA4D;AAG5D,+CAIqB;AAGrB;;;;;;GAMG;AAEI,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IACvD,OAAO,2CAA+B,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACrD,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,YAAY,EAAE,GAA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D,OAAwB,EACxB,OAA8B;IAE9B,IAAI,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAC,IAAI,KAAK,iCAAY,CAAC,EAAE,EAAE;QACrD,OAAO,KAAK,CAAC;KACd;IAED,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,MAAM,oCAAoC,GAAG,CAAC,MAAM,YAAY,EAAE,CAAC,IAAI,CACrE,+BAA+B,EAC/B;QACE,IAAI,EAAE,iCAAY,CAAC,EAAE;QACrB,KAAK,EAAE,CAAC;KACT,EACD,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACpB,OAAO,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;IACrC,CAAC,CACF,CAAa,CAAC;IAEf,OAAO,oCAAoC,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACxE,CAAC;AAtBD,4FAsBC","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n LOCALIZED_DEFAULT_ACCOUNT_NAMES,\n} from './constants';\nimport type { AccountSyncingOptions, UserStorageAccount } from './types';\n\n/**\n * Tells if the given name is a default account name.\n * Default account names are localized names that are automatically generated by the clients.\n *\n * @param name - the name to check\n * @returns true if the name is a default account name, false otherwise\n */\n\nexport const isNameDefaultAccountName = (name: string) => {\n return LOCALIZED_DEFAULT_ACCOUNT_NAMES.some((prefix) => {\n return new RegExp(`^${prefix} ([0-9]+)$`, 'u').test(name);\n });\n};\n\n/**\n * Map an internal account to a user storage account\n *\n * @param internalAccount - An internal account\n * @returns A user storage account\n */\nexport const mapInternalAccountToUserStorageAccount = (\n internalAccount: InternalAccount,\n): UserStorageAccount => {\n const { address, id, metadata } = internalAccount;\n const { name, nameLastUpdatedAt } = metadata;\n\n return {\n [USER_STORAGE_VERSION_KEY]: USER_STORAGE_VERSION,\n a: address,\n i: id,\n n: name,\n ...(isNameDefaultAccountName(name) ? {} : { nlu: nameLastUpdatedAt }),\n };\n};\n\n/**\n * Transforms a list of any internal accounts to a list of internal accounts that\n * have the correct keyring type and are from the primary SRP.\n *\n * @param internalAccountsList - The list of internal accounts\n * @param options - Parameters used for checking if the internal account is from the primary SRP\n * @returns Returns a list of internal accounts that have the correct keyring type and are from the primary SRP.\n */\nexport async function mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(\n internalAccountsList: InternalAccount[],\n options: AccountSyncingOptions,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n type: KeyringTypes.hd,\n index: 0,\n },\n async ({ keyring }) => {\n return await keyring.getAccounts();\n },\n )) as string[];\n\n return internalAccountsList.filter((account) =>\n primarySRPHdKeyringAccountsAddresses?.includes(account.address),\n );\n}\n\n/**\n * Checks if the given internal account is from the primary SRP and is from the HD keyring.\n *\n * @param account - The internal account to check\n * @param options - Parameters used for checking if the internal account is from the primary SRP\n * @returns Returns true if the internal account is from the primary SRP, false otherwise.\n */\nexport async function isInternalAccountFromPrimarySRPHdKeyring(\n account: InternalAccount,\n options: AccountSyncingOptions,\n): Promise<boolean> {\n if (account.metadata.keyring.type !== KeyringTypes.hd) {\n return false;\n }\n\n const { getMessenger } = options;\n\n const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n type: KeyringTypes.hd,\n index: 0,\n },\n async ({ keyring }) => {\n return await keyring.getAccounts();\n },\n )) as string[];\n\n return primarySRPHdKeyringAccountsAddresses.includes(account.address);\n}\n"]}
|
|
@@ -42,7 +42,7 @@ export async function mapInternalAccountsListToPrimarySRPHdKeyringInternalAccoun
|
|
|
42
42
|
const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call('KeyringController:withKeyring', {
|
|
43
43
|
type: KeyringTypes.hd,
|
|
44
44
|
index: 0,
|
|
45
|
-
}, async (keyring) => {
|
|
45
|
+
}, async ({ keyring }) => {
|
|
46
46
|
return await keyring.getAccounts();
|
|
47
47
|
}));
|
|
48
48
|
return internalAccountsList.filter((account) => primarySRPHdKeyringAccountsAddresses?.includes(account.address));
|
|
@@ -62,7 +62,7 @@ export async function isInternalAccountFromPrimarySRPHdKeyring(account, options)
|
|
|
62
62
|
const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call('KeyringController:withKeyring', {
|
|
63
63
|
type: KeyringTypes.hd,
|
|
64
64
|
index: 0,
|
|
65
|
-
}, async (keyring) => {
|
|
65
|
+
}, async ({ keyring }) => {
|
|
66
66
|
return await keyring.getAccounts();
|
|
67
67
|
}));
|
|
68
68
|
return primarySRPHdKeyringAccountsAddresses.includes(account.address);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAG5D,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,+BAA+B,EAChC,wBAAoB;AAGrB;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IACvD,OAAO,+BAA+B,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACrD,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,YAAY,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,CACpD,eAAgC,EACZ,EAAE;IACtB,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC;IAClD,MAAM,EAAE,IAAI,EAAE,iBAAiB,EAAE,GAAG,QAAQ,CAAC;IAE7C,OAAO;QACL,CAAC,wBAAwB,CAAC,EAAE,oBAAoB;QAChD,CAAC,EAAE,OAAO;QACV,CAAC,EAAE,EAAE;QACL,CAAC,EAAE,IAAI;QACP,GAAG,CAAC,wBAAwB,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG,EAAE,iBAAiB,EAAE,CAAC;KACtE,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,KAAK,UAAU,gEAAgE,CACpF,oBAAuC,EACvC,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,MAAM,oCAAoC,GAAG,CAAC,MAAM,YAAY,EAAE,CAAC,IAAI,CACrE,+BAA+B,EAC/B;QACE,IAAI,EAAE,YAAY,CAAC,EAAE;QACrB,KAAK,EAAE,CAAC;KACT,EACD,KAAK,EAAE,OAAO,EAAE,EAAE;
|
|
1
|
+
{"version":3,"file":"utils.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/account-syncing/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,qCAAqC;AAG5D,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,+BAA+B,EAChC,wBAAoB;AAGrB;;;;;;GAMG;AAEH,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,IAAY,EAAE,EAAE;IACvD,OAAO,+BAA+B,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;QACrD,OAAO,IAAI,MAAM,CAAC,IAAI,MAAM,YAAY,EAAE,GAAG,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,CAAC,MAAM,sCAAsC,GAAG,CACpD,eAAgC,EACZ,EAAE;IACtB,MAAM,EAAE,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,GAAG,eAAe,CAAC;IAClD,MAAM,EAAE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C,EAAE;QACrB,KAAK,EAAE,CAAC;KACT,EACD,KAAK,EAAE,EAAE,OAAO,EAAE,EAAE,EAAE;QACpB,OAAO,MAAM,OAAO,CAAC,WAAW,EAAE,CAAC;IACrC,CAAC,CACF,CAAa,CAAC;IAEf,OAAO,oCAAoC,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AACxE,CAAC","sourcesContent":["import { KeyringTypes } from '@metamask/keyring-controller';\nimport type { InternalAccount } from '@metamask/keyring-internal-api';\n\nimport {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n LOCALIZED_DEFAULT_ACCOUNT_NAMES,\n} from './constants';\nimport type { AccountSyncingOptions, UserStorageAccount } from './types';\n\n/**\n * Tells if the given name is a default account name.\n * Default account names are localized names that are automatically generated by the clients.\n *\n * @param name - the name to check\n * @returns true if the name is a default account name, false otherwise\n */\n\nexport const isNameDefaultAccountName = (name: string) => {\n return LOCALIZED_DEFAULT_ACCOUNT_NAMES.some((prefix) => {\n return new RegExp(`^${prefix} ([0-9]+)$`, 'u').test(name);\n });\n};\n\n/**\n * Map an internal account to a user storage account\n *\n * @param internalAccount - An internal account\n * @returns A user storage account\n */\nexport const mapInternalAccountToUserStorageAccount = (\n internalAccount: InternalAccount,\n): UserStorageAccount => {\n const { address, id, metadata } = internalAccount;\n const { name, nameLastUpdatedAt } = metadata;\n\n return {\n [USER_STORAGE_VERSION_KEY]: USER_STORAGE_VERSION,\n a: address,\n i: id,\n n: name,\n ...(isNameDefaultAccountName(name) ? {} : { nlu: nameLastUpdatedAt }),\n };\n};\n\n/**\n * Transforms a list of any internal accounts to a list of internal accounts that\n * have the correct keyring type and are from the primary SRP.\n *\n * @param internalAccountsList - The list of internal accounts\n * @param options - Parameters used for checking if the internal account is from the primary SRP\n * @returns Returns a list of internal accounts that have the correct keyring type and are from the primary SRP.\n */\nexport async function mapInternalAccountsListToPrimarySRPHdKeyringInternalAccountsList(\n internalAccountsList: InternalAccount[],\n options: AccountSyncingOptions,\n): Promise<InternalAccount[]> {\n const { getMessenger } = options;\n\n const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n type: KeyringTypes.hd,\n index: 0,\n },\n async ({ keyring }) => {\n return await keyring.getAccounts();\n },\n )) as string[];\n\n return internalAccountsList.filter((account) =>\n primarySRPHdKeyringAccountsAddresses?.includes(account.address),\n );\n}\n\n/**\n * Checks if the given internal account is from the primary SRP and is from the HD keyring.\n *\n * @param account - The internal account to check\n * @param options - Parameters used for checking if the internal account is from the primary SRP\n * @returns Returns true if the internal account is from the primary SRP, false otherwise.\n */\nexport async function isInternalAccountFromPrimarySRPHdKeyring(\n account: InternalAccount,\n options: AccountSyncingOptions,\n): Promise<boolean> {\n if (account.metadata.keyring.type !== KeyringTypes.hd) {\n return false;\n }\n\n const { getMessenger } = options;\n\n const primarySRPHdKeyringAccountsAddresses = (await getMessenger().call(\n 'KeyringController:withKeyring',\n {\n type: KeyringTypes.hd,\n index: 0,\n },\n async ({ keyring }) => {\n return await keyring.getAccounts();\n },\n )) as string[];\n\n return primarySRPHdKeyringAccountsAddresses.includes(account.address);\n}\n"]}
|
|
@@ -35,7 +35,7 @@ exports.Controller = UserStorageController_1.default;
|
|
|
35
35
|
const UserStorageController = UserStorageController_1.default;
|
|
36
36
|
exports.default = UserStorageController;
|
|
37
37
|
__exportStar(require("./UserStorageController.cjs"), exports);
|
|
38
|
-
exports.Mocks = __importStar(require("./
|
|
38
|
+
exports.Mocks = __importStar(require("./mocks/index.cjs"));
|
|
39
39
|
__exportStar(require("../../shared/encryption/index.cjs"), exports);
|
|
40
40
|
__exportStar(require("../../shared/storage-schema.cjs"), exports);
|
|
41
41
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wFAAiD;AAGxC,qBAHF,+BAAU,CAGE;AADnB,MAAM,qBAAqB,GAAG,+BAAU,CAAC;AAEzC,kBAAe,qBAAqB,CAAC;AACrC,8DAAwC;AACxC,
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,wFAAiD;AAGxC,qBAHF,+BAAU,CAGE;AADnB,MAAM,qBAAqB,GAAG,+BAAU,CAAC;AAEzC,kBAAe,qBAAqB,CAAC;AACrC,8DAAwC;AACxC,2DAAiC;AACjC,oEAAwC;AACxC,kEAA4C","sourcesContent":["import Controller from './UserStorageController';\n\nconst UserStorageController = Controller;\nexport { Controller };\nexport default UserStorageController;\nexport * from './UserStorageController';\nexport * as Mocks from './mocks';\nexport * from '../../shared/encryption';\nexport * from '../../shared/storage-schema';\n"]}
|
|
@@ -3,7 +3,7 @@ declare const UserStorageController: typeof Controller;
|
|
|
3
3
|
export { Controller };
|
|
4
4
|
export default UserStorageController;
|
|
5
5
|
export * from "./UserStorageController.cjs";
|
|
6
|
-
export * as Mocks from "./
|
|
6
|
+
export * as Mocks from "./mocks/index.cjs";
|
|
7
7
|
export * from "../../shared/encryption/index.cjs";
|
|
8
8
|
export * from "../../shared/storage-schema.cjs";
|
|
9
9
|
//# sourceMappingURL=index.d.cts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,oCAAgC;AAEjD,QAAA,MAAM,qBAAqB,mBAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,qBAAqB,CAAC;AACrC,4CAAwC;AACxC,OAAO,KAAK,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,oCAAgC;AAEjD,QAAA,MAAM,qBAAqB,mBAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,qBAAqB,CAAC;AACrC,4CAAwC;AACxC,OAAO,KAAK,KAAK,0BAAgB;AACjC,kDAAwC;AACxC,gDAA4C"}
|
|
@@ -3,7 +3,7 @@ declare const UserStorageController: typeof Controller;
|
|
|
3
3
|
export { Controller };
|
|
4
4
|
export default UserStorageController;
|
|
5
5
|
export * from "./UserStorageController.mjs";
|
|
6
|
-
export * as Mocks from "./
|
|
6
|
+
export * as Mocks from "./mocks/index.mjs";
|
|
7
7
|
export * from "../../shared/encryption/index.mjs";
|
|
8
8
|
export * from "../../shared/storage-schema.mjs";
|
|
9
9
|
//# sourceMappingURL=index.d.mts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,oCAAgC;AAEjD,QAAA,MAAM,qBAAqB,mBAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,qBAAqB,CAAC;AACrC,4CAAwC;AACxC,OAAO,KAAK,KAAK,
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,oCAAgC;AAEjD,QAAA,MAAM,qBAAqB,mBAAa,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,qBAAqB,CAAC;AACrC,4CAAwC;AACxC,OAAO,KAAK,KAAK,0BAAgB;AACjC,kDAAwC;AACxC,gDAA4C"}
|
|
@@ -3,7 +3,7 @@ const UserStorageController = Controller;
|
|
|
3
3
|
export { Controller };
|
|
4
4
|
export default UserStorageController;
|
|
5
5
|
export * from "./UserStorageController.mjs";
|
|
6
|
-
export * as Mocks from "./
|
|
6
|
+
export * as Mocks from "./mocks/index.mjs";
|
|
7
7
|
export * from "../../shared/encryption/index.mjs";
|
|
8
8
|
export * from "../../shared/storage-schema.mjs";
|
|
9
9
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,oCAAgC;AAEjD,MAAM,qBAAqB,GAAG,UAAU,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,qBAAqB,CAAC;AACrC,4CAAwC;AACxC,OAAO,KAAK,KAAK,
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../src/controllers/user-storage/index.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,oCAAgC;AAEjD,MAAM,qBAAqB,GAAG,UAAU,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,CAAC;AACtB,eAAe,qBAAqB,CAAC;AACrC,4CAAwC;AACxC,OAAO,KAAK,KAAK,0BAAgB;AACjC,kDAAwC;AACxC,gDAA4C","sourcesContent":["import Controller from './UserStorageController';\n\nconst UserStorageController = Controller;\nexport { Controller };\nexport default UserStorageController;\nexport * from './UserStorageController';\nexport * as Mocks from './mocks';\nexport * from '../../shared/encryption';\nexport * from '../../shared/storage-schema';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/mocks/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,sDAAgC;AAChC,oDAA8B","sourcesContent":["export * from './mockResponses';\nexport * from './mockStorage';\n"]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/mocks/index.ts"],"names":[],"mappings":"AAAA,oCAAgC;AAChC,kCAA8B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/mocks/index.ts"],"names":[],"mappings":"AAAA,oCAAgC;AAChC,kCAA8B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/mocks/index.ts"],"names":[],"mappings":"AAAA,oCAAgC;AAChC,kCAA8B","sourcesContent":["export * from './mockResponses';\nexport * from './mockStorage';\n"]}
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.deleteMockUserStorageAllFeatureEntriesResponse = exports.deleteMockUserStorageResponse = exports.getMockUserStorageBatchDeleteResponse = exports.getMockUserStorageBatchPutResponse = exports.getMockUserStoragePutResponse = exports.getMockUserStorageAllFeatureEntriesResponse = exports.getMockUserStorageGetResponse = exports.createMockAllFeatureEntriesResponse = exports.createMockGetStorageResponse = exports.getMockUserStorageEndpoint = void 0;
|
|
4
4
|
const mockStorage_1 = require("./mockStorage.cjs");
|
|
5
|
+
const sdk_1 = require("../../../sdk/index.cjs");
|
|
5
6
|
const storage_schema_1 = require("../../../shared/storage-schema.cjs");
|
|
6
|
-
const services_1 = require("../services.cjs");
|
|
7
7
|
const getMockUserStorageEndpoint = (path) => {
|
|
8
8
|
if (path.split('.').length === 1) {
|
|
9
|
-
return `${
|
|
9
|
+
return `${(0, sdk_1.getEnvUrls)(sdk_1.Env.PRD).userStorageApiUrl}/api/v1/userstorage/${path}`;
|
|
10
10
|
}
|
|
11
|
-
return `${
|
|
11
|
+
return `${(0, sdk_1.getEnvUrls)(sdk_1.Env.PRD).userStorageApiUrl}/api/v1/userstorage/${(0, storage_schema_1.createEntryPath)(path, mockStorage_1.MOCK_STORAGE_KEY)}`;
|
|
12
12
|
};
|
|
13
13
|
exports.getMockUserStorageEndpoint = getMockUserStorageEndpoint;
|
|
14
14
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockResponses.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/mocks/mockResponses.ts"],"names":[],"mappings":";;;AAAA,mDAIuB;AACvB,gDAA+C;AAK/C,uEAGwC;AAYjC,MAAM,0BAA0B,GAAG,CACxC,IAAuE,EACvE,EAAE;IACF,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;QAChC,OAAO,GAAG,IAAA,gBAAU,EAAC,SAAG,CAAC,GAAG,CAAC,CAAC,iBAAiB,uBAAuB,IAAI,EAAE,CAAC;KAC9E;IAED,OAAO,GAAG,IAAA,gBAAU,EAAC,SAAG,CAAC,GAAG,CAAC,CAAC,iBAAiB,uBAAuB,IAAA,gCAAe,EACnF,IAAwC,EACxC,8BAAgB,CACjB,EAAE,CAAC;AACN,CAAC,CAAC;AAXW,QAAA,0BAA0B,8BAWrC;AAEF;;;;;GAKG;AACI,KAAK,UAAU,4BAA4B,CAChD,IAAa;IAEb,OAAO;QACL,SAAS,EAAE,YAAY;QACvB,IAAI,EAAE,MAAM,IAAA,yCAA2B,EAAC,IAAI,CAAC;KAC9C,CAAC;AACJ,CAAC;AAPD,oEAOC;AAED;;;;;GAKG;AACI,KAAK,UAAU,mCAAmC,CACvD,UAAoB,CAAC,+BAAiB,CAAC;IAEvC,MAAM,aAAa,GAAG,EAAE,CAAC;IAEzB,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE;QAC1B,aAAa,CAAC,IAAI,CAAC;YACjB,SAAS,EAAE,YAAY;YACvB,IAAI,EAAE,MAAM,IAAA,yCAA2B,EAAC,IAAI,CAAC;SAC9C,CAAC,CAAC;KACJ;IAED,OAAO,aAAa,CAAC;AACvB,CAAC;AAbD,kFAaC;AAED;;;;;GAKG;AACI,KAAK,UAAU,6BAA6B,CACjD,OAAyC,GAAG,2CAA0B,CAAC,aAAa,wBAAwB;IAE5G,OAAO;QACL,GAAG,EAAE,IAAA,kCAA0B,EA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CAA0B,EAAC,IAAI,CAAC;QACrC,aAAa,EAAE,QAAQ;QACvB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AARW,QAAA,6BAA6B,iCAQxC;AAEK,MAAM,8CAA8C,GAAG,CAC5D,OAAuC,2CAA0B,CAAC,aAAa,EAC/E,EAAE;IACF,OAAO;QACL,GAAG,EAAE,IAAA,kCAA0B,EAAC,IAAI,CAAC;QACrC,aAAa,EAAE,QAAQ;QACvB,QAAQ,EAAE,IAAI;KACQ,CAAC;AAC3B,CAAC,CAAC;AARW,QAAA,8CAA8C,kDAQzD","sourcesContent":["import {\n MOCK_ENCRYPTED_STORAGE_DATA,\n MOCK_STORAGE_DATA,\n MOCK_STORAGE_KEY,\n} from './mockStorage';\nimport { Env, getEnvUrls } from '../../../sdk';\nimport type {\n UserStoragePathWithFeatureAndKey,\n UserStoragePathWithFeatureOnly,\n} from '../../../shared/storage-schema';\nimport {\n createEntryPath,\n USER_STORAGE_FEATURE_NAMES,\n} from '../../../shared/storage-schema';\nimport type {\n GetUserStorageAllFeatureEntriesResponse,\n GetUserStorageResponse,\n} from '../types';\n\ntype MockResponse = {\n url: string;\n requestMethod: 'GET' | 'POST' | 'PUT' | 'DELETE';\n response: unknown;\n};\n\nexport const getMockUserStorageEndpoint = (\n path: UserStoragePathWithFeatureAndKey | UserStoragePathWithFeatureOnly,\n) => {\n if (path.split('.').length === 1) {\n return `${getEnvUrls(Env.PRD).userStorageApiUrl}/api/v1/userstorage/${path}`;\n }\n\n return `${getEnvUrls(Env.PRD).userStorageApiUrl}/api/v1/userstorage/${createEntryPath(\n path as UserStoragePathWithFeatureAndKey,\n MOCK_STORAGE_KEY,\n )}`;\n};\n\n/**\n * Creates a mock GET user-storage response\n *\n * @param data - data to encrypt\n * @returns a realistic GET Response Body\n */\nexport async function createMockGetStorageResponse(\n data?: string,\n): Promise<GetUserStorageResponse> {\n return {\n HashedKey: 'HASHED_KEY',\n Data: await MOCK_ENCRYPTED_STORAGE_DATA(data),\n };\n}\n\n/**\n * Creates a mock GET ALL user-storage response\n *\n * @param dataArr - array of data to encrypt\n * @returns a realistic GET ALL Response Body\n */\nexport async function createMockAllFeatureEntriesResponse(\n dataArr: string[] = [MOCK_STORAGE_DATA],\n): Promise<GetUserStorageAllFeatureEntriesResponse> {\n const decryptedData = [];\n\n for (const data of dataArr) {\n decryptedData.push({\n HashedKey: 'HASHED_KEY',\n Data: await MOCK_ENCRYPTED_STORAGE_DATA(data),\n });\n }\n\n return decryptedData;\n}\n\n/**\n * Creates a mock user-storage api GET request\n *\n * @param path - path of the GET Url\n * @returns mock GET API request. Can be used by e2e or unit mock servers\n */\nexport async function getMockUserStorageGetResponse(\n path: UserStoragePathWithFeatureAndKey = `${USER_STORAGE_FEATURE_NAMES.notifications}.notification_settings`,\n) {\n return {\n url: getMockUserStorageEndpoint(path),\n requestMethod: 'GET',\n response: await createMockGetStorageResponse(),\n } satisfies MockResponse;\n}\n\n/**\n * Creates a mock user-storage api GET ALL request\n *\n * @param path - path of the GET url\n * @param dataArr - data to encrypt\n * @returns mock GET ALL API request. Can be used by e2e or unit mock servers\n */\nexport async function getMockUserStorageAllFeatureEntriesResponse(\n path: UserStoragePathWithFeatureOnly = USER_STORAGE_FEATURE_NAMES.notifications,\n dataArr?: string[],\n) {\n return {\n url: getMockUserStorageEndpoint(path),\n requestMethod: 'GET',\n response: await createMockAllFeatureEntriesResponse(dataArr),\n } satisfies MockResponse;\n}\n\nexport const getMockUserStoragePutResponse = (\n path: UserStoragePathWithFeatureAndKey = `${USER_STORAGE_FEATURE_NAMES.notifications}.notification_settings`,\n) => {\n return {\n url: getMockUserStorageEndpoint(path),\n requestMethod: 'PUT',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const getMockUserStorageBatchPutResponse = (\n path: UserStoragePathWithFeatureOnly = USER_STORAGE_FEATURE_NAMES.notifications,\n) => {\n return {\n url: getMockUserStorageEndpoint(path),\n requestMethod: 'PUT',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const getMockUserStorageBatchDeleteResponse = (\n path: UserStoragePathWithFeatureOnly = 'notifications',\n) => {\n return {\n url: getMockUserStorageEndpoint(path),\n requestMethod: 'PUT',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const deleteMockUserStorageResponse = (\n path: UserStoragePathWithFeatureAndKey = `${USER_STORAGE_FEATURE_NAMES.notifications}.notification_settings`,\n) => {\n return {\n url: getMockUserStorageEndpoint(path),\n requestMethod: 'DELETE',\n response: null,\n } satisfies MockResponse;\n};\n\nexport const deleteMockUserStorageAllFeatureEntriesResponse = (\n path: UserStoragePathWithFeatureOnly = USER_STORAGE_FEATURE_NAMES.notifications,\n) => {\n return {\n url: getMockUserStorageEndpoint(path),\n requestMethod: 'DELETE',\n response: null,\n } satisfies MockResponse;\n};\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UserStoragePathWithFeatureAndKey, UserStoragePathWithFeatureOnly } from "../../../shared/storage-schema.cjs";
|
|
2
|
-
import type { GetUserStorageAllFeatureEntriesResponse, GetUserStorageResponse } from "../
|
|
2
|
+
import type { GetUserStorageAllFeatureEntriesResponse, GetUserStorageResponse } from "../types.cjs";
|
|
3
3
|
export declare const getMockUserStorageEndpoint: (path: UserStoragePathWithFeatureAndKey | UserStoragePathWithFeatureOnly) => string;
|
|
4
4
|
/**
|
|
5
5
|
* Creates a mock GET user-storage response
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockResponses.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/mocks/mockResponses.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC/B,2CAAuC;AAKxC,OAAO,KAAK,EACV,uCAAuC,EACvC,sBAAsB,EACvB,qBAAiB;AAQlB,eAAO,MAAM,0BAA0B,SAC/B,gCAAgC,GAAG,8BAA8B,WAUxE,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,4BAA4B,CAChD,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,sBAAsB,CAAC,CAKjC;AAED;;;;;GAKG;AACH,wBAAsB,mCAAmC,CACvD,OAAO,GAAE,MAAM,EAAwB,GACtC,OAAO,CAAC,uCAAuC,CAAC,CAWlD;AAED;;;;;GAKG;AACH,wBAAsB,6BAA6B,CACjD,IAAI,GAAE,gCAAsG;;;;GAO7G;AAED;;;;;;GAMG;AACH,wBAAsB,2CAA2C,CAC/D,IAAI,GAAE,8BAAyE,EAC/E,OAAO,CAAC,EAAE,MAAM,EAAE;;;;GAOnB;AAED,eAAO,MAAM,6BAA6B,UAClC,gCAAgC;;;;CAOvC,CAAC;AAEF,eAAO,MAAM,kCAAkC,UACvC,8BAA8B;;;;CAOrC,CAAC;AAEF,eAAO,MAAM,qCAAqC,UAC1C,8BAA8B;;;;CAOrC,CAAC;AAEF,eAAO,MAAM,6BAA6B,UAClC,gCAAgC;;;;CAOvC,CAAC;AAEF,eAAO,MAAM,8CAA8C,UACnD,8BAA8B;;;;CAOrC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { UserStoragePathWithFeatureAndKey, UserStoragePathWithFeatureOnly } from "../../../shared/storage-schema.mjs";
|
|
2
|
-
import type { GetUserStorageAllFeatureEntriesResponse, GetUserStorageResponse } from "../
|
|
2
|
+
import type { GetUserStorageAllFeatureEntriesResponse, GetUserStorageResponse } from "../types.mjs";
|
|
3
3
|
export declare const getMockUserStorageEndpoint: (path: UserStoragePathWithFeatureAndKey | UserStoragePathWithFeatureOnly) => string;
|
|
4
4
|
/**
|
|
5
5
|
* Creates a mock GET user-storage response
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mockResponses.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/mocks/mockResponses.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACV,gCAAgC,EAChC,8BAA8B,EAC/B,2CAAuC;AAKxC,OAAO,KAAK,EACV,uCAAuC,EACvC,sBAAsB,EACvB,qBAAiB;AAQlB,eAAO,MAAM,0BAA0B,SAC/B,gCAAgC,GAAG,8BAA8B,WAUxE,CAAC;AAEF;;;;;GAKG;AACH,wBAAsB,4BAA4B,CAChD,IAAI,CAAC,EAAE,MAAM,GACZ,OAAO,CAAC,sBAAsB,CAAC,CAKjC;AAED;;;;;GAKG;AACH,wBAAsB,mCAAmC,CACvD,OAAO,GAAE,MAAM,EAAwB,GACtC,OAAO,CAAC,uCAAuC,CAAC,CAWlD;AAED;;;;;GAKG;AACH,wBAAsB,6BAA6B,CACjD,IAAI,GAAE,gCAAsG;;;;GAO7G;AAED;;;;;;GAMG;AACH,wBAAsB,2CAA2C,CAC/D,IAAI,GAAE,8BAAyE,EAC/E,OAAO,CAAC,EAAE,MAAM,EAAE;;;;GAOnB;AAED,eAAO,MAAM,6BAA6B,UAClC,gCAAgC;;;;CAOvC,CAAC;AAEF,eAAO,MAAM,kCAAkC,UACvC,8BAA8B;;;;CAOrC,CAAC;AAEF,eAAO,MAAM,qCAAqC,UAC1C,8BAA8B;;;;CAOrC,CAAC;AAEF,eAAO,MAAM,6BAA6B,UAClC,gCAAgC;;;;CAOvC,CAAC;AAEF,eAAO,MAAM,8CAA8C,UACnD,8BAA8B;;;;CAOrC,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { MOCK_ENCRYPTED_STORAGE_DATA, MOCK_STORAGE_DATA, MOCK_STORAGE_KEY } from "./mockStorage.mjs";
|
|
2
|
+
import { Env, getEnvUrls } from "../../../sdk/index.mjs";
|
|
2
3
|
import { createEntryPath, USER_STORAGE_FEATURE_NAMES } from "../../../shared/storage-schema.mjs";
|
|
3
|
-
import { USER_STORAGE_ENDPOINT } from "../services.mjs";
|
|
4
4
|
export const getMockUserStorageEndpoint = (path) => {
|
|
5
5
|
if (path.split('.').length === 1) {
|
|
6
|
-
return `${
|
|
6
|
+
return `${getEnvUrls(Env.PRD).userStorageApiUrl}/api/v1/userstorage/${path}`;
|
|
7
7
|
}
|
|
8
|
-
return `${
|
|
8
|
+
return `${getEnvUrls(Env.PRD).userStorageApiUrl}/api/v1/userstorage/${createEntryPath(path, MOCK_STORAGE_KEY)}`;
|
|
9
9
|
};
|
|
10
10
|
/**
|
|
11
11
|
* Creates a mock GET user-storage response
|