encodeKeyWithInfo method
Encodes an Ada Byron address with the provided public key and chain code.
The pubKey
parameter is the public key to be encoded.
The optional kwargs
parameter is a map of additional arguments, where "chain_code" can be set to specify the chain code.
Returns a ADAByronAddr representing the encoded Ada Byron address.
Throws an ArgumentException if the provided chain code is invalid.
Implementation
ADAByronAddr encodeKeyWithInfo(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');
}
List<int> chainCodeBytes;
final chainCode = kwargs["chain_code"];
if (chainCode is Bip32ChainCode) {
chainCodeBytes = chainCode.toBytes();
} else if (chainCode is List<int>) {
chainCodeBytes = chainCode;
} else {
throw const AddressConverterException("invalid chaincode ");
}
final pubkeyBytes =
AddrKeyValidator.validateAndGetEd25519Key(pubKey).compressed;
return _AdaByronAddrUtils.encodeKey(
pubkeyBytes, chainCodeBytes, ADAByronAddrTypes.publicKey,
networkMagic: netTag.protocolMagic);
}