use of org.bitcoinj.crypto.DeterministicKey in project bisq-core by bisq-network.
the class SellerSignAndFinalizePayoutTx method run.
@Override
protected void run() {
try {
runInterceptHook();
checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null");
Offer offer = trade.getOffer();
TradingPeer tradingPeer = processModel.getTradingPeer();
BtcWalletService walletService = processModel.getBtcWalletService();
String id = processModel.getOffer().getId();
final byte[] buyerSignature = tradingPeer.getSignature();
Coin buyerPayoutAmount = offer.getBuyerSecurityDeposit().add(trade.getTradeAmount());
Coin sellerPayoutAmount = offer.getSellerSecurityDeposit();
final String buyerPayoutAddressString = tradingPeer.getPayoutAddressString();
String sellerPayoutAddressString = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT).getAddressString();
final byte[] buyerMultiSigPubKey = tradingPeer.getMultiSigPubKey();
byte[] sellerMultiSigPubKey = processModel.getMyMultiSigPubKey();
Optional<AddressEntry> MultiSigAddressEntryOptional = walletService.getAddressEntry(id, AddressEntry.Context.MULTI_SIG);
checkArgument(MultiSigAddressEntryOptional.isPresent() && Arrays.equals(sellerMultiSigPubKey, MultiSigAddressEntryOptional.get().getPubKey()), "sellerMultiSigPubKey from AddressEntry must match the one from the trade data. trade id =" + id);
DeterministicKey multiSigKeyPair = walletService.getMultiSigKeyPair(id, sellerMultiSigPubKey);
Transaction transaction = processModel.getTradeWalletService().sellerSignsAndFinalizesPayoutTx(trade.getDepositTx(), buyerSignature, buyerPayoutAmount, sellerPayoutAmount, buyerPayoutAddressString, sellerPayoutAddressString, multiSigKeyPair, buyerMultiSigPubKey, sellerMultiSigPubKey, trade.getArbitratorBtcPubKey());
trade.setPayoutTx(transaction);
walletService.swapTradeEntryToAvailableEntry(id, AddressEntry.Context.MULTI_SIG);
complete();
} catch (Throwable t) {
failed(t);
}
}
use of org.bitcoinj.crypto.DeterministicKey in project bitrafael_public by GENERALBYTESCOM.
the class MasterPrivateKeyBTC method serializePUB.
public static String serializePUB(DeterministicKey masterKey, int standard, int accountIndex, String cryptoCurrency) {
final DeterministicKey purposeKey = HDKeyDerivation.deriveChildKey(masterKey, new ChildNumber(standard, true));
final DeterministicKey coinKey = HDKeyDerivation.deriveChildKey(purposeKey, new ChildNumber(WalletTools.getCoinTypeByCryptoCurrency(cryptoCurrency), true));
final DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(coinKey, new ChildNumber(accountIndex, true));
int header = 0x0488b21e;
switch(standard) {
case IWalletTools.STANDARD_BIP44:
// xpub
header = XPUB;
break;
case IWalletTools.STANDARD_BIP49:
// ypub
header = YPUB;
break;
case IWalletTools.STANDARD_BIP84:
// zpub
header = ZPUB;
break;
}
ByteBuffer ser = ByteBuffer.allocate(78);
ser.putInt(header);
ser.put((byte) accountKey.getDepth());
ser.putInt(accountKey.getParentFingerprint());
ser.putInt(accountKey.getChildNumber().i());
ser.put(accountKey.getChainCode());
ser.put(accountKey.getPubKey());
checkState(ser.position() == 78);
return Base58.encode(addChecksum(ser.array()));
}
use of org.bitcoinj.crypto.DeterministicKey in project bitsquare by bitsquare.
the class WalletService method encryptWallet.
public void encryptWallet(KeyCrypterScrypt keyCrypterScrypt, KeyParameter key) {
if (this.aesKey != null) {
log.warn("encryptWallet called but we have a aesKey already set. " + "We decryptWallet with the old key before we apply the new key.");
decryptWallet(this.aesKey);
}
wallet.encrypt(keyCrypterScrypt, key);
addressEntryList.stream().forEach(e -> {
final DeterministicKey keyPair = e.getKeyPair();
if (keyPair != null && keyPair.isEncrypted())
e.setDeterministicKey(keyPair.encrypt(keyCrypterScrypt, key));
});
setAesKey(key);
addressEntryList.queueUpForSave();
}
use of org.bitcoinj.crypto.DeterministicKey in project bitsquare by bitsquare.
the class WalletService method decryptWallet.
public void decryptWallet(@NotNull KeyParameter key) {
wallet.decrypt(key);
addressEntryList.stream().forEach(e -> {
final DeterministicKey keyPair = e.getKeyPair();
if (keyPair != null && keyPair.isEncrypted())
e.setDeterministicKey(keyPair.decrypt(key));
});
setAesKey(null);
addressEntryList.queueUpForSave();
}
use of org.bitcoinj.crypto.DeterministicKey in project bitcoin-wallet by bitcoin-wallet.
the class DiagnosticsFragment method handleExtendedPublicKey.
private void handleExtendedPublicKey() {
final DeterministicKey extendedKey = application.getWallet().getWatchingKey();
final String xpub = String.format(Locale.US, "%s?c=%d&h=bip32", extendedKey.serializePubB58(Constants.NETWORK_PARAMETERS), extendedKey.getCreationTimeSeconds());
ExtendedPublicKeyFragment.show(getFragmentManager(), (CharSequence) xpub);
}
Aggregations