Skip to content

Commit

Permalink
feat: FTL-9167 add pex presentation submission v2 types (#307)
Browse files Browse the repository at this point in the history
* feat: FTL-9167 add pex presentation submission v2 types

* feat: add submission context to a document loader

---------

Co-authored-by: Volodymyr Pavlyshyn <volodymyr.p@affinidi.org>
Co-authored-by: Oleksii Piliugin <oleksii.p@affinidi.com>
  • Loading branch information
3 people committed Mar 13, 2023
1 parent 9a8e504 commit d96327e
Show file tree
Hide file tree
Showing 27 changed files with 171 additions and 48 deletions.
2 changes: 2 additions & 0 deletions common-libs/common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# release 3.0.1 (2023-02-10)
* Update vc common lb, extend presentation submission
# release 3.0.0 (2023-03-08)
* added KeyManager abstraction, all operations with Private Key moved to KeyManager
# release 2.14.0 (2023-03-07)
Expand Down
4 changes: 2 additions & 2 deletions common-libs/common/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions common-libs/common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@affinidi/common",
"version": "3.0.0",
"version": "3.0.1",
"description": "Common utilities and types for Affinidi SDKs",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down Expand Up @@ -48,7 +48,7 @@
"@affinidi/tiny-lds-ecdsa-secp256k1-2019": "^1.2.2",
"@affinidi/tools-common": "^1.4.2",
"@affinidi/url-resolver": "^4.0.0",
"@affinidi/vc-common": "^1.7.0",
"@affinidi/vc-common": "^1.7.1",
"base64url": "^3.0.1",
"bip32": "^2.0.5",
"browserify-aes": "^1.2.0",
Expand All @@ -72,7 +72,7 @@
"@affinidi/platform-fetch-node": "^1.1.0",
"@affinidi/prettier-config": "1.0.1",
"@affinidi/tools-openapi": "^1.2.1",
"@affinidi/vc-data": "^1.6.1",
"@affinidi/vc-data": "^1.6.2",
"@types/chai": "4.2.12",
"@types/create-hash": "^1.2.2",
"@types/ethereumjs-util": "5.2.0",
Expand Down Expand Up @@ -107,4 +107,4 @@
"typescript": "^4.3.2"
},
"gitHead": "39b8ae64eb5e37ddae2f80438b320adaefae8ef6"
}
}
15 changes: 15 additions & 0 deletions common-libs/common/src/_baseDocumentLoader/localContexts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -273,4 +273,19 @@ export const localContexts: Record<string, Record<string, any>> = {
},
},
},
'https://identity.foundation/presentation-exchange/submission/v1': {
'@context': {
'@version': 1.1,
PresentationSubmission: {
'@id': 'https://identity.foundation/presentation-exchange/#presentation-submission',
'@context': {
'@version': 1.1,
presentation_submission: {
'@id': 'https://identity.foundation/presentation-exchange/#presentation-submission',
'@type': '@json',
},
},
},
},
},
}
4 changes: 2 additions & 2 deletions common-libs/tools-common/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions common-libs/vc-common/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# release 1.7.0 (2023-03-10)
* Extend types for Presentation Exchange V2 submission
# release 1.7.0 (2023-02-09)
* Added the ability to check if the `challenge` field matches.
* Now the `VP` requester can send an initial `challenge` to compare
Expand Down
4 changes: 2 additions & 2 deletions common-libs/vc-common/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion common-libs/vc-common/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@affinidi/vc-common",
"version": "1.7.0",
"version": "1.7.1",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
"description": "Shared types and utilities for credential related libraries",
Expand Down
6 changes: 6 additions & 0 deletions common-libs/vc-common/src/vc/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ export type VCV1Revocation = {
id: string
}

export type VCV1Schema = {
id: string
type: string
}

export type VCV1Skeleton<
Subject extends MaybeArray<VCV1Subject<SimpleThing>> = VCV1SubjectMA,
Type extends VCV1Type = VCV1Type,
Expand All @@ -49,6 +54,7 @@ export type VCV1Skeleton<
type: Type
holder: Holder
credentialSubject: Subject
credentialSchema?: VCV1Schema
}

export type VCV1Unsigned<
Expand Down
2 changes: 2 additions & 0 deletions common-libs/vc-common/src/vp/v1.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export type PresentationSubmissionDescriptorV1 = {
}
export type PresentationSubmissionV1 = {
locale?: string
id?: string
definition_id?: string
descriptor_map: PresentationSubmissionDescriptorV1[]
}

Expand Down
6 changes: 2 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions sdk/browser/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions sdk/core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# release 7.16.2 (2023-03-10)
* Update common libs to support presentation submission v2
# release 7.16.1 (2023-03-09)
* updated `validateJWT` error handling
# release 7.16.0 (2023-03-08)
Expand Down
6 changes: 3 additions & 3 deletions sdk/core/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions sdk/core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@affinidi/wallet-core-sdk",
"version": "7.16.1",
"version": "7.16.2",
"description": "SDK core monorepo for affinity DID solution",
"main": "dist/index.js",
"typings": "dist/index.d.ts",
Expand Down Expand Up @@ -43,16 +43,16 @@
"dependencies": {
"@affinidi/affinidi-did-auth-lib": "^2.8.0",
"@affinidi/affinity-metrics-lib": "^0.0.25",
"@affinidi/common": "^3.0.0",
"@affinidi/common": "^3.0.1",
"@affinidi/internal-api-clients": "^2.5.1",
"@affinidi/issuer-email-ses-client": "^0.1.1",
"@affinidi/issuer-phone-twilio-client": "^0.1.1",
"@affinidi/platform-fetch": "^1.1.0",
"@affinidi/tools-common": "^1.4.3",
"@affinidi/url-resolver": "^4.0.0",
"@affinidi/user-management": "^2.6.1",
"@affinidi/vc-common": "^1.7.0",
"@affinidi/vc-data": "^1.6.1",
"@affinidi/vc-common": "^1.7.1",
"@affinidi/vc-data": "^1.6.2",
"ajv": "^6.12.3",
"async-retry": "^1.3.1",
"bip32": "^2.0.5",
Expand Down Expand Up @@ -112,4 +112,4 @@
"typescript": "^4.3.2"
},
"gitHead": "5420b34bac444d42d16b336a7ae95f47741d150c"
}
}
66 changes: 66 additions & 0 deletions sdk/core/test/factory/presentationWithSubmission.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
import { VPV1Unsigned } from '@affinidi/vc-common'

const presentationWithSubmission: VPV1Unsigned = {
'@context': [
'https://www.w3.org/2018/credentials/v1',
'https://identity.foundation/presentation-exchange/submission/v1',
],
type: ['VerifiablePresentation', 'PresentationSubmission'],
holder: {
id:
'did:elem:EiBi2nJp4p8x6dVz8zW635_ccJFn3Y_tIQDIvdxUUmtMgQ;elem:initial-state=eyJwcm90ZWN0ZWQiOiJleUp2Y0dWeVlYUnBiMjRpT2lKamNtVmhkR1VpTENKcmFXUWlPaUlqY0hKcGJXRnllU0lzSW1Gc1p5STZJa1ZUTWpVMlN5SjkiLCJwYXlsb2FkIjoiZXlKQVkyOXVkR1Y0ZENJNkltaDBkSEJ6T2k4dmR6TnBaQzV2Y21jdmMyVmpkWEpwZEhrdmRqSWlMQ0p3ZFdKc2FXTkxaWGtpT2x0N0ltbGtJam9pSTNCeWFXMWhjbmtpTENKMWMyRm5aU0k2SW5OcFoyNXBibWNpTENKMGVYQmxJam9pVTJWamNESTFObXN4Vm1WeWFXWnBZMkYwYVc5dVMyVjVNakF4T0NJc0luQjFZbXhwWTB0bGVVaGxlQ0k2SWpBek4yTTFaVFV3WTJKaE9HRTNNamRoWkRSbE5XWXdNamc0Tm1VMll6bGxabVk0TWpGaFl6QTJOV1ZtWXpFd1pEZGhPVEkyT1RJME1XTTNZV1kxTUdVek1pSjlMSHNpYVdRaU9pSWpjbVZqYjNabGNua2lMQ0oxYzJGblpTSTZJbkpsWTI5MlpYSjVJaXdpZEhsd1pTSTZJbE5sWTNBeU5UWnJNVlpsY21sbWFXTmhkR2x2Ymt0bGVUSXdNVGdpTENKd2RXSnNhV05MWlhsSVpYZ2lPaUl3TWpNeVpUazVZekl3T1dVd01HSmxOVGM1TldRMFpqUXlNR0psTlRoak1qQm1OREV5Tm1Vd05qZ3hNbVUxTVROalpXWmtOVEprWW1KaU5qazRNekkxTURNaWZWMHNJbUYxZEdobGJuUnBZMkYwYVc5dUlqcGJJaU53Y21sdFlYSjVJbDBzSW1GemMyVnlkR2x2YmsxbGRHaHZaQ0k2V3lJamNISnBiV0Z5ZVNKZGZRIiwic2lnbmF0dXJlIjoiRWhKdDlCVEtyV0YyRjdRSGhPNTJuODhtZTdxU3VMOHdJOVdCSGh3UC1BQkVvZzF6R2t3SkJUSkdaNE0wTjZLb1c0U2RGYXRlSnJZTUNhamhNeWtSZlEifQ',
},
presentation_submission: {
id: '6HyHIVVLFQ0kq9SMPjmUZ',
definition_id: '048fccfb-1432-474f-ac10-19dafd038435',
descriptor_map: [
{
id: 'score',
format: 'ldp_vc',
path: '$.verifiableCredential[0]',
},
{
id: 'likes',
format: 'ldp_vc',
path: '$.verifiableCredential[0]',
},
],
},
verifiableCredential: [
{
'@context': ['https://www.w3.org/2018/credentials/v1', 'https://schema.affinidi.com/ContentLikeV1-0.jsonld'],
id: 'claimId:dk69lfp6c4',
type: ['VerifiableCredential', 'ContentLike'],
holder: {
id:
'did:elem:EiBi2nJp4p8x6dVz8zW635_ccJFn3Y_tIQDIvdxUUmtMgQ;elem:initial-state=eyJwcm90ZWN0ZWQiOiJleUp2Y0dWeVlYUnBiMjRpT2lKamNtVmhkR1VpTENKcmFXUWlPaUlqY0hKcGJXRnllU0lzSW1Gc1p5STZJa1ZUTWpVMlN5SjkiLCJwYXlsb2FkIjoiZXlKQVkyOXVkR1Y0ZENJNkltaDBkSEJ6T2k4dmR6TnBaQzV2Y21jdmMyVmpkWEpwZEhrdmRqSWlMQ0p3ZFdKc2FXTkxaWGtpT2x0N0ltbGtJam9pSTNCeWFXMWhjbmtpTENKMWMyRm5aU0k2SW5OcFoyNXBibWNpTENKMGVYQmxJam9pVTJWamNESTFObXN4Vm1WeWFXWnBZMkYwYVc5dVMyVjVNakF4T0NJc0luQjFZbXhwWTB0bGVVaGxlQ0k2SWpBek4yTTFaVFV3WTJKaE9HRTNNamRoWkRSbE5XWXdNamc0Tm1VMll6bGxabVk0TWpGaFl6QTJOV1ZtWXpFd1pEZGhPVEkyT1RJME1XTTNZV1kxTUdVek1pSjlMSHNpYVdRaU9pSWpjbVZqYjNabGNua2lMQ0oxYzJGblpTSTZJbkpsWTI5MlpYSjVJaXdpZEhsd1pTSTZJbE5sWTNBeU5UWnJNVlpsY21sbWFXTmhkR2x2Ymt0bGVUSXdNVGdpTENKd2RXSnNhV05MWlhsSVpYZ2lPaUl3TWpNeVpUazVZekl3T1dVd01HSmxOVGM1TldRMFpqUXlNR0psTlRoak1qQm1OREV5Tm1Vd05qZ3hNbVUxTVROalpXWmtOVEprWW1KaU5qazRNekkxTURNaWZWMHNJbUYxZEdobGJuUnBZMkYwYVc5dUlqcGJJaU53Y21sdFlYSjVJbDBzSW1GemMyVnlkR2x2YmsxbGRHaHZaQ0k2V3lJamNISnBiV0Z5ZVNKZGZRIiwic2lnbmF0dXJlIjoiRWhKdDlCVEtyV0YyRjdRSGhPNTJuODhtZTdxU3VMOHdJOVdCSGh3UC1BQkVvZzF6R2t3SkJUSkdaNE0wTjZLb1c0U2RGYXRlSnJZTUNhamhNeWtSZlEifQ',
},
credentialSubject: {
data: {
'@type': ['VerifiableCredential', 'ContentLike'],
url: 'https://www.youtube.com/watch?v=Pk5Rnd5ixCI&list=PL1e3Vu_V-AU9yKjCWIPWDZylRVZvw5kPW&index=1',
date: '2023-03-13T08:57:19.951Z',
like: true,
score: 10,
},
},
credentialSchema: {
id: 'https://schema.affinidi.com/ContentLikeV1-0.json',
type: 'JsonSchemaValidator2018',
},
issuanceDate: '2023-03-13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CSGh3UC1BQkVvZzF6R2t3SkJUSkdaNE0wTjZLb1c0U2RGYXRlSnJZTUNhamhNeWtSZlEifQ',
proof: {
type: 'EcdsaSecp256k1Signature2019',
created: '2023-03-13T08:57:20Z',
verificationMethod: 'did:elem:EiBi2nJp4p8x6dVz8zW635_ccJFn3Y_tIQDIvdxUUmtMgQ#primary',
proofPurpose: 'assertionMethod',
jws:
'eyJhbGciOiJFUzI1NksiLCJiNjQiOmZhbHNlLCJjcml0IjpbImI2NCJdfQ..LbynVws4bVQc1E9RcSAySclkFGMpWZu43-7Lpr-yeKJXxMFold5vbH1sulIaPtw5Sse01in9IG9xMq-NbkLYxA',
},
},
],
}

export default presentationWithSubmission
27 changes: 27 additions & 0 deletions sdk/core/test/unit/CommonNetworkMember.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import cognitoUserTokens from '../factory/cognitoUserTokens'
import credentialShareRequestToken from '../factory/credentialShareRequestToken'
import parsedCredentialShareRequestToken from '../factory/parsedCredentialShareRequestToken'
import parsedCredentialShareResponseToken from '../factory/parsedCredentialShareResponseToken'
import presentationWithSubmission from '../factory/presentationWithSubmission'
import { testPlatformTools } from '../helpers/testPlatformTools'
import { randomBytes } from '../../src/shared/randomBytes'

Expand Down Expand Up @@ -1755,6 +1756,32 @@ describe('CommonNetworkMember', () => {
}
})

it('#verifyPresentation should work with presentation that has submissions', async () => {
const requesterCommonNetworkMember = new AffinidiWallet(walletPassword, encryptedSeedElem, options)
const userSeed =
'a6a6c462b15619273fbf942c99e2b7c1be03ef184f5d1d27a17f29b45c4676dcc5e07ecc835acf1ff1d6f437e95f5cc77ce597d254a7b7' +
'db932bbb2698d0804e47cd02c7f02580da2132d008c0e313820964646c7630e01d65925d4b5f8db741'
const userPassword = 'Test8b60806087f5e7b8eee6607ae8!!'
const userCommonNetworkMember = new AffinidiWallet(userPassword, userSeed, options)

const presentationChallenge = 'beb140f5-e746-4ba0-8bd2-f6ecf26c3f25'
const domain = 'domain'
const vp = await userCommonNetworkMember.signUnsignedPresentation(
presentationWithSubmission,
presentationChallenge,
domain,
)
const result = await requesterCommonNetworkMember.verifyPresentation(vp)

if (result.isValid === true) {
expect(result.challenge).to.eq(presentationChallenge)
expect(result.suppliedPresentation).to.deep.eq(vp)
} else {
expect(result.suppliedPresentation).to.deep.eq(vp)
expect.fail(result.errors.join('\n'))
}
})

it('#generateDidAuthRequest should throw validation error for invalid "jwtOptions.audienceDid"', async () => {
const commonNetworkMember = new AffinidiWallet(walletPassword, encryptedSeedElem, options)

Expand Down
4 changes: 2 additions & 2 deletions sdk/expo/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions sdk/issuer-kit/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d96327e

Please sign in to comment.