Skip to content

Commit 5cfa1e1

Browse files
authored
Merge pull request #97 from aeternity/release/2.4.0
Release 2.4.0
2 parents b722783 + dccb1be commit 5cfa1e1

File tree

8 files changed

+767
-398
lines changed

8 files changed

+767
-398
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 2.4.0 (2019-08-21)
2+
3+
### Features
4+
5+
* **ACCOUNT:** Add command for generating and printing bulk of Key Pairs ([#95](https://github.com/aeternity/aepp-cli-js/issues/95)) ([1cb3e5b](https://github.com/aeternity/aepp-cli-js/commit/1cb3e5b))
6+
7+
8+
19
# 2.3.0 (2019-08-05)
210

311

bin/aecli-account.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,17 @@ program
158158
.description('Get account nonce')
159159
.action(async (walletPath, ...arguments) => await Account.getAccountNonce(walletPath, utils.cli.getCmdFromArguments(arguments)))
160160

161+
// ## Initialize `generateKeyPairs` command
162+
//
163+
// You can use this command to generate KeyPair's.
164+
//
165+
// Example: `aecli account generate 10 --force
166+
program
167+
.command('generate <count>')
168+
.option('--forcePrompt', 'Force prompting')
169+
.description('Generate keyPairs')
170+
.action(async (count, ...arguments) => await Account.generateKeyPairs(count, utils.cli.getCmdFromArguments(arguments)))
171+
161172

162173
// Handle unknown command's
163174
program.on('command:*', () => utils.errors.unknownCommandHandler(program)())

bin/commands/account.js

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
* PERFORMANCE OF THIS SOFTWARE.
2020
*/
2121

22+
import { generateKeyPair } from '@aeternity/aepp-sdk/es/utils/crypto'
2223
import { generateSecureWallet, generateSecureWalletFromPrivKey } from '../utils/account'
2324
import { HASH_TYPES } from '../utils/constant'
2425
import { initClientByWalletFile } from '../utils/cli'
@@ -30,7 +31,7 @@ import { PROMPT_TYPE, prompt } from '../utils/prompt'
3031
// ## `Sign` function
3132
// this function allow you to `sign` transaction's
3233
async function sign (walletPath, tx, options) {
33-
let { json } = options
34+
const { json } = options
3435
try {
3536
// Validate `tx` hash
3637
if (tx.slice(0, 2) !== 'tx') { throw new Error('Invalid transaction hash') }
@@ -153,7 +154,7 @@ async function getAddress (walletPath, options) {
153154
if (privateKey) {
154155
if (forcePrompt || await prompt(PROMPT_TYPE.confirm, { message: 'Are you sure you want print your secret key?' })) {
155156
printUnderscored('Secret Key', keypair.secretKey)
156-
print({ publicKey: await client.address(), secretKey: keypair.secretKey})
157+
print({ publicKey: await client.address(), secretKey: keypair.secretKey })
157158
}
158159
} else {
159160
print({ publicKey: await client.address() })
@@ -244,6 +245,35 @@ async function createSecureWalletByPrivKey (walletPath, priv, { output, password
244245
}
245246
}
246247

248+
// ## Create secure `wallet` file from `private-key`
249+
// This function allow you to generate `keypair` from `private-key` and write it to secure `ethereum` like key-file
250+
async function generateKeyPairs (count = 1, { forcePrompt, json }) {
251+
try {
252+
if (!Number.isInteger(+count)) {
253+
throw new Error('Count must be an Number')
254+
}
255+
if (forcePrompt || await prompt(PROMPT_TYPE.confirm, { message: 'Are you sure you want print your secret key?' })) {
256+
const accounts = Array.from(Array(parseInt(count))).map(_ => generateKeyPair(false))
257+
if (json) {
258+
print(JSON.stringify(accounts, null, 2))
259+
} else {
260+
accounts.forEach((acc, i) => {
261+
printUnderscored('Account index', i)
262+
printUnderscored('Public Key', acc.publicKey)
263+
printUnderscored('Secret Key', acc.secretKey)
264+
print('')
265+
})
266+
}
267+
} else {
268+
process.exit(0)
269+
}
270+
process.exit(0)
271+
} catch (e) {
272+
printError(e.message)
273+
process.exit(1)
274+
}
275+
}
276+
247277
export const Account = {
248278
spend,
249279
getBalance,
@@ -252,5 +282,6 @@ export const Account = {
252282
createSecureWallet,
253283
createSecureWalletByPrivKey,
254284
sign,
255-
transferFunds
285+
transferFunds,
286+
generateKeyPairs
256287
}

bin/utils/account.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import path from 'path'
2121
import * as Crypto from '@aeternity/aepp-sdk/es/utils/crypto'
2222
import { dump, getAddressFromPriv, recover } from '@aeternity/aepp-sdk/es/utils/keystore'
2323

24-
import { printUnderscored } from './print'
2524
import { isFileExist, readJSONFile, writeFile } from './helpers'
2625
import { PROMPT_TYPE, prompt } from './prompt'
2726

bin/utils/print.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export function print (msg, obj) {
5959

6060
// Print error helper
6161
export function printError (msg, obj) {
62-
console.log(msg, obj)
62+
console.log(msg, obj || '')
6363
}
6464

6565
// Print `underscored`

0 commit comments

Comments
 (0)