Skip to content

Commit d4be06e

Browse files
committed
docs: added console logs
1 parent a8d855a commit d4be06e

File tree

4 files changed

+94
-7
lines changed

4 files changed

+94
-7
lines changed

packages/gator-permissions-snap/src/index.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,28 @@ export const onRpcRequest: OnRpcRequestHandler = async ({
208208
request,
209209
}) => {
210210
logger.debug(`RPC request (origin="${origin}"): method="${request.method}"`);
211+
console.log('SNAP================================================1');
212+
logger.debug('🔍 Detailed origin info:', {
213+
origin,
214+
originType: typeof origin,
215+
originLength: origin?.length,
216+
method: request.method,
217+
});
218+
console.log('SNAP================================================2');
219+
// Special logging for revocation requests
220+
if (request.method === 'permissionsProvider_submitRevocation') {
221+
logger.debug('🚨 REVOCATION RPC REQUEST DETECTED 🚨');
222+
logger.debug('Origin:', origin);
223+
logger.debug('Origin type:', typeof origin);
224+
logger.debug('Method:', request.method);
225+
logger.debug('Params:', request.params);
226+
}
211227

212228
if (!isMethodAllowedForOrigin(origin, request.method)) {
229+
logger.debug('❌ Permission denied:', {
230+
origin,
231+
method: request.method,
232+
});
213233
throw new InvalidRequestError(
214234
`Origin '${origin}' is not allowed to call '${request.method}'`,
215235
);

packages/gator-permissions-snap/src/rpc/permissions.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import { logger } from '@metamask/7715-permissions-shared/utils';
2+
13
import { RpcMethod } from './rpcMethod';
24

35
const allowedPermissionsByOrigin: { [origin: string]: string[] } = {
@@ -25,5 +27,24 @@ export const isMethodAllowedForOrigin = (
2527
origin: string,
2628
method: string,
2729
): boolean => {
28-
return allowedPermissionsByOrigin[origin]?.includes(method) ?? false;
30+
logger.debug('🔍 Checking origin permissions:', {
31+
origin,
32+
method,
33+
originCharCodes: origin.split('').map((c) => c.charCodeAt(0)),
34+
allowedOrigins: Object.keys(allowedPermissionsByOrigin),
35+
allowedMethodsForOrigin: allowedPermissionsByOrigin[origin],
36+
exactMatch: allowedPermissionsByOrigin[origin],
37+
includesCheck: allowedPermissionsByOrigin[origin]?.includes(method),
38+
});
39+
40+
const isAllowed =
41+
allowedPermissionsByOrigin[origin]?.includes(method) ?? false;
42+
43+
logger.debug('🔍 Permission check result:', {
44+
origin,
45+
method,
46+
isAllowed,
47+
});
48+
49+
return isAllowed;
2950
};

packages/gator-permissions-snap/src/rpc/rpcHandler.ts

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,62 +139,96 @@ export function createRpcHandler(config: {
139139
* @returns Success confirmation.
140140
*/
141141
const submitRevocation = async (params: Json): Promise<Json> => {
142-
logger.debug('submitRevocation()', params);
142+
console.log('================================================2');
143+
logger.debug('=== SUBMIT REVOCATION RPC CALLED ===');
144+
logger.debug('submitRevocation() called with params:', params);
145+
logger.debug('Params type:', typeof params);
146+
logger.debug('Params stringified:', JSON.stringify(params, null, 2));
143147

144148
const { delegationHash } = validateRevocationParams(params);
149+
logger.debug('Validated delegationHash:', delegationHash);
145150

146151
// First, get the existing permission to validate it exists
152+
logger.debug(
153+
'Looking up existing permission for delegationHash:',
154+
delegationHash,
155+
);
147156
const existingPermission =
148157
await profileSyncManager.getGrantedPermissionByDelegationHash(
149158
delegationHash,
150159
);
151160

152161
if (!existingPermission) {
162+
logger.debug(
163+
'❌ Permission not found for delegationHash:',
164+
delegationHash,
165+
);
153166
throw new InvalidInputError(
154167
`Permission not found for delegation hash: ${delegationHash}`,
155168
);
156169
}
157170

171+
logger.debug('✅ Found existing permission:', {
172+
delegationHash,
173+
isRevoked: existingPermission.isRevoked,
174+
siteOrigin: existingPermission.siteOrigin,
175+
});
176+
158177
// Extract delegationManager and chainId from the permission response for logging
159178
const { chainId: permissionChainId, signerMeta } =
160179
existingPermission.permissionResponse;
161180
const { delegationManager } = signerMeta;
162181

163-
logger.debug(
164-
`Found permission - chainId: ${permissionChainId}, delegationManager: ${delegationManager ?? 'undefined'}`,
165-
);
182+
logger.debug('Permission details extracted:', {
183+
chainId: permissionChainId,
184+
delegationManager: delegationManager ?? 'undefined',
185+
signerMeta: signerMeta,
186+
});
166187

167188
// Check if the delegation is actually disabled on-chain
168189
if (!delegationManager) {
190+
logger.debug('❌ No delegation manager found');
169191
throw new InvalidInputError(
170192
`No delegation manager found for delegation hash: ${delegationHash}`,
171193
);
172194
}
173195

196+
logger.debug('Checking if delegation is disabled on-chain...', {
197+
delegationHash,
198+
chainId: permissionChainId,
199+
delegationManager,
200+
});
201+
174202
const isDelegationDisabled =
175203
await profileSyncManager.checkDelegationDisabledOnChain(
176204
delegationHash,
177205
permissionChainId,
178206
delegationManager,
179207
);
180208

209+
logger.debug('On-chain check result:', { isDelegationDisabled });
210+
181211
if (!isDelegationDisabled) {
212+
logger.debug('❌ Delegation is not disabled on-chain');
182213
throw new InvalidInputError(
183214
`Delegation ${delegationHash} is not disabled on-chain. Cannot process revocation.`,
184215
);
185216
}
186217

187218
logger.debug(
188-
`Processing revocation for delegation ${delegationHash} - validated on-chain`,
219+
'✅ Delegation is disabled on-chain, proceeding with revocation',
189220
);
190221

191222
// Update the permission's revocation status using the optimized method
192223
// This avoids re-fetching the permission we already have
224+
logger.debug('Updating permission revocation status to true...');
193225
await profileSyncManager.updatePermissionRevocationStatusWithPermission(
194226
existingPermission,
195227
true,
196228
);
197229

230+
logger.debug('✅ Revocation completed successfully');
231+
logger.debug('=== SUBMIT REVOCATION RPC COMPLETED ===');
198232
return { success: true };
199233
};
200234

packages/gator-permissions-snap/src/utils/validate.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@ import {
22
type RequestExecutionPermissionsParam,
33
zRequestExecutionPermissionsParam,
44
} from '@metamask/7715-permissions-shared/types';
5-
import { extractZodError } from '@metamask/7715-permissions-shared/utils';
5+
import {
6+
extractZodError,
7+
logger,
8+
} from '@metamask/7715-permissions-shared/utils';
69
import type { Hex } from '@metamask/delegation-core';
710
import { InvalidInputError, type Json } from '@metamask/snaps-sdk';
811
import { z } from 'zod';
@@ -53,15 +56,24 @@ export function validateRevocationParams(params: Json): {
5356
delegationHash: Hex;
5457
} {
5558
try {
59+
console.log('================================================3');
60+
logger.debug('🔍 Validating revocation params:', params);
61+
logger.debug('Params type:', typeof params);
62+
5663
if (!params || typeof params !== 'object') {
64+
logger.debug('❌ Invalid params: not an object');
5765
throw new InvalidInputError('Parameters are required');
5866
}
5967

68+
logger.debug('✅ Params is valid object, parsing with Zod...');
6069
const validated = zRevocationParams.parse(params);
70+
logger.debug('✅ Zod validation successful:', validated);
71+
6172
return {
6273
delegationHash: validated.delegationHash as Hex,
6374
};
6475
} catch (error) {
76+
logger.debug('❌ Validation failed:', error);
6577
if (error instanceof z.ZodError) {
6678
throw new InvalidInputError(extractZodError(error.errors));
6779
}

0 commit comments

Comments
 (0)