address calculated
This commit is contained in:
parent
ec4f0704d6
commit
88d6f7640c
3 changed files with 799 additions and 715 deletions
|
@ -1,76 +1,137 @@
|
||||||
package com.luminiasoft.bitshares;
|
package com.luminiasoft.bitshares;
|
||||||
|
|
||||||
import com.luminiasoft.bitshares.crypto.AndroidRandomSource;
|
import com.luminiasoft.bitshares.crypto.AndroidRandomSource;
|
||||||
import com.luminiasoft.bitshares.crypto.SecureRandomStrengthener;
|
import com.luminiasoft.bitshares.crypto.SecureRandomStrengthener;
|
||||||
import org.bitcoinj.core.ECKey;
|
import org.bitcoinj.core.ECKey;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
import java.io.UnsupportedEncodingException;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.security.SecureRandom;
|
import java.security.SecureRandom;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Base64;
|
import java.util.Base64;
|
||||||
|
import org.bitcoinj.core.Base58;
|
||||||
/**
|
import org.bitcoinj.core.BitcoinSerializer;
|
||||||
* Class used to encapsulate all BrainKey-related operations.
|
import org.bitcoinj.core.Block;
|
||||||
*/
|
import org.bitcoinj.core.Coin;
|
||||||
public class BrainKey {
|
import org.bitcoinj.core.NetworkParameters;
|
||||||
// The size of the word dictionary
|
import org.bitcoinj.core.StoredBlock;
|
||||||
public static final int DICT_WORD_COUNT = 49744;
|
import org.bitcoinj.core.VerificationException;
|
||||||
|
import org.bitcoinj.store.BlockStore;
|
||||||
// The required number of words
|
import org.bitcoinj.store.BlockStoreException;
|
||||||
public static final int BRAINKEY_WORD_COUNT = 12;
|
import org.bitcoinj.utils.MonetaryFormat;
|
||||||
|
import org.spongycastle.crypto.digests.RIPEMD160Digest;
|
||||||
private ECKey mPrivateKey;
|
import org.spongycastle.crypto.digests.SHA512Digest;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method that will generate a random brain key
|
* Class used to encapsulate all BrainKey-related operations.
|
||||||
* @param words The list of words from the graphene specification dictionary.
|
*/
|
||||||
* @return A random sequence of words
|
public class BrainKey {
|
||||||
*/
|
|
||||||
public static String suggest(String words){
|
// The size of the word dictionary
|
||||||
String[] wordArray = words.split(",");
|
public static final int DICT_WORD_COUNT = 49744;
|
||||||
ArrayList<String> suggestedBrainKey = new ArrayList<String>();
|
|
||||||
assert(wordArray.length == DICT_WORD_COUNT);
|
// The required number of words
|
||||||
SecureRandomStrengthener randomStrengthener = SecureRandomStrengthener.getInstance();
|
public static final int BRAINKEY_WORD_COUNT = 12;
|
||||||
randomStrengthener.addEntropySource(new AndroidRandomSource());
|
|
||||||
SecureRandom secureRandom = randomStrengthener.generateAndSeedRandomNumberGenerator();
|
private ECKey mPrivateKey;
|
||||||
int index;
|
|
||||||
for(int i = 0; i < BRAINKEY_WORD_COUNT; i++){
|
/**
|
||||||
index = secureRandom.nextInt(DICT_WORD_COUNT - 1);
|
* Method that will generate a random brain key
|
||||||
suggestedBrainKey.add(wordArray[index].toUpperCase());
|
*
|
||||||
}
|
* @param words The list of words from the graphene specification
|
||||||
String result = String.join(" ", suggestedBrainKey.toArray(new String[suggestedBrainKey.size()]));
|
* dictionary.
|
||||||
System.out.println("result: '"+result+"'");
|
* @return A random sequence of words
|
||||||
return result;
|
*/
|
||||||
}
|
public static String suggest(String words) {
|
||||||
|
String[] wordArray = words.split(",");
|
||||||
/**
|
ArrayList<String> suggestedBrainKey = new ArrayList<String>();
|
||||||
* BrainKey constructor that takes as argument a specific brain key word sequence and generates the
|
assert (wordArray.length == DICT_WORD_COUNT);
|
||||||
* private key and address from that.
|
SecureRandomStrengthener randomStrengthener = SecureRandomStrengthener.getInstance();
|
||||||
* @param words The brain key specifying the private key
|
randomStrengthener.addEntropySource(new AndroidRandomSource());
|
||||||
* @param sequence Sequence number
|
SecureRandom secureRandom = randomStrengthener.generateAndSeedRandomNumberGenerator();
|
||||||
*/
|
int index;
|
||||||
public BrainKey(String words, int sequence) {
|
for (int i = 0; i < BRAINKEY_WORD_COUNT; i++) {
|
||||||
String encoded = String.format("%s %d", words, sequence);
|
index = secureRandom.nextInt(DICT_WORD_COUNT - 1);
|
||||||
try {
|
suggestedBrainKey.add(wordArray[index].toUpperCase());
|
||||||
MessageDigest md = MessageDigest.getInstance("SHA-512");
|
}
|
||||||
byte[] bytes = md.digest(encoded.getBytes("UTF-8"));
|
String result = String.join(" ", suggestedBrainKey.toArray(new String[suggestedBrainKey.size()]));
|
||||||
MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
|
System.out.println("result: '" + result + "'");
|
||||||
byte[] result = sha256.digest(bytes);
|
return result;
|
||||||
mPrivateKey = ECKey.fromPrivate(result);
|
}
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
System.out.println("NoSuchAlgotithmException. Msg: " + e.getMessage());
|
/**
|
||||||
} catch (UnsupportedEncodingException e) {
|
* BrainKey constructor that takes as argument a specific brain key word
|
||||||
System.out.println("UnsupportedEncodingException. Msg: " + e.getMessage());
|
* sequence and generates the private key and address from that.
|
||||||
}
|
*
|
||||||
}
|
* @param words The brain key specifying the private key
|
||||||
|
* @param sequence Sequence number
|
||||||
public String getPublicKey() {
|
*/
|
||||||
return Base64.getEncoder().encodeToString(mPrivateKey.getPubKey());
|
public BrainKey(String words, int sequence) {
|
||||||
}
|
String encoded = String.format("%s %d", words, sequence);
|
||||||
|
try {
|
||||||
public ECKey getPrivateKey(){
|
MessageDigest md = MessageDigest.getInstance("SHA-512");
|
||||||
return mPrivateKey;
|
byte[] bytes = md.digest(encoded.getBytes("UTF-8"));
|
||||||
}
|
MessageDigest sha256 = MessageDigest.getInstance("SHA-256");
|
||||||
}
|
byte[] result = sha256.digest(bytes);
|
||||||
|
mPrivateKey = ECKey.fromPrivate(result);
|
||||||
|
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
System.out.println("NoSuchAlgotithmException. Msg: " + e.getMessage());
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
System.out.println("UnsupportedEncodingException. Msg: " + e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUncompressedAddress() {
|
||||||
|
RIPEMD160Digest ripemd160Digest = new RIPEMD160Digest();
|
||||||
|
SHA512Digest sha512Digest = new SHA512Digest();
|
||||||
|
sha512Digest.update(mPrivateKey.decompress().getPubKey(), 0, mPrivateKey.decompress().getPubKey().length);
|
||||||
|
byte[] intermediate = new byte[512 / 8];
|
||||||
|
sha512Digest.doFinal(intermediate, 0);
|
||||||
|
ripemd160Digest.update(intermediate, 0, intermediate.length);
|
||||||
|
byte[] output = new byte[160 / 8];
|
||||||
|
ripemd160Digest.doFinal(output, 0);
|
||||||
|
String encoded = Base58.encode(output);
|
||||||
|
byte[] checksum = new byte[(160 / 8) + 4];
|
||||||
|
System.arraycopy(calculateChecksum(output), 0, checksum, checksum.length - 4, 4);
|
||||||
|
System.arraycopy(output, 0, checksum, 0, output.length);
|
||||||
|
|
||||||
|
return ("BTS" + Base58.encode(checksum));
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAddress() {
|
||||||
|
RIPEMD160Digest ripemd160Digest = new RIPEMD160Digest();
|
||||||
|
SHA512Digest sha512Digest = new SHA512Digest();
|
||||||
|
sha512Digest.update(mPrivateKey.getPubKey(), 0, mPrivateKey.getPubKey().length);
|
||||||
|
byte[] intermediate = new byte[512 / 8];
|
||||||
|
sha512Digest.doFinal(intermediate, 0);
|
||||||
|
ripemd160Digest.update(intermediate, 0, intermediate.length);
|
||||||
|
byte[] output = new byte[160 / 8];
|
||||||
|
ripemd160Digest.doFinal(output, 0);
|
||||||
|
String encoded = Base58.encode(output);
|
||||||
|
byte[] checksum = new byte[(160 / 8) + 4];
|
||||||
|
System.arraycopy(calculateChecksum(output), 0, checksum, checksum.length - 4, 4);
|
||||||
|
System.arraycopy(output, 0, checksum, 0, output.length);
|
||||||
|
|
||||||
|
return ("BTS" + Base58.encode(checksum));
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] calculateChecksum(byte[] input) {
|
||||||
|
byte[] answer = new byte[4];
|
||||||
|
RIPEMD160Digest ripemd160Digest = new RIPEMD160Digest();
|
||||||
|
ripemd160Digest.update(input, 0, input.length);
|
||||||
|
byte[] output = new byte[160 / 8];
|
||||||
|
ripemd160Digest.doFinal(output, 0);
|
||||||
|
System.arraycopy(output, 0, answer, 0, 4);
|
||||||
|
return answer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] getPublicKey() {
|
||||||
|
return mPrivateKey.getPubKey();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ECKey getPrivateKey() {
|
||||||
|
return mPrivateKey;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,72 +1,73 @@
|
||||||
package com.luminiasoft.bitshares;
|
package com.luminiasoft.bitshares;
|
||||||
|
|
||||||
import org.bitcoinj.core.ECKey;
|
import org.bitcoinj.core.ECKey;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
// Brain key from Nelson's app referencing the bilthon-83 account
|
// Brain key from Nelson's app referencing the bilthon-83 account
|
||||||
public static final String BRAIN_KEY = "PUMPER ISOTOME SERE STAINER CLINGER MOONLIT CHAETA UPBRIM AEDILIC BERTHER NIT SHAP SAID SHADING JUNCOUS CHOUGH";
|
public static final String BRAIN_KEY = "PUMPER ISOTOME SERE STAINER CLINGER MOONLIT CHAETA UPBRIM AEDILIC BERTHER NIT SHAP SAID SHADING JUNCOUS CHOUGH";
|
||||||
|
//public static final String BRAIN_KEY = "TWIXT SERMO TRILLI AUDIO PARDED PLUMET BIWA REHUNG MAUDLE VALVULA OUTBURN FEWNESS ALIENER UNTRACE PRICH TROKER";
|
||||||
public static final String BIP39_KEY = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
|
|
||||||
|
public static final String BIP39_KEY = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about";
|
||||||
// WIF from Nelson's app referencing the bilthon-83 account
|
|
||||||
// public static final String WIF = "5J96pne45qWM1WpektoeazN6k9Mt93jQ7LyueRxFfEMTiy6yxjM";
|
// WIF from Nelson's app referencing the bilthon-83 account
|
||||||
|
// public static final String WIF = "5J96pne45qWM1WpektoeazN6k9Mt93jQ7LyueRxFfEMTiy6yxjM";
|
||||||
// Brain key from an empty account created by the cli_wallet
|
|
||||||
// public static final String BRAIN_KEY = "TWIXT SERMO TRILLI AUDIO PARDED PLUMET BIWA REHUNG MAUDLE VALVULA OUTBURN FEWNESS ALIENER UNTRACE PRICH TROKER";
|
// Brain key from an empty account created by the cli_wallet
|
||||||
|
// public static final String BRAIN_KEY = "TWIXT SERMO TRILLI AUDIO PARDED PLUMET BIWA REHUNG MAUDLE VALVULA OUTBURN FEWNESS ALIENER UNTRACE PRICH TROKER";
|
||||||
// WIF from an emty account created by the cli_wallet
|
|
||||||
public static final String WIF = "5KMzB2GqGhnh7ufhgddmz1eKPHS72uTLeL9hHjSvPb1UywWknF5";
|
// WIF from an emty account created by the cli_wallet
|
||||||
|
public static final String WIF = "5KMzB2GqGhnh7ufhgddmz1eKPHS72uTLeL9hHjSvPb1UywWknF5";
|
||||||
public static final String EXTERNAL_SIGNATURE = "1f36c41acb774fcbc9c231b5895ec9701d6872729098d8ea56d78dda72a6b54252694db85d7591de5751b7aea06871da15d63a1028758421607ffc143e53ef3306";
|
|
||||||
|
public static final String EXTERNAL_SIGNATURE = "1f36c41acb774fcbc9c231b5895ec9701d6872729098d8ea56d78dda72a6b54252694db85d7591de5751b7aea06871da15d63a1028758421607ffc143e53ef3306";
|
||||||
// Static block information used for transaction serialization tests
|
|
||||||
public static int REF_BLOCK_NUM = 56204;
|
// Static block information used for transaction serialization tests
|
||||||
public static int REF_BLOCK_PREFIX = 1614747814;
|
public static int REF_BLOCK_NUM = 56204;
|
||||||
public static int RELATIVE_EXPIRATION = 1478385607;
|
public static int REF_BLOCK_PREFIX = 1614747814;
|
||||||
|
public static int RELATIVE_EXPIRATION = 1478385607;
|
||||||
public static void main(String[] args) {
|
|
||||||
Test test = new Test();
|
public static void main(String[] args) {
|
||||||
// test.testTransactionSerialization();
|
Test test = new Test();
|
||||||
// ECKey.ECDSASignature signature = test.testSigning();
|
// test.testTransactionSerialization();
|
||||||
|
// ECKey.ECDSASignature signature = test.testSigning();
|
||||||
// try {
|
|
||||||
// test.testWebSocketTransfer();
|
// try {
|
||||||
// } catch (IOException e) {
|
// test.testWebSocketTransfer();
|
||||||
// e.printStackTrace();
|
// } catch (IOException e) {
|
||||||
// }
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
// test.testCustomSerializer();
|
|
||||||
|
// test.testCustomSerializer();
|
||||||
// test.testTransactionSerialization();
|
|
||||||
|
// test.testTransactionSerialization();
|
||||||
// test.testLoginSerialization();
|
|
||||||
|
// test.testLoginSerialization();
|
||||||
// test.testNetworkBroadcastSerialization();
|
|
||||||
|
// test.testNetworkBroadcastSerialization();
|
||||||
// test.testNetworkBroadcastDeserialization();
|
|
||||||
|
// test.testNetworkBroadcastDeserialization();
|
||||||
// test.testGetDynamicParams();
|
|
||||||
|
// test.testGetDynamicParams();
|
||||||
// test.testGetRequiredFeesSerialization();
|
|
||||||
|
// test.testGetRequiredFeesSerialization();
|
||||||
// test.testRequiredFeesResponse();
|
|
||||||
|
// test.testRequiredFeesResponse();
|
||||||
// test.testTransactionBroadcastSequence();
|
|
||||||
|
// test.testTransactionBroadcastSequence();
|
||||||
// test.testAccountLookupDeserialization();
|
|
||||||
|
// test.testAccountLookupDeserialization();
|
||||||
// test.testPrivateKeyManipulations();
|
|
||||||
|
// test.testPrivateKeyManipulations();
|
||||||
// test.testGetAccountByName();
|
|
||||||
|
// test.testGetAccountByName();
|
||||||
// test.testGetRequiredFees();
|
|
||||||
|
// test.testGetRequiredFees();
|
||||||
// test.testRandomNumberGeneration();
|
|
||||||
|
// test.testRandomNumberGeneration();
|
||||||
test.testBrainKeyOperations(false);
|
|
||||||
|
test.testBrainKeyOperations(false);
|
||||||
// test.testBip39Opertion();
|
|
||||||
}
|
// test.testBip39Opertion();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue