-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMerkleProof.java
More file actions
72 lines (62 loc) · 1.84 KB
/
MerkleProof.java
File metadata and controls
72 lines (62 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package modules.ads.merkletree;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Objects;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
import model.crypto.Sha3256Hash;
import modules.ads.MembershipProof;
/**
* A proof of membership in a Merkle tree.
*/
public class MerkleProof implements MembershipProof, Serializable {
private ArrayList<Sha3256Hash> path;
private final ArrayList<Boolean> isLeftNode;
private final Sha3256Hash root;
/**
* Constructs a proof from a list of hashes and a root.
*
* @param path the list of hashes
* @param root the root
* @param isLeftNode the list of isLeft Boolean values of the hashes
*/
public MerkleProof(ArrayList<Sha3256Hash> path, Sha3256Hash root, ArrayList<Boolean> isLeftNode) {
this.path = new ArrayList<>(path);
this.root = root;
this.isLeftNode = new ArrayList<>(isLeftNode);
}
@Override
public ArrayList<Sha3256Hash> getPath() {
return new ArrayList<>(path);
}
public void setPath(ArrayList<Sha3256Hash> path) {
this.path = new ArrayList<>(path);
}
@SuppressFBWarnings(value = "EI_EXPOSE_REP", justification = "internal representation is intentionally returned")
public ArrayList<Boolean> getIsLeftNode() {
return isLeftNode;
}
public Sha3256Hash getRoot() {
return root;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
MerkleProof proof = (MerkleProof) o;
for (int i = 0; i < path.size(); i++) {
if (!Arrays.equals(path.get(i).getBytes(), proof.path.get(i).getBytes())) {
return false;
}
}
return root.equals(proof.root);
}
@Override
public int hashCode() {
return Objects.hash(path, root);
}
}