AddressUtils { public static String scriptHashToAddress(byte[] scriptHash) { byte[] script = ArrayUtils.concatenate(NeoConfig.addressVersion(), scriptHash); byte[] checksum = ArrayUtils.getFirstNBytes(hash256(script), 4); return Base58.encode(ArrayUtils.concatenate(script, checksum)); }  static boolean isValidAddress(String address); static byte[] addressToScriptHash(String address); static String scriptHashToAddress(byte[] scriptHash);  }
@Test public void scriptHashToAddress() { NeoConfig.setAddressVersion((byte) 0x17); String script = "2102208aea0068c429a03316e37be0e3e8e21e6cda5442df4c5914a19b3a9b6de37568747476aa"; byte[] scriptHash = Hash.sha256AndThenRipemd160(Numeric.hexStringToByteArray(script)); String address = AddressUtils.scriptHashToAddress(scriptHash); String expectedAddress = "Aa63RMYRWHPRcrZNzUnq5SNrPqoV866Spu"; assertThat(address, is(expectedAddress)); }
@Test public void scriptHashToAddressWithAddressVersion() { String script = "21030529d1296dc2af1f77d8344138a77748599b69599af7ae6be57812a4ec3fa33968747476aa"; byte[] scriptHash = Hash.sha256AndThenRipemd160(Numeric.hexStringToByteArray(script)); System.out.println(Numeric.toHexString(scriptHash)); String address = AddressUtils.scriptHashToAddress(scriptHash); String expectedAddress = "PRivaTenetyWuqK7Gj7Vd747d77ssYeDhL"; assertThat(address, is(expectedAddress)); }
@Test public void testScriptHashToAddress() { byte[] scriptHash = Numeric.hexStringToByteArray("d336d7eb9975a29b2404fdb28185e277a4b299bc"); String address = "Ab2fvZdmnM4HwDgVbdBrbTLz1wK5TcEyhU"; assertThat(AddressUtils.scriptHashToAddress(scriptHash), is(address)); }
@Test public void testScriptHashToAddressWithVersion() { NeoConfig.setAddressVersion((byte) 0x37); byte[] scriptHash = Numeric.hexStringToByteArray("bbf14c0d508108e56402116aede9942a064f7dc6"); String address = "PRivaTenetyWuqK7Gj7Vd747d77ssYeDhL"; assertThat(AddressUtils.scriptHashToAddress(scriptHash), is(address)); }