From 9ed6c3bba122fdd9ff27184ccf8098e38410354c Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Mon, 5 Feb 2024 06:53:12 -0500 Subject: [PATCH 01/17] kotlin shnips --- .../presentation-exchange.mdx | 104 ++++++++- .../presentation-exchange.test.js | 201 +++++++++++++++--- site/testsuites/testsuite-kotlin/pom.xml | 10 + .../PresentationExchangeTest.kt | 159 ++++++++++++++ 4 files changed, 435 insertions(+), 39 deletions(-) create mode 100644 site/testsuites/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/PresentationExchangeTest.kt diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index e1462bc8b..8141cac3f 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -2,9 +2,24 @@ sidebar_position: 3 --- + + import CodeSnippet from '@site/src/components/CodeSnippet'; +import requiredImportsForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/requiredImportsForPex.snippet.js' +import getLoanAppPresentationDefinition from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/getLoanAppPresentationDefinition.snippet.js' +import satisfiesPresentationDefinitionForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/satisfiesPresentationDefinitionForPex.snippet.js' +import selectCredentialsForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/selectCredentialsForPex.snippet.js' +import createPresentationFromCredentialsForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/createPresentationFromCredentialsForPex.snippet.js' + +import requiredImportsForPexKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/requiredImportsForPexKt.snippet.kt' +import getLoanAppPresentationDefinitionKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/getLoanAppPresentationDefinitionKt.snippet.kt' +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' + # Presentation Exchange + In this guide, we'll cover the process of presenting [Verifiable Credentials (VCs)](/docs/web5/learn/verifiable-credentials) to a verifier. This process is known as a **Presentation Exchange (PEX)** and involves selecting credentials that satisfy a Presentation Definition, creating a presentation based on that definition, and submitting the presentation to a verifier. @@ -26,7 +41,12 @@ Assume a lender has an existing Presentation Definition specifying that applican
Presentation Definition - +
@@ -37,9 +57,12 @@ We'll use the Presentation Definition above to present credentials that meet its All methods needed to perform a PEX are in the `PresentationExchange` class. You can import this class from the `@web5/credentials` package: -```js -import { PresentationExchange } from '@web5/credentials'; -``` + ## Select Credentials @@ -47,13 +70,23 @@ A user may possess multiple credentials. To preserve the user's privacy, when creating a Presentation, you'll want to present only the VCs that match the Presentation Definition requirements. This is done with the `selectCredentials()` method: - + ## Satisfy Presentation Definition To ensure that the selected credentials collectively satisfy all of the Presentation Definition's requirements, call the `satisfiesPresentationDefinition()` method: - + This method will throw an error if all requirements of the Presentation Definition are not satisfied. @@ -62,10 +95,19 @@ This method will throw an error if all requirements of the Presentation Definiti Once you've confirmed that the VCs successfully satisfy the Presentation Definition, you can create a presentation using the `createPresentationFromCredentials()` method: + This method returns a `PresentationResult` which contains the presentation: -```js + + ## Validate Presentation Submission diff --git a/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js b/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js index 32ef2ba3a..125f7b50f 100644 --- a/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js +++ b/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js @@ -1,24 +1,156 @@ import { test, describe, expect } from 'vitest'; import { - pex_checkPresentationDefinitionSatisfaction, pex_createPresentationFromCredentials, pex_getLoanAppPresentationDefinition, pex_getPresentationFromResult, - pex_selectCredentials, pex_submissionCheck, } from '../../../../../../code-snippets/web5/build/verifiable-credentials/presentation-exchange'; +import { PresentationExchange } from '@web5/credentials'; -const signedEmploymentVcJwt = - 'eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCIsImtpZCI6ImRpZDprZXk6ejZNa2VyNDlDbnVnN2hzdkhEZ3Y0NHl2cGR2dE1oNHlMaURYeFM2N2huclVodHQyI3o2TWtlcjQ5Q251Zzdoc3ZIRGd2NDR5dnBkdnRNaDR5TGlEWHhTNjdobnJVaHR0MiJ9.eyJpc3MiOiJkaWQ6a2V5Ono2TWtlcjQ5Q251Zzdoc3ZIRGd2NDR5dnBkdnRNaDR5TGlEWHhTNjdobnJVaHR0MiIsInZjIjp7IkBjb250ZXh0IjpbImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL3YxIl0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiLCJFbXBsb3ltZW50Q3JlZGVudGlhbCJdLCJpZCI6InVybjp1dWlkOjcyNDhiOTkyLTkwOTYtNDk2NS1hMGVjLTc3ZDhhODNhMWRmYiIsImlzc3VlciI6ImRpZDprZXk6ejZNa2VyNDlDbnVnN2hzdkhEZ3Y0NHl2cGR2dE1oNHlMaURYeFM2N2huclVodHQyIiwiaXNzdWFuY2VEYXRlIjoiMjAyMy0xMi0yMVQyMDoxMToyNVoiLCJjcmVkZW50aWFsU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lrJeSBg'; -const credentials = [signedEmploymentVcJwt, signedNameAndDobVcJwt]; const pd = await pex_getLoanAppPresentationDefinition(); describe('Presentation Exchange Process', () => { - test('selectCredentials() selects VCs that match presentation defintion', async () => { - const selectedCredentials = await pex_selectCredentials(credentials, pd); + const signedEmploymentVcJwt = + 'eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCIsImtpZCI6ImRpZDprZXk6ejZNa2VyNDlDbnVnN2hzdkhEZ3Y0NHl2cGR2dE1oNHlMaURYeFM2N2huclVodHQyI3o2TWtlcjQ5Q251Zzdoc3ZIRGd2NDR5dnBkdnRNaDR5TGlEWHhTNjdobnJVaHR0MiJ9.eyJpc3MiOiJkaWQ6a2V5Ono2TWtlcjQ5Q251Zzdoc3ZIRGd2NDR5dnBkdnRNaDR5TGlEWHhTNjdobnJVaHR0MiIsInZjIjp7IkBjb250ZXh0IjpbImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWRlbnRpYWxzL3YxIl0sInR5cGUiOlsiVmVyaWZpYWJsZUNyZWRlbnRpYWwiLCJFbXBsb3ltZW50Q3JlZGVudGlhbCJdLCJpZCI6InVybjp1dWlkOjcyNDhiOTkyLTkwOTYtNDk2NS1hMGVjLTc3ZDhhODNhMWRmYiIsImlzc3VlciI6ImRpZDprZXk6ejZNa2VyNDlDbnVnN2hzdkhEZ3Y0NHl2cGR2dE1oNHlMaURYeFM2N2huclVodHQyIiwiaXNzdWFuY2VEYXRlIjoiMjAyMy0xMi0yMVQyMDoxMToyNVoiLCJjcmVkZW50aWFsU3ViamVjdCI6eyJpZCI6ImRpZDppb246RWlEMTR4UmY0cTJNWlh1ZWY2X2ZXYnBGbVlTUG94dGFxTkp1SmdEMG96Wl84UTpleUprWld4MFlTSTZleUp3WVhSamFHVnpJanBiZXlKaFkzUnBiMjRpT2lKeVpYQnNZV05sSWl3aVpHOWpkVzFsYm5RaU9uc2ljSFZpYkdsalMyVjVjeUk2VzNzaWFXUWlPaUprZDI0dGMybG5J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ltVnVZM0o1Y0hScGIyNUxaWGx6SWpwYklpTmtkMjR0Wlc1aklsMHNJbTV2WkdWeklqcGJJbWgwZEhCek9pOHZaSGR1TG5SaVpHUmxkaTV2Y21jdlpIZHVOaUlzSW1oMGRIQnpPaTh2WkhkdUxuUmlaR1JsZGk1dmNtY3ZaSGR1TUNKZExDSnphV2R1YVc1blMyVjVjeUk2V3lJalpIZHVMWE5wWnlKZGZTd2lkSGx3WlNJNklrUmxZMlZ1ZEhKaGJHbDZaV1JYWldKT2IyUmxJbjFkZlgxZExDSjFjR1JoZEdWRGIyMXRhWFJ0Wlc1MElqb2lSV2xCTXpSMlMzb3llVmswZVV4dGRDMUdabkJuYWpWbGFFRm1ZWFI1YzFOa2MwNVNWbVpMYkhwUWRqTjVkeUo5TENKemRXWm1hWGhFWVhSaElqcDdJbVJsYkhSaFNHRnphQ0k2SWtWcFF6ZGZjMXBzTW1wMVVXNUdhRVJIV1RSb2NFVTRiMlF4YVU5MWRuZG1PVFJ5TVVkbk9HMWFWbVJCVmxFaUxDSnlaV052ZG1WeWVVTnZiVzFwZEcxbGJuUWlPaUpGYVVKdU5sTnJiSEpWYzNKdVFuaFJPVXBqVXkxTlNVaGtWelYwTXpRM1MxWjNaMXBwVEZwMFQwcDRRVkYzSW4xOSIsIm5hbWUiOiJhbGljZSBib2IiLCJkYXRlT2ZCaXJ0aCI6IjEwLTAxLTE5OTAifX19.mNCDv_JntH-wZpYONKNL58UbOWaYXCYJO_HPI_WVlSgwzo6dhYmV_9qtpFKd_exFb-aaEYPeSE43twWlrJeSBg'; + const credentials = [signedEmploymentVcJwt, signedNameAndDobVcJwt]; + + + const presentationDefinition = { + id: 'presDefIdloanAppVerification123', + name: 'Loan Application Employment Verification', + purpose: 'To verify applicant’s employment, date of birth, and name', + input_descriptors: [ + // Employment Verification + { + id: 'employmentVerification', + purpose: 'Confirm current employment status', + constraints: { + fields: [ + { + path: ['$.credentialSubject.employmentStatus'], + filter: { + type: 'string', + pattern: 'employed', + }, + }, + ], + }, + }, + // Date of Birth Verification + { + id: 'dobVerification', + purpose: 'Confirm the applicant’s date of birth', + constraints: { + fields: [ + { + path: ['$.credentialSubject.dateOfBirth'], + filter: { + type: 'string', + format: 'date', + }, + }, + ], + }, + }, + // Name Verification + { + id: 'nameVerification', + purpose: 'Confirm the applicant’s legal name', + constraints: { + fields: [ + { + path: ['$.credentialSubject.name'], + filter: { + type: 'string' + } + } + ] + } + } + ] + }; + test('requiredImportsForPex shows required imports for PEX', async () => { + const requiredImportsForPex = ` + // :snippet-start: requiredImportsForPex + import { PresentationExchange } from '@web5/credentials'; + // :snippet-end: + ` + }); + + test('getLoanAppPresentationDefinition returns a presentation definition', async () => { + // :snippet-start: getLoanAppPresentationDefinition + const presentationDefinition = { + id: 'presDefIdloanAppVerification123', + name: 'Loan Application Employment Verification', + purpose: 'To verify applicant’s employment, date of birth, and name', + input_descriptors: [ + // Employment Verification + { + id: 'employmentVerification', + purpose: 'Confirm current employment status', + constraints: { + fields: [ + { + path: ['$.credentialSubject.employmentStatus'], + filter: { + type: 'string', + pattern: 'employed', + }, + }, + ], + }, + }, + // Date of Birth Verification + { + id: 'dobVerification', + purpose: 'Confirm the applicant’s date of birth', + constraints: { + fields: [ + { + path: ['$.credentialSubject.dateOfBirth'], + filter: { + type: 'string', + format: 'date', + }, + }, + ], + }, + }, + // Name Verification + { + id: 'nameVerification', + purpose: 'Confirm the applicant’s legal name', + constraints: { + fields: [ + { + path: ['$.credentialSubject.name'], + filter: { + type: 'string' + } + } + ] + } + } + ] + }; + // :snippet-end: + expect(presentationDefinition).toBeDefined(); + expect(presentationDefinition).toHaveProperty('input_descriptors'); + expect(presentationDefinition.input_descriptors).toBeInstanceOf(Array); + expect(presentationDefinition.input_descriptors.length).toBe(3); + }); + test('selectCredentialsForPex selects VCs that match presentation defintion', async () => { + const allCredentials = credentials + // :snippet-start: selectCredentialsForPex + const selectedCredentials = PresentationExchange.selectCredentials({ + vcJwts: allCredentials, + presentationDefinition: presentationDefinition + }); + // :snippet-end: + expect(selectedCredentials).toBeDefined(); expect(selectedCredentials).toBeInstanceOf(Array); expect.soft(selectedCredentials.length).toBe(2); @@ -26,31 +158,38 @@ describe('Presentation Exchange Process', () => { expect.soft(selectedCredentials).toContain(signedNameAndDobVcJwt); }); - test('satisfiesPresentationDefinition() checks if VCs satisfy PD', async () => { - const satisfied = await pex_checkPresentationDefinitionSatisfaction( - credentials, - pd, - ); - expect(satisfied).toBe(true); + test('satisfiesPresentationDefinitionForPex checks if VCs satisfy PD', async () => { + const selectedCredentials = credentials + expect(() => { + // :snippet-start: satisfiesPresentationDefinitionForPex + try { + PresentationExchange.satisfiesPresentationDefinition({ + vcJwts: selectedCredentials, + presentationDefinition: presentationDefinition + }); + } catch (err) { + //Handle errors here + + } + // :snippet-end: + }).not.toThrow(); }); - test('createPresentationFromCredentials() creates a presentation result', async () => { - const presentationResult = await pex_createPresentationFromCredentials( - credentials, - pd, - ); + test('createPresentationFromCredentialsForPex creates a presentation result', async () => { + const selectedCredentials = credentials + // :snippet-start: createPresentationFromCredentialsForPex + const presentationResult = PresentationExchange.createPresentationFromCredentials({ + vcJwts: selectedCredentials, + presentationDefinition: presentationDefinition + }); + // :snippet-end: expect(presentationResult).toBeDefined(); - expect.soft(presentationResult).toHaveProperty('presentation'); - expect - .soft(presentationResult.presentation) - .toHaveProperty('presentation_submission'); - expect - .soft(presentationResult.presentation) - .toHaveProperty('verifiableCredential'); - expect - .soft(presentationResult.presentation.type) - .toContain('VerifiablePresentation'); - }); + expect(presentationResult).toHaveProperty('presentation'); + expect(presentationResult.presentation).toHaveProperty('presentation_submission'); + expect(presentationResult.presentation).toHaveProperty('verifiableCredential'); + expect(presentationResult.presentation.type).toContain('VerifiablePresentation'); + } + ); test('validateSubmission() checks if the presentation submission is valid', async () => { const pr = await pex_createPresentationFromCredentials(credentials, pd); diff --git a/site/testsuites/testsuite-kotlin/pom.xml b/site/testsuites/testsuite-kotlin/pom.xml index 68aa13ac1..e050e9172 100644 --- a/site/testsuites/testsuite-kotlin/pom.xml +++ b/site/testsuites/testsuite-kotlin/pom.xml @@ -94,6 +94,16 @@ jackson-databind ${version.com.fasterxml.jackson.core} + + com.fasterxml.jackson.core + jackson-core + 2.12.1 + + + com.fasterxml.jackson.core + jackson-databind + 2.12.1 + 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 new file mode 100644 index 000000000..3f596af7e --- /dev/null +++ b/site/testsuites/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/PresentationExchangeTest.kt @@ -0,0 +1,159 @@ +package website.tbd.developer.site.docs.web5.build.decentralizedidentifiers; + +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.Assertions.* +import web5.sdk.crypto.InMemoryKeyManager +import web5.sdk.credentials.PresentationExchange +import web5.sdk.credentials.VerifiableCredential +import web5.sdk.credentials.VerifiablePresentation +import web5.sdk.credentials.model.ConstraintsV2 +import web5.sdk.credentials.model.FieldV2 +import web5.sdk.credentials.model.InputDescriptorV2 +import web5.sdk.credentials.model.PresentationDefinitionV2 + +/** + * Tests backing the Presentation Exchange Guide + */ +internal class PresentationExchangeTest { + val signedEmploymentVcJwt = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCIsImtpZCI6ImRpZDprZXk6ejZNa2VyNDlDbnVnN2hzdkhEZ3Y0NHl2cGR2dE1oNHlMaURYeFM2N2huclVodHQyI3o2TWtlcjQ5Q251Zzdoc3ZIRGd2NDR5dnBkdnRNaDR5TGlEWHhTNjdobnJVaHR0MiJ9.eyJpc3MiOiJkaWQ6a2V5Ono2TWtlcjQ5Q251Zzdoc3ZIRGd2NDR5dnBkdnRNaDR5TGlEWHhTNjdobnJVaHR0MiIsInZjIjp7IkBjb250ZXh0IjpbImh0dHBzOi8vd3d3LnczLm9yZy8yMDE4L2NyZWR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4YVU5MWRuZG1PVFJ5TVVkbk9HMWFWbVJCVmxFaUxDSnlaV052ZG1WeWVVTnZiVzFwZEcxbGJuUWlPaUpGYVVKdU5sTnJiSEpWYzNKdVFuaFJPVXBqVXkxTlNVaGtWelYwTXpRM1MxWjNaMXBwVEZwMFQwcDRRVkYzSW4xOSIsIm5hbWUiOiJhbGljZSBib2IiLCJkYXRlT2ZCaXJ0aCI6IjEwLTAxLTE5OTAifX19.mNCDv_JntH-wZpYONKNL58UbOWaYXCYJO_HPI_WVlSgwzo6dhYmV_9qtpFKd_exFb-aaEYPeSE43twWlrJeSBg" + val allCredentials = listOf(signedEmploymentVcJwt, signedNameAndDobVcJwt) + + val presentationDefinition = PresentationDefinitionV2( + id = "presDefIdloanAppVerification123", + name = "Loan Application Employment Verification", + purpose = "To verify applicant’s employment, date of birth, and name", + inputDescriptors = listOf( + // Employment Verification + InputDescriptorV2( + id = "employmentVerification", + purpose = "Confirm current employment status", + constraints = ConstraintsV2( + fields = listOf(FieldV2(path = listOf("$.vc.credentialSubject.employmentStatus"))) + ) + ), + // Date of Birth Verification + InputDescriptorV2( + id = "dobVerification", + purpose = "Confirm the applicant’s date of birth", + constraints = ConstraintsV2( + fields = listOf(FieldV2(path = listOf("$.vc.credentialSubject.dateOfBirth"))) + ) + ), + // Name Verification + InputDescriptorV2( + id = "nameVerification", + purpose = "Confirm the applicant’s legal name", + constraints = ConstraintsV2( + fields = listOf(FieldV2(path = listOf("$.vc.credentialSubject.name"))) + ) + ) + ) +) + + @Test + fun `requiredImportsForPexKt shows required imports for PEX`() { + val requiredImportsForPexKt = + """ + // :snippet-start: requiredImportsForPexKt + import web5.sdk.credentials.PresentationExchange + import web5.sdk.credentials.VerifiablePresentation + import web5.sdk.credentials.model.* + // :snippet-end: + """ + } + + @Test + fun `getLoanAppPresentationDefinitionKt `() { + // :snippet-start: getLoanAppPresentationDefinitionKt + val presentationDefinition = PresentationDefinitionV2( + id = "presDefIdloanAppVerification123", + name = "Loan Application Employment Verification", + purpose = "To verify applicant’s employment, date of birth, and name", + inputDescriptors = listOf( + // Employment Verification + InputDescriptorV2( + id = "employmentVerification", + purpose = "Confirm current employment status", + constraints = ConstraintsV2( + fields = listOf(FieldV2(path = listOf("$.vc.credentialSubject.employmentStatus"))) + ) + ), + // Date of Birth Verification + InputDescriptorV2( + id = "dobVerification", + purpose = "Confirm the applicant’s date of birth", + constraints = ConstraintsV2( + fields = listOf(FieldV2(path = listOf("$.vc.credentialSubject.dateOfBirth"))) + ) + ), + // Name Verification + InputDescriptorV2( + id = "nameVerification", + purpose = "Confirm the applicant’s legal name", + constraints = ConstraintsV2( + fields = listOf(FieldV2(path = listOf("$.vc.credentialSubject.name"))) + ) + ) + ) + ) + // :snippet-end: + + assertEquals("presDefIdloanAppVerification123", presentationDefinition.id) + assertEquals("Loan Application Employment Verification", presentationDefinition.name) + assertEquals("To verify applicant’s employment, date of birth, and name", presentationDefinition.purpose) + assertEquals(3, presentationDefinition.inputDescriptors.size) + } + + @Test + fun `selectCredentialsForPexKt selects VCs that match presentation defintion`() { + // :snippet-start: selectCredentialsForPexKt + val selectedCredentials = PresentationExchange.selectCredentials( + vcJwts = allCredentials, + presentationDefinition = presentationDefinition + ) + // :snippet-end: + assertNotNull(selectedCredentials, "Selected credentials should not be null") + assertTrue(selectedCredentials is List<*>, "Selected credentials should be a list") + assertEquals(2, selectedCredentials.size, "Selected credentials should contain 2 items") + assertTrue(signedEmploymentVcJwt in selectedCredentials, "Selected credentials should contain the employment VC JWT") + assertTrue(signedNameAndDobVcJwt in selectedCredentials, "Selected credentials should contain the name and DOB VC JWT") + } + + @Test + fun `satisfiesPresentationDefinitionForPexKt checks if VCs satisfy PD`() { + val selectedCredentials = allCredentials + assertDoesNotThrow { + // :snippet-start: satisfiesPresentationDefinitionForPex + try { + PresentationExchange.satisfiesPresentationDefinition( + vcJwts = selectedCredentials, + presentationDefinition = presentationDefinition + ) + } catch (e: Exception) { + // Handle errors here + } + // :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 vp = VerifiablePresentation.create( + vcJwts = selectedCredentials, + holder = holderDid, + additionalData = mapOf("presentation_submission" to presentationResult) + ) + // :snippet-end: + assertNotNull(vp, "Verifiable Presentation should not be null") + assertEquals(holderDid, vp.holder, "Holder DID should match") + } +} From 5fffd19b62188df69ff5543440e11a2cc639e003 Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Mon, 5 Feb 2024 09:08:17 -0500 Subject: [PATCH 02/17] adding new line --- .../web5/build/verifiable-credentials/presentation-exchange.mdx | 1 + 1 file changed, 1 insertion(+) diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index 8141cac3f..4980b41f3 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -19,6 +19,7 @@ import createPresentationFromCredentialsForPexKt from '!!raw-loader!@site/snippe # Presentation Exchange + In this guide, we'll cover the process of presenting [Verifiable Credentials (VCs)](/docs/web5/learn/verifiable-credentials) to a verifier. From 403beefded604e305ca12213db0592628ffbb7fe Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Mon, 5 Feb 2024 09:13:57 -0500 Subject: [PATCH 03/17] kotlin shnip wasnt generating --- .../build/verifiablecredentials/PresentationExchangeTest.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 3f596af7e..1c13f19f2 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 @@ -124,7 +124,7 @@ internal class PresentationExchangeTest { fun `satisfiesPresentationDefinitionForPexKt checks if VCs satisfy PD`() { val selectedCredentials = allCredentials assertDoesNotThrow { - // :snippet-start: satisfiesPresentationDefinitionForPex + // :snippet-start: satisfiesPresentationDefinitionForPexKt try { PresentationExchange.satisfiesPresentationDefinition( vcJwts = selectedCredentials, From 24572e2bc54634dc432784c5d89be37c118f4177 Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Mon, 5 Feb 2024 11:25:23 -0500 Subject: [PATCH 04/17] removing extra code snippet --- .../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 4980b41f3..de20aeb06 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -95,7 +95,6 @@ This method will throw an error if all requirements of the Presentation Definiti Once you've confirmed that the VCs successfully satisfy the Presentation Definition, you can create a presentation using the `createPresentationFromCredentials()` method: - Date: Mon, 5 Feb 2024 12:05:38 -0500 Subject: [PATCH 05/17] enabling switch content --- .../verifiable-credentials/presentation-exchange.mdx | 4 +++- site/src/components/language/Shnip.jsx | 12 +++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index de20aeb06..120f786b3 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -102,11 +102,12 @@ Once you've confirmed that the VCs successfully satisfy the Presentation Definit ]} /> -This method returns a `PresentationResult` which contains the presentation: + { // support line breaks for inline code snippets @@ -38,13 +39,10 @@ const Shnip = ({ snippets, inlineSnippets }) => { {inlineSnippets && inlineSnippets.map( - ({ code, language, codeLanguage, title, breakLineAt }) => ( -
- + ({ content, code, language, codeLanguage, breakLineAt }, index) => ( +
+ {content && {content}} + {addLineBreaks(code, breakLineAt)}
From b28b809f396be2bccd647895962649fe27348052 Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Mon, 5 Feb 2024 14:09:51 -0500 Subject: [PATCH 06/17] adding clarity for presentation submission with Kotlin --- .../presentation-exchange.mdx | 12 +++++++-- site/src/components/language/Shnip.jsx | 21 +++++++++------- .../presentation-exchange.test.js | 14 ++++++++--- .../PresentationExchangeTest.kt | 25 +++++++++++++++++++ 4 files changed, 58 insertions(+), 14 deletions(-) diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index 120f786b3..42277b824 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -10,12 +10,14 @@ import getLoanAppPresentationDefinition from '!!raw-loader!@site/snippets/testsu import satisfiesPresentationDefinitionForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/satisfiesPresentationDefinitionForPex.snippet.js' import selectCredentialsForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/selectCredentialsForPex.snippet.js' import createPresentationFromCredentialsForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/createPresentationFromCredentialsForPex.snippet.js' +import validVerifiablePresentationForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/validVerifiablePresentationForPex.snippet.js' import requiredImportsForPexKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/requiredImportsForPexKt.snippet.kt' import getLoanAppPresentationDefinitionKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/getLoanAppPresentationDefinitionKt.snippet.kt' 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' # Presentation Exchange @@ -215,6 +217,12 @@ Each `Checked` object contains: ## Verifiable Presentation -Once the [Presentation](/docs/glossary#verifiable-presentation) is error-free and has passed the validation checks, you can submit the Verifiable Presentation by providing the lender with the `presentation` JSON object: - + + + diff --git a/site/src/components/language/Shnip.jsx b/site/src/components/language/Shnip.jsx index 59c08e40d..158c031f6 100644 --- a/site/src/components/language/Shnip.jsx +++ b/site/src/components/language/Shnip.jsx @@ -27,15 +27,18 @@ const Shnip = ({ snippets, inlineSnippets }) => { {snippets && - snippets.map(({ snippetContent, language, title }) => ( -
- -
- ))} + snippets.map( + ({ snippetContent, language, title, content }, index) => ( +
+ {content && {content}} + +
+ ), + )} {inlineSnippets && inlineSnippets.map( diff --git a/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js b/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js index 125f7b50f..5cb9571e3 100644 --- a/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js +++ b/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js @@ -202,10 +202,18 @@ describe('Presentation Exchange Process', () => { expect.soft(validationResult[0]).toHaveProperty('message', 'ok'); }); - test('presentationResult.presentation is a valid VP', async () => { - const pr = await pex_createPresentationFromCredentials(credentials, pd); - const presentation = await pex_getPresentationFromResult(pr); + test('validVerifiablePresentationForPex creates a valid VP', async () => { + const selectedCredentials = credentials + const presentationResult = PresentationExchange.createPresentationFromCredentials({ + vcJwts: selectedCredentials, + presentationDefinition: presentationDefinition + }); + // :snippet-start: validVerifiablePresentationForPex + const presentation = presentationResult.presentation; + // :snippet-end: + expect(presentation).toBeDefined(); expect(presentation.type).contains('VerifiablePresentation'); }); + }); 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 1c13f19f2..0e6ce53d9 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 @@ -6,6 +6,7 @@ import web5.sdk.crypto.InMemoryKeyManager 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.ConstraintsV2 import web5.sdk.credentials.model.FieldV2 import web5.sdk.credentials.model.InputDescriptorV2 @@ -156,4 +157,28 @@ internal class PresentationExchangeTest { assertNotNull(vp, "Verifiable Presentation should not be null") assertEquals(holderDid, vp.holder, "Holder DID should match") } + + @Test + fun `validVerifiablePresentationForPexKt creates a valid VP`() { + val holderDid = "did:key:zQ3shXrAnbgfytQYQjifUm2EcBBbRAeAeGfgC4TZrjw4X71iZ" + val selectedCredentials = allCredentials + val presentationResult = PresentationExchange.createPresentationFromCredentials( + vcJwts = selectedCredentials, + presentationDefinition = presentationDefinition + ) + val vp = VerifiablePresentation.create( + vcJwts = selectedCredentials, + holder = holderDid, + additionalData = mapOf("presentation_submission" to presentationResult) + ) + // :snippet-start: validVerifiablePresentationForPexKt + val vpDataModelMap = vp.vpDataModel.toMap() + val mappedPresentationSubmission = vpDataModelMap["presentation_submission"] as? PresentationSubmission + // :snippet-end: + + assertNotNull(mappedPresentationSubmission, "Mapped Presentation Submission should not be null") + assertEquals(presentationResult.definitionId, mappedPresentationSubmission?.definitionId, "Definition ID should match") + } } + + From 54787977af96f58a13783c1ceeeaab6c4c755e1d Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Mon, 5 Feb 2024 14:39:59 -0500 Subject: [PATCH 07/17] showing language switcher at the top --- .../build/verifiable-credentials/presentation-exchange.mdx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index 42277b824..c81704d12 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -1,9 +1,12 @@ --- +title: Presentation Exchange +hide_title: true sidebar_position: 3 --- + import CodeSnippet from '@site/src/components/CodeSnippet'; import requiredImportsForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/requiredImportsForPex.snippet.js' import getLoanAppPresentationDefinition from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/getLoanAppPresentationDefinition.snippet.js' @@ -19,9 +22,6 @@ import selectCredentialsForPexKt from '!!raw-loader!@site/snippets/testsuite-kot 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' - -# Presentation Exchange - In this guide, we'll cover the process of presenting [Verifiable Credentials (VCs)](/docs/web5/learn/verifiable-credentials) to a verifier. From d26aba537740a0fc2823b7fa63022e65ba75a972 Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Mon, 5 Feb 2024 14:54:25 -0500 Subject: [PATCH 08/17] adding back title --- .../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 c81704d12..57ffdd82f 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -1,6 +1,5 @@ --- title: Presentation Exchange -hide_title: true sidebar_position: 3 --- From 5aae6b193711b46ba89383bd171ae498626aa670 Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Mon, 5 Feb 2024 14:55:31 -0500 Subject: [PATCH 09/17] adding back title --- .../web5/build/verifiable-credentials/presentation-exchange.mdx | 2 -- 1 file changed, 2 deletions(-) diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index 57ffdd82f..d1cb47421 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -4,8 +4,6 @@ sidebar_position: 3 --- - - import CodeSnippet from '@site/src/components/CodeSnippet'; import requiredImportsForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/requiredImportsForPex.snippet.js' import getLoanAppPresentationDefinition from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/getLoanAppPresentationDefinition.snippet.js' From a436109f4603c2632bb6abdba1009c7d6a120d25 Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Mon, 5 Feb 2024 14:59:31 -0500 Subject: [PATCH 10/17] hardcode imports --- .../presentation-exchange.mdx | 21 +++++++++++++++++-- .../presentation-exchange.test.js | 9 +------- .../PresentationExchangeTest.kt | 12 ----------- 3 files changed, 20 insertions(+), 22 deletions(-) diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index d1cb47421..1539adf72 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -5,14 +5,12 @@ sidebar_position: 3 import CodeSnippet from '@site/src/components/CodeSnippet'; -import requiredImportsForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/requiredImportsForPex.snippet.js' import getLoanAppPresentationDefinition from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/getLoanAppPresentationDefinition.snippet.js' import satisfiesPresentationDefinitionForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/satisfiesPresentationDefinitionForPex.snippet.js' import selectCredentialsForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/selectCredentialsForPex.snippet.js' import createPresentationFromCredentialsForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/createPresentationFromCredentialsForPex.snippet.js' import validVerifiablePresentationForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/validVerifiablePresentationForPex.snippet.js' -import requiredImportsForPexKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/requiredImportsForPexKt.snippet.kt' import getLoanAppPresentationDefinitionKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/getLoanAppPresentationDefinitionKt.snippet.kt' 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' @@ -64,6 +62,25 @@ You can import this class from the `@web5/credentials` package: ]} /> + + ## Select Credentials A user may possess multiple credentials. diff --git a/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js b/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js index 5cb9571e3..fdcd5d270 100644 --- a/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js +++ b/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js @@ -72,14 +72,7 @@ describe('Presentation Exchange Process', () => { } ] }; - test('requiredImportsForPex shows required imports for PEX', async () => { - const requiredImportsForPex = ` - // :snippet-start: requiredImportsForPex - import { PresentationExchange } from '@web5/credentials'; - // :snippet-end: - ` - }); - + test('getLoanAppPresentationDefinition returns a presentation definition', async () => { // :snippet-start: getLoanAppPresentationDefinition const presentationDefinition = { 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 0e6ce53d9..e0945e0ab 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 @@ -52,18 +52,6 @@ internal class PresentationExchangeTest { ) ) - @Test - fun `requiredImportsForPexKt shows required imports for PEX`() { - val requiredImportsForPexKt = - """ - // :snippet-start: requiredImportsForPexKt - import web5.sdk.credentials.PresentationExchange - import web5.sdk.credentials.VerifiablePresentation - import web5.sdk.credentials.model.* - // :snippet-end: - """ - } - @Test fun `getLoanAppPresentationDefinitionKt `() { // :snippet-start: getLoanAppPresentationDefinitionKt From 27857f83e811a821081e67382aa23c56156805ba Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Mon, 5 Feb 2024 15:02:37 -0500 Subject: [PATCH 11/17] make verifiable presentation more obvious --- .../verifiable-credentials/presentation-exchange.mdx | 7 ------- .../PresentationExchangeTest.kt | 12 ++++++------ 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index 1539adf72..a5ea190cd 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -55,13 +55,6 @@ We'll use the Presentation Definition above to present credentials that meet its All methods needed to perform a PEX are in the `PresentationExchange` class. You can import this class from the `@web5/credentials` package: - - Date: Mon, 5 Feb 2024 15:07:19 -0500 Subject: [PATCH 12/17] put language switcher at the top --- .../build/verifiable-credentials/presentation-exchange.mdx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index a5ea190cd..33cbcfbf8 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -1,5 +1,6 @@ --- title: Presentation Exchange +hide_title: true sidebar_position: 3 --- @@ -19,6 +20,8 @@ import validVerifiablePresentationForPexKt from '!!raw-loader!@site/snippets/tes +# Presentation Exchange + In this guide, we'll cover the process of presenting [Verifiable Credentials (VCs)](/docs/web5/learn/verifiable-credentials) to a verifier. This process is known as a **Presentation Exchange (PEX)** and involves selecting credentials that satisfy a Presentation Definition, creating a presentation based on that definition, and submitting the presentation to a verifier. PEX is typically executed by the user's Wallet application, acting on behalf of the user. From 9eb7a6d50e6fde1673844a0e23bfe53e81e609ec Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Mon, 5 Feb 2024 15:22:47 -0500 Subject: [PATCH 13/17] remove unnnecessary import --- .../build/verifiable-credentials/presentation-exchange.test.js | 1 - 1 file changed, 1 deletion(-) diff --git a/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js b/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js index fdcd5d270..c46985c42 100644 --- a/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js +++ b/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js @@ -3,7 +3,6 @@ import { test, describe, expect } from 'vitest'; import { pex_createPresentationFromCredentials, pex_getLoanAppPresentationDefinition, - pex_getPresentationFromResult, pex_submissionCheck, } from '../../../../../../code-snippets/web5/build/verifiable-credentials/presentation-exchange'; import { PresentationExchange } from '@web5/credentials'; From fe22eb71b7e672ac6495b0164ceaaad6215e798e Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Tue, 6 Feb 2024 11:46:03 -0500 Subject: [PATCH 14/17] possible note for missing method --- .../presentation-exchange.mdx | 26 ++++++++++++++----- site/src/components/language/Shnip.jsx | 4 +-- .../presentation-exchange.test.js | 20 +++++++------- 3 files changed, 33 insertions(+), 17 deletions(-) diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index 33cbcfbf8..3ae5f4d87 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -5,7 +5,6 @@ sidebar_position: 3 --- -import CodeSnippet from '@site/src/components/CodeSnippet'; import getLoanAppPresentationDefinition from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/getLoanAppPresentationDefinition.snippet.js' import satisfiesPresentationDefinitionForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/satisfiesPresentationDefinitionForPex.snippet.js' import selectCredentialsForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/selectCredentialsForPex.snippet.js' @@ -62,15 +61,15 @@ You can import this class from the `@web5/credentials` package: inlineSnippets={[ { code: ` - import { PresentationExchange } from '@web5/credentials'; +import { PresentationExchange } from '@web5/credentials'; `, language: 'JavaScript', }, { code: ` - import web5.sdk.credentials.PresentationExchange - import web5.sdk.credentials.VerifiablePresentation - import web5.sdk.credentials.model.* +import web5.sdk.credentials.PresentationExchange +import web5.sdk.credentials.VerifiablePresentation +import web5.sdk.credentials.model.* `, language: 'Kotlin', } @@ -211,7 +210,22 @@ Once you've confirmed that the VCs successfully satisfy the Presentation Definit Before submitting the presentation to a lender, you can validate the Presentation via the `validateSubmission()` method: - + This method checks the presentation submission for any errors, returns an array of `Checked` objects representing the validation checks performed on the presentation submission: diff --git a/site/src/components/language/Shnip.jsx b/site/src/components/language/Shnip.jsx index 158c031f6..84266dbda 100644 --- a/site/src/components/language/Shnip.jsx +++ b/site/src/components/language/Shnip.jsx @@ -45,9 +45,9 @@ const Shnip = ({ snippets, inlineSnippets }) => { ({ content, code, language, codeLanguage, breakLineAt }, index) => (
{content && {content}} - + {code && {addLineBreaks(code, breakLineAt)} - + }
), )} diff --git a/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js b/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js index c46985c42..1557841c2 100644 --- a/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js +++ b/site/testsuites/testsuite-javascript/__tests__/web5/build/verifiable-credentials/presentation-exchange.test.js @@ -183,15 +183,17 @@ describe('Presentation Exchange Process', () => { } ); - test('validateSubmission() checks if the presentation submission is valid', async () => { - const pr = await pex_createPresentationFromCredentials(credentials, pd); - const validationResult = await pex_submissionCheck(pr); - expect(validationResult).toBeDefined(); - expect(validationResult).toBeInstanceOf(Array); - expect(validationResult.length).toBe(1); - expect.soft(validationResult[0]).toHaveProperty('tag', 'root'); - expect.soft(validationResult[0]).toHaveProperty('status', 'info'); - expect.soft(validationResult[0]).toHaveProperty('message', 'ok'); + test('validPresentationSubmissionForPex check if the presention submission is valid', async () => { + const presentationResult = await pex_createPresentationFromCredentials(credentials, pd); + // snippet-start: validPresentationSubmissionForPex + const submissionCheck = PresentationExchange.validateSubmission({ + presentationSubmission: presentationResult.presentationSubmission + }); + // snippet-end: + expect(submissionCheck.length).toBe(1); + expect.soft(submissionCheck[0]).toHaveProperty('tag', 'root'); + expect.soft(submissionCheck[0]).toHaveProperty('status', 'info'); + expect.soft(submissionCheck[0]).toHaveProperty('message', 'ok'); }); test('validVerifiablePresentationForPex creates a valid VP', async () => { From 2d3d31980bdf71ec80013820a21379405bd3ecf8 Mon Sep 17 00:00:00 2001 From: Andrew Lee Rubinger Date: Tue, 6 Feb 2024 11:39:17 -0800 Subject: [PATCH 15/17] PR #1199 - Fix jackson.core to a more compatible version --- site/testsuites/testsuite-kotlin/pom.xml | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/site/testsuites/testsuite-kotlin/pom.xml b/site/testsuites/testsuite-kotlin/pom.xml index e050e9172..fa7a7a99b 100644 --- a/site/testsuites/testsuite-kotlin/pom.xml +++ b/site/testsuites/testsuite-kotlin/pom.xml @@ -32,7 +32,7 @@ Will eventually go bye-bye once the underlying dep trees are fixed up --> - 2.9.8 + 2.12.6 @@ -94,16 +94,6 @@ jackson-databind ${version.com.fasterxml.jackson.core} - - com.fasterxml.jackson.core - jackson-core - 2.12.1 - - - com.fasterxml.jackson.core - jackson-databind - 2.12.1 - From 09a3d0495d7286b5aa9016ef34dabc83e2dc8d53 Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Tue, 6 Feb 2024 15:06:48 -0500 Subject: [PATCH 16/17] handle all imports with model.* --- .../build/verifiablecredentials/PresentationExchangeTest.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) 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 a720f9511..f75804024 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 @@ -6,11 +6,7 @@ import web5.sdk.crypto.InMemoryKeyManager 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.ConstraintsV2 -import web5.sdk.credentials.model.FieldV2 -import web5.sdk.credentials.model.InputDescriptorV2 -import web5.sdk.credentials.model.PresentationDefinitionV2 +import web5.sdk.credentials.model.* /** * Tests backing the Presentation Exchange Guide From dc15f284e55c93330a5f2874f7f36629cf41a24e Mon Sep 17 00:00:00 2001 From: Rizel Scarlett Date: Tue, 6 Feb 2024 15:53:03 -0500 Subject: [PATCH 17/17] add in as snippet --- .../presentation-exchange.mdx | 13 +++++-------- .../presentation-exchange.test.js | 4 ++-- 2 files changed, 7 insertions(+), 10 deletions(-) diff --git a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx index 3ae5f4d87..e4e151275 100644 --- a/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx +++ b/site/docs/web5/build/verifiable-credentials/presentation-exchange.mdx @@ -10,6 +10,8 @@ import satisfiesPresentationDefinitionForPex from '!!raw-loader!@site/snippets/t import selectCredentialsForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/selectCredentialsForPex.snippet.js' import createPresentationFromCredentialsForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/createPresentationFromCredentialsForPex.snippet.js' import validVerifiablePresentationForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/validVerifiablePresentationForPex.snippet.js' +import validPresentationSubmissionForPex from '!!raw-loader!@site/snippets/testsuite-javascript/__tests__/web5/build/verifiable-credentials/validPresentationSubmissionForPex.snippet.js' + import getLoanAppPresentationDefinitionKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/getLoanAppPresentationDefinitionKt.snippet.kt' import satisfiesPresentationDefinitionForPexKt from '!!raw-loader!@site/snippets/testsuite-kotlin/src/test/kotlin/docs/web5/build/verifiablecredentials/satisfiesPresentationDefinitionForPexKt.snippet.kt' @@ -211,15 +213,10 @@ Once you've confirmed that the VCs successfully satisfy the Presentation Definit Before submitting the presentation to a lender, you can validate the Presentation via the `validateSubmission()` method: { test('validPresentationSubmissionForPex check if the presention submission is valid', async () => { const presentationResult = await pex_createPresentationFromCredentials(credentials, pd); - // snippet-start: validPresentationSubmissionForPex + // :snippet-start: validPresentationSubmissionForPex const submissionCheck = PresentationExchange.validateSubmission({ presentationSubmission: presentationResult.presentationSubmission }); - // snippet-end: + // :snippet-end: expect(submissionCheck.length).toBe(1); expect.soft(submissionCheck[0]).toHaveProperty('tag', 'root'); expect.soft(submissionCheck[0]).toHaveProperty('status', 'info');