net.bither.bitherj.crypto.mnemonic.MnemonicCode Java Examples
The following examples show how to use
net.bither.bitherj.crypto.mnemonic.MnemonicCode.
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: Bither.java From bither-desktop-java with Apache License 2.0 | 6 votes |
private static void initBitherApplication() { ApplicationInstanceManager.txDBHelper = new TxDBHelper(applicationDataDirectoryLocator.getApplicationDataDirectory()); ApplicationInstanceManager.txDBHelper.initDb(); ApplicationInstanceManager.addressDBHelper = new AddressDBHelper(applicationDataDirectoryLocator.getApplicationDataDirectory()); ApplicationInstanceManager.addressDBHelper.initDb(); if (UserPreference.getInstance().getAppMode() == null) { UserPreference.getInstance().setAppMode(BitherjSettings.AppMode.HOT); } DesktopImplAbstractApp desktopImplAbstractApp = new DesktopImplAbstractApp(); desktopImplAbstractApp.construct(); DesktopDbImpl desktopDb = new DesktopDbImpl(); desktopDb.construct(); AddressManager.getInstance(); try { MnemonicCode.setInstance(new MnemonicCodeDesktop()); } catch (IOException e) { e.printStackTrace(); } }
Example #2
Source File: Bither.java From bither-desktop-java with Apache License 2.0 | 6 votes |
private static void initBitherApplication() { ApplicationInstanceManager.txDBHelper = new TxDBHelper(applicationDataDirectoryLocator.getApplicationDataDirectory()); ApplicationInstanceManager.txDBHelper.initDb(); ApplicationInstanceManager.addressDBHelper = new AddressDBHelper(applicationDataDirectoryLocator.getApplicationDataDirectory()); ApplicationInstanceManager.addressDBHelper.initDb(); if (UserPreference.getInstance().getAppMode() == null) { UserPreference.getInstance().setAppMode(BitherjSettings.AppMode.HOT); } DesktopImplAbstractApp desktopImplAbstractApp = new DesktopImplAbstractApp(); desktopImplAbstractApp.construct(); DesktopDbImpl desktopDb = new DesktopDbImpl(); desktopDb.construct(); AddressManager.getInstance(); try { MnemonicCode.setInstance(new MnemonicCodeDesktop()); } catch (IOException e) { e.printStackTrace(); } }
Example #3
Source File: DialogHdmImportWordListReplace.java From bither-android with Apache License 2.0 | 6 votes |
@Override public void onClick(View v) { if (v.getId() == R.id.btn_ok) { String word = et.getText().toString().toLowerCase().trim(); if (Utils.isEmpty(word)) { return; } try { MnemonicCode mnemonic = MnemonicCode.instanceForWord(new MnemonicCodeAndroid(), word); if (mnemonic == null) { tvError.setVisibility(View.VISIBLE); shake(); return; } dismiss(); if (listener != null) { listener.replace(index, word); } } catch (IOException e) { e.printStackTrace(); } } else { dismiss(); } }
Example #4
Source File: ColdActivity.java From bither-android with Apache License 2.0 | 6 votes |
private MnemonicCode getMnemonicCode(String string) { MnemonicWordList mnemonicWordList = MnemonicWordList.getMnemonicWordListForHdSeed(string); if (mnemonicWordList == null && string.equals(MnemonicWordList.getBitpieColdQrCodeFlag())) { mnemonicWordList = MnemonicWordList.English; } MnemonicCode mnemonicCode = null; if (mnemonicWordList != null) { try { mnemonicCode = new MnemonicCodeAndroid(); mnemonicCode.setMnemonicWordList(mnemonicWordList); } catch (Exception e) { e.printStackTrace(); } } return mnemonicCode; }
Example #5
Source File: HdmImportWordListActivity.java From bither-android with Apache License 2.0 | 6 votes |
private void isZhTw() { try { int zhCnCount = 0; for (String word: words) { mnemonic = MnemonicCode.instanceForWord(new MnemonicCodeAndroid(), word); ArrayList<String> zhCnWorsList = mnemonic.getWordListForInputStream(BitherApplication.mContext.getResources().openRawResource(R.raw.mnemonic_wordlist_zh_cn)); ArrayList<String> zhTwWorsList = mnemonic.getWordListForInputStream(BitherApplication.mContext.getResources().openRawResource(R.raw.mnemonic_wordlist_zh_tw)); if (!zhCnWorsList.contains(word) && zhTwWorsList.contains(word)) { mnemonic.setWordList(zhTwWorsList, MnemonicWordList.ZhTw); return; } if (zhCnWorsList.contains(word)) { zhCnCount += 1; } if (zhCnCount == words.size()) { mnemonic.setWordList(zhCnWorsList, MnemonicWordList.ZhCN); return; } } return; } catch (IOException e) { e.printStackTrace(); return; } }
Example #6
Source File: RestoreWalletSeedPhrasePanel.java From bither-desktop-java with Apache License 2.0 | 5 votes |
public void updateModelFromView() { String text = seedPhraseTextArea.getText(); seedPhraseList = Lists.newArrayList(Splitter .on(" ") .omitEmptyStrings() .trimResults() .split(text) ); boolean okEnabled; if (this.importHDSeedType == ImportHDSeed.ImportHDSeedType.HDSeedPhrase) { okEnabled = seedPhraseList.size() % 3 != 0 || !text.endsWith(" "); } else { okEnabled = seedPhraseList.size() < PHRASE_COUNT || !text.endsWith(" "); } if (okEnabled) { setOkEnabled(false); } else { List<String> faildWorldList = new ArrayList<String>(); for (String world : seedPhraseList) { if (!MnemonicCode.instance().getWordList().contains(world)) { faildWorldList.add(world); } } if (faildWorldList.size() == 0) { setOkEnabled(true); } else { String str = Utils.joinString(faildWorldList, "-"); new MessageDialog(LocaliserUtils.getString("hdm_import_word_list_wrong_word_warn") + str).showMsg(); } } }
Example #7
Source File: RestoreWalletSeedPhrasePanel.java From bither-desktop-java with Apache License 2.0 | 5 votes |
public void updateModelFromView() { String text = seedPhraseTextArea.getText(); seedPhraseList = Lists.newArrayList(Splitter .on(" ") .omitEmptyStrings() .trimResults() .split(text) ); boolean okEnabled; if (this.importHDSeedType == ImportHDSeed.ImportHDSeedType.HDSeedPhrase) { okEnabled = seedPhraseList.size() % 3 != 0 || !text.endsWith(" "); } else { okEnabled = seedPhraseList.size() < PHRASE_COUNT || !text.endsWith(" "); } if (okEnabled) { setOkEnabled(false); } else { List<String> faildWorldList = new ArrayList<String>(); for (String world : seedPhraseList) { if (!MnemonicCode.instance().getWordList().contains(world)) { faildWorldList.add(world); } } if (faildWorldList.size() == 0) { setOkEnabled(true); } else { String str = Utils.joinString(faildWorldList, "-"); new MessageDialog(LocaliserUtils.getString("hdm_import_word_list_wrong_word_warn") + str).showMsg(); } } }
Example #8
Source File: HDMKeychain.java From bitherj with Apache License 2.0 | 5 votes |
public static boolean checkPassword(String keysString, CharSequence password) throws MnemonicException.MnemonicLengthException { String[] passwordSeeds = QRCodeUtil.splitOfPasswordSeed(keysString); String address = Base58.hexToBase58WithAddress(passwordSeeds[0]); String encreyptString = Utils.joinString(new String[]{passwordSeeds[1], passwordSeeds[2], passwordSeeds[3]}, QRCodeUtil.QR_CODE_SPLIT); byte[] seed = new EncryptedData(encreyptString).decrypt(password); MnemonicCode mnemonic = MnemonicCode.instance(); byte[] s = mnemonic.toSeed(mnemonic.toMnemonic(seed), ""); DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(s); DeterministicKey purpose = master.deriveHardened(44); DeterministicKey coinType = purpose.deriveHardened(0); DeterministicKey account = coinType.deriveHardened(0); DeterministicKey external = account.deriveSoftened(0); external.clearPrivateKey(); DeterministicKey key = external.deriveSoftened(0); boolean result = Utils.compareString(address, Utils.toAddress(key.getPubKeyHash())); key.wipe(); return result; }
Example #9
Source File: HDAccount.java From bitherj with Apache License 2.0 | 5 votes |
public List<String> getSeedWords(CharSequence password) throws MnemonicException .MnemonicLengthException { decryptMnemonicSeed(password); List<String> words = MnemonicCode.instance().toMnemonic(mnemonicSeed); wipeMnemonicSeed(); return words; }
Example #10
Source File: DesktopHDMKeychain.java From bitherj with Apache License 2.0 | 5 votes |
public static boolean checkPassword(String keysString, CharSequence password) throws MnemonicException.MnemonicLengthException { String[] passwordSeeds = QRCodeUtil.splitOfPasswordSeed(keysString); String address = Base58.hexToBase58WithAddress(passwordSeeds[0]); String encreyptString = Utils.joinString(new String[]{passwordSeeds[1], passwordSeeds[2], passwordSeeds[3]}, QRCodeUtil.QR_CODE_SPLIT); byte[] seed = new EncryptedData(encreyptString).decrypt(password); MnemonicCode mnemonic = MnemonicCode.instance(); byte[] s = mnemonic.toSeed(mnemonic.toMnemonic(seed), ""); DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(s); DeterministicKey purpose = master.deriveHardened(44); DeterministicKey coinType = purpose.deriveHardened(0); DeterministicKey account = coinType.deriveHardened(0); DeterministicKey external = account.deriveSoftened(0); external.clearPrivateKey(); DeterministicKey key = external.deriveSoftened(0); boolean result = Utils.compareString(address, Utils.toAddress(key.getPubKeyHash())); key.wipe(); return result; }
Example #11
Source File: AbstractHD.java From bitherj with Apache License 2.0 | 5 votes |
public List<String> getSeedWords(CharSequence password) throws MnemonicException .MnemonicLengthException { decryptMnemonicSeed(password); List<String> words = MnemonicCode.instance().toMnemonic(mnemonicSeed); wipeMnemonicSeed(); return words; }
Example #12
Source File: HdmImportWordListActivity.java From bither-android with Apache License 2.0 | 5 votes |
@Override public void onClick(View v) { if (words.size() >= WordCount) { return; } String word = etInput.getText().toString().toLowerCase().trim(); if (Utils.isEmpty(word)) { return; } try { mnemonic = MnemonicCode.instanceForWord(new MnemonicCodeAndroid(), word); if (mnemonic == null) { DropdownMessage.showDropdownMessage(HdmImportWordListActivity.this, R.string.hdm_import_word_list_wrong_word_warn); return; } words.add(word); etInput.setText(""); refresh(); gv.smoothScrollToPosition(words.size() - 1); if (words.size() >= WordCount) { complete(); } } catch (IOException e) { e.printStackTrace(); return; } }
Example #13
Source File: HotAdvanceActivity.java From bither-android with Apache License 2.0 | 4 votes |
public ImportHDAccountPasswordListener(String content, MnemonicCode mnemonicCode) { this.content = content; this.mnemonicCode = mnemonicCode; }
Example #14
Source File: ColdAdvanceActivity.java From bither-android with Apache License 2.0 | 4 votes |
public ImportHDAccountPasswordListener(String content, MnemonicCode mnemonicCode) { this.content = content; this.mnemonicCode = mnemonicCode; }
Example #15
Source File: AbstractHD.java From bitherj with Apache License 2.0 | 4 votes |
public static final byte[] seedFromMnemonic(byte[] mnemonicSeed) throws MnemonicException .MnemonicLengthException { MnemonicCode mnemonic = MnemonicCode.instance(); return mnemonic.toSeed(mnemonic.toMnemonic(mnemonicSeed), ""); }
Example #16
Source File: BitpieHDAccountColdUEntropyActivity.java From bither-android with Apache License 2.0 | 4 votes |
@Override public void runWithService(BlockchainService service) { boolean success = false; onProgress(startProgress); try { if (service != null) { service.stopAndUnregister(); } entropyCollector.start(); XRandom xRandom = new XRandom(entropyCollector); if (cancelRunnable != null) { finishGenerate(service); runOnUiThread(cancelRunnable); return; } BitpieHDAccountCold hdAccount = new BitpieHDAccountCold(MnemonicCode.instance(), xRandom, password); if (cancelRunnable != null) { finishGenerate(service); runOnUiThread(cancelRunnable); return; } words = hdAccount.getSeedWords(password); BackupUtil.backupColdKey(false); onProgress(1); entropyCollector.stop(); success = true; } catch (Exception e) { e.printStackTrace(); } finishGenerate(service); if (success) { while (System.currentTimeMillis() - startGeneratingTime < MinGeneratingTime) { } onProgress(1); onSuccess(BitpieHDAccountCold.BitpieHDAccountPlaceHolder); } else { onFailed(); } }
Example #17
Source File: HDAccount.java From bitherj with Apache License 2.0 | 4 votes |
public static final byte[] seedFromMnemonic(byte[] mnemonicSeed) throws MnemonicException .MnemonicLengthException { MnemonicCode mnemonic = MnemonicCode.instance(); return mnemonic.toSeed(mnemonic.toMnemonic(mnemonicSeed), ""); }
Example #18
Source File: HDAccountColdUEntropyActivity.java From bither-android with Apache License 2.0 | 4 votes |
@Override public void runWithService(BlockchainService service) { boolean success = false; onProgress(startProgress); try { if (service != null) { service.stopAndUnregister(); } entropyCollector.start(); XRandom xRandom = new XRandom(entropyCollector); if (cancelRunnable != null) { finishGenerate(service); runOnUiThread(cancelRunnable); return; } HDAccountCold hdAccount = new HDAccountCold(MnemonicCode.instance(), xRandom, password); if (cancelRunnable != null) { finishGenerate(service); runOnUiThread(cancelRunnable); return; } words = hdAccount.getSeedWords(password); BackupUtil.backupColdKey(false); onProgress(1); entropyCollector.stop(); success = true; } catch (Exception e) { e.printStackTrace(); } finishGenerate(service); if (success) { while (System.currentTimeMillis() - startGeneratingTime < MinGeneratingTime) { } onProgress(1); onSuccess(HDAccount.HDAccountPlaceHolder); } else { onFailed(); } }
Example #19
Source File: ImportHDSeedAndroid.java From bither-android with Apache License 2.0 | 4 votes |
public ImportHDSeedAndroid(Activity activity, ImportHDSeedType importHDSeedType, DialogProgress dp, String content, List<String> worlds, SecureCharSequence password, MnemonicCode mnemonicCode) { super(importHDSeedType, content, worlds, password, mnemonicCode); this.activity = activity; this.dp = dp; }
Example #20
Source File: MnemonicCodeAndroid.java From bither-android with Apache License 2.0 | 4 votes |
static public void setMnemonicCode(MnemonicWordList mnemonicWordList) throws IOException { MnemonicCode mnemonicCode = new MnemonicCodeAndroid(); mnemonicCode.setMnemonicWordList(mnemonicWordList); MnemonicCode.setInstance(mnemonicCode); }