Skip to content

Commit 4cfcae9

Browse files
authored
Add permission type erc20-token-revocation (#110)
1 parent 531990c commit 4cfcae9

4 files changed

Lines changed: 292 additions & 116 deletions

File tree

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,23 @@
11
// Export all types from types.ts
22
export type {
3-
Hex,
4-
WalletSigner,
5-
KeyType,
6-
KeySigner,
7-
MultiKeySigner,
8-
AccountSigner,
9-
Signer,
10-
BasePermission,
11-
PermissionTypes,
12-
NativeTokenStreamPermission,
13-
NativeTokenPeriodicPermission,
14-
Erc20TokenStreamPermission,
15-
Erc20TokenPeriodicPermission,
16-
Rule,
17-
PermissionRequest,
18-
PermissionResponse,
19-
RevokeExecutionPermissionRequestParams,
20-
RevokeExecutionPermissionResponseResult,
21-
MetaMaskBasePermissionData,
3+
Hex,
4+
WalletSigner,
5+
KeyType,
6+
KeySigner,
7+
MultiKeySigner,
8+
AccountSigner,
9+
Signer,
10+
BasePermission,
11+
PermissionTypes,
12+
NativeTokenStreamPermission,
13+
NativeTokenPeriodicPermission,
14+
Erc20TokenStreamPermission,
15+
Erc20TokenPeriodicPermission,
16+
Erc20TokenRevocationPermission,
17+
Rule,
18+
PermissionRequest,
19+
PermissionResponse,
20+
RevokeExecutionPermissionRequestParams,
21+
RevokeExecutionPermissionResponseResult,
22+
MetaMaskBasePermissionData,
2223
} from './types';

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

Lines changed: 91 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66
* A hex-encoded string.
77
*/
88
export type Hex = `0x${string}`;
9-
9+
1010
/**
1111
* The types of keys that are supported for the following `key` and `keys` signer types.
1212
*/
13-
export type KeyType = "secp256r1" | "secp256k1" | "ed25519" | "schnorr";
13+
export type KeyType = 'secp256r1' | 'secp256k1' | 'ed25519' | 'schnorr';
1414

1515
////////////////////////////////////////////////////
1616
// Signer Types
@@ -21,44 +21,44 @@ export type KeyType = "secp256r1" | "secp256k1" | "ed25519" | "schnorr";
2121
* `data` is not necessary for this signer type as the wallet is both the signer and grantor of these permissions
2222
*/
2323
export type WalletSigner = {
24-
type: "wallet";
25-
data: {};
24+
type: 'wallet';
25+
data: {};
2626
};
27-
27+
2828
/**
2929
* A signer representing a single key.
3030
* "Key" types are explicitly secp256r1 (p256) or secp256k1, and the public keys are hex-encoded.
3131
*/
3232
export type KeySigner = {
33-
type: "key";
34-
data: {
35-
type: KeyType;
36-
publicKey: Hex;
37-
};
33+
type: 'key';
34+
data: {
35+
type: KeyType;
36+
publicKey: Hex;
37+
};
3838
};
3939

4040
/**
4141
* A signer representing a multisig signer.
4242
* Each element of `publicKeys` are all explicitly the same `KeyType`, and the public keys are hex-encoded.
4343
*/
4444
export type MultiKeySigner = {
45-
type: "keys";
46-
data: {
47-
keys: {
48-
type: KeyType;
49-
publicKey: Hex;
50-
}[];
51-
};
45+
type: 'keys';
46+
data: {
47+
keys: {
48+
type: KeyType;
49+
publicKey: Hex;
50+
}[];
51+
};
5252
};
5353

5454
/**
5555
* An account that can be granted with permissions as in ERC-7710.
5656
*/
5757
export type AccountSigner = {
58-
type: "account";
59-
data: {
60-
address: Hex;
61-
};
58+
type: 'account';
59+
data: {
60+
address: Hex;
61+
};
6262
};
6363

6464
export type Signer = WalletSigner | KeySigner | MultiKeySigner | AccountSigner;
@@ -75,9 +75,9 @@ export type Signer = WalletSigner | KeySigner | MultiKeySigner | AccountSigner;
7575
* @property data - is a record of the data that is associated with the permission, and the structure is defined by the ERCs.
7676
*/
7777
export type BasePermission = {
78-
type: string;
79-
isAdjustmentAllowed: boolean;
80-
data: Record<string, any>;
78+
type: string;
79+
isAdjustmentAllowed: boolean;
80+
data: Record<string, any>;
8181
};
8282

8383
/**
@@ -88,9 +88,9 @@ export type BasePermission = {
8888
* @property data - is a record of the data that is associated with the rule, and the structure is defined by the ERCs.
8989
*/
9090
export type Rule = {
91-
type: string;
92-
isAdjustmentAllowed: boolean;
93-
data: Record<string, any>;
91+
type: string;
92+
isAdjustmentAllowed: boolean;
93+
data: Record<string, any>;
9494
};
9595

9696
////////////////////////////////////////////////////
@@ -102,7 +102,7 @@ export type Rule = {
102102
* @property justification - is a human-readable explanation of why the permission is being requested.
103103
*/
104104
export type MetaMaskBasePermissionData = {
105-
justification?: string | null;
105+
justification?: string | null;
106106
};
107107

108108
/**
@@ -113,13 +113,13 @@ export type MetaMaskBasePermissionData = {
113113
* @property data.startTime - is the start time of the stream. Defaults to current time.
114114
*/
115115
export type NativeTokenStreamPermission = BasePermission & {
116-
type: 'native-token-stream';
117-
data: MetaMaskBasePermissionData & {
118-
initialAmount?: Hex | null;
119-
maxAmount?: Hex | null;
120-
amountPerSecond: Hex;
121-
startTime?: number | null;
122-
};
116+
type: 'native-token-stream';
117+
data: MetaMaskBasePermissionData & {
118+
initialAmount?: Hex | null;
119+
maxAmount?: Hex | null;
120+
amountPerSecond: Hex;
121+
startTime?: number | null;
122+
};
123123
};
124124

125125
/**
@@ -129,12 +129,12 @@ export type NativeTokenStreamPermission = BasePermission & {
129129
* @property data.startTime - is the start time of the stream. Defaults to current time.
130130
*/
131131
export type NativeTokenPeriodicPermission = BasePermission & {
132-
type: 'native-token-periodic';
133-
data: MetaMaskBasePermissionData & {
134-
periodAmount: Hex;
135-
periodDuration: number;
136-
startTime?: number | null;
137-
};
132+
type: 'native-token-periodic';
133+
data: MetaMaskBasePermissionData & {
134+
periodAmount: Hex;
135+
periodDuration: number;
136+
startTime?: number | null;
137+
};
138138
};
139139

140140
/**
@@ -146,16 +146,16 @@ export type NativeTokenPeriodicPermission = BasePermission & {
146146
* @property data.tokenAddress - is the address of the ERC20 token to be streamed.
147147
*/
148148
export type Erc20TokenStreamPermission = BasePermission & {
149-
type: 'erc20-token-stream';
150-
data: MetaMaskBasePermissionData & {
151-
initialAmount?: Hex | null;
152-
maxAmount?: Hex | null;
153-
amountPerSecond: Hex;
154-
startTime?: number | null;
155-
tokenAddress: Hex;
156-
};
149+
type: 'erc20-token-stream';
150+
data: MetaMaskBasePermissionData & {
151+
initialAmount?: Hex | null;
152+
maxAmount?: Hex | null;
153+
amountPerSecond: Hex;
154+
startTime?: number | null;
155+
tokenAddress: Hex;
156+
};
157157
};
158-
158+
159159
/**
160160
* A permission to stream ERC20 tokens periodically.
161161
* @property data.periodAmount - is the amount of the ERC20 token to be streamed per period.
@@ -164,13 +164,21 @@ export type Erc20TokenStreamPermission = BasePermission & {
164164
* @property data.tokenAddress - is the address of the ERC20 token to be streamed per period.
165165
*/
166166
export type Erc20TokenPeriodicPermission = BasePermission & {
167-
type: 'erc20-token-periodic';
168-
data: MetaMaskBasePermissionData & {
169-
periodAmount: Hex;
170-
periodDuration: number;
171-
startTime?: number | null;
172-
tokenAddress: Hex;
173-
};
167+
type: 'erc20-token-periodic';
168+
data: MetaMaskBasePermissionData & {
169+
periodAmount: Hex;
170+
periodDuration: number;
171+
startTime?: number | null;
172+
tokenAddress: Hex;
173+
};
174+
};
175+
176+
/**
177+
* A permission to revoke an ERC20 token allowance.
178+
*/
179+
export type Erc20TokenRevocationPermission = BasePermission & {
180+
type: 'erc20-token-revocation';
181+
data: MetaMaskBasePermissionData;
174182
};
175183

176184
/**
@@ -187,10 +195,11 @@ export type Erc20TokenPeriodicPermission = BasePermission & {
187195
* Represents the type of the ERC-7715 permissions that can be granted.
188196
*/
189197
export type PermissionTypes =
190-
| NativeTokenStreamPermission
191-
| NativeTokenPeriodicPermission
192-
| Erc20TokenStreamPermission
193-
| Erc20TokenPeriodicPermission;
198+
| NativeTokenStreamPermission
199+
| NativeTokenPeriodicPermission
200+
| Erc20TokenStreamPermission
201+
| Erc20TokenPeriodicPermission
202+
| Erc20TokenRevocationPermission;
194203

195204
////////////////////////////////////////////////////
196205
// Permission Requests
@@ -205,14 +214,14 @@ export type PermissionTypes =
205214
* @property 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.
206215
*/
207216
export type PermissionRequest<
208-
TSigner extends Signer,
209-
TPermission extends PermissionTypes
217+
TSigner extends Signer,
218+
TPermission extends PermissionTypes,
210219
> = {
211-
chainId: Hex; // hex-encoding of uint256
212-
address?: Hex;
213-
signer: TSigner;
214-
permission: TPermission;
215-
rules?: Rule[] | null;
220+
chainId: Hex; // hex-encoding of uint256
221+
address?: Hex;
222+
signer: TSigner;
223+
permission: TPermission;
224+
rules?: Rule[] | null;
216225
};
217226

218227
/**
@@ -223,28 +232,28 @@ export type PermissionRequest<
223232
* @property 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.
224233
*/
225234
export type PermissionResponse<
226-
TSigner extends Signer,
227-
TPermission extends PermissionTypes
235+
TSigner extends Signer,
236+
TPermission extends PermissionTypes,
228237
> = PermissionRequest<TSigner, TPermission> & {
229-
context: Hex;
230-
dependencyInfo: {
231-
factory: Hex;
232-
factoryData: Hex;
233-
}[];
234-
signerMeta?: {
235-
// 7679 userOp building
236-
userOpBuilder?: Hex;
237-
// 7710 delegation
238-
delegationManager?: Hex;
239-
};
238+
context: Hex;
239+
dependencyInfo: {
240+
factory: Hex;
241+
factoryData: Hex;
242+
}[];
243+
signerMeta?: {
244+
// 7679 userOp building
245+
userOpBuilder?: Hex;
246+
// 7710 delegation
247+
delegationManager?: Hex;
248+
};
240249
};
241250

242251
/**
243252
* Parameters for the `wallet_revokeExecutionPermission` JSON-RPC method.
244253
* @property permissionContext - the context identifier for the permission to be revoked
245254
*/
246255
export type RevokeExecutionPermissionRequestParams = {
247-
permissionContext: Hex;
256+
permissionContext: Hex;
248257
};
249258

250259
/**

0 commit comments

Comments
 (0)