Search in sources :

Example 6 with NetworkParameters

use of org.bitcoinj.core.NetworkParameters in project cryptoputty by alokmenghrajani.

the class CryptoputtyApplication method initialize.

@Override
public void initialize(final Bootstrap<CryptoputtyConfiguration> bootstrap) {
    bootstrap.addBundle(new ViewBundle<>());
    NetworkParameters params = TestNet3Params.get();
    File tempDir = Files.createTempDir();
    tempDir.deleteOnExit();
    kit = new WalletAppKit(params, tempDir, "cryptoputty");
    try {
        kit.restoreWalletFromSeed(new DeterministicSeed("office suit release flame robust know depth truly swim bird quality reopen", null, "", 1522261414L));
        kit.setBlockingStartup(false);
        kit.setAutoSave(true);
        kit.startAsync();
        kit.awaitRunning();
        // Perhaps having bloom filters doesn't hurt since we don't plan to do anything
        // kit.peerGroup().setBloomFilteringEnabled(false);
        // I have no idea what I'm doing, but let's increase these max values.
        kit.peerGroup().setMaxPeersToDiscoverCount(10000);
        kit.peerGroup().setMaxConnections(5000);
        log.info(format("send money to: %s", kit.wallet().freshReceiveAddress().toString()));
        log.info("done initializing");
    } catch (UnreadableWalletException e) {
        e.printStackTrace();
    }
}
Also used : DeterministicSeed(org.bitcoinj.wallet.DeterministicSeed) UnreadableWalletException(org.bitcoinj.wallet.UnreadableWalletException) NetworkParameters(org.bitcoinj.core.NetworkParameters) WalletAppKit(org.bitcoinj.kits.WalletAppKit) File(java.io.File)

Example 7 with NetworkParameters

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

the class HD_WalletFactory method restoreWallet.

public HD_Wallet restoreWallet(String data, String passphrase, int nbAccounts) throws AddressFormatException, DecoderException {
    HD_Wallet hdw = null;
    if (passphrase == null) {
        passphrase = "";
    }
    NetworkParameters params = MainNetParams.get();
    if (data.startsWith("xpub") || data.startsWith("ypub")) {
        String[] xpub = data.split(":");
        // Log.i("HD_WalletFactory", "xpubs:" + xpub.length);
        hdw = new HD_Wallet(params, xpub);
    }
    if (hdw == null) {
        PrefsUtil.getInstance(context).clear();
        return null;
    }
    wallets.clear();
    wallets.add(hdw);
    return hdw;
}
Also used : NetworkParameters(org.bitcoinj.core.NetworkParameters)

Example 8 with NetworkParameters

use of org.bitcoinj.core.NetworkParameters in project catena-java by alinush.

the class WrongPkTest method testWrongPk.

/**
 * Couldn't make this test work initially, not easily at least. Because the root-of-trust TXN is not saved in the wallet
 * when the wallet is initialized with the wrong PK, since the TXN doesn't transfer any funds and seems irrelevant
 * to the wallet. As a result, processRootOfTrustTxn fails because there's no TXN in the wallet. So we had to call
 * processRootOfTrustTxn manually here.
 *
 * @throws InsufficientMoneyException
 * @throws IOException
 * @throws InterruptedException
 * @throws TimeoutException
 */
@Test
public void testWrongPk() throws InsufficientMoneyException, IOException, InterruptedException, TimeoutException {
    log.info("Test: Fail if the chain PK in the root-of-trust TX differs from the expected one");
    // Replace the expected chain PK with a random one.
    ECKey key = new ECKey();
    super.expectedChainAddr = key.toAddress(params);
    // The Catena client should stop when it encounters a different PK in the root-of-trust TX
    final Semaphore sem = new Semaphore(0);
    walletFactory = new WalletFactory() {

        @Override
        public Wallet create(NetworkParameters params, KeyChainGroup keyChainGroup) {
            log.info("Creating custom wallet that whistleblows on a wrong chain address...");
            ClientWallet wallet = new ClientWallet.Factory().create(params, keyChainGroup);
            wallet.addWhistleblowListener(new CatenaWhistleblowListener() {

                @Override
                public void onWhistleblow(Transaction tx, String message) {
                    log.info("Whistleblowing for tx {}: {}", tx.getHash(), message);
                    sem.release();
                    catenaClient.stopAsync();
                }
            });
            return wallet;
        }
    };
    createCatenaClient(txid, false);
    catenaClient.startAsync();
    catenaClient.awaitRunning();
    // We are cheating here: We're feeding the Catena server-created root-of-trust TXN to the Catena client manually
    catenaClient.getCatenaWallet().processRootOfTrustTxn(rootOfTrustTxn);
    Assert.assertTrue("Catena client should have whistleblown due to wrong PK", sem.tryAcquire(5, TimeUnit.SECONDS));
    catenaClient.stopAsync();
    catenaClient.awaitTerminated(3, TimeUnit.SECONDS);
    Assert.assertTrue(catenaClient.state() == State.TERMINATED);
}
Also used : Transaction(org.bitcoinj.core.Transaction) NetworkParameters(org.bitcoinj.core.NetworkParameters) Wallet(org.bitcoinj.wallet.Wallet) KeyChainGroup(org.bitcoinj.wallet.KeyChainGroup) WalletFactory(org.bitcoinj.wallet.WalletProtobufSerializer.WalletFactory) LoggerFactory(org.slf4j.LoggerFactory) WalletFactory(org.bitcoinj.wallet.WalletProtobufSerializer.WalletFactory) ECKey(org.bitcoinj.core.ECKey) Semaphore(java.util.concurrent.Semaphore) Test(org.junit.Test) ClientServerTest(org.catena.common.ClientServerTest)

Example 9 with NetworkParameters

use of org.bitcoinj.core.NetworkParameters in project Bitcoin-Brainwallet-PasswordCrackPlatform by Dimou-John.

the class AddressGenerator method AddressGenerator.

public static String AddressGenerator(String rest) throws IOException {
    NetworkParameters mainNet = MainNetParams.get();
    String newline = rest;
    rest = getSha256(rest);
    BigInteger big = new BigInteger(rest, 16);
    // uncompressed
    ECKey key = ECKey.fromPrivate(big, false);
    byte[] priv = key.getPrivKeyBytes();
    byte[] bytes = new byte[1 + 32 + 4];
    bytes[0] = (byte) 0x80;
    System.arraycopy(priv, 0, bytes, 1, 32);
    byte[] checksum = Sha256Hash.hashTwice(bytes, 0, 33);
    System.arraycopy(checksum, 0, bytes, 33, 4);
    String wif3 = Base58.encode(bytes);
    Address s = key.toAddress(mainNet);
    String Stringed = s.toString();
    return Stringed;
}
Also used : Address(org.bitcoinj.core.Address) NetworkParameters(org.bitcoinj.core.NetworkParameters) BigInteger(java.math.BigInteger) ECKey(org.bitcoinj.core.ECKey)

Example 10 with NetworkParameters

use of org.bitcoinj.core.NetworkParameters in project Bitcoin-Brainwallet-PasswordCrackPlatform by Dimou-John.

the class PrivateKeyGetter method PrivateKeyGetter.

public static String PrivateKeyGetter(String rest) throws IOException {
    NetworkParameters mainNet = MainNetParams.get();
    rest = getSha256(rest);
    BigInteger big = new BigInteger(rest, 16);
    // uncompressed
    ECKey key = ECKey.fromPrivate(big, false);
    byte[] priv = key.getPrivKeyBytes();
    byte[] bytes = new byte[1 + 32 + 4];
    bytes[0] = (byte) 0x80;
    System.arraycopy(priv, 0, bytes, 1, 32);
    byte[] checksum = Sha256Hash.hashTwice(bytes, 0, 33);
    System.arraycopy(checksum, 0, bytes, 33, 4);
    String wif3 = Base58.encode(bytes);
    Address s = key.toAddress(mainNet);
    String Stringed = s.toString();
    return wif3;
}
Also used : Address(org.bitcoinj.core.Address) NetworkParameters(org.bitcoinj.core.NetworkParameters) BigInteger(java.math.BigInteger) ECKey(org.bitcoinj.core.ECKey)

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