@trust-ethos/cli 0.0.5
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 +21 -0
- package/README.md +1791 -0
- package/bin/dev.cmd +3 -0
- package/bin/dev.js +5 -0
- package/bin/run.cmd +3 -0
- package/bin/run.js +5 -0
- package/dist/commands/auction/active.d.ts +10 -0
- package/dist/commands/auction/active.js +39 -0
- package/dist/commands/auction/info.d.ts +16 -0
- package/dist/commands/auction/info.js +46 -0
- package/dist/commands/auction/list.d.ts +14 -0
- package/dist/commands/auction/list.js +61 -0
- package/dist/commands/broker/info.d.ts +16 -0
- package/dist/commands/broker/info.js +37 -0
- package/dist/commands/broker/list.d.ts +15 -0
- package/dist/commands/broker/list.js +62 -0
- package/dist/commands/config/get.d.ts +9 -0
- package/dist/commands/config/get.js +29 -0
- package/dist/commands/config/path.d.ts +6 -0
- package/dist/commands/config/path.js +12 -0
- package/dist/commands/config/set.d.ts +9 -0
- package/dist/commands/config/set.js +28 -0
- package/dist/commands/listing/info.d.ts +13 -0
- package/dist/commands/listing/info.js +41 -0
- package/dist/commands/listing/list.d.ts +13 -0
- package/dist/commands/listing/list.js +46 -0
- package/dist/commands/listing/voters.d.ts +19 -0
- package/dist/commands/listing/voters.js +48 -0
- package/dist/commands/market/featured.d.ts +10 -0
- package/dist/commands/market/featured.js +34 -0
- package/dist/commands/market/holders.d.ts +14 -0
- package/dist/commands/market/holders.js +46 -0
- package/dist/commands/market/info.d.ts +14 -0
- package/dist/commands/market/info.js +48 -0
- package/dist/commands/market/list.d.ts +16 -0
- package/dist/commands/market/list.js +55 -0
- package/dist/commands/nft/list.d.ts +15 -0
- package/dist/commands/nft/list.js +64 -0
- package/dist/commands/review/info.d.ts +17 -0
- package/dist/commands/review/info.js +49 -0
- package/dist/commands/review/list.d.ts +16 -0
- package/dist/commands/review/list.js +68 -0
- package/dist/commands/review/votes.d.ts +21 -0
- package/dist/commands/review/votes.js +91 -0
- package/dist/commands/score/status.d.ts +13 -0
- package/dist/commands/score/status.js +54 -0
- package/dist/commands/slash/info.d.ts +16 -0
- package/dist/commands/slash/info.js +42 -0
- package/dist/commands/slash/list.d.ts +15 -0
- package/dist/commands/slash/list.js +50 -0
- package/dist/commands/slash/votes.d.ts +21 -0
- package/dist/commands/slash/votes.js +91 -0
- package/dist/commands/user/activity.d.ts +15 -0
- package/dist/commands/user/activity.js +71 -0
- package/dist/commands/user/info.d.ts +14 -0
- package/dist/commands/user/info.js +51 -0
- package/dist/commands/user/invitations.d.ts +16 -0
- package/dist/commands/user/invitations.js +73 -0
- package/dist/commands/user/search.d.ts +15 -0
- package/dist/commands/user/search.js +59 -0
- package/dist/commands/user/summary.d.ts +14 -0
- package/dist/commands/user/summary.js +134 -0
- package/dist/commands/validator/info.d.ts +13 -0
- package/dist/commands/validator/info.js +53 -0
- package/dist/commands/validator/list.d.ts +13 -0
- package/dist/commands/validator/list.js +64 -0
- package/dist/commands/validator/sales.d.ts +12 -0
- package/dist/commands/validator/sales.js +52 -0
- package/dist/commands/vouch/info.d.ts +17 -0
- package/dist/commands/vouch/info.js +53 -0
- package/dist/commands/vouch/list.d.ts +18 -0
- package/dist/commands/vouch/list.js +89 -0
- package/dist/commands/vouch/mutual.d.ts +15 -0
- package/dist/commands/vouch/mutual.js +68 -0
- package/dist/commands/vouch/votes.d.ts +21 -0
- package/dist/commands/vouch/votes.js +91 -0
- package/dist/commands/xp/rank.d.ts +15 -0
- package/dist/commands/xp/rank.js +74 -0
- package/dist/commands/xp/seasons.d.ts +10 -0
- package/dist/commands/xp/seasons.js +42 -0
- package/dist/hooks/init.d.ts +3 -0
- package/dist/hooks/init.js +40 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/lib/api/echo-client.d.ts +624 -0
- package/dist/lib/api/echo-client.js +408 -0
- package/dist/lib/config/index.d.ts +6 -0
- package/dist/lib/config/index.js +32 -0
- package/dist/lib/errors/cli-error.d.ts +23 -0
- package/dist/lib/errors/cli-error.js +57 -0
- package/dist/lib/formatting/colors.d.ts +13 -0
- package/dist/lib/formatting/colors.js +22 -0
- package/dist/lib/formatting/error.d.ts +1 -0
- package/dist/lib/formatting/error.js +64 -0
- package/dist/lib/formatting/output.d.ts +45 -0
- package/dist/lib/formatting/output.js +753 -0
- package/dist/lib/help.d.ts +4 -0
- package/dist/lib/help.js +28 -0
- package/dist/lib/update/index.d.ts +37 -0
- package/dist/lib/update/index.js +286 -0
- package/dist/lib/validation/userkey.d.ts +11 -0
- package/dist/lib/validation/userkey.js +81 -0
- package/oclif.manifest.json +2224 -0
- package/package.json +87 -0
package/dist/lib/help.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { Help } from '@oclif/core';
|
|
2
|
+
import pc from 'picocolors';
|
|
3
|
+
import { loadConfig } from './config/index.js';
|
|
4
|
+
import { ethosGray } from './formatting/colors.js';
|
|
5
|
+
const ETHOS_BANNER = `
|
|
6
|
+
${ethosGray(' ............. .......... .. ...')}
|
|
7
|
+
${ethosGray(' ............ ... .. .. ..')}
|
|
8
|
+
${ethosGray('......... ... . ...... .. .... ..... ......')}
|
|
9
|
+
${ethosGray('......... ... . .. . ... ..... ... ... .. ..')}
|
|
10
|
+
${ethosGray(' .......... ......... .. .. ... ... ... ... .')}
|
|
11
|
+
${ethosGray(' .......... ... ... .. .. ... ... .. .....')}
|
|
12
|
+
${ethosGray('.......... ... .. .. ... ... .. ....')}
|
|
13
|
+
${ethosGray('......... ... .. .. .. ... ... ... . ...')}
|
|
14
|
+
${ethosGray(' ............ ... .. .. .. ... ... .. .. ...')}
|
|
15
|
+
${ethosGray(' ............. ........... .... .... ... ....... ........')}
|
|
16
|
+
`;
|
|
17
|
+
export default class EthosHelp extends Help {
|
|
18
|
+
async showRootHelp() {
|
|
19
|
+
const config = loadConfig();
|
|
20
|
+
console.log(ETHOS_BANNER);
|
|
21
|
+
console.log(pc.dim(' The reputation layer for the internet\n'));
|
|
22
|
+
const isProd = config.apiUrl === 'https://api.ethos.network';
|
|
23
|
+
const apiColor = isProd ? pc.green : pc.yellow;
|
|
24
|
+
console.log(` ${pc.dim('API:')} ${apiColor(config.apiUrl)}`);
|
|
25
|
+
console.log('');
|
|
26
|
+
await super.showRootHelp();
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export interface VersionCache {
|
|
2
|
+
latestVersion: string;
|
|
3
|
+
checkedAt: number;
|
|
4
|
+
downloadUrl?: string;
|
|
5
|
+
}
|
|
6
|
+
export interface UpdateInfo {
|
|
7
|
+
currentVersion: string;
|
|
8
|
+
latestVersion: string;
|
|
9
|
+
updateAvailable: boolean;
|
|
10
|
+
downloadUrl?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ReleaseAsset {
|
|
13
|
+
name: string;
|
|
14
|
+
browser_download_url: string;
|
|
15
|
+
}
|
|
16
|
+
export interface GitHubRelease {
|
|
17
|
+
tag_name: string;
|
|
18
|
+
assets: ReleaseAsset[];
|
|
19
|
+
}
|
|
20
|
+
export declare function getCurrentVersion(): string;
|
|
21
|
+
export declare function compareVersions(a: string, b: string): number;
|
|
22
|
+
export declare function checkForUpdate(): Promise<UpdateInfo>;
|
|
23
|
+
export declare function downloadUpdateInBackground(downloadUrl: string, version: string): void;
|
|
24
|
+
export declare function getPendingUpdate(): {
|
|
25
|
+
version: string;
|
|
26
|
+
path: string;
|
|
27
|
+
} | null;
|
|
28
|
+
export declare function applyPendingUpdate(): boolean;
|
|
29
|
+
export declare function clearUpdateData(): void;
|
|
30
|
+
export declare function getInstallPath(): string;
|
|
31
|
+
export type InstallMethod = 'curl' | 'npm' | 'homebrew' | 'dev' | 'unknown';
|
|
32
|
+
export interface InstallInfo {
|
|
33
|
+
method: InstallMethod;
|
|
34
|
+
supportsAutoUpdate: boolean;
|
|
35
|
+
updateCommand: string;
|
|
36
|
+
}
|
|
37
|
+
export declare function detectInstallMethod(): InstallInfo;
|
|
@@ -0,0 +1,286 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync, unlinkSync, symlinkSync, readdirSync, rmSync } from 'fs';
|
|
2
|
+
import { homedir, platform, arch } from 'os';
|
|
3
|
+
import { join, dirname } from 'path';
|
|
4
|
+
const GITHUB_REPO = 'trust-ethos/ethos-cli';
|
|
5
|
+
const CACHE_TTL_MS = 24 * 60 * 60 * 1000;
|
|
6
|
+
const ETHOS_HOME = join(homedir(), '.ethos');
|
|
7
|
+
const UPDATE_DIR = join(ETHOS_HOME, 'updates');
|
|
8
|
+
const VERSIONS_DIR = join(ETHOS_HOME, 'versions');
|
|
9
|
+
const CURRENT_LINK = join(ETHOS_HOME, 'current');
|
|
10
|
+
const CACHE_FILE = join(UPDATE_DIR, 'version-cache.json');
|
|
11
|
+
const PENDING_FILE = join(UPDATE_DIR, 'pending.json');
|
|
12
|
+
export function getCurrentVersion() {
|
|
13
|
+
try {
|
|
14
|
+
const pkgPath = join(dirname(dirname(dirname(__dirname))), 'package.json');
|
|
15
|
+
if (existsSync(pkgPath)) {
|
|
16
|
+
return JSON.parse(readFileSync(pkgPath, 'utf-8')).version;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch { }
|
|
20
|
+
return '0.0.0';
|
|
21
|
+
}
|
|
22
|
+
function getPlatformTarget() {
|
|
23
|
+
const os = platform();
|
|
24
|
+
const architecture = arch();
|
|
25
|
+
const targetMap = {
|
|
26
|
+
'darwin-arm64': 'darwin-arm64',
|
|
27
|
+
'darwin-x64': 'darwin-x64',
|
|
28
|
+
'linux-x64': 'linux-x64',
|
|
29
|
+
'linux-arm64': 'linux-arm64',
|
|
30
|
+
'win32-x64': 'win32-x64',
|
|
31
|
+
};
|
|
32
|
+
return targetMap[`${os}-${architecture}`] || `${os}-${architecture}`;
|
|
33
|
+
}
|
|
34
|
+
function ensureDir(dir) {
|
|
35
|
+
if (!existsSync(dir)) {
|
|
36
|
+
mkdirSync(dir, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function loadCache() {
|
|
40
|
+
try {
|
|
41
|
+
if (existsSync(CACHE_FILE)) {
|
|
42
|
+
return JSON.parse(readFileSync(CACHE_FILE, 'utf-8'));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
catch { }
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
function saveCache(cache) {
|
|
49
|
+
ensureDir(UPDATE_DIR);
|
|
50
|
+
writeFileSync(CACHE_FILE, JSON.stringify(cache, null, 2));
|
|
51
|
+
}
|
|
52
|
+
function isCacheValid(cache) {
|
|
53
|
+
if (!cache)
|
|
54
|
+
return false;
|
|
55
|
+
return Date.now() - cache.checkedAt < CACHE_TTL_MS;
|
|
56
|
+
}
|
|
57
|
+
export function compareVersions(a, b) {
|
|
58
|
+
const partsA = a.replace(/^v/, '').split('.').map(Number);
|
|
59
|
+
const partsB = b.replace(/^v/, '').split('.').map(Number);
|
|
60
|
+
for (let i = 0; i < Math.max(partsA.length, partsB.length); i++) {
|
|
61
|
+
const numA = partsA[i] || 0;
|
|
62
|
+
const numB = partsB[i] || 0;
|
|
63
|
+
if (numA > numB)
|
|
64
|
+
return 1;
|
|
65
|
+
if (numA < numB)
|
|
66
|
+
return -1;
|
|
67
|
+
}
|
|
68
|
+
return 0;
|
|
69
|
+
}
|
|
70
|
+
async function fetchLatestRelease() {
|
|
71
|
+
try {
|
|
72
|
+
const response = await fetch(`https://api.github.com/repos/${GITHUB_REPO}/releases/latest`, {
|
|
73
|
+
headers: {
|
|
74
|
+
'Accept': 'application/vnd.github.v3+json',
|
|
75
|
+
'User-Agent': 'ethos-cli',
|
|
76
|
+
},
|
|
77
|
+
});
|
|
78
|
+
if (!response.ok)
|
|
79
|
+
return null;
|
|
80
|
+
return await response.json();
|
|
81
|
+
}
|
|
82
|
+
catch {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function findAssetForPlatform(assets) {
|
|
87
|
+
const target = getPlatformTarget();
|
|
88
|
+
return assets.find(a => a.name.includes(target) && a.name.endsWith('.tar.gz'));
|
|
89
|
+
}
|
|
90
|
+
export async function checkForUpdate() {
|
|
91
|
+
const currentVersion = getCurrentVersion();
|
|
92
|
+
const cache = loadCache();
|
|
93
|
+
if (isCacheValid(cache) && cache) {
|
|
94
|
+
return {
|
|
95
|
+
currentVersion,
|
|
96
|
+
latestVersion: cache.latestVersion,
|
|
97
|
+
updateAvailable: compareVersions(cache.latestVersion, currentVersion) > 0,
|
|
98
|
+
downloadUrl: cache.downloadUrl,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
const release = await fetchLatestRelease();
|
|
102
|
+
if (!release) {
|
|
103
|
+
return {
|
|
104
|
+
currentVersion,
|
|
105
|
+
latestVersion: currentVersion,
|
|
106
|
+
updateAvailable: false,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
const latestVersion = release.tag_name.replace(/^v/, '');
|
|
110
|
+
const asset = findAssetForPlatform(release.assets);
|
|
111
|
+
const newCache = {
|
|
112
|
+
latestVersion,
|
|
113
|
+
checkedAt: Date.now(),
|
|
114
|
+
downloadUrl: asset?.browser_download_url,
|
|
115
|
+
};
|
|
116
|
+
saveCache(newCache);
|
|
117
|
+
return {
|
|
118
|
+
currentVersion,
|
|
119
|
+
latestVersion,
|
|
120
|
+
updateAvailable: compareVersions(latestVersion, currentVersion) > 0,
|
|
121
|
+
downloadUrl: asset?.browser_download_url,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export function downloadUpdateInBackground(downloadUrl, version) {
|
|
125
|
+
ensureDir(UPDATE_DIR);
|
|
126
|
+
ensureDir(VERSIONS_DIR);
|
|
127
|
+
const tarballPath = join(UPDATE_DIR, `ethos-v${version}.tar.gz`);
|
|
128
|
+
const extractDir = join(VERSIONS_DIR, `v${version}`);
|
|
129
|
+
const script = `
|
|
130
|
+
const https = require('https');
|
|
131
|
+
const fs = require('fs');
|
|
132
|
+
const { execSync } = require('child_process');
|
|
133
|
+
const path = require('path');
|
|
134
|
+
|
|
135
|
+
const url = '${downloadUrl}';
|
|
136
|
+
const tarball = '${tarballPath}';
|
|
137
|
+
const extractDir = '${extractDir}';
|
|
138
|
+
const pendingFile = '${PENDING_FILE}';
|
|
139
|
+
|
|
140
|
+
function download(url, dest, redirects = 0) {
|
|
141
|
+
if (redirects > 5) process.exit(1);
|
|
142
|
+
|
|
143
|
+
const file = fs.createWriteStream(dest);
|
|
144
|
+
const protocol = url.startsWith('https') ? require('https') : require('http');
|
|
145
|
+
|
|
146
|
+
protocol.get(url, (response) => {
|
|
147
|
+
if (response.statusCode >= 300 && response.statusCode < 400 && response.headers.location) {
|
|
148
|
+
file.close();
|
|
149
|
+
fs.unlinkSync(dest);
|
|
150
|
+
download(response.headers.location, dest, redirects + 1);
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
response.pipe(file);
|
|
155
|
+
file.on('finish', () => {
|
|
156
|
+
file.close();
|
|
157
|
+
try {
|
|
158
|
+
fs.mkdirSync(extractDir, { recursive: true });
|
|
159
|
+
execSync('tar -xzf ' + tarball + ' -C ' + extractDir + ' --strip-components=1', { stdio: 'ignore' });
|
|
160
|
+
fs.unlinkSync(tarball);
|
|
161
|
+
fs.writeFileSync(pendingFile, JSON.stringify({ version: '${version}', path: extractDir }));
|
|
162
|
+
} catch (e) {
|
|
163
|
+
process.exit(1);
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}).on('error', () => {
|
|
167
|
+
fs.unlink(dest, () => {});
|
|
168
|
+
process.exit(1);
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
download(url, tarball);
|
|
173
|
+
`;
|
|
174
|
+
const { spawn } = require('child_process');
|
|
175
|
+
const child = spawn(process.execPath, ['-e', script], {
|
|
176
|
+
detached: true,
|
|
177
|
+
stdio: 'ignore',
|
|
178
|
+
});
|
|
179
|
+
child.unref();
|
|
180
|
+
}
|
|
181
|
+
export function getPendingUpdate() {
|
|
182
|
+
try {
|
|
183
|
+
if (!existsSync(PENDING_FILE))
|
|
184
|
+
return null;
|
|
185
|
+
const data = JSON.parse(readFileSync(PENDING_FILE, 'utf-8'));
|
|
186
|
+
if (existsSync(data.path))
|
|
187
|
+
return data;
|
|
188
|
+
unlinkSync(PENDING_FILE);
|
|
189
|
+
}
|
|
190
|
+
catch { }
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
export function applyPendingUpdate() {
|
|
194
|
+
const pending = getPendingUpdate();
|
|
195
|
+
if (!pending)
|
|
196
|
+
return false;
|
|
197
|
+
const isDevMode = process.execPath.includes('bun') || process.execPath.includes('node');
|
|
198
|
+
if (isDevMode) {
|
|
199
|
+
try {
|
|
200
|
+
unlinkSync(PENDING_FILE);
|
|
201
|
+
}
|
|
202
|
+
catch { }
|
|
203
|
+
return false;
|
|
204
|
+
}
|
|
205
|
+
const isManagedInstall = process.execPath.startsWith(ETHOS_HOME);
|
|
206
|
+
if (!isManagedInstall) {
|
|
207
|
+
try {
|
|
208
|
+
unlinkSync(PENDING_FILE);
|
|
209
|
+
}
|
|
210
|
+
catch { }
|
|
211
|
+
return false;
|
|
212
|
+
}
|
|
213
|
+
try {
|
|
214
|
+
if (existsSync(CURRENT_LINK))
|
|
215
|
+
unlinkSync(CURRENT_LINK);
|
|
216
|
+
symlinkSync(pending.path, CURRENT_LINK);
|
|
217
|
+
unlinkSync(PENDING_FILE);
|
|
218
|
+
cleanupOldVersions(pending.version);
|
|
219
|
+
return true;
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
function cleanupOldVersions(keepVersion) {
|
|
226
|
+
try {
|
|
227
|
+
if (!existsSync(VERSIONS_DIR))
|
|
228
|
+
return;
|
|
229
|
+
const versions = readdirSync(VERSIONS_DIR);
|
|
230
|
+
for (const ver of versions) {
|
|
231
|
+
if (ver !== `v${keepVersion}` && ver !== keepVersion) {
|
|
232
|
+
const verPath = join(VERSIONS_DIR, ver);
|
|
233
|
+
rmSync(verPath, { recursive: true, force: true });
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
catch { }
|
|
238
|
+
}
|
|
239
|
+
export function clearUpdateData() {
|
|
240
|
+
try {
|
|
241
|
+
if (existsSync(CACHE_FILE))
|
|
242
|
+
unlinkSync(CACHE_FILE);
|
|
243
|
+
if (existsSync(PENDING_FILE))
|
|
244
|
+
unlinkSync(PENDING_FILE);
|
|
245
|
+
}
|
|
246
|
+
catch { }
|
|
247
|
+
}
|
|
248
|
+
export function getInstallPath() {
|
|
249
|
+
return ETHOS_HOME;
|
|
250
|
+
}
|
|
251
|
+
export function detectInstallMethod() {
|
|
252
|
+
const execPath = process.execPath;
|
|
253
|
+
if (execPath.includes('bun') || execPath.includes('node')) {
|
|
254
|
+
return {
|
|
255
|
+
method: 'dev',
|
|
256
|
+
supportsAutoUpdate: false,
|
|
257
|
+
updateCommand: 'git pull && bun install && bun run build',
|
|
258
|
+
};
|
|
259
|
+
}
|
|
260
|
+
if (execPath.startsWith(ETHOS_HOME)) {
|
|
261
|
+
return {
|
|
262
|
+
method: 'curl',
|
|
263
|
+
supportsAutoUpdate: true,
|
|
264
|
+
updateCommand: 'Updates automatically',
|
|
265
|
+
};
|
|
266
|
+
}
|
|
267
|
+
if (execPath.includes('/homebrew/') || execPath.includes('/Cellar/')) {
|
|
268
|
+
return {
|
|
269
|
+
method: 'homebrew',
|
|
270
|
+
supportsAutoUpdate: false,
|
|
271
|
+
updateCommand: 'brew upgrade ethos',
|
|
272
|
+
};
|
|
273
|
+
}
|
|
274
|
+
if (execPath.includes('node_modules') || execPath.includes('npm') || execPath.includes('npx')) {
|
|
275
|
+
return {
|
|
276
|
+
method: 'npm',
|
|
277
|
+
supportsAutoUpdate: false,
|
|
278
|
+
updateCommand: 'npm update -g @trust-ethos/cli',
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
return {
|
|
282
|
+
method: 'unknown',
|
|
283
|
+
supportsAutoUpdate: false,
|
|
284
|
+
updateCommand: 'Visit https://github.com/trust-ethos/ethos-cli for update instructions',
|
|
285
|
+
};
|
|
286
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type IdentifierType = 'address' | 'ens' | 'twitter' | 'discord' | 'telegram' | 'farcaster' | 'profileId' | 'unknown';
|
|
2
|
+
export interface ParsedIdentifier {
|
|
3
|
+
type: IdentifierType;
|
|
4
|
+
value: string;
|
|
5
|
+
original: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function parseIdentifier(identifier: string): ParsedIdentifier;
|
|
8
|
+
export declare function toUserkey(parsed: ParsedIdentifier): string;
|
|
9
|
+
export declare function isValidIdentifier(identifier: string): boolean;
|
|
10
|
+
/** @deprecated Use parseIdentifier instead */
|
|
11
|
+
export declare function parseUserkey(identifier: string): string;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
const EXPLICIT_PREFIX_MAP = {
|
|
2
|
+
'address': 'address',
|
|
3
|
+
'twitter': 'twitter',
|
|
4
|
+
'x': 'twitter',
|
|
5
|
+
'discord': 'discord',
|
|
6
|
+
'telegram': 'telegram',
|
|
7
|
+
'farcaster': 'farcaster',
|
|
8
|
+
'profileid': 'profileId',
|
|
9
|
+
'profile': 'profileId',
|
|
10
|
+
'service': 'unknown',
|
|
11
|
+
};
|
|
12
|
+
const SERVICE_TYPE_MAP = {
|
|
13
|
+
'x.com': 'twitter',
|
|
14
|
+
'discord': 'discord',
|
|
15
|
+
'telegram': 'telegram',
|
|
16
|
+
'farcaster': 'farcaster',
|
|
17
|
+
};
|
|
18
|
+
function parseExplicitPrefix(identifier) {
|
|
19
|
+
if (!identifier.includes(':'))
|
|
20
|
+
return null;
|
|
21
|
+
const colonIndex = identifier.indexOf(':');
|
|
22
|
+
const prefix = identifier.substring(0, colonIndex).toLowerCase();
|
|
23
|
+
const value = identifier.substring(colonIndex + 1);
|
|
24
|
+
if (prefix === 'service') {
|
|
25
|
+
const parts = value.split(':');
|
|
26
|
+
const serviceType = SERVICE_TYPE_MAP[parts[0]];
|
|
27
|
+
if (serviceType) {
|
|
28
|
+
return { type: serviceType, value: parts.slice(1).join(':'), original: identifier };
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const type = EXPLICIT_PREFIX_MAP[prefix];
|
|
32
|
+
if (type && type !== 'unknown') {
|
|
33
|
+
return { type, value, original: identifier };
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
export function parseIdentifier(identifier) {
|
|
38
|
+
const trimmed = identifier.trim();
|
|
39
|
+
const explicitResult = parseExplicitPrefix(trimmed);
|
|
40
|
+
if (explicitResult)
|
|
41
|
+
return explicitResult;
|
|
42
|
+
if (/^0x[a-fA-F0-9]{40}$/i.test(trimmed)) {
|
|
43
|
+
return { type: 'address', value: trimmed, original: trimmed };
|
|
44
|
+
}
|
|
45
|
+
if (trimmed.toLowerCase().endsWith('.eth')) {
|
|
46
|
+
return { type: 'ens', value: trimmed, original: trimmed };
|
|
47
|
+
}
|
|
48
|
+
if (/^\d+$/.test(trimmed)) {
|
|
49
|
+
return { type: 'profileId', value: trimmed, original: trimmed };
|
|
50
|
+
}
|
|
51
|
+
return { type: 'twitter', value: trimmed, original: trimmed };
|
|
52
|
+
}
|
|
53
|
+
export function toUserkey(parsed) {
|
|
54
|
+
switch (parsed.type) {
|
|
55
|
+
case 'address':
|
|
56
|
+
return `address:${parsed.value}`;
|
|
57
|
+
case 'profileId':
|
|
58
|
+
return `profileId:${parsed.value}`;
|
|
59
|
+
case 'twitter':
|
|
60
|
+
return `service:x.com:${parsed.value}`;
|
|
61
|
+
case 'discord':
|
|
62
|
+
return `service:discord:${parsed.value}`;
|
|
63
|
+
case 'telegram':
|
|
64
|
+
return `service:telegram:${parsed.value}`;
|
|
65
|
+
case 'farcaster':
|
|
66
|
+
return `service:farcaster:${parsed.value}`;
|
|
67
|
+
default:
|
|
68
|
+
return parsed.original;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
export function isValidIdentifier(identifier) {
|
|
72
|
+
return Boolean(identifier && identifier.trim().length > 0);
|
|
73
|
+
}
|
|
74
|
+
/** @deprecated Use parseIdentifier instead */
|
|
75
|
+
export function parseUserkey(identifier) {
|
|
76
|
+
const parsed = parseIdentifier(identifier);
|
|
77
|
+
if (parsed.type === 'address') {
|
|
78
|
+
return `address:${parsed.value}`;
|
|
79
|
+
}
|
|
80
|
+
return identifier;
|
|
81
|
+
}
|