Skip to content

Conversation

@hanzel98
Copy link
Contributor

@hanzel98 hanzel98 commented Nov 19, 2025

Explanation

This PR export the delegation framework version and skips the rules from the sanitization of the permissions response. The rules include the expiry.

Solution

This PR introduces:

  1. Skip rules from sanitization

    • The rules is part of the permission stored in the profile sync it includes the expiration date
  2. DELEGATION_FRAMEWORK_VERSION constant

    • Moved to new constants.ts file to prevent circular dependencies
    • Ensures version consistency across implementations

References

Checklist

  • I've updated the test suite for new or updated code as appropriate
  • I've updated documentation (JSDoc, Markdown, etc.) for new or updated code as appropriate
  • I've communicated my changes to consumers by updating changelogs for packages I've changed, highlighting breaking changes as necessary
  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes (not applicable - no breaking changes)

Note

Exports DELEGATION_FRAMEWORK_VERSION, preserves rules in sanitized permission responses, and adds robust expiry extraction/validation for TimestampEnforcer with expanded tests.

  • Core:
    • Constants: Move DELEGATION_FRAMEWORK_VERSION to src/constants.ts; update imports and re-export from src/index.ts.
    • Sanitization: Update #sanitizeStoredGatorPermission and PermissionResponseSanitized to remove only dependencyInfo and signer (retain rules).
    • Decoding: Add extractExpiryFromCaveatTerms and use it in getPermissionDataAndExpiry; enforce exact terms length, zero timestampAfterThreshold, and safe integer parsing; support large valid expiries.
  • Tests:
    • Update imports to use constants; add/adjust cases for detailed expiry validation (length too short/long, non-zero after-threshold, non-hex terms, unsafe integers, large valid timestamp).
  • Docs/Meta:
    • Update CHANGELOG.md to note rules inclusion in PermissionResponseSanitized and exported DELEGATION_FRAMEWORK_VERSION.

Written by Cursor Bugbot for commit 30f23bc. This will update automatically on new commits. Configure here.

@hanzel98 hanzel98 requested review from a team as code owners November 19, 2025 21:37
@hanzel98 hanzel98 self-assigned this Nov 19, 2025
@hanzel98 hanzel98 requested review from MoMannn and mj-kiwi November 19, 2025 22:42
@hanzel98 hanzel98 changed the title feat: add expiry extraction utilities to gator-permissions-controller chore: Add Expiry Extraction Utilities to gator-permissions-controller Nov 19, 2025
mj-kiwi
mj-kiwi previously approved these changes Nov 19, 2025
Copy link

@mj-kiwi mj-kiwi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hanzel98 hanzel98 requested a review from mj-kiwi November 20, 2025 05:43
Copy link
Contributor

@MoMannn MoMannn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that instead of a util function the expiry should be decoded and saved under Rules in the permission. So that anyone fetching the permissions would already get decoded expiry and does not need to decode every time.

- Export extractExpiryFromPermissionContext to extract expiry from delegation contexts
- Export DELEGATION_FRAMEWORK_VERSION constant for consistency
- Add extractExpiryFromCaveatTerms helper for parsing TimestampEnforcer terms
- Add validation for terms length (must be exactly 32 bytes)
- Add overflow protection for timestamps exceeding Number.MAX_SAFE_INTEGER
- Add comprehensive test coverage for new functions
- Refactor existing code to use new shared expiry extraction logic
- Fix import of DELEGATION_FRAMEWORK_VERSION in test file
- Remove redundant Number.isSafeInteger check (hexToNumber already validates)
- Update extractExpiry tests to reflect actual error behavior
- Update error message tests in decodePermission.test.ts
- Add tests with real encoded delegations using encodeDelegations
- Cover success case: extraction from valid context with timestamp caveat
- Cover edge cases: no timestamp caveat, zero expiry, multiple delegations
- Cover error cases: invalid context, unsupported chain, malformed data
- This increases coverage for lines 276-299 in decodePermission.ts
- Add test mocking decodeDelegations to return array with undefined element
- This covers line 278: the defensive check for null/undefined delegation
- Should achieve 100% code coverage
…sionResponseSanitized

- Export DELEGATION_FRAMEWORK_VERSION constant for version consistency
- Include rules property in PermissionResponseSanitized for stronger typing
- Remove extractExpiryFromPermissionContext (no longer needed)
- Keep extractExpiryFromCaveatTerms as internal implementation detail
- Update tests and remove unused exports
- Fix linting issues
@hanzel98 hanzel98 force-pushed the feat/gator-permissions-expiry-extraction branch from a544388 to b90b881 Compare November 20, 2025 17:04
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For consistency I would move this tests to decodePermission.test.ts since the method is in that coresponsing file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure

* @returns The expiry timestamp in seconds, or null if no valid expiry exists
* @throws If the terms are not exactly 32 bytes or if the timestampAfterThreshold is non-zero
*/
export const extractExpiryFromCaveatTerms = (terms: Hex): number | null => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This probably does not need to be exported now? Or if we still want it to be usable as a package then it would also need to be exported in index but I don't think we need that now.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

- Move extractExpiryFromCaveatTerms tests to decodePermission.test.ts for consistency
- Make extractExpiryFromCaveatTerms internal (remove export) as it's only used within decodePermission.ts
- Add comprehensive edge case tests through getPermissionDataAndExpiry:
  - Terms too short/long validation
  - Safe integer validation for expiry timestamps
  - Large valid timestamp handling
- Delete separate extractExpiry.test.ts file
- All 49 tests passing with 100% coverage of extraction logic
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants