Skip to content

Commit

Permalink
fix: add documentation
Browse files Browse the repository at this point in the history
Signed-off-by: Mirko Mollik <[email protected]>
  • Loading branch information
Mirko Mollik committed May 7, 2024
1 parent f3795ea commit 322d4bd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
17 changes: 11 additions & 6 deletions packages/jwt-status-list/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,16 @@ const payload: JWTPayload = {
};
const header: JWTHeaderParameters = { alg: 'ES256' };

const jwt = createUnsignedJWT(list, payload, header);
const jwt = createHeaderAndPayload(list, payload, header);

// Sign the JWT with the private key
const signedJwt = await jwt.sign(privateKey);
// Sign the JWT with the private key, e.g. using the `jose` library
const jwt = await new SignJWT(values.payload)
.setProtectedHeader(values.header)
.sign(privateKey);

```

Interaction with a JWT Status List:
Interaction with a JWT status list on low level:
```typescript
//validation of the JWT is not provided by this library!!!

Expand All @@ -67,10 +69,13 @@ const statusList = getListFromStatusListJWT(list);

//get the status of a specific entry
const status = statusList.getStatus(reference.idx);

// handle the status
```

### Integration into sd-jwt-vc
The status list can be integrated into the [sd-jwt-vc](../sd-jwt-vc/README.md) library to provide a way to verify the status of a credential. In the [test folder](../sd-jwt-vc/src/test/index.spec.ts) you will find an example how to add the status reference to a credential and also how to verify the status of a credential.

```typescript

### Caching the status list
Depending on the `ttl` field if provided the status list can be cached for a certain amount of time. This library has no internal cache mechanism, so it is up to the user to implement it for example by providing a custom `fetchStatusList` function.

Expand Down
13 changes: 9 additions & 4 deletions packages/jwt-status-list/src/test/status-list-jwt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ import {
getListFromStatusListJWT,
getStatusListFromJWT,
} from '../status-list-jwt';
import type { JwtHeaderParameters, JWTwithStatusListPayload } from '../types';
import type {
StatusListJWTHeaderParameters,
JWTwithStatusListPayload,
} from '../types';
import { StatusList } from '../status-list';
import { jwtVerify, type KeyLike, SignJWT } from 'jose';
import { beforeAll, describe, expect, it } from 'vitest';
Expand All @@ -14,6 +17,11 @@ describe('JWTStatusList', () => {
let publicKey: KeyLike;
let privateKey: KeyLike;

const header: StatusListJWTHeaderParameters = {
alg: 'ES256',
typ: 'statuslist+jwt',
};

beforeAll(() => {
// Generate a key pair for testing
const keyPair = generateKeyPairSync('ec', {
Expand All @@ -31,7 +39,6 @@ describe('JWTStatusList', () => {
sub: `${iss}/statuslist/1`,
iat: new Date().getTime() / 1000,
};
const header: JwtHeaderParameters = { alg: 'ES256' };

const values = createHeaderAndPayload(statusList, payload, header);

Expand All @@ -56,7 +63,6 @@ describe('JWTStatusList', () => {
sub: `${iss}/statuslist/1`,
iat: new Date().getTime() / 1000,
};
const header: JwtHeaderParameters = { alg: 'ES256' };

const values = createHeaderAndPayload(statusList, payload, header);

Expand All @@ -74,7 +80,6 @@ describe('JWTStatusList', () => {
const list = [1, 0, 1, 0, 1];
const statusList = new StatusList(list, 2);
const iss = 'https://example.com';
const header: JwtHeaderParameters = { alg: 'ES256' };
let payload: JwtPayload = {
sub: `${iss}/statuslist/1`,
iat: new Date().getTime() / 1000,
Expand Down
5 changes: 5 additions & 0 deletions packages/sd-jwt-vc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,13 @@ const verified = await sdjwt.verify(presentation);

Check out more details in our [documentation](https://github.com/openwallet-foundation-labs/sd-jwt-js/tree/main/docs) or [examples](https://github.com/openwallet-foundation-labs/sd-jwt-js/tree/main/examples)

### Revocation
To add revocation capabilities, you can use the `@sd-jwt/jwt-status-list` library to create a JWT Status List and include it in the SD-JWT-VC.


### Dependencies

- @sd-jwt/core
- @sd-jwt/types
- @sd-jwt/utils
- @sd-jwt/jwt-status-list

0 comments on commit 322d4bd

Please sign in to comment.