Repository navigation
feat: add effect/jose APIs - #9883
Conversation
🦋 Changeset detectedLatest commit: 459da6b The changes in this PR will be included in the next version bump. This PR includes changesets to release 33 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
@effect-bot review |
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
|
/effect-bot |
c1dccc7 to
77651c3
Compare
ec0fd7b to
a46ca5b
Compare
77651c3 to
790c162
Compare
c7af9b9 to
56f1503
Compare
|
Thanks for this. We maintain a substantial in-house OAuth 2 / OpenID Connect stack built on Effect and on 1. Bug:
|
|
Thanks for the quick turnaround. We checked 5cf106c against our points:
The jose tests and Two points from our earlier comment are still open, and they're what keep us on panva for encrypted state:
Are these in scope for this PR, or better as a follow-up? |
|
@eugene1g Thanks for all the detailed feedback, adding all of this stuff. |
|
Thanks @danieljvdm, 6928948 covers everything I raised. I checked One optional idea, for consistency with Nothing else here! I have lots of feedback for the other OAuth PRs if they are expected to go ahead (after a clean rebase) |
790c162 to
d8f433d
Compare
6928948 to
a514934
Compare
Yeah oauth is definitely on the backburner for now, I need to do a lot more work on it but will ping you when I think it's ready for your feedback. Once again, appreciate it! |
4e0ea00 to
3994ca7
Compare
|
@danieljvdm One more pass against the rebased head ( From my bots to yours: 1. Expose (and allow setting) header parameters outside the typed set
For comparison, Suggestion: carry the authenticated header through ( 2.
|
|
Hi @danieljvdm, thanks for putting this together, and for how quickly you've worked through eugene's feedback. Before the 1.
|
842d900 to
5227c52
Compare
3994ca7 to
b973e73
Compare
5227c52 to
0dfd080
Compare
b973e73 to
ae97a0d
Compare
0dfd080 to
e75d84d
Compare
ae97a0d to
a1d8b62
Compare
Keep one representative per new path: canonical base64url members, SPKI and PKCS#8 in DER and PEM, generated secrets, thumbprints per key type, header extensions, and JWS interop for every algorithm. Drop member-by-member and per-format matrices and type assertions that repeat the same signatures.
…lgorithm guard The protected header is now built in one step with the same key order and values. verifyWithKeySet rejects non-asymmetric algorithms through Schema.is(AsymmetricAlgorithm) instead of listing the HMAC algorithms, and the thumbprint docs note that secret-key thumbprints are sensitive.
| * @category models | ||
| * @since 4.1.1 | ||
| */ | ||
| export type KeyResolver<E = never, R = never> = ( |
exportSpki and exportPkcs8 carried three overloads plus an implementation signature apiece. A single signature generic over the format gives the same results for DER, PEM, and a format union, as the type tests pin. No behavior change.
…ced use Jws.sign and Jws.verify get explicit overload-style type annotations in place of the overloaded generator declarations. The Jwe.KeyResolver alias is removed and the resolver function type is written inline on Jwe.decrypt and Jwt.decrypt. Jwt.sign, Jwt.encrypt, Jwk.generateSecret, Jwk.exportPublic and Jwk.exportPrivate are plain Effect.flatMap/map compositions instead of fnUntraced generators. No behavior change. Tests still reference Jwe.KeyResolver and need a follow-up edit.
| }) | ||
| ): Effect.Effect<Redacted.Redacted<SecretJwk>, never, SecureRandom.SecureRandom> => | ||
| Effect.map( | ||
| Effect.flatMap(SecureRandom.SecureRandom, (random) => random.randomBytes(secretKeyLength(algorithm))), |
There was a problem hiding this comment.
This can use SecureRandom.SecureRandom.use. There might be other candidates
| ): Effect.fn.Return<Redacted.Redacted<string>, JoseError.JoseError, KeyRequirements<K>> | ||
| function* signGenerator( | ||
| export const sign: { | ||
| <K extends SigningKey, H extends object & { readonly [P in keyof H]: Schema.Json | undefined } = Header>( |
There was a problem hiding this comment.
This only has one overload, so doesn't need the { ... }. Check for other candidates
…ional An options type with an optional "pem" format may omit the property, in which case exportSpki and exportPkcs8 produce DER. The result type must say so. Fails against the current generic signatures, which infer a PEM-only result.
…t service calls exportSpki and exportPkcs8 return to three overloads, so an optional PEM format yields a DER-or-PEM union instead of promising PEM. Jws.sign and Jws.verify use a plain function-type annotation. Single-use service access goes through Service.use in Jwk, Jwe, and Jws. No behavior change.
…ction Jwks candidate selection ran Schema.is(PublicJwk) on every key in the set for every lookup. Filtering on kty, crv, kid, alg and use first means the schema check only runs on keys that can match. A cached RS256 verifyWithKeySet against a 64-key set drops from ~226µs to ~92µs median, the same as a single-key set. Adds that case to the JOSE benchmark.
Jwks computes the selectable public keys once per local key set and per fetched remote snapshot, so lookups no longer re-run the PublicJwk schema. The JWS and JWE header decoders and the JWT claims decoder are built once at module level. The Jws docs point to the node:crypto Mac layers for HMAC.
|
Huge thanks @danieljvdm for building this, and @tim-smart for the thorough review rounds. It's really great to have JOSE in core now. I did some benchmarking against
Setup
Results (ops/sec, higher is better)
What the numbers mean🟢 HMAC and thumbprints: a clear win with NodeCrypto. ⚪ Asymmetric signing and verification, JWE and JWKS: at parity. Both libraries spend their time in 🟡 Non-crypto paths: slower, by design. |
|
Good job guys! |
Add
effect/joseto the core package with algorithm-bound keys, compact JWS/JWE, schema-typed signed and encrypted JWTs, and local or scoped remote JWKS resolution. Effectful decryption key resolvers support rotation, extension headers are preserved for custom key selection, and decryption returns the selected key. Modules also have direct entrypoints such aseffect/jose/Jwt.