/** * Returns the address that corresponds to the public part of this ECKey. Note that an address is derived from * the RIPEMD-160 hash of the public key and is not the public key itself (which is too large to be convenient). */ public Address toAddress(NetworkParameters params) { return new Address(params, getPubKeyHash()); }
/** * Returns the address that corresponds to the public part of this ECKey. Note that an address is derived from * the RIPEMD-160 hash of the public key and is not the public key itself (which is too large to be convenient). */ public Address toAddress(NetworkParameters params) { return new Address(params, getPubKeyHash()); }
/** * Returns the address that corresponds to the public part of this ECKey. Note that an address is derived from * the RIPEMD-160 hash of the public key and is not the public key itself (which is too large to be convenient). */ public Address toAddress(NetworkParameters params) { return new Address(params, getPubKeyHash()); }
public byte [] getId() { return getECKey().getPubKeyHash(); }
/** * Returns the address that corresponds to the public part of this ECKey. Note that an address is derived from * the RIPEMD-160 hash of the public key and is not the public key itself (which is too large to be convenient). */ public Address toAddress(NetworkParameters params) { return new Address(params, getPubKeyHash()); }
public static BitAddress from(CoinType type, ECKey key) { return new BitAddress(type, key.getPubKeyHash()); }
public static BitAddress from(CoinType type, ECKey key) { return new BitAddress(type, key.getPubKeyHash()); }
/** * Removes the given key from the keychain. Be very careful with this - losing a private key <b>destroys the * money associated with it</b>. * @return Whether the key was removed or not. */ public boolean removeKey(ECKey key) { lock.lock(); try { boolean a = hashToKeys.remove(ByteString.copyFrom(key.getPubKeyHash())) != null; boolean b = pubkeyToKeys.remove(ByteString.copyFrom(key.getPubKey())) != null; checkState(a == b); // Should be in both maps or neither. return a; } finally { lock.unlock(); } }
/** * Creates a segwit scriptPubKey that sends to the given public key. */ public static Script createP2WPKHOutputScript(ECKey key) { checkArgument(key.isCompressed()); return createP2WPKHOutputScript(key.getPubKeyHash()); }
/** * Creates a segwit scriptPubKey that sends to the given public key. */ public static Script createP2WPKHOutputScript(ECKey key) { checkArgument(key.isCompressed()); return createP2WPKHOutputScript(key.getPubKeyHash()); }
private void importKeyLocked(ECKey key) { if (hashToKeys.isEmpty()) { isWatching = key.isWatching(); } else { if (key.isWatching() && !isWatching) throw new IllegalArgumentException("Key is watching but chain is not"); if (!key.isWatching() && isWatching) throw new IllegalArgumentException("Key is not watching but chain is"); } ECKey previousKey = pubkeyToKeys.put(ByteString.copyFrom(key.getPubKey()), key); hashToKeys.put(ByteString.copyFrom(key.getPubKeyHash()), key); checkState(previousKey == null); }
private void importKeyLocked(ECKey key) { if (hashToKeys.isEmpty()) { isWatching = key.isWatching(); } else { if (key.isWatching() && !isWatching) throw new IllegalArgumentException("Key is watching but chain is not"); if (!key.isWatching() && isWatching) throw new IllegalArgumentException("Key is not watching but chain is"); } ECKey previousKey = pubkeyToKeys.put(ByteString.copyFrom(key.getPubKey()), key); hashToKeys.put(ByteString.copyFrom(key.getPubKeyHash()), key); checkState(previousKey == null); }
private void importKeyLocked(ECKey key) { if (hashToKeys.isEmpty()) { isWatching = key.isWatching(); } else { if (key.isWatching() && !isWatching) throw new IllegalArgumentException("Key is watching but chain is not"); if (!key.isWatching() && isWatching) throw new IllegalArgumentException("Key is not watching but chain is"); } ECKey previousKey = pubkeyToKeys.put(ByteString.copyFrom(key.getPubKey()), key); hashToKeys.put(ByteString.copyFrom(key.getPubKeyHash()), key); checkState(previousKey == null); }
/** Inserts the given key and equivalent hashed form (for the address). */ public synchronized void insert(ECKey key) { insert(key.getPubKey()); insert(key.getPubKeyHash()); }
/** Inserts the given key and equivalent hashed form (for the address). */ public synchronized void insert(ECKey key) { insert(key.getPubKey()); insert(key.getPubKeyHash()); }
/** Inserts the given key and equivalent hashed form (for the address). */ public synchronized void insert(ECKey key) { insert(key.getPubKey()); insert(key.getPubKeyHash()); }
@Override public void verifyMessage(SignedMessage signedMessage) { try { ECKey pubKey = ECKey.signedMessageToKey( type.getSignedMessageHeader(), signedMessage.message, signedMessage.signature); byte[] expectedPubKeyHash = BitAddress.from(type, signedMessage.address).getHash160(); if (Arrays.equals(expectedPubKeyHash, pubKey.getPubKeyHash())) { signedMessage.status = SignedMessage.Status.VerifiedOK; } else { signedMessage.status = SignedMessage.Status.InvalidSigningAddress; } } catch (SignatureException e) { signedMessage.status = SignedMessage.Status.InvalidMessageSignature; } catch (AddressMalformedException e) { signedMessage.status = SignedMessage.Status.AddressMalformed; } }
@Test public void testRoundTripNormalWallet() throws Exception { Wallet wallet1 = roundTrip(myWallet); assertEquals(0, wallet1.getTransactions(true).size()); assertEquals(Coin.ZERO, wallet1.getBalance()); assertArrayEquals(myKey.getPubKey(), wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPubKey()); assertArrayEquals(myKey.getPrivKeyBytes(), wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getPrivKeyBytes()); assertEquals(myKey.getCreationTimeSeconds(), wallet1.findKeyFromPubHash(myKey.getPubKeyHash()).getCreationTimeSeconds()); }
@Test(expected = PaymentProtocolException.InvalidNetwork.class) public void testWrongNetwork() throws Exception { // Create a PaymentRequest and make sure the correct values are parsed by the PaymentSession. MockPaymentSession paymentSession = new MockPaymentSession(newSimplePaymentRequest("main")); assertEquals(MainNetParams.get(), paymentSession.getNetworkParameters()); // Send the payment and verify that the correct information is sent. // Add a dummy input to tx so it is considered valid. tx.addInput(new TransactionInput(PARAMS, tx, outputToMe.getScriptBytes())); ArrayList<Transaction> txns = new ArrayList<>(); txns.add(tx); Address refundAddr = new Address(PARAMS, serverKey.getPubKeyHash()); paymentSession.sendPayment(txns, refundAddr, paymentMemo); assertEquals(1, paymentSession.getPaymentLog().size()); }
@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()); } }