org.bitcoin.protocols.payments.Protos.PaymentRequest Java Examples

The following examples show how to use org.bitcoin.protocols.payments.Protos.PaymentRequest. 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: PaymentProtocolTest.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@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());
}
 
Example #2
Source File: PaymentProtocolTest.java    From bcm-android with GNU General Public License v3.0 6 votes vote down vote up
@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<Output> parsedOutputs = parsedPaymentRequest.getOutputs();
    assertEquals(1, parsedOutputs.size());
    assertEquals(AMOUNT, parsedOutputs.get(0).amount);
    assertArrayEquals(ScriptBuilder.createOutputScript(TO_ADDRESS).getProgram(), parsedOutputs.get(0).scriptData);
    assertEquals(MEMO, parsedPaymentRequest.getMemo());
    assertEquals(PAYMENT_URL, parsedPaymentRequest.getPaymentUrl());
    assertArrayEquals(MERCHANT_DATA, parsedPaymentRequest.getMerchantData());
}
 
Example #3
Source File: PaymentProtocolTest.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
@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());
}
 
Example #4
Source File: PaymentProtocolTest.java    From green_android with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testPaymentRequest() throws Exception {
    // Create
    PaymentRequest paymentRequest = PaymentProtocol.createPaymentRequest(TestNet3Params.get(), AMOUNT, TO_ADDRESS, MEMO,
            PAYMENT_URL, MERCHANT_DATA).build();
    byte[] paymentRequestBytes = paymentRequest.toByteArray();

    // Parse
    PaymentSession parsedPaymentRequest = PaymentProtocol.parsePaymentRequest(PaymentRequest
            .parseFrom(paymentRequestBytes));
    final List<Output> parsedOutputs = parsedPaymentRequest.getOutputs();
    assertEquals(1, parsedOutputs.size());
    assertEquals(AMOUNT, parsedOutputs.get(0).amount);
    assertArrayEquals(ScriptBuilder.createOutputScript(TO_ADDRESS).getProgram(), parsedOutputs.get(0).scriptData);
    assertEquals(MEMO, parsedPaymentRequest.getMemo());
    assertEquals(PAYMENT_URL, parsedPaymentRequest.getPaymentUrl());
    assertArrayEquals(MERCHANT_DATA, parsedPaymentRequest.getMerchantData());
}
 
Example #5
Source File: PaymentProtocolTest.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
@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());
}
 
Example #6
Source File: PaymentProtocolTest.java    From GreenBits with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testPaymentRequest() throws Exception {
    // Create
    PaymentRequest paymentRequest = PaymentProtocol.createPaymentRequest(TestNet3Params.get(), AMOUNT, TO_ADDRESS, MEMO,
            PAYMENT_URL, MERCHANT_DATA).build();
    byte[] paymentRequestBytes = paymentRequest.toByteArray();

    // Parse
    PaymentSession parsedPaymentRequest = PaymentProtocol.parsePaymentRequest(PaymentRequest
            .parseFrom(paymentRequestBytes));
    final List<Output> parsedOutputs = parsedPaymentRequest.getOutputs();
    assertEquals(1, parsedOutputs.size());
    assertEquals(AMOUNT, parsedOutputs.get(0).amount);
    assertArrayEquals(ScriptBuilder.createOutputScript(TO_ADDRESS).getProgram(), parsedOutputs.get(0).scriptData);
    assertEquals(MEMO, parsedPaymentRequest.getMemo());
    assertEquals(PAYMENT_URL, parsedPaymentRequest.getPaymentUrl());
    assertArrayEquals(MERCHANT_DATA, parsedPaymentRequest.getMerchantData());
}
 
Example #7
Source File: PaymentProtocolTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #8
Source File: PaymentProtocolTest.java    From bcm-android with GNU General Public License v3.0 5 votes vote down vote up
private Protos.PaymentRequest minimalPaymentRequest() {
    Protos.PaymentDetails.Builder paymentDetails = Protos.PaymentDetails.newBuilder();
    paymentDetails.setTime(System.currentTimeMillis());
    Protos.PaymentRequest.Builder paymentRequest = Protos.PaymentRequest.newBuilder();
    paymentRequest.setSerializedPaymentDetails(paymentDetails.build().toByteString());
    return paymentRequest.build();
}
 
Example #9
Source File: PaymentProtocolTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #10
Source File: PaymentProtocolTest.java    From green_android with GNU General Public License v3.0 5 votes vote down vote up
private Protos.PaymentRequest minimalPaymentRequest() {
    Protos.PaymentDetails.Builder paymentDetails = Protos.PaymentDetails.newBuilder();
    paymentDetails.setTime(System.currentTimeMillis());
    Protos.PaymentRequest.Builder paymentRequest = Protos.PaymentRequest.newBuilder();
    paymentRequest.setSerializedPaymentDetails(paymentDetails.build().toByteString());
    return paymentRequest.build();
}
 
Example #11
Source File: PaymentProtocolTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
@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);
}
 
Example #12
Source File: PaymentProtocolTest.java    From GreenBits with GNU General Public License v3.0 5 votes vote down vote up
private Protos.PaymentRequest minimalPaymentRequest() {
    Protos.PaymentDetails.Builder paymentDetails = Protos.PaymentDetails.newBuilder();
    paymentDetails.setTime(System.currentTimeMillis());
    Protos.PaymentRequest.Builder paymentRequest = Protos.PaymentRequest.newBuilder();
    paymentRequest.setSerializedPaymentDetails(paymentDetails.build().toByteString());
    return paymentRequest.build();
}