org.bitcoinj.core.DumpedPrivateKey Java Examples

The following examples show how to use org.bitcoinj.core.DumpedPrivateKey. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TransactionsHelper.java    From smartcoins-wallet with MIT License 6 votes vote down vote up
private void decodeAllMemosInTransactionsReceived(final List<JSONObject> memosArray) {
        ECKey toKey;
        toKey = ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, wifkey).getKey().getPrivKeyBytes());

        for (JSONObject memoObject : memosArray) {
            try {
                String message = memoObject.get("message").toString();
                PublicKey fromKey = new Address(memoObject.get("from").toString()).getPublicKey();
                String nonce = memoObject.get("nonce").toString();
//                if (memosToDecodeHm.containsKey(memoObject)) {
//                    memosToDecodeHm.put(memoObject, Memo.decodeMessage(fromKey, toKey, message, nonce));
//                }
                decodingMemosComplete();

            } catch (JSONException | MalformedAddressException e) {
                e.printStackTrace();
            }
        }
    }
 
Example #2
Source File: TransactionsHelper.java    From smartcoins-wallet with MIT License 6 votes vote down vote up
private void decodeMemoTransactionsReceived(final JSONObject memoObject) {
        ECKey toKey;
        toKey = ECKey.fromPrivate(DumpedPrivateKey.fromBase58(null, wifkey).getKey().getPrivKeyBytes());
        if (context == null) return;
        try {
            String message = memoObject.get("message").toString();
            PublicKey fromKey = new Address(memoObject.get("from").toString()).getPublicKey();
            String nonce = memoObject.get("nonce").toString();

//            if (memosToDecodeHm.containsKey(memoObject)) {
//                memosToDecodeHm.put(memoObject, Memo.decodeMessage(fromKey, toKey, message, nonce));
//            }
            loadMemoSListForDecoding();

        } catch (JSONException | MalformedAddressException e) {
            e.printStackTrace();
        }
    }
 
Example #3
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlockByWif2(String wif, Runnable callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(wif));
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (WrongNetworkException wne) {
        Log.e("psd", "restoreFromBlockByWif2: " + wne.toString());
        callback.run();
        return;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif2: " + iae.toString());
        callback.run();
        return;
    }

    callback.run();

    RequestorBtc.getUTXOListQtum(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #4
Source File: ECKeyDeserializer.java    From consensusj with Apache License 2.0 5 votes vote down vote up
@Override
public ECKey deserialize(JsonParser p, DeserializationContext ctxt) throws IOException, JsonProcessingException {
    JsonToken token = p.getCurrentToken();
    switch (token) {
        case VALUE_STRING:
            try {
                return DumpedPrivateKey.fromBase58(null, p.getValueAsString()).getKey();
            } catch (AddressFormatException e) {
                throw new InvalidFormatException(p, "Invalid Key", p.getValueAsString(), ECKey.class);
            }
        default:
            return (ECKey) ctxt.handleUnexpectedToken(ECKey.class, p);
    }
}
 
Example #5
Source File: BinHelper.java    From smartcoins-wallet with MIT License 5 votes vote down vote up
public void getBinBytesFromWif(final String pin, final String wif_key, final String accountName) {
    Log.d(TAG, "getBinBytesFromWif. pin: " + pin + ", wif_key: " + wif_key + ", accountName: " + accountName);
    //Fill with an invalid brainkey to not break the backup format (The presence of brainkey seems mandatory)
    BrainKey brainKey = new BrainKey("NOT A VALID BRAINKEY (PREVIOUSLY WIF IMPORTED ACCOUNT)", 0);
    try {
        ArrayList<Wallet> wallets = new ArrayList<>();
        ArrayList<LinkedAccount> accounts = new ArrayList<>();
        ArrayList<PrivateKeyBackup> keys = new ArrayList<>();

        Wallet wallet = new Wallet(accountName, brainKey.getBrainKey(), brainKey.getSequenceNumber(), Chains.BITSHARES.CHAIN_ID, pin);
        wallets.add(wallet);
        String wif = Crypt.getInstance().decrypt_string(wif_key);
        ECKey key = DumpedPrivateKey.fromBase58(NetworkParameters.fromID(NetworkParameters.ID_MAINNET), wif).getKey();

        PrivateKeyBackup keyBackup = new PrivateKeyBackup(key.getPrivKeyBytes(),
                brainKey.getSequenceNumber(),
                brainKey.getSequenceNumber(),
                wallet.getEncryptionKey(pin));
        keys.add(keyBackup);

        LinkedAccount linkedAccount = new LinkedAccount(accountName, Chains.BITSHARES.CHAIN_ID);
        accounts.add(linkedAccount);

        WalletBackup backup = new WalletBackup(wallets, keys, accounts);
        byte[] results = FileBin.serializeWalletBackup(backup, pin);
        List<Integer> resultFile = new ArrayList<>();
        for (byte result : results) {
            resultFile.add(result & 0xff);
        }
        saveBinContentToFile(resultFile, accountName);
    } catch (Exception e) {
        hideDialog(false);
        Log.e(TAG, "Exception. Msg: " + e.getMessage());
        Toast.makeText(myActivity, myActivity.getResources().getString(R.string.unable_to_generate_bin_format_for_key), Toast.LENGTH_SHORT).show();
    }
}
 
Example #6
Source File: PrivateKey.java    From evt4j with MIT License 5 votes vote down vote up
private PrivateKey(@NotNull String wif) throws WifFormatException {
    NetworkParameters networkParam = MainNetParams.get();

    if (wif.length() != 51 && wif.length() != 52) {
        throw new WifFormatException("Wif length must be 51 or 52");
    }

    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(networkParam, wif);
        key = dumpedPrivateKey.getKey();
    } catch (AddressFormatException ex) {
        throw new WifFormatException(ex.getMessage(), ex);
    }
}
 
Example #7
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlockByWif2(String wif, Runnable callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(wif));
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (WrongNetworkException wne) {
        Log.e("psd", "restoreFromBlockByWif2: " + wne.toString());
        callback.run();
        return;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif2: " + iae.toString());
        callback.run();
        return;
    }

    callback.run();

    RequestorBtc.getUTXOListBch(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #8
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlockByWif(String wif, WalletCreationCallback callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif: " + iae.toString());
        callback.onWalletCreated(wallet);
        return;
    }

    callback.onWalletCreated(wallet);

    RequestorBtc.getUTXOListBch(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #9
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlockByWif2(String wif, Runnable callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(wif));
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (WrongNetworkException wne) {
        Log.e("psd", "restoreFromBlockByWif2: " + wne.toString());
        callback.run();
        return;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif2: " + iae.toString());
        callback.run();
        return;
    }

    callback.run();

    RequestorBtc.getUTXOListBtgNew(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #10
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlockByWif(String wif, WalletCreationCallback callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif: " + iae.toString());
        callback.onWalletCreated(wallet);
        return;
    }

    callback.onWalletCreated(wallet);

    RequestorBtc.getUTXOListBtgNew(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #11
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlockByWif(String wif, WalletCreationCallback callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif: " + iae.toString());
        callback.onWalletCreated(wallet);
        return;
    }

    callback.onWalletCreated(wallet);

    RequestorBtc.getUTXOList(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            UTXOListResponse utxoResponse = (UTXOListResponse) response;
            setUTXO(utxoResponse.getUTXOList());
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #12
Source File: BitcoinTransaction.java    From token-core-android with Apache License 2.0 5 votes vote down vote up
private void collectPrvKeysAndAddress(String segWit, String password, Wallet wallet) {
  this.network = wallet.getMetadata().isMainNet() ? MainNetParams.get() : TestNet3Params.get();
  if (wallet.getMetadata().getSource().equals(Metadata.FROM_WIF)) {
    changeAddress = Address.fromBase58(network, wallet.getAddress());
    BigInteger prvKey = DumpedPrivateKey.fromBase58(network, wallet.exportPrivateKey(password)).getKey().getPrivKey();
    prvKeys = Collections.singletonList(prvKey);
  } else {
    prvKeys = new ArrayList<>(getOutputs().size());
    String xprv = new String(wallet.decryptMainKey(password), Charset.forName("UTF-8"));
    DeterministicKey xprvKey = DeterministicKey.deserializeB58(xprv, network);
    DeterministicKey changeKey = HDKeyDerivation.deriveChildKey(xprvKey, ChildNumber.ONE);
    DeterministicKey indexKey = HDKeyDerivation.deriveChildKey(changeKey, new ChildNumber(getChangeIdx(), false));
    if (Metadata.P2WPKH.equals(segWit)) {
      changeAddress = new SegWitBitcoinAddressCreator(network).fromPrivateKey(indexKey);
    } else {
      changeAddress = indexKey.toAddress(network);
    }

    for (UTXO output : getOutputs()) {
      String derivedPath = output.getDerivedPath().trim();
      String[] pathIdxs = derivedPath.replace('/', ' ').split(" ");
      int accountIdx = Integer.parseInt(pathIdxs[0]);
      int changeIdx = Integer.parseInt(pathIdxs[1]);

      DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(xprvKey, new ChildNumber(accountIdx, false));
      DeterministicKey externalChangeKey = HDKeyDerivation.deriveChildKey(accountKey, new ChildNumber(changeIdx, false));
      prvKeys.add(externalChangeKey.getPrivKey());
    }
  }
}
 
Example #13
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlockByWif(String wif, WalletCreationCallback callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif: " + iae.toString());
        callback.onWalletCreated(wallet);
        return;
    }

    callback.onWalletCreated(wallet);

    RequestorBtc.getUTXOListQtum(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #14
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlockByWif(String wif, WalletCreationCallback callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif: " + iae.toString());
        callback.onWalletCreated(wallet);
        return;
    }

    callback.onWalletCreated(wallet);

    RequestorBtc.getUTXOListSbtcNew(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            try {
                List<UTXOItem> utxos = (List<UTXOItem>) response;
                setUTXO(utxos);
            } catch (ClassCastException cce) {
                Log.d("psd", "restoreFromBlockByWif - getUTXOList ClassCastException: " + cce.getMessage());
                cce.printStackTrace();
            }

        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #15
Source File: WIFValidator.java    From token-core-android with Apache License 2.0 5 votes vote down vote up
@Override
public String validate() {
  try {
    DumpedPrivateKey.fromBase58(network, wif);
  } catch (WrongNetworkException addressException) {
    throw new TokenException(Messages.WIF_WRONG_NETWORK);
  } catch (AddressFormatException addressFormatException) {
    throw new TokenException(Messages.WIF_INVALID);
  }
  if (requireCompressed && !DumpedPrivateKey.fromBase58(network, wif).getKey().isCompressed()) {
    throw new TokenException(Messages.SEGWIT_NEEDS_COMPRESS_PUBLIC_KEY);
  }
  return this.wif;
}
 
Example #16
Source File: SegWitBitcoinAddressCreator.java    From token-core-android with Apache License 2.0 5 votes vote down vote up
@Override
public String fromPrivateKey(String prvKeyHex) {
  ECKey key;
  if (prvKeyHex.length() == 51 || prvKeyHex.length() == 52) {
    DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(networkParameters, prvKeyHex);
    key = dumpedPrivateKey.getKey();
    if (!key.isCompressed()) {
      throw new TokenException(Messages.SEGWIT_NEEDS_COMPRESS_PUBLIC_KEY);
    }
  } else {
    key = ECKey.fromPrivate(NumericUtil.hexToBytes(prvKeyHex), true);
  }
  return calcSegWitAddress(key.getPubKeyHash());
}
 
Example #17
Source File: BitcoinAddressCreator.java    From token-core-android with Apache License 2.0 5 votes vote down vote up
@Override
public String fromPrivateKey(String prvKeyHex) {
  ECKey key;
  if (prvKeyHex.length() == 51 || prvKeyHex.length() == 52) {
    DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(networkParameters, prvKeyHex);
    key = dumpedPrivateKey.getKey();
  } else {
    key = ECKey.fromPrivate(NumericUtil.hexToBytes(prvKeyHex));
  }
  return key.toAddress(this.networkParameters).toBase58();
}
 
Example #18
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlockByWif(String wif, WalletCreationCallback callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif: " + iae.toString());
        callback.onWalletCreated(wallet);
        return;
    }

    callback.onWalletCreated(wallet);

    RequestorBtc.getUTXOListDgbNew(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItemDgb> utxos = (List<UTXOItemDgb>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #19
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlockByWif2(String wif, Runnable callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(wif));
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (WrongNetworkException wne) {
        Log.e("psd", "restoreFromBlockByWif2: " + wne.toString());
        callback.run();
        return;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif2: " + iae.toString());
        callback.run();
        return;
    }

    callback.run();

    RequestorBtc.getUTXOListLtcNew(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #20
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void createWallet2_wif(String passphrase, Runnable callback) {
        wallet = new Wallet(params);
//        DeterministicSeed seed = wallet.getKeyChainSeed();
//
//        mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode());
        mnemonicKey = wallet.freshReceiveKey().getPrivateKeyAsWiF(params);
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, mnemonicKey);
        ECKey key = dumpedPrivateKey.getKey();
        wallet.importKey(key);

        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        walletFriendlyAddress = testReadonlyAddress == null ? walletFriendlyAddress : testReadonlyAddress;
        callback.run();
    }
 
Example #21
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlock(String mnemonicCode, WalletCreationCallback callback) {
        mnemonicCode = mnemonicCode.trim();
        if (mnemonicCode.equals("")) {
            callback.onWalletCreated(null);
            return;
        }

        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, anyToWif(mnemonicCode));
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        mnemonicKey = mnemonicCode;
//        sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));

        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toBase58();
        walletFriendlyAddress = testReadonlyAddress == null ? walletFriendlyAddress : testReadonlyAddress;

        callback.onWalletCreated(wallet);

        RequestorBtc.getUTXOListKmdNew(walletFriendlyAddress, new ApiMethods.RequestListener() {
            @Override
            public void onSuccess(Object response) {
                List<UTXOItem> utxos = (List<UTXOItem>)response;
                setUTXO(utxos);
            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }
 
Example #22
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlock0(String mnemonicCode, Runnable callback) {
        if (mnemonicCode.charAt(mnemonicCode.length() - 1) == ' ') {
            mnemonicCode = mnemonicCode.substring(0, mnemonicCode.length() - 1);
        }

        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, anyToWif(mnemonicCode));
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        mnemonicKey = mnemonicCode;
//        sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));

        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toBase58();
        walletFriendlyAddress = testReadonlyAddress == null ? walletFriendlyAddress : testReadonlyAddress;

        callback.run();

        RequestorBtc.getUTXOListKmdNew(walletFriendlyAddress, new ApiMethods.RequestListener() {
            @Override
            public void onSuccess(Object response) {
                List<UTXOItem> utxos = (List<UTXOItem>)response;
                setUTXO(utxos);
            }

            @Override
            public void onFailure(String msg) {

            }
        });
    }
 
Example #23
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlock2(String mnemonicCode, Runnable callback) {
    if (mnemonicCode.charAt(mnemonicCode.length() - 1) == ' ') {
        mnemonicCode = mnemonicCode.substring(0, mnemonicCode.length() - 1);
    }

    DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, anyToWif(mnemonicCode));
    ECKey key = dumpedPrivateKey.getKey();
    wallet = new Wallet(params);
    wallet.importKey(key);
    mnemonicKey = mnemonicCode;
    sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey));

    walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toBase58();
    walletFriendlyAddress = testReadonlyAddress == null ? walletFriendlyAddress : testReadonlyAddress;

    callback.run();

    RequestorBtc.getUTXOListKmdNew(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #24
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
public void restoreFromBlockByWif(String wif, WalletCreationCallback callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif: " + iae.toString());
        callback.onWalletCreated(wallet);
        return;
    }

    callback.onWalletCreated(wallet);

    RequestorBtc.getUTXOListLtcNew(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItem> utxos = (List<UTXOItem>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #25
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
public void restoreFromBlockByWif2(String wif, Runnable callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(wif));
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (WrongNetworkException wne) {
        Log.e("psd", "restoreFromBlockByWif2: " + wne.toString());
        callback.run();
        return;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif2: " + iae.toString());
        callback.run();
        return;
    }

    callback.run();

    RequestorBtc.getUTXOListSbtcNew(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            try {
                List<UTXOItem> utxos = (List<UTXOItem>)response;
                setUTXO(utxos);
            } catch (ClassCastException cce) {
                Log.d("psd", "restoreFromBlockByWif2 - getUTXOList ClassCastException: " + cce.getMessage());
            }
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #26
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
public void restoreFromBlockByWif2(String wif, Runnable callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(wif));
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (WrongNetworkException wne) {
        Log.e("psd", "restoreFromBlockByWif2: " + wne.toString());
        callback.run();
        return;
    } catch (AddressFormatException afe) {
        Log.e("psd", "restoreFromBlockByWif2: " + afe.toString());
        callback.run();
        return;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif2: " + iae.toString());
        callback.run();
        return;
    }

    callback.run();

    RequestorBtc.getUTXOListDgbNew(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            List<UTXOItemDgb> utxos = (List<UTXOItemDgb>)response;
            setUTXO(utxos);
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}
 
Example #27
Source File: Validator.java    From balzac with Apache License 2.0 4 votes vote down vote up
public static ValidationResult validatePrivateKey(String wif, NetworkType params) {
    return base58ExceptionHandler(() -> {
        DumpedPrivateKey.fromBase58(params.toNetworkParameters(), wif);
    });
}
 
Example #28
Source File: PrivateKey.java    From balzac with Apache License 2.0 4 votes vote down vote up
public static PrivateKey fromBase58(String wif) {
    DumpedPrivateKey key = DumpedPrivateKey.fromBase58(null, wif);
    return from(key.getKey().getPrivKeyBytes(), NetworkType.from(key.getParameters()));
}
 
Example #29
Source File: TabActivity.java    From smartcoins-wallet with MIT License 4 votes vote down vote up
/**
     * Method that will actually perform a call to the full node and update the key controlling
     * the account specified at the private field called 'updatingAccount'.
     */
    private void updateAccountAuthorities() {
        UserAccount account = currentTask.getAccount();
        BrainKey brainKey = currentTask.getBrainKey();
        oldKey = String.format("%s:%s", account.getName(), brainKey.getWalletImportFormat());

        Log.d(TAG, "updateAccountAuthorities. account to update: " + account.getName() + ", id: " + account.getObjectId());
        Log.d(TAG, "current brain key: " + brainKey.getBrainKey());
        try {
            // Coming up with a new brain key suggestion
            BufferedReader reader = new BufferedReader(new InputStreamReader(getAssets().open(AccountActivity.BRAINKEY_FILE), "UTF-8"));
            String dictionary = reader.readLine();
            String suggestion = BrainKey.suggest(dictionary);
            newBrainKey = new BrainKey(suggestion, 0);

            /* Keeping this suggestion in shared preferences in case we get interrupted */
            storeSuggestion(suggestion);

            /* Storing the key in the database for long-term */
            database.insertKey(newBrainKey);

            Log.d(TAG, "new brain key: " + suggestion);

            // Keeping a reference of the account to be changed, with the updated values
            Address address = new Address(ECKey.fromPublicOnly(newBrainKey.getPrivateKey().getPubKey()));

            // Building a transaction that will be used to update the account key
            HashMap<PublicKey, Long> authMap = new HashMap<>();
            authMap.put(address.getPublicKey(), 1L);
            Authority authority = new Authority(1, authMap, null);
            AccountOptions options = new AccountOptions(address.getPublicKey());
            AccountUpdateOperationBuilder builder = new AccountUpdateOperationBuilder()
                    .setAccount(currentTask.getAccount())
                    .setActive(authority)
                    .setOptions(options);

            AccountUpdateOperation op = builder.build();

            if (currentTask.isUpdateOwner()) {
                // Only changing the "owner" authority in some cases.
                op.setOwner(authority);
            }
//            if(currentTask.isUpdateMemo()){
//                // Only changing the "memo" authority if it is the same as the active.
//                builder.setOptions(options);
//            }

            ArrayList<BaseOperation> operations = new ArrayList<>();
            operations.add(op);
            Date date = Calendar.getInstance().getTime();
            long expirationTime = (date.getTime() / 1000) + Transaction.DEFAULT_EXPIRATION_TIME;
            BlockData blockData = new BlockData(Application.refBlockNum, Application.refBlockPrefix, expirationTime);
            Transaction transaction = new Transaction(DumpedPrivateKey.fromBase58(null, brainKey.getWalletImportFormat()).getKey(), blockData, operations);

            refreshKeyWorker = new WebsocketWorkerThread(new TransactionBroadcastSequence(transaction, new Asset("1.3.0"), refreshKeysListener), nodeIndex);
            refreshKeyWorker.start();
        } catch (IOException e) {
            Log.e(TAG, "IOException. Msg: " + e.getMessage());
        }
    }
 
Example #30
Source File: WalletManager.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
public void restoreFromBlockByWif2(String wif, Runnable callback) {
    wif = wif.trim();
    try {
        DumpedPrivateKey dumpedPrivateKey = DumpedPrivateKey.fromBase58(params, wif);
        ECKey key = dumpedPrivateKey.getKey();
        wallet = new Wallet(params);
        wallet.importKey(key);
        restFromWif = true;
        sharedManager.setLastSyncedBlock(Coders.encodeBase64(wif));
        walletFriendlyAddress = wallet.getImportedKeys().get(0).toAddress(params).toString();
        wifKey = wif;
    } catch (WrongNetworkException wne) {
        FirebaseCrash.report(wne);
        Log.e("psd", "restoreFromBlockByWif2: " + wne.toString());
        callback.run();
        return;
    } catch (IllegalArgumentException iae) {
        FirebaseCrash.report(iae);
        Log.e("psd", "restoreFromBlockByWif2: " + iae.toString());
        callback.run();
        return;
    } catch (NullPointerException npe) {
        FirebaseCrash.report(npe);
        Log.e("psd", "restoreFromBlockByWif2: " + npe.toString());
        callback.run();
        return;
    }

    callback.run();

    RequestorBtc.getUTXOList(walletFriendlyAddress, new ApiMethods.RequestListener() {
        @Override
        public void onSuccess(Object response) {
            UTXOListResponse utxoResponse = (UTXOListResponse) response;
            setUTXO(utxoResponse.getUTXOList());
        }

        @Override
        public void onFailure(String msg) {

        }
    });
}