Skip to content

Commit

Permalink
make account an arg
Browse files Browse the repository at this point in the history
  • Loading branch information
vchong committed May 10, 2024
1 parent dcc6a53 commit 0574819
Showing 1 changed file with 21 additions and 3 deletions.
24 changes: 21 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,13 @@ yargs
})
.option('path', {
alias: 'd',
default: `m/44'/5757'/0'/0/0`,
describe: 'The derivation path for network'
describe: 'The derivation path for network, e.g. "m/44\'/5757\'/0\'/0/0"',
type: 'string',
})
.option('account', {
alias: 'a',
describe: 'Specify the account number for the derivation path',
type: 'number',
})
.choices('w', [12, 24])
.command('sk', 'Generate keys for Stacks 2.0', (yargs) => {
Expand All @@ -125,7 +130,19 @@ yargs
const phrase = argv.phrase || generateMnemonic(entropy, randombytes)
// console.log('generate', phrase, argv.testnet)

console.log(JSON.stringify(await generateKeys(phrase, mainnet, argv.path), null, 2))
let derivationPath;
if (argv.path && argv.account) {
console.error('Error: Only one of --path or --account can be used, not both.');
process.exit(1);
} else if (argv.path) {
derivationPath = argv.path;
} else if (argv.account) {
derivationPath = `m/44'/5757'/${argv.account}'/0/0`;
} else {
derivationPath = `m/44'/5757'/0'/0/0`; // default derivation path
}

console.log(JSON.stringify(await generateKeys(phrase, mainnet, derivationPath), null, 2))
})
.command('pk <key>', 'Generate keys for Stacks 2.0 from private key', (yargs) => {
yargs.positional('key', {
Expand Down Expand Up @@ -171,6 +188,7 @@ yargs
.requiresArg('w')
.requiresArg('p')
.requiresArg('d')
.requiresArg('a')
.strictCommands(true)
.strictOptions(true)
.help()
Expand Down

0 comments on commit 0574819

Please sign in to comment.