deriveChildNode function
Implementation
NodeWithAddress deriveChildNode({
required BipNode masterNode,
required int chainIndex,
required int index,
required UTXONetworkType networkType,
required Iterable<AddressType> addressTypes,
required HDWalletPurpose? walletPurpose,
}) {
if (index < 0) {
throw UnsupportedError("index must not be negative");
}
if (chainIndex != EXTERNAL_CHAIN_INDEX &&
chainIndex != INTERNAL_CHAIN_INDEX) {
throw UnsupportedError("unexpected chainIndex");
}
final childDerivationPath = "$chainIndex/$index";
final node = masterNode.derivePath(childDerivationPath);
final publicKey = node.publicKey;
final addressMap = {
for (final addressType in addressTypes)
addressType: pubKeyToAddress(publicKey, addressType, networkType),
};
final mainAddress = addressMap[addressTypes.first]!;
return NodeWithAddress.fromChainIndex(
node: node,
address: mainAddress,
chainIndex: chainIndex,
derivationPath: childDerivationPath,
addresses: addressMap,
walletPurpose: walletPurpose,
);
}