feat: ValidateToken takes options, too#28
Open
Peeja wants to merge 2 commits into
Open
Conversation
This makes it practical to use on its own, outside of `ValidateInvocation` (for validating a delegation, for instance).
frrist
reviewed
May 27, 2026
| cfg := validationConfig{ | ||
| resolveProof: ProofUnavailable, | ||
| resolveDIDVerifier: ResolveDIDKeyVerifier, | ||
| validationTime: ucan.UnixTimestamp(time.Now().Unix()), |
Member
There was a problem hiding this comment.
nit: replace this with ucan.Now()
Comment on lines
+78
to
+84
|
|
||
| // withConfig reuses an entire built [validationConfig]. | ||
| func withConfig(cfg validationConfig) Option { | ||
| return func(vc *validationConfig) { | ||
| *vc = cfg | ||
| } | ||
| } |
Member
There was a problem hiding this comment.
withConfig is wearing an Option "costume" to do something options aren't supposed to do: replace the whole config rather than tweaking a field. That has a few knock-on costs:
- Order-dependent in a way the type can't express.
withConfigonly behaves correctly when it's alone; combined with any real option it either clobbers them or gets clobbered, silently. - Two ways to express the same intent (build from options vs. inject a pre-built struct) for one underlying need.
Can we instead split this, something like:
func ValidateToken(ctx context.Context, tok ucan.Token, options ...Option) error {
return validateToken(ctx, tok, makeCfg(options...))
}
func validateToken(ctx context.Context, tok ucan.Token, cfg validationConfig) error {
// existing body
}Then ValidateInvocation and the proof-chain loop can call validateToken(ctx, …, cfg) directly, and withConfig goes away.
Contributor
Author
There was a problem hiding this comment.
Ah! That's the way to do it. ✨
frrist
approved these changes
Jun 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This makes it practical to use on its own, outside of
ValidateInvocation(for validating a delegation, for instance).Required for fil-forge/sprue#15.
PR Dependency Tree
ValidateTokentakes options, too #28 👈This tree was auto-generated by Charcoal