childKey method

  1. @override
Zip32Orchard childKey(
  1. Bip32KeyIndex index,
  2. ZCryptoContext context
)
override

Derives a child key at the given index.

Implementation

@override
Zip32Orchard childKey(Bip32KeyIndex index, ZCryptoContext context) {
  final prvKey = _privateKey;

  if (prvKey == null) {
    throw const Zip32Error('Public child derivation is not supported');
  }
  if (!index.isHardened) {
    throw const Zip32Error(
      'Private child derivation with not-hardened index is not supported',
    );
  }
  final extendedKey = keyDerivator.deriveExtendedKey(
    parent: prvKey,
    parentFvk: publicKey,
    context: context,
    index: index,
  );
  return Zip32Orchard._(
    privateKey: extendedKey.$1,
    publicKey: OrchardExtendedFullViewKey(
      fvk: extendedKey.$2,
      keyData: extendedKey.$1.keyData,
    ),
  );
}