Skip to content

refactor: descriptive caip25CaveatBuilder unsupported scopes #5806

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/chain-agnostic-permission/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Bump `@metamask/network-controller` to `^23.4.0` ([#5765](https://github.com/MetaMask/core/pull/5765))
- Bump `@metamask/controller-utils` to `^11.8.0` ([#5765](https://github.com/MetaMask/core/pull/5765))
- Change `caip25CaveatBuilder` to list unsupported scopes in the unsupported scopes error ([#5806](https://github.com/MetaMask/core/pull/5806))

## [0.6.0]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -744,7 +744,7 @@ describe('caip25CaveatBuilder', () => {
});
}).toThrow(
new Error(
`${Caip25EndowmentPermissionName} error: Received scopeString value(s) for caveat of type "${Caip25CaveatType}" that are not supported by the wallet.`,
`${Caip25EndowmentPermissionName} error: Received scopeString value(s): eip155:1, bip122:000000000019d6689c085ae165831e93, eip155:5, bip122:12a765e31ffd4059bada1e25190f6e98 for caveat of type "${Caip25CaveatType}" that are not supported by the wallet.`,
),
);
});
Expand Down
19 changes: 8 additions & 11 deletions packages/chain-agnostic-permission/src/caip25Permission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -220,23 +220,20 @@ export const caip25CaveatBuilder = ({
}
};

const allRequiredScopesSupported = Object.keys(requiredScopes).every(
const unsupportedScopes = Object.keys({
...requiredScopes,
...optionalScopes,
}).filter(
(scopeString) =>
isSupportedScopeString(scopeString, {
!isSupportedScopeString(scopeString, {
isEvmChainIdSupported,
isNonEvmScopeSupported,
}),
);
const allOptionalScopesSupported = Object.keys(optionalScopes).every(
(scopeString) =>
isSupportedScopeString(scopeString, {
isEvmChainIdSupported,
isNonEvmScopeSupported,
}),
);
if (!allRequiredScopesSupported || !allOptionalScopesSupported) {

if (unsupportedScopes.length > 0) {
throw new Error(
`${Caip25EndowmentPermissionName} error: Received scopeString value(s) for caveat of type "${Caip25CaveatType}" that are not supported by the wallet.`,
`${Caip25EndowmentPermissionName} error: Received scopeString value(s): ${unsupportedScopes.join(', ')} for caveat of type "${Caip25CaveatType}" that are not supported by the wallet.`,
);
}

Expand Down