diff --git a/packages/helpers/src/input-generators.ts b/packages/helpers/src/input-generators.ts index e78eeb6..99403c2 100644 --- a/packages/helpers/src/input-generators.ts +++ b/packages/helpers/src/input-generators.ts @@ -79,7 +79,7 @@ export async function generateJWTVerifierInputs( let isVerified; try { isVerified = await verifyJWT(rawJWT, publicKey); - } catch (error) { + } catch (error: any) { throw new JWTVerificationError( `JWT verification failed: ${error.message}` ); @@ -152,7 +152,7 @@ export async function generateJWTVerifierInputs( nonceKeyStartIndex: nonceKeyStartIndex.toString(), commandLength: commandLength.toString(), }; - } catch (error) { + } catch (error: any) { if ( error instanceof JWTVerificationError || error instanceof InvalidInputError diff --git a/packages/helpers/src/jwt.ts b/packages/helpers/src/jwt.ts index 37b4400..692689f 100644 --- a/packages/helpers/src/jwt.ts +++ b/packages/helpers/src/jwt.ts @@ -32,7 +32,7 @@ export function generateJWT(header: object, payload: object): JWTComponents { ); const signature = key.sign( - `${headerString}.${payloadString}`, + Buffer.from(`${headerString}.${payloadString}`), "base64", "utf8" ); @@ -43,7 +43,16 @@ export function generateJWT(header: object, payload: object): JWTComponents { e: key.exportKey("components").e, }; - return { rawJWT, publicKey }; + return { + rawJWT, + publicKey: { + ...publicKey, + e: + typeof publicKey.e === "number" + ? publicKey.e + : parseInt(publicKey.e.toString("hex"), 16), + }, + }; } /** @@ -77,9 +86,9 @@ export async function verifyJWT( try { const isValidSignature = key.verify( Buffer.from(dataToVerify), - Buffer.from(signatureString, "base64"), + signatureString, "utf8", - "buffer" + "base64" ); const isValidBase64 = /^[A-Za-z0-9+/]*={0,2}$/.test(signatureString);