From a27ba7c8a1a19135a688f2a5bde955409b223ae4 Mon Sep 17 00:00:00 2001 From: alan10fm Date: Fri, 30 Oct 2020 13:25:04 -0600 Subject: [PATCH] Upgrading to beta version --- build.gradle.kts | 4 +- .../service/TransactIdService.kt | 185 +++++++++++++----- .../util/TestData.kt | 85 +++++--- 3 files changed, 195 insertions(+), 79 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 722695e..246534d 100755 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,7 +8,7 @@ plugins { } group = "com.netki" -version = "0.1.0-alpha16" +version = "1.0.0-beta1" java.sourceCompatibility = JavaVersion.VERSION_1_8 repositories { @@ -18,7 +18,7 @@ repositories { } dependencies { - implementation("com.netki:transactid:0.1.0-alpha16") + implementation("com.netki:transactid:1.0.0-beta1") implementation("org.springframework.boot:spring-boot-starter-web") implementation("com.fasterxml.jackson.module:jackson-module-kotlin") diff --git a/src/main/java/com/netki/transactidlibraryjavademo/service/TransactIdService.kt b/src/main/java/com/netki/transactidlibraryjavademo/service/TransactIdService.kt index 94b2cd4..5058039 100755 --- a/src/main/java/com/netki/transactidlibraryjavademo/service/TransactIdService.kt +++ b/src/main/java/com/netki/transactidlibraryjavademo/service/TransactIdService.kt @@ -1,22 +1,22 @@ package com.netki.transactidlibraryjavademo.service import com.netki.TransactId -import com.netki.model.EncryptionParameters -import com.netki.model.MessageInformation -import com.netki.model.RecipientParameters -import com.netki.model.SenderParameters +import com.netki.model.* import com.netki.transactidlibraryjavademo.model.EncryptionKeys import com.netki.transactidlibraryjavademo.util.TestData.Attestations.ATTESTATIONS_REQUESTED -import com.netki.transactidlibraryjavademo.util.TestData.InvoiceRequest.INVOICE_REQUEST_DATA -import com.netki.transactidlibraryjavademo.util.TestData.Owners.NO_PRIMARY_OWNER_PKI_X509SHA256 -import com.netki.transactidlibraryjavademo.util.TestData.Owners.PRIMARY_OWNER_PKI_X509SHA256 -import com.netki.transactidlibraryjavademo.util.TestData.Payment.PAYMENT_PARAMETERS -import com.netki.transactidlibraryjavademo.util.TestData.PaymentRequest.PAYMENT_REQUEST_PARAMETERS +import com.netki.transactidlibraryjavademo.util.TestData.Beneficiaries.NO_PRIMARY_BENEFICIARY_PKI_NONE +import com.netki.transactidlibraryjavademo.util.TestData.Beneficiaries.NO_PRIMARY_BENEFICIARY_PKI_X509SHA256 +import com.netki.transactidlibraryjavademo.util.TestData.Beneficiaries.PRIMARY_BENEFICIARY_PKI_X509SHA256 +import com.netki.transactidlibraryjavademo.util.TestData.Originators.NO_PRIMARY_ORIGINATOR_PKI_X509SHA256 +import com.netki.transactidlibraryjavademo.util.TestData.Originators.PRIMARY_ORIGINATOR_PKI_X509SHA256 +import com.netki.transactidlibraryjavademo.util.TestData.Output.OUTPUTS +import com.netki.transactidlibraryjavademo.util.TestData.Payment.PAYMENT import com.netki.transactidlibraryjavademo.util.TestData.PkiData.PKI_DATA_SENDER_X509SHA256 import com.netki.transactidlibraryjavademo.util.TestData.Senders.SENDER_PKI_X509SHA256 import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.stereotype.Service +import java.sql.Timestamp import javax.annotation.PostConstruct @Service @@ -29,7 +29,6 @@ class TransactIdService { private val logger = LoggerFactory.getLogger(this.javaClass) private var transactId = TransactId.getInstance("src/main/resources/certificates") - val ownerParameters = listOf(PRIMARY_OWNER_PKI_X509SHA256, NO_PRIMARY_OWNER_PKI_X509SHA256) val messageInformationEncrypted = MessageInformation( encryptMessage = true ) @@ -57,26 +56,53 @@ class TransactIdService { fun getInitialInvoiceRequest(): ByteArray { logger.info("Creating InvoiceRequest...") - val invoiceRequest = transactId.createInvoiceRequest( - INVOICE_REQUEST_DATA, - ownerParameters, - SENDER_PKI_X509SHA256, - ATTESTATIONS_REQUESTED + val originators = listOf( + PRIMARY_ORIGINATOR_PKI_X509SHA256, + NO_PRIMARY_ORIGINATOR_PKI_X509SHA256 ) + val beneficiaries = listOf( + PRIMARY_BENEFICIARY_PKI_X509SHA256 + ) + val sender = SENDER_PKI_X509SHA256 + val invoiceRequestParameters = InvoiceRequestParameters( + amount = 1000, + memo = "memo", + notificationUrl = "notificationUrl", + originatorsAddresses = OUTPUTS, + originatorParameters = originators, + beneficiaryParameters = beneficiaries, + senderParameters = sender, + attestationsRequested = ATTESTATIONS_REQUESTED + ) + + val invoiceRequest = transactId.createInvoiceRequest(invoiceRequestParameters) logger.info("Returning InvoiceRequest...") return invoiceRequest } fun getInitialInvoiceRequestEncrypted(): ByteArray { logger.info("Creating InvoiceRequest encrypted...") - val invoiceRequest = transactId.createInvoiceRequest( - INVOICE_REQUEST_DATA, - ownerParameters, - senderParameters, - ATTESTATIONS_REQUESTED, - recipientParameters, - messageInformationEncrypted + val originators = listOf( + PRIMARY_ORIGINATOR_PKI_X509SHA256, + NO_PRIMARY_ORIGINATOR_PKI_X509SHA256 + ) + val beneficiaries = listOf( + PRIMARY_BENEFICIARY_PKI_X509SHA256 + ) + val invoiceRequestParameters = InvoiceRequestParameters( + amount = 1000, + memo = "memo", + notificationUrl = "notificationUrl", + originatorsAddresses = OUTPUTS, + originatorParameters = originators, + beneficiaryParameters = beneficiaries, + senderParameters = senderParameters, + attestationsRequested = ATTESTATIONS_REQUESTED, + recipientParameters = recipientParameters, + messageInformation = messageInformationEncrypted ) + + val invoiceRequest = transactId.createInvoiceRequest(invoiceRequestParameters) logger.info("Returning InvoiceRequest...") return invoiceRequest } @@ -96,25 +122,46 @@ class TransactIdService { return if (invoiceRequestModel.protocolMessageMetadata.encrypted) { logger.info("Creating PaymentRequest Encrypted...") logger.info("Returning PaymentRequest Encrypted...") - transactId.createPaymentRequest( - PAYMENT_REQUEST_PARAMETERS, - ownerParameters, - senderParameters, - ATTESTATIONS_REQUESTED, - 1, - messageInformationEncrypted, - recipientParameters + val beneficiaries = listOf( + PRIMARY_BENEFICIARY_PKI_X509SHA256, + NO_PRIMARY_BENEFICIARY_PKI_X509SHA256 ) + val paymentRequestParameters = PaymentRequestParameters( + network = "main", + beneficiariesAddresses = OUTPUTS, + time = Timestamp(System.currentTimeMillis()), + expires = Timestamp(System.currentTimeMillis()), + memo = "memo", + paymentUrl = "www.payment.url/test", + merchantData = "merchant data", + beneficiaryParameters = beneficiaries, + senderParameters = senderParameters, + attestationsRequested = ATTESTATIONS_REQUESTED, + messageInformation = messageInformationEncrypted, + recipientParameters = recipientParameters + ) + transactId.createPaymentRequest(paymentRequestParameters) } else { logger.info("Creating PaymentRequest...") logger.info("Returning PaymentRequest...") - transactId.createPaymentRequest( - PAYMENT_REQUEST_PARAMETERS, - ownerParameters, - SENDER_PKI_X509SHA256, - ATTESTATIONS_REQUESTED, - 1 + val beneficiaries = listOf( + PRIMARY_BENEFICIARY_PKI_X509SHA256, + NO_PRIMARY_BENEFICIARY_PKI_X509SHA256 + ) + val sender = SENDER_PKI_X509SHA256 + val paymentRequestParameters = PaymentRequestParameters( + network = "main", + beneficiariesAddresses = OUTPUTS, + time = Timestamp(System.currentTimeMillis()), + expires = Timestamp(System.currentTimeMillis()), + memo = "memo", + paymentUrl = "www.payment.url/test", + merchantData = "merchant data", + beneficiaryParameters = beneficiaries, + senderParameters = sender, + attestationsRequested = ATTESTATIONS_REQUESTED ) + transactId.createPaymentRequest(paymentRequestParameters) } } @@ -133,18 +180,51 @@ class TransactIdService { return if (paymentRequestModel.protocolMessageMetadata.encrypted) { logger.info("Creating Payment Encrypted...") logger.info("Returning Payment Encrypted...") - transactId.createPayment( - PAYMENT_PARAMETERS, - ownerParameters, - messageInformationEncrypted, - senderParameters, - recipientParameters + val originators = listOf( + PRIMARY_ORIGINATOR_PKI_X509SHA256, + NO_PRIMARY_ORIGINATOR_PKI_X509SHA256 + ) + val beneficiaries = listOf( + PRIMARY_BENEFICIARY_PKI_X509SHA256 ) + val paymentParameters = PaymentParameters( + merchantData = "merchant data", + transactions = arrayListOf( + "transaction1".toByteArray(), + "transaction2".toByteArray() + ), + outputs = OUTPUTS, + memo = "memo", + originatorParameters = originators, + beneficiaryParameters = beneficiaries, + messageInformation = messageInformationEncrypted, + senderParameters = senderParameters, + recipientParameters = recipientParameters + ) + transactId.createPayment(paymentParameters) } else { logger.info("Creating Payment...") logger.info("Returning Payment...") - transactId.createPayment(PAYMENT_PARAMETERS, ownerParameters) + val originators = listOf( + PRIMARY_ORIGINATOR_PKI_X509SHA256, + NO_PRIMARY_ORIGINATOR_PKI_X509SHA256 + ) + val beneficiaries = listOf( + PRIMARY_BENEFICIARY_PKI_X509SHA256 + ) + val paymentParameters = PaymentParameters( + merchantData = "merchant data", + transactions = arrayListOf( + "transaction1".toByteArray(), + "transaction2".toByteArray() + ), + outputs = OUTPUTS, + memo = "memo", + originatorParameters = originators, + beneficiaryParameters = beneficiaries + ) + transactId.createPayment(paymentParameters) } } @@ -157,17 +237,22 @@ class TransactIdService { return if (paymentModel.protocolMessageMetadata!!.encrypted) { logger.info("Creating PaymentAck Encrypted...") logger.info("Returning PaymentAck Encrypted...") - transactId.createPaymentAck( - paymentModel, - "Payment successful", - messageInformationEncrypted, - senderParameters, - recipientParameters + val paymentAckParameters = PaymentAckParameters( + payment = PAYMENT, + memo = "memo ack", + messageInformation = messageInformationEncrypted, + senderParameters = senderParameters, + recipientParameters = recipientParameters ) + transactId.createPaymentAck(paymentAckParameters) } else { logger.info("Creating PaymentAck...") logger.info("Returning PaymentAck...") - transactId.createPaymentAck(paymentModel, "Payment successful") + val paymentAckParameters = PaymentAckParameters( + payment = PAYMENT, + memo = "memo ack" + ) + transactId.createPaymentAck(paymentAckParameters) } } } diff --git a/src/main/java/com/netki/transactidlibraryjavademo/util/TestData.kt b/src/main/java/com/netki/transactidlibraryjavademo/util/TestData.kt index 0de0840..47e8555 100644 --- a/src/main/java/com/netki/transactidlibraryjavademo/util/TestData.kt +++ b/src/main/java/com/netki/transactidlibraryjavademo/util/TestData.kt @@ -5,7 +5,6 @@ import com.netki.transactidlibraryjavademo.util.TestData.Output.OUTPUTS import com.netki.transactidlibraryjavademo.util.TestData.PkiData.PKI_DATA_ONE_OWNER_X509SHA256 import com.netki.transactidlibraryjavademo.util.TestData.PkiData.PKI_DATA_SENDER_X509SHA256 import com.netki.transactidlibraryjavademo.util.TestData.PkiData.PKI_DATA_TWO_OWNER_X509SHA256 -import java.sql.Timestamp object TestData { @@ -111,36 +110,46 @@ object TestData { "UM5JZTOfmyf5CwE2lNBZryI=\n" + "-----END PRIVATE KEY-----\n" - object InvoiceRequest { - val INVOICE_REQUEST_DATA = InvoiceRequestParameters( - amount = 1000, - memo = "memo", - notificationUrl = "notificationUrl", - outputs = OUTPUTS - ) - } - - object PaymentRequest { - val PAYMENT_REQUEST_PARAMETERS = PaymentRequestParameters( - network = "main", - outputs = OUTPUTS, - time = Timestamp(System.currentTimeMillis()), - expires = Timestamp(System.currentTimeMillis()), - memo = "memo", - paymentUrl = "www.payment.url/test", - merchantData = "merchant data" - ) - } - object Payment { - val PAYMENT_PARAMETERS = PaymentParameters( + val PAYMENT = Payment( merchantData = "merchant data", transactions = arrayListOf( "transaction1".toByteArray(), "transaction2".toByteArray() ), outputs = OUTPUTS, - memo = "memo" + memo = "memo", + beneficiaries = listOf( + Beneficiary( + isPrimaryForTransaction = true, + pkiDataSet = listOf( + PkiData( + attestation = Attestation.ADDRESS_COUNTRY, + certificatePem = CLIENT_CERTIFICATE_CHAIN_ONE, + type = PkiType.X509SHA256 + ) + ) + ) + ), + originators = listOf( + Originator( + isPrimaryForTransaction = true, + pkiDataSet = listOf( + PkiData( + attestation = Attestation.ADDRESS_COUNTRY, + certificatePem = CLIENT_CERTIFICATE_CHAIN_ONE, + type = PkiType.X509SHA256 + ) + ) + ) + ), + protocolMessageMetadata = ProtocolMessageMetadata( + 1, + StatusCode.OK, + MessageType.PAYMENT, + "", + "randomIdentifier" + ) ) } @@ -151,13 +160,35 @@ object TestData { ) } - object Owners { - val PRIMARY_OWNER_PKI_X509SHA256 = OwnerParameters( + object Beneficiaries { + val PRIMARY_BENEFICIARY_PKI_X509SHA256 = BeneficiaryParameters( true, listOf(PKI_DATA_ONE_OWNER_X509SHA256, PKI_DATA_TWO_OWNER_X509SHA256) ) - val NO_PRIMARY_OWNER_PKI_X509SHA256 = OwnerParameters( + val NO_PRIMARY_BENEFICIARY_PKI_X509SHA256 = BeneficiaryParameters( + false, + listOf(PKI_DATA_ONE_OWNER_X509SHA256, PKI_DATA_TWO_OWNER_X509SHA256) + ) + + val NO_PRIMARY_BENEFICIARY_PKI_NONE = BeneficiaryParameters( + false, + listOf(PKI_DATA_ONE_OWNER_X509SHA256, PKI_DATA_TWO_OWNER_X509SHA256) + ) + } + + object Originators { + val PRIMARY_ORIGINATOR_PKI_X509SHA256 = OriginatorParameters( + true, + listOf(PKI_DATA_ONE_OWNER_X509SHA256, PKI_DATA_TWO_OWNER_X509SHA256) + ) + + val NO_PRIMARY_ORIGINATOR_PKI_X509SHA256 = OriginatorParameters( + false, + listOf(PKI_DATA_ONE_OWNER_X509SHA256, PKI_DATA_TWO_OWNER_X509SHA256) + ) + + val NO_PRIMARY_ORIGINATOR_PKI_NONE = OriginatorParameters( false, listOf(PKI_DATA_ONE_OWNER_X509SHA256, PKI_DATA_TWO_OWNER_X509SHA256) )