encodeKey method

  1. @override
String encodeKey(
  1. List<int> pubKey, {
  2. int? ss58Format,
  3. CryptoKeyType? type,
})
override

Encodes a public key or address bytes into a blockchain address.

Throws AddressConverterException on invalid input.

Implementation

@override
String encodeKey(List<int> pubKey, {int? ss58Format, CryptoKeyType? type}) {
  type = AddrKeyValidator.getAddrArg<CryptoKeyType>(type, "type");
  ss58Format = AddrKeyValidator.getAddrArg<int>(ss58Format, "ss58Format");
  return switch (type) {
    CryptoKeyType.secp256k1 => SubstrateSecp256k1AddrEncoder().encodeKey(
      pubKey,
      ss58Format: ss58Format,
    ),
    CryptoKeyType.sr25519 => SubstrateSr25519AddrEncoder().encodeKey(
      pubKey,
      ss58Format: ss58Format,
    ),
    CryptoKeyType.ed25519 => SubstrateSr25519AddrEncoder().encodeKey(
      pubKey,
      ss58Format: ss58Format,
    ),
    _ =>
      throw CoreErrors.addressKeyValidationFailed(
        reason: "Unsupported public key type.",
      ),
  };
}