Skip to content

Commit

Permalink
fix: Recover JTI field correctly. Allowing to regenerate the original…
Browse files Browse the repository at this point in the history
… JWT string (#171)
  • Loading branch information
elribonazo committed Feb 8, 2024
1 parent 84efa71 commit 686318e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/pollux/models/JWTVerifiableCredential.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ export const JWTVerifiableCredentialRecoveryId = "jwt+credential";

export class JWTCredential
extends Credential
implements ProvableCredential, StorableCredential
{
implements ProvableCredential, StorableCredential {
public credentialType = CredentialType.JWT;
public recoveryId = JWTVerifiableCredentialRecoveryId;
public properties = new Map<JWTVerifiableCredentialProperties, any>();
Expand All @@ -41,7 +40,7 @@ export class JWTCredential
public readonly originalJWTString?: string
) {
super();

this.properties.set(JWTVerifiableCredentialProperties.jti, jti);
this.properties.set(JWTVerifiableCredentialProperties.iss, iss);
this.properties.set(JWTVerifiableCredentialProperties.sub, sub);
this.properties.set(JWTVerifiableCredentialProperties.nbf, nbf);
Expand Down Expand Up @@ -143,7 +142,7 @@ export class JWTCredential
const credentialData = JSON.stringify(Object.fromEntries(this.properties));

return {
id: this.getProperty(JWTVerifiableCredentialProperties.jti),
id: this.jti || this.getProperty(JWTVerifiableCredentialProperties.jti),
recoveryId: this.recoveryId,
credentialData: credentialData,
issuer: this.getProperty(JWTVerifiableCredentialProperties.iss),
Expand Down
15 changes: 15 additions & 0 deletions tests/pollux/Pollux.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,21 @@ describe("Pollux", () => {
expect(result.issuanceDate).to.equal(issuanceDate);
expect(result.expirationDate).to.equal(expirationDate);
});

it("should be able to recover JTI from a toStorable", async () => {
const result = await pollux.parseCredential(
Buffer.from(Fixtures.Credentials.JWT.credentialPayloadEncoded),
{
type: CredentialType.JWT,
}
) as JWTCredential;

const storable = result.toStorable();

expect(storable).to.be.an("object");
expect(storable).to.have.property("id");
expect(storable.id).to.equal(Fixtures.Credentials.JWT.credentialPayloadEncoded);
});
});
});

Expand Down

1 comment on commit 686318e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines Statements Branches Functions
Coverage: 62%
62.38% (1264/2026) 50.64% (548/1082) 64.47% (372/577)

JUnit

Tests Skipped Failures Errors Time
336 2 💤 0 ❌ 0 🔥 37.481s ⏱️

Please sign in to comment.