Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Recover JTI field correctly. Allowing to regenerate the original JWT string #171

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading