Skip to content

Commit 9441d8c

Browse files
authored
chore: Implement erc-7715 type scheme revisions across packages (#128)
* Implement erc-7715 type scheme revisions across packages * Update failing test cases * Update comments
1 parent 4c91044 commit 9441d8c

File tree

5 files changed

+145
-337
lines changed

5 files changed

+145
-337
lines changed

packages/7715-permission-types/src/index.ts

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
// Export all types from types.ts
22
export type {
33
Hex,
4-
WalletSigner,
5-
KeyType,
6-
KeySigner,
7-
MultiKeySigner,
8-
AccountSigner,
9-
Signer,
104
BasePermission,
115
PermissionTypes,
126
NativeTokenStreamPermission,

packages/7715-permission-types/src/types.ts

Lines changed: 14 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -7,62 +7,6 @@
77
*/
88
export type Hex = `0x${string}`;
99

10-
/**
11-
* The types of keys that are supported for the following `key` and `keys` signer types.
12-
*/
13-
export type KeyType = 'secp256r1' | 'secp256k1' | 'ed25519' | 'schnorr';
14-
15-
// //////////////////////////////////////////////////
16-
// Signer Types
17-
// //////////////////////////////////////////////////
18-
19-
/**
20-
* A wallet is the signer for these permissions
21-
* `data` is not necessary for this signer type as the wallet is both the signer and grantor of these permissions
22-
*/
23-
export type WalletSigner = {
24-
type: 'wallet';
25-
data: object;
26-
};
27-
28-
/**
29-
* A signer representing a single key.
30-
* "Key" types are explicitly secp256r1 (p256) or secp256k1, and the public keys are hex-encoded.
31-
*/
32-
export type KeySigner = {
33-
type: 'key';
34-
data: {
35-
type: KeyType;
36-
publicKey: Hex;
37-
};
38-
};
39-
40-
/**
41-
* A signer representing a multisig signer.
42-
* Each element of `publicKeys` are all explicitly the same `KeyType`, and the public keys are hex-encoded.
43-
*/
44-
export type MultiKeySigner = {
45-
type: 'keys';
46-
data: {
47-
keys: {
48-
type: KeyType;
49-
publicKey: Hex;
50-
}[];
51-
};
52-
};
53-
54-
/**
55-
* An account that can be granted with permissions as in ERC-7710.
56-
*/
57-
export type AccountSigner = {
58-
type: 'account';
59-
data: {
60-
address: Hex;
61-
};
62-
};
63-
64-
export type Signer = WalletSigner | KeySigner | MultiKeySigner | AccountSigner;
65-
6610
// //////////////////////////////////////////////////
6711
// Permission Types
6812
// //////////////////////////////////////////////////
@@ -85,17 +29,13 @@ export type BasePermission = {
8529

8630
/**
8731
* A base rule type that all rules must extend.
88-
* `isAdjustmentAllowed` defines a boolean value that allows DApp to define whether the "rule" can be attenuated–adjusted to meet the user's terms.
8932
*
9033
* type - is an enum defined by the ERCs
9134
*
92-
* isAdjustmentAllowed - is a boolean that indicates whether the rule can be adjusted.
93-
*
9435
* data - is a record of the data that is associated with the rule, and the structure is defined by the ERCs.
9536
*/
9637
export type Rule = {
9738
type: string;
98-
isAdjustmentAllowed: boolean;
9939
data: Record<string, any>;
10040
};
10141

@@ -236,19 +176,16 @@ export type PermissionTypes =
236176
*
237177
* address - address identifies the account being targetted for this permission request which is useful when a connection has been established and multiple accounts have been exposed. It is optional to let the user choose which account to grant permission for.
238178
*
239-
* signer - signer is a field that identifies the key or account associated with the permission or alternatively the wallet will manage the session. See the "Signers" section for details.
179+
* to - is a field that identifies the DApp session account associated with the permission.
240180
*
241181
* permission - permission defines the allowed behavior the signer can do on behalf of the account. See the "Permission" section for details.
242182
*
243183
* rules - rules defined the restrictions or conditions that a signer MUST abide by when using a permission to act on behalf of an account. See the "Rule" section for details.
244184
*/
245-
export type PermissionRequest<
246-
TSigner extends Signer,
247-
TPermission extends PermissionTypes,
248-
> = {
185+
export type PermissionRequest<TPermission extends PermissionTypes> = {
249186
chainId: Hex; // hex-encoding of uint256
250-
address?: Hex;
251-
signer: TSigner;
187+
from?: Hex;
188+
to: Hex;
252189
permission: TPermission;
253190
rules?: Rule[] | null;
254191
};
@@ -259,26 +196,19 @@ export type PermissionRequest<
259196
*
260197
* context - is a catch-all to identify a permission for revoking permissions or submitting userOps, and can contain non-identifying data as well. It MAY be the `context` as defined in ERC-7679 and ERC-7710.
261198
*
262-
* dependencyInfo - is an array of objects, each containing fields for `factory` and `factoryData` as defined in ERC-4337. Either both `factory` and `factoryData` must be specified in an entry, or neither. This array is used describe accounts that are not yet deployed but MUST be deployed in order for a permission to be successfully redeemed.
199+
* dependencies - is an array of objects, each containing fields for `factory` and `factoryData` as defined in ERC-4337. Either both `factory` and `factoryData` must be specified in an entry, or neither. This array is used describe accounts that are not yet deployed but MUST be deployed in order for a permission to be successfully redeemed.
263200
*
264-
* signerMeta - is dependent on the account type. If the signer type is `wallet` then it's not required. If the signer type is `key` or `keys` then `userOpBuilder` is required as defined in ERC-7679. If the signer type is `account` then `delegationManager` is required as defined in ERC-7710.
201+
* delegationManager - is required as defined in ERC-7710.
265202
*/
266-
export type PermissionResponse<
267-
TSigner extends Signer,
268-
TPermission extends PermissionTypes,
269-
> = PermissionRequest<TSigner, TPermission> & {
270-
context: Hex;
271-
dependencyInfo: {
272-
factory: Hex;
273-
factoryData: Hex;
274-
}[];
275-
signerMeta?: {
276-
// 7679 userOp building
277-
userOpBuilder?: Hex;
278-
// 7710 delegation
279-
delegationManager?: Hex;
203+
export type PermissionResponse<TPermission extends PermissionTypes> =
204+
PermissionRequest<TPermission> & {
205+
context: Hex;
206+
dependencies: {
207+
factory: Hex;
208+
factoryData: Hex;
209+
}[];
210+
delegationManager: Hex;
280211
};
281-
};
282212

283213
/**
284214
* Parameters for the `wallet_revokeExecutionPermission` JSON-RPC method.

packages/smart-accounts-kit/src/actions/erc7715RequestExecutionPermissionsAction.ts

Lines changed: 11 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type {
2-
AccountSigner,
32
Erc20TokenPeriodicPermission,
43
Erc20TokenStreamPermission,
54
Erc20TokenRevocationPermission,
@@ -9,6 +8,7 @@ import type {
98
PermissionResponse,
109
PermissionTypes,
1110
Rule,
11+
Hex,
1212
} from '@metamask/7715-permission-types';
1313
import { isHex, toHex } from 'viem';
1414
import type {
@@ -32,9 +32,9 @@ export type MetaMaskExtensionSchema = RpcSchema &
3232
// eslint-disable-next-line @typescript-eslint/naming-convention
3333
Method: 'wallet_requestExecutionPermissions';
3434
// eslint-disable-next-line @typescript-eslint/naming-convention
35-
Params: PermissionRequest<AccountSigner, PermissionTypes>[];
35+
Params: PermissionRequest<PermissionTypes>[];
3636
// eslint-disable-next-line @typescript-eslint/naming-convention
37-
ReturnType: PermissionResponse<AccountSigner, PermissionTypes>[];
37+
ReturnType: PermissionResponse<PermissionTypes>[];
3838
},
3939
];
4040

@@ -135,8 +135,6 @@ export type SupportedPermissionParams =
135135
| Erc20TokenPeriodicPermissionParameter
136136
| Erc20TokenRevocationPermissionParameter;
137137

138-
export type SignerParam = Address | AccountSigner;
139-
140138
/**
141139
* Represents a single permission request.
142140
*/
@@ -147,9 +145,9 @@ export type PermissionRequestParameter = {
147145
// Whether the caller allows the permission to be adjusted.
148146
isAdjustmentAllowed: boolean;
149147
// Account to assign the permission to.
150-
signer: SignerParam;
148+
to: Hex;
151149
// address from which the permission should be granted.
152-
address?: Address | undefined | null;
150+
from?: Address | undefined | null;
153151
// Timestamp (in seconds) that specifies the time by which this permission MUST expire.
154152
expiry?: number | undefined | null;
155153
};
@@ -165,10 +163,8 @@ export type RequestExecutionPermissionsParameters =
165163
/**
166164
* Return type for the request execution permissions action.
167165
*/
168-
export type RequestExecutionPermissionsReturnType = PermissionResponse<
169-
AccountSigner,
170-
PermissionTypes
171-
>[];
166+
export type RequestExecutionPermissionsReturnType =
167+
PermissionResponse<PermissionTypes>[];
172168

173169
/**
174170
* Grants permissions according to EIP-7715 specification.
@@ -211,23 +207,17 @@ export async function erc7715RequestExecutionPermissionsAction(
211207
*/
212208
function formatPermissionsRequest(
213209
parameters: PermissionRequestParameter,
214-
): PermissionRequest<AccountSigner, PermissionTypes> {
215-
const { chainId, address, expiry, isAdjustmentAllowed } = parameters;
210+
): PermissionRequest<PermissionTypes> {
211+
const { chainId, from, expiry, isAdjustmentAllowed } = parameters;
216212

217213
const permissionFormatter = getPermissionFormatter(
218214
parameters.permission.type,
219215
);
220216

221-
const signerAddress =
222-
typeof parameters.signer === 'string'
223-
? parameters.signer
224-
: parameters.signer.data.address;
225-
226217
const rules: Rule[] = isDefined(expiry)
227218
? [
228219
{
229220
type: 'expiry',
230-
isAdjustmentAllowed,
231221
data: {
232222
timestamp: expiry,
233223
},
@@ -236,7 +226,7 @@ function formatPermissionsRequest(
236226
: [];
237227

238228
const optionalFields = {
239-
...(address ? { address } : {}),
229+
...(from ? { from } : {}),
240230
};
241231

242232
return {
@@ -246,13 +236,7 @@ function formatPermissionsRequest(
246236
permission: parameters.permission,
247237
isAdjustmentAllowed,
248238
}),
249-
signer: {
250-
// MetaMask 7715 implementation only supports AccountSigner
251-
type: 'account',
252-
data: {
253-
address: signerAddress,
254-
},
255-
},
239+
to: parameters.to,
256240
rules,
257241
};
258242
}

packages/smart-accounts-kit/src/actions/metaMaskExtension.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import type {
2-
AccountSigner,
32
PermissionRequest,
43
PermissionResponse,
54
PermissionTypes,
@@ -18,9 +17,9 @@ export type MetaMaskExtensionSchema = RpcSchema &
1817
// eslint-disable-next-line @typescript-eslint/naming-convention
1918
Method: 'wallet_requestExecutionPermissions';
2019
// eslint-disable-next-line @typescript-eslint/naming-convention
21-
Params: PermissionRequest<AccountSigner, PermissionTypes>[];
20+
Params: PermissionRequest<PermissionTypes>[];
2221
// eslint-disable-next-line @typescript-eslint/naming-convention
23-
ReturnType: PermissionResponse<AccountSigner, PermissionTypes>[];
22+
ReturnType: PermissionResponse<PermissionTypes>[];
2423
},
2524
];
2625

0 commit comments

Comments
 (0)