@metamask/name-controller 7.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 +35 -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 +22 -16
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@metamask/name-controller",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "8.0.1",
|
|
4
4
|
"description": "Stores and suggests names for values such as Ethereum addresses",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"MetaMask",
|
|
@@ -18,33 +18,39 @@
|
|
|
18
18
|
"sideEffects": false,
|
|
19
19
|
"exports": {
|
|
20
20
|
".": {
|
|
21
|
-
"import":
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
"import": {
|
|
22
|
+
"types": "./dist/index.d.mts",
|
|
23
|
+
"default": "./dist/index.mjs"
|
|
24
|
+
},
|
|
25
|
+
"require": {
|
|
26
|
+
"types": "./dist/index.d.cts",
|
|
27
|
+
"default": "./dist/index.cjs"
|
|
28
|
+
}
|
|
24
29
|
},
|
|
25
30
|
"./package.json": "./package.json"
|
|
26
31
|
},
|
|
27
|
-
"main": "./dist/index.
|
|
28
|
-
"types": "./dist/
|
|
32
|
+
"main": "./dist/index.cjs",
|
|
33
|
+
"types": "./dist/index.d.cts",
|
|
29
34
|
"files": [
|
|
30
35
|
"dist/"
|
|
31
36
|
],
|
|
32
37
|
"scripts": {
|
|
33
|
-
"build": "
|
|
38
|
+
"build": "ts-bridge --project tsconfig.build.json --verbose --clean --no-references",
|
|
34
39
|
"build:docs": "typedoc",
|
|
35
40
|
"changelog:update": "../../scripts/update-changelog.sh @metamask/name-controller",
|
|
36
41
|
"changelog:validate": "../../scripts/validate-changelog.sh @metamask/name-controller",
|
|
37
42
|
"prepare-manifest:preview": "../../scripts/prepare-preview-manifest.sh",
|
|
38
43
|
"publish:preview": "yarn npm publish --tag preview",
|
|
39
|
-
"
|
|
40
|
-
"test
|
|
41
|
-
"test:
|
|
42
|
-
"test:
|
|
44
|
+
"since-latest-release": "../../scripts/since-latest-release.sh",
|
|
45
|
+
"test": "NODE_OPTIONS=--experimental-vm-modules jest --reporters=jest-silent-reporter",
|
|
46
|
+
"test:clean": "NODE_OPTIONS=--experimental-vm-modules jest --clearCache",
|
|
47
|
+
"test:verbose": "NODE_OPTIONS=--experimental-vm-modules jest --verbose",
|
|
48
|
+
"test:watch": "NODE_OPTIONS=--experimental-vm-modules jest --watch"
|
|
43
49
|
},
|
|
44
50
|
"dependencies": {
|
|
45
|
-
"@metamask/base-controller": "^
|
|
46
|
-
"@metamask/controller-utils": "^
|
|
47
|
-
"@metamask/utils": "^
|
|
51
|
+
"@metamask/base-controller": "^7.0.1",
|
|
52
|
+
"@metamask/controller-utils": "^11.3.0",
|
|
53
|
+
"@metamask/utils": "^9.1.0",
|
|
48
54
|
"async-mutex": "^0.5.0"
|
|
49
55
|
},
|
|
50
56
|
"devDependencies": {
|
|
@@ -55,10 +61,10 @@
|
|
|
55
61
|
"ts-jest": "^27.1.4",
|
|
56
62
|
"typedoc": "^0.24.8",
|
|
57
63
|
"typedoc-plugin-missing-exports": "^2.0.0",
|
|
58
|
-
"typescript": "~
|
|
64
|
+
"typescript": "~5.2.2"
|
|
59
65
|
},
|
|
60
66
|
"engines": {
|
|
61
|
-
"node": ">=
|
|
67
|
+
"node": "^18.18 || >=20"
|
|
62
68
|
},
|
|
63
69
|
"publishConfig": {
|
|
64
70
|
"access": "public",
|
package/dist/NameController.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports, "__esModule", {value: true});
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var _chunkPL2KMW2Yjs = require('./chunk-PL2KMW2Y.js');
|
|
7
|
-
require('./chunk-PL7IXD33.js');
|
|
8
|
-
require('./chunk-Z4BLTVTB.js');
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
exports.FALLBACK_VARIATION = _chunkPL2KMW2Yjs.FALLBACK_VARIATION; exports.NameController = _chunkPL2KMW2Yjs.NameController; exports.NameOrigin = _chunkPL2KMW2Yjs.NameOrigin; exports.PROPOSED_NAME_EXPIRE_DURATION = _chunkPL2KMW2Yjs.PROPOSED_NAME_EXPIRE_DURATION;
|
|
15
|
-
//# sourceMappingURL=NameController.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":[],"names":[],"mappings":""}
|
package/dist/chunk-6AVJOVIX.mjs
DELETED
|
@@ -1,519 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
NameType
|
|
3
|
-
} from "./chunk-6W3DEAGA.mjs";
|
|
4
|
-
import {
|
|
5
|
-
__privateAdd,
|
|
6
|
-
__privateGet,
|
|
7
|
-
__privateMethod,
|
|
8
|
-
__privateSet
|
|
9
|
-
} from "./chunk-XUI43LEZ.mjs";
|
|
10
|
-
|
|
11
|
-
// src/NameController.ts
|
|
12
|
-
import { BaseController } from "@metamask/base-controller";
|
|
13
|
-
import { isSafeDynamicKey } from "@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 {
|
|
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
|
-
__privateAdd(this, _updateProposedNameState);
|
|
60
|
-
__privateAdd(this, _updateSourceState);
|
|
61
|
-
__privateAdd(this, _getUpdateProposedNamesResult);
|
|
62
|
-
__privateAdd(this, _getProviderResponse);
|
|
63
|
-
__privateAdd(this, _normalizeProviderResult);
|
|
64
|
-
__privateAdd(this, _normalizeProviderSourceResult);
|
|
65
|
-
__privateAdd(this, _normalizeValue);
|
|
66
|
-
__privateAdd(this, _normalizeVariation);
|
|
67
|
-
__privateAdd(this, _updateEntry);
|
|
68
|
-
__privateAdd(this, _getCurrentTimeSeconds);
|
|
69
|
-
__privateAdd(this, _validateSetNameRequest);
|
|
70
|
-
__privateAdd(this, _validateUpdateProposedNamesRequest);
|
|
71
|
-
__privateAdd(this, _validateValue);
|
|
72
|
-
__privateAdd(this, _validateType);
|
|
73
|
-
__privateAdd(this, _validateName);
|
|
74
|
-
__privateAdd(this, _validateSourceIds);
|
|
75
|
-
__privateAdd(this, _validateSourceId);
|
|
76
|
-
__privateAdd(this, _validateDuplicateSourceIds);
|
|
77
|
-
__privateAdd(this, _validateVariation);
|
|
78
|
-
__privateAdd(this, _validateOrigin);
|
|
79
|
-
__privateAdd(this, _getAllSourceIds);
|
|
80
|
-
__privateAdd(this, _getSourceIds);
|
|
81
|
-
__privateAdd(this, _removeDormantProposedNames);
|
|
82
|
-
__privateAdd(this, _removeExpiredEntries);
|
|
83
|
-
__privateAdd(this, _getEntriesList);
|
|
84
|
-
__privateAdd(this, _providers, void 0);
|
|
85
|
-
__privateAdd(this, _updateDelay, void 0);
|
|
86
|
-
__privateSet(this, _providers, providers);
|
|
87
|
-
__privateSet(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
|
-
__privateMethod(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
|
-
__privateMethod(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
|
-
__privateMethod(this, _validateUpdateProposedNamesRequest, validateUpdateProposedNamesRequest_fn).call(this, request);
|
|
130
|
-
const providerResponses = (await Promise.all(
|
|
131
|
-
__privateGet(this, _providers).map(
|
|
132
|
-
(provider) => __privateMethod(this, _getProviderResponse, getProviderResponse_fn).call(this, request, provider)
|
|
133
|
-
)
|
|
134
|
-
)).filter((response) => Boolean(response));
|
|
135
|
-
__privateMethod(this, _updateProposedNameState, updateProposedNameState_fn).call(this, request, providerResponses);
|
|
136
|
-
__privateMethod(this, _updateSourceState, updateSourceState_fn).call(this, __privateGet(this, _providers));
|
|
137
|
-
__privateMethod(this, _removeExpiredEntries, removeExpiredEntries_fn).call(this);
|
|
138
|
-
return __privateMethod(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 = __privateMethod(this, _getCurrentTimeSeconds, getCurrentTimeSeconds_fn).call(this);
|
|
147
|
-
__privateMethod(this, _updateEntry, updateEntry_fn).call(this, value, type, variation, (entry) => {
|
|
148
|
-
__privateMethod(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 = __privateMethod(this, _getSourceIds, getSourceIds_fn).call(this, provider, type);
|
|
212
|
-
const currentTime = __privateMethod(this, _getCurrentTimeSeconds, getCurrentTimeSeconds_fn).call(this);
|
|
213
|
-
const normalizedValue = __privateMethod(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 ?? __privateGet(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: __privateMethod(this, _normalizeValue, normalizeValue_fn).call(this, value, type),
|
|
234
|
-
type,
|
|
235
|
-
sourceIds: requestedSourceIds ? matchingSourceIds : void 0,
|
|
236
|
-
variation: __privateMethod(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 __privateMethod(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 = __privateMethod(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 = __privateMethod(this, _normalizeValue, normalizeValue_fn).call(this, value, type);
|
|
299
|
-
const normalizedVariation = __privateMethod(this, _normalizeVariation, normalizeVariation_fn).call(this, variationKey, type);
|
|
300
|
-
if ([normalizedValue, normalizedVariation].some(
|
|
301
|
-
(key) => !isSafeDynamicKey(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
|
-
__privateMethod(this, _validateValue, validateValue_fn).call(this, value, errorMessages);
|
|
329
|
-
__privateMethod(this, _validateType, validateType_fn).call(this, type, errorMessages);
|
|
330
|
-
__privateMethod(this, _validateName, validateName_fn).call(this, name, errorMessages);
|
|
331
|
-
__privateMethod(this, _validateSourceId, validateSourceId_fn).call(this, sourceId, type, name, errorMessages);
|
|
332
|
-
__privateMethod(this, _validateVariation, validateVariation_fn).call(this, variation, type, errorMessages);
|
|
333
|
-
__privateMethod(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
|
-
__privateMethod(this, _validateValue, validateValue_fn).call(this, value, errorMessages);
|
|
343
|
-
__privateMethod(this, _validateType, validateType_fn).call(this, type, errorMessages);
|
|
344
|
-
__privateMethod(this, _validateSourceIds, validateSourceIds_fn).call(this, sourceIds, type, errorMessages);
|
|
345
|
-
__privateMethod(this, _validateDuplicateSourceIds, validateDuplicateSourceIds_fn).call(this, type, errorMessages);
|
|
346
|
-
__privateMethod(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(NameType).includes(type)) {
|
|
360
|
-
errorMessages.push(
|
|
361
|
-
`Must specify one of the following types: ${Object.values(
|
|
362
|
-
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 = __privateMethod(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 = __privateMethod(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 = __privateMethod(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 __privateGet(this, _providers).map((provider) => __privateMethod(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 = __privateMethod(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 = __privateMethod(this, _getCurrentTimeSeconds, getCurrentTimeSeconds_fn).call(this);
|
|
483
|
-
this.update((state) => {
|
|
484
|
-
const entries = __privateMethod(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
|
-
export {
|
|
514
|
-
FALLBACK_VARIATION,
|
|
515
|
-
PROPOSED_NAME_EXPIRE_DURATION,
|
|
516
|
-
NameOrigin,
|
|
517
|
-
NameController
|
|
518
|
-
};
|
|
519
|
-
//# sourceMappingURL=chunk-6AVJOVIX.mjs.map
|