Java Code Examples for net.bither.bitherj.crypto.hd.HDKeyDerivation#createMasterPubKeyFromExtendedBytes()

The following examples show how to use net.bither.bitherj.crypto.hd.HDKeyDerivation#createMasterPubKeyFromExtendedBytes() . 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: DesktopHDMKeychain.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public void addAccountKey(byte[] firstByte, byte[] secondByte) {
    if (new BigInteger(1, firstByte).compareTo(new BigInteger(1, secondByte)) > 0) {
        byte[] temp = firstByte;
        firstByte = secondByte;
        secondByte = temp;
    }

    DeterministicKey firstAccountKey = HDKeyDerivation.createMasterPubKeyFromExtendedBytes
            (firstByte);
    DeterministicKey secondAccountKey = HDKeyDerivation.createMasterPubKeyFromExtendedBytes
            (secondByte);

    DeterministicKey firestInternalKey = getChainRootKey(firstAccountKey, AbstractHD.PathType.INTERNAL_ROOT_PATH);
    DeterministicKey firestExternalKey = getChainRootKey(firstAccountKey, AbstractHD.PathType.EXTERNAL_ROOT_PATH);

    DeterministicKey secondInternalKey = getChainRootKey(secondAccountKey, AbstractHD.PathType.INTERNAL_ROOT_PATH);
    DeterministicKey secondExternalKey = getChainRootKey(secondAccountKey, AbstractHD.PathType.EXTERNAL_ROOT_PATH);
    List<byte[]> externalPubs = new ArrayList<byte[]>();
    List<byte[]> internalPubs = new ArrayList<byte[]>();
    externalPubs.add(firestExternalKey.getPubKeyExtended());
    externalPubs.add(secondExternalKey.getPubKeyExtended());
    internalPubs.add(firestInternalKey.getPubKeyExtended());
    internalPubs.add(secondInternalKey.getPubKeyExtended());
    AbstractDb.desktopAddressProvider.addHDMPub(externalPubs, internalPubs);
    addDesktopAddress(PathType.EXTERNAL_ROOT_PATH, LOOK_AHEAD_SIZE);
    addDesktopAddress(PathType.INTERNAL_ROOT_PATH, LOOK_AHEAD_SIZE);
}
 
Example 2
Source File: DesktopHDMKeychain.java    From bitherj with Apache License 2.0 5 votes vote down vote up
private void supplyNewInternalKey(int count, boolean isSyncedComplete) {
    List<DesktopHDMAddress> desktopHDMAddresses = new ArrayList<DesktopHDMAddress>();
    List<byte[]> internalPubs = AbstractDb.desktopAddressProvider.getInternalPubs();
    DeterministicKey internalKey1 = HDKeyDerivation.createMasterPubKeyFromExtendedBytes
            (internalPubs.get(0));
    DeterministicKey internalKey2 = HDKeyDerivation.createMasterPubKeyFromExtendedBytes
            (internalPubs.get(1));
    DeterministicKey internalKey3 = HDKeyDerivation.createMasterPubKeyFromExtendedBytes
            (internalPubs.get(2));
    int firstIndex = allGeneratedInternalAddressCount();
    for (int i = firstIndex;
         i < count + firstIndex;
         i++) {
        byte[] subInternalPub1 = internalKey1.deriveSoftened(i).getPubKey();
        byte[] subInternalPub2 = internalKey2.deriveSoftened(i).getPubKey();
        byte[] subInternalPub3 = internalKey3.deriveSoftened(i).getPubKey();
        HDMAddress.Pubs pubs = new HDMAddress.Pubs();
        pubs.hot = subInternalPub1;
        pubs.cold = subInternalPub2;
        pubs.remote = subInternalPub3;
        pubs.index = i;
        DesktopHDMAddress desktopHDMAddress = new DesktopHDMAddress(pubs, PathType.INTERNAL_ROOT_PATH, DesktopHDMKeychain.this, isSyncedComplete);
        desktopHDMAddresses.add(desktopHDMAddress);

    }
    AbstractDb.desktopTxProvider.addAddress(desktopHDMAddresses);

}
 
Example 3
Source File: DesktopHDMKeychain.java    From bitherj with Apache License 2.0 5 votes vote down vote up
private void supplyNewExternalKey(int count, boolean isSyncedComplete) {
    List<byte[]> externalPubs = AbstractDb.desktopAddressProvider.getExternalPubs();
    DeterministicKey externalKey1 = HDKeyDerivation.createMasterPubKeyFromExtendedBytes
            (externalPubs.get(0));
    DeterministicKey externalKey2 = HDKeyDerivation.createMasterPubKeyFromExtendedBytes
            (externalPubs.get(1));
    DeterministicKey externalKey3 = HDKeyDerivation.createMasterPubKeyFromExtendedBytes
            (externalPubs.get(2));
    List<DesktopHDMAddress> desktopHDMAddresses = new ArrayList<DesktopHDMAddress>();
    int firstIndex = allGeneratedExternalAddressCount();
    for (int i = firstIndex;
         i < count + firstIndex;
         i++) {
        byte[] subExternalPub1 = externalKey1.deriveSoftened(i).getPubKey();
        byte[] subExternalPub2 = externalKey2.deriveSoftened(i).getPubKey();
        byte[] subExternalPub3 = externalKey3.deriveSoftened(i).getPubKey();
        HDMAddress.Pubs pubs = new HDMAddress.Pubs();
        pubs.hot = subExternalPub1;
        pubs.cold = subExternalPub2;
        pubs.remote = subExternalPub3;
        pubs.index = i;
        DesktopHDMAddress desktopHDMAddress = new DesktopHDMAddress(pubs, PathType.EXTERNAL_ROOT_PATH, DesktopHDMKeychain.this, isSyncedComplete);
        desktopHDMAddresses.add(desktopHDMAddress);

    }
    AbstractDb.desktopTxProvider.addAddress(desktopHDMAddresses);
    log.info("HD supplied {} internal addresses", desktopHDMAddresses.size());
}
 
Example 4
Source File: HDAccount.java    From bitherj with Apache License 2.0 5 votes vote down vote up
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 5
Source File: HDAccount.java    From bitherj with Apache License 2.0 5 votes vote down vote up
private void supplyNewInternalKey(int count, boolean isSyncedComplete) {
    DeterministicKey root = HDKeyDerivation.createMasterPubKeyFromExtendedBytes
            (getInternalPub());
    int firstIndex = allGeneratedInternalAddressCount();
    ArrayList<HDAccountAddress> as = new ArrayList<HDAccountAddress>();
    for (int i = firstIndex;
         i < firstIndex + count;
         i++) {
        as.add(new HDAccountAddress(root.deriveSoftened(i).getPubKey(), AbstractHD.PathType
                .INTERNAL_ROOT_PATH, i, isSyncedComplete, hdSeedId));
    }
    AbstractDb.hdAccountAddressProvider.addAddress(as);
    log.info("HD supplied {} internal addresses", as.size());
}
 
Example 6
Source File: HDAccount.java    From bitherj with Apache License 2.0 5 votes vote down vote up
private void supplyNewExternalKey(int count, boolean isSyncedComplete) {
    DeterministicKey root = HDKeyDerivation.createMasterPubKeyFromExtendedBytes
            (getExternalPub());
    int firstIndex = allGeneratedExternalAddressCount();
    ArrayList<HDAccountAddress> as = new ArrayList<HDAccountAddress>();
    for (int i = firstIndex;
         i < firstIndex + count;
         i++) {
        as.add(new HDAccountAddress(root.deriveSoftened(i).getPubKey(), AbstractHD.PathType
                .EXTERNAL_ROOT_PATH, i, isSyncedComplete, hdSeedId));
    }
    AbstractDb.hdAccountAddressProvider.addAddress(as);
    log.info("HD supplied {} external addresses", as.size());
}
 
Example 7
Source File: EnterpriseHDMKeychainAddNewAddressActivity.java    From bither-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (AddPubCode == requestCode) {
        if (resultCode == RESULT_OK) {
            String result = data.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
            if (Utils.isEmpty(result)) {
                return;
            }
            LogUtil.d("AddPub", "pub : " + result);
            byte[] pub = null;
            try {
                if (result.length() == 130) {
                    pub = Utils.hexStringToByteArray(result);
                    if (HDKeyDerivation.createMasterPubKeyFromExtendedBytes(Arrays.copyOf
                            (pub, pub.length)) == null) {
                        pub = null;
                    }
                }
            } catch (Exception e) {
                pub = null;
                e.printStackTrace();
            }
            if (pub == null) {
                DropdownMessage.showDropdownMessage(this, R.string
                        .enterprise_hdm_keychain_collect_pub_error);
                return;
            }
            pubs.add(pub);
            for (int i = 0;
                 i < pubs.size() && i < llPubs.getChildCount();
                 i++) {
                View v = llPubs.getChildAt(i);
                v.setBackgroundColor(getResources().getColor(R.color.blue_dark));
            }
            if (pubs.size() < pubCount()) {
                ibtnAddPub.setVisibility(View.VISIBLE);
                btnCollectFinish.setEnabled(false);
            } else {
                ibtnAddPub.setVisibility(View.GONE);
                btnCollectFinish.setEnabled(true);
            }
        }
        return;
    }
    super.onActivityResult(requestCode, resultCode, data);
}
 
Example 8
Source File: AddEnterpriseHDMKeychainActivity.java    From bither-android with Apache License 2.0 4 votes vote down vote up
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (AddPubCode == requestCode) {
        if (resultCode == RESULT_OK) {
            String result = data.getStringExtra(ScanActivity.INTENT_EXTRA_RESULT);
            if (Utils.isEmpty(result)) {
                return;
            }
            if (!result.startsWith(EnterpriseHDMSeed.XPubPrefix)) {
                DropdownMessage.showDropdownMessage(this, R.string
                        .enterprise_hdm_keychain_collect_pub_error);
                return;
            }
            result = result.substring(EnterpriseHDMSeed.XPubPrefix.length());
            LogUtil.d("AddPub", "pub : " + result);
            byte[] pub = null;
            try {
                if (result.length() == 130) {
                    pub = Utils.hexStringToByteArray(result);
                    if (HDKeyDerivation.createMasterPubKeyFromExtendedBytes(Arrays.copyOf
                            (pub, pub.length)) == null) {
                        pub = null;
                    }
                }
            } catch (Exception e) {
                pub = null;
                e.printStackTrace();
            }
            if (pub == null) {
                DropdownMessage.showDropdownMessage(this, R.string
                        .enterprise_hdm_keychain_collect_pub_error);
                return;
            }
            pubs.add(pub);
            for (int i = 0;
                 i < pubs.size() && i < llPubs.getChildCount();
                 i++) {
                View v = llPubs.getChildAt(i);
                v.setBackgroundColor(getResources().getColor(R.color.blue_dark));
            }
            if (pubs.size() < pubCount()) {
                ibtnAddPub.setVisibility(View.VISIBLE);
                btnCollectFinish.setEnabled(false);
            } else {
                ibtnAddPub.setVisibility(View.GONE);
                btnCollectFinish.setEnabled(true);
            }
        }
        return;
    }
    super.onActivityResult(requestCode, resultCode, data);
}