Skip to content

Commit

Permalink
feat: create kb jwt when present all (#129)
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 3461da1 commit 72ed1ad
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 3 deletions.
8 changes: 5 additions & 3 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,17 +146,19 @@ export class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
kb?: KBOptions;
},
): Promise<SDJWTCompact> {
if (!presentationKeys) return encodedSDJwt;
if (!this.userConfig.hasher) {
throw new SDJWTException('Hasher not found');
}
const hasher = this.userConfig.hasher;

const sdjwt = await SDJwt.fromEncode(encodedSDJwt, hasher);

const sortedpresentationKeys =
presentationKeys?.sort() ?? (await sdjwt.presentableKeys(hasher));

if (!sdjwt.jwt?.payload) throw new SDJWTException('Payload not found');
const presentSdJwtWithoutKb = await sdjwt.present(
presentationKeys.sort(),
sortedpresentationKeys,
hasher,
);

Expand All @@ -171,7 +173,7 @@ export class SDJwtInstance<ExtendedPayload extends SdJwtPayload> {
);

sdjwt.kbJwt = await this.createKBJwt(options.kb, sdHashStr);
return sdjwt.present(presentationKeys.sort(), hasher);
return sdjwt.present(sortedpresentationKeys, hasher);
}

// This function is for verifying the SD JWT
Expand Down
38 changes: 38 additions & 0 deletions packages/core/src/test/index.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -525,4 +525,42 @@ describe('index', () => {
expect(keys).toBeDefined();
expect(keys).toEqual(['foo']);
});

test('present all disclosures with kb jwt', async () => {
const { signer } = createSignerVerifier();
const sdjwt = new SDJwtInstance<SdJwtPayload>({
signer,
kbSigner: signer,
hasher: digest,
saltGenerator: generateSalt,
signAlg: 'EdDSA',
kbSignAlg: 'EdDSA',
});
const credential = await sdjwt.issue(
{
foo: 'bar',
iss: 'Issuer',
iat: new Date().getTime(),
vct: '',
},
{
_sd: ['foo'],
},
);

const presentation = await sdjwt.present(credential, undefined, {
kb: {
payload: {
aud: '1',
iat: 1,
nonce: '342',
},
},
});

const decoded = await sdjwt.decode(presentation);
expect(decoded.jwt).toBeDefined();
expect(decoded.disclosures).toBeDefined();
expect(decoded.kbJwt).toBeDefined();
});
});

0 comments on commit 72ed1ad

Please sign in to comment.