Skip to content

Commit

Permalink
fix: fixed helper build issues
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyas-londhe committed Sep 26, 2024
1 parent 93a6d88 commit 1da53f5
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/helpers/src/input-generators.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);
Expand Down Expand Up @@ -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
Expand Down
17 changes: 13 additions & 4 deletions packages/helpers/src/jwt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function generateJWT(header: object, payload: object): JWTComponents {
);

const signature = key.sign(
`${headerString}.${payloadString}`,
Buffer.from(`${headerString}.${payloadString}`),
"base64",
"utf8"
);
Expand All @@ -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),
},
};
}

/**
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 1da53f5

Please sign in to comment.