@metamask-previews/profile-sync-controller 19.0.0-preview-6fc9506d → 19.0.0-preview-83aa339c

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.
Files changed (92) hide show
  1. package/CHANGELOG.md +2 -1
  2. package/dist/controllers/authentication/AuthenticationController.cjs +5 -0
  3. package/dist/controllers/authentication/AuthenticationController.cjs.map +1 -1
  4. package/dist/controllers/authentication/AuthenticationController.d.cts +4 -2
  5. package/dist/controllers/authentication/AuthenticationController.d.cts.map +1 -1
  6. package/dist/controllers/authentication/AuthenticationController.d.mts +4 -2
  7. package/dist/controllers/authentication/AuthenticationController.d.mts.map +1 -1
  8. package/dist/controllers/authentication/AuthenticationController.mjs +5 -0
  9. package/dist/controllers/authentication/AuthenticationController.mjs.map +1 -1
  10. package/dist/controllers/user-storage/UserStorageController.cjs +3 -10
  11. package/dist/controllers/user-storage/UserStorageController.cjs.map +1 -1
  12. package/dist/controllers/user-storage/UserStorageController.d.cts +1 -3
  13. package/dist/controllers/user-storage/UserStorageController.d.cts.map +1 -1
  14. package/dist/controllers/user-storage/UserStorageController.d.mts +1 -3
  15. package/dist/controllers/user-storage/UserStorageController.d.mts.map +1 -1
  16. package/dist/controllers/user-storage/UserStorageController.mjs +3 -10
  17. package/dist/controllers/user-storage/UserStorageController.mjs.map +1 -1
  18. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs +168 -184
  19. package/dist/controllers/user-storage/account-syncing/controller-integration.cjs.map +1 -1
  20. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts +0 -3
  21. package/dist/controllers/user-storage/account-syncing/controller-integration.d.cts.map +1 -1
  22. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts +0 -3
  23. package/dist/controllers/user-storage/account-syncing/controller-integration.d.mts.map +1 -1
  24. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs +168 -184
  25. package/dist/controllers/user-storage/account-syncing/controller-integration.mjs.map +1 -1
  26. package/dist/controllers/user-storage/account-syncing/types.cjs.map +1 -1
  27. package/dist/controllers/user-storage/account-syncing/types.d.cts +0 -2
  28. package/dist/controllers/user-storage/account-syncing/types.d.cts.map +1 -1
  29. package/dist/controllers/user-storage/account-syncing/types.d.mts +0 -2
  30. package/dist/controllers/user-storage/account-syncing/types.d.mts.map +1 -1
  31. package/dist/controllers/user-storage/account-syncing/types.mjs.map +1 -1
  32. package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs +166 -233
  33. package/dist/controllers/user-storage/contact-syncing/controller-integration.cjs.map +1 -1
  34. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.cts +0 -3
  35. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.cts.map +1 -1
  36. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts +0 -3
  37. package/dist/controllers/user-storage/contact-syncing/controller-integration.d.mts.map +1 -1
  38. package/dist/controllers/user-storage/contact-syncing/controller-integration.mjs +166 -233
  39. package/dist/controllers/user-storage/contact-syncing/controller-integration.mjs.map +1 -1
  40. package/dist/controllers/user-storage/contact-syncing/types.cjs.map +1 -1
  41. package/dist/controllers/user-storage/contact-syncing/types.d.cts +0 -2
  42. package/dist/controllers/user-storage/contact-syncing/types.d.cts.map +1 -1
  43. package/dist/controllers/user-storage/contact-syncing/types.d.mts +0 -2
  44. package/dist/controllers/user-storage/contact-syncing/types.d.mts.map +1 -1
  45. package/dist/controllers/user-storage/contact-syncing/types.mjs.map +1 -1
  46. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs +4 -0
  47. package/dist/sdk/authentication-jwt-bearer/flow-siwe.cjs.map +1 -1
  48. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts +2 -1
  49. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.cts.map +1 -1
  50. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts +2 -1
  51. package/dist/sdk/authentication-jwt-bearer/flow-siwe.d.mts.map +1 -1
  52. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs +5 -1
  53. package/dist/sdk/authentication-jwt-bearer/flow-siwe.mjs.map +1 -1
  54. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs +4 -0
  55. package/dist/sdk/authentication-jwt-bearer/flow-srp.cjs.map +1 -1
  56. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts +2 -1
  57. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.cts.map +1 -1
  58. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts +2 -1
  59. package/dist/sdk/authentication-jwt-bearer/flow-srp.d.mts.map +1 -1
  60. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs +5 -1
  61. package/dist/sdk/authentication-jwt-bearer/flow-srp.mjs.map +1 -1
  62. package/dist/sdk/authentication-jwt-bearer/services.cjs +33 -1
  63. package/dist/sdk/authentication-jwt-bearer/services.cjs.map +1 -1
  64. package/dist/sdk/authentication-jwt-bearer/services.d.cts +10 -1
  65. package/dist/sdk/authentication-jwt-bearer/services.d.cts.map +1 -1
  66. package/dist/sdk/authentication-jwt-bearer/services.d.mts +10 -1
  67. package/dist/sdk/authentication-jwt-bearer/services.d.mts.map +1 -1
  68. package/dist/sdk/authentication-jwt-bearer/services.mjs +30 -0
  69. package/dist/sdk/authentication-jwt-bearer/services.mjs.map +1 -1
  70. package/dist/sdk/authentication-jwt-bearer/types.cjs.map +1 -1
  71. package/dist/sdk/authentication-jwt-bearer/types.d.cts +11 -0
  72. package/dist/sdk/authentication-jwt-bearer/types.d.cts.map +1 -1
  73. package/dist/sdk/authentication-jwt-bearer/types.d.mts +11 -0
  74. package/dist/sdk/authentication-jwt-bearer/types.d.mts.map +1 -1
  75. package/dist/sdk/authentication-jwt-bearer/types.mjs.map +1 -1
  76. package/dist/sdk/authentication.cjs +3 -0
  77. package/dist/sdk/authentication.cjs.map +1 -1
  78. package/dist/sdk/authentication.d.cts +2 -1
  79. package/dist/sdk/authentication.d.cts.map +1 -1
  80. package/dist/sdk/authentication.d.mts +2 -1
  81. package/dist/sdk/authentication.d.mts.map +1 -1
  82. package/dist/sdk/authentication.mjs +3 -0
  83. package/dist/sdk/authentication.mjs.map +1 -1
  84. package/dist/sdk/mocks/auth.cjs +22 -1
  85. package/dist/sdk/mocks/auth.cjs.map +1 -1
  86. package/dist/sdk/mocks/auth.d.cts +13 -0
  87. package/dist/sdk/mocks/auth.d.cts.map +1 -1
  88. package/dist/sdk/mocks/auth.d.mts +13 -0
  89. package/dist/sdk/mocks/auth.d.mts.map +1 -1
  90. package/dist/sdk/mocks/auth.mjs +23 -2
  91. package/dist/sdk/mocks/auth.mjs.map +1 -1
  92. package/package.json +2 -2
@@ -1 +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;AAG1E,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAgB;AAUrD,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,CAuNf;AAmFD;;;;;;;GAOG;AACH,wBAAsB,4BAA4B,CAChD,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CA8Cf;AAED;;;;;;;GAOG;AACH,wBAAsB,4BAA4B,CAChD,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAwDf"}
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;AAG1E,OAAO,KAAK,EAAE,qBAAqB,EAAE,oBAAgB;AAUrD,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;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAsB,2BAA2B,CAC/C,MAAM,EAAE,iCAAiC,EACzC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAgLf;AAgED;;;;;;GAMG;AACH,wBAAsB,4BAA4B,CAChD,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CA0Bf;AAED;;;;;;GAMG;AACH,wBAAsB,4BAA4B,CAChD,OAAO,EAAE,gBAAgB,EACzB,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAgDf"}
@@ -32,167 +32,138 @@ function createContactKey(contact) {
32
32
  *
33
33
  * @param config - Parameters used for syncing callbacks
34
34
  * @param options - Parameters used for syncing operations
35
- * @returns Promise that resolves when contact synchronization is complete
36
35
  */
37
36
  export async function syncContactsWithUserStorage(config, options) {
38
- const { getMessenger, getUserStorageControllerInstance, trace } = options;
37
+ const { getMessenger, getUserStorageControllerInstance } = options;
39
38
  const { onContactSyncErroneousSituation, onContactUpdated, onContactDeleted, } = config;
40
- let localVisibleContacts = [];
41
- let validRemoteContacts = [];
42
- const performSync = async () => {
43
- try {
44
- // Cannot perform sync, conditions not met
45
- if (!canPerformContactSyncing(options)) {
46
- return;
39
+ try {
40
+ // Cannot perform sync, conditions not met
41
+ if (!canPerformContactSyncing(options)) {
42
+ return;
43
+ }
44
+ // Activate sync semaphore to prevent event loops
45
+ await getUserStorageControllerInstance().setIsContactSyncingInProgress(true);
46
+ // Get all local contacts from AddressBookController (exclude chain "*" contacts)
47
+ const localVisibleContacts = getMessenger()
48
+ .call('AddressBookController:list')
49
+ .filter((contact) => !isContactBridgedFromAccounts(contact))
50
+ .filter((contact) => contact.address && contact.chainId && contact.name?.trim()) || [];
51
+ // Get remote contacts from user storage API
52
+ const remoteContacts = await getRemoteContacts(options);
53
+ // Filter remote contacts to exclude invalid ones (or empty array if no remote contacts)
54
+ const validRemoteContacts = remoteContacts?.filter((contact) => contact.address && contact.chainId && contact.name?.trim()) || [];
55
+ // Prepare maps for efficient lookup
56
+ const localContactsMap = new Map();
57
+ const remoteContactsMap = new Map();
58
+ localVisibleContacts.forEach((contact) => {
59
+ const key = createContactKey(contact);
60
+ localContactsMap.set(key, contact);
61
+ });
62
+ validRemoteContacts.forEach((contact) => {
63
+ const key = createContactKey(contact);
64
+ remoteContactsMap.set(key, contact);
65
+ });
66
+ // Lists to track contacts that need to be synced
67
+ const contactsToAddOrUpdateLocally = [];
68
+ const contactsToDeleteLocally = [];
69
+ const contactsToUpdateRemotely = [];
70
+ // SCENARIO 2 & 6: Process remote contacts - handle new device sync and remote updates
71
+ for (const remoteContact of validRemoteContacts) {
72
+ const key = createContactKey(remoteContact);
73
+ const localContact = localContactsMap.get(key);
74
+ // Handle remote contact based on its status and local existence
75
+ if (remoteContact.deletedAt) {
76
+ // SCENARIO 8: Remote deletion - should be applied locally if contact exists locally
77
+ if (localContact) {
78
+ contactsToDeleteLocally.push(remoteContact);
79
+ }
47
80
  }
48
- // Activate sync semaphore to prevent event loops
49
- await getUserStorageControllerInstance().setIsContactSyncingInProgress(true);
50
- // Get all local contacts from AddressBookController (exclude chain "*" contacts)
51
- localVisibleContacts =
52
- getMessenger()
53
- .call('AddressBookController:list')
54
- .filter((contact) => !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
- validRemoteContacts =
60
- remoteContacts?.filter((contact) => contact.address && contact.chainId && contact.name?.trim()) || [];
61
- // Prepare maps for efficient lookup
62
- const localContactsMap = new Map();
63
- const remoteContactsMap = new Map();
64
- localVisibleContacts.forEach((contact) => {
65
- const key = createContactKey(contact);
66
- localContactsMap.set(key, contact);
67
- });
68
- validRemoteContacts.forEach((contact) => {
69
- const key = createContactKey(contact);
70
- remoteContactsMap.set(key, contact);
71
- });
72
- // Lists to track contacts that need to be synced
73
- const contactsToAddOrUpdateLocally = [];
74
- const contactsToDeleteLocally = [];
75
- const contactsToUpdateRemotely = [];
76
- // SCENARIO 2 & 6: Process remote contacts - handle new device sync and remote updates
77
- for (const remoteContact of validRemoteContacts) {
78
- const key = createContactKey(remoteContact);
79
- const localContact = localContactsMap.get(key);
80
- // Handle remote contact based on its status and local existence
81
- if (remoteContact.deletedAt) {
82
- // SCENARIO 8: Remote deletion - should be applied locally if contact exists locally
83
- if (localContact) {
84
- contactsToDeleteLocally.push(remoteContact);
81
+ else if (!localContact) {
82
+ // SCENARIO 2: New contact from remote - import to local
83
+ contactsToAddOrUpdateLocally.push(remoteContact);
84
+ }
85
+ else {
86
+ // SCENARIO 4 & 6: Contact exists on both sides - check for conflicts
87
+ const hasContentDifference = localContact.name !== remoteContact.name ||
88
+ localContact.memo !== remoteContact.memo;
89
+ if (hasContentDifference) {
90
+ // Check timestamps to determine which version to keep
91
+ const localTimestamp = localContact.lastUpdatedAt || 0;
92
+ const remoteTimestamp = remoteContact.lastUpdatedAt || 0;
93
+ if (localTimestamp >= remoteTimestamp) {
94
+ // Local is newer (or same age) - use local version
95
+ contactsToUpdateRemotely.push(localContact);
85
96
  }
86
- }
87
- else if (!localContact) {
88
- // SCENARIO 2: New contact from remote - import to local
89
- contactsToAddOrUpdateLocally.push(remoteContact);
90
- }
91
- else {
92
- // SCENARIO 4 & 6: Contact exists on both sides - check for conflicts
93
- const hasContentDifference = localContact.name !== remoteContact.name ||
94
- localContact.memo !== remoteContact.memo;
95
- if (hasContentDifference) {
96
- // Check timestamps to determine which version to keep
97
- const localTimestamp = localContact.lastUpdatedAt || 0;
98
- const remoteTimestamp = remoteContact.lastUpdatedAt || 0;
99
- if (localTimestamp >= remoteTimestamp) {
100
- // Local is newer (or same age) - use local version
101
- contactsToUpdateRemotely.push(localContact);
102
- }
103
- else {
104
- // Remote is newer - use remote version
105
- contactsToAddOrUpdateLocally.push(remoteContact);
106
- }
97
+ else {
98
+ // Remote is newer - use remote version
99
+ contactsToAddOrUpdateLocally.push(remoteContact);
107
100
  }
108
- // Else: content is identical, no action needed
109
101
  }
102
+ // Else: content is identical, no action needed
110
103
  }
111
- // SCENARIO 1, 3 & 5: Process local contacts not in remote - handles first sync and new local contacts
112
- for (const localContact of localVisibleContacts) {
113
- const key = createContactKey(localContact);
114
- const remoteContact = remoteContactsMap.get(key);
115
- if (!remoteContact) {
116
- // New local contact or first sync - add to remote
117
- contactsToUpdateRemotely.push(localContact);
104
+ }
105
+ // SCENARIO 1, 3 & 5: Process local contacts not in remote - handles first sync and new local contacts
106
+ for (const localContact of localVisibleContacts) {
107
+ const key = createContactKey(localContact);
108
+ const remoteContact = remoteContactsMap.get(key);
109
+ if (!remoteContact) {
110
+ // New local contact or first sync - add to remote
111
+ contactsToUpdateRemotely.push(localContact);
112
+ }
113
+ }
114
+ // Apply local deletions
115
+ for (const contact of contactsToDeleteLocally) {
116
+ try {
117
+ getMessenger().call('AddressBookController:delete', contact.chainId, contact.address);
118
+ if (onContactDeleted) {
119
+ onContactDeleted();
118
120
  }
119
121
  }
120
- // Apply local deletions
121
- for (const contact of contactsToDeleteLocally) {
122
+ catch (error) {
123
+ console.error('Error deleting contact:', error);
124
+ }
125
+ }
126
+ // Apply local additions/updates
127
+ for (const contact of contactsToAddOrUpdateLocally) {
128
+ if (!contact.deletedAt) {
122
129
  try {
123
- getMessenger().call('AddressBookController:delete', contact.chainId, contact.address);
124
- if (onContactDeleted) {
125
- onContactDeleted();
130
+ getMessenger().call('AddressBookController:set', contact.address, contact.name || '', contact.chainId, contact.memo || '', contact.addressType);
131
+ if (onContactUpdated) {
132
+ onContactUpdated();
126
133
  }
127
134
  }
128
135
  catch (error) {
129
- console.error('Error deleting contact:', error);
130
- }
131
- }
132
- // Apply local additions/updates
133
- for (const contact of contactsToAddOrUpdateLocally) {
134
- if (!contact.deletedAt) {
135
- try {
136
- getMessenger().call('AddressBookController:set', contact.address, contact.name || '', contact.chainId, contact.memo || '', contact.addressType);
137
- if (onContactUpdated) {
138
- onContactUpdated();
139
- }
140
- }
141
- catch (error) {
142
- console.error('Error updating contact:', error);
143
- }
144
- }
145
- }
146
- // Apply changes to remote storage
147
- if (contactsToUpdateRemotely.length > 0) {
148
- const updatedRemoteContacts = {};
149
- for (const localContact of contactsToUpdateRemotely) {
150
- const key = createContactKey(localContact);
151
- updatedRemoteContacts[key] = {
152
- ...remoteContactsMap.get(key),
153
- ...localContact,
154
- lastUpdatedAt: Date.now(), // mark as updated
155
- };
136
+ console.error('Error updating contact:', error);
156
137
  }
157
- // Save updated contacts to remote storage
158
- await saveContactsToUserStorage(Object.values(updatedRemoteContacts), options);
159
138
  }
160
139
  }
161
- catch (error) {
162
- if (onContactSyncErroneousSituation) {
163
- onContactSyncErroneousSituation('Error synchronizing contacts', {
164
- error,
165
- });
166
- // Re-throw the error to be handled by the caller
167
- throw error;
140
+ // Apply changes to remote storage
141
+ if (contactsToUpdateRemotely.length > 0) {
142
+ const updatedRemoteContacts = {};
143
+ for (const localContact of contactsToUpdateRemotely) {
144
+ const key = createContactKey(localContact);
145
+ updatedRemoteContacts[key] = {
146
+ ...remoteContactsMap.get(key),
147
+ ...localContact,
148
+ lastUpdatedAt: Date.now(), // mark as updated
149
+ };
168
150
  }
151
+ // Save updated contacts to remote storage
152
+ await saveContactsToUserStorage(Object.values(updatedRemoteContacts), options);
169
153
  }
170
- finally {
171
- await getUserStorageControllerInstance().setIsContactSyncingInProgress(false);
154
+ }
155
+ catch (error) {
156
+ if (onContactSyncErroneousSituation) {
157
+ onContactSyncErroneousSituation('Error synchronizing contacts', {
158
+ error,
159
+ });
160
+ // Re-throw the error to be handled by the caller
161
+ throw error;
172
162
  }
173
- };
174
- if (trace) {
175
- // Gather pre-sync metrics for performance analysis
176
- const initialLocalContacts = localVisibleContacts;
177
- const initialValidRemoteContacts = validRemoteContacts;
178
- return await trace({
179
- name: 'Contact Sync Full',
180
- data: {
181
- localContactCount: initialLocalContacts.length,
182
- remoteContactCount: initialValidRemoteContacts.length,
183
- isFirstSync: initialValidRemoteContacts.length === 0 &&
184
- initialLocalContacts.length > 0,
185
- isNewDeviceSync: initialLocalContacts.length === 0 &&
186
- initialValidRemoteContacts.length > 0,
187
- isRegularSync: initialLocalContacts.length > 0 &&
188
- initialValidRemoteContacts.length > 0,
189
- hasDataToSync: initialLocalContacts.length > 0 ||
190
- initialValidRemoteContacts.length > 0,
191
- expectedWorkload: initialLocalContacts.length + initialValidRemoteContacts.length,
192
- },
193
- }, performSync);
194
163
  }
195
- return await performSync();
164
+ finally {
165
+ await getUserStorageControllerInstance().setIsContactSyncingInProgress(false);
166
+ }
196
167
  }
197
168
  /**
198
169
  * Retrieves remote contacts from user storage API
@@ -223,34 +194,19 @@ async function getRemoteContacts(options) {
223
194
  *
224
195
  * @param contacts - The contacts to save to user storage
225
196
  * @param options - Parameters used for saving contacts
226
- * @returns Promise that resolves when contacts are saved
227
197
  */
228
198
  async function saveContactsToUserStorage(contacts, options) {
229
- const { getUserStorageControllerInstance, trace } = options;
230
- const saveContacts = async () => {
231
- if (!contacts || contacts.length === 0) {
232
- return;
233
- }
234
- // Convert each AddressBookEntry to UserStorageContactEntry format and create key-value pairs
235
- const storageEntries = contacts.map((contact) => {
236
- const key = createContactKey(contact);
237
- const storageEntry = mapAddressBookEntryToUserStorageEntry(contact);
238
- return [key, JSON.stringify(storageEntry)];
239
- });
240
- await getUserStorageControllerInstance().performBatchSetStorage(USER_STORAGE_FEATURE_NAMES.addressBook, storageEntries);
241
- };
242
- return trace
243
- ? await trace({
244
- name: 'Contact Sync Save Batch',
245
- data: {
246
- contactCount: contacts.length,
247
- // Performance scaling indicators
248
- hasBatchOperations: contacts.length > 1,
249
- chainCount: new Set(contacts.map((c) => c.chainId)).size,
250
- hasMemosCount: contacts.filter((c) => c.memo?.length).length,
251
- },
252
- }, saveContacts)
253
- : await saveContacts();
199
+ const { getUserStorageControllerInstance } = options;
200
+ if (!contacts || contacts.length === 0) {
201
+ return;
202
+ }
203
+ // Convert each AddressBookEntry to UserStorageContactEntry format and create key-value pairs
204
+ const storageEntries = contacts.map((contact) => {
205
+ const key = createContactKey(contact);
206
+ const storageEntry = mapAddressBookEntryToUserStorageEntry(contact);
207
+ return [key, JSON.stringify(storageEntry)];
208
+ });
209
+ await getUserStorageControllerInstance().performBatchSetStorage(USER_STORAGE_FEATURE_NAMES.addressBook, storageEntries);
254
210
  }
255
211
  /**
256
212
  * Updates a single contact in remote storage without performing a full sync
@@ -258,40 +214,24 @@ async function saveContactsToUserStorage(contacts, options) {
258
214
  *
259
215
  * @param contact - The contact that was updated locally
260
216
  * @param options - Parameters used for syncing operations
261
- * @returns Promise that resolves when the contact is updated
262
217
  */
263
218
  export async function updateContactInRemoteStorage(contact, options) {
264
- const { trace } = options;
265
- const updateContact = async () => {
266
- if (!canPerformContactSyncing(options) ||
267
- !contact.address ||
268
- !contact.chainId ||
269
- !contact.name?.trim()) {
270
- return;
271
- }
272
- const { getUserStorageControllerInstance } = options;
273
- // Create an updated entry with timestamp
274
- const updatedEntry = {
275
- ...contact,
276
- lastUpdatedAt: contact.lastUpdatedAt || Date.now(),
277
- };
278
- const key = createContactKey(contact);
279
- const storageEntry = mapAddressBookEntryToUserStorageEntry(updatedEntry);
280
- // Save individual contact to remote storage
281
- await getUserStorageControllerInstance().performSetStorage(`${USER_STORAGE_FEATURE_NAMES.addressBook}.${key}`, JSON.stringify(storageEntry));
219
+ if (!canPerformContactSyncing(options) ||
220
+ !contact.address ||
221
+ !contact.chainId ||
222
+ !contact.name?.trim()) {
223
+ return;
224
+ }
225
+ const { getUserStorageControllerInstance } = options;
226
+ // Create an updated entry with timestamp
227
+ const updatedEntry = {
228
+ ...contact,
229
+ lastUpdatedAt: contact.lastUpdatedAt || Date.now(),
282
230
  };
283
- return trace
284
- ? await trace({
285
- name: 'Contact Sync Update Remote',
286
- data: {
287
- chainId: contact.chainId,
288
- // Performance indicators
289
- hasTimestamp: Boolean(contact.lastUpdatedAt),
290
- hasMemo: Boolean(contact.memo?.length),
291
- isUpdate: Boolean(contact.lastUpdatedAt), // vs new contact
292
- },
293
- }, updateContact)
294
- : await updateContact();
231
+ const key = createContactKey(contact);
232
+ const storageEntry = mapAddressBookEntryToUserStorageEntry(updatedEntry);
233
+ // Save individual contact to remote storage
234
+ await getUserStorageControllerInstance().performSetStorage(`${USER_STORAGE_FEATURE_NAMES.addressBook}.${key}`, JSON.stringify(storageEntry));
295
235
  }
296
236
  /**
297
237
  * Marks a single contact as deleted in remote storage without performing a full sync
@@ -299,44 +239,37 @@ export async function updateContactInRemoteStorage(contact, options) {
299
239
  *
300
240
  * @param contact - The contact that was deleted locally (contains at least address and chainId)
301
241
  * @param options - Parameters used for syncing operations
302
- * @returns Promise that resolves when the contact is marked as deleted
303
242
  */
304
243
  export async function deleteContactInRemoteStorage(contact, options) {
305
- const { trace } = options;
306
- const deleteContact = async () => {
307
- if (!canPerformContactSyncing(options) ||
308
- !contact.address ||
309
- !contact.chainId ||
310
- !contact.name?.trim()) {
311
- return;
312
- }
313
- const { getUserStorageControllerInstance } = options;
314
- const key = createContactKey(contact);
315
- try {
316
- // Try to get the existing contact first
317
- const existingContactJson = await getUserStorageControllerInstance().performGetStorage(`${USER_STORAGE_FEATURE_NAMES.addressBook}.${key}`);
318
- if (existingContactJson) {
319
- // Mark the existing contact as deleted
320
- const existingStorageEntry = JSON.parse(existingContactJson);
321
- const existingContact = mapUserStorageEntryToAddressBookEntry(existingStorageEntry);
322
- const now = Date.now();
323
- const deletedContact = {
324
- ...existingContact,
325
- deletedAt: now,
326
- lastUpdatedAt: now,
327
- };
328
- const deletedStorageEntry = mapAddressBookEntryToUserStorageEntry(deletedContact);
329
- // Save the deleted contact back to storage
330
- await getUserStorageControllerInstance().performSetStorage(`${USER_STORAGE_FEATURE_NAMES.addressBook}.${key}`, JSON.stringify(deletedStorageEntry));
331
- }
332
- }
333
- catch {
334
- // If contact doesn't exist in remote storage, no need to mark as deleted
335
- console.warn('Contact not found in remote storage for deletion:', key);
244
+ if (!canPerformContactSyncing(options) ||
245
+ !contact.address ||
246
+ !contact.chainId ||
247
+ !contact.name?.trim()) {
248
+ return;
249
+ }
250
+ const { getUserStorageControllerInstance } = options;
251
+ const key = createContactKey(contact);
252
+ try {
253
+ // Try to get the existing contact first
254
+ const existingContactJson = await getUserStorageControllerInstance().performGetStorage(`${USER_STORAGE_FEATURE_NAMES.addressBook}.${key}`);
255
+ if (existingContactJson) {
256
+ // Mark the existing contact as deleted
257
+ const existingStorageEntry = JSON.parse(existingContactJson);
258
+ const existingContact = mapUserStorageEntryToAddressBookEntry(existingStorageEntry);
259
+ const now = Date.now();
260
+ const deletedContact = {
261
+ ...existingContact,
262
+ deletedAt: now,
263
+ lastUpdatedAt: now,
264
+ };
265
+ const deletedStorageEntry = mapAddressBookEntryToUserStorageEntry(deletedContact);
266
+ // Save the deleted contact back to storage
267
+ await getUserStorageControllerInstance().performSetStorage(`${USER_STORAGE_FEATURE_NAMES.addressBook}.${key}`, JSON.stringify(deletedStorageEntry));
336
268
  }
337
- };
338
- return trace
339
- ? await trace({ name: 'Contact Sync Delete Remote' }, deleteContact)
340
- : await deleteContact();
269
+ }
270
+ catch {
271
+ // If contact doesn't exist in remote storage, no need to mark as deleted
272
+ console.warn('Contact not found in remote storage for deletion:', key);
273
+ }
341
274
  }
342
275
  //# sourceMappingURL=controller-integration.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"controller-integration.mjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/contact-syncing/controller-integration.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,wBAAwB,EAAE,yBAAqB;AAGxD,OAAO,EACL,qCAAqC,EACrC,qCAAqC,EAEtC,oBAAgB;AACjB,OAAO,EAAE,4BAA4B,EAAE,oBAAgB;AACvD,OAAO,EAAE,0BAA0B,EAAE,2CAAuC;AAW5E;;;;;GAKG;AACH,SAAS,gBAAgB,CAAC,OAAyB;IACjD,IAAI,CAAC,OAAO,CAAC,OAAO,EAAE;QACpB,MAAM,IAAI,KAAK,CAAC,mDAAmD,CAAC,CAAC;KACtE;IACD,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,OAAO,CAAC,OAAO,CAAC,WAAW,EAAE,EAAE,CAAC;AAC/D,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,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,IAAI,oBAAoB,GAAuB,EAAE,CAAC;IAClD,IAAI,mBAAmB,GAA2B,EAAE,CAAC;IAErD,MAAM,WAAW,GAAG,KAAK,IAAI,EAAE;QAC7B,IAAI;YACF,0CAA0C;YAC1C,IAAI,CAAC,wBAAwB,CAAC,OAAO,CAAC,EAAE;gBACtC,OAAO;aACR;YAED,iDAAiD;YACjD,MAAM,gCA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ACvB,MAAM,gCAAgC,EAAE,CAAC,iBAAiB,CACxD,GAAG,0BAA0B,CAAC,WAAW,IAAI,GAAG,EAAE,CACnD,CAAC;YAEJ,IAAI,mBAAmB,EAAE;gBACvB,uCAAuC;gBACvC,MAAM,oBAAoB,GAAG,IAAI,CAAC,KAAK,CACrC,mBAAmB,CACO,CAAC;gBAC7B,MAAM,eAAe,GACnB,qCAAqC,CAAC,oBAAoB,CAAC,CAAC;gBAE9D,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;gBACvB,MAAM,cAAc,GAAG;oBACrB,GAAG,eAAe;oBAClB,SAAS,EAAE,GAAG;oBACd,aAAa,EAAE,GAAG;iBACK,CAAC;gBAE1B,MAAM,mBAAmB,GACvB,qCAAqC,CAAC,cAAc,CAAC,CAAC;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;aACH;SACF;QAAC,MAAM;YACN,yEAAyE;YACzE,OAAO,CAAC,IAAI,CAAC,mDAAmD,EAAE,GAAG,CAAC,CAAC;SACxE;IACH,CAAC,CAAC;IAEF,OAAO,KAAK;QACV,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,IAAI,EAAE,4BAA4B,EAAE,EAAE,aAAa,CAAC;QACpE,CAAC,CAAC,MAAM,aAAa,EAAE,CAAC;AAC5B,CAAC","sourcesContent":["import type { AddressBookEntry } from '@metamask/address-book-controller';\n\nimport { canPerformContactSyncing } from './sync-utils';\nimport type { ContactSyncingOptions } from './types';\nimport type { UserStorageContactEntry } from './types';\nimport {\n mapAddressBookEntryToUserStorageEntry,\n mapUserStorageEntryToAddressBookEntry,\n type SyncAddressBookEntry,\n} from './utils';\nimport { isContactBridgedFromAccounts } from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\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 let localVisibleContacts: AddressBookEntry[] = [];\n let validRemoteContacts: SyncAddressBookEntry[] = [];\n\n const performSync = async () => {\n try {\n // Cannot perform sync, conditions not met\n if (!canPerformContactSyncing(options)) {\n return;\n }\n\n // Activate sync semaphore to prevent event loops\n await getUserStorageControllerInstance().setIsContactSyncingInProgress(\n true,\n );\n\n // Get all local contacts from AddressBookController (exclude chain \"*\" contacts)\n localVisibleContacts =\n getMessenger()\n .call('AddressBookController:list')\n .filter((contact) => !isContactBridgedFromAccounts(contact))\n .filter(\n (contact) =>\n 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 validRemoteContacts =\n remoteContacts?.filter(\n (contact) =>\n contact.address && contact.chainId && contact.name?.trim(),\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 for (const contact of contactsToDeleteLocally) {\n try {\n getMessenger().call(\n 'AddressBookController:delete',\n contact.chainId,\n contact.address,\n );\n\n if (onContactDeleted) {\n onContactDeleted();\n }\n } catch (error) {\n console.error('Error deleting contact:', error);\n }\n }\n\n // Apply local additions/updates\n for (const contact of contactsToAddOrUpdateLocally) {\n if (!contact.deletedAt) {\n try {\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 } catch (error) {\n console.error('Error updating contact:', error);\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 return await trace(\n {\n name: 'Contact Sync Full',\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\n return 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: 'Contact Sync Save Batch',\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 return trace\n ? await trace(\n {\n name: 'Contact Sync Update Remote',\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 : 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\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: 'Contact Sync Delete Remote' }, deleteContact)\n : await deleteContact();\n}\n"]}
1
+ {"version":3,"file":"controller-integration.mjs","sourceRoot":"","sources":["../../../../src/controllers/user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AmB,GACvB,MAAM,gCAAgC,EAAE,CAAC,iBAAiB,CACxD,GAAG,0BAA0B,CAAC,WAAW,IAAI,GAAG,EAAE,CACnD,CAAC;QAEJ,IAAI,mBAAmB,EAAE;YACvB,uCAAuC;YACvC,MAAM,oBAAoB,GAAG,IAAI,CAAC,KAAK,CACrC,mBAAmB,CACO,CAAC;YAC7B,MAAM,eAAe,GACnB,qCAAqC,CAAC,oBAAoB,CAAC,CAAC;YAE9D,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YACvB,MAAM,cAAc,GAAG;gBACrB,GAAG,eAAe;gBAClB,SAAS,EAAE,GAAG;gBACd,aAAa,EAAE,GAAG;aACK,CAAC;YAE1B,MAAM,mBAAmB,GACvB,qCAAqC,CAAC,cAAc,CAAC,CAAC;YAExD,2CAA2C;YAC3C,MAAM,gCAAgC,EAAE,CAAC,iBAAiB,CACxD,GAAG,0BAA0B,CAAC,WAAW,IAAI,GAAG,EAAE,EAClD,IAAI,CAAC,SAAS,CAAC,mBAAmB,CAAC,CACpC,CAAC;SACH;KACF;IAAC,MAAM;QACN,yEAAyE;QACzE,OAAO,CAAC,IAAI,CAAC,mDAAmD,EAAE,GAAG,CAAC,CAAC;KACxE;AACH,CAAC","sourcesContent":["import type { AddressBookEntry } from '@metamask/address-book-controller';\n\nimport { canPerformContactSyncing } from './sync-utils';\nimport type { ContactSyncingOptions } from './types';\nimport type { UserStorageContactEntry } from './types';\nimport {\n mapAddressBookEntryToUserStorageEntry,\n mapUserStorageEntryToAddressBookEntry,\n type SyncAddressBookEntry,\n} from './utils';\nimport { isContactBridgedFromAccounts } from './utils';\nimport { USER_STORAGE_FEATURE_NAMES } from '../../../shared/storage-schema';\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 */\nexport async function syncContactsWithUserStorage(\n config: SyncContactsWithUserStorageConfig,\n options: ContactSyncingOptions,\n): Promise<void> {\n const { getMessenger, getUserStorageControllerInstance } = options;\n const {\n onContactSyncErroneousSituation,\n onContactUpdated,\n onContactDeleted,\n } = config;\n\n try {\n // Cannot perform sync, conditions not met\n if (!canPerformContactSyncing(options)) {\n return;\n }\n\n // Activate sync semaphore to prevent event loops\n await getUserStorageControllerInstance().setIsContactSyncingInProgress(\n true,\n );\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) =>\n 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 // 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 for (const contact of contactsToDeleteLocally) {\n try {\n getMessenger().call(\n 'AddressBookController:delete',\n contact.chainId,\n contact.address,\n );\n\n if (onContactDeleted) {\n onContactDeleted();\n }\n } catch (error) {\n console.error('Error deleting contact:', error);\n }\n }\n\n // Apply local additions/updates\n for (const contact of contactsToAddOrUpdateLocally) {\n if (!contact.deletedAt) {\n try {\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 } catch (error) {\n console.error('Error updating contact:', error);\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/**\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 */\nasync function saveContactsToUserStorage(\n contacts: AddressBookEntry[],\n options: ContactSyncingOptions,\n): Promise<void> {\n const { getUserStorageControllerInstance } = options;\n\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/**\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 */\nexport async function updateContactInRemoteStorage(\n contact: AddressBookEntry,\n options: ContactSyncingOptions,\n): Promise<void> {\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/**\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 */\nexport async function deleteContactInRemoteStorage(\n contact: AddressBookEntry,\n options: ContactSyncingOptions,\n): Promise<void> {\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"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/contact-syncing/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TraceCallback } from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\nimport type {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n} from './constants';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport type UserStorageController from '../UserStorageController';\n\nexport type UserStorageContactEntry = {\n /**\n * The Version 'v' of the User Storage.\n * NOTE - will allow us to support upgrade/downgrades in the future\n */\n [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;\n /** the address 'a' of the contact */\n a: string;\n /** the name 'n' of the contact */\n n: string;\n /** the chainId 'c' of the contact */\n c: Hex;\n /** the memo 'm' of the contact (optional) */\n m?: string;\n /** the addressType 't' of the contact (optional) */\n t?: string;\n /** the isEns flag 'e' of the contact (optional) */\n e?: boolean;\n /** the lastUpdatedAt timestamp 'lu' of the contact */\n lu?: number;\n /** the deletedAt timestamp 'dt' of the contact (optional) */\n dt?: number;\n};\n\n/**\n * Options for contact syncing operations\n */\nexport type ContactSyncingOptions = {\n getUserStorageControllerInstance: () => UserStorageController;\n getMessenger: () => UserStorageControllerMessenger;\n trace?: TraceCallback;\n};\n"]}
1
+ {"version":3,"file":"types.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/contact-syncing/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { Hex } from '@metamask/utils';\n\nimport type {\n USER_STORAGE_VERSION_KEY,\n USER_STORAGE_VERSION,\n} from './constants';\nimport type { UserStorageControllerMessenger } from '../UserStorageController';\nimport type UserStorageController from '../UserStorageController';\n\nexport type UserStorageContactEntry = {\n /**\n * The Version 'v' of the User Storage.\n * NOTE - will allow us to support upgrade/downgrades in the future\n */\n [USER_STORAGE_VERSION_KEY]: typeof USER_STORAGE_VERSION;\n /** the address 'a' of the contact */\n a: string;\n /** the name 'n' of the contact */\n n: string;\n /** the chainId 'c' of the contact */\n c: Hex;\n /** the memo 'm' of the contact (optional) */\n m?: string;\n /** the addressType 't' of the contact (optional) */\n t?: string;\n /** the isEns flag 'e' of the contact (optional) */\n e?: boolean;\n /** the lastUpdatedAt timestamp 'lu' of the contact */\n lu?: number;\n /** the deletedAt timestamp 'dt' of the contact (optional) */\n dt?: number;\n};\n\n/**\n * Options for contact syncing operations\n */\nexport type ContactSyncingOptions = {\n getUserStorageControllerInstance: () => UserStorageController;\n getMessenger: () => UserStorageControllerMessenger;\n};\n"]}
@@ -1,4 +1,3 @@
1
- import type { TraceCallback } from "@metamask/controller-utils";
2
1
  import type { Hex } from "@metamask/utils";
3
2
  import type { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION } from "./constants.cjs";
4
3
  import type { UserStorageControllerMessenger } from "../UserStorageController.cjs";
@@ -32,6 +31,5 @@ export type UserStorageContactEntry = {
32
31
  export type ContactSyncingOptions = {
33
32
  getUserStorageControllerInstance: () => UserStorageController;
34
33
  getMessenger: () => UserStorageControllerMessenger;
35
- trace?: TraceCallback;
36
34
  };
37
35
  //# sourceMappingURL=types.d.cts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/contact-syncing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,mCAAmC;AAChE,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EACrB,wBAAoB;AACrB,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,qBAAqB,qCAAiC;AAElE,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;OAGG;IACH,CAAC,wBAAwB,CAAC,EAAE,OAAO,oBAAoB,CAAC;IACxD,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IACV,kCAAkC;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,qCAAqC;IACrC,CAAC,EAAE,GAAG,CAAC;IACP,6CAA6C;IAC7C,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,oDAAoD;IACpD,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,mDAAmD;IACnD,CAAC,CAAC,EAAE,OAAO,CAAC;IACZ,sDAAsD;IACtD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,6DAA6D;IAC7D,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;IAC9D,YAAY,EAAE,MAAM,8BAA8B,CAAC;IACnD,KAAK,CAAC,EAAE,aAAa,CAAC;CACvB,CAAC"}
1
+ {"version":3,"file":"types.d.cts","sourceRoot":"","sources":["../../../../src/controllers/user-storage/contact-syncing/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EACV,wBAAwB,EACxB,oBAAoB,EACrB,wBAAoB;AACrB,OAAO,KAAK,EAAE,8BAA8B,EAAE,qCAAiC;AAC/E,OAAO,KAAK,qBAAqB,qCAAiC;AAElE,MAAM,MAAM,uBAAuB,GAAG;IACpC;;;OAGG;IACH,CAAC,wBAAwB,CAAC,EAAE,OAAO,oBAAoB,CAAC;IACxD,qCAAqC;IACrC,CAAC,EAAE,MAAM,CAAC;IACV,kCAAkC;IAClC,CAAC,EAAE,MAAM,CAAC;IACV,qCAAqC;IACrC,CAAC,EAAE,GAAG,CAAC;IACP,6CAA6C;IAC7C,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,oDAAoD;IACpD,CAAC,CAAC,EAAE,MAAM,CAAC;IACX,mDAAmD;IACnD,CAAC,CAAC,EAAE,OAAO,CAAC;IACZ,sDAAsD;IACtD,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,6DAA6D;IAC7D,EAAE,CAAC,EAAE,MAAM,CAAC;CACb,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,qBAAqB,GAAG;IAClC,gCAAgC,EAAE,MAAM,qBAAqB,CAAC;IAC9D,YAAY,EAAE,MAAM,8BAA8B,CAAC;CACpD,CAAC"}
@@ -1,4 +1,3 @@
1
- import type { TraceCallback } from "@metamask/controller-utils";
2
1
  import type { Hex } from "@metamask/utils";
3
2
  import type { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION } from "./constants.mjs";
4
3
  import type { UserStorageControllerMessenger } from "../UserStorageController.mjs";
@@ -32,6 +31,5 @@ export type UserStorageContactEntry = {
32
31
  export type ContactSyncingOptions = {
33
32
  getUserStorageControllerInstance: () => UserStorageController;
34
33
  getMessenger: () => UserStorageControllerMessenger;
35
- trace?: TraceCallback;
36
34
  };
37
35
  //# sourceMappingURL=types.d.mts.map