Search in sources :

Example 6 with ChildNumber

use of org.bitcoinj.crypto.ChildNumber in project bitrafael_public by GENERALBYTESCOM.

the class MasterPrivateKeyBTC method serializePUB.

public static String serializePUB(DeterministicKey masterKey, int standard, int accountIndex, String cryptoCurrency) {
    final DeterministicKey purposeKey = HDKeyDerivation.deriveChildKey(masterKey, new ChildNumber(standard, true));
    final DeterministicKey coinKey = HDKeyDerivation.deriveChildKey(purposeKey, new ChildNumber(WalletTools.getCoinTypeByCryptoCurrency(cryptoCurrency), true));
    final DeterministicKey accountKey = HDKeyDerivation.deriveChildKey(coinKey, new ChildNumber(accountIndex, true));
    int header = 0x0488b21e;
    switch(standard) {
        case IWalletTools.STANDARD_BIP44:
            // xpub
            header = XPUB;
            break;
        case IWalletTools.STANDARD_BIP49:
            // ypub
            header = YPUB;
            break;
        case IWalletTools.STANDARD_BIP84:
            // zpub
            header = ZPUB;
            break;
    }
    ByteBuffer ser = ByteBuffer.allocate(78);
    ser.putInt(header);
    ser.put((byte) accountKey.getDepth());
    ser.putInt(accountKey.getParentFingerprint());
    ser.putInt(accountKey.getChildNumber().i());
    ser.put(accountKey.getChainCode());
    ser.put(accountKey.getPubKey());
    checkState(ser.position() == 78);
    return Base58.encode(addChecksum(ser.array()));
}
Also used : ChildNumber(org.bitcoinj.crypto.ChildNumber) ByteBuffer(java.nio.ByteBuffer) DeterministicKey(org.bitcoinj.crypto.DeterministicKey)

Example 7 with ChildNumber

use of org.bitcoinj.crypto.ChildNumber in project cosmostation-android by cosmostation.

the class WKey method getKeyWithPathfromEntropy.

// singer
public static DeterministicKey getKeyWithPathfromEntropy(Account account, String entropy) {
    BaseChain chain = getChain(account.baseChain);
    if (!chain.equals(FETCHAI_MAIN)) {
        DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(getHDSeed(WUtil.HexStringToByteArray(entropy)));
        return new DeterministicHierarchy(masterKey).deriveChild(WKey.getParentPath(chain, account.customPath), true, true, new ChildNumber(Integer.parseInt(account.path)));
    } else {
        DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(getHDSeed(WUtil.HexStringToByteArray(entropy)));
        if (account.customPath != 2) {
            DeterministicKey targetKey = new DeterministicHierarchy(masterKey).deriveChild(WKey.getParentPath(chain, account.customPath), true, true, new ChildNumber(Integer.parseInt(account.path)));
            return targetKey;
        } else {
            DeterministicKey targetKey = new DeterministicHierarchy(masterKey).deriveChild(WKey.getParentPath(chain, account.customPath), true, true, new ChildNumber(Integer.parseInt(account.path), true));
            DeterministicKey targetKey2 = new DeterministicHierarchy(targetKey).deriveChild(WKey.getFetchParentPath2(), true, true, ChildNumber.ZERO);
            return targetKey2;
        }
    }
}
Also used : ChildNumber(org.bitcoinj.crypto.ChildNumber) BaseChain(wannabit.io.cosmostaion.base.BaseChain) DeterministicKey(org.bitcoinj.crypto.DeterministicKey) DeterministicHierarchy(org.bitcoinj.crypto.DeterministicHierarchy)

Example 8 with ChildNumber

use of org.bitcoinj.crypto.ChildNumber in project haveno by haveno-dex.

the class HavenoKeyChainFactory method makeKeyChain.

@Override
public DeterministicKeyChain makeKeyChain(Protos.Key key, Protos.Key firstSubKey, DeterministicSeed seed, KeyCrypter crypter, boolean isMarried, Script.ScriptType outputScriptType, ImmutableList<ChildNumber> accountPath) {
    ImmutableList<ChildNumber> maybeUpdatedAccountPath = accountPath;
    if (DeterministicKeyChain.ACCOUNT_ZERO_PATH.equals(accountPath)) {
        // This is a bitcoinj 0.14 wallet that has no account path in the serialized mnemonic
        KeyChainGroupStructure structure = new HavenoKeyChainGroupStructure();
        maybeUpdatedAccountPath = structure.accountPathFor(outputScriptType);
    }
    return super.makeKeyChain(key, firstSubKey, seed, crypter, isMarried, outputScriptType, maybeUpdatedAccountPath);
}
Also used : KeyChainGroupStructure(org.bitcoinj.wallet.KeyChainGroupStructure) ChildNumber(org.bitcoinj.crypto.ChildNumber)

Example 9 with ChildNumber

use of org.bitcoinj.crypto.ChildNumber in project cosmostation-android by cosmostation.

the class WKey method getCreateKeyWithPathfromEntropy.

// create, restore
public static DeterministicKey getCreateKeyWithPathfromEntropy(BaseChain chain, String entropy, int path, int customPath) {
    if (!chain.equals(FETCHAI_MAIN)) {
        DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(getHDSeed(WUtil.HexStringToByteArray(entropy)));
        return new DeterministicHierarchy(masterKey).deriveChild(WKey.getParentPath(chain, customPath), true, true, new ChildNumber(path));
    } else {
        DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(getHDSeed(WUtil.HexStringToByteArray(entropy)));
        if (customPath != 2) {
            DeterministicKey targetKey = new DeterministicHierarchy(masterKey).deriveChild(WKey.getParentPath(chain, customPath), true, true, new ChildNumber(path));
            return targetKey;
        } else {
            DeterministicKey targetKey = new DeterministicHierarchy(masterKey).deriveChild(WKey.getParentPath(chain, customPath), true, true, new ChildNumber(path, true));
            DeterministicKey targetKey2 = new DeterministicHierarchy(targetKey).deriveChild(WKey.getFetchParentPath2(), true, true, ChildNumber.ZERO);
            return targetKey2;
        }
    }
}
Also used : ChildNumber(org.bitcoinj.crypto.ChildNumber) DeterministicKey(org.bitcoinj.crypto.DeterministicKey) DeterministicHierarchy(org.bitcoinj.crypto.DeterministicHierarchy)

Example 10 with ChildNumber

use of org.bitcoinj.crypto.ChildNumber in project bitcoin-spring-boot-starter by theborakompanioni.

the class MoreHdKeyDerivation method deriveChildKeyRecursive.

private static DeterministicKey deriveChildKeyRecursive(DeterministicKey parent, List<ChildNumber> childNumbers) {
    if (childNumbers.isEmpty()) {
        return parent;
    }
    ChildNumber first = childNumbers.get(0);
    DeterministicKey childKey = HDKeyDerivation.deriveChildKey(parent, first);
    List<ChildNumber> newChildNumbers = childNumbers.stream().skip(1).collect(Collectors.toList());
    return deriveChildKeyRecursive(childKey, newChildNumbers);
}
Also used : ChildNumber(org.bitcoinj.crypto.ChildNumber) DeterministicKey(org.bitcoinj.crypto.DeterministicKey)

Aggregations

ChildNumber (org.bitcoinj.crypto.ChildNumber)17 DeterministicKey (org.bitcoinj.crypto.DeterministicKey)15 DeterministicHierarchy (org.bitcoinj.crypto.DeterministicHierarchy)9 ByteString (com.google.protobuf.ByteString)7 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 HDPath (org.bitcoinj.crypto.HDPath)1 KeyChainGroupStructure (org.bitcoinj.wallet.KeyChainGroupStructure)1 WalletKeyPair (snowblossom.proto.WalletKeyPair)1 BaseChain (wannabit.io.cosmostaion.base.BaseChain)1