encodeKey method

  1. @override
String encodeKey(
  1. List<int> pubKey, [
  2. Map<String, dynamic> kwargs = const {}
])
override

Encodes a public key into a blockchain address.

This method takes a public key in the form of a List

  • pubKey: The public key to be encoded as a blockchain address.
  • kwargs: Optional keyword arguments for encoder-specific options.

Returns the blockchain address string representing the encoded 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"] ?? ADANetwork.mainnet;

  /// Check if the provided network tag is a valid enum value.
  if (netTag is! ADANetwork) {
    throw const AddressConverterException(
        'Address type is not an enumerative of ADANetwork');
  }

  final pointer = kwargs["pointer"];
  if (pointer is! Pointer) {
    throw const AddressConverterException(
        'The provided value for "Pointer" is not of type Pointer.');
  }

  /// Validate and retrieve public keys.
  final pubKeyObj = AddrKeyValidator.validateAndGetEd25519Key(pubKey);
  // Compute key hashes for public spending and public delegation keys.
  final pubKeyHash =
      AdaShelleyAddrUtils.keyHash(pubKeyObj.compressed.sublist(1));
  return AdaShelleyAddrUtils.encode(
      credential:
          AdaStakeCredential(hash: pubKeyHash, type: AdaStakeCredType.key),
      netTag: netTag,
      pointer: pointer,
      hrp: AdaShelleyAddrConst.networkTagToAddrHrp[netTag]!,
      type: ADAAddressType.pointer);
}