@metamask/ens-controller 14.0.0 → 14.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 +20 -1
- package/dist/EnsController.cjs +262 -0
- package/dist/EnsController.cjs.map +1 -0
- package/dist/{types/EnsController.d.ts → EnsController.d.cts} +5 -5
- package/dist/EnsController.d.cts.map +1 -0
- package/dist/EnsController.d.mts +103 -0
- package/dist/EnsController.d.mts.map +1 -0
- package/dist/EnsController.mjs +257 -9
- package/dist/EnsController.mjs.map +1 -1
- package/dist/index.cjs +18 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +1 -8
- package/dist/index.mjs.map +1 -1
- package/package.json +15 -10
- package/dist/EnsController.js +0 -11
- package/dist/EnsController.js.map +0 -1
- package/dist/chunk-TGEY3PIG.js +0 -293
- package/dist/chunk-TGEY3PIG.js.map +0 -1
- package/dist/chunk-UALCGKXW.mjs +0 -293
- package/dist/chunk-UALCGKXW.mjs.map +0 -1
- package/dist/index.js +0 -9
- package/dist/index.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/EnsController.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [14.0.1]
|
|
11
|
+
|
|
12
|
+
### Fixed
|
|
13
|
+
|
|
14
|
+
- Produce and export ESM-compatible TypeScript type declaration files in addition to CommonJS-compatible declaration files ([#4648](https://github.com/MetaMask/core/pull/4648))
|
|
15
|
+
- Previously, this package shipped with only one variant of type declaration
|
|
16
|
+
files, and these files were only CommonJS-compatible, and the `exports`
|
|
17
|
+
field in `package.json` linked to these files. This is an anti-pattern and
|
|
18
|
+
was rightfully flagged by the
|
|
19
|
+
["Are the Types Wrong?"](https://arethetypeswrong.github.io/) tool as
|
|
20
|
+
["masquerading as CJS"](https://github.com/arethetypeswrong/arethetypeswrong.github.io/blob/main/docs/problems/FalseCJS.md).
|
|
21
|
+
All of the ATTW checks now pass.
|
|
22
|
+
- Remove chunk files ([#4648](https://github.com/MetaMask/core/pull/4648)).
|
|
23
|
+
- Previously, the build tool we used to generate JavaScript files extracted
|
|
24
|
+
common code to "chunk" files. While this was intended to make this package
|
|
25
|
+
more tree-shakeable, it also made debugging more difficult for our
|
|
26
|
+
development teams. These chunk files are no longer present.
|
|
27
|
+
|
|
10
28
|
## [14.0.0]
|
|
11
29
|
|
|
12
30
|
### Changed
|
|
@@ -229,7 +247,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
229
247
|
|
|
230
248
|
All changes listed after this point were applied to this package following the monorepo conversion.
|
|
231
249
|
|
|
232
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@14.0.
|
|
250
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@14.0.1...HEAD
|
|
251
|
+
[14.0.1]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@14.0.0...@metamask/ens-controller@14.0.1
|
|
233
252
|
[14.0.0]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@13.0.1...@metamask/ens-controller@14.0.0
|
|
234
253
|
[13.0.1]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@13.0.0...@metamask/ens-controller@13.0.1
|
|
235
254
|
[13.0.0]: https://github.com/MetaMask/core/compare/@metamask/ens-controller@12.0.0...@metamask/ens-controller@13.0.0
|
|
@@ -0,0 +1,262 @@
|
|
|
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 __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
8
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
9
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
10
|
+
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");
|
|
11
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
12
|
+
};
|
|
13
|
+
var _EnsController_instances, _EnsController_ethProvider, _EnsController_setDefaultEthProvider, _EnsController_setEthProvider, _EnsController_getChainEnsSupport;
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.EnsController = exports.DEFAULT_ENS_NETWORK_MAP = void 0;
|
|
16
|
+
const providers_1 = require("@ethersproject/providers");
|
|
17
|
+
const base_controller_1 = require("@metamask/base-controller");
|
|
18
|
+
const controller_utils_1 = require("@metamask/controller-utils");
|
|
19
|
+
const utils_1 = require("@metamask/utils");
|
|
20
|
+
const punycode_js_1 = require("punycode/punycode.js");
|
|
21
|
+
const log = (0, utils_1.createProjectLogger)('ens-controller');
|
|
22
|
+
const name = 'EnsController';
|
|
23
|
+
// Map of chainIDs and ENS registry contract addresses
|
|
24
|
+
exports.DEFAULT_ENS_NETWORK_MAP = {
|
|
25
|
+
// Mainnet
|
|
26
|
+
1: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
|
|
27
|
+
// Ropsten
|
|
28
|
+
3: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
|
|
29
|
+
// Rinkeby
|
|
30
|
+
4: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
|
|
31
|
+
// Goerli
|
|
32
|
+
5: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
|
|
33
|
+
// Holesky
|
|
34
|
+
17000: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
|
|
35
|
+
// Sepolia
|
|
36
|
+
11155111: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',
|
|
37
|
+
};
|
|
38
|
+
const metadata = {
|
|
39
|
+
ensEntries: { persist: true, anonymous: false },
|
|
40
|
+
ensResolutionsByAddress: { persist: true, anonymous: false },
|
|
41
|
+
};
|
|
42
|
+
const defaultState = {
|
|
43
|
+
ensEntries: {},
|
|
44
|
+
ensResolutionsByAddress: {},
|
|
45
|
+
};
|
|
46
|
+
const ZERO_ADDRESS = '0x0000000000000000000000000000000000000000';
|
|
47
|
+
const ZERO_X_ERROR_ADDRESS = '0x';
|
|
48
|
+
/**
|
|
49
|
+
* Controller that manages a list ENS names and their resolved addresses
|
|
50
|
+
* by chainId. A null address indicates an unresolved ENS name.
|
|
51
|
+
*/
|
|
52
|
+
class EnsController extends base_controller_1.BaseController {
|
|
53
|
+
/**
|
|
54
|
+
* Creates an EnsController instance.
|
|
55
|
+
*
|
|
56
|
+
* @param options - Constructor options.
|
|
57
|
+
* @param options.registriesByChainId - Map between chain IDs and ENS contract addresses.
|
|
58
|
+
* @param options.messenger - A reference to the messaging system.
|
|
59
|
+
* @param options.state - Initial state to set on this controller.
|
|
60
|
+
* @param options.onNetworkDidChange - Allows subscribing to network controller networkDidChange events.
|
|
61
|
+
*/
|
|
62
|
+
constructor({ registriesByChainId = exports.DEFAULT_ENS_NETWORK_MAP, messenger, state = {}, onNetworkDidChange, }) {
|
|
63
|
+
super({
|
|
64
|
+
name,
|
|
65
|
+
metadata,
|
|
66
|
+
messenger,
|
|
67
|
+
state: {
|
|
68
|
+
...defaultState,
|
|
69
|
+
ensEntries: Object.fromEntries(Object.entries(registriesByChainId).map(([chainId, address]) => [
|
|
70
|
+
(0, controller_utils_1.toHex)(chainId),
|
|
71
|
+
{
|
|
72
|
+
'.': {
|
|
73
|
+
address,
|
|
74
|
+
chainId: (0, controller_utils_1.toHex)(chainId),
|
|
75
|
+
ensName: '.',
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
])),
|
|
79
|
+
...state,
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
_EnsController_instances.add(this);
|
|
83
|
+
_EnsController_ethProvider.set(this, null);
|
|
84
|
+
__classPrivateFieldGet(this, _EnsController_instances, "m", _EnsController_setDefaultEthProvider).call(this, registriesByChainId);
|
|
85
|
+
if (onNetworkDidChange) {
|
|
86
|
+
onNetworkDidChange(({ selectedNetworkClientId }) => {
|
|
87
|
+
this.resetState();
|
|
88
|
+
__classPrivateFieldGet(this, _EnsController_instances, "m", _EnsController_setEthProvider).call(this, selectedNetworkClientId, registriesByChainId);
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Clears ensResolutionsByAddress state property.
|
|
94
|
+
*/
|
|
95
|
+
resetState() {
|
|
96
|
+
this.update((currentState) => {
|
|
97
|
+
currentState.ensResolutionsByAddress = {};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Remove all chain Ids and ENS entries from state.
|
|
102
|
+
*/
|
|
103
|
+
clear() {
|
|
104
|
+
this.update((state) => {
|
|
105
|
+
state.ensEntries = {};
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Delete an ENS entry.
|
|
110
|
+
*
|
|
111
|
+
* @param chainId - Parent chain of the ENS entry to delete.
|
|
112
|
+
* @param ensName - Name of the ENS entry to delete.
|
|
113
|
+
* @returns Boolean indicating if the entry was deleted.
|
|
114
|
+
*/
|
|
115
|
+
delete(chainId, ensName) {
|
|
116
|
+
const normalizedEnsName = (0, controller_utils_1.normalizeEnsName)(ensName);
|
|
117
|
+
if (!(0, controller_utils_1.isSafeDynamicKey)(chainId) ||
|
|
118
|
+
!normalizedEnsName ||
|
|
119
|
+
!this.state.ensEntries[chainId] ||
|
|
120
|
+
!this.state.ensEntries[chainId][normalizedEnsName]) {
|
|
121
|
+
return false;
|
|
122
|
+
}
|
|
123
|
+
this.update((state) => {
|
|
124
|
+
delete state.ensEntries[chainId][normalizedEnsName];
|
|
125
|
+
if (Object.keys(state.ensEntries[chainId]).length === 0) {
|
|
126
|
+
delete state.ensEntries[chainId];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
return true;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Retrieve a DNS entry.
|
|
133
|
+
*
|
|
134
|
+
* @param chainId - Parent chain of the ENS entry to retrieve.
|
|
135
|
+
* @param ensName - Name of the ENS entry to retrieve.
|
|
136
|
+
* @returns The EnsEntry or null if it does not exist.
|
|
137
|
+
*/
|
|
138
|
+
get(chainId, ensName) {
|
|
139
|
+
const normalizedEnsName = (0, controller_utils_1.normalizeEnsName)(ensName);
|
|
140
|
+
// TODO Explicitly handle the case where `normalizedEnsName` is `null`
|
|
141
|
+
// eslint-disable-next-line no-implicit-coercion
|
|
142
|
+
return !!normalizedEnsName && this.state.ensEntries[chainId]
|
|
143
|
+
? this.state.ensEntries[chainId][normalizedEnsName] || null
|
|
144
|
+
: null;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Add or update an ENS entry by chainId and ensName.
|
|
148
|
+
*
|
|
149
|
+
* A null address indicates that the ENS name does not resolve.
|
|
150
|
+
*
|
|
151
|
+
* @param chainId - Id of the associated chain.
|
|
152
|
+
* @param ensName - The ENS name.
|
|
153
|
+
* @param address - Associated address (or null) to add or update.
|
|
154
|
+
* @returns Boolean indicating if the entry was set.
|
|
155
|
+
*/
|
|
156
|
+
set(chainId, ensName, address) {
|
|
157
|
+
if (!Number.isInteger(Number.parseInt(chainId, 10)) ||
|
|
158
|
+
!ensName ||
|
|
159
|
+
typeof ensName !== 'string' ||
|
|
160
|
+
(address && !(0, controller_utils_1.isValidHexAddress)(address))) {
|
|
161
|
+
throw new Error(
|
|
162
|
+
// TODO: Either fix this lint violation or explain why it's necessary to ignore.
|
|
163
|
+
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
164
|
+
`Invalid ENS entry: { chainId:${chainId}, ensName:${ensName}, address:${address}}`);
|
|
165
|
+
}
|
|
166
|
+
const normalizedEnsName = (0, controller_utils_1.normalizeEnsName)(ensName);
|
|
167
|
+
if (!normalizedEnsName) {
|
|
168
|
+
throw new Error(`Invalid ENS name: ${ensName}`);
|
|
169
|
+
}
|
|
170
|
+
const normalizedAddress = address ? (0, controller_utils_1.toChecksumHexAddress)(address) : null;
|
|
171
|
+
const subState = this.state.ensEntries[chainId];
|
|
172
|
+
if (subState?.[normalizedEnsName] &&
|
|
173
|
+
subState[normalizedEnsName].address === normalizedAddress) {
|
|
174
|
+
return false;
|
|
175
|
+
}
|
|
176
|
+
this.update((state) => {
|
|
177
|
+
state.ensEntries = {
|
|
178
|
+
...this.state.ensEntries,
|
|
179
|
+
[chainId]: {
|
|
180
|
+
...this.state.ensEntries[chainId],
|
|
181
|
+
[normalizedEnsName]: {
|
|
182
|
+
address: normalizedAddress,
|
|
183
|
+
chainId,
|
|
184
|
+
ensName: normalizedEnsName,
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
return true;
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Resolve ens by address.
|
|
193
|
+
*
|
|
194
|
+
* @param nonChecksummedAddress - address
|
|
195
|
+
* @returns ens resolution
|
|
196
|
+
*/
|
|
197
|
+
async reverseResolveAddress(nonChecksummedAddress) {
|
|
198
|
+
if (!__classPrivateFieldGet(this, _EnsController_ethProvider, "f")) {
|
|
199
|
+
return undefined;
|
|
200
|
+
}
|
|
201
|
+
const address = (0, controller_utils_1.toChecksumHexAddress)(nonChecksummedAddress);
|
|
202
|
+
if (this.state.ensResolutionsByAddress[address]) {
|
|
203
|
+
return this.state.ensResolutionsByAddress[address];
|
|
204
|
+
}
|
|
205
|
+
let domain;
|
|
206
|
+
try {
|
|
207
|
+
domain = await __classPrivateFieldGet(this, _EnsController_ethProvider, "f").lookupAddress(address);
|
|
208
|
+
}
|
|
209
|
+
catch (error) {
|
|
210
|
+
log(error);
|
|
211
|
+
return undefined;
|
|
212
|
+
}
|
|
213
|
+
if (!domain) {
|
|
214
|
+
return undefined;
|
|
215
|
+
}
|
|
216
|
+
let registeredAddress;
|
|
217
|
+
try {
|
|
218
|
+
registeredAddress = await __classPrivateFieldGet(this, _EnsController_ethProvider, "f").resolveName(domain);
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
log(error);
|
|
222
|
+
return undefined;
|
|
223
|
+
}
|
|
224
|
+
if (!registeredAddress) {
|
|
225
|
+
return undefined;
|
|
226
|
+
}
|
|
227
|
+
if (registeredAddress === ZERO_ADDRESS ||
|
|
228
|
+
registeredAddress === ZERO_X_ERROR_ADDRESS) {
|
|
229
|
+
return undefined;
|
|
230
|
+
}
|
|
231
|
+
if ((0, controller_utils_1.toChecksumHexAddress)(registeredAddress) !== address) {
|
|
232
|
+
return undefined;
|
|
233
|
+
}
|
|
234
|
+
this.update((state) => {
|
|
235
|
+
state.ensResolutionsByAddress[address] = (0, punycode_js_1.toASCII)(domain);
|
|
236
|
+
});
|
|
237
|
+
return domain;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
exports.EnsController = EnsController;
|
|
241
|
+
_EnsController_ethProvider = new WeakMap(), _EnsController_instances = new WeakSet(), _EnsController_setDefaultEthProvider = function _EnsController_setDefaultEthProvider(registriesByChainId) {
|
|
242
|
+
const { selectedNetworkClientId } = this.messagingSystem.call('NetworkController:getState');
|
|
243
|
+
__classPrivateFieldGet(this, _EnsController_instances, "m", _EnsController_setEthProvider).call(this, selectedNetworkClientId, registriesByChainId);
|
|
244
|
+
}, _EnsController_setEthProvider = function _EnsController_setEthProvider(selectedNetworkClientId, registriesByChainId) {
|
|
245
|
+
const { configuration: { chainId: currentChainId }, provider, } = this.messagingSystem.call('NetworkController:getNetworkClientById', selectedNetworkClientId);
|
|
246
|
+
if (registriesByChainId &&
|
|
247
|
+
registriesByChainId[parseInt(currentChainId, 16)] &&
|
|
248
|
+
__classPrivateFieldGet(this, _EnsController_instances, "m", _EnsController_getChainEnsSupport).call(this, currentChainId)) {
|
|
249
|
+
__classPrivateFieldSet(this, _EnsController_ethProvider, new providers_1.Web3Provider(provider, {
|
|
250
|
+
chainId: (0, controller_utils_1.convertHexToDecimal)(currentChainId),
|
|
251
|
+
name: controller_utils_1.CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP[currentChainId],
|
|
252
|
+
ensAddress: registriesByChainId[parseInt(currentChainId, 16)],
|
|
253
|
+
}), "f");
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
__classPrivateFieldSet(this, _EnsController_ethProvider, null, "f");
|
|
257
|
+
}
|
|
258
|
+
}, _EnsController_getChainEnsSupport = function _EnsController_getChainEnsSupport(chainId) {
|
|
259
|
+
return Boolean(this.state.ensEntries[chainId]);
|
|
260
|
+
};
|
|
261
|
+
exports.default = EnsController;
|
|
262
|
+
//# sourceMappingURL=EnsController.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnsController.cjs","sourceRoot":"","sources":["../src/EnsController.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,wDAAwD;AAExD,+DAA2D;AAE3D,iEAQoC;AAOpC,2CAAsD;AACtD,sDAA+C;AAE/C,MAAM,GAAG,GAAG,IAAA,2BAAmB,EAAC,gBAAgB,CAAC,CAAC;AAElD,MAAM,IAAI,GAAG,eAAe,CAAC;AAE7B,sDAAsD;AACzC,QAAA,uBAAuB,GAAwB;IAC1D,UAAU;IACV,CAAC,EAAE,4CAA4C;IAC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A,sCAAmB,EAAC,cAAc,CAAC;YAC5C,IAAI,EAAE,sDAAmC,CAAC,cAAyB,CAAC;YACpE,UAAU,EAAE,mBAAmB,CAAC,QAAQ,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC;SAC9D,CAAC,MAAA,CAAC;KACJ;SAAM;QACL,uBAAA,IAAI,8BAAgB,IAAI,MAAA,CAAC;KAC1B;AACH,CAAC,iFAQmB,OAAY;IAC9B,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,CAAC;AACjD,CAAC;AA4DH,kBAAe,aAAa,CAAC","sourcesContent":["import { 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 isSafeDynamicKey,\n toChecksumHexAddress,\n CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP,\n convertHexToDecimal,\n toHex,\n} from '@metamask/controller-utils';\nimport type {\n NetworkControllerGetNetworkClientByIdAction,\n NetworkControllerGetStateAction,\n NetworkState,\n} from '@metamask/network-controller';\nimport type { Hex } from '@metamask/utils';\nimport { createProjectLogger } from '@metamask/utils';\nimport { toASCII } from 'punycode/punycode.js';\n\nconst log = createProjectLogger('ens-controller');\n\nconst name = 'EnsController';\n\n// Map of chainIDs and ENS registry contract addresses\nexport const DEFAULT_ENS_NETWORK_MAP: Record<number, Hex> = {\n // Mainnet\n 1: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',\n // Ropsten\n 3: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',\n // Rinkeby\n 4: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',\n // Goerli\n 5: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',\n // Holesky\n 17000: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',\n // Sepolia\n 11155111: '0x00000000000C2E074eC69A0dFb2997BA6C7d2e1e',\n};\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 AllowedActions =\n | NetworkControllerGetNetworkClientByIdAction\n | NetworkControllerGetStateAction;\n\nexport type EnsControllerMessenger = RestrictedControllerMessenger<\n typeof name,\n AllowedActions,\n never,\n AllowedActions['type'],\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.registriesByChainId - Map between chain IDs and ENS contract addresses.\n * @param options.messenger - A reference to the messaging system.\n * @param options.state - Initial state to set on this controller.\n * @param options.onNetworkDidChange - Allows subscribing to network controller networkDidChange events.\n */\n constructor({\n registriesByChainId = DEFAULT_ENS_NETWORK_MAP,\n messenger,\n state = {},\n onNetworkDidChange,\n }: {\n registriesByChainId?: Record<number, Hex>;\n messenger: EnsControllerMessenger;\n state?: Partial<EnsControllerState>;\n onNetworkDidChange?: (\n listener: (networkState: NetworkState) => void,\n ) => void;\n }) {\n super({\n name,\n metadata,\n messenger,\n state: {\n ...defaultState,\n ensEntries: Object.fromEntries(\n Object.entries(registriesByChainId).map(([chainId, address]) => [\n toHex(chainId),\n {\n '.': {\n address,\n chainId: toHex(chainId),\n ensName: '.',\n },\n },\n ]),\n ),\n ...state,\n },\n });\n\n this.#setDefaultEthProvider(registriesByChainId);\n\n if (onNetworkDidChange) {\n onNetworkDidChange(({ selectedNetworkClientId }) => {\n this.resetState();\n this.#setEthProvider(selectedNetworkClientId, registriesByChainId);\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 !isSafeDynamicKey(chainId) ||\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 // TODO: Either fix this lint violation or explain why it's necessary to ignore.\n // eslint-disable-next-line @typescript-eslint/restrict-template-expressions\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 #setDefaultEthProvider(registriesByChainId?: Record<number, Hex>) {\n const { selectedNetworkClientId } = this.messagingSystem.call(\n 'NetworkController:getState',\n );\n this.#setEthProvider(selectedNetworkClientId, registriesByChainId);\n }\n\n #setEthProvider(\n selectedNetworkClientId: string,\n registriesByChainId?: Record<number, Hex>,\n ) {\n const {\n configuration: { chainId: currentChainId },\n provider,\n } = this.messagingSystem.call(\n 'NetworkController:getNetworkClientById',\n selectedNetworkClientId,\n );\n\n if (\n registriesByChainId &&\n registriesByChainId[parseInt(currentChainId, 16)] &&\n this.#getChainEnsSupport(currentChainId)\n ) {\n this.#ethProvider = new Web3Provider(provider, {\n chainId: convertHexToDecimal(currentChainId),\n name: CHAIN_ID_TO_ETHERS_NETWORK_NAME_MAP[currentChainId as ChainId],\n ensAddress: registriesByChainId[parseInt(currentChainId, 16)],\n });\n } else {\n this.#ethProvider = null;\n }\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: Hex) {\n return Boolean(this.state.ensEntries[chainId]);\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,7 +1,7 @@
|
|
|
1
|
-
import type { RestrictedControllerMessenger } from
|
|
2
|
-
import { BaseController } from
|
|
3
|
-
import type { NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkState } from
|
|
4
|
-
import type { Hex } from
|
|
1
|
+
import type { RestrictedControllerMessenger } from "@metamask/base-controller";
|
|
2
|
+
import { BaseController } from "@metamask/base-controller";
|
|
3
|
+
import type { NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkState } from "@metamask/network-controller";
|
|
4
|
+
import type { Hex } from "@metamask/utils";
|
|
5
5
|
declare const name = "EnsController";
|
|
6
6
|
export declare const DEFAULT_ENS_NETWORK_MAP: Record<number, Hex>;
|
|
7
7
|
/**
|
|
@@ -100,4 +100,4 @@ export declare class EnsController extends BaseController<typeof name, EnsContro
|
|
|
100
100
|
reverseResolveAddress(nonChecksummedAddress: string): Promise<string | undefined>;
|
|
101
101
|
}
|
|
102
102
|
export default EnsController;
|
|
103
|
-
//# sourceMappingURL=EnsController.d.
|
|
103
|
+
//# sourceMappingURL=EnsController.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnsController.d.cts","sourceRoot":"","sources":["../src/EnsController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6BAA6B,EAAE,kCAAkC;AAC/E,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAW3D,OAAO,KAAK,EACV,2CAA2C,EAC3C,+BAA+B,EAC/B,YAAY,EACb,qCAAqC;AACtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAM3C,QAAA,MAAM,IAAI,kBAAkB,CAAC;AAG7B,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAavD,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE;QACV,CAAC,OAAO,EAAE,GAAG,GAAG;YACd,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CAAC;SAC7B,CAAC;KACH,CAAC;IACF,uBAAuB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACpD,CAAC;AAEF,MAAM,MAAM,cAAc,GACtB,2CAA2C,GAC3C,+BAA+B,CAAC;AAEpC,MAAM,MAAM,sBAAsB,GAAG,6BAA6B,CAChE,OAAO,IAAI,EACX,cAAc,EACd,KAAK,EACL,cAAc,CAAC,MAAM,CAAC,EACtB,KAAK,CACN,CAAC;AAeF;;;GAGG;AACH,qBAAa,aAAc,SAAQ,cAAc,CAC/C,OAAO,IAAI,EACX,kBAAkB,EAClB,sBAAsB,CACvB;;IAGC;;;;;;;;OAQG;gBACS,EACV,mBAA6C,EAC7C,SAAS,EACT,KAAU,EACV,kBAAkB,GACnB,EAAE;QACD,mBAAmB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;QAC1C,SAAS,EAAE,sBAAsB,CAAC;QAClC,KAAK,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;QACpC,kBAAkB,CAAC,EAAE,CACnB,QAAQ,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI,KAC3C,IAAI,CAAC;KACX;IAiCD;;OAEG;IACH,UAAU;IAMV;;OAEG;IACH,KAAK;IAML;;;;;;OAMG;IACH,MAAM,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,OAAO;IAqB9C;;;;;;OAMG;IACH,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI;IAUnD;;;;;;;;;OASG;IACH,GAAG,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,GAAG,OAAO;IAyFnE;;;;;OAKG;IACG,qBAAqB,CAAC,qBAAqB,EAAE,MAAM;CAkD1D;AAED,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import type { RestrictedControllerMessenger } from "@metamask/base-controller";
|
|
2
|
+
import { BaseController } from "@metamask/base-controller";
|
|
3
|
+
import type { NetworkControllerGetNetworkClientByIdAction, NetworkControllerGetStateAction, NetworkState } from "@metamask/network-controller";
|
|
4
|
+
import type { Hex } from "@metamask/utils";
|
|
5
|
+
declare const name = "EnsController";
|
|
6
|
+
export declare const DEFAULT_ENS_NETWORK_MAP: Record<number, Hex>;
|
|
7
|
+
/**
|
|
8
|
+
* @type EnsEntry
|
|
9
|
+
*
|
|
10
|
+
* ENS entry representation
|
|
11
|
+
* @property chainId - Id of the associated chain
|
|
12
|
+
* @property ensName - The ENS name
|
|
13
|
+
* @property address - Hex address with the ENS name, or null
|
|
14
|
+
*/
|
|
15
|
+
export type EnsEntry = {
|
|
16
|
+
chainId: Hex;
|
|
17
|
+
ensName: string;
|
|
18
|
+
address: string | null;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* @type EnsControllerState
|
|
22
|
+
*
|
|
23
|
+
* ENS controller state
|
|
24
|
+
* @property ensEntries - Object of ENS entry objects
|
|
25
|
+
*/
|
|
26
|
+
export type EnsControllerState = {
|
|
27
|
+
ensEntries: {
|
|
28
|
+
[chainId: Hex]: {
|
|
29
|
+
[ensName: string]: EnsEntry;
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
ensResolutionsByAddress: {
|
|
33
|
+
[key: string]: string;
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
export type AllowedActions = NetworkControllerGetNetworkClientByIdAction | NetworkControllerGetStateAction;
|
|
37
|
+
export type EnsControllerMessenger = RestrictedControllerMessenger<typeof name, AllowedActions, never, AllowedActions['type'], never>;
|
|
38
|
+
/**
|
|
39
|
+
* Controller that manages a list ENS names and their resolved addresses
|
|
40
|
+
* by chainId. A null address indicates an unresolved ENS name.
|
|
41
|
+
*/
|
|
42
|
+
export declare class EnsController extends BaseController<typeof name, EnsControllerState, EnsControllerMessenger> {
|
|
43
|
+
#private;
|
|
44
|
+
/**
|
|
45
|
+
* Creates an EnsController instance.
|
|
46
|
+
*
|
|
47
|
+
* @param options - Constructor options.
|
|
48
|
+
* @param options.registriesByChainId - Map between chain IDs and ENS contract addresses.
|
|
49
|
+
* @param options.messenger - A reference to the messaging system.
|
|
50
|
+
* @param options.state - Initial state to set on this controller.
|
|
51
|
+
* @param options.onNetworkDidChange - Allows subscribing to network controller networkDidChange events.
|
|
52
|
+
*/
|
|
53
|
+
constructor({ registriesByChainId, messenger, state, onNetworkDidChange, }: {
|
|
54
|
+
registriesByChainId?: Record<number, Hex>;
|
|
55
|
+
messenger: EnsControllerMessenger;
|
|
56
|
+
state?: Partial<EnsControllerState>;
|
|
57
|
+
onNetworkDidChange?: (listener: (networkState: NetworkState) => void) => void;
|
|
58
|
+
});
|
|
59
|
+
/**
|
|
60
|
+
* Clears ensResolutionsByAddress state property.
|
|
61
|
+
*/
|
|
62
|
+
resetState(): void;
|
|
63
|
+
/**
|
|
64
|
+
* Remove all chain Ids and ENS entries from state.
|
|
65
|
+
*/
|
|
66
|
+
clear(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Delete an ENS entry.
|
|
69
|
+
*
|
|
70
|
+
* @param chainId - Parent chain of the ENS entry to delete.
|
|
71
|
+
* @param ensName - Name of the ENS entry to delete.
|
|
72
|
+
* @returns Boolean indicating if the entry was deleted.
|
|
73
|
+
*/
|
|
74
|
+
delete(chainId: Hex, ensName: string): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Retrieve a DNS entry.
|
|
77
|
+
*
|
|
78
|
+
* @param chainId - Parent chain of the ENS entry to retrieve.
|
|
79
|
+
* @param ensName - Name of the ENS entry to retrieve.
|
|
80
|
+
* @returns The EnsEntry or null if it does not exist.
|
|
81
|
+
*/
|
|
82
|
+
get(chainId: Hex, ensName: string): EnsEntry | null;
|
|
83
|
+
/**
|
|
84
|
+
* Add or update an ENS entry by chainId and ensName.
|
|
85
|
+
*
|
|
86
|
+
* A null address indicates that the ENS name does not resolve.
|
|
87
|
+
*
|
|
88
|
+
* @param chainId - Id of the associated chain.
|
|
89
|
+
* @param ensName - The ENS name.
|
|
90
|
+
* @param address - Associated address (or null) to add or update.
|
|
91
|
+
* @returns Boolean indicating if the entry was set.
|
|
92
|
+
*/
|
|
93
|
+
set(chainId: Hex, ensName: string, address: string | null): boolean;
|
|
94
|
+
/**
|
|
95
|
+
* Resolve ens by address.
|
|
96
|
+
*
|
|
97
|
+
* @param nonChecksummedAddress - address
|
|
98
|
+
* @returns ens resolution
|
|
99
|
+
*/
|
|
100
|
+
reverseResolveAddress(nonChecksummedAddress: string): Promise<string | undefined>;
|
|
101
|
+
}
|
|
102
|
+
export default EnsController;
|
|
103
|
+
//# sourceMappingURL=EnsController.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EnsController.d.mts","sourceRoot":"","sources":["../src/EnsController.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,6BAA6B,EAAE,kCAAkC;AAC/E,OAAO,EAAE,cAAc,EAAE,kCAAkC;AAW3D,OAAO,KAAK,EACV,2CAA2C,EAC3C,+BAA+B,EAC/B,YAAY,EACb,qCAAqC;AACtC,OAAO,KAAK,EAAE,GAAG,EAAE,wBAAwB;AAM3C,QAAA,MAAM,IAAI,kBAAkB,CAAC;AAG7B,eAAO,MAAM,uBAAuB,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAavD,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,MAAM,QAAQ,GAAG;IACrB,OAAO,EAAE,GAAG,CAAC;IACb,OAAO,EAAE,MAAM,CAAC;IAChB,OAAO,EAAE,MAAM,GAAG,IAAI,CAAC;CACxB,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,kBAAkB,GAAG;IAC/B,UAAU,EAAE;QACV,CAAC,OAAO,EAAE,GAAG,GAAG;YACd,CAAC,OAAO,EAAE,MAAM,GAAG,QAAQ,CAAC;SAC7B,CAAC;KACH,CAAC;IACF,uBAAuB,EAAE;QAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAA;KAAE,CAAC;CACpD,CAAC;AA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