@metamask-previews/profile-sync-controller 29.0.0-preview-3866c0ff1 → 29.0.0-preview-e3275932a
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +0 -1
- package/dist/controllers/authentication/AuthenticationController-method-action-types.cjs +7 -0
- package/dist/controllers/authentication/AuthenticationController-method-action-types.cjs.map +1 -0
- package/dist/controllers/authentication/{AuthenticationController-method-action-types.d.ts → AuthenticationController-method-action-types.d.cts} +2 -2
- package/dist/controllers/authentication/AuthenticationController-method-action-types.d.cts.map +1 -0
- package/dist/controllers/authentication/AuthenticationController-method-action-types.d.mts +102 -0
- package/dist/controllers/authentication/AuthenticationController-method-action-types.d.mts.map +1 -0
- package/dist/controllers/authentication/{AuthenticationController-method-action-types.js → AuthenticationController-method-action-types.mjs} +1 -1
- package/dist/controllers/authentication/AuthenticationController-method-action-types.mjs.map +1 -0
- package/dist/controllers/authentication/AuthenticationController.cjs +489 -0
- package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -0
- package/dist/controllers/authentication/{AuthenticationController.d.ts → AuthenticationController.d.cts} +10 -10
- package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -0
- package/dist/controllers/authentication/AuthenticationController.d.mts +130 -0
- package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -0
- package/dist/controllers/authentication/AuthenticationController.mjs +485 -0
- package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -0
- package/dist/controllers/authentication/index.cjs +35 -0
- package/dist/controllers/authentication/index.cjs.map +1 -0
- package/dist/controllers/authentication/{index.d.ts → index.d.cts} +5 -5
- package/dist/controllers/authentication/index.d.cts.map +1 -0
- package/dist/controllers/authentication/index.d.mts +7 -0
- package/dist/controllers/authentication/index.d.mts.map +1 -0
- package/dist/controllers/authentication/index.mjs +6 -0
- package/dist/controllers/authentication/index.mjs.map +1 -0
- package/dist/controllers/authentication/mocks/index.cjs +18 -0
- package/dist/controllers/authentication/mocks/index.cjs.map +1 -0
- package/dist/controllers/authentication/mocks/index.d.cts +2 -0
- package/dist/controllers/authentication/mocks/index.d.cts.map +1 -0
- package/dist/controllers/authentication/mocks/index.d.mts +2 -0
- package/dist/controllers/authentication/mocks/index.d.mts.map +1 -0
- package/dist/controllers/authentication/mocks/index.mjs +2 -0
- package/dist/controllers/authentication/mocks/index.mjs.map +1 -0
- package/dist/controllers/authentication/mocks/mockResponses.cjs +126 -0
- package/dist/controllers/authentication/mocks/mockResponses.cjs.map +1 -0
- package/dist/controllers/authentication/mocks/{mockResponses.d.ts → mockResponses.d.cts} +1 -1
- package/dist/controllers/authentication/mocks/mockResponses.d.cts.map +1 -0
- package/dist/controllers/authentication/mocks/mockResponses.d.mts +58 -0
- package/dist/controllers/authentication/mocks/mockResponses.d.mts.map +1 -0
- package/dist/controllers/authentication/mocks/{mockResponses.js → mockResponses.mjs} +2 -2
- package/dist/controllers/authentication/mocks/mockResponses.mjs.map +1 -0
- package/dist/controllers/index.cjs +29 -0
- package/dist/controllers/index.cjs.map +1 -0
- package/dist/controllers/index.d.cts +3 -0
- package/dist/controllers/index.d.cts.map +1 -0
- package/dist/controllers/index.d.mts +3 -0
- package/dist/controllers/index.d.mts.map +1 -0
- package/dist/controllers/index.mjs +3 -0
- package/dist/controllers/index.mjs.map +1 -0
- package/dist/controllers/user-storage/UserStorageController-method-action-types.cjs +7 -0
- package/dist/controllers/user-storage/UserStorageController-method-action-types.cjs.map +1 -0
- package/dist/controllers/user-storage/{UserStorageController-method-action-types.d.ts → UserStorageController-method-action-types.d.cts} +2 -2
- package/dist/controllers/user-storage/UserStorageController-method-action-types.d.cts.map +1 -0
- package/dist/controllers/user-storage/UserStorageController-method-action-types.d.mts +137 -0
- package/dist/controllers/user-storage/UserStorageController-method-action-types.d.mts.map +1 -0
- package/dist/controllers/user-storage/{UserStorageController-method-action-types.js → UserStorageController-method-action-types.mjs} +1 -1
- package/dist/controllers/user-storage/UserStorageController-method-action-types.mjs.map +1 -0
- package/dist/controllers/user-storage/UserStorageController.cjs +412 -0
- package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -0
- package/dist/controllers/user-storage/{UserStorageController.d.ts → UserStorageController.d.cts} +14 -14
- package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -0
- package/dist/controllers/user-storage/UserStorageController.d.mts +182 -0
- package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -0
- package/dist/controllers/user-storage/UserStorageController.mjs +408 -0
- package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -0
- package/dist/controllers/user-storage/constants.cjs +19 -0
- package/dist/controllers/user-storage/constants.cjs.map +1 -0
- package/dist/controllers/user-storage/constants.d.cts +15 -0
- package/dist/controllers/user-storage/constants.d.cts.map +1 -0
- package/dist/controllers/user-storage/constants.d.mts +15 -0
- package/dist/controllers/user-storage/constants.d.mts.map +1 -0
- package/dist/controllers/user-storage/{constants.js → constants.mjs} +1 -1
- package/dist/controllers/user-storage/constants.mjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/constants.cjs +12 -0
- package/dist/controllers/user-storage/contact-syncing/constants.cjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{constants.d.ts → constants.d.cts} +1 -1
- package/dist/controllers/user-storage/contact-syncing/constants.d.cts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/constants.d.mts +9 -0
- package/dist/controllers/user-storage/contact-syncing/constants.d.mts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{constants.js → constants.mjs} +1 -1
- package/dist/controllers/user-storage/contact-syncing/constants.mjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs +346 -0
- package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{controller-integration.d.ts → controller-integration.d.cts} +3 -3
- package/dist/controllers/user-storage/contact-syncing/controller-integration.d.cts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts +47 -0
- package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{controller-integration.js → controller-integration.mjs} +6 -6
- package/dist/controllers/user-storage/contact-syncing/controller-integration.mjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.cjs +50 -0
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.cjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{setup-subscriptions.d.ts → setup-subscriptions.d.cts} +2 -2
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.cts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.mts +8 -0
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.mts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{setup-subscriptions.js → setup-subscriptions.mjs} +4 -4
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.mjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/sync-utils.cjs +23 -0
- package/dist/controllers/user-storage/contact-syncing/sync-utils.cjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{sync-utils.d.ts → sync-utils.d.cts} +2 -2
- package/dist/controllers/user-storage/contact-syncing/sync-utils.d.cts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/sync-utils.d.mts +9 -0
- package/dist/controllers/user-storage/contact-syncing/sync-utils.d.mts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{sync-utils.js → sync-utils.mjs} +1 -1
- package/dist/controllers/user-storage/contact-syncing/sync-utils.mjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/types.cjs +3 -0
- package/dist/controllers/user-storage/contact-syncing/types.cjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{types.d.ts → types.d.cts} +6 -6
- package/dist/controllers/user-storage/contact-syncing/types.d.cts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/types.d.mts +37 -0
- package/dist/controllers/user-storage/contact-syncing/types.d.mts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/types.mjs +2 -0
- package/dist/controllers/user-storage/contact-syncing/types.mjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/utils.cjs +64 -0
- package/dist/controllers/user-storage/contact-syncing/utils.cjs.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{utils.d.ts → utils.d.cts} +3 -3
- package/dist/controllers/user-storage/contact-syncing/utils.d.cts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/utils.d.mts +36 -0
- package/dist/controllers/user-storage/contact-syncing/utils.d.mts.map +1 -0
- package/dist/controllers/user-storage/contact-syncing/{utils.js → utils.mjs} +2 -2
- package/dist/controllers/user-storage/contact-syncing/utils.mjs.map +1 -0
- package/dist/controllers/user-storage/index.cjs +38 -0
- package/dist/controllers/user-storage/index.cjs.map +1 -0
- package/dist/controllers/user-storage/{index.d.ts → index.d.cts} +8 -8
- package/dist/controllers/user-storage/index.d.cts.map +1 -0
- package/dist/controllers/user-storage/index.d.mts +10 -0
- package/dist/controllers/user-storage/index.d.mts.map +1 -0
- package/dist/controllers/user-storage/index.mjs +9 -0
- package/dist/controllers/user-storage/index.mjs.map +1 -0
- package/dist/controllers/user-storage/mocks/index.cjs +19 -0
- package/dist/controllers/user-storage/mocks/index.cjs.map +1 -0
- package/dist/controllers/user-storage/mocks/index.d.cts +3 -0
- package/dist/controllers/user-storage/mocks/index.d.cts.map +1 -0
- package/dist/controllers/user-storage/mocks/index.d.mts +3 -0
- package/dist/controllers/user-storage/mocks/index.d.mts.map +1 -0
- package/dist/controllers/user-storage/mocks/index.mjs +3 -0
- package/dist/controllers/user-storage/mocks/index.mjs.map +1 -0
- package/dist/controllers/user-storage/mocks/mockResponses.cjs +113 -0
- package/dist/controllers/user-storage/mocks/mockResponses.cjs.map +1 -0
- package/dist/controllers/user-storage/mocks/{mockResponses.d.ts → mockResponses.d.cts} +3 -3
- package/dist/controllers/user-storage/mocks/mockResponses.d.cts.map +1 -0
- package/dist/controllers/user-storage/mocks/mockResponses.d.mts +66 -0
- package/dist/controllers/user-storage/mocks/mockResponses.d.mts.map +1 -0
- package/dist/controllers/user-storage/mocks/{mockResponses.js → mockResponses.mjs} +4 -4
- package/dist/controllers/user-storage/mocks/mockResponses.mjs.map +1 -0
- package/dist/controllers/user-storage/mocks/mockStorage.cjs +36 -0
- package/dist/controllers/user-storage/mocks/mockStorage.cjs.map +1 -0
- package/dist/controllers/user-storage/mocks/{mockStorage.d.ts → mockStorage.d.cts} +1 -1
- package/dist/controllers/user-storage/mocks/mockStorage.d.cts.map +1 -0
- package/dist/controllers/user-storage/mocks/mockStorage.d.mts +5 -0
- package/dist/controllers/user-storage/mocks/mockStorage.d.mts.map +1 -0
- package/dist/controllers/user-storage/mocks/{mockStorage.js → mockStorage.mjs} +3 -3
- package/dist/controllers/user-storage/mocks/mockStorage.mjs.map +1 -0
- 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.ts → types.d.cts} +3 -3
- 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/controllers/user-storage/utils.cjs +32 -0
- package/dist/controllers/user-storage/utils.cjs.map +1 -0
- package/dist/controllers/user-storage/{utils.d.ts → utils.d.cts} +1 -1
- package/dist/controllers/user-storage/utils.d.cts.map +1 -0
- package/dist/controllers/user-storage/utils.d.mts +19 -0
- package/dist/controllers/user-storage/utils.d.mts.map +1 -0
- package/dist/controllers/user-storage/{utils.js → utils.mjs} +1 -1
- package/dist/controllers/user-storage/utils.mjs.map +1 -0
- package/dist/index.cjs +30 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +4 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +4 -0
- package/dist/index.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs +114 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/{flow-siwe.d.ts → flow-siwe.d.cts} +2 -2
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts +25 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +110 -0
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +290 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/{flow-srp.d.ts → flow-srp.d.cts} +5 -5
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +44 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +263 -0
- package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/services.cjs +400 -0
- package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/{services.d.ts → services.d.cts} +5 -5
- package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/services.d.mts +105 -0
- package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/{services.js → services.mjs} +6 -6
- package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/types.cjs +12 -0
- package/dist/sdk/authentication-jwt-bearer/types.cjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/{types.d.ts → types.d.cts} +2 -2
- package/dist/sdk/authentication-jwt-bearer/types.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/types.d.mts +114 -0
- package/dist/sdk/authentication-jwt-bearer/types.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/{types.js → types.mjs} +1 -1
- package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.cjs +27 -0
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.cjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/{identifier.d.ts → identifier.d.cts} +2 -2
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.mts +13 -0
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/{identifier.js → identifier.mjs} +2 -2
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.mjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/time.cjs +17 -0
- package/dist/sdk/authentication-jwt-bearer/utils/time.cjs.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/{time.d.ts → time.d.cts} +1 -1
- package/dist/sdk/authentication-jwt-bearer/utils/time.d.cts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/time.d.mts +8 -0
- package/dist/sdk/authentication-jwt-bearer/utils/time.d.mts.map +1 -0
- package/dist/sdk/authentication-jwt-bearer/utils/{time.js → time.mjs} +1 -1
- package/dist/sdk/authentication-jwt-bearer/utils/time.mjs.map +1 -0
- package/dist/sdk/authentication.cjs +132 -0
- package/dist/sdk/authentication.cjs.map +1 -0
- package/dist/sdk/{authentication.d.ts → authentication.d.cts} +9 -9
- package/dist/sdk/authentication.d.cts.map +1 -0
- package/dist/sdk/authentication.d.mts +38 -0
- package/dist/sdk/authentication.d.mts.map +1 -0
- package/dist/sdk/authentication.mjs +112 -0
- package/dist/sdk/authentication.mjs.map +1 -0
- package/dist/sdk/constants.cjs +7 -0
- package/dist/sdk/constants.cjs.map +1 -0
- package/dist/sdk/{constants.d.ts → constants.d.cts} +1 -1
- package/dist/sdk/constants.d.cts.map +1 -0
- package/dist/sdk/constants.d.mts +4 -0
- package/dist/sdk/constants.d.mts.map +1 -0
- package/dist/sdk/{constants.js → constants.mjs} +1 -1
- package/dist/sdk/constants.mjs.map +1 -0
- package/dist/sdk/errors.cjs +76 -0
- package/dist/sdk/errors.cjs.map +1 -0
- package/dist/sdk/{errors.d.ts → errors.d.cts} +1 -1
- package/dist/sdk/errors.d.cts.map +1 -0
- package/dist/sdk/errors.d.mts +34 -0
- package/dist/sdk/errors.d.mts.map +1 -0
- package/dist/sdk/{errors.js → errors.mjs} +3 -4
- package/dist/sdk/errors.mjs.map +1 -0
- package/dist/sdk/index.cjs +24 -0
- package/dist/sdk/index.cjs.map +1 -0
- package/dist/sdk/index.d.cts +8 -0
- package/dist/sdk/index.d.cts.map +1 -0
- package/dist/sdk/index.d.mts +8 -0
- package/dist/sdk/index.d.mts.map +1 -0
- package/dist/sdk/index.mjs +8 -0
- package/dist/sdk/index.mjs.map +1 -0
- package/dist/sdk/mocks/auth.cjs +82 -0
- package/dist/sdk/mocks/auth.cjs.map +1 -0
- package/dist/sdk/mocks/{auth.d.ts → auth.d.cts} +2 -2
- package/dist/sdk/mocks/auth.d.cts.map +1 -0
- package/dist/sdk/mocks/auth.d.mts +69 -0
- package/dist/sdk/mocks/auth.d.mts.map +1 -0
- package/dist/sdk/mocks/{auth.js → auth.mjs} +3 -3
- 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.ts → userstorage.d.cts} +1 -1
- 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.js → userstorage.mjs} +5 -5
- package/dist/sdk/mocks/userstorage.mjs.map +1 -0
- package/dist/sdk/user-storage.cjs +386 -0
- package/dist/sdk/user-storage.cjs.map +1 -0
- package/dist/sdk/{user-storage.d.ts → user-storage.d.cts} +5 -5
- package/dist/sdk/user-storage.d.cts.map +1 -0
- package/dist/sdk/user-storage.d.mts +47 -0
- package/dist/sdk/user-storage.d.mts.map +1 -0
- package/dist/sdk/user-storage.mjs +358 -0
- package/dist/sdk/user-storage.mjs.map +1 -0
- package/dist/sdk/utils/eip-6963-metamask-provider.cjs +70 -0
- package/dist/sdk/utils/eip-6963-metamask-provider.cjs.map +1 -0
- package/dist/sdk/utils/{eip-6963-metamask-provider.d.ts → eip-6963-metamask-provider.d.cts} +2 -2
- package/dist/sdk/utils/eip-6963-metamask-provider.d.cts.map +1 -0
- package/dist/sdk/utils/eip-6963-metamask-provider.d.mts +25 -0
- package/dist/sdk/utils/eip-6963-metamask-provider.d.mts.map +1 -0
- package/dist/sdk/utils/{eip-6963-metamask-provider.js → eip-6963-metamask-provider.mjs} +1 -1
- package/dist/sdk/utils/eip-6963-metamask-provider.mjs.map +1 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs +96 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.cjs.map +1 -0
- package/dist/sdk/utils/{messaging-signing-snap-requests.d.ts → messaging-signing-snap-requests.d.cts} +2 -2
- package/dist/sdk/utils/messaging-signing-snap-requests.d.cts.map +1 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts +41 -0
- package/dist/sdk/utils/messaging-signing-snap-requests.d.mts.map +1 -0
- package/dist/sdk/utils/{messaging-signing-snap-requests.js → messaging-signing-snap-requests.mjs} +1 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.mjs.map +1 -0
- package/dist/sdk/utils/validate-login-response.cjs +49 -0
- package/dist/sdk/utils/validate-login-response.cjs.map +1 -0
- package/dist/sdk/utils/{validate-login-response.d.ts → validate-login-response.d.cts} +2 -2
- package/dist/sdk/utils/validate-login-response.d.cts.map +1 -0
- package/dist/sdk/utils/validate-login-response.d.mts +14 -0
- package/dist/sdk/utils/validate-login-response.d.mts.map +1 -0
- package/dist/sdk/utils/{validate-login-response.js → validate-login-response.mjs} +1 -1
- package/dist/sdk/utils/validate-login-response.mjs.map +1 -0
- package/dist/sdk/utils/validate-pair-response.cjs +29 -0
- package/dist/sdk/utils/validate-pair-response.cjs.map +1 -0
- package/dist/sdk/utils/{validate-pair-response.d.ts → validate-pair-response.d.cts} +1 -1
- package/dist/sdk/utils/validate-pair-response.d.cts.map +1 -0
- package/dist/sdk/utils/validate-pair-response.d.mts +26 -0
- package/dist/sdk/utils/validate-pair-response.d.mts.map +1 -0
- package/dist/sdk/utils/{validate-pair-response.js → validate-pair-response.mjs} +1 -1
- package/dist/sdk/utils/validate-pair-response.mjs.map +1 -0
- package/dist/shared/encryption/cache.cjs +77 -0
- package/dist/shared/encryption/cache.cjs.map +1 -0
- package/dist/shared/encryption/{cache.d.ts → cache.d.cts} +1 -1
- package/dist/shared/encryption/cache.d.cts.map +1 -0
- package/dist/shared/encryption/cache.d.mts +32 -0
- package/dist/shared/encryption/cache.d.mts.map +1 -0
- package/dist/shared/encryption/{cache.js → cache.mjs} +4 -4
- package/dist/shared/encryption/cache.mjs.map +1 -0
- package/dist/shared/encryption/constants.cjs +17 -0
- package/dist/shared/encryption/constants.cjs.map +1 -0
- package/dist/shared/encryption/{constants.d.ts → constants.d.cts} +2 -2
- package/dist/shared/encryption/constants.d.cts.map +1 -0
- package/dist/shared/encryption/constants.d.mts +9 -0
- package/dist/shared/encryption/constants.d.mts.map +1 -0
- package/dist/shared/encryption/{constants.js → constants.mjs} +1 -1
- package/dist/shared/encryption/constants.mjs.map +1 -0
- package/dist/shared/encryption/encryption.cjs +209 -0
- package/dist/shared/encryption/encryption.cjs.map +1 -0
- package/dist/shared/encryption/{encryption.d.ts → encryption.d.cts} +3 -3
- package/dist/shared/encryption/encryption.d.cts.map +1 -0
- package/dist/shared/encryption/encryption.d.mts +30 -0
- package/dist/shared/encryption/encryption.d.mts.map +1 -0
- package/dist/shared/encryption/encryption.mjs +205 -0
- package/dist/shared/encryption/encryption.mjs.map +1 -0
- package/dist/shared/encryption/index.cjs +25 -0
- package/dist/shared/encryption/index.cjs.map +1 -0
- package/dist/shared/encryption/index.d.cts +5 -0
- package/dist/shared/encryption/index.d.cts.map +1 -0
- package/dist/shared/encryption/index.d.mts +5 -0
- package/dist/shared/encryption/index.d.mts.map +1 -0
- package/dist/shared/encryption/index.mjs +5 -0
- package/dist/shared/encryption/index.mjs.map +1 -0
- package/dist/shared/encryption/utils.cjs +21 -0
- package/dist/shared/encryption/utils.cjs.map +1 -0
- package/dist/shared/encryption/{utils.d.ts → utils.d.cts} +3 -3
- package/dist/shared/encryption/utils.d.cts.map +1 -0
- package/dist/shared/encryption/utils.d.mts +5 -0
- package/dist/shared/encryption/utils.d.mts.map +1 -0
- package/dist/shared/encryption/{utils.js → utils.mjs} +1 -1
- package/dist/shared/encryption/utils.mjs.map +1 -0
- package/dist/shared/env.cjs +85 -0
- package/dist/shared/env.cjs.map +1 -0
- package/dist/shared/{env.d.ts → env.d.cts} +1 -1
- package/dist/shared/env.d.cts.map +1 -0
- package/dist/shared/env.d.mts +34 -0
- package/dist/shared/env.d.mts.map +1 -0
- package/dist/shared/{env.js → env.mjs} +1 -1
- package/dist/shared/env.mjs.map +1 -0
- package/dist/shared/storage-schema.cjs +42 -0
- package/dist/shared/storage-schema.cjs.map +1 -0
- package/dist/shared/{storage-schema.d.ts → storage-schema.d.cts} +1 -1
- package/dist/shared/storage-schema.d.cts.map +1 -0
- package/dist/shared/storage-schema.d.mts +34 -0
- package/dist/shared/storage-schema.d.mts.map +1 -0
- package/dist/shared/{storage-schema.js → storage-schema.mjs} +2 -2
- package/dist/shared/storage-schema.mjs.map +1 -0
- package/dist/shared/types/encryption.cjs +3 -0
- package/dist/shared/types/encryption.cjs.map +1 -0
- package/dist/shared/types/{encryption.d.ts → encryption.d.cts} +1 -1
- package/dist/shared/types/encryption.d.cts.map +1 -0
- package/dist/shared/types/encryption.d.mts +2 -0
- package/dist/shared/types/encryption.d.mts.map +1 -0
- package/dist/shared/types/encryption.mjs +2 -0
- package/dist/shared/types/encryption.mjs.map +1 -0
- package/dist/shared/types/services.cjs +3 -0
- package/dist/shared/types/services.cjs.map +1 -0
- package/dist/shared/types/{services.d.ts → services.d.cts} +2 -2
- package/dist/shared/types/services.d.cts.map +1 -0
- package/dist/shared/types/services.d.mts +17 -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/dist/shared/utils/entropy-source.cjs +37 -0
- package/dist/shared/utils/entropy-source.cjs.map +1 -0
- package/dist/shared/utils/{entropy-source.d.ts → entropy-source.d.cts} +2 -2
- package/dist/shared/utils/entropy-source.d.cts.map +1 -0
- package/dist/shared/utils/entropy-source.d.mts +22 -0
- package/dist/shared/utils/entropy-source.d.mts.map +1 -0
- package/dist/shared/utils/{entropy-source.js → entropy-source.mjs} +2 -2
- package/dist/shared/utils/entropy-source.mjs.map +1 -0
- package/dist/shared/utils/event-queue.cjs +24 -0
- package/dist/shared/utils/event-queue.cjs.map +1 -0
- package/dist/shared/utils/{event-queue.d.ts → event-queue.d.cts} +1 -1
- package/dist/shared/utils/event-queue.d.cts.map +1 -0
- package/dist/shared/utils/event-queue.d.mts +6 -0
- package/dist/shared/utils/event-queue.d.mts.map +1 -0
- package/dist/shared/utils/{event-queue.js → event-queue.mjs} +4 -2
- package/dist/shared/utils/event-queue.mjs.map +1 -0
- package/dist/shared/utils/hd-keyring-seed.cjs +49 -0
- package/dist/shared/utils/hd-keyring-seed.cjs.map +1 -0
- package/dist/shared/utils/{hd-keyring-seed.d.ts → hd-keyring-seed.d.cts} +3 -3
- package/dist/shared/utils/hd-keyring-seed.d.cts.map +1 -0
- package/dist/shared/utils/hd-keyring-seed.d.mts +27 -0
- package/dist/shared/utils/hd-keyring-seed.d.mts.map +1 -0
- package/dist/shared/utils/{hd-keyring-seed.js → hd-keyring-seed.mjs} +1 -1
- package/dist/shared/utils/hd-keyring-seed.mjs.map +1 -0
- package/dist/shared/utils/message-signing.cjs +147 -0
- package/dist/shared/utils/message-signing.cjs.map +1 -0
- package/dist/shared/utils/{message-signing.d.ts → message-signing.d.cts} +1 -1
- package/dist/shared/utils/message-signing.d.cts.map +1 -0
- package/dist/shared/utils/message-signing.d.mts +73 -0
- package/dist/shared/utils/message-signing.d.mts.map +1 -0
- package/dist/shared/utils/{message-signing.js → message-signing.mjs} +7 -7
- package/dist/shared/utils/message-signing.mjs.map +1 -0
- package/package.json +56 -22
- package/dist/controllers/authentication/AuthenticationController-method-action-types.d.ts.map +0 -1
- package/dist/controllers/authentication/AuthenticationController-method-action-types.js.map +0 -1
- package/dist/controllers/authentication/AuthenticationController.d.ts.map +0 -1
- package/dist/controllers/authentication/AuthenticationController.js +0 -536
- package/dist/controllers/authentication/AuthenticationController.js.map +0 -1
- package/dist/controllers/authentication/index.d.ts.map +0 -1
- package/dist/controllers/authentication/index.js +0 -6
- package/dist/controllers/authentication/index.js.map +0 -1
- package/dist/controllers/authentication/mocks/index.d.ts +0 -2
- package/dist/controllers/authentication/mocks/index.d.ts.map +0 -1
- package/dist/controllers/authentication/mocks/index.js +0 -2
- package/dist/controllers/authentication/mocks/index.js.map +0 -1
- package/dist/controllers/authentication/mocks/mockResponses.d.ts.map +0 -1
- package/dist/controllers/authentication/mocks/mockResponses.js.map +0 -1
- package/dist/controllers/index.d.ts +0 -3
- package/dist/controllers/index.d.ts.map +0 -1
- package/dist/controllers/index.js +0 -3
- package/dist/controllers/index.js.map +0 -1
- package/dist/controllers/user-storage/UserStorageController-method-action-types.d.ts.map +0 -1
- package/dist/controllers/user-storage/UserStorageController-method-action-types.js.map +0 -1
- package/dist/controllers/user-storage/UserStorageController.d.ts.map +0 -1
- package/dist/controllers/user-storage/UserStorageController.js +0 -429
- package/dist/controllers/user-storage/UserStorageController.js.map +0 -1
- package/dist/controllers/user-storage/constants.d.ts +0 -15
- package/dist/controllers/user-storage/constants.d.ts.map +0 -1
- package/dist/controllers/user-storage/constants.js.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/constants.d.ts.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/constants.js.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/controller-integration.d.ts.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/controller-integration.js.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.d.ts.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/setup-subscriptions.js.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/sync-utils.d.ts.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/sync-utils.js.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/types.d.ts.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/types.js +0 -2
- package/dist/controllers/user-storage/contact-syncing/types.js.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/utils.d.ts.map +0 -1
- package/dist/controllers/user-storage/contact-syncing/utils.js.map +0 -1
- package/dist/controllers/user-storage/index.d.ts.map +0 -1
- package/dist/controllers/user-storage/index.js +0 -9
- package/dist/controllers/user-storage/index.js.map +0 -1
- package/dist/controllers/user-storage/mocks/index.d.ts +0 -3
- package/dist/controllers/user-storage/mocks/index.d.ts.map +0 -1
- package/dist/controllers/user-storage/mocks/index.js +0 -3
- package/dist/controllers/user-storage/mocks/index.js.map +0 -1
- package/dist/controllers/user-storage/mocks/mockResponses.d.ts.map +0 -1
- package/dist/controllers/user-storage/mocks/mockResponses.js.map +0 -1
- package/dist/controllers/user-storage/mocks/mockStorage.d.ts.map +0 -1
- package/dist/controllers/user-storage/mocks/mockStorage.js.map +0 -1
- package/dist/controllers/user-storage/types.d.ts.map +0 -1
- package/dist/controllers/user-storage/types.js +0 -2
- package/dist/controllers/user-storage/types.js.map +0 -1
- package/dist/controllers/user-storage/utils.d.ts.map +0 -1
- package/dist/controllers/user-storage/utils.js.map +0 -1
- package/dist/index.d.ts +0 -4
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -4
- package/dist/index.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.ts.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.js +0 -99
- package/dist/sdk/authentication-jwt-bearer/flow-siwe.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.d.ts.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/flow-srp.js +0 -255
- package/dist/sdk/authentication-jwt-bearer/flow-srp.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/services.d.ts.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/services.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/types.d.ts.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/types.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.d.ts.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/utils/identifier.js.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/utils/time.d.ts.map +0 -1
- package/dist/sdk/authentication-jwt-bearer/utils/time.js.map +0 -1
- package/dist/sdk/authentication.d.ts.map +0 -1
- package/dist/sdk/authentication.js +0 -100
- package/dist/sdk/authentication.js.map +0 -1
- package/dist/sdk/constants.d.ts.map +0 -1
- package/dist/sdk/constants.js.map +0 -1
- package/dist/sdk/errors.d.ts.map +0 -1
- package/dist/sdk/errors.js.map +0 -1
- package/dist/sdk/index.d.ts +0 -8
- package/dist/sdk/index.d.ts.map +0 -1
- package/dist/sdk/index.js +0 -8
- package/dist/sdk/index.js.map +0 -1
- package/dist/sdk/mocks/auth.d.ts.map +0 -1
- package/dist/sdk/mocks/auth.js.map +0 -1
- package/dist/sdk/mocks/userstorage.d.ts.map +0 -1
- package/dist/sdk/mocks/userstorage.js.map +0 -1
- package/dist/sdk/user-storage.d.ts.map +0 -1
- package/dist/sdk/user-storage.js +0 -364
- package/dist/sdk/user-storage.js.map +0 -1
- package/dist/sdk/utils/eip-6963-metamask-provider.d.ts.map +0 -1
- package/dist/sdk/utils/eip-6963-metamask-provider.js.map +0 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.d.ts.map +0 -1
- package/dist/sdk/utils/messaging-signing-snap-requests.js.map +0 -1
- package/dist/sdk/utils/validate-login-response.d.ts.map +0 -1
- package/dist/sdk/utils/validate-login-response.js.map +0 -1
- package/dist/sdk/utils/validate-pair-response.d.ts.map +0 -1
- package/dist/sdk/utils/validate-pair-response.js.map +0 -1
- package/dist/shared/encryption/cache.d.ts.map +0 -1
- package/dist/shared/encryption/cache.js.map +0 -1
- package/dist/shared/encryption/constants.d.ts.map +0 -1
- package/dist/shared/encryption/constants.js.map +0 -1
- package/dist/shared/encryption/encryption.d.ts.map +0 -1
- package/dist/shared/encryption/encryption.js +0 -202
- package/dist/shared/encryption/encryption.js.map +0 -1
- package/dist/shared/encryption/index.d.ts +0 -5
- package/dist/shared/encryption/index.d.ts.map +0 -1
- package/dist/shared/encryption/index.js +0 -5
- package/dist/shared/encryption/index.js.map +0 -1
- package/dist/shared/encryption/utils.d.ts.map +0 -1
- package/dist/shared/encryption/utils.js.map +0 -1
- package/dist/shared/env.d.ts.map +0 -1
- package/dist/shared/env.js.map +0 -1
- package/dist/shared/storage-schema.d.ts.map +0 -1
- package/dist/shared/storage-schema.js.map +0 -1
- package/dist/shared/types/encryption.d.ts.map +0 -1
- package/dist/shared/types/encryption.js +0 -2
- package/dist/shared/types/encryption.js.map +0 -1
- package/dist/shared/types/services.d.ts.map +0 -1
- package/dist/shared/types/services.js +0 -2
- package/dist/shared/types/services.js.map +0 -1
- package/dist/shared/utils/entropy-source.d.ts.map +0 -1
- package/dist/shared/utils/entropy-source.js.map +0 -1
- package/dist/shared/utils/event-queue.d.ts.map +0 -1
- package/dist/shared/utils/event-queue.js.map +0 -1
- package/dist/shared/utils/hd-keyring-seed.d.ts.map +0 -1
- package/dist/shared/utils/hd-keyring-seed.js.map +0 -1
- package/dist/shared/utils/message-signing.d.ts.map +0 -1
- package/dist/shared/utils/message-signing.js.map +0 -1
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deleteContactInRemoteStorage = exports.updateContactInRemoteStorage = exports.syncContactsWithUserStorage = void 0;
|
|
4
|
+
const storage_schema_js_1 = require("../../../shared/storage-schema.cjs");
|
|
5
|
+
const constants_js_1 = require("../constants.cjs");
|
|
6
|
+
const sync_utils_js_1 = require("./sync-utils.cjs");
|
|
7
|
+
const utils_js_1 = require("./utils.cjs");
|
|
8
|
+
const utils_js_2 = require("./utils.cjs");
|
|
9
|
+
/**
|
|
10
|
+
* Creates a unique key for a contact based on chainId and address
|
|
11
|
+
*
|
|
12
|
+
* @param contact - The contact to create a key for
|
|
13
|
+
* @returns A unique string key
|
|
14
|
+
*/
|
|
15
|
+
function createContactKey(contact) {
|
|
16
|
+
if (!contact.address) {
|
|
17
|
+
throw new Error('Contact address is required to create storage key');
|
|
18
|
+
}
|
|
19
|
+
return `${contact.chainId}_${contact.address.toLowerCase()}`;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Syncs contacts between local storage and user storage (remote).
|
|
23
|
+
*
|
|
24
|
+
* Handles the following syncing scenarios:
|
|
25
|
+
* 1. First Sync: When local contacts exist but there are no remote contacts, uploads all local contacts.
|
|
26
|
+
* 2. New Device Sync: Downloads remote contacts that don't exist locally (empty local address book).
|
|
27
|
+
* 3. Simple Merge: Ensures both sides (local & remote) have all contacts.
|
|
28
|
+
* 4. Contact Naming Conflicts: When same contact has different names, uses most recent by timestamp.
|
|
29
|
+
* 5. Local Updates: When a contact was updated locally, syncs changes to remote if local is newer.
|
|
30
|
+
* 6. Remote Updates: When a contact was updated remotely, applies changes locally if remote is newer.
|
|
31
|
+
* 7. Local Deletions: Handled by real-time event handlers (deleteContactInRemoteStorage) to prevent false positives.
|
|
32
|
+
* 8. Remote Deletions: When a contact was deleted remotely, applies deletion locally.
|
|
33
|
+
* 9. Concurrent Updates: Resolves conflicts using timestamps to determine the winner.
|
|
34
|
+
* 10. Restore After Delete: If a contact is modified after being deleted, restores it.
|
|
35
|
+
* 11. ChainId Differences: Treats same address on different chains as separate contacts.
|
|
36
|
+
*
|
|
37
|
+
* @param config - Parameters used for syncing callbacks
|
|
38
|
+
* @param options - Parameters used for syncing operations
|
|
39
|
+
* @returns Promise that resolves when contact synchronization is complete
|
|
40
|
+
*/
|
|
41
|
+
async function syncContactsWithUserStorage(config, options) {
|
|
42
|
+
const { getMessenger, getUserStorageControllerInstance, trace } = options;
|
|
43
|
+
const { onContactSyncErroneousSituation, onContactUpdated, onContactDeleted, } = config;
|
|
44
|
+
// Cannot perform sync, conditions not met
|
|
45
|
+
if (!(0, sync_utils_js_1.canPerformContactSyncing)(options)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
// NOTE: Pre-sync operations (canPerformContactSyncing, AddressBookController:list, getRemoteContacts)
|
|
49
|
+
// are intentionally outside try-catch to let errors bubble up to Sentry for better debugging.
|
|
50
|
+
// Only "erroneous situation" errors during sync logic itself should be caught.
|
|
51
|
+
// Get all local contacts from AddressBookController (exclude chain "*" contacts)
|
|
52
|
+
const localVisibleContacts = getMessenger()
|
|
53
|
+
.call('AddressBookController:list')
|
|
54
|
+
.filter((contact) => !(0, utils_js_2.isContactBridgedFromAccounts)(contact))
|
|
55
|
+
.filter((contact) => contact.address && contact.chainId && contact.name?.trim()) || [];
|
|
56
|
+
// Get remote contacts from user storage API
|
|
57
|
+
const remoteContacts = await getRemoteContacts(options);
|
|
58
|
+
// Filter remote contacts to exclude invalid ones (or empty array if no remote contacts)
|
|
59
|
+
const validRemoteContacts = remoteContacts?.filter((contact) => contact.address && contact.chainId && contact.name?.trim()) || [];
|
|
60
|
+
const performSync = async () => {
|
|
61
|
+
try {
|
|
62
|
+
// Activate sync semaphore to prevent event loops
|
|
63
|
+
await getUserStorageControllerInstance().setIsContactSyncingInProgress(true);
|
|
64
|
+
// Prepare maps for efficient lookup
|
|
65
|
+
const localContactsMap = new Map();
|
|
66
|
+
const remoteContactsMap = new Map();
|
|
67
|
+
localVisibleContacts.forEach((contact) => {
|
|
68
|
+
const key = createContactKey(contact);
|
|
69
|
+
localContactsMap.set(key, contact);
|
|
70
|
+
});
|
|
71
|
+
validRemoteContacts.forEach((contact) => {
|
|
72
|
+
const key = createContactKey(contact);
|
|
73
|
+
remoteContactsMap.set(key, contact);
|
|
74
|
+
});
|
|
75
|
+
// Lists to track contacts that need to be synced
|
|
76
|
+
const contactsToAddOrUpdateLocally = [];
|
|
77
|
+
const contactsToDeleteLocally = [];
|
|
78
|
+
const contactsToUpdateRemotely = [];
|
|
79
|
+
// SCENARIO 2 & 6: Process remote contacts - handle new device sync and remote updates
|
|
80
|
+
for (const remoteContact of validRemoteContacts) {
|
|
81
|
+
const key = createContactKey(remoteContact);
|
|
82
|
+
const localContact = localContactsMap.get(key);
|
|
83
|
+
// Handle remote contact based on its status and local existence
|
|
84
|
+
if (remoteContact.deletedAt) {
|
|
85
|
+
// SCENARIO 8: Remote deletion - should be applied locally if contact exists locally
|
|
86
|
+
if (localContact) {
|
|
87
|
+
contactsToDeleteLocally.push(remoteContact);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
else if (!localContact) {
|
|
91
|
+
// SCENARIO 2: New contact from remote - import to local
|
|
92
|
+
contactsToAddOrUpdateLocally.push(remoteContact);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
// SCENARIO 4 & 6: Contact exists on both sides - check for conflicts
|
|
96
|
+
const hasContentDifference = localContact.name !== remoteContact.name ||
|
|
97
|
+
localContact.memo !== remoteContact.memo;
|
|
98
|
+
if (hasContentDifference) {
|
|
99
|
+
// Check timestamps to determine which version to keep
|
|
100
|
+
const localTimestamp = localContact.lastUpdatedAt || 0;
|
|
101
|
+
const remoteTimestamp = remoteContact.lastUpdatedAt || 0;
|
|
102
|
+
if (localTimestamp >= remoteTimestamp) {
|
|
103
|
+
// Local is newer (or same age) - use local version
|
|
104
|
+
contactsToUpdateRemotely.push(localContact);
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
// Remote is newer - use remote version
|
|
108
|
+
contactsToAddOrUpdateLocally.push(remoteContact);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
// Else: content is identical, no action needed
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
// SCENARIO 1, 3 & 5: Process local contacts not in remote - handles first sync and new local contacts
|
|
115
|
+
for (const localContact of localVisibleContacts) {
|
|
116
|
+
const key = createContactKey(localContact);
|
|
117
|
+
const remoteContact = remoteContactsMap.get(key);
|
|
118
|
+
if (!remoteContact) {
|
|
119
|
+
// New local contact or first sync - add to remote
|
|
120
|
+
contactsToUpdateRemotely.push(localContact);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
// Apply local deletions
|
|
124
|
+
// Note: Individual errors are intentionally NOT caught here to ensure they reach Sentry
|
|
125
|
+
// for debugging. Previous versions silently suppressed these errors which made
|
|
126
|
+
// troubleshooting contact sync issues difficult.
|
|
127
|
+
for (const contact of contactsToDeleteLocally) {
|
|
128
|
+
getMessenger().call('AddressBookController:delete', contact.chainId, contact.address);
|
|
129
|
+
if (onContactDeleted) {
|
|
130
|
+
onContactDeleted();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
// Apply local additions/updates
|
|
134
|
+
// Note: Individual errors are intentionally NOT caught here to ensure they reach Sentry
|
|
135
|
+
// for debugging. Previous versions silently suppressed these errors which made
|
|
136
|
+
// troubleshooting contact sync issues difficult.
|
|
137
|
+
for (const contact of contactsToAddOrUpdateLocally) {
|
|
138
|
+
if (!contact.deletedAt) {
|
|
139
|
+
getMessenger().call('AddressBookController:set', contact.address, contact.name || '', contact.chainId, contact.memo || '', contact.addressType);
|
|
140
|
+
if (onContactUpdated) {
|
|
141
|
+
onContactUpdated();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Apply changes to remote storage
|
|
146
|
+
if (contactsToUpdateRemotely.length > 0) {
|
|
147
|
+
const updatedRemoteContacts = {};
|
|
148
|
+
for (const localContact of contactsToUpdateRemotely) {
|
|
149
|
+
const key = createContactKey(localContact);
|
|
150
|
+
updatedRemoteContacts[key] = {
|
|
151
|
+
...remoteContactsMap.get(key), // Start with an existing remote contact if it exists
|
|
152
|
+
...localContact, // override with local changes
|
|
153
|
+
lastUpdatedAt: Date.now(), // mark as updated
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
// Save updated contacts to remote storage
|
|
157
|
+
await saveContactsToUserStorage(Object.values(updatedRemoteContacts), options);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
catch (error) {
|
|
161
|
+
if (onContactSyncErroneousSituation) {
|
|
162
|
+
onContactSyncErroneousSituation('Error synchronizing contacts', {
|
|
163
|
+
error,
|
|
164
|
+
});
|
|
165
|
+
// Re-throw the error to be handled by the caller
|
|
166
|
+
throw error;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
finally {
|
|
170
|
+
await getUserStorageControllerInstance().setIsContactSyncingInProgress(false);
|
|
171
|
+
}
|
|
172
|
+
};
|
|
173
|
+
if (trace) {
|
|
174
|
+
// Gather pre-sync metrics for performance analysis
|
|
175
|
+
const initialLocalContacts = localVisibleContacts;
|
|
176
|
+
const initialValidRemoteContacts = validRemoteContacts;
|
|
177
|
+
await trace({
|
|
178
|
+
name: constants_js_1.TraceName.ContactSyncFull,
|
|
179
|
+
data: {
|
|
180
|
+
localContactCount: initialLocalContacts.length,
|
|
181
|
+
remoteContactCount: initialValidRemoteContacts.length,
|
|
182
|
+
isFirstSync: initialValidRemoteContacts.length === 0 &&
|
|
183
|
+
initialLocalContacts.length > 0,
|
|
184
|
+
isNewDeviceSync: initialLocalContacts.length === 0 &&
|
|
185
|
+
initialValidRemoteContacts.length > 0,
|
|
186
|
+
isRegularSync: initialLocalContacts.length > 0 &&
|
|
187
|
+
initialValidRemoteContacts.length > 0,
|
|
188
|
+
hasDataToSync: initialLocalContacts.length > 0 ||
|
|
189
|
+
initialValidRemoteContacts.length > 0,
|
|
190
|
+
expectedWorkload: initialLocalContacts.length + initialValidRemoteContacts.length,
|
|
191
|
+
},
|
|
192
|
+
}, performSync);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
await performSync();
|
|
196
|
+
}
|
|
197
|
+
exports.syncContactsWithUserStorage = syncContactsWithUserStorage;
|
|
198
|
+
/**
|
|
199
|
+
* Retrieves remote contacts from user storage API
|
|
200
|
+
*
|
|
201
|
+
* @param options - Parameters used for retrieving remote contacts
|
|
202
|
+
* @returns Array of contacts from remote storage, or null if none found
|
|
203
|
+
*/
|
|
204
|
+
async function getRemoteContacts(options) {
|
|
205
|
+
const { getUserStorageControllerInstance } = options;
|
|
206
|
+
try {
|
|
207
|
+
const remoteContactsJsonArray = await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(storage_schema_js_1.USER_STORAGE_FEATURE_NAMES.addressBook);
|
|
208
|
+
if (!remoteContactsJsonArray || remoteContactsJsonArray.length === 0) {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
// Parse each JSON entry and convert from UserStorageContactEntry to AddressBookEntry
|
|
212
|
+
const remoteStorageEntries = remoteContactsJsonArray.map((contactJson) => {
|
|
213
|
+
const entry = JSON.parse(contactJson);
|
|
214
|
+
return (0, utils_js_1.mapUserStorageEntryToAddressBookEntry)(entry);
|
|
215
|
+
});
|
|
216
|
+
return remoteStorageEntries;
|
|
217
|
+
}
|
|
218
|
+
catch {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Saves local contacts to user storage
|
|
224
|
+
*
|
|
225
|
+
* @param contacts - The contacts to save to user storage
|
|
226
|
+
* @param options - Parameters used for saving contacts
|
|
227
|
+
* @returns Promise that resolves when contacts are saved
|
|
228
|
+
*/
|
|
229
|
+
async function saveContactsToUserStorage(contacts, options) {
|
|
230
|
+
const { getUserStorageControllerInstance, trace } = options;
|
|
231
|
+
const saveContacts = async () => {
|
|
232
|
+
if (!contacts || contacts.length === 0) {
|
|
233
|
+
return;
|
|
234
|
+
}
|
|
235
|
+
// Convert each AddressBookEntry to UserStorageContactEntry format and create key-value pairs
|
|
236
|
+
const storageEntries = contacts.map((contact) => {
|
|
237
|
+
const key = createContactKey(contact);
|
|
238
|
+
const storageEntry = (0, utils_js_1.mapAddressBookEntryToUserStorageEntry)(contact);
|
|
239
|
+
return [key, JSON.stringify(storageEntry)];
|
|
240
|
+
});
|
|
241
|
+
await getUserStorageControllerInstance().performBatchSetStorage(storage_schema_js_1.USER_STORAGE_FEATURE_NAMES.addressBook, storageEntries);
|
|
242
|
+
};
|
|
243
|
+
return trace
|
|
244
|
+
? await trace({
|
|
245
|
+
name: constants_js_1.TraceName.ContactSyncSaveBatch,
|
|
246
|
+
data: {
|
|
247
|
+
contactCount: contacts.length,
|
|
248
|
+
// Performance scaling indicators
|
|
249
|
+
hasBatchOperations: contacts.length > 1,
|
|
250
|
+
chainCount: new Set(contacts.map((c) => c.chainId)).size,
|
|
251
|
+
hasMemosCount: contacts.filter((c) => c.memo?.length).length,
|
|
252
|
+
},
|
|
253
|
+
}, saveContacts)
|
|
254
|
+
: await saveContacts();
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Updates a single contact in remote storage without performing a full sync
|
|
258
|
+
* This is used when a contact is updated locally to efficiently push changes to remote
|
|
259
|
+
*
|
|
260
|
+
* @param contact - The contact that was updated locally
|
|
261
|
+
* @param options - Parameters used for syncing operations
|
|
262
|
+
* @returns Promise that resolves when the contact is updated
|
|
263
|
+
*/
|
|
264
|
+
async function updateContactInRemoteStorage(contact, options) {
|
|
265
|
+
const { trace } = options;
|
|
266
|
+
const updateContact = async () => {
|
|
267
|
+
if (!(0, sync_utils_js_1.canPerformContactSyncing)(options) ||
|
|
268
|
+
!contact.address ||
|
|
269
|
+
!contact.chainId ||
|
|
270
|
+
!contact.name?.trim()) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const { getUserStorageControllerInstance } = options;
|
|
274
|
+
// Create an updated entry with timestamp
|
|
275
|
+
const updatedEntry = {
|
|
276
|
+
...contact,
|
|
277
|
+
lastUpdatedAt: contact.lastUpdatedAt || Date.now(),
|
|
278
|
+
};
|
|
279
|
+
const key = createContactKey(contact);
|
|
280
|
+
const storageEntry = (0, utils_js_1.mapAddressBookEntryToUserStorageEntry)(updatedEntry);
|
|
281
|
+
// Save individual contact to remote storage
|
|
282
|
+
await getUserStorageControllerInstance().performSetStorage(`${storage_schema_js_1.USER_STORAGE_FEATURE_NAMES.addressBook}.${key}`, JSON.stringify(storageEntry));
|
|
283
|
+
};
|
|
284
|
+
if (trace) {
|
|
285
|
+
return await trace({
|
|
286
|
+
name: constants_js_1.TraceName.ContactSyncUpdateRemote,
|
|
287
|
+
data: {
|
|
288
|
+
chainId: contact.chainId,
|
|
289
|
+
// Performance indicators
|
|
290
|
+
hasTimestamp: Boolean(contact.lastUpdatedAt),
|
|
291
|
+
hasMemo: Boolean(contact.memo?.length),
|
|
292
|
+
isUpdate: Boolean(contact.lastUpdatedAt), // vs new contact
|
|
293
|
+
},
|
|
294
|
+
}, updateContact);
|
|
295
|
+
}
|
|
296
|
+
return await updateContact();
|
|
297
|
+
}
|
|
298
|
+
exports.updateContactInRemoteStorage = updateContactInRemoteStorage;
|
|
299
|
+
/**
|
|
300
|
+
* Marks a single contact as deleted in remote storage without performing a full sync
|
|
301
|
+
* This is used when a contact is deleted locally to efficiently push the deletion to remote
|
|
302
|
+
*
|
|
303
|
+
* @param contact - The contact that was deleted locally (contains at least address and chainId)
|
|
304
|
+
* @param options - Parameters used for syncing operations
|
|
305
|
+
* @returns Promise that resolves when the contact is marked as deleted
|
|
306
|
+
*/
|
|
307
|
+
async function deleteContactInRemoteStorage(contact, options) {
|
|
308
|
+
const { trace } = options;
|
|
309
|
+
const deleteContact = async () => {
|
|
310
|
+
if (!(0, sync_utils_js_1.canPerformContactSyncing)(options) ||
|
|
311
|
+
!contact.address ||
|
|
312
|
+
!contact.chainId ||
|
|
313
|
+
!contact.name?.trim()) {
|
|
314
|
+
return;
|
|
315
|
+
}
|
|
316
|
+
const { getUserStorageControllerInstance } = options;
|
|
317
|
+
const key = createContactKey(contact);
|
|
318
|
+
try {
|
|
319
|
+
// Try to get the existing contact first
|
|
320
|
+
const existingContactJson = await getUserStorageControllerInstance().performGetStorage(`${storage_schema_js_1.USER_STORAGE_FEATURE_NAMES.addressBook}.${key}`);
|
|
321
|
+
if (existingContactJson) {
|
|
322
|
+
// Mark the existing contact as deleted
|
|
323
|
+
const existingStorageEntry = JSON.parse(existingContactJson);
|
|
324
|
+
const existingContact = (0, utils_js_1.mapUserStorageEntryToAddressBookEntry)(existingStorageEntry);
|
|
325
|
+
const now = Date.now();
|
|
326
|
+
const deletedContact = {
|
|
327
|
+
...existingContact,
|
|
328
|
+
deletedAt: now,
|
|
329
|
+
lastUpdatedAt: now,
|
|
330
|
+
};
|
|
331
|
+
const deletedStorageEntry = (0, utils_js_1.mapAddressBookEntryToUserStorageEntry)(deletedContact);
|
|
332
|
+
// Save the deleted contact back to storage
|
|
333
|
+
await getUserStorageControllerInstance().performSetStorage(`${storage_schema_js_1.USER_STORAGE_FEATURE_NAMES.addressBook}.${key}`, JSON.stringify(deletedStorageEntry));
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
catch {
|
|
337
|
+
// If contact doesn't exist in remote storage, no need to mark as deleted
|
|
338
|
+
console.warn('Contact not found in remote storage for deletion:', key);
|
|
339
|
+
}
|
|
340
|
+
};
|
|
341
|
+
return trace
|
|
342
|
+
? await trace({ name: constants_js_1.TraceName.ContactSyncDeleteRemote }, deleteContact)
|
|
343
|
+
: await deleteContact();
|
|
344
|
+
}
|
|
345
|
+
exports.deleteContactInRemoteStorage = deleteContactInRemoteStorage;
|
|
346
|
+
//# sourceMappingURL=controller-integration.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller-integration.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/contact-syncing/controller-integration.ts"],"names":[],"mappings":";;;AAEA,0EAA+E;AAC/E,mDAA4C;AAC5C,oDAA2D;AAI3D,0CAGoB;AACpB,0CAA0D;AAW1D;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAAyB;IACjD,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;AAC/D,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACI,KAAK,UAAU,2BAA2B,CAC/C,MAAyC,EACzC,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,gCAAgC,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC;IAC1E,MAAM,EACJ,+BAA+B,EAC/B,gBAAgB,EAChB,gBAAgB,GACjB,GAAG,MAAM,CAAC;IAEX,0CAA0C;IAC1C,IAAI,CAAC,IAAA,wCAAwB,EAAC,OAAO,CAAC,EAAE,CAAC;QACvC,OAAO;IACT,CAAC;IAED,sGAAsG;IACtG,8FAA8F;IAC9F,+EAA+E;IAE/E,iFAAiF;IACjF,MAAM,oBAAoB,GACxB,YAAY,EAAE;SACX,IAAI,CAAC,4BAA4B,CAAC;SAClC,MAAM,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,IAAA,uCAA4B,EAAC,OAAO,CAAC,CAAC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CAAC;AAC5B,CAAC;AA1DD,oEA0DC","sourcesContent":["import type { AddressBookEntry } from '@metamask/address-book-controller';\n\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema.js';\nimport { TraceName } from '../constants.js';\nimport { canPerformContactSyncing } from './sync-utils.js';\nimport type { ContactSyncingOptions } from './types.js';\nimport type { UserStorageContactEntry } from './types.js';\nimport type { SyncAddressBookEntry } from './utils.js';\nimport {\n mapAddressBookEntryToUserStorageEntry,\n mapUserStorageEntryToAddressBookEntry,\n} from './utils.js';\nimport { isContactBridgedFromAccounts } from './utils.js';\n\nexport type SyncContactsWithUserStorageConfig = {\n onContactSyncErroneousSituation?: (\n errorMessage: string,\n sentryContext?: Record<string, unknown>,\n ) => void;\n onContactUpdated?: () => void;\n onContactDeleted?: () => void;\n};\n\n/**\n * Creates a unique key for a contact based on chainId and address\n *\n * @param contact - The contact to create a key for\n * @returns A unique string key\n */\nfunction createContactKey(contact: AddressBookEntry): string {\n if (!contact.address) {\n throw new Error('Contact address is required to create storage key');\n }\n return `${contact.chainId}_${contact.address.toLowerCase()}`;\n}\n\n/**\n * Syncs contacts between local storage and user storage (remote).\n *\n * Handles the following syncing scenarios:\n * 1. First Sync: When local contacts exist but there are no remote contacts, uploads all local contacts.\n * 2. New Device Sync: Downloads remote contacts that don't exist locally (empty local address book).\n * 3. Simple Merge: Ensures both sides (local & remote) have all contacts.\n * 4. Contact Naming Conflicts: When same contact has different names, uses most recent by timestamp.\n * 5. Local Updates: When a contact was updated locally, syncs changes to remote if local is newer.\n * 6. Remote Updates: When a contact was updated remotely, applies changes locally if remote is newer.\n * 7. Local Deletions: Handled by real-time event handlers (deleteContactInRemoteStorage) to prevent false positives.\n * 8. Remote Deletions: When a contact was deleted remotely, applies deletion locally.\n * 9. Concurrent Updates: Resolves conflicts using timestamps to determine the winner.\n * 10. Restore After Delete: If a contact is modified after being deleted, restores it.\n * 11. ChainId Differences: Treats same address on different chains as separate contacts.\n *\n * @param config - Parameters used for syncing callbacks\n * @param options - Parameters used for syncing operations\n * @returns Promise that resolves when contact synchronization is complete\n */\nexport async function syncContactsWithUserStorage(\n config: SyncContactsWithUserStorageConfig,\n options: ContactSyncingOptions,\n): Promise<void> {\n const { getMessenger, getUserStorageControllerInstance, trace } = options;\n const {\n onContactSyncErroneousSituation,\n onContactUpdated,\n onContactDeleted,\n } = config;\n\n // Cannot perform sync, conditions not met\n if (!canPerformContactSyncing(options)) {\n return;\n }\n\n // NOTE: Pre-sync operations (canPerformContactSyncing, AddressBookController:list, getRemoteContacts)\n // are intentionally outside try-catch to let errors bubble up to Sentry for better debugging.\n // Only \"erroneous situation\" errors during sync logic itself should be caught.\n\n // Get all local contacts from AddressBookController (exclude chain \"*\" contacts)\n const localVisibleContacts =\n getMessenger()\n .call('AddressBookController:list')\n .filter((contact) => !isContactBridgedFromAccounts(contact))\n .filter(\n (contact) => contact.address && contact.chainId && contact.name?.trim(),\n ) || [];\n\n // Get remote contacts from user storage API\n const remoteContacts = await getRemoteContacts(options);\n\n // Filter remote contacts to exclude invalid ones (or empty array if no remote contacts)\n const validRemoteContacts =\n remoteContacts?.filter(\n (contact) => contact.address && contact.chainId && contact.name?.trim(),\n ) || [];\n\n const performSync = async () => {\n try {\n // Activate sync semaphore to prevent event loops\n await getUserStorageControllerInstance().setIsContactSyncingInProgress(\n true,\n );\n\n // Prepare maps for efficient lookup\n const localContactsMap = new Map<string, AddressBookEntry>();\n const remoteContactsMap = new Map<string, SyncAddressBookEntry>();\n\n localVisibleContacts.forEach((contact) => {\n const key = createContactKey(contact);\n localContactsMap.set(key, contact);\n });\n\n validRemoteContacts.forEach((contact) => {\n const key = createContactKey(contact);\n remoteContactsMap.set(key, contact);\n });\n\n // Lists to track contacts that need to be synced\n const contactsToAddOrUpdateLocally: SyncAddressBookEntry[] = [];\n const contactsToDeleteLocally: SyncAddressBookEntry[] = [];\n const contactsToUpdateRemotely: AddressBookEntry[] = [];\n\n // SCENARIO 2 & 6: Process remote contacts - handle new device sync and remote updates\n for (const remoteContact of validRemoteContacts) {\n const key = createContactKey(remoteContact);\n const localContact = localContactsMap.get(key);\n\n // Handle remote contact based on its status and local existence\n if (remoteContact.deletedAt) {\n // SCENARIO 8: Remote deletion - should be applied locally if contact exists locally\n if (localContact) {\n contactsToDeleteLocally.push(remoteContact);\n }\n } else if (!localContact) {\n // SCENARIO 2: New contact from remote - import to local\n contactsToAddOrUpdateLocally.push(remoteContact);\n } else {\n // SCENARIO 4 & 6: Contact exists on both sides - check for conflicts\n const hasContentDifference =\n localContact.name !== remoteContact.name ||\n localContact.memo !== remoteContact.memo;\n\n if (hasContentDifference) {\n // Check timestamps to determine which version to keep\n const localTimestamp = localContact.lastUpdatedAt || 0;\n const remoteTimestamp = remoteContact.lastUpdatedAt || 0;\n\n if (localTimestamp >= remoteTimestamp) {\n // Local is newer (or same age) - use local version\n contactsToUpdateRemotely.push(localContact);\n } else {\n // Remote is newer - use remote version\n contactsToAddOrUpdateLocally.push(remoteContact);\n }\n }\n\n // Else: content is identical, no action needed\n }\n }\n\n // SCENARIO 1, 3 & 5: Process local contacts not in remote - handles first sync and new local contacts\n for (const localContact of localVisibleContacts) {\n const key = createContactKey(localContact);\n const remoteContact = remoteContactsMap.get(key);\n\n if (!remoteContact) {\n // New local contact or first sync - add to remote\n contactsToUpdateRemotely.push(localContact);\n }\n }\n\n // Apply local deletions\n // Note: Individual errors are intentionally NOT caught here to ensure they reach Sentry\n // for debugging. Previous versions silently suppressed these errors which made\n // troubleshooting contact sync issues difficult.\n for (const contact of contactsToDeleteLocally) {\n getMessenger().call(\n 'AddressBookController:delete',\n contact.chainId,\n contact.address,\n );\n\n if (onContactDeleted) {\n onContactDeleted();\n }\n }\n\n // Apply local additions/updates\n // Note: Individual errors are intentionally NOT caught here to ensure they reach Sentry\n // for debugging. Previous versions silently suppressed these errors which made\n // troubleshooting contact sync issues difficult.\n for (const contact of contactsToAddOrUpdateLocally) {\n if (!contact.deletedAt) {\n getMessenger().call(\n 'AddressBookController:set',\n contact.address,\n contact.name || '',\n contact.chainId,\n contact.memo || '',\n contact.addressType,\n );\n\n if (onContactUpdated) {\n onContactUpdated();\n }\n }\n }\n\n // Apply changes to remote storage\n if (contactsToUpdateRemotely.length > 0) {\n const updatedRemoteContacts: Record<string, SyncAddressBookEntry> = {};\n for (const localContact of contactsToUpdateRemotely) {\n const key = createContactKey(localContact);\n updatedRemoteContacts[key] = {\n ...remoteContactsMap.get(key), // Start with an existing remote contact if it exists\n ...localContact, // override with local changes\n lastUpdatedAt: Date.now(), // mark as updated\n };\n }\n // Save updated contacts to remote storage\n await saveContactsToUserStorage(\n Object.values(updatedRemoteContacts),\n options,\n );\n }\n } catch (error) {\n if (onContactSyncErroneousSituation) {\n onContactSyncErroneousSituation('Error synchronizing contacts', {\n error,\n });\n\n // Re-throw the error to be handled by the caller\n throw error;\n }\n } finally {\n await getUserStorageControllerInstance().setIsContactSyncingInProgress(\n false,\n );\n }\n };\n\n if (trace) {\n // Gather pre-sync metrics for performance analysis\n const initialLocalContacts = localVisibleContacts;\n const initialValidRemoteContacts = validRemoteContacts;\n\n await trace(\n {\n name: TraceName.ContactSyncFull,\n data: {\n localContactCount: initialLocalContacts.length,\n remoteContactCount: initialValidRemoteContacts.length,\n isFirstSync:\n initialValidRemoteContacts.length === 0 &&\n initialLocalContacts.length > 0,\n isNewDeviceSync:\n initialLocalContacts.length === 0 &&\n initialValidRemoteContacts.length > 0,\n isRegularSync:\n initialLocalContacts.length > 0 &&\n initialValidRemoteContacts.length > 0,\n hasDataToSync:\n initialLocalContacts.length > 0 ||\n initialValidRemoteContacts.length > 0,\n expectedWorkload:\n initialLocalContacts.length + initialValidRemoteContacts.length,\n },\n },\n performSync,\n );\n\n return;\n }\n\n await performSync();\n}\n\n/**\n * Retrieves remote contacts from user storage API\n *\n * @param options - Parameters used for retrieving remote contacts\n * @returns Array of contacts from remote storage, or null if none found\n */\nasync function getRemoteContacts(\n options: ContactSyncingOptions,\n): Promise<SyncAddressBookEntry[] | null> {\n const { getUserStorageControllerInstance } = options;\n\n try {\n const remoteContactsJsonArray =\n await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(\n USER_STORAGE_FEATURE_NAMES.addressBook,\n );\n\n if (!remoteContactsJsonArray || remoteContactsJsonArray.length === 0) {\n return null;\n }\n\n // Parse each JSON entry and convert from UserStorageContactEntry to AddressBookEntry\n const remoteStorageEntries = remoteContactsJsonArray.map((contactJson) => {\n const entry = JSON.parse(contactJson) as UserStorageContactEntry;\n return mapUserStorageEntryToAddressBookEntry(entry);\n });\n\n return remoteStorageEntries;\n } catch {\n return null;\n }\n}\n\n/**\n * Saves local contacts to user storage\n *\n * @param contacts - The contacts to save to user storage\n * @param options - Parameters used for saving contacts\n * @returns Promise that resolves when contacts are saved\n */\nasync function saveContactsToUserStorage(\n contacts: AddressBookEntry[],\n options: ContactSyncingOptions,\n): Promise<void> {\n const { getUserStorageControllerInstance, trace } = options;\n\n const saveContacts = async () => {\n if (!contacts || contacts.length === 0) {\n return;\n }\n\n // Convert each AddressBookEntry to UserStorageContactEntry format and create key-value pairs\n const storageEntries: [string, string][] = contacts.map((contact) => {\n const key = createContactKey(contact);\n const storageEntry = mapAddressBookEntryToUserStorageEntry(contact);\n return [key, JSON.stringify(storageEntry)];\n });\n\n await getUserStorageControllerInstance().performBatchSetStorage(\n USER_STORAGE_FEATURE_NAMES.addressBook,\n storageEntries,\n );\n };\n\n return trace\n ? await trace(\n {\n name: TraceName.ContactSyncSaveBatch,\n data: {\n contactCount: contacts.length,\n // Performance scaling indicators\n hasBatchOperations: contacts.length > 1,\n chainCount: new Set(contacts.map((c) => c.chainId)).size,\n hasMemosCount: contacts.filter((c) => c.memo?.length).length,\n },\n },\n saveContacts,\n )\n : await saveContacts();\n}\n\n/**\n * Updates a single contact in remote storage without performing a full sync\n * This is used when a contact is updated locally to efficiently push changes to remote\n *\n * @param contact - The contact that was updated locally\n * @param options - Parameters used for syncing operations\n * @returns Promise that resolves when the contact is updated\n */\nexport async function updateContactInRemoteStorage(\n contact: AddressBookEntry,\n options: ContactSyncingOptions,\n): Promise<void> {\n const { trace } = options;\n\n const updateContact = async () => {\n if (\n !canPerformContactSyncing(options) ||\n !contact.address ||\n !contact.chainId ||\n !contact.name?.trim()\n ) {\n return;\n }\n\n const { getUserStorageControllerInstance } = options;\n\n // Create an updated entry with timestamp\n const updatedEntry = {\n ...contact,\n lastUpdatedAt: contact.lastUpdatedAt || Date.now(),\n } as SyncAddressBookEntry;\n\n const key = createContactKey(contact);\n const storageEntry = mapAddressBookEntryToUserStorageEntry(updatedEntry);\n\n // Save individual contact to remote storage\n await getUserStorageControllerInstance().performSetStorage(\n `${USER_STORAGE_FEATURE_NAMES.addressBook}.${key}`,\n JSON.stringify(storageEntry),\n );\n };\n\n if (trace) {\n return await trace(\n {\n name: TraceName.ContactSyncUpdateRemote,\n data: {\n chainId: contact.chainId,\n // Performance indicators\n hasTimestamp: Boolean(contact.lastUpdatedAt),\n hasMemo: Boolean(contact.memo?.length),\n isUpdate: Boolean(contact.lastUpdatedAt), // vs new contact\n },\n },\n updateContact,\n );\n }\n\n return await updateContact();\n}\n\n/**\n * Marks a single contact as deleted in remote storage without performing a full sync\n * This is used when a contact is deleted locally to efficiently push the deletion to remote\n *\n * @param contact - The contact that was deleted locally (contains at least address and chainId)\n * @param options - Parameters used for syncing operations\n * @returns Promise that resolves when the contact is marked as deleted\n */\nexport async function deleteContactInRemoteStorage(\n contact: AddressBookEntry,\n options: ContactSyncingOptions,\n): Promise<void> {\n const { trace } = options;\n const deleteContact = async () => {\n if (\n !canPerformContactSyncing(options) ||\n !contact.address ||\n !contact.chainId ||\n !contact.name?.trim()\n ) {\n return;\n }\n\n const { getUserStorageControllerInstance } = options;\n const key = createContactKey(contact);\n\n try {\n // Try to get the existing contact first\n const existingContactJson =\n await getUserStorageControllerInstance().performGetStorage(\n `${USER_STORAGE_FEATURE_NAMES.addressBook}.${key}`,\n );\n\n if (existingContactJson) {\n // Mark the existing contact as deleted\n const existingStorageEntry = JSON.parse(\n existingContactJson,\n ) as UserStorageContactEntry;\n const existingContact =\n mapUserStorageEntryToAddressBookEntry(existingStorageEntry);\n\n const now = Date.now();\n const deletedContact = {\n ...existingContact,\n deletedAt: now,\n lastUpdatedAt: now,\n } as SyncAddressBookEntry;\n\n const deletedStorageEntry =\n mapAddressBookEntryToUserStorageEntry(deletedContact);\n\n // Save the deleted contact back to storage\n await getUserStorageControllerInstance().performSetStorage(\n `${USER_STORAGE_FEATURE_NAMES.addressBook}.${key}`,\n JSON.stringify(deletedStorageEntry),\n );\n }\n } catch {\n // If contact doesn't exist in remote storage, no need to mark as deleted\n console.warn('Contact not found in remote storage for deletion:', key);\n }\n };\n\n return trace\n ? await trace({ name: TraceName.ContactSyncDeleteRemote }, deleteContact)\n : await deleteContact();\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { AddressBookEntry } from
|
|
2
|
-
import type { ContactSyncingOptions } from
|
|
1
|
+
import type { AddressBookEntry } from "@metamask/address-book-controller";
|
|
2
|
+
import type { ContactSyncingOptions } from "./types.cjs";
|
|
3
3
|
export type SyncContactsWithUserStorageConfig = {
|
|
4
4
|
onContactSyncErroneousSituation?: (errorMessage: string, sentryContext?: Record<string, unknown>) => void;
|
|
5
5
|
onContactUpdated?: () => void;
|
|
@@ -44,4 +44,4 @@ export declare function updateContactInRemoteStorage(contact: AddressBookEntry,
|
|
|
44
44
|
* @returns Promise that resolves when the contact is marked as deleted
|
|
45
45
|
*/
|
|
46
46
|
export declare function deleteContactInRemoteStorage(contact: AddressBookEntry, options: ContactSyncingOptions): Promise<void>;
|
|
47
|
-
//# sourceMappingURL=controller-integration.d.
|
|
47
|
+
//# sourceMappingURL=controller-integration.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller-integration.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/contact-syncing/controller-integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,0CAA0C;AAK1E,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAmB;AASxD,MAAM,MAAM,iCAAiC,GAAG;IAC9C,+BAA+B,CAAC,EAAE,CAChC,YAAY,EAAE,MAAM,EACpB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACpC,IAAI,CAAC;IACV,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;CAC/B,CAAC;AAeF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,EACzC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAsNf;AAmFD;;;;;;;GAOG;AACH,wBAAsB,4BAA4B,CAChD,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAgDf;AAED;;;;;;;GAOG;AACH,wBAAsB,4BAA4B,CAChD,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAuDf"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { AddressBookEntry } from "@metamask/address-book-controller";
|
|
2
|
+
import type { ContactSyncingOptions } from "./types.mjs";
|
|
3
|
+
export type SyncContactsWithUserStorageConfig = {
|
|
4
|
+
onContactSyncErroneousSituation?: (errorMessage: string, sentryContext?: Record<string, unknown>) => void;
|
|
5
|
+
onContactUpdated?: () => void;
|
|
6
|
+
onContactDeleted?: () => void;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Syncs contacts between local storage and user storage (remote).
|
|
10
|
+
*
|
|
11
|
+
* Handles the following syncing scenarios:
|
|
12
|
+
* 1. First Sync: When local contacts exist but there are no remote contacts, uploads all local contacts.
|
|
13
|
+
* 2. New Device Sync: Downloads remote contacts that don't exist locally (empty local address book).
|
|
14
|
+
* 3. Simple Merge: Ensures both sides (local & remote) have all contacts.
|
|
15
|
+
* 4. Contact Naming Conflicts: When same contact has different names, uses most recent by timestamp.
|
|
16
|
+
* 5. Local Updates: When a contact was updated locally, syncs changes to remote if local is newer.
|
|
17
|
+
* 6. Remote Updates: When a contact was updated remotely, applies changes locally if remote is newer.
|
|
18
|
+
* 7. Local Deletions: Handled by real-time event handlers (deleteContactInRemoteStorage) to prevent false positives.
|
|
19
|
+
* 8. Remote Deletions: When a contact was deleted remotely, applies deletion locally.
|
|
20
|
+
* 9. Concurrent Updates: Resolves conflicts using timestamps to determine the winner.
|
|
21
|
+
* 10. Restore After Delete: If a contact is modified after being deleted, restores it.
|
|
22
|
+
* 11. ChainId Differences: Treats same address on different chains as separate contacts.
|
|
23
|
+
*
|
|
24
|
+
* @param config - Parameters used for syncing callbacks
|
|
25
|
+
* @param options - Parameters used for syncing operations
|
|
26
|
+
* @returns Promise that resolves when contact synchronization is complete
|
|
27
|
+
*/
|
|
28
|
+
export declare function syncContactsWithUserStorage(config: SyncContactsWithUserStorageConfig, options: ContactSyncingOptions): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Updates a single contact in remote storage without performing a full sync
|
|
31
|
+
* This is used when a contact is updated locally to efficiently push changes to remote
|
|
32
|
+
*
|
|
33
|
+
* @param contact - The contact that was updated locally
|
|
34
|
+
* @param options - Parameters used for syncing operations
|
|
35
|
+
* @returns Promise that resolves when the contact is updated
|
|
36
|
+
*/
|
|
37
|
+
export declare function updateContactInRemoteStorage(contact: AddressBookEntry, options: ContactSyncingOptions): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Marks a single contact as deleted in remote storage without performing a full sync
|
|
40
|
+
* This is used when a contact is deleted locally to efficiently push the deletion to remote
|
|
41
|
+
*
|
|
42
|
+
* @param contact - The contact that was deleted locally (contains at least address and chainId)
|
|
43
|
+
* @param options - Parameters used for syncing operations
|
|
44
|
+
* @returns Promise that resolves when the contact is marked as deleted
|
|
45
|
+
*/
|
|
46
|
+
export declare function deleteContactInRemoteStorage(contact: AddressBookEntry, options: ContactSyncingOptions): Promise<void>;
|
|
47
|
+
//# sourceMappingURL=controller-integration.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller-integration.d.mts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/contact-syncing/controller-integration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,0CAA0C;AAK1E,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAmB;AASxD,MAAM,MAAM,iCAAiC,GAAG;IAC9C,+BAA+B,CAAC,EAAE,CAChC,YAAY,EAAE,MAAM,EACpB,aAAa,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACpC,IAAI,CAAC;IACV,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC9B,gBAAgB,CAAC,EAAE,MAAM,IAAI,CAAC;CAC/B,CAAC;AAeF;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,EACzC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAsNf;AAmFD;;;;;;;GAOG;AACH,wBAAsB,4BAA4B,CAChD,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAgDf;AAED;;;;;;;GAOG;AACH,wBAAsB,4BAA4B,CAChD,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAuDf"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { USER_STORAGE_FEATURE_NAMES } from
|
|
2
|
-
import { TraceName } from
|
|
3
|
-
import { canPerformContactSyncing } from
|
|
4
|
-
import { mapAddressBookEntryToUserStorageEntry, mapUserStorageEntryToAddressBookEntry
|
|
5
|
-
import { isContactBridgedFromAccounts } from
|
|
1
|
+
import { USER_STORAGE_FEATURE_NAMES } from "../../../shared/storage-schema.mjs";
|
|
2
|
+
import { TraceName } from "../constants.mjs";
|
|
3
|
+
import { canPerformContactSyncing } from "./sync-utils.mjs";
|
|
4
|
+
import { mapAddressBookEntryToUserStorageEntry, mapUserStorageEntryToAddressBookEntry } from "./utils.mjs";
|
|
5
|
+
import { isContactBridgedFromAccounts } from "./utils.mjs";
|
|
6
6
|
/**
|
|
7
7
|
* Creates a unique key for a contact based on chainId and address
|
|
8
8
|
*
|
|
@@ -337,4 +337,4 @@ export async function deleteContactInRemoteStorage(contact, options) {
|
|
|
337
337
|
? await trace({ name: TraceName.ContactSyncDeleteRemote }, deleteContact)
|
|
338
338
|
: await deleteContact();
|
|
339
339
|
}
|
|
340
|
-
//# sourceMappingURL=controller-integration.
|
|
340
|
+
//# sourceMappingURL=controller-integration.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"controller-integration.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/contact-syncing/controller-integration.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,0BAA0B,EAAE,2CAA0C;AAC/E,OAAO,EAAE,SAAS,EAAE,yBAAwB;AAC5C,OAAO,EAAE,wBAAwB,EAAE,yBAAwB;AAI3D,OAAO,EACL,qCAAqC,EACrC,qCAAqC,EACtC,oBAAmB;AACpB,OAAO,EAAE,4BAA4B,EAAE,oBAAmB;AAW1D;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAAyB;IACjD,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QACrB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;IACvE,CAAC;IACD,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;AAC/D,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,C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AC;gBAExD,2CAA2C;gBAC3C,MAAM,gCAAgC,EAAE,CAAC,iBAAiB,CACxD,GAAG,0BAA0B,CAAC,WAAW,IAAI,GAAG,EAAE,EAClD,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CACpC,CAAC;YACJ,CAAC;QACH,CAAC;QAAC,MAAM,CAAC;YACP,yEAAyE;YACzE,OAAO,CAAC,IAAI,CAAC,mDAAmD,EAAE,GAAG,CAAC,CAAC;QACzE,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,KAAK;QACV,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,uBAAuB,EAAE,EAAE,aAAa,CAAC;QACzE,CAAC,CAAC,MAAM,aAAa,EAAE,CAAC;AAC5B,CAAC","sourcesContent":["import type { AddressBookEntry } from '@metamask/address-book-controller';\n\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema.js';\nimport { TraceName } from '../constants.js';\nimport { canPerformContactSyncing } from './sync-utils.js';\nimport type { ContactSyncingOptions } from './types.js';\nimport type { UserStorageContactEntry } from './types.js';\nimport type { SyncAddressBookEntry } from './utils.js';\nimport {\n mapAddressBookEntryToUserStorageEntry,\n mapUserStorageEntryToAddressBookEntry,\n} from './utils.js';\nimport { isContactBridgedFromAccounts } from './utils.js';\n\nexport type SyncContactsWithUserStorageConfig = {\n onContactSyncErroneousSituation?: (\n errorMessage: string,\n sentryContext?: Record<string, unknown>,\n ) => void;\n onContactUpdated?: () => void;\n onContactDeleted?: () => void;\n};\n\n/**\n * Creates a unique key for a contact based on chainId and address\n *\n * @param contact - The contact to create a key for\n * @returns A unique string key\n */\nfunction createContactKey(contact: AddressBookEntry): string {\n if (!contact.address) {\n throw new Error('Contact address is required to create storage key');\n }\n return `${contact.chainId}_${contact.address.toLowerCase()}`;\n}\n\n/**\n * Syncs contacts between local storage and user storage (remote).\n *\n * Handles the following syncing scenarios:\n * 1. First Sync: When local contacts exist but there are no remote contacts, uploads all local contacts.\n * 2. New Device Sync: Downloads remote contacts that don't exist locally (empty local address book).\n * 3. Simple Merge: Ensures both sides (local & remote) have all contacts.\n * 4. Contact Naming Conflicts: When same contact has different names, uses most recent by timestamp.\n * 5. Local Updates: When a contact was updated locally, syncs changes to remote if local is newer.\n * 6. Remote Updates: When a contact was updated remotely, applies changes locally if remote is newer.\n * 7. Local Deletions: Handled by real-time event handlers (deleteContactInRemoteStorage) to prevent false positives.\n * 8. Remote Deletions: When a contact was deleted remotely, applies deletion locally.\n * 9. Concurrent Updates: Resolves conflicts using timestamps to determine the winner.\n * 10. Restore After Delete: If a contact is modified after being deleted, restores it.\n * 11. ChainId Differences: Treats same address on different chains as separate contacts.\n *\n * @param config - Parameters used for syncing callbacks\n * @param options - Parameters used for syncing operations\n * @returns Promise that resolves when contact synchronization is complete\n */\nexport async function syncContactsWithUserStorage(\n config: SyncContactsWithUserStorageConfig,\n options: ContactSyncingOptions,\n): Promise<void> {\n const { getMessenger, getUserStorageControllerInstance, trace } = options;\n const {\n onContactSyncErroneousSituation,\n onContactUpdated,\n onContactDeleted,\n } = config;\n\n // Cannot perform sync, conditions not met\n if (!canPerformContactSyncing(options)) {\n return;\n }\n\n // NOTE: Pre-sync operations (canPerformContactSyncing, AddressBookController:list, getRemoteContacts)\n // are intentionally outside try-catch to let errors bubble up to Sentry for better debugging.\n // Only \"erroneous situation\" errors during sync logic itself should be caught.\n\n // Get all local contacts from AddressBookController (exclude chain \"*\" contacts)\n const localVisibleContacts =\n getMessenger()\n .call('AddressBookController:list')\n .filter((contact) => !isContactBridgedFromAccounts(contact))\n .filter(\n (contact) => contact.address && contact.chainId && contact.name?.trim(),\n ) || [];\n\n // Get remote contacts from user storage API\n const remoteContacts = await getRemoteContacts(options);\n\n // Filter remote contacts to exclude invalid ones (or empty array if no remote contacts)\n const validRemoteContacts =\n remoteContacts?.filter(\n (contact) => contact.address && contact.chainId && contact.name?.trim(),\n ) || [];\n\n const performSync = async () => {\n try {\n // Activate sync semaphore to prevent event loops\n await getUserStorageControllerInstance().setIsContactSyncingInProgress(\n true,\n );\n\n // Prepare maps for efficient lookup\n const localContactsMap = new Map<string, AddressBookEntry>();\n const remoteContactsMap = new Map<string, SyncAddressBookEntry>();\n\n localVisibleContacts.forEach((contact) => {\n const key = createContactKey(contact);\n localContactsMap.set(key, contact);\n });\n\n validRemoteContacts.forEach((contact) => {\n const key = createContactKey(contact);\n remoteContactsMap.set(key, contact);\n });\n\n // Lists to track contacts that need to be synced\n const contactsToAddOrUpdateLocally: SyncAddressBookEntry[] = [];\n const contactsToDeleteLocally: SyncAddressBookEntry[] = [];\n const contactsToUpdateRemotely: AddressBookEntry[] = [];\n\n // SCENARIO 2 & 6: Process remote contacts - handle new device sync and remote updates\n for (const remoteContact of validRemoteContacts) {\n const key = createContactKey(remoteContact);\n const localContact = localContactsMap.get(key);\n\n // Handle remote contact based on its status and local existence\n if (remoteContact.deletedAt) {\n // SCENARIO 8: Remote deletion - should be applied locally if contact exists locally\n if (localContact) {\n contactsToDeleteLocally.push(remoteContact);\n }\n } else if (!localContact) {\n // SCENARIO 2: New contact from remote - import to local\n contactsToAddOrUpdateLocally.push(remoteContact);\n } else {\n // SCENARIO 4 & 6: Contact exists on both sides - check for conflicts\n const hasContentDifference =\n localContact.name !== remoteContact.name ||\n localContact.memo !== remoteContact.memo;\n\n if (hasContentDifference) {\n // Check timestamps to determine which version to keep\n const localTimestamp = localContact.lastUpdatedAt || 0;\n const remoteTimestamp = remoteContact.lastUpdatedAt || 0;\n\n if (localTimestamp >= remoteTimestamp) {\n // Local is newer (or same age) - use local version\n contactsToUpdateRemotely.push(localContact);\n } else {\n // Remote is newer - use remote version\n contactsToAddOrUpdateLocally.push(remoteContact);\n }\n }\n\n // Else: content is identical, no action needed\n }\n }\n\n // SCENARIO 1, 3 & 5: Process local contacts not in remote - handles first sync and new local contacts\n for (const localContact of localVisibleContacts) {\n const key = createContactKey(localContact);\n const remoteContact = remoteContactsMap.get(key);\n\n if (!remoteContact) {\n // New local contact or first sync - add to remote\n contactsToUpdateRemotely.push(localContact);\n }\n }\n\n // Apply local deletions\n // Note: Individual errors are intentionally NOT caught here to ensure they reach Sentry\n // for debugging. Previous versions silently suppressed these errors which made\n // troubleshooting contact sync issues difficult.\n for (const contact of contactsToDeleteLocally) {\n getMessenger().call(\n 'AddressBookController:delete',\n contact.chainId,\n contact.address,\n );\n\n if (onContactDeleted) {\n onContactDeleted();\n }\n }\n\n // Apply local additions/updates\n // Note: Individual errors are intentionally NOT caught here to ensure they reach Sentry\n // for debugging. Previous versions silently suppressed these errors which made\n // troubleshooting contact sync issues difficult.\n for (const contact of contactsToAddOrUpdateLocally) {\n if (!contact.deletedAt) {\n getMessenger().call(\n 'AddressBookController:set',\n contact.address,\n contact.name || '',\n contact.chainId,\n contact.memo || '',\n contact.addressType,\n );\n\n if (onContactUpdated) {\n onContactUpdated();\n }\n }\n }\n\n // Apply changes to remote storage\n if (contactsToUpdateRemotely.length > 0) {\n const updatedRemoteContacts: Record<string, SyncAddressBookEntry> = {};\n for (const localContact of contactsToUpdateRemotely) {\n const key = createContactKey(localContact);\n updatedRemoteContacts[key] = {\n ...remoteContactsMap.get(key), // Start with an existing remote contact if it exists\n ...localContact, // override with local changes\n lastUpdatedAt: Date.now(), // mark as updated\n };\n }\n // Save updated contacts to remote storage\n await saveContactsToUserStorage(\n Object.values(updatedRemoteContacts),\n options,\n );\n }\n } catch (error) {\n if (onContactSyncErroneousSituation) {\n onContactSyncErroneousSituation('Error synchronizing contacts', {\n error,\n });\n\n // Re-throw the error to be handled by the caller\n throw error;\n }\n } finally {\n await getUserStorageControllerInstance().setIsContactSyncingInProgress(\n false,\n );\n }\n };\n\n if (trace) {\n // Gather pre-sync metrics for performance analysis\n const initialLocalContacts = localVisibleContacts;\n const initialValidRemoteContacts = validRemoteContacts;\n\n await trace(\n {\n name: TraceName.ContactSyncFull,\n data: {\n localContactCount: initialLocalContacts.length,\n remoteContactCount: initialValidRemoteContacts.length,\n isFirstSync:\n initialValidRemoteContacts.length === 0 &&\n initialLocalContacts.length > 0,\n isNewDeviceSync:\n initialLocalContacts.length === 0 &&\n initialValidRemoteContacts.length > 0,\n isRegularSync:\n initialLocalContacts.length > 0 &&\n initialValidRemoteContacts.length > 0,\n hasDataToSync:\n initialLocalContacts.length > 0 ||\n initialValidRemoteContacts.length > 0,\n expectedWorkload:\n initialLocalContacts.length + initialValidRemoteContacts.length,\n },\n },\n performSync,\n );\n\n return;\n }\n\n await performSync();\n}\n\n/**\n * Retrieves remote contacts from user storage API\n *\n * @param options - Parameters used for retrieving remote contacts\n * @returns Array of contacts from remote storage, or null if none found\n */\nasync function getRemoteContacts(\n options: ContactSyncingOptions,\n): Promise<SyncAddressBookEntry[] | null> {\n const { getUserStorageControllerInstance } = options;\n\n try {\n const remoteContactsJsonArray =\n await getUserStorageControllerInstance().performGetStorageAllFeatureEntries(\n USER_STORAGE_FEATURE_NAMES.addressBook,\n );\n\n if (!remoteContactsJsonArray || remoteContactsJsonArray.length === 0) {\n return null;\n }\n\n // Parse each JSON entry and convert from UserStorageContactEntry to AddressBookEntry\n const remoteStorageEntries = remoteContactsJsonArray.map((contactJson) => {\n const entry = JSON.parse(contactJson) as UserStorageContactEntry;\n return mapUserStorageEntryToAddressBookEntry(entry);\n });\n\n return remoteStorageEntries;\n } catch {\n return null;\n }\n}\n\n/**\n * Saves local contacts to user storage\n *\n * @param contacts - The contacts to save to user storage\n * @param options - Parameters used for saving contacts\n * @returns Promise that resolves when contacts are saved\n */\nasync function saveContactsToUserStorage(\n contacts: AddressBookEntry[],\n options: ContactSyncingOptions,\n): Promise<void> {\n const { getUserStorageControllerInstance, trace } = options;\n\n const saveContacts = async () => {\n if (!contacts || contacts.length === 0) {\n return;\n }\n\n // Convert each AddressBookEntry to UserStorageContactEntry format and create key-value pairs\n const storageEntries: [string, string][] = contacts.map((contact) => {\n const key = createContactKey(contact);\n const storageEntry = mapAddressBookEntryToUserStorageEntry(contact);\n return [key, JSON.stringify(storageEntry)];\n });\n\n await getUserStorageControllerInstance().performBatchSetStorage(\n USER_STORAGE_FEATURE_NAMES.addressBook,\n storageEntries,\n );\n };\n\n return trace\n ? await trace(\n {\n name: TraceName.ContactSyncSaveBatch,\n data: {\n contactCount: contacts.length,\n // Performance scaling indicators\n hasBatchOperations: contacts.length > 1,\n chainCount: new Set(contacts.map((c) => c.chainId)).size,\n hasMemosCount: contacts.filter((c) => c.memo?.length).length,\n },\n },\n saveContacts,\n )\n : await saveContacts();\n}\n\n/**\n * Updates a single contact in remote storage without performing a full sync\n * This is used when a contact is updated locally to efficiently push changes to remote\n *\n * @param contact - The contact that was updated locally\n * @param options - Parameters used for syncing operations\n * @returns Promise that resolves when the contact is updated\n */\nexport async function updateContactInRemoteStorage(\n contact: AddressBookEntry,\n options: ContactSyncingOptions,\n): Promise<void> {\n const { trace } = options;\n\n const updateContact = async () => {\n if (\n !canPerformContactSyncing(options) ||\n !contact.address ||\n !contact.chainId ||\n !contact.name?.trim()\n ) {\n return;\n }\n\n const { getUserStorageControllerInstance } = options;\n\n // Create an updated entry with timestamp\n const updatedEntry = {\n ...contact,\n lastUpdatedAt: contact.lastUpdatedAt || Date.now(),\n } as SyncAddressBookEntry;\n\n const key = createContactKey(contact);\n const storageEntry = mapAddressBookEntryToUserStorageEntry(updatedEntry);\n\n // Save individual contact to remote storage\n await getUserStorageControllerInstance().performSetStorage(\n `${USER_STORAGE_FEATURE_NAMES.addressBook}.${key}`,\n JSON.stringify(storageEntry),\n );\n };\n\n if (trace) {\n return await trace(\n {\n name: TraceName.ContactSyncUpdateRemote,\n data: {\n chainId: contact.chainId,\n // Performance indicators\n hasTimestamp: Boolean(contact.lastUpdatedAt),\n hasMemo: Boolean(contact.memo?.length),\n isUpdate: Boolean(contact.lastUpdatedAt), // vs new contact\n },\n },\n updateContact,\n );\n }\n\n return await updateContact();\n}\n\n/**\n * Marks a single contact as deleted in remote storage without performing a full sync\n * This is used when a contact is deleted locally to efficiently push the deletion to remote\n *\n * @param contact - The contact that was deleted locally (contains at least address and chainId)\n * @param options - Parameters used for syncing operations\n * @returns Promise that resolves when the contact is marked as deleted\n */\nexport async function deleteContactInRemoteStorage(\n contact: AddressBookEntry,\n options: ContactSyncingOptions,\n): Promise<void> {\n const { trace } = options;\n const deleteContact = async () => {\n if (\n !canPerformContactSyncing(options) ||\n !contact.address ||\n !contact.chainId ||\n !contact.name?.trim()\n ) {\n return;\n }\n\n const { getUserStorageControllerInstance } = options;\n const key = createContactKey(contact);\n\n try {\n // Try to get the existing contact first\n const existingContactJson =\n await getUserStorageControllerInstance().performGetStorage(\n `${USER_STORAGE_FEATURE_NAMES.addressBook}.${key}`,\n );\n\n if (existingContactJson) {\n // Mark the existing contact as deleted\n const existingStorageEntry = JSON.parse(\n existingContactJson,\n ) as UserStorageContactEntry;\n const existingContact =\n mapUserStorageEntryToAddressBookEntry(existingStorageEntry);\n\n const now = Date.now();\n const deletedContact = {\n ...existingContact,\n deletedAt: now,\n lastUpdatedAt: now,\n } as SyncAddressBookEntry;\n\n const deletedStorageEntry =\n mapAddressBookEntryToUserStorageEntry(deletedContact);\n\n // Save the deleted contact back to storage\n await getUserStorageControllerInstance().performSetStorage(\n `${USER_STORAGE_FEATURE_NAMES.addressBook}.${key}`,\n JSON.stringify(deletedStorageEntry),\n );\n }\n } catch {\n // If contact doesn't exist in remote storage, no need to mark as deleted\n console.warn('Contact not found in remote storage for deletion:', key);\n }\n };\n\n return trace\n ? await trace({ name: TraceName.ContactSyncDeleteRemote }, deleteContact)\n : await deleteContact();\n}\n"]}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.setupContactSyncingSubscriptions = void 0;
|
|
4
|
+
const controller_integration_js_1 = require("./controller-integration.cjs");
|
|
5
|
+
const sync_utils_js_1 = require("./sync-utils.cjs");
|
|
6
|
+
const utils_js_1 = require("./utils.cjs");
|
|
7
|
+
/**
|
|
8
|
+
* Initialize and setup events to listen to for contact syncing
|
|
9
|
+
*
|
|
10
|
+
* @param options - parameters used for initializing and enabling contact syncing
|
|
11
|
+
*/
|
|
12
|
+
function setupContactSyncingSubscriptions(options) {
|
|
13
|
+
const { getMessenger } = options;
|
|
14
|
+
// Listen for contact updates and immediately sync the individual contact
|
|
15
|
+
getMessenger().subscribe('AddressBookController:contactUpdated', (contactEntry) => {
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
17
|
+
(async () => {
|
|
18
|
+
if (!(0, sync_utils_js_1.canPerformContactSyncing)(options) ||
|
|
19
|
+
(0, utils_js_1.isContactBridgedFromAccounts)(contactEntry)) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
// Use the targeted method to update just this contact
|
|
24
|
+
await (0, controller_integration_js_1.updateContactInRemoteStorage)(contactEntry, options);
|
|
25
|
+
}
|
|
26
|
+
catch (error) {
|
|
27
|
+
console.error('Error updating contact in remote storage:', error);
|
|
28
|
+
}
|
|
29
|
+
})();
|
|
30
|
+
});
|
|
31
|
+
// Listen for contact deletions and immediately sync the individual deletion
|
|
32
|
+
getMessenger().subscribe('AddressBookController:contactDeleted', (contactEntry) => {
|
|
33
|
+
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
|
34
|
+
(async () => {
|
|
35
|
+
if (!(0, sync_utils_js_1.canPerformContactSyncing)(options) ||
|
|
36
|
+
(0, utils_js_1.isContactBridgedFromAccounts)(contactEntry)) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
// Use the targeted method to delete just this contact
|
|
41
|
+
await (0, controller_integration_js_1.deleteContactInRemoteStorage)(contactEntry, options);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
console.error('Error deleting contact from remote storage:', error);
|
|
45
|
+
}
|
|
46
|
+
})();
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
exports.setupContactSyncingSubscriptions = setupContactSyncingSubscriptions;
|
|
50
|
+
//# sourceMappingURL=setup-subscriptions.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"setup-subscriptions.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/contact-syncing/setup-subscriptions.ts"],"names":[],"mappings":";;;AAEA,4EAGqC;AACrC,oDAA2D;AAE3D,0CAA0D;AAE1D;;;;GAIG;AACH,SAAgB,gCAAgC,CAC9C,OAA8B;IAE9B,MAAM,EAAE,YAAY,EAAE,GAAG,OAAO,CAAC;IAEjC,yEAAyE;IACzE,YAAY,EAAE,CAAC,SAAS,CACtB,sCAAsC,EACtC,CAAC,YAA8B,EAAE,EAAE;QACjC,mEAAmE;QACnE,CAAC,KAAK,IAAI,EAAE;YACV,IACE,CAAC,IAAA,wCAAwB,EAAC,OAAO,CAAC;gBAClC,IAAA,uCAA4B,EAAC,YAAY,CAAC,EAC1C,CAAC;gBACD,OAAO;YACT,CAAC;YAED,IAAI,CAAC;gBACH,sDAAsD;gBACtD,MAAM,IAAA,wDAA4B,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;YAC5D,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,2CAA2C,EAAE,KAAK,CAAC,CAAC;YACpE,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;IACP,CAAC,CACF,CAAC;IAEF,4EAA4E;IAC5E,YAAY,EAAE,CAAC,SAAS,CACtB,sCAAsC,EACtC,CAAC,YAA8B,EAAE,EAAE;QACjC,mEAAmE;QACnE,CAAC,KAAK,IAAI,EAAE;YACV,IACE,CAAC,IAAA,wCAAwB,EAAC,OAAO,CAAC;gBAClC,IAAA,uCAA4B,EAAC,YAAY,CAAC,EAC1C,CAAC;gBACD,OAAO;YACT,CAAC;YAED,IAAI,CAAC;gBACH,sDAAsD;gBACtD,MAAM,IAAA,wDAA4B,EAAC,YAAY,EAAE,OAAO,CAAC,CAAC;YAC5D,CAAC;YAAC,OAAO,KAAK,EAAE,CAAC;gBACf,OAAO,CAAC,KAAK,CAAC,6CAA6C,EAAE,KAAK,CAAC,CAAC;YACtE,CAAC;QACH,CAAC,CAAC,EAAE,CAAC;IACP,CAAC,CACF,CAAC;AACJ,CAAC;AAlDD,4EAkDC","sourcesContent":["import type { AddressBookEntry } from '@metamask/address-book-controller';\n\nimport {\n updateContactInRemoteStorage,\n deleteContactInRemoteStorage,\n} from './controller-integration.js';\nimport { canPerformContactSyncing } from './sync-utils.js';\nimport type { ContactSyncingOptions } from './types.js';\nimport { isContactBridgedFromAccounts } from './utils.js';\n\n/**\n * Initialize and setup events to listen to for contact syncing\n *\n * @param options - parameters used for initializing and enabling contact syncing\n */\nexport function setupContactSyncingSubscriptions(\n options: ContactSyncingOptions,\n): void {\n const { getMessenger } = options;\n\n // Listen for contact updates and immediately sync the individual contact\n getMessenger().subscribe(\n 'AddressBookController:contactUpdated',\n (contactEntry: AddressBookEntry) => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n (async () => {\n if (\n !canPerformContactSyncing(options) ||\n isContactBridgedFromAccounts(contactEntry)\n ) {\n return;\n }\n\n try {\n // Use the targeted method to update just this contact\n await updateContactInRemoteStorage(contactEntry, options);\n } catch (error) {\n console.error('Error updating contact in remote storage:', error);\n }\n })();\n },\n );\n\n // Listen for contact deletions and immediately sync the individual deletion\n getMessenger().subscribe(\n 'AddressBookController:contactDeleted',\n (contactEntry: AddressBookEntry) => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n (async () => {\n if (\n !canPerformContactSyncing(options) ||\n isContactBridgedFromAccounts(contactEntry)\n ) {\n return;\n }\n\n try {\n // Use the targeted method to delete just this contact\n await deleteContactInRemoteStorage(contactEntry, options);\n } catch (error) {\n console.error('Error deleting contact from remote storage:', error);\n }\n })();\n },\n );\n}\n"]}
|