Java Code Examples for net.bither.bitherj.crypto.hd.DeterministicKey#deriveHardened()
The following examples show how to use
net.bither.bitherj.crypto.hd.DeterministicKey#deriveHardened() .
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: AbstractHD.java From bitherj with Apache License 2.0 | 5 votes |
protected DeterministicKey getAccount(DeterministicKey master) { DeterministicKey purpose = master.deriveHardened(44); DeterministicKey coinType = purpose.deriveHardened(0); DeterministicKey account = coinType.deriveHardened(0); purpose.wipe(); coinType.wipe(); return account; }
Example 3
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 4
Source File: HDAccount.java From bitherj with Apache License 2.0 | 5 votes |
protected DeterministicKey getAccount(DeterministicKey master) { DeterministicKey purpose = master.deriveHardened(44); DeterministicKey coinType = purpose.deriveHardened(0); DeterministicKey account = coinType.deriveHardened(0); purpose.wipe(); coinType.wipe(); return account; }
Example 5
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 6
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 7
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 8
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; }