mirror of
https://github.com/m2049r/xmrwallet
synced 2025-05-01 01:37:21 +02:00
fix for 2N9fzq66uZYQXp7uqrPBH6jKBhjrgTzpGCy (#190)
This commit is contained in:
parent
641abd13f5
commit
dd689b1883
app/src
main/java/com/m2049r/xmrwallet/util
test/java/com/m2049r/xmrwallet/util
@ -34,10 +34,11 @@ public class BitcoinAddressValidator {
|
|||||||
if (decoded == null)
|
if (decoded == null)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
int v = decoded[0] & 0xFF;
|
||||||
if (!testnet) {
|
if (!testnet) {
|
||||||
if ((decoded[0] != 0x00) && (decoded[0] != 0x05)) return false;
|
if ((v != 0x00) && (v != 0x05)) return false;
|
||||||
} else {
|
} 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));
|
byte[] hash1 = sha256(Arrays.copyOfRange(decoded, 0, 21));
|
||||||
@ -57,7 +58,11 @@ public class BitcoinAddressValidator {
|
|||||||
|
|
||||||
byte[] result = new byte[25];
|
byte[] result = new byte[25];
|
||||||
byte[] numBytes = num.toByteArray();
|
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;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ public class BitcoinAddressValidatorTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void validateBTC_shouldValidate() {
|
public void validateBTC_shouldValidate() {
|
||||||
|
assertTrue(BitcoinAddressValidator.validate("2N9fzq66uZYQXp7uqrPBH6jKBhjrgTzpGCy", true));
|
||||||
assertTrue(BitcoinAddressValidator.validate("1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i", false));
|
assertTrue(BitcoinAddressValidator.validate("1AGNa15ZQXAZUgFiqJ2i7Z2DPU2J6hW62i", false));
|
||||||
assertTrue(BitcoinAddressValidator.validate("1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9", false));
|
assertTrue(BitcoinAddressValidator.validate("1Q1pE5vPGEEMqRcVRMbtBK842Y6Pzo6nK9", false));
|
||||||
assertTrue(BitcoinAddressValidator.validate("3R2MPpTNQLCNs13qnHz89Rm82jQ27bAwft", false));
|
assertTrue(BitcoinAddressValidator.validate("3R2MPpTNQLCNs13qnHz89Rm82jQ27bAwft", false));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user