encodeAddress static method

String encodeAddress(
  1. Uint8List publicKey
)

Encode a public key to a human-readable representation, with a 4-byte checksum appended at the end, using SHA512/256.

Note that string representations of addresses generated by different SDKs may not be compatible.

Implementation

static String encodeAddress(Uint8List publicKey) {
  // Sanitize public key length
  if (publicKey.length != PUBLIC_KEY_LENGTH) {
    throw AlgorandException(
        message: 'Public key is an invalid address. Wrong length');
  }

  // Compute the hash using sha512/256
  final digest = sha512256.convert(publicKey);
  final hashBytes = Uint8List.fromList(digest.bytes);

  // Take the last 4 bytes and append to addr
  final checksum = hashBytes.sublist(hashBytes.length - 4);

  final addr = base32.encode(Uint8List.fromList(publicKey + checksum));
  return addr.trimPadding();
}