-
Notifications
You must be signed in to change notification settings - Fork 217
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 functions for serializing keys as text #272
Conversation
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, let's add unit tests corresponding to these too.
546945d
to
a88694b
Compare
To store XPrv and XPub in a database column or text file, a hex-encoded string is best.
-> Property | ||
prop_roundtripXPriv xpriv = do | ||
let (Right xpriv') = (deserializeXPrv . serializeXPrv) xpriv | ||
xpriv === xpriv' |
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 should rather be written:
xpriv' = (deserializeXPrv . serializeXPrv) xpriv
Right xpriv === xpriv'
With the latter version, in case the property fails, we get a nice error output with a counter example from Quickcheck. With the former, it blows up because of an invalid pattern-match 😬
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.
corrected
genRootKeys :: Gen (Key 'RootK XPrv) | ||
genRootKeys = do | ||
(s, g, e) <- (,,) | ||
<$> genPassphrase @"seed" (0, 32) |
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.
Minor remark but the seed should be at least 16-bit according to cardano-crypto
:
-- | Generate a new XPrv from an entropy seed
--
-- The seed should be at least 16 bytes, although it is not enforced
--
-- The passphrase encrypt the secret key in memory
generateNew :: (ByteArrayAccess keyPassPhrase, ByteArrayAccess generationPassPhrase, ByteArrayAccess seed)
We don't actually have any comment on the matter in our code either. I'll put a point on the blackboard.
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.
corrected
a88694b
to
e224d4b
Compare
address review remarks
Relates to #143.
Overview
To store XPrv and XPub in a database column or text file, a hex-encoded string is suitable.