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

lowercase input before bech32 encoding #378

Merged
merged 6 commits into from
Oct 29, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Network/Haskoin/Address/Bech32.hs
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ maxBech32Length = 90
bech32Encode :: HRP -> [Word5] -> Maybe Bech32
bech32Encode hrp dat = do
guard $ checkHRP hrp
let dat' = dat ++ bech32CreateChecksum hrp dat
let dat' = dat ++ bech32CreateChecksum (T.toLower hrp) dat
rest = map (charset !) dat'
result = T.concat [T.toLower hrp, T.pack "1", T.pack rest]
guard $ T.length result <= maxBech32Length
Expand Down
13 changes: 13 additions & 0 deletions test/Network/Haskoin/Address/Bech32Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ spec = do
it "should be a valid address" $ forM_ validAddresses testValidAddress
it "should be an invalid address" $
forM_ invalidAddresses testInvalidAddress
it "should be same for the input in different case" $
all (== Just "test12hrzfj") . map (flip bech32Encode []) $ hrpCaseVariants
describe "more encoding/decoding cases" $ do
it "length > 90" $
assert $
Expand Down Expand Up @@ -141,3 +143,14 @@ invalidAddresses =
, "tb1qrp33g0q5c5txsp9arysrx4k6zdkfs4nce4xj0gdcccefvpysxf3pjxtptv"
, "bc1gmk9yu"
]

hrpCaseVariants:: [Text]
hrpCaseVariants = map T.pack hrpTestPermutations

hrpTestPermutations :: [String]
hrpTestPermutations = do
a <- ['t', 'T']
b <- ['e', 'E']
c <- ['s', 'S']
d <- ['t', 'T']
return [a, b, c, d]