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

Update @web5/credentials README #349

Merged
merged 10 commits into from
Dec 13, 2023
37 changes: 21 additions & 16 deletions packages/credentials/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class StreetCredibility {
}
}

const vc = new VerifiableCredential({
const vc = await VerifiableCredential.create({
type: "StreetCred",
issuer: "did:example:issuer",
subject: "did:example:subject",
Expand All @@ -51,16 +51,16 @@ const issuer = await DidKeyMethod.create();

Then sign the VC using the `did` object
```javascript
const vcJwt = vc.sign({ did: issuer });
const vcJwt = await vc.sign({ did: issuer });
```

### Verifying a Verifiable Credential
Verify the integrity and authenticity of a VC JWT
Verify the integrity and authenticity of a Verifiable Credential

- `vcJwt`: The VC in JWT format as a String.
```javascript
try {
await VerifiableCredential.verify(vcJwt)
await VerifiableCredential.verify({ vcJwt: signedVcJwt })
console.log("VC Verification successful!")
} catch (e: Error) {
console.log("VC Verification failed: ${e.message}")
Expand All @@ -73,7 +73,7 @@ Parse a JWT into a `VerifiableCredential` instance
`vcJwt`: The VC JWT as a String.

```javascript
const vc = VerifiableCredential.parseJwt(vcJwt)
const vc = VerifiableCredential.parseJwt({ vcJwt: signedVcJwt })
```

## Presentation Exchange
Expand All @@ -97,10 +97,10 @@ Select Verifiable Credentials that meet the criteria of a given presentation def

This returns a list of the vcJwts that are acceptable in the presentation definition.
```javascript
const selectedCredentials = PresentationExchange.selectCredentials(
vcJwts,
presentationDefinition
)
const selectedCredentials = PresentationExchange.selectCredentials({
vcJwts: signedVcJwts,
presentationDefinition: presentationDefinition
})
```

### Satisfying a Presentation Definition
Expand All @@ -111,13 +111,11 @@ Validate if a Verifiable Credential JWT satisfies the given presentation definit

```javascript
try {
PresentationExchange.satisfiesPresentationDefinition(vcJwts, presentationDefinition)
PresentationExchange.satisfiesPresentationDefinition({vcJwts: signedVcJwts, presentationDefinition: presentationDefinition})
nitro-neal marked this conversation as resolved.
Show resolved Hide resolved
console.log("vcJwts satisfies Presentation Definition!")
} catch (e: Error) {
console.log("Verification failed: ${e.message}")
}


```

### Create Presentation From Credentials
Expand All @@ -127,26 +125,33 @@ Creates a presentation from a list of Verifiable Credentials that satisfy a give
- `presentationDefinition` The Presentation Definition to match against.

```javascript
const presentationResult = PresentationExchange.createPresentationFromCredentials(vcJwts, presentationDefinition)
const presentationResult = PresentationExchange.createPresentationFromCredentials({vcJwts: signedVcJwts, presentationDefinition: presentationDefinition})
nitro-neal marked this conversation as resolved.
Show resolved Hide resolved
```

### Validate Definition
This method validates whether an object is usable as a presentation definition or not.

- `presentationDefinition` The Presentation Definition to validate

```javascript
const valid = PresentationExchange.validateDefinition(presentationDefinition)
const valid = PresentationExchange.validateDefinition({presentationDefinition})
nitro-neal marked this conversation as resolved.
Show resolved Hide resolved
```

### Validate Submission
This method validates whether an object is usable as a presentation submission or not.

- `presentationSubmission` The Presentation Submission to validate

```javascript
const valid = PresentationExchange.validateSubmission(presentationSubmission)
const valid = PresentationExchange.validateSubmission({presentationSubmission})
nitro-neal marked this conversation as resolved.
Show resolved Hide resolved
```

### Validate Presentation
Evaluates a presentation against a presentation definition.

- `presentationDefinition` The Presentation Definition to validate
- `presentation` The Presentation

```javascript
const evaluationResults = PresentationExchange.evaluatePresentation(presentationDefinition, presentation)
const evaluationResults = PresentationExchange.evaluatePresentation({presentationDefinition, presentation})
nitro-neal marked this conversation as resolved.
Show resolved Hide resolved
```
4 changes: 3 additions & 1 deletion packages/credentials/src/presentation-exchange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ export class PresentationExchange {
* @param {PresentationSubmission} presentationSubmission the object to be validated.
* @returns {Validated} the validation results to reveal what is acceptable/unacceptable about the passed object to be considered a valid presentation submission
*/
public static validateSubmission(presentationSubmission: PresentationSubmission): Validated {
public static validateSubmission({ presentationSubmission }: {
presentationSubmission: PresentationSubmission
}): Validated {
return PEX.validateSubmission(presentationSubmission);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/credentials/src/verifiable-credential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ export class VerifiableCredential {
*
* @example
* ```ts
* const vc = VerifiableCredential.create({
* const vc = await VerifiableCredential.create({
* type: 'StreetCredibility',
* issuer: 'did:ex:issuer',
* subject: 'did:ex:subject',
Expand Down Expand Up @@ -209,7 +209,7 @@ export class VerifiableCredential {
*
* @example
* ```ts
* val vc = VerifiableCredential.parseJwt({ vcJwt: signedVcJwt })
* const vc = VerifiableCredential.parseJwt({ vcJwt: signedVcJwt })
* ```
*
* @param vcJwt The verifiable credential JWT as a [String].
Expand Down
7 changes: 5 additions & 2 deletions packages/credentials/tests/presentation-exchange.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ describe('PresentationExchange', () => {
vcJwts: [btcCredentialJwt],
presentationDefinition
});
const result = PresentationExchange.validateSubmission(presentationResult.presentationSubmission);

const presentationSubmission = presentationResult.presentationSubmission;
const result = PresentationExchange.validateSubmission({presentationSubmission});
nitro-neal marked this conversation as resolved.
Show resolved Hide resolved
expect(result).to.deep.equal([{ tag: 'root', status: 'info', message: 'ok' }]);
});

Expand All @@ -184,7 +186,8 @@ describe('PresentationExchange', () => {
expect(presentationEvaluationResults.errors).to.deep.equal([]);
expect(presentationEvaluationResults.warnings).to.deep.equal([]);

const result = PresentationExchange.validateSubmission(presentationResult.presentationSubmission);
const presentationSubmission = presentationResult.presentationSubmission;
const result = PresentationExchange.validateSubmission({presentationSubmission});
nitro-neal marked this conversation as resolved.
Show resolved Hide resolved
expect(result).to.deep.equal([{ tag: 'root', status: 'info', message: 'ok' }]);
});

Expand Down