Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

Commit

Permalink
Implement near generate-key
Browse files Browse the repository at this point in the history
  • Loading branch information
vgrichina committed Nov 5, 2019
1 parent 5244d9c commit 271d7e0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 1 deletion.
1 change: 1 addition & 0 deletions bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ yargs // eslint-disable-line
.command(stake)
.command(login)
.command(require('../commands/repl'))
.command(require('../commands/generate-key'))
.config(config)
.alias({
'accountId': ['account_id'],
Expand Down
17 changes: 17 additions & 0 deletions commands/generate-key.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const KeyPair = require('nearlib').KeyPair;
const exitOnError = require('../utils/exit-on-error');

module.exports = {
command: 'generate-key <account-id>',
desc: 'generate key ',
builder: (yargs) => yargs,
handler: exitOnError(async (argv) => {
let near = await require('../utils/connect')(argv);
if (argv.accountId) {
const { deps: { keyStore }} = near.config;
const keyPair = KeyPair.fromRandom('ed25519');
await keyStore.setKey(argv.networkId, argv.accountId, keyPair);
console.log(`Generated key pair with ${keyPair.publicKey} public key`);
}
})
};
9 changes: 8 additions & 1 deletion test/test_generate_key.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,16 @@ set -ex
KEY_FILE=neardev/default/generate-key-test.json
rm -f KEY_FILE

./bin/near generate-key generate-key-test
RESULT=$(./bin/near generate-key generate-key-test --networkId default)
echo $RESULT

if [[ ! -f "${KEY_FILE}" ]]; then
echo "FAILURE Key file doesn't exist"
exit 1
fi

EXPECTED=".*Generated key pair with ed25519:.+ public key.*"
if [[ ! "$RESULT" =~ $EXPECTED ]]; then
echo FAILURE Unexpected output from near generate-key
exit 1
fi

0 comments on commit 271d7e0

Please sign in to comment.