@metamask/ens-controller 8.0.0 → 10.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # Changelog
2
+
2
3
  All notable changes to this project will be documented in this file.
3
4
 
4
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
@@ -6,61 +7,110 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
7
 
7
8
  ## [Unreleased]
8
9
 
10
+ ## [10.0.0]
11
+
12
+ ### Added
13
+
14
+ - **BREAKING**: Add ESM build ([#3998](https://github.com/MetaMask/core/pull/3998))
15
+ - It's no longer possible to import files from `./dist` directly.
16
+ - Add support for Holesky and Sepolia registries ([#4006](https://github.com/MetaMask/core/pull/4006))
17
+ - Add optional constructor option `registriesByChainId`, which allows overriding the default ENS network map ([#4006](https://github.com/MetaMask/core/pull/4006))
18
+ - Update default value of `ensEntries` state property to include entry for `.` ([#4006](https://github.com/MetaMask/core/pull/4006))
19
+ - Update `get` so that it now returns registry address for chain when queried for the name `.` ([#4006](https://github.com/MetaMask/core/pull/4006))
20
+ - Update `delete` so that entry for `.` can be removed ([#4006](https://github.com/MetaMask/core/pull/4006))
21
+
22
+ ### Changed
23
+
24
+ - **BREAKING:** Bump `@metamask/base-controller` to `^5.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039))
25
+ - This version has a number of breaking changes. See the changelog for more.
26
+ - **BREAKING:** Bump peer dependency on `@metamask/network-controller` to `^18.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039))
27
+ - Bump `@metamask/controller-utils` to `^9.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039))
28
+
29
+ ## [9.0.0]
30
+
31
+ ### Changed
32
+
33
+ - **BREAKING:** Bump `@metamask/network-controller` peer dependency to `^17.2.0` ([#3821](https://github.com/MetaMask/core/pull/3821))
34
+ - Bump `@metamask/utils` to `^8.3.0` ([#3769](https://github.com/MetaMask/core/pull/3769))
35
+ - Bump `@metamask/base-controller` to `^4.1.1` ([#3760](https://github.com/MetaMask/core/pull/3760), [#3821](https://github.com/MetaMask/core/pull/3821))
36
+ - Bump `@metamask/controller-utils` to `^8.0.2` ([#3821](https://github.com/MetaMask/core/pull/3821))
37
+
9
38
  ## [8.0.0]
39
+
10
40
  ### Changed
41
+
11
42
  - **BREAKING:** Replace constructor parameter `onNetworkStateChange` with `onNetworkDidChange` ([#3610](https://github.com/MetaMask/core/pull/3610))
12
43
  - **BREAKING:** Bump `@metamask/network-controller` peer dependency from `^17.0.0` to `^17.1.0` ([#3695](https://github.com/MetaMask/core/pull/3695))
13
44
  - Bump `@metamask/controller-utils` to `^8.0.1` ([#3695](https://github.com/MetaMask/core/pull/3695), [#3678](https://github.com/MetaMask/core/pull/3678), [#3667](https://github.com/MetaMask/core/pull/3667), [#3580](https://github.com/MetaMask/core/pull/3580))
14
45
  - Bump `@metamask/base-controller` to `^4.0.1` ([#3695](https://github.com/MetaMask/core/pull/3695))
15
46
 
16
47
  ### Fixed
48
+
17
49
  - Remove `@metamask/network-controller` dependency ([#3607](https://github.com/MetaMask/core/pull/3607))
18
50
 
19
51
  ## [7.0.0]
52
+
20
53
  ### Changed
54
+
21
55
  - **BREAKING:** Bump `@metamask/base-controller` to ^4.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
22
56
  - This is breaking because the type of the `messenger` has backward-incompatible changes. See the changelog for this package for more.
23
57
  - Bump `@metamask/controller-utils` to ^6.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
24
58
  - Bump `@metamask/network-controller` to ^17.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
25
59
 
26
60
  ## [6.0.1]
61
+
27
62
  ### Changed
63
+
28
64
  - **BREAKING:** Bump dependency and peer dependency on `@metamask/network-controller` to ^16.0.0
29
65
  - Bump @metamask/utils from 8.1.0 to 8.2.0 ([#1957](https://github.com/MetaMask/core/pull/1957))
30
66
 
31
67
  ## [6.0.0]
68
+
32
69
  ### Changed
70
+
33
71
  - **BREAKING:** Bump dependency and peer dependency on `@metamask/network-controller` to ^15.0.0
34
72
 
35
73
  ## [5.0.2]
74
+
36
75
  ### Changed
76
+
37
77
  - Bump dependency on `@metamask/utils` to ^8.1.0 ([#1639](https://github.com/MetaMask/core/pull/1639))
38
78
  - Bump dependency on `@metamask/base-controller` to ^3.2.3
39
79
  - Bump dependency on `@metamask/controller-utils` to ^5.0.2
40
80
  - Bump dependency and peer dependency on `@metamask/network-controller` to ^14.0.0
41
81
 
42
82
  ## [5.0.1]
83
+
43
84
  ### Changed
85
+
44
86
  - Update TypeScript to v4.8.x ([#1718](https://github.com/MetaMask/core/pull/1718))
45
87
 
46
88
  ## [5.0.0]
89
+
47
90
  ### Changed
91
+
48
92
  - **BREAKING**: Bump peer dependency on `@metamask/network-controller` to ^13.0.0 ([#1633](https://github.com/MetaMask/core/pull/1633))
49
93
  - Use `providerConfig.chainId` instead of `providerConfig.networkId` to determine ENS compatability ([#1633](https://github.com/MetaMask/core/pull/1633))
50
94
  - Bump dependency on `@metamask/controller-utils` to ^5.0.0 ([#1633](https://github.com/MetaMask/core/pull/1633))
51
95
 
52
96
  ## [4.1.1]
97
+
53
98
  ### Changed
99
+
54
100
  - Bump dependency on `@metamask/base-controller` to ^3.2.1
55
101
  - Bump dependency on `@metamask/controller-utils` to ^4.3.2
56
102
  - Bump dependency and peer dependency on `@metamask/network-controller` to ^12.1.2
57
103
 
58
104
  ## [4.1.0]
105
+
59
106
  ### Changed
107
+
60
108
  - Update `@metamask/utils` to `^6.2.0` ([#1514](https://github.com/MetaMask/core/pull/1514))
61
109
 
62
110
  ## [4.0.0]
111
+
63
112
  ### Changed
113
+
64
114
  - **BREAKING:** Bump to Node 16 ([#1262](https://github.com/MetaMask/core/pull/1262))
65
115
  - **BREAKING:** Add `@metamask/network-controller` as a dependency and peer dependency ([#1367](https://github.com/MetaMask/core/pull/1367), [#1362](https://github.com/MetaMask/core/pull/1362))
66
116
  - **BREAKING:** The `ensEntries` state property is now keyed by `Hex` chain ID rather than `string`, and the `chainId` property of each ENS entry is also `Hex` rather than `string`. ([#1367](https://github.com/MetaMask/core/pull/1367))
@@ -69,41 +119,58 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
69
119
  - Bump @metamask/utils from 5.0.1 to 5.0.2 ([#1271](https://github.com/MetaMask/core/pull/1271))
70
120
 
71
121
  ### Fixed
122
+
72
123
  - Fix ENS controller failure to initialize after switching networks ([#1362](https://github.com/MetaMask/core/pull/1362))
73
124
 
74
125
  ## [3.1.0]
126
+
75
127
  ### Changed
128
+
76
129
  - Add support for reverse ENS address resolution ([#1170](https://github.com/MetaMask/core/pull/1170))
77
130
  - This controller can now resolve a network address to an ENS address. This feature was ported from the extension ENS controller.
78
131
 
79
132
  ## [3.0.0]
133
+
80
134
  ### Changed
135
+
81
136
  - **BREAKING:** Convert the ENS controller to the BaseController v2 API ([#1134](https://github.com/MetaMask/core/pull/1134))
82
137
 
83
138
  ## [2.0.0]
139
+
84
140
  ### Removed
141
+
85
142
  - **BREAKING:** Remove `isomorphic-fetch` ([#1106](https://github.com/MetaMask/controllers/pull/1106))
86
143
  - Consumers must now import `isomorphic-fetch` or another polyfill themselves if they are running in an environment without `fetch`
87
144
 
88
145
  ## [1.0.2]
146
+
89
147
  ### Changed
148
+
90
149
  - Rename this repository to `core` ([#1031](https://github.com/MetaMask/controllers/pull/1031))
91
150
  - Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
92
151
 
93
152
  ## [1.0.1]
153
+
94
154
  ### Changed
155
+
95
156
  - Relax dependencies on `@metamask/base-controller` and `@metamask/controller-utils` (use `^` instead of `~`) ([#998](https://github.com/MetaMask/core/pull/998))
96
157
 
97
158
  ## [1.0.0]
159
+
98
160
  ### Added
161
+
99
162
  - Initial release
163
+
100
164
  - 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:
165
+
101
166
  - `src/third-party/EnsController.ts`
102
167
  - `src/third-party/EnsController.test.ts`
103
168
 
104
169
  All changes listed after this point were applied to this package following the monorepo conversion.
105
170
 
106
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@8.0.0...HEAD
171
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@10.0.0...HEAD
172
+ [10.0.0]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@9.0.0...@metamask/ens-controller@10.0.0
173
+ [9.0.0]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@8.0.0...@metamask/ens-controller@9.0.0
107
174
  [8.0.0]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@7.0.0...@metamask/ens-controller@8.0.0
108
175
  [7.0.0]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@6.0.1...@metamask/ens-controller@7.0.0
109
176
  [6.0.1]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@6.0.0...@metamask/ens-controller@6.0.1
@@ -1,231 +1,11 @@
1
- "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
- var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
12
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
13
- 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");
14
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
15
- };
16
- var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
17
- if (kind === "m") throw new TypeError("Private method is not writable");
18
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
19
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
20
- return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
21
- };
22
- var __importDefault = (this && this.__importDefault) || function (mod) {
23
- return (mod && mod.__esModule) ? mod : { "default": mod };
24
- };
25
- var _EnsController_instances, _EnsController_ethProvider, _EnsController_getChainEnsSupport;
26
- Object.defineProperty(exports, "__esModule", { value: true });
27
- exports.EnsController = void 0;
28
- const providers_1 = require("@ethersproject/providers");
29
- const base_controller_1 = require("@metamask/base-controller");
30
- const controller_utils_1 = require("@metamask/controller-utils");
31
- const utils_1 = require("@metamask/utils");
32
- const ethereum_ens_network_map_1 = __importDefault(require("ethereum-ens-network-map"));
33
- const punycode_1 = require("punycode/");
34
- const log = (0, utils_1.createProjectLogger)('ens-controller');
35
- const name = 'EnsController';
36
- const metadata = {
37
- ensEntries: { persist: true, anonymous: false },
38
- ensResolutionsByAddress: { persist: true, anonymous: false },
39
- };
40
- const defaultState = {
41
- ensEntries: {},
42
- ensResolutionsByAddress: {},
43
- };
44
- const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
45
- const ZERO_X_ERROR_ADDRESS = '0x';
46
- /**
47
- * Controller that manages a list ENS names and their resolved addresses
48
- * by chainId. A null address indicates an unresolved ENS name.
49
- */
50
- class EnsController extends base_controller_1.BaseController {
51
- /**
52
- * Creates an EnsController instance.
53
- *
54
- * @param options - Constructor options.
55
- * @param options.messenger - A reference to the messaging system.
56
- * @param options.state - Initial state to set on this controller.
57
- * @param options.provider - Provider instance.
58
- * @param options.onNetworkDidChange - Allows subscribing to network controller networkDidChange events.
59
- */
60
- constructor({ messenger, state = {}, provider, onNetworkDidChange, }) {
61
- super({
62
- name,
63
- metadata,
64
- messenger,
65
- state: Object.assign(Object.assign({}, defaultState), state),
66
- });
67
- _EnsController_instances.add(this);
68
- _EnsController_ethProvider.set(this, null);
69
- if (provider && onNetworkDidChange) {
70
- onNetworkDidChange((networkState) => {
71
- this.resetState();
72
- const currentChainId = networkState.providerConfig.chainId;
73
- if (__classPrivateFieldGet(this, _EnsController_instances, "m", _EnsController_getChainEnsSupport).call(this, currentChainId)) {
74
- __classPrivateFieldSet(this, _EnsController_ethProvider, new providers_1.Web3Provider(provider, {
75
- chainId: (0, controller_utils_1.convertHexToDecimal)(currentChainId),
76
- name: controller_utils_1.CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP[currentChainId],
77
- ensAddress: ethereum_ens_network_map_1.default[parseInt(currentChainId, 16)],
78
- }), "f");
79
- }
80
- else {
81
- __classPrivateFieldSet(this, _EnsController_ethProvider, null, "f");
82
- }
83
- });
84
- }
85
- }
86
- /**
87
- * Clears ensResolutionsByAddress state property.
88
- */
89
- resetState() {
90
- this.update((currentState) => {
91
- currentState.ensResolutionsByAddress = {};
92
- });
93
- }
94
- /**
95
- * Remove all chain Ids and ENS entries from state.
96
- */
97
- clear() {
98
- this.update((state) => {
99
- state.ensEntries = {};
100
- });
101
- }
102
- /**
103
- * Delete an ENS entry.
104
- *
105
- * @param chainId - Parent chain of the ENS entry to delete.
106
- * @param ensName - Name of the ENS entry to delete.
107
- * @returns Boolean indicating if the entry was deleted.
108
- */
109
- delete(chainId, ensName) {
110
- const normalizedEnsName = (0, controller_utils_1.normalizeEnsName)(ensName);
111
- if (!normalizedEnsName ||
112
- !this.state.ensEntries[chainId] ||
113
- !this.state.ensEntries[chainId][normalizedEnsName]) {
114
- return false;
115
- }
116
- this.update((state) => {
117
- delete state.ensEntries[chainId][normalizedEnsName];
118
- if (Object.keys(state.ensEntries[chainId]).length === 0) {
119
- delete state.ensEntries[chainId];
120
- }
121
- });
122
- return true;
123
- }
124
- /**
125
- * Retrieve a DNS entry.
126
- *
127
- * @param chainId - Parent chain of the ENS entry to retrieve.
128
- * @param ensName - Name of the ENS entry to retrieve.
129
- * @returns The EnsEntry or null if it does not exist.
130
- */
131
- get(chainId, ensName) {
132
- const normalizedEnsName = (0, controller_utils_1.normalizeEnsName)(ensName);
133
- // TODO Explicitly handle the case where `normalizedEnsName` is `null`
134
- // eslint-disable-next-line no-implicit-coercion
135
- return !!normalizedEnsName && this.state.ensEntries[chainId]
136
- ? this.state.ensEntries[chainId][normalizedEnsName] || null
137
- : null;
138
- }
139
- /**
140
- * Add or update an ENS entry by chainId and ensName.
141
- *
142
- * A null address indicates that the ENS name does not resolve.
143
- *
144
- * @param chainId - Id of the associated chain.
145
- * @param ensName - The ENS name.
146
- * @param address - Associated address (or null) to add or update.
147
- * @returns Boolean indicating if the entry was set.
148
- */
149
- set(chainId, ensName, address) {
150
- if (!Number.isInteger(Number.parseInt(chainId, 10)) ||
151
- !ensName ||
152
- typeof ensName !== 'string' ||
153
- (address && !(0, controller_utils_1.isValidHexAddress)(address))) {
154
- throw new Error(`Invalid ENS entry: { chainId:${chainId}, ensName:${ensName}, address:${address}}`);
155
- }
156
- const normalizedEnsName = (0, controller_utils_1.normalizeEnsName)(ensName);
157
- if (!normalizedEnsName) {
158
- throw new Error(`Invalid ENS name: ${ensName}`);
159
- }
160
- const normalizedAddress = address ? (0, controller_utils_1.toChecksumHexAddress)(address) : null;
161
- const subState = this.state.ensEntries[chainId];
162
- if ((subState === null || subState === void 0 ? void 0 : subState[normalizedEnsName]) &&
163
- subState[normalizedEnsName].address === normalizedAddress) {
164
- return false;
165
- }
166
- this.update((state) => {
167
- state.ensEntries = Object.assign(Object.assign({}, this.state.ensEntries), { [chainId]: Object.assign(Object.assign({}, this.state.ensEntries[chainId]), { [normalizedEnsName]: {
168
- address: normalizedAddress,
169
- chainId,
170
- ensName: normalizedEnsName,
171
- } }) });
172
- });
173
- return true;
174
- }
175
- /**
176
- * Resolve ens by address.
177
- *
178
- * @param nonChecksummedAddress - address
179
- * @returns ens resolution
180
- */
181
- reverseResolveAddress(nonChecksummedAddress) {
182
- return __awaiter(this, void 0, void 0, function* () {
183
- if (!__classPrivateFieldGet(this, _EnsController_ethProvider, "f")) {
184
- return undefined;
185
- }
186
- const address = (0, controller_utils_1.toChecksumHexAddress)(nonChecksummedAddress);
187
- if (this.state.ensResolutionsByAddress[address]) {
188
- return this.state.ensResolutionsByAddress[address];
189
- }
190
- let domain;
191
- try {
192
- domain = yield __classPrivateFieldGet(this, _EnsController_ethProvider, "f").lookupAddress(address);
193
- }
194
- catch (error) {
195
- log(error);
196
- return undefined;
197
- }
198
- if (!domain) {
199
- return undefined;
200
- }
201
- let registeredAddress;
202
- try {
203
- registeredAddress = yield __classPrivateFieldGet(this, _EnsController_ethProvider, "f").resolveName(domain);
204
- }
205
- catch (error) {
206
- log(error);
207
- return undefined;
208
- }
209
- if (!registeredAddress) {
210
- return undefined;
211
- }
212
- if (registeredAddress === ZERO_ADDRESS ||
213
- registeredAddress === ZERO_X_ERROR_ADDRESS) {
214
- return undefined;
215
- }
216
- if ((0, controller_utils_1.toChecksumHexAddress)(registeredAddress) !== address) {
217
- return undefined;
218
- }
219
- this.update((state) => {
220
- state.ensResolutionsByAddress[address] = (0, punycode_1.toASCII)(domain);
221
- });
222
- return domain;
223
- });
224
- }
225
- }
226
- exports.EnsController = EnsController;
227
- _EnsController_ethProvider = new WeakMap(), _EnsController_instances = new WeakSet(), _EnsController_getChainEnsSupport = function _EnsController_getChainEnsSupport(chainId) {
228
- return Boolean(ethereum_ens_network_map_1.default[parseInt(chainId, 16)]);
229
- };
230
- exports.default = EnsController;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+
5
+ var _chunkS7KH3XXUjs = require('./chunk-S7KH3XXU.js');
6
+
7
+
8
+
9
+
10
+ exports.DEFAULT_ENS_NETWORK_MAP = _chunkS7KH3XXUjs.DEFAULT_ENS_NETWORK_MAP; exports.EnsController = _chunkS7KH3XXUjs.EnsController; exports.default = _chunkS7KH3XXUjs.EnsController_default;
231
11
  //# sourceMappingURL=EnsController.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"EnsController.js","sourceRoot":"","sources":["../src/EnsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAIA,wDAAwD;AAExD,+DAA2D;AAE3D,iEAMoC;AAGpC,2CAAsD;AACtD,wFAAqD;AACrD,wCAAoC;AAEpC,MAAM,GAAG,GAAG,IAAA,2BAAmB,EAAC,gBAAgB,CAAC,CAAC;AAElD,MAAM,IAAI,GAAG,eAAe,CAAC;AAuC7B,MAAM,QAAQ,GAAG;IACf,UAAU,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;IAC/C,uBAAuB,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE;CAC7D,CAAC;AAEF,MAAM,YAAY,GAAG;IACnB,UAAU,EAAE,EAAE;IACd,uBAAuB,EAAE,EAAE;CAC5B,CAAC;AAEF,MAAM,YAAY,GAAG,4CAA4C,CAAC;AAClE,MAAM,oBAAoB,GAAG,IAAI,CAAC;AAElC;;;GAGG;AACH,MAAa,aAAc,SAAQ,gCAIlC;IAGC;;;;;;;;OAQG;IACH,YAAY,EACV,SAAS,EACT,KAAK,GAAG,EAAE,EACV,QAAQ,EACR,kBAAkB,GAQnB;QACC,KAAK,CAAC;YACJ,IAAI;YACJ,QAAQ;YACR,SAAS;YACT,KAAK,kCACA,YAAY,GACZ,KAAK,CACT;SACF,CAAC,CAAC;;QAhCL,qCAAoC,IAAI,EAAC;QAkCvC,IAAI,QAAQ,IAAI,kBAAkB,EAAE;YAClC,kBAAkB,CAAC,CAAC,YAAY,EAAE,EAAE;gBAClC,IAAI,CAAC,UAAU,EAAE,CAAC;gBAClB,MAAM,cAAc,GAAG,YAAY,CAAC,cAAc,CAAC,OA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;YAED,IAAI,iBAAgC,CAAC;YACrC,IAAI;gBACF,iBAAiB,GAAG,MAAM,uBAAA,IAAI,kCAAa,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;aACjE;YAAC,OAAO,KAAK,EAAE;gBACd,GAAG,CAAC,KAAK,CAAC,CAAC;gBACX,OAAO,SAAS,CAAC;aAClB;YAED,IAAI,CAAC,iBAAiB,EAAE;gBACtB,OAAO,SAAS,CAAC;aAClB;YAED,IACE,iBAAiB,KAAK,YAAY;gBAClC,iBAAiB,KAAK,oBAAoB,EAC1C;gBACA,OAAO,SAAS,CAAC;aAClB;YACD,IAAI,IAAA,uCAAoB,EAAC,iBAAiB,CAAC,KAAK,OAAO,EAAE;gBACvD,OAAO,SAAS,CAAC;aAClB;YAED,IAAI,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,EAAE;gBACpB,KAAK,CAAC,uBAAuB,CAAC,OAAO,CAAC,GAAG,IAAA,kBAAO,EAAC,MAAgB,CAAC,CAAC;YACrE,CAAC,CAAC,CAAC;YAEH,OAAO,MAAM,CAAC;QAChB,CAAC;KAAA;CACF;AA/OD,sCA+OC;qKA5DqB,OAAe;IACjC,OAAO,OAAO,CAAC,kCAAa,CAAC,QAAQ,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;AACvD,CAAC;AA4DH,kBAAe,aAAa,CAAC","sourcesContent":["import type {\n ExternalProvider,\n JsonRpcFetchFunc,\n} from '@ethersproject/providers';\nimport { Web3Provider } from '@ethersproject/providers';\nimport type { RestrictedControllerMessenger } from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport type { ChainId } from '@metamask/controller-utils';\nimport {\n normalizeEnsName,\n isValidHexAddress,\n toChecksumHexAddress,\n CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP,\n convertHexToDecimal,\n} from '@metamask/controller-utils';\nimport type { NetworkState } from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createProjectLogger } from '@metamask/utils';\nimport ensNetworkMap from 'ethereum-ens-network-map';\nimport { toASCII } from 'punycode/';\n\nconst log = createProjectLogger('ens-controller');\n\nconst name = 'EnsController';\n\n/**\n * @type EnsEntry\n *\n * ENS entry representation\n * @property chainId - Id of the associated chain\n * @property ensName - The ENS name\n * @property address - Hex address with the ENS name, or null\n */\nexport type EnsEntry = {\n chainId: Hex;\n ensName: string;\n address: string | null;\n};\n\n/**\n * @type EnsControllerState\n *\n * ENS controller state\n * @property ensEntries - Object of ENS entry objects\n */\nexport type EnsControllerState = {\n ensEntries: {\n [chainId: Hex]: {\n [ensName: string]: EnsEntry;\n };\n };\n ensResolutionsByAddress: { [key: string]: string };\n};\n\nexport type EnsControllerMessenger = RestrictedControllerMessenger<\n typeof name,\n never,\n never,\n never,\n never\n>;\n\nconst metadata = {\n ensEntries: { persist: true, anonymous: false },\n ensResolutionsByAddress: { persist: true, anonymous: false },\n};\n\nconst defaultState = {\n ensEntries: {},\n ensResolutionsByAddress: {},\n};\n\nconst ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';\nconst ZERO_X_ERROR_ADDRESS = '0x';\n\n/**\n * Controller that manages a list ENS names and their resolved addresses\n * by chainId. A null address indicates an unresolved ENS name.\n */\nexport class EnsController extends BaseController<\n typeof name,\n EnsControllerState,\n EnsControllerMessenger\n> {\n #ethProvider: Web3Provider | null = null;\n\n /**\n * Creates an EnsController instance.\n *\n * @param options - Constructor options.\n * @param options.messenger - A reference to the messaging system.\n * @param options.state - Initial state to set on this controller.\n * @param options.provider - Provider instance.\n * @param options.onNetworkDidChange - Allows subscribing to network controller networkDidChange events.\n */\n constructor({\n messenger,\n state = {},\n provider,\n onNetworkDidChange,\n }: {\n messenger: EnsControllerMessenger;\n state?: Partial<EnsControllerState>;\n provider?: ExternalProvider | JsonRpcFetchFunc;\n onNetworkDidChange?: (\n listener: (networkState: Pick<NetworkState, 'providerConfig'>) => void,\n ) => void;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: {\n ...defaultState,\n ...state,\n },\n });\n\n if (provider && onNetworkDidChange) {\n onNetworkDidChange((networkState) => {\n this.resetState();\n const currentChainId = networkState.providerConfig.chainId;\n if (this.#getChainEnsSupport(currentChainId)) {\n this.#ethProvider = new Web3Provider(provider, {\n chainId: convertHexToDecimal(currentChainId),\n name: CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP[\n currentChainId as ChainId\n ],\n ensAddress: ensNetworkMap[parseInt(currentChainId, 16)],\n });\n } else {\n this.#ethProvider = null;\n }\n });\n }\n }\n\n /**\n * Clears ensResolutionsByAddress state property.\n */\n resetState() {\n this.update((currentState) => {\n currentState.ensResolutionsByAddress = {};\n });\n }\n\n /**\n * Remove all chain Ids and ENS entries from state.\n */\n clear() {\n this.update((state) => {\n state.ensEntries = {};\n });\n }\n\n /**\n * Delete an ENS entry.\n *\n * @param chainId - Parent chain of the ENS entry to delete.\n * @param ensName - Name of the ENS entry to delete.\n * @returns Boolean indicating if the entry was deleted.\n */\n delete(chainId: Hex, ensName: string): boolean {\n const normalizedEnsName = normalizeEnsName(ensName);\n if (\n !normalizedEnsName ||\n !this.state.ensEntries[chainId] ||\n !this.state.ensEntries[chainId][normalizedEnsName]\n ) {\n return false;\n }\n\n this.update((state) => {\n delete state.ensEntries[chainId][normalizedEnsName];\n\n if (Object.keys(state.ensEntries[chainId]).length === 0) {\n delete state.ensEntries[chainId];\n }\n });\n return true;\n }\n\n /**\n * Retrieve a DNS entry.\n *\n * @param chainId - Parent chain of the ENS entry to retrieve.\n * @param ensName - Name of the ENS entry to retrieve.\n * @returns The EnsEntry or null if it does not exist.\n */\n get(chainId: Hex, ensName: string): EnsEntry | null {\n const normalizedEnsName = normalizeEnsName(ensName);\n\n // TODO Explicitly handle the case where `normalizedEnsName` is `null`\n // eslint-disable-next-line no-implicit-coercion\n return !!normalizedEnsName && this.state.ensEntries[chainId]\n ? this.state.ensEntries[chainId][normalizedEnsName] || null\n : null;\n }\n\n /**\n * Add or update an ENS entry by chainId and ensName.\n *\n * A null address indicates that the ENS name does not resolve.\n *\n * @param chainId - Id of the associated chain.\n * @param ensName - The ENS name.\n * @param address - Associated address (or null) to add or update.\n * @returns Boolean indicating if the entry was set.\n */\n set(chainId: Hex, ensName: string, address: string | null): boolean {\n if (\n !Number.isInteger(Number.parseInt(chainId, 10)) ||\n !ensName ||\n typeof ensName !== 'string' ||\n (address && !isValidHexAddress(address))\n ) {\n throw new Error(\n `Invalid ENS entry: { chainId:${chainId}, ensName:${ensName}, address:${address}}`,\n );\n }\n\n const normalizedEnsName = normalizeEnsName(ensName);\n if (!normalizedEnsName) {\n throw new Error(`Invalid ENS name: ${ensName}`);\n }\n\n const normalizedAddress = address ? toChecksumHexAddress(address) : null;\n const subState = this.state.ensEntries[chainId];\n\n if (\n subState?.[normalizedEnsName] &&\n subState[normalizedEnsName].address === normalizedAddress\n ) {\n return false;\n }\n\n this.update((state) => {\n state.ensEntries = {\n ...this.state.ensEntries,\n [chainId]: {\n ...this.state.ensEntries[chainId],\n [normalizedEnsName]: {\n address: normalizedAddress,\n chainId,\n ensName: normalizedEnsName,\n },\n },\n };\n });\n return true;\n }\n\n /**\n * Check if the chain supports ENS.\n *\n * @param chainId - chain id.\n * @returns Boolean indicating if the chain supports ENS.\n */\n #getChainEnsSupport(chainId: string) {\n return Boolean(ensNetworkMap[parseInt(chainId, 16)]);\n }\n\n /**\n * Resolve ens by address.\n *\n * @param nonChecksummedAddress - address\n * @returns ens resolution\n */\n async reverseResolveAddress(nonChecksummedAddress: string) {\n if (!this.#ethProvider) {\n return undefined;\n }\n\n const address = toChecksumHexAddress(nonChecksummedAddress);\n if (this.state.ensResolutionsByAddress[address]) {\n return this.state.ensResolutionsByAddress[address];\n }\n\n let domain: string | null;\n try {\n domain = await this.#ethProvider.lookupAddress(address);\n } catch (error) {\n log(error);\n return undefined;\n }\n\n if (!domain) {\n return undefined;\n }\n\n let registeredAddress: string | null;\n try {\n registeredAddress = await this.#ethProvider.resolveName(domain);\n } catch (error) {\n log(error);\n return undefined;\n }\n\n if (!registeredAddress) {\n return undefined;\n }\n\n if (\n registeredAddress === ZERO_ADDRESS ||\n registeredAddress === ZERO_X_ERROR_ADDRESS\n ) {\n return undefined;\n }\n if (toChecksumHexAddress(registeredAddress) !== address) {\n return undefined;\n }\n\n this.update((state) => {\n state.ensResolutionsByAddress[address] = toASCII(domain as string);\n });\n\n return domain;\n }\n}\n\nexport default EnsController;\n"]}
1
+ {"version":3,"sources":[],"names":[],"mappings":""}
@@ -0,0 +1,11 @@
1
+ import {
2
+ DEFAULT_ENS_NETWORK_MAP,
3
+ EnsController,
4
+ EnsController_default
5
+ } from "./chunk-LQYXJTIO.mjs";
6
+ export {
7
+ DEFAULT_ENS_NETWORK_MAP,
8
+ EnsController,
9
+ EnsController_default as default
10
+ };
11
+ //# sourceMappingURL=EnsController.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}