public class PaymentProtocol extends Object
Utility methods and constants for working with
BIP 70 aka the payment protocol. These are low level wrappers around the protocol buffers. If you're implementing
a wallet app, look at PaymentSession
for a higher level API that should simplify working with the protocol.
BIP 70 defines a binary, protobuf based protocol that runs directly between sender and receiver of funds. Payment protocol data does not flow over the Bitcoin P2P network or enter the block chain. It's instead for data that is only of interest to the parties involved but isn't otherwise needed for consensus.
Modifier and Type | Class and Description |
---|---|
static class |
PaymentProtocol.Ack
Message returned by the merchant in response to a Payment message.
|
static class |
PaymentProtocol.Output
Value object to hold amount/script pairs.
|
static class |
PaymentProtocol.PkiVerificationData
Information about the X.509 signature's issuer and subject.
|
Modifier and Type | Field and Description |
---|---|
static String |
MIMETYPE_PAYMENT |
static String |
MIMETYPE_PAYMENTACK |
static String |
MIMETYPE_PAYMENTREQUEST |
Constructor and Description |
---|
PaymentProtocol() |
Modifier and Type | Method and Description |
---|---|
static Protos.PaymentACK |
createPaymentAck(Protos.Payment paymentMessage,
String memo)
Create a payment ack.
|
static Protos.Payment |
createPaymentMessage(List<Transaction> transactions,
Coin refundAmount,
Address refundAddress,
String memo,
byte[] merchantData)
Create a payment message with one standard pay to address output.
|
static Protos.Payment |
createPaymentMessage(List<Transaction> transactions,
List<Protos.Output> refundOutputs,
String memo,
byte[] merchantData)
Create a payment message.
|
static Protos.PaymentRequest.Builder |
createPaymentRequest(NetworkParameters params,
Coin amount,
Address toAddress,
String memo,
String paymentUrl,
byte[] merchantData)
Create a payment request with one standard pay to address output.
|
static Protos.PaymentRequest.Builder |
createPaymentRequest(NetworkParameters params,
List<Protos.Output> outputs,
String memo,
String paymentUrl,
byte[] merchantData)
Create a payment request.
|
static Protos.Output |
createPayToAddressOutput(Coin amount,
Address address)
Create a standard pay to address output for usage in
createPaymentRequest(org.bitcoinj.core.NetworkParameters, org.bitcoinj.core.Coin, org.bitcoinj.core.Address, java.lang.String, java.lang.String, byte[]) and
createPaymentMessage(java.util.List<org.bitcoinj.core.Transaction>, org.bitcoinj.core.Coin, org.bitcoinj.core.Address, java.lang.String, byte[]) . |
static PaymentProtocol.Ack |
parsePaymentAck(Protos.PaymentACK paymentAck)
Parse payment ack into an object.
|
static PaymentSession |
parsePaymentRequest(Protos.PaymentRequest paymentRequest)
Parse a payment request.
|
static List<Transaction> |
parseTransactionsFromPaymentMessage(NetworkParameters params,
Protos.Payment paymentMessage)
Parse transactions from payment message.
|
static void |
signPaymentRequest(Protos.PaymentRequest.Builder paymentRequest,
X509Certificate[] certificateChain,
PrivateKey privateKey)
Sign the provided payment request.
|
static PaymentProtocol.PkiVerificationData |
verifyPaymentRequestPki(Protos.PaymentRequest paymentRequest,
KeyStore trustStore)
Uses the provided PKI method to find the corresponding public key and verify the provided signature.
|
public static final String MIMETYPE_PAYMENTREQUEST
public static final String MIMETYPE_PAYMENT
public static final String MIMETYPE_PAYMENTACK
public static Protos.PaymentRequest.Builder createPaymentRequest(NetworkParameters params, @Nullable Coin amount, Address toAddress, @Nullable String memo, @Nullable String paymentUrl, @Nullable byte[] merchantData)
signPaymentRequest(org.bitcoin.protocols.payments.Protos.PaymentRequest.Builder, java.security.cert.X509Certificate[], java.security.PrivateKey)
. Use Protos.PaymentRequest.Builder#build
to get the actual payment
request.params
- network parametersamount
- amount of coins to request, or nulltoAddress
- address to request coins tomemo
- arbitrary, user readable memo, or null if nonepaymentUrl
- URL to send payment message to, or null if nonemerchantData
- arbitrary merchant data, or null if nonepublic static Protos.PaymentRequest.Builder createPaymentRequest(NetworkParameters params, List<Protos.Output> outputs, @Nullable String memo, @Nullable String paymentUrl, @Nullable byte[] merchantData)
signPaymentRequest(org.bitcoin.protocols.payments.Protos.PaymentRequest.Builder, java.security.cert.X509Certificate[], java.security.PrivateKey)
. Use
Protos.PaymentRequest.Builder#build
to get the actual payment request.params
- network parametersoutputs
- list of outputs to request coins tomemo
- arbitrary, user readable memo, or null if nonepaymentUrl
- URL to send payment message to, or null if nonemerchantData
- arbitrary merchant data, or null if nonepublic static PaymentSession parsePaymentRequest(Protos.PaymentRequest paymentRequest) throws PaymentProtocolException
paymentRequest
- payment request to parsePaymentSession
, used as a value objectPaymentProtocolException
public static void signPaymentRequest(Protos.PaymentRequest.Builder paymentRequest, X509Certificate[] certificateChain, PrivateKey privateKey)
paymentRequest
- Payment request to sign, in its builder form.certificateChain
- Certificate chain to send with the payment request, ordered from client certificate to root
certificate. The root certificate itself may be omitted.privateKey
- The key to sign with. Must match the public key from the first certificate of the certificate chain.@Nullable public static PaymentProtocol.PkiVerificationData verifyPaymentRequestPki(Protos.PaymentRequest paymentRequest, KeyStore trustStore) throws PaymentProtocolException
paymentRequest
- Payment request to verify.trustStore
- KeyStore of trusted root certificate authorities.Protos.PaymentRequest
.PaymentProtocolException
- if payment request could not be verified.public static Protos.Payment createPaymentMessage(List<Transaction> transactions, @Nullable Coin refundAmount, @Nullable Address refundAddress, @Nullable String memo, @Nullable byte[] merchantData)
transactions
- one or more transactions that satisfy the requested outputs.refundAmount
- amount of coins to request as a refund, or null if no refund.refundAddress
- address to refund coins tomemo
- arbitrary, user readable memo, or null if nonemerchantData
- arbitrary merchant data, or null if nonepublic static Protos.Payment createPaymentMessage(List<Transaction> transactions, @Nullable List<Protos.Output> refundOutputs, @Nullable String memo, @Nullable byte[] merchantData)
transactions
- transactions to include with the payment messagerefundOutputs
- list of outputs to refund coins to, or nullmemo
- arbitrary, user readable memo, or null if nonemerchantData
- arbitrary merchant data, or null if nonepublic static List<Transaction> parseTransactionsFromPaymentMessage(NetworkParameters params, Protos.Payment paymentMessage)
params
- network parameters (needed for transaction deserialization)paymentMessage
- payment message to parsepublic static Protos.PaymentACK createPaymentAck(Protos.Payment paymentMessage, @Nullable String memo)
paymentMessage
- payment message to send with the ackmemo
- arbitrary, user readable memo, or null if nonepublic static PaymentProtocol.Ack parsePaymentAck(Protos.PaymentACK paymentAck)
public static Protos.Output createPayToAddressOutput(@Nullable Coin amount, Address address)
createPaymentRequest(org.bitcoinj.core.NetworkParameters, org.bitcoinj.core.Coin, org.bitcoinj.core.Address, java.lang.String, java.lang.String, byte[])
and
createPaymentMessage(java.util.List<org.bitcoinj.core.Transaction>, org.bitcoinj.core.Coin, org.bitcoinj.core.Address, java.lang.String, byte[])
.amount
- amount to pay, or nulladdress
- address to pay toCopyright © 2016. All rights reserved.