-
Notifications
You must be signed in to change notification settings - Fork 106
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
Java implementation #19
base: master
Are you sure you want to change the base?
Conversation
|
||
private static byte[] createChecksum(byte[] hrp, byte[] data) { | ||
|
||
byte[] zeroes = new byte[] { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; |
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.
final?
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.
Updated.
|
||
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a risk that toLowerCase/toUpperCase are locale dependent?
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 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd still be a bit more confortable with bech.toLowerCase(Locale.ROOT)
, which should be deterministic?
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.
Updated.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would leave that up to the caller, who should know what hrp is expected anyway.
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.
Updated.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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.
Updated.
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.