-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathcreate.js
More file actions
63 lines (53 loc) · 2.06 KB
/
create.js
File metadata and controls
63 lines (53 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import * as ows from "../../utils/wallet/keystore.js";
import { print, printError } from "../../utils/common/output.js";
import { setConfigValue, getConfigValue } from "../../utils/config.js";
import { readPassphrase, readSecret } from "../../utils/common/prompt.js";
import { PASSPHRASE_WARNING } from "../../utils/common/constants.js";
import { offerAgentToken } from "../../utils/wallet/offer-agent-token.js";
import { offerLogin } from "../../utils/wallet/offer-login.js";
export default async function walletCreate(args, flags) {
const name = flags.name || args[0] || generateName();
try {
process.stderr.write("A passphrase is required to encrypt your wallet.\n\n");
const passphrase = await readPassphrase({ confirm: true });
process.stderr.write(PASSPHRASE_WARNING);
let ack = "";
while (ack.trim() !== "YES") {
ack = await readSecret("Have you backed up the passphrase? Type YES to confirm: ");
if (ack.trim() !== "YES") {
process.stderr.write("Please back up your passphrase before continuing.\n\n");
}
}
const wallet = ows.createWallet(name, passphrase);
// Set as default wallet if none exists
if (!getConfigValue("defaultWallet")) {
setConfigValue("defaultWallet", name);
}
print({
wallet: {
name: wallet.name,
evmAddress: wallet.evmAddress,
solAddress: wallet.solAddress,
chains: wallet.chains.length,
},
created: true,
isDefault: getConfigValue("defaultWallet") === name,
});
// Offer API key login first — agent tokens / trading / analysis all need one.
await offerLogin();
// Offer agent token creation as part of wallet setup
await offerAgentToken(name, passphrase);
} catch (err) {
printError("ows_error", `Failed to create wallet: ${err.message}`);
process.exit(1);
}
}
function generateName() {
try {
const existing = ows.listWallets();
return `wallet-${existing.length + 1}`;
} catch (err) {
process.stderr.write(`Warning: could not list wallets: ${err.message}\n`);
return "wallet-1";
}
}