ethnotary 1.0.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.
- package/README.md +514 -0
- package/cli/commands/account/index.js +855 -0
- package/cli/commands/config/index.js +369 -0
- package/cli/commands/contact/index.js +139 -0
- package/cli/commands/contract/index.js +197 -0
- package/cli/commands/data/index.js +536 -0
- package/cli/commands/tx/index.js +841 -0
- package/cli/commands/wallet/index.js +181 -0
- package/cli/index.js +624 -0
- package/cli/utils/auth.js +146 -0
- package/cli/utils/constants.js +68 -0
- package/cli/utils/contacts.js +131 -0
- package/cli/utils/contracts.js +269 -0
- package/cli/utils/crosschain.js +278 -0
- package/cli/utils/networks.js +335 -0
- package/cli/utils/notifications.js +135 -0
- package/cli/utils/output.js +123 -0
- package/cli/utils/pin.js +89 -0
- package/data/balance.js +680 -0
- package/data/events.js +334 -0
- package/data/pending.js +261 -0
- package/data/scanWorker.js +169 -0
- package/data/token_cache.json +54 -0
- package/data/token_database.json +92 -0
- package/data/tokens.js +380 -0
- package/package.json +57 -0
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
const { Command } = require('commander');
|
|
2
|
+
const { createOutput } = require('../../utils/output');
|
|
3
|
+
const { createKeystore, importKeystore, getKeystoreAddress, keystoreExists } = require('../../utils/auth');
|
|
4
|
+
const { ethers } = require('ethers');
|
|
5
|
+
|
|
6
|
+
const wallet = new Command('wallet')
|
|
7
|
+
.description('Wallet management commands');
|
|
8
|
+
|
|
9
|
+
// wallet init - Generate new wallet
|
|
10
|
+
wallet
|
|
11
|
+
.command('init')
|
|
12
|
+
.description('Generate a new wallet and save encrypted keystore')
|
|
13
|
+
.action(async (options, command) => {
|
|
14
|
+
const globalOpts = command.parent.parent.opts();
|
|
15
|
+
const out = createOutput(globalOpts);
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
if (keystoreExists()) {
|
|
19
|
+
const existingAddress = getKeystoreAddress();
|
|
20
|
+
out.error(`Keystore already exists with address: ${existingAddress}. Use "ethnotary wallet import" to replace.`);
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
let password;
|
|
25
|
+
|
|
26
|
+
if (globalOpts.json) {
|
|
27
|
+
// In JSON mode, generate wallet and output private key (for agent setup)
|
|
28
|
+
const wallet = ethers.Wallet.createRandom();
|
|
29
|
+
out.print({
|
|
30
|
+
address: wallet.address,
|
|
31
|
+
privateKey: wallet.privateKey,
|
|
32
|
+
mnemonic: wallet.mnemonic.phrase,
|
|
33
|
+
note: 'Store these securely. Use --private-key or PRIVATE_KEY env var to authenticate.'
|
|
34
|
+
});
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Interactive mode - prompt for password
|
|
39
|
+
const inquirer = require('inquirer');
|
|
40
|
+
const answers = await inquirer.prompt([
|
|
41
|
+
{
|
|
42
|
+
type: 'password',
|
|
43
|
+
name: 'password',
|
|
44
|
+
message: 'Enter password to encrypt keystore:',
|
|
45
|
+
mask: '*',
|
|
46
|
+
validate: (input) => input.length >= 8 || 'Password must be at least 8 characters'
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
type: 'password',
|
|
50
|
+
name: 'confirmPassword',
|
|
51
|
+
message: 'Confirm password:',
|
|
52
|
+
mask: '*',
|
|
53
|
+
validate: (input, answers) => input === answers.password || 'Passwords do not match'
|
|
54
|
+
}
|
|
55
|
+
]);
|
|
56
|
+
|
|
57
|
+
out.startSpinner('Generating wallet and encrypting keystore...');
|
|
58
|
+
const newWallet = await createKeystore(answers.password);
|
|
59
|
+
out.succeedSpinner('Wallet created successfully');
|
|
60
|
+
|
|
61
|
+
out.print({
|
|
62
|
+
address: newWallet.address,
|
|
63
|
+
mnemonic: newWallet.mnemonic.phrase
|
|
64
|
+
}, { title: '\nš New Wallet Created' });
|
|
65
|
+
|
|
66
|
+
out.warn('Save your mnemonic phrase securely. It will not be shown again.');
|
|
67
|
+
|
|
68
|
+
} catch (error) {
|
|
69
|
+
out.error(error.message);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
// wallet import - Import existing key/mnemonic
|
|
74
|
+
wallet
|
|
75
|
+
.command('import')
|
|
76
|
+
.description('Import an existing private key or mnemonic phrase')
|
|
77
|
+
.option('--key <privateKey>', 'Private key to import')
|
|
78
|
+
.option('--mnemonic <phrase>', 'Mnemonic phrase to import')
|
|
79
|
+
.action(async (options, command) => {
|
|
80
|
+
const globalOpts = command.parent.parent.opts();
|
|
81
|
+
const out = createOutput(globalOpts);
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
let keyOrMnemonic = options.key || options.mnemonic;
|
|
85
|
+
|
|
86
|
+
if (!keyOrMnemonic) {
|
|
87
|
+
if (globalOpts.json) {
|
|
88
|
+
out.error('Provide --key or --mnemonic in JSON mode');
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const inquirer = require('inquirer');
|
|
93
|
+
const { inputType } = await inquirer.prompt([{
|
|
94
|
+
type: 'list',
|
|
95
|
+
name: 'inputType',
|
|
96
|
+
message: 'What do you want to import?',
|
|
97
|
+
choices: ['Private Key', 'Mnemonic Phrase']
|
|
98
|
+
}]);
|
|
99
|
+
|
|
100
|
+
const { input } = await inquirer.prompt([{
|
|
101
|
+
type: 'password',
|
|
102
|
+
name: 'input',
|
|
103
|
+
message: `Enter your ${inputType.toLowerCase()}:`,
|
|
104
|
+
mask: '*'
|
|
105
|
+
}]);
|
|
106
|
+
keyOrMnemonic = input;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
let password;
|
|
110
|
+
if (globalOpts.json) {
|
|
111
|
+
// In JSON mode, just validate and output address
|
|
112
|
+
let testWallet;
|
|
113
|
+
if (keyOrMnemonic.includes(' ')) {
|
|
114
|
+
testWallet = ethers.Wallet.fromPhrase(keyOrMnemonic);
|
|
115
|
+
} else {
|
|
116
|
+
testWallet = new ethers.Wallet(keyOrMnemonic);
|
|
117
|
+
}
|
|
118
|
+
out.print({
|
|
119
|
+
address: testWallet.address,
|
|
120
|
+
note: 'Use --private-key or PRIVATE_KEY env var to authenticate.'
|
|
121
|
+
});
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const inquirer = require('inquirer');
|
|
126
|
+
const { password: pwd } = await inquirer.prompt([{
|
|
127
|
+
type: 'password',
|
|
128
|
+
name: 'password',
|
|
129
|
+
message: 'Enter password to encrypt keystore:',
|
|
130
|
+
mask: '*',
|
|
131
|
+
validate: (input) => input.length >= 8 || 'Password must be at least 8 characters'
|
|
132
|
+
}]);
|
|
133
|
+
|
|
134
|
+
out.startSpinner('Importing and encrypting keystore...');
|
|
135
|
+
const importedWallet = await importKeystore(keyOrMnemonic, pwd);
|
|
136
|
+
out.succeedSpinner('Wallet imported successfully');
|
|
137
|
+
|
|
138
|
+
out.print({ address: importedWallet.address }, { title: '\nš Wallet Imported' });
|
|
139
|
+
|
|
140
|
+
} catch (error) {
|
|
141
|
+
out.error(error.message);
|
|
142
|
+
}
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
// wallet show - Display wallet address
|
|
146
|
+
wallet
|
|
147
|
+
.command('show')
|
|
148
|
+
.description('Display the current wallet address')
|
|
149
|
+
.action(async (options, command) => {
|
|
150
|
+
const globalOpts = command.parent.parent.opts();
|
|
151
|
+
const out = createOutput(globalOpts);
|
|
152
|
+
|
|
153
|
+
try {
|
|
154
|
+
// Check for private key in options or env
|
|
155
|
+
if (globalOpts.privateKey) {
|
|
156
|
+
const wallet = new ethers.Wallet(globalOpts.privateKey);
|
|
157
|
+
out.print({ address: wallet.address, source: 'private-key-flag' });
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
if (process.env.PRIVATE_KEY) {
|
|
162
|
+
const wallet = new ethers.Wallet(process.env.PRIVATE_KEY);
|
|
163
|
+
out.print({ address: wallet.address, source: 'environment' });
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
// Check keystore
|
|
168
|
+
if (keystoreExists()) {
|
|
169
|
+
const address = getKeystoreAddress();
|
|
170
|
+
out.print({ address: address, source: 'keystore' });
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
out.error('No wallet configured. Use --private-key, set PRIVATE_KEY env var, or run "ethnotary wallet init"');
|
|
175
|
+
|
|
176
|
+
} catch (error) {
|
|
177
|
+
out.error(error.message);
|
|
178
|
+
}
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
module.exports = wallet;
|