Search in sources :

Example 1 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 2 with ChildNumber

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

the class KeyChainTransactionSigner method getSignature.

@Override
protected SignatureAndKey getSignature(Sha256Hash sighash, List<ChildNumber> derivationPath) {
    List<ChildNumber> keyPath = ImmutableList.copyOf(derivationPath);
    DeterministicKey key = keyChain.getKeyByPath(keyPath, true);
    return new SignatureAndKey(key.sign(sighash), key.dropPrivateBytes().dropParent());
}
Also used : ChildNumber(org.bitcoinj.crypto.ChildNumber) DeterministicKey(org.bitcoinj.crypto.DeterministicKey)

Example 3 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 4 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 5 with ChildNumber

use of org.bitcoinj.crypto.ChildNumber in project Elastos.DID.Java.SDK by elastos.

the class HDKey method derive.

public HDKey derive(String path) {
    HDPath derivePath = HDPath.parsePath(path);
    DeterministicKey child = key;
    for (ChildNumber childNumber : derivePath) child = HDKeyDerivation.deriveChildKey(child, childNumber);
    return new HDKey(child);
}
Also used : HDPath(org.bitcoinj.crypto.HDPath) 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