Skip to content

Add utility functions to improve DX for Advanced Permissions #181

@cursor

Description

@cursor

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 null if 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 true if 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.ts
    • packages/smart-accounts-kit/src/actions/getCaveatAvailableAmount.ts
    • packages/smart-accounts-kit/src/delegation.ts (contains decodeDelegations)
    • packages/smart-accounts-kit/src/caveatBuilder/timestampBuilder.ts
    • packages/delegation-core/src/caveats/timestamp.ts
  • References:

    • PermissionContext type: Delegation[] | Hex
    • TimestampEnforcer caveat uses 32 bytes: 16 bytes for afterThreshold, 16 bytes for beforeThreshold

Benefits

  1. Improved Developer Experience: Developers won't need to manually parse caveats to extract common information like expiry
  2. Less Error-Prone: Utilities handle edge cases and parsing logic consistently
  3. Better Ergonomics: Working with permission contexts becomes seamless without manual decoding
  4. Cleaner Code: Applications using the SDK will have cleaner, more readable code

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions