Skip to content
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

Replace sephereon/PEX presentation definitions with web5 js VCs implementation #112

Merged
merged 7 commits into from
Dec 7, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@
},
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think this PR necessitates a version bump - would you be able to do that? the readme has a section on how to add a changeset and automatically bump the version.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

automagic nice!

"dependencies": {
"@noble/hashes": "1.3.2",
"@sphereon/pex": "2.1.0",
"@sphereon/pex-models": "2.0.3",
"@web5/common": "0.2.1",
"@web5/credentials": "0.3.2",
"@web5/crypto": "0.2.2",
Expand Down
9 changes: 3 additions & 6 deletions packages/protocol/src/message-kinds/rfq.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import type { MessageKind, MessageKindModel, MessageMetadata, ResourceModel } from '../types.js'

import { Offering } from '../resource-kinds/index.js'
import { VerifiableCredential } from '@web5/credentials'
import { VerifiableCredential, PresentationExchange } from '@web5/credentials'
import { Message } from '../message.js'
import { PEXv2 } from '@sphereon/pex'

const pex = new PEXv2()

/**
* Options passed to {@link Rfq.create}
Expand Down Expand Up @@ -77,9 +74,9 @@ export class Rfq extends Message<'rfq'> {
* @throws if rfq's claims do not fulfill the offering's requirements
*/
async verifyClaims(offering: Offering | ResourceModel<'offering'>) {
const { areRequiredCredentialsPresent } = pex.evaluateCredentials(offering.data.requiredClaims, this.claims)
const requiredCredentialsPresent = PresentationExchange.selectCredentials(this.claims, offering.data.requiredClaims)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a nit-pick, but variable name is slightly misleading IMO, could do either one of these...

Suggested change
const requiredCredentialsPresent = PresentationExchange.selectCredentials(this.claims, offering.data.requiredClaims)
const requiredCredentialsPresent = PresentationExchange.selectCredentials(this.claims, offering.data.requiredClaims).length > 0

And then update the if () condition below like this

    if (!requiredCredentialsPresent) {
      throw new Error(`claims do not fulfill the offering's requirements`)
    }

Or, could do...

Suggested change
const requiredCredentialsPresent = PresentationExchange.selectCredentials(this.claims, offering.data.requiredClaims)
const credentials = PresentationExchange.selectCredentials(this.claims, offering.data.requiredClaims)

and then keep the if () condition as-is (I think I prefer this way)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah good callout, totes agree.


if (areRequiredCredentialsPresent === 'error') {
if (!requiredCredentialsPresent.length) {
throw new Error(`claims do not fulfill the offering's requirements`)
}

Expand Down
3 changes: 2 additions & 1 deletion packages/protocol/src/resource-kinds/offering.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { ResourceKindModel, ResourceMetadata } from '../types.js'
import { Resource } from '../resource.js'
import type { PresentationDefinitionV2 } from '@web5/credentials'

/**
* Options passed to {@link Offering.create}
Expand Down Expand Up @@ -64,7 +65,7 @@ export class Offering extends Resource<'offering'> {
}

/** Articulates the claim(s) required when submitting an RFQ for this offering. */
get requiredClaims() {
get requiredClaims(): PresentationDefinitionV2 {
return this.data.requiredClaims
}
}
2 changes: 1 addition & 1 deletion packages/protocol/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Schema as JsonSchema } from 'ajv'
import type { PresentationDefinitionV2 } from '@sphereon/pex-models'
import type { PresentationDefinitionV2 } from '@web5/credentials'

export { JsonSchema }

Expand Down
6 changes: 0 additions & 6 deletions pnpm-lock.yaml

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