hodl-wallet 1.3.4 → 1.3.8

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/index.mjs +41 -21
  2. package/package.json +3 -3
package/index.mjs CHANGED
@@ -127,19 +127,35 @@ class Wallet {
127
127
  }
128
128
 
129
129
  if (accountAction === 'Create New Account') {
130
- const mnemonic = bip39.generateMnemonic();
131
- const seed = await bip39.mnemonicToSeed(mnemonic);
132
- const root = hdkey.fromMasterSeed(seed);
133
- const addrNode = root.derive("m/44'/60'/0'/0/0");
134
- const privateKey = addrNode.privateKey.toString('hex');
135
- this.account = this.web3.eth.accounts.privateKeyToAccount('0x' + privateKey);
136
- this.account.mnemonic = mnemonic;
130
+ const { createWithMnemonic } = await inquirer.prompt({
131
+ type: 'confirm',
132
+ name: 'createWithMnemonic',
133
+ message: 'Create account with mnemonic?',
134
+ default: true
135
+ });
136
+
137
+ let message = 'Do you want to display sensitive information (private key';
138
+ if (createWithMnemonic) {
139
+ const mnemonic = bip39.generateMnemonic();
140
+ const seed = await bip39.mnemonicToSeed(mnemonic);
141
+ const root = hdkey.fromMasterSeed(seed);
142
+ const addrNode = root.derive("m/44'/60'/0'/0/0");
143
+ const privateKey = addrNode.privateKey.toString('hex');
144
+ this.account = this.web3.eth.accounts.privateKeyToAccount('0x' + privateKey);
145
+ this.account.mnemonic = mnemonic;
146
+ message += ' and mnemonic';
147
+ } else {
148
+ this.account = this.web3.eth.accounts.create();
149
+ }
150
+
151
+ message += ')?';
152
+
137
153
  await this.db.secureSet('account', this.account);
138
154
 
139
155
  const { showSensitive } = await inquirer.prompt({
140
156
  type: 'confirm',
141
157
  name: 'showSensitive',
142
- message: 'Do you want to display sensitive information (private key and mnemonic)?',
158
+ message,
143
159
  default: false,
144
160
  });
145
161
 
@@ -273,16 +289,8 @@ class Wallet {
273
289
  }
274
290
 
275
291
  async transferFunds() {
276
- let addressBook = this.db.get('addressBook') || [];
277
-
278
- const { token } = await inquirer.prompt({
279
- type: 'list',
280
- name: 'token',
281
- message: 'Token to transfer:',
282
- choices: Object.keys(this.selectedNetwork.tokens),
283
- });
284
-
285
- const tokens = this.selectedNetwork.tokens;
292
+ const addressBook = this.db.get('addressBook') || [];
293
+ addressBook.push({ name: 'Go Back', address: '' });
286
294
 
287
295
  // Implement autocomplete for address book
288
296
  const { recipient } = await inquirer.prompt({
@@ -293,13 +301,27 @@ class Wallet {
293
301
  input = input || '';
294
302
  return addressBook
295
303
  .filter(entry => entry.name.toLowerCase().includes(input.toLowerCase()) || entry.address.toLowerCase().includes(input.toLowerCase()))
296
- .map(entry => ({ name: `${entry.name} (${entry.address})`, value: entry.address }))
304
+ .map(entry => ({
305
+ name: entry.address ? `${entry.name} (${entry.address})` : entry.name,
306
+ value: entry.address
307
+ }))
297
308
  .concat([{ name: input, value: input }]); // Add the input as a possible choice
298
309
  },
299
310
  });
300
311
 
312
+ if (!recipient) return;
313
+
301
314
  let address = recipient;
302
315
 
316
+ const { token } = await inquirer.prompt({
317
+ type: 'list',
318
+ name: 'token',
319
+ message: 'Token to transfer:',
320
+ choices: Object.keys(this.selectedNetwork.tokens),
321
+ });
322
+
323
+ const tokens = this.selectedNetwork.tokens;
324
+
303
325
  const { amount } = await inquirer.prompt({
304
326
  type: 'input',
305
327
  name: 'amount',
@@ -697,8 +719,6 @@ while (true) {
697
719
  }
698
720
  }
699
721
 
700
-
701
-
702
722
  process.on('SIGINT', () => {
703
723
  console.log('\n');
704
724
  process.exit();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hodl-wallet",
3
- "version": "1.3.4",
3
+ "version": "1.3.8",
4
4
  "description": "🧊 HODL Wallet - Fast CLI crypto wallet!",
5
5
  "author": "Martin Clasen",
6
6
  "repository": {
@@ -43,10 +43,10 @@
43
43
  "bip39": "^3.1.0",
44
44
  "cli-table3": "^0.6.5",
45
45
  "crypto-js": "^4.2.0",
46
- "deepbase": "^1.1.8",
46
+ "deepbase": "^1.2.2",
47
47
  "hdkey": "^2.1.0",
48
48
  "inquirer": "^9.3.7",
49
49
  "inquirer-autocomplete-prompt": "^3.0.1",
50
50
  "web3": "^4.13.0"
51
51
  }
52
- }
52
+ }