-
Notifications
You must be signed in to change notification settings - Fork 49
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 pub option for public keys #87
Add pub option for public keys #87
Conversation
README.md
Outdated
$ cat recovery-phrase.prv | cardano-address key from-recovery-phrase Shelley \ | ||
| cardano-address key child 1852H/1815H/0H/2/0 \ | ||
| cardano-address key public --pub | ||
xpub16apaenn9ut6s40lcw3l8v68xawlrlq20z2966uzcx8jmv2q9uy7qh83kg9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like here pub
rather than xpub
- but do not know at this moment how to elegantly do it 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or more precisely I would like addr_vk
if we are dealing with payment/delegating address and stake_vk
if we are dealing with stake address (reward account). If not possible we will need a way to have --bech32WithHrp prefix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use pub/xpub only in cardano-address, and show how to use the bech32 util to change HRP.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of flipping this around and, have this being the default behavior, but require an explicit --with-chain-code
flag to return the public key with chain code.
We should avoid returning the chain code unless the user knows what he/she is doing with it. Changing the default, we would also need to change a bit the error message when failing to parse bytes into a public key + chain code (so that it hints users in the right direction, that a 32-byte chain code is missing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like that idea of requiring the user to specify what kind of key they need. Such as:
(--with-chain-code | --without-chain-code )
.cardano-address key xpub
/cardano-address key public
( --extended-key | --key-only )
$ cardano-address recovery-phrase generate --size 15 > recovery-phrase.prv | ||
$ cat recovery-phrase.prv | cardano-address key from-recovery-phrase Shelley | ||
xprv1fzu4e8cecxshgzzxzh7557sd8tffqreeq2je7fgsm7f02mq849vdupw7qwgxc3qawyqev0l8ew0f4fkp8hvr8mskz4hz6e6ejzjlevcskcl6lqpr07u7552fsfgteztuclse7luh4cp493zdhkrjdss0250cdw8n | ||
$ cat recovery-phrase.txt | cardano-address key from-recovery-phrase Shelley |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this change ? I think it was clearer before with both instructions visible in the same excerpt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and yes
- It would be better if the
recovery-phrase generate
command were added back to provide context. .txt
is a good extension to describe the content of the file.
README.md
Outdated
$ cat recovery-phrase.prv | cardano-address key from-recovery-phrase Shelley \ | ||
| cardano-address key child 1852H/1815H/0H/2/0 \ | ||
| cardano-address key public --pub | ||
xpub16apaenn9ut6s40lcw3l8v68xawlrlq20z2966uzcx8jmv2q9uy7qh83kg9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think of flipping this around and, have this being the default behavior, but require an explicit --with-chain-code
flag to return the public key with chain code.
We should avoid returning the chain code unless the user knows what he/she is doing with it. Changing the default, we would also need to change a bit the error message when failing to parse bytes into a public key + chain code (so that it hints users in the right direction, that a 32-byte chain code is missing).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good so far - do you think pub or xpub should be the "default"? Or should there be separate subcommands for pub and xpub?
( Parser, flag, long ) | ||
|
||
|
||
data PublicType = WithChainCode | WithoutChainCode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does a single type and parse function need its own module?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I somewhat just complied with the pattern we have for other things. So although I am slightly in favour with your opinion on this this would be outlier and may surprise anyone NEW looking at the code....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
, "Extended public key is default. In order to get public key" | ||
, ", ei., without chain code use '--pub'." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you know which use case is more common?
I am thinking that public key only might be a better default. Not sure though.
Another alternative could be to have completely separate subcommands -- e.g. public
and xpub
, or something like that. Then you could tell users to run xpub
if they need to derive child keys.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
More than which one is most common, I'd go for the "safest" from a privacy standpoint here. Since sharing your chain code allows other to create new (public) child keys from your public key, you may inadvertently gives access to an entire part of your sub-tree by sharing your extended public key.
Plus, cardano-cli and other cardano-tools mostly deals with non-extended ed25519 keys only.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
introduced --with-chain-code
and --without-chain-code
here c2e3c78
README.md
Outdated
$ cat recovery-phrase.prv | cardano-address key from-recovery-phrase Shelley \ | ||
| cardano-address key child 1852H/1815H/0H/2/0 \ | ||
| cardano-address key public --pub | ||
xpub16apaenn9ut6s40lcw3l8v68xawlrlq20z2966uzcx8jmv2q9uy7qh83kg9 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps use pub/xpub only in cardano-address, and show how to use the bech32 util to change HRP.
]) | ||
where | ||
parser = Public | ||
<$> encodingOpt [humanReadablePart|xpub|] | ||
<*> publicOpt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sometthing like this will let you change the HRP...
<*> publicOpt | |
parser = do | |
pub <- publicOpt | |
Public <$> encodingOpt (if pub == WithChainCode then [humanReadablePart|xpub|] else [humanReadablePart|pub|]) | |
<*> pure pub |
(clean it up though)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks for suggestion! in the end solved this like that 4ad1a31
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you use monadic rather than applicative then the ??? placeholder is not needed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A couple style issues, but otherwise good.
$ cardano-address recovery-phrase generate --size 15 > recovery-phrase.prv | ||
$ cat recovery-phrase.prv | cardano-address key from-recovery-phrase Shelley | ||
xprv1fzu4e8cecxshgzzxzh7557sd8tffqreeq2je7fgsm7f02mq849vdupw7qwgxc3qawyqev0l8ew0f4fkp8hvr8mskz4hz6e6ejzjlevcskcl6lqpr07u7552fsfgteztuclse7luh4cp493zdhkrjdss0250cdw8n | ||
$ cat recovery-phrase.txt | cardano-address key from-recovery-phrase Shelley |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes and yes
- It would be better if the
recovery-phrase generate
command were added back to provide context. .txt
is a good extension to describe the content of the file.
]) | ||
where | ||
parser = Public | ||
<$> encodingOpt [humanReadablePart|xpub|] | ||
<*> publicOpt |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you use monadic rather than applicative then the ??? placeholder is not needed.
xprv <- hGetXPrv stdin | ||
let xpub = toXPub xprv | ||
hPutBytes stdout (xpubToBytes xpub) encoding | ||
(bytes, encoding') <- case chainCode of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line doesn't need to be an IO action. It could be a plain let or where clause.
I would be inclined to set up hrp in the CLI Parser, and use a function.
let toBytes = case chainCode of
WithChainCode -> xpubToBytes
WithoutChainCode -> xpubPublicKey
hPutBytes stdout (toBytes xpub) encoding
( Parser, flag, long ) | ||
|
||
|
||
data PublicType = WithChainCode | WithoutChainCode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK
{ encoding :: Encoding | ||
, chainCode :: PublicType |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Parser will look better if the order of constructor fields are swapped.
2253: ADP-494 - Add POST endpoint for script address r=paweljakubas a=paweljakubas # Issue Number https://jira.iohk.io/browse/ADP-494 # Overview - [x] I have updated swagger with script as string - [x] I have added script as json - [x] I have extended Api - [x] I have extended core unit tests - [x] I have added cardano-addresses based impl - [x] I have added illustrative integration tests # Comments - Uses IntersectMBO/cardano-addresses#87 Co-authored-by: Pawel Jakubas <[email protected]> Co-authored-by: Rodney Lorrimar <[email protected]> Co-authored-by: IOHK <[email protected]>
For credentials from public key we need to have public keys without chain code.
cardano-foundation/cardano-wallet#2253
This PR adds a way to get public key (without chain code) if
--pub
is sneaked. Otherwise extended public key is returned.