How to detect that address string is correct Waves account address


#1

My API have user account address as input parameter.
I want to define that address is correct before I will send transactions.
Is there any way to do it? I cannot find corresponding API in your JS libraries.


#2

curl -X GET --header ‘Accept: application/json’ ‘https://nodes.wavesplatform.com/addresses/data/3PPsHUKZ8WLU7sLm9sV5Sb75RNKnMinqU58
Response Body
[]
Response Code
200

curl -X GET --header ‘Accept: application/json’ ‘https://nodes.wavesplatform.com/addresses/data/3PPsHUKZ8WLU7sLm9sV5Sb75RNKnMinqU59

Response Body

{
  "error": 102,
  "message": "invalid address"
}

Response Code

400

Probably there are simplier ways


#3

Unfortunately, any server requests is not solution for me.
I require a way to determine it offline using something like formula for sample:
address[0]===‘3’ (ugly sample)


#4

Account validation

Account is valid then it is a valid Base58 string and the length of corresponding array is 26 bytes. Version of address (1st byte) is equal to 1. The network byte (2nd byte) is equal to network ID. The checksum of address (last 4 bytes) is correct.

In Java:

private static byte[] address(byte[] publicKey, byte chainId) {
    ByteBuffer buf = ByteBuffer.allocate(26);
    byte[] hash = secureHash(publicKey, 0, publicKey.length);
    buf.put((byte) 1).put((byte) chainId).put(hash, 0, 20);
    byte[] checksum = secureHash(buf.array(), 0, 22);
    buf.put(checksum, 0, 4);
    return buf.array();
}

where secureHash is KECCAK256(BLAKE2B256(buffer))