decodeAddress static method

Uint8List decodeAddress(
  1. String address
)

Decode an encoded, uppercased Algorand address to a public key.

Throws an AlgorandException when the address cannot be decoded.

Implementation

static Uint8List decodeAddress(String address) {
  // Decode the address
  final addressBytes = base32.decode(address);

  // Sanity length check
  if (addressBytes.length != PUBLIC_KEY_LENGTH + CHECKSUM_BYTE_LENGTH) {
    throw AlgorandException(
        message: 'Input string is an invalid address. Wrong length');
  }

  // Find the public key & checksum
  final publicKey = addressBytes.sublist(0, PUBLIC_KEY_LENGTH);
  final checksum = addressBytes.sublist(
      PUBLIC_KEY_LENGTH, PUBLIC_KEY_LENGTH + CHECKSUM_BYTE_LENGTH);

  // Compute the expected checksum
  final computedChecksum = sha512256
      .convert(publicKey)
      .bytes
      .sublist(PUBLIC_KEY_LENGTH - CHECKSUM_BYTE_LENGTH);

  if (!const ListEquality().equals(computedChecksum, checksum)) {
    throw AlgorandException(
        message: 'Invalid Algorand address. Checksums do not match.');
  }

  return publicKey;
}