generated from TBD54566975/tbd-project-template
-
Notifications
You must be signed in to change notification settings - Fork 17
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
Add Presentation Definition Object #249
Merged
Merged
Changes from all commits
Commits
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
49 changes: 49 additions & 0 deletions
49
bound/kt/src/main/kotlin/web5/sdk/vc/pex/PresentationDefinition.kt
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,49 @@ | ||
package web5.sdk.vc.pex | ||
|
||
import web5.sdk.rust.ConstraintsData as RustCoreConstraintsData | ||
import web5.sdk.rust.FieldData as RustCoreFieldData | ||
import web5.sdk.rust.FilterData as RustCoreFilterData | ||
import web5.sdk.rust.Optionality as RustCoreOptionality | ||
import web5.sdk.rust.InputDescriptorData as RustCoreInputDescriptorData | ||
|
||
import web5.sdk.rust.PresentationDefinition as RustCorePresentationDefinition | ||
import web5.sdk.rust.PresentationDefinitionData as RustCorePresentationDefinitionData | ||
|
||
typealias ConstraintsData = RustCoreConstraintsData | ||
typealias FieldData = RustCoreFieldData | ||
typealias FilterData = RustCoreFilterData | ||
typealias Optionality = RustCoreOptionality | ||
typealias InputDescriptor = RustCoreInputDescriptorData | ||
|
||
class PresentationDefinition { | ||
val id: String | ||
val name: String? | ||
val purpose: String? | ||
val inputDescriptors: List<InputDescriptor> | ||
|
||
internal val rustCorePresentationDefinition: RustCorePresentationDefinition | ||
|
||
constructor(id: String, name: String? = null, purpose: String? = null, inputDescriptors: List<InputDescriptor>) { | ||
this.id = id | ||
this.name = name | ||
this.purpose = purpose | ||
this.inputDescriptors = inputDescriptors | ||
|
||
this.rustCorePresentationDefinition = RustCorePresentationDefinition( | ||
RustCorePresentationDefinitionData(id, name, purpose, inputDescriptors) | ||
) | ||
} | ||
|
||
constructor(rustCorePresentationDefinitionData: RustCorePresentationDefinitionData) { | ||
this.id = rustCorePresentationDefinitionData.id | ||
this.name = rustCorePresentationDefinitionData.name | ||
this.purpose = rustCorePresentationDefinitionData.purpose | ||
this.inputDescriptors = rustCorePresentationDefinitionData.inputDescriptors | ||
|
||
this.rustCorePresentationDefinition = RustCorePresentationDefinition(rustCorePresentationDefinitionData) | ||
} | ||
|
||
fun selectCredentials(vcJwts: List<String>): List<String> { | ||
return this.rustCorePresentationDefinition.selectCredentials(vcJwts) | ||
} | ||
} |
68 changes: 68 additions & 0 deletions
68
bound/kt/src/test/kotlin/web5/sdk/vcs/pex/PresentationDefinitionTest.kt
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,68 @@ | ||
package web5.sdk.vcs.pex | ||
|
||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.Assertions.assertFalse | ||
import org.junit.jupiter.api.Assertions.assertNotNull | ||
import org.junit.jupiter.api.Assertions.assertNull | ||
import org.junit.jupiter.api.Test | ||
import web5.sdk.vc.pex.* | ||
|
||
class PresentationDefinitionTest { | ||
|
||
@Test | ||
fun `test basic presentation definition`() { | ||
val inputDescriptor = InputDescriptor( | ||
id = "test_input", | ||
name = "Test Input", | ||
purpose = "For testing", | ||
constraints = ConstraintsData( | ||
fields = listOf( | ||
FieldData( | ||
id = "field1", | ||
name = "Field 1", | ||
path = listOf("$.field1"), | ||
purpose = "Test field", | ||
filter = FilterData( | ||
type = "string", | ||
pattern = "^[a-zA-Z]+$", | ||
constValue = null | ||
), | ||
optional = false, | ||
predicate = Optionality.REQUIRED | ||
) | ||
) | ||
) | ||
) | ||
|
||
val presentationDefinition = PresentationDefinition( | ||
id = "test_presentation", | ||
name = "Test Presentation", | ||
purpose = "For testing purposes", | ||
inputDescriptors = listOf(inputDescriptor) | ||
) | ||
|
||
assertEquals("test_presentation", presentationDefinition.id) | ||
assertEquals("Test Presentation", presentationDefinition.name) | ||
assertEquals("For testing purposes", presentationDefinition.purpose) | ||
assertEquals(1, presentationDefinition.inputDescriptors.size) | ||
|
||
val firstInputDescriptor = presentationDefinition.inputDescriptors[0] | ||
assertEquals("test_input", firstInputDescriptor.id) | ||
assertEquals("Test Input", firstInputDescriptor.name) | ||
assertEquals("For testing", firstInputDescriptor.purpose) | ||
|
||
val field = firstInputDescriptor.constraints.fields[0] | ||
assertEquals("field1", field.id) | ||
assertEquals("Field 1", field.name) | ||
assertEquals(listOf("$.field1"), field.path) | ||
assertEquals("Test field", field.purpose) | ||
assertFalse(field.optional ?: true) | ||
assertEquals(Optionality.REQUIRED, field.predicate) | ||
|
||
val filter = field.filter | ||
assertNotNull(filter) | ||
assertEquals("string", filter?.type) | ||
assertEquals("^[a-zA-Z]+$", filter?.pattern) | ||
assertNull(filter?.constValue) | ||
} | ||
} |
Oops, something went wrong.
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.
nice!
internal