@metamask/ens-controller 9.0.0 → 10.0.1

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,69 +7,116 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
6
7
 
7
8
  ## [Unreleased]
8
9
 
10
+ ## [10.0.1]
11
+
12
+ ### Fixed
13
+
14
+ - Fix `types` field in `package.json` ([#4047](https://github.com/MetaMask/core/pull/4047))
15
+
16
+ ## [10.0.0]
17
+
18
+ ### Added
19
+
20
+ - **BREAKING**: Add ESM build ([#3998](https://github.com/MetaMask/core/pull/3998))
21
+ - It's no longer possible to import files from `./dist` directly.
22
+ - Add support for Holesky and Sepolia registries ([#4006](https://github.com/MetaMask/core/pull/4006))
23
+ - Add optional constructor option `registriesByChainId`, which allows overriding the default ENS network map ([#4006](https://github.com/MetaMask/core/pull/4006))
24
+ - Update default value of `ensEntries` state property to include entry for `.` ([#4006](https://github.com/MetaMask/core/pull/4006))
25
+ - Update `get` so that it now returns registry address for chain when queried for the name `.` ([#4006](https://github.com/MetaMask/core/pull/4006))
26
+ - Update `delete` so that entry for `.` can be removed ([#4006](https://github.com/MetaMask/core/pull/4006))
27
+
28
+ ### Changed
29
+
30
+ - **BREAKING:** Bump `@metamask/base-controller` to `^5.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039))
31
+ - This version has a number of breaking changes. See the changelog for more.
32
+ - **BREAKING:** Bump peer dependency on `@metamask/network-controller` to `^18.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039))
33
+ - Bump `@metamask/controller-utils` to `^9.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039))
34
+
9
35
  ## [9.0.0]
36
+
10
37
  ### Changed
38
+
11
39
  - **BREAKING:** Bump `@metamask/network-controller` peer dependency to `^17.2.0` ([#3821](https://github.com/MetaMask/core/pull/3821))
12
40
  - Bump `@metamask/utils` to `^8.3.0` ([#3769](https://github.com/MetaMask/core/pull/3769))
13
41
  - Bump `@metamask/base-controller` to `^4.1.1` ([#3760](https://github.com/MetaMask/core/pull/3760), [#3821](https://github.com/MetaMask/core/pull/3821))
14
42
  - Bump `@metamask/controller-utils` to `^8.0.2` ([#3821](https://github.com/MetaMask/core/pull/3821))
15
43
 
16
-
17
44
  ## [8.0.0]
45
+
18
46
  ### Changed
47
+
19
48
  - **BREAKING:** Replace constructor parameter `onNetworkStateChange` with `onNetworkDidChange` ([#3610](https://github.com/MetaMask/core/pull/3610))
20
49
  - **BREAKING:** Bump `@metamask/network-controller` peer dependency from `^17.0.0` to `^17.1.0` ([#3695](https://github.com/MetaMask/core/pull/3695))
21
50
  - 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))
22
51
  - Bump `@metamask/base-controller` to `^4.0.1` ([#3695](https://github.com/MetaMask/core/pull/3695))
23
52
 
24
53
  ### Fixed
54
+
25
55
  - Remove `@metamask/network-controller` dependency ([#3607](https://github.com/MetaMask/core/pull/3607))
26
56
 
27
57
  ## [7.0.0]
58
+
28
59
  ### Changed
60
+
29
61
  - **BREAKING:** Bump `@metamask/base-controller` to ^4.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
30
62
  - This is breaking because the type of the `messenger` has backward-incompatible changes. See the changelog for this package for more.
31
63
  - Bump `@metamask/controller-utils` to ^6.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
32
64
  - Bump `@metamask/network-controller` to ^17.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
33
65
 
34
66
  ## [6.0.1]
67
+
35
68
  ### Changed
69
+
36
70
  - **BREAKING:** Bump dependency and peer dependency on `@metamask/network-controller` to ^16.0.0
37
71
  - Bump @metamask/utils from 8.1.0 to 8.2.0 ([#1957](https://github.com/MetaMask/core/pull/1957))
38
72
 
39
73
  ## [6.0.0]
74
+
40
75
  ### Changed
76
+
41
77
  - **BREAKING:** Bump dependency and peer dependency on `@metamask/network-controller` to ^15.0.0
42
78
 
43
79
  ## [5.0.2]
80
+
44
81
  ### Changed
82
+
45
83
  - Bump dependency on `@metamask/utils` to ^8.1.0 ([#1639](https://github.com/MetaMask/core/pull/1639))
46
84
  - Bump dependency on `@metamask/base-controller` to ^3.2.3
47
85
  - Bump dependency on `@metamask/controller-utils` to ^5.0.2
48
86
  - Bump dependency and peer dependency on `@metamask/network-controller` to ^14.0.0
49
87
 
50
88
  ## [5.0.1]
89
+
51
90
  ### Changed
91
+
52
92
  - Update TypeScript to v4.8.x ([#1718](https://github.com/MetaMask/core/pull/1718))
53
93
 
54
94
  ## [5.0.0]
95
+
55
96
  ### Changed
97
+
56
98
  - **BREAKING**: Bump peer dependency on `@metamask/network-controller` to ^13.0.0 ([#1633](https://github.com/MetaMask/core/pull/1633))
57
99
  - Use `providerConfig.chainId` instead of `providerConfig.networkId` to determine ENS compatability ([#1633](https://github.com/MetaMask/core/pull/1633))
58
100
  - Bump dependency on `@metamask/controller-utils` to ^5.0.0 ([#1633](https://github.com/MetaMask/core/pull/1633))
59
101
 
60
102
  ## [4.1.1]
103
+
61
104
  ### Changed
105
+
62
106
  - Bump dependency on `@metamask/base-controller` to ^3.2.1
63
107
  - Bump dependency on `@metamask/controller-utils` to ^4.3.2
64
108
  - Bump dependency and peer dependency on `@metamask/network-controller` to ^12.1.2
65
109
 
66
110
  ## [4.1.0]
111
+
67
112
  ### Changed
113
+
68
114
  - Update `@metamask/utils` to `^6.2.0` ([#1514](https://github.com/MetaMask/core/pull/1514))
69
115
 
70
116
  ## [4.0.0]
117
+
71
118
  ### Changed
119
+
72
120
  - **BREAKING:** Bump to Node 16 ([#1262](https://github.com/MetaMask/core/pull/1262))
73
121
  - **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))
74
122
  - **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))
@@ -77,41 +125,58 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
125
  - Bump @metamask/utils from 5.0.1 to 5.0.2 ([#1271](https://github.com/MetaMask/core/pull/1271))
78
126
 
79
127
  ### Fixed
128
+
80
129
  - Fix ENS controller failure to initialize after switching networks ([#1362](https://github.com/MetaMask/core/pull/1362))
81
130
 
82
131
  ## [3.1.0]
132
+
83
133
  ### Changed
134
+
84
135
  - Add support for reverse ENS address resolution ([#1170](https://github.com/MetaMask/core/pull/1170))
85
136
  - This controller can now resolve a network address to an ENS address. This feature was ported from the extension ENS controller.
86
137
 
87
138
  ## [3.0.0]
139
+
88
140
  ### Changed
141
+
89
142
  - **BREAKING:** Convert the ENS controller to the BaseController v2 API ([#1134](https://github.com/MetaMask/core/pull/1134))
90
143
 
91
144
  ## [2.0.0]
145
+
92
146
  ### Removed
147
+
93
148
  - **BREAKING:** Remove `isomorphic-fetch` ([#1106](https://github.com/MetaMask/controllers/pull/1106))
94
149
  - Consumers must now import `isomorphic-fetch` or another polyfill themselves if they are running in an environment without `fetch`
95
150
 
96
151
  ## [1.0.2]
152
+
97
153
  ### Changed
154
+
98
155
  - Rename this repository to `core` ([#1031](https://github.com/MetaMask/controllers/pull/1031))
99
156
  - Update `@metamask/controller-utils` package ([#1041](https://github.com/MetaMask/controllers/pull/1041))
100
157
 
101
158
  ## [1.0.1]
159
+
102
160
  ### Changed
161
+
103
162
  - Relax dependencies on `@metamask/base-controller` and `@metamask/controller-utils` (use `^` instead of `~`) ([#998](https://github.com/MetaMask/core/pull/998))
104
163
 
105
164
  ## [1.0.0]
165
+
106
166
  ### Added
167
+
107
168
  - Initial release
169
+
108
170
  - 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:
171
+
109
172
  - `src/third-party/EnsController.ts`
110
173
  - `src/third-party/EnsController.test.ts`
111
174
 
112
175
  All changes listed after this point were applied to this package following the monorepo conversion.
113
176
 
114
- [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@9.0.0...HEAD
177
+ [Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@10.0.1...HEAD
178
+ [10.0.1]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@10.0.0...@metamask/ens-controller@10.0.1
179
+ [10.0.0]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@9.0.0...@metamask/ens-controller@10.0.0
115
180
  [9.0.0]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@8.0.0...@metamask/ens-controller@9.0.0
116
181
  [8.0.0]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@7.0.0...@metamask/ens-controller@8.0.0
117
182
  [7.0.0]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@6.0.1...@metamask/ens-controller@7.0.0
@@ -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,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,CAAC,KAAK,CAAC,CAAC;gBACX,OAAO,SAAS,CAAC;aAClB;YAED,IAAI,CAAC,MAAM,EAAE;gBACX,OAAO,SAAS,CAAC;aAClB;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":[]}