Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for array format in account import and export #74

Merged
merged 6 commits into from
Jan 29, 2021

Conversation

moshthepitt
Copy link
Contributor

@moshthepitt moshthepitt commented Jan 27, 2021

Changes things such that you can only import/export accounts using the array format used in Solana at ~/.config/solana/id.json and other places.

@moshthepitt moshthepitt changed the title Add support for raw key export Add support for raw key array format export Jan 27, 2021
Adds a switch to output the exported private key as a "raw" key that
can be used from solana (~/.config/solana/id.json), among other places.

Fixes: https://github.com/project-serum/spl-token-wallet/issues/66
@moshthepitt
Copy link
Contributor Author

Updated the wording to "array format"

arrayfmt


const keyOutput = isArrayFormat
? `[${[].slice.call(wallet.provider.account.secretKey)}]`
: bs58.encode(wallet.provider.account.secretKey);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To both line 19 and 20, is it worth adding the optional chaining operator e.g. wallet?.provider?.account?.secretKey? I'm new to the Solana codebase, so maybe all of these keys are guaranteed by the ts interfaces, if so then disregard this comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure about this. @armaniferrante thoughts?

Copy link
Contributor

@armaniferrante armaniferrante Jan 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not the expert here, but I would be surprised if any of these fields were null or undefined.

@evanpipta
Copy link

evanpipta commented Jan 28, 2021

Should there also be the "array format" option for importing?

If you're not going to add an "array format" option for importing accounts, then for better UX I think there should be some kind of message along the lines of "Developer feature - array format cannot be imported directly" when exporting in the byte array format.

The problem I'm foreseeing is non-technical users of the wallet accidentally exporting the array format instead of base58, then not being able to import their wallet later on another device / another browser.

@moshthepitt
Copy link
Contributor Author

If you're not going to add an "array format" option for importing accounts, then for better UX I think there should be some kind of message along the lines of "Developer feature - array format cannot be imported directly" when exporting in the byte array format.

Added this notice

improved

@moshthepitt
Copy link
Contributor Author

@evanpipta thanks for the comments. I made changes.

@evanpipta
Copy link

@evanpipta thanks for the comments. I made changes.

Sweet! After I commented I noticed this open ticket to support different import formats including array:
https://github.com/project-serum/spl-token-wallet/issues/55

I might work on it, then the notice about the array format could be removed after that's implemented.

@armaniferrante
Copy link
Contributor

As mentioned by @sconybeare, since no tools actually use the base58 private key format directly, the right thing to do here is to replace the base58 import/export with the array format. @moshthepitt do you want to extend this PR to do this? If not @evanpipta that'd be awesome if you wanted to take this.

@moshthepitt
Copy link
Contributor Author

@evanpipta @armaniferrante please have a look. I have now changed it such that both importing and exporting only work with the array format.

onlyarrayexport

@moshthepitt moshthepitt changed the title Add support for raw key array format export Add support for array format in account import and export Jan 29, 2021
Copy link
Contributor

@armaniferrante armaniferrante left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for doing this!

@armaniferrante armaniferrante merged commit f0386ce into project-serum:master Jan 29, 2021
@moshthepitt moshthepitt deleted the raw-key-support branch January 29, 2021 08:50
@evanpipta
Copy link

evanpipta commented Jan 29, 2021

Nice, I see you merged this, should we still work on #55 to have "legacy support" for accounts exported before this change? Or to make it easier to import keys from other wallets that might export in a different format?

@armaniferrante
Copy link
Contributor

Nice, I see you merged this, should we still work on #55 to have "legacy support" for accounts exported before this change? Or to make it easier to import keys from other wallets that might export in a different format?

I think it's a good idea to import/export keys from other (relatively popular) wallets that are in different formats. Any in particular you had in mind?

@pnzfox
Copy link

pnzfox commented Feb 1, 2021

i cant import my private key with old format!!!!

@moshthepitt
Copy link
Contributor Author

@armaniferrante does it make sense to allow importing the old bs58 keys to support existing users at sollet.io and possibly elsewhere?

@armaniferrante
Copy link
Contributor

@moshthepitt yes lets just import them both and automatically detect which format is being used. I see no need to require this elsewhere (other than sollet).

@moshthepitt
Copy link
Contributor Author

Cool, will send a PR your way @armaniferrante

moshthepitt added a commit to moshthepitt/spl-token-wallet that referenced this pull request Feb 2, 2021
This modified version can import private keys formated as:

- base58 strings
- raw arrays

Context: project-serum#74 (comment)
@moshthepitt
Copy link
Contributor Author

@armaniferrante please have a look at #77

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Export private key in array format Add label for private key import format
4 participants