A library extending the ruby-jwt gem with EdDSA algorithms. Based on RFC 8037.
Add the gem to your Gemfile:
gem "jwt-eddsa"
And in your application add the following require:
require "jwt/eddsa"
private_key = Ed25519::SigningKey.new("b" * 32)
token = JWT.encode({pay: "load"}, private_key, "EdDSA")
payload, header = JWT.decode(token, private_key.verify_key, true, algorithm: "EdDSA")Two algorithm names are supported for Ed25519 keys:
EdDSA, from RFC 8037. Most JWT libraries support it.Ed25519, from RFC 9864, which deprecatesEdDSAin favour of names that identify the curve.
The alg header names the algorithm you sign with, in its registered spelling. ruby-jwt looks algorithm names up regardless of case, so signing with Ed25519 or ED25519 writes "alg": "Ed25519", and signing with EdDSA writes "alg": "EdDSA".
JWT.decode only accepts a token whose alg is one of the allowed algorithms, also when the keys come from a JWKS. A token signed with Ed25519 is rejected when only EdDSA is allowed, and the other way round. JWT::EncodedToken#verify_signature! with a key passed directly checks the signature with the allowed algorithms, but does not compare them with the alg header.
An OKP JWK without alg uses EdDSA. To sign or verify Ed25519 tokens with JWT::Token and JWT::EncodedToken using a JWK as the key, create the JWK with alg: "Ed25519". In a JWKS given to jwks:, a JWK without alg verifies tokens with either name.
Signing with Ed25519 or ED25519, or with a JWK whose alg is Ed25519, used to write "alg": "EdDSA". It now writes "alg": "Ed25519". If the tokens you sign must keep "alg": "EdDSA", for example because the verifier only allows EdDSA, sign with EdDSA instead.
OKP JWKs must specify crv: "Ed25519" to provide a signing or verification key.
Requesting a key with a missing or unsupported curve (including X25519 and
Ed448) raises JWT::JWKError. Such JWKs can still be imported, so an unrelated
key in a mixed JWKS does not prevent verification with a selected Ed25519 key.
bundle install
bundle exec rake
Bug reports and pull requests are welcome on GitHub at https://github.com/jwt/ruby-jwt-eddsa. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
In this repository, pull request titles must follow the Conventional Commit specification to ensure clear and consistent communication of changes.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the jwt-eddsa project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.