encodeKey method

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

Overrides the base class method to encode a public key as a Harmony ONE address using Bech32 encoding.

This method encodes a public key as a Harmony ONE address using Bech32 encoding. It expects an Ethereum address as input, encodes it as an Ethereum address without a '0x' prefix, and then encodes it as a Harmony ONE address using the ONE configuration's Human-Readable Part (HRP). The result is returned as a String representing the Bech32-encoded Harmony ONE address.

Parameters:

  • pubKey: The Ethereum address in the form of a List
  • kwargs: Optional keyword arguments.

Returns: A String representing the Bech32-encoded Harmony ONE address derived from the provided Ethereum address.

Implementation

@override
String encodeKey(List<int> pubKey, [Map<String, dynamic> kwargs = const {}]) {
  /// Encode the Ethereum address without the '0x' prefix.
  final String ethAddr =
      StringUtils.strip0x(EthAddrEncoder().encodeKey(pubKey));

  /// Encode the Ethereum address as a Harmony ONE address using Bech32 encoding.
  return Bech32Encoder.encode(
    CoinsConf.harmonyOne.params.addrHrp!,
    BytesUtils.fromHexString(ethAddr),
  );
}