web3bio-profile-kit 0.2.5 → 0.2.8
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/dist/types/platform.cjs +0 -14
- package/dist/types/platform.d.ts +0 -14
- package/dist/types/platform.js +0 -14
- package/dist/types/source.cjs +3 -0
- package/dist/types/source.d.ts +3 -0
- package/dist/types/source.js +3 -0
- package/dist/utils/helpers.cjs +45 -45
- package/dist/utils/helpers.js +46 -46
- package/dist/utils/ipfs.cjs +19 -11
- package/dist/utils/ipfs.js +19 -11
- package/dist/utils/network.cjs +22 -20
- package/dist/utils/network.js +22 -20
- package/dist/utils/platform.cjs +3 -140
- package/dist/utils/platform.js +3 -140
- package/dist/utils/resolver.cjs +3 -2
- package/dist/utils/resolver.js +3 -2
- package/dist/utils/source.cjs +15 -1
- package/dist/utils/source.js +15 -1
- package/package.json +14 -15
package/dist/types/platform.cjs
CHANGED
|
@@ -7,8 +7,6 @@
|
|
|
7
7
|
*/
|
|
8
8
|
exports.Platform = void 0;
|
|
9
9
|
(function (Platform) {
|
|
10
|
-
Platform["ailayer"] = "ailayer";
|
|
11
|
-
Platform["alienx"] = "alienx";
|
|
12
10
|
Platform["aptos"] = "aptos";
|
|
13
11
|
Platform["arbitrum"] = "arbitrum";
|
|
14
12
|
Platform["basenames"] = "basenames";
|
|
@@ -23,8 +21,6 @@ exports.Platform = void 0;
|
|
|
23
21
|
Platform["clusters"] = "clusters";
|
|
24
22
|
Platform["coinbase"] = "coinbase";
|
|
25
23
|
Platform["coingecko"] = "coingecko";
|
|
26
|
-
Platform["cosmos"] = "cosmos";
|
|
27
|
-
Platform["cyberconnect"] = "cyberconnect";
|
|
28
24
|
Platform["deepdao"] = "deepdao";
|
|
29
25
|
Platform["degenscore"] = "degenscore";
|
|
30
26
|
Platform["dentity"] = "dentity";
|
|
@@ -33,7 +29,6 @@ exports.Platform = void 0;
|
|
|
33
29
|
Platform["dotbit"] = "dotbit";
|
|
34
30
|
Platform["dns"] = "dns";
|
|
35
31
|
Platform["ecp"] = "ecp";
|
|
36
|
-
Platform["edgeless"] = "edgeless";
|
|
37
32
|
Platform["efp"] = "efp";
|
|
38
33
|
Platform["ens"] = "ens";
|
|
39
34
|
Platform["ethereum"] = "ethereum";
|
|
@@ -55,18 +50,13 @@ exports.Platform = void 0;
|
|
|
55
50
|
Platform["interface"] = "interface";
|
|
56
51
|
Platform["keybase"] = "keybase";
|
|
57
52
|
Platform["lens"] = "lens";
|
|
58
|
-
Platform["lightlink"] = "lightlink";
|
|
59
53
|
Platform["linkedin"] = "linkedin";
|
|
60
54
|
Platform["linea"] = "linea";
|
|
61
55
|
Platform["lobsters"] = "lobsters";
|
|
62
|
-
Platform["manta"] = "manta";
|
|
63
56
|
Platform["matters"] = "matters";
|
|
64
57
|
Platform["medium"] = "medium";
|
|
65
|
-
Platform["merlin"] = "merlin";
|
|
66
58
|
Platform["minds"] = "minds";
|
|
67
|
-
Platform["mint"] = "mint";
|
|
68
59
|
Platform["mirror"] = "mirror";
|
|
69
|
-
Platform["mode"] = "mode";
|
|
70
60
|
Platform["mstdnjp"] = "mstdnjp";
|
|
71
61
|
Platform["near"] = "near";
|
|
72
62
|
Platform["nextid"] = "nextid";
|
|
@@ -88,13 +78,11 @@ exports.Platform = void 0;
|
|
|
88
78
|
Platform["space_id"] = "space_id";
|
|
89
79
|
Platform["stacks"] = "stacks";
|
|
90
80
|
Platform["substack"] = "substack";
|
|
91
|
-
Platform["taiko"] = "taiko";
|
|
92
81
|
Platform["talent"] = "talentprotocol";
|
|
93
82
|
Platform["tally"] = "tally";
|
|
94
83
|
Platform["telegram"] = "telegram";
|
|
95
84
|
Platform["threads"] = "threads";
|
|
96
85
|
Platform["tiktok"] = "tiktok";
|
|
97
|
-
Platform["tomo"] = "tomo";
|
|
98
86
|
Platform["ton"] = "ton";
|
|
99
87
|
Platform["tron"] = "tron";
|
|
100
88
|
Platform["twitter"] = "twitter";
|
|
@@ -109,8 +97,6 @@ exports.Platform = void 0;
|
|
|
109
97
|
Platform["world_id"] = "world_id";
|
|
110
98
|
Platform["xmtp"] = "xmtp";
|
|
111
99
|
Platform["youtube"] = "youtube";
|
|
112
|
-
Platform["zeta"] = "zeta";
|
|
113
|
-
Platform["zkfair"] = "zkfair";
|
|
114
100
|
Platform["zkme"] = "zkme";
|
|
115
101
|
Platform["zora"] = "zora";
|
|
116
102
|
})(exports.Platform || (exports.Platform = {}));
|
package/dist/types/platform.d.ts
CHANGED
|
@@ -4,8 +4,6 @@
|
|
|
4
4
|
* @public
|
|
5
5
|
*/
|
|
6
6
|
export declare enum Platform {
|
|
7
|
-
ailayer = "ailayer",
|
|
8
|
-
alienx = "alienx",
|
|
9
7
|
aptos = "aptos",
|
|
10
8
|
arbitrum = "arbitrum",
|
|
11
9
|
basenames = "basenames",
|
|
@@ -20,8 +18,6 @@ export declare enum Platform {
|
|
|
20
18
|
clusters = "clusters",
|
|
21
19
|
coinbase = "coinbase",
|
|
22
20
|
coingecko = "coingecko",
|
|
23
|
-
cosmos = "cosmos",
|
|
24
|
-
cyberconnect = "cyberconnect",
|
|
25
21
|
deepdao = "deepdao",
|
|
26
22
|
degenscore = "degenscore",
|
|
27
23
|
dentity = "dentity",
|
|
@@ -30,7 +26,6 @@ export declare enum Platform {
|
|
|
30
26
|
dotbit = "dotbit",
|
|
31
27
|
dns = "dns",
|
|
32
28
|
ecp = "ecp",
|
|
33
|
-
edgeless = "edgeless",
|
|
34
29
|
efp = "efp",
|
|
35
30
|
ens = "ens",
|
|
36
31
|
ethereum = "ethereum",
|
|
@@ -52,18 +47,13 @@ export declare enum Platform {
|
|
|
52
47
|
interface = "interface",
|
|
53
48
|
keybase = "keybase",
|
|
54
49
|
lens = "lens",
|
|
55
|
-
lightlink = "lightlink",
|
|
56
50
|
linkedin = "linkedin",
|
|
57
51
|
linea = "linea",
|
|
58
52
|
lobsters = "lobsters",
|
|
59
|
-
manta = "manta",
|
|
60
53
|
matters = "matters",
|
|
61
54
|
medium = "medium",
|
|
62
|
-
merlin = "merlin",
|
|
63
55
|
minds = "minds",
|
|
64
|
-
mint = "mint",
|
|
65
56
|
mirror = "mirror",
|
|
66
|
-
mode = "mode",
|
|
67
57
|
mstdnjp = "mstdnjp",
|
|
68
58
|
near = "near",
|
|
69
59
|
nextid = "nextid",
|
|
@@ -85,13 +75,11 @@ export declare enum Platform {
|
|
|
85
75
|
space_id = "space_id",
|
|
86
76
|
stacks = "stacks",
|
|
87
77
|
substack = "substack",
|
|
88
|
-
taiko = "taiko",
|
|
89
78
|
talent = "talentprotocol",
|
|
90
79
|
tally = "tally",
|
|
91
80
|
telegram = "telegram",
|
|
92
81
|
threads = "threads",
|
|
93
82
|
tiktok = "tiktok",
|
|
94
|
-
tomo = "tomo",
|
|
95
83
|
ton = "ton",
|
|
96
84
|
tron = "tron",
|
|
97
85
|
twitter = "twitter",
|
|
@@ -106,8 +94,6 @@ export declare enum Platform {
|
|
|
106
94
|
world_id = "world_id",
|
|
107
95
|
xmtp = "xmtp",
|
|
108
96
|
youtube = "youtube",
|
|
109
|
-
zeta = "zeta",
|
|
110
|
-
zkfair = "zkfair",
|
|
111
97
|
zkme = "zkme",
|
|
112
98
|
zora = "zora"
|
|
113
99
|
}
|
package/dist/types/platform.js
CHANGED
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
*/
|
|
6
6
|
var Platform;
|
|
7
7
|
(function (Platform) {
|
|
8
|
-
Platform["ailayer"] = "ailayer";
|
|
9
|
-
Platform["alienx"] = "alienx";
|
|
10
8
|
Platform["aptos"] = "aptos";
|
|
11
9
|
Platform["arbitrum"] = "arbitrum";
|
|
12
10
|
Platform["basenames"] = "basenames";
|
|
@@ -21,8 +19,6 @@ var Platform;
|
|
|
21
19
|
Platform["clusters"] = "clusters";
|
|
22
20
|
Platform["coinbase"] = "coinbase";
|
|
23
21
|
Platform["coingecko"] = "coingecko";
|
|
24
|
-
Platform["cosmos"] = "cosmos";
|
|
25
|
-
Platform["cyberconnect"] = "cyberconnect";
|
|
26
22
|
Platform["deepdao"] = "deepdao";
|
|
27
23
|
Platform["degenscore"] = "degenscore";
|
|
28
24
|
Platform["dentity"] = "dentity";
|
|
@@ -31,7 +27,6 @@ var Platform;
|
|
|
31
27
|
Platform["dotbit"] = "dotbit";
|
|
32
28
|
Platform["dns"] = "dns";
|
|
33
29
|
Platform["ecp"] = "ecp";
|
|
34
|
-
Platform["edgeless"] = "edgeless";
|
|
35
30
|
Platform["efp"] = "efp";
|
|
36
31
|
Platform["ens"] = "ens";
|
|
37
32
|
Platform["ethereum"] = "ethereum";
|
|
@@ -53,18 +48,13 @@ var Platform;
|
|
|
53
48
|
Platform["interface"] = "interface";
|
|
54
49
|
Platform["keybase"] = "keybase";
|
|
55
50
|
Platform["lens"] = "lens";
|
|
56
|
-
Platform["lightlink"] = "lightlink";
|
|
57
51
|
Platform["linkedin"] = "linkedin";
|
|
58
52
|
Platform["linea"] = "linea";
|
|
59
53
|
Platform["lobsters"] = "lobsters";
|
|
60
|
-
Platform["manta"] = "manta";
|
|
61
54
|
Platform["matters"] = "matters";
|
|
62
55
|
Platform["medium"] = "medium";
|
|
63
|
-
Platform["merlin"] = "merlin";
|
|
64
56
|
Platform["minds"] = "minds";
|
|
65
|
-
Platform["mint"] = "mint";
|
|
66
57
|
Platform["mirror"] = "mirror";
|
|
67
|
-
Platform["mode"] = "mode";
|
|
68
58
|
Platform["mstdnjp"] = "mstdnjp";
|
|
69
59
|
Platform["near"] = "near";
|
|
70
60
|
Platform["nextid"] = "nextid";
|
|
@@ -86,13 +76,11 @@ var Platform;
|
|
|
86
76
|
Platform["space_id"] = "space_id";
|
|
87
77
|
Platform["stacks"] = "stacks";
|
|
88
78
|
Platform["substack"] = "substack";
|
|
89
|
-
Platform["taiko"] = "taiko";
|
|
90
79
|
Platform["talent"] = "talentprotocol";
|
|
91
80
|
Platform["tally"] = "tally";
|
|
92
81
|
Platform["telegram"] = "telegram";
|
|
93
82
|
Platform["threads"] = "threads";
|
|
94
83
|
Platform["tiktok"] = "tiktok";
|
|
95
|
-
Platform["tomo"] = "tomo";
|
|
96
84
|
Platform["ton"] = "ton";
|
|
97
85
|
Platform["tron"] = "tron";
|
|
98
86
|
Platform["twitter"] = "twitter";
|
|
@@ -107,8 +95,6 @@ var Platform;
|
|
|
107
95
|
Platform["world_id"] = "world_id";
|
|
108
96
|
Platform["xmtp"] = "xmtp";
|
|
109
97
|
Platform["youtube"] = "youtube";
|
|
110
|
-
Platform["zeta"] = "zeta";
|
|
111
|
-
Platform["zkfair"] = "zkfair";
|
|
112
98
|
Platform["zkme"] = "zkme";
|
|
113
99
|
Platform["zora"] = "zora";
|
|
114
100
|
})(Platform || (Platform = {}));
|
package/dist/types/source.cjs
CHANGED
|
@@ -29,16 +29,19 @@ exports.Source = void 0;
|
|
|
29
29
|
Source["keybase"] = "keybase";
|
|
30
30
|
Source["lens"] = "lens";
|
|
31
31
|
Source["linea"] = "linea";
|
|
32
|
+
Source["magiceden"] = "magiceden";
|
|
32
33
|
Source["metopia"] = "metopia";
|
|
33
34
|
Source["mirror"] = "mirror";
|
|
34
35
|
Source["nextid"] = "nextid";
|
|
35
36
|
Source["nftd"] = "nftd";
|
|
36
37
|
Source["nostr"] = "nostr";
|
|
37
38
|
Source["opensea"] = "opensea";
|
|
39
|
+
Source["opinion"] = "opinion";
|
|
38
40
|
Source["paragraph"] = "paragraph";
|
|
39
41
|
Source["particle"] = "particle";
|
|
40
42
|
Source["polymarket"] = "polymarket";
|
|
41
43
|
Source["ppl"] = "ppl";
|
|
44
|
+
Source["predictfun"] = "predictfun";
|
|
42
45
|
Source["privy"] = "privy";
|
|
43
46
|
Source["questn"] = "questn";
|
|
44
47
|
Source["rarible"] = "rarible";
|
package/dist/types/source.d.ts
CHANGED
|
@@ -26,16 +26,19 @@ export declare enum Source {
|
|
|
26
26
|
keybase = "keybase",
|
|
27
27
|
lens = "lens",
|
|
28
28
|
linea = "linea",
|
|
29
|
+
magiceden = "magiceden",
|
|
29
30
|
metopia = "metopia",
|
|
30
31
|
mirror = "mirror",
|
|
31
32
|
nextid = "nextid",
|
|
32
33
|
nftd = "nftd",
|
|
33
34
|
nostr = "nostr",
|
|
34
35
|
opensea = "opensea",
|
|
36
|
+
opinion = "opinion",
|
|
35
37
|
paragraph = "paragraph",
|
|
36
38
|
particle = "particle",
|
|
37
39
|
polymarket = "polymarket",
|
|
38
40
|
ppl = "ppl",
|
|
41
|
+
predictfun = "predictfun",
|
|
39
42
|
privy = "privy",
|
|
40
43
|
questn = "questn",
|
|
41
44
|
rarible = "rarible",
|
package/dist/types/source.js
CHANGED
|
@@ -27,16 +27,19 @@ var Source;
|
|
|
27
27
|
Source["keybase"] = "keybase";
|
|
28
28
|
Source["lens"] = "lens";
|
|
29
29
|
Source["linea"] = "linea";
|
|
30
|
+
Source["magiceden"] = "magiceden";
|
|
30
31
|
Source["metopia"] = "metopia";
|
|
31
32
|
Source["mirror"] = "mirror";
|
|
32
33
|
Source["nextid"] = "nextid";
|
|
33
34
|
Source["nftd"] = "nftd";
|
|
34
35
|
Source["nostr"] = "nostr";
|
|
35
36
|
Source["opensea"] = "opensea";
|
|
37
|
+
Source["opinion"] = "opinion";
|
|
36
38
|
Source["paragraph"] = "paragraph";
|
|
37
39
|
Source["particle"] = "particle";
|
|
38
40
|
Source["polymarket"] = "polymarket";
|
|
39
41
|
Source["ppl"] = "ppl";
|
|
42
|
+
Source["predictfun"] = "predictfun";
|
|
40
43
|
Source["privy"] = "privy";
|
|
41
44
|
Source["questn"] = "questn";
|
|
42
45
|
Source["rarible"] = "rarible";
|
package/dist/utils/helpers.cjs
CHANGED
|
@@ -10,6 +10,29 @@ var platform$1 = require('./platform.cjs');
|
|
|
10
10
|
var regex = require('./regex.cjs');
|
|
11
11
|
|
|
12
12
|
const PROFILE_API_ENDPOINT = "https://api.web3.bio";
|
|
13
|
+
const FARCASTER_SUFFIXES = [".farcaster", ".fcast.id", ".farcaster.eth"];
|
|
14
|
+
const CHAIN_ALIASES = [".base", ".linea"];
|
|
15
|
+
const hasAnySuffix = (value, suffixes) => suffixes.some((suffix) => value.endsWith(suffix));
|
|
16
|
+
const getSuffixAfterLastDot = (value) => {
|
|
17
|
+
const lastDotIndex = value.lastIndexOf(".");
|
|
18
|
+
return lastDotIndex === -1 ? null : value.slice(lastDotIndex + 1);
|
|
19
|
+
};
|
|
20
|
+
const removeWeb2PlatformSuffix = (value) => {
|
|
21
|
+
const suffix = getSuffixAfterLastDot(value);
|
|
22
|
+
if (!suffix || !platform$1.isWeb2Platform(suffix))
|
|
23
|
+
return value;
|
|
24
|
+
return value.slice(0, -(suffix.length + 1));
|
|
25
|
+
};
|
|
26
|
+
const normalizeChainAliasToEth = (value) => {
|
|
27
|
+
const [name, ...rest] = value.split(".");
|
|
28
|
+
const chain = rest[rest.length - 1];
|
|
29
|
+
return `${name}.${chain}.eth`;
|
|
30
|
+
};
|
|
31
|
+
const withPlatformEthSuffix = (value, shortSuffix, fullSuffix) => {
|
|
32
|
+
if (value.endsWith(fullSuffix))
|
|
33
|
+
return value;
|
|
34
|
+
return value.endsWith(shortSuffix) ? `${value}.eth` : `${value}${fullSuffix}`;
|
|
35
|
+
};
|
|
13
36
|
/**
|
|
14
37
|
* Resolves an identity string to a platform and identifier
|
|
15
38
|
* @param input The identity to resolve
|
|
@@ -50,24 +73,14 @@ const prettify = (input) => {
|
|
|
50
73
|
return "";
|
|
51
74
|
if (input.startsWith("farcaster,#"))
|
|
52
75
|
return input.replace(/^(farcaster),/, "");
|
|
53
|
-
if (input
|
|
54
|
-
input.endsWith(".fcast.id") ||
|
|
55
|
-
input.endsWith(".farcaster.eth")) {
|
|
76
|
+
if (hasAnySuffix(input, FARCASTER_SUFFIXES)) {
|
|
56
77
|
return input.replace(/(\.farcaster|\.fcast\.id|\.farcaster\.eth)$/, "");
|
|
57
78
|
}
|
|
58
|
-
if (input
|
|
59
|
-
|
|
60
|
-
return `${parts[0]}.${parts[parts.length - 1]}.eth`;
|
|
61
|
-
}
|
|
62
|
-
// for all web2 platform prettify format as "identity.platform"
|
|
63
|
-
const lastDotIndex = input.lastIndexOf(".");
|
|
64
|
-
if (lastDotIndex !== -1) {
|
|
65
|
-
const suffix = input.slice(lastDotIndex + 1);
|
|
66
|
-
if (platform$1.isWeb2Platform(suffix)) {
|
|
67
|
-
return input.slice(0, lastDotIndex);
|
|
68
|
-
}
|
|
79
|
+
if (hasAnySuffix(input, CHAIN_ALIASES)) {
|
|
80
|
+
return normalizeChainAliasToEth(input);
|
|
69
81
|
}
|
|
70
|
-
|
|
82
|
+
// For all web2 platforms prettify format as "identity.platform".
|
|
83
|
+
return removeWeb2PlatformSuffix(input);
|
|
71
84
|
};
|
|
72
85
|
/**
|
|
73
86
|
* Fufill and standardize identity format
|
|
@@ -77,25 +90,15 @@ const uglify = (input, platform$1) => {
|
|
|
77
90
|
return "";
|
|
78
91
|
switch (platform$1) {
|
|
79
92
|
case platform.Platform.farcaster:
|
|
80
|
-
return input
|
|
81
|
-
input.endsWith(".fcast.id") ||
|
|
82
|
-
input.endsWith(".farcaster.eth")
|
|
93
|
+
return hasAnySuffix(input, FARCASTER_SUFFIXES)
|
|
83
94
|
? input
|
|
84
95
|
: `${input}.farcaster`;
|
|
85
96
|
case platform.Platform.lens:
|
|
86
97
|
return input.endsWith(".lens") ? input : `${input}.lens`;
|
|
87
98
|
case platform.Platform.basenames:
|
|
88
|
-
return input.
|
|
89
|
-
? input
|
|
90
|
-
: input.endsWith(".base")
|
|
91
|
-
? `${input}.eth`
|
|
92
|
-
: `${input}.base.eth`;
|
|
99
|
+
return withPlatformEthSuffix(input, ".base", ".base.eth");
|
|
93
100
|
case platform.Platform.linea:
|
|
94
|
-
return input.
|
|
95
|
-
? input
|
|
96
|
-
: input.endsWith(".linea")
|
|
97
|
-
? `${input}.eth`
|
|
98
|
-
: `${input}.linea.eth`;
|
|
101
|
+
return withPlatformEthSuffix(input, ".linea", ".linea.eth");
|
|
99
102
|
default:
|
|
100
103
|
return input;
|
|
101
104
|
}
|
|
@@ -128,9 +131,7 @@ const SUPPORTED_PLATFORMS = new Set([
|
|
|
128
131
|
* Check if the platform is supported for API queries
|
|
129
132
|
*/
|
|
130
133
|
const isSupportedPlatform = (platform) => {
|
|
131
|
-
|
|
132
|
-
return false;
|
|
133
|
-
return SUPPORTED_PLATFORMS.has(platform);
|
|
134
|
+
return !!platform && SUPPORTED_PLATFORMS.has(platform);
|
|
134
135
|
};
|
|
135
136
|
const platformMap = new Map([
|
|
136
137
|
[regex.REGEX.BASENAMES, platform.Platform.basenames],
|
|
@@ -155,19 +156,16 @@ const platformMap = new Map([
|
|
|
155
156
|
* Detect platform from identity string based on regex patterns
|
|
156
157
|
*/
|
|
157
158
|
const detectPlatform = (term) => {
|
|
158
|
-
if (
|
|
159
|
+
if (hasAnySuffix(term, FARCASTER_SUFFIXES))
|
|
159
160
|
return platform.Platform.farcaster;
|
|
160
|
-
for (const [regex,
|
|
161
|
+
for (const [regex, platform] of platformMap) {
|
|
161
162
|
if (regex.test(term)) {
|
|
162
|
-
return
|
|
163
|
+
return platform;
|
|
163
164
|
}
|
|
164
165
|
}
|
|
165
|
-
const
|
|
166
|
-
if (
|
|
167
|
-
|
|
168
|
-
if (platform$1.PLATFORM_DATA.has(suffix))
|
|
169
|
-
return suffix;
|
|
170
|
-
}
|
|
166
|
+
const suffix = getSuffixAfterLastDot(term);
|
|
167
|
+
if (suffix && platform$1.PLATFORM_DATA.has(suffix))
|
|
168
|
+
return suffix;
|
|
171
169
|
return term.includes(".") ? platform.Platform.ens : platform.Platform.farcaster;
|
|
172
170
|
};
|
|
173
171
|
/**
|
|
@@ -189,9 +187,7 @@ const getApiKey = (userProvidedKey) => {
|
|
|
189
187
|
* @returns True if addresses match (ignoring case), false otherwise
|
|
190
188
|
*/
|
|
191
189
|
const isSameAddress = (address, otherAddress) => {
|
|
192
|
-
|
|
193
|
-
return false;
|
|
194
|
-
return address.toLowerCase() === otherAddress.toLowerCase();
|
|
190
|
+
return !!address && !!otherAddress && address.toLowerCase() === otherAddress.toLowerCase();
|
|
195
191
|
};
|
|
196
192
|
const web3AddressRegexes = [
|
|
197
193
|
regex.REGEX.ETH_ADDRESS,
|
|
@@ -234,7 +230,7 @@ const isValidEthereumAddress = (address) => {
|
|
|
234
230
|
* @returns True if the string is a valid Solana address, false otherwise
|
|
235
231
|
*/
|
|
236
232
|
const isValidSolanaAddress = (address) => {
|
|
237
|
-
return regex.REGEX.SOLANA_ADDRESS.test(address);
|
|
233
|
+
return !!address && regex.REGEX.SOLANA_ADDRESS.test(address);
|
|
238
234
|
};
|
|
239
235
|
/**
|
|
240
236
|
* Converts an identity string to a JSON object with platform and identity
|
|
@@ -250,7 +246,11 @@ const idToJson = (input) => {
|
|
|
250
246
|
const id = resolveIdentity(input);
|
|
251
247
|
if (!id)
|
|
252
248
|
return null;
|
|
253
|
-
const
|
|
249
|
+
const separatorIndex = id.indexOf(",");
|
|
250
|
+
if (separatorIndex === -1)
|
|
251
|
+
return null;
|
|
252
|
+
const _platform = id.slice(0, separatorIndex);
|
|
253
|
+
const _identity = id.slice(separatorIndex + 1);
|
|
254
254
|
return {
|
|
255
255
|
platform: _platform,
|
|
256
256
|
identity: _identity,
|
package/dist/utils/helpers.js
CHANGED
|
@@ -4,10 +4,33 @@ import '../types/hook.js';
|
|
|
4
4
|
import '../types/source.js';
|
|
5
5
|
import '../types/cointype.js';
|
|
6
6
|
import '../types/credential.js';
|
|
7
|
-
import {
|
|
7
|
+
import { PLATFORM_DATA, isWeb2Platform } from './platform.js';
|
|
8
8
|
import { REGEX } from './regex.js';
|
|
9
9
|
|
|
10
10
|
const PROFILE_API_ENDPOINT = "https://api.web3.bio";
|
|
11
|
+
const FARCASTER_SUFFIXES = [".farcaster", ".fcast.id", ".farcaster.eth"];
|
|
12
|
+
const CHAIN_ALIASES = [".base", ".linea"];
|
|
13
|
+
const hasAnySuffix = (value, suffixes) => suffixes.some((suffix) => value.endsWith(suffix));
|
|
14
|
+
const getSuffixAfterLastDot = (value) => {
|
|
15
|
+
const lastDotIndex = value.lastIndexOf(".");
|
|
16
|
+
return lastDotIndex === -1 ? null : value.slice(lastDotIndex + 1);
|
|
17
|
+
};
|
|
18
|
+
const removeWeb2PlatformSuffix = (value) => {
|
|
19
|
+
const suffix = getSuffixAfterLastDot(value);
|
|
20
|
+
if (!suffix || !isWeb2Platform(suffix))
|
|
21
|
+
return value;
|
|
22
|
+
return value.slice(0, -(suffix.length + 1));
|
|
23
|
+
};
|
|
24
|
+
const normalizeChainAliasToEth = (value) => {
|
|
25
|
+
const [name, ...rest] = value.split(".");
|
|
26
|
+
const chain = rest[rest.length - 1];
|
|
27
|
+
return `${name}.${chain}.eth`;
|
|
28
|
+
};
|
|
29
|
+
const withPlatformEthSuffix = (value, shortSuffix, fullSuffix) => {
|
|
30
|
+
if (value.endsWith(fullSuffix))
|
|
31
|
+
return value;
|
|
32
|
+
return value.endsWith(shortSuffix) ? `${value}.eth` : `${value}${fullSuffix}`;
|
|
33
|
+
};
|
|
11
34
|
/**
|
|
12
35
|
* Resolves an identity string to a platform and identifier
|
|
13
36
|
* @param input The identity to resolve
|
|
@@ -48,24 +71,14 @@ const prettify = (input) => {
|
|
|
48
71
|
return "";
|
|
49
72
|
if (input.startsWith("farcaster,#"))
|
|
50
73
|
return input.replace(/^(farcaster),/, "");
|
|
51
|
-
if (input
|
|
52
|
-
input.endsWith(".fcast.id") ||
|
|
53
|
-
input.endsWith(".farcaster.eth")) {
|
|
74
|
+
if (hasAnySuffix(input, FARCASTER_SUFFIXES)) {
|
|
54
75
|
return input.replace(/(\.farcaster|\.fcast\.id|\.farcaster\.eth)$/, "");
|
|
55
76
|
}
|
|
56
|
-
if (input
|
|
57
|
-
|
|
58
|
-
return `${parts[0]}.${parts[parts.length - 1]}.eth`;
|
|
59
|
-
}
|
|
60
|
-
// for all web2 platform prettify format as "identity.platform"
|
|
61
|
-
const lastDotIndex = input.lastIndexOf(".");
|
|
62
|
-
if (lastDotIndex !== -1) {
|
|
63
|
-
const suffix = input.slice(lastDotIndex + 1);
|
|
64
|
-
if (isWeb2Platform(suffix)) {
|
|
65
|
-
return input.slice(0, lastDotIndex);
|
|
66
|
-
}
|
|
77
|
+
if (hasAnySuffix(input, CHAIN_ALIASES)) {
|
|
78
|
+
return normalizeChainAliasToEth(input);
|
|
67
79
|
}
|
|
68
|
-
|
|
80
|
+
// For all web2 platforms prettify format as "identity.platform".
|
|
81
|
+
return removeWeb2PlatformSuffix(input);
|
|
69
82
|
};
|
|
70
83
|
/**
|
|
71
84
|
* Fufill and standardize identity format
|
|
@@ -75,25 +88,15 @@ const uglify = (input, platform) => {
|
|
|
75
88
|
return "";
|
|
76
89
|
switch (platform) {
|
|
77
90
|
case Platform.farcaster:
|
|
78
|
-
return input
|
|
79
|
-
input.endsWith(".fcast.id") ||
|
|
80
|
-
input.endsWith(".farcaster.eth")
|
|
91
|
+
return hasAnySuffix(input, FARCASTER_SUFFIXES)
|
|
81
92
|
? input
|
|
82
93
|
: `${input}.farcaster`;
|
|
83
94
|
case Platform.lens:
|
|
84
95
|
return input.endsWith(".lens") ? input : `${input}.lens`;
|
|
85
96
|
case Platform.basenames:
|
|
86
|
-
return input.
|
|
87
|
-
? input
|
|
88
|
-
: input.endsWith(".base")
|
|
89
|
-
? `${input}.eth`
|
|
90
|
-
: `${input}.base.eth`;
|
|
97
|
+
return withPlatformEthSuffix(input, ".base", ".base.eth");
|
|
91
98
|
case Platform.linea:
|
|
92
|
-
return input.
|
|
93
|
-
? input
|
|
94
|
-
: input.endsWith(".linea")
|
|
95
|
-
? `${input}.eth`
|
|
96
|
-
: `${input}.linea.eth`;
|
|
99
|
+
return withPlatformEthSuffix(input, ".linea", ".linea.eth");
|
|
97
100
|
default:
|
|
98
101
|
return input;
|
|
99
102
|
}
|
|
@@ -126,9 +129,7 @@ const SUPPORTED_PLATFORMS = new Set([
|
|
|
126
129
|
* Check if the platform is supported for API queries
|
|
127
130
|
*/
|
|
128
131
|
const isSupportedPlatform = (platform) => {
|
|
129
|
-
|
|
130
|
-
return false;
|
|
131
|
-
return SUPPORTED_PLATFORMS.has(platform);
|
|
132
|
+
return !!platform && SUPPORTED_PLATFORMS.has(platform);
|
|
132
133
|
};
|
|
133
134
|
const platformMap = new Map([
|
|
134
135
|
[REGEX.BASENAMES, Platform.basenames],
|
|
@@ -153,19 +154,16 @@ const platformMap = new Map([
|
|
|
153
154
|
* Detect platform from identity string based on regex patterns
|
|
154
155
|
*/
|
|
155
156
|
const detectPlatform = (term) => {
|
|
156
|
-
if (
|
|
157
|
+
if (hasAnySuffix(term, FARCASTER_SUFFIXES))
|
|
157
158
|
return Platform.farcaster;
|
|
158
|
-
for (const [regex,
|
|
159
|
+
for (const [regex, platform] of platformMap) {
|
|
159
160
|
if (regex.test(term)) {
|
|
160
|
-
return
|
|
161
|
+
return platform;
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
|
-
const
|
|
164
|
-
if (
|
|
165
|
-
|
|
166
|
-
if (PLATFORM_DATA.has(suffix))
|
|
167
|
-
return suffix;
|
|
168
|
-
}
|
|
164
|
+
const suffix = getSuffixAfterLastDot(term);
|
|
165
|
+
if (suffix && PLATFORM_DATA.has(suffix))
|
|
166
|
+
return suffix;
|
|
169
167
|
return term.includes(".") ? Platform.ens : Platform.farcaster;
|
|
170
168
|
};
|
|
171
169
|
/**
|
|
@@ -187,9 +185,7 @@ const getApiKey = (userProvidedKey) => {
|
|
|
187
185
|
* @returns True if addresses match (ignoring case), false otherwise
|
|
188
186
|
*/
|
|
189
187
|
const isSameAddress = (address, otherAddress) => {
|
|
190
|
-
|
|
191
|
-
return false;
|
|
192
|
-
return address.toLowerCase() === otherAddress.toLowerCase();
|
|
188
|
+
return !!address && !!otherAddress && address.toLowerCase() === otherAddress.toLowerCase();
|
|
193
189
|
};
|
|
194
190
|
const web3AddressRegexes = [
|
|
195
191
|
REGEX.ETH_ADDRESS,
|
|
@@ -232,7 +228,7 @@ const isValidEthereumAddress = (address) => {
|
|
|
232
228
|
* @returns True if the string is a valid Solana address, false otherwise
|
|
233
229
|
*/
|
|
234
230
|
const isValidSolanaAddress = (address) => {
|
|
235
|
-
return REGEX.SOLANA_ADDRESS.test(address);
|
|
231
|
+
return !!address && REGEX.SOLANA_ADDRESS.test(address);
|
|
236
232
|
};
|
|
237
233
|
/**
|
|
238
234
|
* Converts an identity string to a JSON object with platform and identity
|
|
@@ -248,7 +244,11 @@ const idToJson = (input) => {
|
|
|
248
244
|
const id = resolveIdentity(input);
|
|
249
245
|
if (!id)
|
|
250
246
|
return null;
|
|
251
|
-
const
|
|
247
|
+
const separatorIndex = id.indexOf(",");
|
|
248
|
+
if (separatorIndex === -1)
|
|
249
|
+
return null;
|
|
250
|
+
const _platform = id.slice(0, separatorIndex);
|
|
251
|
+
const _identity = id.slice(separatorIndex + 1);
|
|
252
252
|
return {
|
|
253
253
|
platform: _platform,
|
|
254
254
|
identity: _identity,
|
package/dist/utils/ipfs.cjs
CHANGED
|
@@ -9,35 +9,43 @@ const MATCH_IPFS_CID_RE = new RegExp(IPFS_CID_PATTERN);
|
|
|
9
9
|
const MATCH_IPFS_CID_AT_STARTS_RE = new RegExp(`^https://(?:${IPFS_CID_PATTERN})`);
|
|
10
10
|
const MATCH_IPFS_CID_AND_PATHNAME_RE = new RegExp(`(?:${IPFS_CID_PATTERN})(?:/.*)?`);
|
|
11
11
|
const CORS_HOST_RE = new RegExp(`^(?:${CORS_HOST}|${CF_IPFS_HOST})\\??`);
|
|
12
|
+
const tryDecodeURIComponent = (value) => {
|
|
13
|
+
try {
|
|
14
|
+
return decodeURIComponent(value);
|
|
15
|
+
}
|
|
16
|
+
catch (_a) {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
12
20
|
const resolveIPFS_CID = (str) => { var _a; return (_a = str.match(MATCH_IPFS_CID_RE)) === null || _a === void 0 ? void 0 : _a[0]; };
|
|
13
21
|
const isIPFS = (str) => MATCH_IPFS_CID_RE.test(str);
|
|
14
22
|
function resolveIPFS_URL(cidOrURL) {
|
|
15
23
|
if (!cidOrURL)
|
|
16
24
|
return cidOrURL;
|
|
17
|
-
// Normalize input by trimming and decoding
|
|
25
|
+
// Normalize input by trimming and decoding.
|
|
18
26
|
const queryIndex = cidOrURL.indexOf("?");
|
|
19
|
-
let normalizedURL =
|
|
20
|
-
// Handle CORS proxies first
|
|
27
|
+
let normalizedURL = tryDecodeURIComponent(queryIndex !== -1 ? cidOrURL.slice(0, queryIndex) : cidOrURL);
|
|
28
|
+
// Handle CORS proxies first.
|
|
21
29
|
if (normalizedURL.startsWith(CORS_HOST) ||
|
|
22
30
|
normalizedURL.startsWith(CF_IPFS_HOST)) {
|
|
23
31
|
normalizedURL = normalizedURL.replace(CORS_HOST_RE, "");
|
|
24
|
-
// Continue processing the URL without the proxy prefix
|
|
32
|
+
// Continue processing the URL without the proxy prefix.
|
|
25
33
|
}
|
|
26
|
-
// Handle ipfs.io URLs
|
|
27
|
-
if (normalizedURL.startsWith(
|
|
34
|
+
// Handle ipfs.io URLs.
|
|
35
|
+
if (normalizedURL.startsWith(IPFS_GATEWAY_HOST)) {
|
|
28
36
|
const dataMatch = normalizedURL.match(MATCH_IPFS_DATA_RE);
|
|
29
37
|
if (dataMatch === null || dataMatch === void 0 ? void 0 : dataMatch[1]) {
|
|
30
|
-
return
|
|
38
|
+
return tryDecodeURIComponent(dataMatch[1]);
|
|
31
39
|
}
|
|
32
40
|
return normalizedURL;
|
|
33
41
|
}
|
|
34
|
-
// Handle ipfs protocol and CIDs
|
|
42
|
+
// Handle ipfs protocol and CIDs.
|
|
35
43
|
if (normalizedURL.includes("ipfs:") || isIPFS(normalizedURL)) {
|
|
36
|
-
// Convert ipfs:// protocol to CID format
|
|
44
|
+
// Convert ipfs:// protocol to CID format.
|
|
37
45
|
if (normalizedURL.startsWith("ipfs://")) {
|
|
38
46
|
normalizedURL = normalizedURL.slice(7);
|
|
39
47
|
}
|
|
40
|
-
// Handle URLs that start with a CID
|
|
48
|
+
// Handle URLs that start with a CID.
|
|
41
49
|
if (MATCH_IPFS_CID_AT_STARTS_RE.test(normalizedURL)) {
|
|
42
50
|
try {
|
|
43
51
|
const url = new URL(normalizedURL);
|
|
@@ -51,7 +59,7 @@ function resolveIPFS_URL(cidOrURL) {
|
|
|
51
59
|
console.debug("Failed to parse URL with CID", { normalizedURL, error });
|
|
52
60
|
}
|
|
53
61
|
}
|
|
54
|
-
// Handle bare CIDs or CIDs with paths
|
|
62
|
+
// Handle bare CIDs or CIDs with paths.
|
|
55
63
|
const pathMatch = normalizedURL.match(MATCH_IPFS_CID_AND_PATHNAME_RE);
|
|
56
64
|
if (pathMatch === null || pathMatch === void 0 ? void 0 : pathMatch[0]) {
|
|
57
65
|
return `${IPFS_GATEWAY_HOST}/ipfs/${pathMatch[0]}`;
|