OSDN Git Service

merge tx signer
[bytom/bytom-java-sdk.git] / tx-signer / src / main / java / io / bytom / types / Hash.java
1 package io.bytom.types;\r
2 \r
3 import org.bouncycastle.util.encoders.Hex;\r
4 \r
5 import java.util.Objects;\r
6 \r
7 public class Hash {\r
8 \r
9     private String hexValue;\r
10 \r
11     public Hash() {\r
12     }\r
13 \r
14     public Hash(String hexValue) {\r
15         this.hexValue = hexValue;\r
16     }\r
17 \r
18     public Hash(byte[] byteArray) {\r
19         this.hexValue = Hex.toHexString(byteArray);\r
20     }\r
21 \r
22     public byte[] toByteArray() {\r
23         return Hex.decode(this.hexValue);\r
24     }\r
25 \r
26     @Override\r
27     public boolean equals(Object o) {\r
28         if (this == o) return true;\r
29         if (o == null || getClass() != o.getClass()) return false;\r
30         Hash hash = (Hash) o;\r
31         return Objects.equals(hexValue, hash.hexValue);\r
32     }\r
33 \r
34     @Override\r
35     public int hashCode() {\r
36         return Objects.hash(hexValue);\r
37     }\r
38 \r
39     @Override\r
40     public String toString() {\r
41         return this.hexValue;\r
42     }\r
43 }\r