{"version":3,"file":"utils.cjs","sourceRoot":"","sources":["../../../../src/controllers/user-storage/contact-syncing/utils.ts"],"names":[],"mappings":";;;AAKA,+CAA6E;AAY7E;;;;;;GAMG;AACI,MAAM,qCAAqC,GAAG,CACnD,gBAAkC,EACT,EAAE;IAC3B,MAAM,EACJ,OAAO,EACP,IAAI,EACJ,OAAO,EACP,IAAI,EACJ,WAAW,EACX,KAAK,EACL,aAAa,EACb,SAAS,GACV,GAAG,gBAAwC,CAAC;IAE7C,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IAEvB,OAAO;QACL,CAAC,oCAAwB,CAAC,EAAE,gCAAoB;QAChD,CAAC,EAAE,OAAO;QACV,CAAC,EAAE,IAAI;QACP,CAAC,EAAE,OAAO;QACV,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5B,GAAG,CAAC,WAAW,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1C,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC9B,EAAE,EAAE,aAAa,IAAI,GAAG;QACxB,GAAG,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACxC,CAAC;AACJ,CAAC,CAAC;AA3BW,QAAA,qCAAqC,yCA2BhD;AAEF;;;;;;;GAOG;AACI,MAAM,qCAAqC,GAAG,CACnD,gBAAyC,EACnB,EAAE;IACxB,MAAM,gBAAgB,GAAyB;QAC7C,OAAO,EAAE,gBAAgB,CAAC,CAAC;QAC3B,IAAI,EAAE,gBAAgB,CAAC,CAAC;QACxB,OAAO,EAAE,gBAAgB,CAAC,CAAC;QAC3B,IAAI,EAAE,gBAAgB,CAAC,CAAC,IAAI,EAAE;QAC9B,KAAK,EAAE,gBAAgB,CAAC,CAAC,IAAI,KAAK;QAClC,GAAG,CAAC,gBAAgB,CAAC,CAAC;YACpB,CAAC,CAAC,EAAE,WAAW,EAAE,gBAAgB,CAAC,CAAgB,EAAE;YACpD,CAAC,CAAC,EAAE,CAAC;QACP,wFAAwF;QACxF,GAAG,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,gBAAgB,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAClE,GAAG,CAAC,gBAAgB,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,aAAa,EAAE,gBAAgB,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACvE,CAAC;IAEF,OAAO,gBAAgB,CAAC;AAC1B,CAAC,CAAC;AAlBW,QAAA,qCAAqC,yCAkBhD;AAEF;;;;;;GAMG;AACI,MAAM,4BAA4B,GAAG,CAC1C,YAA8B,EACrB,EAAE;IACX,OAAO,MAAM,CAAC,YAAY,CAAC,OAAO,CAAC,KAAK,GAAG,CAAC;AAC9C,CAAC,CAAC;AAJW,QAAA,4BAA4B,gCAIvC","sourcesContent":["import type {\n  AddressBookEntry,\n  AddressType,\n} from '@metamask/address-book-controller';\n\nimport { USER_STORAGE_VERSION_KEY, USER_STORAGE_VERSION } from './constants';\nimport type { UserStorageContactEntry } from './types';\n\n/**\n * Extends AddressBookEntry with sync metadata\n * This is only used internally during the sync process and is not stored in AddressBookController\n */\nexport type SyncAddressBookEntry = AddressBookEntry & {\n  lastUpdatedAt?: number;\n  deletedAt?: number;\n};\n\n/**\n * Map an address book entry to a user storage address book entry\n * Always sets a current timestamp for entries going to remote storage\n *\n * @param addressBookEntry - An address book entry\n * @returns A user storage address book entry\n */\nexport const mapAddressBookEntryToUserStorageEntry = (\n  addressBookEntry: AddressBookEntry,\n): UserStorageContactEntry => {\n  const {\n    address,\n    name,\n    chainId,\n    memo,\n    addressType,\n    isEns,\n    lastUpdatedAt,\n    deletedAt,\n  } = addressBookEntry as SyncAddressBookEntry;\n\n  const now = Date.now();\n\n  return {\n    [USER_STORAGE_VERSION_KEY]: USER_STORAGE_VERSION,\n    a: address,\n    n: name,\n    c: chainId,\n    ...(memo ? { m: memo } : {}),\n    ...(addressType ? { t: addressType } : {}),\n    ...(isEns ? { e: isEns } : {}),\n    lu: lastUpdatedAt || now,\n    ...(deletedAt ? { dt: deletedAt } : {}),\n  };\n};\n\n/**\n * Map a user storage address book entry to an address book entry\n * Preserves sync metadata from remote storage while keeping the\n * entry compatible with AddressBookController\n *\n * @param userStorageEntry - A user storage address book entry\n * @returns An address book entry with sync metadata for internal use\n */\nexport const mapUserStorageEntryToAddressBookEntry = (\n  userStorageEntry: UserStorageContactEntry,\n): SyncAddressBookEntry => {\n  const addressBookEntry: SyncAddressBookEntry = {\n    address: userStorageEntry.a,\n    name: userStorageEntry.n,\n    chainId: userStorageEntry.c,\n    memo: userStorageEntry.m || '',\n    isEns: userStorageEntry.e || false,\n    ...(userStorageEntry.t\n      ? { addressType: userStorageEntry.t as AddressType }\n      : {}),\n    // Include remote metadata for sync operation only (not stored in AddressBookController)\n    ...(userStorageEntry.dt ? { deletedAt: userStorageEntry.dt } : {}),\n    ...(userStorageEntry.lu ? { lastUpdatedAt: userStorageEntry.lu } : {}),\n  };\n\n  return addressBookEntry;\n};\n\n/**\n * Check if a contact entry is bridged from accounts\n * Contacts with chainId \"*\" are global accounts bridged from the accounts system\n *\n * @param contactEntry - The contact entry to check\n * @returns True if the contact is bridged from accounts\n */\nexport const isContactBridgedFromAccounts = (\n  contactEntry: AddressBookEntry,\n): boolean => {\n  return String(contactEntry.chainId) === '*';\n};\n"]}