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 Readme #337

Merged
merged 5 commits into from
Dec 7, 2023
Merged

Update Readme #337

merged 5 commits into from
Dec 7, 2023

Conversation

nitro-neal
Copy link
Contributor

Credentials

The Credentials package enables the creation, signing, verification, and general processing of Verifiable Credentials (VCs). It also has full Presentation Exchange support.

Verifiable Credential

Features

  • Create Verifiable Credentials with flexible data types.
  • Sign credentials using decentralized identifiers (DIDs).
  • Verify the integrity and authenticity of VCs encoded as JSON Web Tokens (JWTs).
  • Parse JWT representations of VCs into VerifiableCredential instances.

Usage:

Creating a Verifiable Credential

Create a new VerifiableCredential with the following parameters:

  • type: Type of the credential.
  • issuer: Issuer URI.
  • subject: Subject URI.
  • data: Credential data.
  • expirationDate?: (optinal) Expiration Date
class StreetCredibility {
  constructor(localRespect, legit) {
    this.localRespect = localRespect;
    this.legit = legit;
  }
}

const vc = new VerifiableCredential({
  type: "StreetCred",
  issuer: "did:example:issuer",
  subject: "did:example:subject",
  data: new StreetCredibility("high", true)
});

Signing a Verifiable Credential

Sign a VerifiableCredential with a DID:

  • did: The did that is signing the VC

First create a Did object as follows:

import { DidKeyMethod } from '@web5/dids';
const issuer = await DidKeyMethod.create();

Then sign the VC using the did object

const vcJwt = vc.sign({did:issuer})

Verifying a Verifiable Credential

Verify the integrity and authenticity of a VC JWT

  • vcJwt: The VC in JWT format as a String.
try {
  await VerifiableCredential.verify(vcJwt)
  console.log("VC Verification successful!")
} catch (e: Error) {
  console.log("VC Verification failed: ${e.message}")
}

Parsing a JWT into a Verifiable Credential

Parse a JWT into a VerifiableCredential instance

vcJwt: The VC JWT as a String.

const vc = VerifiableCredential.parseJwt(vcJwt)

Presentation Exchange

PresentationExchange is designed to facilitate the creation of a Verifiable Presentation by providing tools to select and validate Verifiable Credentials against defined criteria.

Features

  • Select credentials that satisfy a given presentation definition.
  • Validate if a Verifiable Credential JWT satisfies a Presentation Definition.
  • Validate input descriptors within Verifiable Credentials.

Usage

Selecting Credentials

Select Verifiable Credentials that meet the criteria of a given presentation definition.

  • vcJwts: The list of Verifiable Credentials to select from.
  • presentationDefinition The Presentation Definition to match against.

This returns a list of the vcJwts that are acceptable in the presentation definition.

const selectedCredentials = PresentationExchange.selectCredentials(
    vcJwts,
    presentationDefinition
)

Satisfying a Presentation Definition

Validate if a Verifiable Credential JWT satisfies the given presentation definition. Will return an error if the evaluation results in warnings or errors.

  • vcJwts: The list of Verifiable Credentials to select from.
  • presentationDefinition The Presentation Definition to match against.
try {
  PresentationExchange.satisfiesPresentationDefinition(vcJwts, presentationDefinition)
  console.log("vcJwts satisfies Presentation Definition!")
} catch (e: Error) {
  console.log("Verification failed: ${e.message}")
}

Create Presentation From Credentials

Creates a presentation from a list of Verifiable Credentials that satisfy a given presentation definition. This function initializes the Presentation Exchange (PEX) process, validates the presentation definition, evaluates the credentials against the definition, and finally constructs the presentation result if the evaluation is successful.

  • vcJwts: The list of Verifiable Credentials to select from.
  • presentationDefinition The Presentation Definition to match against.
const presentationResult = PresentationExchange.createPresentationFromCredentials(vcJwts, presentationDefinition)

Validate Definition

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

const valid = PresentationExchange.validateDefinition(presentationDefinition)

Validate Submission

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

const valid = PresentationExchange.validateSubmission(presentationSubmission)

Validate Presentation

Evaluates a presentation against a presentation definition.

const evaluationResults = PresentationExchange.evaluatePresentation(presentationDefinition, presentation)

Copy link

codesandbox bot commented Dec 7, 2023

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link
Contributor

github-actions bot commented Dec 7, 2023

TBDocs Report

✅ No errors or warnings

@web5/api

  • Project entry file: packages/api/src/index.ts

TBDocs Report Updated at 2023-12-07T01:07:12Z 9f1213f

Copy link

codecov bot commented Dec 7, 2023

Codecov Report

Merging #337 (9f1213f) into main (2a38d1c) will not change coverage.
The diff coverage is n/a.

❗ Current head 9f1213f differs from pull request most recent head 461bac9. Consider uploading reports for the commit 461bac9 to get more accurate results

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #337   +/-   ##
=======================================
  Coverage   92.71%   92.71%           
=======================================
  Files          75       75           
  Lines       16838    16838           
  Branches     1577     1577           
=======================================
  Hits        15611    15611           
  Misses       1201     1201           
  Partials       26       26           
Components Coverage Δ
api 96.94% <ø> (ø)
common 97.78% <ø> (ø)
credentials 94.15% <ø> (ø)
crypto 100.00% <ø> (ø)
dids 91.80% <ø> (ø)
agent 88.08% <ø> (ø)
identity-agent 56.81% <ø> (ø)
proxy-agent 58.43% <ø> (ø)
user-agent 55.22% <ø> (ø)

@nitro-neal nitro-neal merged commit 01ece16 into main Dec 7, 2023
8 of 9 checks passed
@nitro-neal nitro-neal deleted the update-cred-readme branch December 7, 2023 19:23
finn-tbd pushed a commit that referenced this pull request Mar 19, 2024
* add readme

* Update packages/credentials/README.md

* Update packages/credentials/README.md

* Update packages/credentials/README.md

* Update packages/credentials/README.md

---------

Co-authored-by: Frank Hinek <[email protected]>
finn-tbd pushed a commit that referenced this pull request Mar 19, 2024
* add readme

* Update packages/credentials/README.md

* Update packages/credentials/README.md

* Update packages/credentials/README.md

* Update packages/credentials/README.md

---------

Co-authored-by: Frank Hinek <[email protected]>
finn-tbd pushed a commit that referenced this pull request Mar 19, 2024
* add readme

* Update packages/credentials/README.md

* Update packages/credentials/README.md

* Update packages/credentials/README.md

* Update packages/credentials/README.md

---------

Co-authored-by: Frank Hinek <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants