From 867cd8d4b3349b0cd16ce37a47fe1e8268dcebb1 Mon Sep 17 00:00:00 2001 From: "Nelson R. Perez" Date: Fri, 3 Mar 2017 22:12:33 -0500 Subject: [PATCH] Fixing bin backups, making them completely compatible with the web wallet now --- .../de/bitsharesmunich/graphenej/Main.java | 8 ++++++-- .../de/bitsharesmunich/graphenej/Test.java | 13 +++++++------ .../models/SubscriptionResponse.java | 2 +- .../graphenej/models/backup/Wallet.java | 19 +++++++++++++++++-- 4 files changed, 31 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/de/bitsharesmunich/graphenej/Main.java b/app/src/main/java/de/bitsharesmunich/graphenej/Main.java index 65dc19e..75b710f 100644 --- a/app/src/main/java/de/bitsharesmunich/graphenej/Main.java +++ b/app/src/main/java/de/bitsharesmunich/graphenej/Main.java @@ -27,8 +27,12 @@ public class Main { public static final String BILTHON_16_BRAIN_KEY = System.getenv("BILTHON_16_BRAINKEY"); + public static final String BILTHON_36_BRAIN_KEY = System.getenv("BILTHON_36_BRAINKEY"); + public static final String GENERIC_PASSWORD = System.getenv("GENERIC_PASSWORD"); + public static final String DISCLOSABLE_PASSWORD = System.getenv("DISCLOSABLE_PASSWORD"); + // Static block information used for transaction serialization tests public static int REF_BLOCK_NUM = 56204; public static int REF_BLOCK_PREFIX = 1614747814; @@ -54,7 +58,7 @@ public class Main { // test.testGetDynamicParams(); // test.testGetRequiredFeesSerialization(); // test.testRequiredFeesResponse(); - test.testTransactionBroadcastSequence(); +// test.testTransactionBroadcastSequence(); // test.testAccountLookupDeserialization(); // test.testPrivateKeyManipulations(); // test.testPublicKeyManipulations(); @@ -72,7 +76,7 @@ public class Main { // test.testAccountUpdateOperationBroadcast(); // test.testCreateBinFile(); // test.testImportBinFile(); -// test.testExportBinFile(); + test.testExportBinFile(); // test.testLzmaCompression(); // test.testLzmaDecompression(); // test.testSimpleDecompression(); diff --git a/app/src/main/java/de/bitsharesmunich/graphenej/Test.java b/app/src/main/java/de/bitsharesmunich/graphenej/Test.java index b6b8647..68ffad5 100644 --- a/app/src/main/java/de/bitsharesmunich/graphenej/Test.java +++ b/app/src/main/java/de/bitsharesmunich/graphenej/Test.java @@ -633,7 +633,7 @@ public class Test { String password = Main.GENERIC_PASSWORD; try { String current = new File(".").getCanonicalPath(); - File file = new File(current + "/bts_vinicius_default_20170218_20170219.bin"); + File file = new File(current + "/bilthon-36.bin"); Path path = Paths.get(file.getAbsolutePath()); byte[] data = Files.readAllBytes(path); byte[] publicKey = new byte[FileBin.PUBLIC_KEY_LENGTH]; @@ -673,12 +673,13 @@ public class Test { } public void testExportBinFile(){ - String password = Main.GENERIC_PASSWORD; - BrainKey brainKey = new BrainKey(Main.BILTHON_11_BRAIN_KEY, 0); - Wallet wallet = new Wallet("bilthon-11", brainKey.getBrainKey(), brainKey.getSequenceNumber(), Chains.BITSHARES.CHAIN_ID, password); + String password = Main.DISCLOSABLE_PASSWORD; + BrainKey brainKey = new BrainKey(Main.BILTHON_36_BRAIN_KEY, 0); + String accountName = "bilthon-36"; + Wallet wallet = new Wallet(accountName, brainKey.getBrainKey(), brainKey.getSequenceNumber(), Chains.BITSHARES.CHAIN_ID, password); byte[] privateKey = brainKey.getPrivateKey().getPrivKeyBytes(); PrivateKeyBackup privateKeyBackup = new PrivateKeyBackup(privateKey, brainKey.getSequenceNumber(), 1, wallet.getEncryptionKey(password)); - LinkedAccount linkedAccount = new LinkedAccount("bilthon-11", Chains.BITSHARES.CHAIN_ID); + LinkedAccount linkedAccount = new LinkedAccount(accountName, Chains.BITSHARES.CHAIN_ID); ArrayList walletList = new ArrayList<>(); walletList.add(wallet); @@ -691,7 +692,7 @@ public class Test { System.out.println("Serialized: "+Util.bytesToHex(serialized)); try { String current = new File(".").getCanonicalPath(); - String fullPath = current + "/scwall_bilthon_11.bin"; + String fullPath = current + "/scwall_"+accountName+".bin"; System.out.println("Full path: "+fullPath); File file = new File(fullPath); FileOutputStream out = new FileOutputStream(file); diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/SubscriptionResponse.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/SubscriptionResponse.java index d8502be..dbf896a 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/SubscriptionResponse.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/SubscriptionResponse.java @@ -136,7 +136,7 @@ public class SubscriptionResponse { secondArgument.add(dynamicGlobal); }else if(grapheneObject.getObjectType() == ObjectType.TRANSACTION_OBJECT){ BroadcastedTransaction broadcastedTransaction = new BroadcastedTransaction(grapheneObject.getObjectId()); - broadcastedTransaction.setTransaction(context.deserialize(jsonObject.get(BroadcastedTransaction.KEY_TRX), Transaction.class)); + broadcastedTransaction.setTransaction((Transaction) context.deserialize(jsonObject.get(BroadcastedTransaction.KEY_TRX), Transaction.class)); broadcastedTransaction.setTransactionId(jsonObject.get(BroadcastedTransaction.KEY_TRX_ID).getAsString()); secondArgument.add(broadcastedTransaction); }else{ diff --git a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/Wallet.java b/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/Wallet.java index b522a4e..d4c5218 100644 --- a/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/Wallet.java +++ b/graphenej/src/main/java/de/bitsharesmunich/graphenej/models/backup/Wallet.java @@ -1,9 +1,13 @@ package de.bitsharesmunich.graphenej.models.backup; -import de.bitsharesmunich.graphenej.Chains; +import de.bitsharesmunich.graphenej.Address; import de.bitsharesmunich.graphenej.Util; import de.bitsharesmunich.graphenej.crypto.SecureRandomGenerator; +import org.bitcoinj.core.ECKey; +import org.bitcoinj.core.Sha256Hash; +import org.spongycastle.crypto.digests.SHA256Digest; +import java.io.UnsupportedEncodingException; import java.security.SecureRandom; import java.text.SimpleDateFormat; import java.util.Date; @@ -55,7 +59,18 @@ public class Wallet { this.brainkey_sequence = brainkeySequence; this.chain_id = chainId; - //TODO: Find out how to fill "password_pubkey" and "brainkey_pubkey" fields. + try { + byte[] passwordHash = Sha256Hash.hash(password.getBytes("UTF8")); + this.password_pubkey = new Address(ECKey.fromPublicOnly(ECKey.fromPrivate(passwordHash).getPubKey())).toString(); + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + try{ + byte[] brainkeyHash = Sha256Hash.hash(brainKey.getBytes("UTF8")); + this.brainkey_pubkey = new Address(ECKey.fromPublicOnly(ECKey.fromPrivate(brainkeyHash).getPubKey())).toString(); + } catch(UnsupportedEncodingException e){ + e.printStackTrace(); + } Date now = new Date(); SimpleDateFormat dateFormat = new SimpleDateFormat(Util.TIME_DATE_FORMAT);