-
Notifications
You must be signed in to change notification settings - Fork 23
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
feat(mercury) : Added challenge domain and presentation definition #322
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...f/src/main/scala/io/iohk/atala/mercury/protocol/presentproof/PresentationAttachment.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package io.iohk.atala.mercury.protocol.presentproof | ||
|
||
import io.circe._ | ||
import io.circe.generic.semiauto._ | ||
import io.circe.syntax._ | ||
|
||
case class Field( | ||
id: Option[String] = None, | ||
path: Seq[String] = Seq.empty, | ||
name: Option[String] = None, | ||
purpose: Option[String] = None, | ||
) | ||
object Field { | ||
given Encoder[Field] = deriveEncoder[Field] | ||
given Decoder[Field] = deriveDecoder[Field] | ||
} | ||
|
||
case class Jwt(alg: Seq[String], proof_type: Seq[String]) | ||
object Jwt { | ||
given Encoder[Jwt] = deriveEncoder[Jwt] | ||
given Decoder[Jwt] = deriveDecoder[Jwt] | ||
} | ||
case class ClaimFormat(jwt: Jwt) | ||
object ClaimFormat { | ||
given Encoder[ClaimFormat] = deriveEncoder[ClaimFormat] | ||
given Decoder[ClaimFormat] = deriveDecoder[ClaimFormat] | ||
} | ||
case class Constraints(fields: Option[Seq[Field]]) | ||
object Constraints { | ||
given Encoder[Constraints] = deriveEncoder[Constraints] | ||
given Decoder[Constraints] = deriveDecoder[Constraints] | ||
} | ||
|
||
/** Refer to <a href="https://identity.foundation/presentation-exchange/#input-descriptor">Input Descriptors</a> | ||
*/ | ||
case class InputDescriptor( | ||
id: String = java.util.UUID.randomUUID.toString(), | ||
name: Option[String] = None, | ||
purpose: Option[String] = None, | ||
format: Option[ClaimFormat] = None, | ||
constraints: Constraints | ||
) | ||
object InputDescriptor { | ||
given Encoder[InputDescriptor] = deriveEncoder[InputDescriptor] | ||
given Decoder[InputDescriptor] = deriveDecoder[InputDescriptor] | ||
} | ||
|
||
/** Refer to <a href="https://identity.foundation/presentation-exchange/#presentation-definition">Presentation | ||
* Definition</a> | ||
*/ | ||
case class PresentationDefinition( | ||
id: String = java.util.UUID.randomUUID.toString(), // UUID | ||
input_descriptors: Seq[InputDescriptor] = Seq.empty, | ||
name: Option[String] = None, | ||
purpose: Option[String] = None, | ||
format: Option[ClaimFormat] = None, | ||
) | ||
object PresentationDefinition { | ||
given Encoder[PresentationDefinition] = deriveEncoder[PresentationDefinition] | ||
given Decoder[PresentationDefinition] = deriveDecoder[PresentationDefinition] | ||
} | ||
|
||
case class Options(challenge: String, domain: String) | ||
object Options { | ||
given Encoder[Options] = deriveEncoder[Options] | ||
given Decoder[Options] = deriveDecoder[Options] | ||
} | ||
|
||
case class PresentationAttachment(options: Option[Options] = None, presentation_definition: PresentationDefinition) | ||
object PresentationAttachment { | ||
given Encoder[PresentationAttachment] = deriveEncoder[PresentationAttachment] | ||
given Decoder[PresentationAttachment] = deriveDecoder[PresentationAttachment] | ||
|
||
def build(options: Option[Options] = None): PresentationAttachment = { | ||
val presentationDefinition = | ||
PresentationDefinition(input_descriptors = Seq.empty) | ||
PresentationAttachment(options, presentationDefinition) | ||
} | ||
} |
141 changes: 141 additions & 0 deletions
141
...c/test/scala/io/iohk/atala/mercury/protocol/presentproof/PresentationAttachmentSpec.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package io.iohk.atala.mercury.protocol.presentproof | ||
|
||
import cats.implicits.* | ||
import io.circe.Json | ||
import io.circe.parser.* | ||
import io.circe.syntax.* | ||
import io.iohk.atala.mercury.model.AttachmentDescriptor.attachmentDescriptorEncoderV2 | ||
import io.iohk.atala.mercury.model.{AttachmentDescriptor, DidId} | ||
import munit.* | ||
import zio.* | ||
import io.iohk.atala.mercury.model._ | ||
|
||
class PresentationAttachmentSpec extends ZSuite { | ||
|
||
test("Verifier Request Presentation Attachment") { | ||
val expectedConstraintJson = parse(s""" | ||
{ | ||
"fields": [ | ||
{ | ||
"path": [ | ||
"credentialSubject.dateOfBirth", | ||
"credentialSubject.dob", | ||
"vc.credentialSubject.dateOfBirth", | ||
"vc.credentialSubject.dob" | ||
] | ||
} | ||
] | ||
} | ||
""".stripMargin).getOrElse(Json.Null) | ||
val field = Field( | ||
None, | ||
path = Seq( | ||
"credentialSubject.dateOfBirth", | ||
"credentialSubject.dob", | ||
"vc.credentialSubject.dateOfBirth", | ||
"vc.credentialSubject.dob" | ||
) | ||
) | ||
val constraints = Constraints(fields = Some(Seq(field))) | ||
val result = constraints.asJson.deepDropNullValues | ||
assertEquals(result, expectedConstraintJson) | ||
|
||
val expectedInputDescriptorJson = parse(s""" | ||
{ | ||
"id": "wa_driver_license", | ||
"name": "Washington State Business License", | ||
"purpose": "We can only allow licensed Washington State business representatives into the WA Business Conference", | ||
"constraints": { | ||
"fields": [ | ||
{ | ||
"path": [ | ||
"credentialSubject.dateOfBirth", | ||
"credentialSubject.dob", | ||
"vc.credentialSubject.dateOfBirth", | ||
"vc.credentialSubject.dob" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
""".stripMargin).getOrElse(Json.Null) | ||
|
||
val inputDescriptor = InputDescriptor( | ||
id = "wa_driver_license", | ||
name = Some("Washington State Business License"), | ||
purpose = | ||
Some("We can only allow licensed Washington State business representatives into the WA Business Conference"), | ||
constraints = constraints | ||
) | ||
val resultInputDescriptor = inputDescriptor.asJson.deepDropNullValues | ||
assertEquals(resultInputDescriptor, expectedInputDescriptorJson) | ||
|
||
val expectedPresentationDefinitionJson = parse(s""" | ||
{ | ||
"id": "32f54163-7166-48f1-93d8-ff217bdb0653", | ||
"input_descriptors": [ | ||
{ | ||
"id": "wa_driver_license", | ||
"name": "Washington State Business License", | ||
"purpose": "We can only allow licensed Washington State business representatives into the WA Business Conference", | ||
"constraints": { | ||
"fields": [ | ||
{ | ||
"path": [ | ||
"credentialSubject.dateOfBirth", | ||
"credentialSubject.dob", | ||
"vc.credentialSubject.dateOfBirth", | ||
"vc.credentialSubject.dob" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
""".stripMargin).getOrElse(Json.Null) | ||
|
||
val presentationDefinition = | ||
PresentationDefinition(id = "32f54163-7166-48f1-93d8-ff217bdb0653", input_descriptors = Seq(inputDescriptor)) | ||
val resultPresentationDefinition = presentationDefinition.asJson.deepDropNullValues | ||
assertEquals(resultPresentationDefinition, expectedPresentationDefinitionJson) | ||
|
||
val expectedPresentationAttachmentJson = parse(s""" | ||
{ | ||
"options": { | ||
"challenge": "23516943-1d79-4ebd-8981-623f036365ef", | ||
"domain": "us.gov/DriversLicense" | ||
}, | ||
"presentation_definition": { | ||
"id": "32f54163-7166-48f1-93d8-ff217bdb0653", | ||
"input_descriptors": [ | ||
{ | ||
"id": "wa_driver_license", | ||
"name": "Washington State Business License", | ||
"purpose": "We can only allow licensed Washington State business representatives into the WA Business Conference", | ||
"constraints": { | ||
"fields": [ | ||
{ | ||
"path": [ | ||
"credentialSubject.dateOfBirth", | ||
"credentialSubject.dob", | ||
"vc.credentialSubject.dateOfBirth", | ||
"vc.credentialSubject.dob" | ||
] | ||
} | ||
] | ||
} | ||
} | ||
] | ||
} | ||
} | ||
""".stripMargin).getOrElse(Json.Null) | ||
val options = Options(challenge = "23516943-1d79-4ebd-8981-623f036365ef", domain = "us.gov/DriversLicense") | ||
val presentationAttachment = | ||
PresentationAttachment(presentation_definition = presentationDefinition, options = Some(options)) | ||
val resultPresentationAttachment = presentationAttachment.asJson.deepDropNullValues | ||
println(resultPresentationAttachment) | ||
assertEquals(resultPresentationAttachment, expectedPresentationAttachmentJson) | ||
|
||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this method returns a ZIO
We have to change a lot of code, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes it will be more refactoring required