Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
nitro-neal committed Dec 11, 2023
1 parent 78c2de2 commit dd69257
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 18 deletions.
33 changes: 19 additions & 14 deletions packages/credentials/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,12 @@ const vcJwt = 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})
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})
```

### 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})
```

### 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})
```

### 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})
```
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
2 changes: 1 addition & 1 deletion packages/credentials/src/verifiable-credential.ts
Original file line number Diff line number Diff line change
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});
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});
expect(result).to.deep.equal([{ tag: 'root', status: 'info', message: 'ok' }]);
});

Expand Down

0 comments on commit dd69257

Please sign in to comment.