feat(engine): Add JSON Web Token (JWT) token generation and validation support #612
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Closes #599
Solution
Implements JSON Web Token utilities in the
rpc-types-engine
crate. Only focuses on JWT token generation and validation, not the auth layer as the generated token is used as a string in bearer auth.Largely uses the JWT secret implementation by Reth with some enhancements to documentation and using built-in
get_current_timestamp
. Notably does not implement loading from file, reading from file or writing to file as that is out of scope for Alloy I feel.Regarding the defined limitations on the algorithm and length, I've kept that 1:1 with the Reth implementation to make sure it can be used in that context and the limitations seem reasonable enough for a more general case.
See for reference: https://github.com/paradigmxyz/reth/blob/79452eadaf4963f1e8d78a18b1f490d7c560aa54/crates/rpc/rpc/src/layers/jwt_secret.rs
Proposed API:
Where
Claims::default()
is a claim defined as:Claim { iat: get_current_timestamp(), exp: None }
The
random()
syntax is consistent with other places that uses it (Address::random()
, etc..)PR Checklist