-
Notifications
You must be signed in to change notification settings - Fork 9
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
Changes from 5 commits
752ee43
e6d7784
2a6b134
f8f5765
3bd5cfd
de22b4f
b96056a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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} | ||
|
@@ -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 credentials = PresentationExchange.selectCredentials(this.claims, offering.data.requiredClaims) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does this method return credentials or error encapsulated in an object? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. /**
* Selects credentials that satisfy a given presentation definition.
*
* @param {string[]} vcJwts The list of Verifiable Credentials to select from.
* @param {PresentationDefinitionV2} presentationDefinition The Presentation Definition to match against.
* @return {string[]} selectedVcJwts A list of Verifiable Credentials that satisfy the Presentation Definition.
*/
public static selectCredentials(
vcJwts: string[],
presentationDefinition: PresentationDefinitionV2
): string[] {
this.resetPex();
const selectResults: SelectResults = this.pex.selectFrom(presentationDefinition, vcJwts);
return selectResults.verifiableCredential as string[] ?? [];
}
it retuns the list of Verifiable Credentials that can satisfy the Presentation Definition. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. actually might be helpful to return the error. this way we can surface it back up to the caller There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I propose we use exceptions for error cases. Two benefits I can think of:
The counter argument is it makes the consumer have to use |
||
|
||
if (areRequiredCredentialsPresent === 'error') { | ||
if (!credentials.length) { | ||
throw new Error(`claims do not fulfill the offering's requirements`) | ||
} | ||
|
||
|
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} | ||
|
@@ -64,7 +65,9 @@ export class Offering extends Resource<'offering'> { | |
} | ||
|
||
/** Articulates the claim(s) required when submitting an RFQ for this offering. */ | ||
get requiredClaims() { | ||
// TODO: Remove type annotation once type alias replaced with direct export in @web5/credentials | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is good to go now, right? Do we have to wait on a release to be cut? If so, and that may be some time, then I'm cool with leaving this comment, opening and issue, and going ahead with a merge here |
||
// [Link to the PR](https://github.com/TBD54566975/web5-js/pull/336) | ||
get requiredClaims(): PresentationDefinitionV2 { | ||
return this.data.requiredClaims | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
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.
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.
automagic nice!