Skip to content

Commit

Permalink
WIP hash Rfq privateData
Browse files Browse the repository at this point in the history
  • Loading branch information
Diane Huxley committed Mar 30, 2024
1 parent 3aba7dd commit 428c714
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 53 deletions.
9 changes: 6 additions & 3 deletions httpclient/src/test/kotlin/tbdex/sdk/httpclient/E2ETest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ import tbdex.sdk.protocol.models.Rfq
import tbdex.sdk.protocol.models.RfqData
import tbdex.sdk.protocol.models.SelectedPayinMethod
import tbdex.sdk.protocol.models.SelectedPayoutMethod
import tbdex.sdk.protocol.models.UnhashedRfqData
import tbdex.sdk.protocol.models.UnhashedSelectedPayinMethod
import tbdex.sdk.protocol.models.UnhashedSelectedPayoutMethod
import web5.sdk.credentials.VerifiableCredential
import web5.sdk.crypto.InMemoryKeyManager
import web5.sdk.crypto.JwaCurve
Expand Down Expand Up @@ -254,14 +257,14 @@ class E2ETest {
private fun buildRfqData(
firstOfferingId: String,
vcJwt: String
) = RfqData(
) = UnhashedRfqData(
offeringId = firstOfferingId,
payin = SelectedPayinMethod(
payin = UnhashedSelectedPayinMethod(
kind = "NGN_ADDRESS",
paymentDetails = mapOf("walletAddress" to "ngn-wallet-address"),
amount = "1.00"
),
payout = SelectedPayoutMethod(
payout = UnhashedSelectedPayoutMethod(
kind = "BANK_Access Bank",
paymentDetails = mapOf(
"accountNumber" to "1234567890",
Expand Down
9 changes: 6 additions & 3 deletions httpclient/src/test/kotlin/tbdex/sdk/httpclient/TestData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import tbdex.sdk.protocol.models.Rfq
import tbdex.sdk.protocol.models.RfqData
import tbdex.sdk.protocol.models.SelectedPayinMethod
import tbdex.sdk.protocol.models.SelectedPayoutMethod
import tbdex.sdk.protocol.models.UnhashedRfqData
import tbdex.sdk.protocol.models.UnhashedSelectedPayinMethod
import tbdex.sdk.protocol.models.UnhashedSelectedPayoutMethod
import web5.sdk.credentials.VcDataModel
import web5.sdk.credentials.VerifiableCredential
import web5.sdk.credentials.model.ConstraintsV2
Expand Down Expand Up @@ -82,10 +85,10 @@ object TestData {
val rfq = Rfq.create(
to = to,
from = ALICE_DID.uri,
rfqData = RfqData(
unhashedRfqData = UnhashedRfqData(
offeringId = offeringId,
payin = SelectedPayinMethod("BTC_ADDRESS", mapOf("address" to 123456), amount = "10.00"),
payout = SelectedPayoutMethod("MOMO", mapOf("phone_number" to 123456)),
payin = UnhashedSelectedPayinMethod("BTC_ADDRESS", mapOf("address" to 123456), amount = "10.00"),
payout = UnhashedSelectedPayoutMethod("MOMO", mapOf("phone_number" to 123456)),
claims = claims
)
)
Expand Down
9 changes: 6 additions & 3 deletions httpserver/src/test/kotlin/TestData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ import tbdex.sdk.protocol.models.Rfq
import tbdex.sdk.protocol.models.RfqData
import tbdex.sdk.protocol.models.SelectedPayinMethod
import tbdex.sdk.protocol.models.SelectedPayoutMethod
import tbdex.sdk.protocol.models.UnhashedRfqData
import tbdex.sdk.protocol.models.UnhashedSelectedPayinMethod
import tbdex.sdk.protocol.models.UnhashedSelectedPayoutMethod
import web5.sdk.crypto.InMemoryKeyManager
import web5.sdk.dids.methods.dht.DidDht
import java.time.OffsetDateTime
Expand All @@ -26,14 +29,14 @@ object TestData {
return Rfq.create(
to = pfiDid.uri,
from = aliceDid.uri,
rfqData = RfqData(
unhashedRfqData = UnhashedRfqData(
offeringId = offering?.metadata?.id ?: TypeId.generate("offering").toString(),
payin = SelectedPayinMethod(
payin = UnhashedSelectedPayinMethod(
kind = offering?.data?.payin?.methods?.first()?.kind ?: "DEBIT_CARD",
paymentDetails = mapOf("foo" to "bar"),
amount = "1.00"
),
payout = SelectedPayoutMethod(
payout = UnhashedSelectedPayoutMethod(
kind = offering?.data?.payout?.methods?.first()?.kind ?: "BTC_ADDRESS",
paymentDetails = mapOf("foo" to "bar")
),
Expand Down
100 changes: 88 additions & 12 deletions protocol/src/main/kotlin/tbdex/sdk/protocol/models/MessageData.kt
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,56 @@ sealed interface MessageData : Data
* @property offeringId Offering which Alice would like to get a quote for
* @property payin selected payin amount, method, and details
* @property payout selected payout method, and details
* @property claims an array of claims that fulfill the requirements declared in the referenced Offering
* @property claimsHash hash of claims that fulfill the requirements declared in the referenced Offering
*/
class RfqData(
val offeringId: String,
val payin: SelectedPayinMethod,
val payout: SelectedPayoutMethod,
val claims: List<String>
val claimsHash: String? = null
) : MessageData

/**
* Private data contained in a RFQ message, including data which will be placed in {@link RfqPrivateData}
*
* @property salt Randomly generated cryptographic salt used to hash privateData fields
* @property payin A container for the unhashed `payin.paymentDetails`
* @property payout A container for the unhashed `payout.paymentDetails`
* @property claims claims that fulfill the requirements declared in an Offering
*/
class RfqPrivateData(
val salt: String,
val payin: PrivatePaymentDetails? = null,
val payout: PrivatePaymentDetails? = null,
val claims: List<String>? = null
)

/**
* Data contained in a RFQ message, including data which will be placed in Rfq.privateDAta.
* Used for creating an RFQ.
*
* @property offeringId Offering which Alice would like to get a quote for
* @property payin selected payin amount, method, and unhashed payment details
* @property payout selected payout method, and unhashed payment details
* @property claims an array of hashes claims that fulfill the requirements declared in the referenced Offering
*/
class UnhashedRfqData(
val offeringId: String,
val payin: UnhashedSelectedPayinMethod,
val payout: UnhashedSelectedPayoutMethod,
val claims: List<String>
)

/**
* A container for the unhashed `paymentDetails`
*
* @property paymentDetails An object containing the properties defined in the
* respective Offering's requiredPaymentDetails json schema.
*/
class PrivatePaymentDetails(
val paymentDetails: Map<String, Any>? = null
)

/**
* A data class representing the payment method selected.
*
Expand All @@ -33,35 +74,70 @@ class RfqData(
*/
sealed class SelectedPaymentMethod(
val kind: String,
val paymentDetails: Map<String, Any>? = null
val paymentDetailsHash: String? = null
) : MessageData

/**
* A data class representing the payin method selected.
*
* @property kind type of payin method
* A data class representing the payment method selected, including the unhashed payment details.
* Used for creating an RFQ.
* @property kind type of payment method
* @property paymentDetails An object containing the properties
* defined in an Offering's requiredPaymentDetails json schema
*/
sealed class UnhashedSelectedPaymentMethod(
val kind: String,
val paymentDetails: Map<String, Any>? = null
)

/**
* A data class representing the payin method selected.
*
* @property kind type of payment method
* @property paymentDetailsHash A hash of the object containing the properties
* defined in an Offering's requiredPaymentDetails json schema
* @property amount Amount of currency Alice wants to pay in exchange for payout currency
*/
class SelectedPayinMethod(
kind: String,
paymentDetails: Map<String, Any>? = null,
paymentDetailsHash: String? = null,
val amount: String
) : SelectedPaymentMethod(kind, paymentDetails)
) : SelectedPaymentMethod(kind, paymentDetailsHash)

/**
* A data class representing the payin method selected, including the unhashed payin details.
* @property kind type of payment method
* @property paymentDetails An object containing the properties
* defined in an Offering's requiredPaymentDetails json schema
* @property amount Amount of currency Alice wants to pay in exchange for payout currency
*/
class UnhashedSelectedPayinMethod(
kind: String,
paymentDetails: Map<String, Any>? = null,
val amount: String
) : UnhashedSelectedPaymentMethod(kind, paymentDetails)

/**
* A data class representing the payout method selected.
*
* @property kind type of payout method
* @property paymentDetails An object containing the properties
* @property kind type of payment method
* @property paymentDetailsHash A hash of the object containing the properties
* defined in an Offering's requiredPaymentDetails json schema
*/
class SelectedPayoutMethod(
kind: String,
paymentDetails: Map<String, Any>? = null
) : SelectedPaymentMethod(kind, paymentDetails)
paymentDetailsHash: String? = null
) : SelectedPaymentMethod(kind, paymentDetailsHash)

/**
* A data class representing the payin method selected, including the unhashed payout details.
* @property kind type of payment method
* @property paymentDetails An object containing the properties
* defined in an Offering's requiredPaymentDetails json schema
*/
class UnhashedSelectedPayoutMethod(
kind: String,
paymentDetails: Map<String, Any>? = null,
) : UnhashedSelectedPaymentMethod(kind, paymentDetails)

/**
* A data class implementing [MessageData] that represents the contents of a [Quote].
Expand Down
Loading

0 comments on commit 428c714

Please sign in to comment.