Skip to content

Commit 53aa57e

Browse files
committed
Remove option to invoke snaps, and only support invoking wallet_requestExecutionPermissions on the walletApi
1 parent a197a06 commit 53aa57e

File tree

5 files changed

+285
-883
lines changed

5 files changed

+285
-883
lines changed

packages/delegation-toolkit/src/experimental/erc7715RequestExecutionPermissionsAction.ts

Lines changed: 48 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,47 @@ import type {
99
PermissionTypes,
1010
Rule,
1111
} from '@metamask/7715-permission-types';
12-
import { isHex, toHex, type Address } from 'viem';
12+
import { isHex, toHex } from 'viem';
13+
import type {
14+
Client,
15+
Account,
16+
RpcSchema,
17+
Transport,
18+
Chain,
19+
Address,
20+
} from 'viem';
1321

14-
import type { MetaMaskExtensionClient } from './snapsAuthorization.js';
22+
/**
23+
* RPC schema for MetaMask related methods.
24+
*
25+
* Extends the base RPC schema with methods specific to interacting with EIP-7715:
26+
* - `wallet_invokeSnap`: Invokes a method on a specific Snap.
27+
*/
28+
export type MetaMaskExtensionSchema = RpcSchema &
29+
[
30+
{
31+
// eslint-disable-next-line @typescript-eslint/naming-convention
32+
Method: 'wallet_requestExecutionPermissions';
33+
// eslint-disable-next-line @typescript-eslint/naming-convention
34+
Params: PermissionRequest<AccountSigner, PermissionTypes>[];
35+
// eslint-disable-next-line @typescript-eslint/naming-convention
36+
ReturnType: PermissionResponse<AccountSigner, PermissionTypes>[];
37+
},
38+
];
39+
40+
/**
41+
* A Viem client extended with MetaMask Snap-specific RPC methods.
42+
*
43+
* This client type allows for interaction with MetaMask Snaps through
44+
* the standard Viem client interface, with added type safety for
45+
* Snap-specific methods.
46+
*/
47+
export type MetaMaskExtensionClient = Client<
48+
Transport,
49+
Chain | undefined,
50+
Account | undefined,
51+
MetaMaskExtensionSchema
52+
>;
1553

1654
type PermissionParameter = {
1755
type: string;
@@ -125,44 +163,24 @@ export type RequestExecutionPermissionsReturnType = PermissionResponse<
125163
* @template Signer - The type of the signer, either an Address or Account.
126164
* @param client - The client to use for the request.
127165
* @param parameters - The permissions requests to grant.
128-
* @param kernelSnapId - The ID of the kernel snap to invoke, undefined to request via the wallet RPC method.
129166
* @returns A promise that resolves to the permission responses.
130167
* @description
131-
* This function formats the permissions requests and invokes the wallet snap to grant permissions.
168+
* This function formats the permissions requests and invokes the wallet method to grant permissions.
132169
* It will throw an error if the permissions could not be granted.
133170
*/
134171
export async function erc7715RequestExecutionPermissionsAction(
135172
client: MetaMaskExtensionClient,
136173
parameters: RequestExecutionPermissionsParameters,
137-
kernelSnapId: string | undefined,
138174
): Promise<RequestExecutionPermissionsReturnType> {
139175
const formattedPermissionRequest = parameters.map(formatPermissionsRequest);
140176

141-
let result: PermissionResponse<AccountSigner, PermissionTypes>[] | null;
142-
143-
if (kernelSnapId) {
144-
result = await client.request(
145-
{
146-
method: 'wallet_invokeSnap',
147-
params: {
148-
snapId: kernelSnapId,
149-
request: {
150-
method: 'wallet_requestExecutionPermissions',
151-
params: formattedPermissionRequest,
152-
},
153-
},
154-
},
155-
{ retryCount: 0 },
156-
);
157-
} else {
158-
result = await client.request(
159-
{
160-
method: 'wallet_requestExecutionPermissions',
161-
params: formattedPermissionRequest,
162-
},
163-
{ retryCount: 0 },
164-
);
165-
}
177+
const result = await client.request(
178+
{
179+
method: 'wallet_requestExecutionPermissions',
180+
params: formattedPermissionRequest,
181+
},
182+
{ retryCount: 0 },
183+
);
166184

167185
if (!result) {
168186
throw new Error('Failed to grant permissions');

packages/delegation-toolkit/src/experimental/index.ts

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,15 @@ import {
1010
sendUserOperationWithDelegationAction,
1111
} from './erc7710RedeemDelegationAction';
1212
import { erc7715RequestExecutionPermissionsAction } from './erc7715RequestExecutionPermissionsAction';
13-
import type { RequestExecutionPermissionsParameters } from './erc7715RequestExecutionPermissionsAction';
14-
import { ensureSnapsAuthorized } from './snapsAuthorization';
15-
import type { MetaMaskExtensionClient } from './snapsAuthorization';
13+
import type {
14+
MetaMaskExtensionClient,
15+
RequestExecutionPermissionsParameters,
16+
} from './erc7715RequestExecutionPermissionsAction';
1617

1718
export {
1819
erc7715RequestExecutionPermissionsAction as requestExecutionPermissions,
20+
type MetaMaskExtensionClient,
21+
type MetaMaskExtensionSchema,
1922
type RequestExecutionPermissionsParameters,
2023
type RequestExecutionPermissionsReturnType,
2124
} from './erc7715RequestExecutionPermissionsAction';
@@ -27,51 +30,16 @@ export {
2730
type DelegationStorageConfig,
2831
} from './delegationStorage';
2932

30-
type Erc7715ProviderConfig = {
31-
useWalletMethod: boolean;
32-
snapIds?: {
33-
kernelSnapId?: string;
34-
providerSnapId?: string;
35-
};
36-
};
37-
38-
export const erc7715ProviderActions =
39-
(erc7715ProviderConfig: Erc7715ProviderConfig = { useWalletMethod: false }) =>
40-
(client: Client) => ({
41-
requestExecutionPermissions: async (
42-
parameters: RequestExecutionPermissionsParameters,
43-
) => {
44-
const { useWalletMethod, snapIds } = erc7715ProviderConfig;
45-
46-
let kernelSnapId: string | undefined;
47-
48-
if (!useWalletMethod) {
49-
kernelSnapId =
50-
snapIds?.kernelSnapId ?? 'npm:@metamask/permissions-kernel-snap';
51-
52-
const snapIdsToAuthorize = {
53-
kernelSnapId,
54-
providerSnapId:
55-
snapIds?.providerSnapId ?? 'npm:@metamask/gator-permissions-snap',
56-
};
57-
58-
if (
59-
!(await ensureSnapsAuthorized(
60-
client as MetaMaskExtensionClient,
61-
snapIdsToAuthorize,
62-
))
63-
) {
64-
throw new Error('Snaps not authorized');
65-
}
66-
}
67-
68-
return erc7715RequestExecutionPermissionsAction(
69-
client as MetaMaskExtensionClient,
70-
parameters,
71-
kernelSnapId,
72-
);
73-
},
74-
});
33+
export const erc7715ProviderActions = () => (client: Client) => ({
34+
requestExecutionPermissions: async (
35+
parameters: RequestExecutionPermissionsParameters,
36+
) => {
37+
return erc7715RequestExecutionPermissionsAction(
38+
client as MetaMaskExtensionClient,
39+
parameters,
40+
);
41+
},
42+
});
7543

7644
export const erc7710WalletActions = () => (client: WalletClient) => ({
7745
sendTransactionWithDelegation: async (
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import type {
2+
AccountSigner,
3+
PermissionRequest,
4+
PermissionResponse,
5+
PermissionTypes,
6+
} from '@metamask/7715-permission-types';
7+
import type { Account, Chain, Client, RpcSchema, Transport } from 'viem';
8+
9+
/**
10+
* RPC schema for MetaMask related methods.
11+
*
12+
* Extends the base RPC schema with methods specific to interacting with EIP-7715:
13+
* - `wallet_invokeSnap`: Invokes a method on a specific Snap.
14+
*/
15+
export type MetaMaskExtensionSchema = RpcSchema &
16+
[
17+
{
18+
// eslint-disable-next-line @typescript-eslint/naming-convention
19+
Method: 'wallet_requestExecutionPermissions';
20+
// eslint-disable-next-line @typescript-eslint/naming-convention
21+
Params: PermissionRequest<AccountSigner, PermissionTypes>[];
22+
// eslint-disable-next-line @typescript-eslint/naming-convention
23+
ReturnType: PermissionResponse<AccountSigner, PermissionTypes>[];
24+
},
25+
];
26+
27+
/**
28+
* A Viem client extended with MetaMask Snap-specific RPC methods.
29+
*
30+
* This client type allows for interaction with MetaMask Snaps through
31+
* the standard Viem client interface, with added type safety for
32+
* Snap-specific methods.
33+
*/
34+
export type MetaMaskExtensionClient = Client<
35+
Transport,
36+
Chain | undefined,
37+
Account | undefined,
38+
MetaMaskExtensionSchema
39+
>;

packages/delegation-toolkit/src/experimental/snapsAuthorization.ts

Lines changed: 0 additions & 161 deletions
This file was deleted.

0 commit comments

Comments
 (0)