arc402-cli 1.8.5 → 1.8.7

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.
@@ -0,0 +1,3 @@
1
+ import { Command } from "commander";
2
+ export declare function registerTelegramCommands(program: Command): void;
3
+ //# sourceMappingURL=telegram.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telegram.d.ts","sourceRoot":"","sources":["../../src/commands/telegram.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAoDpC,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA6G/D"}
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.registerTelegramCommands = registerTelegramCommands;
7
+ const prompts_1 = __importDefault(require("prompts"));
8
+ const chalk_1 = __importDefault(require("chalk"));
9
+ const config_1 = require("../config");
10
+ const colors_1 = require("../ui/colors");
11
+ async function telegramApi(botToken, method, body) {
12
+ const res = await fetch(`https://api.telegram.org/bot${botToken}/${method}`, {
13
+ method: body ? "POST" : "GET",
14
+ headers: body ? { "Content-Type": "application/json" } : undefined,
15
+ body: body ? JSON.stringify(body) : undefined,
16
+ signal: AbortSignal.timeout(15000),
17
+ });
18
+ const json = await res.json();
19
+ return json;
20
+ }
21
+ async function validateBotToken(botToken) {
22
+ try {
23
+ const res = await telegramApi(botToken, "getMe");
24
+ if (!res.ok)
25
+ return { ok: false, error: res.description ?? "Telegram rejected the bot token." };
26
+ return { ok: true, username: res.result?.username };
27
+ }
28
+ catch (error) {
29
+ return { ok: false, error: error instanceof Error ? error.message : String(error) };
30
+ }
31
+ }
32
+ async function sendTestMessage(botToken, chatId, threadId) {
33
+ try {
34
+ const res = await telegramApi(botToken, "sendMessage", {
35
+ chat_id: chatId,
36
+ ...(threadId !== undefined ? { message_thread_id: threadId } : {}),
37
+ text: "🔧 ARC-402 CLI Telegram delivery test — approval prompts can be sent here.",
38
+ });
39
+ if (!res.ok || !res.result)
40
+ return { ok: false, error: res.description ?? "Telegram rejected the test message." };
41
+ return { ok: true, messageId: res.result.message_id };
42
+ }
43
+ catch (error) {
44
+ return { ok: false, error: error instanceof Error ? error.message : String(error) };
45
+ }
46
+ }
47
+ function registerTelegramCommands(program) {
48
+ const telegram = program.command("telegram").description("Configure Telegram delivery for WalletConnect approval prompts");
49
+ telegram.command("show")
50
+ .description("Show current Telegram delivery settings")
51
+ .action(() => {
52
+ const cfg = (0, config_1.loadConfig)();
53
+ console.log(JSON.stringify({
54
+ telegramBotToken: cfg.telegramBotToken ? "***configured***" : undefined,
55
+ telegramChatId: cfg.telegramChatId,
56
+ telegramThreadId: cfg.telegramThreadId,
57
+ }, null, 2));
58
+ });
59
+ telegram.command("init")
60
+ .description("Interactive setup for Telegram approval-button delivery")
61
+ .option("--bot-token <token>", "Telegram bot token from BotFather")
62
+ .option("--chat-id <id>", "Telegram chat ID, e.g. 123456789 or -100... for groups")
63
+ .option("--thread-id <id>", "Telegram topic/thread ID for forum groups")
64
+ .option("--skip-test", "Skip sending a Telegram test message")
65
+ .action(async (opts) => {
66
+ const existing = (0, config_1.loadConfig)();
67
+ console.log();
68
+ console.log(chalk_1.default.white("Telegram approval-button setup"));
69
+ console.log(chalk_1.default.dim(" 1. Create a bot with @BotFather"));
70
+ console.log(chalk_1.default.dim(" 2. Add that bot to the target chat/group"));
71
+ console.log(chalk_1.default.dim(" 3. Paste the bot token + chat ID below"));
72
+ console.log(chalk_1.default.dim(" 4. Optional: add a forum topic/thread ID"));
73
+ console.log();
74
+ const answers = await (0, prompts_1.default)([
75
+ {
76
+ type: opts.botToken ? null : "text",
77
+ name: "botToken",
78
+ message: "Telegram bot token",
79
+ initial: existing.telegramBotToken,
80
+ validate: (value) => value.trim().length > 20 ? true : "Enter a valid bot token from BotFather.",
81
+ },
82
+ {
83
+ type: opts.chatId ? null : "text",
84
+ name: "chatId",
85
+ message: "Telegram chat ID",
86
+ initial: existing.telegramChatId,
87
+ validate: (value) => value.trim() ? true : "Chat ID is required.",
88
+ },
89
+ {
90
+ type: opts.threadId !== undefined ? null : "text",
91
+ name: "threadId",
92
+ message: "Telegram thread/topic ID (optional)",
93
+ initial: existing.telegramThreadId !== undefined ? String(existing.telegramThreadId) : undefined,
94
+ validate: (value) => !value.trim() || /^\d+$/.test(value.trim()) ? true : "Thread ID must be numeric.",
95
+ },
96
+ ], {
97
+ onCancel: () => {
98
+ console.log(chalk_1.default.red("✗ Telegram setup cancelled"));
99
+ return true;
100
+ },
101
+ });
102
+ const botToken = (opts.botToken ?? answers.botToken ?? existing.telegramBotToken ?? "").trim();
103
+ const chatId = (opts.chatId ?? answers.chatId ?? existing.telegramChatId ?? "").trim();
104
+ const threadRaw = (opts.threadId ?? answers.threadId ?? "").trim();
105
+ const threadId = threadRaw ? Number(threadRaw) : undefined;
106
+ if (!botToken || !chatId) {
107
+ console.log(chalk_1.default.red("✗ Telegram setup incomplete"));
108
+ return;
109
+ }
110
+ process.stdout.write("Validating bot token… ");
111
+ const botCheck = await validateBotToken(botToken);
112
+ if (!botCheck.ok) {
113
+ console.log(chalk_1.default.red("failed"));
114
+ console.log(chalk_1.default.red(` ${botCheck.error}`));
115
+ console.log(chalk_1.default.dim(" Fix the bot token first, then rerun `arc402 telegram init`."));
116
+ return;
117
+ }
118
+ console.log(chalk_1.default.green(`✓ ${botCheck.username ? `@${botCheck.username}` : "bot ok"}`));
119
+ const cfg = {
120
+ ...existing,
121
+ telegramBotToken: botToken,
122
+ telegramChatId: chatId,
123
+ ...(threadId !== undefined ? { telegramThreadId: threadId } : {}),
124
+ };
125
+ if (threadId === undefined)
126
+ delete cfg.telegramThreadId;
127
+ (0, config_1.saveConfig)(cfg);
128
+ console.log();
129
+ console.log(" " + colors_1.c.success + colors_1.c.white(" Telegram delivery saved"));
130
+ console.log(chalk_1.default.dim(" Chat ID ") + chalk_1.default.white(chatId));
131
+ console.log(chalk_1.default.dim(" Thread ID ") + chalk_1.default.white(threadId !== undefined ? String(threadId) : "(none)"));
132
+ console.log();
133
+ if (!opts.skipTest) {
134
+ process.stdout.write("Sending test message… ");
135
+ const test = await sendTestMessage(botToken, chatId, threadId);
136
+ if (!test.ok) {
137
+ console.log(chalk_1.default.red("failed"));
138
+ console.log(chalk_1.default.red(` ${test.error}`));
139
+ console.log(chalk_1.default.dim(" The config is saved, but Telegram delivery will not work until the bot can message that chat/topic."));
140
+ return;
141
+ }
142
+ console.log(chalk_1.default.green(`✓ message ${test.messageId}`));
143
+ }
144
+ console.log(chalk_1.default.dim(" Next: any WalletConnect-backed ARC-402 CLI command can now send approval prompts here."));
145
+ });
146
+ }
147
+ //# sourceMappingURL=telegram.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telegram.js","sourceRoot":"","sources":["../../src/commands/telegram.ts"],"names":[],"mappings":";;;;;AAoDA,4DA6GC;AAhKD,sDAA8B;AAC9B,kDAA0B;AAC1B,sCAAmD;AACnD,yCAAiC;AAYjC,KAAK,UAAU,WAAW,CAAI,QAAgB,EAAE,MAAc,EAAE,IAA8B;IAC5F,MAAM,GAAG,GAAG,MAAM,KAAK,CAAC,+BAA+B,QAAQ,IAAI,MAAM,EAAE,EAAE;QAC3E,MAAM,EAAE,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK;QAC7B,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,EAAE,cAAc,EAAE,kBAAkB,EAAE,CAAC,CAAC,CAAC,SAAS;QAClE,IAAI,EAAE,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,SAAS;QAC7C,MAAM,EAAE,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC;KACnC,CAAC,CAAC;IAEH,MAAM,IAAI,GAAG,MAAM,GAAG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AI,CA0uG7D"}
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/commands/wallet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AA0qBpC,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CA4tG7D"}
@@ -58,7 +58,52 @@ const telegram_notify_1 = require("../telegram-notify");
58
58
  const tree_1 = require("../ui/tree");
59
59
  const spinner_1 = require("../ui/spinner");
60
60
  const colors_1 = require("../ui/colors");
61
+ const rpc_fallback_1 = require("../ui/rpc-fallback");
61
62
  const GUARDIAN_KEY_PATH = path_1.default.join(os_1.default.homedir(), ".arc402", "guardian.key");
63
+ function buildFreshConfigFromDefaults(existing, network, privateKey, ownerAddress) {
64
+ const defaults = config_1.NETWORK_DEFAULTS[network];
65
+ if (!defaults)
66
+ throw new Error(`Unknown network: ${network}`);
67
+ return {
68
+ network,
69
+ rpcUrl: defaults.rpcUrl,
70
+ privateKey,
71
+ ownerAddress,
72
+ walletConnectProjectId: existing?.walletConnectProjectId,
73
+ subdomainApi: existing?.subdomainApi,
74
+ telegramBotToken: existing?.telegramBotToken,
75
+ telegramChatId: existing?.telegramChatId,
76
+ telegramThreadId: existing?.telegramThreadId,
77
+ deviceId: existing?.deviceId,
78
+ chat: existing?.chat,
79
+ policyEngineAddress: defaults.policyEngineAddress,
80
+ trustRegistryAddress: defaults.trustRegistryAddress,
81
+ trustRegistryV2Address: defaults.trustRegistryV2Address,
82
+ intentAttestationAddress: defaults.intentAttestationAddress,
83
+ settlementCoordinatorAddress: defaults.settlementCoordinatorAddress,
84
+ agentRegistryAddress: defaults.agentRegistryV2Address ?? defaults.agentRegistryAddress,
85
+ agentRegistryV2Address: defaults.agentRegistryV2Address,
86
+ arc402RegistryV3Address: defaults.arc402RegistryV3Address,
87
+ serviceAgreementAddress: defaults.serviceAgreementAddress,
88
+ disputeArbitrationAddress: defaults.disputeArbitrationAddress,
89
+ disputeModuleAddress: defaults.disputeModuleAddress,
90
+ sessionChannelsAddress: defaults.sessionChannelsAddress,
91
+ reputationOracleAddress: defaults.reputationOracleAddress,
92
+ sponsorshipAttestationAddress: defaults.sponsorshipAttestationAddress,
93
+ capabilityRegistryAddress: defaults.capabilityRegistryAddress,
94
+ governanceAddress: defaults.governanceAddress,
95
+ agreementTreeAddress: defaults.agreementTreeAddress,
96
+ walletFactoryAddress: defaults.walletFactoryAddress,
97
+ watchtowerRegistryAddress: defaults.watchtowerRegistryAddress,
98
+ governedTokenWhitelistAddress: defaults.governedTokenWhitelistAddress,
99
+ vouchingRegistryAddress: defaults.vouchingRegistryAddress,
100
+ migrationRegistryAddress: defaults.migrationRegistryAddress,
101
+ handshakeAddress: defaults.handshakeAddress,
102
+ computeAgreementAddress: defaults.computeAgreementAddress,
103
+ subscriptionAgreementAddress: defaults.subscriptionAgreementAddress,
104
+ lastCliVersion: existing?.lastCliVersion,
105
+ };
106
+ }
62
107
  /** Save guardian private key to a restricted standalone file (never to config.json). */
63
108
  function saveGuardianKey(privateKey) {
64
109
  fs_1.default.mkdirSync(path_1.default.dirname(GUARDIAN_KEY_PATH), { recursive: true, mode: 0o700 });
@@ -619,21 +664,30 @@ function registerWalletCommands(program) {
619
664
  if (!address)
620
665
  throw new Error("No wallet configured");
621
666
  const usdcAddress = (0, config_1.getUsdcAddress)(config);
622
- const usdc = new ethers_1.ethers.Contract(usdcAddress, ["function balanceOf(address owner) external view returns (uint256)"], provider);
623
- const trust = new sdk_1.TrustClient(config.trustRegistryAddress, provider);
624
667
  const statusSpinner = opts.json ? null : (0, spinner_1.startSpinner)("Loading wallet status…");
625
- let ethBalance, usdcBalance, score;
626
- try {
627
- [ethBalance, usdcBalance, score] = await Promise.all([
628
- provider.getBalance(address),
629
- usdc.balanceOf(address),
630
- trust.getScore(address),
631
- ]);
632
- statusSpinner?.succeed("Wallet status loaded");
633
- }
634
- catch (err) {
668
+ const [ethResult, usdcResult, trustResult] = await Promise.allSettled([
669
+ (0, rpc_fallback_1.callWithFallback)(config.rpcUrl, (fallbackProvider) => fallbackProvider.getBalance(address)),
670
+ (0, rpc_fallback_1.callWithFallback)(config.rpcUrl, async (fallbackProvider) => {
671
+ const usdc = new ethers_1.ethers.Contract(usdcAddress, ["function balanceOf(address owner) external view returns (uint256)"], fallbackProvider);
672
+ return usdc.balanceOf(address);
673
+ }),
674
+ (0, rpc_fallback_1.callWithFallback)(config.rpcUrl, async (fallbackProvider) => {
675
+ const trust = new sdk_1.TrustClient(config.trustRegistryAddress, fallbackProvider);
676
+ return trust.getScore(address);
677
+ }),
678
+ ]);
679
+ if (ethResult.status === "rejected") {
635
680
  statusSpinner?.fail("Failed to load wallet status");
636
- throw err;
681
+ throw ethResult.reason;
682
+ }
683
+ const ethBalance = ethResult.value;
684
+ const usdcBalance = usdcResult.status === "fulfilled" ? usdcResult.value : 0n;
685
+ const score = trustResult.status === "fulfilled" ? trustResult.value : { score: 0 };
686
+ if (usdcResult.status === "rejected" || trustResult.status === "rejected") {
687
+ statusSpinner?.succeed("Wallet status loaded (with fallbacks)");
688
+ }
689
+ else {
690
+ statusSpinner?.succeed("Wallet status loaded");
637
691
  }
638
692
  // Query contract wallet for frozen/guardian state if deployed
639
693
  let contractFrozen = null;
@@ -740,23 +794,7 @@ function registerWalletCommands(program) {
740
794
  process.exit(1);
741
795
  }
742
796
  const generated = ethers_1.ethers.Wallet.createRandom();
743
- const networkChanged = !!existing && existing.network !== network;
744
- const config = {
745
- ...(existing ?? {}),
746
- network,
747
- rpcUrl: defaults.rpcUrl,
748
- privateKey: generated.privateKey,
749
- trustRegistryAddress: defaults.trustRegistryAddress,
750
- policyEngineAddress: defaults.policyEngineAddress,
751
- walletFactoryAddress: defaults.walletFactoryAddress,
752
- agentRegistryV2Address: defaults.agentRegistryV2Address,
753
- };
754
- if (networkChanged) {
755
- delete config.walletContractAddress;
756
- delete config.ownerAddress;
757
- delete config.onboardingProgress;
758
- delete config.wcSession;
759
- }
797
+ const config = buildFreshConfigFromDefaults(existing, network, generated.privateKey, generated.address);
760
798
  (0, config_1.saveConfig)(config);
761
799
  (0, tree_1.renderTree)([
762
800
  { label: "Address", value: generated.address },
@@ -808,23 +846,7 @@ function registerWalletCommands(program) {
808
846
  console.error("Invalid private key. Must be a 0x-prefixed hex string.");
809
847
  process.exit(1);
810
848
  }
811
- const networkChanged = !!existing && existing.network !== network;
812
- const config = {
813
- ...(existing ?? {}),
814
- network,
815
- rpcUrl: defaults.rpcUrl,
816
- privateKey: imported.privateKey,
817
- trustRegistryAddress: defaults.trustRegistryAddress,
818
- policyEngineAddress: defaults.policyEngineAddress,
819
- walletFactoryAddress: defaults.walletFactoryAddress,
820
- agentRegistryV2Address: defaults.agentRegistryV2Address,
821
- };
822
- if (networkChanged) {
823
- delete config.walletContractAddress;
824
- delete config.ownerAddress;
825
- delete config.onboardingProgress;
826
- delete config.wcSession;
827
- }
849
+ const config = buildFreshConfigFromDefaults(existing, network, imported.privateKey, imported.address);
828
850
  (0, config_1.saveConfig)(config);
829
851
  (0, tree_1.renderTree)([
830
852
  { label: "Address", value: imported.address },
@@ -888,15 +910,20 @@ function registerWalletCommands(program) {
888
910
  console.error("No owner address. Pass --owner <address> or set ownerAddress in config (run `arc402 wallet deploy` first).");
889
911
  process.exit(1);
890
912
  }
891
- const provider = new ethers_1.ethers.JsonRpcProvider(config.rpcUrl);
892
- const factory = new ethers_1.ethers.Contract(factoryAddress, abis_1.WALLET_FACTORY_ABI, provider);
893
- const wallets = await factory.getWallets(ownerAddress);
913
+ const wallets = await (0, rpc_fallback_1.callWithFallback)(config.rpcUrl, async (fallbackProvider) => {
914
+ const factory = new ethers_1.ethers.Contract(factoryAddress, abis_1.WALLET_FACTORY_ABI, fallbackProvider);
915
+ return factory.getWallets(ownerAddress);
916
+ });
894
917
  const results = await Promise.all(wallets.map(async (addr) => {
895
- const walletContract = new ethers_1.ethers.Contract(addr, abis_1.ARC402_WALLET_GUARDIAN_ABI, provider);
896
- const trustContract = new ethers_1.ethers.Contract(config.trustRegistryAddress, abis_1.TRUST_REGISTRY_ABI, provider);
897
918
  const [frozen, score] = await Promise.all([
898
- walletContract.frozen().catch(() => null),
899
- trustContract.getScore(addr).catch(() => BigInt(0)),
919
+ (0, rpc_fallback_1.callWithFallback)(config.rpcUrl, async (fallbackProvider) => {
920
+ const walletContract = new ethers_1.ethers.Contract(addr, abis_1.ARC402_WALLET_GUARDIAN_ABI, fallbackProvider);
921
+ return walletContract.frozen().catch(() => null);
922
+ }).catch(() => null),
923
+ (0, rpc_fallback_1.callWithFallback)(config.rpcUrl, async (fallbackProvider) => {
924
+ const trustContract = new ethers_1.ethers.Contract(config.trustRegistryAddress, abis_1.TRUST_REGISTRY_ABI, fallbackProvider);
925
+ return trustContract.getScore(addr).catch(() => BigInt(0));
926
+ }).catch(() => BigInt(0)),
900
927
  ]);
901
928
  return { address: addr, frozen: frozen, score: Number(score) };
902
929
  }));
@@ -936,9 +963,10 @@ function registerWalletCommands(program) {
936
963
  const factoryAddress = config.walletFactoryAddress ?? config_1.NETWORK_DEFAULTS[config.network]?.walletFactoryAddress;
937
964
  if (factoryAddress && config.ownerAddress) {
938
965
  try {
939
- const provider = new ethers_1.ethers.JsonRpcProvider(config.rpcUrl);
940
- const factory = new ethers_1.ethers.Contract(factoryAddress, abis_1.WALLET_FACTORY_ABI, provider);
941
- const wallets = await factory.getWallets(config.ownerAddress);
966
+ const wallets = await (0, rpc_fallback_1.callWithFallback)(config.rpcUrl, async (fallbackProvider) => {
967
+ const factory = new ethers_1.ethers.Contract(factoryAddress, abis_1.WALLET_FACTORY_ABI, fallbackProvider);
968
+ return factory.getWallets(config.ownerAddress);
969
+ });
942
970
  const found = wallets.some((w) => w.toLowerCase() === checksumAddress.toLowerCase());
943
971
  if (!found) {
944
972
  console.warn(`WARN: ${checksumAddress} was not found in WalletFactory wallets for owner ${config.ownerAddress}`);