derive method

Bip32KeyPair derive({
  1. Bip32KeyPair? keys,
  2. required int index,
})

BIP-44 path: m / purpose' / coin_type' / account_ix' / change_chain / address_ix

Cardano adoption: Topl adoption: m / 1852' / 7091' / 0' / change_chain --> role / address_ix

+--------------------------------------------------------------------------------+ | BIP-39 Encoded Seed with CRC a.k.a Mnemonic Words | | | | squirrel material silly twice direct ... razor become junk kingdom flee | | | +--------------------------------------------------------------------------------+ | | v +--------------------------+ +-----------------------+ | Wallet Private Key |--->| Wallet Public Key | +--------------------------+ +-----------------------+ | | purpose (e.g. 1852') | v +--------------------------+ | Purpose Private Key | +--------------------------+ | | coin type (e.g. 7091' for Poly) v +--------------------------+ | Coin Type Private Key | +--------------------------+ | | account ix (e.g. 0') v +--------------------------+ +-----------------------+ | Account Private Key |--->| Account Public Key | +--------------------------+ +-----------------------+ | | | chain (e.g. 0=external/payments, | | 1=internal/change, 2=staking) | v v +--------------------------+ +-----------------------+ | Change Private Key |--->| Change Public Key | +--------------------------+ +-----------------------+ | | | address ix (e.g. 0) | v v +--------------------------+ +-----------------------+ | Address Private Key |--->| Address Public Key | +--------------------------+ +-----------------------+

         BIP-44 Wallets Key Hierarchy

Implementation

Bip32KeyPair derive({Bip32KeyPair? keys, required int index}) {
  // computes a child extended private key from the parent extended private key.
  if (keys != null) {
    keys = keys;
  } else {
    keys =
        Bip32KeyPair(privateKey: _rootSigningKey, publicKey: rootVerifyKey);
  }

  final privateKey = keys.privateKey != null
      ? _derivator.ckdPriv(keys.privateKey!, index)
      : null;
  final publicKey = isHardened(index)
      ? null
      : keys.publicKey != null
          ? _derivator.ckdPub(keys.publicKey!, index)
          : _derivator.neuterPriv(privateKey!);
  return Bip32KeyPair(privateKey: privateKey, publicKey: publicKey);
}