Skip to content

Commit

Permalink
use base64-unpadded encoding/decoding for tokenmessage
Browse files Browse the repository at this point in the history
  • Loading branch information
imalsogreg committed Feb 22, 2024
1 parent 89d10ca commit f899c60
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Pact/Native.hs
Original file line number Diff line number Diff line change
Expand Up @@ -1642,7 +1642,7 @@ hyperlaneDecodeTokenMessageDef =
-- fails in exactly the cases we expect.
-- (The only change we make to its output is to strip error messages).
computeGas' i (GHyperlaneDecodeTokenMessage (T.length msg)) $
case B64URL.decode (T.encodeUtf8 msg) of
case B64URL.decodeUnpadded (T.encodeUtf8 msg) of
Left _ -> evalError' i "Failed to base64-decode token message"
Right bytes -> do
case runGetOrFail (getTokenMessageERC20 <* eof) (BS.fromStrict bytes) of
Expand Down Expand Up @@ -1706,7 +1706,7 @@ hyperlaneDecodeTokenMessageDef =
-- | Helper function for creating TokenMessages encoded in the ERC20 format
-- and base64url encoded. Used for generating test data.
encodeTokenMessage :: BS.ByteString -> Word256 -> Word256 -> Text
encodeTokenMessage recipient amount chain = T.decodeUtf8 $ B64URL.encode (BS.toStrict bytes)
encodeTokenMessage recipient amount chain = T.decodeUtf8 $ B64URL.encodeUnpadded (BS.toStrict bytes)
where
bytes = runPut $ do
putWord256be (96 :: Word256)
Expand Down
5 changes: 5 additions & 0 deletions tests/pact/hyperlane.repl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"chainId": "4",
"recipient": (read-keyset 'test-keys)
}
(hyperlane-decode-token-message "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAewAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGF7InByZWQiOiAia2V5cy1hbGwiLCAia2V5cyI6WyJkYTFhMzM5YmQ4MmQyYzJlOTE4MDYyNmEwMGRjMDQzMjc1ZGViM2FiYWJiMjdiNTczOGFiZjZiOWRjZWU4ZGI2Il19AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA")
)

; Decoding a valid TokenMessage should succeed.
(expect-failure "decoding fails for base64-padded messages"
(hyperlane-decode-token-message "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAewAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAGF7InByZWQiOiAia2V5cy1hbGwiLCAia2V5cyI6WyJkYTFhMzM5YmQ4MmQyYzJlOTE4MDYyNmEwMGRjMDQzMjc1ZGViM2FiYWJiMjdiNTczOGFiZjZiOWRjZWU4ZGI2Il19AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA==")
)

Expand Down

0 comments on commit f899c60

Please sign in to comment.