Search in sources :

Example 11 with NetworkParameters

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

the class Networks method unregister.

public static void unregister(NetworkParameters network) {
    if (networks.contains(network)) {
        ImmutableSet.Builder<NetworkParameters> builder = ImmutableSet.builder();
        for (NetworkParameters parameters : networks) {
            if (parameters.equals(network))
                continue;
            builder.add(parameters);
        }
        networks = builder.build();
    }
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) NetworkParameters(org.bitcoinj.core.NetworkParameters)

Example 12 with NetworkParameters

use of org.bitcoinj.core.NetworkParameters in project samourai-wallet-android by Samourai-Wallet.

the class HD_WalletFactory method restoreWallet.

public HD_Wallet restoreWallet(String data, String passphrase, int nbAccounts) throws AddressFormatException, IOException, DecoderException, MnemonicException.MnemonicLengthException, MnemonicException.MnemonicWordException, MnemonicException.MnemonicChecksumException {
    HD_Wallet hdw = null;
    if (passphrase == null) {
        passphrase = "";
    }
    NetworkParameters params = SamouraiWallet.getInstance().getCurrentNetworkParams();
    InputStream wis = context.getResources().getAssets().open("BIP39/en.txt");
    if (wis != null) {
        List<String> words = null;
        MnemonicCode mc = null;
        mc = new MnemonicCode(wis, BIP39_ENGLISH_SHA256);
        byte[] seed = null;
        if (data.matches(FormatsUtil.XPUB)) {
            String[] xpub = data.split(":");
            hdw = new HD_Wallet(params, xpub);
        } else if (data.matches(FormatsUtil.HEX) && data.length() % 4 == 0) {
            seed = Hex.decodeHex(data.toCharArray());
            hdw = new HD_Wallet(44, mc, params, seed, passphrase, nbAccounts);
        } else {
            // only use for BIP39 English
            data = data.toLowerCase().replaceAll("[^a-z]+", " ");
            words = Arrays.asList(data.trim().split("\\s+"));
            seed = mc.toEntropy(words);
            hdw = new HD_Wallet(44, mc, params, seed, passphrase, nbAccounts);
        }
        wis.close();
    }
    BIP47Util.getInstance(context).reset();
    BIP49Util.getInstance(context).reset();
    wallets.clear();
    wallets.add(hdw);
    return hdw;
}
Also used : NetworkParameters(org.bitcoinj.core.NetworkParameters) InputStream(java.io.InputStream) MnemonicCode(org.bitcoinj.crypto.MnemonicCode)

Example 13 with NetworkParameters

use of org.bitcoinj.core.NetworkParameters in project elastic-core-maven by OrdinaryDude.

the class RedeemFunctions method redeem.

public static boolean redeem(String address_entry, String secretPhrase, String[] bitcoin_privkeys, boolean graceblock) {
    String secp_signatures = "";
    NetworkParameters params = MainNetParams.get();
    long target_id = Account.getId(Crypto.getPublicKey(secretPhrase));
    String message = Redeem.getSignMessage(Redeem.getClaimableAmount(address_entry), address_entry, target_id);
    // Sign inputs
    for (int i = 0; i < bitcoin_privkeys.length; ++i) {
        ECKey key;
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, bitcoin_privkeys[i]);
        key = dumpedPrivateKey.getKey();
        String signed = key.signMessage(message);
        bitcoin_privkeys[i] = signed;
    }
    secp_signatures = String.join("-", bitcoin_privkeys);
    final Attachment attachment = new Attachment.RedeemAttachment(address_entry, secp_signatures);
    boolean success = false;
    try {
        make(attachment, secretPhrase, Account.getId(Crypto.getPublicKey(secretPhrase)), Redeem.getClaimableAmount(address_entry), true, graceblock);
        success = true;
    } catch (Exception e) {
        Logger.logErrorMessage(e.getMessage());
    }
    return success;
}
Also used : NetworkParameters(org.bitcoinj.core.NetworkParameters) ECKey(org.bitcoinj.core.ECKey) Attachment(org.xel.Attachment) DumpedPrivateKey(org.bitcoinj.core.DumpedPrivateKey)

Example 14 with NetworkParameters

use of org.bitcoinj.core.NetworkParameters in project elastic-core-maven by OrdinaryDude.

the class RedeemTest method redeem_different_sig_and_receipient.

private static boolean redeem_different_sig_and_receipient(String address_entry, String secretPhrase, long accountId, String[] bitcoin_privkeys, boolean graceblock) {
    String secp_signatures = "";
    NetworkParameters params = MainNetParams.get();
    long target_id = Account.getId(Crypto.getPublicKey(secretPhrase));
    String message = Redeem.getSignMessage(Redeem.getClaimableAmount(address_entry), address_entry, target_id);
    // Sign inputs
    for (int i = 0; i < bitcoin_privkeys.length; ++i) {
        ECKey key;
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, bitcoin_privkeys[i]);
        key = dumpedPrivateKey.getKey();
        String signed = key.signMessage(message);
        bitcoin_privkeys[i] = signed;
    }
    secp_signatures = String.join("-", bitcoin_privkeys);
    final Attachment attachment = new Attachment.RedeemAttachment(address_entry, secp_signatures);
    boolean success = false;
    try {
        make(attachment, secretPhrase, accountId, Redeem.getClaimableAmount(address_entry), true, graceblock);
        success = true;
    } catch (Exception e) {
        Logger.logErrorMessage(e.getMessage());
    }
    return success;
}
Also used : NetworkParameters(org.bitcoinj.core.NetworkParameters) ECKey(org.bitcoinj.core.ECKey) DumpedPrivateKey(org.bitcoinj.core.DumpedPrivateKey)

Aggregations

NetworkParameters (org.bitcoinj.core.NetworkParameters)14 Address (org.bitcoinj.core.Address)5 ECKey (org.bitcoinj.core.ECKey)5 InputStream (java.io.InputStream)2 BigInteger (java.math.BigInteger)2 DumpedPrivateKey (org.bitcoinj.core.DumpedPrivateKey)2 Transaction (org.bitcoinj.core.Transaction)2 MnemonicCode (org.bitcoinj.crypto.MnemonicCode)2 SharedPreferences (android.content.SharedPreferences)1 UserThread (bisq.common.UserThread)1 TaskRunner (bisq.common.taskrunner.TaskRunner)1 AddressEntry (bisq.core.btc.AddressEntry)1 AddressConfidenceListener (bisq.core.btc.listeners.AddressConfidenceListener)1 BtcWalletService (bisq.core.btc.wallet.BtcWalletService)1 Trade (bisq.core.trade.Trade)1 TradeTask (bisq.core.trade.protocol.tasks.TradeTask)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ByteString (com.google.protobuf.ByteString)1 HD_Wallet (com.samourai.wallet.hd.HD_Wallet)1