Skip to content

Commit

Permalink
Adds ZenCash Support
Browse files Browse the repository at this point in the history
  • Loading branch information
smrtz committed Sep 5, 2017
1 parent 902e3de commit 728e178
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
Expand Up @@ -28,6 +28,7 @@
import io.bisq.gui.util.validation.params.PivxParams;
import io.bisq.gui.util.validation.params.btc.BtcMainNetParams;
import lombok.extern.slf4j.Slf4j;
import org.bitcoinj.core.Base58;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.AddressFormatException;
import org.bitcoinj.params.MainNetParams;
Expand Down Expand Up @@ -245,6 +246,39 @@ public ValidationResult validate(String input) {
} catch (NxtReedSolomonValidator.DecodeException e) {
return wrongChecksum;
}
// Address validation for Zencash - https://zensystem.io
case "ZEN":
try {
// Get the non Base58 form of the address and the bytecode of the first two bytes
byte [] byteAddress = Base58.decodeChecked(input);
int version0 = byteAddress[0] & 0xFF;
int version1 = byteAddress[1] & 0xFF;

// We only support public ("zn" (0x20,0x89), "t1" (0x1C,0xB8))
// and multisig ("zs" (0x20,0x96), "t3" (0x1C,0xBD)) addresses

// Fail for private addresses
if (version0 == 0x16 && version1 == 0x9A) {
// Address starts with "zc"
return new ValidationResult(false, Res.get("validation.altcoin.zAddressesNotSupported"));
}
else if (version0 == 0x1C && (version1 == 0xB8 || version1 == 0xBD)) {
// "t1" or "t3" address
return new ValidationResult(true);
}
else if (version0 == 0x20 && (version1 == 0x89 || version1 == 0x96)) {
// "zn" or "zs" address
return new ValidationResult(true);
}
else {
// Unknown Type
return new ValidationResult(false);
}
}
catch (AddressFormatException e) {
// Unhandled Exception (probably a checksum error)
return new ValidationResult(false);
}
default:
log.debug("Validation for AltCoinAddress not implemented yet. currencyCode: " + currencyCode);
return validationResult;
Expand Down
Expand Up @@ -135,4 +135,21 @@ public void testNXT() {
assertFalse(validator.validate("NXT-JM2U-U4AE-G7WF-3Np9F").isValid);
assertFalse(validator.validate("NXT-2222-2222-2222-22222").isValid);
}

@Test
public void testZEN() {
AltCoinAddressValidator validator = new AltCoinAddressValidator();
validator.setCurrencyCode("ZEN");

assertTrue(validator.validate("znk62Ey7ptTyHgYLaLDTEwhLF6uN1DXTBfa").isValid);
assertTrue(validator.validate("znTqzi5rTXf6KJnX5tLaC5CMGHfeWJwy1c7").isValid);
assertTrue(validator.validate("t1V9h2P9n4sYg629Xn4jVDPySJJxGmPb1HK").isValid); // Random address from ZCash blockchain
assertTrue(validator.validate("t3Ut4KUq2ZSMTPNE67pBU5LqYCi2q36KpXQ").isValid); // Random address from ZCash blockchain

assertFalse(validator.validate("zcKffBrza1cirFY47aKvXiV411NZMscf7zUY5bD1HwvkoQvKHgpxLYUHtMCLqBAeif1VwHmMjrMAKNrdCknCVqCzRNizHUq").isValid);
assertFalse(validator.validate("AFTqzi5rTXf6KJnX5tLaC5CMGHfeWJwy1c7").isValid);
assertFalse(validator.validate("zig-zag").isValid);
assertFalse(validator.validate("0123456789").isValid);
assertFalse(validator.validate("").isValid);
}
}

0 comments on commit 728e178

Please sign in to comment.