@zerodev/sdk 4.0.28 → 4.0.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/dist/cjs/index.d.ts +1 -1
  2. package/dist/cjs/index.js +3 -1
  3. package/dist/cjs/index.js.map +1 -1
  4. package/dist/cjs/kernel-zerodev/abis/ERC20Abi.d.ts +231 -39
  5. package/dist/cjs/kernel-zerodev/abis/ERC20Abi.js.map +1 -1
  6. package/dist/cjs/kernel-zerodev/paymaster/token-paymaster.js +5 -1
  7. package/dist/cjs/kernel-zerodev/paymaster/token-paymaster.js.map +1 -1
  8. package/dist/cjs/kernel-zerodev/validator/session-key-validator.d.ts +11 -6
  9. package/dist/cjs/kernel-zerodev/validator/session-key-validator.js +81 -5
  10. package/dist/cjs/kernel-zerodev/validator/session-key-validator.js.map +1 -1
  11. package/dist/cjs/kernel-zerodev/validator/types.d.ts +27 -1
  12. package/dist/cjs/kernel-zerodev/validator/types.js.map +1 -1
  13. package/dist/esm/index.d.ts +1 -1
  14. package/dist/esm/index.js +1 -1
  15. package/dist/esm/index.js.map +1 -1
  16. package/dist/esm/kernel-zerodev/abis/ERC20Abi.d.ts +231 -39
  17. package/dist/esm/kernel-zerodev/abis/ERC20Abi.js.map +1 -1
  18. package/dist/esm/kernel-zerodev/paymaster/token-paymaster.js +5 -1
  19. package/dist/esm/kernel-zerodev/paymaster/token-paymaster.js.map +1 -1
  20. package/dist/esm/kernel-zerodev/validator/session-key-validator.d.ts +11 -6
  21. package/dist/esm/kernel-zerodev/validator/session-key-validator.js +78 -4
  22. package/dist/esm/kernel-zerodev/validator/session-key-validator.js.map +1 -1
  23. package/dist/esm/kernel-zerodev/validator/types.d.ts +27 -1
  24. package/dist/esm/kernel-zerodev/validator/types.js +2 -1
  25. package/dist/esm/kernel-zerodev/validator/types.js.map +1 -1
  26. package/dist/types/index.d.ts +1 -1
  27. package/dist/types/index.d.ts.map +1 -1
  28. package/dist/types/kernel-zerodev/abis/ERC20Abi.d.ts +231 -39
  29. package/dist/types/kernel-zerodev/abis/ERC20Abi.d.ts.map +1 -1
  30. package/dist/types/kernel-zerodev/paymaster/token-paymaster.d.ts.map +1 -1
  31. package/dist/types/kernel-zerodev/validator/session-key-validator.d.ts +11 -6
  32. package/dist/types/kernel-zerodev/validator/session-key-validator.d.ts.map +1 -1
  33. package/dist/types/kernel-zerodev/validator/types.d.ts +27 -1
  34. package/dist/types/kernel-zerodev/validator/types.d.ts.map +1 -1
  35. package/package.json +1 -1
  36. package/src/index.ts +5 -1
  37. package/src/kernel-zerodev/abis/ERC20Abi.ts +1 -1
  38. package/src/kernel-zerodev/paymaster/token-paymaster.ts +8 -1
  39. package/src/kernel-zerodev/validator/session-key-validator.ts +111 -9
  40. package/src/kernel-zerodev/validator/types.ts +64 -0
@@ -1,40 +1,232 @@
1
- export declare const ERC20Abi: ({
2
- inputs: {
3
- internalType: string;
4
- name: string;
5
- type: string;
6
- }[];
7
- stateMutability: string;
8
- type: string;
9
- anonymous?: undefined;
10
- name?: undefined;
11
- outputs?: undefined;
12
- } | {
13
- anonymous: boolean;
14
- inputs: {
15
- indexed: boolean;
16
- internalType: string;
17
- name: string;
18
- type: string;
19
- }[];
20
- name: string;
21
- type: string;
22
- stateMutability?: undefined;
23
- outputs?: undefined;
24
- } | {
25
- inputs: {
26
- internalType: string;
27
- name: string;
28
- type: string;
29
- }[];
30
- name: string;
31
- outputs: {
32
- internalType: string;
33
- name: string;
34
- type: string;
35
- }[];
36
- stateMutability: string;
37
- type: string;
38
- anonymous?: undefined;
39
- })[];
1
+ export declare const ERC20Abi: readonly [{
2
+ readonly inputs: readonly [{
3
+ readonly internalType: "string";
4
+ readonly name: "name_";
5
+ readonly type: "string";
6
+ }, {
7
+ readonly internalType: "string";
8
+ readonly name: "symbol_";
9
+ readonly type: "string";
10
+ }, {
11
+ readonly internalType: "uint8";
12
+ readonly name: "decimals_";
13
+ readonly type: "uint8";
14
+ }, {
15
+ readonly internalType: "uint256";
16
+ readonly name: "initialBalance_";
17
+ readonly type: "uint256";
18
+ }, {
19
+ readonly internalType: "address payable";
20
+ readonly name: "feeReceiver_";
21
+ readonly type: "address";
22
+ }];
23
+ readonly stateMutability: "payable";
24
+ readonly type: "constructor";
25
+ }, {
26
+ readonly anonymous: false;
27
+ readonly inputs: readonly [{
28
+ readonly indexed: true;
29
+ readonly internalType: "address";
30
+ readonly name: "owner";
31
+ readonly type: "address";
32
+ }, {
33
+ readonly indexed: true;
34
+ readonly internalType: "address";
35
+ readonly name: "spender";
36
+ readonly type: "address";
37
+ }, {
38
+ readonly indexed: false;
39
+ readonly internalType: "uint256";
40
+ readonly name: "value";
41
+ readonly type: "uint256";
42
+ }];
43
+ readonly name: "Approval";
44
+ readonly type: "event";
45
+ }, {
46
+ readonly anonymous: false;
47
+ readonly inputs: readonly [{
48
+ readonly indexed: true;
49
+ readonly internalType: "address";
50
+ readonly name: "from";
51
+ readonly type: "address";
52
+ }, {
53
+ readonly indexed: true;
54
+ readonly internalType: "address";
55
+ readonly name: "to";
56
+ readonly type: "address";
57
+ }, {
58
+ readonly indexed: false;
59
+ readonly internalType: "uint256";
60
+ readonly name: "value";
61
+ readonly type: "uint256";
62
+ }];
63
+ readonly name: "Transfer";
64
+ readonly type: "event";
65
+ }, {
66
+ readonly inputs: readonly [{
67
+ readonly internalType: "address";
68
+ readonly name: "owner";
69
+ readonly type: "address";
70
+ }, {
71
+ readonly internalType: "address";
72
+ readonly name: "spender";
73
+ readonly type: "address";
74
+ }];
75
+ readonly name: "allowance";
76
+ readonly outputs: readonly [{
77
+ readonly internalType: "uint256";
78
+ readonly name: "";
79
+ readonly type: "uint256";
80
+ }];
81
+ readonly stateMutability: "view";
82
+ readonly type: "function";
83
+ }, {
84
+ readonly inputs: readonly [{
85
+ readonly internalType: "address";
86
+ readonly name: "spender";
87
+ readonly type: "address";
88
+ }, {
89
+ readonly internalType: "uint256";
90
+ readonly name: "amount";
91
+ readonly type: "uint256";
92
+ }];
93
+ readonly name: "approve";
94
+ readonly outputs: readonly [{
95
+ readonly internalType: "bool";
96
+ readonly name: "";
97
+ readonly type: "bool";
98
+ }];
99
+ readonly stateMutability: "nonpayable";
100
+ readonly type: "function";
101
+ }, {
102
+ readonly inputs: readonly [{
103
+ readonly internalType: "address";
104
+ readonly name: "account";
105
+ readonly type: "address";
106
+ }];
107
+ readonly name: "balanceOf";
108
+ readonly outputs: readonly [{
109
+ readonly internalType: "uint256";
110
+ readonly name: "";
111
+ readonly type: "uint256";
112
+ }];
113
+ readonly stateMutability: "view";
114
+ readonly type: "function";
115
+ }, {
116
+ readonly inputs: readonly [];
117
+ readonly name: "decimals";
118
+ readonly outputs: readonly [{
119
+ readonly internalType: "uint8";
120
+ readonly name: "";
121
+ readonly type: "uint8";
122
+ }];
123
+ readonly stateMutability: "view";
124
+ readonly type: "function";
125
+ }, {
126
+ readonly inputs: readonly [{
127
+ readonly internalType: "address";
128
+ readonly name: "spender";
129
+ readonly type: "address";
130
+ }, {
131
+ readonly internalType: "uint256";
132
+ readonly name: "subtractedValue";
133
+ readonly type: "uint256";
134
+ }];
135
+ readonly name: "decreaseAllowance";
136
+ readonly outputs: readonly [{
137
+ readonly internalType: "bool";
138
+ readonly name: "";
139
+ readonly type: "bool";
140
+ }];
141
+ readonly stateMutability: "nonpayable";
142
+ readonly type: "function";
143
+ }, {
144
+ readonly inputs: readonly [{
145
+ readonly internalType: "address";
146
+ readonly name: "spender";
147
+ readonly type: "address";
148
+ }, {
149
+ readonly internalType: "uint256";
150
+ readonly name: "addedValue";
151
+ readonly type: "uint256";
152
+ }];
153
+ readonly name: "increaseAllowance";
154
+ readonly outputs: readonly [{
155
+ readonly internalType: "bool";
156
+ readonly name: "";
157
+ readonly type: "bool";
158
+ }];
159
+ readonly stateMutability: "nonpayable";
160
+ readonly type: "function";
161
+ }, {
162
+ readonly inputs: readonly [];
163
+ readonly name: "name";
164
+ readonly outputs: readonly [{
165
+ readonly internalType: "string";
166
+ readonly name: "";
167
+ readonly type: "string";
168
+ }];
169
+ readonly stateMutability: "view";
170
+ readonly type: "function";
171
+ }, {
172
+ readonly inputs: readonly [];
173
+ readonly name: "symbol";
174
+ readonly outputs: readonly [{
175
+ readonly internalType: "string";
176
+ readonly name: "";
177
+ readonly type: "string";
178
+ }];
179
+ readonly stateMutability: "view";
180
+ readonly type: "function";
181
+ }, {
182
+ readonly inputs: readonly [];
183
+ readonly name: "totalSupply";
184
+ readonly outputs: readonly [{
185
+ readonly internalType: "uint256";
186
+ readonly name: "";
187
+ readonly type: "uint256";
188
+ }];
189
+ readonly stateMutability: "view";
190
+ readonly type: "function";
191
+ }, {
192
+ readonly inputs: readonly [{
193
+ readonly internalType: "address";
194
+ readonly name: "recipient";
195
+ readonly type: "address";
196
+ }, {
197
+ readonly internalType: "uint256";
198
+ readonly name: "amount";
199
+ readonly type: "uint256";
200
+ }];
201
+ readonly name: "transfer";
202
+ readonly outputs: readonly [{
203
+ readonly internalType: "bool";
204
+ readonly name: "";
205
+ readonly type: "bool";
206
+ }];
207
+ readonly stateMutability: "nonpayable";
208
+ readonly type: "function";
209
+ }, {
210
+ readonly inputs: readonly [{
211
+ readonly internalType: "address";
212
+ readonly name: "sender";
213
+ readonly type: "address";
214
+ }, {
215
+ readonly internalType: "address";
216
+ readonly name: "recipient";
217
+ readonly type: "address";
218
+ }, {
219
+ readonly internalType: "uint256";
220
+ readonly name: "amount";
221
+ readonly type: "uint256";
222
+ }];
223
+ readonly name: "transferFrom";
224
+ readonly outputs: readonly [{
225
+ readonly internalType: "bool";
226
+ readonly name: "";
227
+ readonly type: "bool";
228
+ }];
229
+ readonly stateMutability: "nonpayable";
230
+ readonly type: "function";
231
+ }];
40
232
  //# sourceMappingURL=ERC20Abi.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ERC20Abi.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/abis/ERC20Abi.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;IAwJpB,CAAC"}
1
+ {"version":3,"file":"ERC20Abi.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/abis/ERC20Abi.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAwJX,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"token-paymaster.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/paymaster/token-paymaster.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,SAAS,EAEd,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,KAAK,GAAG,EAKT,MAAM,MAAM,CAAC;AAcd,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAEL,KAAK,iCAAiC,EACvC,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACtC,OAAO,EACL,KAAK,4BAA4B,EACjC,KAAK,eAAe,EACrB,MAAM,YAAY,CAAC;AAGpB,qBAAa,cAAe,SAAQ,SAAS;IAGzC,SAAS,CAAC,eAAe,EAAE,eAAe,CAAC,iBAAiB,CAAC;gBAD7D,QAAQ,EAAE,eAAe,EACf,eAAe,EAAE,eAAe,CAAC,iBAAiB,CAAC;IAIzD,mBAAmB,CACvB,iBAAiB,CAAC,EAAE,4BAA4B,GAC/C,OAAO,CAAC,GAAG,GAAG,SAAS,CAAC;IAmBrB,0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,aAAa,EAAE,cAAc,CAAC,MAAM,CAAC,EACrC,QAAQ,EAAE,cAAc,CAAC,SAAS,CAAC,GAClC,OAAO,CAAC,iCAAiC,GAAG,SAAS,CAAC;IA2DnD,cAAc,CAClB,MAAM,EAAE,mBAAmB,EAC3B,QAAQ,EAAE,iCAAiC,EAC3C,eAAe,EAAE,GAAG,EACpB,gBAAgB,EAAE,GAAG,GACpB,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;IAuCrC,oBAAoB,CACxB,MAAM,EAAE,mBAAmB,EAC3B,iBAAiB,CAAC,EAAE,4BAA4B,EAChD,iBAAiB,CAAC,EAAE,OAAO,GAC1B,OAAO,CAAC,mBAAmB,GAAG,SAAS,CAAC;CAkD5C"}
@@ -1,7 +1,10 @@
1
- import { type Address, type Hex, type SmartAccountSigner, type UserOperationRequest, type SignTypedDataParams } from "@alchemy/aa-core";
1
+ import { type Address, type Hex, type SmartAccountSigner, type UserOperationRequest, type SignTypedDataParams, type Abi } from "@alchemy/aa-core";
2
2
  import { KernelBaseValidator, type KernelBaseValidatorParams, type ValidatorPluginData } from "./base.js";
3
+ import { type GetAbiItemParameters } from "viem";
3
4
  import { MerkleTree } from "merkletreejs";
4
- import type { Operation } from "../provider.js";
5
+ import { Operation } from "../provider.js";
6
+ import type { GetAbiItemReturnType } from "viem/dist/types/utils/abi/getAbiItem.js";
7
+ import type { GeneratePermissionFromArgsParameters } from "./types.js";
5
8
  export interface SessionKeyValidatorParams extends KernelBaseValidatorParams {
6
9
  sessionKey: SmartAccountSigner;
7
10
  sessionKeyData: SessionKeyData;
@@ -24,19 +27,21 @@ export interface ParamRules {
24
27
  condition: ParamCondition;
25
28
  param: Hex;
26
29
  }
27
- export interface Permission {
30
+ export type Permission = {
28
31
  target: Address;
29
- valueLimit: bigint;
30
32
  sig: Hex;
31
33
  rules: ParamRules[];
32
- operation: Operation;
33
- }
34
+ valueLimit?: bigint;
35
+ operation?: Operation;
36
+ };
34
37
  export interface SessionKeyData {
35
38
  validUntil: number;
36
39
  validAfter: number;
37
40
  paymaster?: Address;
38
41
  permissions?: Permission[];
39
42
  }
43
+ export declare function getAbiItem<TAbi extends Abi | readonly unknown[], TItemName extends string>({ abi, args, name, }: GetAbiItemParameters<TAbi, TItemName>): GetAbiItemReturnType<TAbi, TItemName>;
44
+ export declare function getPermissionFromABI<TAbi extends Abi | readonly unknown[], TFunctionName extends string | undefined = string>({ abi, target, args, conditions, functionName, operation, valueLimit, }: GeneratePermissionFromArgsParameters<TAbi, TFunctionName>): Permission;
40
45
  export declare class SessionKeyValidator extends KernelBaseValidator {
41
46
  protected sessionKey: SmartAccountSigner;
42
47
  sessionKeyData: SessionKeyData;
@@ -1 +1 @@
1
- {"version":3,"file":"session-key-validator.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/validator/session-key-validator.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,OAAO,EACZ,KAAK,GAAG,EACR,KAAK,kBAAkB,EACvB,KAAK,oBAAoB,EAEzB,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,mBAAmB,EAEnB,KAAK,yBAAyB,EAC9B,KAAK,mBAAmB,EACzB,MAAM,WAAW,CAAC;AAkBnB,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC1C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAWhD,MAAM,WAAW,yBAA0B,SAAQ,yBAAyB;IAC1E,UAAU,EAAE,kBAAkB,CAAC;IAC/B,cAAc,EAAE,cAAc,CAAC;CAChC;AAED,MAAM,MAAM,gBAAgB,GAAG,IAAI,CACjC,yBAAyB,EACzB,gBAAgB,GAAG,iBAAiB,CACrC,GACC,mBAAmB,GAAG;IACpB,iBAAiB,CAAC,EAAE,GAAG,CAAC;IACxB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAEJ,oBAAY,cA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AAG,OAAO,CAAC,GAAG,CAAC;IAIvD,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,OAAO,CAAC,GAAG,CAAC;IAIxD,UAAU,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,GAAG,CAAC;CA0C7D"}
@@ -1,8 +1,11 @@
1
+ import { type AbiParameter, type AbiParameterKind, type AbiParameterToPrimitiveType, type AbiFunction, type ExtractAbiFunction } from "abitype";
2
+ import { type Pretty } from "abitype/src/types.js";
1
3
  import type { ECDSAValidator, ECDSAValidatorParams } from "./ecdsa-validator.js";
2
4
  import type { ERC165SessionKeyValidator, ERC165SessionKeyValidatorParams } from "./erc165-session-key-validator.js";
3
5
  import type { KillSwitchValidator, KillSwitchValidatorParams } from "./kill-switch-validator.js";
4
6
  import type { RecoveryValidator, RecoveryValidatorParams } from "./recovery-validator.js";
5
- import type { SessionKeyValidator, SessionKeyValidatorParams, ParamRules, Permission, SessionKeyData, SessionKeyParams } from "./session-key-validator.js";
7
+ import type { SessionKeyValidator, SessionKeyValidatorParams, ParamRules, Permission, SessionKeyData, SessionKeyParams, ParamCondition } from "./session-key-validator.js";
8
+ import type { Abi, InferFunctionName, Narrow } from "viem";
6
9
  export type SupportedValidators = "ECDSA" | "KILL_SWITCH" | "ERC165_SESSION_KEY" | "SESSION_KEY" | "RECOVERY";
7
10
  export type ValidatorTypeMap = {
8
11
  ECDSA: ECDSAValidator;
@@ -25,4 +28,27 @@ export type EthereumProvider = {
25
28
  request(...args: any): Promise<any>;
26
29
  };
27
30
  export type { ParamRules, Permission, SessionKeyData, SessionKeyParams };
31
+ export type AbiParametersToPrimitiveTypes<TAbiParameters extends readonly AbiParameter[], TAbiParameterKind extends AbiParameterKind = AbiParameterKind> = Pretty<{
32
+ [K in keyof TAbiParameters]: AbiParameterToPrimitiveType<TAbiParameters[K], TAbiParameterKind> | null;
33
+ }>;
34
+ export type AbiParametersToConditons<TAbiParameters extends readonly AbiParameter[]> = Pretty<{
35
+ [K in keyof TAbiParameters]: ParamCondition | null;
36
+ }>;
37
+ export type GetFunctionArgs<TAbi extends Abi | readonly unknown[], TFunctionName extends string, TAbiFunction extends AbiFunction = TAbi extends Abi ? ExtractAbiFunction<TAbi, TFunctionName> : AbiFunction, TArgs = AbiParametersToPrimitiveTypes<TAbiFunction["inputs"]>, TConditions = AbiParametersToConditons<TAbiFunction["inputs"]>, FailedToParseArgs = ([TArgs] extends [never] ? true : false) | (readonly unknown[] extends TArgs ? true : false)> = true extends FailedToParseArgs ? {
38
+ args?: readonly unknown[];
39
+ conditions?: readonly unknown[];
40
+ } : TArgs extends readonly [] ? {
41
+ args?: never;
42
+ conditions?: never;
43
+ } : {
44
+ args?: TArgs;
45
+ conditions?: TConditions;
46
+ };
47
+ export type GeneratePermissionFromArgsParameters<TAbi extends Abi | readonly unknown[], TFunctionName extends string | undefined = string, _FunctionName = TAbi extends Abi ? InferFunctionName<TAbi, TFunctionName> : never> = Pick<Permission, "operation" | "target" | "valueLimit"> & {
48
+ functionName?: _FunctionName;
49
+ } & (TFunctionName extends string ? {
50
+ abi: Narrow<TAbi>;
51
+ } & GetFunctionArgs<TAbi, TFunctionName> : _FunctionName extends string ? {
52
+ abi: [Narrow<TAbi[number]>];
53
+ } & GetFunctionArgs<TAbi, _FunctionName> : never);
28
54
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/validator/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,cAAc,EACd,oBAAoB,EACrB,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EACV,yBAAyB,EACzB,+BAA+B,EAChC,MAAM,mCAAmC,CAAC;AAE3C,OAAO,KAAK,EACV,mBAAmB,EACnB,yBAAyB,EAC1B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EACV,iBAAiB,EACjB,uBAAuB,EACxB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAA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AAE,IAAI,CAAC,EAAE,KAAK,CAAC;IAAC,UAAU,CAAC,EAAE,KAAK,CAAA;CAAE,GACpC;IACE,IAAI,CAAC,EAAE,KAAK,CAAC;IACb,UAAU,CAAC,EAAE,WAAW,CAAC;CAC1B,CAAC;AAEN,MAAM,MAAM,oCAAoC,CAC9C,IAAI,SAAS,GAAG,GAAG,SAAS,OAAO,EAAE,EACrC,aAAa,SAAS,MAAM,GAAG,SAAS,GAAG,MAAM,EACjD,aAAa,GAAG,IAAI,SAAS,GAAG,GAC5B,iBAAiB,CAAC,IAAI,EAAE,aAAa,CAAC,GACtC,KAAK,IACP,IAAI,CAAC,UAAU,EAAE,WAAW,GAAG,QAAQ,GAAG,YAAY,CAAC,GAAG;IAC5D,YAAY,CAAC,EAAE,aAAa,CAAC;CAC9B,GAAG,CAAC,aAAa,SAAS,MAAM,GAC3B;IAAE,GAAG,EAAE,MAAM,CAAC,IAAI,CAAC,CAAA;CAAE,GAAG,eAAe,CAAC,IAAI,EAAE,aAAa,CAAC,GAC5D,aAAa,SAAS,MAAM,GAC5B;IAAE,GAAG,EAAE,CAAC,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAA;CAAE,GAAG,eAAe,CAAC,IAAI,EAAE,aAAa,CAAC,GACtE,KAAK,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zerodev/sdk",
3
- "version": "4.0.28",
3
+ "version": "4.0.30",
4
4
  "description": "A collection of ERC-4337 compliant smart contract account interfaces",
5
5
  "author": "ZeroDev",
6
6
  "license": "MIT",
package/src/index.ts CHANGED
@@ -12,7 +12,11 @@ export {
12
12
  export * from "./kernel-zerodev/validator/index.js";
13
13
  export type * from "./kernel-zerodev/validator/types.js";
14
14
  export type { KernelBaseValidatorParams } from "./kernel-zerodev/validator/base.js";
15
- export { ParamCondition } from "./kernel-zerodev/validator/session-key-validator.js";
15
+ export {
16
+ ParamCondition,
17
+ getAbiItem,
18
+ getPermissionFromABI,
19
+ } from "./kernel-zerodev/validator/session-key-validator.js";
16
20
 
17
21
  // Validator Provider exports
18
22
  export { ValidatorProvider } from "./kernel-zerodev/validator-provider/base.js";
@@ -150,4 +150,4 @@ export const ERC20Abi = [
150
150
  stateMutability: "nonpayable",
151
151
  type: "function",
152
152
  },
153
- ];
153
+ ] as const;
@@ -158,6 +158,13 @@ export class TokenPaymaster extends Paymaster {
158
158
  to: await this.provider.getAddress(),
159
159
  data: erc20CallData,
160
160
  }),
161
+ signature: await this.provider
162
+ .getAccount()
163
+ .getValidator()
164
+ .getDynamicDummySignature(
165
+ (await struct.sender) as Hex,
166
+ erc20CallData
167
+ ),
161
168
  };
162
169
  } catch (error) {
163
170
  return;
@@ -198,7 +205,7 @@ export class TokenPaymaster extends Paymaster {
198
205
  paymasterAddress
199
206
  );
200
207
  if (!erc20UserOp) {
201
- return struct;
208
+ return;
202
209
  }
203
210
  const paymasterResp = await this.signUserOp({
204
211
  userOp: struct,
@@ -6,6 +6,7 @@ import {
6
6
  type UserOperationRequest,
7
7
  getChain,
8
8
  type SignTypedDataParams,
9
+ type Abi,
9
10
  } from "@alchemy/aa-core";
10
11
  import {
11
12
  KernelBaseValidator,
@@ -26,14 +27,18 @@ import {
26
27
  decodeFunctionData,
27
28
  isHex,
28
29
  getFunctionSelector,
30
+ type GetAbiItemParameters,
29
31
  } from "viem";
32
+ import { formatAbiItem } from "viem/utils";
30
33
  import { SessionKeyValidatorAbi } from "../abis/SessionKeyValidatorAbi.js";
31
34
  import { DUMMY_ECDSA_SIG } from "../constants.js";
32
35
  import { KernelAccountAbi } from "../abis/KernelAccountAbi.js";
33
36
  import { MerkleTree } from "merkletreejs";
34
- import type { Operation } from "../provider.js";
37
+ import { Operation } from "../provider.js";
35
38
  import { getChainId } from "../api/index.js";
36
39
  import { fixSignedData } from "../utils.js";
40
+ import type { GetAbiItemReturnType } from "viem/dist/types/utils/abi/getAbiItem.js";
41
+ import type { GeneratePermissionFromArgsParameters } from "./types.js";
37
42
 
38
43
  // We need to be able to serialize bigint to transmit session key over
39
44
  // the network.
@@ -72,13 +77,13 @@ export interface ParamRules {
72
77
  param: Hex;
73
78
  }
74
79
 
75
- export interface Permission {
80
+ export type Permission = {
76
81
  target: Address;
77
- valueLimit: bigint;
78
82
  sig: Hex;
79
83
  rules: ParamRules[];
80
- operation: Operation;
81
- }
84
+ valueLimit?: bigint;
85
+ operation?: Operation;
86
+ };
82
87
 
83
88
  export interface SessionKeyData {
84
89
  validUntil: number;
@@ -87,6 +92,93 @@ export interface SessionKeyData {
87
92
  permissions?: Permission[];
88
93
  }
89
94
 
95
+ export function getAbiItem<
96
+ TAbi extends Abi | readonly unknown[],
97
+ TItemName extends string
98
+ >({
99
+ abi,
100
+ args = [],
101
+ name,
102
+ }: GetAbiItemParameters<TAbi, TItemName>): GetAbiItemReturnType<
103
+ TAbi,
104
+ TItemName
105
+ > {
106
+ const abiItems = (abi as Abi).filter((x) => "name" in x && x.name === name);
107
+ if (abiItems.length === 0) return undefined as any;
108
+ if (abiItems.length === 1) return abiItems[0] as any;
109
+ const abiItemsParamFiltered = [];
110
+ for (const abiItem of abiItems) {
111
+ if (!("inputs" in abiItem)) continue;
112
+ if (!args || args.length === 0) {
113
+ if (!abiItem.inputs || abiItem.inputs.length === 0) return abiItem as any;
114
+ continue;
115
+ }
116
+ if (!abiItem.inputs) continue;
117
+ if (abiItem.inputs.length === 0) continue;
118
+ if (abiItem.inputs.length !== args.length) continue;
119
+ abiItemsParamFiltered.push(abiItem);
120
+ }
121
+ if (abiItemsParamFiltered.length === 0) return abiItems[0] as any;
122
+ else if (abiItemsParamFiltered.length === 1)
123
+ return abiItemsParamFiltered[0] as any;
124
+ else
125
+ throw Error(
126
+ `Couldn't parse funtion signature using params, set appropriate one from below:\n${abiItemsParamFiltered
127
+ .map((item) => formatAbiItem(item))
128
+ .reduce((a, c) => `${a}\n${c}`)}`
129
+ );
130
+ }
131
+
132
+ export function getPermissionFromABI<
133
+ TAbi extends Abi | readonly unknown[],
134
+ TFunctionName extends string | undefined = string
135
+ >({
136
+ abi,
137
+ target,
138
+ args,
139
+ conditions,
140
+ functionName,
141
+ operation,
142
+ valueLimit,
143
+ }: GeneratePermissionFromArgsParameters<TAbi, TFunctionName>): Permission {
144
+ const abiItem = getAbiItem({
145
+ abi,
146
+ args,
147
+ name: functionName,
148
+ } as GetAbiItemParameters);
149
+ if (abiItem.type !== "function") {
150
+ throw Error(`${functionName} not found in abi`);
151
+ }
152
+ const functionSelector = getFunctionSelector(abiItem);
153
+ let paramRules: ParamRules[] = [];
154
+ if (
155
+ args &&
156
+ Array.isArray(args) &&
157
+ conditions &&
158
+ Array.isArray(conditions) &&
159
+ args.length === conditions.length
160
+ ) {
161
+ paramRules = args
162
+ .map<ParamRules>(
163
+ (arg, i) =>
164
+ arg &&
165
+ conditions && {
166
+ param: pad(isHex(arg) ? arg : toHex(arg), { size: 32 }),
167
+ offset: i * 32,
168
+ condition: conditions[i],
169
+ }
170
+ )
171
+ .filter((rule) => rule);
172
+ }
173
+ return {
174
+ sig: functionSelector,
175
+ rules: paramRules,
176
+ target,
177
+ operation: operation ?? Operation.Call,
178
+ valueLimit: valueLimit ?? 0n,
179
+ };
180
+ }
181
+
90
182
  export class SessionKeyValidator extends KernelBaseValidator {
91
183
  protected sessionKey: SmartAccountSigner;
92
184
  sessionKeyData: SessionKeyData;
@@ -97,8 +189,17 @@ export class SessionKeyValidator extends KernelBaseValidator {
97
189
  this.sessionKey = params.sessionKey;
98
190
  this.sessionKeyData = {
99
191
  ...params.sessionKeyData,
192
+ validAfter: params.sessionKeyData.validAfter ?? 0,
193
+ validUntil: params.sessionKeyData.validUntil ?? 0,
100
194
  paymaster: params.sessionKeyData.paymaster ?? zeroAddress,
101
195
  };
196
+ this.sessionKeyData.permissions = this.sessionKeyData.permissions?.map(
197
+ (perm) => ({
198
+ ...perm,
199
+ operation: perm.operation ?? Operation.Call,
200
+ valueLimit: perm.valueLimit ?? 0n,
201
+ })
202
+ );
102
203
  this.merkleTree = this.getMerkleTree();
103
204
  if (this.shouldDelegateViaFallback()) {
104
205
  throw Error("Session key permissions not set");
@@ -168,15 +269,15 @@ export class SessionKeyValidator extends KernelBaseValidator {
168
269
  );
169
270
 
170
271
  const valueLimitPermissions = signaturePermissions.filter(
171
- (permission) => permission.valueLimit >= args[1]
272
+ (permission) => (permission.valueLimit ?? 0n) >= args[1]
172
273
  );
173
274
 
174
275
  if (!valueLimitPermissions.length) return undefined;
175
276
 
176
277
  const sortedPermissions = valueLimitPermissions.sort((a, b) => {
177
- if (b.valueLimit > a.valueLimit) {
278
+ if ((b.valueLimit ?? 0n) > (a.valueLimit ?? 0n)) {
178
279
  return 1;
179
- } else if (b.valueLimit < a.valueLimit) {
280
+ } else if ((b.valueLimit ?? 0n) < (a.valueLimit ?? 0n)) {
180
281
  return -1;
181
282
  } else {
182
283
  return 0;
@@ -194,7 +295,8 @@ export class SessionKeyValidator extends KernelBaseValidator {
194
295
  operation: Operation
195
296
  ): Permission[] {
196
297
  return permissions.filter(
197
- (permission) => permission.operation === operation
298
+ (permission) =>
299
+ permission.operation === operation || Operation.Call === operation
198
300
  );
199
301
  }
200
302