net.bither.bitherj.crypto.hd.DeterministicKey Java Examples

The following examples show how to use net.bither.bitherj.crypto.hd.DeterministicKey. 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: HDMAddress.java    From bitherj with Apache License 2.0 6 votes vote down vote up
public ArrayList<TransactionSignature> signMyPart(List<byte[]> unsignedHashes,
                                                  CharSequence password) {
    if (isInRecovery()) {
        throw new AssertionError("recovery hdm address can not sign");
    }
    DeterministicKey key = keychain.getExternalKey(pubs.index, password);
    ArrayList<TransactionSignature> sigs = new ArrayList<TransactionSignature>();
    for (int i = 0;
         i < unsignedHashes.size();
         i++) {
        TransactionSignature transactionSignature = new TransactionSignature(key.sign
                (unsignedHashes.get(i)), TransactionSignature.SigHash.ALL, false);
        sigs.add(transactionSignature);
    }
    key.wipe();
    return sigs;
}
 
Example #2
Source File: DesktopHDMKeychain.java    From bitherj with Apache License 2.0 6 votes vote down vote up
public ArrayList<TransactionSignature> signMyPart(List<byte[]> unsignedHashes,
                                                  CharSequence password,
                                                  List<PathTypeIndex> pathTypeIndexList) {


    ArrayList<TransactionSignature> sigs = new ArrayList<TransactionSignature>();
    for (int i = 0;
         i < unsignedHashes.size();
         i++) {
        PathTypeIndex pathTypeIndex = pathTypeIndexList.get(i);
        DeterministicKey key;
        if (pathTypeIndex.pathType == PathType.EXTERNAL_ROOT_PATH) {
            key = getExternalKey(pathTypeIndex.index, password);
        } else {
            key = getInternalKey(pathTypeIndex.index, password);
        }
        TransactionSignature transactionSignature = new TransactionSignature(key.sign
                (unsignedHashes.get(i)), TransactionSignature.SigHash.ALL, false);
        sigs.add(transactionSignature);
        key.wipe();
    }

    return sigs;
}
 
Example #3
Source File: DesktopHDMKeychain.java    From bitherj with Apache License 2.0 6 votes vote down vote up
public ArrayList<byte[]> signWithCold(List<byte[]> unsignedHashes,
                                      CharSequence password,
                                      List<PathTypeIndex> pathTypeIndexList) {


    ArrayList<byte[]> sigs = new ArrayList<byte[]>();
    for (int i = 0;
         i < unsignedHashes.size();
         i++) {
        PathTypeIndex pathTypeIndex = pathTypeIndexList.get(i);
        DeterministicKey key;
        if (pathTypeIndex.pathType == PathType.EXTERNAL_ROOT_PATH) {
            key = getExternalKey(pathTypeIndex.index, password);
            System.out.println("pub:" + Base58.encode(key.getPubKey()));
        } else {
            key = getInternalKey(pathTypeIndex.index, password);
        }
        ECKey.ECDSASignature signed = key.sign(unsignedHashes.get(i));
        sigs.add(signed.encodeToDER());
        key.wipe();
    }

    return sigs;
}
 
Example #4
Source File: DesktopHDMKeychain.java    From bitherj with Apache License 2.0 6 votes vote down vote up
private void initHDAccount(DeterministicKey master, EncryptedData encryptedMnemonicSeed,
                           EncryptedData encryptedHDSeed, boolean isSyncedComplete) {
    String firstAddress;
    ECKey k = new ECKey(mnemonicSeed, null);
    String address = k.toAddress();
    k.clearPrivateKey();
    DeterministicKey accountKey = getAccount(master);
    DeterministicKey internalKey = getChainRootKey(accountKey, AbstractHD.PathType.INTERNAL_ROOT_PATH);
    DeterministicKey externalKey = getChainRootKey(accountKey, AbstractHD.PathType.EXTERNAL_ROOT_PATH);
    DeterministicKey key = externalKey.deriveSoftened(0);
    firstAddress = key.toAddress();
    accountKey.wipe();
    master.wipe();

    wipeHDSeed();
    wipeMnemonicSeed();
    hdSeedId = AbstractDb.desktopAddressProvider.addHDKey(encryptedMnemonicSeed.toEncryptedString(),
            encryptedHDSeed.toEncryptedString(), firstAddress, isFromXRandom, address, externalKey.getPubKeyExtended(), internalKey
                    .getPubKeyExtended());
    internalKey.wipe();
    externalKey.wipe();


}
 
Example #5
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 #6
Source File: HDAccount.java    From bitherj with Apache License 2.0 5 votes vote down vote up
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 #7
Source File: HDAccount.java    From bitherj with Apache License 2.0 5 votes vote down vote up
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 #8
Source File: HDMKeychain.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public String signHDMBId(String messageHash, SecureCharSequence password) {
    DeterministicKey key = getExternalKey(0, password);
    log.info("messageHash:" + messageHash);
    if (key == null) {
        log.info("key:null");
    }

    byte[] signData = key.signHash(Utils.hexStringToByteArray(messageHash), null);

    return Utils.bytesToHexString(signData).toUpperCase();
}
 
Example #9
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 #10
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 #11
Source File: HDMKeychain.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public byte[] getExternalChainRootPubExtended(CharSequence password) throws MnemonicException
        .MnemonicLengthException {
    DeterministicKey ex = externalChainRoot(password);
    byte[] pub = ex.getPubKeyExtended();
    ex.wipe();
    return pub;
}
 
Example #12
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 #13
Source File: HDMKeychain.java    From bitherj with Apache License 2.0 5 votes vote down vote up
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 #14
Source File: HDAccount.java    From bitherj with Apache License 2.0 5 votes vote down vote up
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 #15
Source File: HDAccount.java    From bitherj with Apache License 2.0 5 votes vote down vote up
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 #16
Source File: HDAccount.java    From bitherj with Apache License 2.0 5 votes vote down vote up
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 #17
Source File: HDMKeychain.java    From bitherj with Apache License 2.0 5 votes vote down vote up
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 #18
Source File: DesktopHDMAddress.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public ArrayList<TransactionSignature> signMyPart(List<byte[]> unsignedHashes,
                                                  CharSequence password) {
    DeterministicKey key = keychain.getExternalKey(pubs.index, password);
    ArrayList<TransactionSignature> sigs = new ArrayList<TransactionSignature>();
    for (int i = 0;
         i < unsignedHashes.size();
         i++) {
        TransactionSignature transactionSignature = new TransactionSignature(key.sign
                (unsignedHashes.get(i)), TransactionSignature.SigHash.ALL, false);
        sigs.add(transactionSignature);
    }
    key.wipe();
    return sigs;
}
 
Example #19
Source File: HDAccount.java    From bitherj with Apache License 2.0 5 votes vote down vote up
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 #20
Source File: HDMKeychain.java    From bitherj with Apache License 2.0 5 votes vote down vote up
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 #21
Source File: DesktopHDMKeychain.java    From bitherj with Apache License 2.0 5 votes vote down vote up
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 #22
Source File: DesktopHDMKeychain.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public byte[] getExternalChainRootPubExtended(CharSequence password) throws MnemonicException
        .MnemonicLengthException {
    DeterministicKey ex = externalChainRoot(password);
    byte[] pub = ex.getPubKeyExtended();
    ex.wipe();
    return pub;
}
 
Example #23
Source File: DesktopHDMKeychain.java    From bitherj with Apache License 2.0 5 votes vote down vote up
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 #24
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 #25
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 #26
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 #27
Source File: EnterpriseHDMSeed.java    From bitherj with Apache License 2.0 5 votes vote down vote up
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 #28
Source File: EnterpriseHDMSeed.java    From bitherj with Apache License 2.0 5 votes vote down vote up
public List<byte[]> signHashes(int index, List<byte[]> hashes, CharSequence password) {
    DeterministicKey key = getExternalKey(index, password);
    ArrayList<byte[]> sigs = new ArrayList<byte[]>();
    for (int i = 0;
         i < hashes.size();
         i++) {
        sigs.add(key.sign(hashes.get(i)).encodeToDER());
    }
    return sigs;
}
 
Example #29
Source File: AbstractHD.java    From bitherj with Apache License 2.0 5 votes vote down vote up
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 #30
Source File: AbstractHD.java    From bitherj with Apache License 2.0 5 votes vote down vote up
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;
}