From 6d8a415a19c062e4840ea8a232d95150851b36eb Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Tue, 13 Feb 2024 13:12:10 -0500 Subject: [PATCH 1/5] added validate submission and vp --- .../presentation-exchange.mdx | 43 ++++++++++---- .../PresentationExchangeTest.kt | 57 +++++++++---------- 2 files changed, 60 insertions(+), 40 deletions(-) diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index e4e151275..f9be47a39 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -18,6 +18,8 @@ import satisfiesPresentationDefinitionForPexKt from '!!raw-loader!@site/snippets import selectCredentialsForPexKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/selectCredentialsForPexKt.snippet.kt' import createPresentationFromCredentialsForPexKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/createPresentationFromCredentialsForPexKt.snippet.kt' import validVerifiablePresentationForPexKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/validVerifiablePresentationForPexKt.snippet.kt' +import validatePresentationSubmissionForPexKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/validatePresentationSubmissionForPexKt.snippet.kt' +import signVpForPexKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/signVpForPexKt.snippet.kt' @@ -71,6 +73,7 @@ import { PresentationExchange } from '@web5/credentials'; code: ` import web5.sdk.credentials.PresentationExchange import web5.sdk.credentials.VerifiablePresentation +import web5.sdk.credentials.model.PresentationSubmission import web5.sdk.credentials.model.* `, language: 'Kotlin', @@ -215,20 +218,31 @@ Before submitting the presentation to a lender, you can validate the Presentatio + +:::note +The information regarding `Checked` objects is only applicable to the JavaScript SDK. +::: + +This method checks the presentation submission for any errors, returns an array of `Checked` objects representing the validation checks performed on the presentation submission: + + -This method checks the presentation submission for any errors, returns an array of `Checked` objects representing the validation checks performed on the presentation submission: - -```js -[ Checked { tag: 'root', status: 'info', message: 'ok' } ] -``` Each `Checked` object contains: @@ -236,14 +250,21 @@ Each `Checked` object contains: - **status**: the result of the check, which is `info` for successful checks or `error` for failed checks - **message**: shows `ok` if successful, and if unsuccessful this is where you'll find error messages -## Verifiable Presentation - +## Verifiable Presentation + + diff --git a/site/testsuites/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/PresentationExchangeTest.kt b/site/testsuites/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/PresentationExchangeTest.kt index f75804024..697e6f91c 100644 --- a/site/testsuites/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/PresentationExchangeTest.kt +++ b/site/testsuites/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/PresentationExchangeTest.kt @@ -1,11 +1,13 @@ -package website.tbd.developer.site.docs.web5.build.decentralizedidentifiers; +package website.tbd.developer.site.docs.web5.build.verifiablecredentials; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Assertions.* import web5.sdk.crypto.InMemoryKeyManager +import web5.sdk.dids.methods.dht.DidDht import web5.sdk.credentials.PresentationExchange import web5.sdk.credentials.VerifiableCredential import web5.sdk.credentials.VerifiablePresentation +import web5.sdk.credentials.model.PresentationSubmission import web5.sdk.credentials.model.* /** @@ -121,47 +123,44 @@ internal class PresentationExchangeTest { // :snippet-end: } } - - @Test - fun `createPresentationFromCredentialsForPexKt creates a presentation result`() { - val holderDid = "did:key:zQ3shXrAnbgfytQYQjifUm2EcBBbRAeAeGfgC4TZrjw4X71iZ" - val selectedCredentials = allCredentials - // :snippet-start: createPresentationFromCredentialsForPexKt - val presentationResult = PresentationExchange.createPresentationFromCredentials( - vcJwts = selectedCredentials, - presentationDefinition = presentationDefinition - ) - - val verifiablePresentation = VerifiablePresentation.create( - vcJwts = selectedCredentials, - holder = holderDid, - additionalData = mapOf("presentation_submission" to presentationResult) - ) - // :snippet-end: - assertNotNull(verifiablePresentation, "Verifiable Presentation should not be null") - assertEquals(holderDid, verifiablePresentation.holder, "Holder DID should match") - } @Test - fun `validVerifiablePresentationForPexKt creates a valid VP`() { - val holderDid = "did:key:zQ3shXrAnbgfytQYQjifUm2EcBBbRAeAeGfgC4TZrjw4X71iZ" + fun `createPresentationForPexKt creates a presentation result, a valid VP, and validates submission`() { + val holderDid = DidDht.create(InMemoryKeyManager()) val selectedCredentials = allCredentials + // :snippet-start: createPresentationFromCredentialsForPexKt val presentationResult = PresentationExchange.createPresentationFromCredentials( vcJwts = selectedCredentials, presentationDefinition = presentationDefinition ) + val verifiablePresentation = VerifiablePresentation.create( vcJwts = selectedCredentials, - holder = holderDid, + holder = holderDid.uri, additionalData = mapOf("presentation_submission" to presentationResult) ) - // :snippet-start: validVerifiablePresentationForPexKt - val verifiablePresentationDataModelMap = verifiablePresentation.vpDataModel.toMap() - val mappedPresentationSubmission = verifiablePresentationDataModelMap["presentation_submission"] as? PresentationSubmission + // :snippet-end: + assertDoesNotThrow { + // :snippet-start: validatePresentationSubmissionForPexKt + val vpDataMap = verifiablePresentation.vpDataModel.toMap() + val presentationSubmission = vpDataMap["presentation_submission"] as PresentationSubmission + + try { + PresentationExchange.validateSubmission(presentationSubmission) + } catch (e: Exception) { + println("Invalid Presentation Submission: ${e.message}") + } + // :snippet-end: + } + + // :snippet-start: signVpForPexKt + val vpJwt = verifiablePresentation.sign(holderDid) // :snippet-end: - assertNotNull(mappedPresentationSubmission, "Mapped Presentation Submission should not be null") - assertEquals(presentationResult.definitionId, mappedPresentationSubmission?.definitionId, "Definition ID should match") + assertNotNull(verifiablePresentation, "Verifiable Presentation should not be null") + assertEquals(holderDid.uri, verifiablePresentation.holder, "Holder DID should match") + assertNotNull(vpJwt, "Verifiable Presentation JWT should not be null") + assertTrue(vpJwt is String, "Verifiable Presentation JWT should be a string") } } From c13e1bf854b4106c789641935419b4d2b91a12e8 Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Tue, 13 Feb 2024 14:34:38 -0500 Subject: [PATCH 2/5] more clarity on why a vp is created --- .../presentation-exchange.mdx | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index f9be47a39..4f927c552 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -113,8 +113,14 @@ Once you've confirmed that the VCs successfully satisfy the Presentation Definit @@ -226,18 +232,21 @@ snippets={[ The information regarding `Checked` objects is only applicable to the JavaScript SDK. ::: -This method checks the presentation submission for any errors, returns an array of `Checked` objects representing the validation checks performed on the presentation submission: Date: Tue, 13 Feb 2024 14:37:43 -0500 Subject: [PATCH 3/5] clarity on language --- .../build/verifiable-credentials/presentation-exchange.mdx | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index 4f927c552..3d3eb58fc 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -269,11 +269,8 @@ Each `Checked` object contains: snippetContent: validVerifiablePresentationForPex, language: 'JavaScript'}, { - content: 'After creating and validating the [Presentation](/docs/glossary#verifiable-presentation), you can submit a signed [Verifiable Presentation](/docs/glossary#verifiable-presentation) encoded as a JWT, so the lender can [verify](/docs/web5/build/verifiable-credentials/verify-vc#verify-verifiable-presentations) it. To submit a signed Verifiable Presentation, the Holder signs it with their DID:', + content: 'Once the [Presentation](/docs/glossary#verifiable-presentation) is error-free and has passed the validation checks, you can submit the Verifiable Presentation as a signed and encoded JWT to the lender for [verification](/docs/web5/build/verifiable-credentials/verify-vc#verify-verifiable-presentations).', snippetContent: signVpForPexKt, language: 'Kotlin'}, ]} -/> - - - +/> \ No newline at end of file From 1f8df1998653141a5204be2ab0a5aa5da84163d2 Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Tue, 13 Feb 2024 15:22:51 -0500 Subject: [PATCH 4/5] unnecessary import --- .../web5/build/verifiable-credentials/presentation-exchange.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index 3d3eb58fc..5b51bb077 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -17,7 +17,6 @@ import getLoanAppPresentationDefinitionKt from '!!raw-loader!@site/snippets/test import satisfiesPresentationDefinitionForPexKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/satisfiesPresentationDefinitionForPexKt.snippet.kt' import selectCredentialsForPexKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/selectCredentialsForPexKt.snippet.kt' import createPresentationFromCredentialsForPexKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/createPresentationFromCredentialsForPexKt.snippet.kt' -import validVerifiablePresentationForPexKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/validVerifiablePresentationForPexKt.snippet.kt' import validatePresentationSubmissionForPexKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/validatePresentationSubmissionForPexKt.snippet.kt' import signVpForPexKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/signVpForPexKt.snippet.kt' From a93a2debeeb399cc3aeaf317567b90845596bc94 Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Tue, 13 Feb 2024 19:00:21 -0500 Subject: [PATCH 5/5] Update site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx Co-authored-by: Angie Jones --- .../web5/build/verifiable-credentials/presentation-exchange.mdx | 1 - 1 file changed, 1 deletion(-) diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index 5b51bb077..3a42d3830 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -117,7 +117,6 @@ Once you've confirmed that the VCs successfully satisfy the Presentation Definit language: 'JavaScript' }, { - content: 'Bundle your VCs into one presentation by converting your presentation result into a [Verifiable Presentation](/docs/glossary#verifiable-presentation) with the `VerifiablePresentation.create()` method. In this case, the holder is the entity presenting the VP to the lender.', snippetContent: createPresentationFromCredentialsForPexKt, language: 'Kotlin'}, ]}