Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hash Rfq privateData #222

Merged
merged 16 commits into from
Apr 1, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -17,6 +17,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 @@ -94,10 +97,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
1 change: 0 additions & 1 deletion httpserver/src/test/kotlin/ServerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ open class ServerTest {
val serverConfig = TbdexHttpServerConfig(
port = 8080,
pfiDid = TestData.pfiDid.uri,
balancesEnabled = true
diehuxx marked this conversation as resolved.
Show resolved Hide resolved
)
val tbdexServer = TbdexHttpServer(serverConfig)
tbdexServer.configure(this)
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
jiyoontbd marked this conversation as resolved.
Show resolved Hide resolved
* @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>
var 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
jiyoontbd marked this conversation as resolved.
Show resolved Hide resolved
)

/**
* 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
var 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
Loading