Search in sources :

Example 16 with ChildNumber

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

the class MasterPrivateKeyBCH 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;
    }
    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 17 with ChildNumber

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

the class MasterPrivateKeyETH 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;
    }
    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)

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