encodeKeyWithInfo method

ADAByronAddr encodeKeyWithInfo(
  1. List<int> pubKey, {
  2. ADANetwork network = ADANetwork.mainnet,
  3. String? path,
  4. List<int>? chainCode,
  5. List<int>? hdPathKey,
})

Encodes an Ada Byron Legacy address with the provided public key, chain code, and optional HD path information.

The pubKey parameter is the public key to be encoded. The optional kwargs parameter is a map of additional arguments, including:

  • "hd_path": A string or Bip32Path specifying the hierarchical deterministic (HD) path.
  • "chain_code": A bytes or Bip32ChainCode representing the chain code.
  • "hd_path_key": An optional bytes for the HD path key (must be 32 bytes).

Returns a ADAByronAddr representing the encoded Ada Byron Legacy address.

Throws an ArgumentException if the provided HD path, chain code, or HD path key is invalid.

Implementation

ADAByronAddr encodeKeyWithInfo(
  List<int> pubKey, {
  ADANetwork network = ADANetwork.mainnet,
  String? path,
  List<int>? chainCode,
  List<int>? hdPathKey,
}) {
  final hdPath = Bip32PathParser.parse(
    AddrKeyValidator.getAddrArg(path, "path"),
  );
  final chainCodeBytes = AddrKeyValidator.getAddrArg(chainCode, "chainCode");
  final hdPathKeyBytes = AddrKeyValidator.getAddrArg(hdPathKey, "hdPathKey");
  if (hdPathKeyBytes.length != QuickCrypto.chacha20Polu1305Keysize) {
    throw AddressConverterException.missingOrInvalidAddressArguments(
      reason:
          "HD path key shall be ${QuickCrypto.chacha20Polu1305Keysize}-byte long",
    );
  }
  final pubKeyBytes =
      AddrKeyValidator.validateAndGetEd25519Key(pubKey).compressed;
  return _AdaByronAddrUtils.encodeKey(
    pubKeyBytes,
    chainCodeBytes,
    ADAByronAddrTypes.publicKey,
    hdPathEncBytes: _AdaByronAddrHdPath.encrypt(hdPath, hdPathKeyBytes),
    networkMagic: network.protocolMagic,
  );
}