@@ -42,6 +42,7 @@ This script initialize all `account` function
42
42
* PERFORMANCE OF THIS SOFTWARE.
43
43
*/
44
44
45
+ import { generateKeyPair } from ' @aeternity/aepp-sdk/es/utils/crypto'
45
46
import { generateSecureWallet , generateSecureWalletFromPrivKey } from ' ../utils/account'
46
47
import { HASH_TYPES } from ' ../utils/constant'
47
48
import { initClientByWalletFile } from ' ../utils/cli'
@@ -67,7 +68,7 @@ this function allow you to `sign` transaction's
67
68
68
69
``` js
69
70
async function sign (walletPath , tx , options ) {
70
- let { json } = options
71
+ const { json } = options
71
72
try {
72
73
73
74
` ` `
@@ -113,6 +114,7 @@ Get `keyPair` by `walletPath`, decrypt using password and initialize `Account` f
113
114
printUnderscored (' Unsigned' , tx)
114
115
printUnderscored (' Signed' , signedTx)
115
116
}
117
+ process .exit (0 )
116
118
})
117
119
} catch (e) {
118
120
printError (e .message )
@@ -184,6 +186,7 @@ if waitMined false
184
186
json
185
187
? print ({ tx })
186
188
: printTransaction (tx, json)
189
+ process .exit (0 )
187
190
})
188
191
} catch (e) {
189
192
printError (e .message )
@@ -258,6 +261,7 @@ if waitMined false
258
261
} else {
259
262
printTransaction (tx, json)
260
263
}
264
+ process .exit (0 )
261
265
})
262
266
} catch (e) {
263
267
printError (e .message )
@@ -305,6 +309,7 @@ Get `keyPair` by `walletPath`, decrypt using password and initialize `Ae` client
305
309
printUnderscored (' Balance' , await client .balance (keypair .publicKey , { height: + height, hash }))
306
310
printUnderscored (' ID' , await client .address ())
307
311
printUnderscored (' Nonce' , nonce)
312
+ process .exit (0 )
308
313
}
309
314
)
310
315
} catch (e) {
@@ -329,7 +334,7 @@ This function allow you retrieve account `public` and `private` keys
329
334
330
335
``` js
331
336
async function getAddress (walletPath , options ) {
332
- const { privateKey , forcePrompt = false } = options
337
+ const { privateKey , forcePrompt = false , json } = options
333
338
try {
334
339
335
340
` ` `
@@ -350,12 +355,24 @@ Get `keyPair` by `walletPath`, decrypt using password and initialize `Ae` client
350
355
351
356
await handleApiError (
352
357
async () => {
353
- printUnderscored (' Address' , await client .address ())
354
- if (privateKey) {
355
- if (forcePrompt || await prompt (PROMPT_TYPE .confirm , { message: ' Are you sure you want print your secret key?' })) {
356
- printUnderscored (' Secret Key' , keypair .secretKey )
358
+ if (json) {
359
+ if (privateKey) {
360
+ if (forcePrompt || await prompt (PROMPT_TYPE .confirm , { message: ' Are you sure you want print your secret key?' })) {
361
+ printUnderscored (' Secret Key' , keypair .secretKey )
362
+ print ({ publicKey: await client .address (), secretKey: keypair .secretKey })
363
+ }
364
+ } else {
365
+ print ({ publicKey: await client .address () })
366
+ }
367
+ } else {
368
+ printUnderscored (' Address' , await client .address ())
369
+ if (privateKey) {
370
+ if (forcePrompt || await prompt (PROMPT_TYPE .confirm , { message: ' Are you sure you want print your secret key?' })) {
371
+ printUnderscored (' Secret Key' , keypair .secretKey )
372
+ }
357
373
}
358
374
}
375
+ process .exit (0 )
359
376
}
360
377
)
361
378
} catch (e) {
@@ -380,6 +397,7 @@ This function allow you retrieve account `nonce`
380
397
381
398
``` js
382
399
async function getAccountNonce (walletPath , options ) {
400
+ const { json } = options
383
401
try {
384
402
385
403
` ` `
@@ -401,9 +419,18 @@ Get `keyPair` by `walletPath`, decrypt using password and initialize `Ae` client
401
419
await handleApiError (
402
420
async () => {
403
421
const nonce = await client .getAccountNonce (keypair .publicKey )
404
- printUnderscored (' ID' , keypair .publicKey )
405
- printUnderscored (' Nonce' , nonce - 1 )
406
- printUnderscored (' Next Nonce' , nonce)
422
+ if (json) {
423
+ print ({
424
+ id: keypair .publicKey ,
425
+ nonce: nonce - 1 ,
426
+ nextNonce: nonce
427
+ })
428
+ } else {
429
+ printUnderscored (' ID' , keypair .publicKey )
430
+ printUnderscored (' Nonce' , nonce - 1 )
431
+ printUnderscored (' Next Nonce' , nonce)
432
+ }
433
+ process .exit (0 )
407
434
}
408
435
)
409
436
} catch (e) {
@@ -427,9 +454,52 @@ This function allow you to generate `keypair` and write it to secure `ethereum`
427
454
428
455
429
456
``` js
430
- async function createSecureWallet (walletPath , { output, password, overwrite }) {
457
+ async function createSecureWallet (walletPath , { output, password, overwrite, json }) {
458
+ try {
459
+ const { publicKey , path } = await generateSecureWallet (walletPath, { output, password, overwrite })
460
+ if (json) {
461
+ print ({
462
+ publicKey,
463
+ path
464
+ })
465
+ } else {
466
+ printUnderscored (' Address' , publicKey)
467
+ printUnderscored (' Path' , path)
468
+ }
469
+ process .exit (0 )
470
+ } catch (e) {
471
+ printError (e .message )
472
+ }
473
+ }
474
+
475
+
476
+ ```
477
+
478
+
479
+
480
+
481
+
482
+
483
+
484
+ ## Create secure ` wallet ` file from ` private-key `
485
+ This function allow you to generate ` keypair ` from ` private-key ` and write it to secure ` ethereum ` like key-file
486
+
487
+
488
+
489
+
490
+ ``` js
491
+ async function createSecureWalletByPrivKey (walletPath , priv , { output, password, overwrite, json }) {
431
492
try {
432
- await generateSecureWallet (walletPath, { output, password, overwrite })
493
+ const { publicKey , path } = await generateSecureWalletFromPrivKey (walletPath, priv, { output, password, overwrite })
494
+ if (json) {
495
+ print ({
496
+ publicKey,
497
+ path
498
+ })
499
+ } else {
500
+ printUnderscored (' Address' , publicKey)
501
+ printUnderscored (' Path' , path)
502
+ }
433
503
process .exit (0 )
434
504
} catch (e) {
435
505
printError (e .message )
@@ -452,12 +522,30 @@ This function allow you to generate `keypair` from `private-key` and write it to
452
522
453
523
454
524
``` js
455
- async function createSecureWalletByPrivKey ( walletPath , priv , { output, password, overwrite }) {
525
+ async function generateKeyPairs ( count = 1 , { forcePrompt, json }) {
456
526
try {
457
- await generateSecureWalletFromPrivKey (walletPath, priv, { output, password, overwrite })
527
+ if (! Number .isInteger (+ count)) {
528
+ throw new Error (' Count must be an Number' )
529
+ }
530
+ if (forcePrompt || await prompt (PROMPT_TYPE .confirm , { message: ' Are you sure you want print your secret key?' })) {
531
+ const accounts = Array .from (Array (parseInt (count))).map (_ => generateKeyPair (false ))
532
+ if (json) {
533
+ print (JSON .stringify (accounts, null , 2 ))
534
+ } else {
535
+ accounts .forEach ((acc , i ) => {
536
+ printUnderscored (' Account index' , i)
537
+ printUnderscored (' Public Key' , acc .publicKey )
538
+ printUnderscored (' Secret Key' , acc .secretKey )
539
+ print (' ' )
540
+ })
541
+ }
542
+ } else {
543
+ process .exit (0 )
544
+ }
458
545
process .exit (0 )
459
546
} catch (e) {
460
547
printError (e .message )
548
+ process .exit (1 )
461
549
}
462
550
}
463
551
@@ -469,7 +557,8 @@ export const Account = {
469
557
createSecureWallet,
470
558
createSecureWalletByPrivKey,
471
559
sign,
472
- transferFunds
560
+ transferFunds,
561
+ generateKeyPairs
473
562
}
474
563
475
564
0 commit comments