solana icon indicating copy to clipboard operation
solana copied to clipboard

keygen: add the ability to use derivation path for new & grind commands

Open diman-io opened this issue 3 years ago • 18 comments

Problem

Impossible to use mnemonic from keygen in Phantom wallet and others.

Summary of Changes

Added ability to generate keypairs with mnemonic which is friendly with Phantom wallet and others.

This feature has been added for new and grind subcommands.

UPD. Now it looks:

solana-keygen new -o keypair.json prompt://?key=0/0
solana-keygen new -o keypair.json prompt://?full-path=m/44/2017/0/1
solana-keygen grind --use-mnemonic --starts-with a:1 prompt://?key=0/0
solana-keygen grind --use-mnemonic --starts-with a:1 prompt://?full-path=m/44/2017/0/1 

diman-io avatar Dec 04 '21 22:12 diman-io

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Jan 09 '22 04:01 stale[bot]

Hi there @solana-labs/community-pr-subscribers ! What's wrong with this PR? Do I need to add a new test for pub function? Or are you just too busy right now to be distracted by such features?)

diman-io avatar Jan 09 '22 10:01 diman-io

Hey @mvines @t-nelson I'm sorry for pinging you, but could you please reply to my comments? It'll weekend and I'll have time to make some work.

diman-io avatar Feb 04 '22 11:02 diman-io

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Mar 02 '22 17:03 stale[bot]

ping @solana-labs/community-pr-subscribers

diman-io avatar Apr 09 '22 19:04 diman-io

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Apr 17 '22 15:04 stale[bot]

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Apr 25 '22 13:04 stale[bot]

Codecov Report

Merging #21614 (11fdcb3) into master (8ba003a) will increase coverage by 0.1%. The diff coverage is 0.0%.

:exclamation: Current head 11fdcb3 differs from pull request most recent head 79d4136. Consider uploading reports for the commit 79d4136 to get more accurate results

@@            Coverage Diff            @@
##           master   #21614     +/-   ##
=========================================
+ Coverage    81.8%    82.0%   +0.1%     
=========================================
  Files         632      596     -36     
  Lines      167499   165242   -2257     
  Branches      322        0    -322     
=========================================
- Hits       137169   135546   -1623     
+ Misses      30217    29696    -521     
+ Partials      113        0    -113     

codecov[bot] avatar Apr 26 '22 11:04 codecov[bot]

I have merged with the current master, and I have updated the code to use clap-v3-utils.

diman-io avatar Apr 26 '22 18:04 diman-io

@t-nelson Could you please re-review?

diman-io avatar May 05 '22 19:05 diman-io

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Jun 12 '22 18:06 stale[bot]

@t-nelson could you please review? Now it is as you suggested:

solana-keygen new -o keypair.json prompt://?key=0/0
solana-keygen new -o keypair.json prompt://?full-path=m/44/2017/0/1
solana-keygen grind --use-mnemonic --starts-with a:1 prompt://?key=0/0
solana-keygen grind --use-mnemonic --starts-with a:1 prompt://?full-path=m/44/2017/0/1 

diman-io avatar Jun 13 '22 08:06 diman-io

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Jul 10 '22 18:07 stale[bot]

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

stale[bot] avatar Jul 31 '22 06:07 stale[bot]

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

Please don't close this 🙌

beeman avatar Jul 31 '22 12:07 beeman

@solana-labs/community-pr-subscribers I'm so sorry to bore you, but it looks like t-nelson is too busy to rereview. So maybe you could assign someone else to review this PR?

diman-io avatar Aug 03 '22 15:08 diman-io

I find it pretty odd that you're pulling the derivation from the prompt uri. I would recommend that you introduce a new derivation path cli argument for these subcommands. A lot of your changes in this PR add unnecessary complexity, this change should be much smaller, can you try creating a new more focused PR?

@jstarry Thank you for your answer! 🙏 🙏 🙏

At the begin of this PR it was as you suggest now:

solana-keygen new --use-derivation-path -o keypair.json
solana-keygen new --use-derivation-path m/44/2017/0/1 -o keypair.json
solana-keygen grind --use-mnemonic --use-derivation-path --starts-with a:1
solana-keygen grind --use-mnemonic --use-derivation-path m/44/2017/0/1 --starts-with a:1

mvines suggested just to remove use.

But later t-nelson suggested to use prompt uri instead of additional arg (this pattern is used with other solana-keygen subcommands: recover, pubkey, verify) and I redid.

So now I'm confusion.

diman-io avatar Aug 07 '22 12:08 diman-io

I agree with mvines' suggestion to drop use but I disagree with t-nelson's suggestion to use prompt here. Please move forward with --derivation-path (without use as you had before) sorry for the back and forth!

jstarry avatar Aug 07 '22 16:08 jstarry

Hello @jstarry I've done the suggestions. Could you please review?

diman-io avatar Sep 07 '22 09:09 diman-io

@diman-io I was attempting to use this new version of the keygen program (built from source) to generate with a derivation path, but I continue to get a panic error when running the following commands:

# `new` subcommand
solana-keygen new --derivation-path -o ./keypair.json --force
# `grind` subcommand
solana-keygen grind --ignore-case --starts-with a:1 --derivation-path --use-mnemonic

NOTE: This is true for both the grind and new subcommands

The only way I have found to not get a panic, is if I also specify the --no-passphase or --no-bip39-passphrase. But there is no explicit mention of this requirement. Is there something I am missing/not understanding here, or is this in face a bug?

Update: This error seems to appear anytime I have the --use-mnemonic flag

nickfrosty avatar Dec 25 '22 15:12 nickfrosty

@nickfrosty I just built from the tip of master and your examples worked for me. How did you build? cd keygen && ../cargo build --release ?

diman-io avatar Dec 25 '22 16:12 diman-io

@diman-io strange. I tried building both the full release from both the tip of master and the most the 1.14.11 release source using the same build command. Maybe it is something with my local computer?

The panic error keeps happening at the code below, both in grind and new:

acquire_passphrase_and_message(matches).unwrap()

This is the error I keep getting

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Os { code: 6, kind: Uncategorized, message: "No such device or address" }',

Thoughts?

Edit: As another data point, it seems that any time I build for source, the keygen program always gives me this error when I get the prompt to enter a passphrase. The code panics before I am even able to enter an input. But it does print the prompt to the terminal

nickfrosty avatar Dec 25 '22 16:12 nickfrosty

@diman-io I just realized that it was my VS code integrated terminal. For some reason it does not want to accept stdin and causes the panic. When I run the program in my actual terminal, no issues. Sorry about my troubles 🙃

nickfrosty avatar Dec 25 '22 17:12 nickfrosty