Allow scope type parameter to be passed as a string as well as enum reference
#137
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.
📝 Description
#133 updates the
ScopeConfigtype to require thetypeparameter be passed as an enum reference. This PR updates this configuration type to also allow the enum value to be passed.This allows developers to pass either:
🔄 What Changed?
Left the scope configurations and functions as is for simplicity, and just updated the
ScopeConfigtype (which is an argument oncreateDelegation()function) to accept both the enum reference and the enum value.🚀 Why?
This change keeps the devex improvements from the original PR while aligning with established viem conventions. viem commonly uses string literal unions for parameters, and developers in that ecosystem generally expect to pass string values directly. Supporting both the enum reference and its string value preserves backwards compatibility, reduces friction for existing users, and adds flexibility without detracting from the value of the enum-based API.
🧪 How to Test?
Describe how to test these changes:
The
createDelegationfunction should operate as documented, but optionally accept the enumScopeTypeas thetypeparameter.This should no longer be breaking. If accepted, the parent PR may be marked as non-breaking.
📋 Checklist
Check off completed items:
🔗 Related Issues
Link to related issues:
Closes #
Related to #
📚 Additional Notes
Any additional information, concerns, or context:
Note
Low Risk
Low risk: primarily a TypeScript typing/normalization change that widens accepted inputs for scope configs; runtime behavior is unchanged aside from accepting enum-equivalent strings.
Overview
Expands
ScopeConfiginputs to accept eitherScopeTypeenum members or their string values (e.g.'erc20TransferAmount').Adds a small normalization step in
createCaveatBuilderFromScopeto coerce the inputtypeback toScopeTypebefore switching/dispatching to the specific caveat builder.Updates tests to cover creating delegations with string scope types and removes a few unnecessary
as Hexassertions in expectations.Written by Cursor Bugbot for commit 4f32037. This will update automatically on new commits. Configure here.