net.bither.bitherj.crypto.mnemonic.MnemonicException Java Examples
The following examples show how to use
net.bither.bitherj.crypto.mnemonic.MnemonicException.
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: HDMSingular.java From bitherj with Apache License 2.0 | 6 votes |
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 #2
Source File: HDAccount.java From bitherj with Apache License 2.0 | 5 votes |
public HDAccount(byte[] mnemonicSeed, CharSequence password, boolean isSyncedComplete) throws MnemonicException .MnemonicLengthException { super(); this.mnemonicSeed = mnemonicSeed; hdSeed = seedFromMnemonic(mnemonicSeed); DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(hdSeed); EncryptedData encryptedHDSeed = new EncryptedData(hdSeed, password, isFromXRandom); EncryptedData encryptedMnemonicSeed = new EncryptedData(mnemonicSeed, password, isFromXRandom); DeterministicKey account = getAccount(master); account.clearPrivateKey(); initHDAccount(account, encryptedMnemonicSeed, encryptedHDSeed, isFromXRandom, isSyncedComplete, null); }
Example #3
Source File: BCCAssetsHDAccountMonitoredActivity.java From bither-android with Apache License 2.0 | 5 votes |
private void send() { this.txs = null; HDAccount account = (HDAccount) address; try { txs = account.newForkTx(toAddress, btcAmount,outs, SplitCoin.BCC); } catch (Exception e) { e.printStackTrace(); btcAmount = 0; txs = null; String msg = getString(R.string.send_failed); if (e instanceof KeyCrypterException || e instanceof MnemonicException .MnemonicLengthException) { msg = getString(R.string.password_wrong); } else if (e instanceof TxBuilderException) { msg = e.getMessage(); } final String m = msg; runOnUiThread(new Runnable() { @Override public void run() { if (dp.isShowing()) { dp.dismiss(); } DropdownMessage.showDropdownMessage(BCCAssetsHDAccountMonitoredActivity.this, m); } }); } if (this.txs != null) { runOnUiThread(new Runnable() { @Override public void run() { showConfirm(); } }); } }
Example #4
Source File: HDAccount.java From bitherj with Apache License 2.0 | 5 votes |
public HDAccount(SecureRandom random, CharSequence password, HDAccountGenerationDelegate generationDelegate) throws MnemonicException.MnemonicLengthException { isFromXRandom = random.getClass().getCanonicalName().indexOf("XRandom") >= 0; mnemonicSeed = new byte[16]; random.nextBytes(mnemonicSeed); hdSeed = seedFromMnemonic(mnemonicSeed); EncryptedData encryptedHDSeed = new EncryptedData(hdSeed, password, isFromXRandom); EncryptedData encryptedMnemonicSeed = new EncryptedData(mnemonicSeed, password, isFromXRandom); DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(hdSeed); DeterministicKey account = getAccount(master); account.clearPrivateKey(); initHDAccount(account, encryptedMnemonicSeed, encryptedHDSeed, isFromXRandom, true, generationDelegate); }
Example #5
Source File: HDAccount.java From bitherj with Apache License 2.0 | 5 votes |
public HDAccount(EncryptedData encryptedMnemonicSeed, CharSequence password, boolean isSyncedComplete) throws MnemonicException.MnemonicLengthException { mnemonicSeed = encryptedMnemonicSeed.decrypt(password); hdSeed = seedFromMnemonic(mnemonicSeed); isFromXRandom = encryptedMnemonicSeed.isXRandom(); EncryptedData encryptedHDSeed = new EncryptedData(hdSeed, password, isFromXRandom); DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(hdSeed); DeterministicKey account = getAccount(master); account.clearPrivateKey(); initHDAccount(account, encryptedMnemonicSeed, encryptedHDSeed, isFromXRandom, isSyncedComplete, null); }
Example #6
Source File: HDAccount.java From bitherj with Apache License 2.0 | 5 votes |
public HDAccount(byte[] accountExtentedPub, boolean isFromXRandom, boolean isSyncedComplete, HDAccount.HDAccountGenerationDelegate generationDelegate) throws MnemonicException.MnemonicLengthException { super(); this.isFromXRandom = isFromXRandom; DeterministicKey account = HDKeyDerivation.createMasterPubKeyFromExtendedBytes (accountExtentedPub); initHDAccount(account, null, null, isFromXRandom, isSyncedComplete, generationDelegate); }
Example #7
Source File: HDAccount.java From bitherj with Apache License 2.0 | 5 votes |
public Tx newTx(String[] toAddresses, Long[] amounts) throws TxBuilderException, MnemonicException.MnemonicLengthException { List<Out> outs = AbstractDb.hdAccountAddressProvider.getUnspendOutByHDAccount(hdSeedId); Tx tx = TxBuilder.getInstance().buildTxFromAllAddress(outs, getNewChangeAddress(), Arrays .asList(amounts), Arrays.asList(toAddresses)); return tx; }
Example #8
Source File: HDAccount.java From bitherj with Apache License 2.0 | 5 votes |
protected DeterministicKey masterKey(CharSequence password) throws MnemonicException .MnemonicLengthException { long begin = System.currentTimeMillis(); decryptHDSeed(password); DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(hdSeed); wipeHDSeed(); log.info("hdm keychain decrypt time: {}", System.currentTimeMillis() - begin); return master; }
Example #9
Source File: HDAccount.java From bitherj with Apache License 2.0 | 5 votes |
protected void decryptHDSeed(CharSequence password) throws MnemonicException .MnemonicLengthException { if (hdSeedId < 0 || password == null) { return; } String encryptedHDSeed = getEncryptedHDSeed(); if (!Utils.isEmpty(encryptedHDSeed)) { hdSeed = new EncryptedData(encryptedHDSeed).decrypt(password); } }
Example #10
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 #11
Source File: HDAccount.java From bitherj with Apache License 2.0 | 5 votes |
public String xPubB58(CharSequence password) throws MnemonicException .MnemonicLengthException { DeterministicKey master = masterKey(password); DeterministicKey purpose = master.deriveHardened(44); DeterministicKey coinType = purpose.deriveHardened(0); DeterministicKey account = coinType.deriveHardened(0); String xpub = account.serializePubB58(); master.wipe(); purpose.wipe(); coinType.wipe(); account.wipe(); return xpub; }
Example #12
Source File: HDMKeychain.java From bitherj with Apache License 2.0 | 5 votes |
private DeterministicKey externalChainRoot(CharSequence password) throws MnemonicException.MnemonicLengthException { DeterministicKey master = masterKey(password); DeterministicKey accountKey = getAccount(master); DeterministicKey externalKey = getChainRootKey(accountKey, PathType.EXTERNAL_ROOT_PATH); master.wipe(); accountKey.wipe(); return externalKey; }
Example #13
Source File: HDMKeychain.java From bitherj with Apache License 2.0 | 5 votes |
public byte[] getExternalChainRootPubExtended(CharSequence password) throws MnemonicException .MnemonicLengthException { DeterministicKey ex = externalChainRoot(password); byte[] pub = ex.getPubKeyExtended(); ex.wipe(); return pub; }
Example #14
Source File: HDMKeychain.java From bitherj with Apache License 2.0 | 5 votes |
public boolean checkSingularBackupWithPassword(CharSequence password) { if (isInRecovery()) { return true; } if (getAllCompletedAddresses().size() == 0) { return true; } String backup = AbstractDb.addressProvider.getSingularModeBackup(getHdSeedId()); if (backup == null) { return true; } EncryptedData encrypted = new EncryptedData(backup); byte[] mnemonic = encrypted.decrypt(password); boolean result; try { byte[] seed = seedFromMnemonic(mnemonic); byte[] pub = getAllCompletedAddresses().get(0).getPubCold(); DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(seed); DeterministicKey purpose = master.deriveHardened(44); DeterministicKey coinType = purpose.deriveHardened(0); DeterministicKey account = coinType.deriveHardened(0); DeterministicKey external = account.deriveSoftened(0); DeterministicKey first = external.deriveSoftened(0); master.wipe(); purpose.wipe(); coinType.wipe(); account.wipe(); external.wipe(); Utils.wipeBytes(seed); result = Arrays.equals(first.getPubKey(), pub); first.wipe(); } catch (MnemonicException.MnemonicLengthException e) { e.printStackTrace(); result = false; } Utils.wipeBytes(mnemonic); return result; }
Example #15
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 #16
Source File: EnterpriseHDMSeed.java From bitherj with Apache License 2.0 | 5 votes |
public byte[] getExternalRootPubExtended(CharSequence password) throws MnemonicException .MnemonicLengthException { DeterministicKey master = masterKey(password); DeterministicKey accountKey = getAccount(master); DeterministicKey externalChainRoot = getChainRootKey(accountKey, PathType .EXTERNAL_ROOT_PATH); master.wipe(); accountKey.wipe(); byte[] ext = externalChainRoot.getPubKeyExtended(); externalChainRoot.clearPrivateKey(); externalChainRoot.clearChainCode(); return ext; }
Example #17
Source File: HDAccountCold.java From bitherj with Apache License 2.0 | 5 votes |
public HDAccountCold(byte[] mnemonicSeed, CharSequence password, boolean isFromXRandom) throws MnemonicException.MnemonicLengthException { this.mnemonicSeed = mnemonicSeed; hdSeed = seedFromMnemonic(mnemonicSeed); this.isFromXRandom = isFromXRandom; DeterministicKey master = HDKeyDerivation.createMasterPrivateKey(hdSeed); EncryptedData encryptedHDSeed = new EncryptedData(hdSeed, password, isFromXRandom); EncryptedData encryptedMnemonicSeed = new EncryptedData(mnemonicSeed, password, isFromXRandom); ECKey k = new ECKey(mnemonicSeed, null); String address = k.toAddress(); k.clearPrivateKey(); DeterministicKey accountKey = getAccount(master); DeterministicKey externalKey = getChainRootKey(accountKey, AbstractHD.PathType .EXTERNAL_ROOT_PATH); DeterministicKey internalKey = getChainRootKey(accountKey, PathType .INTERNAL_ROOT_PATH); DeterministicKey key = externalKey.deriveSoftened(0); String firstAddress = key.toAddress(); accountKey.wipe(); master.wipe(); wipeHDSeed(); wipeMnemonicSeed(); hdSeedId = AbstractDb.hdAccountProvider.addHDAccount(encryptedMnemonicSeed .toEncryptedString(), encryptedHDSeed.toEncryptedString(), firstAddress, isFromXRandom, address, externalKey.getPubKeyExtended(), internalKey .getPubKeyExtended()); externalKey.wipe(); }
Example #18
Source File: HDAccountCold.java From bitherj with Apache License 2.0 | 5 votes |
public List<byte[]> signHashHexes(final Collection<String> hashes, Collection<PathTypeIndex> paths, CharSequence password) throws MnemonicException .MnemonicLengthException { return signHashes(Collections2.transform(hashes, new Function<String, byte[]>() { @Nullable @Override public byte[] apply(String input) { return Utils.hexStringToByteArray(input); } }), paths, password); }
Example #19
Source File: HDAccountCold.java From bitherj with Apache License 2.0 | 5 votes |
public List<byte[]> signHashes(Collection<byte[]> hashes, Collection<PathTypeIndex> paths, CharSequence password) throws MnemonicException .MnemonicLengthException { assert hashes.size() == paths.size(); ArrayList<byte[]> sigs = new ArrayList<byte[]>(); DeterministicKey master = masterKey(password); DeterministicKey account = getAccount(master); DeterministicKey external = getChainRootKey(account, PathType.EXTERNAL_ROOT_PATH); DeterministicKey internal = getChainRootKey(account, PathType.INTERNAL_ROOT_PATH); master.wipe(); account.wipe(); Iterator<byte[]> hashIterator = hashes.iterator(); Iterator<PathTypeIndex> pathIterator = paths.iterator(); while (hashIterator.hasNext() && pathIterator.hasNext()) { byte[] hash = hashIterator.next(); PathTypeIndex path = pathIterator.next(); DeterministicKey key; if (path.pathType == PathType.EXTERNAL_ROOT_PATH) { key = external.deriveSoftened(path.index); } else { key = internal.deriveSoftened(path.index); } TransactionSignature sig = new TransactionSignature(key.sign(hash), TransactionSignature.SigHash.ALL, false); sigs.add(ScriptBuilder.createInputScript(sig, key).getProgram()); key.wipe(); } external.wipe(); internal.wipe(); return sigs; }
Example #20
Source File: HDAccountCold.java From bitherj with Apache License 2.0 | 5 votes |
public byte[] accountPubExtended(CharSequence password) throws MnemonicException .MnemonicLengthException { DeterministicKey master = masterKey(password); DeterministicKey account = getAccount(master); byte[] extended = account.getPubKeyExtended(); master.wipe(); account.wipe(); return extended; }
Example #21
Source File: HDAccountCold.java From bitherj with Apache License 2.0 | 5 votes |
public String accountPubExtendedString(CharSequence password) throws MnemonicException .MnemonicLengthException { byte[] extended = accountPubExtended(password); String result = ""; if (isFromXRandom) { result += QRCodeUtil.XRANDOM_FLAG; } result += Utils.bytesToHexString(extended).toUpperCase(); return result; }
Example #22
Source File: HDAccountCold.java From bitherj with Apache License 2.0 | 5 votes |
public String xPubB58(CharSequence password) throws MnemonicException .MnemonicLengthException { DeterministicKey master = masterKey(password); DeterministicKey purpose = master.deriveHardened(44); DeterministicKey coinType = purpose.deriveHardened(0); DeterministicKey account = coinType.deriveHardened(0); String xpub = account.serializePubB58(); master.wipe(); purpose.wipe(); coinType.wipe(); account.wipe(); return xpub; }
Example #23
Source File: HDAccountSendPanel.java From bither-desktop-java with Apache License 2.0 | 5 votes |
private void send() { tx = null; HDAccount account = (HDAccount) Bither.getActionAddress(); SecureCharSequence password = new SecureCharSequence(currentPassword.getPassword()); try { tx = account.newTx(toAddress, btcAmount, password); } catch (Exception e) { e.printStackTrace(); btcAmount = 0; tx = null; String msg = LocaliserUtils.getString("send_failed"); if (e instanceof KeyCrypterException || e instanceof MnemonicException .MnemonicLengthException) { msg = LocaliserUtils.getString("password_wrong"); } else if (e instanceof TxBuilderException) { msg = e.getMessage(); } final String m = msg; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { dp.dispose(); new MessageDialog(m).showMsg(); } }); } finally { password.wipe(); } if (tx != null) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { showConfirm(); } }); } }
Example #24
Source File: AbstractHD.java From bitherj with Apache License 2.0 | 5 votes |
protected void decryptHDSeed(CharSequence password) throws MnemonicException .MnemonicLengthException { if (hdSeedId < 0 || password == null) { return; } String encryptedHDSeed = getEncryptedHDSeed(); if (Utils.isEmpty(encryptedHDSeed)) { initHDSeedFromMnemonicSeed(password); } else { hdSeed = new EncryptedData(encryptedHDSeed).decrypt(password); } }
Example #25
Source File: HDAccountSendPanel.java From bither-desktop-java with Apache License 2.0 | 5 votes |
private void send() { tx = null; HDAccount account = (HDAccount) Bither.getActionAddress(); SecureCharSequence password = new SecureCharSequence(currentPassword.getPassword()); try { tx = account.newTx(toAddress, btcAmount, password); } catch (Exception e) { e.printStackTrace(); btcAmount = 0; tx = null; String msg = LocaliserUtils.getString("send_failed"); if (e instanceof KeyCrypterException || e instanceof MnemonicException .MnemonicLengthException) { msg = LocaliserUtils.getString("password_wrong"); } else if (e instanceof TxBuilderException) { msg = e.getMessage(); } final String m = msg; SwingUtilities.invokeLater(new Runnable() { @Override public void run() { dp.dispose(); new MessageDialog(m).showMsg(); } }); } finally { password.wipe(); } if (tx != null) { SwingUtilities.invokeLater(new Runnable() { @Override public void run() { showConfirm(); } }); } }
Example #26
Source File: BCCAssetsDetectHDActivity.java From bither-android with Apache License 2.0 | 5 votes |
private void send() { txs = null; HDAccount account = (HDAccount) address; SecureCharSequence password = new SecureCharSequence(etPassword.getText()); try { txs = account.extractBcc(etAddress.getText().toString().trim(), getAmount(outs), outs, path, index, password); } catch (Exception e) { e.printStackTrace(); btcAmount = 0; txs = null; String msg = getString(R.string.send_failed); if (e instanceof KeyCrypterException || e instanceof MnemonicException .MnemonicLengthException) { msg = getString(R.string.password_wrong); } else if (e instanceof TxBuilderException) { msg = e.getMessage(); } final String m = msg; runOnUiThread(new Runnable() { @Override public void run() { if (dp.isShowing()) { dp.dismiss(); } DropdownMessage.showDropdownMessage(BCCAssetsDetectHDActivity.this, m); } }); } finally { password.wipe(); } if (txs != null) { runOnUiThread(new Runnable() { @Override public void run() { showConfirm(); } }); } }
Example #27
Source File: AddEnterpriseHDMSeedActivity.java From bither-android with Apache License 2.0 | 5 votes |
@Override public void onPasswordEntered(final SecureCharSequence password) { if (dp != null && !dp.isShowing()) { dp.setMessage(R.string.import_private_key_qr_code_importing); } new ThreadNeedService(dp, AddEnterpriseHDMSeedActivity.this) { @Override public void runWithService(BlockchainService service) { EncryptedData data = new EncryptedData(content.substring(1)); try { EnterpriseHDMSeed seed = new EnterpriseHDMSeed(data.decrypt(new SecureCharSequence(password)), data.isXRandom(), password); runOnUiThread(new Runnable() { @Override public void run() { dp.dismiss(); setResult(RESULT_OK); finish(); } }); } catch (MnemonicException.MnemonicLengthException e) { e.printStackTrace(); runOnUiThread(new Runnable() { @Override public void run() { dp.dismiss(); DropdownMessage.showDropdownMessage(AddEnterpriseHDMSeedActivity .this, R.string.enterprise_hdm_seed_add_fail); } }); } } }.start(); }
Example #28
Source File: SplitBCCHDAccountMonitoredSendActivity.java From bither-android with Apache License 2.0 | 5 votes |
private void send() { this.txs = null; HDAccount account = (HDAccount) address; try { txs = account.newForkTx(toAddress, btcAmount, splitCoin); } catch (Exception e) { e.printStackTrace(); btcAmount = 0; txs = null; String msg = getString(R.string.send_failed); if (e instanceof KeyCrypterException || e instanceof MnemonicException .MnemonicLengthException) { msg = getString(R.string.password_wrong); } else if (e instanceof TxBuilderException) { msg = e.getMessage(); } final String m = msg; runOnUiThread(new Runnable() { @Override public void run() { if (dp.isShowing()) { dp.dismiss(); } DropdownMessage.showDropdownMessage(SplitBCCHDAccountMonitoredSendActivity.this, m); } }); } if (this.txs != null) { runOnUiThread(new Runnable() { @Override public void run() { showConfirm(); } }); } }
Example #29
Source File: SplitBCCHDAccountSendActivity.java From bither-android with Apache License 2.0 | 5 votes |
private void send(String...blockhash) { txs = null; HDAccount account = (HDAccount) address; SecureCharSequence password = new SecureCharSequence(etPassword.getText()); try { txs = account.newForkTx(etAddress.getText().toString().trim(), btcAmount, password, splitCoin,blockhash); } catch (Exception e) { e.printStackTrace(); btcAmount = 0; txs = null; String msg = getString(R.string.send_failed); if (e instanceof KeyCrypterException || e instanceof MnemonicException .MnemonicLengthException) { msg = getString(R.string.password_wrong); } else if (e instanceof TxBuilderException) { msg = e.getMessage(); } final String m = msg; runOnUiThread(new Runnable() { @Override public void run() { if (dp.isShowing()) { dp.dismiss(); } DropdownMessage.showDropdownMessage(SplitBCCHDAccountSendActivity.this, m); } }); } finally { password.wipe(); } if (txs != null) { runOnUiThread(new Runnable() { @Override public void run() { showConfirm(); } }); } }
Example #30
Source File: EnterpriseHDMSendActivity.java From bither-android with Apache License 2.0 | 5 votes |
private void send() { tx = null; String changeTo = getChangeAddress(); try { tx = address.buildTx(btcAmount, toAddress, changeTo == null ? address.getAddress() : changeTo); } catch (Exception e) { e.printStackTrace(); btcAmount = 0; tx = null; String msg = getString(R.string.send_failed); if (e instanceof KeyCrypterException || e instanceof MnemonicException .MnemonicLengthException) { msg = getString(R.string.password_wrong); } else if (e instanceof TxBuilderException) { msg = e.getMessage(); } final String m = msg; runOnUiThread(new Runnable() { @Override public void run() { if (dp.isShowing()) { dp.dismiss(); } DropdownMessage.showDropdownMessage(EnterpriseHDMSendActivity.this, m); } }); } if (tx != null) { runOnUiThread(new Runnable() { @Override public void run() { showConfirm(); } }); } }