Search in sources :

Example 16 with DeterministicKey

use of org.bitcoinj.crypto.DeterministicKey in project bisq-core by bisq-network.

the class BuyerAsMakerSignPayoutTx method run.

@Override
protected void run() {
    try {
        runInterceptHook();
        Preconditions.checkNotNull(trade.getTradeAmount(), "trade.getTradeAmount() must not be null");
        Preconditions.checkNotNull(trade.getDepositTx(), "trade.getDepositTx() must not be null");
        BtcWalletService walletService = processModel.getBtcWalletService();
        String id = processModel.getOffer().getId();
        Coin buyerPayoutAmount = trade.getOffer().getBuyerSecurityDeposit().add(trade.getTradeAmount());
        Coin sellerPayoutAmount = trade.getOffer().getSellerSecurityDeposit();
        String buyerPayoutAddressString = walletService.getOrCreateAddressEntry(id, AddressEntry.Context.TRADE_PAYOUT).getAddressString();
        final String sellerPayoutAddressString = processModel.getTradingPeer().getPayoutAddressString();
        DeterministicKey buyerMultiSigKeyPair = walletService.getMultiSigKeyPair(id, processModel.getMyMultiSigPubKey());
        byte[] buyerMultiSigPubKey = processModel.getMyMultiSigPubKey();
        checkArgument(Arrays.equals(buyerMultiSigPubKey, walletService.getOrCreateAddressEntry(id, AddressEntry.Context.MULTI_SIG).getPubKey()), "buyerMultiSigPubKey from AddressEntry must match the one from the trade data. trade id =" + id);
        final byte[] sellerMultiSigPubKey = processModel.getTradingPeer().getMultiSigPubKey();
        byte[] payoutTxSignature = processModel.getTradeWalletService().buyerSignsPayoutTx(trade.getDepositTx(), buyerPayoutAmount, sellerPayoutAmount, buyerPayoutAddressString, sellerPayoutAddressString, buyerMultiSigKeyPair, buyerMultiSigPubKey, sellerMultiSigPubKey, trade.getArbitratorBtcPubKey());
        processModel.setPayoutTxSignature(payoutTxSignature);
        complete();
    } catch (Throwable t) {
        failed(t);
    }
}
Also used : Coin(org.bitcoinj.core.Coin) BtcWalletService(bisq.core.btc.wallet.BtcWalletService) DeterministicKey(org.bitcoinj.crypto.DeterministicKey)

Example 17 with DeterministicKey

use of org.bitcoinj.crypto.DeterministicKey in project account-identity by cryptofiat.

the class HDKey method deriveAddressFromKey.

public static HdAddress deriveAddressFromKey(String pubkey, int index) {
    while (index < 1 << 30) {
        try {
            DeterministicKey master = DeterministicKey.deserializeB58(null, pubkey, MainNetParams.get());
            DeterministicKey child = HDKeyDerivation.deriveChildKey(master, index);
            ECKey childkey = ECKey.fromPublicOnly(child.getPubKey());
            HdAddress address = new HdAddress(index, "0x".concat(org.spongycastle.util.encoders.Hex.toHexString(childkey.getAddress())));
            return address;
        } catch (HDDerivationException e) {
            index++;
        }
    }
    throw new RuntimeException("Couldn't generate HD Key after max tries");
}
Also used : HDDerivationException(org.bitcoinj.crypto.HDDerivationException) ECKey(org.ethereum.crypto.ECKey) DeterministicKey(org.bitcoinj.crypto.DeterministicKey)

Example 18 with DeterministicKey

use of org.bitcoinj.crypto.DeterministicKey in project bitrafael_public by GENERALBYTESCOM.

the class MasterPrivateKeyBCH 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;
    }
    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 19 with DeterministicKey

use of org.bitcoinj.crypto.DeterministicKey in project bitrafael_public by GENERALBYTESCOM.

the class MasterPrivateKeyETH 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;
    }
    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)

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