certificates) {
- super(e);
- this.certificates = certificates;
- }
- }
-}
diff --git a/core/src/main/java/org/bitcoinj/protocols/payments/PaymentSession.java b/core/src/main/java/org/bitcoinj/protocols/payments/PaymentSession.java
deleted file mode 100644
index d47089433c0..00000000000
--- a/core/src/main/java/org/bitcoinj/protocols/payments/PaymentSession.java
+++ /dev/null
@@ -1,438 +0,0 @@
-/*
- * Copyright by the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.bitcoinj.protocols.payments;
-
-import com.google.common.annotations.VisibleForTesting;
-import com.google.protobuf.InvalidProtocolBufferException;
-import org.bitcoinj.protobuf.payments.Protos;
-import org.bitcoinj.base.Address;
-import org.bitcoinj.base.Coin;
-import org.bitcoinj.base.internal.TimeUtils;
-import org.bitcoinj.core.NetworkParameters;
-import org.bitcoinj.core.Transaction;
-import org.bitcoinj.core.TransactionOutput;
-import org.bitcoinj.crypto.TrustStoreLoader;
-import org.bitcoinj.params.MainNetParams;
-import org.bitcoinj.protocols.payments.PaymentProtocol.PkiVerificationData;
-import org.bitcoinj.uri.BitcoinURI;
-import org.bitcoinj.base.internal.FutureUtils;
-import org.bitcoinj.utils.Threading;
-import org.bitcoinj.wallet.SendRequest;
-
-import javax.annotation.Nullable;
-import java.io.DataOutputStream;
-import java.io.IOException;
-import java.net.HttpURLConnection;
-import java.net.MalformedURLException;
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.net.URL;
-import java.security.KeyStoreException;
-import java.time.Instant;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Optional;
-import java.util.concurrent.CompletableFuture;
-import java.util.concurrent.ExecutorService;
-
-/**
- * Provides a standard implementation of the Payment Protocol (BIP 0070)
- *
- * A PaymentSession can be initialized from one of the following:
- *
- *
- * - A {@link BitcoinURI} object that conforms to BIP 0072
- * - A url where the {@link Protos.PaymentRequest} can be fetched
- * - Directly with a {@link Protos.PaymentRequest} object
- *
- *
- * If initialized with a BitcoinURI or a url, a network request is made for the payment request object and a
- * {@link CompletableFuture} is returned that will be notified with the PaymentSession object after it is downloaded.
- *
- * Once the PaymentSession is initialized, typically a wallet application will prompt the user to confirm that the
- * amount and recipient are correct, perform any additional steps, and then construct a list of transactions to pass to
- * the sendPayment method.
- *
- * Call sendPayment with a list of transactions that will be broadcast. A {@link Protos.Payment} message will be sent
- * to the merchant if a payment url is provided in the PaymentRequest. NOTE: sendPayment does NOT broadcast the
- * transactions to the bitcoin network. Instead it returns a CompletableFuture that will be notified when a
- * {@link Protos.PaymentACK} is received from the merchant. Typically a wallet will show the message to the user
- * as a confirmation message that the payment is now "processing" or that an error occurred, and then broadcast the
- * tx itself later if needed.
- *
- * @see BIP 0070
- */
-public class PaymentSession {
- private final static ExecutorService executor = Threading.THREAD_POOL;
- private NetworkParameters params;
- private Protos.PaymentRequest paymentRequest;
- private Protos.PaymentDetails paymentDetails;
- private Coin totalValue = Coin.ZERO;
-
- /**
- * Stores the calculated PKI verification data, or null if none is available.
- * Only valid after the session is created with the verifyPki parameter set to true.
- */
- @Nullable public final PkiVerificationData pkiVerificationData;
-
- /**
- * Returns a future that will be notified with a PaymentSession object after it is fetched using the provided uri.
- * uri is a BIP-72-style BitcoinURI object that specifies where the {@link Protos.PaymentRequest} object may
- * be fetched in the r= parameter.
- *
- * If the payment request object specifies a PKI method, then the system trust store will be used to verify
- * the signature provided by the payment request. An exception is thrown by the future if the signature cannot
- * be verified.
- */
- public static CompletableFuture createFromBitcoinUri(final BitcoinURI uri) throws PaymentProtocolException {
- return createFromBitcoinUri(uri, true, null);
- }
-
- /**
- * Returns a future that will be notified with a PaymentSession object after it is fetched using the provided uri.
- * uri is a BIP-72-style BitcoinURI object that specifies where the {@link Protos.PaymentRequest} object may
- * be fetched in the r= parameter.
- * If verifyPki is specified and the payment request object specifies a PKI method, then the system trust store will
- * be used to verify the signature provided by the payment request. An exception is thrown by the future if the
- * signature cannot be verified.
- */
- public static CompletableFuture createFromBitcoinUri(final BitcoinURI uri, final boolean verifyPki)
- throws PaymentProtocolException {
- return createFromBitcoinUri(uri, verifyPki, null);
- }
-
- /**
- * Returns a future that will be notified with a PaymentSession object after it is fetched using the provided uri.
- * uri is a BIP-72-style BitcoinURI object that specifies where the {@link Protos.PaymentRequest} object may
- * be fetched in the r= parameter.
- * If verifyPki is specified and the payment request object specifies a PKI method, then the system trust store will
- * be used to verify the signature provided by the payment request. An exception is thrown by the future if the
- * signature cannot be verified.
- * If trustStoreLoader is null, the system default trust store is used.
- */
- public static CompletableFuture createFromBitcoinUri(final BitcoinURI uri, final boolean verifyPki, @Nullable final TrustStoreLoader trustStoreLoader)
- throws PaymentProtocolException {
- String url = uri.getPaymentRequestUrl();
- if (url == null)
- throw new PaymentProtocolException.InvalidPaymentRequestURL("No payment request URL (r= parameter) in BitcoinURI " + uri);
- try {
- return fetchPaymentRequest(new URI(url), verifyPki, trustStoreLoader);
- } catch (URISyntaxException e) {
- throw new PaymentProtocolException.InvalidPaymentRequestURL(e);
- }
- }
-
- /**
- * Returns a future that will be notified with a PaymentSession object after it is fetched using the provided url.
- * url is an address where the {@link Protos.PaymentRequest} object may be fetched.
- * If verifyPki is specified and the payment request object specifies a PKI method, then the system trust store will
- * be used to verify the signature provided by the payment request. An exception is thrown by the future if the
- * signature cannot be verified.
- */
- public static CompletableFuture createFromUrl(final String url) throws PaymentProtocolException {
- return createFromUrl(url, true, null);
- }
-
- /**
- * Returns a future that will be notified with a PaymentSession object after it is fetched using the provided url.
- * url is an address where the {@link Protos.PaymentRequest} object may be fetched.
- * If the payment request object specifies a PKI method, then the system trust store will
- * be used to verify the signature provided by the payment request. An exception is thrown by the future if the
- * signature cannot be verified.
- */
- public static CompletableFuture createFromUrl(final String url, final boolean verifyPki)
- throws PaymentProtocolException {
- return createFromUrl(url, verifyPki, null);
- }
-
- /**
- * Returns a future that will be notified with a PaymentSession object after it is fetched using the provided url.
- * url is an address where the {@link Protos.PaymentRequest} object may be fetched.
- * If the payment request object specifies a PKI method, then the system trust store will
- * be used to verify the signature provided by the payment request. An exception is thrown by the future if the
- * signature cannot be verified.
- * If trustStoreLoader is null, the system default trust store is used.
- */
- public static CompletableFuture createFromUrl(final String url, final boolean verifyPki, @Nullable final TrustStoreLoader trustStoreLoader)
- throws PaymentProtocolException {
- if (url == null)
- throw new PaymentProtocolException.InvalidPaymentRequestURL("null paymentRequestUrl");
- try {
- return fetchPaymentRequest(new URI(url), verifyPki, trustStoreLoader);
- } catch(URISyntaxException e) {
- throw new PaymentProtocolException.InvalidPaymentRequestURL(e);
- }
- }
-
- private static CompletableFuture fetchPaymentRequest(final URI uri, final boolean verifyPki, @Nullable final TrustStoreLoader trustStoreLoader) {
- return CompletableFuture.supplyAsync((FutureUtils.ThrowingSupplier) () -> {
- HttpURLConnection connection = (HttpURLConnection)uri.toURL().openConnection();
- connection.setRequestProperty("Accept", PaymentProtocol.MIMETYPE_PAYMENTREQUEST);
- connection.setUseCaches(false);
- Protos.PaymentRequest paymentRequest = Protos.PaymentRequest.parseFrom(connection.getInputStream());
- return new PaymentSession(paymentRequest, verifyPki, trustStoreLoader);
- }, executor);
- }
-
- /**
- * Creates a PaymentSession from the provided {@link Protos.PaymentRequest}.
- * Verifies PKI by default.
- */
- public PaymentSession(Protos.PaymentRequest request) throws PaymentProtocolException {
- this(request, true, null);
- }
-
- /**
- * Creates a PaymentSession from the provided {@link Protos.PaymentRequest}.
- * If verifyPki is true, also validates the signature and throws an exception if it fails.
- */
- public PaymentSession(Protos.PaymentRequest request, boolean verifyPki) throws PaymentProtocolException {
- this(request, verifyPki, null);
- }
-
- /**
- * Creates a PaymentSession from the provided {@link Protos.PaymentRequest}.
- * If verifyPki is true, also validates the signature and throws an exception if it fails.
- * If trustStoreLoader is null, the system default trust store is used.
- */
- public PaymentSession(Protos.PaymentRequest request, boolean verifyPki, @Nullable final TrustStoreLoader trustStoreLoader) throws PaymentProtocolException {
- TrustStoreLoader nonNullTrustStoreLoader = trustStoreLoader != null ? trustStoreLoader : new TrustStoreLoader.DefaultTrustStoreLoader();
- parsePaymentRequest(request);
- if (verifyPki) {
- try {
- pkiVerificationData = PaymentProtocol.verifyPaymentRequestPki(request, nonNullTrustStoreLoader.getKeyStore());
- } catch (IOException | KeyStoreException x) {
- throw new PaymentProtocolException(x);
- }
- } else {
- pkiVerificationData = null;
- }
- }
-
- /**
- * Returns the outputs of the payment request.
- */
- public List getOutputs() {
- List outputs = new ArrayList<>(paymentDetails.getOutputsCount());
- for (Protos.Output output : paymentDetails.getOutputsList()) {
- Coin amount = output.hasAmount() ? Coin.valueOf(output.getAmount()) : null;
- outputs.add(new PaymentProtocol.Output(amount, output.getScript().toByteArray()));
- }
- return outputs;
- }
-
- /**
- * Returns the memo included by the merchant in the payment request, or null if not found.
- */
- @Nullable public String getMemo() {
- if (paymentDetails.hasMemo())
- return paymentDetails.getMemo();
- else
- return null;
- }
-
- /**
- * Returns the total amount of bitcoins requested.
- */
- public Coin getValue() {
- return totalValue;
- }
-
- /**
- * Returns the time that the payment request was generated.
- */
- public Instant time() {
- return Instant.ofEpochSecond(paymentDetails.getTime());
- }
-
- /**
- * Returns the expires time of the payment request, or empty if none.
- */
- public Optional expires() {
- if (paymentDetails.hasExpires())
- return Optional.of(Instant.ofEpochSecond(paymentDetails.getExpires()));
- else
- return Optional.empty();
- }
-
- /**
- * This should always be called before attempting to call sendPayment.
- */
- public boolean isExpired() {
- return expires()
- .map(time -> TimeUtils.currentTime().isAfter(time))
- .orElse(false);
- }
-
- /**
- * Returns the payment url where the Payment message should be sent.
- * Returns null if no payment url was provided in the PaymentRequest.
- */
- @Nullable
- public String getPaymentUrl() {
- if (paymentDetails.hasPaymentUrl())
- return paymentDetails.getPaymentUrl();
- return null;
- }
-
- /**
- * Returns the merchant data included by the merchant in the payment request, or null if none.
- */
- @Nullable public byte[] getMerchantData() {
- if (paymentDetails.hasMerchantData())
- return paymentDetails.getMerchantData().toByteArray();
- else
- return null;
- }
-
- /**
- * Returns a {@link SendRequest} suitable for broadcasting to the network.
- */
- public SendRequest getSendRequest() {
- Transaction tx = new Transaction();
- for (Protos.Output output : paymentDetails.getOutputsList())
- tx.addOutput(new TransactionOutput(tx, Coin.valueOf(output.getAmount()), output.getScript().toByteArray()));
- return SendRequest.forTx(tx).fromPaymentDetails(paymentDetails);
- }
-
- /**
- * Generates a Payment message and sends the payment to the merchant who sent the PaymentRequest.
- * Provide transactions built by the wallet.
- * NOTE: This does not broadcast the transactions to the bitcoin network, it merely sends a Payment message to the
- * merchant confirming the payment.
- * Returns an object wrapping PaymentACK once received.
- * If the PaymentRequest did not specify a payment_url, completes exceptionally.
- * @param txns list of transactions to be included with the Payment message.
- * @param refundAddr will be used by the merchant to send money back if there was a problem.
- * @param memo is a message to include in the payment message sent to the merchant.
- * @return a future for the PaymentACK
- */
- public CompletableFuture sendPayment(List txns, @Nullable Address refundAddr, @Nullable String memo) {
- Protos.Payment payment = null;
- try {
- payment = getPayment(txns, refundAddr, memo);
- } catch (IOException e) {
- return FutureUtils.failedFuture(e);
- }
- if (payment == null)
- return FutureUtils.failedFuture(new PaymentProtocolException.InvalidPaymentRequestURL("Missing Payment URL"));
- if (isExpired())
- return FutureUtils.failedFuture(new PaymentProtocolException.Expired("PaymentRequest is expired"));
- URL url;
- try {
- url = new URL(paymentDetails.getPaymentUrl());
- } catch (MalformedURLException e) {
- return FutureUtils.failedFuture(new PaymentProtocolException.InvalidPaymentURL(e));
- }
- return sendPayment(url, payment);
- }
-
- /**
- * Generates a Payment message based on the information in the PaymentRequest.
- * Provide transactions built by the wallet.
- * @param txns list of transactions to be included with the Payment message.
- * @param refundAddr will be used by the merchant to send money back if there was a problem.
- * @param memo is a message to include in the payment message sent to the merchant.
- * @return Payment message or null (if the PaymentRequest did not specify a payment_url)
- */
- @Nullable
- public Protos.Payment getPayment(List txns, @Nullable Address refundAddr, @Nullable String memo)
- throws IOException {
- if (paymentDetails.hasPaymentUrl()) {
- return PaymentProtocol.createPaymentMessage(txns, totalValue, refundAddr, memo, getMerchantData());
- } else {
- return null;
- }
- }
-
- @VisibleForTesting
- protected CompletableFuture sendPayment(final URL url, final Protos.Payment payment) {
- return CompletableFuture.supplyAsync((FutureUtils.ThrowingSupplier) () -> {
- HttpURLConnection connection = (HttpURLConnection) url.openConnection();
- connection.setRequestMethod("POST");
- connection.setRequestProperty("Content-Type", PaymentProtocol.MIMETYPE_PAYMENT);
- connection.setRequestProperty("Accept", PaymentProtocol.MIMETYPE_PAYMENTACK);
- connection.setRequestProperty("Content-Length", Integer.toString(payment.getSerializedSize()));
- connection.setUseCaches(false);
- connection.setDoInput(true);
- connection.setDoOutput(true);
-
- // Send request.
- DataOutputStream outStream = new DataOutputStream(connection.getOutputStream());
- payment.writeTo(outStream);
- outStream.flush();
- outStream.close();
-
- // Get response.
- Protos.PaymentACK paymentAck = Protos.PaymentACK.parseFrom(connection.getInputStream());
- return PaymentProtocol.parsePaymentAck(paymentAck);
- }, executor);
- }
-
- private void parsePaymentRequest(Protos.PaymentRequest request) throws PaymentProtocolException {
- try {
- if (request == null)
- throw new PaymentProtocolException("request cannot be null");
- if (request.getPaymentDetailsVersion() != 1)
- throw new PaymentProtocolException.InvalidVersion("Version 1 required. Received version " + request.getPaymentDetailsVersion());
- paymentRequest = request;
- if (!request.hasSerializedPaymentDetails())
- throw new PaymentProtocolException("No PaymentDetails");
- paymentDetails = Protos.PaymentDetails.newBuilder().mergeFrom(request.getSerializedPaymentDetails()).build();
- if (paymentDetails == null)
- throw new PaymentProtocolException("Invalid PaymentDetails");
- if (!paymentDetails.hasNetwork())
- params = MainNetParams.get();
- else
- params = PaymentProtocol.paramsFromPmtProtocolID(paymentDetails.getNetwork());
- if (params == null)
- throw new PaymentProtocolException.InvalidNetwork("Invalid network " + paymentDetails.getNetwork());
- if (paymentDetails.getOutputsCount() < 1)
- throw new PaymentProtocolException.InvalidOutputs("No outputs");
- for (Protos.Output output : paymentDetails.getOutputsList()) {
- if (output.hasAmount())
- totalValue = totalValue.add(Coin.valueOf(output.getAmount()));
- }
- // This won't ever happen in practice. It would only happen if the user provided outputs
- // that are obviously invalid. Still, we don't want to silently overflow.
- if (params.network().exceedsMaxMoney(totalValue))
- throw new PaymentProtocolException.InvalidOutputs("The outputs are way too big.");
- } catch (InvalidProtocolBufferException e) {
- throw new PaymentProtocolException(e);
- }
- }
-
- /** Returns the value of pkiVerificationData or null if it wasn't verified at construction time. */
- @Nullable public PkiVerificationData verifyPki() {
- return pkiVerificationData;
- }
-
- /** Gets the params as read from the PaymentRequest.network field: main is the default if missing. */
- public NetworkParameters getNetworkParameters() {
- return params;
- }
-
- /** Returns the protobuf that this object was instantiated with. */
- public Protos.PaymentRequest getPaymentRequest() {
- return paymentRequest;
- }
-
- /** Returns the protobuf that describes the payment to be made. */
- public Protos.PaymentDetails getPaymentDetails() {
- return paymentDetails;
- }
-}
diff --git a/core/src/main/java/org/bitcoinj/protocols/payments/package-info.java b/core/src/main/java/org/bitcoinj/protocols/payments/package-info.java
deleted file mode 100644
index 72cf934ca5a..00000000000
--- a/core/src/main/java/org/bitcoinj/protocols/payments/package-info.java
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * Copyright by the original author or authors.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- * The BIP70 payment protocol wraps Bitcoin transactions and adds various useful features like memos, refund addresses
- * and authentication.
- */
-package org.bitcoinj.protocols.payments;
\ No newline at end of file
diff --git a/core/src/main/java/org/bitcoinj/testing/MockAltNetworkParams.java b/core/src/main/java/org/bitcoinj/testing/MockAltNetworkParams.java
index 20f68736f4d..b71e1289d25 100644
--- a/core/src/main/java/org/bitcoinj/testing/MockAltNetworkParams.java
+++ b/core/src/main/java/org/bitcoinj/testing/MockAltNetworkParams.java
@@ -39,11 +39,6 @@ public MockAltNetworkParams() {
p2shHeader = 5;
}
- @Override
- public String getPaymentProtocolId() {
- return null;
- }
-
@Override
public void checkDifficultyTransitions(StoredBlock storedPrev, Block next, BlockStore blockStore) throws VerificationException, BlockStoreException {
diff --git a/core/src/main/java/org/bitcoinj/uri/BitcoinURI.java b/core/src/main/java/org/bitcoinj/uri/BitcoinURI.java
index 2e9dc36aedb..250a8575e4b 100644
--- a/core/src/main/java/org/bitcoinj/uri/BitcoinURI.java
+++ b/core/src/main/java/org/bitcoinj/uri/BitcoinURI.java
@@ -82,7 +82,6 @@ public class BitcoinURI {
public static final String FIELD_LABEL = "label";
public static final String FIELD_AMOUNT = "amount";
public static final String FIELD_ADDRESS = "address";
- public static final String FIELD_PAYMENT_REQUEST_URL = "r";
/**
* URI Scheme for Bitcoin network.
@@ -188,8 +187,8 @@ private BitcoinURI(String input, @Nullable Network network) throws BitcoinURIPar
}
}
- if (addressToken.isEmpty() && getPaymentRequestUrl() == null) {
- throw new BitcoinURIParseException("No address and no r= parameter found");
+ if (addressToken.isEmpty()) {
+ throw new BitcoinURIParseException("No address found");
}
}
@@ -287,32 +286,6 @@ public String getMessage() {
return (String) parameterMap.get(FIELD_MESSAGE);
}
- /**
- * @return The URL where a payment request (as specified in BIP 70) may
- * be fetched.
- */
- public final String getPaymentRequestUrl() {
- return (String) parameterMap.get(FIELD_PAYMENT_REQUEST_URL);
- }
-
- /**
- * Returns the URLs where a payment request (as specified in BIP 70) may be fetched. The first URL is the main URL,
- * all subsequent URLs are fallbacks.
- */
- public List getPaymentRequestUrls() {
- ArrayList urls = new ArrayList<>();
- while (true) {
- int i = urls.size();
- String paramName = FIELD_PAYMENT_REQUEST_URL + (i > 0 ? Integer.toString(i) : "");
- String url = (String) parameterMap.get(paramName);
- if (url == null)
- break;
- urls.add(url);
- }
- Collections.reverse(urls);
- return urls;
- }
-
/**
* @param name The name of the parameter
* @return The parameter value, or null if not present
diff --git a/core/src/main/java/org/bitcoinj/wallet/SendRequest.java b/core/src/main/java/org/bitcoinj/wallet/SendRequest.java
index 9a67d34fda3..bc92791dd1f 100644
--- a/core/src/main/java/org/bitcoinj/wallet/SendRequest.java
+++ b/core/src/main/java/org/bitcoinj/wallet/SendRequest.java
@@ -18,7 +18,6 @@
package org.bitcoinj.wallet;
import com.google.common.base.MoreObjects;
-import org.bitcoinj.protobuf.payments.Protos.PaymentDetails;
import org.bitcoinj.base.Address;
import org.bitcoinj.base.Coin;
import org.bitcoinj.crypto.AesKey;
@@ -228,13 +227,6 @@ public static SendRequest childPaysForParent(Wallet wallet, Transaction parentTr
return req;
}
- /** Copy data from payment request. */
- public SendRequest fromPaymentDetails(PaymentDetails paymentDetails) {
- if (paymentDetails.hasMemo())
- this.memo = paymentDetails.getMemo();
- return this;
- }
-
@Override
public String toString() {
// print only the user-settable fields
diff --git a/core/src/main/proto/paymentrequest.proto b/core/src/main/proto/paymentrequest.proto
deleted file mode 100644
index d961ea542e1..00000000000
--- a/core/src/main/proto/paymentrequest.proto
+++ /dev/null
@@ -1,73 +0,0 @@
-/** Copyright 2013 Google Inc.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/*
- * Authors: Mike Hearn, Gavin Andresen
- */
-
-/* Notes:
- * - Endianness: All byte arrays that represent numbers (such as hashes and private keys) are Big Endian
- * - To regenerate after editing, run gradle generateProto
- */
-
-//
-// Simple Bitcoin Payment Protocol messages
-//
-// Use fields 100+ for extensions;
-// to avoid conflicts, register extensions at:
-// https://en.bitcoin.it/wiki/Payment_Request
-//
-
-syntax = "proto2";
-
-package payments;
-
-option java_package = "org.bitcoinj.protobuf.payments";
-option java_outer_classname = "Protos";
-
-// Generalized form of "send payment to this/these bitcoin addresses"
-message Output {
- optional uint64 amount = 1 [default = 0]; // amount is integer-number-of-satoshis
- required bytes script = 2; // usually one of the standard Script forms
-}
-message PaymentDetails {
- optional string network = 1 [default = "main"]; // "main" or "test"
- repeated Output outputs = 2; // Where payment should be sent
- required uint64 time = 3; // Timestamp; when payment request created
- optional uint64 expires = 4; // Timestamp; when this request should be considered invalid
- optional string memo = 5; // Human-readable description of request for the customer
- optional string payment_url = 6; // URL to send Payment and get PaymentACK
- optional bytes merchant_data = 7; // Arbitrary data to include in the Payment message
-}
-message PaymentRequest {
- optional uint32 payment_details_version = 1 [default = 1];
- optional string pki_type = 2 [default = "none"]; // none / x509+sha256 / x509+sha1
- optional bytes pki_data = 3; // depends on pki_type
- required bytes serialized_payment_details = 4; // PaymentDetails
- optional bytes signature = 5; // pki-dependent signature
-}
-message X509Certificates {
- repeated bytes certificate = 1; // DER-encoded X.509 certificate chain
-}
-message Payment {
- optional bytes merchant_data = 1; // From PaymentDetails.merchant_data
- repeated bytes transactions = 2; // Signed transactions that satisfy PaymentDetails.outputs
- repeated Output refund_to = 3; // Where to send refunds, if a refund is necessary
- optional string memo = 4; // Human-readable message for the merchant
-}
-message PaymentACK {
- required Payment payment = 1; // Payment message that triggered this ACK
- optional string memo = 2; // human-readable message for customer
-}
\ No newline at end of file
diff --git a/core/src/test/java/org/bitcoinj/crypto/X509UtilsTest.java b/core/src/test/java/org/bitcoinj/crypto/X509UtilsTest.java
deleted file mode 100644
index 782311d1767..00000000000
--- a/core/src/test/java/org/bitcoinj/crypto/X509UtilsTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Copyright 2014 Andreas Schildbach
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.bitcoinj.crypto;
-
-import org.junit.Test;
-
-import java.security.cert.CertificateFactory;
-import java.security.cert.X509Certificate;
-
-import static org.junit.Assert.assertEquals;
-
-public class X509UtilsTest {
-
- @Test
- public void testDisplayName() throws Exception {
- CertificateFactory cf = CertificateFactory.getInstance("X.509");
-
- X509Certificate clientCert = (X509Certificate) cf.generateCertificate(getClass().getResourceAsStream(
- "startssl-client.crt"));
- assertEquals("Andreas Schildbach", X509Utils.getDisplayNameFromCertificate(clientCert, false));
-
- X509Certificate comodoCert = (X509Certificate) cf.generateCertificate(getClass().getResourceAsStream(
- "comodo-smime.crt"));
- assertEquals("comodo.com@schildbach.de", X509Utils.getDisplayNameFromCertificate(comodoCert, true));
- }
-}
diff --git a/core/src/test/java/org/bitcoinj/protocols/payments/PaymentProtocolTest.java b/core/src/test/java/org/bitcoinj/protocols/payments/PaymentProtocolTest.java
deleted file mode 100644
index f61403b3462..00000000000
--- a/core/src/test/java/org/bitcoinj/protocols/payments/PaymentProtocolTest.java
+++ /dev/null
@@ -1,162 +0,0 @@
-/*
- * Copyright 2014 Andreas Schildbach
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.bitcoinj.protocols.payments;
-
-import org.bitcoinj.protobuf.payments.Protos;
-import org.bitcoinj.protobuf.payments.Protos.Payment;
-import org.bitcoinj.protobuf.payments.Protos.PaymentACK;
-import org.bitcoinj.protobuf.payments.Protos.PaymentRequest;
-import org.bitcoinj.base.BitcoinNetwork;
-import org.bitcoinj.base.ScriptType;
-import org.bitcoinj.base.Address;
-import org.bitcoinj.base.Coin;
-import org.bitcoinj.base.internal.TimeUtils;
-import org.bitcoinj.crypto.ECKey;
-import org.bitcoinj.core.NetworkParameters;
-import org.bitcoinj.core.Transaction;
-import org.bitcoinj.crypto.X509Utils;
-import org.bitcoinj.params.TestNet3Params;
-import org.bitcoinj.protocols.payments.PaymentProtocol.Output;
-import org.bitcoinj.protocols.payments.PaymentProtocol.PkiVerificationData;
-import org.bitcoinj.protocols.payments.PaymentProtocolException.PkiVerificationException;
-import org.bitcoinj.script.ScriptBuilder;
-import org.bitcoinj.testing.FakeTxBuilder;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.security.KeyStore;
-import java.security.PrivateKey;
-import java.security.cert.X509Certificate;
-import java.util.LinkedList;
-import java.util.List;
-
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-public class PaymentProtocolTest {
- private static final NetworkParameters TESTNET = TestNet3Params.get();
-
- // static test data
- private static final Coin AMOUNT = Coin.SATOSHI;
- private static final Address TO_ADDRESS = new ECKey().toAddress(ScriptType.P2PKH, BitcoinNetwork.TESTNET);
- private static final String MEMO = "memo";
- private static final String PAYMENT_URL = "https://example.com";
- private static final byte[] MERCHANT_DATA = { 0, 1, 2 };
-
- private KeyStore caStore;
- private X509Certificate caCert;
-
- @Before
- public void setUp() throws Exception {
- caStore = X509Utils.loadKeyStore("JKS", "password", getClass().getResourceAsStream("test-cacerts"));
- caCert = (X509Certificate) caStore.getCertificate("test-cacert");
- }
-
- @Test
- public void testSignAndVerifyValid() throws Exception {
- Protos.PaymentRequest.Builder paymentRequest = minimalPaymentRequest().toBuilder();
-
- // Sign
- KeyStore keyStore = X509Utils
- .loadKeyStore("JKS", "password", getClass().getResourceAsStream("test-valid-cert"));
- PrivateKey privateKey = (PrivateKey) keyStore.getKey("test-valid", "password".toCharArray());
- X509Certificate clientCert = (X509Certificate) keyStore.getCertificate("test-valid");
- PaymentProtocol.signPaymentRequest(paymentRequest, new X509Certificate[]{clientCert}, privateKey);
-
- // Verify
- PkiVerificationData verificationData = PaymentProtocol.verifyPaymentRequestPki(paymentRequest.build(), caStore);
- assertNotNull(verificationData);
- assertEquals(caCert, verificationData.rootAuthority.getTrustedCert());
- }
-
- @Test(expected = PkiVerificationException.class)
- public void testSignAndVerifyExpired() throws Exception {
- Protos.PaymentRequest.Builder paymentRequest = minimalPaymentRequest().toBuilder();
-
- // Sign
- KeyStore keyStore = X509Utils.loadKeyStore("JKS", "password",
- getClass().getResourceAsStream("test-expired-cert"));
- PrivateKey privateKey = (PrivateKey) keyStore.getKey("test-expired", "password".toCharArray());
- X509Certificate clientCert = (X509Certificate) keyStore.getCertificate("test-expired");
- PaymentProtocol.signPaymentRequest(paymentRequest, new X509Certificate[]{clientCert}, privateKey);
-
- // Verify
- PaymentProtocol.verifyPaymentRequestPki(paymentRequest.build(), caStore);
- }
-
- private Protos.PaymentRequest minimalPaymentRequest() {
- Protos.PaymentDetails.Builder paymentDetails = Protos.PaymentDetails.newBuilder();
- paymentDetails.setTime(TimeUtils.currentTime().getEpochSecond());
- Protos.PaymentRequest.Builder paymentRequest = Protos.PaymentRequest.newBuilder();
- paymentRequest.setSerializedPaymentDetails(paymentDetails.build().toByteString());
- return paymentRequest.build();
- }
-
- @Test
- public void testPaymentRequest() throws Exception {
- // Create
- PaymentRequest paymentRequest = PaymentProtocol.createPaymentRequest(TESTNET, AMOUNT, TO_ADDRESS, MEMO,
- PAYMENT_URL, MERCHANT_DATA).build();
- byte[] paymentRequestBytes = paymentRequest.toByteArray();
-
- // Parse
- PaymentSession parsedPaymentRequest = PaymentProtocol.parsePaymentRequest(PaymentRequest
- .parseFrom(paymentRequestBytes));
- final List