Created the Address class
This commit is contained in:
parent
4a4a7b9032
commit
d906d98bad
1 changed files with 39 additions and 0 deletions
39
src/main/java/com/luminiasoft/bitshares/Address.java
Normal file
39
src/main/java/com/luminiasoft/bitshares/Address.java
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
package com.luminiasoft.bitshares;
|
||||||
|
|
||||||
|
import com.google.common.primitives.Bytes;
|
||||||
|
import org.bitcoinj.core.Base58;
|
||||||
|
import org.bitcoinj.core.ECKey;
|
||||||
|
import org.spongycastle.crypto.digests.RIPEMD160Digest;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class used to encapsulate address-related operations.
|
||||||
|
*/
|
||||||
|
public class Address {
|
||||||
|
public final static String DEFAULT_PREFIX = "BTS";
|
||||||
|
|
||||||
|
private ECKey key;
|
||||||
|
private String prefix;
|
||||||
|
|
||||||
|
public Address(ECKey key){
|
||||||
|
this.key = key;
|
||||||
|
this.prefix = DEFAULT_PREFIX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Address(ECKey key, String prefix){
|
||||||
|
this.key = key;
|
||||||
|
this.prefix = prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString(){
|
||||||
|
byte[] pubKey = key.getPubKey();
|
||||||
|
byte[] checksum = new byte[160 / 8];
|
||||||
|
RIPEMD160Digest ripemd160Digest = new RIPEMD160Digest();
|
||||||
|
ripemd160Digest.update(pubKey, 0, pubKey.length);
|
||||||
|
ripemd160Digest.doFinal(checksum, 0);
|
||||||
|
byte[] pubKeyChecksummed = Bytes.concat(pubKey, Arrays.copyOfRange(checksum, 0, 4));
|
||||||
|
return this.prefix + Base58.encode(pubKeyChecksummed);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue