net.bither.bitherj.core.HDMKeychain Java Examples

The following examples show how to use net.bither.bitherj.core.HDMKeychain. 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: AbstractAddressProvider.java    From bitherj with Apache License 2.0 6 votes vote down vote up
@Override
public List<HDMAddress> getHDMAddressInUse(HDMKeychain keychain) {
    String sql = "select hd_seed_index,pub_key_hot,pub_key_cold,pub_key_remote,address,is_synced " +
            " from hdm_addresses " +
            " where hd_seed_id=? and address is not null order by hd_seed_index";
    final List<HDMAddress> addresses = new ArrayList<HDMAddress>();
    final HDMKeychain hdmKeychain = keychain;
    this.execQueryLoop(sql, new String[]{Integer.toString(keychain.getHdSeedId())}, new Function<ICursor, Void>() {
        @Nullable
        @Override
        public Void apply(@Nullable ICursor c) {
            HDMAddress hdmAddress = applyHDMAddress(c, hdmKeychain);
            if (hdmAddress != null) {
                addresses.add(hdmAddress);
            }
            return null;
        }
    });
    return addresses;
}
 
Example #2
Source File: CheckUtil.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
public static Check initCheckForHDMKeychain(final HDMKeychain keychain, final SecureCharSequence password) {
    String title = LocaliserUtils.getString("hdm_keychain_check_title_cold");
    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.HOT) {
        title = LocaliserUtils.getString("hdm_keychain_check_title_hot");
    }
    Check check = new Check(title, new ICheckAction() {
        @Override
        public boolean check() {
            boolean result = false;
            try {
                result = keychain.checkWithPassword(password);
                if (result) {
                    result = keychain.checkSingularBackupWithPassword(password);
                }
                //TODO need to check backup here?
            } catch (Exception e) {
                e.printStackTrace();
            }
            password.wipe();
            return result;
        }
    });
    return check;
}
 
Example #3
Source File: HDMSingular.java    From bitherj with Apache License 2.0 6 votes vote down vote up
private DeterministicKey rootFromMnemonic(byte[] mnemonic) {
    try {
        byte[] hdSeed = HDMKeychain.seedFromMnemonic(mnemonic);
        DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(hdSeed);
        DeterministicKey purpose = master.deriveHardened(44);
        DeterministicKey coinType = purpose.deriveHardened(0);
        DeterministicKey account = coinType.deriveHardened(0);
        DeterministicKey external = account.deriveSoftened(0);
        master.wipe();
        purpose.wipe();
        coinType.wipe();
        account.wipe();
        return external;
    } catch (MnemonicException.MnemonicLengthException e) {
        throw new RuntimeException(e);
    }
}
 
Example #4
Source File: AddressProvider.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public List<HDMAddress> getHDMAddressInUse(HDMKeychain keychain) {
    List<HDMAddress> addresses = new ArrayList<HDMAddress>();

    try {
        ResultSet c = null;

        String sql = "select hd_seed_index,pub_key_hot,pub_key_cold,pub_key_remote,address,is_synced " +
                "from hdm_addresses " +
                "where hd_seed_id=? and address is not null order by hd_seed_index";
        PreparedStatement statement = this.mDb.getPreparedStatement(sql, new String[]{Integer.toString(keychain.getHdSeedId())});
        c = statement.executeQuery();
        while (c.next()) {
            HDMAddress hdmAddress = applyHDMAddress(c, keychain);
            if (hdmAddress != null) {
                addresses.add(hdmAddress);
            }
        }
        c.close();
        statement.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return addresses;
}
 
Example #5
Source File: CheckUtil.java    From bither-android with Apache License 2.0 6 votes vote down vote up
public static Check initCheckForHDMKeychain(final HDMKeychain keychain, final SecureCharSequence password) {
    int titleResource = R.string.hdm_keychain_check_title_cold;
    if (AppSharedPreference.getInstance().getAppMode() == BitherjSettings.AppMode.HOT) {
        titleResource = R.string.hdm_keychain_check_title_hot;
    }
    String title = BitherApplication.mContext.getString(titleResource);
    Check check = new Check(title, new ICheckAction() {
        @Override
        public boolean check() {
            boolean result = false;
            try {
                result = keychain.checkWithPassword(password);
                //TODO need to check backup here?
                if(result){
                    result = keychain.checkSingularBackupWithPassword(password);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            password.wipe();
            return result;
        }
    });
    return check;
}
 
Example #6
Source File: AddressProvider.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
@Override
public List<HDMAddress> getHDMAddressInUse(HDMKeychain keychain) {
    List<HDMAddress> addresses = new ArrayList<HDMAddress>();

    try {
        ResultSet c = null;

        String sql = "select hd_seed_index,pub_key_hot,pub_key_cold,pub_key_remote,address,is_synced " +
                "from hdm_addresses " +
                "where hd_seed_id=? and address is not null order by hd_seed_index";
        PreparedStatement statement = this.mDb.getPreparedStatement(sql, new String[]{Integer.toString(keychain.getHdSeedId())});
        c = statement.executeQuery();
        while (c.next()) {
            HDMAddress hdmAddress = applyHDMAddress(c, keychain);
            if (hdmAddress != null) {
                addresses.add(hdmAddress);
            }
        }
        c.close();
        statement.close();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return addresses;
}
 
Example #7
Source File: CheckUtil.java    From bither-desktop-java with Apache License 2.0 6 votes vote down vote up
public static Check initCheckForHDMKeychain(final HDMKeychain keychain, final SecureCharSequence password) {
    String title = LocaliserUtils.getString("hdm_keychain_check_title_cold");
    if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.HOT) {
        title = LocaliserUtils.getString("hdm_keychain_check_title_hot");
    }
    Check check = new Check(title, new ICheckAction() {
        @Override
        public boolean check() {
            boolean result = false;
            try {
                result = keychain.checkWithPassword(password);
                if (result) {
                    result = keychain.checkSingularBackupWithPassword(password);
                }
                //TODO need to check backup here?
            } catch (Exception e) {
                e.printStackTrace();
            }
            password.wipe();
            return result;
        }
    });
    return check;
}
 
Example #8
Source File: HDMSingularDesktop.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public void server() {
    new Thread() {
        @Override
        public void run() {
            callInServer(new HDMHotAdd.IGenerateHDMKeyChain() {
                @Override
                public void generateHDMKeyChain(HDMKeychain hdmKeychain) {
                    KeyUtil.setHDKeyChain(hdmKeychain);

                }

                @Override
                public void beginCompleteAddress() {
                    PeerUtil.stopPeer();
                }

                @Override
                public void completeAddrees(List<HDMAddress> hdmAddresses) {
                    Bither.refreshFrame();
                }


            });
        }


    }.start();
}
 
Example #9
Source File: PrivateKeyUtil.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public static String getEncryptPrivateKeyStringFromAllAddresses() {
    String content = "";
    List<Address> privates = AddressManager.getInstance().getPrivKeyAddresses();
    for (int i = 0;
         i < privates.size();
         i++) {
        Address address = privates.get(i);
        content += address.getFullEncryptPrivKey();
        if (i < privates.size() - 1) {
            content += QRCodeUtil.QR_CODE_SPLIT;
        }
    }
    HDMKeychain keychain = AddressManager.getInstance().getHdmKeychain();
    if (keychain != null) {
        if (Utils.isEmpty(content)) {
            content += keychain.getQRCodeFullEncryptPrivKey();
        } else {
            content += QRCodeUtil.QR_CODE_SPLIT + keychain.getQRCodeFullEncryptPrivKey();
        }
    }
    HDAccount hdAccount = AddressManager.getInstance().getHDAccountHot();
    if (hdAccount != null) {
        if (Utils.isEmpty(content)) {
            content += hdAccount.getQRCodeFullEncryptPrivKey();
        } else {
            content += QRCodeUtil.QR_CODE_SPLIT + hdAccount.getQRCodeFullEncryptPrivKey();
        }
    }
    HDAccountCold hdAccountCold = AddressManager.getInstance().getHDAccountCold();
    if (hdAccountCold != null) {
        if (Utils.isEmpty(content)) {
            content += hdAccountCold.getQRCodeFullEncryptPrivKey();
        } else {
            content += QRCodeUtil.QR_CODE_SPLIT + hdAccountCold.getQRCodeFullEncryptPrivKey();
        }
    }
    return content;
}
 
Example #10
Source File: HDMSingularAndroid.java    From bither-android with Apache License 2.0 5 votes vote down vote up
public void server() {
    new ThreadNeedService(null, context) {
        @Override
        public void runWithService(final BlockchainService service) {
            callInServer(new HDMHotAdd.IGenerateHDMKeyChain() {
                @Override
                public void generateHDMKeyChain(HDMKeychain hdmKeychain) {
                    KeyUtil.setHDKeyChain(hdmKeychain);

                }

                @Override
                public void beginCompleteAddress() {
                    if (service != null) {
                        service.stopAndUnregister();
                    }
                }

                @Override
                public void completeAddrees(List<HDMAddress> hdmAddresses) {
                    if (service != null) {
                        service.startAndRegister();
                    }
                }


            });
        }
    }.start();
}
 
Example #11
Source File: KeyUtil.java    From bither-android with Apache License 2.0 5 votes vote down vote up
public static void setHDKeyChain(HDMKeychain keyChain) {
    AddressManager.getInstance().setHDMKeychain(keyChain);
    if (AppSharedPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD) {
        BackupUtil.backupColdKey(false);
    } else {
        BackupUtil.backupHotKey();
    }

}
 
Example #12
Source File: HDMSingularDesktop.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public void server() {
    new Thread() {
        @Override
        public void run() {
            callInServer(new HDMHotAdd.IGenerateHDMKeyChain() {
                @Override
                public void generateHDMKeyChain(HDMKeychain hdmKeychain) {
                    KeyUtil.setHDKeyChain(hdmKeychain);

                }

                @Override
                public void beginCompleteAddress() {
                    PeerUtil.stopPeer();
                }

                @Override
                public void completeAddrees(List<HDMAddress> hdmAddresses) {
                    Bither.refreshFrame();
                }


            });
        }


    }.start();
}
 
Example #13
Source File: ColdAddressFragmentHDMListItemView.java    From bither-android with Apache License 2.0 5 votes vote down vote up
public void setKeychain(HDMKeychain chain) {
    this.keychain = chain;
    if (keychain.isFromXRandom()) {
        ibtnXRandomLabel.setVisibility(View.VISIBLE);
    } else {
        ibtnXRandomLabel.setVisibility(View.INVISIBLE);
    }
}
 
Example #14
Source File: ImportHDSeedDesktop.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public void importHDMColdSeed() {
    new Thread() {
        @Override
        public void run() {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    dialogProgress = new DialogProgress();
                    dialogProgress.pack();
                    dialogProgress.setVisible(true);
                }
            });
            HDMKeychain result = importHDMKeychain();
            if (result != null) {
                if (importListener != null) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            importListener.importSuccess();
                        }
                    });
                }
                KeyUtil.setHDKeyChain(result);
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        dialogProgress.dispose();
                        Bither.getCoreController().fireRecreateAllViews(true);
                        new MessageDialog(LocaliserUtils.getString("import_private_key_qr_code_success")).showMsg();
                    }
                });
                Bither.refreshFrame();

            }
        }
    }.start();

}
 
Example #15
Source File: AddAddressColdHDMFragment.java    From bither-android with Apache License 2.0 5 votes vote down vote up
@Override
public void onPasswordEntered(final SecureCharSequence password) {
    btnAdd.setKeepScreenOn(true);
    ThreadNeedService thread = new ThreadNeedService(dp, activity) {

        @Override
        public void runWithService(BlockchainService service) {
            chain = new HDMKeychain(new SecureRandom(), password);
            KeyUtil.setHDKeyChain(chain);
            password.wipe();
            ArrayList<String> addresses = getAddresses();
            Intent intent = new Intent();
            intent.putExtra(BitherSetting.INTENT_REF.ADDRESS_POSITION_PASS_VALUE_TAG,
                    addresses);
            getActivity().setResult(Activity.RESULT_OK, intent);
            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    btnAdd.setKeepScreenOn(false);
                    if (dp.isShowing()) {
                        dp.dismiss();
                    }
                    activity.save();
                }
            });
        }
    };
    thread.start();
}
 
Example #16
Source File: HDMColdPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public HDMColdPanel() {
    super(MessageKey.HDM, AwesomeIcon.FA_RECYCLE);
    passwordGetter = new PasswordPanel.PasswordGetter(HDMColdPanel.this);
    setOkAction(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    final SecureCharSequence password = passwordGetter.getPassword();
                    if (password == null) {
                        return;
                    }
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            closePanel();
                            if (xrandomCheckBox.isSelected()) {
                                HDMKeychainColdUEntropyDialog hdmKeychainColdUEntropyDialog = new HDMKeychainColdUEntropyDialog(passwordGetter);
                                hdmKeychainColdUEntropyDialog.pack();
                                hdmKeychainColdUEntropyDialog.setVisible(true);
                            } else {
                                HDMKeychain chain = new HDMKeychain(new SecureRandom(), password);
                                KeyUtil.setHDKeyChain(chain);
                                password.wipe();
                                Bither.refreshFrame();


                            }
                        }
                    });

                }
            }).start();

        }
    });

    setOkEnabled(AddressManager.getInstance().getHdmKeychain() == null);
}
 
Example #17
Source File: ImportPrivateKeyPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public void run() {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {

        }
    });
    List<Address> addressList = PrivateKeyUtil.getECKeysFromBackupString(content, password);
    HDMKeychain hdmKeychain = PrivateKeyUtil.getHDMKeychain(content, password);

    if ((addressList == null || addressList.size() == 0) && (hdmKeychain == null)) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                dp.dispose();
                new MessageDialog(LocaliserUtils.getString("clone_from_failed")).showMsg();
            }
        });
        return;
    }

    KeyUtil.addAddressListByDesc(addressList);
    if (hdmKeychain != null) {
        KeyUtil.setHDKeyChain(hdmKeychain);
    }
    password.wipe();

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            dp.dispose();
            new MessageDialog(LocaliserUtils.getString("clone_from_success")).showMsg();
            closePanel();
            Bither.refreshFrame();
        }
    });
}
 
Example #18
Source File: ImportPrivateKeyPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public void run() {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {

        }
    });
    List<Address> addressList = PrivateKeyUtil.getECKeysFromBackupString(content, password);
    HDMKeychain hdmKeychain = PrivateKeyUtil.getHDMKeychain(content, password);

    if ((addressList == null || addressList.size() == 0) && (hdmKeychain == null)) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                dp.dispose();
                new MessageDialog(LocaliserUtils.getString("clone_from_failed")).showMsg();
            }
        });
        return;
    }

    KeyUtil.addAddressListByDesc(addressList);
    if (hdmKeychain != null) {
        KeyUtil.setHDKeyChain(hdmKeychain);
    }
    password.wipe();

    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            dp.dispose();
            new MessageDialog(LocaliserUtils.getString("clone_from_success")).showMsg();
            closePanel();
            Bither.refreshFrame();
        }
    });
}
 
Example #19
Source File: HDMColdPanel.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public HDMColdPanel() {
    super(MessageKey.HDM, AwesomeIcon.FA_RECYCLE);
    passwordGetter = new PasswordPanel.PasswordGetter(HDMColdPanel.this);
    setOkAction(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            new Thread(new Runnable() {
                @Override
                public void run() {
                    final SecureCharSequence password = passwordGetter.getPassword();
                    if (password == null) {
                        return;
                    }
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            closePanel();
                            if (xrandomCheckBox.isSelected()) {
                                HDMKeychainColdUEntropyDialog hdmKeychainColdUEntropyDialog = new HDMKeychainColdUEntropyDialog(passwordGetter);
                                hdmKeychainColdUEntropyDialog.pack();
                                hdmKeychainColdUEntropyDialog.setVisible(true);
                            } else {
                                HDMKeychain chain = new HDMKeychain(new SecureRandom(), password);
                                KeyUtil.setHDKeyChain(chain);
                                password.wipe();
                                Bither.refreshFrame();


                            }
                        }
                    });

                }
            }).start();

        }
    });

    setOkEnabled(AddressManager.getInstance().getHdmKeychain() == null);
}
 
Example #20
Source File: ImportHDSeedDesktop.java    From bither-desktop-java with Apache License 2.0 5 votes vote down vote up
public void importHDMColdSeed() {
    new Thread() {
        @Override
        public void run() {
            SwingUtilities.invokeLater(new Runnable() {
                @Override
                public void run() {
                    dialogProgress = new DialogProgress();
                    dialogProgress.pack();
                    dialogProgress.setVisible(true);
                }
            });
            HDMKeychain result = importHDMKeychain();
            if (result != null) {
                if (importListener != null) {
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            importListener.importSuccess();
                        }
                    });
                }
                KeyUtil.setHDKeyChain(result);
                SwingUtilities.invokeLater(new Runnable() {
                    @Override
                    public void run() {
                        dialogProgress.dispose();
                        Bither.getCoreController().fireRecreateAllViews(true);
                        new MessageDialog(LocaliserUtils.getString("import_private_key_qr_code_success")).showMsg();
                    }
                });
                Bither.refreshFrame();

            }
        }
    }.start();

}
 
Example #21
Source File: HDMKeychainColdUEntropyDialog.java    From bither-desktop-java with Apache License 2.0 4 votes vote down vote up
@Override
public void run() {
    boolean success = false;
    final ArrayList<String> addressStrs = new ArrayList<String>();
    double progress = startProgress;
    double itemProgress = (1.0 - startProgress - saveProgress) / (double) targetCount;

    try {
        entropyCollector.start();
        PeerUtil.stopPeer();


        for (int i = 0;
             i < targetCount;
             i++) {
            if (cancelRunnable != null) {
                finishGenerate();
                SwingUtilities.invokeLater(cancelRunnable);
                return;
            }

            XRandom xRandom = new XRandom(entropyCollector);

            if (cancelRunnable != null) {
                finishGenerate();
                SwingUtilities.invokeLater(cancelRunnable);
                return;
            }

            HDMKeychain chain = new HDMKeychain(xRandom, passwordGetter.getPassword());

            progress += itemProgress * progressKeyRate;
            onProgress(progress);
            if (cancelRunnable != null) {
                finishGenerate();
                SwingUtilities.invokeLater(cancelRunnable);
                return;
            }


            progress += itemProgress * progressKeyRate;
            onProgress(progress);
            if (cancelRunnable != null) {
                finishGenerate();
                SwingUtilities.invokeLater(cancelRunnable);

                return;
            }
            // start encrypt
            KeyUtil.setHDKeyChain(chain);

            progress += itemProgress * progressEntryptRate;
            onProgress(progress);
        }
        entropyCollector.stop();
        passwordGetter.wipe();
        if (cancelRunnable != null) {
            finishGenerate();
            SwingUtilities.invokeLater(cancelRunnable);
            return;
        }

        success = true;
    } catch (Exception e) {
        e.printStackTrace();
    }

    finishGenerate();
    if (success) {
        while (System.currentTimeMillis() - startGeneratingTime < MinGeneratingTime) {

        }
        onProgress(1);
        didSuccess(addressStrs);
    } else {
        onFailed();
    }
}
 
Example #22
Source File: HDMHotAddDesktop.java    From bither-desktop-java with Apache License 2.0 4 votes vote down vote up
@Override
public void hotClick() {

    if (hdmKeychainLimit) {
        return;
    }
    if (singular.isInSingularMode()) {
        return;
    }
    HdmKeychainAddHotPanel hdmKeychainAddHotPanel = new HdmKeychainAddHotPanel(new HdmKeychainAddHotPanel.DialogHdmKeychainAddHotDelegate() {

        @Override
        public void addWithXRandom() {
            //  HDMKeychainHotUEntropyActivity.passwordGetter = passwordGetter;
            if (singular.shouldGoSingularMode()) {
                HDMKeychainHotUEntropyDialog.hdmSingular = singular;
            } else {
                singular.runningWithoutSingularMode();
            }
            if (delegate != null) {
                delegate.callKeychainHotUEntropy();
            }
        }

        @Override
        public void addWithoutXRandom() {
            new Thread() {
                @Override
                public void run() {
                    SecureCharSequence password = passwordGetter.getPassword();
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            dp.beginProgress();
                        }
                    });
                    if (password == null) {
                        return;
                    }
                    PeerUtil.stopPeer();
                    if (singular.shouldGoSingularMode()) {
                        singular.setPassword(password);
                        singular.generateEntropy();
                    } else {
                        singular.runningWithoutSingularMode();
                        HDMKeychain keychain = new HDMKeychain(new SecureRandom(),
                                password);
                        KeyUtil.setHDKeyChain(keychain);
                        PeerUtil.startPeer();
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                dp.endProgress();
                                if (delegate != null) {
                                    delegate.moveToCold(true);
                                }
                            }
                        });
                    }
                }
            }.start();
        }
    });
    hdmKeychainAddHotPanel.showPanel();
}
 
Example #23
Source File: HDMHotAddDesktop.java    From bither-desktop-java with Apache License 2.0 4 votes vote down vote up
@Override
public void hotClick() {

    if (hdmKeychainLimit) {
        return;
    }
    if (singular.isInSingularMode()) {
        return;
    }
    HdmKeychainAddHotPanel hdmKeychainAddHotPanel = new HdmKeychainAddHotPanel(new HdmKeychainAddHotPanel.DialogHdmKeychainAddHotDelegate() {

        @Override
        public void addWithXRandom() {
            //  HDMKeychainHotUEntropyActivity.passwordGetter = passwordGetter;
            if (singular.shouldGoSingularMode()) {
                HDMKeychainHotUEntropyDialog.hdmSingular = singular;
            } else {
                singular.runningWithoutSingularMode();
            }
            if (delegate != null) {
                delegate.callKeychainHotUEntropy();
            }
        }

        @Override
        public void addWithoutXRandom() {
            new Thread() {
                @Override
                public void run() {
                    SecureCharSequence password = passwordGetter.getPassword();
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            dp.beginProgress();
                        }
                    });
                    if (password == null) {
                        return;
                    }
                    PeerUtil.stopPeer();
                    if (singular.shouldGoSingularMode()) {
                        singular.setPassword(password);
                        singular.generateEntropy();
                    } else {
                        singular.runningWithoutSingularMode();
                        HDMKeychain keychain = new HDMKeychain(new SecureRandom(),
                                password);
                        KeyUtil.setHDKeyChain(keychain);
                        PeerUtil.startPeer();
                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                dp.endProgress();
                                if (delegate != null) {
                                    delegate.moveToCold(true);
                                }
                            }
                        });
                    }
                }
            }.start();
        }
    });
    hdmKeychainAddHotPanel.showPanel();
}
 
Example #24
Source File: CheckPrivateKeyPanel.java    From bither-desktop-java with Apache License 2.0 4 votes vote down vote up
@Override
public void initialiseContent(JPanel panel) {
    panel.setLayout(new MigLayout(
            Panels.migXYLayout(),
            "[]", // Column constraints
            "[]" // Row constraints
    ));

    addressCheckList = new ArrayList<AddressCheck>();
    HDAccount hdAccount = AddressManager.getInstance().getHdAccount();
    if (hdAccount != null) {
        addressCheckList.add(new AddressCheck(AddressCheck.CheckType.HDAccount, LocaliserUtils.getString("add_hd_account_tab_hd"),
                AddressCheck.CheckStatus.Prepare));
    }

    HDMKeychain keychain = AddressManager.getInstance().getHdmKeychain();
    if (keychain != null) {
        String str = LocaliserUtils.getString("hdm_keychain_check_title_cold");
        if (UserPreference.getInstance().getAppMode() == BitherjSettings.AppMode.HOT) {
            if (keychain.isInRecovery()) {
                str = LocaliserUtils.getString("address_group_hdm_recovery");
            } else {
                str = LocaliserUtils.getString("hdm_keychain_check_title_hot");
            }

        }
        addressCheckList.add(new AddressCheck(AddressCheck.CheckType.HDMKeyChain, str,
                AddressCheck.CheckStatus.Prepare));
    }
    for (Address address : AddressManager.getInstance().getPrivKeyAddresses()) {
        addressCheckList.add(new AddressCheck(address, AddressCheck.CheckStatus.Prepare));
    }
    checkPrivateKeyTableModel = new CheckPrivateKeyTableModel(addressCheckList);
    table = new JTable(checkPrivateKeyTableModel);

    table.setOpaque(false);
    table.setBorder(BorderFactory.createEmptyBorder());
    table.setRowHeight(Math.max(BitherSetting.MINIMUM_ICON_HEIGHT, panel.getFontMetrics(FontSizer.INSTANCE.getAdjustedDefaultFont()).getHeight()) + BitherSetting.HEIGHT_DELTA);
    table.getColumnModel().getColumn(1).setCellRenderer(new CheckImageRenderer());
    table.getColumnModel().getColumn(0).setCellRenderer(new AddressRenderer());

    checkNowButton = Buttons.newNormalButton(new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (AddressManager.getInstance().getPrivKeyAddresses().size() > 0 || AddressManager.getInstance().getHdmKeychain() != null
                    || AddressManager.getInstance().getHdAccount() != null) {
                PasswordPanel dialogPassword = new PasswordPanel((CheckPrivateKeyPanel.this));
                dialogPassword.showPanel();


            } else {
                new MessageDialog(LocaliserUtils.getString("private_key_is_empty")).showMsg();
            }
        }
    }, MessageKey.CHECK_PRIVATE_KEY, AwesomeIcon.CHECK);

    JScrollPane jScrollPane = new JScrollPane(table);
    panel.add(jScrollPane, "push,grow,align center, wrap");
    panel.add(checkNowButton, "push,shrink,align right");

}
 
Example #25
Source File: HDMHotAddAndroid.java    From bither-android with Apache License 2.0 4 votes vote down vote up
@Override
public void hotClick() {
    if (hdmKeychainLimit) {
        return;
    }
    if (singular.isInSingularMode()) {
        return;
    }
    new DialogHdmKeychainAddHot(activity, new DialogHdmKeychainAddHot
            .DialogHdmKeychainAddHotDelegate() {

        @Override
        public void addWithXRandom() {
            HDMKeychainHotUEntropyActivity.passwordGetter = passwordGetter;
            if (singular.shouldGoSingularMode()) {
                HDMKeychainHotUEntropyActivity.singularUtil = singular;
            } else {
                singular.runningWithoutSingularMode();
            }
            if (delegate != null) {
                delegate.callKeychainHotUEntropy();
            }
        }

        @Override
        public void addWithoutXRandom() {
            new Thread() {
                @Override
                public void run() {
                    SecureCharSequence password = passwordGetter.getPassword();
                    if (password == null) {
                        return;
                    }
                    if (singular.shouldGoSingularMode()) {
                        singular.setPassword(password);
                        singular.generateEntropy();
                    } else {
                        singular.runningWithoutSingularMode();
                        HDMKeychain keychain = new HDMKeychain(new SecureRandom(),
                                password);

                        KeyUtil.setHDKeyChain(keychain);
                        ThreadUtil.runOnMainThread(new Runnable() {
                            @Override
                            public void run() {
                                if (dp.isShowing()) {
                                    dp.dismiss();
                                }
                                if (delegate != null) {
                                    delegate.moveToCold(true);
                                }
                            }
                        });
                    }
                }
            }.start();
        }
    }).show();
}
 
Example #26
Source File: DialogHDMSeedOptions.java    From bither-android with Apache License 2.0 4 votes vote down vote up
public DialogHDMSeedOptions(Context context, HDMKeychain keychain, DialogProgress dp) {
    super(context);
    this.keychain = keychain;
    this.dp = dp;
    isCold = AppSharedPreference.getInstance().getAppMode() == BitherjSettings.AppMode.COLD;
}
 
Example #27
Source File: HDMKeychainColdUEntropyActivity.java    From bither-android with Apache License 2.0 4 votes vote down vote up
@Override
public void runWithService(BlockchainService service) {
    boolean success = false;
    double progress = startProgress;
    double itemProgress = (1.0 - startProgress - saveProgress);

    try {
        entropyCollector.start();
        if (service != null) {
            service.stopAndUnregister();
        }

        XRandom xRandom = new XRandom(entropyCollector);

        if (cancelRunnable != null) {
            finishGenerate(service);
            runOnUiThread(cancelRunnable);
            return;
        }

        HDMKeychain chain = new HDMKeychain(xRandom, password);

        progress += itemProgress * progressKeyRate;
        onProgress(progress);
        if (cancelRunnable != null) {
            finishGenerate(service);
            runOnUiThread(cancelRunnable);
            return;
        }
        KeyUtil.setHDKeyChain(chain);
        progress += itemProgress * progressEntryptRate;
        onProgress(progress);

        entropyCollector.stop();
        password.wipe();
        password = null;
        success = true;
    } catch (Exception e) {
        e.printStackTrace();
    }

    finishGenerate(service);
    if (success) {
        while (System.currentTimeMillis() - startGeneratingTime < MinGeneratingTime) {

        }
        onProgress(1);
        onSuccess(AddAddressColdHDMFragment.HDMSeedAddressPlaceHolder);
    } else {
        onFailed();
    }
}
 
Example #28
Source File: HDMKeychainHotUEntropyActivity.java    From bither-android with Apache License 2.0 4 votes vote down vote up
@Override
public void runWithService(BlockchainService service) {
    boolean success = false;
    double progress = startProgress;
    double itemProgress = (1.0 - startProgress - saveProgress);

    try {
        entropyCollector.start();

        XRandom xRandom = new XRandom(entropyCollector);

        if (cancelRunnable != null) {
            finishGenerate(service);
            runOnUiThread(cancelRunnable);
            return;
        }

        if (singularUtil != null && singularUtil.shouldGoSingularMode()) {
            byte[] entropy = new byte[64];
            xRandom.nextBytes(entropy);
            progress += itemProgress * progressKeyRate;
            onProgress(progress);
            if (cancelRunnable != null) {
                finishGenerate(service);
                runOnUiThread(cancelRunnable);
                return;
            }
            singularUtil.setPassword(password);
            singularUtil.setEntropy(entropy);
            progress += itemProgress * progressEntryptRate;
            onProgress(progress);
        } else {
            HDMKeychain chain = new HDMKeychain(xRandom, password);

            progress += itemProgress * progressKeyRate;
            onProgress(progress);
            if (cancelRunnable != null) {
                finishGenerate(service);
                runOnUiThread(cancelRunnable);
                return;
            }
            KeyUtil.setHDKeyChain(chain);
            progress += itemProgress * progressEntryptRate;
            onProgress(progress);
        }

        entropyCollector.stop();
        passwordGetter.setPassword(password);
        success = true;
    } catch (Exception e) {
        e.printStackTrace();
    }

    finishGenerate(service);
    if (success) {
        while (System.currentTimeMillis() - startGeneratingTime < MinGeneratingTime) {

        }
        onProgress(1);
        onSuccess(AddAddressColdHDMFragment.HDMSeedAddressPlaceHolder);
    } else {
        onFailed();
    }
}
 
Example #29
Source File: ImportHDSeedAndroid.java    From bither-android with Apache License 2.0 4 votes vote down vote up
public void importHDMColdSeed() {

        new ThreadNeedService(dp, activity) {
            @Override
            public void runWithService(BlockchainService service) {
                HDMKeychain result = importHDMKeychain();
                if (result != null) {

                    KeyUtil.setHDKeyChain(result);
                    ThreadUtil.runOnMainThread(new Runnable() {
                        @Override
                        public void run() {
                            if (dp != null && dp.isShowing()) {
                                dp.setThread(null);
                                dp.dismiss();
                            }
                            if (activity instanceof HotAdvanceActivity) {
                                ((HotAdvanceActivity) activity).showImportSuccess();
                            }
                            if (activity instanceof ColdAdvanceActivity) {
                                ((ColdAdvanceActivity) activity).showImportSuccess();
                            }
                            if (activity instanceof HdmImportWordListActivity) {
                                HdmImportWordListActivity hdmImportWordListActivity = (HdmImportWordListActivity) activity;
                                hdmImportWordListActivity.showImportSuccess();
                                hdmImportWordListActivity.finish();
                            }

                        }
                    });
                } else {
                    ThreadUtil.runOnMainThread(new Runnable() {
                        @Override
                        public void run() {
                            if (dp != null && dp.isShowing()) {
                                dp.setThread(null);
                                dp.dismiss();
                            }
                        }
                    });
                }
            }
        }.start();

    }
 
Example #30
Source File: ColdAddressFragment.java    From bither-android with Apache License 2.0 4 votes vote down vote up
@Override
public void requestHDMServerQrCode(HDMKeychain keychain) {
    startActivityForResult(new Intent(getActivity(), ScanActivity.class),
            HDMServerQrCodeRequestCode);
}