dcdpr / libbech32-java

BSD 3-Clause "New" or "Revised" License
2 stars 5 forks source link

bech32 result is not right, maybe checksum exist bug #4

Open youngqqcn opened 3 years ago

youngqqcn commented 3 years ago
String humanReadablePart = "hello";
char[] data = {14, 15, 3, 31, 13};
String b = Bech32.encode(humanReadablePart, data);
System.out.println(b);   
// "hello1w0rldcs7fw6" : "hello" + Bech32.separator + encoded data + 6 char checksum

I use python bech32 library

pip3 install bech32

>>> from bech32 import bech32_encode
>>> bech32_encode("hello", [14, 15, 3, 31, 13])
'hello1w0rld80pk3y'

6 char checksum is different

danpape commented 3 years ago

Hi, thanks for bringing this up.

Several months ago, Pieter Wuille recommended that the bech32 algorithm be slightly changed to improve certain properties of the encoding: https://gist.github.com/sipa/a9845b37c1b298a7301c33a04090b2eb

Due to that recommendation, we have updated our c++ and java implementations: https://github.com/dcdpr/libbech32/commit/698cd6d671d321f69c749cdb5748d4db5445d1f3 and https://github.com/dcdpr/libbech32-java/commit/1d188e800cd02bce764398b8e3f031306864ed40

It does not appear that the python bech32 library you refer to has made that update yet: https://github.com/fiatjaf/bech32/blob/master/bech32/__init__.py#L46