diff --git a/packages/chain-agnostic-permission/CHANGELOG.md b/packages/chain-agnostic-permission/CHANGELOG.md index f025aa5a44a..ee3a3ba4bb7 100644 --- a/packages/chain-agnostic-permission/CHANGELOG.md +++ b/packages/chain-agnostic-permission/CHANGELOG.md @@ -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] diff --git a/packages/chain-agnostic-permission/src/caip25Permission.test.ts b/packages/chain-agnostic-permission/src/caip25Permission.test.ts index d7627ed4606..9823811eb15 100644 --- a/packages/chain-agnostic-permission/src/caip25Permission.test.ts +++ b/packages/chain-agnostic-permission/src/caip25Permission.test.ts @@ -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.`, ), ); }); diff --git a/packages/chain-agnostic-permission/src/caip25Permission.ts b/packages/chain-agnostic-permission/src/caip25Permission.ts index 3d709418901..44a90150a72 100644 --- a/packages/chain-agnostic-permission/src/caip25Permission.ts +++ b/packages/chain-agnostic-permission/src/caip25Permission.ts @@ -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.`, ); }