Conversation
|
|
||
| private static byte[] createChecksum(byte[] hrp, byte[] data) { | ||
|
|
||
| byte[] zeroes = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
|
|
||
| public static Pair<byte[], byte[]> bech32Decode(String bech) throws Exception { | ||
|
|
||
| if(!bech.equals(bech.toLowerCase()) && !bech.equals(bech.toUpperCase())) { |
There was a problem hiding this comment.
Is there a risk that toLowerCase/toUpperCase are locale dependent?
There was a problem hiding this comment.
I don't think so given the character set being used. In any case, placing the test after the byte value test should remove any doubt.
There was a problem hiding this comment.
I'd still be a bit more confortable with bech.toLowerCase(Locale.ROOT), which should be deterministic?
| if (!hrp.equals(hrpgotStr)) { | ||
| throw new Exception("mismatching bech32 human readeable part"); | ||
| } | ||
| if (!hrpgotStr.equalsIgnoreCase("bc") && !hrpgotStr.equalsIgnoreCase("tb")) { |
There was a problem hiding this comment.
I would leave that up to the caller, who should know what hrp is expected anyway.
| ret.add((byte)((acc << (toBits - bits)) & maxv)); | ||
| } | ||
| else if (bits >= fromBits || (byte)(((acc << (toBits - bits)) & maxv)) != 0) { | ||
| throw new Exception("panic"); |
There was a problem hiding this comment.
This case is different from the cases above, as it can occur without any programmer error (malformed input can trigger it), so I'm unsure if an exception is the right way to deal with it.
|
Thanks a lot for doing this, and my apologies for the slow responses. Two comments:
|
|
Bech32 encoding of SegWit addresses in Java. Build instructions are in README.md.