diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts index 1fdf44d..fec1606 100644 --- a/packages/core/src/index.ts +++ b/packages/core/src/index.ts @@ -146,7 +146,6 @@ export class SDJwtInstance { kb?: KBOptions; }, ): Promise { - if (!presentationKeys) return encodedSDJwt; if (!this.userConfig.hasher) { throw new SDJWTException('Hasher not found'); } @@ -154,9 +153,12 @@ export class SDJwtInstance { 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, ); @@ -171,7 +173,7 @@ export class SDJwtInstance { ); 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 diff --git a/packages/core/src/test/index.spec.ts b/packages/core/src/test/index.spec.ts index 16d1ab6..ebf9343 100644 --- a/packages/core/src/test/index.spec.ts +++ b/packages/core/src/test/index.spec.ts @@ -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({ + 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(); + }); });