Conversation
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
7f7d307 to
b6a1c5d
Compare
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
There was a problem hiding this comment.
adapters probably isn't the best descriptor for these anymore. getters/setters seem more appropriate now, but a problem for later
|
|
||
| updatedScopesObject[scopeString] = { | ||
| ...scopeObject, | ||
| accounts: uniq(caipAccounts), |
There was a problem hiding this comment.
nit. thoughts on doing this uniq call at the top of this helper?
There was a problem hiding this comment.
not sure I follow? Where are you thinking?
| * @param requestedCaip25CaveatValue - CAIP-25 request values. | ||
| * @returns Accounts available for requesting. | ||
| */ | ||
| export function getAllAccountsFromCaip25Caveat( |
There was a problem hiding this comment.
thoughts on just calling this getPermittedAccounts? The ending of this one sticks out from the rest. I can see why getPermittedAccounts might conflict in other contexts though, but maybe that can be fixed with a rename on import by the code that imports this package?
There was a problem hiding this comment.
Agreed that its not a great name, especially since others don't follow that naming convention. I'm going to change it to getAllAccounts for now since really this is used before the caveat is persisted... but it can be used for the caveat persisted or not...
| // If its a wallet scope or a wallet:* scope we don't filter it | ||
| if (isWalletScope(scopeString)) { | ||
| updatedScopesObject[scopeString] = scopeObject; | ||
| } else if (chainIds.includes(scopeString)) { |
There was a problem hiding this comment.
can these two statements be combined into one guard?
|
@metamaskbot publish-preview |
|
Preview builds have been published. See these instructions for more information about preview builds. Expand for full list of packages and versions. |
| }); | ||
| }); | ||
|
|
||
| describe('setPermittedAccounts', () => { |
There was a problem hiding this comment.
is it okay if we add a scenario to setting accounts where there is no scope for that account defined in the caveat?
| }; | ||
|
|
||
| /** | ||
| * Sets the permitted accounts for the given scopes object. |
There was a problem hiding this comment.
worth mentioning the caveat that the scope must already exist in the scopesObject?
| }; | ||
|
|
||
| /** | ||
| * Sets the permitted accounts for the given CAIP-25 caveat value. |
…more-chain-agnostic
## @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))
Explanation
Currently the utility/helper functions we expose to interface with and help construct a valid caip25 permission caveat are very eth/evm centric (i.e.
setPermittedAccounts,addPermittedEthChainId,getPermittedEthChainIdsetc)This PR adds some new helpers that are actually chain agnostic
References
see @david0xd 's PR here
and my extension PR ontop of it that uses these changes:
MetaMask/metamask-extension#31253
@metamask/chain-agnostic-permissioncaip-permission-adapter-eth-accounts.tstocaip-permission-adapter-accounts.tsto better reflect its more generalized functionality.setPermittedAccountsfunction that allows setting accounts for any CAIP namespace, not just EVM scopes.addPermittedChainIdandsetPermittedChainIdsfunctions for managing permitted chains across any CAIP namespace.generateCaip25Caveatfunction to simplify modification of CAIP-25 permissions after UI confirmation.isWalletScopeutility function to detect wallet-related scopes.CHANGED : BREAKING Thecaip25:endowmentpermission caveat validator now throws an error when bothrequiredScopesandoptionalScopescontain no scopes.Moved to another PR: https://github.com/MetaMask/core/pull/5548.diff
Checklist