@metamask-previews/address-book-controller 7.1.2-preview-8bfa290fb → 8.0.0-preview-0a30e47

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 (33) hide show
  1. package/CHANGELOG.md +16 -7
  2. package/dist/{AddressBookController-method-action-types.d.mts → AddressBookController-method-action-types.d.ts} +2 -2
  3. package/dist/AddressBookController-method-action-types.d.ts.map +1 -0
  4. package/dist/{AddressBookController-method-action-types.mjs → AddressBookController-method-action-types.js} +1 -1
  5. package/dist/AddressBookController-method-action-types.js.map +1 -0
  6. package/dist/{AddressBookController.d.cts → AddressBookController.d.ts} +6 -6
  7. package/dist/AddressBookController.d.ts.map +1 -0
  8. package/dist/{AddressBookController.mjs → AddressBookController.js} +3 -3
  9. package/dist/AddressBookController.js.map +1 -0
  10. package/dist/{index.d.cts → index.d.ts} +4 -4
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +2 -0
  13. package/dist/index.js.map +1 -0
  14. package/package.json +15 -19
  15. package/dist/AddressBookController-method-action-types.cjs +0 -7
  16. package/dist/AddressBookController-method-action-types.cjs.map +0 -1
  17. package/dist/AddressBookController-method-action-types.d.cts +0 -51
  18. package/dist/AddressBookController-method-action-types.d.cts.map +0 -1
  19. package/dist/AddressBookController-method-action-types.d.mts.map +0 -1
  20. package/dist/AddressBookController-method-action-types.mjs.map +0 -1
  21. package/dist/AddressBookController.cjs +0 -168
  22. package/dist/AddressBookController.cjs.map +0 -1
  23. package/dist/AddressBookController.d.cts.map +0 -1
  24. package/dist/AddressBookController.d.mts +0 -145
  25. package/dist/AddressBookController.d.mts.map +0 -1
  26. package/dist/AddressBookController.mjs.map +0 -1
  27. package/dist/index.cjs +0 -7
  28. package/dist/index.cjs.map +0 -1
  29. package/dist/index.d.cts.map +0 -1
  30. package/dist/index.d.mts +0 -4
  31. package/dist/index.d.mts.map +0 -1
  32. package/dist/index.mjs +0 -2
  33. package/dist/index.mjs.map +0 -1
package/CHANGELOG.md CHANGED
@@ -7,11 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [8.0.0]
11
+
10
12
  ### Changed
11
13
 
14
+ - **BREAKING:** Drop CommonJS support ([#9536](https://github.com/MetaMask/core/pull/9536))
15
+ - This package is now ESM-only, but can still be used in CommonJS projects via `require(esm)` in modern Node.js versions (22+), or dynamic imports in older Node.js versions.
16
+ - **BREAKING:** Bump minimum Node.js version to 22 ([#9976](https://github.com/MetaMask/core/pull/9976))
17
+ - **BREAKING:** Bump TypeScript target to ES2022 ([#10019](https://github.com/MetaMask/core/pull/10019))
18
+ - This package now ships ES2022 code, requiring a compatible modern environment or bundler configuration to consume.
12
19
  - Bump `@metamask/utils` from `^11.9.0` to `^11.12.0` ([#9074](https://github.com/MetaMask/core/pull/9074), [#10076](https://github.com/MetaMask/core/pull/10076))
13
- - Bump `@metamask/controller-utils` from `^12.0.0` to `^12.3.0` ([#8774](https://github.com/MetaMask/core/pull/8774), [#9058](https://github.com/MetaMask/core/pull/9058), [#9083](https://github.com/MetaMask/core/pull/9083), [#9218](https://github.com/MetaMask/core/pull/9218))
14
- - Bump `@metamask/messenger` from `^1.2.0` to `^2.0.0` ([#9392](https://github.com/MetaMask/core/pull/9392))
20
+ - Bump `@metamask/controller-utils` from `^12.0.0` to `^13.0.0` ([#8774](https://github.com/MetaMask/core/pull/8774), [#9058](https://github.com/MetaMask/core/pull/9058), [#9083](https://github.com/MetaMask/core/pull/9083), [#9218](https://github.com/MetaMask/core/pull/9218), [#10160](https://github.com/MetaMask/core/pull/10160))
21
+ - Bump `@metamask/messenger` from `^1.2.0` to `^3.0.0` ([#9392](https://github.com/MetaMask/core/pull/9392), [#10160](https://github.com/MetaMask/core/pull/10160))
22
+ - Bump `@metamask/base-controller` from `^9.1.0` to `^10.0.0` ([#10160](https://github.com/MetaMask/core/pull/10160))
15
23
 
16
24
  ## [7.1.2]
17
25
 
@@ -106,10 +114,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
106
114
 
107
115
  ### Changed
108
116
 
109
- - Bump `@metamask/base-controller` from `^7.0.2` to `^8.0.0` ([#5079](https://github.com/MetaMask/core/pull/5079)), ([#5135](https://github.com/MetaMask/core/pull/5135)), ([#5305](https://github.com/MetaMask/core/pull/5305))
110
- - Bump `@metamask/controller-utils` from `^11.4.4` to `^11.5.0` ([#5135](https://github.com/MetaMask/core/pull/5135)), ([#5272](https://github.com/MetaMask/core/pull/5272))
117
+ - Bump `@metamask/base-controller` from `^7.0.2` to `^8.0.0` ([#5079](https://github.com/MetaMask/core/pull/5079), [#5135](https://github.com/MetaMask/core/pull/5135), [#5305](https://github.com/MetaMask/core/pull/5305))
118
+ - Bump `@metamask/controller-utils` from `^11.4.4` to `^11.5.0` ([#5135](https://github.com/MetaMask/core/pull/5135), [#5272](https://github.com/MetaMask/core/pull/5272))
111
119
  - Bump `@metamask/rpc-errors` from `^7.0.1` to `^7.0.2` ([#5080](https://github.com/MetaMask/core/pull/5080))
112
- - Bump `@metamask/utils` from `^10.0.0` to `^11.1.0` ([#5080](https://github.com/MetaMask/core/pull/5080)), ([#5223](https://github.com/MetaMask/core/pull/5223))
120
+ - Bump `@metamask/utils` from `^10.0.0` to `^11.1.0` ([#5080](https://github.com/MetaMask/core/pull/5080), [#5223](https://github.com/MetaMask/core/pull/5223))
113
121
 
114
122
  ## [6.0.2]
115
123
 
@@ -131,7 +139,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
131
139
  ["Are the Types Wrong?"](https://arethetypeswrong.github.io/) tool as
132
140
  ["masquerading as CJS"](https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md).
133
141
  All of the ATTW checks now pass.
134
- - Remove chunk files ([#4648](https://github.com/MetaMask/core/pull/4648)).
142
+ - Remove chunk files. ([#4648](https://github.com/MetaMask/core/pull/4648))
135
143
  - Previously, the build tool we used to generate JavaScript files extracted
136
144
  common code to "chunk" files. While this was intended to make this package
137
145
  more tree-shakeable, it also made debugging more difficult for our
@@ -296,7 +304,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
296
304
 
297
305
  All changes listed after this point were applied to this package following the monorepo conversion.
298
306
 
299
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/address-book-controller@7.1.2...HEAD
307
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/address-book-controller@8.0.0...HEAD
308
+ [8.0.0]: https://github.com/MetaMask/core/compare/@metamask/address-book-controller@7.1.2...@metamask/address-book-controller@8.0.0
300
309
  [7.1.2]: https://github.com/MetaMask/core/compare/@metamask/address-book-controller@7.1.1...@metamask/address-book-controller@7.1.2
301
310
  [7.1.1]: https://github.com/MetaMask/core/compare/@metamask/address-book-controller@7.1.0...@metamask/address-book-controller@7.1.1
302
311
  [7.1.0]: https://github.com/MetaMask/core/compare/@metamask/address-book-controller@7.0.1...@metamask/address-book-controller@7.1.0
@@ -2,7 +2,7 @@
2
2
  * This file is auto generated.
3
3
  * Do not edit manually.
4
4
  */
5
- import type { AddressBookController } from "./AddressBookController.mjs";
5
+ import type { AddressBookController } from './AddressBookController.js';
6
6
  /**
7
7
  * Returns all address book entries as an array.
8
8
  *
@@ -48,4 +48,4 @@ export type AddressBookControllerSetAction = {
48
48
  * Union of all AddressBookController action types.
49
49
  */
50
50
  export type AddressBookControllerMethodActions = AddressBookControllerListAction | AddressBookControllerClearAction | AddressBookControllerDeleteAction | AddressBookControllerSetAction;
51
- //# sourceMappingURL=AddressBookController-method-action-types.d.mts.map
51
+ //# sourceMappingURL=AddressBookController-method-action-types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AddressBookController-method-action-types.d.ts","sourceRoot":"","sources":["../src/AddressBookController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,4BAA4B,CAAC;AAExE;;;;GAIG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,qBAAqB,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE,6BAA6B,CAAC;IACpC,OAAO,EAAE,qBAAqB,CAAC,OAAO,CAAC,CAAC;CACzC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,qBAAqB,CAAC,QAAQ,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC;CACvC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAC1C,+BAA+B,GAC/B,gCAAgC,GAChC,iCAAiC,GACjC,8BAA8B,CAAC"}
@@ -3,4 +3,4 @@
3
3
  * Do not edit manually.
4
4
  */
5
5
  export {};
6
- //# sourceMappingURL=AddressBookController-method-action-types.mjs.map
6
+ //# sourceMappingURL=AddressBookController-method-action-types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AddressBookController-method-action-types.js","sourceRoot":"","sources":["../src/AddressBookController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AddressBookController } from './AddressBookController.js';\n\n/**\n * Returns all address book entries as an array.\n *\n * @returns Array of all address book entries.\n */\nexport type AddressBookControllerListAction = {\n type: `AddressBookController:list`;\n handler: AddressBookController['list'];\n};\n\n/**\n * Remove all contract entries.\n */\nexport type AddressBookControllerClearAction = {\n type: `AddressBookController:clear`;\n handler: AddressBookController['clear'];\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 */\nexport type AddressBookControllerDeleteAction = {\n type: `AddressBookController:delete`;\n handler: AddressBookController['delete'];\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 */\nexport type AddressBookControllerSetAction = {\n type: `AddressBookController:set`;\n handler: AddressBookController['set'];\n};\n\n/**\n * Union of all AddressBookController action types.\n */\nexport type AddressBookControllerMethodActions =\n | AddressBookControllerListAction\n | AddressBookControllerClearAction\n | AddressBookControllerDeleteAction\n | AddressBookControllerSetAction;\n"]}
@@ -1,8 +1,8 @@
1
- import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
- import { BaseController } from "@metamask/base-controller";
3
- import type { Messenger } from "@metamask/messenger";
4
- import type { Hex } from "@metamask/utils";
5
- import type { AddressBookControllerMethodActions } from "./AddressBookController-method-action-types.cjs";
1
+ import type { ControllerGetStateAction, ControllerStateChangeEvent } from '@metamask/base-controller';
2
+ import { BaseController } from '@metamask/base-controller';
3
+ import type { Messenger } from '@metamask/messenger';
4
+ import type { Hex } from '@metamask/utils';
5
+ import type { AddressBookControllerMethodActions } from './AddressBookController-method-action-types.js';
6
6
  /**
7
7
  * ContactEntry representation
8
8
  */
@@ -142,4 +142,4 @@ export declare class AddressBookController extends BaseController<typeof control
142
142
  set(address: string, name: string, chainId?: `0x${string}`, memo?: string, addressType?: AddressType): boolean;
143
143
  }
144
144
  export default AddressBookController;
145
- //# sourceMappingURL=AddressBookController.d.cts.map
145
+ //# sourceMappingURL=AddressBookController.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AddressBookController.d.ts","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":"AAAA,OAAO,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AAE,OAAO,EAAE,MAAM,WAmCnC;IAED;;;;;;;;;OASG;IACH,GAAG,CACD,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,gBAAW,EAClB,IAAI,SAAK,EACT,WAAW,CAAC,EAAE,WAAW,WAwC1B;CACF;eAEc,qBAAqB"}
@@ -1,5 +1,5 @@
1
- import { BaseController } from "@metamask/base-controller";
2
- import { normalizeEnsName, isValidHexAddress, isSafeDynamicKey, toChecksumHexAddress, toHex } from "@metamask/controller-utils";
1
+ import { BaseController } from '@metamask/base-controller';
2
+ import { normalizeEnsName, isValidHexAddress, isSafeDynamicKey, toChecksumHexAddress, toHex, } from '@metamask/controller-utils';
3
3
  /**
4
4
  * The type of address.
5
5
  */
@@ -160,4 +160,4 @@ export class AddressBookController extends BaseController {
160
160
  }
161
161
  }
162
162
  export default AddressBookController;
163
- //# sourceMappingURL=AddressBookController.mjs.map
163
+ //# sourceMappingURL=AddressBookController.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AddressBookController.js","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAC;AAC3D,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,GACN,MAAM,4BAA4B,CAAC;AAkBpC;;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;AAErC,MAAM,yBAAyB,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAU,CAAC;AAiD9E,M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ACf,IAAY,EACZ,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,EAClB,IAAI,GAAG,EAAE,EACT,WAAyB;QAEzB,OAAO,GAAG,oBAAoB,CAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,iBAAiB,CAAC,OAAO,CAAC,EAAE,CAAC;YAChC,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,KAAK,GAAG;YACZ,OAAO;YACP,OAAO;YACP,KAAK,EAAE,KAAK;YACZ,IAAI;YACJ,IAAI;YACJ,WAAW;YACX,aAAa,EAAE,IAAI,CAAC,GAAG,EAAE;SAC1B,CAAC;QACF,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,OAAO,EAAE,CAAC;YACZ,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC;YACrB,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC;QACrB,CAAC;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,CAAC;YACjD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,eAAe,qBAAqB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\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 { Messenger } from '@metamask/messenger';\nimport type { Hex } from '@metamask/utils';\n\nimport type { AddressBookControllerMethodActions } from './AddressBookController-method-action-types.js';\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\nconst MESSENGER_EXPOSED_METHODS = ['list', 'set', 'delete', 'clear'] as const;\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 * 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 | AddressBookControllerMethodActions;\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.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\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]?.[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\nexport default AddressBookController;\n"]}
@@ -1,4 +1,4 @@
1
- export type { AddressType, AddressBookEntry, AddressBookControllerState, AddressBookControllerGetStateAction, AddressBookControllerActions, AddressBookControllerStateChangeEvent, AddressBookControllerContactUpdatedEvent, AddressBookControllerContactDeletedEvent, AddressBookControllerEvents, AddressBookControllerMessenger, ContactEntry, } from "./AddressBookController.cjs";
2
- export { getDefaultAddressBookControllerState, AddressBookController, } from "./AddressBookController.cjs";
3
- export type { AddressBookControllerListAction, AddressBookControllerSetAction, AddressBookControllerDeleteAction, AddressBookControllerClearAction, } from "./AddressBookController-method-action-types.cjs";
4
- //# sourceMappingURL=index.d.cts.map
1
+ export type { AddressType, AddressBookEntry, AddressBookControllerState, AddressBookControllerGetStateAction, AddressBookControllerActions, AddressBookControllerStateChangeEvent, AddressBookControllerContactUpdatedEvent, AddressBookControllerContactDeletedEvent, AddressBookControllerEvents, AddressBookControllerMessenger, ContactEntry, } from './AddressBookController.js';
2
+ export { getDefaultAddressBookControllerState, AddressBookController, } from './AddressBookController.js';
3
+ export type { AddressBookControllerListAction, AddressBookControllerSetAction, AddressBookControllerDeleteAction, AddressBookControllerClearAction, } from './AddressBookController-method-action-types.js';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,0BAA0B,EAC1B,mCAAmC,EACnC,4BAA4B,EAC5B,qCAAqC,EACrC,wCAAwC,EACxC,wCAAwC,EACxC,2BAA2B,EAC3B,8BAA8B,EAC9B,YAAY,GACb,MAAM,4BAA4B,CAAC;AACpC,OAAO,EACL,oCAAoC,EACpC,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AAEpC,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,iCAAiC,EACjC,gCAAgC,GACjC,MAAM,gDAAgD,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export { getDefaultAddressBookControllerState, AddressBookController, } from './AddressBookController.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,oCAAoC,EACpC,qBAAqB,GACtB,MAAM,4BAA4B,CAAC","sourcesContent":["export type {\n AddressType,\n AddressBookEntry,\n AddressBookControllerState,\n AddressBookControllerGetStateAction,\n AddressBookControllerActions,\n AddressBookControllerStateChangeEvent,\n AddressBookControllerContactUpdatedEvent,\n AddressBookControllerContactDeletedEvent,\n AddressBookControllerEvents,\n AddressBookControllerMessenger,\n ContactEntry,\n} from './AddressBookController.js';\nexport {\n getDefaultAddressBookControllerState,\n AddressBookController,\n} from './AddressBookController.js';\n\nexport type {\n AddressBookControllerListAction,\n AddressBookControllerSetAction,\n AddressBookControllerDeleteAction,\n AddressBookControllerClearAction,\n} from './AddressBookController-method-action-types.js';\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask-previews/address-book-controller",
3
- "version": "7.1.2-preview-8bfa290fb",
3
+ "version": "8.0.0-preview-0a30e47",
4
4
  "description": "Manages a list of recipient addresses associated with nicknames",
5
5
  "keywords": [
6
6
  "Ethereum",
@@ -18,19 +18,12 @@
18
18
  "files": [
19
19
  "dist/"
20
20
  ],
21
+ "type": "module",
21
22
  "sideEffects": false,
22
- "main": "./dist/index.cjs",
23
- "types": "./dist/index.d.cts",
24
23
  "exports": {
25
24
  ".": {
26
- "import": {
27
- "types": "./dist/index.d.mts",
28
- "default": "./dist/index.mjs"
29
- },
30
- "require": {
31
- "types": "./dist/index.d.cts",
32
- "default": "./dist/index.cjs"
33
- }
25
+ "types": "./dist/index.d.ts",
26
+ "default": "./dist/index.js"
34
27
  },
35
28
  "./package.json": "./package.json"
36
29
  },
@@ -39,9 +32,11 @@
39
32
  "registry": "https://registry.npmjs.org/"
40
33
  },
41
34
  "scripts": {
42
- "build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
43
- "build:all": "ts-bridge --project tsconfig.build.json --verbose --clean",
35
+ "build": "tsc --project tsconfig.build.json",
36
+ "build:all": "tsc --build tsconfig.build.json --verbose",
37
+ "build:clean": "yarn build:only-clean && yarn build",
44
38
  "build:docs": "typedoc",
39
+ "build:only-clean": "rimraf './dist' './tsconfig.build.tsbuildinfo'",
45
40
  "changelog:update": "../../scripts/update-changelog.sh @metamask/address-book-controller",
46
41
  "changelog:validate": "../../scripts/validate-changelog.sh @metamask/address-book-controller",
47
42
  "lint:tsconfigs": "tsx ../../scripts/lint-tsconfigs/lint-tsconfigs.mts",
@@ -55,24 +50,25 @@
55
50
  "test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
56
51
  },
57
52
  "dependencies": {
58
- "@metamask/base-controller": "^9.1.0",
59
- "@metamask/controller-utils": "^12.3.0",
60
- "@metamask/messenger": "^2.0.0",
53
+ "@metamask/base-controller": "^10.0.0",
54
+ "@metamask/controller-utils": "^13.0.0",
55
+ "@metamask/messenger": "^3.0.0",
61
56
  "@metamask/utils": "^11.12.0"
62
57
  },
63
58
  "devDependencies": {
64
59
  "@metamask/auto-changelog": "^6.1.0",
65
- "@ts-bridge/cli": "^0.6.4",
66
60
  "@types/jest": "^30.0.0",
61
+ "@typescript/native": "npm:typescript@^7.0.2",
67
62
  "deepmerge": "^4.2.2",
68
63
  "jest": "^30.4.2",
64
+ "rimraf": "^5.0.5",
69
65
  "ts-jest": "^29.4.11",
70
66
  "tsx": "^4.20.5",
71
67
  "typedoc": "^0.25.13",
72
68
  "typedoc-plugin-missing-exports": "^2.0.0",
73
- "typescript": "~5.3.3"
69
+ "typescript": "npm:@typescript/typescript6@^6.0.2"
74
70
  },
75
71
  "engines": {
76
- "node": "^18.18 || >=20"
72
+ "node": "^22.14.0 || ^24"
77
73
  }
78
74
  }
@@ -1,7 +0,0 @@
1
- "use strict";
2
- /**
3
- * This file is auto generated.
4
- * Do not edit manually.
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- //# sourceMappingURL=AddressBookController-method-action-types.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AddressBookController-method-action-types.cjs","sourceRoot":"","sources":["../src/AddressBookController-method-action-types.ts"],"names":[],"mappings":";AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AddressBookController } from './AddressBookController.js';\n\n/**\n * Returns all address book entries as an array.\n *\n * @returns Array of all address book entries.\n */\nexport type AddressBookControllerListAction = {\n type: `AddressBookController:list`;\n handler: AddressBookController['list'];\n};\n\n/**\n * Remove all contract entries.\n */\nexport type AddressBookControllerClearAction = {\n type: `AddressBookController:clear`;\n handler: AddressBookController['clear'];\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 */\nexport type AddressBookControllerDeleteAction = {\n type: `AddressBookController:delete`;\n handler: AddressBookController['delete'];\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 */\nexport type AddressBookControllerSetAction = {\n type: `AddressBookController:set`;\n handler: AddressBookController['set'];\n};\n\n/**\n * Union of all AddressBookController action types.\n */\nexport type AddressBookControllerMethodActions =\n | AddressBookControllerListAction\n | AddressBookControllerClearAction\n | AddressBookControllerDeleteAction\n | AddressBookControllerSetAction;\n"]}
@@ -1,51 +0,0 @@
1
- /**
2
- * This file is auto generated.
3
- * Do not edit manually.
4
- */
5
- import type { AddressBookController } from "./AddressBookController.cjs";
6
- /**
7
- * Returns all address book entries as an array.
8
- *
9
- * @returns Array of all address book entries.
10
- */
11
- export type AddressBookControllerListAction = {
12
- type: `AddressBookController:list`;
13
- handler: AddressBookController['list'];
14
- };
15
- /**
16
- * Remove all contract entries.
17
- */
18
- export type AddressBookControllerClearAction = {
19
- type: `AddressBookController:clear`;
20
- handler: AddressBookController['clear'];
21
- };
22
- /**
23
- * Remove a contract entry by address.
24
- *
25
- * @param chainId - Chain id identifies the current chain.
26
- * @param address - Recipient address to delete.
27
- * @returns Whether the entry was deleted.
28
- */
29
- export type AddressBookControllerDeleteAction = {
30
- type: `AddressBookController:delete`;
31
- handler: AddressBookController['delete'];
32
- };
33
- /**
34
- * Add or update a contact entry by address.
35
- *
36
- * @param address - Recipient address to add or update.
37
- * @param name - Nickname to associate with this address.
38
- * @param chainId - Chain id identifies the current chain.
39
- * @param memo - User's note about address.
40
- * @param addressType - Contact's address type.
41
- * @returns Boolean indicating if the address was successfully set.
42
- */
43
- export type AddressBookControllerSetAction = {
44
- type: `AddressBookController:set`;
45
- handler: AddressBookController['set'];
46
- };
47
- /**
48
- * Union of all AddressBookController action types.
49
- */
50
- export type AddressBookControllerMethodActions = AddressBookControllerListAction | AddressBookControllerClearAction | AddressBookControllerDeleteAction | AddressBookControllerSetAction;
51
- //# sourceMappingURL=AddressBookController-method-action-types.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AddressBookController-method-action-types.d.cts","sourceRoot":"","sources":["../src/AddressBookController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,oCAAmC;AAExE;;;;GAIG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,qBAAqB,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE,6BAA6B,CAAC;IACpC,OAAO,EAAE,qBAAqB,CAAC,OAAO,CAAC,CAAC;CACzC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,qBAAqB,CAAC,QAAQ,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC;CACvC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAC1C,+BAA+B,GAC/B,gCAAgC,GAChC,iCAAiC,GACjC,8BAA8B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"AddressBookController-method-action-types.d.mts","sourceRoot":"","sources":["../src/AddressBookController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,oCAAmC;AAExE;;;;GAIG;AACH,MAAM,MAAM,+BAA+B,GAAG;IAC5C,IAAI,EAAE,4BAA4B,CAAC;IACnC,OAAO,EAAE,qBAAqB,CAAC,MAAM,CAAC,CAAC;CACxC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,gCAAgC,GAAG;IAC7C,IAAI,EAAE,6BAA6B,CAAC;IACpC,OAAO,EAAE,qBAAqB,CAAC,OAAO,CAAC,CAAC;CACzC,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,MAAM,iCAAiC,GAAG;IAC9C,IAAI,EAAE,8BAA8B,CAAC;IACrC,OAAO,EAAE,qBAAqB,CAAC,QAAQ,CAAC,CAAC;CAC1C,CAAC;AAEF;;;;;;;;;GASG;AACH,MAAM,MAAM,8BAA8B,GAAG;IAC3C,IAAI,EAAE,2BAA2B,CAAC;IAClC,OAAO,EAAE,qBAAqB,CAAC,KAAK,CAAC,CAAC;CACvC,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,kCAAkC,GAC1C,+BAA+B,GAC/B,gCAAgC,GAChC,iCAAiC,GACjC,8BAA8B,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"AddressBookController-method-action-types.mjs","sourceRoot":"","sources":["../src/AddressBookController-method-action-types.ts"],"names":[],"mappings":"AAAA;;;GAGG","sourcesContent":["/**\n * This file is auto generated.\n * Do not edit manually.\n */\n\nimport type { AddressBookController } from './AddressBookController.js';\n\n/**\n * Returns all address book entries as an array.\n *\n * @returns Array of all address book entries.\n */\nexport type AddressBookControllerListAction = {\n type: `AddressBookController:list`;\n handler: AddressBookController['list'];\n};\n\n/**\n * Remove all contract entries.\n */\nexport type AddressBookControllerClearAction = {\n type: `AddressBookController:clear`;\n handler: AddressBookController['clear'];\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 */\nexport type AddressBookControllerDeleteAction = {\n type: `AddressBookController:delete`;\n handler: AddressBookController['delete'];\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 */\nexport type AddressBookControllerSetAction = {\n type: `AddressBookController:set`;\n handler: AddressBookController['set'];\n};\n\n/**\n * Union of all AddressBookController action types.\n */\nexport type AddressBookControllerMethodActions =\n | AddressBookControllerListAction\n | AddressBookControllerClearAction\n | AddressBookControllerDeleteAction\n | AddressBookControllerSetAction;\n"]}
@@ -1,168 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AddressBookController = exports.getDefaultAddressBookControllerState = exports.controllerName = exports.AddressType = void 0;
4
- const base_controller_1 = require("@metamask/base-controller");
5
- const controller_utils_1 = require("@metamask/controller-utils");
6
- /**
7
- * The type of address.
8
- */
9
- var AddressType;
10
- (function (AddressType) {
11
- AddressType["externallyOwnedAccounts"] = "EXTERNALLY_OWNED_ACCOUNTS";
12
- AddressType["contractAccounts"] = "CONTRACT_ACCOUNTS";
13
- AddressType["nonAccounts"] = "NON_ACCOUNTS";
14
- })(AddressType || (exports.AddressType = AddressType = {}));
15
- /**
16
- * The name of the {@link AddressBookController}.
17
- */
18
- exports.controllerName = 'AddressBookController';
19
- /**
20
- * Special chainId used for wallet's own accounts (internal MetaMask accounts).
21
- * These entries don't trigger sync events as they are not user-created contacts.
22
- */
23
- const WALLET_ACCOUNTS_CHAIN_ID = '*';
24
- const MESSENGER_EXPOSED_METHODS = ['list', 'set', 'delete', 'clear'];
25
- const addressBookControllerMetadata = {
26
- addressBook: {
27
- includeInStateLogs: true,
28
- persist: true,
29
- includeInDebugSnapshot: false,
30
- usedInUi: true,
31
- },
32
- };
33
- /**
34
- * Get the default {@link AddressBookController} state.
35
- *
36
- * @returns The default {@link AddressBookController} state.
37
- */
38
- const getDefaultAddressBookControllerState = () => {
39
- return {
40
- addressBook: {},
41
- };
42
- };
43
- exports.getDefaultAddressBookControllerState = getDefaultAddressBookControllerState;
44
- /**
45
- * Controller that manages a list of recipient addresses associated with nicknames.
46
- */
47
- class AddressBookController extends base_controller_1.BaseController {
48
- /**
49
- * Creates an AddressBookController instance.
50
- *
51
- * @param args - The {@link AddressBookController} arguments.
52
- * @param args.messenger - The controller messenger instance for communication.
53
- * @param args.state - Initial state to set on this controller.
54
- */
55
- constructor({ messenger, state, }) {
56
- const mergedState = { ...(0, exports.getDefaultAddressBookControllerState)(), ...state };
57
- super({
58
- messenger,
59
- metadata: addressBookControllerMetadata,
60
- name: exports.controllerName,
61
- state: mergedState,
62
- });
63
- this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
64
- }
65
- /**
66
- * Returns all address book entries as an array.
67
- *
68
- * @returns Array of all address book entries.
69
- */
70
- list() {
71
- const { addressBook } = this.state;
72
- return Object.keys(addressBook).reduce((acc, chainId) => {
73
- const chainIdHex = chainId;
74
- const chainContacts = Object.values(addressBook[chainIdHex]);
75
- return [...acc, ...chainContacts];
76
- }, []);
77
- }
78
- /**
79
- * Remove all contract entries.
80
- */
81
- clear() {
82
- this.update((state) => {
83
- state.addressBook = {};
84
- });
85
- }
86
- /**
87
- * Remove a contract entry by address.
88
- *
89
- * @param chainId - Chain id identifies the current chain.
90
- * @param address - Recipient address to delete.
91
- * @returns Whether the entry was deleted.
92
- */
93
- delete(chainId, address) {
94
- address = (0, controller_utils_1.toChecksumHexAddress)(address);
95
- if (![chainId, address].every((key) => (0, controller_utils_1.isSafeDynamicKey)(key)) ||
96
- !(0, controller_utils_1.isValidHexAddress)(address) ||
97
- !this.state.addressBook[chainId]?.[address]) {
98
- return false;
99
- }
100
- const deletedEntry = { ...this.state.addressBook[chainId][address] };
101
- this.update((state) => {
102
- const chainContacts = state.addressBook[chainId];
103
- if (chainContacts?.[address]) {
104
- delete chainContacts[address];
105
- // Clean up empty chainId objects
106
- if (Object.keys(chainContacts).length === 0) {
107
- delete state.addressBook[chainId];
108
- }
109
- }
110
- });
111
- // Skip sending delete event for global contacts with chainId '*'
112
- // These entries with chainId='*' are the wallet's own accounts (internal MetaMask accounts),
113
- // not user-created contacts. They don't need to trigger sync events.
114
- if (String(chainId) !== WALLET_ACCOUNTS_CHAIN_ID) {
115
- this.messenger.publish('AddressBookController:contactDeleted', deletedEntry);
116
- }
117
- return true;
118
- }
119
- /**
120
- * Add or update a contact entry by address.
121
- *
122
- * @param address - Recipient address to add or update.
123
- * @param name - Nickname to associate with this address.
124
- * @param chainId - Chain id identifies the current chain.
125
- * @param memo - User's note about address.
126
- * @param addressType - Contact's address type.
127
- * @returns Boolean indicating if the address was successfully set.
128
- */
129
- set(address, name, chainId = (0, controller_utils_1.toHex)(1), memo = '', addressType) {
130
- address = (0, controller_utils_1.toChecksumHexAddress)(address);
131
- if (!(0, controller_utils_1.isValidHexAddress)(address)) {
132
- return false;
133
- }
134
- const entry = {
135
- address,
136
- chainId,
137
- isEns: false,
138
- memo,
139
- name,
140
- addressType,
141
- lastUpdatedAt: Date.now(),
142
- };
143
- const ensName = (0, controller_utils_1.normalizeEnsName)(name);
144
- if (ensName) {
145
- entry.name = ensName;
146
- entry.isEns = true;
147
- }
148
- this.update((state) => {
149
- state.addressBook = {
150
- ...this.state.addressBook,
151
- [chainId]: {
152
- ...this.state.addressBook[chainId],
153
- [address]: entry,
154
- },
155
- };
156
- });
157
- // Skip sending update event for global contacts with chainId '*'
158
- // These entries with chainId='*' are the wallet's own accounts (internal MetaMask accounts),
159
- // not user-created contacts. They don't need to trigger sync events.
160
- if (String(chainId) !== WALLET_ACCOUNTS_CHAIN_ID) {
161
- this.messenger.publish('AddressBookController:contactUpdated', entry);
162
- }
163
- return true;
164
- }
165
- }
166
- exports.AddressBookController = AddressBookController;
167
- exports.default = AddressBookController;
168
- //# sourceMappingURL=AddressBookController.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AddressBookController.cjs","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":";;;AAIA,+DAA2D;AAC3D,iEAMoC;AAkBpC;;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;A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AsC,EAAE,KAAK,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAjKD,sDAiKC;AAED,kBAAe,qBAAqB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\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 { Messenger } from '@metamask/messenger';\nimport type { Hex } from '@metamask/utils';\n\nimport type { AddressBookControllerMethodActions } from './AddressBookController-method-action-types.js';\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\nconst MESSENGER_EXPOSED_METHODS = ['list', 'set', 'delete', 'clear'] as const;\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 * 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 | AddressBookControllerMethodActions;\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.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\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]?.[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\nexport default AddressBookController;\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"AddressBookController.d.cts","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAQ3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,kCAAkC,EAAE,wDAAuD;AAEzG;;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;AAC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qCAAqC,GAAG,0BAA0B,CAC5E,OAAO,cAAc,EACrB,0BAA0B,CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,2BAA2B,GACnC,qCAAqC,GACrC,wCAAwC,GACxC,wCAAwC,CAAC;AAW7C;;;;GAIG;AACH,eAAO,MAAM,oCAAoC,QAC3C,0BAIH,CAAC;AAEJ;;GAEG;AACH,MAAM,MAAM,8BAA8B,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;IAeD;;;;OAIG;IACH,IAAI,IAAI,gBAAgB,EAAE;IAc1B;;OAEG;IACH,KAAK;IAML;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM;IAqCpC;;;;;;;;;OASG;IACH,GAAG,CACD,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,gBAAW,EAClB,IAAI,SAAK,EACT,WAAW,CAAC,EAAE,WAAW;CAyC5B;AAED,eAAe,qBAAqB,CAAC"}
@@ -1,145 +0,0 @@
1
- import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@metamask/base-controller";
2
- import { BaseController } from "@metamask/base-controller";
3
- import type { Messenger } from "@metamask/messenger";
4
- import type { Hex } from "@metamask/utils";
5
- import type { AddressBookControllerMethodActions } from "./AddressBookController-method-action-types.mjs";
6
- /**
7
- * ContactEntry representation
8
- */
9
- export type ContactEntry = {
10
- /** Hex address of a recipient account */
11
- address: string;
12
- /** Nickname associated with this address */
13
- name: string;
14
- /** Data time when an account as created/imported */
15
- importTime?: number;
16
- };
17
- /**
18
- * The type of address.
19
- */
20
- export declare enum AddressType {
21
- externallyOwnedAccounts = "EXTERNALLY_OWNED_ACCOUNTS",
22
- contractAccounts = "CONTRACT_ACCOUNTS",
23
- nonAccounts = "NON_ACCOUNTS"
24
- }
25
- /**
26
- * AddressBookEntry represents a contact in the address book.
27
- */
28
- export type AddressBookEntry = {
29
- /** Hex address of a recipient account */
30
- address: string;
31
- /** Nickname associated with this address */
32
- name: string;
33
- /** Chain id identifies the current chain */
34
- chainId: Hex;
35
- /** User's note about address */
36
- memo: string;
37
- /** Indicates if the entry is an ENS name */
38
- isEns: boolean;
39
- /** The type of this address */
40
- addressType?: AddressType;
41
- /** Timestamp of when this entry was last updated */
42
- lastUpdatedAt?: number;
43
- };
44
- /**
45
- * State for the AddressBookController.
46
- */
47
- export type AddressBookControllerState = {
48
- /** Map of chainId to address to contact entries */
49
- addressBook: {
50
- [chainId: Hex]: {
51
- [address: string]: AddressBookEntry;
52
- };
53
- };
54
- };
55
- /**
56
- * The name of the {@link AddressBookController}.
57
- */
58
- export declare const controllerName = "AddressBookController";
59
- /**
60
- * The action that can be performed to get the state of the {@link AddressBookController}.
61
- */
62
- export type AddressBookControllerGetStateAction = ControllerGetStateAction<typeof controllerName, AddressBookControllerState>;
63
- /**
64
- * Event emitted when a contact is added or updated
65
- */
66
- export type AddressBookControllerContactUpdatedEvent = {
67
- type: `${typeof controllerName}:contactUpdated`;
68
- payload: [AddressBookEntry];
69
- };
70
- /**
71
- * Event emitted when a contact is deleted
72
- */
73
- export type AddressBookControllerContactDeletedEvent = {
74
- type: `${typeof controllerName}:contactDeleted`;
75
- payload: [AddressBookEntry];
76
- };
77
- /**
78
- * The actions that can be performed using the {@link AddressBookController}.
79
- */
80
- export type AddressBookControllerActions = AddressBookControllerGetStateAction | AddressBookControllerMethodActions;
81
- /**
82
- * The event that {@link AddressBookController} can emit.
83
- */
84
- export type AddressBookControllerStateChangeEvent = ControllerStateChangeEvent<typeof controllerName, AddressBookControllerState>;
85
- /**
86
- * The events that {@link AddressBookController} can emit.
87
- */
88
- export type AddressBookControllerEvents = AddressBookControllerStateChangeEvent | AddressBookControllerContactUpdatedEvent | AddressBookControllerContactDeletedEvent;
89
- /**
90
- * Get the default {@link AddressBookController} state.
91
- *
92
- * @returns The default {@link AddressBookController} state.
93
- */
94
- export declare const getDefaultAddressBookControllerState: () => AddressBookControllerState;
95
- /**
96
- * The messenger of the {@link AddressBookController} for communication.
97
- */
98
- export type AddressBookControllerMessenger = Messenger<typeof controllerName, AddressBookControllerActions, AddressBookControllerEvents>;
99
- /**
100
- * Controller that manages a list of recipient addresses associated with nicknames.
101
- */
102
- export declare class AddressBookController extends BaseController<typeof controllerName, AddressBookControllerState, AddressBookControllerMessenger> {
103
- /**
104
- * Creates an AddressBookController instance.
105
- *
106
- * @param args - The {@link AddressBookController} arguments.
107
- * @param args.messenger - The controller messenger instance for communication.
108
- * @param args.state - Initial state to set on this controller.
109
- */
110
- constructor({ messenger, state, }: {
111
- messenger: AddressBookControllerMessenger;
112
- state?: Partial<AddressBookControllerState>;
113
- });
114
- /**
115
- * Returns all address book entries as an array.
116
- *
117
- * @returns Array of all address book entries.
118
- */
119
- list(): AddressBookEntry[];
120
- /**
121
- * Remove all contract entries.
122
- */
123
- clear(): void;
124
- /**
125
- * Remove a contract entry by address.
126
- *
127
- * @param chainId - Chain id identifies the current chain.
128
- * @param address - Recipient address to delete.
129
- * @returns Whether the entry was deleted.
130
- */
131
- delete(chainId: Hex, address: string): boolean;
132
- /**
133
- * Add or update a contact entry by address.
134
- *
135
- * @param address - Recipient address to add or update.
136
- * @param name - Nickname to associate with this address.
137
- * @param chainId - Chain id identifies the current chain.
138
- * @param memo - User's note about address.
139
- * @param addressType - Contact's address type.
140
- * @returns Boolean indicating if the address was successfully set.
141
- */
142
- set(address: string, name: string, chainId?: `0x${string}`, memo?: string, addressType?: AddressType): boolean;
143
- }
144
- export default AddressBookController;
145
- //# sourceMappingURL=AddressBookController.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AddressBookController.d.mts","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,wBAAwB,EACxB,0BAA0B,EAC3B,kCAAkC;AACnC,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAQ3D,OAAO,KAAK,EAAE,SAAS,EAAE,4BAA4B;AACrD,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAE3C,OAAO,KAAK,EAAE,kCAAkC,EAAE,wDAAuD;AAEzG;;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,C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;;;OAMG;IACH,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM;IAqCpC;;;;;;;;;OASG;IACH,GAAG,CACD,OAAO,EAAE,MAAM,EACf,IAAI,EAAE,MAAM,EACZ,OAAO,gBAAW,EAClB,IAAI,SAAK,EACT,WAAW,CAAC,EAAE,WAAW;CAyC5B;AAED,eAAe,qBAAqB,CAAC"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"AddressBookController.mjs","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAC3D,OAAO,EACL,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,oBAAoB,EACpB,KAAK,EACN,mCAAmC;AAkBpC;;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;AAErC,MAAM,yBAAyB,GAAG,CAAC,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,CAAU,CAAC;AAiD9E,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,EACV,S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;SAC1B,CAAC;QACF,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC;QACvC,IAAI,OAAO,EAAE,CAAC;YACZ,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC;YACrB,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC;QACrB,CAAC;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,CAAC;YACjD,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,sCAAsC,EAAE,KAAK,CAAC,CAAC;QACxE,CAAC;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAED,eAAe,qBAAqB,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\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 { Messenger } from '@metamask/messenger';\nimport type { Hex } from '@metamask/utils';\n\nimport type { AddressBookControllerMethodActions } from './AddressBookController-method-action-types.js';\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\nconst MESSENGER_EXPOSED_METHODS = ['list', 'set', 'delete', 'clear'] as const;\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 * 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 | AddressBookControllerMethodActions;\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.messenger.registerMethodActionHandlers(\n this,\n MESSENGER_EXPOSED_METHODS,\n );\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]?.[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\nexport default AddressBookController;\n"]}
package/dist/index.cjs DELETED
@@ -1,7 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.AddressBookController = exports.getDefaultAddressBookControllerState = void 0;
4
- var AddressBookController_js_1 = require("./AddressBookController.cjs");
5
- Object.defineProperty(exports, "getDefaultAddressBookControllerState", { enumerable: true, get: function () { return AddressBookController_js_1.getDefaultAddressBookControllerState; } });
6
- Object.defineProperty(exports, "AddressBookController", { enumerable: true, get: function () { return AddressBookController_js_1.AddressBookController; } });
7
- //# sourceMappingURL=index.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAaA,wEAGoC;AAFlC,gJAAA,oCAAoC,OAAA;AACpC,iIAAA,qBAAqB,OAAA","sourcesContent":["export type {\n AddressType,\n AddressBookEntry,\n AddressBookControllerState,\n AddressBookControllerGetStateAction,\n AddressBookControllerActions,\n AddressBookControllerStateChangeEvent,\n AddressBookControllerContactUpdatedEvent,\n AddressBookControllerContactDeletedEvent,\n AddressBookControllerEvents,\n AddressBookControllerMessenger,\n ContactEntry,\n} from './AddressBookController.js';\nexport {\n getDefaultAddressBookControllerState,\n AddressBookController,\n} from './AddressBookController.js';\n\nexport type {\n AddressBookControllerListAction,\n AddressBookControllerSetAction,\n AddressBookControllerDeleteAction,\n AddressBookControllerClearAction,\n} from './AddressBookController-method-action-types.js';\n"]}
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,0BAA0B,EAC1B,mCAAmC,EACnC,4BAA4B,EAC5B,qCAAqC,EACrC,wCAAwC,EACxC,wCAAwC,EACxC,2BAA2B,EAC3B,8BAA8B,EAC9B,YAAY,GACb,oCAAmC;AACpC,OAAO,EACL,oCAAoC,EACpC,qBAAqB,GACtB,oCAAmC;AAEpC,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,iCAAiC,EACjC,gCAAgC,GACjC,wDAAuD"}
package/dist/index.d.mts DELETED
@@ -1,4 +0,0 @@
1
- export type { AddressType, AddressBookEntry, AddressBookControllerState, AddressBookControllerGetStateAction, AddressBookControllerActions, AddressBookControllerStateChangeEvent, AddressBookControllerContactUpdatedEvent, AddressBookControllerContactDeletedEvent, AddressBookControllerEvents, AddressBookControllerMessenger, ContactEntry, } from "./AddressBookController.mjs";
2
- export { getDefaultAddressBookControllerState, AddressBookController, } from "./AddressBookController.mjs";
3
- export type { AddressBookControllerListAction, AddressBookControllerSetAction, AddressBookControllerDeleteAction, AddressBookControllerClearAction, } from "./AddressBookController-method-action-types.mjs";
4
- //# sourceMappingURL=index.d.mts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,WAAW,EACX,gBAAgB,EAChB,0BAA0B,EAC1B,mCAAmC,EACnC,4BAA4B,EAC5B,qCAAqC,EACrC,wCAAwC,EACxC,wCAAwC,EACxC,2BAA2B,EAC3B,8BAA8B,EAC9B,YAAY,GACb,oCAAmC;AACpC,OAAO,EACL,oCAAoC,EACpC,qBAAqB,GACtB,oCAAmC;AAEpC,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,iCAAiC,EACjC,gCAAgC,GACjC,wDAAuD"}
package/dist/index.mjs DELETED
@@ -1,2 +0,0 @@
1
- export { getDefaultAddressBookControllerState, AddressBookController } from "./AddressBookController.mjs";
2
- //# sourceMappingURL=index.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,oCAAoC,EACpC,qBAAqB,EACtB,oCAAmC","sourcesContent":["export type {\n AddressType,\n AddressBookEntry,\n AddressBookControllerState,\n AddressBookControllerGetStateAction,\n AddressBookControllerActions,\n AddressBookControllerStateChangeEvent,\n AddressBookControllerContactUpdatedEvent,\n AddressBookControllerContactDeletedEvent,\n AddressBookControllerEvents,\n AddressBookControllerMessenger,\n ContactEntry,\n} from './AddressBookController.js';\nexport {\n getDefaultAddressBookControllerState,\n AddressBookController,\n} from './AddressBookController.js';\n\nexport type {\n AddressBookControllerListAction,\n AddressBookControllerSetAction,\n AddressBookControllerDeleteAction,\n AddressBookControllerClearAction,\n} from './AddressBookController-method-action-types.js';\n"]}