childKey method
Derives a child key from the current key, based on the provided index.
index: The index used to derive the child key.
Implementation
@override
Bip32Slip10Secp256k1 childKey(Bip32KeyIndex index) {
final isPublic = isPublicOnly;
if (!isPublic) {
if (!index.isHardened && !isPublicDerivationSupported) {
throw Bip32KeyError.notHardenedIndexNotSupported;
}
assert(!isPublicOnly);
final result = keyDerivator.deriveFromSecret(
parent: privateKey,
ctx: publicKey,
index: index,
type: curveType,
);
return Bip32Slip10Secp256k1._(
keyData: Bip32KeyData(
chainCode: result.chainCode,
depth: depth.increase(),
index: index,
fingerPrint: fingerPrint,
),
keyNetVer: keyNetVersions,
privKey: result.key,
pubKey: null,
);
}
// Check if supported
if (!isPublicDerivationSupported) {
throw Bip32KeyError.publicDerivationNotSupported;
}
if (index.isHardened) {
throw Bip32KeyError.publicHardenedIndexNotSupported;
}
final result = keyDerivator.deriveFromPublic(
parent: publicKey,
index: index,
type: curveType,
);
return Bip32Slip10Secp256k1._(
keyData: Bip32KeyData(
chainCode: result.chainCode,
depth: depth.increase(),
index: index,
fingerPrint: fingerPrint,
),
keyNetVer: keyNetVersions,
privKey: null,
pubKey: result.key,
);
}