/** * <p>Deprecated alias for {@link #importKey(ECKey)}.</p> * * <p><b>Replace with either {@link #freshReceiveKey()} if your call is addKey(new ECKey()), or with {@link #importKey(ECKey)} * which does the same thing this method used to, but with a better name.</b></p> */ @Deprecated public boolean addKey(ECKey key) { return importKey(key); }
/** * <p>Deprecated alias for {@link #importKey(ECKey)}.</p> * * <p><b>Replace with either {@link #freshReceiveKey()} if your call is addKey(new ECKey()), or with {@link #importKey(ECKey)} * which does the same thing this method used to, but with a better name.</b></p> */ @Deprecated public boolean addKey(ECKey key) { return importKey(key); }
/** * <p>Deprecated alias for {@link #importKey(ECKey)}.</p> * * <p><b>Replace with either {@link #freshReceiveKey()} if your call is addKey(new ECKey()), or with {@link #importKey(ECKey)} * which does the same thing this method used to, but with a better name.</b></p> */ @Deprecated public boolean addKey(ECKey key) { return importKey(key); }
/** * <p>Deprecated alias for {@link #importKey(ECKey)}.</p> * * <p><b>Replace with either {@link #freshReceiveKey()} if your call is addKey(new ECKey()), or with {@link #importKey(ECKey)} * which does the same thing this method used to, but with a better name.</b></p> */ @Deprecated public boolean addKey(ECKey key) { return importKey(key); }
@Override protected void onSetupCompleted() { if (wallet().getImportedKeys().size() < 1) wallet().importKey(new ECKey()); wallet().allowSpendingUnconfirmedTransactions(); view.displayWalletPath(vWalletFile.getAbsolutePath()); setupWalletListeners(wallet()); Log.d("myLogs", "My address = " + wallet().freshReceiveAddress()); } };
@Test(expected = IllegalArgumentException.class) public void importOfHDKeyForbidden() throws Exception { wallet.importKey(wallet.freshReceiveKey()); }
appKit.wallet().importKey(myKey); appKit.wallet().allowSpendingUnconfirmedTransactions();
key = key.encrypt(checkNotNull(wallet.getKeyCrypter()), aesKey); wallet.importKey(key); System.out.println(key.toAddress(params) + " " + key); } catch (KeyCrypterException kce) {
@Test(expected = KeyCrypterException.class) public void addUnencryptedKeyToEncryptedWallet() throws Exception { Wallet encryptedWallet = new Wallet(PARAMS); encryptedWallet.encrypt(PASSWORD1); ECKey key1 = new ECKey(); encryptedWallet.importKey(key1); }
wallet.importKey(key);
@Before public void setUp() throws Exception { BriefLogFormatter.initVerbose(); Context ctx = new Context(PARAMS); myWatchedKey = new ECKey(); myWallet = new Wallet(PARAMS); myKey = new ECKey(); myKey.setCreationTimeSeconds(123456789L); myWallet.importKey(myKey); myAddress = myKey.toAddress(PARAMS); myWallet = new Wallet(PARAMS); myWallet.importKey(myKey); mScriptCreationTime = new Date().getTime() / 1000 - 1234; myWallet.addWatchedAddress(myWatchedKey.toAddress(PARAMS), mScriptCreationTime); myWallet.setDescription(WALLET_DESCRIPTION); }
@Test(expected = KeyCrypterException.class) public void addEncryptedKeyToUnencryptedWallet() throws Exception { Wallet encryptedWallet = new Wallet(PARAMS); encryptedWallet.encrypt(PASSWORD1); KeyCrypter keyCrypter = encryptedWallet.getKeyCrypter(); ECKey key1 = new ECKey(); key1 = key1.encrypt(keyCrypter, keyCrypter.deriveKey("PASSWORD!")); wallet.importKey(key1); }
@Test public void testMultiSigOutputToString() throws Exception { sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, Coin.COIN); ECKey myKey = new ECKey(); this.wallet.importKey(myKey); // Simulate another signatory ECKey otherKey = new ECKey(); // Create multi-sig transaction Transaction multiSigTransaction = new Transaction(PARAMS); ImmutableList<ECKey> keys = ImmutableList.of(myKey, otherKey); Script scriptPubKey = ScriptBuilder.createMultiSigOutputScript(2, keys); multiSigTransaction.addOutput(Coin.COIN, scriptPubKey); SendRequest req = SendRequest.forTx(multiSigTransaction); this.wallet.completeTx(req); TransactionOutput multiSigTransactionOutput = multiSigTransaction.getOutput(0); assertThat(multiSigTransactionOutput.toString(), CoreMatchers.containsString("CHECKMULTISIG")); }
@Test(expected = KeyCrypterException.class) public void mismatchedCrypter() throws Exception { Wallet encryptedWallet = new Wallet(PARAMS); encryptedWallet.encrypt(PASSWORD1); KeyCrypter keyCrypter = encryptedWallet.getKeyCrypter(); KeyParameter aesKey = keyCrypter.deriveKey(PASSWORD1); // Try added an ECKey that was encrypted with a differenct ScryptParameters (i.e. a non-homogenous key). // This is not allowed as the ScryptParameters is stored at the Wallet level. Protos.ScryptParameters.Builder scryptParametersBuilder = Protos.ScryptParameters.newBuilder() .setSalt(ByteString.copyFrom(KeyCrypterScrypt.randomSalt())); Protos.ScryptParameters scryptParameters = scryptParametersBuilder.build(); KeyCrypter keyCrypterDifferent = new KeyCrypterScrypt(scryptParameters); ECKey ecKeyDifferent = new ECKey(); ecKeyDifferent = ecKeyDifferent.encrypt(keyCrypterDifferent, aesKey); encryptedWallet.importKey(ecKeyDifferent); }
@Test public void testWalletCatchupTime() throws Exception { // Check the fast catchup time was initialized to something around the current runtime minus a week. // The wallet was already added to the peer in setup. final int WEEK = 86400 * 7; final long now = Utils.currentTimeSeconds(); peerGroup.start(); assertTrue(peerGroup.getFastCatchupTimeSecs() > now - WEEK - 10000); Wallet w2 = new Wallet(PARAMS); ECKey key1 = new ECKey(); key1.setCreationTimeSeconds(now - 86400); // One day ago. w2.importKey(key1); peerGroup.addWallet(w2); peerGroup.waitForJobQueue(); assertEquals(peerGroup.getFastCatchupTimeSecs(), now - 86400 - WEEK); // Adding a key to the wallet should update the fast catchup time, but asynchronously and in the background // due to the need to avoid complicated lock inversions. ECKey key2 = new ECKey(); key2.setCreationTimeSeconds(now - 100000); w2.importKey(key2); peerGroup.waitForJobQueue(); assertEquals(peerGroup.getFastCatchupTimeSecs(), now - WEEK - 100000); }
Context context = new Context(PARAMS); Wallet wallet = new Wallet(context); wallet.importKey(miningKey);
@Test public void testKeys() throws Exception { for (int i = 0 ; i < 20 ; i++) { myKey = new ECKey(); myAddress = myKey.toAddress(PARAMS); myWallet = new Wallet(PARAMS); myWallet.importKey(myKey); Wallet wallet1 = roundTrip(myWallet); assertArrayEquals(myKey.getPubKey(), wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPubKey()); assertArrayEquals(myKey.getPrivKeyBytes(), wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPrivKeyBytes()); } }
@SuppressWarnings("ConstantConditions") public void completeTxPartiallySigned(Wallet.MissingSigsMode missSigMode, byte[] expectedSig) throws Exception { // Check the wallet will write dummy scriptSigs for inputs that we have only pubkeys for without the privkey. ECKey priv = new ECKey(); ECKey pub = ECKey.fromPublicOnly(priv.getPubKeyPoint()); wallet.importKey(pub); ECKey priv2 = wallet.freshReceiveKey(); // Send three transactions, with one being an address type and the other being a raw CHECKSIG type pubkey only, // and the final one being a key we do have. We expect the first two inputs to be dummy values and the last // to be signed correctly. Transaction t1 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, pub.toAddress(PARAMS)); Transaction t2 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, pub); Transaction t3 = sendMoneyToWallet(AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, priv2); SendRequest req = SendRequest.emptyWallet(OTHER_ADDRESS); req.missingSigsMode = missSigMode; wallet.completeTx(req); byte[] dummySig = TransactionSignature.dummy().encodeToBitcoin(); // Selected inputs can be in any order. for (int i = 0; i < req.tx.getInputs().size(); i++) { TransactionInput input = req.tx.getInput(i); if (input.getConnectedOutput().getParentTransaction().equals(t1)) { assertArrayEquals(expectedSig, input.getScriptSig().getChunks().get(0).data); } else if (input.getConnectedOutput().getParentTransaction().equals(t2)) { assertArrayEquals(expectedSig, input.getScriptSig().getChunks().get(0).data); } else if (input.getConnectedOutput().getParentTransaction().equals(t3)) { input.getScriptSig().correctlySpends(req.tx, i, t3.getOutput(0).getScriptPubKey()); } } assertTrue(TransactionSignature.isEncodingCanonical(dummySig)); }
results[0] = results[1] = null; ECKey key2 = new ECKey(); wallet.importKey(key2);
ECKey key2 = new ECKey(); key2.setCreationTimeSeconds(Utils.currentTimeSeconds() - 86400); wallet.importKey(key1); wallet.importKey(key2); sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, key1.toAddress(PARAMS)); sendMoneyToWallet(wallet, AbstractBlockChain.NewBlockType.BEST_CHAIN, CENT, key2.toAddress(PARAMS));