@metamask/address-book-controller
Advanced tools
+12
-5
@@ -9,5 +9,11 @@ # Changelog | ||
| ## [1.1.0] | ||
| ### Changed | ||
| - Add optional `addressType` property to address book entries ([#828](https://github.com/MetaMask/controllers/pull/828), [#1068](https://github.com/MetaMask/core/pull/1068)) | ||
| - Rename this repository to `core` ([#1031](https://github.com/MetaMask/controllers/pull/1031)) | ||
| - Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041)) | ||
| ## [1.0.1] | ||
| ### Changed | ||
| - Relax dependencies on `@metamask/base-controller` and `@metamask/controller-utils` (use `^` instead of `~`) ([#998](https://github.com/MetaMask/controllers/pull/998)) | ||
| - Relax dependencies on `@metamask/base-controller` and `@metamask/controller-utils` (use `^` instead of `~`) ([#998](https://github.com/MetaMask/core/pull/998)) | ||
@@ -17,3 +23,3 @@ ## [1.0.0] | ||
| - Initial release | ||
| - As a result of converting our shared controllers repo into a monorepo ([#831](https://github.com/MetaMask/controllers/pull/831)), we've created this package from select parts of [`@metamask/controllers` v33.0.0](https://github.com/MetaMask/controllers/tree/v33.0.0), namely: | ||
| - As a result of converting our shared controllers repo into a monorepo ([#831](https://github.com/MetaMask/core/pull/831)), we've created this package from select parts of [`@metamask/controllers` v33.0.0](https://github.com/MetaMask/core/tree/v33.0.0), namely: | ||
| - `src/user/AddressBookController.ts` | ||
@@ -24,4 +30,5 @@ - `src/user/AddressBookController.test.ts` | ||
| [Unreleased]: https://github.com/MetaMask/controllers/compare/@metamask/address-book-controller@1.0.1...HEAD | ||
| [1.0.1]: https://github.com/MetaMask/controllers/compare/@metamask/address-book-controller@1.0.0...@metamask/address-book-controller@1.0.1 | ||
| [1.0.0]: https://github.com/MetaMask/controllers/releases/tag/@metamask/address-book-controller@1.0.0 | ||
| [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/address-book-controller@1.1.0...HEAD | ||
| [1.1.0]: https://github.com/MetaMask/core/compare/@metamask/address-book-controller@1.0.1...@metamask/address-book-controller@1.1.0 | ||
| [1.0.1]: https://github.com/MetaMask/core/compare/@metamask/address-book-controller@1.0.0...@metamask/address-book-controller@1.0.1 | ||
| [1.0.0]: https://github.com/MetaMask/core/releases/tag/@metamask/address-book-controller@1.0.0 |
@@ -15,2 +15,7 @@ import { BaseController, BaseConfig, BaseState } from '@metamask/base-controller'; | ||
| } | ||
| export declare enum AddressType { | ||
| externallyOwnedAccounts = "EXTERNALLY_OWNED_ACCOUNTS", | ||
| contractAccounts = "CONTRACT_ACCOUNTS", | ||
| nonAccounts = "NON_ACCOUNTS" | ||
| } | ||
| /** | ||
@@ -25,2 +30,3 @@ * @type AddressBookEntry | ||
| * @property isEns - is the entry an ENS name | ||
| * @property addressType - is the type of this address | ||
| */ | ||
@@ -33,2 +39,3 @@ export interface AddressBookEntry { | ||
| isEns: boolean; | ||
| addressType?: AddressType; | ||
| } | ||
@@ -82,6 +89,7 @@ /** | ||
| * @param memo - User's note about address. | ||
| * @param addressType - Contact's address type. | ||
| * @returns Boolean indicating if the address was successfully set. | ||
| */ | ||
| set(address: string, name: string, chainId?: string, memo?: string): boolean; | ||
| set(address: string, name: string, chainId?: string, memo?: string, addressType?: AddressType): boolean; | ||
| } | ||
| export default AddressBookController; |
| "use strict"; | ||
| Object.defineProperty(exports, "__esModule", { value: true }); | ||
| exports.AddressBookController = void 0; | ||
| exports.AddressBookController = exports.AddressType = void 0; | ||
| const controller_utils_1 = require("@metamask/controller-utils"); | ||
| const base_controller_1 = require("@metamask/base-controller"); | ||
| var AddressType; | ||
| (function (AddressType) { | ||
| AddressType["externallyOwnedAccounts"] = "EXTERNALLY_OWNED_ACCOUNTS"; | ||
| AddressType["contractAccounts"] = "CONTRACT_ACCOUNTS"; | ||
| AddressType["nonAccounts"] = "NON_ACCOUNTS"; | ||
| })(AddressType = exports.AddressType || (exports.AddressType = {})); | ||
| /** | ||
@@ -60,5 +66,6 @@ * Controller that manages a list of recipient addresses associated with nicknames. | ||
| * @param memo - User's note about address. | ||
| * @param addressType - Contact's address type. | ||
| * @returns Boolean indicating if the address was successfully set. | ||
| */ | ||
| set(address, name, chainId = '1', memo = '') { | ||
| set(address, name, chainId = '1', memo = '', addressType) { | ||
| address = (0, controller_utils_1.toChecksumHexAddress)(address); | ||
@@ -74,2 +81,3 @@ if (!(0, controller_utils_1.isValidHexAddress)(address)) { | ||
| name, | ||
| addressType, | ||
| }; | ||
@@ -76,0 +84,0 @@ const ensName = (0, controller_utils_1.normalizeEnsName)(name); |
@@ -1,1 +0,1 @@ | ||
| {"version":3,"file":"AddressBookController.js","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":";;;AAAA,iEAIoC;AACpC,+DAImC;AA4CnC;;GAEG;AACH,MAAa,qBAAsB,SAAQ,gCAG1C;IAMC;;;;;OAKG;IACH,YAAY,MAA4B,EAAE,KAAiC;QACzE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAZvB;;WAEG;QACM,SAAI,GAAG,uBAAuB,CAAC;QAWtC,IAAI,CAAC,YAAY,GAAG,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;QAExC,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;IACnC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,OAAe,EAAE,OAAe;QACrC,OAAO,GAAG,IAAA,uCAAoB,EAAC,OAAO,CAAC,CAAC;QACxC,IACE,CAAC,IAAA,oCAAiB,EAAC,OAAO,CAAC;YAC3B,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC;YAChC,CAAC,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,EACzC;YACA,OAAO,KAAK,CAAC;SACd;QAED,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,CAAC;QAC9D,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC,OAAO,CAAC,CAAC;QAErC,IAAI,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE;YAClD,OAAO,WAAW,CAAC,OAAO,CAAC,CAAC;SAC7B;QAED,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC,CAAC;QAC7B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;OAQG;IACH,GAAG,CAAC,OAAe,EAAE,IAAY,EAAE,OAAO,GAAG,GAAG,EAAE,IAAI,GAAG,EAAE;QACzD,OAAO,GAAG,IAAA,uCAAoB,EAAC,OAAO,CAAC,CAAC;QACxC,IAAI,CAAC,IAAA,oCAAiB,EAAC,OAAO,CAAC,EAAE;YAC/B,OAAO,KAAK,CAAC;SACd;QAED,MAAM,KAAK,GAAG;YACZ,OAAO;YACP,OAAO;YACP,KAAK,EAAE,KAAK;YACZ,IAAI;YACJ,IAAI;SACL,CAAC;QAEF,MAAM,OAAO,GAAG,IAAA,mCAAgB,EAAC,IAAI,CAAC,CAAC;QACvC,IAAI,OAAO,EAAE;YACX,KAAK,CAAC,IAAI,GAAG,OAAO,CAAC;YACrB,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC;SACpB;QAED,IAAI,CAAC,MAAM,CAAC;YACV,WAAW,kCACN,IAAI,CAAC,KAAK,CAAC,WAAW,KACzB,CAAC,OAAO,CAAC,kCACJ,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,KAClC,CAAC,OAAO,CAAC,EAAE,KAAK,MAEnB;SACF,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAnGD,sDAmGC;AAED,kBAAe,qBAAqB,CAAC","sourcesContent":["import {\n normalizeEnsName,\n isValidHexAddress,\n toChecksumHexAddress,\n} from '@metamask/controller-utils';\nimport {\n BaseController,\n BaseConfig,\n BaseState,\n} from '@metamask/base-controller';\n\n/**\n * @type ContactEntry\n *\n * ContactEntry representation\n * @property address - Hex address of a recipient account\n * @property name - Nickname associated with this address\n * @property importTime - Data time when an account as created/imported\n */\nexport interface ContactEntry {\n address: string;\n name: string;\n importTime?: number;\n}\n\n/**\n * @type AddressBookEntry\n *\n * AddressBookEntry representation\n * @property address - Hex address of a recipient account\n * @property name - Nickname associated with this address\n * @property chainId - Chain id identifies the current chain\n * @property memo - User's note about address\n * @property isEns - is the entry an ENS name\n */\nexport interface AddressBookEntry {\n address: string;\n name: string;\n chainId: string;\n memo: string;\n isEns: boolean;\n}\n\n/**\n * @type AddressBookState\n *\n * Address book controller state\n * @property addressBook - Array of contact entry objects\n */\nexport interface AddressBookState extends BaseState {\n addressBook: { [chainId: string]: { [address: string]: AddressBookEntry } };\n}\n\n/**\n * Controller that manages a list of recipient addresses associated with nicknames.\n */\nexport class AddressBookController extends BaseController<\n BaseConfig,\n AddressBookState\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'AddressBookController';\n\n /**\n * Creates an AddressBookController instance.\n *\n * @param config - Initial options used to configure this controller.\n * @param state - Initial state to set on this controller.\n */\n constructor(config?: Partial<BaseConfig>, state?: Partial<AddressBookState>) {\n super(config, state);\n\n this.defaultState = { addressBook: {} };\n\n this.initialize();\n }\n\n /**\n * Remove all contract entries.\n */\n clear() {\n this.update({ addressBook: {} });\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: string, address: string) {\n address = toChecksumHexAddress(address);\n if (\n !isValidHexAddress(address) ||\n !this.state.addressBook[chainId] ||\n !this.state.addressBook[chainId][address]\n ) {\n return false;\n }\n\n const addressBook = Object.assign({}, this.state.addressBook);\n delete addressBook[chainId][address];\n\n if (Object.keys(addressBook[chainId]).length === 0) {\n delete addressBook[chainId];\n }\n\n this.update({ addressBook });\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 * @returns Boolean indicating if the address was successfully set.\n */\n set(address: string, name: string, chainId = '1', memo = '') {\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 };\n\n const ensName = normalizeEnsName(name);\n if (ensName) {\n entry.name = ensName;\n entry.isEns = true;\n }\n\n this.update({\n addressBook: {\n ...this.state.addressBook,\n [chainId]: {\n ...this.state.addressBook[chainId],\n [address]: entry,\n },\n },\n });\n\n return true;\n }\n}\n\nexport default AddressBookController;\n"]} | ||
| {"version":3,"file":"AddressBookController.js","sourceRoot":"","sources":["../src/AddressBookController.ts"],"names":[],"mappings":";;;AAAA,iEAIoC;AACpC,+DAImC;AAgBnC,IAAY,WAIX;AAJD,WAAY,WAAW;IACrB,oEAAqD,CAAA;IACrD,qDAAsC,CAAA;IACtC,2CAA4B,CAAA;AAC9B,CAAC,EAJW,WAAW,GAAX,mBAAW,KAAX,mBAAW,QAItB;AAgCD;;GAEG;AACH,MAAa,qBAAsB,SAAQ,gCAG1C;IAMC;;;;;OAKG;IACH,YAAY,MAA4B,EAAE,KAAiC;QACzE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;QAZvB;;WAEG;QACM,SAAI,GAAG,uBAAuB,CAAC;QAWtC,IAAI,CAAC,YAAY,GAAG,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC;QAExC,IAAI,CAAC,UAAU,EAAE,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,EAAE,EAAE,CAAC,CAAC;IACnC,CAAC;IAED;;;;;;OAMG;IACH,MAAM,CAAC,OAAe,EAAE,OAAe;QACrC,OAAO,GAAG,IAAA,uCAAoB,EAAC,OA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N,IAAI,CAAC,KAAK,CAAC,WAAW,KACzB,CAAC,OAAO,CAAC,kCACJ,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,KAClC,CAAC,OAAO,CAAC,EAAE,KAAK,MAEnB;SACF,CAAC,CAAC;QAEH,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AA3GD,sDA2GC;AAED,kBAAe,qBAAqB,CAAC","sourcesContent":["import {\n normalizeEnsName,\n isValidHexAddress,\n toChecksumHexAddress,\n} from '@metamask/controller-utils';\nimport {\n BaseController,\n BaseConfig,\n BaseState,\n} from '@metamask/base-controller';\n\n/**\n * @type ContactEntry\n *\n * ContactEntry representation\n * @property address - Hex address of a recipient account\n * @property name - Nickname associated with this address\n * @property importTime - Data time when an account as created/imported\n */\nexport interface ContactEntry {\n address: string;\n name: string;\n importTime?: number;\n}\n\nexport enum AddressType {\n externallyOwnedAccounts = 'EXTERNALLY_OWNED_ACCOUNTS',\n contractAccounts = 'CONTRACT_ACCOUNTS',\n nonAccounts = 'NON_ACCOUNTS',\n}\n\n/**\n * @type AddressBookEntry\n *\n * AddressBookEntry representation\n * @property address - Hex address of a recipient account\n * @property name - Nickname associated with this address\n * @property chainId - Chain id identifies the current chain\n * @property memo - User's note about address\n * @property isEns - is the entry an ENS name\n * @property addressType - is the type of this address\n */\nexport interface AddressBookEntry {\n address: string;\n name: string;\n chainId: string;\n memo: string;\n isEns: boolean;\n addressType?: AddressType;\n}\n\n/**\n * @type AddressBookState\n *\n * Address book controller state\n * @property addressBook - Array of contact entry objects\n */\nexport interface AddressBookState extends BaseState {\n addressBook: { [chainId: string]: { [address: string]: AddressBookEntry } };\n}\n\n/**\n * Controller that manages a list of recipient addresses associated with nicknames.\n */\nexport class AddressBookController extends BaseController<\n BaseConfig,\n AddressBookState\n> {\n /**\n * Name of this controller used during composition\n */\n override name = 'AddressBookController';\n\n /**\n * Creates an AddressBookController instance.\n *\n * @param config - Initial options used to configure this controller.\n * @param state - Initial state to set on this controller.\n */\n constructor(config?: Partial<BaseConfig>, state?: Partial<AddressBookState>) {\n super(config, state);\n\n this.defaultState = { addressBook: {} };\n\n this.initialize();\n }\n\n /**\n * Remove all contract entries.\n */\n clear() {\n this.update({ addressBook: {} });\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: string, address: string) {\n address = toChecksumHexAddress(address);\n if (\n !isValidHexAddress(address) ||\n !this.state.addressBook[chainId] ||\n !this.state.addressBook[chainId][address]\n ) {\n return false;\n }\n\n const addressBook = Object.assign({}, this.state.addressBook);\n delete addressBook[chainId][address];\n\n if (Object.keys(addressBook[chainId]).length === 0) {\n delete addressBook[chainId];\n }\n\n this.update({ addressBook });\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 = '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 };\n\n const ensName = normalizeEnsName(name);\n if (ensName) {\n entry.name = ensName;\n entry.isEns = true;\n }\n\n this.update({\n addressBook: {\n ...this.state.addressBook,\n [chainId]: {\n ...this.state.addressBook[chainId],\n [address]: entry,\n },\n },\n });\n\n return true;\n }\n}\n\nexport default AddressBookController;\n"]} |
+6
-6
| { | ||
| "name": "@metamask/address-book-controller", | ||
| "version": "1.0.1", | ||
| "version": "1.1.0", | ||
| "description": "Manages a list of recipient addresses associated with nicknames", | ||
@@ -9,9 +9,9 @@ "keywords": [ | ||
| ], | ||
| "homepage": "https://github.com/MetaMask/controllers/tree/main/packages/address-book-controller#readme", | ||
| "homepage": "https://github.com/MetaMask/core/tree/main/packages/address-book-controller#readme", | ||
| "bugs": { | ||
| "url": "https://github.com/MetaMask/controllers/issues" | ||
| "url": "https://github.com/MetaMask/core/issues" | ||
| }, | ||
| "repository": { | ||
| "type": "git", | ||
| "url": "https://github.com/MetaMask/controllers.git" | ||
| "url": "https://github.com/MetaMask/core.git" | ||
| }, | ||
@@ -33,4 +33,4 @@ "license": "MIT", | ||
| "dependencies": { | ||
| "@metamask/base-controller": "^1.1.1", | ||
| "@metamask/controller-utils": "^1.0.0" | ||
| "@metamask/base-controller": "^1.1.2", | ||
| "@metamask/controller-utils": "^2.0.0" | ||
| }, | ||
@@ -37,0 +37,0 @@ "devDependencies": { |
+1
-1
@@ -15,2 +15,2 @@ # `@metamask/address-book-controller` | ||
| This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/controllers#readme). | ||
| This package is part of a monorepo. Instructions for contributing can be found in the [monorepo README](https://github.com/MetaMask/core#readme). |
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
18693
10.29%203
8.56%- Removed