-
-
Notifications
You must be signed in to change notification settings - Fork 256
chore: Add Expiry Extraction Utilities to gator-permissions-controller #7195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
mj-kiwi
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
packages/gator-permissions-controller/src/decodePermission/decodePermission.ts
Outdated
Show resolved
Hide resolved
packages/gator-permissions-controller/src/decodePermission/decodePermission.ts
Show resolved
Hide resolved
MoMannn
left a comment
There was a problem hiding this 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
a544388 to
b90b881
Compare
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
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:
Skip rules from sanitizationDELEGATION_FRAMEWORK_VERSIONconstantconstants.tsfile to prevent circular dependenciesReferences
Checklist
Note
Exports DELEGATION_FRAMEWORK_VERSION, preserves rules in sanitized permission responses, and adds robust expiry extraction/validation for TimestampEnforcer with expanded tests.
DELEGATION_FRAMEWORK_VERSIONtosrc/constants.ts; update imports and re-export fromsrc/index.ts.#sanitizeStoredGatorPermissionandPermissionResponseSanitizedto remove onlydependencyInfoandsigner(retainrules).extractExpiryFromCaveatTermsand use it ingetPermissionDataAndExpiry; enforce exact terms length, zerotimestampAfterThreshold, and safe integer parsing; support large valid expiries.constants; add/adjust cases for detailed expiry validation (length too short/long, non-zero after-threshold, non-hex terms, unsafe integers, large valid timestamp).CHANGELOG.mdto noterulesinclusion inPermissionResponseSanitizedand exportedDELEGATION_FRAMEWORK_VERSION.Written by Cursor Bugbot for commit 30f23bc. This will update automatically on new commits. Configure here.