elysiajs / elysia-jwt

Plugin for Elysia for using JWT Authentication
MIT License
41 stars 16 forks source link

JWT secret accepts string, EdDSA keys require type CryptoKey for signing #2

Open VaronLaStrauss opened 1 year ago

VaronLaStrauss commented 1 year ago

TypeError: Key for the EdDSA algorithm must be of type CryptoKey. Received an instance of Uint8Array

Replicability:

jwt({
      alg: "EdDSA",
      // both have errors
      secret: (await readPrivateKey()), // returns CryptoKey
      // secret: readPrivateKeyToString() // returns string
})
// ...
jwt.sign({}) // error here

Version: "@elysiajs/jwt": "^0.6.3"

pan93412 commented 1 year ago

Fixed by #5. Code example:

const privateKey = await jose.importPKCS8(
  await Bun.file("./keys/your-key.pem").text(),
  "EdDSA"
);

export const setup = new Elysia().use(
  jwt({
    name: "jwt",
    secret: privateKey,
    exp: "1d",
  })
);