Skip to content

Commit

Permalink
Move validation to MerkleTree constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ernestognw committed Mar 4, 2024
1 parent 6ff294d commit a9ae830
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 2 deletions.
1 change: 1 addition & 0 deletions src/merkletree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ export abstract class MerkleTreeImpl<T> implements MerkleTree<T> {
'Leaf values cannot be numbers',
);
this.hashLookup = Object.fromEntries(values.map(({ treeIndex }, valueIndex) => [tree[treeIndex], valueIndex]));
this.validate();
}

protected static prepare<T>(
Expand Down
1 change: 0 additions & 1 deletion src/simple.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export class SimpleMerkleTree extends MerkleTreeImpl<BytesLike> {
);

const tree = new SimpleMerkleTree(data.tree, data.values, formatLeaf, nodeHash);
tree.validate();
return tree;
}

Expand Down
1 change: 0 additions & 1 deletion src/standard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export class StandardMerkleTree<T extends any[]> extends MerkleTreeImpl<T> {
validateArgument(data.leafEncoding !== undefined, 'Expected leaf encoding');

const tree = new StandardMerkleTree(data.tree, data.values, data.leafEncoding);
tree.validate();
return tree;
}

Expand Down

0 comments on commit a9ae830

Please sign in to comment.