-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "generate function for asking id (#581)"
This reverts commit 6a71513.
- Loading branch information
Showing
7 changed files
with
43 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,45 @@ | ||
const KeyPair = require('near-api-js').KeyPair; | ||
const exitOnError = require('../utils/exit-on-error'); | ||
const implicitAccountId = require('../utils/implicit-accountid'); | ||
const connect = require('../utils/connect'); | ||
const eventtracking = require('../utils/eventtracking'); | ||
|
||
module.exports = { | ||
command: 'generate-key [account-id]', | ||
desc: 'generate key or show key from Ledger', | ||
builder: (yargs) => yargs, | ||
handler: exitOnError(generateKey) | ||
}; | ||
|
||
async function generateKey(options) { | ||
await eventtracking.askForId(options); | ||
const near = await connect(options); | ||
handler: exitOnError(async (argv) => { | ||
let near = await require('../utils/connect')(argv); | ||
|
||
if (options.usingLedger) { | ||
if (options.accountId) { | ||
console.log('WARN: Account id is provided but ignored in case of using Ledger.'); | ||
if (argv.usingLedger) { | ||
if (argv.accountId) { | ||
console.log('WARN: Account id is provided but ignored in case of using Ledger.'); | ||
} | ||
const publicKey = await argv.signer.getPublicKey(); | ||
// NOTE: Command above already prints public key. | ||
console.log(`Implicit account: ${implicitAccountId(publicKey.toString())}`); | ||
// TODO: query all accounts with this public key here. | ||
// TODO: check if implicit account exist, and if the key doen't match already. | ||
return; | ||
} | ||
const publicKey = await options.signer.getPublicKey(); | ||
// NOTE: Command above already prints public key. | ||
console.log(`Implicit account: ${implicitAccountId(publicKey.toString())}`); | ||
// TODO: query all accounts with this public key here. | ||
// TODO: check if implicit account exist, and if the key doesn't match already. | ||
return; | ||
} | ||
|
||
const { deps: { keyStore } } = near.config; | ||
const existingKey = await keyStore.getKey(options.networkId, options.accountId); | ||
if (existingKey) { | ||
console.log(`Account has existing key pair with ${existingKey.publicKey} public key`); | ||
return; | ||
} | ||
|
||
// If key doesn't exist, create one and store in the keyStore. | ||
// Otherwise, it's expected that both key and accountId are already provided in arguments. | ||
if (!options.publicKey) { | ||
const keyPair = KeyPair.fromRandom('ed25519'); | ||
options.publicKey = keyPair.publicKey.toString(); | ||
options.accountId = options.accountId || implicitAccountId(options.publicKey); | ||
await keyStore.setKey(options.networkId, options.accountId, keyPair); | ||
} else if (options.seedPhrase) { | ||
const seededKeyPair = await options.signer.keyStore.getKey(options.networkId, options.accountId); | ||
await keyStore.setKey(options.networkId, options.accountId, seededKeyPair); | ||
} | ||
const { deps: { keyStore } } = near.config; | ||
const existingKey = await keyStore.getKey(argv.networkId, argv.accountId); | ||
if (existingKey) { | ||
console.log(`Account has existing key pair with ${existingKey.publicKey} public key`); | ||
return; | ||
} | ||
|
||
console.log(`Key pair with ${options.publicKey} public key for an account "${options.accountId}"`); | ||
} | ||
// If key doesn't exist, create one and store in the keyStore. | ||
// Otherwise, it's expected that both key and accountId are already provided in arguments. | ||
if (!argv.publicKey) { | ||
const keyPair = KeyPair.fromRandom('ed25519'); | ||
argv.publicKey = keyPair.publicKey.toString(); | ||
argv.accountId = argv.accountId || implicitAccountId(argv.publicKey); | ||
await keyStore.setKey(argv.networkId, argv.accountId, keyPair); | ||
} else if (argv.seedPhrase) { | ||
const seededKeyPair = await argv.signer.keyStore.getKey(argv.networkId, argv.accountId); | ||
await keyStore.setKey(argv.networkId, argv.accountId, seededKeyPair); | ||
} | ||
|
||
console.log(`Key pair with ${argv.publicKey} public key for an account "${argv.accountId}"`); | ||
}) | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters