-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #90 from terra-money/feat/arguments
feat: refact arguments and add missing ones
- Loading branch information
Showing
38 changed files
with
271 additions
and
372 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,5 @@ yarn-error.log | |
# Files that must be skipped | ||
default.js | ||
.env | ||
voter.json | ||
voter.json | ||
dist/ |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,43 +1,39 @@ | ||
import * as keystore from './keystore' | ||
import * as promptly from 'promptly' | ||
|
||
export async function addKey(filePath: string, coinType: string, keyName: string, prefix: string): Promise<void> { | ||
export async function addKey(args): Promise<void> { | ||
console.log(args) | ||
let password = process.env.PASSWORD || '' | ||
let mnemonic = process.env.MNEMONIC || '' | ||
|
||
coinType = process.env.COIN_TYPE ? process.env.COIN_TYPE : coinType | ||
keyName = process.env.KEY_NAME ? process.env.KEY_NAME : keyName | ||
|
||
if (password === '') { | ||
password = await promptly.password(`Enter a passphrase to encrypt your key to disk:`, { | ||
replace: `*`, | ||
password = await promptly.password('Enter a passphrase to encrypt your key to disk:', { | ||
replace: '*', | ||
}) | ||
const confirm = await promptly.password(`Repeat the passphrase:`, { replace: `*` }) | ||
|
||
if (password !== confirm) { | ||
console.error(`ERROR: passphrases don't matchPassword confirm failed`) | ||
return | ||
if (password.length < 8) { | ||
throw Error('ERROR: password must be at least 8 characters') | ||
} | ||
} | ||
|
||
if (password.length < 8) { | ||
console.error(`ERROR: password must be at least 8 characters`) | ||
return | ||
const confirm = await promptly.password('Repeat the passphrase:', { replace: '*' }) | ||
|
||
if (password !== confirm) { | ||
throw Error("ERROR: passphrases don't matchPassword confirm failed") | ||
} | ||
} | ||
|
||
if (mnemonic === '') { | ||
mnemonic = await promptly.prompt(`Enter your bip39 mnemonic: `) | ||
mnemonic = await promptly.prompt('Enter your bip39 mnemonic: ') | ||
} | ||
|
||
if (mnemonic.trim().split(` `).length !== 24) { | ||
console.error(`Error: Mnemonic is not valid.`) | ||
return | ||
if (mnemonic.trim().split(' ').length !== 24) { | ||
throw Error('Error: Mnemonic is not valid.') | ||
} | ||
|
||
if (!prefix) { | ||
prefix = await promptly.prompt(`\nEnter the address prefix: `) | ||
if (!args.prefix) { | ||
args.prefix = await promptly.prompt('\nEnter the address prefix: ') | ||
} | ||
|
||
await keystore.save(filePath, keyName, password, mnemonic, coinType, prefix) | ||
console.info(`saved!`) | ||
await keystore.save(args, password, mnemonic) | ||
console.info('saved!') | ||
} |
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
Oops, something went wrong.