Skip to content

feat: @metamask/delegation-core encoders and decoders now accept periodDuration as bigint#227

Merged
jeffsmale90 merged 2 commits into
mainfrom
feat/period-duration-as-bigint
May 11, 2026
Merged

feat: @metamask/delegation-core encoders and decoders now accept periodDuration as bigint#227
jeffsmale90 merged 2 commits into
mainfrom
feat/period-duration-as-bigint

Conversation

@jeffsmale90

@jeffsmale90 jeffsmale90 commented May 10, 2026

Copy link
Copy Markdown
Collaborator

📝 Description

MultiTokenPeriod, NativeTokenPeriodTransfer and Erc20TokenPeriodTransfer enforcers encode periodDuration as UINT256. Because number is the natural type for duration represented as seconds, it was chosen as the periodDuration type for the typescript interface.

There's a case where the enforcer is used to encode a single allowance, where the period duration is simply set as UINT256_MAX - meaning there's no real possibility of a second duration (unless you wait ~3.6 times 10^69 years).

By making the config type generic with default value, the return type of decodeXXX is unchanged, and a caller can specify periodDuration as bigint.

🧪 How to Test?

This is a typing only change, as the encoders already work with periodDuration values specified as bigint. New unit tests invoke the encodeXXX functions with periodDuration as bigint.

⚠️ Breaking Changes

Non breaking.

List any breaking changes:

  • No breaking changes
  • Breaking changes (describe below):

📋 Checklist

Check off completed items:

  • Code follows the project's coding standards
  • Self-review completed
  • Documentation updated (if needed)
  • Tests added/updated
  • Changelog updated (if needed)
  • All CI checks pass

🔗 Related Issues

Link to related issues:
Closes #
Related to #

📚 Additional Notes

Any additional information, concerns, or context:


Note

Low Risk
Low risk typing/API-surface tweak: encoding already uses uint256 and runtime behavior is unchanged; primary impact is TypeScript types and added test coverage.

Overview
Adds bigint support for periodDuration inputs in the MultiTokenPeriod, ERC20TokenPeriodTransfer, and NativeTokenPeriodTransfer terms/encoder APIs by making the term types generic and widening the encoder overloads to number | bigint.

Keeps decode output unchanged (still decoding periodDuration to a number), and adds unit tests to ensure encoding accepts bigint durations and decoding normalizes them back to numbers. The CHANGELOG.md is updated to document the behavior change.

Reviewed by Cursor Bugbot for commit 3a7f12b. Bugbot is set up for automated code reviews on this repo. Configure here.

… as either number of bigint

- erc20tokenPeriodTransfer
- nativeTokenPeriodTransfer
- multiTokenPeriod
- also adds missing tests for erc20TokenPeriodTransfer
@jeffsmale90 jeffsmale90 force-pushed the feat/period-duration-as-bigint branch from cc55536 to 5be332a Compare May 10, 2026 23:45
@jeffsmale90 jeffsmale90 changed the title feat: @metamask/delegation-core encoders and decoders for erc20/native Periodic caveats now accept periodDuration as bigint feat: @metamask/delegation-core encoders and decoders now accept periodDuration as bigint May 10, 2026
@jeffsmale90 jeffsmale90 force-pushed the feat/period-duration-as-bigint branch from 5a3a6da to 3a7f12b Compare May 11, 2026 00:13
@jeffsmale90 jeffsmale90 marked this pull request as ready for review May 11, 2026 01:57
@jeffsmale90 jeffsmale90 requested a review from a team as a code owner May 11, 2026 01:57
@jeffsmale90 jeffsmale90 merged commit dd5b564 into main May 11, 2026
18 checks passed
@jeffsmale90 jeffsmale90 deleted the feat/period-duration-as-bigint branch May 11, 2026 02:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants