decodeAddr method
Decodes an Ethereum address from its string representation.
This method takes a string representing an Ethereum address as input and decodes it into its byte representation. It also provides an option to skip checksum validation if specified.
Parameters:
- addr: The Ethereum address as a string to be decoded.
- kwargs: Optional keyword arguments (e.g., skip_chksum_enc) for additional configuration.
Returns: A List
Throws:
- ArgumentException: If the address is not of the correct length or if checksum validation fails (if not skipped).
Implementation
@override
List<int> decodeAddr(String addr, [Map<String, dynamic> kwargs = const {}]) {
final skipChecksum = kwargs["skip_chksum_enc"] ?? false;
final String addrNoPrefix = AddrDecUtils.validateAndRemovePrefix(
addr, CoinsConf.ethereum.params.addrPrefix!);
AddrDecUtils.validateLength(addrNoPrefix, EthAddrConst.addrLen);
if (!skipChecksum &&
addrNoPrefix != EthAddrUtils._checksumEncode(addrNoPrefix)) {
throw const AddressConverterException("Invalid checksum encoding");
}
return BytesUtils.fromHexString(addrNoPrefix);
}