Search in sources :

Example 6 with DeterministicKey

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);
    }
}
Also used : Coin(org.bitcoinj.core.Coin) TradingPeer(bisq.core.trade.protocol.TradingPeer) Transaction(org.bitcoinj.core.Transaction) Offer(bisq.core.offer.Offer) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) AddressEntry(bisq.core.btc.AddressEntry) DeterministicKey(org.bitcoinj.crypto.DeterministicKey)

Example 7 with DeterministicKey

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()));
}
Also used : ChildNumber(org.bitcoinj.crypto.ChildNumber) ByteBuffer(java.nio.ByteBuffer) DeterministicKey(org.bitcoinj.crypto.DeterministicKey)

Example 8 with DeterministicKey

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();
}
Also used : DeterministicKey(org.bitcoinj.crypto.DeterministicKey)

Example 9 with DeterministicKey

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();
}
Also used : DeterministicKey(org.bitcoinj.crypto.DeterministicKey)

Example 10 with DeterministicKey

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);
}
Also used : DeterministicKey(org.bitcoinj.crypto.DeterministicKey)

Aggregations

DeterministicKey (org.bitcoinj.crypto.DeterministicKey)19 Transaction (org.bitcoinj.core.Transaction)5 ByteBuffer (java.nio.ByteBuffer)3 Coin (org.bitcoinj.core.Coin)3 ChildNumber (org.bitcoinj.crypto.ChildNumber)3 AddressEntry (bisq.core.btc.AddressEntry)2 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)2 TransactionOutput (org.bitcoinj.core.TransactionOutput)2 Timer (bisq.common.Timer)1 DisputeCommunicationMessage (bisq.core.arbitration.messages.DisputeCommunicationMessage)1 TransactionVerificationException (bisq.core.btc.exceptions.TransactionVerificationException)1 WalletException (bisq.core.btc.exceptions.WalletException)1 Offer (bisq.core.offer.Offer)1 Contract (bisq.core.trade.Contract)1 Tradable (bisq.core.trade.Tradable)1 Trade (bisq.core.trade.Trade)1 TradingPeer (bisq.core.trade.protocol.TradingPeer)1 ArrayList (java.util.ArrayList)1 Optional (java.util.Optional)1 AddressFormatException (org.bitcoinj.core.AddressFormatException)1