From 4741b9a41f2989aadac62b7e8fc21f8df7513913 Mon Sep 17 00:00:00 2001 From: Evguenia degtiareva Date: Thu, 25 Jul 2019 14:40:49 -0700 Subject: [PATCH 1/2] Create account : add option to pass a public key --- bin/near | 5 +++++ index.js | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/bin/near b/bin/near index ab32c3b5..09c40890 100755 --- a/bin/near +++ b/bin/near @@ -85,6 +85,11 @@ const createAccount = { type: 'string', required: true }) + .option('publicKey', { + desc: 'Public key to initialize the account with', + type: 'string', + required: false + }) .option('initialBalance', { desc: 'Number of tokens to transfer to newly created account', type: 'string', diff --git a/index.js b/index.js index bf1ec2c2..f053c326 100755 --- a/index.js +++ b/index.js @@ -50,9 +50,18 @@ async function connect(options) { exports.createAccount = async function(options) { let near = await connect(options); - const keyPair = await KeyPair.fromRandom('ed25519'); - await near.createAccount(options.accountId, keyPair.getPublicKey()); - near.connection.signer.keyStore.setKey(options.networkId, options.accountId, keyPair); + let keyPair; + let publicKey; + if (options.publicKey) { + publicKey = options.publicKey; + } else { + keyPair = await KeyPair.fromRandom('ed25519'); + publicKey = keyPair.getPublicKey(); + } + await near.createAccount(options.accountId, publicKey); + if (keyPair) { + near.connection.signer.keyStore.setKey(options.networkId, options.accountId, keyPair); + } console.log(`Account ${options.accountId} for network "${options.networkId}" was created.`); } From c942019d087aa23684fbfab45d7ca85358000980 Mon Sep 17 00:00:00 2001 From: Evguenia degtiareva Date: Thu, 25 Jul 2019 16:32:39 -0700 Subject: [PATCH 2/2] Addressing code review comments for adding public key param to createAccount --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index f053c326..88305ea0 100755 --- a/index.js +++ b/index.js @@ -60,7 +60,7 @@ exports.createAccount = async function(options) { } await near.createAccount(options.accountId, publicKey); if (keyPair) { - near.connection.signer.keyStore.setKey(options.networkId, options.accountId, keyPair); + await near.connection.signer.keyStore.setKey(options.networkId, options.accountId, keyPair); } console.log(`Account ${options.accountId} for network "${options.networkId}" was created.`); }