@metamask/name-controller 4.2.0 → 6.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 +42 -1
- package/dist/NameController.js +14 -391
- package/dist/NameController.js.map +1 -1
- package/dist/NameController.mjs +15 -0
- package/dist/NameController.mjs.map +1 -0
- package/dist/chunk-6W3DEAGA.mjs +10 -0
- package/dist/chunk-6W3DEAGA.mjs.map +1 -0
- package/dist/chunk-B2WJNTJS.js +513 -0
- package/dist/chunk-B2WJNTJS.js.map +1 -0
- package/dist/chunk-BLG7EQAA.mjs +66 -0
- package/dist/chunk-BLG7EQAA.mjs.map +1 -0
- package/dist/chunk-DSVOMJX6.mjs +43 -0
- package/dist/chunk-DSVOMJX6.mjs.map +1 -0
- package/dist/chunk-EOUDE5KM.mjs +67 -0
- package/dist/chunk-EOUDE5KM.mjs.map +1 -0
- package/dist/chunk-GJYKWMRC.mjs +513 -0
- package/dist/chunk-GJYKWMRC.mjs.map +1 -0
- package/dist/chunk-JHYBLEC5.js +43 -0
- package/dist/chunk-JHYBLEC5.js.map +1 -0
- package/dist/chunk-L244TFFU.mjs +9 -0
- package/dist/chunk-L244TFFU.mjs.map +1 -0
- package/dist/chunk-PL7IXD33.js +10 -0
- package/dist/chunk-PL7IXD33.js.map +1 -0
- package/dist/chunk-QBR7BSWB.js +9 -0
- package/dist/chunk-QBR7BSWB.js.map +1 -0
- package/dist/chunk-RYIUDJOI.js +66 -0
- package/dist/chunk-RYIUDJOI.js.map +1 -0
- package/dist/chunk-SHTSUEYM.mjs +113 -0
- package/dist/chunk-SHTSUEYM.mjs.map +1 -0
- package/dist/chunk-UALYD4SG.mjs +138 -0
- package/dist/chunk-UALYD4SG.mjs.map +1 -0
- package/dist/chunk-W64QIPGB.js +80 -0
- package/dist/chunk-W64QIPGB.js.map +1 -0
- package/dist/chunk-WSOVXHAC.mjs +80 -0
- package/dist/chunk-WSOVXHAC.mjs.map +1 -0
- package/dist/chunk-X55IV67M.js +138 -0
- package/dist/chunk-X55IV67M.js.map +1 -0
- package/dist/chunk-XQXO5QPM.js +113 -0
- package/dist/chunk-XQXO5QPM.js.map +1 -0
- package/dist/chunk-XUI43LEZ.mjs +30 -0
- package/dist/chunk-XUI43LEZ.mjs.map +1 -0
- package/dist/chunk-Z4BLTVTB.js +30 -0
- package/dist/chunk-Z4BLTVTB.js.map +1 -0
- package/dist/chunk-Z6YC2DHC.js +67 -0
- package/dist/chunk-Z6YC2DHC.js.map +1 -0
- package/dist/constants.js +9 -105
- package/dist/constants.js.map +1 -1
- package/dist/constants.mjs +10 -0
- package/dist/constants.mjs.map +1 -0
- package/dist/index.js +36 -22
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +37 -0
- package/dist/index.mjs.map +1 -0
- package/dist/logger.js +9 -6
- package/dist/logger.js.map +1 -1
- package/dist/logger.mjs +10 -0
- package/dist/logger.mjs.map +1 -0
- package/dist/providers/ens.js +9 -75
- package/dist/providers/ens.js.map +1 -1
- package/dist/providers/ens.mjs +10 -0
- package/dist/providers/ens.mjs.map +1 -0
- package/dist/providers/etherscan.js +11 -141
- package/dist/providers/etherscan.js.map +1 -1
- package/dist/providers/etherscan.mjs +12 -0
- package/dist/providers/etherscan.mjs.map +1 -0
- package/dist/providers/lens.js +10 -88
- package/dist/providers/lens.js.map +1 -1
- package/dist/providers/lens.mjs +11 -0
- package/dist/providers/lens.mjs.map +1 -0
- package/dist/providers/token.js +10 -78
- package/dist/providers/token.js.map +1 -1
- package/dist/providers/token.mjs +11 -0
- package/dist/providers/token.mjs.map +1 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -0
- package/dist/{NameController.d.ts → types/NameController.d.ts} +1 -0
- package/dist/types/NameController.d.ts.map +1 -0
- package/dist/{constants.d.ts → types/constants.d.ts} +7 -2
- package/dist/types/constants.d.ts.map +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/logger.d.ts.map +1 -0
- package/dist/types/providers/ens.d.ts.map +1 -0
- package/dist/types/providers/etherscan.d.ts.map +1 -0
- package/dist/types/providers/lens.d.ts.map +1 -0
- package/dist/types/providers/token.d.ts.map +1 -0
- package/dist/types/types.d.ts.map +1 -0
- package/dist/types/util.d.ts.map +1 -0
- package/dist/types.js +7 -9
- package/dist/types.js.map +1 -1
- package/dist/types.mjs +8 -0
- package/dist/types.mjs.map +1 -0
- package/dist/util.js +13 -88
- package/dist/util.js.map +1 -1
- package/dist/util.mjs +14 -0
- package/dist/util.mjs.map +1 -0
- package/package.json +12 -2
- package/dist/NameController.d.ts.map +0 -1
- package/dist/constants.d.ts.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/logger.d.ts.map +0 -1
- package/dist/providers/ens.d.ts.map +0 -1
- package/dist/providers/etherscan.d.ts.map +0 -1
- package/dist/providers/lens.d.ts.map +0 -1
- package/dist/providers/token.d.ts.map +0 -1
- package/dist/types.d.ts.map +0 -1
- package/dist/util.d.ts.map +0 -1
- /package/dist/{index.d.ts → types/index.d.ts} +0 -0
- /package/dist/{logger.d.ts → types/logger.d.ts} +0 -0
- /package/dist/{providers → types/providers}/ens.d.ts +0 -0
- /package/dist/{providers → types/providers}/etherscan.d.ts +0 -0
- /package/dist/{providers → types/providers}/lens.d.ts +0 -0
- /package/dist/{providers → types/providers}/token.d.ts +0 -0
- /package/dist/{types.d.ts → types/types.d.ts} +0 -0
- /package/dist/{util.d.ts → types/util.d.ts} +0 -0
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,38 +7,74 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
6
7
|
|
|
7
8
|
## [Unreleased]
|
|
8
9
|
|
|
10
|
+
## [6.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 Linea Sepolia (chain ID `0xe705`) ([#3995](https://github.com/MetaMask/core/pull/3995))
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
|
|
20
|
+
- **BREAKING:** Bump `@metamask/base-controller` to `^5.0.0` ([#4039](https://github.com/MetaMask/core/pull/4039))
|
|
21
|
+
- This version has a number of breaking changes. See the changelog for more.
|
|
22
|
+
- **BREAKING:** Remove support for Optimism Goerli (chain ID `0x1a4`); replace with support for Optimism Sepolia (chain ID `0xaa37dc`) ([#3999](https://github.com/MetaMask/core/pull/3999))
|
|
23
|
+
|
|
24
|
+
## [5.0.0]
|
|
25
|
+
|
|
26
|
+
### Changed
|
|
27
|
+
|
|
28
|
+
- **BREAKING:** Add expire limit for proposed names ([#3748](https://github.com/MetaMask/core/pull/3748))
|
|
29
|
+
- Expired names now get removed on every call to `updateProposedNames`
|
|
30
|
+
- Bump `@metamask/base-controller` to `^4.1.1` ([#3821](https://github.com/MetaMask/core/pull/3821))
|
|
31
|
+
|
|
9
32
|
## [4.2.0]
|
|
33
|
+
|
|
10
34
|
### Added
|
|
35
|
+
|
|
11
36
|
- Add `origin` property to `NameEntry` and `SetNameRequest` ([#3751](https://github.com/MetaMask/core/pull/3751))
|
|
12
37
|
|
|
13
38
|
## [4.1.0]
|
|
39
|
+
|
|
14
40
|
### Added
|
|
41
|
+
|
|
15
42
|
- Add fallback variation for petnames ([#3705](https://github.com/MetaMask/core/pull/3705))
|
|
16
43
|
|
|
17
44
|
## [4.0.1]
|
|
45
|
+
|
|
18
46
|
### Changed
|
|
47
|
+
|
|
19
48
|
- Bump `@metamask/base-controller` to `^4.0.1` ([#3695](https://github.com/MetaMask/core/pull/3695))
|
|
20
49
|
|
|
21
50
|
## [4.0.0]
|
|
51
|
+
|
|
22
52
|
### Changed
|
|
53
|
+
|
|
23
54
|
- **BREAKING:** Bump `@metamask/base-controller` to ^4.0.0 ([#2063](https://github.com/MetaMask/core/pull/2063))
|
|
24
55
|
- This is breaking because the type of the `messenger` has backward-incompatible changes. See the changelog for this package for more.
|
|
25
56
|
- Bump `@metamask/utils` to ^8.2.0 ([#1957](https://github.com/MetaMask/core/pull/1957))
|
|
26
57
|
|
|
27
58
|
## [3.0.1]
|
|
59
|
+
|
|
28
60
|
### Changed
|
|
61
|
+
|
|
29
62
|
- Bump dependency on `@metamask/utils` to ^8.1.0 ([#1639](https://github.com/MetaMask/core/pull/1639))
|
|
30
63
|
- Bump dependency on `@metamask/base-controller` to ^3.2.3
|
|
31
64
|
|
|
32
65
|
## [3.0.0]
|
|
66
|
+
|
|
33
67
|
### Changed
|
|
68
|
+
|
|
34
69
|
- **BREAKING**: Normalize addresses and chain IDs ([#1732](https://github.com/MetaMask/core/pull/1732))
|
|
35
70
|
- Save addresses and chain IDs as lowercase in state
|
|
36
71
|
- Remove `getChainId` constructor callback
|
|
37
72
|
- Require a `variation` property when calling `setName` or `updateProposedNames` with the `ethereumAddress` type
|
|
38
73
|
|
|
39
74
|
## [2.0.0]
|
|
75
|
+
|
|
40
76
|
### Changed
|
|
77
|
+
|
|
41
78
|
- **BREAKING**: Support rate limiting in name providers ([#1715](https://github.com/MetaMask/core/pull/1715))
|
|
42
79
|
- Breaking changes:
|
|
43
80
|
- Change `proposedNames` property in `NameEntry` type from string array to new `ProposedNamesEntry` type
|
|
@@ -52,10 +89,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
52
89
|
- Update TypeScript to v4.8.x ([#1718](https://github.com/MetaMask/core/pull/1718))
|
|
53
90
|
|
|
54
91
|
## [1.0.0]
|
|
92
|
+
|
|
55
93
|
### Added
|
|
94
|
+
|
|
56
95
|
- Initial Release ([#1647](https://github.com/MetaMask/core/pull/1647))
|
|
57
96
|
|
|
58
|
-
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/name-controller@
|
|
97
|
+
[Unreleased]: https://github.com/MetaMask/core/compare/@metamask/name-controller@6.0.0...HEAD
|
|
98
|
+
[6.0.0]: https://github.com/MetaMask/core/compare/@metamask/name-controller@5.0.0...@metamask/name-controller@6.0.0
|
|
99
|
+
[5.0.0]: https://github.com/MetaMask/core/compare/@metamask/name-controller@4.2.0...@metamask/name-controller@5.0.0
|
|
59
100
|
[4.2.0]: https://github.com/MetaMask/core/compare/@metamask/name-controller@4.1.0...@metamask/name-controller@4.2.0
|
|
60
101
|
[4.1.0]: https://github.com/MetaMask/core/compare/@metamask/name-controller@4.0.1...@metamask/name-controller@4.1.0
|
|
61
102
|
[4.0.1]: https://github.com/MetaMask/core/compare/@metamask/name-controller@4.0.0...@metamask/name-controller@4.0.1
|
package/dist/NameController.js
CHANGED
|
@@ -1,392 +1,15 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
16
|
-
};
|
|
17
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
18
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
19
|
-
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");
|
|
20
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
21
|
-
};
|
|
22
|
-
var _NameController_instances, _NameController_providers, _NameController_updateDelay, _NameController_updateProposedNameState, _NameController_updateSourceState, _NameController_getUpdateProposedNamesResult, _NameController_getProviderResponse, _NameController_normalizeProviderResult, _NameController_normalizeProviderSourceResult, _NameController_normalizeValue, _NameController_normalizeVariation, _NameController_updateEntry, _NameController_getCurrentTimeSeconds, _NameController_validateSetNameRequest, _NameController_validateUpdateProposedNamesRequest, _NameController_validateValue, _NameController_validateType, _NameController_validateName, _NameController_validateSourceIds, _NameController_validateSourceId, _NameController_validateDuplicateSourceIds, _NameController_validateVariation, _NameController_validateOrigin, _NameController_getAllSourceIds, _NameController_getSourceIds, _NameController_removeDormantProposedNames;
|
|
23
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.NameController = exports.NameOrigin = exports.FALLBACK_VARIATION = void 0;
|
|
25
|
-
const base_controller_1 = require("@metamask/base-controller");
|
|
26
|
-
const types_1 = require("./types");
|
|
27
|
-
exports.FALLBACK_VARIATION = '*';
|
|
28
|
-
/**
|
|
29
|
-
* Enumerates the possible origins responsible for setting a petname.
|
|
30
|
-
*/
|
|
31
|
-
var NameOrigin;
|
|
32
|
-
(function (NameOrigin) {
|
|
33
|
-
// Originated from an account identity.
|
|
34
|
-
NameOrigin["ACCOUNT_IDENTITY"] = "account-identity";
|
|
35
|
-
// Originated from an address book entry.
|
|
36
|
-
NameOrigin["ADDRESS_BOOK"] = "address-book";
|
|
37
|
-
// Originated from the API (NameController.setName). This is the default.
|
|
38
|
-
NameOrigin["API"] = "api";
|
|
39
|
-
// Originated from the user taking action in the UI.
|
|
40
|
-
NameOrigin["UI"] = "ui";
|
|
41
|
-
})(NameOrigin = exports.NameOrigin || (exports.NameOrigin = {}));
|
|
42
|
-
const DEFAULT_UPDATE_DELAY = 60 * 2; // 2 Minutes
|
|
43
|
-
const DEFAULT_VARIATION = '';
|
|
44
|
-
const controllerName = 'NameController';
|
|
45
|
-
const stateMetadata = {
|
|
46
|
-
names: { persist: true, anonymous: false },
|
|
47
|
-
nameSources: { persist: true, anonymous: false },
|
|
48
|
-
};
|
|
49
|
-
const getDefaultState = () => ({
|
|
50
|
-
names: {
|
|
51
|
-
[types_1.NameType.ETHEREUM_ADDRESS]: {},
|
|
52
|
-
},
|
|
53
|
-
nameSources: {},
|
|
54
|
-
});
|
|
55
|
-
/**
|
|
56
|
-
* Controller for storing and deriving names for values such as Ethereum addresses.
|
|
57
|
-
*/
|
|
58
|
-
class NameController extends base_controller_1.BaseController {
|
|
59
|
-
/**
|
|
60
|
-
* Construct a Name controller.
|
|
61
|
-
*
|
|
62
|
-
* @param options - Controller options.
|
|
63
|
-
* @param options.messenger - Restricted controller messenger for the name controller.
|
|
64
|
-
* @param options.providers - Array of name provider instances to propose names.
|
|
65
|
-
* @param options.state - Initial state to set on the controller.
|
|
66
|
-
* @param options.updateDelay - The delay in seconds before a new request to a source should be made.
|
|
67
|
-
*/
|
|
68
|
-
constructor({ messenger, providers, state, updateDelay, }) {
|
|
69
|
-
super({
|
|
70
|
-
name: controllerName,
|
|
71
|
-
metadata: stateMetadata,
|
|
72
|
-
messenger,
|
|
73
|
-
state: Object.assign(Object.assign({}, getDefaultState()), state),
|
|
74
|
-
});
|
|
75
|
-
_NameController_instances.add(this);
|
|
76
|
-
_NameController_providers.set(this, void 0);
|
|
77
|
-
_NameController_updateDelay.set(this, void 0);
|
|
78
|
-
__classPrivateFieldSet(this, _NameController_providers, providers, "f");
|
|
79
|
-
__classPrivateFieldSet(this, _NameController_updateDelay, updateDelay !== null && updateDelay !== void 0 ? updateDelay : DEFAULT_UPDATE_DELAY, "f");
|
|
80
|
-
}
|
|
81
|
-
/**
|
|
82
|
-
* Set the user specified name for a value.
|
|
83
|
-
*
|
|
84
|
-
* @param request - Request object.
|
|
85
|
-
* @param request.name - Name to set.
|
|
86
|
-
* @param request.sourceId - Optional ID of the source of the proposed name.
|
|
87
|
-
* @param request.type - Type of value to set the name for.
|
|
88
|
-
* @param request.value - Value to set the name for.
|
|
89
|
-
* @param request.variation - Variation of the raw value to set the name for. The chain ID if the type is Ethereum address.
|
|
90
|
-
*/
|
|
91
|
-
setName(request) {
|
|
92
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_validateSetNameRequest).call(this, request);
|
|
93
|
-
const { value, type, name, sourceId: requestSourceId, origin: requestOrigin, variation, } = request;
|
|
94
|
-
const sourceId = requestSourceId !== null && requestSourceId !== void 0 ? requestSourceId : null;
|
|
95
|
-
// If the name is being cleared, the fallback origin should be cleared as well.
|
|
96
|
-
const fallbackOrigin = name === null ? null : NameOrigin.API;
|
|
97
|
-
const origin = requestOrigin !== null && requestOrigin !== void 0 ? requestOrigin : fallbackOrigin;
|
|
98
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_updateEntry).call(this, value, type, variation, (entry) => {
|
|
99
|
-
entry.name = name;
|
|
100
|
-
entry.sourceId = sourceId;
|
|
101
|
-
entry.origin = origin;
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
/**
|
|
105
|
-
* Generate the proposed names for a value using the name providers and store them in the state.
|
|
106
|
-
*
|
|
107
|
-
* @param request - Request object.
|
|
108
|
-
* @param request.value - Value to update the proposed names for.
|
|
109
|
-
* @param request.type - Type of value to update the proposed names for.
|
|
110
|
-
* @param request.sourceIds - Optional array of source IDs to limit which sources are used by the providers. If not provided, all sources in all providers will be used.
|
|
111
|
-
* @param request.variation - Variation of the raw value to update proposed names for. The chain ID if the type is Ethereum address.
|
|
112
|
-
* @returns The updated proposed names for the value.
|
|
113
|
-
*/
|
|
114
|
-
updateProposedNames(request) {
|
|
115
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
116
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_validateUpdateProposedNamesRequest).call(this, request);
|
|
117
|
-
const providerResponses = (yield Promise.all(__classPrivateFieldGet(this, _NameController_providers, "f").map((provider) => __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_getProviderResponse).call(this, request, provider)))).filter((response) => Boolean(response));
|
|
118
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_updateProposedNameState).call(this, request, providerResponses);
|
|
119
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_updateSourceState).call(this, __classPrivateFieldGet(this, _NameController_providers, "f"));
|
|
120
|
-
return __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_getUpdateProposedNamesResult).call(this, providerResponses);
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
exports.NameController = NameController;
|
|
125
|
-
_NameController_providers = new WeakMap(), _NameController_updateDelay = new WeakMap(), _NameController_instances = new WeakSet(), _NameController_updateProposedNameState = function _NameController_updateProposedNameState(request, providerResponses) {
|
|
126
|
-
const { value, type, variation } = request;
|
|
127
|
-
const currentTime = __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_getCurrentTimeSeconds).call(this);
|
|
128
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_updateEntry).call(this, value, type, variation, (entry) => {
|
|
129
|
-
var _a;
|
|
130
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_removeDormantProposedNames).call(this, entry.proposedNames, type);
|
|
131
|
-
for (const providerResponse of providerResponses) {
|
|
132
|
-
const { results } = providerResponse;
|
|
133
|
-
for (const sourceId of Object.keys(providerResponse.results)) {
|
|
134
|
-
const result = results[sourceId];
|
|
135
|
-
const { proposedNames, updateDelay } = result;
|
|
136
|
-
const proposedNameEntry = (_a = entry.proposedNames[sourceId]) !== null && _a !== void 0 ? _a : {
|
|
137
|
-
proposedNames: [],
|
|
138
|
-
lastRequestTime: null,
|
|
139
|
-
updateDelay: null,
|
|
140
|
-
};
|
|
141
|
-
entry.proposedNames[sourceId] = proposedNameEntry;
|
|
142
|
-
if (proposedNames) {
|
|
143
|
-
proposedNameEntry.proposedNames = proposedNames;
|
|
144
|
-
}
|
|
145
|
-
proposedNameEntry.lastRequestTime = currentTime;
|
|
146
|
-
proposedNameEntry.updateDelay = updateDelay !== null && updateDelay !== void 0 ? updateDelay : null;
|
|
147
|
-
}
|
|
148
|
-
}
|
|
149
|
-
});
|
|
150
|
-
}, _NameController_updateSourceState = function _NameController_updateSourceState(providers) {
|
|
151
|
-
const newNameSources = Object.assign({}, this.state.nameSources);
|
|
152
|
-
for (const provider of providers) {
|
|
153
|
-
const { sourceLabels } = provider.getMetadata();
|
|
154
|
-
for (const sourceId of Object.keys(sourceLabels)) {
|
|
155
|
-
newNameSources[sourceId] = {
|
|
156
|
-
label: sourceLabels[sourceId],
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
this.update((state) => {
|
|
161
|
-
state.nameSources = newNameSources;
|
|
162
|
-
});
|
|
163
|
-
}, _NameController_getUpdateProposedNamesResult = function _NameController_getUpdateProposedNamesResult(providerResponses) {
|
|
164
|
-
return providerResponses.reduce((acc, providerResponse) => {
|
|
165
|
-
const { results } = providerResponse;
|
|
166
|
-
for (const sourceId of Object.keys(results)) {
|
|
167
|
-
const { proposedNames, error } = results[sourceId];
|
|
168
|
-
acc.results[sourceId] = {
|
|
169
|
-
proposedNames,
|
|
170
|
-
error,
|
|
171
|
-
};
|
|
172
|
-
}
|
|
173
|
-
return acc;
|
|
174
|
-
}, { results: {} });
|
|
175
|
-
}, _NameController_getProviderResponse = function _NameController_getProviderResponse(request, provider) {
|
|
176
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
177
|
-
const { value, type, sourceIds: requestedSourceIds, onlyUpdateAfterDelay, variation, } = request;
|
|
178
|
-
/* istanbul ignore next */
|
|
179
|
-
const variationKey = variation !== null && variation !== void 0 ? variation : DEFAULT_VARIATION;
|
|
180
|
-
const supportedSourceIds = __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_getSourceIds).call(this, provider, type);
|
|
181
|
-
const currentTime = __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_getCurrentTimeSeconds).call(this);
|
|
182
|
-
const normalizedValue = __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_normalizeValue).call(this, value, type);
|
|
183
|
-
const matchingSourceIds = supportedSourceIds.filter((sourceId) => {
|
|
184
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
185
|
-
if (requestedSourceIds && !requestedSourceIds.includes(sourceId)) {
|
|
186
|
-
return false;
|
|
187
|
-
}
|
|
188
|
-
if (onlyUpdateAfterDelay) {
|
|
189
|
-
const entry = (_c = (_b = (_a = this.state.names[type]) === null || _a === void 0 ? void 0 : _a[normalizedValue]) === null || _b === void 0 ? void 0 : _b[variationKey]) !== null && _c !== void 0 ? _c : {};
|
|
190
|
-
const proposedNamesEntry = (_e = (_d = entry.proposedNames) === null || _d === void 0 ? void 0 : _d[sourceId]) !== null && _e !== void 0 ? _e : {};
|
|
191
|
-
const lastRequestTime = (_f = proposedNamesEntry.lastRequestTime) !== null && _f !== void 0 ? _f : 0;
|
|
192
|
-
const updateDelay = (_g = proposedNamesEntry.updateDelay) !== null && _g !== void 0 ? _g : __classPrivateFieldGet(this, _NameController_updateDelay, "f");
|
|
193
|
-
if (currentTime - lastRequestTime < updateDelay) {
|
|
194
|
-
return false;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
return true;
|
|
198
|
-
});
|
|
199
|
-
if (!matchingSourceIds.length) {
|
|
200
|
-
return undefined;
|
|
201
|
-
}
|
|
202
|
-
const providerRequest = {
|
|
203
|
-
value: __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_normalizeValue).call(this, value, type),
|
|
204
|
-
type,
|
|
205
|
-
sourceIds: requestedSourceIds ? matchingSourceIds : undefined,
|
|
206
|
-
variation: __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_normalizeVariation).call(this, variationKey, type),
|
|
207
|
-
};
|
|
208
|
-
let responseError;
|
|
209
|
-
let response;
|
|
210
|
-
try {
|
|
211
|
-
response = yield provider.getProposedNames(providerRequest);
|
|
212
|
-
responseError = response.error;
|
|
213
|
-
}
|
|
214
|
-
catch (error) {
|
|
215
|
-
responseError = error;
|
|
216
|
-
}
|
|
217
|
-
return __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_normalizeProviderResult).call(this, response, responseError, matchingSourceIds);
|
|
218
|
-
});
|
|
219
|
-
}, _NameController_normalizeProviderResult = function _NameController_normalizeProviderResult(result, responseError, matchingSourceIds) {
|
|
220
|
-
const error = responseError !== null && responseError !== void 0 ? responseError : undefined;
|
|
221
|
-
const results = matchingSourceIds.reduce((acc, sourceId) => {
|
|
222
|
-
var _a;
|
|
223
|
-
const sourceResult = (_a = result === null || result === void 0 ? void 0 : result.results) === null || _a === void 0 ? void 0 : _a[sourceId];
|
|
224
|
-
const normalizedSourceResult = __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_normalizeProviderSourceResult).call(this, sourceResult, responseError);
|
|
225
|
-
return Object.assign(Object.assign({}, acc), { [sourceId]: normalizedSourceResult });
|
|
226
|
-
}, {});
|
|
227
|
-
return { results, error };
|
|
228
|
-
}, _NameController_normalizeProviderSourceResult = function _NameController_normalizeProviderSourceResult(result, responseError) {
|
|
229
|
-
var _a, _b, _c, _d;
|
|
230
|
-
const error = (_b = (_a = result === null || result === void 0 ? void 0 : result.error) !== null && _a !== void 0 ? _a : responseError) !== null && _b !== void 0 ? _b : undefined;
|
|
231
|
-
const updateDelay = (_c = result === null || result === void 0 ? void 0 : result.updateDelay) !== null && _c !== void 0 ? _c : undefined;
|
|
232
|
-
let proposedNames = error ? undefined : (_d = result === null || result === void 0 ? void 0 : result.proposedNames) !== null && _d !== void 0 ? _d : undefined;
|
|
233
|
-
if (proposedNames) {
|
|
234
|
-
proposedNames = proposedNames.filter((proposedName) => proposedName === null || proposedName === void 0 ? void 0 : proposedName.length);
|
|
235
|
-
}
|
|
236
|
-
return {
|
|
237
|
-
proposedNames,
|
|
238
|
-
error,
|
|
239
|
-
updateDelay,
|
|
240
|
-
};
|
|
241
|
-
}, _NameController_normalizeValue = function _NameController_normalizeValue(value, type) {
|
|
242
|
-
/* istanbul ignore next */
|
|
243
|
-
switch (type) {
|
|
244
|
-
case types_1.NameType.ETHEREUM_ADDRESS:
|
|
245
|
-
return value.toLowerCase();
|
|
246
|
-
default:
|
|
247
|
-
return value;
|
|
248
|
-
}
|
|
249
|
-
}, _NameController_normalizeVariation = function _NameController_normalizeVariation(variation, type) {
|
|
250
|
-
/* istanbul ignore next */
|
|
251
|
-
switch (type) {
|
|
252
|
-
case types_1.NameType.ETHEREUM_ADDRESS:
|
|
253
|
-
return variation.toLowerCase();
|
|
254
|
-
default:
|
|
255
|
-
return variation;
|
|
256
|
-
}
|
|
257
|
-
}, _NameController_updateEntry = function _NameController_updateEntry(value, type, variation, callback) {
|
|
258
|
-
/* istanbul ignore next */
|
|
259
|
-
const variationKey = variation !== null && variation !== void 0 ? variation : DEFAULT_VARIATION;
|
|
260
|
-
const normalizedValue = __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_normalizeValue).call(this, value, type);
|
|
261
|
-
const normalizedVariation = __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_normalizeVariation).call(this, variationKey, type);
|
|
262
|
-
this.update((state) => {
|
|
263
|
-
var _a;
|
|
264
|
-
const typeEntries = state.names[type] || {};
|
|
265
|
-
state.names[type] = typeEntries;
|
|
266
|
-
const variationEntries = typeEntries[normalizedValue] || {};
|
|
267
|
-
typeEntries[normalizedValue] = variationEntries;
|
|
268
|
-
const entry = (_a = variationEntries[normalizedVariation]) !== null && _a !== void 0 ? _a : {
|
|
269
|
-
proposedNames: {},
|
|
270
|
-
name: null,
|
|
271
|
-
sourceId: null,
|
|
272
|
-
origin: null,
|
|
273
|
-
};
|
|
274
|
-
variationEntries[normalizedVariation] = entry;
|
|
275
|
-
callback(entry);
|
|
276
|
-
});
|
|
277
|
-
}, _NameController_getCurrentTimeSeconds = function _NameController_getCurrentTimeSeconds() {
|
|
278
|
-
return Math.round(Date.now() / 1000);
|
|
279
|
-
}, _NameController_validateSetNameRequest = function _NameController_validateSetNameRequest(request) {
|
|
280
|
-
const { name, value, type, sourceId, variation, origin } = request;
|
|
281
|
-
const errorMessages = [];
|
|
282
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_validateValue).call(this, value, errorMessages);
|
|
283
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_validateType).call(this, type, errorMessages);
|
|
284
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_validateName).call(this, name, errorMessages);
|
|
285
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_validateSourceId).call(this, sourceId, type, name, errorMessages);
|
|
286
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_validateVariation).call(this, variation, type, errorMessages);
|
|
287
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_validateOrigin).call(this, origin, name, errorMessages);
|
|
288
|
-
if (errorMessages.length) {
|
|
289
|
-
throw new Error(errorMessages.join(' '));
|
|
290
|
-
}
|
|
291
|
-
}, _NameController_validateUpdateProposedNamesRequest = function _NameController_validateUpdateProposedNamesRequest(request) {
|
|
292
|
-
const { value, type, sourceIds, variation } = request;
|
|
293
|
-
const errorMessages = [];
|
|
294
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_validateValue).call(this, value, errorMessages);
|
|
295
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_validateType).call(this, type, errorMessages);
|
|
296
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_validateSourceIds).call(this, sourceIds, type, errorMessages);
|
|
297
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_validateDuplicateSourceIds).call(this, type, errorMessages);
|
|
298
|
-
__classPrivateFieldGet(this, _NameController_instances, "m", _NameController_validateVariation).call(this, variation, type, errorMessages);
|
|
299
|
-
if (errorMessages.length) {
|
|
300
|
-
throw new Error(errorMessages.join(' '));
|
|
301
|
-
}
|
|
302
|
-
}, _NameController_validateValue = function _NameController_validateValue(value, errorMessages) {
|
|
303
|
-
if (!(value === null || value === void 0 ? void 0 : value.length) || typeof value !== 'string') {
|
|
304
|
-
errorMessages.push('Must specify a non-empty string for value.');
|
|
305
|
-
}
|
|
306
|
-
}, _NameController_validateType = function _NameController_validateType(type, errorMessages) {
|
|
307
|
-
if (!Object.values(types_1.NameType).includes(type)) {
|
|
308
|
-
errorMessages.push(`Must specify one of the following types: ${Object.values(types_1.NameType).join(', ')}`);
|
|
309
|
-
}
|
|
310
|
-
}, _NameController_validateName = function _NameController_validateName(name, errorMessages) {
|
|
311
|
-
if (name === null) {
|
|
312
|
-
return;
|
|
313
|
-
}
|
|
314
|
-
if (!(name === null || name === void 0 ? void 0 : name.length) || typeof name !== 'string') {
|
|
315
|
-
errorMessages.push('Must specify a non-empty string or null for name.');
|
|
316
|
-
}
|
|
317
|
-
}, _NameController_validateSourceIds = function _NameController_validateSourceIds(sourceIds, type, errorMessages) {
|
|
318
|
-
if (!sourceIds) {
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
const allSourceIds = __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_getAllSourceIds).call(this, type);
|
|
322
|
-
const missingSourceIds = [];
|
|
323
|
-
for (const sourceId of sourceIds) {
|
|
324
|
-
if (!allSourceIds.includes(sourceId)) {
|
|
325
|
-
missingSourceIds.push(sourceId);
|
|
326
|
-
continue;
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
if (missingSourceIds.length) {
|
|
330
|
-
errorMessages.push(`Unknown source IDs for type '${type}': ${missingSourceIds.join(', ')}`);
|
|
331
|
-
}
|
|
332
|
-
}, _NameController_validateSourceId = function _NameController_validateSourceId(sourceId, type, name, errorMessages) {
|
|
333
|
-
if (sourceId === null || sourceId === undefined) {
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
if (name === null) {
|
|
337
|
-
errorMessages.push(`Cannot specify a source ID when clearing the saved name: ${sourceId}`);
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
const allSourceIds = __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_getAllSourceIds).call(this, type);
|
|
341
|
-
if (!sourceId.length || typeof sourceId !== 'string') {
|
|
342
|
-
errorMessages.push('Must specify a non-empty string for sourceId.');
|
|
343
|
-
return;
|
|
344
|
-
}
|
|
345
|
-
if (!allSourceIds.includes(sourceId)) {
|
|
346
|
-
errorMessages.push(`Unknown source ID for type '${type}': ${sourceId}`);
|
|
347
|
-
}
|
|
348
|
-
}, _NameController_validateDuplicateSourceIds = function _NameController_validateDuplicateSourceIds(type, errorMessages) {
|
|
349
|
-
const allSourceIds = __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_getAllSourceIds).call(this, type);
|
|
350
|
-
const duplicateSourceIds = allSourceIds.filter((sourceId, index) => allSourceIds.indexOf(sourceId) !== index);
|
|
351
|
-
if (duplicateSourceIds.length) {
|
|
352
|
-
errorMessages.push(`Duplicate source IDs found for type '${type}': ${duplicateSourceIds.join(', ')}`);
|
|
353
|
-
}
|
|
354
|
-
}, _NameController_validateVariation = function _NameController_validateVariation(variation, type, errorMessages) {
|
|
355
|
-
if (type !== types_1.NameType.ETHEREUM_ADDRESS) {
|
|
356
|
-
return;
|
|
357
|
-
}
|
|
358
|
-
if (!(variation === null || variation === void 0 ? void 0 : variation.length) ||
|
|
359
|
-
typeof variation !== 'string' ||
|
|
360
|
-
(!variation.match(/^0x[0-9A-Fa-f]+$/u) &&
|
|
361
|
-
variation !== exports.FALLBACK_VARIATION)) {
|
|
362
|
-
errorMessages.push(`Must specify a chain ID in hexidecimal format or the fallback, "${exports.FALLBACK_VARIATION}", for variation when using '${type}' type.`);
|
|
363
|
-
}
|
|
364
|
-
}, _NameController_validateOrigin = function _NameController_validateOrigin(origin, name, errorMessages) {
|
|
365
|
-
if (!origin) {
|
|
366
|
-
return;
|
|
367
|
-
}
|
|
368
|
-
if (name === null) {
|
|
369
|
-
errorMessages.push(`Cannot specify an origin when clearing the saved name: ${origin}`);
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
if (!Object.values(NameOrigin).includes(origin)) {
|
|
373
|
-
errorMessages.push(`Must specify one of the following origins: ${Object.values(NameOrigin).join(', ')}`);
|
|
374
|
-
}
|
|
375
|
-
}, _NameController_getAllSourceIds = function _NameController_getAllSourceIds(type) {
|
|
376
|
-
return (__classPrivateFieldGet(this, _NameController_providers, "f")
|
|
377
|
-
/* istanbul ignore next */
|
|
378
|
-
.map((provider) => __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_getSourceIds).call(this, provider, type))
|
|
379
|
-
.flat());
|
|
380
|
-
}, _NameController_getSourceIds = function _NameController_getSourceIds(provider, type) {
|
|
381
|
-
return provider.getMetadata().sourceIds[type];
|
|
382
|
-
}, _NameController_removeDormantProposedNames = function _NameController_removeDormantProposedNames(proposedNames, type) {
|
|
383
|
-
if (Object.keys(proposedNames).length === 0) {
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
const typeSourceIds = __classPrivateFieldGet(this, _NameController_instances, "m", _NameController_getAllSourceIds).call(this, type);
|
|
387
|
-
const dormantSourceIds = Object.keys(proposedNames).filter((sourceId) => !typeSourceIds.includes(sourceId));
|
|
388
|
-
for (const dormantSourceId of dormantSourceIds) {
|
|
389
|
-
delete proposedNames[dormantSourceId];
|
|
390
|
-
}
|
|
391
|
-
};
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
var _chunkB2WJNTJSjs = require('./chunk-B2WJNTJS.js');
|
|
7
|
+
require('./chunk-PL7IXD33.js');
|
|
8
|
+
require('./chunk-Z4BLTVTB.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
exports.FALLBACK_VARIATION = _chunkB2WJNTJSjs.FALLBACK_VARIATION; exports.NameController = _chunkB2WJNTJSjs.NameController; exports.NameOrigin = _chunkB2WJNTJSjs.NameOrigin; exports.PROPOSED_NAME_EXPIRE_DURATION = _chunkB2WJNTJSjs.PROPOSED_NAME_EXPIRE_DURATION;
|
|
392
15
|
//# sourceMappingURL=NameController.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NameController.js","sourceRoot":"","sources":["../src/NameController.ts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,CACxD,CAAC,QAAQ,EAAE,EAAE,CAAC,CAAC,aAAa,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAChD,CAAC;IAEF,KAAK,MAAM,eAAe,IAAI,gBAAgB,EAAE;QAC9C,OAAO,aAAa,CAAC,eAAe,CAAC,CAAC;KACvC;AACH,CAAC","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\n\nimport type {\n NameProvider,\n NameProviderRequest,\n NameProviderResult,\n NameProviderSourceResult,\n} from './types';\nimport { NameType } from './types';\n\nexport const FALLBACK_VARIATION = '*';\n\n/**\n * Enumerates the possible origins responsible for setting a petname.\n */\nexport enum NameOrigin {\n // Originated from an account identity.\n ACCOUNT_IDENTITY = 'account-identity',\n // Originated from an address book entry.\n ADDRESS_BOOK = 'address-book',\n // Originated from the API (NameController.setName). This is the default.\n API = 'api',\n // Originated from the user taking action in the UI.\n UI = 'ui',\n}\n\nconst DEFAULT_UPDATE_DELAY = 60 * 2; // 2 Minutes\nconst DEFAULT_VARIATION = '';\n\nconst controllerName = 'NameController';\n\nconst stateMetadata = {\n names: { persist: true, anonymous: false },\n nameSources: { persist: true, anonymous: false },\n};\n\nconst getDefaultState = () => ({\n names: {\n [NameType.ETHEREUM_ADDRESS]: {},\n },\n nameSources: {},\n});\n\nexport type ProposedNamesEntry = {\n proposedNames: string[];\n lastRequestTime: number | null;\n updateDelay: number | null;\n};\n\nexport type NameEntry = {\n name: string | null;\n sourceId: string | null;\n origin: NameOrigin | null;\n proposedNames: Record<string, ProposedNamesEntry>;\n};\n\nexport type SourceEntry = {\n label: string;\n};\n\nexport type NameControllerState = {\n // Type > Value > Variation > Entry\n names: Record<NameType, Record<string, Record<string, NameEntry>>>;\n nameSources: Record<string, SourceEntry>;\n};\n\nexport type GetNameState = ControllerGetStateAction<\n typeof controllerName,\n NameControllerState\n>;\n\nexport type NameStateChange = ControllerStateChangeEvent<\n typeof controllerName,\n NameControllerState\n>;\n\nexport type NameControllerActions = GetNameState;\n\nexport type NameControllerEvents = NameStateChange;\n\nexport type NameControllerMessenger = RestrictedControllerMessenger<\n typeof controllerName,\n NameControllerActions,\n NameControllerEvents,\n never,\n never\n>;\n\nexport type NameControllerOptions = {\n messenger: NameControllerMessenger;\n providers: NameProvider[];\n state?: Partial<NameControllerState>;\n updateDelay?: number;\n};\n\nexport type UpdateProposedNamesRequest = {\n value: string;\n type: NameType;\n sourceIds?: string[];\n onlyUpdateAfterDelay?: boolean;\n variation?: string;\n};\n\nexport type UpdateProposedNamesResult = {\n results: Record<string, { proposedNames?: string[]; error?: unknown }>;\n};\n\nexport type SetNameRequest = {\n value: string;\n type: NameType;\n name: string | null;\n sourceId?: string;\n variation?: string;\n origin?: NameOrigin;\n};\n\n/**\n * Controller for storing and deriving names for values such as Ethereum addresses.\n */\nexport class NameController extends BaseController<\n typeof controllerName,\n NameControllerState,\n NameControllerMessenger\n> {\n #providers: NameProvider[];\n\n #updateDelay: number;\n\n /**\n * Construct a Name controller.\n *\n * @param options - Controller options.\n * @param options.messenger - Restricted controller messenger for the name controller.\n * @param options.providers - Array of name provider instances to propose names.\n * @param options.state - Initial state to set on the controller.\n * @param options.updateDelay - The delay in seconds before a new request to a source should be made.\n */\n constructor({\n messenger,\n providers,\n state,\n updateDelay,\n }: NameControllerOptions) {\n super({\n name: controllerName,\n metadata: stateMetadata,\n messenger,\n state: { ...getDefaultState(), ...state },\n });\n\n this.#providers = providers;\n this.#updateDelay = updateDelay ?? DEFAULT_UPDATE_DELAY;\n }\n\n /**\n * Set the user specified name for a value.\n *\n * @param request - Request object.\n * @param request.name - Name to set.\n * @param request.sourceId - Optional ID of the source of the proposed name.\n * @param request.type - Type of value to set the name for.\n * @param request.value - Value to set the name for.\n * @param request.variation - Variation of the raw value to set the name for. The chain ID if the type is Ethereum address.\n */\n setName(request: SetNameRequest) {\n this.#validateSetNameRequest(request);\n\n const {\n value,\n type,\n name,\n sourceId: requestSourceId,\n origin: requestOrigin,\n variation,\n } = request;\n const sourceId = requestSourceId ?? null;\n // If the name is being cleared, the fallback origin should be cleared as well.\n const fallbackOrigin = name === null ? null : NameOrigin.API;\n const origin = requestOrigin ?? fallbackOrigin;\n\n this.#updateEntry(value, type, variation, (entry: NameEntry) => {\n entry.name = name;\n entry.sourceId = sourceId;\n entry.origin = origin;\n });\n }\n\n /**\n * Generate the proposed names for a value using the name providers and store them in the state.\n *\n * @param request - Request object.\n * @param request.value - Value to update the proposed names for.\n * @param request.type - Type of value to update the proposed names for.\n * @param request.sourceIds - Optional array of source IDs to limit which sources are used by the providers. If not provided, all sources in all providers will be used.\n * @param request.variation - Variation of the raw value to update proposed names for. The chain ID if the type is Ethereum address.\n * @returns The updated proposed names for the value.\n */\n async updateProposedNames(\n request: UpdateProposedNamesRequest,\n ): Promise<UpdateProposedNamesResult> {\n this.#validateUpdateProposedNamesRequest(request);\n\n const providerResponses = (\n await Promise.all(\n this.#providers.map((provider) =>\n this.#getProviderResponse(request, provider),\n ),\n )\n ).filter((response) => Boolean(response)) as NameProviderResult[];\n\n this.#updateProposedNameState(request, providerResponses);\n this.#updateSourceState(this.#providers);\n\n return this.#getUpdateProposedNamesResult(providerResponses);\n }\n\n #updateProposedNameState(\n request: UpdateProposedNamesRequest,\n providerResponses: NameProviderResult[],\n ) {\n const { value, type, variation } = request;\n const currentTime = this.#getCurrentTimeSeconds();\n\n this.#updateEntry(value, type, variation, (entry: NameEntry) => {\n this.#removeDormantProposedNames(entry.proposedNames, type);\n\n for (const providerResponse of providerResponses) {\n const { results } = providerResponse;\n\n for (const sourceId of Object.keys(providerResponse.results)) {\n const result = results[sourceId];\n const { proposedNames, updateDelay } = result;\n\n const proposedNameEntry = entry.proposedNames[sourceId] ?? {\n proposedNames: [],\n lastRequestTime: null,\n updateDelay: null,\n };\n\n entry.proposedNames[sourceId] = proposedNameEntry;\n\n if (proposedNames) {\n proposedNameEntry.proposedNames = proposedNames;\n }\n\n proposedNameEntry.lastRequestTime = currentTime;\n proposedNameEntry.updateDelay = updateDelay ?? null;\n }\n }\n });\n }\n\n #updateSourceState(providers: NameProvider[]) {\n const newNameSources = { ...this.state.nameSources };\n\n for (const provider of providers) {\n const { sourceLabels } = provider.getMetadata();\n\n for (const sourceId of Object.keys(sourceLabels)) {\n newNameSources[sourceId] = {\n label: sourceLabels[sourceId],\n };\n }\n }\n\n this.update((state) => {\n state.nameSources = newNameSources;\n });\n }\n\n #getUpdateProposedNamesResult(\n providerResponses: NameProviderResult[],\n ): UpdateProposedNamesResult {\n return providerResponses.reduce(\n (acc: UpdateProposedNamesResult, providerResponse) => {\n const { results } = providerResponse;\n\n for (const sourceId of Object.keys(results)) {\n const { proposedNames, error } = results[sourceId];\n\n acc.results[sourceId] = {\n proposedNames,\n error,\n };\n }\n\n return acc;\n },\n { results: {} },\n );\n }\n\n async #getProviderResponse(\n request: UpdateProposedNamesRequest,\n provider: NameProvider,\n ): Promise<NameProviderResult | undefined> {\n const {\n value,\n type,\n sourceIds: requestedSourceIds,\n onlyUpdateAfterDelay,\n variation,\n } = request;\n\n /* istanbul ignore next */\n const variationKey = variation ?? DEFAULT_VARIATION;\n const supportedSourceIds = this.#getSourceIds(provider, type);\n const currentTime = this.#getCurrentTimeSeconds();\n const normalizedValue = this.#normalizeValue(value, type);\n\n const matchingSourceIds = supportedSourceIds.filter((sourceId) => {\n if (requestedSourceIds && !requestedSourceIds.includes(sourceId)) {\n return false;\n }\n\n if (onlyUpdateAfterDelay) {\n const entry =\n this.state.names[type]?.[normalizedValue]?.[variationKey] ?? {};\n const proposedNamesEntry = entry.proposedNames?.[sourceId] ?? {};\n const lastRequestTime = proposedNamesEntry.lastRequestTime ?? 0;\n const updateDelay = proposedNamesEntry.updateDelay ?? this.#updateDelay;\n\n if (currentTime - lastRequestTime < updateDelay) {\n return false;\n }\n }\n\n return true;\n });\n\n if (!matchingSourceIds.length) {\n return undefined;\n }\n\n const providerRequest: NameProviderRequest = {\n value: this.#normalizeValue(value, type),\n type,\n sourceIds: requestedSourceIds ? matchingSourceIds : undefined,\n variation: this.#normalizeVariation(variationKey, type),\n };\n\n let responseError: unknown | undefined;\n let response: NameProviderResult | undefined;\n\n try {\n response = await provider.getProposedNames(providerRequest);\n responseError = response.error;\n } catch (error) {\n responseError = error;\n }\n\n return this.#normalizeProviderResult(\n response,\n responseError,\n matchingSourceIds,\n );\n }\n\n #normalizeProviderResult(\n result: NameProviderResult | undefined,\n responseError: unknown,\n matchingSourceIds: string[],\n ): NameProviderResult {\n const error = responseError ?? undefined;\n\n const results = matchingSourceIds.reduce((acc, sourceId) => {\n const sourceResult = result?.results?.[sourceId];\n\n const normalizedSourceResult = this.#normalizeProviderSourceResult(\n sourceResult,\n responseError,\n );\n\n return {\n ...acc,\n [sourceId]: normalizedSourceResult,\n };\n }, {});\n\n return { results, error };\n }\n\n #normalizeProviderSourceResult(\n result: NameProviderSourceResult | undefined,\n responseError: unknown,\n ): NameProviderSourceResult | undefined {\n const error = result?.error ?? responseError ?? undefined;\n const updateDelay = result?.updateDelay ?? undefined;\n let proposedNames = error ? undefined : result?.proposedNames ?? undefined;\n\n if (proposedNames) {\n proposedNames = proposedNames.filter(\n (proposedName) => proposedName?.length,\n );\n }\n\n return {\n proposedNames,\n error,\n updateDelay,\n };\n }\n\n #normalizeValue(value: string, type: NameType): string {\n /* istanbul ignore next */\n switch (type) {\n case NameType.ETHEREUM_ADDRESS:\n return value.toLowerCase();\n\n default:\n return value;\n }\n }\n\n #normalizeVariation(variation: string, type: NameType): string {\n /* istanbul ignore next */\n switch (type) {\n case NameType.ETHEREUM_ADDRESS:\n return variation.toLowerCase();\n\n default:\n return variation;\n }\n }\n\n #updateEntry(\n value: string,\n type: NameType,\n variation: string | undefined,\n callback: (entry: NameEntry) => void,\n ) {\n /* istanbul ignore next */\n const variationKey = variation ?? DEFAULT_VARIATION;\n const normalizedValue = this.#normalizeValue(value, type);\n const normalizedVariation = this.#normalizeVariation(variationKey, type);\n\n this.update((state) => {\n const typeEntries = state.names[type] || {};\n state.names[type] = typeEntries;\n\n const variationEntries = typeEntries[normalizedValue] || {};\n typeEntries[normalizedValue] = variationEntries;\n\n const entry = variationEntries[normalizedVariation] ?? {\n proposedNames: {},\n name: null,\n sourceId: null,\n origin: null,\n };\n variationEntries[normalizedVariation] = entry;\n\n callback(entry);\n });\n }\n\n #getCurrentTimeSeconds(): number {\n return Math.round(Date.now() / 1000);\n }\n\n #validateSetNameRequest(request: SetNameRequest) {\n const { name, value, type, sourceId, variation, origin } = request;\n const errorMessages: string[] = [];\n\n this.#validateValue(value, errorMessages);\n this.#validateType(type, errorMessages);\n this.#validateName(name, errorMessages);\n this.#validateSourceId(sourceId, type, name, errorMessages);\n this.#validateVariation(variation, type, errorMessages);\n this.#validateOrigin(origin, name, errorMessages);\n\n if (errorMessages.length) {\n throw new Error(errorMessages.join(' '));\n }\n }\n\n #validateUpdateProposedNamesRequest(request: UpdateProposedNamesRequest) {\n const { value, type, sourceIds, variation } = request;\n const errorMessages: string[] = [];\n\n this.#validateValue(value, errorMessages);\n this.#validateType(type, errorMessages);\n this.#validateSourceIds(sourceIds, type, errorMessages);\n this.#validateDuplicateSourceIds(type, errorMessages);\n this.#validateVariation(variation, type, errorMessages);\n\n if (errorMessages.length) {\n throw new Error(errorMessages.join(' '));\n }\n }\n\n #validateValue(value: string, errorMessages: string[]) {\n if (!value?.length || typeof value !== 'string') {\n errorMessages.push('Must specify a non-empty string for value.');\n }\n }\n\n #validateType(type: NameType, errorMessages: string[]) {\n if (!Object.values(NameType).includes(type)) {\n errorMessages.push(\n `Must specify one of the following types: ${Object.values(\n NameType,\n ).join(', ')}`,\n );\n }\n }\n\n #validateName(name: string | null, errorMessages: string[]) {\n if (name === null) {\n return;\n }\n\n if (!name?.length || typeof name !== 'string') {\n errorMessages.push('Must specify a non-empty string or null for name.');\n }\n }\n\n #validateSourceIds(\n sourceIds: string[] | undefined,\n type: NameType,\n errorMessages: string[],\n ) {\n if (!sourceIds) {\n return;\n }\n\n const allSourceIds = this.#getAllSourceIds(type);\n const missingSourceIds = [];\n\n for (const sourceId of sourceIds) {\n if (!allSourceIds.includes(sourceId)) {\n missingSourceIds.push(sourceId);\n continue;\n }\n }\n\n if (missingSourceIds.length) {\n errorMessages.push(\n `Unknown source IDs for type '${type}': ${missingSourceIds.join(', ')}`,\n );\n }\n }\n\n #validateSourceId(\n sourceId: string | undefined,\n type: NameType,\n name: string | null,\n errorMessages: string[],\n ) {\n if (sourceId === null || sourceId === undefined) {\n return;\n }\n\n if (name === null) {\n errorMessages.push(\n `Cannot specify a source ID when clearing the saved name: ${sourceId}`,\n );\n return;\n }\n\n const allSourceIds = this.#getAllSourceIds(type);\n\n if (!sourceId.length || typeof sourceId !== 'string') {\n errorMessages.push('Must specify a non-empty string for sourceId.');\n return;\n }\n\n if (!allSourceIds.includes(sourceId)) {\n errorMessages.push(`Unknown source ID for type '${type}': ${sourceId}`);\n }\n }\n\n #validateDuplicateSourceIds(type: NameType, errorMessages: string[]) {\n const allSourceIds = this.#getAllSourceIds(type);\n\n const duplicateSourceIds = allSourceIds.filter(\n (sourceId, index) => allSourceIds.indexOf(sourceId) !== index,\n );\n\n if (duplicateSourceIds.length) {\n errorMessages.push(\n `Duplicate source IDs found for type '${type}': ${duplicateSourceIds.join(\n ', ',\n )}`,\n );\n }\n }\n\n #validateVariation(\n variation: string | undefined,\n type: string,\n errorMessages: string[],\n ) {\n if (type !== NameType.ETHEREUM_ADDRESS) {\n return;\n }\n\n if (\n !variation?.length ||\n typeof variation !== 'string' ||\n (!variation.match(/^0x[0-9A-Fa-f]+$/u) &&\n variation !== FALLBACK_VARIATION)\n ) {\n errorMessages.push(\n `Must specify a chain ID in hexidecimal format or the fallback, \"${FALLBACK_VARIATION}\", for variation when using '${type}' type.`,\n );\n }\n }\n\n #validateOrigin(\n origin: NameOrigin | null | undefined,\n name: string | null,\n errorMessages: string[],\n ) {\n if (!origin) {\n return;\n }\n\n if (name === null) {\n errorMessages.push(\n `Cannot specify an origin when clearing the saved name: ${origin}`,\n );\n return;\n }\n\n if (!Object.values(NameOrigin).includes(origin)) {\n errorMessages.push(\n `Must specify one of the following origins: ${Object.values(\n NameOrigin,\n ).join(', ')}`,\n );\n }\n }\n\n #getAllSourceIds(type: NameType): string[] {\n return (\n this.#providers\n /* istanbul ignore next */\n .map((provider) => this.#getSourceIds(provider, type))\n .flat()\n );\n }\n\n #getSourceIds(provider: NameProvider, type: NameType): string[] {\n return provider.getMetadata().sourceIds[type];\n }\n\n #removeDormantProposedNames(\n proposedNames: Record<string, ProposedNamesEntry>,\n type: NameType,\n ) {\n if (Object.keys(proposedNames).length === 0) {\n return;\n }\n\n const typeSourceIds = this.#getAllSourceIds(type);\n\n const dormantSourceIds = Object.keys(proposedNames).filter(\n (sourceId) => !typeSourceIds.includes(sourceId),\n );\n\n for (const dormantSourceId of dormantSourceIds) {\n delete proposedNames[dormantSourceId];\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"sources":[],"names":[],"mappings":""}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {
|
|
2
|
+
FALLBACK_VARIATION,
|
|
3
|
+
NameController,
|
|
4
|
+
NameOrigin,
|
|
5
|
+
PROPOSED_NAME_EXPIRE_DURATION
|
|
6
|
+
} from "./chunk-GJYKWMRC.mjs";
|
|
7
|
+
import "./chunk-6W3DEAGA.mjs";
|
|
8
|
+
import "./chunk-XUI43LEZ.mjs";
|
|
9
|
+
export {
|
|
10
|
+
FALLBACK_VARIATION,
|
|
11
|
+
NameController,
|
|
12
|
+
NameOrigin,
|
|
13
|
+
PROPOSED_NAME_EXPIRE_DURATION
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=NameController.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":[],"sourcesContent":[],"mappings":"","names":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/types.ts"],"sourcesContent":["/** The name types supported by the NameController. */\nexport enum NameType {\n /** The address of an Ethereum account. */\n ETHEREUM_ADDRESS = 'ethereumAddress',\n}\n\n/** The metadata for a name provider. */\nexport type NameProviderMetadata = {\n /**\n * IDs for each alternate source of proposed names.\n * Keyed by the name type.\n */\n sourceIds: Record<NameType, string[]>;\n\n /**\n * Friendly labels to describe each source of proposed names.\n * Keyed by the source ID.\n */\n sourceLabels: Record<string, string>;\n};\n\n/** The request data to get proposed names from a name provider. */\nexport type NameProviderRequest = {\n /** The optional list of source IDs to get proposed names from. */\n sourceIds?: string[];\n\n /** The type of name being requested. */\n type: NameType;\n\n /** The raw value to get proposed names for. */\n value: string;\n\n /**\n * The variation of the raw value to get proposed names for.\n * For example, the chain ID if the raw value is an Ethereum address.\n */\n variation: string;\n};\n\n/** The resulting data after requesting proposed names from a name provider, for a single source. */\nexport type NameProviderSourceResult = {\n /**\n * The array of proposed names from the source.\n * Undefined if there is an error.\n */\n proposedNames?: string[];\n\n /**\n * The delay in seconds before the next request to the source should be made.\n * Can be used to avoid rate limiting for example.\n */\n updateDelay?: number;\n\n /**\n * An error that occurred while fetching the proposed names from the source.\n * Undefined if there was no error.\n */\n error?: unknown;\n};\n\n/** The resulting data after requesting proposed names from a name provider. */\nexport type NameProviderResult = {\n /**\n * The resulting data from each alternate source of proposed names supported by the name provider.\n * Keyed by the source ID.\n */\n results: Record<string, NameProviderSourceResult>;\n\n /**\n * An error that occurred while fetching the proposed names that was not specific to a single source.\n * Undefined if there was no error.\n */\n error?: unknown;\n};\n\n/** An object capable of proposing friendly names for a raw value of a given type. */\nexport type NameProvider = {\n /**\n * Returns metadata about the name provider.\n */\n getMetadata(): NameProviderMetadata;\n\n /**\n * Returns proposed names for the given value and request data.\n *\n * @param request - The request data including the value to propose names for.\n */\n getProposedNames(request: NameProviderRequest): Promise<NameProviderResult>;\n};\n"],"mappings":";AACO,IAAK,WAAL,kBAAKA,cAAL;AAEL,EAAAA,UAAA,sBAAmB;AAFT,SAAAA;AAAA,GAAA;","names":["NameType"]}
|