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()));
}
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;
}
}
}
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);
}
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;
}
}
}
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);
}
Aggregations