Skip to content

Commit

Permalink
feat: update present example (#142)
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas.J.Han <[email protected]>
Signed-off-by: Mirko Mollik <[email protected]>
  • Loading branch information
lukasjhan authored and cre8 committed Mar 8, 2024
1 parent 10e6288 commit f9ae804
Show file tree
Hide file tree
Showing 14 changed files with 132 additions and 43 deletions.
2 changes: 1 addition & 1 deletion docs/0.x/claims.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## Claims

You can get claims by using `getCliams` method
You can get claims by using `getClaims` method

```ts
const claims = sdjwt.getClaims(encodedSdjwt);
Expand Down
13 changes: 8 additions & 5 deletions docs/0.x/keybinding.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@ const kbPayload = {
aud: 'https://example.com',
nonce: '1234',
custom: 'data',
sd_hash: '1234',
};
const presentedSdJwt = await sdjwt.present(encodedSdjwt, ['id'], {
kb: {
payload: kbPayload,
const presentedSdJwt = await sdjwt.present(
encodedSdjwt,
{ id: true },
{
kb: {
payload: kbPayload,
},
},
});
);
```

## Verify
Expand Down
43 changes: 38 additions & 5 deletions docs/0.x/present.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,53 @@
```ts
const presentedSDJwt = await sdjwt.present(encodedSdjwt, presentationKeys);
const presentedSDJwt = await sdjwt.present(encodedSdjwt, presentationFrame);
```

## Parameters

- encodedSdjwt: encoded SD JWT [string]
- presentationKeys: JSON path key to selectively disclosure [Array<string>] (optional)
- presentationFrame: Represent the properties that should be selectively disclosed [object]

### PresentationFrame

```ts
{
const claims = {
data: {
arr: ['value'];
arr: 'value';
}
}

// The JSON Path of value 'value' is 'data.arr.0'
// To present 'arr' property
const presentationFrame = {
data: {
arr: true
}
}
```

```ts
const claims = {
data: {
arr: 'value';
}
}

// To present 'data' property
const presentationFrame = {
data: true,
}
```

```ts
const claims = {
data: ['A', 'B'],
};

// To present 1st element of 'data' property
const presentationFrame = {
data: {
0: true,
},
};
```

## Returns
Expand Down
31 changes: 21 additions & 10 deletions docs/0.x/sdjwt-instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,27 @@ sdjwt.config({

```ts
type SDJWTConfig = {
omitTyp?: boolean; // omit typ property in JWT header
hasher?: Hasher; // hash function: (data: string) => Promise<string> or string;
hashAlg?: string; // hash algorithm string (e.g. 'SHA-256')
saltGenerator?: SaltGenerator; // salt generate function: (length: number) => string;
signer?: Signer; // sign function: (data: string) => Promise<string> or string;
signAlg?: string; // sign algorithm string (e.g. 'EdDSA')
verifier?: Verifier; // verify function: (data: string, signature: string) => Promise<boolean> or boolean;
kbSigner?: Signer; // optional key binding sign function
kbSignAlg?: string; // optional key binding sign algorithm
kbVerifier?: Verifier; // optional key binding verify function
// omit typ property in JWT header
omitTyp?: boolean;
// hash function: (data: string) => Promise<string> or string;
hasher?: Hasher;
// hash algorithm string (e.g. 'SHA-256')
hashAlg?: string;
// salt generate function: (length: number) => Promise<string> or string;
saltGenerator?: SaltGenerator;
// sign function: (data: string) => Promise<string> or string;
signer?: Signer;
// sign algorithm string (e.g. 'EdDSA')
signAlg?: string;
// verify function: (data: string, signature: string) => Promise<boolean> or boolean;
verifier?: Verifier;
// optional key binding sign function
kbSigner?: Signer;
// optional key binding sign algorithm
kbSignAlg?: string;
// optional key binding verify function: (data: string, sig: string, payload: JwtPayload) => Promise<boolean> or boolean;
// JwtPayload: { cnf?: { jwk: JsonWebKey } }
kbVerifier?: KbVerifier;
};
```

Expand Down
22 changes: 22 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,28 @@ SD-JWT-JS is a [promise-based](https://javascript.info/promise-basics) SD JWT Cl

## Installing

### If you want to use SD-JWT VC for credentials

Using npm:

```bash
npm install @sd-jwt/sd-jwt-vc
```

Using yarn:

```bash
yarn add @sd-jwt/sd-jwt-vc
```

Using pnpm:

```bash
pnpm install @sd-jwt/sd-jwt-vc
```

### Using SD JWT Features Only

Using npm:

```bash
Expand Down
16 changes: 14 additions & 2 deletions examples/present-example/present.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,21 @@ import { digest } from '@sd-jwt/crypto-nodejs';
console.log('The presentable keys are:', keys);

// You can present the SD JWT with the combination of presentable keys
const presentedSdJwt = await present(
const presentedSdJwt = await present<{
foo: string;
test: { zzz: string };
arr: (string | { a: string })[];
}>(
sdjwt,
['foo', 'arr.0', 'arr', 'test.zzz'],
{
foo: true,
arr: {
0: true,
},
test: {
zzz: true,
},
},
digest,
);

Expand Down
4 changes: 2 additions & 2 deletions examples/sd-jwt-example/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ import { createSignerVerifier, digest, generateSalt } from './utils';
console.log('encodedJwt:', credential);

// Holder Receive the credential from the issuer and validate it
// Return a boolean result
// Return a result of header and payload
const validated = await sdjwt.validate(credential);
console.log('validated:', validated);

Expand Down Expand Up @@ -88,7 +88,7 @@ import { createSignerVerifier, digest, generateSalt } from './utils';
// Holder Define the presentation frame to specify which claims should be presented
// The list of presented claims must be a subset of the disclosed claims
// the presentation frame is determined by the verifier or the protocol that was agreed upon between the holder and the verifier
const presentationFrame = ['firstname', 'id'];
const presentationFrame = { firstname: true, id: true };

// Create a presentation using the issued credential and the presentation frame
// return a Encoded SD JWT. Holder send the presentation to the verifier
Expand Down
4 changes: 2 additions & 2 deletions examples/sd-jwt-example/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ import { createSignerVerifier, digest, generateSalt } from './utils';
const credential = await sdjwt.issue(claims, disclosureFrame);

// Holder Receive the credential from the issuer and validate it
// Return a boolean result
// Return a result of header and payload
const valid = await sdjwt.validate(credential);

// Holder Define the presentation frame to specify which claims should be presented
// The list of presented claims must be a subset of the disclosed claims
// the presentation frame is determined by the verifier or the protocol that was agreed upon between the holder and the verifier
const presentationFrame = ['firstname', 'ssn'];
const presentationFrame = { firstname: true, id: true, ssn: true };

// Create a presentation using the issued credential and the presentation frame
// return a Encoded SD JWT. Holder send the presentation to the verifier
Expand Down
4 changes: 2 additions & 2 deletions examples/sd-jwt-example/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import { createSignerVerifier, digest, generateSalt } from './utils';
console.log('encodedJwt:', credential);

// Holder Receive the credential from the issuer and validate it
// Return a boolean result
// Return a result of header and payload
const validated = await sdjwt.validate(credential);
console.log('validated:', validated);

Expand Down Expand Up @@ -65,7 +65,7 @@ import { createSignerVerifier, digest, generateSalt } from './utils';
// Holder Define the presentation frame to specify which claims should be presented
// The list of presented claims must be a subset of the disclosed claims
// the presentation frame is determined by the verifier or the protocol that was agreed upon between the holder and the verifier
const presentationFrame = ['firstname', 'id'];
const presentationFrame = { firstname: true, id: true };

// Create a presentation using the issued credential and the presentation frame
// return a Encoded SD JWT. Holder send the presentation to the verifier
Expand Down
12 changes: 8 additions & 4 deletions examples/sd-jwt-example/kb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,15 @@ import { createSignerVerifier, digest, generateSalt } from './utils';
const sdjwttoken = await sdjwt.decode(encodedSdjwt);
console.log(sdjwttoken);

const presentedSdJwt = await sdjwt.present(encodedSdjwt, ['id'], {
kb: {
payload: kbPayload,
const presentedSdJwt = await sdjwt.present(
encodedSdjwt,
{ id: true },
{
kb: {
payload: kbPayload,
},
},
});
);

const verified = await sdjwt.verify(presentedSdJwt, ['id', 'ssn'], true);
console.log(verified);
Expand Down
4 changes: 2 additions & 2 deletions examples/sd-jwt-vc-example/all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ import { createSignerVerifier, digest, generateSalt } from './utils';
console.log('encodedJwt:', credential);

// Holder Receive the credential from the issuer and validate it
// Return a boolean result
// Return a result of header and payload
const validated = await sdjwt.validate(credential);
console.log('validated:', validated);

Expand Down Expand Up @@ -96,7 +96,7 @@ import { createSignerVerifier, digest, generateSalt } from './utils';
// Holder Define the presentation frame to specify which claims should be presented
// The list of presented claims must be a subset of the disclosed claims
// the presentation frame is determined by the verifier or the protocol that was agreed upon between the holder and the verifier
const presentationFrame = ['firstname', 'id'];
const presentationFrame = { firstname: true, id: true };

// Create a presentation using the issued credential and the presentation frame
// return a Encoded SD JWT. Holder send the presentation to the verifier
Expand Down
4 changes: 2 additions & 2 deletions examples/sd-jwt-vc-example/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ import { createSignerVerifier, digest, generateSalt } from './utils';
);

// Holder Receive the credential from the issuer and validate it
// Return a boolean result
// Return a result of header and payload
const valid = await sdjwt.validate(credential);

// Holder Define the presentation frame to specify which claims should be presented
// The list of presented claims must be a subset of the disclosed claims
// the presentation frame is determined by the verifier or the protocol that was agreed upon between the holder and the verifier
const presentationFrame = ['firstname', 'ssn'];
const presentationFrame = { firstname: true, id: true, ssn: true };

// Create a presentation using the issued credential and the presentation frame
// return a Encoded SD JWT. Holder send the presentation to the verifier
Expand Down
4 changes: 2 additions & 2 deletions examples/sd-jwt-vc-example/custom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { createSignerVerifier, digest, generateSalt } from './utils';
console.log('encodedJwt:', credential);

// Holder Receive the credential from the issuer and validate it
// Return a boolean result
// Return a result of header and payload
const validated = await sdjwt.validate(credential);
console.log('validated:', validated);

Expand Down Expand Up @@ -73,7 +73,7 @@ import { createSignerVerifier, digest, generateSalt } from './utils';
// Holder Define the presentation frame to specify which claims should be presented
// The list of presented claims must be a subset of the disclosed claims
// the presentation frame is determined by the verifier or the protocol that was agreed upon between the holder and the verifier
const presentationFrame = ['firstname', 'id'];
const presentationFrame = { firstname: true, id: true };

// Create a presentation using the issued credential and the presentation frame
// return a Encoded SD JWT. Holder send the presentation to the verifier
Expand Down
12 changes: 8 additions & 4 deletions examples/sd-jwt-vc-example/kb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,15 @@ import { createSignerVerifier, digest, generateSalt } from './utils';
const sdjwttoken = await sdjwt.decode(encodedSdjwt);
console.log(sdjwttoken);

const presentedSdJwt = await sdjwt.present(encodedSdjwt, ['id'], {
kb: {
payload: kbPayload,
const presentedSdJwt = await sdjwt.present(
encodedSdjwt,
{ id: true },
{
kb: {
payload: kbPayload,
},
},
});
);

const verified = await sdjwt.verify(presentedSdJwt, ['id', 'ssn'], true);
console.log(verified);
Expand Down

0 comments on commit f9ae804

Please sign in to comment.