-
Notifications
You must be signed in to change notification settings - Fork 48
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
CIP-0129 support #288
base: master
Are you sure you want to change the base?
CIP-0129 support #288
Conversation
a316308
to
7a3a998
Compare
@paweljakubas If you replace |
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.
That provides a very good coverage of the features, I would like to suggest we remove some duplication in order to improve the maintainability of this code over time
@@ -85,6 +87,22 @@ run Hash{outputFormat} = do | |||
allowedPrefixes = map fst prefixes | |||
prefixFor = fromJust . flip lookup prefixes | |||
|
|||
afterHashing hrp hashed |
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.
Wouldn't pattern matching be a more elegant solution than a sequence of ifs
here?
-- | Print string to the console without newline appended. | ||
hPutStringNoNewLn :: Handle -> String -> IO () | ||
hPutStringNoNewLn h = | ||
B8.hPutStr h . T.encodeUtf8 . T.pack |
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 feels weird, why not use directly System.IO.hPutStr
?
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.
Because of strictness perhaps?
@@ -44,85 +44,85 @@ spec = do | |||
specScriptHashProper "script1w8469gq5ed7xtyf2tqdng5yn7ykgckkfcl38xre8hk3ejk2lcwt" | |||
[iii|#{verKeyH4}|] | |||
|
|||
specScriptHashProper "drep_script13hu7a632tuntrlyjkazzczrzzt7dx6e8v3rc25jd9zcgv68nx9r" | |||
specScriptHashProper "drep1ydv8xcdxwpy7zrf805yenpz7cdnap4c87v7zewvmdjyyygq44jy4j" |
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.
Looking at those strings makes me wish those were in a text file usable externally and loaded by our tests so as to be relatively simple to edit and publish
core/lib/Cardano/Address/Script.hs
Outdated
appendByte payload = case cred of | ||
Representative -> | ||
let fstByte = 0b00100011 :: Word8 | ||
in BS.cons fstByte payload | ||
CommitteeCold -> | ||
let fstByte = 0b00010011 :: Word8 | ||
in BS.cons fstByte payload | ||
CommitteeHot -> | ||
let fstByte = 0b00000011 :: Word8 | ||
in BS.cons fstByte payload | ||
_ -> payload |
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.
appendByte payload = case cred of | |
Representative -> | |
let fstByte = 0b00100011 :: Word8 | |
in BS.cons fstByte payload | |
CommitteeCold -> | |
let fstByte = 0b00010011 :: Word8 | |
in BS.cons fstByte payload | |
CommitteeHot -> | |
let fstByte = 0b00000011 :: Word8 | |
in BS.cons fstByte payload | |
_ -> payload | |
appendByte payload = maybe payload (`BS.cons` payload) bytePrefix | |
bytePrefix = case cred of | |
Representative -> Just 0b00100011 | |
CommitteeCold -> Just 0b00010011 | |
CommitteeHot -> Just 0b00000011 | |
_ -> Nothing |
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.
Also I would move toBytePrefix
function cloes to the KeyRole
type, possibly with a fromBytePrefix
counterpart so that we can reuse them
let (fstByte, payload) = first BS.head $ BS.splitAt 1 bytes | ||
-- drep 0010.... | ||
-- scripthash ....0011 | ||
in if fstByte == 0b00100011 then |
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.
that's where we could reuse toBytePrefix/fromBytePrefix
perhaps?
>>= maybeToRight ErrScriptHashFromTextWrongPayload . scriptHashFromBytes | ||
where | ||
convertBytes hrp bytes | ||
| hrp == CIP5.drep && checkBSLength bytes 29 = |
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.
Lots of duplication in there :)
core/lib/Cardano/Address/Script.hs
Outdated
-- | ||
-- keyhash ....0010 | ||
keyHashAppendByteCIP0129 :: ByteString -> KeyRole -> ByteString | ||
keyHashAppendByteCIP0129 payload = \case |
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 duplicates the appendByte
function above, factor out?
-- Possible errors when deserializing a script hash from text. | ||
-- | ||
-- @since 4.0.0 | ||
data ErrScriptHashFromText |
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 think it would be useful to provide more details to the user when something fails, like the invalid string, or the wrong prefix, etc.
remove redundant trace
7a3a998
to
2b8ac69
Compare
PR adds CIP-0129 support
Basically drep, cc hot and cc cold key hashes are decorated with prepended byte. The same is for script hashes.
It affects data payload that is used as hashes. For the rest key hashes and script hashes it is 28-byte payload, here 29-byte payload.
Tackles #284
There is going to be additional PR enhancing https://github.com/cardano-foundation/CIPs/tree/master/CIP-0105 test vectors and deprecation comments
In the end we are going to have the following behavior