@aixyz/cli 0.15.0 → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/package.json +4 -3
  2. package/wallet/index.ts +73 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aixyz/cli",
3
- "version": "0.15.0",
3
+ "version": "0.17.0",
4
4
  "description": "Payment-native SDK for AI Agent",
5
5
  "keywords": [
6
6
  "ai",
@@ -24,11 +24,12 @@
24
24
  "build",
25
25
  "dev",
26
26
  "register",
27
+ "wallet",
27
28
  "bin.ts"
28
29
  ],
29
30
  "dependencies": {
30
- "@aixyz/config": "0.15.0",
31
- "@aixyz/erc-8004": "0.15.0",
31
+ "@aixyz/config": "0.17.0",
32
+ "@aixyz/erc-8004": "0.17.0",
32
33
  "@inquirer/prompts": "^8.3.0",
33
34
  "@next/env": "^16.1.6",
34
35
  "boxen": "^8.0.1",
@@ -0,0 +1,73 @@
1
+ import { Command } from "commander";
2
+ import { existsSync, copyFileSync } from "node:fs";
3
+ import { generateLocalWallet, getLocalWalletPath } from "../register/wallet/local";
4
+ import chalk from "chalk";
5
+ import boxen from "boxen";
6
+
7
+ const generateCommand = new Command("generate")
8
+ .description("Generate a new local wallet and save to .aixyz/wallet.json")
9
+ .option("--force", "Overwrite existing wallet")
10
+ .addHelpText(
11
+ "after",
12
+ `
13
+ Details:
14
+ Generates a new BIP-39 mnemonic wallet and saves it to .aixyz/wallet.json.
15
+ Also creates .aixyz/.gitignore and .aixyz/.aiignore to protect the wallet
16
+ from being accidentally committed or read by AI tools.
17
+
18
+ The generated wallet can be used with \`aixyz erc-8004 register --broadcast\`
19
+ without providing a separate --keystore or PRIVATE_KEY.
20
+
21
+ WARNING: The mnemonic in .aixyz/wallet.json grants full access to the wallet.
22
+ Keep it secure and never share it.
23
+
24
+ Examples:
25
+ $ aixyz wallet generate
26
+ $ aixyz wallet generate --force`,
27
+ )
28
+ .action(async (options: { force?: boolean }) => {
29
+ const walletPath = getLocalWalletPath();
30
+
31
+ if (existsSync(walletPath) && !options.force) {
32
+ console.error(chalk.red(`Wallet already exists at ${walletPath}`));
33
+ console.error(chalk.dim("Use --force to overwrite."));
34
+ process.exit(1);
35
+ }
36
+
37
+ if (existsSync(walletPath) && options.force) {
38
+ const backupPath = `${walletPath}.${Date.now()}.bak`;
39
+ copyFileSync(walletPath, backupPath);
40
+ console.log(chalk.dim(`Backed up existing wallet to ${backupPath}`));
41
+ }
42
+
43
+ let wallet;
44
+ try {
45
+ wallet = generateLocalWallet();
46
+ } catch (err) {
47
+ console.error(chalk.red(`Failed to generate wallet: ${err instanceof Error ? err.message : String(err)}`));
48
+ console.error(chalk.dim("Check that the current directory is writable."));
49
+ process.exit(1);
50
+ }
51
+
52
+ const lines = [
53
+ `${chalk.dim("Address")} ${wallet.address}`,
54
+ `${chalk.dim("Mnemonic")} ${wallet.mnemonic}`,
55
+ `${chalk.dim("Path")} ${walletPath}`,
56
+ ];
57
+
58
+ console.log("");
59
+ console.log(
60
+ boxen(lines.join("\n"), {
61
+ padding: { left: 1, right: 1, top: 0, bottom: 0 },
62
+ borderStyle: "round",
63
+ borderColor: "green",
64
+ title: "Wallet generated",
65
+ titleAlignment: "left",
66
+ }),
67
+ );
68
+ console.log("");
69
+ console.log(chalk.yellow("⚠ Keep your mnemonic secret. Anyone with it can access your funds."));
70
+ console.log(chalk.dim(" .aixyz/.gitignore and .aixyz/.aiignore have been written to protect wallet.json."));
71
+ });
72
+
73
+ export const walletCommand = new Command("wallet").description("Manage local wallet").addCommand(generateCommand);