validate function
Implementation
Address validate(String address) {
if (address.length < minLength) {
throw FormatException(
'Too short: addresses must be at least $minLength characters');
}
/// First try to parse as taproot / segwit
final prefix = address.substring(0, 2).toLowerCase();
if (prefix == 'bc' || prefix == 'tb') {
return validateSegwit(address);
}
final codec = Base58CheckCodec.bitcoin();
Base58CheckPayload decoded;
try {
decoded = codec.decode(address);
} catch (e) {
throw Base58CheckException(e);
}
if (decoded.payload.length != 20) {
throw FormatException('Invalid Base58 payload length');
}
final version = decoded.version;
if (!versionToType.keys.contains(version)) {
throw FormatException('Invalid Base58 version');
}
return Address(
versionToType[version]!,
versionToNetwork[version]!,
false,
);
}