@Override public MarriedKeyChain build() { checkState(random != null || entropy != null || seed != null || watchingKey!= null, "Must provide either entropy or random or seed or watchingKey"); checkNotNull(followingKeys, "followingKeys must be provided"); MarriedKeyChain chain; if (threshold == 0) threshold = (followingKeys.size() + 1) / 2 + 1; if (random != null) { chain = new MarriedKeyChain(random, bits, getPassphrase(), seedCreationTimeSecs); } else if (entropy != null) { chain = new MarriedKeyChain(entropy, getPassphrase(), seedCreationTimeSecs); } else if (seed != null) { seed.setCreationTimeSeconds(seedCreationTimeSecs); chain = new MarriedKeyChain(seed); } else { watchingKey.setCreationTimeSeconds(seedCreationTimeSecs); chain = new MarriedKeyChain(watchingKey); } chain.addFollowingAccountKeys(followingKeys, threshold); return chain; } }
private void createMarriedWallet(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(PARAMS), PARAMS); 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); }
private MarriedKeyChain createMarriedKeyChain() { byte[] entropy = Sha256Hash.hash("don't use a seed like this in real life".getBytes()); DeterministicSeed seed = new DeterministicSeed(entropy, "", MnemonicCode.BIP39_STANDARDISATION_TIME_SECS); MarriedKeyChain chain = MarriedKeyChain.builder() .seed(seed) .followingKeys(watchingAccountKey) .threshold(2).build(); return chain; }
wallet.addTransactionSigner(signer); MarriedKeyChain chain = MarriedKeyChain.builder() .random(new SecureRandom()) .followingKeys(partnerKey) .build(); wallet.addAndActivateHDChain(chain);
@Override public MarriedKeyChain build() { checkState(random != null || entropy != null || seed != null || watchingKey!= null, "Must provide either entropy or random or seed or watchingKey"); checkNotNull(followingKeys, "followingKeys must be provided"); MarriedKeyChain chain; if (threshold == 0) threshold = (followingKeys.size() + 1) / 2 + 1; if (random != null) { chain = new MarriedKeyChain(random, bits, getPassphrase(), seedCreationTimeSecs); } else if (entropy != null) { chain = new MarriedKeyChain(entropy, getPassphrase(), seedCreationTimeSecs); } else if (seed != null) { seed.setCreationTimeSeconds(seedCreationTimeSecs); chain = new MarriedKeyChain(seed); } else { watchingKey.setCreationTimeSeconds(seedCreationTimeSecs); chain = new MarriedKeyChain(watchingKey); } chain.addFollowingAccountKeys(followingKeys, threshold); return chain; } }
@Override public MarriedKeyChain build() { checkState(random != null || entropy != null || seed != null || watchingKey!= null, "Must provide either entropy or random or seed or watchingKey"); checkNotNull(followingKeys, "followingKeys must be provided"); MarriedKeyChain chain; if (threshold == 0) threshold = (followingKeys.size() + 1) / 2 + 1; if (random != null) { chain = new MarriedKeyChain(random, bits, getPassphrase(), seedCreationTimeSecs); } else if (entropy != null) { chain = new MarriedKeyChain(entropy, getPassphrase(), seedCreationTimeSecs); } else if (seed != null) { seed.setCreationTimeSeconds(seedCreationTimeSecs); chain = new MarriedKeyChain(seed); } else { watchingKey.setCreationTimeSeconds(seedCreationTimeSecs); chain = new MarriedKeyChain(watchingKey); } chain.addFollowingAccountKeys(followingKeys, threshold); return chain; } }
@Override public MarriedKeyChain build() { checkState(random != null || entropy != null || seed != null || watchingKey!= null, "Must provide either entropy or random or seed or watchingKey"); checkNotNull(followingKeys, "followingKeys must be provided"); MarriedKeyChain chain; if (threshold == 0) threshold = (followingKeys.size() + 1) / 2 + 1; if (random != null) { chain = new MarriedKeyChain(random, bits, getPassphrase(), seedCreationTimeSecs); } else if (entropy != null) { chain = new MarriedKeyChain(entropy, getPassphrase(), seedCreationTimeSecs); } else if (seed != null) { seed.setCreationTimeSeconds(seedCreationTimeSecs); chain = new MarriedKeyChain(seed); } else { watchingKey.setCreationTimeSeconds(seedCreationTimeSecs); chain = new MarriedKeyChain(watchingKey); } chain.addFollowingAccountKeys(followingKeys, threshold); return chain; } }
@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)); }
private static void marry() { if (!options.has(xpubkeysFlag)) { throw new IllegalStateException(); } String[] xpubkeys = options.valueOf(xpubkeysFlag).split(","); ImmutableList.Builder<DeterministicKey> keys = ImmutableList.builder(); for (String xpubkey : xpubkeys) { keys.add(DeterministicKey.deserializeB58(null, xpubkey.trim(), params)); } MarriedKeyChain chain = MarriedKeyChain.builder() .random(new SecureRandom()) .followingKeys(keys.build()) .build(); wallet.addAndActivateHDChain(chain); }
public static Builder<?> builder() { return new Builder(); }
public static Builder<?> builder() { return new Builder(); }
public T followingKeys(List<DeterministicKey> followingKeys) { this.followingKeys = followingKeys; return self(); }
public static Builder<?> builder() { return new Builder(); }
public T followingKeys(DeterministicKey followingKey, DeterministicKey ...followingKeys) { this.followingKeys = Lists.asList(followingKey, followingKeys); return self(); }
public static Builder<?> builder() { return new Builder(); }
public T followingKeys(DeterministicKey followingKey, DeterministicKey ...followingKeys) { this.followingKeys = Lists.asList(followingKey, followingKeys); return self(); }
public T followingKeys(DeterministicKey followingKey, DeterministicKey ...followingKeys) { this.followingKeys = Lists.asList(followingKey, followingKeys); return self(); }
public T followingKeys(DeterministicKey followingKey, DeterministicKey ...followingKeys) { this.followingKeys = Lists.asList(followingKey, followingKeys); return self(); }
public T followingKeys(List<DeterministicKey> followingKeys) { this.followingKeys = followingKeys; return self(); }
public T followingKeys(List<DeterministicKey> followingKeys) { this.followingKeys = followingKeys; return self(); }