@metamask-previews/address-book-controller 7.0.1-preview-efc1fb7 → 7.0.1-preview-6cb7e4bcf
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 +7 -0
- package/dist/AddressBookController-method-action-types.cjs +7 -0
- package/dist/AddressBookController-method-action-types.cjs.map +1 -0
- package/dist/AddressBookController-method-action-types.d.cts +51 -0
- package/dist/AddressBookController-method-action-types.d.cts.map +1 -0
- package/dist/AddressBookController-method-action-types.d.mts +51 -0
- package/dist/AddressBookController-method-action-types.d.mts.map +1 -0
- package/dist/AddressBookController-method-action-types.mjs +6 -0
- package/dist/AddressBookController-method-action-types.mjs.map +1 -0
- package/dist/AddressBookController.cjs +2 -13
- package/dist/AddressBookController.cjs.map +1 -1
- package/dist/AddressBookController.d.cts +2 -23
- package/dist/AddressBookController.d.cts.map +1 -1
- package/dist/AddressBookController.d.mts +2 -23
- package/dist/AddressBookController.d.mts.map +1 -1
- package/dist/AddressBookController.mjs +2 -13
- package/dist/AddressBookController.mjs.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +2 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
### Added
|
|
11
|
+
|
|
12
|
+
- Expose missing public `AddressBookController` method through its messenger ([#8183](https://github.com/MetaMask/core/pull/8183))
|
|
13
|
+
- The following action is now available:
|
|
14
|
+
- `AddressBookController:clear`
|
|
15
|
+
- Corresponding action type (`AddressBookControllerClearAction`) is available as well.
|
|
16
|
+
|
|
10
17
|
### Changed
|
|
11
18
|
|
|
12
19
|
- Upgrade `@metamask/utils` from `^11.8.1` to `^11.9.0` ([#7511](https://github.com/MetaMask/core/pull/7511))
|
|
@@ -0,0 +1 @@
|
|
|
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 by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AddressBookController } from './AddressBookController';\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"]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,oCAAgC;AAErE;;;;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"}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file is auto generated by `scripts/generate-method-action-types.ts`.
|
|
3
|
+
* Do not edit manually.
|
|
4
|
+
*/
|
|
5
|
+
import type { AddressBookController } from "./AddressBookController.mjs";
|
|
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.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
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,oCAAgC;AAErE;;;;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"}
|
|
@@ -0,0 +1 @@
|
|
|
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 by `scripts/generate-method-action-types.ts`.\n * Do not edit manually.\n */\n\nimport type { AddressBookController } from './AddressBookController';\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,10 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
3
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
4
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
5
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
6
|
-
};
|
|
7
|
-
var _AddressBookController_instances, _AddressBookController_registerMessageHandlers;
|
|
8
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
3
|
exports.AddressBookController = exports.getDefaultAddressBookControllerState = exports.controllerName = exports.AddressType = void 0;
|
|
10
4
|
const base_controller_1 = require("@metamask/base-controller");
|
|
@@ -27,6 +21,7 @@ exports.controllerName = 'AddressBookController';
|
|
|
27
21
|
* These entries don't trigger sync events as they are not user-created contacts.
|
|
28
22
|
*/
|
|
29
23
|
const WALLET_ACCOUNTS_CHAIN_ID = '*';
|
|
24
|
+
const MESSENGER_EXPOSED_METHODS = ['list', 'set', 'delete', 'clear'];
|
|
30
25
|
const addressBookControllerMetadata = {
|
|
31
26
|
addressBook: {
|
|
32
27
|
includeInStateLogs: true,
|
|
@@ -65,8 +60,7 @@ class AddressBookController extends base_controller_1.BaseController {
|
|
|
65
60
|
name: exports.controllerName,
|
|
66
61
|
state: mergedState,
|
|
67
62
|
});
|
|
68
|
-
|
|
69
|
-
__classPrivateFieldGet(this, _AddressBookController_instances, "m", _AddressBookController_registerMessageHandlers).call(this);
|
|
63
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
70
64
|
}
|
|
71
65
|
/**
|
|
72
66
|
* Returns all address book entries as an array.
|
|
@@ -170,10 +164,5 @@ class AddressBookController extends base_controller_1.BaseController {
|
|
|
170
164
|
}
|
|
171
165
|
}
|
|
172
166
|
exports.AddressBookController = AddressBookController;
|
|
173
|
-
_AddressBookController_instances = new WeakSet(), _AddressBookController_registerMessageHandlers = function _AddressBookController_registerMessageHandlers() {
|
|
174
|
-
this.messenger.registerActionHandler(`${exports.controllerName}:list`, this.list.bind(this));
|
|
175
|
-
this.messenger.registerActionHandler(`${exports.controllerName}:set`, this.set.bind(this));
|
|
176
|
-
this.messenger.registerActionHandler(`${exports.controllerName}:delete`, this.delete.bind(this));
|
|
177
|
-
};
|
|
178
167
|
exports.default = AddressBookController;
|
|
179
168
|
//# sourceMappingURL=AddressBookController.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AddressBookController.cjs","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":";;;;;;;;;AAIA,+DAA2D;AAC3D,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,KAA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Ac,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';\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\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]?.[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":";;;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;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;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,gCAI1C;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,IAAI,CAAC,SAAS,CAAC,4BAA4B,CACzC,IAAI,EACJ,yBAAyB,CAC1B,CAAC;IACJ,CAAC;IAED;;;;OAIG;IACH,IAAI;Q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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;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';\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"]}
|
|
@@ -2,6 +2,7 @@ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@meta
|
|
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
|
3
3
|
import type { Messenger } from "@metamask/messenger";
|
|
4
4
|
import type { Hex } from "@metamask/utils";
|
|
5
|
+
import type { AddressBookControllerMethodActions } from "./AddressBookController-method-action-types.cjs";
|
|
5
6
|
/**
|
|
6
7
|
* ContactEntry representation
|
|
7
8
|
*/
|
|
@@ -59,27 +60,6 @@ export declare const controllerName = "AddressBookController";
|
|
|
59
60
|
* The action that can be performed to get the state of the {@link AddressBookController}.
|
|
60
61
|
*/
|
|
61
62
|
export type AddressBookControllerGetStateAction = ControllerGetStateAction<typeof controllerName, AddressBookControllerState>;
|
|
62
|
-
/**
|
|
63
|
-
* The action that can be performed to list contacts from the {@link AddressBookController}.
|
|
64
|
-
*/
|
|
65
|
-
export type AddressBookControllerListAction = {
|
|
66
|
-
type: `${typeof controllerName}:list`;
|
|
67
|
-
handler: AddressBookController['list'];
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* The action that can be performed to set a contact in the {@link AddressBookController}.
|
|
71
|
-
*/
|
|
72
|
-
export type AddressBookControllerSetAction = {
|
|
73
|
-
type: `${typeof controllerName}:set`;
|
|
74
|
-
handler: AddressBookController['set'];
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* The action that can be performed to delete a contact from the {@link AddressBookController}.
|
|
78
|
-
*/
|
|
79
|
-
export type AddressBookControllerDeleteAction = {
|
|
80
|
-
type: `${typeof controllerName}:delete`;
|
|
81
|
-
handler: AddressBookController['delete'];
|
|
82
|
-
};
|
|
83
63
|
/**
|
|
84
64
|
* Event emitted when a contact is added or updated
|
|
85
65
|
*/
|
|
@@ -97,7 +77,7 @@ export type AddressBookControllerContactDeletedEvent = {
|
|
|
97
77
|
/**
|
|
98
78
|
* The actions that can be performed using the {@link AddressBookController}.
|
|
99
79
|
*/
|
|
100
|
-
export type AddressBookControllerActions = AddressBookControllerGetStateAction |
|
|
80
|
+
export type AddressBookControllerActions = AddressBookControllerGetStateAction | AddressBookControllerMethodActions;
|
|
101
81
|
/**
|
|
102
82
|
* The event that {@link AddressBookController} can emit.
|
|
103
83
|
*/
|
|
@@ -120,7 +100,6 @@ export type AddressBookControllerMessenger = Messenger<typeof controllerName, Ad
|
|
|
120
100
|
* Controller that manages a list of recipient addresses associated with nicknames.
|
|
121
101
|
*/
|
|
122
102
|
export declare class AddressBookController extends BaseController<typeof controllerName, AddressBookControllerState, AddressBookControllerMessenger> {
|
|
123
|
-
#private;
|
|
124
103
|
/**
|
|
125
104
|
* Creates an AddressBookController instance.
|
|
126
105
|
*
|
|
@@ -1 +1 @@
|
|
|
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;;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;
|
|
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,wDAAoD;AAEtG;;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;AAE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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"}
|
|
@@ -2,6 +2,7 @@ import type { ControllerGetStateAction, ControllerStateChangeEvent } from "@meta
|
|
|
2
2
|
import { BaseController } from "@metamask/base-controller";
|
|
3
3
|
import type { Messenger } from "@metamask/messenger";
|
|
4
4
|
import type { Hex } from "@metamask/utils";
|
|
5
|
+
import type { AddressBookControllerMethodActions } from "./AddressBookController-method-action-types.mjs";
|
|
5
6
|
/**
|
|
6
7
|
* ContactEntry representation
|
|
7
8
|
*/
|
|
@@ -59,27 +60,6 @@ export declare const controllerName = "AddressBookController";
|
|
|
59
60
|
* The action that can be performed to get the state of the {@link AddressBookController}.
|
|
60
61
|
*/
|
|
61
62
|
export type AddressBookControllerGetStateAction = ControllerGetStateAction<typeof controllerName, AddressBookControllerState>;
|
|
62
|
-
/**
|
|
63
|
-
* The action that can be performed to list contacts from the {@link AddressBookController}.
|
|
64
|
-
*/
|
|
65
|
-
export type AddressBookControllerListAction = {
|
|
66
|
-
type: `${typeof controllerName}:list`;
|
|
67
|
-
handler: AddressBookController['list'];
|
|
68
|
-
};
|
|
69
|
-
/**
|
|
70
|
-
* The action that can be performed to set a contact in the {@link AddressBookController}.
|
|
71
|
-
*/
|
|
72
|
-
export type AddressBookControllerSetAction = {
|
|
73
|
-
type: `${typeof controllerName}:set`;
|
|
74
|
-
handler: AddressBookController['set'];
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* The action that can be performed to delete a contact from the {@link AddressBookController}.
|
|
78
|
-
*/
|
|
79
|
-
export type AddressBookControllerDeleteAction = {
|
|
80
|
-
type: `${typeof controllerName}:delete`;
|
|
81
|
-
handler: AddressBookController['delete'];
|
|
82
|
-
};
|
|
83
63
|
/**
|
|
84
64
|
* Event emitted when a contact is added or updated
|
|
85
65
|
*/
|
|
@@ -97,7 +77,7 @@ export type AddressBookControllerContactDeletedEvent = {
|
|
|
97
77
|
/**
|
|
98
78
|
* The actions that can be performed using the {@link AddressBookController}.
|
|
99
79
|
*/
|
|
100
|
-
export type AddressBookControllerActions = AddressBookControllerGetStateAction |
|
|
80
|
+
export type AddressBookControllerActions = AddressBookControllerGetStateAction | AddressBookControllerMethodActions;
|
|
101
81
|
/**
|
|
102
82
|
* The event that {@link AddressBookController} can emit.
|
|
103
83
|
*/
|
|
@@ -120,7 +100,6 @@ export type AddressBookControllerMessenger = Messenger<typeof controllerName, Ad
|
|
|
120
100
|
* Controller that manages a list of recipient addresses associated with nicknames.
|
|
121
101
|
*/
|
|
122
102
|
export declare class AddressBookController extends BaseController<typeof controllerName, AddressBookControllerState, AddressBookControllerMessenger> {
|
|
123
|
-
#private;
|
|
124
103
|
/**
|
|
125
104
|
* Creates an AddressBookController instance.
|
|
126
105
|
*
|
|
@@ -1 +1 @@
|
|
|
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;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG;IACzB,yCAAyC;IACzC,OAAO,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AC;IAChD,OAAO,EAAE,CAAC,gBAAgB,CAAC,CAAC;CAC7B,CAAC;AAEF;;GAEG;AACH,MAAM,MAAM,4BAA4B,GACpC,mCAAmC,GACnC,kCAAkC,CAAC;AAEvC;;GAEG;AACH,MAAM,MAAM,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,9 +1,3 @@
|
|
|
1
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
2
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
3
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
4
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
5
|
-
};
|
|
6
|
-
var _AddressBookController_instances, _AddressBookController_registerMessageHandlers;
|
|
7
1
|
import { BaseController } from "@metamask/base-controller";
|
|
8
2
|
import { normalizeEnsName, isValidHexAddress, isSafeDynamicKey, toChecksumHexAddress, toHex } from "@metamask/controller-utils";
|
|
9
3
|
/**
|
|
@@ -24,6 +18,7 @@ export const controllerName = 'AddressBookController';
|
|
|
24
18
|
* These entries don't trigger sync events as they are not user-created contacts.
|
|
25
19
|
*/
|
|
26
20
|
const WALLET_ACCOUNTS_CHAIN_ID = '*';
|
|
21
|
+
const MESSENGER_EXPOSED_METHODS = ['list', 'set', 'delete', 'clear'];
|
|
27
22
|
const addressBookControllerMetadata = {
|
|
28
23
|
addressBook: {
|
|
29
24
|
includeInStateLogs: true,
|
|
@@ -61,8 +56,7 @@ export class AddressBookController extends BaseController {
|
|
|
61
56
|
name: controllerName,
|
|
62
57
|
state: mergedState,
|
|
63
58
|
});
|
|
64
|
-
|
|
65
|
-
__classPrivateFieldGet(this, _AddressBookController_instances, "m", _AddressBookController_registerMessageHandlers).call(this);
|
|
59
|
+
this.messenger.registerMethodActionHandlers(this, MESSENGER_EXPOSED_METHODS);
|
|
66
60
|
}
|
|
67
61
|
/**
|
|
68
62
|
* Returns all address book entries as an array.
|
|
@@ -165,10 +159,5 @@ export class AddressBookController extends BaseController {
|
|
|
165
159
|
return true;
|
|
166
160
|
}
|
|
167
161
|
}
|
|
168
|
-
_AddressBookController_instances = new WeakSet(), _AddressBookController_registerMessageHandlers = function _AddressBookController_registerMessageHandlers() {
|
|
169
|
-
this.messenger.registerActionHandler(`${controllerName}:list`, this.list.bind(this));
|
|
170
|
-
this.messenger.registerActionHandler(`${controllerName}:set`, this.set.bind(this));
|
|
171
|
-
this.messenger.registerActionHandler(`${controllerName}:delete`, this.delete.bind(this));
|
|
172
|
-
};
|
|
173
162
|
export default AddressBookController;
|
|
174
163
|
//# sourceMappingURL=AddressBookController.mjs.map
|
|
@@ -1 +1 @@
|
|
|
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;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,EACV,SAAS,EACT,KAAK,GAIN;QACC,MAAM,WAAW,GAAG,EAAE,GAAG,oCAAoC,EAAE,EAAE,GAAG,KAAK,EAAE,CAAC;QAC5E,KAAK,CAAC;YACJ,SAAS;YACT,QAAQ,EAAE,6BAA6B;YACvC,IAAI,EAAE,cAAc;YACpB,KAA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AM,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;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';\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\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]?.[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":"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,yBAA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Action,\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';\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.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"index.cjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAaA,qEAGiC;AAF/B,6IAAA,oCAAoC,OAAA;AACpC,8HAAA,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';\nexport {\n getDefaultAddressBookControllerState,\n AddressBookController,\n} from './AddressBookController';\n\nexport type {\n AddressBookControllerListAction,\n AddressBookControllerSetAction,\n AddressBookControllerDeleteAction,\n AddressBookControllerClearAction,\n} from './AddressBookController-method-action-types';\n"]}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export type { AddressType, AddressBookEntry, AddressBookControllerState, AddressBookControllerGetStateAction,
|
|
1
|
+
export type { AddressType, AddressBookEntry, AddressBookControllerState, AddressBookControllerGetStateAction, AddressBookControllerActions, AddressBookControllerStateChangeEvent, AddressBookControllerContactUpdatedEvent, AddressBookControllerContactDeletedEvent, AddressBookControllerEvents, AddressBookControllerMessenger, ContactEntry, } from "./AddressBookController.cjs";
|
|
2
2
|
export { getDefaultAddressBookControllerState, AddressBookController, } from "./AddressBookController.cjs";
|
|
3
|
+
export type { AddressBookControllerListAction, AddressBookControllerSetAction, AddressBookControllerDeleteAction, AddressBookControllerClearAction, } from "./AddressBookController-method-action-types.cjs";
|
|
3
4
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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,oCAAgC;AACjC,OAAO,EACL,oCAAoC,EACpC,qBAAqB,GACtB,oCAAgC;AAEjC,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,iCAAiC,EACjC,gCAAgC,GACjC,wDAAoD"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
export type { AddressType, AddressBookEntry, AddressBookControllerState, AddressBookControllerGetStateAction,
|
|
1
|
+
export type { AddressType, AddressBookEntry, AddressBookControllerState, AddressBookControllerGetStateAction, AddressBookControllerActions, AddressBookControllerStateChangeEvent, AddressBookControllerContactUpdatedEvent, AddressBookControllerContactDeletedEvent, AddressBookControllerEvents, AddressBookControllerMessenger, ContactEntry, } from "./AddressBookController.mjs";
|
|
2
2
|
export { getDefaultAddressBookControllerState, AddressBookController, } from "./AddressBookController.mjs";
|
|
3
|
+
export type { AddressBookControllerListAction, AddressBookControllerSetAction, AddressBookControllerDeleteAction, AddressBookControllerClearAction, } from "./AddressBookController-method-action-types.mjs";
|
|
3
4
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
|
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,oCAAgC;AACjC,OAAO,EACL,oCAAoC,EACpC,qBAAqB,GACtB,oCAAgC;AAEjC,YAAY,EACV,+BAA+B,EAC/B,8BAA8B,EAC9B,iCAAiC,EACjC,gCAAgC,GACjC,wDAAoD"}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.mjs","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAaA,OAAO,EACL,oCAAoC,EACpC,qBAAqB,EACtB,oCAAgC","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';\nexport {\n getDefaultAddressBookControllerState,\n AddressBookController,\n} from './AddressBookController';\n\nexport type {\n AddressBookControllerListAction,\n AddressBookControllerSetAction,\n AddressBookControllerDeleteAction,\n AddressBookControllerClearAction,\n} from './AddressBookController-method-action-types';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask-previews/address-book-controller",
|
|
3
|
-
"version": "7.0.1-preview-
|
|
3
|
+
"version": "7.0.1-preview-6cb7e4bcf",
|
|
4
4
|
"description": "Manages a list of recipient addresses associated with nicknames",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
"build:docs": "typedoc",
|
|
41
41
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/address-book-controller",
|
|
42
42
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/address-book-controller",
|
|
43
|
+
"generate-method-action-types": "tsx ../../scripts/generate-method-action-types.ts",
|
|
43
44
|
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
44
45
|
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
45
46
|
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
@@ -59,6 +60,7 @@
|
|
|
59
60
|
"deepmerge": "^4.2.2",
|
|
60
61
|
"jest": "^29.7.0",
|
|
61
62
|
"ts-jest": "^29.2.5",
|
|
63
|
+
"tsx": "^4.20.5",
|
|
62
64
|
"typedoc": "^0.25.13",
|
|
63
65
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
64
66
|
"typescript": "~5.3.3"
|