Skip to content

throw error in caveat validator when caip25:endowment permission caveat when no scopes are requested#5548

Merged
adonesky1 merged 5 commits intomainfrom
ad/throw-error-when-no-scopes-in-caveat
Mar 25, 2025
Merged

throw error in caveat validator when caip25:endowment permission caveat when no scopes are requested#5548
adonesky1 merged 5 commits intomainfrom
ad/throw-error-when-no-scopes-in-caveat

Conversation

@adonesky1
Copy link
Copy Markdown
Contributor

@adonesky1 adonesky1 commented Mar 25, 2025

Explanation

We need to add further caveat validation to throw when no scopes are requested in either requiredScopes or optionalScopes

References

See this thread: https://consensys.slack.com/archives/C089Q8CQZHT/p1742825693477409

Changelog

@metamask/chain-agnostic-permission

  • ADDED: BREAKING Validation check in caip25CaveatBuilder to prevent creating permission requests with no scopes. This ensures that all CAIP-25 permission requests must specify at least one scope in either requiredScopes or optionalScopes.

  • 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 highlighted breaking changes using the "BREAKING" category above as appropriate

  • I've prepared draft pull requests for clients and consumer packages to resolve any breaking changes

@adonesky1 adonesky1 marked this pull request as ready for review March 25, 2025 16:51
@adonesky1 adonesky1 requested a review from a team as a code owner March 25, 2025 16:51
jiexi
jiexi previously approved these changes Mar 25, 2025
});
}).toThrow(
new Error(
`${Caip25EndowmentPermissionName} error: Received no scopes requested for caveat of type "${Caip25CaveatType}".`,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
`${Caip25EndowmentPermissionName} error: Received no scopes requested for caveat of type "${Caip25CaveatType}".`,
`${Caip25EndowmentPermissionName} error: Received no scopes for caveat of type "${Caip25CaveatType}".`,

ffmcgee725
ffmcgee725 previously approved these changes Mar 25, 2025
Copy link
Copy Markdown
Member

@ffmcgee725 ffmcgee725 left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@adonesky1 adonesky1 enabled auto-merge (squash) March 25, 2025 18:01
@adonesky1 adonesky1 merged commit 7f13d47 into main Mar 25, 2025
193 checks passed
@adonesky1 adonesky1 deleted the ad/throw-error-when-no-scopes-in-caveat branch March 25, 2025 18:06
@adonesky1 adonesky1 mentioned this pull request Mar 25, 2025
adonesky1 added a commit that referenced this pull request Mar 25, 2025
## @metamask/chain-agnostic-permission

## [0.3.0]

### Added

- Export `KnownSessionProperties` enum
([#5522](#5522))
- Add more chain agnostic utility functions for interfacing w/ caip25
permission ([#5536](#5536))
- New `setPermittedAccounts` function that allows setting accounts for
any CAIP namespace, not just EVM scopes.
- New `addPermittedChainId` and `setPermittedChainIds` functions for
managing permitted chains across any CAIP namespace.
- New `generateCaip25Caveat` function to generate a valid
`endowment:caip25` permission caveat from given accounts and chains of
any CAIP namespace.
- New `isWalletScope` utility function to detect wallet-related scopes.

### Changed

- **BREAKING:** An error is now thrown in the caveat validator when a
`caip25:endowment` permission caveat has no scopes in either
`requiredScopes` or `optionalScopes`
([#5548](#5548))
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.

3 participants