本文整理汇总了Java中org.bitcoinj.crypto.ChildNumber类的典型用法代码示例。如果您正苦于以下问题:Java ChildNumber类的具体用法?Java ChildNumber怎么用?Java ChildNumber使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ChildNumber类属于org.bitcoinj.crypto包,在下文中一共展示了ChildNumber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: init
import org.bitcoinj.crypto.ChildNumber; //导入依赖的package包/类
private void init(NetworkParameters params, byte[] seed, String passphrase) {
this.params = params;
this.seed = seed;
strPassphrase = passphrase;
byte[] hd_seed = MnemonicCode.toSeed(wordList, "");
dkKey = HDKeyDerivation.createMasterPrivateKey(hd_seed);
DeterministicKey dKey = HDKeyDerivation.deriveChildKey(dkKey, 44 | ChildNumber.HARDENED_BIT);
dkRoot = HDKeyDerivation.deriveChildKey(dKey, ChildNumber.HARDENED_BIT);
int nbAccounts = 1;
accounts = new ArrayList<Account>();
for(int i = 0; i < nbAccounts; i++) {
accounts.add(new Account(params, dkRoot, i));
}
strPath = dKey.getPathAsString();
}
示例2: getUserExternalAddress
import org.bitcoinj.crypto.ChildNumber; //导入依赖的package包/类
public static Address getUserExternalAddress(final String pubKey, final NetworkParameters networkParameters,
final long userIndex) {
DeterministicKey deterministicKey = DeterministicKey.deserializeB58(pubKey, networkParameters);
DeterministicHierarchy deterministicHierarchy = new DeterministicHierarchy(deterministicKey);
List<ChildNumber> child = null;
if (deterministicKey.getDepth() == 2) {
/* M/44'/0' node tpub */
child = ImmutableList.of(new ChildNumber(0, false), new ChildNumber(1/*user*/, false),
new ChildNumber(0/*external*/, false), new ChildNumber((int)userIndex, false));
} else if (deterministicKey.getDepth() == 3) {
/* M/44'/0'/X context tpub */
child = ImmutableList.of(new ChildNumber(1/*user*/, false),
new ChildNumber(0/*external*/, false), new ChildNumber((int)userIndex, false));
}
DeterministicKey imprintingKey = deterministicHierarchy.get(child, true, true);
return imprintingKey.toAddress(networkParameters);
}
示例3: getUserInternalAddress
import org.bitcoinj.crypto.ChildNumber; //导入依赖的package包/类
public static Address getUserInternalAddress(final String pubKey, final NetworkParameters networkParameters,
final long userIndex) {
DeterministicKey deterministicKey = DeterministicKey.deserializeB58(pubKey, networkParameters);
DeterministicHierarchy deterministicHierarchy = new DeterministicHierarchy(deterministicKey);
List<ChildNumber> child = null;
if (deterministicKey.getDepth() == 2) {
/* M/44'/0' node tpub */
child = ImmutableList.of(new ChildNumber(0, false), new ChildNumber(1/*user*/, false),
new ChildNumber(1/*internal*/, false), new ChildNumber((int)userIndex, false));
} else if (deterministicKey.getDepth() == 3) {
/* M/44'/0'/X context tpub */
child = ImmutableList.of(new ChildNumber(1/*user*/, false),
new ChildNumber(1/*internal*/, false), new ChildNumber((int)userIndex, false));
}
DeterministicKey imprintingKey = deterministicHierarchy.get(child, true, true);
return imprintingKey.toAddress(networkParameters);
}
示例4: getProviderExternalAddress
import org.bitcoinj.crypto.ChildNumber; //导入依赖的package包/类
public static Address getProviderExternalAddress(final String pubKey, final NetworkParameters networkParameters,
final long providerIndex) {
DeterministicKey deterministicKey = DeterministicKey.deserializeB58(pubKey, networkParameters);
DeterministicHierarchy deterministicHierarchy = new DeterministicHierarchy(deterministicKey);
List<ChildNumber> child = null;
if (deterministicKey.getDepth() == 2) {
/* M/44'/0' node tpub */
child = ImmutableList.of(new ChildNumber(0, false), new ChildNumber(0/*provider*/, false),
new ChildNumber(/*external*/0, false), new ChildNumber((int)providerIndex, false));
} else if (deterministicKey.getDepth() == 3) {
/* M/44'/0'/X context tpub */
child = ImmutableList.of(new ChildNumber(0/*provider*/, false),
new ChildNumber(/*external*/0, false), new ChildNumber((int)providerIndex, false));
}
DeterministicKey imprintingKey = deterministicHierarchy.get(child, true, true);
return imprintingKey.toAddress(networkParameters);
}
示例5: getProviderInternalAddress
import org.bitcoinj.crypto.ChildNumber; //导入依赖的package包/类
public static Address getProviderInternalAddress(final String pubKey, final NetworkParameters networkParameters,
final long providerIndex) {
DeterministicKey deterministicKey = DeterministicKey.deserializeB58(pubKey, networkParameters);
DeterministicHierarchy deterministicHierarchy = new DeterministicHierarchy(deterministicKey);
List<ChildNumber> child = null;
if (deterministicKey.getDepth() == 2) {
/* M/44'/0' node tpub */
child = ImmutableList.of(new ChildNumber(0, false), new ChildNumber(0/*provider*/, false),
new ChildNumber(1/*internal*/, false), new ChildNumber((int)providerIndex, false));
} else if (deterministicKey.getDepth() == 3) {
/* M/44'/0'/X context tpub */
child = ImmutableList.of(new ChildNumber(0/*provider*/, false),
new ChildNumber(1/*internal*/, false), new ChildNumber((int)providerIndex, false));
}
DeterministicKey imprintingKey = deterministicHierarchy.get(child, true, true);
return imprintingKey.toAddress(networkParameters);
}
示例6: Account
import org.bitcoinj.crypto.ChildNumber; //导入依赖的package包/类
/**
* Constructor for account.
*
* @param NetworkParameters params
* @param DeterministicKey mwey deterministic key for this account
* @param int child id within the wallet for this account
*
*/
public Account(NetworkParameters params, DeterministicKey wKey, int child) {
this.params = params;
aID = child;
// L0PRV & STDVx: private derivation.
int childnum = child;
childnum |= ChildNumber.HARDENED_BIT;
aKey = HDKeyDerivation.deriveChildKey(wKey, childnum);
strXPUB = aKey.serializePubB58(params);
chains = new ArrayList<Chain>();
chains.add(new Chain(params, aKey, true));
chains.add(new Chain(params, aKey, false));
strPath = aKey.getPathAsString();
}
示例7: toEditableProtobuf
import org.bitcoinj.crypto.ChildNumber; //导入依赖的package包/类
List<Protos.Key.Builder> toEditableProtobuf() {
LinkedList<Protos.Key.Builder> entries = newLinkedList();
// Entropy
Protos.Key.Builder entropyProto = KeyUtils.serializeKey(entropy);
entropyProto.setType(Protos.Key.Type.DETERMINISTIC_KEY);
final Protos.DeterministicKey.Builder detKey = entropyProto.getDeterministicKeyBuilder();
detKey.setChainCode(ByteString.copyFrom(entropy.getChainCode()));
for (ChildNumber num : entropy.getPath()) {
detKey.addPath(num.i());
}
entries.add(entropyProto);
// NTX key
Protos.Key.Builder publicKeyProto = Protos.Key.newBuilder();
publicKeyProto.setType(Protos.Key.Type.ORIGINAL);
publicKeyProto.setPublicKey(ByteString.copyFrom(publicKey));
entries.add(publicKeyProto);
return entries;
}
示例8: createCurrentKeysMap
import org.bitcoinj.crypto.ChildNumber; //导入依赖的package包/类
private static EnumMap<KeyChain.KeyPurpose, DeterministicKey> createCurrentKeysMap(List<DeterministicKeyChain> chains) {
DeterministicKeyChain activeChain = chains.get(chains.size() - 1);
EnumMap<KeyChain.KeyPurpose, DeterministicKey> currentKeys = new EnumMap<KeyChain.KeyPurpose, DeterministicKey>(KeyChain.KeyPurpose.class);
// assuming that only RECEIVE and CHANGE keys are being used at the moment, we will treat latest issued external key
// as current RECEIVE key and latest issued internal key as CHANGE key. This should be changed as soon as other
// kinds of KeyPurpose are introduced.
if (activeChain.getIssuedExternalKeys() > 0) {
DeterministicKey currentExternalKey = activeChain.getKeyByPath(
ImmutableList.of(ChildNumber.ZERO_HARDENED, ChildNumber.ZERO, new ChildNumber(activeChain.getIssuedExternalKeys() - 1))
);
currentKeys.put(KeyChain.KeyPurpose.RECEIVE_FUNDS, currentExternalKey);
}
if (activeChain.getIssuedInternalKeys() > 0) {
DeterministicKey currentInternalKey = activeChain.getKeyByPath(
ImmutableList.of(ChildNumber.ZERO_HARDENED, new ChildNumber(1), new ChildNumber(activeChain.getIssuedInternalKeys() - 1))
);
currentKeys.put(KeyChain.KeyPurpose.CHANGE, currentInternalKey);
}
return currentKeys;
}
示例9: getMasterKey
import org.bitcoinj.crypto.ChildNumber; //导入依赖的package包/类
/**
* Call to get the MasterKey for a new Channel.
* TODO: Change to request master node key..
*
* @param number Query the Database to get the latest unused number
* @return DeterministicKey for the new Channel
*/
public static DeterministicKey getMasterKey (int number) {
DeterministicKey hd = DeterministicKey.deserializeB58(SideConstants.KEY_B58, Constants.getNetwork());
// DeterministicKey hd = DeterministicKey.deserializeB58(null,KEY_B58);
// DeterministicKey hd = HDKeyDerivation.createMasterPrivateKey(KEY.getBytes());
DeterministicHierarchy hi = new DeterministicHierarchy(hd);
List<ChildNumber> childList = new ArrayList<ChildNumber>();
ChildNumber childNumber = new ChildNumber(number, true);
childList.add(childNumber);
DeterministicKey key = hi.get(childList, true, true);
return key;
}
示例10: EWDerivation
import org.bitcoinj.crypto.ChildNumber; //导入依赖的package包/类
public EWDerivation(byte[] seed) {
deterministicKey = HDKeyDerivation.createMasterPrivateKey(seed);
ewMaster = HDKeyDerivation.deriveChildKey(deterministicKey, new ChildNumber(EW_DERIVATION, true)); // /m/4544288'/
bitcoinMaster = HDKeyDerivation.deriveChildKey(ewMaster, new ChildNumber(0, true)); // /m/4544288'/0'
firstAccountMaster = HDKeyDerivation.deriveChildKey(bitcoinMaster, new ChildNumber(0, true)); // /m/4544288'/0'/0'
changesMaster = HDKeyDerivation.deriveChildKey(firstAccountMaster, new ChildNumber(0, false)); // /m/4544288'/0'/0'/0
messagesMaster = HDKeyDerivation.deriveChildKey(firstAccountMaster, new ChildNumber(1, false)); // /m/4544288'/0'/0'/1
/*
//Anonymous derivation are probably not needed
final DeterministicKey anonymousMaster = HDKeyDerivation.deriveChildKey(ewMaster, new ChildNumber(1,false) ); // /m/4544288'/1
anonymousChangesMaster = HDKeyDerivation.deriveChildKey(anonymousMaster, new ChildNumber(0,false) ); // /m/4544288'/1/0
anonymousMessagesMaster = HDKeyDerivation.deriveChildKey(anonymousMaster, new ChildNumber(1,false) ); // /m/4544288'/1/1
*/
final byte[] bytesMasterPublicKey = Bitcoin.fromHex(hexMasterPublicKey);
final byte[] bytesChainCode = Bitcoin.fromHex(hexChainCode);
donationMasterPublic = HDKeyDerivation.createMasterPubKeyFromBytes(bytesMasterPublicKey, bytesChainCode);
}
示例11: encrypt
import org.bitcoinj.crypto.ChildNumber; //导入依赖的package包/类
/**
*
* ALICE
* Encrypt the keys in the group using the KeyCrypter and the AES key. A good default KeyCrypter to use is
* {@link org.bitcoinj.crypto.KeyCrypterScrypt}.
*
* @throws org.bitcoinj.crypto.KeyCrypterException Thrown if the wallet encryption fails for some reason,
* leaving the group unchanged.
* @throws DeterministicUpgradeRequiredException Thrown if there are random keys but no HD chain.
*/
public void encrypt(KeyCrypter keyCrypter, KeyParameter aesKey, @Nullable ImmutableList<ChildNumber> rootNodeList) {
checkNotNull(keyCrypter);
checkNotNull(aesKey);
// This code must be exception safe.
BasicKeyChain newBasic = basic.toEncrypted(keyCrypter, aesKey);
List<DeterministicKeyChain> newChains = new ArrayList<DeterministicKeyChain>(chains.size());
if (chains.isEmpty() && basic.numKeys() == 0) {
// No HD chains and no random keys: encrypting an entirely empty keychain group. But we can't do that, we
// must have something to encrypt: so instantiate a new HD chain here.
createAndActivateNewHDChain(rootNodeList);
}
for (DeterministicKeyChain chain : chains) {
log.debug("chain: " + chain.toString());
newChains.add(chain.toEncrypted(keyCrypter, aesKey, rootNodeList));
}
this.keyCrypter = keyCrypter;
basic = newBasic;
chains.clear();
chains.addAll(newChains);
}
示例12: generatePathUntilAccountsAddress
import org.bitcoinj.crypto.ChildNumber; //导入依赖的package包/类
private DeterministicKey generatePathUntilAccountsAddress(byte[] seed, int accountIdx, HierarchyAddressTypes type) {
HDKeyDerivation HDKey = null;
DeterministicKey masterkey = HDKey.createMasterPrivateKey(seed);
// purpose level
ChildNumber purposeIndex = new ChildNumber(HierarchyPurpose.Bip43_VALUE, true); // is harden
DeterministicKey purpose = HDKey.deriveChildKey(masterkey,purposeIndex);
// coin level
ChildNumber coinIndex = new ChildNumber(typeBitcoin.getNumber(), true); // is harden
DeterministicKey coin = HDKey.deriveChildKey(purpose,coinIndex);
//account
ChildNumber accountIndex = new ChildNumber(accountIdx, true); // is harden
DeterministicKey account = HDKey.deriveChildKey(coin, accountIndex);
//address type
ChildNumber addressTypeIndex = new ChildNumber(type.getNumber(), false); // is not harden
DeterministicKey addressType = HDKey.deriveChildKey(account, addressTypeIndex);
return addressType;
}
示例13: getSignature
import org.bitcoinj.crypto.ChildNumber; //导入依赖的package包/类
@Override
protected SignatureAndKey getSignature(Sha256Hash sighash, List<ChildNumber> derivationPath) {
ImmutableList<ChildNumber> keyPath = ImmutableList.copyOf(derivationPath);
System.out.println("child numer: "+keyPath.get(0).getI());
System.out.println("getKeyByPath t: " + keyChain.getKeyByPath(keyPath, true));
//Dummy check. We will base our accept/reject criteria off of this.
Scanner in = new Scanner(System.in);
System.out.println("TransactionSigner: " + description + ", do you want to sign this transaxtion? [y/n]");
String sig = in.nextLine();
if(sig.equals("y") || sig.equals("yes")){
DeterministicKey key = keyChain.getKeyByPath(keyPath, true);
return new SignatureAndKey(key.sign(sighash), key.getPubOnly());
} else {
return new SignatureAndKey(watchingKey.sign(sighash), watchingKey.getPubOnly());
}
}
示例14: Address
import org.bitcoinj.crypto.ChildNumber; //导入依赖的package包/类
/**
* Constructor an HD address.
*
* @param NetworkParameters params
* @param DeterministicKey cKey deterministic key for this address
* @param int child index of this address in its chain
*
*/
public Address(NetworkParameters params, DeterministicKey cKey, int child) {
this.params = params;
childNum = child;
DeterministicKey dk = HDKeyDerivation.deriveChildKey(cKey, new ChildNumber(childNum, false));
// compressed WIF private key format
if(dk.hasPrivKey()) {
// byte[] prepended0Byte = ArrayUtils.addAll(new byte[1], dk.getPrivKeyBytes());
byte[] getPrivKeyBytes = dk.getPrivKeyBytes();
byte[] prepended0Byte = new byte[1 + getPrivKeyBytes.length];
prepended0Byte[0] = 0;
System.arraycopy(getPrivKeyBytes, 0, prepended0Byte, 1, getPrivKeyBytes.length);
ecKey = ECKey.fromPrivate(new BigInteger(prepended0Byte), true);
}
else {
ecKey = ECKey.fromPublicOnly(dk.getPubKey());
}
long now = Utils.now().getTime() / 1000; // use Unix time (in seconds)
ecKey.setCreationTimeSeconds(now);
pubKey = ecKey.getPubKey();
pubKeyHash = ecKey.getPubKeyHash();
strPath = dk.getPathAsString();
}
示例15: getKeyProtoPath
import org.bitcoinj.crypto.ChildNumber; //导入依赖的package包/类
public static ImmutableList<ChildNumber> getKeyProtoPath(Protos.Key key) {
ImmutableList.Builder<ChildNumber> pathBuilder = ImmutableList.builder();
for (int i : key.getDeterministicKey().getPathList()) {
pathBuilder.add(new ChildNumber(i));
}
return pathBuilder.build();
}