addressToBytes static method

List<int> addressToBytes(
  1. String address
)

convert address string to bytes with padding zero for special addresses.

Implementation

static List<int> addressToBytes(String address) {
  address = StringUtils.strip0x(address);
  List<int>? bytes = BytesUtils.tryFromHexString(
    address,
    paddingZero:
        address.length == 1 ||
        address.length == AptosAddrConst.shortAddressLength,
  );
  if (bytes == null ||
      (bytes.length != AptosAddrConst.addressBytesLength &&
          bytes.length != 1)) {
    throw AddressConverterException.addressValidationFailed(
      network: "Aptos",
      details: {"address": address},
    );
  }
  if (bytes.length == 1) {
    final byte = bytes[0];
    if (byte >= AptosAddrConst.specialAddressLastBytesMax) {
      throw AddressConverterException.addressValidationFailed(
        network: "Aptos",
        details: {"address": BytesUtils.toHexString(bytes)},
      );
    }
    bytes = List.filled(AptosAddrConst.addressBytesLength, 0);
    bytes.last = byte;
  }
  return praseAddressBytes(bytes);
}