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


Java DeterministicKeyChain类代码示例

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


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

示例1: testRoundTripMarriedWallet

import org.bitcoinj.wallet.DeterministicKeyChain; //导入依赖的package包/类
@Test
public void testRoundTripMarriedWallet() throws Exception {
    // create 2-of-2 married wallet
    myWallet = new Wallet(PARAMS);
    final DeterministicKeyChain partnerChain = new DeterministicKeyChain(new SecureRandom());
    DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, partnerChain.getWatchingKey().serializePubB58(PARAMS), PARAMS);
    MarriedKeyChain chain = MarriedKeyChain.builder()
            .random(new SecureRandom())
            .followingKeys(partnerKey)
            .threshold(2).build();
    myWallet.addAndActivateHDChain(chain);

    myAddress = myWallet.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);

    Wallet wallet1 = roundTrip(myWallet);
    assertEquals(0, wallet1.getTransactions(true).size());
    assertEquals(Coin.ZERO, wallet1.getBalance());
    assertEquals(2, wallet1.getActiveKeyChain().getSigsRequiredToSpend());
    assertEquals(myAddress, wallet1.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS));
}
 
开发者ID:Grant-Redmond,项目名称:cryptwallet,代码行数:21,代码来源:WalletProtobufSerializerTest.java

示例2: setUp

import org.bitcoinj.wallet.DeterministicKeyChain; //导入依赖的package包/类
@Before
public void setUp() throws Exception {
    params = NetworkParameters.fromID(NetworkParameters.ID_UNITTESTNET);
    mapper = new ObjectMapper();

    DeterministicSeed seed = new DeterministicSeed("correct battery horse staple", null, "", 0);
    DeterministicKeyChain chain =
            DeterministicKeyChain.builder()
                    .seed(seed)
                    .build();
    KeyChainGroup group = new KeyChainGroup(params);
    group.addAndActivateHDChain(chain);
    wallet = new SmartWallet(params, group);
    wallet.setKeychainLookaheadSize(10);

    control = EasyMock.createStrictControl();
    client = control.createMock(StratumClient.class);
    expect(client.getConnectedAddresses()).andStubReturn(Lists.newArrayList(new InetSocketAddress(InetAddress.getLocalHost(), 0)));
    expect(client.getPeerVersion()).andStubReturn("1.0");
    store = control.createMock(HeadersStore.class);
    stratumChain = control.createMock(StratumChain.class);
    expect(stratumChain.getPeerHeight()).andStubReturn(100L);
    expect(store.get(340242)).andStubReturn(params.getGenesisBlock().cloneAsHeader());
    multiWallet = new ElectrumMultiWallet(wallet, BASE_DIRECTORY);
    multiWallet.start(client, stratumChain, store);
}
 
开发者ID:devrandom,项目名称:java-stratum,代码行数:27,代码来源:ElectrumMultiWalletTest.java

示例3: testRoundTripMarriedWallet

import org.bitcoinj.wallet.DeterministicKeyChain; //导入依赖的package包/类
@Test
public void testRoundTripMarriedWallet() throws Exception {
    // create 2-of-2 married wallet
    myWallet = new Wallet(params);
    final DeterministicKeyChain keyChain = new DeterministicKeyChain(new SecureRandom());
    DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, keyChain.getWatchingKey().serializePubB58());

    myWallet.addFollowingAccountKeys(ImmutableList.of(partnerKey), 2);
    myAddress = myWallet.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);

    Wallet wallet1 = roundTrip(myWallet);
    assertEquals(0, wallet1.getTransactions(true).size());
    assertEquals(Coin.ZERO, wallet1.getBalance());
    assertEquals(2, wallet1.getSigsRequiredToSpend());
    assertEquals(myAddress, wallet1.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS));
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:17,代码来源:WalletProtobufSerializerTest.java

示例4: testRoundTripMarriedWallet

import org.bitcoinj.wallet.DeterministicKeyChain; //导入依赖的package包/类
@Test
public void testRoundTripMarriedWallet() throws Exception {
    // create 2-of-2 married wallet
    myWallet = new Wallet(params);
    final DeterministicKeyChain partnerChain = new DeterministicKeyChain(new SecureRandom());
    DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, partnerChain.getWatchingKey().serializePubB58(params), params);
    MarriedKeyChain chain = MarriedKeyChain.builder()
            .random(new SecureRandom())
            .followingKeys(partnerKey)
            .threshold(2).build();
    myWallet.addAndActivateHDChain(chain);

    myAddress = myWallet.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS);

    Wallet wallet1 = roundTrip(myWallet);
    assertEquals(0, wallet1.getTransactions(true).size());
    assertEquals(Coin.ZERO, wallet1.getBalance());
    assertEquals(2, wallet1.getActiveKeychain().getSigsRequiredToSpend());
    assertEquals(myAddress, wallet1.currentAddress(KeyChain.KeyPurpose.RECEIVE_FUNDS));
}
 
开发者ID:DigiByte-Team,项目名称:digibytej-alice,代码行数:21,代码来源:WalletProtobufSerializerTest.java

示例5: addPairedWallet

import org.bitcoinj.wallet.DeterministicKeyChain; //导入依赖的package包/类
public void addPairedWallet (String description, DeterministicKeyChain chain, boolean increaseThreshold){
    	System.out.print(wallet().getDescription()+", a "+currentSigners+"/"+(followingKeyChains.size()+1)+" wallet... ");
    	
    	followingKeyChains.add(chain);
		if(increaseThreshold && currentSigners < walletThreshold){
			currentSigners++;
			this.wallet().addTransactionSigner(new DemoTransactionSigner(chain, description));
		}
	
		//We can leverage addAndActivateHDChain 
//		MarriedKeyChain marriedChain = MarriedKeyChain.builder()
//				.random(new SecureRandom())
//				.followingKeys(DeterministicKey.deserializeB58(null, chain.getWatchingKey().serializePubB58()))
//				.threshold(walletThreshold).build();
//		this.wallet().addAndActivateHDChain(marriedChain);
    	System.out.println("Is now a "+currentSigners+"/"+(followingKeyChains.size()+1)+" wallet");
    }
 
开发者ID:JohnnyCryptoCoin,项目名称:speciebox,代码行数:18,代码来源:HDWalletKit.java

示例6: startUp

import org.bitcoinj.wallet.DeterministicKeyChain; //导入依赖的package包/类
@Override
protected void startUp() throws Exception {
	super.startUp();
	
	if(! RELOAD){
		for(int i = 0; i<walletThreshold-1; i++){
			DeterministicKeyChain keyChain = new DeterministicKeyChain(new SecureRandom());
			followingKeys.add(keyChain.getWatchingKey());
			if(currentSigners < walletThreshold){
				currentSigners++;
				this.wallet().addTransactionSigner(new PluggableTransactionSigner(keyChain.getWatchingKey(), ("signer-"+(i+1))));
			}
		}
		//this.wallet().addFollowingAccountKeys(followingKeys, walletThreshold);
	}

}
 
开发者ID:JohnnyCryptoCoin,项目名称:speciebox,代码行数:18,代码来源:HDWalletKit2.java

示例7: createMultiSigWallet

import org.bitcoinj.wallet.DeterministicKeyChain; //导入依赖的package包/类
private void createMultiSigWallet(int threshold, int numKeys, boolean addSigners) throws BlockStoreException {
        wallet = new Wallet(params);
        blockStore = new MemoryBlockStore(params);
        chain = new BlockChain(params, wallet, blockStore);

        List<DeterministicKey> followingKeys = Lists.newArrayList();
        for (int i = 0; i < numKeys - 1; i++) {
            final DeterministicKeyChain keyChain = new DeterministicKeyChain(new SecureRandom());
            DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, keyChain.getWatchingKey().serializePubB58());
            followingKeys.add(partnerKey);
            if (addSigners && i < threshold - 1)
                wallet.addTransactionSigner(new KeyChainTransactionSigner(keyChain));
        }

//        MarriedKeyChain chain = MarriedKeyChain.builder()
//                .random(new SecureRandom())
//                .followingKeys(followingKeys)
//                .threshold(threshold).build();
//        wallet.addAndActivateHDChain(chain);
    }
 
开发者ID:JohnnyCryptoCoin,项目名称:speciebox,代码行数:21,代码来源:WalletTools.java

示例8: testSetupHDWalletAndAddWatchingKey

import org.bitcoinj.wallet.DeterministicKeyChain; //导入依赖的package包/类
public void testSetupHDWalletAndAddWatchingKey() throws Exception{
	walletKit_1 = new HDWalletKit(params, new File(testDirectory), filePrefix+System.currentTimeMillis(), 2);
	walletKit_1.startAsync();
	walletKit_1.awaitRunning();
	
	assertTrue(walletKit_1.getThreshold() == 2);
       assertTrue(walletKit_1.getSigners().size() == 1);
       SecureRandom random = new SecureRandom();
       DeterministicKeyChain chain = new DeterministicKeyChain(random);
       
       
       walletKit_1.addPairedWallet("description", chain, true);
       assertTrue(walletKit_1.getSigners().size() == 2);
       Address a = walletKit_1.wallet().freshReceiveAddress();
       assertTrue(a.isP2SHAddress());
	walletKit_1.stopAsync();
	walletKit_1.awaitTerminated();
}
 
开发者ID:JohnnyCryptoCoin,项目名称:speciebox,代码行数:19,代码来源:HDWalletKitTest.java

示例9: setup

import org.bitcoinj.wallet.DeterministicKeyChain; //导入依赖的package包/类
@Before
public void setup() {
    BriefLogFormatter.init();
    // You should use a random seed instead. The secs constant comes from the unit test file, so we can compare
    // serialized data properly.
    long secs = 1389353062L;
    chain = new DeterministicKeyChain(ENTROPY, "", secs);
    chain.setLookaheadSize(10);
    assertEquals(secs, checkNotNull(chain.getSeed()).getCreationTimeSeconds());
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:11,代码来源:DeterministicKeyChainTest.java

示例10: events

import org.bitcoinj.wallet.DeterministicKeyChain; //导入依赖的package包/类
@Test
public void events() throws Exception {
    // Check that we get the right events at the right time.
    final List<List<ECKey>> listenerKeys = Lists.newArrayList();
    long secs = 1389353062L;
    chain = new DeterministicKeyChain(ENTROPY, "", secs);
    chain.addEventListener(new AbstractKeyChainEventListener() {
        @Override
        public void onKeysAdded(List<ECKey> keys) {
            listenerKeys.add(keys);
        }
    }, Threading.SAME_THREAD);
    assertEquals(0, listenerKeys.size());
    chain.setLookaheadSize(5);
    assertEquals(0, listenerKeys.size());
    ECKey key = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    assertEquals(1, listenerKeys.size());  // 1 event
    final List<ECKey> firstEvent = listenerKeys.get(0);
    assertEquals(1, firstEvent.size());
    assertTrue(firstEvent.contains(key));   // order is not specified.
    listenerKeys.clear();

    chain.maybeLookAhead();
    final List<ECKey> secondEvent = listenerKeys.get(0);
    assertEquals(12, secondEvent.size());  // (5 lookahead keys, +1 lookahead threshold) * 2 chains
    listenerKeys.clear();

    chain.getKey(KeyChain.KeyPurpose.CHANGE);
    // At this point we've entered the threshold zone so more keys won't immediately trigger more generations.
    assertEquals(0, listenerKeys.size());  // 1 event
    final int lookaheadThreshold = chain.getLookaheadThreshold() + chain.getLookaheadSize();
    for (int i = 0; i < lookaheadThreshold; i++)
        chain.getKey(KeyChain.KeyPurpose.CHANGE);
    assertEquals(1, listenerKeys.size());  // 1 event
    assertEquals(1, listenerKeys.get(0).size());  // 1 key.
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:37,代码来源:DeterministicKeyChainTest.java

示例11: random

import org.bitcoinj.wallet.DeterministicKeyChain; //导入依赖的package包/类
@Test
public void random() {
    // Can't test much here but verify the constructor worked and the class is functional. The other tests rely on
    // a fixed seed to be deterministic.
    chain = new DeterministicKeyChain(new SecureRandom(), 384);
    chain.setLookaheadSize(10);
    chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).sign(Sha256Hash.ZERO_HASH);
    chain.getKey(KeyChain.KeyPurpose.CHANGE).sign(Sha256Hash.ZERO_HASH);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:10,代码来源:DeterministicKeyChainTest.java

示例12: serializeUnencrypted

import org.bitcoinj.wallet.DeterministicKeyChain; //导入依赖的package包/类
@Test
public void serializeUnencrypted() throws UnreadableWalletException {
    chain.maybeLookAhead();
    DeterministicKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey key2 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKey key3 = chain.getKey(KeyChain.KeyPurpose.CHANGE);
    List<Protos.Key> keys = chain.serializeToProtobuf();
    // 1 mnemonic/seed, 1 master key, 1 account key, 2 internal keys, 3 derived, 20 lookahead and 5 lookahead threshold.
    int numItems =
            1  // mnemonic/seed
          + 1  // master key
          + 1  // account key
          + 2  // ext/int parent keys
          + (chain.getLookaheadSize() + chain.getLookaheadThreshold()) * 2   // lookahead zone on each chain
    ;
    assertEquals(numItems, keys.size());

    // Get another key that will be lost during round-tripping, to ensure we can derive it again.
    DeterministicKey key4 = chain.getKey(KeyChain.KeyPurpose.CHANGE);

    final String EXPECTED_SERIALIZATION = checkSerialization(keys, "deterministic-wallet-serialization.txt");

    // Round trip the data back and forth to check it is preserved.
    int oldLookaheadSize = chain.getLookaheadSize();
    chain = DeterministicKeyChain.fromProtobuf(keys, null).get(0);
    assertEquals(EXPECTED_SERIALIZATION, protoToString(chain.serializeToProtobuf()));
    assertEquals(key1, chain.findKeyFromPubHash(key1.getPubKeyHash()));
    assertEquals(key2, chain.findKeyFromPubHash(key2.getPubKeyHash()));
    assertEquals(key3, chain.findKeyFromPubHash(key3.getPubKeyHash()));
    assertEquals(key4, chain.getKey(KeyChain.KeyPurpose.CHANGE));
    key1.sign(Sha256Hash.ZERO_HASH);
    key2.sign(Sha256Hash.ZERO_HASH);
    key3.sign(Sha256Hash.ZERO_HASH);
    key4.sign(Sha256Hash.ZERO_HASH);
    assertEquals(oldLookaheadSize, chain.getLookaheadSize());
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:37,代码来源:DeterministicKeyChainTest.java

示例13: checkEncryptedKeyChain

import org.bitcoinj.wallet.DeterministicKeyChain; //导入依赖的package包/类
private void checkEncryptedKeyChain(DeterministicKeyChain encChain, DeterministicKey key1) {
    // Check we can look keys up and extend the chain without the AES key being provided.
    DeterministicKey encKey1 = encChain.findKeyFromPubKey(key1.getPubKey());
    DeterministicKey encKey2 = encChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    assertFalse(key1.isEncrypted());
    assertTrue(encKey1.isEncrypted());
    assertEquals(encKey1.getPubKeyPoint(), key1.getPubKeyPoint());
    final KeyParameter aesKey = checkNotNull(encChain.getKeyCrypter()).deriveKey("open secret");
    encKey1.sign(Sha256Hash.ZERO_HASH, aesKey);
    encKey2.sign(Sha256Hash.ZERO_HASH, aesKey);
    assertTrue(encChain.checkAESKey(aesKey));
    assertFalse(encChain.checkPassword("access denied"));
    assertTrue(encChain.checkPassword("open secret"));
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:15,代码来源:DeterministicKeyChainTest.java

示例14: encryption

import org.bitcoinj.wallet.DeterministicKeyChain; //导入依赖的package包/类
@Test
public void encryption() throws UnreadableWalletException {
    DeterministicKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    DeterministicKeyChain encChain = chain.toEncrypted("open secret");
    DeterministicKey encKey1 = encChain.findKeyFromPubKey(key1.getPubKey());
    checkEncryptedKeyChain(encChain, key1);

    // Round-trip to ensure de/serialization works and that we can store two chains and they both deserialize.
    List<Protos.Key> serialized = encChain.serializeToProtobuf();
    List<Protos.Key> doubled = Lists.newArrayListWithExpectedSize(serialized.size() * 2);
    doubled.addAll(serialized);
    doubled.addAll(serialized);
    final List<DeterministicKeyChain> chains = DeterministicKeyChain.fromProtobuf(doubled, encChain.getKeyCrypter());
    assertEquals(2, chains.size());
    encChain = chains.get(0);
    checkEncryptedKeyChain(encChain, chain.findKeyFromPubKey(key1.getPubKey()));
    encChain = chains.get(1);
    checkEncryptedKeyChain(encChain, chain.findKeyFromPubKey(key1.getPubKey()));

    DeterministicKey encKey2 = encChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS);
    // Decrypt and check the keys match.
    DeterministicKeyChain decChain = encChain.toDecrypted("open secret");
    DeterministicKey decKey1 = decChain.findKeyFromPubHash(encKey1.getPubKeyHash());
    DeterministicKey decKey2 = decChain.findKeyFromPubHash(encKey2.getPubKeyHash());
    assertEquals(decKey1.getPubKeyPoint(), encKey1.getPubKeyPoint());
    assertEquals(decKey2.getPubKeyPoint(), encKey2.getPubKeyPoint());
    assertFalse(decKey1.isEncrypted());
    assertFalse(decKey2.isEncrypted());
    assertNotEquals(encKey1.getParent(), decKey1.getParent());   // parts of a different hierarchy
    // Check we can once again derive keys from the decrypted chain.
    decChain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS).sign(Sha256Hash.ZERO_HASH);
    decChain.getKey(KeyChain.KeyPurpose.CHANGE).sign(Sha256Hash.ZERO_HASH);
}
 
开发者ID:HashEngineering,项目名称:namecoinj,代码行数:34,代码来源:DeterministicKeyChainTest.java

示例15: watchingChain

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


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