childKey method
Derives a child key from the current key, based on the provided index.
This method derives a child key from the current key, either privately or publicly, depending on the input and key type. If the current key is private, it can derive both private and public child keys. If the current key is public, it can only derive public child keys. For Bip32Slip10Ed25519Derivator derivator, it can only derive private child keys.
index
: The index used to derive the child key.
If the current key is private:
- For non-hardened derivation, this method can derive both private and public child keys.
Returns a new key instance representing the derived child key. If public derivation is not supported or if there's an issue with the derivation process, an error is thrown.
Implementation
@override
Bip32Slip10Ed25519 childKey(Bip32KeyIndex index) {
final isPublic = isPublicOnly;
if (!isPublic) {
if (!index.isHardened && !isPublicDerivationSupported) {
throw const Bip32KeyError(
'Private child derivation with not-hardened index is not supported');
}
assert(!isPublicOnly);
final result =
keyDerivator.ckdPriv(privateKey, publicKey, index, curveType);
if (curveType == EllipticCurveTypes.ed25519Blake2b) {
return Bip32Slip10Ed25519Blake2b(
keyData: Bip32KeyData(
chainCode: Bip32ChainCode(result.item2),
depth: depth.increase(),
index: index,
parentFingerPrint: fingerPrint,
),
keyNetVer: keyNetVersions,
privKey: result.item1,
pubKey: null);
}
return Bip32Slip10Ed25519(
keyData: Bip32KeyData(
chainCode: Bip32ChainCode(result.item2),
depth: depth.increase(),
index: index,
parentFingerPrint: fingerPrint,
),
keyNetVer: keyNetVersions,
privKey: result.item1,
pubKey: null);
}
throw const Bip32KeyError('Public child derivation is not supported');
}