Example #1
0
 /**
  * Convert to a human readable (BASE58) address with network and type prefixes.
  *
  * @param address
  * @return human readable representation of the address
  * @throws ValidationException
  */
 public static String toSatoshiStyle(Address address) throws ValidationException {
   byte[] keyDigest = address.toByteArray();
   int addressFlag;
   if (address.getNetwork() == Network.PRODUCTION) {
     if (address.getType() == Address.Type.COMMON) {
       addressFlag = 0x0;
     } else if (address.getType() == Address.Type.P2SH) {
       addressFlag = 0x5;
     } else {
       throw new ValidationException("unknown address type");
     }
   } else if (address.getNetwork() == Network.TEST) {
     if (address.getType() == Address.Type.COMMON) {
       addressFlag = 0x6f;
     } else if (address.getType() == Address.Type.P2SH) {
       addressFlag = 196;
     } else {
       throw new ValidationException("unknown address type");
     }
   } else {
     throw new ValidationException("unknown network");
   }
   byte[] addressBytes = new byte[1 + keyDigest.length + 4];
   addressBytes[0] = (byte) (addressFlag & 0xff);
   System.arraycopy(keyDigest, 0, addressBytes, 1, keyDigest.length);
   byte[] check = Hash.hash(addressBytes, 0, keyDigest.length + 1);
   System.arraycopy(check, 0, addressBytes, keyDigest.length + 1, 4);
   return ByteUtils.toBase58(addressBytes);
 }
Example #2
0
 /**
  * Convert to a human readable address string from a digest
  *
  * @param keyDigest - the digest
  * @param addressFlag - a flag encoded in the first byte of string representation
  * @return
  * @throws ValidationException
  */
 @Deprecated
 public static String toSatoshiStyle(byte[] keyDigest, int addressFlag) {
   byte[] addressBytes = new byte[1 + keyDigest.length + 4];
   addressBytes[0] = (byte) (addressFlag & 0xff);
   System.arraycopy(keyDigest, 0, addressBytes, 1, keyDigest.length);
   byte[] check = Hash.hash(addressBytes, 0, keyDigest.length + 1);
   System.arraycopy(check, 0, addressBytes, keyDigest.length + 1, 4);
   return ByteUtils.toBase58(addressBytes);
 }