@trustwallet/cli 0.6.3 → 0.6.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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"auth.d.ts","sourceRoot":"","sources":["../../src/commands/auth.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAKpC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAyC1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../../src/commands/init.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAoBpC,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA6D1D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/commands/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"query.d.ts","sourceRoot":"","sources":["../../src/commands/query.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAmBpC,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAqf3D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/commands/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,
|
|
1
|
+
{"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/commands/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAsBpC,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA0pB5D"}
|
package/dist/index.js
CHANGED
|
@@ -49,6 +49,13 @@
|
|
|
49
49
|
head: { appendChild: function(){} }
|
|
50
50
|
};
|
|
51
51
|
}
|
|
52
|
+
// --- Suppress Node.js --localstorage-file warning from Trust SDK WASM ---
|
|
53
|
+
var _origEmit = process.emitWarning;
|
|
54
|
+
process.emitWarning = function(warning) {
|
|
55
|
+
if (typeof warning === 'string' && warning.indexOf('--localstorage-file') !== -1) return;
|
|
56
|
+
return _origEmit.apply(process, arguments);
|
|
57
|
+
};
|
|
58
|
+
|
|
52
59
|
if (typeof globalThis.window === 'undefined') globalThis.window = globalThis;
|
|
53
60
|
if (typeof globalThis.self === 'undefined') globalThis.self = globalThis;
|
|
54
61
|
if (typeof globalThis.navigator === 'undefined') globalThis.navigator = { onLine: true, userAgent: 'Mozilla/5.0 (twak)' };
|
|
@@ -216,8 +223,8 @@ var init_dist = __esm({
|
|
|
216
223
|
setPassword(service, account, password) {
|
|
217
224
|
(0, import_child_process.execFileSync)(
|
|
218
225
|
"security",
|
|
219
|
-
["add-generic-password", "-s", service, "-a", account, "-w"
|
|
220
|
-
{ input: password, stdio: ["pipe", "pipe", "pipe"] }
|
|
226
|
+
["add-generic-password", "-U", "-s", service, "-a", account, "-w"],
|
|
227
|
+
{ input: password + "\n", stdio: ["pipe", "pipe", "pipe"] }
|
|
221
228
|
);
|
|
222
229
|
},
|
|
223
230
|
deletePassword(service, account) {
|
|
@@ -456,6 +463,7 @@ __export(dist_exports, {
|
|
|
456
463
|
getChainByEvmId: () => getChainByEvmId,
|
|
457
464
|
getChainById: () => getChainById,
|
|
458
465
|
getChainDomainId: () => getChainDomainId,
|
|
466
|
+
getChainMapKey: () => getChainMapKey,
|
|
459
467
|
getEVMChains: () => getEVMChains,
|
|
460
468
|
getExplorerTxUrl: () => getExplorerTxUrl,
|
|
461
469
|
getNativeAddressPlaceholder: () => getNativeAddressPlaceholder,
|
|
@@ -495,12 +503,19 @@ function getEVMChains() {
|
|
|
495
503
|
function isChainSupported(chainKey) {
|
|
496
504
|
return chainKey.toLowerCase() in CHAINS;
|
|
497
505
|
}
|
|
498
|
-
function
|
|
506
|
+
function getChainMapKey(chainKey) {
|
|
499
507
|
const lower = chainKey.toLowerCase();
|
|
500
508
|
if (CHAINS[lower]) return lower;
|
|
501
|
-
const
|
|
502
|
-
|
|
503
|
-
|
|
509
|
+
const entry = Object.entries(CHAINS).find(([, c]) => c.id === lower);
|
|
510
|
+
return entry?.[0];
|
|
511
|
+
}
|
|
512
|
+
function getChainDomainId(chainKey) {
|
|
513
|
+
const lower = chainKey.toLowerCase();
|
|
514
|
+
const chain = CHAINS[lower];
|
|
515
|
+
if (chain) return chain.id;
|
|
516
|
+
const entry = Object.entries(CHAINS).find(([, c]) => c.id === lower);
|
|
517
|
+
if (!entry) throw new Error(`Unsupported chain: ${chainKey}`);
|
|
518
|
+
return entry[1].id;
|
|
504
519
|
}
|
|
505
520
|
function getExplorerTxUrl(chainKey, txHash) {
|
|
506
521
|
const chain = getChainById(chainKey);
|
|
@@ -540,18 +555,19 @@ function resolveToken(token, chainKey) {
|
|
|
540
555
|
}
|
|
541
556
|
const upperToken = token.toUpperCase();
|
|
542
557
|
const chainConfig = getChainById(chainKey);
|
|
558
|
+
const mapKey = getChainMapKey(chainKey) ?? chainKey.toLowerCase();
|
|
559
|
+
const isBsc = mapKey === "bsc";
|
|
560
|
+
const chainTokens = COMMON_TOKENS[mapKey];
|
|
561
|
+
if (chainTokens?.[upperToken]) {
|
|
562
|
+
const decimals = isBsc && BSC_18_DECIMAL_TOKENS.has(upperToken) ? 18 : TOKEN_DECIMALS[upperToken] ?? 18;
|
|
563
|
+
return { address: chainTokens[upperToken], decimals };
|
|
564
|
+
}
|
|
543
565
|
if (NATIVE_SYMBOLS.has(upperToken) || chainConfig && upperToken === chainConfig.symbol.toUpperCase()) {
|
|
544
566
|
return {
|
|
545
567
|
address: getNativeAddressPlaceholder(chainKey),
|
|
546
568
|
decimals: chainConfig?.decimals ?? 18
|
|
547
569
|
};
|
|
548
570
|
}
|
|
549
|
-
const chainTokens = COMMON_TOKENS[chainKey.toLowerCase()];
|
|
550
|
-
const isBsc = chainKey.toLowerCase() === "bsc" || chainKey.toLowerCase() === "smartchain";
|
|
551
|
-
if (chainTokens?.[upperToken]) {
|
|
552
|
-
const decimals = isBsc && BSC_18_DECIMAL_TOKENS.has(upperToken) ? 18 : TOKEN_DECIMALS[upperToken] ?? 18;
|
|
553
|
-
return { address: chainTokens[upperToken], decimals };
|
|
554
|
-
}
|
|
555
571
|
if (upperToken.startsWith("USDC")) {
|
|
556
572
|
const addr = chainTokens?.["USDC.e"] || chainTokens?.["USDC"] || token;
|
|
557
573
|
return { address: addr, decimals: isBsc ? 18 : 6 };
|
|
@@ -1066,7 +1082,8 @@ var init_dist2 = __esm({
|
|
|
1066
1082
|
"USDC.e": "0xFF970A61A04b1cA14834A43f5dE4533eBDDB5CC8",
|
|
1067
1083
|
DAI: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
|
|
1068
1084
|
WETH: "0x82aF49447D8a07e3bd95BD0d56f35241523fBab1",
|
|
1069
|
-
WBTC: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f"
|
|
1085
|
+
WBTC: "0x2f2a2543B76A4166549F7aaB2e75Bef0aefC5B0f",
|
|
1086
|
+
ARB: "0x912CE59144191C1204E64559FE8253a0e49E6548"
|
|
1070
1087
|
},
|
|
1071
1088
|
polygon: {
|
|
1072
1089
|
USDT: "0xc2132D05D31c914a87C6611C10748AEb04B58e8F",
|
|
@@ -1082,6 +1099,7 @@ var init_dist2 = __esm({
|
|
|
1082
1099
|
BUSD: "0xe9e7CEA3DedcA5984780Bafc599bD69ADd087D56",
|
|
1083
1100
|
DAI: "0x1AF3F329e8BE154074D8769D1FFa4eE058B1DBc3",
|
|
1084
1101
|
WBNB: "0xbb4CdB9CBd36B01bD1cBaEBF2De08d9173bc095c",
|
|
1102
|
+
ETH: "0x2170Ed0880ac9A755fd29B2688956BD959F933F8",
|
|
1085
1103
|
TWT: "0x4B0F1812e5Df2A09796481Ff14017e6005508003"
|
|
1086
1104
|
},
|
|
1087
1105
|
base: {
|
|
@@ -1102,7 +1120,8 @@ var init_dist2 = __esm({
|
|
|
1102
1120
|
USDC: "0x0b2C639c533813f4Aa9D7837CAf62653d097Ff85",
|
|
1103
1121
|
"USDC.e": "0x7F5c764cBc14f9669B88837ca1490cCa17c31607",
|
|
1104
1122
|
DAI: "0xDA10009cBd5D07dd0CeCc66161FC93D7c9000da1",
|
|
1105
|
-
WETH: "0x4200000000000000000000000000000000000006"
|
|
1123
|
+
WETH: "0x4200000000000000000000000000000000000006",
|
|
1124
|
+
OP: "0x4200000000000000000000000000000000000042"
|
|
1106
1125
|
},
|
|
1107
1126
|
tron: {
|
|
1108
1127
|
USDT: "TR7NHqjeKQxGTCi8q8ZY4pL8otSzgjLj6t",
|
|
@@ -2728,7 +2747,7 @@ var init_dist5 = __esm({
|
|
|
2728
2747
|
};
|
|
2729
2748
|
});
|
|
2730
2749
|
}
|
|
2731
|
-
async getTrendingTokens(limit = 20) {
|
|
2750
|
+
async getTrendingTokens(limit = 20, sort = "percent_change_24h") {
|
|
2732
2751
|
const knownAssets = [
|
|
2733
2752
|
"c60",
|
|
2734
2753
|
"c501",
|
|
@@ -2756,7 +2775,8 @@ var init_dist5 = __esm({
|
|
|
2756
2775
|
assets: knownAssets
|
|
2757
2776
|
});
|
|
2758
2777
|
const tickers = response.tickers || [];
|
|
2759
|
-
|
|
2778
|
+
const sortKey = sort === "market_cap" ? "market_cap" : sort === "volume_24h" ? "volume_24h" : "change_24h";
|
|
2779
|
+
return tickers.sort((a, b) => (b[sortKey] ?? 0) - (a[sortKey] ?? 0)).slice(0, limit).map((t) => {
|
|
2760
2780
|
const coinId = t.id ? parseInt(t.id.replace(/^c/, ""), 10) : NaN;
|
|
2761
2781
|
const chain = !isNaN(coinId) ? coinTypeToChainKey(coinId) || "" : "";
|
|
2762
2782
|
return {
|
|
@@ -2768,7 +2788,7 @@ var init_dist5 = __esm({
|
|
|
2768
2788
|
priceUsd: t.price,
|
|
2769
2789
|
priceChange24h: t.change_24h,
|
|
2770
2790
|
marketCapUsd: t.market_cap,
|
|
2771
|
-
volume24hUsd:
|
|
2791
|
+
volume24hUsd: t.volume_24h
|
|
2772
2792
|
};
|
|
2773
2793
|
});
|
|
2774
2794
|
}
|
|
@@ -12170,59 +12190,91 @@ function info(message) {
|
|
|
12170
12190
|
console.log(import_chalk.default.cyan(message));
|
|
12171
12191
|
}
|
|
12172
12192
|
|
|
12173
|
-
// src/
|
|
12193
|
+
// src/config-loader.ts
|
|
12174
12194
|
var import_chalk2 = __toESM(require("chalk"));
|
|
12175
|
-
|
|
12176
|
-
|
|
12177
|
-
|
|
12178
|
-
|
|
12179
|
-
|
|
12180
|
-
|
|
12181
|
-
|
|
12182
|
-
|
|
12183
|
-
|
|
12184
|
-
|
|
12185
|
-
|
|
12186
|
-
|
|
12187
|
-
|
|
12188
|
-
|
|
12189
|
-
"
|
|
12190
|
-
"
|
|
12191
|
-
|
|
12192
|
-
" @@@@@@@@@@@%%%%%%%%%%% ",
|
|
12193
|
-
" @@@@@@@@@@@@@%%%%% ",
|
|
12194
|
-
" @@@@@@@@@@@@@@ ",
|
|
12195
|
-
" @@@@@@@@@@ ",
|
|
12196
|
-
" @@ "
|
|
12197
|
-
];
|
|
12198
|
-
function printBanner(version2) {
|
|
12199
|
-
const logo = SHIELD.map((l) => import_chalk2.default.green(l)).join("\n");
|
|
12200
|
-
const title = import_chalk2.default.green.bold(" Trust Wallet Agent Kit");
|
|
12201
|
-
const ver = import_chalk2.default.dim(` v${version2}`);
|
|
12202
|
-
console.log(
|
|
12203
|
-
boxen(`${logo}
|
|
12204
|
-
|
|
12205
|
-
${title}
|
|
12206
|
-
${ver}`, {
|
|
12207
|
-
borderColor: "green",
|
|
12208
|
-
borderStyle: "round",
|
|
12209
|
-
padding: { top: 1, bottom: 1, left: 2, right: 2 }
|
|
12210
|
-
})
|
|
12211
|
-
);
|
|
12195
|
+
init_dist2();
|
|
12196
|
+
init_dist4();
|
|
12197
|
+
init_dist();
|
|
12198
|
+
async function getCredentials() {
|
|
12199
|
+
const envAccessId = process.env.TWAK_ACCESS_ID;
|
|
12200
|
+
const envSecret = process.env.TWAK_HMAC_SECRET;
|
|
12201
|
+
if (envAccessId && envSecret) {
|
|
12202
|
+
return { accessId: envAccessId, hmacSecret: envSecret };
|
|
12203
|
+
}
|
|
12204
|
+
const credManager = new CredentialManager();
|
|
12205
|
+
const credentials = await credManager.load();
|
|
12206
|
+
if (credentials) {
|
|
12207
|
+
return { accessId: credentials.accessId, hmacSecret: credentials.hmacSecret };
|
|
12208
|
+
}
|
|
12209
|
+
console.error(import_chalk2.default.red("No API credentials found."));
|
|
12210
|
+
console.error(import_chalk2.default.dim("Set TWAK_ACCESS_ID and TWAK_HMAC_SECRET environment variables, then run `twak init`"));
|
|
12211
|
+
process.exit(1);
|
|
12212
12212
|
}
|
|
12213
|
-
function
|
|
12214
|
-
|
|
12215
|
-
|
|
12216
|
-
|
|
12217
|
-
|
|
12213
|
+
async function getClient() {
|
|
12214
|
+
const creds = await getCredentials();
|
|
12215
|
+
return createTwakClient({ ...creds });
|
|
12216
|
+
}
|
|
12217
|
+
async function ensureTrustSDK() {
|
|
12218
|
+
const creds = await getCredentials();
|
|
12219
|
+
await initTrustSDK({
|
|
12220
|
+
accessId: creds.accessId,
|
|
12221
|
+
hmacSecret: creds.hmacSecret,
|
|
12222
|
+
naasSessionId: process.env.TWAK_NAAS_SESSION_ID
|
|
12218
12223
|
});
|
|
12224
|
+
return creds;
|
|
12225
|
+
}
|
|
12226
|
+
async function registerWalletWithBackend(creds, provider) {
|
|
12227
|
+
const accounts = [];
|
|
12228
|
+
for (const key of Object.keys(CHAINS)) {
|
|
12229
|
+
const chain = getChainById(key);
|
|
12230
|
+
if (!chain) continue;
|
|
12231
|
+
try {
|
|
12232
|
+
const address = await provider.getAddress(key);
|
|
12233
|
+
if (address) accounts.push({ coin: chain.coinId, address });
|
|
12234
|
+
} catch {
|
|
12235
|
+
}
|
|
12236
|
+
}
|
|
12237
|
+
if (accounts.length > 0) {
|
|
12238
|
+
await registerDeviceAndWallet(creds, accounts);
|
|
12239
|
+
}
|
|
12219
12240
|
}
|
|
12241
|
+
async function resolvePassword(opts) {
|
|
12242
|
+
if (opts?.password) {
|
|
12243
|
+
process.stderr.write(
|
|
12244
|
+
import_chalk2.default.yellow("Note: --password is visible in shell history. Use `twak wallet keychain save` or TWAK_WALLET_PASSWORD instead.\n")
|
|
12245
|
+
);
|
|
12246
|
+
return opts.password;
|
|
12247
|
+
}
|
|
12248
|
+
if (process.env.TWAK_WALLET_PASSWORD) return process.env.TWAK_WALLET_PASSWORD;
|
|
12249
|
+
const kc = new KeychainManager();
|
|
12250
|
+
const stored = await kc.getWalletPassword();
|
|
12251
|
+
if (stored) return stored;
|
|
12252
|
+
throw new Error(
|
|
12253
|
+
"No wallet password found. Provide --password, set TWAK_WALLET_PASSWORD, or run `twak wallet keychain save --password <pw>`"
|
|
12254
|
+
);
|
|
12255
|
+
}
|
|
12256
|
+
|
|
12257
|
+
// ../wallet/dist/index.mjs
|
|
12258
|
+
init_dist3();
|
|
12259
|
+
|
|
12260
|
+
// ../walletconnect/dist/index.mjs
|
|
12261
|
+
init_dist3();
|
|
12220
12262
|
|
|
12221
12263
|
// src/commands/init.ts
|
|
12264
|
+
async function tryRegisterWallet() {
|
|
12265
|
+
const store = new WalletConfigStore();
|
|
12266
|
+
if (!await store.exists()) return;
|
|
12267
|
+
try {
|
|
12268
|
+
const creds = await ensureTrustSDK();
|
|
12269
|
+
const password = await resolvePassword();
|
|
12270
|
+
const provider = await AgentWalletProvider.fromStorage(password);
|
|
12271
|
+
await registerWalletWithBackend(creds, provider);
|
|
12272
|
+
info("Wallet registered with backend");
|
|
12273
|
+
} catch {
|
|
12274
|
+
}
|
|
12275
|
+
}
|
|
12222
12276
|
function registerInitCommand(program2) {
|
|
12223
12277
|
program2.command("init").description("Initialize twak configuration").option("--api-key <key>", "TWAK API access ID (prefer TWAK_ACCESS_ID env var)").option("--api-secret <secret>", "TWAK HMAC secret (prefer TWAK_HMAC_SECRET env var)").option("--wc-project-id <id>", "WalletConnect project ID").action(async (opts) => {
|
|
12224
|
-
printBanner(program2.version() ?? "0.2.0");
|
|
12225
|
-
console.log("");
|
|
12226
12278
|
const credManager = new CredentialManager();
|
|
12227
12279
|
if (opts.apiKey && opts.apiSecret) {
|
|
12228
12280
|
warn("Secrets passed as CLI arguments are visible in shell history.");
|
|
@@ -12234,6 +12286,8 @@ function registerInitCommand(program2) {
|
|
|
12234
12286
|
walletConnectProjectId: opts.wcProjectId
|
|
12235
12287
|
});
|
|
12236
12288
|
success("Credentials saved to ~/.twak/credentials.json");
|
|
12289
|
+
await tryRegisterWallet();
|
|
12290
|
+
info("\nNext step: create a wallet with `twak wallet create --password <pw>`");
|
|
12237
12291
|
return;
|
|
12238
12292
|
}
|
|
12239
12293
|
const envAccessId = process.env.TWAK_ACCESS_ID;
|
|
@@ -12246,6 +12300,8 @@ function registerInitCommand(program2) {
|
|
|
12246
12300
|
walletConnectProjectId: envWcId
|
|
12247
12301
|
});
|
|
12248
12302
|
success("Credentials saved from environment variables to ~/.twak/credentials.json");
|
|
12303
|
+
await tryRegisterWallet();
|
|
12304
|
+
info("\nNext step: create a wallet with `twak wallet create --password <pw>`");
|
|
12249
12305
|
return;
|
|
12250
12306
|
}
|
|
12251
12307
|
const existing = await credManager.load();
|
|
@@ -12267,6 +12323,7 @@ function registerInitCommand(program2) {
|
|
|
12267
12323
|
}
|
|
12268
12324
|
|
|
12269
12325
|
// src/commands/auth.ts
|
|
12326
|
+
var import_chalk3 = __toESM(require("chalk"));
|
|
12270
12327
|
init_dist();
|
|
12271
12328
|
function registerAuthCommand(program2) {
|
|
12272
12329
|
const auth = program2.command("auth").description("Manage authentication");
|
|
@@ -12283,91 +12340,74 @@ function registerAuthCommand(program2) {
|
|
|
12283
12340
|
const credManager = new CredentialManager();
|
|
12284
12341
|
const creds = await credManager.load();
|
|
12285
12342
|
const envConfigured = !!(process.env.TWAK_ACCESS_ID && process.env.TWAK_HMAC_SECRET);
|
|
12286
|
-
const
|
|
12287
|
-
|
|
12288
|
-
|
|
12289
|
-
|
|
12290
|
-
|
|
12291
|
-
|
|
12343
|
+
const configured = !!creds || envConfigured;
|
|
12344
|
+
const source = creds ? "file" : envConfigured ? "environment" : "none";
|
|
12345
|
+
const accessId = creds?.accessId?.slice(0, 8) || process.env.TWAK_ACCESS_ID?.slice(0, 8) || null;
|
|
12346
|
+
if (opts.json) {
|
|
12347
|
+
output({ configured, source, accessId }, true);
|
|
12348
|
+
} else {
|
|
12349
|
+
console.log(` ${import_chalk3.default.dim("Status")} ${configured ? import_chalk3.default.green("configured") : import_chalk3.default.yellow("not configured")}`);
|
|
12350
|
+
console.log(` ${import_chalk3.default.dim("Source")} ${source}`);
|
|
12351
|
+
if (accessId) console.log(` ${import_chalk3.default.dim("Access ID")} ${accessId}...`);
|
|
12352
|
+
if (!configured) info("\nRun `twak init` to set up credentials.");
|
|
12353
|
+
}
|
|
12292
12354
|
});
|
|
12293
12355
|
}
|
|
12294
12356
|
|
|
12295
|
-
// ../wallet/dist/index.mjs
|
|
12296
|
-
init_dist3();
|
|
12297
|
-
|
|
12298
|
-
// ../walletconnect/dist/index.mjs
|
|
12299
|
-
init_dist3();
|
|
12300
|
-
|
|
12301
12357
|
// src/commands/wallet.ts
|
|
12302
12358
|
init_dist();
|
|
12359
|
+
var import_chalk5 = __toESM(require("chalk"));
|
|
12360
|
+
init_dist2();
|
|
12361
|
+
|
|
12362
|
+
// src/branding.ts
|
|
12303
12363
|
var import_chalk4 = __toESM(require("chalk"));
|
|
12364
|
+
var boxen = require("boxen");
|
|
12365
|
+
var SHIELD = [
|
|
12366
|
+
" @@=+ ",
|
|
12367
|
+
" @@@@@@@======= ",
|
|
12368
|
+
" @@@@@@@@@@@@@============+ ",
|
|
12369
|
+
" @@@@@@@@@@@@@@@@================ ",
|
|
12370
|
+
" @@@@@@@@@@@@@@@@+=============== ",
|
|
12371
|
+
" @@@@@@@@@@@@@@@@++++============ ",
|
|
12372
|
+
" @@@@@@@@@@@@@@@@++++++++++=====+ ",
|
|
12373
|
+
" @@@@@@@@@@@@@@@@**++++++++++++++ ",
|
|
12374
|
+
" @@@@@@@@@@@@@@@@********++++++++ ",
|
|
12375
|
+
" @@@@@@@@@@@@@@@@**************++ ",
|
|
12376
|
+
" @@@@@@@@@@@@@@@@#####*********** ",
|
|
12377
|
+
" @@@@@@@@@@@@@@@###########**** ",
|
|
12378
|
+
" @@@@@@@@@@@@@@%############## ",
|
|
12379
|
+
" @@@@@@@@@@@@@@%%%%%%%####### ",
|
|
12380
|
+
" @@@@@@@@@@@@@%%%%%%%%%%%%% ",
|
|
12381
|
+
" @@@@@@@@@@@%%%%%%%%%%% ",
|
|
12382
|
+
" @@@@@@@@@@@@@%%%%% ",
|
|
12383
|
+
" @@@@@@@@@@@@@@ ",
|
|
12384
|
+
" @@@@@@@@@@ ",
|
|
12385
|
+
" @@ "
|
|
12386
|
+
];
|
|
12387
|
+
function printBanner(version2) {
|
|
12388
|
+
const logo = SHIELD.map((l) => import_chalk4.default.green(l)).join("\n");
|
|
12389
|
+
const title = import_chalk4.default.green.bold(" Trust Wallet Agent Kit");
|
|
12390
|
+
const ver = import_chalk4.default.dim(` v${version2}`);
|
|
12391
|
+
console.log(
|
|
12392
|
+
boxen(`${logo}
|
|
12304
12393
|
|
|
12305
|
-
|
|
12306
|
-
|
|
12307
|
-
|
|
12308
|
-
|
|
12309
|
-
|
|
12310
|
-
|
|
12311
|
-
|
|
12312
|
-
const envSecret = process.env.TWAK_HMAC_SECRET;
|
|
12313
|
-
if (envAccessId && envSecret) {
|
|
12314
|
-
return { accessId: envAccessId, hmacSecret: envSecret };
|
|
12315
|
-
}
|
|
12316
|
-
const credManager = new CredentialManager();
|
|
12317
|
-
const credentials = await credManager.load();
|
|
12318
|
-
if (credentials) {
|
|
12319
|
-
return { accessId: credentials.accessId, hmacSecret: credentials.hmacSecret };
|
|
12320
|
-
}
|
|
12321
|
-
console.error(import_chalk3.default.red("No API credentials found."));
|
|
12322
|
-
console.error(import_chalk3.default.dim("Set TWAK_ACCESS_ID and TWAK_HMAC_SECRET environment variables, then run `twak init`"));
|
|
12323
|
-
process.exit(1);
|
|
12324
|
-
}
|
|
12325
|
-
async function getClient() {
|
|
12326
|
-
const creds = await getCredentials();
|
|
12327
|
-
return createTwakClient({ ...creds });
|
|
12394
|
+
${title}
|
|
12395
|
+
${ver}`, {
|
|
12396
|
+
borderColor: "green",
|
|
12397
|
+
borderStyle: "round",
|
|
12398
|
+
padding: { top: 1, bottom: 1, left: 2, right: 2 }
|
|
12399
|
+
})
|
|
12400
|
+
);
|
|
12328
12401
|
}
|
|
12329
|
-
|
|
12330
|
-
|
|
12331
|
-
|
|
12332
|
-
|
|
12333
|
-
|
|
12334
|
-
naasSessionId: process.env.TWAK_NAAS_SESSION_ID
|
|
12402
|
+
function box(content) {
|
|
12403
|
+
return boxen(content, {
|
|
12404
|
+
borderColor: "green",
|
|
12405
|
+
borderStyle: "round",
|
|
12406
|
+
padding: { top: 0, bottom: 0, left: 1, right: 1 }
|
|
12335
12407
|
});
|
|
12336
|
-
return creds;
|
|
12337
|
-
}
|
|
12338
|
-
async function registerWalletWithBackend(creds, provider) {
|
|
12339
|
-
const accounts = [];
|
|
12340
|
-
for (const key of Object.keys(CHAINS)) {
|
|
12341
|
-
const chain = getChainById(key);
|
|
12342
|
-
if (!chain) continue;
|
|
12343
|
-
try {
|
|
12344
|
-
const address = await provider.getAddress(key);
|
|
12345
|
-
if (address) accounts.push({ coin: chain.coinId, address });
|
|
12346
|
-
} catch {
|
|
12347
|
-
}
|
|
12348
|
-
}
|
|
12349
|
-
if (accounts.length > 0) {
|
|
12350
|
-
await registerDeviceAndWallet(creds, accounts);
|
|
12351
|
-
}
|
|
12352
|
-
}
|
|
12353
|
-
async function resolvePassword(opts) {
|
|
12354
|
-
if (opts?.password) {
|
|
12355
|
-
process.stderr.write(
|
|
12356
|
-
import_chalk3.default.yellow("Note: --password is visible in shell history. Use `twak wallet keychain save` or TWAK_WALLET_PASSWORD instead.\n")
|
|
12357
|
-
);
|
|
12358
|
-
return opts.password;
|
|
12359
|
-
}
|
|
12360
|
-
if (process.env.TWAK_WALLET_PASSWORD) return process.env.TWAK_WALLET_PASSWORD;
|
|
12361
|
-
const kc = new KeychainManager();
|
|
12362
|
-
const stored = await kc.getWalletPassword();
|
|
12363
|
-
if (stored) return stored;
|
|
12364
|
-
throw new Error(
|
|
12365
|
-
"No wallet password found. Provide --password, set TWAK_WALLET_PASSWORD, or run `twak wallet keychain save --password <pw>`"
|
|
12366
|
-
);
|
|
12367
12408
|
}
|
|
12368
12409
|
|
|
12369
12410
|
// src/commands/wallet.ts
|
|
12370
|
-
init_dist2();
|
|
12371
12411
|
var qrcode = require("qrcode-terminal");
|
|
12372
12412
|
function getQRString(address) {
|
|
12373
12413
|
let result = "";
|
|
@@ -12383,7 +12423,7 @@ function registerWalletCommand(program2) {
|
|
|
12383
12423
|
await ensureTrustSDK();
|
|
12384
12424
|
const store = new WalletConfigStore();
|
|
12385
12425
|
if (await store.exists()) {
|
|
12386
|
-
const msg = "Wallet already exists.
|
|
12426
|
+
const msg = "Wallet already exists. Back up ~/.twak/wallet.json, then delete it to create a new one.";
|
|
12387
12427
|
error(msg);
|
|
12388
12428
|
if (opts.json) output({ error: msg }, true);
|
|
12389
12429
|
process.exitCode = 1;
|
|
@@ -12392,7 +12432,6 @@ function registerWalletCommand(program2) {
|
|
|
12392
12432
|
}
|
|
12393
12433
|
const provider = await AgentWalletProvider.create(opts.password);
|
|
12394
12434
|
const addresses = await provider.getAddresses();
|
|
12395
|
-
if (!opts.json) success("Agent wallet created successfully");
|
|
12396
12435
|
if (opts.keychain !== false) {
|
|
12397
12436
|
const kc = new KeychainManager();
|
|
12398
12437
|
if (kc.isAvailable()) {
|
|
@@ -12400,6 +12439,7 @@ function registerWalletCommand(program2) {
|
|
|
12400
12439
|
if (!opts.json) info("Password saved to OS keychain (use --no-keychain to skip)");
|
|
12401
12440
|
}
|
|
12402
12441
|
}
|
|
12442
|
+
if (!opts.json) success("Agent wallet created successfully");
|
|
12403
12443
|
try {
|
|
12404
12444
|
const creds = await getCredentials();
|
|
12405
12445
|
await registerWalletWithBackend(creds, provider);
|
|
@@ -12430,8 +12470,8 @@ function registerWalletCommand(program2) {
|
|
|
12430
12470
|
output({ chain: opts.chain, address }, true);
|
|
12431
12471
|
} else {
|
|
12432
12472
|
const qr = getQRString(address);
|
|
12433
|
-
const content = `${
|
|
12434
|
-
${
|
|
12473
|
+
const content = `${import_chalk5.default.dim("Chain")} ${import_chalk5.default.bold(opts.chain)}
|
|
12474
|
+
${import_chalk5.default.dim("Address")} ${import_chalk5.default.green(address)}
|
|
12435
12475
|
|
|
12436
12476
|
${qr}`;
|
|
12437
12477
|
console.log(box(content));
|
|
@@ -12462,7 +12502,7 @@ ${qr}`;
|
|
|
12462
12502
|
for (const [address, chains] of grouped) {
|
|
12463
12503
|
const qr = getQRString(address);
|
|
12464
12504
|
const maxWidth = Math.max(address.length + 9, 50);
|
|
12465
|
-
const chainLabel = `${
|
|
12505
|
+
const chainLabel = `${import_chalk5.default.dim("Chains")} `;
|
|
12466
12506
|
const chainLabelLen = 9;
|
|
12467
12507
|
const chainLines = [];
|
|
12468
12508
|
let line = "";
|
|
@@ -12476,9 +12516,9 @@ ${qr}`;
|
|
|
12476
12516
|
}
|
|
12477
12517
|
}
|
|
12478
12518
|
if (line) chainLines.push(line);
|
|
12479
|
-
const chainsStr = chainLines.map((l, i) => (i === 0 ? chainLabel : " ".repeat(chainLabelLen)) +
|
|
12519
|
+
const chainsStr = chainLines.map((l, i) => (i === 0 ? chainLabel : " ".repeat(chainLabelLen)) + import_chalk5.default.bold(l)).join("\n");
|
|
12480
12520
|
const content = `${chainsStr}
|
|
12481
|
-
${
|
|
12521
|
+
${import_chalk5.default.dim("Address")} ${import_chalk5.default.green(address)}
|
|
12482
12522
|
|
|
12483
12523
|
${qr}`;
|
|
12484
12524
|
console.log(box(content));
|
|
@@ -12652,17 +12692,17 @@ ${qr}`;
|
|
|
12652
12692
|
for (let i = 0; i < results.length; i++) {
|
|
12653
12693
|
const r = results[i];
|
|
12654
12694
|
if (i > 0) console.log("");
|
|
12655
|
-
console.log(
|
|
12656
|
-
console.log(` ${
|
|
12657
|
-
console.log(` ${
|
|
12658
|
-
if (r.staked) console.log(` ${
|
|
12659
|
-
if (r.pending) console.log(` ${
|
|
12660
|
-
console.log(` ${
|
|
12695
|
+
console.log(import_chalk5.default.bold.underline(`${String(r.chain)} (${String(r.symbol)})`));
|
|
12696
|
+
console.log(` ${import_chalk5.default.dim("Address")} ${r.address}`);
|
|
12697
|
+
console.log(` ${import_chalk5.default.dim("Available")} ${r.available}`);
|
|
12698
|
+
if (r.staked) console.log(` ${import_chalk5.default.dim("Staked")} ${r.staked}`);
|
|
12699
|
+
if (r.pending) console.log(` ${import_chalk5.default.dim("Pending")} ${r.pending}`);
|
|
12700
|
+
console.log(` ${import_chalk5.default.dim("Total")} ${r.total}`);
|
|
12661
12701
|
const tokens = r.tokens;
|
|
12662
12702
|
if (tokens.length > 0) {
|
|
12663
|
-
console.log(` ${
|
|
12703
|
+
console.log(` ${import_chalk5.default.dim("Tokens:")}`);
|
|
12664
12704
|
for (const t of tokens) {
|
|
12665
|
-
console.log(` ${
|
|
12705
|
+
console.log(` ${import_chalk5.default.bold(t.symbol.padEnd(10))} ${t.balance}`);
|
|
12666
12706
|
}
|
|
12667
12707
|
}
|
|
12668
12708
|
}
|
|
@@ -12688,20 +12728,16 @@ ${qr}`;
|
|
|
12688
12728
|
if (opts.json) {
|
|
12689
12729
|
output(result, true);
|
|
12690
12730
|
} else {
|
|
12691
|
-
|
|
12692
|
-
|
|
12693
|
-
|
|
12694
|
-
|
|
12695
|
-
|
|
12696
|
-
|
|
12697
|
-
...result.pending ? { pending: result.pending } : {},
|
|
12698
|
-
total: result.total
|
|
12699
|
-
}, false);
|
|
12731
|
+
console.log(import_chalk5.default.bold.underline(`${result.chain} (${result.symbol})`));
|
|
12732
|
+
console.log(` ${import_chalk5.default.dim("Address")} ${result.address}`);
|
|
12733
|
+
console.log(` ${import_chalk5.default.dim("Available")} ${result.available}`);
|
|
12734
|
+
if (result.staked) console.log(` ${import_chalk5.default.dim("Staked")} ${result.staked}`);
|
|
12735
|
+
if (result.pending) console.log(` ${import_chalk5.default.dim("Pending")} ${result.pending}`);
|
|
12736
|
+
console.log(` ${import_chalk5.default.dim("Total")} ${result.total}`);
|
|
12700
12737
|
if (result.tokens.length > 0) {
|
|
12701
|
-
console.log("");
|
|
12702
|
-
info("Token balances:");
|
|
12738
|
+
console.log(` ${import_chalk5.default.dim("Tokens:")}`);
|
|
12703
12739
|
for (const t of result.tokens) {
|
|
12704
|
-
console.log(`
|
|
12740
|
+
console.log(` ${import_chalk5.default.bold(t.symbol.padEnd(10))} ${t.balance}`);
|
|
12705
12741
|
}
|
|
12706
12742
|
}
|
|
12707
12743
|
}
|
|
@@ -12756,10 +12792,17 @@ ${qr}`;
|
|
|
12756
12792
|
const exists = await store.exists();
|
|
12757
12793
|
const kc = new KeychainManager();
|
|
12758
12794
|
const keychainHasPassword = kc.isAvailable() ? !!await kc.getWalletPassword() : false;
|
|
12759
|
-
|
|
12795
|
+
const result = {
|
|
12760
12796
|
agentWallet: exists ? "configured" : "not configured",
|
|
12761
12797
|
keychainPassword: keychainHasPassword ? "stored" : "not stored"
|
|
12762
|
-
}
|
|
12798
|
+
};
|
|
12799
|
+
if (opts.json) {
|
|
12800
|
+
output(result, true);
|
|
12801
|
+
} else {
|
|
12802
|
+
console.log(` ${import_chalk5.default.dim("Wallet")} ${exists ? import_chalk5.default.green("configured") : import_chalk5.default.yellow("not configured")}`);
|
|
12803
|
+
console.log(` ${import_chalk5.default.dim("Keychain")} ${keychainHasPassword ? import_chalk5.default.green("password stored") : import_chalk5.default.yellow("no password")}`);
|
|
12804
|
+
if (!exists) info("\nRun `twak wallet create --password <pw>` to create a wallet.");
|
|
12805
|
+
}
|
|
12763
12806
|
});
|
|
12764
12807
|
wallet.command("portfolio").description("Show portfolio balances and USD values across chains, including token holdings").option("--chains <list>", "Comma-separated chain keys (default: all EVM + major L1s)", "ethereum,base,bsc,polygon,arbitrum,optimism,avalanche,fantom,linea,scroll,zksync,blast,sonic,celo,aurora,solana,tron").option("--password <password>", "Wallet password (falls back to keychain / TWAK_WALLET_PASSWORD)").option("--json", "JSON output").action(async (opts) => {
|
|
12765
12808
|
try {
|
|
@@ -13569,9 +13612,9 @@ function registerAlertCommand(program2) {
|
|
|
13569
13612
|
}
|
|
13570
13613
|
const condition = aboveProvided ? "above" : "below";
|
|
13571
13614
|
const targetPrice = parseFloat(aboveProvided ? opts.above : opts.below);
|
|
13572
|
-
if (isNaN(targetPrice)) {
|
|
13573
|
-
error("Price must be a
|
|
13574
|
-
if (opts.json) output({ error: "Price must be a
|
|
13615
|
+
if (isNaN(targetPrice) || targetPrice <= 0) {
|
|
13616
|
+
error("Price must be a positive number");
|
|
13617
|
+
if (opts.json) output({ error: "Price must be a positive number" }, true);
|
|
13575
13618
|
process.exitCode = 1;
|
|
13576
13619
|
return;
|
|
13577
13620
|
}
|
|
@@ -13645,50 +13688,12 @@ function registerAlertCommand(program2) {
|
|
|
13645
13688
|
init_dist2();
|
|
13646
13689
|
|
|
13647
13690
|
// ../transactions/dist/index.mjs
|
|
13691
|
+
init_dist2();
|
|
13648
13692
|
function toRFC3339(value) {
|
|
13649
13693
|
const d = new Date(value);
|
|
13650
13694
|
if (!isNaN(d.getTime())) return d.toISOString();
|
|
13651
13695
|
return value;
|
|
13652
13696
|
}
|
|
13653
|
-
var BLOCKSCOUT_HOSTS = {
|
|
13654
|
-
ethereum: "https://eth.blockscout.com",
|
|
13655
|
-
base: "https://base.blockscout.com",
|
|
13656
|
-
bsc: "https://bsc.blockscout.com",
|
|
13657
|
-
polygon: "https://polygon.blockscout.com",
|
|
13658
|
-
arbitrum: "https://arbitrum.blockscout.com",
|
|
13659
|
-
optimism: "https://optimism.blockscout.com",
|
|
13660
|
-
avalanche: "https://avalanche.blockscout.com",
|
|
13661
|
-
fantom: "https://fantom.blockscout.com",
|
|
13662
|
-
linea: "https://explorer.linea.build",
|
|
13663
|
-
scroll: "https://scroll.blockscout.com",
|
|
13664
|
-
blast: "https://blast.blockscout.com",
|
|
13665
|
-
celo: "https://celo.blockscout.com"
|
|
13666
|
-
};
|
|
13667
|
-
async function getHistoryFromExplorer(address, chain, limit) {
|
|
13668
|
-
const host = BLOCKSCOUT_HOSTS[chain.toLowerCase()];
|
|
13669
|
-
if (!host) return [];
|
|
13670
|
-
const url = `${host}/api/v2/addresses/${address}/transactions`;
|
|
13671
|
-
const resp = await fetch(url, { signal: AbortSignal.timeout(15e3) });
|
|
13672
|
-
if (!resp.ok) {
|
|
13673
|
-
if (resp.status === 404) return [];
|
|
13674
|
-
throw new Error(`Blockscout ${chain} returned ${resp.status}`);
|
|
13675
|
-
}
|
|
13676
|
-
const data = await resp.json();
|
|
13677
|
-
if (!Array.isArray(data.items)) return [];
|
|
13678
|
-
return data.items.slice(0, limit).map((tx) => ({
|
|
13679
|
-
id: tx.hash,
|
|
13680
|
-
hash: tx.hash,
|
|
13681
|
-
chain,
|
|
13682
|
-
type: tx.tx_types?.[0] ?? (tx.to?.is_contract ? "contract" : "transfer"),
|
|
13683
|
-
status: tx.status === "ok" ? "confirmed" : "failed",
|
|
13684
|
-
from: tx.from?.hash ?? tx.from,
|
|
13685
|
-
to: tx.to?.hash ?? tx.to,
|
|
13686
|
-
amount: tx.value,
|
|
13687
|
-
fee: tx.fee?.value ?? "0",
|
|
13688
|
-
date: tx.timestamp,
|
|
13689
|
-
metadata: { blockNumber: tx.block, nonce: tx.nonce }
|
|
13690
|
-
}));
|
|
13691
|
-
}
|
|
13692
13697
|
var TransactionService = class {
|
|
13693
13698
|
constructor(client) {
|
|
13694
13699
|
this.client = client;
|
|
@@ -13696,36 +13701,32 @@ var TransactionService = class {
|
|
|
13696
13701
|
async getHistory(params) {
|
|
13697
13702
|
const from = params.from ?? new Date(Date.now() - 30 * 24 * 60 * 60 * 1e3).toISOString();
|
|
13698
13703
|
const to = params.to ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
13704
|
+
const chainId = params.chain ? getChainById(params.chain)?.id ?? params.chain : void 0;
|
|
13699
13705
|
const query = new URLSearchParams();
|
|
13700
13706
|
query.set("address", params.address);
|
|
13701
13707
|
if (params.asset) query.set("asset", params.asset);
|
|
13702
|
-
if (
|
|
13708
|
+
if (chainId) query.set("chain", chainId);
|
|
13703
13709
|
query.set("from", toRFC3339(from));
|
|
13704
13710
|
query.set("to", toRFC3339(to));
|
|
13705
13711
|
if (params.limit) query.set("limit", params.limit.toString());
|
|
13706
13712
|
if (params.txType) query.set("tx_type", params.txType);
|
|
13707
|
-
|
|
13708
|
-
|
|
13709
|
-
|
|
13710
|
-
|
|
13711
|
-
|
|
13712
|
-
|
|
13713
|
-
|
|
13714
|
-
return response.data || [];
|
|
13715
|
-
} catch (err) {
|
|
13716
|
-
const statusCode = err.statusCode;
|
|
13717
|
-
if (statusCode !== 403 && statusCode !== 401 && statusCode !== 400) throw err;
|
|
13718
|
-
if (params.chain) {
|
|
13719
|
-
return getHistoryFromExplorer(params.address, params.chain, params.limit || 20);
|
|
13720
|
-
}
|
|
13721
|
-
throw err;
|
|
13722
|
-
}
|
|
13713
|
+
const response = await this.client.gateway(
|
|
13714
|
+
"GET",
|
|
13715
|
+
"/v1/txhub/txs",
|
|
13716
|
+
void 0,
|
|
13717
|
+
query.toString()
|
|
13718
|
+
);
|
|
13719
|
+
return response.data || [];
|
|
13723
13720
|
}
|
|
13724
13721
|
async getBulkHistory(params) {
|
|
13725
13722
|
const from = params.from ?? new Date(Date.now() - 30 * 24 * 60 * 60 * 1e3).toISOString();
|
|
13726
13723
|
const to = params.to ?? (/* @__PURE__ */ new Date()).toISOString();
|
|
13724
|
+
const addresses = params.addresses.map((a) => ({
|
|
13725
|
+
...a,
|
|
13726
|
+
chain: getChainById(a.chain)?.id ?? a.chain
|
|
13727
|
+
}));
|
|
13727
13728
|
const response = await this.client.gateway("POST", "/v1/txhub/bulk_history", {
|
|
13728
|
-
addresses
|
|
13729
|
+
addresses,
|
|
13729
13730
|
from: toRFC3339(from),
|
|
13730
13731
|
to: toRFC3339(to),
|
|
13731
13732
|
...params.nextToken ? { next_token: params.nextToken } : {}
|
|
@@ -13733,11 +13734,12 @@ var TransactionService = class {
|
|
|
13733
13734
|
return response.data || [];
|
|
13734
13735
|
}
|
|
13735
13736
|
async getByHash(hash, chain) {
|
|
13737
|
+
const chainId = getChainById(chain)?.id ?? chain;
|
|
13736
13738
|
return this.client.gateway(
|
|
13737
13739
|
"GET",
|
|
13738
13740
|
`/v1/txhub/txs/${hash}`,
|
|
13739
13741
|
void 0,
|
|
13740
|
-
`chain=${
|
|
13742
|
+
`chain=${chainId}`
|
|
13741
13743
|
);
|
|
13742
13744
|
}
|
|
13743
13745
|
async getSwapHistory(params) {
|
|
@@ -13748,9 +13750,11 @@ var TransactionService = class {
|
|
|
13748
13750
|
// src/commands/query.ts
|
|
13749
13751
|
init_dist5();
|
|
13750
13752
|
init_dist4();
|
|
13753
|
+
var import_chalk6 = __toESM(require("chalk"));
|
|
13751
13754
|
function handleError(err, json) {
|
|
13752
13755
|
const msg = err instanceof Error ? err.message : String(err);
|
|
13753
|
-
|
|
13756
|
+
const hint = msg.includes("403 Forbidden") ? " \u2014 check your API key at https://portal.trustwallet.com" : "";
|
|
13757
|
+
error(`${msg}${hint}`);
|
|
13754
13758
|
if (json) output({ error: msg }, true);
|
|
13755
13759
|
process.exitCode = 1;
|
|
13756
13760
|
}
|
|
@@ -13760,7 +13764,16 @@ function registerQueryCommand(program2) {
|
|
|
13760
13764
|
const client = await getClient();
|
|
13761
13765
|
const swapClient = new SwapClient(client);
|
|
13762
13766
|
const tokens = token.split(",").map((t) => t.trim()).filter(Boolean);
|
|
13763
|
-
const resolveChain = (t) =>
|
|
13767
|
+
const resolveChain = (t) => {
|
|
13768
|
+
if (opts.chain) return opts.chain;
|
|
13769
|
+
const bySymbol = Object.entries(CHAINS).find(([, c]) => c.symbol.toUpperCase() === t.toUpperCase())?.[0];
|
|
13770
|
+
if (bySymbol) return bySymbol;
|
|
13771
|
+
const upper = t.toUpperCase();
|
|
13772
|
+
for (const [chainKey, chainTokens] of Object.entries(COMMON_TOKENS)) {
|
|
13773
|
+
if (Object.prototype.hasOwnProperty.call(chainTokens, upper)) return chainKey;
|
|
13774
|
+
}
|
|
13775
|
+
return "ethereum";
|
|
13776
|
+
};
|
|
13764
13777
|
if (tokens.length > 1) {
|
|
13765
13778
|
const assetIds = [];
|
|
13766
13779
|
const tokenMeta = [];
|
|
@@ -13787,7 +13800,14 @@ function registerQueryCommand(program2) {
|
|
|
13787
13800
|
chain: m.chain,
|
|
13788
13801
|
priceUsd: priceMap.get(assetIds[i]) ?? null
|
|
13789
13802
|
}));
|
|
13790
|
-
|
|
13803
|
+
if (opts.json) {
|
|
13804
|
+
output(results, true);
|
|
13805
|
+
} else {
|
|
13806
|
+
for (const r of results) {
|
|
13807
|
+
const priceStr = r.priceUsd !== null ? `$${r.priceUsd.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 6 })}` : "N/A";
|
|
13808
|
+
console.log(`${import_chalk6.default.bold(r.token.padEnd(10))} ${priceStr.padStart(14)} ${import_chalk6.default.dim(r.chain)}`);
|
|
13809
|
+
}
|
|
13810
|
+
}
|
|
13791
13811
|
return;
|
|
13792
13812
|
}
|
|
13793
13813
|
const chain = resolveChain(token);
|
|
@@ -13812,7 +13832,12 @@ function registerQueryCommand(program2) {
|
|
|
13812
13832
|
output({ token: token.toUpperCase(), chain, priceUsd: price, history: chartData.prices }, opts.json);
|
|
13813
13833
|
return;
|
|
13814
13834
|
}
|
|
13815
|
-
|
|
13835
|
+
if (opts.json) {
|
|
13836
|
+
output({ token: token.toUpperCase(), chain, priceUsd: price }, true);
|
|
13837
|
+
} else {
|
|
13838
|
+
const priceStr = price !== null ? `$${price.toLocaleString("en-US", { minimumFractionDigits: 2, maximumFractionDigits: 6 })}` : "N/A";
|
|
13839
|
+
console.log(`${import_chalk6.default.bold(token.toUpperCase())} ${priceStr} ${import_chalk6.default.dim(chain)}`);
|
|
13840
|
+
}
|
|
13816
13841
|
} catch (err) {
|
|
13817
13842
|
handleError(err, opts.json);
|
|
13818
13843
|
}
|
|
@@ -13821,7 +13846,7 @@ function registerQueryCommand(program2) {
|
|
|
13821
13846
|
try {
|
|
13822
13847
|
const client = await getClient();
|
|
13823
13848
|
const swapClient = new SwapClient(client);
|
|
13824
|
-
const result = await swapClient.searchTokens({ query, limit: parseInt(opts.limit) });
|
|
13849
|
+
const result = await swapClient.searchTokens({ query, limit: parseInt(opts.limit, 10) });
|
|
13825
13850
|
output(result, opts.json);
|
|
13826
13851
|
} catch (err) {
|
|
13827
13852
|
handleError(err, opts.json);
|
|
@@ -13845,7 +13870,14 @@ function registerQueryCommand(program2) {
|
|
|
13845
13870
|
from: opts.from,
|
|
13846
13871
|
to: opts.to
|
|
13847
13872
|
});
|
|
13848
|
-
|
|
13873
|
+
const sliced = result2.slice(0, parseInt(opts.limit, 10));
|
|
13874
|
+
if (opts.json) {
|
|
13875
|
+
output(sliced, true);
|
|
13876
|
+
} else if (sliced.length === 0) {
|
|
13877
|
+
info("No transactions found.");
|
|
13878
|
+
} else {
|
|
13879
|
+
output(sliced, false);
|
|
13880
|
+
}
|
|
13849
13881
|
return;
|
|
13850
13882
|
}
|
|
13851
13883
|
let address = opts.address;
|
|
@@ -13860,7 +13892,7 @@ function registerQueryCommand(program2) {
|
|
|
13860
13892
|
chain: opts.chain,
|
|
13861
13893
|
from: opts.from,
|
|
13862
13894
|
to: opts.to,
|
|
13863
|
-
limit: parseInt(opts.limit)
|
|
13895
|
+
limit: parseInt(opts.limit, 10)
|
|
13864
13896
|
});
|
|
13865
13897
|
if (result.length > 0) {
|
|
13866
13898
|
const chain = getChainById(opts.chain);
|
|
@@ -13885,28 +13917,56 @@ function registerQueryCommand(program2) {
|
|
|
13885
13917
|
return;
|
|
13886
13918
|
}
|
|
13887
13919
|
}
|
|
13888
|
-
|
|
13920
|
+
if (opts.json) {
|
|
13921
|
+
output(result, true);
|
|
13922
|
+
} else if (result.length === 0) {
|
|
13923
|
+
info("No transactions found.");
|
|
13924
|
+
} else {
|
|
13925
|
+
output(result, false);
|
|
13926
|
+
}
|
|
13889
13927
|
} catch (err) {
|
|
13890
13928
|
handleError(err, opts.json);
|
|
13891
13929
|
}
|
|
13892
13930
|
});
|
|
13893
|
-
program2.command("tx <hash>").description("Get transaction details").requiredOption("--chain <name>", "Chain name").option("--json", "JSON output").action(async (hash, opts) => {
|
|
13931
|
+
program2.command("tx <hash>").description("Get transaction details by hash (on-chain RPC lookup)").requiredOption("--chain <name>", "Chain name").option("--address <address>", "Wallet address (auto-detected from wallet if omitted)").option("--password <pw>", "Wallet password (for auto-detecting address)").option("--json", "JSON output").action(async (hash, opts) => {
|
|
13894
13932
|
try {
|
|
13895
|
-
|
|
13896
|
-
|
|
13897
|
-
|
|
13898
|
-
|
|
13933
|
+
let address = opts.address;
|
|
13934
|
+
if (!address) {
|
|
13935
|
+
try {
|
|
13936
|
+
await ensureTrustSDK();
|
|
13937
|
+
const password = await resolvePassword(opts);
|
|
13938
|
+
const provider = await AgentWalletProvider.fromStorage(password);
|
|
13939
|
+
address = await provider.getAddress(opts.chain);
|
|
13940
|
+
} catch {
|
|
13941
|
+
}
|
|
13942
|
+
}
|
|
13943
|
+
if (address) {
|
|
13944
|
+
await ensureTrustSDK();
|
|
13945
|
+
const blockchainClient = new BlockchainClient();
|
|
13946
|
+
const status = await blockchainClient.findTransactionStatus(opts.chain, address, hash);
|
|
13947
|
+
output({
|
|
13948
|
+
hash,
|
|
13949
|
+
chain: opts.chain,
|
|
13950
|
+
...status
|
|
13951
|
+
}, opts.json);
|
|
13952
|
+
} else {
|
|
13953
|
+
const client = await getClient();
|
|
13954
|
+
const service = new TransactionService(client);
|
|
13955
|
+
const result = await service.getByHash(hash, opts.chain);
|
|
13956
|
+
output(result, opts.json);
|
|
13957
|
+
}
|
|
13899
13958
|
} catch (err) {
|
|
13900
13959
|
handleError(err, opts.json);
|
|
13901
13960
|
}
|
|
13902
13961
|
});
|
|
13903
13962
|
program2.command("chains").description("List supported chains").option("--json", "JSON output").action(async (opts) => {
|
|
13904
|
-
const
|
|
13963
|
+
const chainEntries = Object.entries(CHAINS);
|
|
13905
13964
|
if (opts.json) {
|
|
13906
|
-
output(
|
|
13965
|
+
output(chainEntries.map(([key, chain]) => ({ key, ...chain })), true);
|
|
13907
13966
|
} else {
|
|
13908
|
-
for (const chain of
|
|
13909
|
-
|
|
13967
|
+
for (const [key, chain] of chainEntries) {
|
|
13968
|
+
const idHint = key !== chain.id ? import_chalk6.default.dim(` (${chain.id})`) : "";
|
|
13969
|
+
console.log(`${key.padEnd(15)} ${chain.name.padEnd(25)} coinId:${chain.coinId}${idHint}`);
|
|
13910
13970
|
}
|
|
13911
13971
|
}
|
|
13912
13972
|
});
|
|
@@ -14016,9 +14076,10 @@ function registerQueryCommand(program2) {
|
|
|
14016
14076
|
if (opts.category) {
|
|
14017
14077
|
const categoryId = categoryMap[opts.category] ?? opts.category;
|
|
14018
14078
|
const sort = opts.sort ? sortMap[opts.sort] ?? opts.sort : "percent_change_24h";
|
|
14019
|
-
tokens = await service.getAssetListings({ categoryId, sort, limit: parseInt(opts.limit) });
|
|
14079
|
+
tokens = await service.getAssetListings({ categoryId, sort, limit: parseInt(opts.limit, 10) });
|
|
14020
14080
|
} else {
|
|
14021
|
-
|
|
14081
|
+
const sort = opts.sort ? sortMap[opts.sort] ?? opts.sort : "percent_change_24h";
|
|
14082
|
+
tokens = await service.getTrendingTokens(parseInt(opts.limit, 10), sort);
|
|
14022
14083
|
}
|
|
14023
14084
|
const seen = /* @__PURE__ */ new Map();
|
|
14024
14085
|
for (const t of tokens) {
|
|
@@ -14055,7 +14116,7 @@ function registerQueryCommand(program2) {
|
|
|
14055
14116
|
}
|
|
14056
14117
|
return;
|
|
14057
14118
|
}
|
|
14058
|
-
const dapps = opts.search ? await service.search(opts.search, parseInt(opts.limit)) : await service.getTop(parseInt(opts.limit), opts.category);
|
|
14119
|
+
const dapps = opts.search ? await service.search(opts.search, parseInt(opts.limit, 10)) : await service.getTop(parseInt(opts.limit, 10), opts.category);
|
|
14059
14120
|
if (opts.json) {
|
|
14060
14121
|
output(dapps, true);
|
|
14061
14122
|
} else {
|
|
@@ -18332,13 +18393,12 @@ var TransferActionProvider = class extends ActionProvider {
|
|
|
18332
18393
|
to: external_exports.string().describe("Destination address or ENS name (e.g., vitalik.eth)"),
|
|
18333
18394
|
amount: external_exports.string().describe('Amount in human-readable format (e.g., "1.5", "0.01")'),
|
|
18334
18395
|
token: external_exports.string().optional().describe("ERC-20 token contract address (omit for native token)"),
|
|
18335
|
-
decimals: external_exports.coerce.number().optional().default(18).describe("Token decimals (default 18, use 6 for USDC/USDT)")
|
|
18336
|
-
skipSafetyCheck: external_exports.boolean().optional().default(false).describe("Skip USD-value safety limit (default: false)")
|
|
18396
|
+
decimals: external_exports.coerce.number().optional().default(18).describe("Token decimals (default 18, use 6 for USDC/USDT)")
|
|
18337
18397
|
}),
|
|
18338
18398
|
invoke: async (_ctx, input) => {
|
|
18339
18399
|
const signer = this.walletProvider;
|
|
18340
18400
|
if (!signer) return { success: false, error: "No wallet provider configured" };
|
|
18341
|
-
if (
|
|
18401
|
+
if (this.priceLookup) {
|
|
18342
18402
|
try {
|
|
18343
18403
|
const evmId2 = extractEvmChainId(input.chainId);
|
|
18344
18404
|
const chain = getChainById(evmId2) ?? getChainByEvmId(evmId2);
|
|
@@ -18350,7 +18410,7 @@ var TransferActionProvider = class extends ActionProvider {
|
|
|
18350
18410
|
if (usdValue > this.maxTransferUsd) {
|
|
18351
18411
|
return {
|
|
18352
18412
|
success: false,
|
|
18353
|
-
error: `Transfer value ~$${usdValue.toFixed(2)} USD exceeds safety limit of $${this.maxTransferUsd}.
|
|
18413
|
+
error: `Transfer value ~$${usdValue.toFixed(2)} USD exceeds safety limit of $${this.maxTransferUsd}. Use the CLI with --skip-safety-check to override.`
|
|
18354
18414
|
};
|
|
18355
18415
|
}
|
|
18356
18416
|
}
|
|
@@ -28099,7 +28159,7 @@ var crypto3 = __toESM(require("crypto"));
|
|
|
28099
28159
|
// package.json
|
|
28100
28160
|
var package_default = {
|
|
28101
28161
|
name: "@trustwallet/cli",
|
|
28102
|
-
version: "0.6.
|
|
28162
|
+
version: "0.6.5",
|
|
28103
28163
|
description: "TWAK CLI \u2014 command-line interface for Trust Wallet Agent Kit",
|
|
28104
28164
|
main: "dist/index.js",
|
|
28105
28165
|
types: "dist/index.d.ts",
|
|
@@ -28259,7 +28319,7 @@ function registerTelemetryCommand(program2) {
|
|
|
28259
28319
|
// src/index.ts
|
|
28260
28320
|
var VERSION2 = package_default.version;
|
|
28261
28321
|
var program = new import_commander.Command();
|
|
28262
|
-
program.name("twak").description("Trust Wallet Agent \u2014 AI-powered multichain wallet SDK").version(VERSION2).option("--no-analytics", "Disable telemetry for this invocation").addHelpText("
|
|
28322
|
+
program.name("twak").description("Trust Wallet Agent \u2014 AI-powered multichain wallet SDK").version(VERSION2).option("--no-analytics", "Disable telemetry for this invocation").addHelpText("before", () => {
|
|
28263
28323
|
printBanner(VERSION2);
|
|
28264
28324
|
return "";
|
|
28265
28325
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trustwallet/cli",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.5",
|
|
4
4
|
"description": "TWAK CLI — command-line interface for Trust Wallet Agent Kit",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -27,17 +27,17 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"tsup": "8.5.1",
|
|
29
29
|
"typescript": "5.7.3",
|
|
30
|
-
"@twak/actions": "0.6.
|
|
31
|
-
"@twak/blockchain": "0.6.
|
|
32
|
-
"@twak/core": "0.6.
|
|
33
|
-
"@twak/
|
|
34
|
-
"@twak/
|
|
35
|
-
"@twak/
|
|
36
|
-
"@twak/swap": "0.6.
|
|
37
|
-
"@twak/
|
|
38
|
-
"@twak/wallet-core": "0.6.
|
|
39
|
-
"@twak/walletconnect": "0.6.
|
|
40
|
-
"@twak/
|
|
30
|
+
"@twak/actions": "0.6.5",
|
|
31
|
+
"@twak/blockchain": "0.6.5",
|
|
32
|
+
"@twak/core": "0.6.5",
|
|
33
|
+
"@twak/security": "0.6.5",
|
|
34
|
+
"@twak/storage": "0.6.5",
|
|
35
|
+
"@twak/mcp": "0.6.5",
|
|
36
|
+
"@twak/swap": "0.6.5",
|
|
37
|
+
"@twak/transactions": "0.6.5",
|
|
38
|
+
"@twak/wallet-core": "0.6.5",
|
|
39
|
+
"@twak/walletconnect": "0.6.5",
|
|
40
|
+
"@twak/wallet": "0.6.5"
|
|
41
41
|
},
|
|
42
42
|
"publishConfig": {
|
|
43
43
|
"access": "public"
|
|
@@ -48,6 +48,13 @@
|
|
|
48
48
|
head: { appendChild: function(){} }
|
|
49
49
|
};
|
|
50
50
|
}
|
|
51
|
+
// --- Suppress Node.js --localstorage-file warning from Trust SDK WASM ---
|
|
52
|
+
var _origEmit = process.emitWarning;
|
|
53
|
+
process.emitWarning = function(warning) {
|
|
54
|
+
if (typeof warning === 'string' && warning.indexOf('--localstorage-file') !== -1) return;
|
|
55
|
+
return _origEmit.apply(process, arguments);
|
|
56
|
+
};
|
|
57
|
+
|
|
51
58
|
if (typeof globalThis.window === 'undefined') globalThis.window = globalThis;
|
|
52
59
|
if (typeof globalThis.self === 'undefined') globalThis.self = globalThis;
|
|
53
60
|
if (typeof globalThis.navigator === 'undefined') globalThis.navigator = { onLine: true, userAgent: 'Mozilla/5.0 (twak)' };
|