decodeAddr method

  1. @override
List<int> decodeAddr(
  1. String addr, {
  2. ErgoNetworkTypes netType = ErgoNetworkTypes.mainnet,
})
override

Decodes an Ergo address into its respective public key bytes.

Implementation

@override
List<int> decodeAddr(
  String addr, {
  ErgoNetworkTypes netType = ErgoNetworkTypes.mainnet,
}) {
  final addrDecBytes = Base58Decoder.decode(addr);
  AddrDecUtils.validateBytesLength(
    addrDecBytes,
    EcdsaKeysConst.pubKeyCompressedByteLen +
        ErgoAddrConst.checksumByteLen +
        1,
  );

  final decode = AddrDecUtils.splitPartsByChecksum(
    addrDecBytes,
    ErgoAddrConst.checksumByteLen,
  );

  /// Extract checksum and public key bytes
  final addrWithPrefix = decode.$1;
  final checksumBytes = decode.$2;

  /// Validate checksum
  AddrDecUtils.validateChecksum(
    addrWithPrefix,
    checksumBytes,
    (pubKeyBytes) => _ErgoAddrUtils.computeChecksum(pubKeyBytes),
  );

  /// Extract public key bytes and remove the prefix
  final pubKeyBytes = AddrDecUtils.validateAndRemovePrefixBytes(
    addrWithPrefix,
    _ErgoAddrUtils.encodePrefix(ErgoAddressTypes.p2pkh, netType),
  );

  return pubKeyBytes;
}