Skip to content

Commit

Permalink
Package Splitting works (#68)
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas <[email protected]>
Signed-off-by: Lukas.J.Han <[email protected]>
  • Loading branch information
lukasjhan authored Feb 20, 2024
1 parent c4d555c commit e95cac5
Show file tree
Hide file tree
Showing 84 changed files with 1,976 additions and 520 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-pr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Install pnpm
run: npm install -g pnpm
- name: Install Dependencies
run: pnpm install
run: pnpm install && pnpm build && pnpm install
- name: Run Tests(Browser)
run: pnpm test:browser
- name: Run Tests(Node)
Expand Down
36 changes: 4 additions & 32 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,7 @@

This directory contains examples of how to use the SD JWT(sd-jwt-js) library.

## How to run the examples

```bash
pnpm install
```

## Run the example
## How to run the example

```bash
pnpm run {example_file_name}
Expand All @@ -19,28 +13,6 @@ pnpm run all

### Example lists

- basic: Example of basic usage(issue, validate, present, verify) of SD JWT
- all: Example of issue, present and verify the comprehensive data.
- custom: Example of using custom hasher and salt generator for SD JWT
- custom_header: Example of using custom header for SD JWT
- sdjwtobject: Example of using SD JWT Object
- decoy: Example of adding decoy digest in SD JWT
- kb: key binding example in SD JWT
- decode: Decoding example of a SD JWT sample

### Variables In Examples

- claims: the user's information
- disclosureFrame: specify which claims should be disclosed
- credential: Issued Encoded SD JWT.
- validated: result of SD JWT validation
- presentationFrame: specify which claims should be presented
- presentation: Presented Encoded SD JWT.
- requiredClaims: specify which claims should be verified
- verified: result of verification
- sdJwtToken: SD JWT Token Object
- SDJwtInstance: SD JWT Instance

## More examples from tests

You can find more examples from [tests](../test).
- core: Example of basic usage(issue, validate, present, verify) of SD JWT
- decode: Decoding example of a SD JWT (only use decode package)
- present: Example of presenting the SD JWT (only use present, decode package)
36 changes: 36 additions & 0 deletions examples/core-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# SD JWT Core Examples

This directory contains example of basic usage(issue, validate, present, verify) of SD JWT

## Run the example

```bash
pnpm run {example_file_name}

# example
pnpm run all
```

### Example lists

- basic: Example of basic usage(issue, validate, present, verify) of SD JWT
- all: Example of issue, present and verify the comprehensive data.
- custom: Example of using custom hasher and salt generator for SD JWT
- custom_header: Example of using custom header for SD JWT
- sdjwtobject: Example of using SD JWT Object
- decoy: Example of adding decoy digest in SD JWT
- kb: key binding example in SD JWT
- decode: Decoding example of a SD JWT sample

### Variables In Examples

- claims: the user's information
- disclosureFrame: specify which claims should be disclosed
- credential: Issued Encoded SD JWT.
- validated: result of SD JWT validation
- presentationFrame: specify which claims should be presented
- presentation: Presented Encoded SD JWT.
- requiredClaims: specify which claims should be verified
- verified: result of verification
- sdJwtToken: SD JWT Token Object
- SDJwtInstance: SD JWT Instance
3 changes: 2 additions & 1 deletion examples/all.ts → examples/core-example/all.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DisclosureFrame, SDJwtInstance } from '@hopae/sd-jwt';
import { SDJwtInstance } from '@hopae/sd-jwt-core';
import { DisclosureFrame } from '@hopae/sd-jwt-type';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
3 changes: 2 additions & 1 deletion examples/basic.ts → examples/core-example/basic.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DisclosureFrame, SDJwtInstance } from '@hopae/sd-jwt';
import { SDJwtInstance } from '@hopae/sd-jwt-core';
import { DisclosureFrame } from '@hopae/sd-jwt-type';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
3 changes: 2 additions & 1 deletion examples/custom.ts → examples/core-example/custom.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DisclosureFrame, SDJwtInstance } from '@hopae/sd-jwt';
import { SDJwtInstance } from '@hopae/sd-jwt-core';
import { DisclosureFrame } from '@hopae/sd-jwt-type';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DisclosureFrame, SDJwtInstance } from '@hopae/sd-jwt';
import { SDJwtInstance } from '@hopae/sd-jwt-core';
import { DisclosureFrame } from '@hopae/sd-jwt-type';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
2 changes: 1 addition & 1 deletion examples/decode.ts → examples/core-example/decode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { SDJwtInstance } from '@hopae/sd-jwt';
import { SDJwtInstance } from '@hopae/sd-jwt-core';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
3 changes: 2 additions & 1 deletion examples/decoy.ts → examples/core-example/decoy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DisclosureFrame, SDJwtInstance } from '@hopae/sd-jwt';
import { SDJwtInstance } from '@hopae/sd-jwt-core';
import { DisclosureFrame } from '@hopae/sd-jwt-type';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
3 changes: 2 additions & 1 deletion examples/kb.ts → examples/core-example/kb.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DisclosureFrame, SDJwtInstance } from '@hopae/sd-jwt';
import { SDJwtInstance } from '@hopae/sd-jwt-core';
import { DisclosureFrame } from '@hopae/sd-jwt-type';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
7 changes: 4 additions & 3 deletions examples/package.json → examples/core-example/package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "sdjwt-examples",
"name": "sdjwt-core-examples",
"version": "1.0.0",
"description": "",
"main": "index.js",
"private": true,
"scripts": {
"prepare": "cd ../ && pnpm install && pnpm build",
"basic": "ts-node basic.ts",
"all": "ts-node all.ts",
"sdjwtobject": "ts-node sdjwtobject.ts",
Expand All @@ -23,6 +23,7 @@
"typescript": "^5.3.3"
},
"dependencies": {
"@hopae/sd-jwt": "link:.."
"@hopae/sd-jwt-core": "workspace:*",
"@hopae/sd-jwt-type": "workspace:*"
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { DisclosureFrame, SDJwtInstance } from '@hopae/sd-jwt';
import { SDJwtInstance } from '@hopae/sd-jwt-core';
import { DisclosureFrame } from '@hopae/sd-jwt-type';
import { createSignerVerifier, digest, generateSalt } from './utils';

(async () => {
Expand Down
8 changes: 8 additions & 0 deletions examples/core-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"references": [
{
"path": "../../packages/core"
}
]
}
4 changes: 2 additions & 2 deletions examples/utils.ts → examples/core-example/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import Crypto from 'node:crypto';
import { Signer, Verifier } from '@hopae/sd-jwt';
import Crypto from 'crypto';
import { Signer, Verifier } from '@hopae/sd-jwt-type';

export const createSignerVerifier = () => {
const { privateKey, publicKey } = Crypto.generateKeyPairSync('ed25519');
Expand Down
9 changes: 9 additions & 0 deletions examples/decode-example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# SD JWT Core Examples

This directory contains decoding example of a SD JWT (only use decode package)

## Run the example

```bash
pnpm run decode
```
23 changes: 23 additions & 0 deletions examples/decode-example/decode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { decodeSdJwt, getClaims } from '@hopae/sd-jwt-decode';
import { digest } from '@hopae/sd-jwt-node-crypto';

(async () => {
const sdjwt =
'eyJ0eXAiOiJzZC1qd3QiLCJhbGciOiJFZERTQSJ9.eyJ0ZXN0Ijp7Il9zZCI6WyJqVEszMHNleDZhYV9kUk1KSWZDR056Q0FwbVB5MzRRNjNBa3QzS3hhSktzIl19LCJfc2QiOlsiME9nMi1ReG95eW1UOGNnVzZZUjVSSFpQLUJuR2tHUi1NM2otLV92RWlzSSIsIkcwZ3lHNnExVFMyUlQxMkZ3X2RRRDVVcjlZc1AwZlVWOXVtQWdGMC1jQ1EiXSwiX3NkX2FsZyI6InNoYS0yNTYifQ.ggEyE4SeDO2Hu3tol3VLmi7NQj56yKzKQDaafocgkLrUBdivghohtzrfcbrMN7CRufJ_Cnh0EL54kymXLGTdDQ~WyIwNGU0MjAzOWU4ZWFiOWRjIiwiYSIsIjEiXQ~WyIwOGE1Yjc5MjMyYjAzYzBhIiwiMSJd~WyJiNWE2YjUzZGQwYTFmMGIwIiwienp6IiwieHh4Il0~WyIxYzdmOTE4ZTE0MjA2NzZiIiwiZm9vIiwiYmFyIl0~WyJmZjYxYzQ5ZGU2NjFiYzMxIiwiYXJyIixbeyIuLi4iOiJTSG96VW5KNUpkd0ZtTjVCbXB5dXZCWGZfZWRjckVvcExPYThTVlBFUmg0In0sIjIiLHsiX3NkIjpbIkpuODNhZkp0OGx4NG1FMzZpRkZyS2U2R2VnN0dlVUQ4Z3UwdVo3NnRZcW8iXX1dXQ~';
const decodedSdJwt = await decodeSdJwt(sdjwt, digest);
console.log('The decoded SD JWT is:');
console.log(JSON.stringify(decodedSdJwt, null, 2));
console.log(
'================================================================',
);

// Get the claims from the SD JWT
const claims = await getClaims(
decodedSdJwt.jwt.payload,
decodedSdJwt.disclosures,
digest,
);

console.log('The claims are:');
console.log(JSON.stringify(claims, null, 2));
})();
23 changes: 23 additions & 0 deletions examples/decode-example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"name": "sdjwt-decode-examples",
"version": "1.0.0",
"description": "",
"main": "index.js",
"private": true,
"scripts": {
"decode": "ts-node decode.ts"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
"@types/node": "^20.10.4",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
},
"dependencies": {
"@hopae/sd-jwt-decode": "workspace:*",
"@hopae/sd-jwt-type": "workspace:*",
"@hopae/sd-jwt-node-crypto": "workspace:*"
}
}
8 changes: 8 additions & 0 deletions examples/decode-example/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "../../tsconfig.json",
"references": [
{
"path": "../../packages/decode"
}
]
}
Loading

0 comments on commit e95cac5

Please sign in to comment.