-
-
Notifications
You must be signed in to change notification settings - Fork 1
Added New RPC for Marking Delegation as Revoked #171
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
base: main
Are you sure you want to change the base?
Conversation
02f55e2 to
d4be06e
Compare
ef7bcf7 to
52417dc
Compare
|
No dependency changes detected. Learn more about Socket for GitHub. 👍 No dependency changes detected in pull request |
| // In case of error, assume not disabled to avoid blocking legitimate operations | ||
| return false; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| 'latest', | ||
| chainId, | ||
| ], | ||
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is definetly a problem. Do we have any function like: findNetworkClientIdByChainId in the snap ? This exists in extension.
| const grantedPermission = | ||
| await profileSyncManager.getAllGrantedPermissions(); | ||
| return grantedPermission as Json[]; | ||
| const getGrantedPermissions = async (params?: Json): Promise<Json> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we add a definition for params with Zod and then validate the params like in grantPermission.
| signerMeta, | ||
| }); | ||
|
|
||
| // Check if the delegation is actually disabled on-chain |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
comment does not match code
|
|
||
| if (!isDelegationDisabled) { | ||
| throw new InvalidInputError( | ||
| `Delegation ${delegationHash} is not disabled on-chain. Cannot process revocation.`, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If its not disabled then its an error? So the logic for this is to only update profile sync and not start a revocation process?
|
|
||
| // Check if any delegation is disabled on-chain | ||
| // For now, we'll check the first delegation. This might need adjustment based on business logic | ||
| const firstDelegation = delegations[0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shouldn't we then just iterate through if there is more then one and validate all?
| ); | ||
| } | ||
|
|
||
| logger.debug( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a bit too much logging here?
| * @param delegationManagerAddress - The address of the DelegationManager contract. | ||
| * @returns True if the delegation is disabled, false otherwise. | ||
| */ | ||
| async function checkDelegationDisabledOnChain( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually maybe it would be better for this to be in: blockchainMetadataClient which also has a retry and check we are on the correct chain?
| * @param isRevoked - The new revocation status. | ||
| */ | ||
| async function updatePermissionRevocationStatusWithPermission( | ||
| existingPermission: StoredGrantedPermission, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove updatePermissionRevocationStatusWithPermission() function?
Consumers of the revocation flag feature are restricted to the MetaMask client and should only need to call updatePermissionRevocationStatus(permissionContext, isRevoked), which are provided as params on the permissionsProvider_submitRevocation rpc method.
When we allow the consumer to update a permission by providing an existingPermission, the consumer could unintentionally corrupt the user storage (i.e., changing other fields in the permission data).
There is also no check to ensure the item is in the store, which morphs the expected behavior of an 'update' function into a proxy for creating a new store entry. The only field the consumer can update is the isRevoked flag, but this function escalates that privilege to allow mutation of other properties.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have created a branch against your PR with my suggestions. Here is the commit: c628a5a
| * @param params - The parameters for the revocation. | ||
| * @returns Success confirmation. | ||
| */ | ||
| const submitRevocation = async (params: Json): Promise<Json> => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the submitRevocation() function can be simplified further by moving onchain check business logic to the updatePermissionRevocationStatus() function in profile sync and then calling updatePermissionRevocationStatus() here.
We should check onchain revoke status anytime we attempt to update the isRevoke flag on a storage entry in profile sync, not just on rpc calls.
Description
This PR implements the
isRevokedflag feature for permissions stored in profile sync to ensure off-chain storage stays in sync with on-chain contract state after revocation transactions reach finality.Key Changes:
isRevokedflag to theStoredGrantedPermissiontype that defaults tofalsewhen permissions are storedpermissionsProvider_submitRevocationaccessible only by the MetaMask origin to update the revocation statusThe RPC method validates the delegation hash, fetches the existing permission, verifies the delegation is disabled on-chain via the delegation manager contract, and updates the permission's
isRevokedstatus totrue.Related issues
Fixes: #357
Manual testing steps
permissionsProvider_submitRevocationRPC method with the delegation hashisRevokedflag is set totruein profile syncScreenshots/Recordings
Before
After
isRevokedboolean flag (defaults tofalse)permissionsProvider_submitRevocationallows MetaMask to update revocation statusPre-merge author checklist
Pre-merge reviewer checklist
Additional Technical Details:
Note
Adds isRevoked tracking to stored permissions and a MetaMask-only permissionsProvider_submitRevocation RPC with on-chain validation and filtering support.
src/profileSync/profileSync.ts):isRevokedtoStoredGrantedPermission; defaultfalsewhen storing.updatePermissionRevocationStatus(…)and optimizedupdatePermissionRevocationStatusWithPermission(…).checkDelegationDisabledOnChain(…)usingeth_call; injectethereumProviderviacreateProfileSyncManagerconfig.generateObjectKeyand improve auth error logging.RpcMethod.PermissionsProviderSubmitRevocationand binding insrc/index.ts.src/rpc/permissions.tstometamaskorigin.getGrantedPermissions(params?)to support filters:isRevoked,siteOrigin,chainId,delegationManager.submitRevocation(params)insrc/rpc/rpcHandler.ts: validate params, fetch permission, verify delegation disabled on-chain, then markisRevoked=true.src/utils/validate.ts):validateRevocationParams(hexpermissionContext) with Zod-based errors.ethereumtocreateProfileSyncManagerinsrc/index.ts.Written by Cursor Bugbot for commit 5059b2b. This will update automatically on new commits. Configure here.