-
-
Notifications
You must be signed in to change notification settings - Fork 32
Description
AI Generated; use caution
Overview
While working with the SDK, several developer experience (DX) issues have been identified that could be improved with utility functions. These utilities would make it easier to work with delegations and permission contexts without requiring manual parsing of caveats.
Requested Features
1. Get expiry date from permission response
Problem: Currently, developers need to manually parse the rules in the Advanced Permissions response to get the expiry date.
Proposed Solution: Add a utility function that extracts and returns expiry date given permission response/ rules.
Example API:
const grantedPermissions = await walletClient.requestExecutionPermissions([{
chainId: chain.id,
expiry,
/// ....
}])
const expiryDate = resolvePermissionExpiry(grantedPermissions[0])Notes:
- Should return
nullif no expiry rule is present.
2. Check if permission is valid
Problem: Developers need a simple way to check whether a permission has expired without manually parsing and comparing timestamps.
Proposed Solution: Add a utility function that checks if a permission has expired based on the current time. Should check if the expiry date exist in the rules, and verify the timestamp.
Example API:
const grantedPermissions = await walletClient.requestExecutionPermissions([{
chainId: chain.id,
expiry,
/// ....
}])
isValid: boolean = isPermissionValid(grantedPermissions[0]);Notes:
- Should return
trueif no expiry rule is found (permission doesn't expire) - Should check against the current timestamp
Additional Context
-
Related Files:
packages/smart-accounts-kit/src/actions/caveatEnforcerClient.tspackages/smart-accounts-kit/src/actions/getCaveatAvailableAmount.tspackages/smart-accounts-kit/src/delegation.ts(containsdecodeDelegations)packages/smart-accounts-kit/src/caveatBuilder/timestampBuilder.tspackages/delegation-core/src/caveats/timestamp.ts
-
References:
PermissionContexttype:Delegation[] | HexTimestampEnforcercaveat uses 32 bytes: 16 bytes forafterThreshold, 16 bytes forbeforeThreshold
Benefits
- Improved Developer Experience: Developers won't need to manually parse caveats to extract common information like expiry
- Less Error-Prone: Utilities handle edge cases and parsing logic consistently
- Better Ergonomics: Working with permission contexts becomes seamless without manual decoding
- Cleaner Code: Applications using the SDK will have cleaner, more readable code