-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Expand file tree
/
Copy pathCredentials.java
More file actions
63 lines (50 loc) · 1.47 KB
/
Credentials.java
File metadata and controls
63 lines (50 loc) · 1.47 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
package org.tron.keystore;
import java.util.Objects;
import org.tron.common.crypto.SignInterface;
import org.tron.common.crypto.sm2.SM2;
import org.tron.common.utils.StringUtil;
/**
* Credentials wrapper.
*/
public class Credentials {
private final SignInterface cryptoEngine;
private final String address;
private Credentials(SignInterface cryptoEngine, String address) {
this.cryptoEngine = cryptoEngine;
this.address = address;
}
public static Credentials create(SignInterface cryptoEngine) {
String address = StringUtil.encode58Check(cryptoEngine.getAddress());
return new Credentials(cryptoEngine, address);
}
public static Credentials create(SM2 sm2Pair) {
String address = StringUtil.encode58Check(sm2Pair.getAddress());
return new Credentials(sm2Pair, address);
}
public SignInterface getSignInterface() {
return cryptoEngine;
}
public String getAddress() {
return address;
}
@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}
Credentials that = (Credentials) o;
if (!Objects.equals(cryptoEngine, that.cryptoEngine)) {
return false;
}
return Objects.equals(address, that.address);
}
@Override
public int hashCode() {
int result = cryptoEngine != null ? cryptoEngine.hashCode() : 0;
result = 31 * result + (address != null ? address.hashCode() : 0);
return result;
}
}