1
mirror of https://github.com/m2049r/xmrwallet synced 2025-02-26 20:13:03 +01:00

fix for 2N9fzq66uZYQXp7uqrPBH6jKBhjrgTzpGCy (#190)

This commit is contained in:
m2049r 2018-01-24 19:59:13 +01:00 committed by GitHub
parent 641abd13f5
commit dd689b1883
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 3 deletions

View File

@ -34,10 +34,11 @@ public class BitcoinAddressValidator {
if (decoded == null)
return false;
int v = decoded[0] & 0xFF;
if (!testnet) {
if ((decoded[0] != 0x00) && (decoded[0] != 0x05)) return false;
if ((v != 0x00) && (v != 0x05)) return false;
} else {
if ((decoded[0] != 0x6f) && (decoded[0] != 0xc4)) return false;
if ((v != 0x6f) && (v != 0xc4)) return false;
}
byte[] hash1 = sha256(Arrays.copyOfRange(decoded, 0, 21));
@ -57,7 +58,11 @@ public class BitcoinAddressValidator {
byte[] result = new byte[25];
byte[] numBytes = num.toByteArray();
System.arraycopy(numBytes, 0, result, result.length - numBytes.length, numBytes.length);
if (num.bitLength() == 200) {
System.arraycopy(numBytes, 1, result, 0, 25);
} else {
System.arraycopy(numBytes, 0, result, result.length - numBytes.length, numBytes.length);
}
return result;
}

View File

@ -25,6 +25,7 @@ public class BitcoinAddressValidatorTest {
@Test
public void validateBTC_shouldValidate() {
assertTrue(BitcoinAddressValidator.validate("2N9fzq66uZYQXp7uqrPBH6jKBhjrgTzpGCy", true));
assertTrue(BitcoinAddressValidator.validate("1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i", false));
assertTrue(BitcoinAddressValidator.validate("1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9", false));
assertTrue(BitcoinAddressValidator.validate("3R2MPpTNQLCNs13qnHz89Rm82jQ27bAwft", false));