Skip to content
Merged
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
15 changes: 13 additions & 2 deletions packages/gator-permissions-snap/src/core/accountController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export class AccountController {
): Promise<Delegation> {
logger.debug('AccountController:signDelegation()');

const { chainId, delegation, address } = options;
const { chainId, delegation, address, origin, justification } = options;

const selectedChain = await this.#ethereumProvider.request<Hex>({
method: 'eth_chainId',
Expand Down Expand Up @@ -96,6 +96,8 @@ export class AccountController {
chainId,
delegationManager,
delegation,
origin,
justification,
});

const signature = await this.#ethereumProvider.request<Hex>({
Expand All @@ -117,10 +119,14 @@ export class AccountController {
chainId,
delegationManager,
delegation,
origin,
justification,
}: {
chainId: number;
delegationManager: Hex;
delegation: Omit<Delegation, 'signature'>;
origin: string;
justification: string;
}) {
logger.debug('AccountController:#getSignDelegationArgs()');

Expand Down Expand Up @@ -151,10 +157,15 @@ export class AccountController {
],
};

const metadata = {
origin,
justification,
};

const primaryType = 'Delegation';

const message = { ...delegation, salt: bigIntToHex(delegation.salt) };

return { domain, types, primaryType, message };
return { domain, types, primaryType, message, metadata };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ export class PermissionRequestLifecycleOrchestrator {
lifecycleHandlers,
isAdjustmentAllowed,
chainId,
origin,
});

return {
Expand Down Expand Up @@ -286,9 +287,10 @@ export class PermissionRequestLifecycleOrchestrator {
* @param params - Parameters for resolving the response.
* @param params.originalRequest - The original unmodified permission request.
* @param params.modifiedContext - The possibly modified context after user interaction.
* @param params.lifecycleHandlers - Handlers for the permission lifecycle.
* @param params.isAdjustmentAllowed - Whether the permission can be adjusted.
* @param params.chainId - The chain ID for the permission.
* @param params.origin - The origin of the permission request.
* @param params.lifecycleHandlers - Handlers for the permission lifecycle.
* @returns The resolved permission response.
*/
async #resolveResponse<
Expand All @@ -300,14 +302,16 @@ export class PermissionRequestLifecycleOrchestrator {
>({
originalRequest,
modifiedContext,
lifecycleHandlers,
isAdjustmentAllowed,
chainId,
origin,
lifecycleHandlers,
}: {
originalRequest: TRequest;
modifiedContext: TContext;
isAdjustmentAllowed: boolean;
chainId: number;
origin: string;
lifecycleHandlers: LifecycleOrchestrationHandlers<
TRequest,
TContext,
Expand Down Expand Up @@ -397,11 +401,15 @@ export class PermissionRequestLifecycleOrchestrator {
salt: BigInt(salt),
} as const;

const { justification } = modifiedContext;

const signedDelegation: Delegation =
await this.#accountController.signDelegation({
chainId,
delegation,
address,
origin,
justification,
});

const context = encodeDelegations([signedDelegation], { out: 'hex' });
Expand Down
2 changes: 2 additions & 0 deletions packages/gator-permissions-snap/src/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ export type SignDelegationOptions = {
chainId: number;
delegation: Omit<Delegation, 'signature'>;
address: Hex;
origin: string;
justification: string;
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ describe('AccountController', () => {
const mockSignature =
'0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef11';
const expectedBalance = '0x1000000000000000000';
const origin = 'https://example.com';
const justification = 'Test justification';

let accountController: AccountController;
let mockSnapsProvider: ReturnType<typeof createMockSnapsProvider>;
Expand Down Expand Up @@ -103,6 +105,8 @@ describe('AccountController', () => {
chainId: sepolia,
delegation: unsignedDelegation,
address: mockAddress,
origin,
justification,
});

expect(signedDelegation).toStrictEqual({
Expand All @@ -123,6 +127,8 @@ describe('AccountController', () => {
chainId: sepolia,
delegation: unsignedDelegation,
address: mockAddress,
origin,
justification,
});

expect(signature).toStrictEqual({
Expand All @@ -145,6 +151,8 @@ describe('AccountController', () => {
chainId: sepolia,
delegation: unsignedDelegation,
address: mockAddress,
origin,
justification,
}),
).rejects.toThrow('Failed to sign delegation');
});
Expand All @@ -154,6 +162,8 @@ describe('AccountController', () => {
chainId: sepolia,
delegation: unsignedDelegation,
address: mockAddress,
origin,
justification,
});

expect(mockEthereumProvider.request).toHaveBeenCalledWith({
Expand Down Expand Up @@ -218,6 +228,10 @@ describe('AccountController', () => {
...unsignedDelegation,
salt: '0x1',
},
metadata: {
origin,
justification,
},
},
],
});
Expand Down
Loading