npm.io
0.23.0 • Published 5d ago

@sd-jwt/sd-jwt-vc

Licence
Apache-2.0
Version
0.23.0
Deps
4
Size
112 kB
Vulns
0
Weekly
0
Stars
8

@sd-jwt/sd-jwt-vc

npm version License

Implementation of SD-JWT-based Verifiable Credentials (SD-JWT VC) — draft-ietf-oauth-sd-jwt-vc-15, built on top of @sd-jwt/core (RFC 9901).

Installation

# Using npm
npm install @sd-jwt/sd-jwt-vc

# Using pnpm
pnpm add @sd-jwt/sd-jwt-vc

# Using yarn
yarn add @sd-jwt/sd-jwt-vc

Usage

Here's a basic example of how to use this library:

import type { DisclosureFrame } from '@sd-jwt/core';

// identifier of the issuer
const iss = 'University';

// issuance time
const iat = Math.floor(Date.now() / 1000); // current time in seconds

//unique identifier of the schema
const vct = 'University-Degree';

// Issuer defines the claims object with the user's information
const claims = {
  firstname: 'John',
  lastname: 'Doe',
  ssn: '123-45-6789',
  id: '1234',
};

// Issuer defines the disclosure frame to specify which claims can be disclosed/undisclosed
const disclosureFrame: DisclosureFrame<typeof claims> = {
  _sd: ['firstname', 'lastname', 'ssn'],
};

// Issuer issues a signed JWT credential with the specified claims and disclosure frame
// returns an encoded JWT
const credential = await sdjwt.issue(
  { iss, iat, vct, ...claims },
  disclosureFrame,
);

// Holder may validate the credential from the issuer
const valid = await sdjwt.validate(credential);

// Holder defines the presentation frame to specify which claims should be presented
// The list of presented claims must be a subset of the disclosed claims
const presentationFrame = { firstname: true, ssn: true };

// Holder creates a presentation using the issued credential and the presentation frame
// returns an encoded SD JWT.
const presentation = await sdjwt.present(credential, presentationFrame);

// Verifier can verify the presentation using the Issuer's public key
const verified = await sdjwt.verify(presentation);

Examples

Runnable examples are available in examples/sd-jwt/sd-jwt-vc. Run them from the repository root:

pnpm tsx examples/sd-jwt/sd-jwt-vc/basic.ts

See the SD-JWT examples overview for the full list.

Dependencies

Platform Support

This library is platform agnostic and works in:

  • Node.js (>=20)
  • Browsers (modern browsers with ES2020 support)
  • React Native

A global TextEncoder and TextDecoder must be available. See the React Native notes if you need a polyfill.

Cryptographic operations (signing, verification, hashing, salt generation) are provided as callbacks. @owf/crypto provides Web Crypto based implementations.

Contributing

See the Contributing Guide for details on how to contribute to this project.

License

This project is licensed under the Apache License Version 2.0 (Apache-2.0).