Skip to content

Commit

Permalink
fix: missing y coordinate when restoring a public key
Browse files Browse the repository at this point in the history
Signed-off-by: Francisco Javier Ribo Labrador <[email protected]>
  • Loading branch information
elribonazo committed Feb 6, 2025
1 parent 4fa5b1d commit 5be619a
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/pollux/utils/jwt/JWTCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ export abstract class JWTCore {
if (!privateKey.isSignable()) {
throw new Error("Cannot sign with this key");
}
const signature = privateKey.sign(Buffer.from(data));
const signature = Uint8Array.from(
privateKey.sign(Buffer.from(data))
);
const signatureEncoded = base64url.baseEncode(signature)
return signatureEncoded
},
Expand Down Expand Up @@ -130,18 +132,24 @@ export abstract class JWTCore {
return pk
}
if (verificationMethod.publicKeyJwk) {
const { crv, x } = verificationMethod.publicKeyJwk;
const { crv, x, y } = verificationMethod.publicKeyJwk;
const rawKeyProperties = x !== undefined && y !== undefined ? {
[KeyProperties.curvePointX]: base64url.baseDecode(x!),

Check warning on line 137 in src/pollux/utils/jwt/JWTCore.ts

View workflow job for this annotation

GitHub Actions / Build and test

Forbidden non-null assertion
[KeyProperties.curvePointY]: base64url.baseDecode(y!)

Check warning on line 138 in src/pollux/utils/jwt/JWTCore.ts

View workflow job for this annotation

GitHub Actions / Build and test

Forbidden non-null assertion
} : {
[KeyProperties.rawKey]: base64url.baseDecode(x!)

Check warning on line 140 in src/pollux/utils/jwt/JWTCore.ts

View workflow job for this annotation

GitHub Actions / Build and test

Forbidden non-null assertion
}
if (crv === Curve.ED25519) {
pk = this.apollo.createPublicKey({
[KeyProperties.curve]: Curve.ED25519,
[KeyProperties.type]: KeyTypes.EC,
[KeyProperties.rawKey]: base64url.baseDecode(x!)
...rawKeyProperties
})
} else if (crv === Curve.SECP256K1) {
pk = this.apollo.createPublicKey({
[KeyProperties.curve]: Curve.SECP256K1,
[KeyProperties.type]: KeyTypes.EC,
[KeyProperties.rawKey]: base64url.baseDecode(x!)
...rawKeyProperties
})
}
return pk
Expand Down

0 comments on commit 5be619a

Please sign in to comment.