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

adding credentials package to web5-js #175

Merged
merged 19 commits into from
Sep 12, 2023
Merged

Conversation

nitro-neal
Copy link
Contributor

@nitro-neal nitro-neal commented Aug 22, 2023

Summary

Integrate pex SSI objects within the credentials package of web5 and provide an SSI SDK

The types.ts file in the credential package exports web5 objects as wrapped pex objects
This allows users to only need to import web5 and not pex, and we can add abstractions around pex lib as needed.

Credentials

VerifiableCredential Creation and Verification

The VerifiableCredential class provides methods for the creation, handling, and signing of Verifiable Credentials (VCs) in JWT format.

  • VerifiableCredential.create: Creates a Verifiable Credential (VC) in JWT format.
  • VerifiableCredential.validatePayload: Validates the structure and integrity of a Verifiable Credential payload.
  • VerifiableCredential.verify: Verifies the integrity of a VC JWT.
  • VerifiableCredential.decode: Decodes a VC JWT into its constituent parts: header, payload, and signature.

VP Creation and Verification

The VerifiablePresentation class provides utility methods for creation and handling Verifiable Presentations (VPs) in JWT format.

  • VerifiablePresentation.create: Creates a Verifiable Presentation (VP) in JWT format from a presentation definition and set of credentials.
  • VerifiablePresentation.verify: Verifies the integrity of a VP JWT.
  • VerifiablePresentation.validatePayload: Validates the structure and integrity of a Verifiable Presentation payload.
  • VerifiablePresentation.decode: Decodes a VP JWT into its constituent parts: header, payload, and signature.

Presentation Exchange Helpers

These methods assist in evaluating verifiable credentials and presentations against specified presentation definitions.

  • VerifiableCredential.evaluateCredentials: Evaluates a set of verifiable credentials against a specified presentation definition.
  • VerifiablePresentation.evaluatePresentation: Evaluates a given Verifiable Presentation against a specified presentation definition.

Verifiable Credentials and Presentations Library

Note: you do not have to use the functions to create SSI objects, you can instead create them yourselves with the boilerplate types in types.ts

      const vc: VerifiableCredentialV1 = {
        '@context'          : ['https://www.w3.org/2018/credentials/v1'],
        'id'                : 'my-cred',
        'type'              : ['VerifiableCredential'],
        'issuer'            : 'did:key:123',
        'issuanceDate'      : getCurrentXmlSchema112Timestamp(),
        'credentialSubject' : {
          'btcAddress': 'btcAddress123'
        }
      };

Signer Options Object

The Signer represents a function that takes a byte array as input and returns a promise that resolves to a byte array, representing the signature of the input data.

Type Definition

type Signer = (data: Uint8Array) => Promise<Uint8Array>;

This change also allows a full PE by users using boilerplate ssi objects. A full Presentation Exchange is available as a new unit test presentationexchange.spec.ts

@nitro-neal
Copy link
Contributor Author

nitro-neal commented Aug 22, 2023

image Tests Passing

@codecov
Copy link

codecov bot commented Aug 22, 2023

Codecov Report

Merging #175 (15154b6) into main (150b419) will increase coverage by 0.11%.
The diff coverage is 92.77%.

@@            Coverage Diff             @@
##             main     #175      +/-   ##
==========================================
+ Coverage   89.42%   89.53%   +0.11%     
==========================================
  Files          64       67       +3     
  Lines       12399    12828     +429     
  Branches     1188     1238      +50     
==========================================
+ Hits        11088    11486     +398     
- Misses       1291     1319      +28     
- Partials       20       23       +3     
Components Coverage Δ
api 94.32% <ø> (ø)
common 95.00% <ø> (ø)
credentials 92.77% <92.77%> (∅)
crypto 94.87% <ø> (ø)
dids 92.16% <ø> (ø)
agent 87.80% <ø> (ø)
identity-agent 59.05% <ø> (ø)
proxy-agent 58.59% <ø> (ø)
user-agent 57.36% <ø> (ø)

Copy link
Contributor

@frankhinek frankhinek left a comment

Choose a reason for hiding this comment

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

Notes:

  • Switched to using Convert utility from the @web5/common package instead of Encoder from @tbd54566975/dwn-sdk-js.
  • A devDependency on @tbd54566975/dwn-sdk-js was added to the PresentationExchange test but not added to package.json. Doesn't need to be fixed since it was swapped for Convert but something to keep an eye on.

And a a few minor changes:

  • Added comments to the newly added utility functions. @nitro-neal double-check that the explanations and usage examples are accurate.
  • Used exact dependency version for @sphereon/pex.
  • Updated formatting, word wrap, and code style to match SDK conventions.

@frankhinek frankhinek added this to the 0.8 milestone Aug 23, 2023
Copy link
Member

@mistermoe mistermoe left a comment

Choose a reason for hiding this comment

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

🎖️ 💯 🍖 🌞

@nitro-neal nitro-neal merged commit efb65b3 into main Sep 12, 2023
22 of 23 checks passed
andorsk pushed a commit to modernfoundry/web5-js that referenced this pull request Sep 28, 2023
* adding credentials package to web5-js

* Minor formatting and code style adjustments

Signed-off-by: Frank Hinek <[email protected]>

* Add comments to utility functions

Signed-off-by: Frank Hinek <[email protected]>

* Add EdDSA alg to JWS header parameters type

Signed-off-by: Frank Hinek <[email protected]>

* Pin @sphereon/pex version

Signed-off-by: Frank Hinek <[email protected]>

* Use Convert from @web5/common and fix type issues

Signed-off-by: Frank Hinek <[email protected]>

* Add named export for utils

Signed-off-by: Frank Hinek <[email protected]>

* Rewrite the PresentationExchange test to not rely on the 'agent' package

Signed-off-by: Frank Hinek <[email protected]>

* updating with credentials ssi package

* update package-lock

* adding full vc and vp impl

* adding more tests

* updating tests and renaming VC and VP

* adding validator tests

* fix pex state issues

* more tests

---------

Signed-off-by: Frank Hinek <[email protected]>
Co-authored-by: Frank Hinek <[email protected]>
@frankhinek frankhinek deleted the web-js-credentials-package branch October 3, 2023 18:31
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