Refactor key handling

This commit is contained in:
Manfred Karrer 2015-03-16 01:50:46 +01:00
parent 32db4c0c75
commit ca32014f8b
24 changed files with 147 additions and 190 deletions

View File

@ -19,7 +19,6 @@ package io.bitsquare.btc;
import org.bitcoinj.core.Address;
import org.bitcoinj.core.NetworkParameters;
import org.bitcoinj.core.Utils;
import org.bitcoinj.crypto.DeterministicKey;
import java.io.Serializable;
@ -32,26 +31,25 @@ import java.util.Arrays;
*/
public class AddressEntry implements Serializable {
private static final long serialVersionUID = 5501603992599920416L;
private transient DeterministicKey key;
private transient DeterministicKey keyPair;
private final NetworkParameters params;
private final AddressContext addressContext;
private final String offerId;
private final byte[] pubKey;
private final byte[] pubKeyHash;
public AddressEntry(DeterministicKey key, NetworkParameters params, AddressContext addressContext) {
this(key, params, addressContext, null);
public AddressEntry(DeterministicKey keyPair, NetworkParameters params, AddressContext addressContext) {
this(keyPair, params, addressContext, null);
}
public AddressEntry(DeterministicKey key, NetworkParameters params, AddressContext addressContext, String offerId) {
this.key = key;
public AddressEntry(DeterministicKey keyPair, NetworkParameters params, AddressContext addressContext, String offerId) {
this.keyPair = keyPair;
this.params = params;
this.addressContext = addressContext;
this.offerId = offerId;
pubKey = key.getPubOnly().getPubKey();
pubKeyHash = key.getPubOnly().getPubKeyHash();
pubKey = keyPair.getPubOnly().getPubKey();
pubKeyHash = keyPair.getPubOnly().getPubKeyHash();
}
public String getOfferId() {
@ -66,20 +64,16 @@ public class AddressEntry implements Serializable {
return getAddress().toString();
}
public String getPubKeyAsHex() {
return Utils.HEX.encode(key.getPubKey());
}
public DeterministicKey getKey() {
return key;
public DeterministicKey getKeyPair() {
return keyPair;
}
public Address getAddress() {
return key.toAddress(params);
return keyPair.toAddress(params);
}
public void setDeterministicKey(DeterministicKey key) {
this.key = key;
public void setDeterministicKey(DeterministicKey deterministicKey) {
this.keyPair = deterministicKey;
}
public byte[] getPubKeyHash() {
@ -100,7 +94,7 @@ public class AddressEntry implements Serializable {
public String toString() {
return "AddressEntry{" +
"addressString=" + getAddress().toString() +
"key=" + key +
"key=" + keyPair +
", params=" + params +
", addressContext=" + addressContext +
", offerId='" + offerId + '\'' +

View File

@ -490,8 +490,7 @@ public class WalletService {
Transaction tx = new Transaction(params);
byte[] data = signatureService.digestMessageWithSignature(
getRegistrationAddressEntry().getKey(), stringifiedBankAccounts);
byte[] data = signatureService.digestMessageWithSignature(getRegistrationAddressEntry().getKeyPair(), stringifiedBankAccounts);
tx.addOutput(Transaction.MIN_NONDUST_OUTPUT, new ScriptBuilder().op(OP_RETURN).data(data).build());
// We don't take a fee at the moment
@ -615,7 +614,7 @@ public class WalletService {
Transaction dummyTX = new Transaction(params);
// The output is just used to get the right inputs and change outputs, so we use an anonymous ECKey, as it will never be used for anything.
// We don't care about fee calculation differences between the real tx and that dummy tx as we use a static tx fee.
TransactionOutput msOutput = new TransactionOutput(params, dummyTX, dummyOutputAmount, new ECKey());
TransactionOutput msOutput = new TransactionOutput(params, dummyTX, dummyOutputAmount, new ECKey().toAddress(params));
dummyTX.addOutput(msOutput);
// Fin the needed inputs to pay the output, optional add change output.
@ -670,7 +669,7 @@ public class WalletService {
TransactionVerificationException, WalletException {
// TODO verify amounts, addresses, MS
Transaction depositTx = new Transaction(params);
Script multiSigOutputScript = getMultiSigOutputScript(offererPubKey, takerPubKey, arbitratorPubKey);
// We use temporary inputAmount as the value for the output amount to get the correct inputs from the takers side.
@ -719,8 +718,8 @@ public class WalletService {
// Taker inputs are the first inputs (0 -n), so the index of takerInputs and depositTx.getInputs() matches for the number of takerInputs.
int index = 0;
for (TransactionInput input : takerInputs) {
log.debug("signInput input "+input.toString());
log.debug("signInput index "+index);
log.debug("signInput input " + input.toString());
log.debug("signInput index " + index);
signInput(depositTx, input, index);
checkScriptSig(depositTx, input, index);
index++;
@ -746,7 +745,7 @@ public class WalletService {
FutureCallback<Transaction> callback) throws SigningException, TransactionVerificationException, WalletException {
// TODO verify amounts, addresses, MS
// The outpoints are not available from the serialized takersDepositTx, so we cannot use that tx directly, but we use it to construct a new depositTx
Transaction depositTx = new Transaction(params);
@ -782,7 +781,7 @@ public class WalletService {
printInputs("depositTx", depositTx);
log.debug("depositTx = " + depositTx);
// Offerer inputs are the first inputs (0 -n), so the index of offererInputs and depositTx.getInputs() matches for the number of offererInputs.
int index = 0;
for (TransactionInput input : offererInputs) {
@ -797,7 +796,7 @@ public class WalletService {
verifyTransaction(depositTx);
checkWalletConsistency();
checkScriptSigForAllInputs(depositTx);
// Broadcast depositTx
log.trace("Wallet balance before broadcastTransaction: " + wallet.getBalance());
log.trace("Check if wallet is consistent before broadcastTransaction: result=" + wallet.isConsistent());
@ -813,9 +812,9 @@ public class WalletService {
log.trace("inputs: ");
log.trace("depositTx=" + depositTx);
// If not recreate the tx we get a null pointer at receivePending
log.debug("tx id "+depositTx.getHashAsString());
log.debug("tx id " + depositTx.getHashAsString());
depositTx = new Transaction(params, depositTx.bitcoinSerialize());
log.debug("tx id "+depositTx.getHashAsString());
log.debug("tx id " + depositTx.getHashAsString());
log.trace("depositTx=" + depositTx);
// boolean isAlreadyInWallet = wallet.maybeCommitTx(depositTx);
//log.trace("isAlreadyInWallet=" + isAlreadyInWallet);
@ -859,7 +858,7 @@ public class WalletService {
TransactionOutput multiSigOutput = tx.getInput(0).getConnectedOutput();
Script multiSigScript = multiSigOutput.getScriptPubKey();
Sha256Hash sigHash = tx.hashForSignature(0, multiSigScript, Transaction.SigHash.ALL, false);
ECKey.ECDSASignature offererSignature = getAddressInfo(tradeID).getKey().sign(sigHash);
ECKey.ECDSASignature offererSignature = getAddressInfo(tradeID).getKeyPair().sign(sigHash);
TransactionSignature offererTxSig = new TransactionSignature(offererSignature, Transaction.SigHash.ALL, false);
Script inputScript = ScriptBuilder.createMultiSigInputScript(ImmutableList.of(offererTxSig));
@ -895,7 +894,7 @@ public class WalletService {
Sha256Hash sigHash = tx.hashForSignature(0, multiSigScript, Transaction.SigHash.ALL, false);
log.trace("sigHash=" + sigHash);
ECKey.ECDSASignature takerSignature = getAddressInfo(tradeID).getKey().sign(sigHash);
ECKey.ECDSASignature takerSignature = getAddressInfo(tradeID).getKeyPair().sign(sigHash);
TransactionSignature takerTxSig = new TransactionSignature(takerSignature, Transaction.SigHash.ALL, false);
TransactionSignature offererTxSig = new TransactionSignature(offererSignature, Transaction.SigHash.ALL, false);

View File

@ -157,7 +157,7 @@ class MainViewModel implements ViewModel {
error -> log.error(error.toString()),
() -> Platform.runLater(() -> setBitcoinNetworkSyncProgress(1.0)));
Observable<BootstrapState> messageObservable = clientNode.bootstrap(user.getMessageKeyPair(), tradeMessageService);
Observable<BootstrapState> messageObservable = clientNode.bootstrap(user.getNetworkKeyPair(), tradeMessageService);
messageObservable.publish();
messageObservable.subscribe(
state -> Platform.runLater(() -> setBootstrapState(state)),
@ -350,9 +350,9 @@ class MainViewModel implements ViewModel {
}
private void addMockArbitrator() {
if (accountSettings.getAcceptedArbitrators().isEmpty() && user.getMessageKeyPair() != null) {
if (accountSettings.getAcceptedArbitrators().isEmpty() && user.getNetworkKeyPair() != null) {
byte[] pubKey = new ECKey().getPubKey();
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey());
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getNetworkPubKey());
List<Locale> languages = new ArrayList<>();
languages.add(LanguageUtil.getDefaultLanguageLocale());
List<Arbitrator.METHOD> arbitrationMethods = new ArrayList<>();

View File

@ -370,7 +370,7 @@ public class ArbitratorRegistrationView extends ActivatableView<AnchorPane, Void
private Arbitrator getEditedArbitrator() {
byte[] pubKey = walletService.getArbitratorDepositAddressEntry().getPubKey();
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey());
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getNetworkPubKey());
String name = nameTextField.getText();
Coin fee = formatter.parseToCoin(arbitrationFeeTextField.getText());
String webUrl = webPageTextField.getText();

View File

@ -122,9 +122,9 @@ class IrcAccountDataModel implements Activatable, DataModel {
}
private void addMockArbitrator() {
if (accountSettings.getAcceptedArbitrators().isEmpty() && user.getMessageKeyPair() != null) {
if (accountSettings.getAcceptedArbitrators().isEmpty() && user.getNetworkKeyPair() != null) {
byte[] pubKey = new ECKey().getPubKey();
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey());
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getNetworkPubKey());
List<Locale> languages = new ArrayList<>();
languages.add(LanguageUtil.getDefaultLanguageLocale());
List<Arbitrator.METHOD> arbitrationMethods = new ArrayList<>();

View File

@ -152,9 +152,9 @@ class RestrictionsDataModel implements Activatable, DataModel {
// TODO Remove mock later
private void addMockArbitrator() {
if (accountSettings.getAcceptedArbitrators().isEmpty() && user.getMessageKeyPair() != null) {
if (accountSettings.getAcceptedArbitrators().isEmpty() && user.getNetworkKeyPair() != null) {
byte[] pubKey = new ECKey().getPubKey();
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getMessagePublicKey());
String messagePubKeyAsHex = DSAKeyUtil.getHexStringFromPublicKey(user.getNetworkPubKey());
List<Locale> languages = new ArrayList<>();
languages.add(LanguageUtil.getDefaultLanguageLocale());
List<Arbitrator.METHOD> arbitrationMethods = new ArrayList<>();

View File

@ -74,7 +74,7 @@ class ClosedTradesDataModel implements Activatable, DataModel {
}
public Direction getDirection(Offer offer) {
return offer.getMessagePublicKey().equals(user.getMessagePublicKey()) ?
return offer.getMessagePublicKey().equals(user.getNetworkPubKey()) ?
offer.getDirection() : offer.getMirroredDirection();
}

View File

@ -88,7 +88,7 @@ class OffersDataModel implements Activatable, DataModel {
public Direction getDirection(OpenOffer openOffer) {
Offer offer = openOffer.getOffer();
return offer.getMessagePublicKey().equals(user.getMessagePublicKey()) ?
return offer.getMessagePublicKey().equals(user.getNetworkPubKey()) ?
offer.getDirection() : offer.getMirroredDirection();
}
}

View File

@ -130,7 +130,7 @@ class PendingTradesDataModel implements Activatable, DataModel {
selectedItem = item;
if (selectedItem != null) {
isOfferer = getTrade().getOffer().getMessagePublicKey().equals(user.getMessagePublicKey());
isOfferer = getTrade().getOffer().getMessagePublicKey().equals(user.getNetworkPubKey());
Trade trade = getTrade();
trade.stateProperty().addListener(stateChangeListener);
@ -253,7 +253,7 @@ class PendingTradesDataModel implements Activatable, DataModel {
}
public Direction getDirection(Offer offer) {
return offer.getMessagePublicKey().equals(user.getMessagePublicKey()) ?
return offer.getMessagePublicKey().equals(user.getNetworkPubKey()) ?
offer.getDirection() : offer.getMirroredDirection();
}

View File

@ -213,7 +213,7 @@ class OfferBookDataModel implements Activatable, DataModel {
}
boolean isMyOffer(Offer offer) {
return offer.getMessagePublicKey() != null && offer.getMessagePublicKey().equals(user.getMessagePublicKey());
return offer.getMessagePublicKey() != null && offer.getMessagePublicKey().equals(user.getNetworkPubKey());
}
Coin getAmountAsCoin() {

View File

@ -167,7 +167,7 @@ public class TradeManager {
BankAccount currentBankAccount = user.getCurrentBankAccount().get();
Offer offer = new Offer(id,
user.getMessagePublicKey(),
user.getNetworkPubKey(),
direction,
price.getValue(),
amount,

View File

@ -27,7 +27,7 @@ import io.bitsquare.trade.TradeMessageService;
import io.bitsquare.user.User;
import io.bitsquare.util.taskrunner.SharedModel;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.crypto.DeterministicKey;
import java.security.PublicKey;
@ -47,18 +47,15 @@ public class OfferSharedModel extends SharedModel {
// derived
protected final BankAccount bankAccount;
protected final String accountId;
protected final PublicKey messagePublicKey;
protected final ECKey accountKey;
protected final byte[] arbitratorPubKey;
protected final PublicKey networkPubKey;
protected final byte[] registrationPubKey;
// lazy initialized at first read access, as we don't want to create an entry before it is really needed
protected AddressEntry addressInfo;
protected final DeterministicKey registrationKeyPair;
protected final byte[] arbitratorPubKey;
protected final AddressEntry addressInfo;
// data written/read by tasks
protected TradeMessage tradeMessage;
protected byte[] takerPubKey;
protected String peersAccountId;
protected BankAccount peersBankAccount;
public OfferSharedModel(Offer offer,
TradeMessageService tradeMessageService,
@ -74,34 +71,26 @@ public class OfferSharedModel extends SharedModel {
//TODO use default arbitrator for now
arbitratorPubKey = offer.getArbitrators().get(0).getPubKey();
registrationPubKey = walletService.getRegistrationAddressEntry().getPubKey();
registrationKeyPair = walletService.getRegistrationAddressEntry().getKeyPair();
addressInfo = walletService.getAddressInfo(offer.getId());
bankAccount = user.getBankAccount(offer.getBankAccountId());
accountId = user.getAccountId();
messagePublicKey = user.getMessagePublicKey();
accountKey = walletService.getRegistrationAddressEntry().getKey();
networkPubKey = user.getNetworkPubKey();
}
// getter/setter
public AddressEntry getAddressInfo() {
if (addressInfo == null)
addressInfo = getWalletService().getAddressInfo(offer.getId());
return addressInfo;
public TradeMessage getTradeMessage() {
return tradeMessage;
}
public String getPeersAccountId() {
return peersAccountId;
public void setTradeMessage(TradeMessage tradeMessage) {
this.tradeMessage = tradeMessage;
}
public void setPeersAccountId(String peersAccountId) {
this.peersAccountId = peersAccountId;
}
public BankAccount getPeersBankAccount() {
return peersBankAccount;
}
public void setPeersBankAccount(BankAccount peersBankAccount) {
this.peersBankAccount = peersBankAccount;
public Offer getOffer() {
return offer;
}
public TradeMessageService getTradeMessageService() {
@ -120,14 +109,6 @@ public class OfferSharedModel extends SharedModel {
return signatureService;
}
public Offer getOffer() {
return offer;
}
public byte[] getArbitratorPubKey() {
return arbitratorPubKey;
}
public BankAccount getBankAccount() {
return bankAccount;
}
@ -136,44 +117,24 @@ public class OfferSharedModel extends SharedModel {
return accountId;
}
public PublicKey getMessagePublicKey() {
return messagePublicKey;
public PublicKey getNetworkPubKey() {
return networkPubKey;
}
public ECKey getAccountKey() {
return accountKey;
public byte[] getRegistrationPubKey() {
return registrationPubKey;
}
public byte[] getTakerPubKey() {
return takerPubKey;
public DeterministicKey getRegistrationKeyPair() {
return registrationKeyPair;
}
public void setTakerPubKey(byte[] takerPubKey) {
this.takerPubKey = takerPubKey;
public byte[] getArbitratorPubKey() {
return arbitratorPubKey;
}
public String getTakerAccountId() {
return peersAccountId;
}
public void setTakerAccountId(String peersAccountId) {
this.peersAccountId = peersAccountId;
}
public BankAccount getTakerBankAccount() {
return peersBankAccount;
}
public void setTakerBankAccount(BankAccount peersBankAccount) {
this.peersBankAccount = peersBankAccount;
}
public TradeMessage getTradeMessage() {
return tradeMessage;
}
public void setTradeMessage(TradeMessage tradeMessage) {
this.tradeMessage = tradeMessage;
public AddressEntry getAddressInfo() {
return addressInfo;
}
}

View File

@ -44,12 +44,11 @@ public class BuyerAsOffererModel extends OfferSharedModel {
private static final Logger log = LoggerFactory.getLogger(BuyerAsOffererModel.class);
// provided
private final OpenOffer openOffer;
// derived
private final String offererPaybackAddress;
private final byte[] offererPubKey;
// data written/read by tasks
private Trade trade;
@ -63,7 +62,7 @@ public class BuyerAsOffererModel extends OfferSharedModel {
private Coin takerPaybackAmount;
private String takeOfferFeeTxId;
private byte[] offererPubKey;
private ECKey.ECDSASignature offererSignature;
private Coin offererPaybackAmount;
private List<TransactionOutput> offererConnectedOutputsForAllInputs;
@ -74,6 +73,7 @@ public class BuyerAsOffererModel extends OfferSharedModel {
private String takerPayoutAddress;
private Transaction offererPayoutTx;
private Transaction publishedDepositTx;
private byte[] takerPubKey;
///////////////////////////////////////////////////////////////////////////////////////////
@ -93,11 +93,28 @@ public class BuyerAsOffererModel extends OfferSharedModel {
signatureService,
user);
this.openOffer = openOffer;
offererPaybackAddress = walletService.getAddressInfo(offer.getId()).getAddressString();
offererPubKey = getAddressInfo().getPubKey();
}
//getter/setter
public List<TransactionOutput> getOffererConnectedOutputsForAllInputs() {
return offererConnectedOutputsForAllInputs;
}
public void setOffererConnectedOutputsForAllInputs(List<TransactionOutput> offererConnectedOutputsForAllInputs) {
this.offererConnectedOutputsForAllInputs = offererConnectedOutputsForAllInputs;
}
public List<TransactionOutput> getOffererOutputs() {
return offererOutputs;
}
public void setOffererOutputs(List<TransactionOutput> offererOutputs) {
this.offererOutputs = offererOutputs;
}
public OpenOffer getOpenOffer() {
return openOffer;
}
@ -106,10 +123,6 @@ public class BuyerAsOffererModel extends OfferSharedModel {
return taker;
}
public String getOffererPaybackAddress() {
return offererPaybackAddress;
}
public String getTakeOfferFeeTxId() {
return takeOfferFeeTxId;
@ -119,22 +132,18 @@ public class BuyerAsOffererModel extends OfferSharedModel {
this.takeOfferFeeTxId = takeOfferFeeTxId;
}
@Override
public String getTakerAccountId() {
return takerAccountId;
}
@Override
public void setTakerAccountId(String takerAccountId) {
this.takerAccountId = takerAccountId;
}
@Override
public BankAccount getTakerBankAccount() {
return takerBankAccount;
}
@Override
public void setTakerBankAccount(BankAccount takerBankAccount) {
this.takerBankAccount = takerBankAccount;
}
@ -155,16 +164,10 @@ public class BuyerAsOffererModel extends OfferSharedModel {
this.takerContractAsJson = takerContractAsJson;
}
public byte[] getOffererPubKey() {
return offererPubKey;
}
public void setOffererPubKey(byte[] offererPubKey) {
this.offererPubKey = offererPubKey;
}
public ECKey.ECDSASignature getOffererSignature() {
return offererSignature;
}
@ -201,21 +204,6 @@ public class BuyerAsOffererModel extends OfferSharedModel {
this.taker = taker;
}
public List<TransactionOutput> getOffererConnectedOutputsForAllInputs() {
return offererConnectedOutputsForAllInputs;
}
public void setOffererConnectedOutputsForAllInputs(List<TransactionOutput> offererConnectedOutputsForAllInputs) {
this.offererConnectedOutputsForAllInputs = offererConnectedOutputsForAllInputs;
}
public List<TransactionOutput> getOffererOutputs() {
return offererOutputs;
}
public void setOffererOutputs(List<TransactionOutput> offererOutputs) {
this.offererOutputs = offererOutputs;
}
public void setTakerDepositTx(Transaction takerDepositTx) {
this.takerDepositTx = takerDepositTx;
@ -264,4 +252,12 @@ public class BuyerAsOffererModel extends OfferSharedModel {
public Transaction getPublishedDepositTx() {
return publishedDepositTx;
}
public byte[] getTakerPubKey() {
return takerPubKey;
}
public void setTakerPubKey(byte[] takerPubKey) {
this.takerPubKey = takerPubKey;
}
}

View File

@ -35,12 +35,12 @@ public class RequestDepositPayment extends Task<BuyerAsOffererModel> {
@Override
protected void doRun() {
byte[] offererPubKey = model.getWalletService().getAddressInfo(model.getTrade().getId()).getPubKey();
model.getOffererPubKey();
RequestDepositPaymentMessage tradeMessage = new RequestDepositPaymentMessage(
model.getTrade().getId(),
model.getOffererConnectedOutputsForAllInputs(),
model.getOffererOutputs(),
offererPubKey,
model.getOffererPubKey(),
model.getBankAccount(),
model.getAccountId());

View File

@ -41,7 +41,7 @@ public class SendBankTransferStartedMessage extends Task<BuyerAsOffererModel> {
model.getOffererSignature().encodeToDER(),
model.getOffererPaybackAmount(),
model.getTakerPaybackAmount(),
model.getOffererPaybackAddress());
model.getAddressInfo().getAddressString());
model.getTradeMessageService().sendMessage(model.getTaker(), tradeMessage, new SendMessageListener() {
@Override
public void handleResult() {

View File

@ -46,10 +46,10 @@ public class VerifyAndSignContract extends Task<BuyerAsOffererModel> {
model.getTakerAccountId(),
model.getBankAccount(),
model.getTakerBankAccount(),
model.getMessagePublicKey(),
model.getNetworkPubKey(),
model.getTakerMessagePublicKey());
String contractAsJson = Utilities.objectToJson(contract);
String signature = model.getSignatureService().signMessage(model.getAccountKey(), contractAsJson);
String signature = model.getSignatureService().signMessage(model.getRegistrationKeyPair(), contractAsJson);
trade.setContract(contract);
trade.setContractAsJson(contractAsJson);

View File

@ -17,6 +17,7 @@
package io.bitsquare.trade.protocol.trade.taker;
import io.bitsquare.bank.BankAccount;
import io.bitsquare.btc.BlockChainService;
import io.bitsquare.btc.WalletService;
import io.bitsquare.crypto.SignatureService;
@ -27,7 +28,6 @@ import io.bitsquare.trade.protocol.trade.OfferSharedModel;
import io.bitsquare.user.User;
import org.bitcoinj.core.Coin;
import org.bitcoinj.core.ECKey;
import org.bitcoinj.core.Transaction;
import org.bitcoinj.core.TransactionOutput;
@ -41,7 +41,10 @@ public class SellerAsTakerModel extends OfferSharedModel {
// provided
private final Trade trade;
// derived
private final byte[] takerPubKey;
// written/read by task
private Peer offerer;
@ -53,15 +56,16 @@ public class SellerAsTakerModel extends OfferSharedModel {
private Coin takerPaybackAmount;
private byte[] offererPubKey;
private long offererTxOutIndex;
private ECKey.ECDSASignature offererSignature;
private Coin offererPaybackAmount;
private String offererPayoutAddress;
private List<TransactionOutput> offererConnectedOutputsForAllInputs;
private List<TransactionOutput> offererOutputs;
private List<TransactionOutput> offererConnectedOutputsForAllInputs;
private List<TransactionOutput> offererOutputs;
private List<TransactionOutput> takerConnectedOutputsForAllInputs;
private List<TransactionOutput> takerOutputs;
private Transaction takerDepositTx;
private Transaction publishedDepositTx;
private BankAccount takerBankAccount;
private String takerAccountId;
public SellerAsTakerModel(Trade trade,
TradeMessageService tradeMessageService,
@ -77,11 +81,14 @@ public class SellerAsTakerModel extends OfferSharedModel {
user);
this.trade = trade;
takerPubKey = walletService.getAddressInfo(trade.getId()).getPubKey();
takerPubKey = getAddressInfo().getPubKey();
}
// getter/setter
public byte[] getTakerPubKey() {
return takerPubKey;
}
public void setOffererPubKey(byte[] offererPubKey) {
this.offererPubKey = offererPubKey;
}
@ -101,6 +108,7 @@ public class SellerAsTakerModel extends OfferSharedModel {
public void setOffererOutputs(List<TransactionOutput> offererOutputs) {
this.offererOutputs = offererOutputs;
}
public Trade getTrade() {
return trade;
}
@ -158,14 +166,6 @@ public class SellerAsTakerModel extends OfferSharedModel {
this.depositTx = depositTx;
}
public ECKey.ECDSASignature getOffererSignature() {
return offererSignature;
}
public void setOffererSignature(ECKey.ECDSASignature offererSignature) {
this.offererSignature = offererSignature;
}
public Coin getOffererPaybackAmount() {
return offererPaybackAmount;
}
@ -230,4 +230,20 @@ public class SellerAsTakerModel extends OfferSharedModel {
public Transaction getPublishedDepositTx() {
return publishedDepositTx;
}
public void setTakerBankAccount(BankAccount takerBankAccount) {
this.takerBankAccount = takerBankAccount;
}
public BankAccount getTakerBankAccount() {
return takerBankAccount;
}
public void setTakerAccountId(String takerAccountId) {
this.takerAccountId = takerAccountId;
}
public String getTakerAccountId() {
return takerAccountId;
}
}

View File

@ -46,9 +46,9 @@ public class CreateAndSignContract extends Task<SellerAsTakerModel> {
model.getTakerBankAccount(),
model.getBankAccount(),
model.getOffer().getMessagePublicKey(),
model.getMessagePublicKey());
model.getNetworkPubKey());
String contractAsJson = Utilities.objectToJson(contract);
String signature = model.getSignatureService().signMessage(model.getAccountKey(), contractAsJson);
String signature = model.getSignatureService().signMessage(model.getRegistrationKeyPair(), contractAsJson);
trade.setContract(contract);
trade.setContractAsJson(contractAsJson);

View File

@ -22,12 +22,9 @@ import io.bitsquare.trade.protocol.trade.taker.SellerAsTakerModel;
import io.bitsquare.util.taskrunner.Task;
import io.bitsquare.util.taskrunner.TaskRunner;
import org.bitcoinj.core.ECKey;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static com.google.common.base.Preconditions.checkNotNull;
import static io.bitsquare.util.Validator.*;
public class ProcessBankTransferStartedMessage extends Task<SellerAsTakerModel> {
@ -44,7 +41,7 @@ public class ProcessBankTransferStartedMessage extends Task<SellerAsTakerModel>
BankTransferStartedMessage message = (BankTransferStartedMessage) model.getTradeMessage();
//model.setDepositTx(checkNotNull(message.getDepositTx()));
model.setOffererSignature(checkNotNull(ECKey.ECDSASignature.decodeFromDER(message.getOffererSignature())));
//model.setOffererSignature(checkNotNull(ECKey.ECDSASignature.decodeFromDER(message.getOffererSignature())));
model.setOffererPaybackAmount(positiveCoinOf(nonZeroCoinOf(message.getOffererPaybackAmount())));
model.setTakerPaybackAmount(positiveCoinOf(nonZeroCoinOf(message.getTakerPaybackAmount())));
model.setOffererPayoutAddress(nonEmptyStringOf(message.getOffererPayoutAddress()));

View File

@ -45,6 +45,7 @@ public class ProcessRequestDepositPaymentMessage extends Task<SellerAsTakerModel
checkArgument(message.getOffererConnectedOutputsForAllInputs().size() > 0);
model.setOffererOutputs(checkNotNull(message.getOffererOutputs()));
model.setOffererPubKey(checkNotNull(message.getOffererPubKey()));
model.setTakerBankAccount(checkNotNull(message.getBankAccount()));
model.setTakerAccountId(nonEmptyStringOf(message.getAccountId()));

View File

@ -39,7 +39,7 @@ public class SendSignedTakerDepositTx extends Task<SellerAsTakerModel> {
model.getTrade().getId(),
model.getBankAccount(),
model.getAccountId(),
model.getMessagePublicKey(),
model.getNetworkPubKey(),
model.getTrade().getContractAsJson(),
model.getTrade().getTakerContractSignature(),
model.getTakerDepositTx(),

View File

@ -44,7 +44,7 @@ public class SignAndPublishPayoutTx extends Task<SellerAsTakerModel> {
protected void doRun() {
try {
model.getWalletService().takerSignsAndSendsTx(model.getPublishedDepositTx(),
model.getOffererSignature(),
null,
model.getOffererPaybackAmount(),
model.getTakerPaybackAmount(),
model.getOffererPayoutAddress(),

View File

@ -43,7 +43,7 @@ import javafx.collections.ObservableList;
public class User implements Serializable {
private static final long serialVersionUID = 7409078808248518638L;
private KeyPair messageKeyPair;
private KeyPair networkKeyPair;
private String accountID;
// Used for serialisation (ObservableList cannot be serialized) -> serialisation will change anyway so that is
@ -57,8 +57,7 @@ public class User implements Serializable {
public User() {
// Used for serialisation (ObservableList cannot be serialized) -> serialisation will change anyway so that is
// only temporary
bankAccounts.addListener((ListChangeListener<BankAccount>) change ->
_bankAccounts = new ArrayList<>(bankAccounts));
bankAccounts.addListener((ListChangeListener<BankAccount>) change -> _bankAccounts = new ArrayList<>(bankAccounts));
currentBankAccount.addListener((ov) -> _currentBankAccount = currentBankAccount.get());
}
@ -72,13 +71,13 @@ public class User implements Serializable {
if (persistedUser != null) {
bankAccounts.setAll(persistedUser.getSerializedBankAccounts());
setCurrentBankAccount(persistedUser.getSerializedCurrentBankAccount());
messageKeyPair = persistedUser.getMessageKeyPair();
networkKeyPair = persistedUser.getNetworkKeyPair();
accountID = persistedUser.getAccountId();
}
else {
// First time
// TODO use separate thread. DSAKeyUtil.getKeyPair() runs in same thread now
messageKeyPair = DSAKeyUtil.generateKeyPair();
networkKeyPair = DSAKeyUtil.generateKeyPair();
}
}
@ -153,7 +152,6 @@ public class User implements Serializable {
}
public BankAccount getBankAccount(String bankAccountId) {
// TODO use steam API
for (final BankAccount bankAccount : bankAccounts) {
if (bankAccount.getUid().equals(bankAccountId)) {
return bankAccount;
@ -162,24 +160,19 @@ public class User implements Serializable {
return null;
}
public KeyPair getMessageKeyPair() {
return messageKeyPair;
public KeyPair getNetworkKeyPair() {
return networkKeyPair;
}
public PublicKey getMessagePublicKey() {
return messageKeyPair.getPublic();
}
public String getMessagePublicKeyAsString() {
return DSAKeyUtil.getHexStringFromPublicKey(getMessagePublicKey());
public PublicKey getNetworkPubKey() {
return networkKeyPair.getPublic();
}
public ObjectProperty<BankAccount> currentBankAccountProperty() {
return currentBankAccount;
}
// Used for serialisation (ObservableList cannot be serialized) -> serialisation will change anyway so that is
// only temporary
// Used for serialisation (ObservableList cannot be serialized)
List<BankAccount> getSerializedBankAccounts() {
return _bankAccounts;
}

View File

@ -98,7 +98,7 @@ public class PlaceOfferProtocolTest {
tomP2PNode = new TomP2PNode(bootstrappedPeerBuilder);
tradeMessageService = new TomP2PTradeMessageService(user, tomP2PNode);
Observable<BootstrapState> messageObservable = tomP2PNode.bootstrap(user.getMessageKeyPair(), tradeMessageService);
Observable<BootstrapState> messageObservable = tomP2PNode.bootstrap(user.getNetworkKeyPair(), tradeMessageService);
messageObservable.publish();
messageObservable.subscribe(
state -> log.trace("state changed: " + state),