• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java DeterministicHierarchy类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.bitcoinj.crypto.DeterministicHierarchy的典型用法代码示例。如果您正苦于以下问题:Java DeterministicHierarchy类的具体用法?Java DeterministicHierarchy怎么用?Java DeterministicHierarchy使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



DeterministicHierarchy类属于org.bitcoinj.crypto包,在下文中一共展示了DeterministicHierarchy类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getUserExternalAddress

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的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);
	
}
 
开发者ID:uniquid,项目名称:uniquid-utils,代码行数:25,代码来源:AddressUtils.java


示例2: getUserInternalAddress

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的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);
	
}
 
开发者ID:uniquid,项目名称:uniquid-utils,代码行数:25,代码来源:AddressUtils.java


示例3: getProviderExternalAddress

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的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);
	
}
 
开发者ID:uniquid,项目名称:uniquid-utils,代码行数:25,代码来源:AddressUtils.java


示例4: getProviderInternalAddress

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的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);
	
}
 
开发者ID:uniquid,项目名称:uniquid-utils,代码行数:25,代码来源:AddressUtils.java


示例5: deriveCoin

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的package包/类
@Test
public void deriveCoin() throws Exception {
    DeterministicHierarchy hierarchy = new DeterministicHierarchy(masterKey);
    DeterministicKey rootKey = hierarchy.get(BitcoinMain.get().getBip44Path(0), false, true);
    chain = new SimpleHDKeyChain(rootKey);

    ECKey key1 = chain.getKey(SimpleHDKeyChain.KeyPurpose.RECEIVE_FUNDS);
    ECKey key2 = chain.getKey(SimpleHDKeyChain.KeyPurpose.RECEIVE_FUNDS);

    final Address address = new Address(BitcoinMain.get(), "1Fp7CA7ZVqZNFVNQ9TpeqWUas7K28K9zig");
    assertEquals(address, key1.toAddress(BitcoinMain.get()));
    assertEquals("1AKqkQM4VqyVis6hscj8695WHPCCzgHNY3", key2.toAddress(BitcoinMain.get()).toString());
    assertEquals(key1, chain.findKeyFromPubHash(address.getHash160()));
    assertEquals(key2, chain.findKeyFromPubKey(key2.getPubKey()));

    key1.sign(Sha256Hash.ZERO_HASH);

    ECKey key3 = chain.getKey(SimpleHDKeyChain.KeyPurpose.CHANGE);
    assertEquals("18YvGiRqXKxrzB72ckfrRSizWeHgwRP94V", key3.toAddress(BitcoinMain.get()).toString());
    key3.sign(Sha256Hash.ZERO_HASH);

    ECKey key4 = chain.getKey(SimpleHDKeyChain.KeyPurpose.CHANGE);
    assertEquals("1861TX2MbyPEUrxDQVWgV4Tp9991bK1zpy", key4.toAddress(BitcoinMain.get()).toString());
    key4.sign(Sha256Hash.ZERO_HASH);
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:26,代码来源:SimpleHDKeyChainTest.java


示例6: testHDAccountNxt

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的package包/类
@Test
public void testHDAccountNxt() throws MnemonicException, UnreadableWalletException {
    DeterministicSeed seed = new DeterministicSeed(recoveryPhrase, null, "", 0);
    DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes());
    DeterministicHierarchy hierarchy = new DeterministicHierarchy(masterKey);
    DeterministicKey entropy = hierarchy.get(NxtMain.get().getBip44Path(0), false, true);

    NxtFamilyKey nxtKey = new NxtFamilyKey(entropy, null, null);
    byte[] privateKey = nxtKey.getPrivateKey();
    byte[] publicKey = nxtKey.getPublicKey();
    NxtAddress address = new NxtAddress(NxtMain.get(), publicKey);

    assertArrayEquals(nxtPrivateKey, privateKey);
    assertArrayEquals(nxtPublicKey, publicKey);
    assertEquals(nxtRsAddress, address.toString());
    assertEquals(nxtAccountId, address.getAccountId());
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:18,代码来源:NxtFamilyTest.java


示例7: getMasterKey

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的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;

}
 
开发者ID:matsjj,项目名称:thundernetwork,代码行数:23,代码来源:Tools.java


示例8: initializeHierarchyUnencrypted

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的package包/类
private void initializeHierarchyUnencrypted(DeterministicKey baseKey) {
    rootKey = baseKey;
    addToBasicChain(rootKey);
    hierarchy = new DeterministicHierarchy(rootKey);
    externalKey = hierarchy.get(EXTERNAL_PATH, true, true);
    internalKey = hierarchy.get(INTERNAL_PATH, true, true);
    addToBasicChain(externalKey);
    addToBasicChain(internalKey);
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:10,代码来源:SimpleHDKeyChain.java


示例9: setup

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的package包/类
@Before
public void setup() {
    BriefLogFormatter.init();

    DeterministicSeed seed = new DeterministicSeed(ENTROPY, "", 0);
    masterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes());
    DeterministicHierarchy hierarchy = new DeterministicHierarchy(masterKey);
    DeterministicKey rootKey = hierarchy.get(ImmutableList.of(ChildNumber.ZERO_HARDENED), false, true);
    chain = new SimpleHDKeyChain(rootKey);
    chain.setLookaheadSize(10);
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:12,代码来源:SimpleHDKeyChainTest.java


示例10: serializeUnencryptedChildRoot

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的package包/类
@Test
public void serializeUnencryptedChildRoot() throws UnreadableWalletException {
    DeterministicHierarchy hierarchy = new DeterministicHierarchy(masterKey);
    DeterministicKey rootKey = hierarchy.get(BitcoinTest.get().getBip44Path(0), false, true);
    SimpleHDKeyChain newChain = new SimpleHDKeyChain(rootKey);
    serializeUnencrypted(newChain, DETERMINISTIC_WALLET_SERIALIZATION_TXT_CHILD_ROOT_KEY);
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:8,代码来源:SimpleHDKeyChainTest.java


示例11: encryptionChildRoot

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的package包/类
@Test
public void encryptionChildRoot() throws UnreadableWalletException {
    DeterministicHierarchy hierarchy = new DeterministicHierarchy(masterKey);
    DeterministicKey rootKey = hierarchy.get(BitcoinTest.get().getBip44Path(0), false, true);
    SimpleHDKeyChain newChain = new SimpleHDKeyChain(rootKey);

    encryption(newChain);
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:9,代码来源:SimpleHDKeyChainTest.java


示例12: setup

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的package包/类
@Before
public void setup() throws MnemonicException, UnreadableWalletException {
    DeterministicSeed seed = new DeterministicSeed(recoveryPhrase, null, "", 0);
    DeterministicKey masterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes());
    hierarchy = new DeterministicHierarchy(masterKey);
    wallet = new Wallet(recoveryPhrase);
    nxtAccount = (NxtFamilyWallet)wallet.createAccount(NXT, null);
    otherAccount = new NxtFamilyWallet(hierarchy.get(NXT.getBip44Path(1), false, true), NXT);
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:10,代码来源:NxtFamilyWalletTest.java


示例13: watchingChain

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的package包/类
@Test
public void watchingChain() throws UnreadableWalletException {
    Utils.setMockClock();
    DeterministicKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey key2 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey key3 = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    DeterministicKey key4 = chain.getKey(KeyChain.KeyPurpose.CHANGE);

    DeterministicKey watchingKey = chain.getWatchingKey();
    final String pub58 = watchingKey.serializePubB58();
    assertEquals("xpub69KR9epSNBM59KLuasxMU5CyKytMJjBP5HEZ5p8YoGUCpM6cM9hqxB9DDPCpUUtqmw5duTckvPfwpoWGQUFPmRLpxs5jYiTf2u6xRMcdhDf", pub58);
    watchingKey = DeterministicKey.deserializeB58(null, pub58);
    watchingKey.setCreationTimeSeconds(100000);
    chain = DeterministicKeyChain.watch(watchingKey);
    assertEquals(DeterministicHierarchy.BIP32_STANDARDISATION_TIME_SECS, chain.getEarliestKeyCreationTime());
    chain.setLookaheadSize(10);
    chain.maybeLookAhead();

    assertEquals(key1.getPubKeyPoint(), chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).getPubKeyPoint());
    assertEquals(key2.getPubKeyPoint(), chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).getPubKeyPoint());
    final DeterministicKey key = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    assertEquals(key3.getPubKeyPoint(), key.getPubKeyPoint());
    try {
        // Can't sign with a key from a watching chain.
        key.sign(Sha256Hash.ZERO_HASH);
        fail();
    } catch (ECKey.MissingPrivateKeyException e) {
        // Ignored.
    }
    // Test we can serialize and deserialize a watching chain OK.
    List<Protos.Key> serialization = chain.serializeToProtobuf();
    checkSerialization(serialization, "watching-wallet-serialization.txt");
    chain = DeterministicKeyChain.fromProtobuf(serialization, null).get(0);
    final DeterministicKey rekey4 = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    assertEquals(key4.getPubKeyPoint(), rekey4.getPubKeyPoint());
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:37,代码来源:DeterministicKeyChainTest.java


示例14: watchingChain

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的package包/类
@Test
public void watchingChain() throws UnreadableWalletException {
    Utils.setMockClock();
    DeterministicKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey key2 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey key3 = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    DeterministicKey key4 = chain.getKey(KeyChain.KeyPurpose.CHANGE);

    NetworkParameters params = MainNetParams.get();
    DeterministicKey watchingKey = chain.getWatchingKey();
    final String pub58 = watchingKey.serializePubB58(params);
    assertEquals("xpub69KR9epSNBM59KLuasxMU5CyKytMJjBP5HEZ5p8YoGUCpM6cM9hqxB9DDPCpUUtqmw5duTckvPfwpoWGQUFPmRLpxs5jYiTf2u6xRMcdhDf", pub58);
    watchingKey = DeterministicKey.deserializeB58(null, pub58, params);
    watchingKey.setCreationTimeSeconds(100000);
    chain = DeterministicKeyChain.watch(watchingKey);
    assertEquals(DeterministicHierarchy.BIP32_STANDARDISATION_TIME_SECS, chain.getEarliestKeyCreationTime());
    chain.setLookaheadSize(10);
    chain.maybeLookAhead();

    assertEquals(key1.getPubKeyPoint(), chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).getPubKeyPoint());
    assertEquals(key2.getPubKeyPoint(), chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).getPubKeyPoint());
    final DeterministicKey key = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    assertEquals(key3.getPubKeyPoint(), key.getPubKeyPoint());
    try {
        // Can't sign with a key from a watching chain.
        key.sign(Sha256Hash.ZERO_HASH);
        fail();
    } catch (ECKey.MissingPrivateKeyException e) {
        // Ignored.
    }
    // Test we can serialize and deserialize a watching chain OK.
    List<Protos.Key> serialization = chain.serializeToProtobuf();
    checkSerialization(serialization, "watching-wallet-serialization.txt");
    chain = DeterministicKeyChain.fromProtobuf(serialization, null).get(0);
    final DeterministicKey rekey4 = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    assertEquals(key4.getPubKeyPoint(), rekey4.getPubKeyPoint());
}
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:38,代码来源:DeterministicKeyChainTest.java


示例15: trezorAccountChainUsingPrivateMasterKey

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的package包/类
/**
* Test that a chain can be created for an account other than the HD account 0 of the BIP32 spec.
* In this test a chain pointing to account 44 is created and some addresses tested.
* This is a BIP44/ Trezor compatible chain. See https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
*
* In this test the private master key is available
*
* @throws UnreadableWalletException
*/
 @Test
 public void trezorAccountChainUsingPrivateMasterKey() throws UnreadableWalletException {
     DeterministicSeed seed = new DeterministicSeed(TREZOR_SEED_PHRASE, null, "", secs);
     DeterministicKey privateMasterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes());
     log.debug("privateMasterKey = " + privateMasterKey);

     DeterministicKey key_m_44h = HDKeyDerivation.deriveChildKey(privateMasterKey, new ChildNumber(44 | ChildNumber.HARDENED_BIT));
     log.debug("key_m_44h deterministic key = " + key_m_44h);

     DeterministicKey key_m_44h_0h = HDKeyDerivation.deriveChildKey(key_m_44h, ChildNumber.ZERO_HARDENED);
     log.debug("key_m_44h_0h deterministic key = " + key_m_44h_0h);

     DeterministicHierarchy deterministicHierarchy = new DeterministicHierarchy(key_m_44h_0h);

     DeterministicKey key_m_44h_0h_0h = deterministicHierarchy.deriveChild(key_m_44h_0h.getPath(), false, false, new ChildNumber(0, true));
     log.debug("key_m_44h_0h_0h = " + key_m_44h_0h_0h);

     ImmutableList<ChildNumber> key_m_44h_0h_0h_path = key_m_44h_0h_0h.getPath();
     log.debug("key_m_44h_0h_0h_path = " + key_m_44h_0h_0h_path);

     // Generate a chain using the derived key i.e. master private key is available
     DeterministicKeyChain accountChain = new DeterministicKeyChain(seed, key_m_44h_0h_0h_path);
     log.debug("accountChain = " + accountChain);

     assertNotNull(accountChain.getSeed());
     assertEquals(secs, accountChain.getSeed().getCreationTimeSeconds());

     checkAccountChain(accountChain);
 }
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:39,代码来源:DeterministicKeyChainTest.java


示例16: calculateImprintAddress

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的package包/类
/**
 * Calculates the imprint address from a node's deterministic key
 * 
 * @param deterministicKey the node's deterministicKey key 
 * @param networkParameters the network parameters to use
 * @return the imprint address of the node
 */
public static Address calculateImprintAddress(final DeterministicKey deterministicKey, final NetworkParameters networkParameters) {

	final DeterministicHierarchy deterministicHierarchy = new DeterministicHierarchy(deterministicKey);

	List<ChildNumber> imprintingChild = null;
	if (deterministicKey.getDepth() == 2) {

		/* M/44'/0' node tpub */

		imprintingChild = ImmutableList.of(new ChildNumber(0, false), new ChildNumber(0, false),
				new ChildNumber(0, false), new ChildNumber(0, false));

	} else if (deterministicKey.getDepth() == 3) {

		/* M/44'/0'/X context tpub */
		imprintingChild = ImmutableList.of(new ChildNumber(0, false), new ChildNumber(0, false),
				new ChildNumber(0, false));
	}

	DeterministicKey imprintingKey = deterministicHierarchy.get(imprintingChild, true, true);
	return imprintingKey.toAddress(networkParameters);

}
 
开发者ID:uniquid,项目名称:uidcore-java,代码行数:31,代码来源:NodeUtils.java


示例17: fromProtobuf

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的package包/类
/**
 * Returns the key chain found in the given list of keys.
 */
public static SimpleHDKeyChain fromProtobuf(List<Protos.Key> keys, @Nullable KeyCrypter crypter) throws UnreadableWalletException {
    SimpleHDKeyChain chain = null;
    int lookaheadSize = -1;
    // If the root key is a child of another hierarchy, the depth will be > 0
    int rootTreeSize = 0;
    for (Protos.Key key : keys) {
        final Protos.Key.Type t = key.getType();
        if (t == Protos.Key.Type.DETERMINISTIC_KEY) {
            if (!key.hasDeterministicKey())
                throw new UnreadableWalletException("Deterministic key missing extra data: " + key.toString());

            if (chain == null) {
                DeterministicKey rootKey = KeyUtils.getDeterministicKey(key, null, crypter);
                chain = new SimpleHDKeyChain(rootKey, crypter);
                chain.lookaheadSize = LAZY_CALCULATE_LOOKAHEAD;
                rootTreeSize = rootKey.getPath().size();
            }
            LinkedList<ChildNumber> path = newLinkedList(KeyUtils.getKeyProtoPath(key));
            // Find the parent key assuming this is not the root key, and not an account key for a watching chain.
            DeterministicKey parent = null;
            if (path.size() > rootTreeSize) {
                ChildNumber index = path.removeLast();
                parent = chain.hierarchy.get(path, false, false);
                path.add(index);
            }
            DeterministicKey detkey = KeyUtils.getDeterministicKey(key, parent, crypter);
            if (log.isDebugEnabled()) {
                log.debug("Deserializing: DETERMINISTIC_KEY: {}", detkey);
            }
            // If the non-encrypted case, the non-leaf keys (account, internal, external) have already been
            // rederived and inserted at this point and the two lines below are just a no-op. In the encrypted
            // case though, we can't rederive and we must reinsert, potentially building the heirarchy object
            // if need be.
            if (path.size() == rootTreeSize) {
                // Master key.
                chain.rootKey = detkey;
                chain.hierarchy = new DeterministicHierarchy(detkey);
            } else if (path.size() == rootTreeSize + EXTERNAL_PATH.size()) {
                if (EXTERNAL_PATH_NUM.equals(detkey.getChildNumber())) {
                    chain.externalKey = detkey;
                    chain.issuedExternalKeys = key.getDeterministicKey().getIssuedSubkeys();
                    lookaheadSize = Math.max(lookaheadSize, key.getDeterministicKey().getLookaheadSize());
                } else if (INTERNAL_PATH_NUM.equals(detkey.getChildNumber())) {
                    chain.internalKey = detkey;
                    chain.issuedInternalKeys = key.getDeterministicKey().getIssuedSubkeys();
                }
            }
            chain.hierarchy.putKey(detkey);
            chain.simpleKeyChain.importKey(detkey);
        }
    }
    if (chain == null) {
        throw new UnreadableWalletException("Could not create a key chain.");
    }
    checkState(lookaheadSize >= 0, "Negative lookahead size");
    chain.setLookaheadSize(lookaheadSize);
    chain.maybeLookAhead();
    return chain;
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:63,代码来源:SimpleHDKeyChain.java


示例18: testSendingAndBalances

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的package包/类
@Test
public void testSendingAndBalances() throws Exception {
    DeterministicHierarchy h = new DeterministicHierarchy(masterKey);
    WalletPocketHD account1 = new WalletPocketHD(h.get(BTC.getBip44Path(0), false, true), BTC, null, null);
    WalletPocketHD account2 = new WalletPocketHD(h.get(BTC.getBip44Path(1), false, true), BTC, null, null);
    WalletPocketHD account3 = new WalletPocketHD(h.get(BTC.getBip44Path(2), false, true), BTC, null, null);

    Transaction tx = new Transaction(BTC);
    tx.addOutput(BTC.oneCoin().toCoin(), account1.getReceiveAddress());
    tx.getConfidence().setSource(Source.SELF);
    account1.addNewTransactionIfNeeded(tx);


    assertEquals(BTC.value("1"), account1.getBalance());
    assertEquals(BTC.value("0"), account2.getBalance());
    assertEquals(BTC.value("0"), account3.getBalance());

    Sha256Hash txId = send(BTC.value("0.05"), account1, account2);

    assertEquals(BTC.value("0.94"), account1.getBalance());
    assertEquals(BTC.value("0"), account2.getBalance());
    assertEquals(BTC.value("0"), account3.getBalance());

    setTrustedTransaction(account1, txId);
    setTrustedTransaction(account2, txId);

    assertEquals(BTC.value("0.94"), account1.getBalance());
    assertEquals(BTC.value("0.05"), account2.getBalance());

    txId = send(BTC.value("0.07"), account1, account3);
    setTrustedTransaction(account1, txId);
    setTrustedTransaction(account3, txId);

    assertEquals(BTC.value("0.86"), account1.getBalance());
    assertEquals(BTC.value("0.05"), account2.getBalance());
    assertEquals(BTC.value("0.07"), account3.getBalance());

    txId = send(BTC.value("0.03"), account2, account3);
    setTrustedTransaction(account2, txId);
    setTrustedTransaction(account3, txId);

    assertEquals(BTC.value("0.86"), account1.getBalance());
    assertEquals(BTC.value("0.01"), account2.getBalance());
    assertEquals(BTC.value("0.1"), account3.getBalance());
}
 
开发者ID:filipnyquist,项目名称:lbry-android,代码行数:46,代码来源:WalletPocketHDTest.java


示例19: accountChainUsingPublicMasterKey

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的package包/类
/**
* Test that a chain can be created for an account other than the HD account 0 of the BIP32 spec.
* In this test a chain pointing to account 44 is created and some addresses tested.
* This is a BIP44/ Trezor compatible chain. See https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki
*
* In this test only the public master key is available
*
* @throws UnreadableWalletException
*/
@Test
public void accountChainUsingPublicMasterKey() throws UnreadableWalletException {

    DeterministicSeed seed = new DeterministicSeed(TREZOR_SEED_PHRASE, null, "", secs);

    DeterministicKey privateMasterKey = HDKeyDerivation.createMasterPrivateKey(seed.getSeedBytes());
    log.debug("privateMasterKey = " + privateMasterKey);

    DeterministicKey key_m_44h = HDKeyDerivation.deriveChildKey(privateMasterKey, new ChildNumber(44 | ChildNumber.HARDENED_BIT));

    DeterministicKey key_m_44h_0h = HDKeyDerivation.deriveChildKey(key_m_44h, ChildNumber.ZERO_HARDENED);

    DeterministicHierarchy deterministicHierarchy = new DeterministicHierarchy(key_m_44h_0h);

    DeterministicKey key_m_44h_0h_0h = deterministicHierarchy.deriveChild(key_m_44h_0h.getPath(), false, false, new ChildNumber(0, true));

    ImmutableList<ChildNumber> key_m_44h_0h_0h_path = key_m_44h_0h_0h.getPath();

    DeterministicKey key_m_44h_0h_0h_pubOnly = key_m_44h_0h_0h.getPubOnly();

    // Generate a chain using the pubkey only of the root node
    DeterministicKeyChain accountChain = new DeterministicKeyChain(key_m_44h_0h_0h_pubOnly, key_m_44h_0h_0h_pubOnly.getCreationTimeSeconds(), key_m_44h_0h_0h_path);

    checkAccountChain(accountChain);
}
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:35,代码来源:DeterministicKeyChainTest.java


示例20: UniquidNodeImpl

import org.bitcoinj.crypto.DeterministicHierarchy; //导入依赖的package包/类
/**
 * Creates a new instance
 * 
 * @param uniquidNodeConfiguration
 * @throws NodeException
 */
protected UniquidNodeImpl(T uniquidNodeConfiguration, DeterministicSeed deterministicSeed) throws NodeException {

	super(uniquidNodeConfiguration);
	
	this.deterministicSeed = deterministicSeed;
	
	DeterministicKey deterministicKey = NodeUtils
			.createDeterministicKeyFromDeterministicSeed(deterministicSeed);
	
	deterministicHierarchy = new DeterministicHierarchy(deterministicKey);

}
 
开发者ID:uniquid,项目名称:uidcore-java,代码行数:19,代码来源:UniquidNodeImpl.java



注:本文中的org.bitcoinj.crypto.DeterministicHierarchy类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java ChallengeState类代码示例发布时间:2022-05-23
下一篇:
Java UIView类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap