org.bitcoinj.wallet.KeyChain Java Examples
The following examples show how to use
org.bitcoinj.wallet.KeyChain.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WalletProtobufSerializerTest.java From bcm-android with GNU General Public License v3.0 | 6 votes |
@Test public void testRoundTripMarriedWallet() throws Exception { // create 2-of-2 married wallet myWallet = new Wallet(UNITTEST); final DeterministicKeyChain partnerChain = new DeterministicKeyChain(new SecureRandom()); DeterministicKey partnerKey = DeterministicKey.deserializeB58(null, partnerChain.getWatchingKey().serializePubB58(UNITTEST), UNITTEST); 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)); }
Example #2
Source File: WalletProtobufSerializerTest.java From green_android with GNU General Public License v3.0 | 6 votes |
@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)); }
Example #3
Source File: WalletProtobufSerializerTest.java From GreenBits with GNU General Public License v3.0 | 6 votes |
@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)); }
Example #4
Source File: BasicKeyChainTest.java From bcm-android with GNU General Public License v3.0 | 5 votes |
@Test public void getKey() { ECKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(onKeysAddedRan.getAndSet(false)); assertEquals(key1, onKeysAdded.getAndSet(null).get(0)); ECKey key2 = chain.getKey(KeyChain.KeyPurpose.CHANGE); assertFalse(onKeysAddedRan.getAndSet(false)); assertEquals(key2, key1); }
Example #5
Source File: BasicKeyChainTest.java From bcm-android with GNU General Public License v3.0 | 5 votes |
@Test(expected = KeyCrypterException.class) public void cannotImportEncryptedKey() { final ECKey key1 = new ECKey(); chain.importKeys(ImmutableList.of(key1)); chain = chain.toEncrypted("foobar"); ECKey encryptedKey = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(encryptedKey.isEncrypted()); BasicKeyChain chain2 = new BasicKeyChain(); chain2.importKeys(ImmutableList.of(encryptedKey)); }
Example #6
Source File: BasicKeyChainTest.java From green_android with GNU General Public License v3.0 | 5 votes |
@Test public void getKey() { ECKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(onKeysAddedRan.getAndSet(false)); assertEquals(key1, onKeysAdded.getAndSet(null).get(0)); ECKey key2 = chain.getKey(KeyChain.KeyPurpose.CHANGE); assertFalse(onKeysAddedRan.getAndSet(false)); assertEquals(key2, key1); }
Example #7
Source File: BasicKeyChainTest.java From green_android with GNU General Public License v3.0 | 5 votes |
@Test(expected = KeyCrypterException.class) public void cannotImportEncryptedKey() { final ECKey key1 = new ECKey(); chain.importKeys(ImmutableList.of(key1)); chain = chain.toEncrypted("foobar"); ECKey encryptedKey = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(encryptedKey.isEncrypted()); BasicKeyChain chain2 = new BasicKeyChain(); chain2.importKeys(ImmutableList.of(encryptedKey)); }
Example #8
Source File: BasicKeyChainTest.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@Test public void getKey() { ECKey key1 = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(onKeysAddedRan.getAndSet(false)); assertEquals(key1, onKeysAdded.getAndSet(null).get(0)); ECKey key2 = chain.getKey(KeyChain.KeyPurpose.CHANGE); assertFalse(onKeysAddedRan.getAndSet(false)); assertEquals(key2, key1); }
Example #9
Source File: BasicKeyChainTest.java From GreenBits with GNU General Public License v3.0 | 5 votes |
@Test(expected = KeyCrypterException.class) public void cannotImportEncryptedKey() { final ECKey key1 = new ECKey(); chain.importKeys(ImmutableList.of(key1)); chain = chain.toEncrypted("foobar"); ECKey encryptedKey = chain.getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); assertTrue(encryptedKey.isEncrypted()); BasicKeyChain chain2 = new BasicKeyChain(); chain2.importKeys(ImmutableList.of(encryptedKey)); }
Example #10
Source File: WalletService.java From bisq-core with GNU Affero General Public License v3.0 | 4 votes |
public DeterministicKey freshKey(KeyChain.KeyPurpose purpose) { return wallet.freshKey(purpose); }
Example #11
Source File: WalletManager.java From guarda-android-wallets with GNU General Public License v3.0 | 4 votes |
public void restoreFromBlock2(String mnemonicCode, Runnable callback) { if (mnemonicCode.charAt(mnemonicCode.length() - 1) == ' ') { mnemonicCode = mnemonicCode.substring(0, mnemonicCode.length() - 1); } DeterministicSeed seed = new DeterministicSeed(Splitter.on(' ').splitToList(mnemonicCode), null, "", 0); wallet = Wallet.fromSeed(params, seed); mnemonicKey = Joiner.on(" ").join(seed.getMnemonicCode()); sharedManager.setLastSyncedBlock(Coders.encodeBase64(mnemonicKey)); updateWalletFriendlyAddress(); DeterministicKey deterministicKey = wallet.getActiveKeyChain().getKey(KeyChain.KeyPurpose.RECEIVE_FUNDS); // Log.d("flint", "walletAddress: " + deterministicKey.toAddress(params)); // Log.d("flint", "friendlyWalletAddress: " + deterministicKey.toAddress(params).toBase58()); // ChildNumber childNumber = new ChildNumber(ChildNumber.HARDENED_BIT); // DeterministicKey de = wallet.getKeyByPath(ImmutableList.of(childNumber)); // xprvKey = de.serializePrivB58(params); // // if (BuildConfig.DEBUG) { // DeterministicKey dk = extractWalletDeterministicKey(); // wifKey = dk.getPrivateKeyAsWiF(params); // } else { // wifKey = wallet.currentReceiveKey().getPrivateKeyAsWiF(params); // } callback.run(); RequestorBtc.getUTXOListQtum(walletFriendlyAddress, new ApiMethods.RequestListener() { @Override public void onSuccess(Object response) { List<UTXOItem> utxos = (List<UTXOItem>)response; setUTXO(utxos); } @Override public void onFailure(String msg) { } }); }
Example #12
Source File: WalletService.java From bisq with GNU Affero General Public License v3.0 | 4 votes |
public DeterministicKey freshKey(KeyChain.KeyPurpose purpose) { return wallet.freshKey(purpose); }