@metamask-previews/address-book-controller 6.2.0-preview-e9856975 → 6.2.0-preview-83095132

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 CHANGED
@@ -15,8 +15,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
15
15
 
16
16
  ### Changed
17
17
 
18
- - **BREAKING:** Use new `Messenger` from `@metamask/messenger` ([#6383](https://github.com/MetaMask/core/pull/6383))
19
- - Previously, `AddressBookController` accepted a `RestrictedMessenger` instance from `@metamask/base-controller`.
20
18
  - Bump `@metamask/base-controller` from `^8.0.1` to `^8.4.1` ([#6284](https://github.com/MetaMask/core/pull/6284), [#6355](https://github.com/MetaMask/core/pull/6355), [#6465](https://github.com/MetaMask/core/pull/6465), [#6632](https://github.com/MetaMask/core/pull/6632), [#6807](https://github.com/MetaMask/core/pull/6807))
21
19
  - Bump `@metamask/controller-utils` from `^11.11.0` to `^11.14.1` ([#6303](https://github.com/MetaMask/core/pull/6303), [#6620](https://github.com/MetaMask/core/pull/6620), [#6629](https://github.com/MetaMask/core/pull/6629), [#6807](https://github.com/MetaMask/core/pull/6807))
22
20
  - Bump `@metamask/utils` from `^11.4.2` to `^11.8.1` ([#6588](https://github.com/MetaMask/core/pull/6588), [#6708](https://github.com/MetaMask/core/pull/6708))
@@ -7,7 +7,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
7
7
  var _AddressBookController_instances, _AddressBookController_registerMessageHandlers;
8
8
  Object.defineProperty(exports, "__esModule", { value: true });
9
9
  exports.AddressBookController = exports.getDefaultAddressBookControllerState = exports.controllerName = exports.AddressType = void 0;
10
- const next_1 = require("@metamask/base-controller/next");
10
+ const base_controller_1 = require("@metamask/base-controller");
11
11
  const controller_utils_1 = require("@metamask/controller-utils");
12
12
  /**
13
13
  * The type of address.
@@ -31,7 +31,7 @@ const addressBookControllerMetadata = {
31
31
  addressBook: {
32
32
  includeInStateLogs: true,
33
33
  persist: true,
34
- includeInDebugSnapshot: false,
34
+ anonymous: false,
35
35
  usedInUi: true,
36
36
  },
37
37
  };
@@ -49,7 +49,7 @@ exports.getDefaultAddressBookControllerState = getDefaultAddressBookControllerSt
49
49
  /**
50
50
  * Controller that manages a list of recipient addresses associated with nicknames.
51
51
  */
52
- class AddressBookController extends next_1.BaseController {
52
+ class AddressBookController extends base_controller_1.BaseController {
53
53
  /**
54
54
  * Creates an AddressBookController instance.
55
55
  *
@@ -119,7 +119,7 @@ class AddressBookController extends next_1.BaseController {
119
119
  // These entries with chainId='*' are the wallet's own accounts (internal MetaMask accounts),
120
120
  // not user-created contacts. They don't need to trigger sync events.
121
121
  if (String(chainId) !== WALLET_ACCOUNTS_CHAIN_ID) {
122
- this.messenger.publish('AddressBookController:contactDeleted', deletedEntry);
122
+ this.messagingSystem.publish('AddressBookController:contactDeleted', deletedEntry);
123
123
  }
124
124
  return true;
125
125
  }
@@ -165,16 +165,16 @@ class AddressBookController extends next_1.BaseController {
165
165
  // These entries with chainId='*' are the wallet's own accounts (internal MetaMask accounts),
166
166
  // not user-created contacts. They don't need to trigger sync events.
167
167
  if (String(chainId) !== WALLET_ACCOUNTS_CHAIN_ID) {
168
- this.messenger.publish('AddressBookController:contactUpdated', entry);
168
+ this.messagingSystem.publish('AddressBookController:contactUpdated', entry);
169
169
  }
170
170
  return true;
171
171
  }
172
172
  }
173
173
  exports.AddressBookController = AddressBookController;
174
174
  _AddressBookController_instances = new WeakSet(), _AddressBookController_registerMessageHandlers = function _AddressBookController_registerMessageHandlers() {
175
- this.messenger.registerActionHandler(`${exports.controllerName}:list`, this.list.bind(this));
176
- this.messenger.registerActionHandler(`${exports.controllerName}:set`, this.set.bind(this));
177
- this.messenger.registerActionHandler(`${exports.controllerName}:delete`, this.delete.bind(this));
175
+ this.messagingSystem.registerActionHandler(`${exports.controllerName}:list`, this.list.bind(this));
176
+ this.messagingSystem.registerActionHandler(`${exports.controllerName}:set`, this.set.bind(this));
177
+ this.messagingSystem.registerActionHandler(`${exports.controllerName}:delete`, this.delete.bind(this));
178
178
  };
179
179
  exports.default = AddressBookController;
180
180
  //# sourceMappingURL=AddressBookController.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"AddressBookController.cjs","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":";;;;;;;;;AAIA,yDAAgE;AAChE,iEAMoC;AAgBpC;;GAEG;AACH,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,oEAAqD,CAAA;IACrD,qDAAsC,CAAA;IACtC,2CAA4B,CAAA;AAC9B,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB;AA8BD;;GAEG;AACU,QAAA,cAAc,GAAG,uBAAuB,CAAC;AAEtD;;;GAGG;AACH,MAAM,wBAAwB,GAAG,GAAG,CAAC;AA2ErC,MAAM,6BAA6B,GAAG;IACpC,WAAW,EAAE;QACX,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF;;;;GAIG;AACI,MAAM,oCAAoC,GAC/C,GAA+B,EAAE;IAC/B,OAAO;QACL,WAAW,EAAE,EAAE;KAChB,CAAC;AACJ,CAAC,CAAC;AALS,QAAA,oCAAoC,wCAK7C;AAWJ;;GAEG;AACH,MAAa,qBAAsB,SAAQ,qBAI1C;IACC;;;;;;OAMG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GAIN;QACC,MAAM,WAAW,GAAG,EAAE,GAAG,IAAA,4CAAoC,GAAE,EAAE,GAAG,KAAK,EAAE,CAAC;QAC5E,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,6BAA6B;YACvC,IAAI,EAAE,sBAAc;YACpB,KAAK,EAAE,WAAW;SACnB,CAAC,CAAC;;QAEH,uBAAA,IAAI,wFAAyB,MAA7B,IAAI,CAA2B,CAAC;IAClC,CAAC;IAED;;;;OAIG;IACH,IAAI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WAAW;gBACzB,CAAC,OAAO,CAAC,EAAE;oBACT,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC;oBAClC,CAAC,OAAO,CAAC,EAAE,KAAK;iBACjB;aACF,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,iEAAiE;QACjE,6FAA6F;QAC7F,qEAAqE;QACrE,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,wBAAwB,EAAE;YAChD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;SACvE;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CAmBF;AAjLD,sDAiLC;;IAbG,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAClC,GAAG,sBAAc,OAAO,EACxB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CACrB,CAAC;IACF,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAClC,GAAG,sBAAc,MAAM,EACvB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CACpB,CAAC;IACF,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAClC,GAAG,sBAAc,SAAS,EAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CACvB,CAAC;AACJ,CAAC;AAGH,kBAAe,qBAAqB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller/next';\nimport { BaseController } from '@metamask/base-controller/next';\nimport {\n normalizeEnsName,\n isValidHexAddress,\n isSafeDynamicKey,\n toChecksumHexAddress,\n toHex,\n} from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Hex } from '@metamask/utils';\n\n/**\n * ContactEntry representation\n */\nexport type ContactEntry = {\n /** Hex address of a recipient account */\n address: string;\n /** Nickname associated with this address */\n name: string;\n /** Data time when an account as created/imported */\n importTime?: number;\n};\n\n/**\n * The type of address.\n */\nexport enum AddressType {\n externallyOwnedAccounts = 'EXTERNALLY_OWNED_ACCOUNTS',\n contractAccounts = 'CONTRACT_ACCOUNTS',\n nonAccounts = 'NON_ACCOUNTS',\n}\n\n/**\n * AddressBookEntry represents a contact in the address book.\n */\nexport type AddressBookEntry = {\n /** Hex address of a recipient account */\n address: string;\n /** Nickname associated with this address */\n name: string;\n /** Chain id identifies the current chain */\n chainId: Hex;\n /** User's note about address */\n memo: string;\n /** Indicates if the entry is an ENS name */\n isEns: boolean;\n /** The type of this address */\n addressType?: AddressType;\n /** Timestamp of when this entry was last updated */\n lastUpdatedAt?: number;\n};\n\n/**\n * State for the AddressBookController.\n */\nexport type AddressBookControllerState = {\n /** Map of chainId to address to contact entries */\n addressBook: { [chainId: Hex]: { [address: string]: AddressBookEntry } };\n};\n\n/**\n * The name of the {@link AddressBookController}.\n */\nexport const controllerName = 'AddressBookController';\n\n/**\n * Special chainId used for wallet's own accounts (internal MetaMask accounts).\n * These entries don't trigger sync events as they are not user-created contacts.\n */\nconst WALLET_ACCOUNTS_CHAIN_ID = '*';\n\n/**\n * The action that can be performed to get the state of the {@link AddressBookController}.\n */\nexport type AddressBookControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AddressBookControllerState\n>;\n\n/**\n * The action that can be performed to list contacts from the {@link AddressBookController}.\n */\nexport type AddressBookControllerListAction = {\n type: `${typeof controllerName}:list`;\n handler: AddressBookController['list'];\n};\n\n/**\n * The action that can be performed to set a contact in the {@link AddressBookController}.\n */\nexport type AddressBookControllerSetAction = {\n type: `${typeof controllerName}:set`;\n handler: AddressBookController['set'];\n};\n\n/**\n * The action that can be performed to delete a contact from the {@link AddressBookController}.\n */\nexport type AddressBookControllerDeleteAction = {\n type: `${typeof controllerName}:delete`;\n handler: AddressBookController['delete'];\n};\n\n/**\n * Event emitted when a contact is added or updated\n */\nexport type AddressBookControllerContactUpdatedEvent = {\n type: `${typeof controllerName}:contactUpdated`;\n payload: [AddressBookEntry];\n};\n\n/**\n * Event emitted when a contact is deleted\n */\nexport type AddressBookControllerContactDeletedEvent = {\n type: `${typeof controllerName}:contactDeleted`;\n payload: [AddressBookEntry];\n};\n\n/**\n * The actions that can be performed using the {@link AddressBookController}.\n */\nexport type AddressBookControllerActions =\n | AddressBookControllerGetStateAction\n | AddressBookControllerListAction\n | AddressBookControllerSetAction\n | AddressBookControllerDeleteAction;\n\n/**\n * The event that {@link AddressBookController} can emit.\n */\nexport type AddressBookControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AddressBookControllerState\n>;\n\n/**\n * The events that {@link AddressBookController} can emit.\n */\nexport type AddressBookControllerEvents =\n | AddressBookControllerStateChangeEvent\n | AddressBookControllerContactUpdatedEvent\n | AddressBookControllerContactDeletedEvent;\n\nconst addressBookControllerMetadata = {\n addressBook: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\n/**\n * Get the default {@link AddressBookController} state.\n *\n * @returns The default {@link AddressBookController} state.\n */\nexport const getDefaultAddressBookControllerState =\n (): AddressBookControllerState => {\n return {\n addressBook: {},\n };\n };\n\n/**\n * The messenger of the {@link AddressBookController} for communication.\n */\nexport type AddressBookControllerMessenger = Messenger<\n typeof controllerName,\n AddressBookControllerActions,\n AddressBookControllerEvents\n>;\n\n/**\n * Controller that manages a list of recipient addresses associated with nicknames.\n */\nexport class AddressBookController extends BaseController<\n typeof controllerName,\n AddressBookControllerState,\n AddressBookControllerMessenger\n> {\n /**\n * Creates an AddressBookController instance.\n *\n * @param args - The {@link AddressBookController} arguments.\n * @param args.messenger - The controller messenger instance for communication.\n * @param args.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: AddressBookControllerMessenger;\n state?: Partial<AddressBookControllerState>;\n }) {\n const mergedState = { ...getDefaultAddressBookControllerState(), ...state };\n super({\n messenger,\n metadata: addressBookControllerMetadata,\n name: controllerName,\n state: mergedState,\n });\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Returns all address book entries as an array.\n *\n * @returns Array of all address book entries.\n */\n list(): AddressBookEntry[] {\n const { addressBook } = this.state;\n\n return Object.keys(addressBook).reduce<AddressBookEntry[]>(\n (acc, chainId) => {\n const chainIdHex = chainId as Hex;\n const chainContacts = Object.values(addressBook[chainIdHex]);\n\n return [...acc, ...chainContacts];\n },\n [],\n );\n }\n\n /**\n * Remove all contract entries.\n */\n clear() {\n this.update((state) => {\n state.addressBook = {};\n });\n }\n\n /**\n * Remove a contract entry by address.\n *\n * @param chainId - Chain id identifies the current chain.\n * @param address - Recipient address to delete.\n * @returns Whether the entry was deleted.\n */\n delete(chainId: Hex, address: string) {\n address = toChecksumHexAddress(address);\n if (\n ![chainId, address].every((key) => isSafeDynamicKey(key)) ||\n !isValidHexAddress(address) ||\n !this.state.addressBook[chainId] ||\n !this.state.addressBook[chainId][address]\n ) {\n return false;\n }\n\n const deletedEntry = { ...this.state.addressBook[chainId][address] };\n\n this.update((state) => {\n const chainContacts = state.addressBook[chainId];\n if (chainContacts?.[address]) {\n delete chainContacts[address];\n\n // Clean up empty chainId objects\n if (Object.keys(chainContacts).length === 0) {\n delete state.addressBook[chainId];\n }\n }\n });\n\n // Skip sending delete event for global contacts with chainId '*'\n // These entries with chainId='*' are the wallet's own accounts (internal MetaMask accounts),\n // not user-created contacts. They don't need to trigger sync events.\n if (String(chainId) !== WALLET_ACCOUNTS_CHAIN_ID) {\n this.messenger.publish(\n 'AddressBookController:contactDeleted',\n deletedEntry,\n );\n }\n\n return true;\n }\n\n /**\n * Add or update a contact entry by address.\n *\n * @param address - Recipient address to add or update.\n * @param name - Nickname to associate with this address.\n * @param chainId - Chain id identifies the current chain.\n * @param memo - User's note about address.\n * @param addressType - Contact's address type.\n * @returns Boolean indicating if the address was successfully set.\n */\n set(\n address: string,\n name: string,\n chainId = toHex(1),\n memo = '',\n addressType?: AddressType,\n ) {\n address = toChecksumHexAddress(address);\n if (!isValidHexAddress(address)) {\n return false;\n }\n\n const entry = {\n address,\n chainId,\n isEns: false,\n memo,\n name,\n addressType,\n lastUpdatedAt: Date.now(),\n };\n const ensName = normalizeEnsName(name);\n if (ensName) {\n entry.name = ensName;\n entry.isEns = true;\n }\n\n this.update((state) => {\n state.addressBook = {\n ...this.state.addressBook,\n [chainId]: {\n ...this.state.addressBook[chainId],\n [address]: entry,\n },\n };\n });\n\n // Skip sending update event for global contacts with chainId '*'\n // These entries with chainId='*' are the wallet's own accounts (internal MetaMask accounts),\n // not user-created contacts. They don't need to trigger sync events.\n if (String(chainId) !== WALLET_ACCOUNTS_CHAIN_ID) {\n this.messenger.publish('AddressBookController:contactUpdated', entry);\n }\n\n return true;\n }\n\n /**\n * Registers message handlers for the AddressBookController.\n */\n #registerMessageHandlers() {\n this.messenger.registerActionHandler(\n `${controllerName}:list`,\n this.list.bind(this),\n );\n this.messenger.registerActionHandler(\n `${controllerName}:set`,\n this.set.bind(this),\n );\n this.messenger.registerActionHandler(\n `${controllerName}:delete`,\n this.delete.bind(this),\n );\n }\n}\n\nexport default AddressBookController;\n"]}
1
+ {"version":3,"file":"AddressBookController.cjs","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":";;;;;;;;;AAKA,+DAA2D;AAC3D,iEAMoC;AAepC;;GAEG;AACH,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,oEAAqD,CAAA;IACrD,qDAAsC,CAAA;IACtC,2CAA4B,CAAA;AAC9B,CAAC,EAJW,WAAW,2BAAX,WAAW,QAItB;AA8BD;;GAEG;AACU,QAAA,cAAc,GAAG,uBAAuB,CAAC;AAEtD;;;GAGG;AACH,MAAM,wBAAwB,GAAG,GAAG,CAAC;AA2ErC,MAAM,6BAA6B,GAAG;IACpC,WAAW,EAAE;QACX,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,SAAS,EAAE,KAAK;QAChB,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF;;;;GAIG;AACI,MAAM,oCAAoC,GAC/C,GAA+B,EAA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,SAAS,EAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CACvB,CAAC;AACJ,CAAC;AAGH,kBAAe,qBAAqB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport {\n normalizeEnsName,\n isValidHexAddress,\n isSafeDynamicKey,\n toChecksumHexAddress,\n toHex,\n} from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\n/**\n * ContactEntry representation\n */\nexport type ContactEntry = {\n /** Hex address of a recipient account */\n address: string;\n /** Nickname associated with this address */\n name: string;\n /** Data time when an account as created/imported */\n importTime?: number;\n};\n\n/**\n * The type of address.\n */\nexport enum AddressType {\n externallyOwnedAccounts = 'EXTERNALLY_OWNED_ACCOUNTS',\n contractAccounts = 'CONTRACT_ACCOUNTS',\n nonAccounts = 'NON_ACCOUNTS',\n}\n\n/**\n * AddressBookEntry represents a contact in the address book.\n */\nexport type AddressBookEntry = {\n /** Hex address of a recipient account */\n address: string;\n /** Nickname associated with this address */\n name: string;\n /** Chain id identifies the current chain */\n chainId: Hex;\n /** User's note about address */\n memo: string;\n /** Indicates if the entry is an ENS name */\n isEns: boolean;\n /** The type of this address */\n addressType?: AddressType;\n /** Timestamp of when this entry was last updated */\n lastUpdatedAt?: number;\n};\n\n/**\n * State for the AddressBookController.\n */\nexport type AddressBookControllerState = {\n /** Map of chainId to address to contact entries */\n addressBook: { [chainId: Hex]: { [address: string]: AddressBookEntry } };\n};\n\n/**\n * The name of the {@link AddressBookController}.\n */\nexport const controllerName = 'AddressBookController';\n\n/**\n * Special chainId used for wallet's own accounts (internal MetaMask accounts).\n * These entries don't trigger sync events as they are not user-created contacts.\n */\nconst WALLET_ACCOUNTS_CHAIN_ID = '*';\n\n/**\n * The action that can be performed to get the state of the {@link AddressBookController}.\n */\nexport type AddressBookControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AddressBookControllerState\n>;\n\n/**\n * The action that can be performed to list contacts from the {@link AddressBookController}.\n */\nexport type AddressBookControllerListAction = {\n type: `${typeof controllerName}:list`;\n handler: AddressBookController['list'];\n};\n\n/**\n * The action that can be performed to set a contact in the {@link AddressBookController}.\n */\nexport type AddressBookControllerSetAction = {\n type: `${typeof controllerName}:set`;\n handler: AddressBookController['set'];\n};\n\n/**\n * The action that can be performed to delete a contact from the {@link AddressBookController}.\n */\nexport type AddressBookControllerDeleteAction = {\n type: `${typeof controllerName}:delete`;\n handler: AddressBookController['delete'];\n};\n\n/**\n * Event emitted when a contact is added or updated\n */\nexport type AddressBookControllerContactUpdatedEvent = {\n type: `${typeof controllerName}:contactUpdated`;\n payload: [AddressBookEntry];\n};\n\n/**\n * Event emitted when a contact is deleted\n */\nexport type AddressBookControllerContactDeletedEvent = {\n type: `${typeof controllerName}:contactDeleted`;\n payload: [AddressBookEntry];\n};\n\n/**\n * The actions that can be performed using the {@link AddressBookController}.\n */\nexport type AddressBookControllerActions =\n | AddressBookControllerGetStateAction\n | AddressBookControllerListAction\n | AddressBookControllerSetAction\n | AddressBookControllerDeleteAction;\n\n/**\n * The event that {@link AddressBookController} can emit.\n */\nexport type AddressBookControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AddressBookControllerState\n>;\n\n/**\n * The events that {@link AddressBookController} can emit.\n */\nexport type AddressBookControllerEvents =\n | AddressBookControllerStateChangeEvent\n | AddressBookControllerContactUpdatedEvent\n | AddressBookControllerContactDeletedEvent;\n\nconst addressBookControllerMetadata = {\n addressBook: {\n includeInStateLogs: true,\n persist: true,\n anonymous: false,\n usedInUi: true,\n },\n};\n\n/**\n * Get the default {@link AddressBookController} state.\n *\n * @returns The default {@link AddressBookController} state.\n */\nexport const getDefaultAddressBookControllerState =\n (): AddressBookControllerState => {\n return {\n addressBook: {},\n };\n };\n\n/**\n * The messenger of the {@link AddressBookController} for communication.\n */\nexport type AddressBookControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n AddressBookControllerActions,\n AddressBookControllerEvents,\n never,\n never\n>;\n\n/**\n * Controller that manages a list of recipient addresses associated with nicknames.\n */\nexport class AddressBookController extends BaseController<\n typeof controllerName,\n AddressBookControllerState,\n AddressBookControllerMessenger\n> {\n /**\n * Creates an AddressBookController instance.\n *\n * @param args - The {@link AddressBookController} arguments.\n * @param args.messenger - The controller messenger instance for communication.\n * @param args.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: AddressBookControllerMessenger;\n state?: Partial<AddressBookControllerState>;\n }) {\n const mergedState = { ...getDefaultAddressBookControllerState(), ...state };\n super({\n messenger,\n metadata: addressBookControllerMetadata,\n name: controllerName,\n state: mergedState,\n });\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Returns all address book entries as an array.\n *\n * @returns Array of all address book entries.\n */\n list(): AddressBookEntry[] {\n const { addressBook } = this.state;\n\n return Object.keys(addressBook).reduce<AddressBookEntry[]>(\n (acc, chainId) => {\n const chainIdHex = chainId as Hex;\n const chainContacts = Object.values(addressBook[chainIdHex]);\n\n return [...acc, ...chainContacts];\n },\n [],\n );\n }\n\n /**\n * Remove all contract entries.\n */\n clear() {\n this.update((state) => {\n state.addressBook = {};\n });\n }\n\n /**\n * Remove a contract entry by address.\n *\n * @param chainId - Chain id identifies the current chain.\n * @param address - Recipient address to delete.\n * @returns Whether the entry was deleted.\n */\n delete(chainId: Hex, address: string) {\n address = toChecksumHexAddress(address);\n if (\n ![chainId, address].every((key) => isSafeDynamicKey(key)) ||\n !isValidHexAddress(address) ||\n !this.state.addressBook[chainId] ||\n !this.state.addressBook[chainId][address]\n ) {\n return false;\n }\n\n const deletedEntry = { ...this.state.addressBook[chainId][address] };\n\n this.update((state) => {\n const chainContacts = state.addressBook[chainId];\n if (chainContacts?.[address]) {\n delete chainContacts[address];\n\n // Clean up empty chainId objects\n if (Object.keys(chainContacts).length === 0) {\n delete state.addressBook[chainId];\n }\n }\n });\n\n // Skip sending delete event for global contacts with chainId '*'\n // These entries with chainId='*' are the wallet's own accounts (internal MetaMask accounts),\n // not user-created contacts. They don't need to trigger sync events.\n if (String(chainId) !== WALLET_ACCOUNTS_CHAIN_ID) {\n this.messagingSystem.publish(\n 'AddressBookController:contactDeleted',\n deletedEntry,\n );\n }\n\n return true;\n }\n\n /**\n * Add or update a contact entry by address.\n *\n * @param address - Recipient address to add or update.\n * @param name - Nickname to associate with this address.\n * @param chainId - Chain id identifies the current chain.\n * @param memo - User's note about address.\n * @param addressType - Contact's address type.\n * @returns Boolean indicating if the address was successfully set.\n */\n set(\n address: string,\n name: string,\n chainId = toHex(1),\n memo = '',\n addressType?: AddressType,\n ) {\n address = toChecksumHexAddress(address);\n if (!isValidHexAddress(address)) {\n return false;\n }\n\n const entry = {\n address,\n chainId,\n isEns: false,\n memo,\n name,\n addressType,\n lastUpdatedAt: Date.now(),\n };\n const ensName = normalizeEnsName(name);\n if (ensName) {\n entry.name = ensName;\n entry.isEns = true;\n }\n\n this.update((state) => {\n state.addressBook = {\n ...this.state.addressBook,\n [chainId]: {\n ...this.state.addressBook[chainId],\n [address]: entry,\n },\n };\n });\n\n // Skip sending update event for global contacts with chainId '*'\n // These entries with chainId='*' are the wallet's own accounts (internal MetaMask accounts),\n // not user-created contacts. They don't need to trigger sync events.\n if (String(chainId) !== WALLET_ACCOUNTS_CHAIN_ID) {\n this.messagingSystem.publish(\n 'AddressBookController:contactUpdated',\n entry,\n );\n }\n\n return true;\n }\n\n /**\n * Registers message handlers for the AddressBookController.\n */\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:list`,\n this.list.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${controllerName}:set`,\n this.set.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${controllerName}:delete`,\n this.delete.bind(this),\n );\n }\n}\n\nexport default AddressBookController;\n"]}
@@ -1,6 +1,5 @@
1
- import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller/next";
2
- import { BaseController } from "@metamask/base-controller/next";
3
- import type { Messenger } from "@metamask/messenger";
1
+ import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
2
+ import { BaseController } from "@metamask/base-controller";
4
3
  import type { Hex } from "@metamask/utils";
5
4
  /**
6
5
  * ContactEntry representation
@@ -115,7 +114,7 @@ export declare const getDefaultAddressBookControllerState: () => AddressBookCont
115
114
  /**
116
115
  * The messenger of the {@link AddressBookController} for communication.
117
116
  */
118
- export type AddressBookControllerMessenger = Messenger<typeof controllerName, AddressBookControllerActions, AddressBookControllerEvents>;
117
+ export type AddressBookControllerMessenger = RestrictedMessenger<typeof controllerName, AddressBookControllerActions, AddressBookControllerEvents, never, never>;
119
118
  /**
120
119
  * Controller that manages a list of recipient addresses associated with nicknames.
121
120
  */
@@ -1 +1 @@
1
- {"version":3,"file":"AddressBookController.d.cts","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,uCAAuC;AACxC,OAAO,EAAE,cAAc,EAAE,uCAAuC;AAQhE,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,oBAAY,WAAW;IACrB,uBAAuB,8BAA8B;IACrD,gBAAgB,sBAAsB;IACtC,WAAW,iBAAiB;CAC7B;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAA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B,2BAA2B,EAC3B,KAAK,EACL,KAAK,CACN,CAAC;AAEF;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,cAAc,CACvD,OAAO,cAAc,EACrB,0BAA0B,EAC1B,8BAA8B,CAC/B;;IACC;;;;;;OAMG;gBACS,EACV,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,8BAA8B,CAAC;QAC1C,KAAK,CAAC,EAAE,OAAO,CAAC,0BAA0B,CAAC,CAAC;KAC7C;IAYD;;;;OAIG;IACH,IAAI,IAAI,gBAAgB,EAAE;IAc1B;;OAEG;IACH,KAAK;IAML;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM;IAsCpC;;;;;;;;;OASG;IACH,GAAG,CACD,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,gBAAW,EAClB,IAAI,SAAK,EACT,WAAW,CAAC,EAAE,WAAW;CA8D5B;AAED,eAAe,qBAAqB,CAAC"}
@@ -1,6 +1,5 @@
1
- import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller/next";
2
- import { BaseController } from "@metamask/base-controller/next";
3
- import type { Messenger } from "@metamask/messenger";
1
+ import type { ControllerGetStateAction, ControllerStateChangeEvent, RestrictedMessenger } from "@metamask/base-controller";
2
+ import { BaseController } from "@metamask/base-controller";
4
3
  import type { Hex } from "@metamask/utils";
5
4
  /**
6
5
  * ContactEntry representation
@@ -115,7 +114,7 @@ export declare const getDefaultAddressBookControllerState: () => AddressBookCont
115
114
  /**
116
115
  * The messenger of the {@link AddressBookController} for communication.
117
116
  */
118
- export type AddressBookControllerMessenger = Messenger<typeof controllerName, AddressBookControllerActions, AddressBookControllerEvents>;
117
+ export type AddressBookControllerMessenger = RestrictedMessenger<typeof controllerName, AddressBookControllerActions, AddressBookControllerEvents, never, never>;
119
118
  /**
120
119
  * Controller that manages a list of recipient addresses associated with nicknames.
121
120
  */
@@ -1 +1 @@
1
- {"version":3,"file":"AddressBookController.d.mts","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,uCAAuC;AACxC,OAAO,EAAE,cAAc,EAAE,uCAAuC;AAQhE,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,oBAAY,WAAW;IACrB,uBAAuB,8BAA8B;IACrD,gBAAgB,sBAAsB;IACtC,WAAW,iBAAiB;CAC7B;AAED;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,OAAO,EAAE,GAAG,CAAC;IACb,gCAAgC;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,KAAK,EAAE,OAAO,CAAC;IACf,+BAA+B;IAC/B,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,oDAAoD;IACpD,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,0BAA0B,GAAG;IACvC,mDAAmD;IACnD,WAAW,EAAE;QAAE,CAAC,OAAO,EAAE,GAAG,GAAG;YAAE,CAAC,OAAO,EAAE,MAAM,GAAG,gBAAgB,CAAA;SAAE,CAAA;KAAE,CAAC;CAC1E,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,cAAc,0BAA0B,CAAC;AAQtD;;GAEG;AACH,MAAM,MAAM,mCA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AA8B,GAAG,SAAS,CACpD,OAAO,cAAc,EACrB,4BAA4B,EAC5B,2BAA2B,CAC5B,CAAC;AAEF;;GAEG;AACH,qBAAa,qBAAsB,SAAQ,cAAc,CACvD,OAAO,cAAc,EACrB,0BAA0B,EAC1B,8BAA8B,CAC/B;;IACC;;;;;;OAMG;gBACS,EACV,SAAS,EACT,KAAK,GACN,EAAE;QACD,SAAS,EAAE,8BAA8B,CAAC;QAC1C,KAAK,CAAC,EAAE,OAAO,CAAC,0BAA0B,CAAC,CAAC;KAC7C;IAYD;;;;OAIG;IACH,IAAI,IAAI,gBAAgB,EAAE;IAc1B;;OAEG;IACH,KAAK;IAML;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM;IAsCpC;;;;;;;;;OASG;IACH,GAAG,CACD,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,gBAAW,EAClB,IAAI,SAAK,EACT,WAAW,CAAC,EAAE,WAAW;CA2D5B;AAED,eAAe,qBAAqB,CAAC"}
1
+ {"version":3,"file":"AddressBookController.d.mts","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC1B,mBAAmB,EACpB,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAQ3D,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;IAChB,4CAA4C;IAC5C,IAAI,EAAE,MAAM,CAAC;IACb,oDAAoD;IACpD,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAEF;;GAEG;AACH,oBAAY,WAAW;IACrB,uBAAuB,8BAA8B;IACrD,gBAAgB,sBAAsB;IACtC,WAAW,iBAAiB;CAC7B;AAED;;GAEG;AACH,MAAM,MAAM,g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AAO,gBAAW,EAClB,IAAI,SAAK,EACT,WAAW,CAAC,EAAE,WAAW;CA8D5B;AAED,eAAe,qBAAqB,CAAC"}
@@ -4,7 +4,7 @@ var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (
4
4
  return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5
5
  };
6
6
  var _AddressBookController_instances, _AddressBookController_registerMessageHandlers;
7
- import { BaseController } from "@metamask/base-controller/next";
7
+ import { BaseController } from "@metamask/base-controller";
8
8
  import { normalizeEnsName, isValidHexAddress, isSafeDynamicKey, toChecksumHexAddress, toHex } from "@metamask/controller-utils";
9
9
  /**
10
10
  * The type of address.
@@ -28,7 +28,7 @@ const addressBookControllerMetadata = {
28
28
  addressBook: {
29
29
  includeInStateLogs: true,
30
30
  persist: true,
31
- includeInDebugSnapshot: false,
31
+ anonymous: false,
32
32
  usedInUi: true,
33
33
  },
34
34
  };
@@ -115,7 +115,7 @@ export class AddressBookController extends BaseController {
115
115
  // These entries with chainId='*' are the wallet's own accounts (internal MetaMask accounts),
116
116
  // not user-created contacts. They don't need to trigger sync events.
117
117
  if (String(chainId) !== WALLET_ACCOUNTS_CHAIN_ID) {
118
- this.messenger.publish('AddressBookController:contactDeleted', deletedEntry);
118
+ this.messagingSystem.publish('AddressBookController:contactDeleted', deletedEntry);
119
119
  }
120
120
  return true;
121
121
  }
@@ -161,15 +161,15 @@ export class AddressBookController extends BaseController {
161
161
  // These entries with chainId='*' are the wallet's own accounts (internal MetaMask accounts),
162
162
  // not user-created contacts. They don't need to trigger sync events.
163
163
  if (String(chainId) !== WALLET_ACCOUNTS_CHAIN_ID) {
164
- this.messenger.publish('AddressBookController:contactUpdated', entry);
164
+ this.messagingSystem.publish('AddressBookController:contactUpdated', entry);
165
165
  }
166
166
  return true;
167
167
  }
168
168
  }
169
169
  _AddressBookController_instances = new WeakSet(), _AddressBookController_registerMessageHandlers = function _AddressBookController_registerMessageHandlers() {
170
- this.messenger.registerActionHandler(`${controllerName}:list`, this.list.bind(this));
171
- this.messenger.registerActionHandler(`${controllerName}:set`, this.set.bind(this));
172
- this.messenger.registerActionHandler(`${controllerName}:delete`, this.delete.bind(this));
170
+ this.messagingSystem.registerActionHandler(`${controllerName}:list`, this.list.bind(this));
171
+ this.messagingSystem.registerActionHandler(`${controllerName}:set`, this.set.bind(this));
172
+ this.messagingSystem.registerActionHandler(`${controllerName}:delete`, this.delete.bind(this));
173
173
  };
174
174
  export default AddressBookController;
175
175
  //# sourceMappingURL=AddressBookController.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"AddressBookController.mjs","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":";;;;;;AAIA,OAAO,EAAE,cAAc,EAAE,uCAAuC;AAChE,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,EACN,mCAAmC;AAgBpC;;GAEG;AACH,MAAM,CAAN,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,oEAAqD,CAAA;IACrD,qDAAsC,CAAA;IACtC,2CAA4B,CAAA;AAC9B,CAAC,EAJW,WAAW,KAAX,WAAW,QAItB;AA8BD;;GAEG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,uBAAuB,CAAC;AAEtD;;;GAGG;AACH,MAAM,wBAAwB,GAAG,GAAG,CAAC;AA2ErC,MAAM,6BAA6B,GAAG;IACpC,WAAW,EAAE;QACX,kBAAkB,EAAE,IAAI;QACxB,OAAO,EAAE,IAAI;QACb,sBAAsB,EAAE,KAAK;QAC7B,QAAQ,EAAE,IAAI;KACf;CACF,CAAC;AAEF;;;;GAIG;AACH,MAAM,CAAC,MAAM,oCAAoC,GAC/C,GAA+B,EAAE;IAC/B,OAAO;QACL,WAAW,EAAE,EAAE;KAChB,CAAC;AACJ,CAAC,CAAC;AAWJ;;GAEG;AACH,MAAM,OAAO,qBAAsB,SAAQ,cAI1C;IACC;;;;;;OAMG;IACH,YAAY,E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OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,OAAO,EAAE;YACX,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC;YACrB,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC;SACpB;QAED,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;YACpB,KAAK,CAAC,WAAW,GAAG;gBAClB,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW;gBACzB,CAAC,OAAO,CAAC,EAAE;oBACT,GAAG,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC;oBAClC,CAAC,OAAO,CAAC,EAAE,KAAK;iBACjB;aACF,CAAC;QACJ,CAAC,CAAC,CAAC;QAEH,iEAAiE;QACjE,6FAA6F;QAC7F,qEAAqE;QACrE,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,wBAAwB,EAAE;YAChD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;SACvE;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CAmBF;;IAbG,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAClC,GAAG,cAAc,OAAO,EACxB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CACrB,CAAC;IACF,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAClC,GAAG,cAAc,MAAM,EACvB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CACpB,CAAC;IACF,IAAI,CAAC,SAAS,CAAC,qBAAqB,CAClC,GAAG,cAAc,SAAS,EAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CACvB,CAAC;AACJ,CAAC;AAGH,eAAe,qBAAqB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n} from '@metamask/base-controller/next';\nimport { BaseController } from '@metamask/base-controller/next';\nimport {\n normalizeEnsName,\n isValidHexAddress,\n isSafeDynamicKey,\n toChecksumHexAddress,\n toHex,\n} from '@metamask/controller-utils';\nimport type { Messenger } from '@metamask/messenger';\nimport type { Hex } from '@metamask/utils';\n\n/**\n * ContactEntry representation\n */\nexport type ContactEntry = {\n /** Hex address of a recipient account */\n address: string;\n /** Nickname associated with this address */\n name: string;\n /** Data time when an account as created/imported */\n importTime?: number;\n};\n\n/**\n * The type of address.\n */\nexport enum AddressType {\n externallyOwnedAccounts = 'EXTERNALLY_OWNED_ACCOUNTS',\n contractAccounts = 'CONTRACT_ACCOUNTS',\n nonAccounts = 'NON_ACCOUNTS',\n}\n\n/**\n * AddressBookEntry represents a contact in the address book.\n */\nexport type AddressBookEntry = {\n /** Hex address of a recipient account */\n address: string;\n /** Nickname associated with this address */\n name: string;\n /** Chain id identifies the current chain */\n chainId: Hex;\n /** User's note about address */\n memo: string;\n /** Indicates if the entry is an ENS name */\n isEns: boolean;\n /** The type of this address */\n addressType?: AddressType;\n /** Timestamp of when this entry was last updated */\n lastUpdatedAt?: number;\n};\n\n/**\n * State for the AddressBookController.\n */\nexport type AddressBookControllerState = {\n /** Map of chainId to address to contact entries */\n addressBook: { [chainId: Hex]: { [address: string]: AddressBookEntry } };\n};\n\n/**\n * The name of the {@link AddressBookController}.\n */\nexport const controllerName = 'AddressBookController';\n\n/**\n * Special chainId used for wallet's own accounts (internal MetaMask accounts).\n * These entries don't trigger sync events as they are not user-created contacts.\n */\nconst WALLET_ACCOUNTS_CHAIN_ID = '*';\n\n/**\n * The action that can be performed to get the state of the {@link AddressBookController}.\n */\nexport type AddressBookControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AddressBookControllerState\n>;\n\n/**\n * The action that can be performed to list contacts from the {@link AddressBookController}.\n */\nexport type AddressBookControllerListAction = {\n type: `${typeof controllerName}:list`;\n handler: AddressBookController['list'];\n};\n\n/**\n * The action that can be performed to set a contact in the {@link AddressBookController}.\n */\nexport type AddressBookControllerSetAction = {\n type: `${typeof controllerName}:set`;\n handler: AddressBookController['set'];\n};\n\n/**\n * The action that can be performed to delete a contact from the {@link AddressBookController}.\n */\nexport type AddressBookControllerDeleteAction = {\n type: `${typeof controllerName}:delete`;\n handler: AddressBookController['delete'];\n};\n\n/**\n * Event emitted when a contact is added or updated\n */\nexport type AddressBookControllerContactUpdatedEvent = {\n type: `${typeof controllerName}:contactUpdated`;\n payload: [AddressBookEntry];\n};\n\n/**\n * Event emitted when a contact is deleted\n */\nexport type AddressBookControllerContactDeletedEvent = {\n type: `${typeof controllerName}:contactDeleted`;\n payload: [AddressBookEntry];\n};\n\n/**\n * The actions that can be performed using the {@link AddressBookController}.\n */\nexport type AddressBookControllerActions =\n | AddressBookControllerGetStateAction\n | AddressBookControllerListAction\n | AddressBookControllerSetAction\n | AddressBookControllerDeleteAction;\n\n/**\n * The event that {@link AddressBookController} can emit.\n */\nexport type AddressBookControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AddressBookControllerState\n>;\n\n/**\n * The events that {@link AddressBookController} can emit.\n */\nexport type AddressBookControllerEvents =\n | AddressBookControllerStateChangeEvent\n | AddressBookControllerContactUpdatedEvent\n | AddressBookControllerContactDeletedEvent;\n\nconst addressBookControllerMetadata = {\n addressBook: {\n includeInStateLogs: true,\n persist: true,\n includeInDebugSnapshot: false,\n usedInUi: true,\n },\n};\n\n/**\n * Get the default {@link AddressBookController} state.\n *\n * @returns The default {@link AddressBookController} state.\n */\nexport const getDefaultAddressBookControllerState =\n (): AddressBookControllerState => {\n return {\n addressBook: {},\n };\n };\n\n/**\n * The messenger of the {@link AddressBookController} for communication.\n */\nexport type AddressBookControllerMessenger = Messenger<\n typeof controllerName,\n AddressBookControllerActions,\n AddressBookControllerEvents\n>;\n\n/**\n * Controller that manages a list of recipient addresses associated with nicknames.\n */\nexport class AddressBookController extends BaseController<\n typeof controllerName,\n AddressBookControllerState,\n AddressBookControllerMessenger\n> {\n /**\n * Creates an AddressBookController instance.\n *\n * @param args - The {@link AddressBookController} arguments.\n * @param args.messenger - The controller messenger instance for communication.\n * @param args.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: AddressBookControllerMessenger;\n state?: Partial<AddressBookControllerState>;\n }) {\n const mergedState = { ...getDefaultAddressBookControllerState(), ...state };\n super({\n messenger,\n metadata: addressBookControllerMetadata,\n name: controllerName,\n state: mergedState,\n });\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Returns all address book entries as an array.\n *\n * @returns Array of all address book entries.\n */\n list(): AddressBookEntry[] {\n const { addressBook } = this.state;\n\n return Object.keys(addressBook).reduce<AddressBookEntry[]>(\n (acc, chainId) => {\n const chainIdHex = chainId as Hex;\n const chainContacts = Object.values(addressBook[chainIdHex]);\n\n return [...acc, ...chainContacts];\n },\n [],\n );\n }\n\n /**\n * Remove all contract entries.\n */\n clear() {\n this.update((state) => {\n state.addressBook = {};\n });\n }\n\n /**\n * Remove a contract entry by address.\n *\n * @param chainId - Chain id identifies the current chain.\n * @param address - Recipient address to delete.\n * @returns Whether the entry was deleted.\n */\n delete(chainId: Hex, address: string) {\n address = toChecksumHexAddress(address);\n if (\n ![chainId, address].every((key) => isSafeDynamicKey(key)) ||\n !isValidHexAddress(address) ||\n !this.state.addressBook[chainId] ||\n !this.state.addressBook[chainId][address]\n ) {\n return false;\n }\n\n const deletedEntry = { ...this.state.addressBook[chainId][address] };\n\n this.update((state) => {\n const chainContacts = state.addressBook[chainId];\n if (chainContacts?.[address]) {\n delete chainContacts[address];\n\n // Clean up empty chainId objects\n if (Object.keys(chainContacts).length === 0) {\n delete state.addressBook[chainId];\n }\n }\n });\n\n // Skip sending delete event for global contacts with chainId '*'\n // These entries with chainId='*' are the wallet's own accounts (internal MetaMask accounts),\n // not user-created contacts. They don't need to trigger sync events.\n if (String(chainId) !== WALLET_ACCOUNTS_CHAIN_ID) {\n this.messenger.publish(\n 'AddressBookController:contactDeleted',\n deletedEntry,\n );\n }\n\n return true;\n }\n\n /**\n * Add or update a contact entry by address.\n *\n * @param address - Recipient address to add or update.\n * @param name - Nickname to associate with this address.\n * @param chainId - Chain id identifies the current chain.\n * @param memo - User's note about address.\n * @param addressType - Contact's address type.\n * @returns Boolean indicating if the address was successfully set.\n */\n set(\n address: string,\n name: string,\n chainId = toHex(1),\n memo = '',\n addressType?: AddressType,\n ) {\n address = toChecksumHexAddress(address);\n if (!isValidHexAddress(address)) {\n return false;\n }\n\n const entry = {\n address,\n chainId,\n isEns: false,\n memo,\n name,\n addressType,\n lastUpdatedAt: Date.now(),\n };\n const ensName = normalizeEnsName(name);\n if (ensName) {\n entry.name = ensName;\n entry.isEns = true;\n }\n\n this.update((state) => {\n state.addressBook = {\n ...this.state.addressBook,\n [chainId]: {\n ...this.state.addressBook[chainId],\n [address]: entry,\n },\n };\n });\n\n // Skip sending update event for global contacts with chainId '*'\n // These entries with chainId='*' are the wallet's own accounts (internal MetaMask accounts),\n // not user-created contacts. They don't need to trigger sync events.\n if (String(chainId) !== WALLET_ACCOUNTS_CHAIN_ID) {\n this.messenger.publish('AddressBookController:contactUpdated', entry);\n }\n\n return true;\n }\n\n /**\n * Registers message handlers for the AddressBookController.\n */\n #registerMessageHandlers() {\n this.messenger.registerActionHandler(\n `${controllerName}:list`,\n this.list.bind(this),\n );\n this.messenger.registerActionHandler(\n `${controllerName}:set`,\n this.set.bind(this),\n );\n this.messenger.registerActionHandler(\n `${controllerName}:delete`,\n this.delete.bind(this),\n );\n }\n}\n\nexport default AddressBookController;\n"]}
1
+ {"version":3,"file":"AddressBookController.mjs","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":";;;;;;AAKA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,EACN,mCAAmC;AAepC;;GAEG;AACH,MAAM,CAAN,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,oEAAqD,CAAA;IACrD,qDAAsC,CAAA;IACtC,2CAA4B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I,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,OAAO,EACxB,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CACrB,CAAC;IACF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,MAAM,EACvB,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC,CACpB,CAAC;IACF,IAAI,CAAC,eAAe,CAAC,qBAAqB,CACxC,GAAG,cAAc,SAAS,EAC1B,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CACvB,CAAC;AACJ,CAAC;AAGH,eAAe,qBAAqB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedMessenger,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport {\n normalizeEnsName,\n isValidHexAddress,\n isSafeDynamicKey,\n toChecksumHexAddress,\n toHex,\n} from '@metamask/controller-utils';\nimport type { Hex } from '@metamask/utils';\n\n/**\n * ContactEntry representation\n */\nexport type ContactEntry = {\n /** Hex address of a recipient account */\n address: string;\n /** Nickname associated with this address */\n name: string;\n /** Data time when an account as created/imported */\n importTime?: number;\n};\n\n/**\n * The type of address.\n */\nexport enum AddressType {\n externallyOwnedAccounts = 'EXTERNALLY_OWNED_ACCOUNTS',\n contractAccounts = 'CONTRACT_ACCOUNTS',\n nonAccounts = 'NON_ACCOUNTS',\n}\n\n/**\n * AddressBookEntry represents a contact in the address book.\n */\nexport type AddressBookEntry = {\n /** Hex address of a recipient account */\n address: string;\n /** Nickname associated with this address */\n name: string;\n /** Chain id identifies the current chain */\n chainId: Hex;\n /** User's note about address */\n memo: string;\n /** Indicates if the entry is an ENS name */\n isEns: boolean;\n /** The type of this address */\n addressType?: AddressType;\n /** Timestamp of when this entry was last updated */\n lastUpdatedAt?: number;\n};\n\n/**\n * State for the AddressBookController.\n */\nexport type AddressBookControllerState = {\n /** Map of chainId to address to contact entries */\n addressBook: { [chainId: Hex]: { [address: string]: AddressBookEntry } };\n};\n\n/**\n * The name of the {@link AddressBookController}.\n */\nexport const controllerName = 'AddressBookController';\n\n/**\n * Special chainId used for wallet's own accounts (internal MetaMask accounts).\n * These entries don't trigger sync events as they are not user-created contacts.\n */\nconst WALLET_ACCOUNTS_CHAIN_ID = '*';\n\n/**\n * The action that can be performed to get the state of the {@link AddressBookController}.\n */\nexport type AddressBookControllerGetStateAction = ControllerGetStateAction<\n typeof controllerName,\n AddressBookControllerState\n>;\n\n/**\n * The action that can be performed to list contacts from the {@link AddressBookController}.\n */\nexport type AddressBookControllerListAction = {\n type: `${typeof controllerName}:list`;\n handler: AddressBookController['list'];\n};\n\n/**\n * The action that can be performed to set a contact in the {@link AddressBookController}.\n */\nexport type AddressBookControllerSetAction = {\n type: `${typeof controllerName}:set`;\n handler: AddressBookController['set'];\n};\n\n/**\n * The action that can be performed to delete a contact from the {@link AddressBookController}.\n */\nexport type AddressBookControllerDeleteAction = {\n type: `${typeof controllerName}:delete`;\n handler: AddressBookController['delete'];\n};\n\n/**\n * Event emitted when a contact is added or updated\n */\nexport type AddressBookControllerContactUpdatedEvent = {\n type: `${typeof controllerName}:contactUpdated`;\n payload: [AddressBookEntry];\n};\n\n/**\n * Event emitted when a contact is deleted\n */\nexport type AddressBookControllerContactDeletedEvent = {\n type: `${typeof controllerName}:contactDeleted`;\n payload: [AddressBookEntry];\n};\n\n/**\n * The actions that can be performed using the {@link AddressBookController}.\n */\nexport type AddressBookControllerActions =\n | AddressBookControllerGetStateAction\n | AddressBookControllerListAction\n | AddressBookControllerSetAction\n | AddressBookControllerDeleteAction;\n\n/**\n * The event that {@link AddressBookController} can emit.\n */\nexport type AddressBookControllerStateChangeEvent = ControllerStateChangeEvent<\n typeof controllerName,\n AddressBookControllerState\n>;\n\n/**\n * The events that {@link AddressBookController} can emit.\n */\nexport type AddressBookControllerEvents =\n | AddressBookControllerStateChangeEvent\n | AddressBookControllerContactUpdatedEvent\n | AddressBookControllerContactDeletedEvent;\n\nconst addressBookControllerMetadata = {\n addressBook: {\n includeInStateLogs: true,\n persist: true,\n anonymous: false,\n usedInUi: true,\n },\n};\n\n/**\n * Get the default {@link AddressBookController} state.\n *\n * @returns The default {@link AddressBookController} state.\n */\nexport const getDefaultAddressBookControllerState =\n (): AddressBookControllerState => {\n return {\n addressBook: {},\n };\n };\n\n/**\n * The messenger of the {@link AddressBookController} for communication.\n */\nexport type AddressBookControllerMessenger = RestrictedMessenger<\n typeof controllerName,\n AddressBookControllerActions,\n AddressBookControllerEvents,\n never,\n never\n>;\n\n/**\n * Controller that manages a list of recipient addresses associated with nicknames.\n */\nexport class AddressBookController extends BaseController<\n typeof controllerName,\n AddressBookControllerState,\n AddressBookControllerMessenger\n> {\n /**\n * Creates an AddressBookController instance.\n *\n * @param args - The {@link AddressBookController} arguments.\n * @param args.messenger - The controller messenger instance for communication.\n * @param args.state - Initial state to set on this controller.\n */\n constructor({\n messenger,\n state,\n }: {\n messenger: AddressBookControllerMessenger;\n state?: Partial<AddressBookControllerState>;\n }) {\n const mergedState = { ...getDefaultAddressBookControllerState(), ...state };\n super({\n messenger,\n metadata: addressBookControllerMetadata,\n name: controllerName,\n state: mergedState,\n });\n\n this.#registerMessageHandlers();\n }\n\n /**\n * Returns all address book entries as an array.\n *\n * @returns Array of all address book entries.\n */\n list(): AddressBookEntry[] {\n const { addressBook } = this.state;\n\n return Object.keys(addressBook).reduce<AddressBookEntry[]>(\n (acc, chainId) => {\n const chainIdHex = chainId as Hex;\n const chainContacts = Object.values(addressBook[chainIdHex]);\n\n return [...acc, ...chainContacts];\n },\n [],\n );\n }\n\n /**\n * Remove all contract entries.\n */\n clear() {\n this.update((state) => {\n state.addressBook = {};\n });\n }\n\n /**\n * Remove a contract entry by address.\n *\n * @param chainId - Chain id identifies the current chain.\n * @param address - Recipient address to delete.\n * @returns Whether the entry was deleted.\n */\n delete(chainId: Hex, address: string) {\n address = toChecksumHexAddress(address);\n if (\n ![chainId, address].every((key) => isSafeDynamicKey(key)) ||\n !isValidHexAddress(address) ||\n !this.state.addressBook[chainId] ||\n !this.state.addressBook[chainId][address]\n ) {\n return false;\n }\n\n const deletedEntry = { ...this.state.addressBook[chainId][address] };\n\n this.update((state) => {\n const chainContacts = state.addressBook[chainId];\n if (chainContacts?.[address]) {\n delete chainContacts[address];\n\n // Clean up empty chainId objects\n if (Object.keys(chainContacts).length === 0) {\n delete state.addressBook[chainId];\n }\n }\n });\n\n // Skip sending delete event for global contacts with chainId '*'\n // These entries with chainId='*' are the wallet's own accounts (internal MetaMask accounts),\n // not user-created contacts. They don't need to trigger sync events.\n if (String(chainId) !== WALLET_ACCOUNTS_CHAIN_ID) {\n this.messagingSystem.publish(\n 'AddressBookController:contactDeleted',\n deletedEntry,\n );\n }\n\n return true;\n }\n\n /**\n * Add or update a contact entry by address.\n *\n * @param address - Recipient address to add or update.\n * @param name - Nickname to associate with this address.\n * @param chainId - Chain id identifies the current chain.\n * @param memo - User's note about address.\n * @param addressType - Contact's address type.\n * @returns Boolean indicating if the address was successfully set.\n */\n set(\n address: string,\n name: string,\n chainId = toHex(1),\n memo = '',\n addressType?: AddressType,\n ) {\n address = toChecksumHexAddress(address);\n if (!isValidHexAddress(address)) {\n return false;\n }\n\n const entry = {\n address,\n chainId,\n isEns: false,\n memo,\n name,\n addressType,\n lastUpdatedAt: Date.now(),\n };\n const ensName = normalizeEnsName(name);\n if (ensName) {\n entry.name = ensName;\n entry.isEns = true;\n }\n\n this.update((state) => {\n state.addressBook = {\n ...this.state.addressBook,\n [chainId]: {\n ...this.state.addressBook[chainId],\n [address]: entry,\n },\n };\n });\n\n // Skip sending update event for global contacts with chainId '*'\n // These entries with chainId='*' are the wallet's own accounts (internal MetaMask accounts),\n // not user-created contacts. They don't need to trigger sync events.\n if (String(chainId) !== WALLET_ACCOUNTS_CHAIN_ID) {\n this.messagingSystem.publish(\n 'AddressBookController:contactUpdated',\n entry,\n );\n }\n\n return true;\n }\n\n /**\n * Registers message handlers for the AddressBookController.\n */\n #registerMessageHandlers() {\n this.messagingSystem.registerActionHandler(\n `${controllerName}:list`,\n this.list.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${controllerName}:set`,\n this.set.bind(this),\n );\n this.messagingSystem.registerActionHandler(\n `${controllerName}:delete`,\n this.delete.bind(this),\n );\n }\n}\n\nexport default AddressBookController;\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/address-book-controller",
3
- "version": "6.2.0-preview-e9856975",
3
+ "version": "6.2.0-preview-83095132",
4
4
  "description": "Manages a list of recipient addresses associated with nicknames",
5
5
  "keywords": [
6
6
  "MetaMask",
@@ -49,7 +49,6 @@
49
49
  "dependencies": {
50
50
  "@metamask/base-controller": "^8.4.1",
51
51
  "@metamask/controller-utils": "^11.14.1",
52
- "@metamask/messenger": "^0.3.0",
53
52
  "@metamask/utils": "^11.8.1"
54
53
  },
55
54
  "devDependencies": {