encodeKey method
Blockchain address encoder for Ada Shelley staking addresses. This encoder is used to create staking addresses based on the network tag and public key.
Implementation
@override
String encodeKey(List<int> pubKey, [Map<String, dynamic> kwargs = const {}]) {
/// Determine the network tag, defaulting to mainnet if not specified.
final netTag = kwargs["net_tag"] ?? AdaShelleyAddrNetworkTags.mainnet;
/// Check if the provided network tag is a valid enum value.
if (netTag is! AdaShelleyAddrNetworkTags) {
throw ArgumentException(
'Address type is not an enumerative of AdaShelleyAddrNetworkTags');
}
/// Validate and get the Ed25519 public key object from the provided bytes.
final pubKeyObj = AddrKeyValidator.validateAndGetEd25519Key(pubKey);
/// Compute the public key hash based on the compressed key bytes.
final pubKeyHash =
_AdaShelleyAddrUtils.keyHash(pubKeyObj.compressed.sublist(1));
/// Encode the address prefix based on the reward header type and network tag.
final firstByte = _AdaShelleyAddrUtils.encodePrefix(
AdaShelleyAddrHeaderTypes.reward, netTag.value);
/// Generate the staking address using Bech32 encoding with the appropriate HRP.
return Bech32Encoder.encode(
AdaShelleyAddrConst.networkTagToRewardAddrHrp[netTag]!,
List<int>.from([...firstByte, ...pubKeyHash]));
}