MetaMask / MetaMask/smart-accounts-kit

Add utility functions to improve DX for Advanced Permissions

Open
#181 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
63
Forks
45
Avg merge
4d 15h
Merged PRs (30d)
2

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:**
```typescript
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:**
```typescript
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

Contributor guide

Open the contributing guide

Research direction

Start by reading PermissionContext and decodeDelegations in packages/smart-accounts-kit/src/delegation.ts, then compare timestamp handling in caveatBuilder/timestampBuilder.ts and packages/delegation-core/src/caveats/timestamp.ts. Review the related action files for existing caveat utilities. Done means both utilities work with the documented permission response or rules, return null or true when no expiry exists, and validate expiry against the current timestamp.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
developer-experience
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.