当前位置: 首页>>代码示例>>Java>>正文


Java DeterministicHierarchy类代码示例

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


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


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