@metamask/name-controller 8.0.0 → 8.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 +26 -1
- package/dist/NameController.cjs +410 -0
- package/dist/NameController.cjs.map +1 -0
- package/dist/{types/NameController.d.ts → NameController.d.cts} +5 -5
- package/dist/NameController.d.cts.map +1 -0
- package/dist/NameController.d.mts +106 -0
- package/dist/NameController.d.mts.map +1 -0
- package/dist/NameController.mjs +404 -13
- package/dist/NameController.mjs.map +1 -1
- package/dist/constants.cjs +111 -0
- package/dist/constants.cjs.map +1 -0
- package/dist/{types/constants.d.ts → constants.d.cts} +1 -1
- package/dist/constants.d.cts.map +1 -0
- package/dist/constants.d.mts +105 -0
- package/dist/constants.d.mts.map +1 -0
- package/dist/constants.mjs +106 -8
- package/dist/constants.mjs.map +1 -1
- package/dist/index.cjs +23 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +7 -0
- package/dist/index.d.cts.map +1 -0
- package/dist/index.d.mts +7 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +6 -36
- package/dist/index.mjs.map +1 -1
- package/dist/logger.cjs +7 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/{types/logger.d.ts → logger.d.cts} +2 -2
- package/dist/logger.d.cts.map +1 -0
- package/dist/logger.d.mts +5 -0
- package/dist/logger.d.mts.map +1 -0
- package/dist/logger.mjs +3 -9
- package/dist/logger.mjs.map +1 -1
- package/dist/providers/ens.cjs +65 -0
- package/dist/providers/ens.cjs.map +1 -0
- package/dist/{types/providers/ens.d.ts → providers/ens.d.cts} +2 -2
- package/dist/providers/ens.d.cts.map +1 -0
- package/dist/providers/ens.d.mts +12 -0
- package/dist/providers/ens.d.mts.map +1 -0
- package/dist/providers/ens.mjs +59 -8
- package/dist/providers/ens.mjs.map +1 -1
- package/dist/providers/etherscan.cjs +130 -0
- package/dist/providers/etherscan.cjs.map +1 -0
- package/dist/{types/providers/etherscan.d.ts → providers/etherscan.d.cts} +2 -2
- package/dist/providers/etherscan.d.cts.map +1 -0
- package/dist/providers/etherscan.d.mts +10 -0
- package/dist/providers/etherscan.d.mts.map +1 -0
- package/dist/providers/etherscan.mjs +124 -10
- package/dist/providers/etherscan.mjs.map +1 -1
- package/dist/providers/lens.cjs +77 -0
- package/dist/providers/lens.cjs.map +1 -0
- package/dist/{types/providers/lens.d.ts → providers/lens.d.cts} +2 -2
- package/dist/providers/lens.d.cts.map +1 -0
- package/dist/providers/lens.d.mts +10 -0
- package/dist/providers/lens.d.mts.map +1 -0
- package/dist/providers/lens.mjs +71 -9
- package/dist/providers/lens.mjs.map +1 -1
- package/dist/providers/token.cjs +68 -0
- package/dist/providers/token.cjs.map +1 -0
- package/dist/{types/providers/token.d.ts → providers/token.d.cts} +2 -2
- package/dist/providers/token.d.cts.map +1 -0
- package/dist/providers/token.d.mts +10 -0
- package/dist/providers/token.d.mts.map +1 -0
- package/dist/providers/token.mjs +62 -9
- package/dist/providers/token.mjs.map +1 -1
- package/dist/types.cjs +12 -0
- package/dist/types.cjs.map +1 -0
- package/dist/{types/types.d.ts → types.d.cts} +1 -1
- package/dist/types.d.cts.map +1 -0
- package/dist/types.d.mts +77 -0
- package/dist/types.d.mts.map +1 -0
- package/dist/types.mjs +8 -7
- package/dist/types.mjs.map +1 -1
- package/dist/util.cjs +76 -0
- package/dist/util.cjs.map +1 -0
- package/dist/{types/util.d.ts → util.d.cts} +1 -1
- package/dist/util.d.cts.map +1 -0
- package/dist/util.d.mts +35 -0
- package/dist/util.d.mts.map +1 -0
- package/dist/util.mjs +68 -13
- package/dist/util.mjs.map +1 -1
- package/package.json +21 -15
- package/dist/NameController.js +0 -15
- package/dist/NameController.js.map +0 -1
- package/dist/chunk-6AVJOVIX.mjs +0 -519
- package/dist/chunk-6AVJOVIX.mjs.map +0 -1
- package/dist/chunk-6W3DEAGA.mjs +0 -10
- package/dist/chunk-6W3DEAGA.mjs.map +0 -1
- package/dist/chunk-BLG7EQAA.mjs +0 -66
- package/dist/chunk-BLG7EQAA.mjs.map +0 -1
- package/dist/chunk-DSVOMJX6.mjs +0 -43
- package/dist/chunk-DSVOMJX6.mjs.map +0 -1
- package/dist/chunk-JHYBLEC5.js +0 -43
- package/dist/chunk-JHYBLEC5.js.map +0 -1
- package/dist/chunk-L244TFFU.mjs +0 -9
- package/dist/chunk-L244TFFU.mjs.map +0 -1
- package/dist/chunk-PL2KMW2Y.js +0 -519
- package/dist/chunk-PL2KMW2Y.js.map +0 -1
- package/dist/chunk-PL7IXD33.js +0 -10
- package/dist/chunk-PL7IXD33.js.map +0 -1
- package/dist/chunk-QBR7BSWB.js +0 -9
- package/dist/chunk-QBR7BSWB.js.map +0 -1
- package/dist/chunk-RYIUDJOI.js +0 -66
- package/dist/chunk-RYIUDJOI.js.map +0 -1
- package/dist/chunk-SHTSUEYM.mjs +0 -113
- package/dist/chunk-SHTSUEYM.mjs.map +0 -1
- package/dist/chunk-ST2ADXPO.js +0 -67
- package/dist/chunk-ST2ADXPO.js.map +0 -1
- package/dist/chunk-UALYD4SG.mjs +0 -138
- package/dist/chunk-UALYD4SG.mjs.map +0 -1
- package/dist/chunk-W64QIPGB.js +0 -80
- package/dist/chunk-W64QIPGB.js.map +0 -1
- package/dist/chunk-WHDNAWDA.mjs +0 -67
- package/dist/chunk-WHDNAWDA.mjs.map +0 -1
- package/dist/chunk-WSOVXHAC.mjs +0 -80
- package/dist/chunk-WSOVXHAC.mjs.map +0 -1
- package/dist/chunk-X55IV67M.js +0 -138
- package/dist/chunk-X55IV67M.js.map +0 -1
- package/dist/chunk-XQXO5QPM.js +0 -113
- package/dist/chunk-XQXO5QPM.js.map +0 -1
- package/dist/chunk-XUI43LEZ.mjs +0 -30
- package/dist/chunk-XUI43LEZ.mjs.map +0 -1
- package/dist/chunk-Z4BLTVTB.js +0 -30
- package/dist/chunk-Z4BLTVTB.js.map +0 -1
- package/dist/constants.js +0 -10
- package/dist/constants.js.map +0 -1
- package/dist/index.js +0 -37
- package/dist/index.js.map +0 -1
- package/dist/logger.js +0 -10
- package/dist/logger.js.map +0 -1
- package/dist/providers/ens.js +0 -10
- package/dist/providers/ens.js.map +0 -1
- package/dist/providers/etherscan.js +0 -12
- package/dist/providers/etherscan.js.map +0 -1
- package/dist/providers/lens.js +0 -11
- package/dist/providers/lens.js.map +0 -1
- package/dist/providers/token.js +0 -11
- package/dist/providers/token.js.map +0 -1
- package/dist/tsconfig.build.tsbuildinfo +0 -1
- package/dist/types/NameController.d.ts.map +0 -1
- package/dist/types/constants.d.ts.map +0 -1
- package/dist/types/index.d.ts +0 -7
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/logger.d.ts.map +0 -1
- package/dist/types/providers/ens.d.ts.map +0 -1
- package/dist/types/providers/etherscan.d.ts.map +0 -1
- package/dist/types/providers/lens.d.ts.map +0 -1
- package/dist/types/providers/token.d.ts.map +0 -1
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/util.d.ts.map +0 -1
- package/dist/types.js +0 -8
- package/dist/types.js.map +0 -1
- package/dist/util.js +0 -14
- package/dist/util.js.map +0 -1
package/dist/chunk-PL2KMW2Y.js
DELETED
|
@@ -1,519 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
var _chunkPL7IXD33js = require('./chunk-PL7IXD33.js');
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
var _chunkZ4BLTVTBjs = require('./chunk-Z4BLTVTB.js');
|
|
10
|
-
|
|
11
|
-
// src/NameController.ts
|
|
12
|
-
var _basecontroller = require('@metamask/base-controller');
|
|
13
|
-
var _controllerutils = require('@metamask/controller-utils');
|
|
14
|
-
var FALLBACK_VARIATION = "*";
|
|
15
|
-
var PROPOSED_NAME_EXPIRE_DURATION = 60 * 60 * 24;
|
|
16
|
-
var NameOrigin = /* @__PURE__ */ ((NameOrigin2) => {
|
|
17
|
-
NameOrigin2["ACCOUNT_IDENTITY"] = "account-identity";
|
|
18
|
-
NameOrigin2["ADDRESS_BOOK"] = "address-book";
|
|
19
|
-
NameOrigin2["API"] = "api";
|
|
20
|
-
NameOrigin2["UI"] = "ui";
|
|
21
|
-
return NameOrigin2;
|
|
22
|
-
})(NameOrigin || {});
|
|
23
|
-
var DEFAULT_UPDATE_DELAY = 60 * 2;
|
|
24
|
-
var DEFAULT_VARIATION = "";
|
|
25
|
-
var controllerName = "NameController";
|
|
26
|
-
var stateMetadata = {
|
|
27
|
-
names: { persist: true, anonymous: false },
|
|
28
|
-
nameSources: { persist: true, anonymous: false }
|
|
29
|
-
};
|
|
30
|
-
var getDefaultState = () => ({
|
|
31
|
-
names: {
|
|
32
|
-
["ethereumAddress" /* ETHEREUM_ADDRESS */]: {}
|
|
33
|
-
},
|
|
34
|
-
nameSources: {}
|
|
35
|
-
});
|
|
36
|
-
var _providers, _updateDelay, _updateProposedNameState, updateProposedNameState_fn, _updateSourceState, updateSourceState_fn, _getUpdateProposedNamesResult, getUpdateProposedNamesResult_fn, _getProviderResponse, getProviderResponse_fn, _normalizeProviderResult, normalizeProviderResult_fn, _normalizeProviderSourceResult, normalizeProviderSourceResult_fn, _normalizeValue, normalizeValue_fn, _normalizeVariation, normalizeVariation_fn, _updateEntry, updateEntry_fn, _getCurrentTimeSeconds, getCurrentTimeSeconds_fn, _validateSetNameRequest, validateSetNameRequest_fn, _validateUpdateProposedNamesRequest, validateUpdateProposedNamesRequest_fn, _validateValue, validateValue_fn, _validateType, validateType_fn, _validateName, validateName_fn, _validateSourceIds, validateSourceIds_fn, _validateSourceId, validateSourceId_fn, _validateDuplicateSourceIds, validateDuplicateSourceIds_fn, _validateVariation, validateVariation_fn, _validateOrigin, validateOrigin_fn, _getAllSourceIds, getAllSourceIds_fn, _getSourceIds, getSourceIds_fn, _removeDormantProposedNames, removeDormantProposedNames_fn, _removeExpiredEntries, removeExpiredEntries_fn, _getEntriesList, getEntriesList_fn;
|
|
37
|
-
var NameController = class extends _basecontroller.BaseController {
|
|
38
|
-
/**
|
|
39
|
-
* Construct a Name controller.
|
|
40
|
-
*
|
|
41
|
-
* @param options - Controller options.
|
|
42
|
-
* @param options.messenger - Restricted controller messenger for the name controller.
|
|
43
|
-
* @param options.providers - Array of name provider instances to propose names.
|
|
44
|
-
* @param options.state - Initial state to set on the controller.
|
|
45
|
-
* @param options.updateDelay - The delay in seconds before a new request to a source should be made.
|
|
46
|
-
*/
|
|
47
|
-
constructor({
|
|
48
|
-
messenger,
|
|
49
|
-
providers,
|
|
50
|
-
state,
|
|
51
|
-
updateDelay
|
|
52
|
-
}) {
|
|
53
|
-
super({
|
|
54
|
-
name: controllerName,
|
|
55
|
-
metadata: stateMetadata,
|
|
56
|
-
messenger,
|
|
57
|
-
state: { ...getDefaultState(), ...state }
|
|
58
|
-
});
|
|
59
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _updateProposedNameState);
|
|
60
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _updateSourceState);
|
|
61
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getUpdateProposedNamesResult);
|
|
62
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getProviderResponse);
|
|
63
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _normalizeProviderResult);
|
|
64
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _normalizeProviderSourceResult);
|
|
65
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _normalizeValue);
|
|
66
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _normalizeVariation);
|
|
67
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _updateEntry);
|
|
68
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getCurrentTimeSeconds);
|
|
69
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _validateSetNameRequest);
|
|
70
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _validateUpdateProposedNamesRequest);
|
|
71
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _validateValue);
|
|
72
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _validateType);
|
|
73
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _validateName);
|
|
74
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _validateSourceIds);
|
|
75
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _validateSourceId);
|
|
76
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _validateDuplicateSourceIds);
|
|
77
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _validateVariation);
|
|
78
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _validateOrigin);
|
|
79
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getAllSourceIds);
|
|
80
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getSourceIds);
|
|
81
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _removeDormantProposedNames);
|
|
82
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _removeExpiredEntries);
|
|
83
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _getEntriesList);
|
|
84
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _providers, void 0);
|
|
85
|
-
_chunkZ4BLTVTBjs.__privateAdd.call(void 0, this, _updateDelay, void 0);
|
|
86
|
-
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _providers, providers);
|
|
87
|
-
_chunkZ4BLTVTBjs.__privateSet.call(void 0, this, _updateDelay, updateDelay ?? DEFAULT_UPDATE_DELAY);
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Set the user specified name for a value.
|
|
91
|
-
*
|
|
92
|
-
* @param request - Request object.
|
|
93
|
-
* @param request.name - Name to set.
|
|
94
|
-
* @param request.sourceId - Optional ID of the source of the proposed name.
|
|
95
|
-
* @param request.type - Type of value to set the name for.
|
|
96
|
-
* @param request.value - Value to set the name for.
|
|
97
|
-
* @param request.variation - Variation of the raw value to set the name for. The chain ID if the type is Ethereum address.
|
|
98
|
-
*/
|
|
99
|
-
setName(request) {
|
|
100
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _validateSetNameRequest, validateSetNameRequest_fn).call(this, request);
|
|
101
|
-
const {
|
|
102
|
-
value,
|
|
103
|
-
type,
|
|
104
|
-
name,
|
|
105
|
-
sourceId: requestSourceId,
|
|
106
|
-
origin: requestOrigin,
|
|
107
|
-
variation
|
|
108
|
-
} = request;
|
|
109
|
-
const sourceId = requestSourceId ?? null;
|
|
110
|
-
const fallbackOrigin = name === null ? null : "api" /* API */;
|
|
111
|
-
const origin = requestOrigin ?? fallbackOrigin;
|
|
112
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateEntry, updateEntry_fn).call(this, value, type, variation, (entry) => {
|
|
113
|
-
entry.name = name;
|
|
114
|
-
entry.sourceId = sourceId;
|
|
115
|
-
entry.origin = origin;
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Generate the proposed names for a value using the name providers and store them in the state.
|
|
120
|
-
*
|
|
121
|
-
* @param request - Request object.
|
|
122
|
-
* @param request.value - Value to update the proposed names for.
|
|
123
|
-
* @param request.type - Type of value to update the proposed names for.
|
|
124
|
-
* @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.
|
|
125
|
-
* @param request.variation - Variation of the raw value to update proposed names for. The chain ID if the type is Ethereum address.
|
|
126
|
-
* @returns The updated proposed names for the value.
|
|
127
|
-
*/
|
|
128
|
-
async updateProposedNames(request) {
|
|
129
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _validateUpdateProposedNamesRequest, validateUpdateProposedNamesRequest_fn).call(this, request);
|
|
130
|
-
const providerResponses = (await Promise.all(
|
|
131
|
-
_chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _providers).map(
|
|
132
|
-
(provider) => _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getProviderResponse, getProviderResponse_fn).call(this, request, provider)
|
|
133
|
-
)
|
|
134
|
-
)).filter((response) => Boolean(response));
|
|
135
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateProposedNameState, updateProposedNameState_fn).call(this, request, providerResponses);
|
|
136
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateSourceState, updateSourceState_fn).call(this, _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _providers));
|
|
137
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _removeExpiredEntries, removeExpiredEntries_fn).call(this);
|
|
138
|
-
return _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getUpdateProposedNamesResult, getUpdateProposedNamesResult_fn).call(this, providerResponses);
|
|
139
|
-
}
|
|
140
|
-
};
|
|
141
|
-
_providers = new WeakMap();
|
|
142
|
-
_updateDelay = new WeakMap();
|
|
143
|
-
_updateProposedNameState = new WeakSet();
|
|
144
|
-
updateProposedNameState_fn = function(request, providerResponses) {
|
|
145
|
-
const { value, type, variation } = request;
|
|
146
|
-
const currentTime = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getCurrentTimeSeconds, getCurrentTimeSeconds_fn).call(this);
|
|
147
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _updateEntry, updateEntry_fn).call(this, value, type, variation, (entry) => {
|
|
148
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _removeDormantProposedNames, removeDormantProposedNames_fn).call(this, entry.proposedNames, type);
|
|
149
|
-
for (const providerResponse of providerResponses) {
|
|
150
|
-
const { results } = providerResponse;
|
|
151
|
-
for (const sourceId of Object.keys(providerResponse.results)) {
|
|
152
|
-
const result = results[sourceId];
|
|
153
|
-
const { proposedNames, updateDelay } = result;
|
|
154
|
-
const proposedNameEntry = entry.proposedNames[sourceId] ?? {
|
|
155
|
-
proposedNames: [],
|
|
156
|
-
lastRequestTime: null,
|
|
157
|
-
updateDelay: null
|
|
158
|
-
};
|
|
159
|
-
entry.proposedNames[sourceId] = proposedNameEntry;
|
|
160
|
-
if (proposedNames) {
|
|
161
|
-
proposedNameEntry.proposedNames = proposedNames;
|
|
162
|
-
}
|
|
163
|
-
proposedNameEntry.lastRequestTime = currentTime;
|
|
164
|
-
proposedNameEntry.updateDelay = updateDelay ?? null;
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
});
|
|
168
|
-
};
|
|
169
|
-
_updateSourceState = new WeakSet();
|
|
170
|
-
updateSourceState_fn = function(providers) {
|
|
171
|
-
const newNameSources = { ...this.state.nameSources };
|
|
172
|
-
for (const provider of providers) {
|
|
173
|
-
const { sourceLabels } = provider.getMetadata();
|
|
174
|
-
for (const sourceId of Object.keys(sourceLabels)) {
|
|
175
|
-
newNameSources[sourceId] = {
|
|
176
|
-
label: sourceLabels[sourceId]
|
|
177
|
-
};
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
this.update((state) => {
|
|
181
|
-
state.nameSources = newNameSources;
|
|
182
|
-
});
|
|
183
|
-
};
|
|
184
|
-
_getUpdateProposedNamesResult = new WeakSet();
|
|
185
|
-
getUpdateProposedNamesResult_fn = function(providerResponses) {
|
|
186
|
-
return providerResponses.reduce(
|
|
187
|
-
(acc, providerResponse) => {
|
|
188
|
-
const { results } = providerResponse;
|
|
189
|
-
for (const sourceId of Object.keys(results)) {
|
|
190
|
-
const { proposedNames, error } = results[sourceId];
|
|
191
|
-
acc.results[sourceId] = {
|
|
192
|
-
proposedNames,
|
|
193
|
-
error
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
return acc;
|
|
197
|
-
},
|
|
198
|
-
{ results: {} }
|
|
199
|
-
);
|
|
200
|
-
};
|
|
201
|
-
_getProviderResponse = new WeakSet();
|
|
202
|
-
getProviderResponse_fn = async function(request, provider) {
|
|
203
|
-
const {
|
|
204
|
-
value,
|
|
205
|
-
type,
|
|
206
|
-
sourceIds: requestedSourceIds,
|
|
207
|
-
onlyUpdateAfterDelay,
|
|
208
|
-
variation
|
|
209
|
-
} = request;
|
|
210
|
-
const variationKey = variation ?? DEFAULT_VARIATION;
|
|
211
|
-
const supportedSourceIds = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getSourceIds, getSourceIds_fn).call(this, provider, type);
|
|
212
|
-
const currentTime = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getCurrentTimeSeconds, getCurrentTimeSeconds_fn).call(this);
|
|
213
|
-
const normalizedValue = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _normalizeValue, normalizeValue_fn).call(this, value, type);
|
|
214
|
-
const matchingSourceIds = supportedSourceIds.filter((sourceId) => {
|
|
215
|
-
if (requestedSourceIds && !requestedSourceIds.includes(sourceId)) {
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
if (onlyUpdateAfterDelay) {
|
|
219
|
-
const entry = this.state.names[type]?.[normalizedValue]?.[variationKey] ?? {};
|
|
220
|
-
const proposedNamesEntry = entry.proposedNames?.[sourceId] ?? {};
|
|
221
|
-
const lastRequestTime = proposedNamesEntry.lastRequestTime ?? 0;
|
|
222
|
-
const updateDelay = proposedNamesEntry.updateDelay ?? _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _updateDelay);
|
|
223
|
-
if (currentTime - lastRequestTime < updateDelay) {
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
}
|
|
227
|
-
return true;
|
|
228
|
-
});
|
|
229
|
-
if (!matchingSourceIds.length) {
|
|
230
|
-
return void 0;
|
|
231
|
-
}
|
|
232
|
-
const providerRequest = {
|
|
233
|
-
value: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _normalizeValue, normalizeValue_fn).call(this, value, type),
|
|
234
|
-
type,
|
|
235
|
-
sourceIds: requestedSourceIds ? matchingSourceIds : void 0,
|
|
236
|
-
variation: _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _normalizeVariation, normalizeVariation_fn).call(this, variationKey, type)
|
|
237
|
-
};
|
|
238
|
-
let responseError;
|
|
239
|
-
let response;
|
|
240
|
-
try {
|
|
241
|
-
response = await provider.getProposedNames(providerRequest);
|
|
242
|
-
responseError = response.error;
|
|
243
|
-
} catch (error) {
|
|
244
|
-
responseError = error;
|
|
245
|
-
}
|
|
246
|
-
return _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _normalizeProviderResult, normalizeProviderResult_fn).call(this, response, responseError, matchingSourceIds);
|
|
247
|
-
};
|
|
248
|
-
_normalizeProviderResult = new WeakSet();
|
|
249
|
-
normalizeProviderResult_fn = function(result, responseError, matchingSourceIds) {
|
|
250
|
-
const error = responseError ?? void 0;
|
|
251
|
-
const results = matchingSourceIds.reduce((acc, sourceId) => {
|
|
252
|
-
const sourceResult = result?.results?.[sourceId];
|
|
253
|
-
const normalizedSourceResult = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _normalizeProviderSourceResult, normalizeProviderSourceResult_fn).call(this, sourceResult, responseError);
|
|
254
|
-
return {
|
|
255
|
-
...acc,
|
|
256
|
-
[sourceId]: normalizedSourceResult
|
|
257
|
-
};
|
|
258
|
-
}, {});
|
|
259
|
-
return { results, error };
|
|
260
|
-
};
|
|
261
|
-
_normalizeProviderSourceResult = new WeakSet();
|
|
262
|
-
normalizeProviderSourceResult_fn = function(result, responseError) {
|
|
263
|
-
const error = result?.error ?? responseError ?? void 0;
|
|
264
|
-
const updateDelay = result?.updateDelay ?? void 0;
|
|
265
|
-
let proposedNames = error ? void 0 : result?.proposedNames ?? void 0;
|
|
266
|
-
if (proposedNames) {
|
|
267
|
-
proposedNames = proposedNames.filter(
|
|
268
|
-
(proposedName) => proposedName?.length
|
|
269
|
-
);
|
|
270
|
-
}
|
|
271
|
-
return {
|
|
272
|
-
proposedNames,
|
|
273
|
-
error,
|
|
274
|
-
updateDelay
|
|
275
|
-
};
|
|
276
|
-
};
|
|
277
|
-
_normalizeValue = new WeakSet();
|
|
278
|
-
normalizeValue_fn = function(value, type) {
|
|
279
|
-
switch (type) {
|
|
280
|
-
case "ethereumAddress" /* ETHEREUM_ADDRESS */:
|
|
281
|
-
return value.toLowerCase();
|
|
282
|
-
default:
|
|
283
|
-
return value;
|
|
284
|
-
}
|
|
285
|
-
};
|
|
286
|
-
_normalizeVariation = new WeakSet();
|
|
287
|
-
normalizeVariation_fn = function(variation, type) {
|
|
288
|
-
switch (type) {
|
|
289
|
-
case "ethereumAddress" /* ETHEREUM_ADDRESS */:
|
|
290
|
-
return variation.toLowerCase();
|
|
291
|
-
default:
|
|
292
|
-
return variation;
|
|
293
|
-
}
|
|
294
|
-
};
|
|
295
|
-
_updateEntry = new WeakSet();
|
|
296
|
-
updateEntry_fn = function(value, type, variation, callback) {
|
|
297
|
-
const variationKey = variation ?? DEFAULT_VARIATION;
|
|
298
|
-
const normalizedValue = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _normalizeValue, normalizeValue_fn).call(this, value, type);
|
|
299
|
-
const normalizedVariation = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _normalizeVariation, normalizeVariation_fn).call(this, variationKey, type);
|
|
300
|
-
if ([normalizedValue, normalizedVariation].some(
|
|
301
|
-
(key) => !_controllerutils.isSafeDynamicKey.call(void 0, key)
|
|
302
|
-
)) {
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
this.update((state) => {
|
|
306
|
-
const typeEntries = state.names[type] || {};
|
|
307
|
-
state.names[type] = typeEntries;
|
|
308
|
-
const variationEntries = typeEntries[normalizedValue] || {};
|
|
309
|
-
typeEntries[normalizedValue] = variationEntries;
|
|
310
|
-
const entry = variationEntries[normalizedVariation] ?? {
|
|
311
|
-
proposedNames: {},
|
|
312
|
-
name: null,
|
|
313
|
-
sourceId: null,
|
|
314
|
-
origin: null
|
|
315
|
-
};
|
|
316
|
-
variationEntries[normalizedVariation] = entry;
|
|
317
|
-
callback(entry);
|
|
318
|
-
});
|
|
319
|
-
};
|
|
320
|
-
_getCurrentTimeSeconds = new WeakSet();
|
|
321
|
-
getCurrentTimeSeconds_fn = function() {
|
|
322
|
-
return Math.round(Date.now() / 1e3);
|
|
323
|
-
};
|
|
324
|
-
_validateSetNameRequest = new WeakSet();
|
|
325
|
-
validateSetNameRequest_fn = function(request) {
|
|
326
|
-
const { name, value, type, sourceId, variation, origin } = request;
|
|
327
|
-
const errorMessages = [];
|
|
328
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _validateValue, validateValue_fn).call(this, value, errorMessages);
|
|
329
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _validateType, validateType_fn).call(this, type, errorMessages);
|
|
330
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _validateName, validateName_fn).call(this, name, errorMessages);
|
|
331
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _validateSourceId, validateSourceId_fn).call(this, sourceId, type, name, errorMessages);
|
|
332
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _validateVariation, validateVariation_fn).call(this, variation, type, errorMessages);
|
|
333
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _validateOrigin, validateOrigin_fn).call(this, origin, name, errorMessages);
|
|
334
|
-
if (errorMessages.length) {
|
|
335
|
-
throw new Error(errorMessages.join(" "));
|
|
336
|
-
}
|
|
337
|
-
};
|
|
338
|
-
_validateUpdateProposedNamesRequest = new WeakSet();
|
|
339
|
-
validateUpdateProposedNamesRequest_fn = function(request) {
|
|
340
|
-
const { value, type, sourceIds, variation } = request;
|
|
341
|
-
const errorMessages = [];
|
|
342
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _validateValue, validateValue_fn).call(this, value, errorMessages);
|
|
343
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _validateType, validateType_fn).call(this, type, errorMessages);
|
|
344
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _validateSourceIds, validateSourceIds_fn).call(this, sourceIds, type, errorMessages);
|
|
345
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _validateDuplicateSourceIds, validateDuplicateSourceIds_fn).call(this, type, errorMessages);
|
|
346
|
-
_chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _validateVariation, validateVariation_fn).call(this, variation, type, errorMessages);
|
|
347
|
-
if (errorMessages.length) {
|
|
348
|
-
throw new Error(errorMessages.join(" "));
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
_validateValue = new WeakSet();
|
|
352
|
-
validateValue_fn = function(value, errorMessages) {
|
|
353
|
-
if (!value?.length || typeof value !== "string") {
|
|
354
|
-
errorMessages.push("Must specify a non-empty string for value.");
|
|
355
|
-
}
|
|
356
|
-
};
|
|
357
|
-
_validateType = new WeakSet();
|
|
358
|
-
validateType_fn = function(type, errorMessages) {
|
|
359
|
-
if (!Object.values(_chunkPL7IXD33js.NameType).includes(type)) {
|
|
360
|
-
errorMessages.push(
|
|
361
|
-
`Must specify one of the following types: ${Object.values(
|
|
362
|
-
_chunkPL7IXD33js.NameType
|
|
363
|
-
).join(", ")}`
|
|
364
|
-
);
|
|
365
|
-
}
|
|
366
|
-
};
|
|
367
|
-
_validateName = new WeakSet();
|
|
368
|
-
validateName_fn = function(name, errorMessages) {
|
|
369
|
-
if (name === null) {
|
|
370
|
-
return;
|
|
371
|
-
}
|
|
372
|
-
if (!name?.length || typeof name !== "string") {
|
|
373
|
-
errorMessages.push("Must specify a non-empty string or null for name.");
|
|
374
|
-
}
|
|
375
|
-
};
|
|
376
|
-
_validateSourceIds = new WeakSet();
|
|
377
|
-
validateSourceIds_fn = function(sourceIds, type, errorMessages) {
|
|
378
|
-
if (!sourceIds) {
|
|
379
|
-
return;
|
|
380
|
-
}
|
|
381
|
-
const allSourceIds = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getAllSourceIds, getAllSourceIds_fn).call(this, type);
|
|
382
|
-
const missingSourceIds = [];
|
|
383
|
-
for (const sourceId of sourceIds) {
|
|
384
|
-
if (!allSourceIds.includes(sourceId)) {
|
|
385
|
-
missingSourceIds.push(sourceId);
|
|
386
|
-
continue;
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
if (missingSourceIds.length) {
|
|
390
|
-
errorMessages.push(
|
|
391
|
-
`Unknown source IDs for type '${type}': ${missingSourceIds.join(", ")}`
|
|
392
|
-
);
|
|
393
|
-
}
|
|
394
|
-
};
|
|
395
|
-
_validateSourceId = new WeakSet();
|
|
396
|
-
validateSourceId_fn = function(sourceId, type, name, errorMessages) {
|
|
397
|
-
if (sourceId === null || sourceId === void 0) {
|
|
398
|
-
return;
|
|
399
|
-
}
|
|
400
|
-
if (name === null) {
|
|
401
|
-
errorMessages.push(
|
|
402
|
-
`Cannot specify a source ID when clearing the saved name: ${sourceId}`
|
|
403
|
-
);
|
|
404
|
-
return;
|
|
405
|
-
}
|
|
406
|
-
const allSourceIds = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getAllSourceIds, getAllSourceIds_fn).call(this, type);
|
|
407
|
-
if (!sourceId.length || typeof sourceId !== "string") {
|
|
408
|
-
errorMessages.push("Must specify a non-empty string for sourceId.");
|
|
409
|
-
return;
|
|
410
|
-
}
|
|
411
|
-
if (!allSourceIds.includes(sourceId)) {
|
|
412
|
-
errorMessages.push(`Unknown source ID for type '${type}': ${sourceId}`);
|
|
413
|
-
}
|
|
414
|
-
};
|
|
415
|
-
_validateDuplicateSourceIds = new WeakSet();
|
|
416
|
-
validateDuplicateSourceIds_fn = function(type, errorMessages) {
|
|
417
|
-
const allSourceIds = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getAllSourceIds, getAllSourceIds_fn).call(this, type);
|
|
418
|
-
const duplicateSourceIds = allSourceIds.filter(
|
|
419
|
-
(sourceId, index) => allSourceIds.indexOf(sourceId) !== index
|
|
420
|
-
);
|
|
421
|
-
if (duplicateSourceIds.length) {
|
|
422
|
-
errorMessages.push(
|
|
423
|
-
`Duplicate source IDs found for type '${type}': ${duplicateSourceIds.join(
|
|
424
|
-
", "
|
|
425
|
-
)}`
|
|
426
|
-
);
|
|
427
|
-
}
|
|
428
|
-
};
|
|
429
|
-
_validateVariation = new WeakSet();
|
|
430
|
-
validateVariation_fn = function(variation, type, errorMessages) {
|
|
431
|
-
if (type !== "ethereumAddress" /* ETHEREUM_ADDRESS */) {
|
|
432
|
-
return;
|
|
433
|
-
}
|
|
434
|
-
if (!variation?.length || typeof variation !== "string" || !variation.match(/^0x[0-9A-Fa-f]+$/u) && variation !== FALLBACK_VARIATION) {
|
|
435
|
-
errorMessages.push(
|
|
436
|
-
`Must specify a chain ID in hexidecimal format or the fallback, "${FALLBACK_VARIATION}", for variation when using '${type}' type.`
|
|
437
|
-
);
|
|
438
|
-
}
|
|
439
|
-
};
|
|
440
|
-
_validateOrigin = new WeakSet();
|
|
441
|
-
validateOrigin_fn = function(origin, name, errorMessages) {
|
|
442
|
-
if (!origin) {
|
|
443
|
-
return;
|
|
444
|
-
}
|
|
445
|
-
if (name === null) {
|
|
446
|
-
errorMessages.push(
|
|
447
|
-
`Cannot specify an origin when clearing the saved name: ${origin}`
|
|
448
|
-
);
|
|
449
|
-
return;
|
|
450
|
-
}
|
|
451
|
-
if (!Object.values(NameOrigin).includes(origin)) {
|
|
452
|
-
errorMessages.push(
|
|
453
|
-
`Must specify one of the following origins: ${Object.values(
|
|
454
|
-
NameOrigin
|
|
455
|
-
).join(", ")}`
|
|
456
|
-
);
|
|
457
|
-
}
|
|
458
|
-
};
|
|
459
|
-
_getAllSourceIds = new WeakSet();
|
|
460
|
-
getAllSourceIds_fn = function(type) {
|
|
461
|
-
return _chunkZ4BLTVTBjs.__privateGet.call(void 0, this, _providers).map((provider) => _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getSourceIds, getSourceIds_fn).call(this, provider, type)).flat();
|
|
462
|
-
};
|
|
463
|
-
_getSourceIds = new WeakSet();
|
|
464
|
-
getSourceIds_fn = function(provider, type) {
|
|
465
|
-
return provider.getMetadata().sourceIds[type];
|
|
466
|
-
};
|
|
467
|
-
_removeDormantProposedNames = new WeakSet();
|
|
468
|
-
removeDormantProposedNames_fn = function(proposedNames, type) {
|
|
469
|
-
if (Object.keys(proposedNames).length === 0) {
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
|
-
const typeSourceIds = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getAllSourceIds, getAllSourceIds_fn).call(this, type);
|
|
473
|
-
const dormantSourceIds = Object.keys(proposedNames).filter(
|
|
474
|
-
(sourceId) => !typeSourceIds.includes(sourceId)
|
|
475
|
-
);
|
|
476
|
-
for (const dormantSourceId of dormantSourceIds) {
|
|
477
|
-
delete proposedNames[dormantSourceId];
|
|
478
|
-
}
|
|
479
|
-
};
|
|
480
|
-
_removeExpiredEntries = new WeakSet();
|
|
481
|
-
removeExpiredEntries_fn = function() {
|
|
482
|
-
const currentTime = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getCurrentTimeSeconds, getCurrentTimeSeconds_fn).call(this);
|
|
483
|
-
this.update((state) => {
|
|
484
|
-
const entries = _chunkZ4BLTVTBjs.__privateMethod.call(void 0, this, _getEntriesList, getEntriesList_fn).call(this, state);
|
|
485
|
-
for (const { nameType, value, variation, entry } of entries) {
|
|
486
|
-
if (entry.name !== null) {
|
|
487
|
-
continue;
|
|
488
|
-
}
|
|
489
|
-
const proposedNames = Object.values(entry.proposedNames);
|
|
490
|
-
const allProposedNamesExpired = proposedNames.every(
|
|
491
|
-
(proposedName) => currentTime - (proposedName.lastRequestTime ?? 0) >= PROPOSED_NAME_EXPIRE_DURATION
|
|
492
|
-
);
|
|
493
|
-
if (allProposedNamesExpired) {
|
|
494
|
-
delete state.names[nameType][value][variation];
|
|
495
|
-
}
|
|
496
|
-
}
|
|
497
|
-
});
|
|
498
|
-
};
|
|
499
|
-
_getEntriesList = new WeakSet();
|
|
500
|
-
getEntriesList_fn = function(state) {
|
|
501
|
-
return Object.entries(state.names).flatMap(
|
|
502
|
-
([type, typeEntries]) => Object.entries(typeEntries).flatMap(
|
|
503
|
-
([value, variationEntries]) => Object.entries(variationEntries).map(([variation, entry]) => ({
|
|
504
|
-
entry,
|
|
505
|
-
nameType: type,
|
|
506
|
-
value,
|
|
507
|
-
variation
|
|
508
|
-
}))
|
|
509
|
-
)
|
|
510
|
-
);
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
exports.FALLBACK_VARIATION = FALLBACK_VARIATION; exports.PROPOSED_NAME_EXPIRE_DURATION = PROPOSED_NAME_EXPIRE_DURATION; exports.NameOrigin = NameOrigin; exports.NameController = NameController;
|
|
519
|
-
//# sourceMappingURL=chunk-PL2KMW2Y.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/NameController.ts"],"names":["NameOrigin"],"mappings":";;;;;;;;;;;AAKA,SAAS,sBAAsB;AAC/B,SAAS,wBAAwB;AAU1B,IAAM,qBAAqB;AAC3B,IAAM,gCAAgC,KAAK,KAAK;AAKhD,IAAK,aAAL,kBAAKA,gBAAL;AAEL,EAAAA,YAAA,sBAAmB;AAEnB,EAAAA,YAAA,kBAAe;AAEf,EAAAA,YAAA,SAAM;AAEN,EAAAA,YAAA,QAAK;AARK,SAAAA;AAAA,GAAA;AAWZ,IAAM,uBAAuB,KAAK;AAClC,IAAM,oBAAoB;AAE1B,IAAM,iBAAiB;AAEvB,IAAM,gBAAgB;AAAA,EACpB,OAAO,EAAE,SAAS,MAAM,WAAW,MAAM;AAAA,EACzC,aAAa,EAAE,SAAS,MAAM,WAAW,MAAM;AACjD;AAEA,IAAM,kBAAkB,OAAO;AAAA,EAC7B,OAAO;AA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M,QAAQ,EAAE,KAAK,EAAE,SAAS;AAAA,MAC/C;AAAA,IACF;AAAA,EACF,CAAC;AACH;AAEA;AAAA,oBAAe,SAAC,OAKZ;AACF,SAAO,OAAO,QAAQ,MAAM,KAAK,EAAE;AAAA,IAAQ,CAAC,CAAC,MAAM,WAAW,MAC5D,OAAO,QAAQ,WAAW,EAAE;AAAA,MAAQ,CAAC,CAAC,OAAO,gBAAgB,MAC3D,OAAO,QAAQ,gBAAgB,EAAE,IAAI,CAAC,CAAC,WAAW,KAAK,OAAO;AAAA,QAC5D;AAAA,QACA,UAAU;AAAA,QACV;AAAA,QACA;AAAA,MACF,EAAE;AAAA,IACJ;AAAA,EACF;AACF","sourcesContent":["import type {\n ControllerGetStateAction,\n ControllerStateChangeEvent,\n RestrictedControllerMessenger,\n} from '@metamask/base-controller';\nimport { BaseController } from '@metamask/base-controller';\nimport { isSafeDynamicKey } from '@metamask/controller-utils';\n\nimport type {\n NameProvider,\n NameProviderRequest,\n NameProviderResult,\n NameProviderSourceResult,\n} from './types';\nimport { NameType } from './types';\n\nexport const FALLBACK_VARIATION = '*';\nexport const PROPOSED_NAME_EXPIRE_DURATION = 60 * 60 * 24; // 24 hours\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 this.#removeExpiredEntries();\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 if (\n [normalizedValue, normalizedVariation].some(\n (key) => !isSafeDynamicKey(key),\n )\n ) {\n return;\n }\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 #removeExpiredEntries(): void {\n const currentTime = this.#getCurrentTimeSeconds();\n\n this.update((state: NameControllerState) => {\n const entries = this.#getEntriesList(state);\n for (const { nameType, value, variation, entry } of entries) {\n if (entry.name !== null) {\n continue;\n }\n\n const proposedNames = Object.values(entry.proposedNames);\n const allProposedNamesExpired = proposedNames.every(\n (proposedName: ProposedNamesEntry) =>\n currentTime - (proposedName.lastRequestTime ?? 0) >=\n PROPOSED_NAME_EXPIRE_DURATION,\n );\n\n if (allProposedNamesExpired) {\n delete state.names[nameType][value][variation];\n }\n }\n });\n }\n\n #getEntriesList(state: NameControllerState): {\n nameType: NameType;\n value: string;\n variation: string;\n entry: NameEntry;\n }[] {\n return Object.entries(state.names).flatMap(([type, typeEntries]) =>\n Object.entries(typeEntries).flatMap(([value, variationEntries]) =>\n Object.entries(variationEntries).map(([variation, entry]) => ({\n entry,\n nameType: type as NameType,\n value,\n variation,\n })),\n ),\n );\n }\n}\n"]}
|
package/dist/chunk-PL7IXD33.js
DELETED
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/types.ts
|
|
2
|
-
var NameType = /* @__PURE__ */ ((NameType2) => {
|
|
3
|
-
NameType2["ETHEREUM_ADDRESS"] = "ethereumAddress";
|
|
4
|
-
return NameType2;
|
|
5
|
-
})(NameType || {});
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
exports.NameType = NameType;
|
|
10
|
-
//# sourceMappingURL=chunk-PL7IXD33.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/types.ts"],"names":["NameType"],"mappings":";AACO,IAAK,WAAL,kBAAKA,cAAL;AAEL,EAAAA,UAAA,sBAAmB;AAFT,SAAAA;AAAA,GAAA","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"]}
|
package/dist/chunk-QBR7BSWB.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/logger.ts
|
|
2
|
-
var _utils = require('@metamask/utils');
|
|
3
|
-
var projectLogger = _utils.createProjectLogger.call(void 0, "name-controller");
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
exports.createModuleLogger = _utils.createModuleLogger; exports.projectLogger = projectLogger;
|
|
9
|
-
//# sourceMappingURL=chunk-QBR7BSWB.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/logger.ts"],"names":[],"mappings":";AAAA,SAAS,qBAAqB,0BAA0B;AAEjD,IAAM,gBAAgB,oBAAoB,iBAAiB","sourcesContent":["import { createProjectLogger, createModuleLogger } from '@metamask/utils';\n\nexport const projectLogger = createProjectLogger('name-controller');\n\nexport { createModuleLogger };\n"]}
|