diff --git a/settings.gradle b/settings.gradle index 0c35b70..b36009e 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,3 +1,3 @@ -rootProject.name = 'fullerene' +rootProject.name = 'graphenej' include 'application' diff --git a/src/main/java/com/luminiasoft/bitshares/Memo.java b/src/main/java/com/luminiasoft/bitshares/Memo.java deleted file mode 100644 index 67650b3..0000000 --- a/src/main/java/com/luminiasoft/bitshares/Memo.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.luminiasoft.bitshares; - -import com.luminiasoft.bitshares.interfaces.ByteSerializable; - -/** - * Created by nelson on 11/9/16. - */ -public class Memo implements ByteSerializable { - //TODO: Give this class a proper implementation - - @Override - public byte[] toBytes() { - return new byte[1]; - } -} diff --git a/src/main/java/com/luminiasoft/bitshares/AccountOptions.java b/src/main/java/de/bitsharesmunich/graphenej/AccountOptions.java similarity index 97% rename from src/main/java/com/luminiasoft/bitshares/AccountOptions.java rename to src/main/java/de/bitsharesmunich/graphenej/AccountOptions.java index 972a133..9311c30 100644 --- a/src/main/java/com/luminiasoft/bitshares/AccountOptions.java +++ b/src/main/java/de/bitsharesmunich/graphenej/AccountOptions.java @@ -1,10 +1,10 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; import com.google.common.primitives.Bytes; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.luminiasoft.bitshares.interfaces.GrapheneSerializable; +import de.bitsharesmunich.graphenej.interfaces.GrapheneSerializable; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/com/luminiasoft/bitshares/AccountUpdateOperation.java b/src/main/java/de/bitsharesmunich/graphenej/AccountUpdateOperation.java similarity index 96% rename from src/main/java/com/luminiasoft/bitshares/AccountUpdateOperation.java rename to src/main/java/de/bitsharesmunich/graphenej/AccountUpdateOperation.java index c716e1c..5416f87 100644 --- a/src/main/java/com/luminiasoft/bitshares/AccountUpdateOperation.java +++ b/src/main/java/de/bitsharesmunich/graphenej/AccountUpdateOperation.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; import com.google.common.primitives.Bytes; import com.google.common.primitives.UnsignedLong; @@ -6,8 +6,6 @@ import com.google.gson.Gson; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.sun.istack.internal.NotNull; -import com.sun.istack.internal.Nullable; /** * Class used to encapsulate operations related to the account_update_operation. diff --git a/src/main/java/com/luminiasoft/bitshares/AccountUpdateTransactionBuilder.java b/src/main/java/de/bitsharesmunich/graphenej/AccountUpdateTransactionBuilder.java similarity index 94% rename from src/main/java/com/luminiasoft/bitshares/AccountUpdateTransactionBuilder.java rename to src/main/java/de/bitsharesmunich/graphenej/AccountUpdateTransactionBuilder.java index 435f8a3..2fb6d56 100644 --- a/src/main/java/com/luminiasoft/bitshares/AccountUpdateTransactionBuilder.java +++ b/src/main/java/de/bitsharesmunich/graphenej/AccountUpdateTransactionBuilder.java @@ -1,6 +1,6 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; -import com.luminiasoft.bitshares.errors.MalformedTransactionException; +import de.bitsharesmunich.graphenej.errors.MalformedTransactionException; import org.bitcoinj.core.ECKey; import java.util.ArrayList; diff --git a/src/main/java/com/luminiasoft/bitshares/Address.java b/src/main/java/de/bitsharesmunich/graphenej/Address.java similarity index 91% rename from src/main/java/com/luminiasoft/bitshares/Address.java rename to src/main/java/de/bitsharesmunich/graphenej/Address.java index d363500..b2c9ed0 100644 --- a/src/main/java/com/luminiasoft/bitshares/Address.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Address.java @@ -1,14 +1,12 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; import com.google.common.primitives.Bytes; -import com.luminiasoft.bitshares.errors.MalformedAddressException; +import de.bitsharesmunich.graphenej.errors.MalformedAddressException; import org.bitcoinj.core.Base58; import org.bitcoinj.core.ECKey; import org.spongycastle.crypto.digests.RIPEMD160Digest; -import org.spongycastle.math.ec.ECPoint; import java.util.Arrays; -import java.util.IllegalFormatException; /** * Class used to encapsulate address-related operations. diff --git a/src/main/java/com/luminiasoft/bitshares/Asset.java b/src/main/java/de/bitsharesmunich/graphenej/Asset.java similarity index 79% rename from src/main/java/com/luminiasoft/bitshares/Asset.java rename to src/main/java/de/bitsharesmunich/graphenej/Asset.java index e6a1103..27faf17 100644 --- a/src/main/java/com/luminiasoft/bitshares/Asset.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Asset.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; /** * Created by nelson on 11/9/16. diff --git a/src/main/java/com/luminiasoft/bitshares/AssetAmount.java b/src/main/java/de/bitsharesmunich/graphenej/AssetAmount.java similarity index 94% rename from src/main/java/com/luminiasoft/bitshares/AssetAmount.java rename to src/main/java/de/bitsharesmunich/graphenej/AssetAmount.java index 344c957..c4b49e4 100644 --- a/src/main/java/com/luminiasoft/bitshares/AssetAmount.java +++ b/src/main/java/de/bitsharesmunich/graphenej/AssetAmount.java @@ -1,16 +1,16 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; import com.google.common.primitives.UnsignedLong; import com.google.gson.*; -import com.luminiasoft.bitshares.interfaces.ByteSerializable; -import com.luminiasoft.bitshares.interfaces.JsonSerializable; +import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; +import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; import java.lang.reflect.Type; /** * Created by nelson on 11/7/16. */ -public class AssetAmount implements ByteSerializable, JsonSerializable{ +public class AssetAmount implements ByteSerializable, JsonSerializable { /** * Constants used in the JSON serialization procedure. */ diff --git a/src/main/java/com/luminiasoft/bitshares/Authority.java b/src/main/java/de/bitsharesmunich/graphenej/Authority.java similarity index 96% rename from src/main/java/com/luminiasoft/bitshares/Authority.java rename to src/main/java/de/bitsharesmunich/graphenej/Authority.java index a3637af..8c70e7b 100644 --- a/src/main/java/com/luminiasoft/bitshares/Authority.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Authority.java @@ -1,11 +1,11 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; import com.google.common.primitives.Bytes; import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; -import com.luminiasoft.bitshares.errors.MalformedAddressException; -import com.luminiasoft.bitshares.interfaces.GrapheneSerializable; +import de.bitsharesmunich.graphenej.errors.MalformedAddressException; +import de.bitsharesmunich.graphenej.interfaces.GrapheneSerializable; import java.util.*; diff --git a/src/main/java/com/luminiasoft/bitshares/BIP39.java b/src/main/java/de/bitsharesmunich/graphenej/BIP39.java similarity index 98% rename from src/main/java/com/luminiasoft/bitshares/BIP39.java rename to src/main/java/de/bitsharesmunich/graphenej/BIP39.java index 2b10c83..ecb532d 100644 --- a/src/main/java/com/luminiasoft/bitshares/BIP39.java +++ b/src/main/java/de/bitsharesmunich/graphenej/BIP39.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; import java.util.Arrays; import org.bitcoinj.core.Base58; diff --git a/src/main/java/com/luminiasoft/bitshares/BaseOperation.java b/src/main/java/de/bitsharesmunich/graphenej/BaseOperation.java similarity index 67% rename from src/main/java/com/luminiasoft/bitshares/BaseOperation.java rename to src/main/java/de/bitsharesmunich/graphenej/BaseOperation.java index 89616f2..fdbe9c7 100644 --- a/src/main/java/com/luminiasoft/bitshares/BaseOperation.java +++ b/src/main/java/de/bitsharesmunich/graphenej/BaseOperation.java @@ -1,12 +1,12 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; -import com.luminiasoft.bitshares.interfaces.ByteSerializable; -import com.luminiasoft.bitshares.interfaces.JsonSerializable; +import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; +import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; /** * Created by nelson on 11/5/16. */ -public abstract class BaseOperation implements ByteSerializable, JsonSerializable{ +public abstract class BaseOperation implements ByteSerializable, JsonSerializable { protected OperationType type; diff --git a/src/main/java/com/luminiasoft/bitshares/BlockData.java b/src/main/java/de/bitsharesmunich/graphenej/BlockData.java similarity index 95% rename from src/main/java/com/luminiasoft/bitshares/BlockData.java rename to src/main/java/de/bitsharesmunich/graphenej/BlockData.java index 6a2a340..5ef1b08 100644 --- a/src/main/java/com/luminiasoft/bitshares/BlockData.java +++ b/src/main/java/de/bitsharesmunich/graphenej/BlockData.java @@ -1,10 +1,6 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; -import com.luminiasoft.bitshares.interfaces.ByteSerializable; - -import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.TimeZone; +import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; /** * This class encapsulates all block-related information needed in order to build a valid transaction. diff --git a/src/main/java/com/luminiasoft/bitshares/BrainKey.java b/src/main/java/de/bitsharesmunich/graphenej/BrainKey.java similarity index 94% rename from src/main/java/com/luminiasoft/bitshares/BrainKey.java rename to src/main/java/de/bitsharesmunich/graphenej/BrainKey.java index 79a359e..c8f966a 100644 --- a/src/main/java/com/luminiasoft/bitshares/BrainKey.java +++ b/src/main/java/de/bitsharesmunich/graphenej/BrainKey.java @@ -1,8 +1,7 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; -import com.luminiasoft.bitshares.crypto.AndroidRandomSource; -import com.luminiasoft.bitshares.crypto.SecureRandomStrengthener; -import org.bitcoinj.core.Base58; +import de.bitsharesmunich.graphenej.crypto.AndroidRandomSource; +import de.bitsharesmunich.graphenej.crypto.SecureRandomStrengthener; import org.bitcoinj.core.DumpedPrivateKey; import org.bitcoinj.core.ECKey; import org.bitcoinj.core.NetworkParameters; @@ -11,7 +10,6 @@ import java.io.UnsupportedEncodingException; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; -import java.security.spec.ECPoint; import java.util.ArrayList; /** diff --git a/src/main/java/com/luminiasoft/bitshares/Chains.java b/src/main/java/de/bitsharesmunich/graphenej/Chains.java similarity index 93% rename from src/main/java/com/luminiasoft/bitshares/Chains.java rename to src/main/java/de/bitsharesmunich/graphenej/Chains.java index 31cc615..775bbf2 100644 --- a/src/main/java/com/luminiasoft/bitshares/Chains.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Chains.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; /** * Created by nelson on 11/8/16. diff --git a/src/main/java/com/luminiasoft/bitshares/Extensions.java b/src/main/java/de/bitsharesmunich/graphenej/Extensions.java similarity index 83% rename from src/main/java/com/luminiasoft/bitshares/Extensions.java rename to src/main/java/de/bitsharesmunich/graphenej/Extensions.java index 18c9a6d..1848855 100644 --- a/src/main/java/com/luminiasoft/bitshares/Extensions.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Extensions.java @@ -1,9 +1,9 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; import com.google.gson.JsonArray; import com.google.gson.JsonElement; -import com.luminiasoft.bitshares.interfaces.ByteSerializable; -import com.luminiasoft.bitshares.interfaces.JsonSerializable; +import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; +import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; import java.util.ArrayList; diff --git a/src/main/java/com/luminiasoft/bitshares/FileBin.java b/src/main/java/de/bitsharesmunich/graphenej/FileBin.java similarity index 53% rename from src/main/java/com/luminiasoft/bitshares/FileBin.java rename to src/main/java/de/bitsharesmunich/graphenej/FileBin.java index 797e50e..281a574 100644 --- a/src/main/java/com/luminiasoft/bitshares/FileBin.java +++ b/src/main/java/de/bitsharesmunich/graphenej/FileBin.java @@ -1,24 +1,16 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; import com.google.gson.JsonArray; import com.google.gson.JsonObject; import com.google.gson.JsonParser; -import com.luminiasoft.bitshares.crypto.AndroidRandomSource; -import com.luminiasoft.bitshares.crypto.SecureRandomStrengthener; +import de.bitsharesmunich.graphenej.crypto.SecureRandomStrengthener; import java.io.UnsupportedEncodingException; import java.math.BigInteger; import java.security.MessageDigest; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; -import java.util.Arrays; + import org.bitcoinj.core.ECKey; -import org.spongycastle.crypto.DataLengthException; -import org.spongycastle.crypto.InvalidCipherTextException; -import org.spongycastle.crypto.engines.AESFastEngine; -import org.spongycastle.crypto.modes.CBCBlockCipher; -import org.spongycastle.crypto.paddings.PaddedBufferedBlockCipher; -import org.spongycastle.crypto.params.KeyParameter; -import org.spongycastle.crypto.params.ParametersWithIV; /** * Class to manage the Bin Files @@ -38,25 +30,24 @@ public abstract class FileBin { public static String getBrainkeyFromByte(byte[] input, String password) { try { byte[] publicKey = new byte[33]; - byte[] rawDataEncripted = new byte[input.length-33]; + byte[] rawDataEncripted = new byte[input.length - 33]; System.arraycopy(input, 0, publicKey, 0, publicKey.length); System.arraycopy(input, 33, rawDataEncripted, 0, rawDataEncripted.length); MessageDigest md = MessageDigest.getInstance("SHA-256"); - + ECKey randomECKey = ECKey.fromPublicOnly(publicKey); byte[] finalKey = randomECKey.getPubKeyPoint().multiply(ECKey.fromPrivate(md.digest(password.getBytes("UTF-8"))).getPrivKey()).normalize().getXCoord().getEncoded(); MessageDigest md1 = MessageDigest.getInstance("SHA-512"); finalKey = md1.digest(finalKey); - byte[] rawData = decryptAES(rawDataEncripted, byteToString(finalKey).getBytes()); + byte[] rawData = Util.decryptAES(rawDataEncripted, Util.byteToString(finalKey).getBytes()); byte[] checksum = new byte[4]; System.arraycopy(rawData, 0, checksum, 0, 4); byte[] compressedData = new byte[rawData.length - 4]; System.arraycopy(rawData, 4, compressedData, 0, compressedData.length); - System.out.println("Despues:"+byteToString(compressedData)); byte[] wallet_object_bytes = Util.decompress(compressedData, Util.XZ); String wallet_string = new String(wallet_object_bytes, "UTF-8"); JsonObject wallet = new JsonParser().parse(wallet_string).getAsJsonObject(); @@ -65,21 +56,21 @@ public abstract class FileBin { } else { wallet = wallet.get("wallet").getAsJsonObject(); } - + byte[] encKey_enc = new BigInteger(wallet.get("encryption_key").getAsString(), 16).toByteArray(); byte[] temp = new byte[encKey_enc.length - (encKey_enc[0] == 0 ? 1 : 0)]; System.arraycopy(encKey_enc, (encKey_enc[0] == 0 ? 1 : 0), temp, 0, temp.length); - byte[] encKey = decryptAES(temp, password.getBytes("UTF-8")); + byte[] encKey = Util.decryptAES(temp, password.getBytes("UTF-8")); temp = new byte[encKey.length]; System.arraycopy(encKey, 0, temp, 0, temp.length); byte[] encBrain = new BigInteger(wallet.get("encrypted_brainkey").getAsString(), 16).toByteArray(); - while(encBrain[0] == 0){ - byte[]temp2 = new byte[encBrain.length-1]; + while (encBrain[0] == 0) { + byte[] temp2 = new byte[encBrain.length - 1]; System.arraycopy(encBrain, 1, temp2, 0, temp2.length); encBrain = temp2; } - String BrainKey = new String((decryptAES(encBrain, temp)), "UTF-8"); + String BrainKey = new String((Util.decryptAES(encBrain, temp)), "UTF-8"); return BrainKey; @@ -105,15 +96,15 @@ public abstract class FileBin { //randomStrengthener.addEntropySource(new AndroidRandomSource()); SecureRandom secureRandom = randomStrengthener.generateAndSeedRandomNumberGenerator(); secureRandom.nextBytes(encKey); - byte[] encKey_enc = encryptAES(encKey, password.getBytes("UTF-8")); - byte[] encBrain = encryptAES(BrainKey.getBytes("ASCII"), encKey); + byte[] encKey_enc = Util.encryptAES(encKey, password.getBytes("UTF-8")); + byte[] encBrain = Util.encryptAES(BrainKey.getBytes("ASCII"), encKey); /** * Data to Store */ JsonObject wallet = new JsonObject(); - wallet.add("encryption_key", new JsonParser().parse(byteToString(encKey_enc))); - wallet.add("encrypted_brainkey", new JsonParser().parse(byteToString(encBrain))); + wallet.add("encryption_key", new JsonParser().parse(Util.byteToString(encKey_enc))); + wallet.add("encrypted_brainkey", new JsonParser().parse(Util.byteToString(encBrain))); JsonObject wallet_object = new JsonObject(); wallet_object.add("wallet", wallet); JsonArray accountNames = new JsonArray(); @@ -122,7 +113,6 @@ public abstract class FileBin { accountNames.add(jsonAccountName); wallet_object.add("linked_accounts", accountNames); byte[] compressedData = Util.compress(wallet_object.toString().getBytes("UTF-8"), Util.XZ); - System.out.println("Antes:"+byteToString(compressedData)); MessageDigest md = MessageDigest.getInstance("SHA-256"); byte[] checksum = md.digest(compressedData); byte[] rawData = new byte[compressedData.length + 4]; @@ -135,7 +125,7 @@ public abstract class FileBin { byte[] finalKey = randomECKey.getPubKeyPoint().multiply(ECKey.fromPrivate(md.digest(password.getBytes("UTF-8"))).getPrivKey()).normalize().getXCoord().getEncoded(); MessageDigest md1 = MessageDigest.getInstance("SHA-512"); finalKey = md1.digest(finalKey); - rawData = encryptAES(rawData, byteToString(finalKey).getBytes()); + rawData = Util.encryptAES(rawData, Util.byteToString(finalKey).getBytes()); byte[] result = new byte[rawData.length + randPubKey.length]; System.arraycopy(randPubKey, 0, result, 0, randPubKey.length); @@ -149,80 +139,5 @@ public abstract class FileBin { return null; } - private static byte[] encryptAES(byte[] input, byte[] key) { - try { - MessageDigest md = MessageDigest.getInstance("SHA-512"); - byte[] result = md.digest(key); - byte[] ivBytes = new byte[16]; - System.arraycopy(result, 32, ivBytes, 0, 16); - byte[] sksBytes = new byte[32]; - System.arraycopy(result, 0, sksBytes, 0, 32); - PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine())); - cipher.init(true, new ParametersWithIV(new KeyParameter(sksBytes), ivBytes)); - byte[] temp = new byte[input.length + (16 - (input.length % 16))]; - System.arraycopy(input, 0, temp, 0, input.length); - Arrays.fill(temp, input.length, temp.length, (byte) (16 - (input.length % 16))); - byte[] out = new byte[cipher.getOutputSize(temp.length)]; - int proc = cipher.processBytes(temp, 0, temp.length, out, 0); - cipher.doFinal(out, proc); - temp = new byte[out.length - 16]; - System.arraycopy(out, 0, temp, 0, temp.length); - return temp; - } catch (NoSuchAlgorithmException | DataLengthException | IllegalStateException | InvalidCipherTextException ex) { - } - return null; - } - - private static byte[] decryptAES(byte[] input, byte[] key) { - try { - MessageDigest md = MessageDigest.getInstance("SHA-512"); - byte[] result = md.digest(key); - byte[] ivBytes = new byte[16]; - System.arraycopy(result, 32, ivBytes, 0, 16); - byte[] sksBytes = new byte[32]; - System.arraycopy(result, 0, sksBytes, 0, 32); - PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine())); - cipher.init(false, new ParametersWithIV(new KeyParameter(sksBytes), ivBytes)); - - byte[] pre_out = new byte[cipher.getOutputSize(input.length)]; - int proc = cipher.processBytes(input, 0, input.length, pre_out, 0); - int proc2 = cipher.doFinal(pre_out, proc); - byte[] out = new byte[proc+proc2]; - System.arraycopy(pre_out, 0, out, 0, proc+proc2); - - //Unpadding - byte countByte = (byte)((byte)out[out.length-1] % 16); - int count = countByte & 0xFF; - - if ((count > 15) || (count <= 0)){ - return out; - } - - byte[] temp = new byte[count]; - System.arraycopy(out, out.length - count, temp, 0, temp.length); - byte[] temp2 = new byte[count]; - Arrays.fill(temp2, (byte) count); - if (Arrays.equals(temp, temp2)) { - temp = new byte[out.length - count]; - System.arraycopy(out, 0, temp, 0, out.length - count); - return temp; - } else { - return out; - } - } catch (NoSuchAlgorithmException | DataLengthException | IllegalStateException | InvalidCipherTextException ex) { - ex.printStackTrace(); - } - return null; - } - - public static String byteToString(byte[] input) { - StringBuilder result = new StringBuilder(); - for (byte in : input) { - if ((in & 0xff) < 0x10) { - result.append("0"); - } - result.append(Integer.toHexString(in & 0xff)); - } - return result.toString(); - } + } diff --git a/src/main/java/com/luminiasoft/bitshares/GrapheneObject.java b/src/main/java/de/bitsharesmunich/graphenej/GrapheneObject.java similarity index 95% rename from src/main/java/com/luminiasoft/bitshares/GrapheneObject.java rename to src/main/java/de/bitsharesmunich/graphenej/GrapheneObject.java index ede0e47..a30355b 100644 --- a/src/main/java/com/luminiasoft/bitshares/GrapheneObject.java +++ b/src/main/java/de/bitsharesmunich/graphenej/GrapheneObject.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; diff --git a/src/main/java/com/luminiasoft/bitshares/Invoice.java b/src/main/java/de/bitsharesmunich/graphenej/Invoice.java similarity index 94% rename from src/main/java/com/luminiasoft/bitshares/Invoice.java rename to src/main/java/de/bitsharesmunich/graphenej/Invoice.java index 5f513d4..7109fa3 100644 --- a/src/main/java/com/luminiasoft/bitshares/Invoice.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Invoice.java @@ -1,8 +1,8 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; import com.google.gson.Gson; import com.google.gson.JsonElement; -import com.luminiasoft.bitshares.interfaces.JsonSerializable; +import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; import org.bitcoinj.core.Base58; /** diff --git a/src/main/java/com/luminiasoft/bitshares/Main.java b/src/main/java/de/bitsharesmunich/graphenej/Main.java similarity index 57% rename from src/main/java/com/luminiasoft/bitshares/Main.java rename to src/main/java/de/bitsharesmunich/graphenej/Main.java index 0218171..53a78e7 100644 --- a/src/main/java/com/luminiasoft/bitshares/Main.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Main.java @@ -1,31 +1,18 @@ -package com.luminiasoft.bitshares; - -import org.bitcoinj.core.ECKey; - -import java.io.IOException; +package de.bitsharesmunich.graphenej; public class Main { // Brain key from Nelson's app referencing the bilthon-83 account - public static final String BILTHON_83_BRAIN_KEY = "PUMPER ISOTOME SERE STAINER CLINGER MOONLIT CHAETA UPBRIM AEDILIC BERTHER NIT SHAP SAID SHADING JUNCOUS CHOUGH"; + public static final String BILTHON_83_BRAIN_KEY = System.getenv("BILTHON_83_BRAIN_KEY"); - public static final String BILTHON_5_BRAIN_KEY = "UNMATE AURIGAL NAVET WAVICLE REWOVE ABBOTCY COWHERB OUTKICK STOPPER JUSSORY BEAMLET WIRY"; + public static final String BILTHON_5_BRAIN_KEY = System.getenv("BILTHON_5_BRAIN_KEY"); - public static final String BILTHON_7_BRAIN_KEY = "VENIN QUOTHA OBESELY TORIC OSMATIC SPOKEN DIACOPE CUBICA TABULA REDDING APONIA TARTAR"; + public static final String BILTHON_7_BRAIN_KEY = System.getenv("BILTHON_7_BRAIN_KEY"); - //public static final String BILTHON_83_BRAIN_KEY = "TWIXT SERMO TRILLI AUDIO PARDED PLUMET BIWA REHUNG MAUDLE VALVULA OUTBURN FEWNESS ALIENER UNTRACE PRICH TROKER"; - //public static final String BILTHON_83_BRAIN_KEY = "SIVER TIKKER FOGO HOMINAL PRAYER LUTEIN SMALLY ACARID MEROPIA TRANCE BOGONG IDDAT HICKORY SOUTANE MOOD DOWSER"; 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"; - // Brain key from an empty account created by the cli_wallet -// public static final String BILTHON_83_BRAIN_KEY = "TWIXT SERMO TRILLI AUDIO PARDED PLUMET BIWA REHUNG MAUDLE VALVULA OUTBURN FEWNESS ALIENER UNTRACE PRICH TROKER"; - // WIF from an empty account created by the cli_wallet public static final String WIF = "5KMzB2GqGhnh7ufhgddmz1eKPHS72uTLeL9hHjSvPb1UywWknF5"; - public static final String EXTERNAL_SIGNATURE = "1f36c41acb774fcbc9c231b5895ec9701d6872729098d8ea56d78dda72a6b54252694db85d7591de5751b7aea06871da15d63a1028758421607ffc143e53ef3306"; - // Static block information used for transaction serialization tests public static int REF_BLOCK_NUM = 56204; public static int REF_BLOCK_PREFIX = 1614747814; @@ -33,6 +20,7 @@ public class Main { public static void main(String[] args) { Test test = new Test(); + // test.testTransactionSerialization(); // ECKey.ECDSASignature signature = test.testSigning(); @@ -68,6 +56,8 @@ public class Main { // test.testAccountUpdateOperationBroadcast(); // test.testCreateBinFile(); // test.testImportBinFile(); - test.testLookupAccounts(); + test.testLookupAccounts(); +// test.testLookupAccounts(); +// test.testDecodeMemo(); } } diff --git a/src/main/java/com/luminiasoft/bitshares/OperationType.java b/src/main/java/de/bitsharesmunich/graphenej/OperationType.java similarity index 97% rename from src/main/java/com/luminiasoft/bitshares/OperationType.java rename to src/main/java/de/bitsharesmunich/graphenej/OperationType.java index ae26a48..2f54488 100644 --- a/src/main/java/com/luminiasoft/bitshares/OperationType.java +++ b/src/main/java/de/bitsharesmunich/graphenej/OperationType.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; /** * Created by nelson on 11/6/16. diff --git a/src/main/java/com/luminiasoft/bitshares/Optional.java b/src/main/java/de/bitsharesmunich/graphenej/Optional.java similarity index 86% rename from src/main/java/com/luminiasoft/bitshares/Optional.java rename to src/main/java/de/bitsharesmunich/graphenej/Optional.java index f7cc88f..889b418 100644 --- a/src/main/java/com/luminiasoft/bitshares/Optional.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Optional.java @@ -1,7 +1,7 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; import com.google.gson.JsonElement; -import com.luminiasoft.bitshares.interfaces.GrapheneSerializable; +import de.bitsharesmunich.graphenej.interfaces.GrapheneSerializable; /** * Used whenever we have an optional field. diff --git a/src/main/java/com/luminiasoft/bitshares/PublicKey.java b/src/main/java/de/bitsharesmunich/graphenej/PublicKey.java similarity index 65% rename from src/main/java/com/luminiasoft/bitshares/PublicKey.java rename to src/main/java/de/bitsharesmunich/graphenej/PublicKey.java index 14dd927..163ec3b 100644 --- a/src/main/java/com/luminiasoft/bitshares/PublicKey.java +++ b/src/main/java/de/bitsharesmunich/graphenej/PublicKey.java @@ -1,6 +1,6 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; -import com.luminiasoft.bitshares.interfaces.ByteSerializable; +import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; import org.bitcoinj.core.ECKey; /** @@ -21,4 +21,8 @@ public class PublicKey implements ByteSerializable { public byte[] toBytes() { return publicKey.getPubKey(); } + + public String getAddress(){ + return new Address(publicKey).toString(); + } } diff --git a/src/main/java/com/luminiasoft/bitshares/RPC.java b/src/main/java/de/bitsharesmunich/graphenej/RPC.java similarity index 96% rename from src/main/java/com/luminiasoft/bitshares/RPC.java rename to src/main/java/de/bitsharesmunich/graphenej/RPC.java index f7db64b..2d10295 100644 --- a/src/main/java/com/luminiasoft/bitshares/RPC.java +++ b/src/main/java/de/bitsharesmunich/graphenej/RPC.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; /** * Created by nelson on 11/16/16. diff --git a/src/main/java/com/luminiasoft/bitshares/Test.java b/src/main/java/de/bitsharesmunich/graphenej/Test.java similarity index 74% rename from src/main/java/com/luminiasoft/bitshares/Test.java rename to src/main/java/de/bitsharesmunich/graphenej/Test.java index 286d8fa..2de438b 100644 --- a/src/main/java/com/luminiasoft/bitshares/Test.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Test.java @@ -1,16 +1,23 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; +import de.bitsharesmunich.graphenej.models.ApiCall; +import de.bitsharesmunich.graphenej.models.BaseResponse; +import de.bitsharesmunich.graphenej.objects.Memo; import com.google.common.primitives.UnsignedLong; import com.google.gson.Gson; import com.google.gson.GsonBuilder; +import com.google.gson.JsonArray; +import com.google.gson.JsonElement; import com.google.gson.reflect.TypeToken; -import com.luminiasoft.bitshares.errors.MalformedAddressException; -import com.luminiasoft.bitshares.errors.MalformedTransactionException; -import com.luminiasoft.bitshares.interfaces.WitnessResponseListener; -import com.luminiasoft.bitshares.models.*; -import com.luminiasoft.bitshares.test.NaiveSSLContext; -import com.luminiasoft.bitshares.ws.*; +import de.bitsharesmunich.graphenej.errors.MalformedAddressException; +import de.bitsharesmunich.graphenej.errors.MalformedTransactionException; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.objects.MemoBuilder; +import de.bitsharesmunich.graphenej.test.NaiveSSLContext; import com.neovisionaries.ws.client.*; +import de.bitsharesmunich.graphenej.models.AccountProperties; +import de.bitsharesmunich.graphenej.models.WitnessResponse; +import de.bitsharesmunich.graphenej.api.*; import org.bitcoinj.core.*; import org.spongycastle.crypto.digests.RIPEMD160Digest; @@ -27,9 +34,10 @@ import java.util.logging.Logger; */ public class Test { - public static final String WITNESS_URL = "ws://api.devling.xyz:8088"; - public static final String OPENLEDGER_WITNESS_URL = "wss://bitshares.openledger.info/ws"; -// public static final String WITNESS_URL = "wss://fr.blockpay.ch:8089"; + public static final String WITNESS_URL = "api://api.devling.xyz:8088"; + public static final String OPENLEDGER_WITNESS_URL = "wss://bitshares.openledger.info/api"; + public static final String BLOCK_PAY_DE = "wss://de.blockpay.ch:8089"; + public static final String BLOCK_PAY_FR = "wss://fr.blockpay.ch:8089"; private Transaction transaction; @@ -45,7 +53,9 @@ public class Test { if (response.result.getClass() == AccountProperties.class) { AccountProperties accountProperties = (AccountProperties) response.result; System.out.println("Got account properties"); + System.out.println("account: " + accountProperties.toString()); System.out.println("id: " + accountProperties.id); + } else if (response.result.getClass() == ArrayList.class) { List list = (List) response.result; if (list.size() > 0) { @@ -93,6 +103,8 @@ public class Test { } else { System.out.println("Got empty list!"); } + } else if (response.result.getClass() == JsonArray.class) { + System.out.println("Json array : " + ((JsonArray) response.result)); } else { System.out.println("Got other: " + response.result.getClass()); } @@ -286,13 +298,19 @@ public class Test { }; try { + // Creating memo + PublicKey from = new PublicKey(new BrainKey(Main.BILTHON_83_BRAIN_KEY, 0).getPrivateKey()); + PublicKey to = new PublicKey(ECKey.fromPublicOnly(new BrainKey(Main.BILTHON_5_BRAIN_KEY, 0).getPublicKey())); + Memo memo = new MemoBuilder().setFromKey(from).setToKey(to).setMessage("sample message").build(); + + // Creating transaction Transaction transaction = new TransferTransactionBuilder() - .setSource(new UserAccount("1.2.138632")) - .setDestination(new UserAccount("1.2.129848")) - .setAmount(new AssetAmount(UnsignedLong.valueOf(100), new Asset("1.3.120"))) + .setSource(new UserAccount("1.2.139270")) // bilthon-83 + .setDestination(new UserAccount("1.2.142115")) // bilthon-5 + .setAmount(new AssetAmount(UnsignedLong.valueOf(1), new Asset("1.3.0"))) .setFee(new AssetAmount(UnsignedLong.valueOf(264174), new Asset("1.3.0"))) - .setBlockData(new BlockData(43408, 1430521623, 1479231969)) - .setPrivateKey(DumpedPrivateKey.fromBase58(null, Main.BILTHON_5_BRAIN_KEY).getKey()) + .setPrivateKey(new BrainKey(Main.BILTHON_83_BRAIN_KEY, 0).getPrivateKey()) + .setMemo(memo) .build(); ArrayList transactionList = new ArrayList<>(); @@ -305,7 +323,7 @@ public class Test { // Set the custom SSL context. factory.setSSLContext(context); - WebSocket mWebSocket = factory.createSocket(OPENLEDGER_WITNESS_URL); + WebSocket mWebSocket = factory.createSocket(BLOCK_PAY_DE); mWebSocket.addListener(new TransactionBroadcastSequence(transaction, new Asset("1.3.0"), listener)); mWebSocket.connect(); @@ -344,7 +362,7 @@ public class Test { System.out.println("base58...................: " + Base58.encode(privateKey.getPubKey())); } - public void testPublicKeyManipulations(){ + public void testPublicKeyManipulations() { // PublicKey publicKey = new PublicKey("BTS8RiFgs8HkcVPVobHLKEv6yL3iXcC9SWjbPVS15dDAXLG9GYhnY"); // System.out.println("Public key bytes"); // System.out.println(Util.bytesToHex(publicKey.toBytes())); @@ -414,17 +432,17 @@ public class Test { String suggestion = BrainKey.suggest(words); brainKey = new BrainKey(suggestion, 0); } else { - System.out.println("Using brain key: "+Main.BILTHON_5_BRAIN_KEY); + System.out.println("Using brain key: " + Main.BILTHON_5_BRAIN_KEY); // brainKey = new BrainKey(Main.BILTHON_83_BRAIN_KEY, 0); brainKey = new BrainKey("CYNEBOT LUFBERY DAUNTER TOO SALOOP HOPOFF DIAULOS REV AES TORPOR RECTRIX DEVILRY", 0); } ECKey key = brainKey.getPrivateKey(); - System.out.println("Private key..................: "+Util.bytesToHex(key.getSecretBytes())); + System.out.println("Private key..................: " + Util.bytesToHex(key.getSecretBytes())); String wif = key.getPrivateKeyAsWiF(NetworkParameters.fromID(NetworkParameters.ID_MAINNET)); System.out.println("Wif Compressed...............: " + wif); String wif2 = key.decompress().getPrivateKeyAsWiF(NetworkParameters.fromID(NetworkParameters.ID_MAINNET)); System.out.println("Wif Decompressed.............: " + wif2); - System.out.println("Wif from BrainKey............: "+ brainKey.getWalletImportFormat()); + System.out.println("Wif from BrainKey............: " + brainKey.getWalletImportFormat()); byte[] uncompressedPubKey = key.decompress().getPubKey(); byte[] compressedPubKey = key.getPubKey(); @@ -564,9 +582,10 @@ public class Test { } public void testImportBinFile() { - byte inputBytes[] = new byte[] {(byte)2, (byte)175, (byte)24, (byte)227, (byte)182, (byte)11, (byte)113, (byte)151, (byte)112, (byte)157, (byte)137, (byte)157, (byte)244, (byte)237, (byte)228, (byte)92, (byte)34, (byte)138, (byte)171, (byte)248, (byte)24, (byte)161, (byte)171, (byte)75, (byte)2, (byte)183, (byte)47, (byte)213, (byte)50, (byte)109, (byte)220, (byte)6, (byte)124, (byte)108, (byte)32, (byte)164, (byte)204, (byte)234, (byte)10, (byte)12, (byte)154, (byte)225, (byte)11, (byte)178, (byte)238, (byte)9, (byte)122, (byte)244, (byte)175, (byte)185, (byte)143, (byte)27, (byte)134, (byte)192, (byte)37, (byte)239, (byte)148, (byte)253, (byte)124, (byte)68, (byte)6, (byte)211, (byte)20, (byte)224, (byte)50, (byte)31, (byte)208, (byte)87, (byte)115, (byte)115, (byte)11, (byte)81, (byte)182, (byte)223, (byte)230, (byte)102, (byte)230, (byte)245, (byte)182, (byte)77, (byte)157, (byte)182, (byte)79, (byte)247, (byte)134, (byte)178, (byte)87, (byte)93, (byte)146, (byte)89, (byte)167, (byte)191, (byte)34, (byte)17, (byte)117, (byte)173, (byte)59, (byte)142, (byte)54, (byte)120, (byte)237, (byte)124, (byte)217, (byte)252, (byte)112, (byte)97, (byte)153, (byte)124, (byte)144, (byte)80, (byte)33, (byte)130, (byte)15, (byte)18, (byte)157, (byte)98, (byte)130, (byte)80, (byte)206, (byte)27, (byte)8, (byte)142, (byte)245, (byte)22, (byte)244, (byte)219, (byte)38, (byte)228, (byte)173, (byte)147, (byte)42, (byte)100, (byte)99, (byte)108, (byte)146, (byte)110, (byte)100, (byte)215, (byte)183, (byte)20, (byte)112, (byte)93, (byte)195, (byte)12, (byte)174, (byte)130, (byte)35, (byte)71, (byte)172, (byte)237, (byte)112, (byte)197, (byte)250, (byte)67, (byte)36, (byte)185, (byte)117, (byte)211, (byte)147, (byte)21, (byte)251, (byte)214, (byte)178, (byte)152, (byte)25, (byte)107, (byte)206, (byte)184, (byte)113, (byte)67, (byte)169, (byte)55, (byte)95, (byte)249, (byte)193, (byte)215, (byte)20, (byte)124, (byte)62, (byte)179, (byte)125, (byte)2, (byte)96, (byte)46, (byte)137, (byte)133, (byte)46, (byte)37, (byte)138, (byte)19, (byte)215, (byte)2, (byte)189, (byte)91, (byte)61, (byte)119, (byte)150, (byte)6, (byte)188, (byte)220, (byte)232, (byte)12, (byte)108, (byte)128, (byte)92, (byte)172, (byte)119, (byte)138, (byte)215, (byte)90, (byte)8, (byte)56, (byte)126, (byte)145, (byte)133, (byte)193, (byte)47, (byte)147, (byte)106, (byte)219, (byte)58, (byte)227, (byte)20, (byte)60, (byte)147, (byte)38, (byte)218, (byte)17, (byte)130, (byte)196, (byte)134, (byte)105, (byte)94, (byte)235, (byte)26, (byte)245, (byte)119, (byte)153, (byte)11, (byte)29, (byte)33, (byte)230, (byte)151, (byte)149, (byte)63, (byte)91, (byte)170, (byte)75, (byte)43, (byte)223, (byte)192, (byte)104, (byte)161, (byte)58, (byte)135, (byte)226, (byte)175, (byte)171, (byte)202, (byte)113, (byte)142, (byte)40, (byte)139, (byte)240, (byte)10, (byte)54, (byte)213, (byte)55, (byte)235, (byte)175, (byte)211, (byte)193, (byte)151, (byte)43, (byte)233, (byte)81, (byte)250, (byte)245, (byte)120, (byte)211, (byte)107, (byte)73, (byte)75, (byte)74, (byte)98, (byte)10, (byte)208, (byte)68, (byte)185, (byte)183, (byte)251, (byte)193, (byte)65, (byte)125, (byte)65, (byte)52, (byte)154, (byte)115, (byte)118, (byte)217, (byte)254, (byte)140, (byte)116, (byte)124, (byte)158, (byte)70, (byte)94, (byte)28, (byte)132, (byte)231, (byte)142, (byte)209, (byte)163, (byte)182, (byte)227, (byte)129, (byte)243, (byte)130, (byte)28, (byte)238, (byte)35, (byte)235, (byte)120, (byte)199, (byte)26, (byte)209, (byte)58, (byte)181, (byte)124, (byte)44, (byte)38, (byte)132, (byte)54, (byte)168, (byte)31, (byte)150, (byte)191, (byte)140, (byte)101, (byte)141, (byte)104, (byte)74, (byte)29, (byte)76, (byte)254, (byte)67, (byte)43, (byte)123, (byte)67, (byte)208, (byte)132, (byte)61, (byte)36, (byte)167, (byte)195, (byte)231, (byte)234, (byte)136, (byte)55, (byte)97, (byte)205, (byte)242, (byte)182, (byte)237, (byte)179, (byte)13, (byte)24, (byte)249, (byte)53, (byte)151, (byte)66, (byte)252, (byte)254, (byte)173, (byte)91, (byte)52, (byte)70, (byte)239, (byte)235, (byte)94, (byte)18, (byte)115, (byte)143, (byte)134, (byte)206, (byte)244, (byte)77, (byte)247, (byte)201, (byte)61, (byte)115, (byte)78, (byte)186, (byte)199, (byte)89, (byte)144, (byte)69, (byte)231, (byte)174, (byte)2, (byte)167, (byte)157, (byte)148, (byte)88, (byte)150, (byte)171, (byte)50, (byte)82, (byte)230, (byte)211, (byte)14, (byte)55, (byte)165, (byte)103, (byte)67, (byte)172, (byte)148, (byte)252, (byte)10, (byte)104, (byte)24, (byte)179, (byte)152, (byte)156, (byte)169, (byte)228, (byte)123, (byte)205, (byte)247, (byte)10, (byte)127, (byte)106, (byte)100, (byte)10, (byte)187, (byte)81, (byte)0, (byte)55, (byte)177, (byte)60, (byte)139, (byte)41, (byte)62, (byte)163, (byte)83, (byte)242, (byte)1, (byte)122, (byte)247, (byte)181, (byte)102, (byte)218, (byte)205, (byte)70, (byte)235, (byte)147, (byte)195, (byte)107, (byte)248, (byte)139, (byte)169, (byte)203, (byte)174, (byte)22, (byte)126, (byte)65, (byte)123, (byte)14, (byte)33, (byte)131, (byte)49, (byte)6, (byte)187, (byte)156, (byte)50, (byte)92, (byte)145, (byte)74, (byte)90, (byte)132, (byte)151, (byte)105, (byte)187, (byte)195, (byte)56, (byte)45, (byte)134, (byte)204, (byte)7, (byte)130, (byte)153, (byte)209, (byte)87, (byte)231, (byte)78, (byte)90, (byte)168, (byte)93, (byte)200, (byte)149, (byte)204, (byte)128, (byte)85, (byte)17, (byte)17, (byte)219, (byte)161, (byte)167, (byte)73, (byte)218, (byte)116, (byte)233, (byte)202, (byte)19, (byte)110, (byte)95, (byte)115, (byte)233, (byte)137, (byte)85, (byte)112, (byte)70, (byte)226, (byte)217, (byte)126, (byte)70, (byte)214, (byte)47, (byte)133, (byte)129, (byte)78, (byte)127, (byte)81, (byte)192, (byte)48, (byte)91, (byte)224, (byte)124, (byte)13, (byte)176, (byte)131, (byte)53, (byte)192, (byte)92, (byte)113, (byte)235, (byte)86, (byte)38, (byte)178, (byte)133, (byte)204, (byte)110, (byte)195, (byte)230, (byte)140, (byte)213, (byte)208, (byte)188, (byte)185, (byte)37, (byte)103, (byte)177, (byte)181, (byte)120, (byte)78, (byte)192, (byte)30, (byte)224, (byte)250, (byte)2, (byte)66, (byte)76, (byte)162, (byte)87, (byte)8, (byte)131, (byte)54, (byte)247, (byte)91, (byte)9, (byte)236, (byte)18, (byte)53, (byte)11, (byte)141, (byte)144, (byte)193, (byte)139, (byte)168, (byte)170, (byte)223, (byte)190, (byte)90, (byte)23, (byte)29, (byte)177, (byte)79, (byte)38, (byte)232, (byte)148, (byte)80, (byte)211, (byte)207, (byte)201, (byte)129, (byte)2, (byte)228, (byte)86, (byte)144, (byte)32, (byte)27, (byte)235, (byte)105, (byte)136, (byte)217, (byte)195, (byte)234, (byte)243, (byte)198, (byte)87, (byte)186, (byte)31, (byte)21, (byte)144, (byte)200, (byte)27, (byte)34, (byte)82, (byte)220, (byte)37, (byte)67, (byte)44, (byte)140, (byte)233, (byte)144, (byte)218, (byte)185, (byte)46, (byte)151, (byte)96, (byte)91}; - //BigInteger b = new BigInteger(new String(inputBytes),16); + byte inputBytes[] = new byte[]{(byte) 2, (byte) 175, (byte) 24, (byte) 227, (byte) 182, (byte) 11, (byte) 113, (byte) 151, (byte) 112, (byte) 157, (byte) 137, (byte) 157, (byte) 244, (byte) 237, (byte) 228, (byte) 92, (byte) 34, (byte) 138, (byte) 171, (byte) 248, (byte) 24, (byte) 161, (byte) 171, (byte) 75, (byte) 2, (byte) 183, (byte) 47, (byte) 213, (byte) 50, (byte) 109, (byte) 220, (byte) 6, (byte) 124, (byte) 108, (byte) 32, (byte) 164, (byte) 204, (byte) 234, (byte) 10, (byte) 12, (byte) 154, (byte) 225, (byte) 11, (byte) 178, (byte) 238, (byte) 9, (byte) 122, (byte) 244, (byte) 175, (byte) 185, (byte) 143, (byte) 27, (byte) 134, (byte) 192, (byte) 37, (byte) 239, (byte) 148, (byte) 253, (byte) 124, (byte) 68, (byte) 6, (byte) 211, (byte) 20, (byte) 224, (byte) 50, (byte) 31, (byte) 208, (byte) 87, (byte) 115, (byte) 115, (byte) 11, (byte) 81, (byte) 182, (byte) 223, (byte) 230, (byte) 102, (byte) 230, (byte) 245, (byte) 182, (byte) 77, (byte) 157, (byte) 182, (byte) 79, (byte) 247, (byte) 134, (byte) 178, (byte) 87, (byte) 93, (byte) 146, (byte) 89, (byte) 167, (byte) 191, (byte) 34, (byte) 17, (byte) 117, (byte) 173, (byte) 59, (byte) 142, (byte) 54, (byte) 120, (byte) 237, (byte) 124, (byte) 217, (byte) 252, (byte) 112, (byte) 97, (byte) 153, (byte) 124, (byte) 144, (byte) 80, (byte) 33, (byte) 130, (byte) 15, (byte) 18, (byte) 157, (byte) 98, (byte) 130, (byte) 80, (byte) 206, (byte) 27, (byte) 8, (byte) 142, (byte) 245, (byte) 22, (byte) 244, (byte) 219, (byte) 38, (byte) 228, (byte) 173, (byte) 147, (byte) 42, (byte) 100, (byte) 99, (byte) 108, (byte) 146, (byte) 110, (byte) 100, (byte) 215, (byte) 183, (byte) 20, (byte) 112, (byte) 93, (byte) 195, (byte) 12, (byte) 174, (byte) 130, (byte) 35, (byte) 71, (byte) 172, (byte) 237, (byte) 112, (byte) 197, (byte) 250, (byte) 67, (byte) 36, (byte) 185, (byte) 117, (byte) 211, (byte) 147, (byte) 21, (byte) 251, (byte) 214, (byte) 178, (byte) 152, (byte) 25, (byte) 107, (byte) 206, (byte) 184, (byte) 113, (byte) 67, (byte) 169, (byte) 55, (byte) 95, (byte) 249, (byte) 193, (byte) 215, (byte) 20, (byte) 124, (byte) 62, (byte) 179, (byte) 125, (byte) 2, (byte) 96, (byte) 46, (byte) 137, (byte) 133, (byte) 46, (byte) 37, (byte) 138, (byte) 19, (byte) 215, (byte) 2, (byte) 189, (byte) 91, (byte) 61, (byte) 119, (byte) 150, (byte) 6, (byte) 188, (byte) 220, (byte) 232, (byte) 12, (byte) 108, (byte) 128, (byte) 92, (byte) 172, (byte) 119, (byte) 138, (byte) 215, (byte) 90, (byte) 8, (byte) 56, (byte) 126, (byte) 145, (byte) 133, (byte) 193, (byte) 47, (byte) 147, (byte) 106, (byte) 219, (byte) 58, (byte) 227, (byte) 20, (byte) 60, (byte) 147, (byte) 38, (byte) 218, (byte) 17, (byte) 130, (byte) 196, (byte) 134, (byte) 105, (byte) 94, (byte) 235, (byte) 26, (byte) 245, (byte) 119, (byte) 153, (byte) 11, (byte) 29, (byte) 33, (byte) 230, (byte) 151, (byte) 149, (byte) 63, (byte) 91, (byte) 170, (byte) 75, (byte) 43, (byte) 223, (byte) 192, (byte) 104, (byte) 161, (byte) 58, (byte) 135, (byte) 226, (byte) 175, (byte) 171, (byte) 202, (byte) 113, (byte) 142, (byte) 40, (byte) 139, (byte) 240, (byte) 10, (byte) 54, (byte) 213, (byte) 55, (byte) 235, (byte) 175, (byte) 211, (byte) 193, (byte) 151, (byte) 43, (byte) 233, (byte) 81, (byte) 250, (byte) 245, (byte) 120, (byte) 211, (byte) 107, (byte) 73, (byte) 75, (byte) 74, (byte) 98, (byte) 10, (byte) 208, (byte) 68, (byte) 185, (byte) 183, (byte) 251, (byte) 193, (byte) 65, (byte) 125, (byte) 65, (byte) 52, (byte) 154, (byte) 115, (byte) 118, (byte) 217, (byte) 254, (byte) 140, (byte) 116, (byte) 124, (byte) 158, (byte) 70, (byte) 94, (byte) 28, (byte) 132, (byte) 231, (byte) 142, (byte) 209, (byte) 163, (byte) 182, (byte) 227, (byte) 129, (byte) 243, (byte) 130, (byte) 28, (byte) 238, (byte) 35, (byte) 235, (byte) 120, (byte) 199, (byte) 26, (byte) 209, (byte) 58, (byte) 181, (byte) 124, (byte) 44, (byte) 38, (byte) 132, (byte) 54, (byte) 168, (byte) 31, (byte) 150, (byte) 191, (byte) 140, (byte) 101, (byte) 141, (byte) 104, (byte) 74, (byte) 29, (byte) 76, (byte) 254, (byte) 67, (byte) 43, (byte) 123, (byte) 67, (byte) 208, (byte) 132, (byte) 61, (byte) 36, (byte) 167, (byte) 195, (byte) 231, (byte) 234, (byte) 136, (byte) 55, (byte) 97, (byte) 205, (byte) 242, (byte) 182, (byte) 237, (byte) 179, (byte) 13, (byte) 24, (byte) 249, (byte) 53, (byte) 151, (byte) 66, (byte) 252, (byte) 254, (byte) 173, (byte) 91, (byte) 52, (byte) 70, (byte) 239, (byte) 235, (byte) 94, (byte) 18, (byte) 115, (byte) 143, (byte) 134, (byte) 206, (byte) 244, (byte) 77, (byte) 247, (byte) 201, (byte) 61, (byte) 115, (byte) 78, (byte) 186, (byte) 199, (byte) 89, (byte) 144, (byte) 69, (byte) 231, (byte) 174, (byte) 2, (byte) 167, (byte) 157, (byte) 148, (byte) 88, (byte) 150, (byte) 171, (byte) 50, (byte) 82, (byte) 230, (byte) 211, (byte) 14, (byte) 55, (byte) 165, (byte) 103, (byte) 67, (byte) 172, (byte) 148, (byte) 252, (byte) 10, (byte) 104, (byte) 24, (byte) 179, (byte) 152, (byte) 156, (byte) 169, (byte) 228, (byte) 123, (byte) 205, (byte) 247, (byte) 10, (byte) 127, (byte) 106, (byte) 100, (byte) 10, (byte) 187, (byte) 81, (byte) 0, (byte) 55, (byte) 177, (byte) 60, (byte) 139, (byte) 41, (byte) 62, (byte) 163, (byte) 83, (byte) 242, (byte) 1, (byte) 122, (byte) 247, (byte) 181, (byte) 102, (byte) 218, (byte) 205, (byte) 70, (byte) 235, (byte) 147, (byte) 195, (byte) 107, (byte) 248, (byte) 139, (byte) 169, (byte) 203, (byte) 174, (byte) 22, (byte) 126, (byte) 65, (byte) 123, (byte) 14, (byte) 33, (byte) 131, (byte) 49, (byte) 6, (byte) 187, (byte) 156, (byte) 50, (byte) 92, (byte) 145, (byte) 74, (byte) 90, (byte) 132, (byte) 151, (byte) 105, (byte) 187, (byte) 195, (byte) 56, (byte) 45, (byte) 134, (byte) 204, (byte) 7, (byte) 130, (byte) 153, (byte) 209, (byte) 87, (byte) 231, (byte) 78, (byte) 90, (byte) 168, (byte) 93, (byte) 200, (byte) 149, (byte) 204, (byte) 128, (byte) 85, (byte) 17, (byte) 17, (byte) 219, (byte) 161, (byte) 167, (byte) 73, (byte) 218, (byte) 116, (byte) 233, (byte) 202, (byte) 19, (byte) 110, (byte) 95, (byte) 115, (byte) 233, (byte) 137, (byte) 85, (byte) 112, (byte) 70, (byte) 226, (byte) 217, (byte) 126, (byte) 70, (byte) 214, (byte) 47, (byte) 133, (byte) 129, (byte) 78, (byte) 127, (byte) 81, (byte) 192, (byte) 48, (byte) 91, (byte) 224, (byte) 124, (byte) 13, (byte) 176, (byte) 131, (byte) 53, (byte) 192, (byte) 92, (byte) 113, (byte) 235, (byte) 86, (byte) 38, (byte) 178, (byte) 133, (byte) 204, (byte) 110, (byte) 195, (byte) 230, (byte) 140, (byte) 213, (byte) 208, (byte) 188, (byte) 185, (byte) 37, (byte) 103, (byte) 177, (byte) 181, (byte) 120, (byte) 78, (byte) 192, (byte) 30, (byte) 224, (byte) 250, (byte) 2, (byte) 66, (byte) 76, (byte) 162, (byte) 87, (byte) 8, (byte) 131, (byte) 54, (byte) 247, (byte) 91, (byte) 9, (byte) 236, (byte) 18, (byte) 53, (byte) 11, (byte) 141, (byte) 144, (byte) 193, (byte) 139, (byte) 168, (byte) 170, (byte) 223, (byte) 190, (byte) 90, (byte) 23, (byte) 29, (byte) 177, (byte) 79, (byte) 38, (byte) 232, (byte) 148, (byte) 80, (byte) 211, (byte) 207, (byte) 201, (byte) 129, (byte) 2, (byte) 228, (byte) 86, (byte) 144, (byte) 32, (byte) 27, (byte) 235, (byte) 105, (byte) 136, (byte) 217, (byte) 195, (byte) 234, (byte) 243, (byte) 198, (byte) 87, (byte) 186, (byte) 31, (byte) 21, (byte) 144, (byte) 200, (byte) 27, (byte) 34, (byte) 82, (byte) 220, (byte) 37, (byte) 67, (byte) 44, (byte) 140, (byte) 233, (byte) 144, (byte) 218, (byte) 185, (byte) 46, (byte) 151, (byte) 96, (byte) 91}; + System.out.println(FileBin.getBrainkeyFromByte(inputBytes, "123456")); + } public void testAccountUpdateSerialization() { @@ -590,14 +609,14 @@ public class Test { System.out.println(transaction.toJsonString()); System.out.println("Serialized transaction"); System.out.println(Util.bytesToHex(transaction.toBytes())); - } catch(MalformedAddressException e){ - System.out.println("MalformedAddressException. Msg: "+e.getMessage()); + } catch (MalformedAddressException e) { + System.out.println("MalformedAddressException. Msg: " + e.getMessage()); } catch (MalformedTransactionException e) { - System.out.println("MalformedTransactionException. Msg: "+e.getMessage()); + System.out.println("MalformedTransactionException. Msg: " + e.getMessage()); } } - public void testAccountUpdateOperationBroadcast(){ + public void testAccountUpdateOperationBroadcast() { WitnessResponseListener listener = new WitnessResponseListener() { @Override @@ -639,19 +658,19 @@ public class Test { mWebSocket.connect(); } catch (MalformedAddressException e) { - System.out.println("MalformedAddressException. Msg: "+e.getMessage()); + System.out.println("MalformedAddressException. Msg: " + e.getMessage()); } catch (MalformedTransactionException e) { - System.out.println("MalformedTransactionException. Msg: "+e.getMessage()); + System.out.println("MalformedTransactionException. Msg: " + e.getMessage()); } catch (NoSuchAlgorithmException e) { - System.out.println("NoSuchAlgorithmException. Msg: "+e.getMessage()); + System.out.println("NoSuchAlgorithmException. Msg: " + e.getMessage()); } catch (IOException e) { - System.out.println("IOException. Msg: "+e.getMessage()); + System.out.println("IOException. Msg: " + e.getMessage()); } catch (WebSocketException e) { - System.out.println("WebSocketException. Msg: "+e.getMessage()); + System.out.println("WebSocketException. Msg: " + e.getMessage()); } } - public void testLookupAccounts(){ + public void testLookupAccounts() { WitnessResponseListener listener = new WitnessResponseListener() { @Override public void onSuccess(WitnessResponse response) { @@ -672,17 +691,29 @@ public class Test { // Set the custom SSL context. factory.setSSLContext(context); - WebSocket mWebSocket = factory.createSocket(OPENLEDGER_WITNESS_URL); + WebSocket mWebSocket = factory.createSocket(BLOCK_PAY_DE); mWebSocket.addListener(new LookupAccounts("bilthon", listener)); mWebSocket.connect(); } catch (NoSuchAlgorithmException e) { - System.out.println("NoSuchAlgorithmException. Msg: "+e.getMessage()); + System.out.println("NoSuchAlgorithmException. Msg: " + e.getMessage()); } catch (WebSocketException e) { - System.out.println("WebSocketException. Msg: "+e.getMessage()); + System.out.println("WebSocketException. Msg: " + e.getMessage()); } catch (IOException e) { - System.out.println("IOException. Msg: "+e.getMessage()); + System.out.println("IOException. Msg: " + e.getMessage()); } } + + public void testDecodeMemo() { + + PublicKey from = new PublicKey((new BrainKey(Main.BILTHON_83_BRAIN_KEY, 0).getPrivateKey())); + PublicKey to = new PublicKey(new BrainKey(Main.BILTHON_5_BRAIN_KEY, 0).getPrivateKey()); + + Memo sendMemo = new MemoBuilder().setFromKey(from).setToKey(to).setMessage("test message").build(); + + JsonElement memoJson = sendMemo.toJsonObject(); + System.out.println("generated Json : " + memoJson.toString()); + System.out.println("Decode Memo : " + Memo.decodeMessage(from, to, memoJson.getAsJsonObject().get("message").getAsString(), memoJson.getAsJsonObject().get("nonce").getAsString())); + } } diff --git a/src/main/java/com/luminiasoft/bitshares/Transaction.java b/src/main/java/de/bitsharesmunich/graphenej/Transaction.java similarity index 97% rename from src/main/java/com/luminiasoft/bitshares/Transaction.java rename to src/main/java/de/bitsharesmunich/graphenej/Transaction.java index 29a4620..244247c 100644 --- a/src/main/java/com/luminiasoft/bitshares/Transaction.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Transaction.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; import com.google.common.primitives.Bytes; import com.google.gson.GsonBuilder; @@ -7,9 +7,8 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -import com.luminiasoft.bitshares.errors.MalformedTransactionException; -import com.luminiasoft.bitshares.interfaces.ByteSerializable; -import com.luminiasoft.bitshares.interfaces.JsonSerializable; +import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; +import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; import org.bitcoinj.core.DumpedPrivateKey; import org.bitcoinj.core.ECKey; diff --git a/src/main/java/com/luminiasoft/bitshares/TransactionBuilder.java b/src/main/java/de/bitsharesmunich/graphenej/TransactionBuilder.java similarity index 82% rename from src/main/java/com/luminiasoft/bitshares/TransactionBuilder.java rename to src/main/java/de/bitsharesmunich/graphenej/TransactionBuilder.java index 068a23c..fecf99e 100644 --- a/src/main/java/com/luminiasoft/bitshares/TransactionBuilder.java +++ b/src/main/java/de/bitsharesmunich/graphenej/TransactionBuilder.java @@ -1,6 +1,6 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; -import com.luminiasoft.bitshares.errors.MalformedTransactionException; +import de.bitsharesmunich.graphenej.errors.MalformedTransactionException; import org.bitcoinj.core.ECKey; diff --git a/src/main/java/com/luminiasoft/bitshares/TransferOperation.java b/src/main/java/de/bitsharesmunich/graphenej/TransferOperation.java similarity index 95% rename from src/main/java/com/luminiasoft/bitshares/TransferOperation.java rename to src/main/java/de/bitsharesmunich/graphenej/TransferOperation.java index 4f12f70..f0d8d5b 100644 --- a/src/main/java/com/luminiasoft/bitshares/TransferOperation.java +++ b/src/main/java/de/bitsharesmunich/graphenej/TransferOperation.java @@ -1,5 +1,6 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; +import de.bitsharesmunich.graphenej.objects.Memo; import com.google.common.primitives.Bytes; import com.google.gson.*; @@ -15,6 +16,7 @@ public class TransferOperation extends BaseOperation { public static final String KEY_EXTENSIONS = "extensions"; public static final String KEY_FROM = "from"; public static final String KEY_TO = "to"; + public static final String KEY_MEMO = "memo"; private AssetAmount fee; private AssetAmount amount; @@ -85,14 +87,19 @@ public class TransferOperation extends BaseOperation { array.add(this.getId()); JsonObject jsonObject = new JsonObject(); jsonObject.add(KEY_FEE, fee.toJsonObject()); - jsonObject.add(KEY_AMOUNT, amount.toJsonObject()); - jsonObject.add(KEY_EXTENSIONS, new JsonArray()); jsonObject.addProperty(KEY_FROM, from.toJsonString()); jsonObject.addProperty(KEY_TO, to.toJsonString()); + jsonObject.add(KEY_AMOUNT, amount.toJsonObject()); + jsonObject.add(KEY_MEMO, memo.toJsonObject()); + jsonObject.add(KEY_EXTENSIONS, new JsonArray()); array.add(jsonObject); return array; } + public void setMemo(Memo memo) { + this.memo = memo; + } + public static class TransferSerializer implements JsonSerializer { @Override diff --git a/src/main/java/com/luminiasoft/bitshares/TransferTransactionBuilder.java b/src/main/java/de/bitsharesmunich/graphenej/TransferTransactionBuilder.java similarity index 88% rename from src/main/java/com/luminiasoft/bitshares/TransferTransactionBuilder.java rename to src/main/java/de/bitsharesmunich/graphenej/TransferTransactionBuilder.java index c3ada97..88ba4c4 100644 --- a/src/main/java/com/luminiasoft/bitshares/TransferTransactionBuilder.java +++ b/src/main/java/de/bitsharesmunich/graphenej/TransferTransactionBuilder.java @@ -1,6 +1,7 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; -import com.luminiasoft.bitshares.errors.MalformedTransactionException; +import de.bitsharesmunich.graphenej.objects.Memo; +import de.bitsharesmunich.graphenej.errors.MalformedTransactionException; import org.bitcoinj.core.ECKey; import java.util.ArrayList; @@ -15,6 +16,7 @@ public class TransferTransactionBuilder extends TransactionBuilder { private UserAccount destinationAccount; private AssetAmount transferAmount; private AssetAmount feeAmount; + private Memo memo; public TransferTransactionBuilder(){} @@ -51,6 +53,11 @@ public class TransferTransactionBuilder extends TransactionBuilder { this.feeAmount = amount; return this; } + + public TransferTransactionBuilder setMemo(Memo memo){ + this.memo = memo; + return this; + } //TODO: Add support for multiple transfer operations in a single transaction public TransferTransactionBuilder addOperation(TransferOperation transferOperation){ @@ -84,6 +91,9 @@ public class TransferTransactionBuilder extends TransactionBuilder { }else{ transferOperation = new TransferOperation(sourceAccount, destinationAccount, transferAmount, feeAmount); } + if(memo != null){ + transferOperation.setMemo(this.memo); + } operations.add(transferOperation); } return new Transaction(privateKey, blockData, operations); diff --git a/src/main/java/com/luminiasoft/bitshares/UserAccount.java b/src/main/java/de/bitsharesmunich/graphenej/UserAccount.java similarity index 94% rename from src/main/java/com/luminiasoft/bitshares/UserAccount.java rename to src/main/java/de/bitsharesmunich/graphenej/UserAccount.java index 8ed3743..3689de4 100644 --- a/src/main/java/com/luminiasoft/bitshares/UserAccount.java +++ b/src/main/java/de/bitsharesmunich/graphenej/UserAccount.java @@ -1,8 +1,8 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; import com.google.gson.*; -import com.luminiasoft.bitshares.interfaces.ByteSerializable; -import com.luminiasoft.bitshares.interfaces.JsonSerializable; +import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; +import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; import java.io.ByteArrayOutputStream; import java.io.DataOutput; diff --git a/src/main/java/com/luminiasoft/bitshares/Util.java b/src/main/java/de/bitsharesmunich/graphenej/Util.java similarity index 53% rename from src/main/java/com/luminiasoft/bitshares/Util.java rename to src/main/java/de/bitsharesmunich/graphenej/Util.java index 5925ef4..1df7493 100644 --- a/src/main/java/com/luminiasoft/bitshares/Util.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Util.java @@ -1,20 +1,28 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; import org.tukaani.xz.FinishableOutputStream; -import com.google.common.primitives.Bytes; import org.tukaani.xz.LZMA2Options; import org.tukaani.xz.LZMAInputStream; import org.tukaani.xz.LZMAOutputStream; import org.tukaani.xz.XZInputStream; import org.tukaani.xz.XZOutputStream; - import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.Arrays; import java.util.logging.Level; import java.util.logging.Logger; +import org.spongycastle.crypto.DataLengthException; +import org.spongycastle.crypto.InvalidCipherTextException; +import org.spongycastle.crypto.engines.AESFastEngine; +import org.spongycastle.crypto.modes.CBCBlockCipher; +import org.spongycastle.crypto.paddings.PaddedBufferedBlockCipher; +import org.spongycastle.crypto.params.KeyParameter; +import org.spongycastle.crypto.params.ParametersWithIV; /** * Class used to encapsulate common utility methods @@ -142,7 +150,101 @@ public class Util { * @param input A Long value * @return The array of bytes that represent this value in the reverse format. */ - public static byte[] revertLong(Long input){ + public static byte[] revertLong(Long input) { return ByteBuffer.allocate(Long.SIZE / 8).putLong(Long.reverseBytes(input)).array(); } + + /** + * Function to encrypt a message with AES + * @param input data to encrypt + * @param key key for encryption + * @return AES Encription of input + */ + public static byte[] encryptAES(byte[] input, byte[] key) { + try { + MessageDigest md = MessageDigest.getInstance("SHA-512"); + byte[] result = md.digest(key); + byte[] ivBytes = new byte[16]; + System.arraycopy(result, 32, ivBytes, 0, 16); + byte[] sksBytes = new byte[32]; + System.arraycopy(result, 0, sksBytes, 0, 32); + PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine())); + cipher.init(true, new ParametersWithIV(new KeyParameter(sksBytes), ivBytes)); + byte[] temp = new byte[input.length + (16 - (input.length % 16))]; + System.arraycopy(input, 0, temp, 0, input.length); + Arrays.fill(temp, input.length, temp.length, (byte) (16 - (input.length % 16))); + byte[] out = new byte[cipher.getOutputSize(temp.length)]; + int proc = cipher.processBytes(temp, 0, temp.length, out, 0); + cipher.doFinal(out, proc); + temp = new byte[out.length - 16]; + System.arraycopy(out, 0, temp, 0, temp.length); + return temp; + } catch (NoSuchAlgorithmException | DataLengthException | IllegalStateException | InvalidCipherTextException ex) { + } + return null; + } + + /** + * Function to decrypt a message with AES encryption + * @param input data to decrypt + * @param key key for decryption + * @return input decrypted with AES. Null if the decrypt failed (Bad Key) + */ + public static byte[] decryptAES(byte[] input, byte[] key) { + try { + MessageDigest md = MessageDigest.getInstance("SHA-512"); + byte[] result = md.digest(key); + byte[] ivBytes = new byte[16]; + System.arraycopy(result, 32, ivBytes, 0, 16); + byte[] sksBytes = new byte[32]; + System.arraycopy(result, 0, sksBytes, 0, 32); + PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new AESFastEngine())); + cipher.init(false, new ParametersWithIV(new KeyParameter(sksBytes), ivBytes)); + + byte[] pre_out = new byte[cipher.getOutputSize(input.length)]; + int proc = cipher.processBytes(input, 0, input.length, pre_out, 0); + int proc2 = cipher.doFinal(pre_out, proc); + byte[] out = new byte[proc+proc2]; + System.arraycopy(pre_out, 0, out, 0, proc+proc2); + + //Unpadding + byte countByte = (byte)((byte)out[out.length-1] % 16); + int count = countByte & 0xFF; + + if ((count > 15) || (count <= 0)){ + return out; + } + + byte[] temp = new byte[count]; + System.arraycopy(out, out.length - count, temp, 0, temp.length); + byte[] temp2 = new byte[count]; + Arrays.fill(temp2, (byte) count); + if (Arrays.equals(temp, temp2)) { + temp = new byte[out.length - count]; + System.arraycopy(out, 0, temp, 0, out.length - count); + return temp; + } else { + return out; + } + } catch (NoSuchAlgorithmException | DataLengthException | IllegalStateException | InvalidCipherTextException ex) { + ex.printStackTrace(); + } + return null; + } + + /** + * Transform an array of bytes to an hex String representation + * @param input array of bytes to transform as a string + * @return Input as a String + */ + public static String byteToString(byte[] input) { + StringBuilder result = new StringBuilder(); + for (byte in : input) { + if ((in & 0xff) < 0x10) { + result.append("0"); + } + result.append(Integer.toHexString(in & 0xff)); + } + return result.toString(); + } } diff --git a/src/main/java/com/luminiasoft/bitshares/Varint.java b/src/main/java/de/bitsharesmunich/graphenej/Varint.java similarity index 99% rename from src/main/java/com/luminiasoft/bitshares/Varint.java rename to src/main/java/de/bitsharesmunich/graphenej/Varint.java index 1b37689..c06e05a 100644 --- a/src/main/java/com/luminiasoft/bitshares/Varint.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Varint.java @@ -15,7 +15,7 @@ * limitations under the License. */ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; import java.io.DataInput; diff --git a/src/main/java/com/luminiasoft/bitshares/Vote.java b/src/main/java/de/bitsharesmunich/graphenej/Vote.java similarity index 87% rename from src/main/java/com/luminiasoft/bitshares/Vote.java rename to src/main/java/de/bitsharesmunich/graphenej/Vote.java index d8f674f..7c50a90 100644 --- a/src/main/java/com/luminiasoft/bitshares/Vote.java +++ b/src/main/java/de/bitsharesmunich/graphenej/Vote.java @@ -1,6 +1,6 @@ -package com.luminiasoft.bitshares; +package de.bitsharesmunich.graphenej; -import com.luminiasoft.bitshares.interfaces.ByteSerializable; +import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; /** * Created by nelson on 12/5/16. diff --git a/src/main/java/com/luminiasoft/bitshares/ws/GetAccountByName.java b/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountByName.java similarity index 85% rename from src/main/java/com/luminiasoft/bitshares/ws/GetAccountByName.java rename to src/main/java/de/bitsharesmunich/graphenej/api/GetAccountByName.java index fc84df6..3dc1780 100644 --- a/src/main/java/com/luminiasoft/bitshares/ws/GetAccountByName.java +++ b/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountByName.java @@ -1,13 +1,13 @@ -package com.luminiasoft.bitshares.ws; +package de.bitsharesmunich.graphenej.api; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; -import com.luminiasoft.bitshares.RPC; -import com.luminiasoft.bitshares.interfaces.WitnessResponseListener; -import com.luminiasoft.bitshares.models.AccountProperties; -import com.luminiasoft.bitshares.models.ApiCall; -import com.luminiasoft.bitshares.models.BaseResponse; -import com.luminiasoft.bitshares.models.WitnessResponse; +import de.bitsharesmunich.graphenej.RPC; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.models.AccountProperties; +import de.bitsharesmunich.graphenej.models.ApiCall; +import de.bitsharesmunich.graphenej.models.BaseResponse; +import de.bitsharesmunich.graphenej.models.WitnessResponse; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketAdapter; import com.neovisionaries.ws.client.WebSocketException; diff --git a/src/main/java/com/luminiasoft/bitshares/ws/GetAccountNameById.java b/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountNameById.java similarity index 87% rename from src/main/java/com/luminiasoft/bitshares/ws/GetAccountNameById.java rename to src/main/java/de/bitsharesmunich/graphenej/api/GetAccountNameById.java index d2994a6..e7f465a 100644 --- a/src/main/java/com/luminiasoft/bitshares/ws/GetAccountNameById.java +++ b/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountNameById.java @@ -1,20 +1,21 @@ -package com.luminiasoft.bitshares.ws; +package de.bitsharesmunich.graphenej.api; import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.google.gson.reflect.TypeToken; -import com.luminiasoft.bitshares.RPC; -import com.luminiasoft.bitshares.interfaces.JsonSerializable; -import com.luminiasoft.bitshares.interfaces.WitnessResponseListener; -import com.luminiasoft.bitshares.models.AccountProperties; -import com.luminiasoft.bitshares.models.ApiCall; -import com.luminiasoft.bitshares.models.BaseResponse; -import com.luminiasoft.bitshares.models.WitnessResponse; +import de.bitsharesmunich.graphenej.RPC; +import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.models.AccountProperties; +import de.bitsharesmunich.graphenej.models.BaseResponse; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketAdapter; import com.neovisionaries.ws.client.WebSocketException; import com.neovisionaries.ws.client.WebSocketFrame; +import de.bitsharesmunich.graphenej.models.ApiCall; +import de.bitsharesmunich.graphenej.models.WitnessResponse; + import java.io.Serializable; import java.lang.reflect.Type; import java.util.ArrayList; diff --git a/src/main/java/com/luminiasoft/bitshares/ws/GetAccountsByAddress.java b/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountsByAddress.java similarity index 86% rename from src/main/java/com/luminiasoft/bitshares/ws/GetAccountsByAddress.java rename to src/main/java/de/bitsharesmunich/graphenej/api/GetAccountsByAddress.java index 0b0be52..b3c716c 100644 --- a/src/main/java/com/luminiasoft/bitshares/ws/GetAccountsByAddress.java +++ b/src/main/java/de/bitsharesmunich/graphenej/api/GetAccountsByAddress.java @@ -1,17 +1,16 @@ -package com.luminiasoft.bitshares.ws; +package de.bitsharesmunich.graphenej.api; import com.google.gson.Gson; import com.google.gson.JsonElement; import com.google.gson.JsonParser; import com.google.gson.reflect.TypeToken; -import com.luminiasoft.bitshares.Address; -import com.luminiasoft.bitshares.RPC; -import com.luminiasoft.bitshares.interfaces.JsonSerializable; -import com.luminiasoft.bitshares.interfaces.WitnessResponseListener; -import com.luminiasoft.bitshares.models.AccountProperties; -import com.luminiasoft.bitshares.models.ApiCall; -import com.luminiasoft.bitshares.models.BaseResponse; -import com.luminiasoft.bitshares.models.WitnessResponse; +import de.bitsharesmunich.graphenej.Address; +import de.bitsharesmunich.graphenej.RPC; +import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.models.ApiCall; +import de.bitsharesmunich.graphenej.models.BaseResponse; +import de.bitsharesmunich.graphenej.models.WitnessResponse; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketAdapter; import com.neovisionaries.ws.client.WebSocketException; diff --git a/src/main/java/com/luminiasoft/bitshares/ws/GetRelativeAccountHistory.java b/src/main/java/de/bitsharesmunich/graphenej/api/GetRelativeAccountHistory.java similarity index 91% rename from src/main/java/com/luminiasoft/bitshares/ws/GetRelativeAccountHistory.java rename to src/main/java/de/bitsharesmunich/graphenej/api/GetRelativeAccountHistory.java index d32806e..c2f0cb6 100644 --- a/src/main/java/com/luminiasoft/bitshares/ws/GetRelativeAccountHistory.java +++ b/src/main/java/de/bitsharesmunich/graphenej/api/GetRelativeAccountHistory.java @@ -1,17 +1,17 @@ -package com.luminiasoft.bitshares.ws; +package de.bitsharesmunich.graphenej.api; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import com.luminiasoft.bitshares.AssetAmount; -import com.luminiasoft.bitshares.RPC; -import com.luminiasoft.bitshares.TransferOperation; -import com.luminiasoft.bitshares.UserAccount; -import com.luminiasoft.bitshares.interfaces.WitnessResponseListener; -import com.luminiasoft.bitshares.models.ApiCall; -import com.luminiasoft.bitshares.models.BaseResponse; -import com.luminiasoft.bitshares.models.HistoricalTransfer; -import com.luminiasoft.bitshares.models.WitnessResponse; +import de.bitsharesmunich.graphenej.AssetAmount; +import de.bitsharesmunich.graphenej.RPC; +import de.bitsharesmunich.graphenej.TransferOperation; +import de.bitsharesmunich.graphenej.UserAccount; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.models.ApiCall; +import de.bitsharesmunich.graphenej.models.BaseResponse; +import de.bitsharesmunich.graphenej.models.HistoricalTransfer; +import de.bitsharesmunich.graphenej.models.WitnessResponse; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketAdapter; import com.neovisionaries.ws.client.WebSocketException; diff --git a/src/main/java/com/luminiasoft/bitshares/ws/GetRequiredFees.java b/src/main/java/de/bitsharesmunich/graphenej/api/GetRequiredFees.java similarity index 84% rename from src/main/java/com/luminiasoft/bitshares/ws/GetRequiredFees.java rename to src/main/java/de/bitsharesmunich/graphenej/api/GetRequiredFees.java index c4920f5..dfc9118 100644 --- a/src/main/java/com/luminiasoft/bitshares/ws/GetRequiredFees.java +++ b/src/main/java/de/bitsharesmunich/graphenej/api/GetRequiredFees.java @@ -1,20 +1,20 @@ -package com.luminiasoft.bitshares.ws; +package de.bitsharesmunich.graphenej.api; import com.google.gson.Gson; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import com.luminiasoft.bitshares.Asset; -import com.luminiasoft.bitshares.AssetAmount; -import com.luminiasoft.bitshares.BaseOperation; -import com.luminiasoft.bitshares.RPC; -import com.luminiasoft.bitshares.interfaces.WitnessResponseListener; -import com.luminiasoft.bitshares.models.ApiCall; -import com.luminiasoft.bitshares.models.BaseResponse; -import com.luminiasoft.bitshares.models.WitnessResponse; +import de.bitsharesmunich.graphenej.AssetAmount; +import de.bitsharesmunich.graphenej.RPC; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.models.ApiCall; +import de.bitsharesmunich.graphenej.models.BaseResponse; +import de.bitsharesmunich.graphenej.models.WitnessResponse; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketAdapter; import com.neovisionaries.ws.client.WebSocketException; import com.neovisionaries.ws.client.WebSocketFrame; +import de.bitsharesmunich.graphenej.Asset; +import de.bitsharesmunich.graphenej.BaseOperation; import java.io.Serializable; import java.lang.reflect.Type; diff --git a/src/main/java/com/luminiasoft/bitshares/ws/LookupAccounts.java b/src/main/java/de/bitsharesmunich/graphenej/api/LookupAccounts.java similarity index 89% rename from src/main/java/com/luminiasoft/bitshares/ws/LookupAccounts.java rename to src/main/java/de/bitsharesmunich/graphenej/api/LookupAccounts.java index e6e44d7..37274bd 100644 --- a/src/main/java/com/luminiasoft/bitshares/ws/LookupAccounts.java +++ b/src/main/java/de/bitsharesmunich/graphenej/api/LookupAccounts.java @@ -1,13 +1,13 @@ -package com.luminiasoft.bitshares.ws; +package de.bitsharesmunich.graphenej.api; import com.google.gson.GsonBuilder; import com.google.gson.reflect.TypeToken; -import com.luminiasoft.bitshares.RPC; -import com.luminiasoft.bitshares.UserAccount; -import com.luminiasoft.bitshares.interfaces.WitnessResponseListener; -import com.luminiasoft.bitshares.models.ApiCall; -import com.luminiasoft.bitshares.models.BaseResponse; -import com.luminiasoft.bitshares.models.WitnessResponse; +import de.bitsharesmunich.graphenej.RPC; +import de.bitsharesmunich.graphenej.UserAccount; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.models.ApiCall; +import de.bitsharesmunich.graphenej.models.BaseResponse; +import de.bitsharesmunich.graphenej.models.WitnessResponse; import com.neovisionaries.ws.client.WebSocket; import com.neovisionaries.ws.client.WebSocketAdapter; import com.neovisionaries.ws.client.WebSocketException; diff --git a/src/main/java/com/luminiasoft/bitshares/ws/TransactionBroadcastSequence.java b/src/main/java/de/bitsharesmunich/graphenej/api/TransactionBroadcastSequence.java similarity index 95% rename from src/main/java/com/luminiasoft/bitshares/ws/TransactionBroadcastSequence.java rename to src/main/java/de/bitsharesmunich/graphenej/api/TransactionBroadcastSequence.java index 386693b..c92137a 100644 --- a/src/main/java/com/luminiasoft/bitshares/ws/TransactionBroadcastSequence.java +++ b/src/main/java/de/bitsharesmunich/graphenej/api/TransactionBroadcastSequence.java @@ -1,23 +1,22 @@ -package com.luminiasoft.bitshares.ws; - -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; -import com.luminiasoft.bitshares.*; -import com.luminiasoft.bitshares.interfaces.WitnessResponseListener; -import com.luminiasoft.bitshares.models.ApiCall; -import com.luminiasoft.bitshares.models.BaseResponse; -import com.luminiasoft.bitshares.models.DynamicGlobalProperties; -import com.luminiasoft.bitshares.models.WitnessResponse; -import com.neovisionaries.ws.client.WebSocket; -import com.neovisionaries.ws.client.WebSocketAdapter; -import com.neovisionaries.ws.client.WebSocketException; -import com.neovisionaries.ws.client.WebSocketFrame; +package de.bitsharesmunich.graphenej.api; import java.io.Serializable; import java.lang.reflect.Type; import java.text.SimpleDateFormat; import java.util.*; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; +import de.bitsharesmunich.graphenej.*; +import de.bitsharesmunich.graphenej.interfaces.WitnessResponseListener; +import de.bitsharesmunich.graphenej.models.ApiCall; +import de.bitsharesmunich.graphenej.models.BaseResponse; +import de.bitsharesmunich.graphenej.models.DynamicGlobalProperties; +import de.bitsharesmunich.graphenej.models.WitnessResponse; +import com.neovisionaries.ws.client.WebSocket; +import com.neovisionaries.ws.client.WebSocketAdapter; +import com.neovisionaries.ws.client.WebSocketException; +import com.neovisionaries.ws.client.WebSocketFrame; /** * Class that will handle the transaction publication procedure. diff --git a/src/main/java/com/luminiasoft/bitshares/brainkeydict.txt b/src/main/java/de/bitsharesmunich/graphenej/brainkeydict.txt similarity index 100% rename from src/main/java/com/luminiasoft/bitshares/brainkeydict.txt rename to src/main/java/de/bitsharesmunich/graphenej/brainkeydict.txt diff --git a/src/main/java/com/luminiasoft/bitshares/crypto/AndroidRandomSource.java b/src/main/java/de/bitsharesmunich/graphenej/crypto/AndroidRandomSource.java similarity index 98% rename from src/main/java/com/luminiasoft/bitshares/crypto/AndroidRandomSource.java rename to src/main/java/de/bitsharesmunich/graphenej/crypto/AndroidRandomSource.java index 700af6d..0e3863b 100644 --- a/src/main/java/com/luminiasoft/bitshares/crypto/AndroidRandomSource.java +++ b/src/main/java/de/bitsharesmunich/graphenej/crypto/AndroidRandomSource.java @@ -32,7 +32,7 @@ * fitness for a particular purpose and non-infringement. */ -package com.luminiasoft.bitshares.crypto; +package de.bitsharesmunich.graphenej.crypto; import java.io.DataInputStream; import java.io.File; diff --git a/src/main/java/com/luminiasoft/bitshares/crypto/EntropySource.java b/src/main/java/de/bitsharesmunich/graphenej/crypto/EntropySource.java similarity index 92% rename from src/main/java/com/luminiasoft/bitshares/crypto/EntropySource.java rename to src/main/java/de/bitsharesmunich/graphenej/crypto/EntropySource.java index bb16c03..6c07b43 100644 --- a/src/main/java/com/luminiasoft/bitshares/crypto/EntropySource.java +++ b/src/main/java/de/bitsharesmunich/graphenej/crypto/EntropySource.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares.crypto; +package de.bitsharesmunich.graphenej.crypto; import java.nio.ByteBuffer; diff --git a/src/main/java/com/luminiasoft/bitshares/crypto/RandomSource.java b/src/main/java/de/bitsharesmunich/graphenej/crypto/RandomSource.java similarity index 94% rename from src/main/java/com/luminiasoft/bitshares/crypto/RandomSource.java rename to src/main/java/de/bitsharesmunich/graphenej/crypto/RandomSource.java index 91e38d6..aaf4940 100644 --- a/src/main/java/com/luminiasoft/bitshares/crypto/RandomSource.java +++ b/src/main/java/de/bitsharesmunich/graphenej/crypto/RandomSource.java @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.luminiasoft.bitshares.crypto; +package de.bitsharesmunich.graphenej.crypto; public interface RandomSource { /** diff --git a/src/main/java/com/luminiasoft/bitshares/crypto/SecureRandomStrengthener.java b/src/main/java/de/bitsharesmunich/graphenej/crypto/SecureRandomStrengthener.java similarity index 99% rename from src/main/java/com/luminiasoft/bitshares/crypto/SecureRandomStrengthener.java rename to src/main/java/de/bitsharesmunich/graphenej/crypto/SecureRandomStrengthener.java index 54ddff2..093cffd 100644 --- a/src/main/java/com/luminiasoft/bitshares/crypto/SecureRandomStrengthener.java +++ b/src/main/java/de/bitsharesmunich/graphenej/crypto/SecureRandomStrengthener.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares.crypto; +package de.bitsharesmunich.graphenej.crypto; import java.nio.ByteBuffer; import java.security.DigestException; diff --git a/src/main/java/com/luminiasoft/bitshares/errors/MalformedAddressException.java b/src/main/java/de/bitsharesmunich/graphenej/errors/MalformedAddressException.java similarity index 80% rename from src/main/java/com/luminiasoft/bitshares/errors/MalformedAddressException.java rename to src/main/java/de/bitsharesmunich/graphenej/errors/MalformedAddressException.java index a1c673d..8348d3e 100644 --- a/src/main/java/com/luminiasoft/bitshares/errors/MalformedAddressException.java +++ b/src/main/java/de/bitsharesmunich/graphenej/errors/MalformedAddressException.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares.errors; +package de.bitsharesmunich.graphenej.errors; /** * Created by nelson on 12/1/16. diff --git a/src/main/java/com/luminiasoft/bitshares/errors/MalformedTransactionException.java b/src/main/java/de/bitsharesmunich/graphenej/errors/MalformedTransactionException.java similarity index 81% rename from src/main/java/com/luminiasoft/bitshares/errors/MalformedTransactionException.java rename to src/main/java/de/bitsharesmunich/graphenej/errors/MalformedTransactionException.java index 604f8c4..34e303e 100644 --- a/src/main/java/com/luminiasoft/bitshares/errors/MalformedTransactionException.java +++ b/src/main/java/de/bitsharesmunich/graphenej/errors/MalformedTransactionException.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares.errors; +package de.bitsharesmunich.graphenej.errors; /** * Created by nelson on 11/14/16. diff --git a/src/main/java/com/luminiasoft/bitshares/interfaces/ByteSerializable.java b/src/main/java/de/bitsharesmunich/graphenej/interfaces/ByteSerializable.java similarity index 77% rename from src/main/java/com/luminiasoft/bitshares/interfaces/ByteSerializable.java rename to src/main/java/de/bitsharesmunich/graphenej/interfaces/ByteSerializable.java index b557013..b60c6c1 100644 --- a/src/main/java/com/luminiasoft/bitshares/interfaces/ByteSerializable.java +++ b/src/main/java/de/bitsharesmunich/graphenej/interfaces/ByteSerializable.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares.interfaces; +package de.bitsharesmunich.graphenej.interfaces; /** * Interface implemented by all entities for which makes sense to have a byte-array representation. diff --git a/src/main/java/com/luminiasoft/bitshares/interfaces/GrapheneSerializable.java b/src/main/java/de/bitsharesmunich/graphenej/interfaces/GrapheneSerializable.java similarity index 78% rename from src/main/java/com/luminiasoft/bitshares/interfaces/GrapheneSerializable.java rename to src/main/java/de/bitsharesmunich/graphenej/interfaces/GrapheneSerializable.java index 68ed06f..93eb781 100644 --- a/src/main/java/com/luminiasoft/bitshares/interfaces/GrapheneSerializable.java +++ b/src/main/java/de/bitsharesmunich/graphenej/interfaces/GrapheneSerializable.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares.interfaces; +package de.bitsharesmunich.graphenej.interfaces; /** * Interface used to group both ByteSerializable and JsonSerializable interfaces. diff --git a/src/main/java/com/luminiasoft/bitshares/interfaces/JsonSerializable.java b/src/main/java/de/bitsharesmunich/graphenej/interfaces/JsonSerializable.java similarity index 86% rename from src/main/java/com/luminiasoft/bitshares/interfaces/JsonSerializable.java rename to src/main/java/de/bitsharesmunich/graphenej/interfaces/JsonSerializable.java index e1f7377..5e64e4d 100644 --- a/src/main/java/com/luminiasoft/bitshares/interfaces/JsonSerializable.java +++ b/src/main/java/de/bitsharesmunich/graphenej/interfaces/JsonSerializable.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares.interfaces; +package de.bitsharesmunich.graphenej.interfaces; import com.google.gson.JsonElement; diff --git a/src/main/java/com/luminiasoft/bitshares/interfaces/WitnessResponseListener.java b/src/main/java/de/bitsharesmunich/graphenej/interfaces/WitnessResponseListener.java similarity index 55% rename from src/main/java/com/luminiasoft/bitshares/interfaces/WitnessResponseListener.java rename to src/main/java/de/bitsharesmunich/graphenej/interfaces/WitnessResponseListener.java index 58560c0..0a25d0a 100644 --- a/src/main/java/com/luminiasoft/bitshares/interfaces/WitnessResponseListener.java +++ b/src/main/java/de/bitsharesmunich/graphenej/interfaces/WitnessResponseListener.java @@ -1,7 +1,7 @@ -package com.luminiasoft.bitshares.interfaces; +package de.bitsharesmunich.graphenej.interfaces; -import com.luminiasoft.bitshares.models.BaseResponse; -import com.luminiasoft.bitshares.models.WitnessResponse; +import de.bitsharesmunich.graphenej.models.BaseResponse; +import de.bitsharesmunich.graphenej.models.WitnessResponse; /** * Class used to represent any listener to network requests. diff --git a/src/main/java/com/luminiasoft/bitshares/models/AccountProperties.java b/src/main/java/de/bitsharesmunich/graphenej/models/AccountProperties.java similarity index 96% rename from src/main/java/com/luminiasoft/bitshares/models/AccountProperties.java rename to src/main/java/de/bitsharesmunich/graphenej/models/AccountProperties.java index b57f0a2..f2fd595 100644 --- a/src/main/java/com/luminiasoft/bitshares/models/AccountProperties.java +++ b/src/main/java/de/bitsharesmunich/graphenej/models/AccountProperties.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares.models; +package de.bitsharesmunich.graphenej.models; /** * Created by nelson on 11/15/16. diff --git a/src/main/java/com/luminiasoft/bitshares/models/ApiCall.java b/src/main/java/de/bitsharesmunich/graphenej/models/ApiCall.java similarity index 97% rename from src/main/java/com/luminiasoft/bitshares/models/ApiCall.java rename to src/main/java/de/bitsharesmunich/graphenej/models/ApiCall.java index 6d29147..e07416e 100644 --- a/src/main/java/com/luminiasoft/bitshares/models/ApiCall.java +++ b/src/main/java/de/bitsharesmunich/graphenej/models/ApiCall.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares.models; +package de.bitsharesmunich.graphenej.models; import com.google.gson.GsonBuilder; import com.google.gson.JsonArray; @@ -6,7 +6,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonSerializationContext; import com.google.gson.JsonSerializer; -import com.luminiasoft.bitshares.interfaces.JsonSerializable; +import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; import java.io.Serializable; import java.lang.reflect.Type; diff --git a/src/main/java/com/luminiasoft/bitshares/models/BaseResponse.java b/src/main/java/de/bitsharesmunich/graphenej/models/BaseResponse.java similarity index 92% rename from src/main/java/com/luminiasoft/bitshares/models/BaseResponse.java rename to src/main/java/de/bitsharesmunich/graphenej/models/BaseResponse.java index 13df8f6..3801777 100644 --- a/src/main/java/com/luminiasoft/bitshares/models/BaseResponse.java +++ b/src/main/java/de/bitsharesmunich/graphenej/models/BaseResponse.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares.models; +package de.bitsharesmunich.graphenej.models; /** * Created by nelson on 11/12/16. diff --git a/src/main/java/com/luminiasoft/bitshares/models/DynamicGlobalProperties.java b/src/main/java/de/bitsharesmunich/graphenej/models/DynamicGlobalProperties.java similarity index 93% rename from src/main/java/com/luminiasoft/bitshares/models/DynamicGlobalProperties.java rename to src/main/java/de/bitsharesmunich/graphenej/models/DynamicGlobalProperties.java index c59278d..26d711c 100644 --- a/src/main/java/com/luminiasoft/bitshares/models/DynamicGlobalProperties.java +++ b/src/main/java/de/bitsharesmunich/graphenej/models/DynamicGlobalProperties.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares.models; +package de.bitsharesmunich.graphenej.models; /** * Class used to deserialize the 'result' field returned by the full node after making a call diff --git a/src/main/java/com/luminiasoft/bitshares/models/HistoricalTransfer.java b/src/main/java/de/bitsharesmunich/graphenej/models/HistoricalTransfer.java similarity index 83% rename from src/main/java/com/luminiasoft/bitshares/models/HistoricalTransfer.java rename to src/main/java/de/bitsharesmunich/graphenej/models/HistoricalTransfer.java index 1e27519..8c5cfeb 100644 --- a/src/main/java/com/luminiasoft/bitshares/models/HistoricalTransfer.java +++ b/src/main/java/de/bitsharesmunich/graphenej/models/HistoricalTransfer.java @@ -1,6 +1,6 @@ -package com.luminiasoft.bitshares.models; +package de.bitsharesmunich.graphenej.models; -import com.luminiasoft.bitshares.TransferOperation; +import de.bitsharesmunich.graphenej.TransferOperation; /** * This class offers support to deserialization of transfer operations received by the API diff --git a/src/main/java/com/luminiasoft/bitshares/models/WitnessResponse.java b/src/main/java/de/bitsharesmunich/graphenej/models/WitnessResponse.java similarity index 71% rename from src/main/java/com/luminiasoft/bitshares/models/WitnessResponse.java rename to src/main/java/de/bitsharesmunich/graphenej/models/WitnessResponse.java index 0ba8b26..3e5e7da 100644 --- a/src/main/java/com/luminiasoft/bitshares/models/WitnessResponse.java +++ b/src/main/java/de/bitsharesmunich/graphenej/models/WitnessResponse.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares.models; +package de.bitsharesmunich.graphenej.models; /** * Generic witness response diff --git a/src/main/java/de/bitsharesmunich/graphenej/objects/Memo.java b/src/main/java/de/bitsharesmunich/graphenej/objects/Memo.java new file mode 100644 index 0000000..7cb9c08 --- /dev/null +++ b/src/main/java/de/bitsharesmunich/graphenej/objects/Memo.java @@ -0,0 +1,184 @@ +package de.bitsharesmunich.graphenej.objects; + +import com.google.common.primitives.Bytes; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; +import de.bitsharesmunich.graphenej.PublicKey; +import de.bitsharesmunich.graphenej.Util; +import de.bitsharesmunich.graphenej.crypto.SecureRandomStrengthener; +import de.bitsharesmunich.graphenej.interfaces.ByteSerializable; +import de.bitsharesmunich.graphenej.interfaces.JsonSerializable; +import java.math.BigInteger; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.security.SecureRandom; + +/** + * Created by nelson on 11/9/16. + */ +public class Memo implements ByteSerializable, JsonSerializable { + + public static final String KEY_FROM = "from"; + public static final String KEY_TO = "to"; + public static final String KEY_NONCE = "nonce"; + public static final String KEY_MESSAGE = "message"; + + private PublicKey from; + private PublicKey to; + private final byte[] nonce = new byte[8]; + private byte[] message; + + /** + * Empty Constructor + */ + public Memo() { + this.from = null; + this.to = null; + this.message = null; + } + + /** + * Implement metod, serialized this Object + * @return the byte array of this object serialized + */ + @Override + public byte[] toBytes() { + if ((this.from == null) || (this.to == null) || (this.message == null)) { + return new byte[]{(byte) 0}; + } else { + byte[] nonceformat = new byte[nonce.length]; + for (int i = 0; i < nonceformat.length; i++) { + nonceformat[i] = nonce[nonce.length - i - 1]; + } + return Bytes.concat(new byte[]{1}, this.from.toBytes(), this.to.toBytes(), nonceformat, new byte[]{(byte) this.message.length}, this.message); + } + } + + /** + * Encode a memo message using the input source key and destination key + * @param fromKey The source destination, need to have a private key accesss + * @param toKey The destination, needs only the public key access + * @param msg The message in bytes + * @return a Memo corresponding with the message encoding + */ + public static Memo encodeMessage(PublicKey fromKey, PublicKey toKey, byte[] msg) { + return encodeMessage(fromKey, toKey, msg, 0); + } + + /** + * Encode a message a return a memo with that message encoded + * + * @param fromKey The source destination, need to have a private key accesss + * @param toKey The destination, needs only the public key access + * @param msg The message in bytes + * @param custom_nonce the custom nonce to be use or 0 to create a new one + * @return a Memo corresponding with the message encoding + */ + public static Memo encodeMessage(PublicKey fromKey, PublicKey toKey, byte[] msg, long custom_nonce) { + Memo memo = new Memo(); + try { + MessageDigest md = MessageDigest.getInstance("SHA-256"); + + memo.from = fromKey; + memo.to = toKey; + + if (custom_nonce == 0) { + SecureRandomStrengthener randomStrengthener = SecureRandomStrengthener.getInstance(); + //randomStrengthener.addEntropySource(new AndroidRandomSource()); + SecureRandom secureRandom = randomStrengthener.generateAndSeedRandomNumberGenerator(); + secureRandom.nextBytes(memo.nonce); + + long time = System.currentTimeMillis(); + + for (int i = 7; i >= 1; i--) { + memo.nonce[i] = (byte) (time & 0xff); + time = time / 0x100; + } + } else { + for (int i = 7; i >= 0; i--) { + memo.nonce[i] = (byte) (custom_nonce & 0xff); + custom_nonce = custom_nonce / 0x100; + } + } + + byte[] secret = toKey.getKey().getPubKeyPoint().multiply(fromKey.getKey().getPrivKey()).normalize().getXCoord().getEncoded(); + byte[] finalKey = new byte[secret.length + memo.nonce.length]; + System.arraycopy(secret, 0, finalKey, 0, secret.length); + System.arraycopy(memo.nonce, 0, finalKey, secret.length, memo.nonce.length); + + byte[] sha256Msg = md.digest(msg); + byte[] serialChecksum = new byte[4]; + System.arraycopy(sha256Msg, 0, serialChecksum, 0, 4); + byte[] msgFinal = new byte[serialChecksum.length + msg.length]; + System.arraycopy(serialChecksum, 0, msgFinal, 0, serialChecksum.length); + System.arraycopy(msg, 0, msgFinal, serialChecksum.length, msg.length); + memo.message = Util.encryptAES(msgFinal, finalKey); + } catch (NoSuchAlgorithmException ex) { + } + return memo; + } + + /** + * returns the string coreesponding a encode memo + * + * @param fromKey The soruce key, need to have public key only + * @param toKey The destination key, need to have private key access + * @param msg The message to be decoded + * @param nonce The nonce used in the decoded message + * @return The message + */ + public static String decodeMessage(PublicKey fromKey, PublicKey toKey, byte[] msg, byte[] nonce) { + + byte[] secret = fromKey.getKey().getPubKeyPoint().multiply(toKey.getKey().getPrivKey()).normalize().getXCoord().getEncoded(); + byte[] finalKey = new byte[secret.length + nonce.length]; + System.arraycopy(secret, 0, finalKey, 0, secret.length); + System.arraycopy(nonce, 0, finalKey, secret.length, nonce.length); + + byte[] msgFinal = Util.decryptAES(msg, finalKey); + byte[] decodedMsg = new byte[msgFinal.length - 4]; + //TODO verify checksum for integrity + System.arraycopy(msgFinal, 4, decodedMsg, 0, decodedMsg.length); + return new String(decodedMsg); + } + + /** + * returns the string coreesponding a encode memo + * + * @param fromKey The soruce key, need to have public key only + * @param toKey The destination key, need to have private key access + * @param message The message to be decoded + * @param nonce The nonce used in the decoded message + * @return The message + */ + public static String decodeMessage(PublicKey fromKey, PublicKey toKey, String message, String nonce) { + byte[] msg = new BigInteger(message, 16).toByteArray(); + if (msg[0] == 0) { + byte[] temp = new byte[msg.length - 1]; + System.arraycopy(msg, 1, temp, 0, temp.length); + msg = temp; + } + byte[] firstNonce = new BigInteger(nonce, 10).toByteArray(); + byte[] nonceByte = new byte[8]; + System.arraycopy(firstNonce, firstNonce.length - 8, nonceByte, 0, nonceByte.length); + return decodeMessage(fromKey, toKey, msg, nonceByte); + } + + @Override + public String toJsonString() { + throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates. + } + + @Override + public JsonElement toJsonObject() { + if ((this.from == null) || (this.to == null) || (this.nonce == null) || (this.message == null)) { + return null; + } + JsonObject memoObject = new JsonObject(); + memoObject.addProperty(KEY_FROM, this.from.getAddress()); + memoObject.addProperty(KEY_TO, this.to.getAddress()); + memoObject.addProperty(KEY_NONCE, new BigInteger(1, this.nonce).toString(10)); + memoObject.addProperty(KEY_MESSAGE, new BigInteger(1, this.message).toString(16)); + return memoObject; + } + +} diff --git a/src/main/java/de/bitsharesmunich/graphenej/objects/MemoBuilder.java b/src/main/java/de/bitsharesmunich/graphenej/objects/MemoBuilder.java new file mode 100644 index 0000000..ab8426b --- /dev/null +++ b/src/main/java/de/bitsharesmunich/graphenej/objects/MemoBuilder.java @@ -0,0 +1,74 @@ +package de.bitsharesmunich.graphenej.objects; + +import de.bitsharesmunich.graphenej.PublicKey; + +/** + * Class to build a Memo Object + * @author henry 10/12/2016 + */ +public class MemoBuilder { + + private PublicKey fromKey; + private PublicKey toKey; + private String message; + private long nonce = 0; + + /** + * Empty Constructor + */ + public MemoBuilder() { + } + + /** + * Set the key of the Source, needs to have a private Key access + * @param fromKey The Public Key of the sender + * @return The MemoBuilder + */ + public MemoBuilder setFromKey(PublicKey fromKey) { + this.fromKey = fromKey; + return this; + } + + /** + * Set the key of the destination, only need the public key. + * @param toKey The Public Key of the receiver + * @return The MemoBuilder + */ + public MemoBuilder setToKey(PublicKey toKey) { + this.toKey = toKey; + return this; + } + + /** + * Set the message to be send + * @param message The message as a String + * @return The MemoBuilder + */ + public MemoBuilder setMessage(String message) { + this.message = message; + return this; + } + + /** + * (Optional) Sets a custom nonce + * @param nonce The custom nonce + * @return The MemoBuilder + */ + public MemoBuilder setNone(Long nonce) { + this.nonce = nonce; + return this; + } + + /** + * Biulds the memo object + * @return The Memo object + */ + public Memo build() { + //Todo unencode key + if (nonce == 0) { + return Memo.encodeMessage(fromKey, toKey, message.getBytes()); + } + return Memo.encodeMessage(fromKey, toKey, message.getBytes(), nonce); + } + +} diff --git a/src/main/java/com/luminiasoft/bitshares/test/NaiveSSLContext.java b/src/main/java/de/bitsharesmunich/graphenej/test/NaiveSSLContext.java similarity index 98% rename from src/main/java/com/luminiasoft/bitshares/test/NaiveSSLContext.java rename to src/main/java/de/bitsharesmunich/graphenej/test/NaiveSSLContext.java index a54d8ab..8858aba 100644 --- a/src/main/java/com/luminiasoft/bitshares/test/NaiveSSLContext.java +++ b/src/main/java/de/bitsharesmunich/graphenej/test/NaiveSSLContext.java @@ -1,4 +1,4 @@ -package com.luminiasoft.bitshares.test; +package de.bitsharesmunich.graphenej.test; /* * Copyright (C) 2015 Neo Visionaries Inc.