encodeKey method
Encodes a public key into an Ergo address.
pubKey
: The public key to encode into an address.
kwargs
: Optional parameters.
net_type
: The network type for the Ergo address (mainnet or testnet).
Returns an Ergo address as a string. Throws an ArgumentException if the address type is not of ErgoNetworkTypes.
Implementation
@override
String encodeKey(List<int> pubKey, [Map<String, dynamic> kwargs = const {}]) {
final netType = kwargs['net_type'] ?? ErgoNetworkTypes.mainnet;
/// Validate network type
if (netType is! ErgoNetworkTypes) {
throw const AddressConverterException(
'Address type is not an enumerative of ErgoNetworkTypes');
}
final pubKeyObj = AddrKeyValidator.validateAndGetSecp256k1Key(pubKey);
final pubKeyBytes = pubKeyObj.compressed;
final prefixByte =
_ErgoAddrUtils.encodePrefix(ErgoAddressTypes.p2pkh, netType);
final addrPayloadBytes = List<int>.from([...prefixByte, ...pubKeyBytes]);
final checksum = _ErgoAddrUtils.computeChecksum(addrPayloadBytes);
return Base58Encoder.encode(
List<int>.from([...addrPayloadBytes, ...checksum]));
}