@talismn/on-chain-id 0.2.11 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +253 -674
- package/dist/index.d.mts +36 -30
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +36 -30
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +132 -211
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +112 -178
- package/dist/index.mjs.map +1 -1
- package/package.json +7 -7
package/dist/index.d.mts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IChainConnectorDot, IChainConnectorEth, IChainConnectorSol } from
|
|
2
|
-
|
|
1
|
+
import { IChainConnectorDot, IChainConnectorEth, IChainConnectorSol } from "@talismn/chain-connectors";
|
|
2
|
+
//#region src/util/types.d.ts
|
|
3
3
|
type ChainConnectors = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
substrate?: IChainConnectorDot;
|
|
5
|
+
evm?: IChainConnectorEth;
|
|
6
|
+
solana?: IChainConnectorSol;
|
|
7
7
|
};
|
|
8
8
|
/** A map of addresses to their on-chain ids. */
|
|
9
9
|
type OnChainIds = Map<string, string | null>;
|
|
@@ -15,15 +15,15 @@ type NsLookupType = "ens" | "azns";
|
|
|
15
15
|
* Used as the first parameter to all `namesToAddresses`/`addressesToNames` functions.
|
|
16
16
|
*/
|
|
17
17
|
type Config = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
chainConnectors: ChainConnectors;
|
|
19
|
+
/** Used for ens lookups */
|
|
20
|
+
networkIdEthereum: string;
|
|
21
|
+
/** @deprecated */
|
|
22
|
+
registryAlephZero?: unknown;
|
|
23
|
+
/** @deprecated */
|
|
24
|
+
chainIdAlephZero?: string;
|
|
25
|
+
/** @deprecated */
|
|
26
|
+
aznsSupportedChainIdAlephZero?: string;
|
|
27
27
|
};
|
|
28
28
|
type OptionalConfigParams = "chainIdAlephZero" | "aznsSupportedChainIdAlephZero" | "networkIdEthereum";
|
|
29
29
|
type OptionalConfig = Omit<Config, OptionalConfigParams> & Partial<Pick<Config, OptionalConfigParams>>;
|
|
@@ -34,7 +34,8 @@ type OptionalConfig = Omit<Config, OptionalConfigParams> & Partial<Pick<Config,
|
|
|
34
34
|
* type DropFirstParams = DropFirst<AllParams> // evaluates to ["two", "three"]
|
|
35
35
|
*/
|
|
36
36
|
type DropFirst<T extends unknown[]> = T extends [unknown, ...infer U] ? U : never;
|
|
37
|
-
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/util/addressesToNames.d.ts
|
|
38
39
|
/**
|
|
39
40
|
* Looks up the on-chain identifiers for some addresses.
|
|
40
41
|
* Supports ENS.
|
|
@@ -49,7 +50,8 @@ declare const lookupAznsAddresses: (_config: Config, addresses: string[]) => Pro
|
|
|
49
50
|
* Looks up the on-chain ENS domains for some addresses.
|
|
50
51
|
*/
|
|
51
52
|
declare const lookupEnsAddresses: (config: Config, addresses: string[]) => Promise<OnChainIds>;
|
|
52
|
-
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/util/namesToAddresses.d.ts
|
|
53
55
|
declare const resolveNames: (config: Config, names: string[]) => Promise<ResolvedNames>;
|
|
54
56
|
/**
|
|
55
57
|
* Looks up the addresses for some azns (azero.id) domains.
|
|
@@ -60,24 +62,28 @@ declare const resolveAznsNames: (_config: Config, names: string[]) => Promise<Re
|
|
|
60
62
|
* Looks up the addresses for some ens (ens.domains) domains.
|
|
61
63
|
*/
|
|
62
64
|
declare const resolveEnsNames: (config: Config, names: string[]) => Promise<ResolvedNames>;
|
|
63
|
-
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/util/isPotentialAzns.d.ts
|
|
64
67
|
/** @deprecated */
|
|
65
68
|
declare const isPotentialAzns: (_name?: string) => boolean;
|
|
66
|
-
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/util/isPotentialEns.d.ts
|
|
67
71
|
/** dot separated string e.g. `ens.eth` or `hello.lol` */
|
|
68
72
|
declare const isPotentialEns: (name?: string) => boolean;
|
|
69
|
-
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/index.d.ts
|
|
70
75
|
declare class OnChainId {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
#private;
|
|
77
|
+
constructor(config: OptionalConfig);
|
|
78
|
+
resolveNames: (...args: DropFirst<Parameters<typeof resolveNames>>) => Promise<ResolvedNames>;
|
|
79
|
+
resolveEnsNames: (...args: DropFirst<Parameters<typeof resolveEnsNames>>) => Promise<ResolvedNames>;
|
|
80
|
+
/** @deprecated */
|
|
81
|
+
resolveAznsNames: (...args: DropFirst<Parameters<typeof resolveAznsNames>>) => Promise<ResolvedNames>;
|
|
82
|
+
lookupAddresses: (...args: DropFirst<Parameters<typeof lookupAddresses>>) => Promise<OnChainIds>;
|
|
83
|
+
/** @deprecated */
|
|
84
|
+
lookupEnsAddresses: (...args: DropFirst<Parameters<typeof lookupEnsAddresses>>) => Promise<OnChainIds>;
|
|
85
|
+
lookupAznsAddresses: (...args: DropFirst<Parameters<typeof lookupAznsAddresses>>) => Promise<OnChainIds>;
|
|
81
86
|
}
|
|
82
|
-
|
|
87
|
+
//#endregion
|
|
83
88
|
export { type NsLookupType, OnChainId, type Config as OnChainIdConfig, type OnChainIds, type ResolvedNames, isPotentialAzns, isPotentialEns };
|
|
89
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/util/types.ts","../src/util/addressesToNames.ts","../src/util/namesToAddresses.ts","../src/util/isPotentialAzns.ts","../src/util/isPotentialEns.ts","../src/index.ts"],"mappings":";;KAMY;EACV,YAAY;EACZ,MAAM;EACN,SAAS;;;KAIC,aAAa;;KAGb,gBAAgB,qBAAqB;;KAGrC;;;;KAKA;EACV,iBAAiB;;EAEjB;;EAGA;;EAEA;;EAEA;;KAGU;KAIA,iBAAiB,KAAK,QAAQ,wBACxC,QAAQ,KAAK,QAAQ;;;;;;;KAQX,UAAU,uBAAuB,6BAA6B,KAAK;;;;;;;cCzClE,kBAAe,QAAkB,QAAM,wBAAwB,QAAQ;;;;;cAoBvE,sBAAmB,SACrB,QAAM,wBAEd,QAAQ;;;;cASE,qBAAkB,QACrB,QAAM,wBAEb,QAAQ;;;cCtCE,eAAY,QAAkB,QAAM,oBAAoB,QAAQ;;;;;cAwBhE,mBAAgB,SAAa,QAAM,oBAAoB,QAAQ;;;;cAS/D,kBAAe,QAAkB,QAAM,oBAAoB,QAAQ;;;;cCtCnE,kBAAe;;;;cCAf,iBAAc;;;cCYd;;EAGX,YAAY,QAAQ;EAOpB,kBAAY,MAAa,UAAU,kBAAkB,mBAAc,QAA1C;EAEzB,qBAAe,MAAa,UAAU,kBAAkB,sBAAiB,QAA7C;;EAG5B,sBAAgB,MAAa,UAAU,kBAAkB,uBAAkB,QAA9C;EAG7B,qBAAe,MAAa,UAAU,kBAAkB,sBAAiB,QAA7C;;EAG5B,wBAAkB,MAAa,UAAU,kBAAkB,yBAAoB,QAAhD;EAE/B,yBAAmB,MAAa,UAAU,kBAAkB,0BAAqB,QAAjD"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { IChainConnectorDot, IChainConnectorEth, IChainConnectorSol } from
|
|
2
|
-
|
|
1
|
+
import { IChainConnectorDot, IChainConnectorEth, IChainConnectorSol } from "@talismn/chain-connectors";
|
|
2
|
+
//#region src/util/types.d.ts
|
|
3
3
|
type ChainConnectors = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
substrate?: IChainConnectorDot;
|
|
5
|
+
evm?: IChainConnectorEth;
|
|
6
|
+
solana?: IChainConnectorSol;
|
|
7
7
|
};
|
|
8
8
|
/** A map of addresses to their on-chain ids. */
|
|
9
9
|
type OnChainIds = Map<string, string | null>;
|
|
@@ -15,15 +15,15 @@ type NsLookupType = "ens" | "azns";
|
|
|
15
15
|
* Used as the first parameter to all `namesToAddresses`/`addressesToNames` functions.
|
|
16
16
|
*/
|
|
17
17
|
type Config = {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
18
|
+
chainConnectors: ChainConnectors;
|
|
19
|
+
/** Used for ens lookups */
|
|
20
|
+
networkIdEthereum: string;
|
|
21
|
+
/** @deprecated */
|
|
22
|
+
registryAlephZero?: unknown;
|
|
23
|
+
/** @deprecated */
|
|
24
|
+
chainIdAlephZero?: string;
|
|
25
|
+
/** @deprecated */
|
|
26
|
+
aznsSupportedChainIdAlephZero?: string;
|
|
27
27
|
};
|
|
28
28
|
type OptionalConfigParams = "chainIdAlephZero" | "aznsSupportedChainIdAlephZero" | "networkIdEthereum";
|
|
29
29
|
type OptionalConfig = Omit<Config, OptionalConfigParams> & Partial<Pick<Config, OptionalConfigParams>>;
|
|
@@ -34,7 +34,8 @@ type OptionalConfig = Omit<Config, OptionalConfigParams> & Partial<Pick<Config,
|
|
|
34
34
|
* type DropFirstParams = DropFirst<AllParams> // evaluates to ["two", "three"]
|
|
35
35
|
*/
|
|
36
36
|
type DropFirst<T extends unknown[]> = T extends [unknown, ...infer U] ? U : never;
|
|
37
|
-
|
|
37
|
+
//#endregion
|
|
38
|
+
//#region src/util/addressesToNames.d.ts
|
|
38
39
|
/**
|
|
39
40
|
* Looks up the on-chain identifiers for some addresses.
|
|
40
41
|
* Supports ENS.
|
|
@@ -49,7 +50,8 @@ declare const lookupAznsAddresses: (_config: Config, addresses: string[]) => Pro
|
|
|
49
50
|
* Looks up the on-chain ENS domains for some addresses.
|
|
50
51
|
*/
|
|
51
52
|
declare const lookupEnsAddresses: (config: Config, addresses: string[]) => Promise<OnChainIds>;
|
|
52
|
-
|
|
53
|
+
//#endregion
|
|
54
|
+
//#region src/util/namesToAddresses.d.ts
|
|
53
55
|
declare const resolveNames: (config: Config, names: string[]) => Promise<ResolvedNames>;
|
|
54
56
|
/**
|
|
55
57
|
* Looks up the addresses for some azns (azero.id) domains.
|
|
@@ -60,24 +62,28 @@ declare const resolveAznsNames: (_config: Config, names: string[]) => Promise<Re
|
|
|
60
62
|
* Looks up the addresses for some ens (ens.domains) domains.
|
|
61
63
|
*/
|
|
62
64
|
declare const resolveEnsNames: (config: Config, names: string[]) => Promise<ResolvedNames>;
|
|
63
|
-
|
|
65
|
+
//#endregion
|
|
66
|
+
//#region src/util/isPotentialAzns.d.ts
|
|
64
67
|
/** @deprecated */
|
|
65
68
|
declare const isPotentialAzns: (_name?: string) => boolean;
|
|
66
|
-
|
|
69
|
+
//#endregion
|
|
70
|
+
//#region src/util/isPotentialEns.d.ts
|
|
67
71
|
/** dot separated string e.g. `ens.eth` or `hello.lol` */
|
|
68
72
|
declare const isPotentialEns: (name?: string) => boolean;
|
|
69
|
-
|
|
73
|
+
//#endregion
|
|
74
|
+
//#region src/index.d.ts
|
|
70
75
|
declare class OnChainId {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
76
|
+
#private;
|
|
77
|
+
constructor(config: OptionalConfig);
|
|
78
|
+
resolveNames: (...args: DropFirst<Parameters<typeof resolveNames>>) => Promise<ResolvedNames>;
|
|
79
|
+
resolveEnsNames: (...args: DropFirst<Parameters<typeof resolveEnsNames>>) => Promise<ResolvedNames>;
|
|
80
|
+
/** @deprecated */
|
|
81
|
+
resolveAznsNames: (...args: DropFirst<Parameters<typeof resolveAznsNames>>) => Promise<ResolvedNames>;
|
|
82
|
+
lookupAddresses: (...args: DropFirst<Parameters<typeof lookupAddresses>>) => Promise<OnChainIds>;
|
|
83
|
+
/** @deprecated */
|
|
84
|
+
lookupEnsAddresses: (...args: DropFirst<Parameters<typeof lookupEnsAddresses>>) => Promise<OnChainIds>;
|
|
85
|
+
lookupAznsAddresses: (...args: DropFirst<Parameters<typeof lookupAznsAddresses>>) => Promise<OnChainIds>;
|
|
81
86
|
}
|
|
82
|
-
|
|
87
|
+
//#endregion
|
|
83
88
|
export { type NsLookupType, OnChainId, type Config as OnChainIdConfig, type OnChainIds, type ResolvedNames, isPotentialAzns, isPotentialEns };
|
|
89
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/util/types.ts","../src/util/addressesToNames.ts","../src/util/namesToAddresses.ts","../src/util/isPotentialAzns.ts","../src/util/isPotentialEns.ts","../src/index.ts"],"mappings":";;KAMY;EACV,YAAY;EACZ,MAAM;EACN,SAAS;;;KAIC,aAAa;;KAGb,gBAAgB,qBAAqB;;KAGrC;;;;KAKA;EACV,iBAAiB;;EAEjB;;EAGA;;EAEA;;EAEA;;KAGU;KAIA,iBAAiB,KAAK,QAAQ,wBACxC,QAAQ,KAAK,QAAQ;;;;;;;KAQX,UAAU,uBAAuB,6BAA6B,KAAK;;;;;;;cCzClE,kBAAe,QAAkB,QAAM,wBAAwB,QAAQ;;;;;cAoBvE,sBAAmB,SACrB,QAAM,wBAEd,QAAQ;;;;cASE,qBAAkB,QACrB,QAAM,wBAEb,QAAQ;;;cCtCE,eAAY,QAAkB,QAAM,oBAAoB,QAAQ;;;;;cAwBhE,mBAAgB,SAAa,QAAM,oBAAoB,QAAQ;;;;cAS/D,kBAAe,QAAkB,QAAM,oBAAoB,QAAQ;;;;cCtCnE,kBAAe;;;;cCAf,iBAAc;;;cCYd;;EAGX,YAAY,QAAQ;EAOpB,kBAAY,MAAa,UAAU,kBAAkB,mBAAc,QAA1C;EAEzB,qBAAe,MAAa,UAAU,kBAAkB,sBAAiB,QAA7C;;EAG5B,sBAAgB,MAAa,UAAU,kBAAkB,uBAAkB,QAA9C;EAG7B,qBAAe,MAAa,UAAU,kBAAkB,sBAAiB,QAA7C;;EAG5B,wBAAkB,MAAa,UAAU,kBAAkB,yBAAoB,QAAhD;EAE/B,yBAAmB,MAAa,UAAU,kBAAkB,0BAAqB,QAAjD"}
|
package/dist/index.js
CHANGED
|
@@ -1,228 +1,149 @@
|
|
|
1
|
-
"
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
//#region \0rolldown/runtime.js
|
|
2
3
|
var __create = Object.create;
|
|
3
4
|
var __defProp = Object.defineProperty;
|
|
4
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
7
|
var __getProtoOf = Object.getPrototypeOf;
|
|
7
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
9
|
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
19
18
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
var package_default = {
|
|
47
|
-
name: "@talismn/on-chain-id",
|
|
48
|
-
version: "0.2.11",
|
|
49
|
-
author: "Talisman",
|
|
50
|
-
homepage: "https://talisman.xyz",
|
|
51
|
-
license: "GPL-3.0-or-later",
|
|
52
|
-
publishConfig: {
|
|
53
|
-
access: "public"
|
|
54
|
-
},
|
|
55
|
-
repository: {
|
|
56
|
-
directory: "packages/on-chain-id",
|
|
57
|
-
type: "git",
|
|
58
|
-
url: "https://github.com/TalismanSociety/talisman.git"
|
|
59
|
-
},
|
|
60
|
-
main: "./dist/index.js",
|
|
61
|
-
module: "./dist/index.mjs",
|
|
62
|
-
files: [
|
|
63
|
-
"dist"
|
|
64
|
-
],
|
|
65
|
-
engines: {
|
|
66
|
-
node: ">=20"
|
|
67
|
-
},
|
|
68
|
-
scripts: {
|
|
69
|
-
test: "vitest run",
|
|
70
|
-
clean: "rm -rf dist .turbo node_modules",
|
|
71
|
-
build: "tsup --silent",
|
|
72
|
-
typecheck: "tsc --noEmit"
|
|
73
|
-
},
|
|
74
|
-
dependencies: {
|
|
75
|
-
"@talismn/chain-connectors": "workspace:*",
|
|
76
|
-
"@talismn/crypto": "workspace:*",
|
|
77
|
-
"@talismn/util": "workspace:*",
|
|
78
|
-
anylogger: "^1.0.11"
|
|
79
|
-
},
|
|
80
|
-
devDependencies: {
|
|
81
|
-
"@talismn/tsconfig": "workspace:*",
|
|
82
|
-
typescript: "^6.0.3"
|
|
83
|
-
},
|
|
84
|
-
types: "./dist/index.d.ts",
|
|
85
|
-
exports: {
|
|
86
|
-
".": {
|
|
87
|
-
"@talismn/source": "./src/index.ts",
|
|
88
|
-
import: {
|
|
89
|
-
types: "./dist/index.d.mts",
|
|
90
|
-
default: "./dist/index.mjs"
|
|
91
|
-
},
|
|
92
|
-
require: {
|
|
93
|
-
types: "./dist/index.d.ts",
|
|
94
|
-
default: "./dist/index.js"
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
|
|
100
|
-
// src/log.ts
|
|
101
|
-
var log_default = (0, import_anylogger.default)(package_default.name);
|
|
102
|
-
|
|
103
|
-
// src/util/addressesToNames.ts
|
|
104
|
-
var lookupAddresses = async (config, addresses) => {
|
|
105
|
-
const onChainIds = new Map(addresses.map((address) => [address, null]));
|
|
106
|
-
const [ensDomains] = await Promise.all([
|
|
107
|
-
lookupEnsAddresses(config, addresses)
|
|
108
|
-
// add more providers here
|
|
109
|
-
]);
|
|
110
|
-
ensDomains.forEach((domain, address) => {
|
|
111
|
-
if (!domain) return;
|
|
112
|
-
onChainIds.set(address, domain);
|
|
113
|
-
});
|
|
114
|
-
return onChainIds;
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
23
|
+
//#endregion
|
|
24
|
+
let _talismn_crypto = require("@talismn/crypto");
|
|
25
|
+
let anylogger = require("anylogger");
|
|
26
|
+
anylogger = __toESM(anylogger);
|
|
27
|
+
let _talismn_util = require("@talismn/util");
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/log.ts
|
|
30
|
+
var log_default = (0, anylogger.default)("@talismn/on-chain-id");
|
|
31
|
+
//#endregion
|
|
32
|
+
//#region src/util/addressesToNames.ts
|
|
33
|
+
/**
|
|
34
|
+
* Looks up the on-chain identifiers for some addresses.
|
|
35
|
+
* Supports ENS.
|
|
36
|
+
*/
|
|
37
|
+
const lookupAddresses = async (config, addresses) => {
|
|
38
|
+
const onChainIds = new Map(addresses.map((address) => [address, null]));
|
|
39
|
+
const [ensDomains] = await Promise.all([lookupEnsAddresses(config, addresses)]);
|
|
40
|
+
ensDomains.forEach((domain, address) => {
|
|
41
|
+
if (!domain) return;
|
|
42
|
+
onChainIds.set(address, domain);
|
|
43
|
+
});
|
|
44
|
+
return onChainIds;
|
|
115
45
|
};
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
46
|
+
/**
|
|
47
|
+
* Looks up the on-chain AZNS domains for some addresses.
|
|
48
|
+
* @deprecated
|
|
49
|
+
*/
|
|
50
|
+
const lookupAznsAddresses = async (_config, addresses) => {
|
|
51
|
+
return new Promise((resolve) => resolve(new Map(addresses.map((address) => [address, null]))));
|
|
120
52
|
};
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
results.forEach((result) => result.status === "rejected" && log_default.warn(result.reason.message));
|
|
143
|
-
return onChainIds;
|
|
53
|
+
/**
|
|
54
|
+
* Looks up the on-chain ENS domains for some addresses.
|
|
55
|
+
*/
|
|
56
|
+
const lookupEnsAddresses = async (config, addresses) => {
|
|
57
|
+
const onChainIds = new Map(addresses.map((address) => [address, null]));
|
|
58
|
+
const client = await config.chainConnectors.evm?.getPublicClientForEvmNetwork(config.networkIdEthereum);
|
|
59
|
+
if (!client) {
|
|
60
|
+
log_default.warn(`Could not find Ethereum client in OnChainId::lookupEnsAddresses`);
|
|
61
|
+
return onChainIds;
|
|
62
|
+
}
|
|
63
|
+
(await Promise.allSettled(addresses.map(async (address) => {
|
|
64
|
+
if (!(0, _talismn_crypto.isEthereumAddress)(address)) return;
|
|
65
|
+
try {
|
|
66
|
+
const domain = await client.getEnsName({ address });
|
|
67
|
+
domain !== null && onChainIds.set(address, domain);
|
|
68
|
+
} catch (cause) {
|
|
69
|
+
const errorMessage = cause?.shortMessage ?? String(cause);
|
|
70
|
+
throw new Error(`Failed to resolve ENS domain for address '${address}': ${errorMessage}`);
|
|
71
|
+
}
|
|
72
|
+
}))).forEach((result) => result.status === "rejected" && log_default.warn(result.reason.message));
|
|
73
|
+
return onChainIds;
|
|
144
74
|
};
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
const [address, lookupType] = lookup;
|
|
162
|
-
if (!address) return;
|
|
163
|
-
resolvedNames.set(name, [address, lookupType]);
|
|
164
|
-
});
|
|
165
|
-
return resolvedNames;
|
|
75
|
+
//#endregion
|
|
76
|
+
//#region src/util/isPotentialEns.ts
|
|
77
|
+
/** dot separated string e.g. `ens.eth` or `hello.lol` */
|
|
78
|
+
const isPotentialEns = (name) => typeof name === "string" && /^.+\..+$/.test(name);
|
|
79
|
+
//#endregion
|
|
80
|
+
//#region src/util/namesToAddresses.ts
|
|
81
|
+
const resolveNames = async (config, names) => {
|
|
82
|
+
const resolvedNames = new Map(names.map((name) => [name, null]));
|
|
83
|
+
const [ensNames] = await Promise.all([resolveEnsNames(config, names)]);
|
|
84
|
+
ensNames.forEach((lookup, name) => {
|
|
85
|
+
if (!lookup) return;
|
|
86
|
+
const [address, lookupType] = lookup;
|
|
87
|
+
if (!address) return;
|
|
88
|
+
resolvedNames.set(name, [address, lookupType]);
|
|
89
|
+
});
|
|
90
|
+
return resolvedNames;
|
|
166
91
|
};
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
92
|
+
/**
|
|
93
|
+
* Looks up the addresses for some azns (azero.id) domains.
|
|
94
|
+
* @deprecated
|
|
95
|
+
*/
|
|
96
|
+
const resolveAznsNames = (_config, names) => {
|
|
97
|
+
return new Promise((resolve) => resolve(new Map(names.map((name) => [name, null]))));
|
|
171
98
|
};
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
throw new Error(`Failed to resolve address for ens domain '${name}'`, { cause });
|
|
194
|
-
}
|
|
195
|
-
})
|
|
196
|
-
);
|
|
197
|
-
results.forEach((result) => result.status === "rejected" && log_default.warn(result.reason));
|
|
198
|
-
return resolvedNames;
|
|
99
|
+
/**
|
|
100
|
+
* Looks up the addresses for some ens (ens.domains) domains.
|
|
101
|
+
*/
|
|
102
|
+
const resolveEnsNames = async (config, names) => {
|
|
103
|
+
const resolvedNames = new Map(names.map((name) => [name, null]));
|
|
104
|
+
if (names.every((name) => !isPotentialEns(name))) return resolvedNames;
|
|
105
|
+
const client = await config.chainConnectors.evm?.getPublicClientForEvmNetwork(config.networkIdEthereum);
|
|
106
|
+
if (!client) {
|
|
107
|
+
log_default.warn(`Could not find Ethereum client in OnChainId::resolveNames`);
|
|
108
|
+
return resolvedNames;
|
|
109
|
+
}
|
|
110
|
+
(await Promise.allSettled(names.map(async (name) => {
|
|
111
|
+
if (!isPotentialEns(name)) return;
|
|
112
|
+
try {
|
|
113
|
+
const address = await Promise.race([client.getEnsAddress({ name }), (0, _talismn_util.throwAfter)(1e4, "Timeout")]);
|
|
114
|
+
address !== null && resolvedNames.set(name, [address, "ens"]);
|
|
115
|
+
} catch (cause) {
|
|
116
|
+
throw new Error(`Failed to resolve address for ens domain '${name}'`, { cause });
|
|
117
|
+
}
|
|
118
|
+
}))).forEach((result) => result.status === "rejected" && log_default.warn(result.reason));
|
|
119
|
+
return resolvedNames;
|
|
199
120
|
};
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
121
|
+
//#endregion
|
|
122
|
+
//#region src/util/isPotentialAzns.ts
|
|
123
|
+
/** @deprecated */
|
|
124
|
+
const isPotentialAzns = (_name) => false;
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/index.ts
|
|
205
127
|
var OnChainId = class {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
128
|
+
#config;
|
|
129
|
+
constructor(config) {
|
|
130
|
+
this.#config = {
|
|
131
|
+
...config,
|
|
132
|
+
networkIdEthereum: config.networkIdEthereum ?? "1"
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
resolveNames = (...args) => resolveNames(this.#config, ...args);
|
|
136
|
+
resolveEnsNames = (...args) => resolveEnsNames(this.#config, ...args);
|
|
137
|
+
/** @deprecated */
|
|
138
|
+
resolveAznsNames = (...args) => resolveAznsNames(this.#config, ...args);
|
|
139
|
+
lookupAddresses = (...args) => lookupAddresses(this.#config, ...args);
|
|
140
|
+
/** @deprecated */
|
|
141
|
+
lookupEnsAddresses = (...args) => lookupEnsAddresses(this.#config, ...args);
|
|
142
|
+
lookupAznsAddresses = (...args) => lookupAznsAddresses(this.#config, ...args);
|
|
221
143
|
};
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
});
|
|
144
|
+
//#endregion
|
|
145
|
+
exports.OnChainId = OnChainId;
|
|
146
|
+
exports.isPotentialAzns = isPotentialAzns;
|
|
147
|
+
exports.isPotentialEns = isPotentialEns;
|
|
148
|
+
|
|
228
149
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/util/addressesToNames.ts","../src/log.ts","../package.json","../src/util/namesToAddresses.ts","../src/util/isPotentialEns.ts","../src/util/isPotentialAzns.ts"],"sourcesContent":["import { lookupAddresses, lookupAznsAddresses, lookupEnsAddresses } from \"./util/addressesToNames\"\nimport { resolveAznsNames, resolveEnsNames, resolveNames } from \"./util/namesToAddresses\"\nimport type { Config, DropFirst, OptionalConfig } from \"./util/types\"\n\nexport * from \"./util/isPotentialAzns\"\nexport * from \"./util/isPotentialEns\"\nexport type {\n Config as OnChainIdConfig,\n NsLookupType,\n OnChainIds,\n ResolvedNames,\n} from \"./util/types\"\n\nexport class OnChainId {\n #config: Config\n\n constructor(config: OptionalConfig) {\n this.#config = {\n ...config,\n networkIdEthereum: config.networkIdEthereum ?? \"1\",\n }\n }\n\n resolveNames = (...args: DropFirst<Parameters<typeof resolveNames>>) =>\n resolveNames(this.#config, ...args)\n resolveEnsNames = (...args: DropFirst<Parameters<typeof resolveEnsNames>>) =>\n resolveEnsNames(this.#config, ...args)\n /** @deprecated */\n resolveAznsNames = (...args: DropFirst<Parameters<typeof resolveAznsNames>>) =>\n resolveAznsNames(this.#config, ...args)\n\n lookupAddresses = (...args: DropFirst<Parameters<typeof lookupAddresses>>) =>\n lookupAddresses(this.#config, ...args)\n /** @deprecated */\n lookupEnsAddresses = (...args: DropFirst<Parameters<typeof lookupEnsAddresses>>) =>\n lookupEnsAddresses(this.#config, ...args)\n lookupAznsAddresses = (...args: DropFirst<Parameters<typeof lookupAznsAddresses>>) =>\n lookupAznsAddresses(this.#config, ...args)\n}\n","import { isEthereumAddress } from \"@talismn/crypto\"\n\nimport log from \"../log\"\nimport type { Config, OnChainIds } from \"./types\"\n\n/**\n * Looks up the on-chain identifiers for some addresses.\n * Supports ENS.\n */\nexport const lookupAddresses = async (config: Config, addresses: string[]): Promise<OnChainIds> => {\n const onChainIds: OnChainIds = new Map(addresses.map((address) => [address, null]))\n\n const [ensDomains] = await Promise.all([\n lookupEnsAddresses(config, addresses),\n // add more providers here\n ])\n\n ensDomains.forEach((domain, address) => {\n if (!domain) return\n onChainIds.set(address, domain)\n })\n\n return onChainIds\n}\n\n/**\n * Looks up the on-chain AZNS domains for some addresses.\n * @deprecated\n */\nexport const lookupAznsAddresses = async (\n _config: Config,\n addresses: string[]\n): Promise<OnChainIds> => {\n return new Promise<OnChainIds>((resolve) =>\n resolve(new Map(addresses.map((address) => [address, null])))\n )\n}\n\n/**\n * Looks up the on-chain ENS domains for some addresses.\n */\nexport const lookupEnsAddresses = async (\n config: Config,\n addresses: string[]\n): Promise<OnChainIds> => {\n const onChainIds: OnChainIds = new Map(addresses.map((address) => [address, null]))\n\n const client = await config.chainConnectors.evm?.getPublicClientForEvmNetwork(\n config.networkIdEthereum\n )\n if (!client) {\n log.warn(`Could not find Ethereum client in OnChainId::lookupEnsAddresses`)\n return onChainIds\n }\n\n const results = await Promise.allSettled(\n addresses.map(async (address) => {\n // no need to do ENS lookup for polkadot addresses\n if (!isEthereumAddress(address)) return\n\n try {\n const domain = await client.getEnsName({ address })\n domain !== null && onChainIds.set(address, domain)\n } catch (cause) {\n const errorMessage = (cause as { shortMessage?: string })?.shortMessage ?? String(cause)\n throw new Error(`Failed to resolve ENS domain for address '${address}': ${errorMessage}`)\n }\n })\n )\n // biome-ignore lint/suspicious/useIterableCallbackReturn: legacy\n results.forEach((result) => result.status === \"rejected\" && log.warn(result.reason.message))\n\n return onChainIds\n}\n","import anylogger from \"anylogger\"\n\nimport packageJson from \"../package.json\"\n\nexport default anylogger(packageJson.name)\n","{\n \"name\": \"@talismn/on-chain-id\",\n \"version\": \"0.2.11\",\n \"author\": \"Talisman\",\n \"homepage\": \"https://talisman.xyz\",\n \"license\": \"GPL-3.0-or-later\",\n \"publishConfig\": {\n \"access\": \"public\"\n },\n \"repository\": {\n \"directory\": \"packages/on-chain-id\",\n \"type\": \"git\",\n \"url\": \"https://github.com/TalismanSociety/talisman.git\"\n },\n \"main\": \"./dist/index.js\",\n \"module\": \"./dist/index.mjs\",\n \"files\": [\n \"dist\"\n ],\n \"engines\": {\n \"node\": \">=20\"\n },\n \"scripts\": {\n \"test\": \"vitest run\",\n \"clean\": \"rm -rf dist .turbo node_modules\",\n \"build\": \"tsup --silent\",\n \"typecheck\": \"tsc --noEmit\"\n },\n \"dependencies\": {\n \"@talismn/chain-connectors\": \"workspace:*\",\n \"@talismn/crypto\": \"workspace:*\",\n \"@talismn/util\": \"workspace:*\",\n \"anylogger\": \"^1.0.11\"\n },\n \"devDependencies\": {\n \"@talismn/tsconfig\": \"workspace:*\",\n \"typescript\": \"^6.0.3\"\n },\n \"types\": \"./dist/index.d.ts\",\n \"exports\": {\n \".\": {\n \"@talismn/source\": \"./src/index.ts\",\n \"import\": {\n \"types\": \"./dist/index.d.mts\",\n \"default\": \"./dist/index.mjs\"\n },\n \"require\": {\n \"types\": \"./dist/index.d.ts\",\n \"default\": \"./dist/index.js\"\n }\n }\n }\n}\n","import { throwAfter } from \"@talismn/util\"\n\nimport log from \"../log\"\nimport { isPotentialEns } from \"./isPotentialEns\"\nimport type { Config, ResolvedNames } from \"./types\"\n\nexport const resolveNames = async (config: Config, names: string[]): Promise<ResolvedNames> => {\n const resolvedNames: ResolvedNames = new Map(names.map((name) => [name, null]))\n\n const [ensNames] = await Promise.all([\n resolveEnsNames(config, names),\n // add more providers here\n ])\n\n ensNames.forEach((lookup, name) => {\n if (!lookup) return\n\n const [address, lookupType] = lookup\n if (!address) return\n\n resolvedNames.set(name, [address, lookupType])\n })\n\n return resolvedNames\n}\n\n/**\n * Looks up the addresses for some azns (azero.id) domains.\n * @deprecated\n */\nexport const resolveAznsNames = (_config: Config, names: string[]): Promise<ResolvedNames> => {\n return new Promise<ResolvedNames>((resolve) =>\n resolve(new Map(names.map((name) => [name, null])))\n )\n}\n\n/**\n * Looks up the addresses for some ens (ens.domains) domains.\n */\nexport const resolveEnsNames = async (config: Config, names: string[]): Promise<ResolvedNames> => {\n const resolvedNames: ResolvedNames = new Map(names.map((name) => [name, null]))\n\n if (names.every((name) => !isPotentialEns(name))) return resolvedNames\n\n const client = await config.chainConnectors.evm?.getPublicClientForEvmNetwork(\n config.networkIdEthereum\n )\n if (!client) {\n log.warn(`Could not find Ethereum client in OnChainId::resolveNames`)\n return resolvedNames\n }\n\n const results = await Promise.allSettled(\n names.map(async (name) => {\n if (!isPotentialEns(name)) return\n\n try {\n const address = await Promise.race([\n // this hangs forever in some cases (ex: try agyle.e first, then agyle.et => hangs) - couldn't explain it\n client.getEnsAddress({ name }),\n throwAfter(10_000, \"Timeout\"),\n ])\n address !== null && resolvedNames.set(name, [address, \"ens\"])\n } catch (cause) {\n throw new Error(`Failed to resolve address for ens domain '${name}'`, { cause })\n }\n })\n )\n\n // biome-ignore lint/suspicious/useIterableCallbackReturn: legacy\n results.forEach((result) => result.status === \"rejected\" && log.warn(result.reason))\n\n return resolvedNames\n}\n","/** dot separated string e.g. `ens.eth` or `hello.lol` */\nexport const isPotentialEns = (name?: string) => typeof name === \"string\" && /^.+\\..+$/.test(name)\n","/** @deprecated */\nexport const isPotentialAzns = (_name?: string) => false\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,oBAAkC;;;ACAlC,uBAAsB;;;ACAtB;AAAA,EACE,MAAQ;AAAA,EACR,SAAW;AAAA,EACX,QAAU;AAAA,EACV,UAAY;AAAA,EACZ,SAAW;AAAA,EACX,eAAiB;AAAA,IACf,QAAU;AAAA,EACZ;AAAA,EACA,YAAc;AAAA,IACZ,WAAa;AAAA,IACb,MAAQ;AAAA,IACR,KAAO;AAAA,EACT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SAAK,UAAU;AAAA,MACb,GAAG;AAAA,MACH,mBAAmB,OAAO,qBAAqB;AAAA,IACjD;AAAA,EACF;AAAA,EAEA,eAAe,IAAI,SACjB,aAAa,KAAK,SAAS,GAAG,IAAI;AAAA,EACpC,kBAAkB,IAAI,SACpB,gBAAgB,KAAK,SAAS,GAAG,IAAI;AAAA;AAAA,EAEvC,mBAAmB,IAAI,SACrB,iBAAiB,KAAK,SAAS,GAAG,IAAI;AAAA,EAExC,kBAAkB,IAAI,SACpB,gBAAgB,KAAK,SAAS,GAAG,IAAI;AAAA;AAAA,EAEvC,qBAAqB,IAAI,SACvB,mBAAmB,KAAK,SAAS,GAAG,IAAI;AAAA,EAC1C,sBAAsB,IAAI,SACxB,oBAAoB,KAAK,SAAS,GAAG,IAAI;AAC7C;","names":["anylogger"]}
|
|
1
|
+
{"version":3,"file":"index.js","names":["packageJson.name","log","log","#config"],"sources":["../package.json","../src/log.ts","../src/util/addressesToNames.ts","../src/util/isPotentialEns.ts","../src/util/namesToAddresses.ts","../src/util/isPotentialAzns.ts","../src/index.ts"],"sourcesContent":["","import anylogger from \"anylogger\"\n\nimport packageJson from \"../package.json\"\n\nexport default anylogger(packageJson.name)\n","import { isEthereumAddress } from \"@talismn/crypto\"\n\nimport log from \"../log\"\nimport type { Config, OnChainIds } from \"./types\"\n\n/**\n * Looks up the on-chain identifiers for some addresses.\n * Supports ENS.\n */\nexport const lookupAddresses = async (config: Config, addresses: string[]): Promise<OnChainIds> => {\n const onChainIds: OnChainIds = new Map(addresses.map((address) => [address, null]))\n\n const [ensDomains] = await Promise.all([\n lookupEnsAddresses(config, addresses),\n // add more providers here\n ])\n\n ensDomains.forEach((domain, address) => {\n if (!domain) return\n onChainIds.set(address, domain)\n })\n\n return onChainIds\n}\n\n/**\n * Looks up the on-chain AZNS domains for some addresses.\n * @deprecated\n */\nexport const lookupAznsAddresses = async (\n _config: Config,\n addresses: string[]\n): Promise<OnChainIds> => {\n return new Promise<OnChainIds>((resolve) =>\n resolve(new Map(addresses.map((address) => [address, null])))\n )\n}\n\n/**\n * Looks up the on-chain ENS domains for some addresses.\n */\nexport const lookupEnsAddresses = async (\n config: Config,\n addresses: string[]\n): Promise<OnChainIds> => {\n const onChainIds: OnChainIds = new Map(addresses.map((address) => [address, null]))\n\n const client = await config.chainConnectors.evm?.getPublicClientForEvmNetwork(\n config.networkIdEthereum\n )\n if (!client) {\n log.warn(`Could not find Ethereum client in OnChainId::lookupEnsAddresses`)\n return onChainIds\n }\n\n const results = await Promise.allSettled(\n addresses.map(async (address) => {\n // no need to do ENS lookup for polkadot addresses\n if (!isEthereumAddress(address)) return\n\n try {\n const domain = await client.getEnsName({ address })\n domain !== null && onChainIds.set(address, domain)\n } catch (cause) {\n const errorMessage = (cause as { shortMessage?: string })?.shortMessage ?? String(cause)\n throw new Error(`Failed to resolve ENS domain for address '${address}': ${errorMessage}`)\n }\n })\n )\n // biome-ignore lint/suspicious/useIterableCallbackReturn: legacy\n results.forEach((result) => result.status === \"rejected\" && log.warn(result.reason.message))\n\n return onChainIds\n}\n","/** dot separated string e.g. `ens.eth` or `hello.lol` */\nexport const isPotentialEns = (name?: string) => typeof name === \"string\" && /^.+\\..+$/.test(name)\n","import { throwAfter } from \"@talismn/util\"\n\nimport log from \"../log\"\nimport { isPotentialEns } from \"./isPotentialEns\"\nimport type { Config, ResolvedNames } from \"./types\"\n\nexport const resolveNames = async (config: Config, names: string[]): Promise<ResolvedNames> => {\n const resolvedNames: ResolvedNames = new Map(names.map((name) => [name, null]))\n\n const [ensNames] = await Promise.all([\n resolveEnsNames(config, names),\n // add more providers here\n ])\n\n ensNames.forEach((lookup, name) => {\n if (!lookup) return\n\n const [address, lookupType] = lookup\n if (!address) return\n\n resolvedNames.set(name, [address, lookupType])\n })\n\n return resolvedNames\n}\n\n/**\n * Looks up the addresses for some azns (azero.id) domains.\n * @deprecated\n */\nexport const resolveAznsNames = (_config: Config, names: string[]): Promise<ResolvedNames> => {\n return new Promise<ResolvedNames>((resolve) =>\n resolve(new Map(names.map((name) => [name, null])))\n )\n}\n\n/**\n * Looks up the addresses for some ens (ens.domains) domains.\n */\nexport const resolveEnsNames = async (config: Config, names: string[]): Promise<ResolvedNames> => {\n const resolvedNames: ResolvedNames = new Map(names.map((name) => [name, null]))\n\n if (names.every((name) => !isPotentialEns(name))) return resolvedNames\n\n const client = await config.chainConnectors.evm?.getPublicClientForEvmNetwork(\n config.networkIdEthereum\n )\n if (!client) {\n log.warn(`Could not find Ethereum client in OnChainId::resolveNames`)\n return resolvedNames\n }\n\n const results = await Promise.allSettled(\n names.map(async (name) => {\n if (!isPotentialEns(name)) return\n\n try {\n const address = await Promise.race([\n // this hangs forever in some cases (ex: try agyle.e first, then agyle.et => hangs) - couldn't explain it\n client.getEnsAddress({ name }),\n throwAfter(10_000, \"Timeout\"),\n ])\n address !== null && resolvedNames.set(name, [address, \"ens\"])\n } catch (cause) {\n throw new Error(`Failed to resolve address for ens domain '${name}'`, { cause })\n }\n })\n )\n\n // biome-ignore lint/suspicious/useIterableCallbackReturn: legacy\n results.forEach((result) => result.status === \"rejected\" && log.warn(result.reason))\n\n return resolvedNames\n}\n","/** @deprecated */\nexport const isPotentialAzns = (_name?: string) => false\n","import { lookupAddresses, lookupAznsAddresses, lookupEnsAddresses } from \"./util/addressesToNames\"\nimport { resolveAznsNames, resolveEnsNames, resolveNames } from \"./util/namesToAddresses\"\nimport type { Config, DropFirst, OptionalConfig } from \"./util/types\"\n\nexport * from \"./util/isPotentialAzns\"\nexport * from \"./util/isPotentialEns\"\nexport type {\n Config as OnChainIdConfig,\n NsLookupType,\n OnChainIds,\n ResolvedNames,\n} from \"./util/types\"\n\nexport class OnChainId {\n #config: Config\n\n constructor(config: OptionalConfig) {\n this.#config = {\n ...config,\n networkIdEthereum: config.networkIdEthereum ?? \"1\",\n }\n }\n\n resolveNames = (...args: DropFirst<Parameters<typeof resolveNames>>) =>\n resolveNames(this.#config, ...args)\n resolveEnsNames = (...args: DropFirst<Parameters<typeof resolveEnsNames>>) =>\n resolveEnsNames(this.#config, ...args)\n /** @deprecated */\n resolveAznsNames = (...args: DropFirst<Parameters<typeof resolveAznsNames>>) =>\n resolveAznsNames(this.#config, ...args)\n\n lookupAddresses = (...args: DropFirst<Parameters<typeof lookupAddresses>>) =>\n lookupAddresses(this.#config, ...args)\n /** @deprecated */\n lookupEnsAddresses = (...args: DropFirst<Parameters<typeof lookupEnsAddresses>>) =>\n lookupEnsAddresses(this.#config, ...args)\n lookupAznsAddresses = (...args: DropFirst<Parameters<typeof lookupAznsAddresses>>) =>\n lookupAznsAddresses(this.#config, ...args)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACIA,IAAA,eAAA,GAAA,UAAA,QAAA,CAAyBA,sBAAgB;;;;;;;ACKzC,MAAa,kBAAkB,OAAO,QAAgB,cAA6C;CACjG,MAAM,aAAyB,IAAI,IAAI,UAAU,KAAK,YAAY,CAAC,SAAS,IAAI,CAAC,CAAC;CAElF,MAAM,CAAC,cAAc,MAAM,QAAQ,IAAI,CACrC,mBAAmB,QAAQ,SAAS,CAEtC,CAAC;CAED,WAAW,SAAS,QAAQ,YAAY;EACtC,IAAI,CAAC,QAAQ;EACb,WAAW,IAAI,SAAS,MAAM;CAChC,CAAC;CAED,OAAO;AACT;;;;;AAMA,MAAa,sBAAsB,OACjC,SACA,cACwB;CACxB,OAAO,IAAI,SAAqB,YAC9B,QAAQ,IAAI,IAAI,UAAU,KAAK,YAAY,CAAC,SAAS,IAAI,CAAC,CAAC,CAAC,CAC9D;AACF;;;;AAKA,MAAa,qBAAqB,OAChC,QACA,cACwB;CACxB,MAAM,aAAyB,IAAI,IAAI,UAAU,KAAK,YAAY,CAAC,SAAS,IAAI,CAAC,CAAC;CAElF,MAAM,SAAS,MAAM,OAAO,gBAAgB,KAAK,6BAC/C,OAAO,iBACT;CACA,IAAI,CAAC,QAAQ;EACX,YAAI,KAAK,iEAAiE;EAC1E,OAAO;CACT;CAiBA,CAAA,MAf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