generateProof method

MerkleProof<T> generateProof(
  1. int leafIndex
)

Generates a Merkle proof for a specific leaf

Implementation

MerkleProof<T> generateProof(int leafIndex) {
  if (root == null || leafIndex < 0 || leafIndex >= leafCount) {
    throw ArgumentError('Invalid leaf index: $leafIndex');
  }

  final proof = <String>[];
  final directions = <bool>[];

  _generateProofRecursive(root!, leafIndex, 0, proof, directions);

  return MerkleProof<T>(
    hashes: proof,
    directions: directions,
    leafIndex: leafIndex,
    totalLeaves: leafCount,
  );
}