diff --git a/packages/sdk/src/api/entities/VCLFinalizeOffersDescriptor.ts b/packages/sdk/src/api/entities/VCLFinalizeOffersDescriptor.ts index 1b0561f..61345ba 100644 --- a/packages/sdk/src/api/entities/VCLFinalizeOffersDescriptor.ts +++ b/packages/sdk/src/api/entities/VCLFinalizeOffersDescriptor.ts @@ -43,7 +43,7 @@ export default class VCLFinalizeOffersDescriptor { const proofJson: any = {}; if (proof) { proofJson[VCLFinalizeOffersDescriptor.KeyProofType] = VCLFinalizeOffersDescriptor.KeyJwt; - proofJson[VCLFinalizeOffersDescriptor.KeyJwt] = proof.signedJwt.serialize(); + proofJson[VCLFinalizeOffersDescriptor.KeyJwt] = proof.encodedJwt; retVal[VCLFinalizeOffersDescriptor.KeyProof] = proofJson } return retVal; diff --git a/packages/sdk/src/api/entities/VCLJwt.ts b/packages/sdk/src/api/entities/VCLJwt.ts index 34a1f03..87085bd 100644 --- a/packages/sdk/src/api/entities/VCLJwt.ts +++ b/packages/sdk/src/api/entities/VCLJwt.ts @@ -31,7 +31,7 @@ export default class VCLJwt { } get jwk(): Dictionary { - return this.header.jwk || JSON.parse("{}") + return this.header.jwk || {} } get header(): Dictionary { diff --git a/packages/sdk/test/entities/VCLJwt.test.ts b/packages/sdk/test/entities/VCLJwt.test.ts index 3bf3065..a5d8681 100644 --- a/packages/sdk/test/entities/VCLJwt.test.ts +++ b/packages/sdk/test/entities/VCLJwt.test.ts @@ -1,7 +1,6 @@ import VCLJwt from "../../src/api/entities/VCLJwt"; import "../../src/impl/extensions/StringExtensions"; -let subject: VCLJwt const jwtWtithKidStr = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCIsImtpZCI6InNvbWVfa2lkIn0.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.lGqyFj2RpmostxLvCcMFym9kWM0bzQcty9a81EdzrhM" const jwtWtihJwkStr = @@ -10,37 +9,38 @@ const jwtWtihJwkStr = describe("test jwt", () => { test("empty jwt", async () => { - subject = VCLJwt.fromEncodedJwt("") - - expect(JSON.stringify(subject.header) == "{}").toBeTruthy() - expect(JSON.stringify(subject.payload) == "{}").toBeTruthy() - expect(subject.signature == "").toBeTruthy() - expect(subject.encodedJwt == "").toBeTruthy() - expect(JSON.stringify(subject.jwk) == "{}").toBeTruthy() - expect(subject.kid == "").toBeTruthy() + const subject = VCLJwt.fromEncodedJwt("") + + expect(subject.header).toStrictEqual({}) + expect(subject.payload).toStrictEqual({}) + expect(subject.signature).toStrictEqual("") + expect(subject.encodedJwt).toStrictEqual("") + expect(subject.jwk).toStrictEqual({}) + expect(subject.kid).toStrictEqual("") }) test("valid jwt with kid", async () => { - subject = VCLJwt.fromEncodedJwt(jwtWtithKidStr) - - expect(JSON.stringify(subject.header) == "{\"alg\":\"HS256\",\"typ\":\"JWT\",\"kid\":\"some_kid\"}").toBeTruthy() - expect(JSON.stringify(subject.payload) == "{\"sub\":\"1234567890\",\"name\":\"John Doe\",\"iat\":1516239022}").toBeTruthy() - expect(subject.signature == "lGqyFj2RpmostxLvCcMFym9kWM0bzQcty9a81EdzrhM").toBeTruthy() - expect(subject.encodedJwt == jwtWtithKidStr).toBeTruthy() - expect(JSON.stringify(subject.jwk) == "{}").toBeTruthy() - expect(subject.kid == "some_kid").toBeTruthy() + const subject = VCLJwt.fromEncodedJwt(jwtWtithKidStr) + + expect(subject.header).toStrictEqual(JSON.parse("{\"alg\":\"HS256\",\"typ\":\"JWT\",\"kid\":\"some_kid\"}")) + expect(subject.payload).toStrictEqual(JSON.parse("{\"sub\":\"1234567890\",\"name\":\"John Doe\",\"iat\":1516239022}")) + expect(subject.signature).toStrictEqual("lGqyFj2RpmostxLvCcMFym9kWM0bzQcty9a81EdzrhM") + expect(subject.encodedJwt).toStrictEqual(jwtWtithKidStr) + expect(subject.jwk).toStrictEqual({}) + expect(subject.kid).toStrictEqual("some_kid") }) test("valid jwt with jwk", async () => { - subject = VCLJwt.fromEncodedJwt(jwtWtihJwkStr) + const subject = VCLJwt.fromEncodedJwt(jwtWtihJwkStr) - expect(JSON.stringify(subject.header) == + expect(subject.header).toStrictEqual( + JSON.parse( "{\"alg\":\"HS256\",\"typ\":\"JWT\",\"jwk\":{\"kty\":\"RSA\",\"use\":\"sig\",\"kid\":\"some_kid\",\"n\":\"zg7-8aYrxuV7H4t...\",\"e\":\"AQAB\"}}" - ).toBeTruthy() - expect(JSON.stringify(subject.payload) == "{\"sub\":\"1234567890\",\"name\":\"John Doe\",\"iat\":1516239022}").toBeTruthy() - expect(subject.signature == "ijeuQTlhK7jpYkRmD_yWFKtluFWLEhjdieZJxkTc9fY").toBeTruthy() - expect(subject.encodedJwt == jwtWtihJwkStr).toBeTruthy() - expect(JSON.stringify(subject.jwk) == "{\"kty\":\"RSA\",\"use\":\"sig\",\"kid\":\"some_kid\",\"n\":\"zg7-8aYrxuV7H4t...\",\"e\":\"AQAB\"}").toBeTruthy() - expect(subject.kid == "some_kid").toBeTruthy() + )) + expect(subject.payload).toStrictEqual(JSON.parse("{\"sub\":\"1234567890\",\"name\":\"John Doe\",\"iat\":1516239022}")) + expect(subject.signature).toStrictEqual("ijeuQTlhK7jpYkRmD_yWFKtluFWLEhjdieZJxkTc9fY") + expect(subject.encodedJwt).toStrictEqual(jwtWtihJwkStr) + expect(subject.jwk).toStrictEqual(JSON.parse("{\"kty\":\"RSA\",\"use\":\"sig\",\"kid\":\"some_kid\",\"n\":\"zg7-8aYrxuV7H4t...\",\"e\":\"AQAB\"}")) + expect(subject.kid).toStrictEqual("some_kid") }) })