@zerodev/sdk 4.0.29 → 4.0.31
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.
- package/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/index.js +3 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/kernel-zerodev/abis/ERC20Abi.d.ts +231 -39
- package/dist/cjs/kernel-zerodev/abis/ERC20Abi.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator/session-key-validator.d.ts +11 -6
- package/dist/cjs/kernel-zerodev/validator/session-key-validator.js +81 -5
- package/dist/cjs/kernel-zerodev/validator/session-key-validator.js.map +1 -1
- package/dist/cjs/kernel-zerodev/validator/types.d.ts +27 -1
- package/dist/cjs/kernel-zerodev/validator/types.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/kernel-zerodev/abis/ERC20Abi.d.ts +231 -39
- package/dist/esm/kernel-zerodev/abis/ERC20Abi.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator/session-key-validator.d.ts +11 -6
- package/dist/esm/kernel-zerodev/validator/session-key-validator.js +78 -4
- package/dist/esm/kernel-zerodev/validator/session-key-validator.js.map +1 -1
- package/dist/esm/kernel-zerodev/validator/types.d.ts +27 -1
- package/dist/esm/kernel-zerodev/validator/types.js +2 -1
- package/dist/esm/kernel-zerodev/validator/types.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/abis/ERC20Abi.d.ts +231 -39
- package/dist/types/kernel-zerodev/abis/ERC20Abi.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/ethers-provider/ethers-provider.d.ts +0 -17
- package/dist/types/kernel-zerodev/ethers-provider/ethers-provider.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/middleware/gas-estimator.d.ts +0 -4
- package/dist/types/kernel-zerodev/middleware/gas-estimator.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/owner/passkey/types.d.ts +0 -1
- package/dist/types/kernel-zerodev/owner/passkey/types.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/utils/ERC4337-utils.d.ts +0 -12
- package/dist/types/kernel-zerodev/utils/ERC4337-utils.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/utils/calc-pre-verification-gas.d.ts +0 -28
- package/dist/types/kernel-zerodev/utils/calc-pre-verification-gas.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/validator/session-key-validator.d.ts +11 -6
- package/dist/types/kernel-zerodev/validator/session-key-validator.d.ts.map +1 -1
- package/dist/types/kernel-zerodev/validator/types.d.ts +27 -1
- package/dist/types/kernel-zerodev/validator/types.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/index.ts +5 -1
- package/src/kernel-zerodev/abis/ERC20Abi.ts +1 -1
- package/src/kernel-zerodev/validator/session-key-validator.ts +111 -9
- package/src/kernel-zerodev/validator/types.ts +64 -0
|
@@ -8,25 +8,8 @@ export declare class ZeroDevEthersProvider<V extends SupportedValidators> extend
|
|
|
8
8
|
constructor(validatorType: V, params: ValidatorProviderParamsMap[V]);
|
|
9
9
|
static init<V extends SupportedValidators>(validatorType: V, params: ValidatorProviderParamsMap[V]): Promise<ZeroDevEthersProvider<V>>;
|
|
10
10
|
getAccountProvider(): ValidatorProviderTypeMap[V];
|
|
11
|
-
/**
|
|
12
|
-
* Rewrites the send method to use the account provider's EIP-1193
|
|
13
|
-
* compliant request method
|
|
14
|
-
*
|
|
15
|
-
* @param method - the RPC method to call
|
|
16
|
-
* @param params - the params required by the RPC method
|
|
17
|
-
* @returns the result of the RPC call
|
|
18
|
-
*/
|
|
19
11
|
send(method: string, params: any[]): Promise<any>;
|
|
20
|
-
/**
|
|
21
|
-
* Connects the Provider to an Account and returns a Signer
|
|
22
|
-
*
|
|
23
|
-
* @param fn - a function that takes the account provider's rpcClient and returns a BaseSmartContractAccount
|
|
24
|
-
* @returns an {@link ZeroDevAccountSigner} that can be used to sign and send user operations
|
|
25
|
-
*/
|
|
26
12
|
connectToAccount(fn: (rpcClient: PublicErc4337Client) => BaseSmartContractAccount): ZeroDevAccountSigner<V>;
|
|
27
|
-
/**
|
|
28
|
-
* @returns an {@link ZeroDevAccountSigner} using this as the underlying provider
|
|
29
|
-
*/
|
|
30
13
|
getAccountSigner(): ZeroDevAccountSigner<V>;
|
|
31
14
|
withPaymasterMiddleware: (overrides: {
|
|
32
15
|
dummyPaymasterDataMiddleware?: PaymasterAndDataMiddleware;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ethers-provider.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/ethers-provider/ethers-provider.ts"],"names":[],"mappings":"AACA,OAAO,EAEL,wBAAwB,EAExB,KAAK,mBAAmB,EACxB,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,KAAK,0BAA0B,EAC/B,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,uBAAuB,CAAC;AACjE,OAAO,KAAK,EACV,0BAA0B,EAC1B,wBAAwB,EACzB,MAAM,gCAAgC,CAAC;AAIxC,qBAAa,qBAAqB,CAChC,CAAC,SAAS,mBAAmB,CAC7B,SAAQ,eAAe;IACvB,QAAQ,CAAC,eAAe,EAAE,wBAAwB,CAAC,CAAC,CAAC,CAAC;gBAC1C,aAAa,EAAE,CAAC,EAAE,MAAM,EAAE,0BAA0B,CAAC,CAAC,CAAC;WAiC/C,IAAI,CAAC,CAAC,SAAS,mBAAmB,EACpD,aAAa,EAAE,CAAC,EAChB,MAAM,EAAE,0BAA0B,CAAC,CAAC,CAAC,GACpC,OAAO,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;IAoB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AAe;QACpC,4BAA4B,CAAC,EAAE,0BAA0B,CAAC;QAC1D,uBAAuB,CAAC,EAAE,0BAA0B,CAAC;KACtD,KAAG,IAAI,CAGN;IAEF,gBAAgB,aAAc,sBAAsB,KAAG,IAAI,CAGzD;IAEF,iBAAiB,aAAc,iBAAiB,KAAG,IAAI,CAGrD;IAEF,oBAAoB,aAAc,mBAAmB,KAAG,IAAI,CAG1D;IAEF,sBAAsB,IAAI,mBAAmB;CAG9C"}
|
|
@@ -2,10 +2,6 @@ import type { ZeroDevProvider } from "../provider.js";
|
|
|
2
2
|
import { type UserOperationStruct, type BigNumberish } from "@alchemy/aa-core";
|
|
3
3
|
export declare const withZeroDevGasEstimator: (provider: ZeroDevProvider) => ZeroDevProvider;
|
|
4
4
|
export declare const estimateCreationGas: (provider: ZeroDevProvider, initCode?: string) => Promise<bigint>;
|
|
5
|
-
/**
|
|
6
|
-
* should cover cost of putting calldata on-chain, and some overhead.
|
|
7
|
-
* actual overhead depends on the expected bundle size
|
|
8
|
-
*/
|
|
9
5
|
export declare const getPreVerificationGas: (userOp: Partial<UserOperationStruct>) => Promise<number>;
|
|
10
6
|
export declare const eip1559GasPrice: (provider: ZeroDevProvider) => Promise<{
|
|
11
7
|
maxFeePerGas: bigint;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gas-estimator.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/middleware/gas-estimator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAGL,KAAK,mBAAmB,EAExB,KAAK,YAAY,EAElB,MAAM,kBAAkB,CAAC;AAI1B,eAAO,MAAM,uBAAuB,aACxB,eAAe,KACxB,eAmFF,CAAC;AAEF,eAAO,MAAM,mBAAmB,aACpB,eAAe,aACd,MAAM,KAChB,QAAQ,MAAM,CAShB,CAAC;
|
|
1
|
+
{"version":3,"file":"gas-estimator.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/middleware/gas-estimator.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EAGL,KAAK,mBAAmB,EAExB,KAAK,YAAY,EAElB,MAAM,kBAAkB,CAAC;AAI1B,eAAO,MAAM,uBAAuB,aACxB,eAAe,KACxB,eAmFF,CAAC;AAEF,eAAO,MAAM,mBAAmB,aACpB,eAAe,aACd,MAAM,KAChB,QAAQ,MAAM,CAShB,CAAC;AAMF,eAAO,MAAM,qBAAqB,WACxB,QAAQ,mBAAmB,CAAC,KACnC,QAAQ,MAAM,CAGhB,CAAC;AAEF,eAAO,MAAM,eAAe,aAAoB,eAAe;;;EAkB9D,CAAC;AACF,UAAU,OAAO;IACf,YAAY,EAAE,YAAY,GAAG,IAAI,CAAC;IAClC,oBAAoB,EAAE,YAAY,GAAG,IAAI,CAAC;CAC3C;AAED,eAAO,MAAM,UAAU,aACX,eAAe,KACxB,QAAQ,OAAO,CAgCjB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/kernel-zerodev/owner/passkey/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC;AACnC,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAChC,MAAM,MAAM,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;AACjC,MAAM,MAAM,QAAQ,GAAG,GAAG,GAAG,GAAG,EAAE,GAAG,IAAI,CAAC;AAC1C,MAAM,MAAM,eAAe,GACvB,MAAM,GACN;
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/kernel-zerodev/owner/passkey/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,SAAS,GAAG,UAAU,CAAC;AACnC,MAAM,MAAM,GAAG,GAAG,KAAK,MAAM,EAAE,CAAC;AAChC,MAAM,MAAM,IAAI,GAAG,KAAK,MAAM,EAAE,CAAC;AACjC,MAAM,MAAM,QAAQ,GAAG,GAAG,GAAG,GAAG,EAAE,GAAG,IAAI,CAAC;AAC1C,MAAM,MAAM,eAAe,GACvB,MAAM,GACN;IAEE,GAAG,EAAE,GAAG,GAAG,SAAS,CAAC;CACtB,CAAC;AACN,MAAM,MAAM,SAAS,GAAG;IAEtB,CAAC,EAAE,GAAG,CAAC;IAEP,CAAC,EAAE,GAAG,CAAC;IAEP,CAAC,EAAE,MAAM,CAAC;CACX,CAAC"}
|
|
@@ -1,18 +1,6 @@
|
|
|
1
1
|
import { type UserOperationRequest, type UserOperationStruct } from "@alchemy/aa-core";
|
|
2
2
|
import type { NotPromise } from "./calc-pre-verification-gas.js";
|
|
3
|
-
/**
|
|
4
|
-
* pack the userOperation
|
|
5
|
-
* @param op
|
|
6
|
-
* @param forSignature "true" if the hash is needed to calculate the getUserOpHash()
|
|
7
|
-
* "false" to pack entire UserOp, for calculating the calldata cost of putting it on-chain.
|
|
8
|
-
*/
|
|
9
3
|
export declare function packUserOp(op: NotPromise<UserOperationStruct>, forSignature?: boolean): string;
|
|
10
|
-
/**
|
|
11
|
-
* Utility method for asserting a {@link UserOperationStruct} is a {@link UserOperationRequest}
|
|
12
|
-
*
|
|
13
|
-
* @param request a {@link UserOperationStruct} to validate
|
|
14
|
-
* @returns a type guard that asserts the {@link UserOperationStruct} is a {@link UserOperationRequest}
|
|
15
|
-
*/
|
|
16
4
|
export declare function isValidRequest(request: UserOperationStruct): request is UserOperationRequest;
|
|
17
5
|
export declare const hexifyUserOp: (resolvedUserOp: any) => {};
|
|
18
6
|
//# sourceMappingURL=ERC4337-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ERC4337-utils.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/utils/ERC4337-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"ERC4337-utils.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/utils/ERC4337-utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,oBAAoB,EACzB,KAAK,mBAAmB,EACzB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAyCjE,wBAAgB,UAAU,CACxB,EAAE,EAAE,UAAU,CAAC,mBAAmB,CAAC,EACnC,YAAY,UAAO,GAClB,MAAM,CA0ER;AAQD,wBAAgB,cAAc,CAC5B,OAAO,EAAE,mBAAmB,GAC3B,OAAO,IAAI,oBAAoB,CASjC;AAED,eAAO,MAAM,YAAY,mBAAoB,GAAG,OAgB/C,CAAC"}
|
|
@@ -1,44 +1,16 @@
|
|
|
1
1
|
import type { UserOperationStruct } from "@alchemy/aa-core";
|
|
2
2
|
export interface GasOverheads {
|
|
3
|
-
/**
|
|
4
|
-
* fixed overhead for entire handleOp bundle.
|
|
5
|
-
*/
|
|
6
3
|
fixed: number;
|
|
7
|
-
/**
|
|
8
|
-
* per userOp overhead, added on top of the above fixed per-bundle.
|
|
9
|
-
*/
|
|
10
4
|
perUserOp: number;
|
|
11
|
-
/**
|
|
12
|
-
* overhead for userOp word (32 bytes) block
|
|
13
|
-
*/
|
|
14
5
|
perUserOpWord: number;
|
|
15
|
-
/**
|
|
16
|
-
* zero byte cost, for calldata gas cost calculations
|
|
17
|
-
*/
|
|
18
6
|
zeroByte: number;
|
|
19
|
-
/**
|
|
20
|
-
* non-zero byte cost, for calldata gas cost calculations
|
|
21
|
-
*/
|
|
22
7
|
nonZeroByte: number;
|
|
23
|
-
/**
|
|
24
|
-
* expected bundle size, to split per-bundle overhead between all ops.
|
|
25
|
-
*/
|
|
26
8
|
bundleSize: number;
|
|
27
|
-
/**
|
|
28
|
-
* expected length of the userOp signature.
|
|
29
|
-
*/
|
|
30
9
|
sigSize: number;
|
|
31
10
|
}
|
|
32
11
|
export declare const DefaultGasOverheads: GasOverheads;
|
|
33
12
|
export type NotPromise<T> = {
|
|
34
13
|
[P in keyof T]: Exclude<T[P], Promise<any>>;
|
|
35
14
|
};
|
|
36
|
-
/**
|
|
37
|
-
* calculate the preVerificationGas of the given UserOperation
|
|
38
|
-
* preVerificationGas (by definition) is the cost overhead that can't be calculated on-chain.
|
|
39
|
-
* it is based on parameters that are defined by the Ethereum protocol for external transactions.
|
|
40
|
-
* @param userOp filled userOp to calculate. The only possible missing fields can be the signature and preVerificationGas itself
|
|
41
|
-
* @param overheads gas overheads to use, to override the default values
|
|
42
|
-
*/
|
|
43
15
|
export declare function calcPreVerificationGas(userOp: Partial<NotPromise<UserOperationStruct>>, overheads?: Partial<GasOverheads>): number;
|
|
44
16
|
//# sourceMappingURL=calc-pre-verification-gas.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calc-pre-verification-gas.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/utils/calc-pre-verification-gas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAI5D,MAAM,WAAW,YAAY;
|
|
1
|
+
{"version":3,"file":"calc-pre-verification-gas.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/utils/calc-pre-verification-gas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAI5D,MAAM,WAAW,YAAY;IAI3B,KAAK,EAAE,MAAM,CAAC;IAKd,SAAS,EAAE,MAAM,CAAC;IAKlB,aAAa,EAAE,MAAM,CAAC;IAOtB,QAAQ,EAAE,MAAM,CAAC;IAKjB,WAAW,EAAE,MAAM,CAAC;IAKpB,UAAU,EAAE,MAAM,CAAC;IAKnB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,eAAO,MAAM,mBAAmB,EAAE,YAQjC,CAAC;AAEF,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI;KACzB,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;CAC5C,CAAC;AASF,wBAAgB,sBAAsB,CACpC,MAAM,EAAE,OAAO,CAAC,UAAU,CAAC,mBAAmB,CAAC,CAAC,EAChD,SAAS,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,GAChC,MAAM,CAoBR"}
|
|
@@ -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
|
|
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
|
|
30
|
+
export type Permission = {
|
|
28
31
|
target: Address;
|
|
29
|
-
valueLimit: bigint;
|
|
30
32
|
sig: Hex;
|
|
31
33
|
rules: ParamRules[];
|
|
32
|
-
|
|
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,
|
|
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,EACxB,KAAK,GAAG,EACT,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EACL,mBAAmB,EAEnB,KAAK,yBAAyB,EAC9B,KAAK,mBAAmB,EACzB,MAAM,WAAW,CAAC;AACnB,OAAO,EAaL,KAAK,oBAAoB,EAC1B,MAAM,MAAM,CAAC;AAKd,OAAO,EA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AO,CAAC,OAAO,CAAC;IA+Bb,uBAAuB,CAAC,QAAQ,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;IA6B1D,YAAY,CAAC,oBAAoB,EAAE,GAAG,GAAG,GAAG;IAQ5C,aAAa,CAAC,UAAU,EAAE,GAAG,GAAG,GAAG;IAQ7B,WAAW,CAAC,OAAO,EAAE,MAAM,GAAG,UAAU,GAAG,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,KAAK,EACV,mBAAmB,EACnB,yBAAyB,EACzB,UAAU,EACV,UAAU,EACV,cAAc,EACd,gBAAgB,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/kernel-zerodev/validator/types.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,2BAA2B,EAChC,KAAK,WAAW,EAChB,KAAK,kBAAkB,EACxB,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,sBAAsB,CAAC;AACnD,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,KAAK,EACV,mBAAmB,EACnB,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AAC,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.
|
|
3
|
+
"version": "4.0.31",
|
|
4
4
|
"description": "A collection of ERC-4337 compliant smart contract account interfaces",
|
|
5
5
|
"author": "ZeroDev",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,8 +36,8 @@
|
|
|
36
36
|
},
|
|
37
37
|
"scripts": {
|
|
38
38
|
"build": "yarn clean && yarn build:cjs && yarn build:esm && yarn build:types",
|
|
39
|
-
"build:cjs": "tsc --project tsconfig.build.json
|
|
40
|
-
"build:esm": "tsc --project tsconfig.build.json
|
|
39
|
+
"build:cjs": "tsc --project tsconfig.build-cjs.json && echo > ./dist/cjs/package.json '{\"type\":\"commonjs\"}'",
|
|
40
|
+
"build:esm": "tsc --project tsconfig.build.json && echo > ./dist/esm/package.json '{\"type\":\"module\"}'",
|
|
41
41
|
"build:types": "tsc --project tsconfig.build.json --module esnext --declarationDir ./dist/types --emitDeclarationOnly --declaration --declarationMap",
|
|
42
42
|
"clean": "rm -rf ./dist",
|
|
43
43
|
"test": "vitest",
|
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 {
|
|
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";
|
|
@@ -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
|
|
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
|
|
80
|
+
export type Permission = {
|
|
76
81
|
target: Address;
|
|
77
|
-
valueLimit: bigint;
|
|
78
82
|
sig: Hex;
|
|
79
83
|
rules: ParamRules[];
|
|
80
|
-
|
|
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) =>
|
|
298
|
+
(permission) =>
|
|
299
|
+
permission.operation === operation || Operation.Call === operation
|
|
198
300
|
);
|
|
199
301
|
}
|
|
200
302
|
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type AbiParameter,
|
|
3
|
+
type AbiParameterKind,
|
|
4
|
+
type AbiParameterToPrimitiveType,
|
|
5
|
+
type AbiFunction,
|
|
6
|
+
type ExtractAbiFunction,
|
|
7
|
+
} from "abitype";
|
|
8
|
+
import { type Pretty } from "abitype/src/types.js";
|
|
1
9
|
import type {
|
|
2
10
|
ECDSAValidator,
|
|
3
11
|
ECDSAValidatorParams,
|
|
@@ -22,7 +30,9 @@ import type {
|
|
|
22
30
|
Permission,
|
|
23
31
|
SessionKeyData,
|
|
24
32
|
SessionKeyParams,
|
|
33
|
+
ParamCondition,
|
|
25
34
|
} from "./session-key-validator.js";
|
|
35
|
+
import type { Abi, InferFunctionName, Narrow } from "viem";
|
|
26
36
|
|
|
27
37
|
export type SupportedValidators =
|
|
28
38
|
| "ECDSA"
|
|
@@ -56,3 +66,57 @@ export type ValidatorMap = {
|
|
|
56
66
|
export type EthereumProvider = { request(...args: any): Promise<any> };
|
|
57
67
|
|
|
58
68
|
export type { ParamRules, Permission, SessionKeyData, SessionKeyParams };
|
|
69
|
+
|
|
70
|
+
// Session Key types
|
|
71
|
+
export type AbiParametersToPrimitiveTypes<
|
|
72
|
+
TAbiParameters extends readonly AbiParameter[],
|
|
73
|
+
TAbiParameterKind extends AbiParameterKind = AbiParameterKind
|
|
74
|
+
> = Pretty<{
|
|
75
|
+
[K in keyof TAbiParameters]: AbiParameterToPrimitiveType<
|
|
76
|
+
TAbiParameters[K],
|
|
77
|
+
TAbiParameterKind
|
|
78
|
+
> | null;
|
|
79
|
+
}>;
|
|
80
|
+
|
|
81
|
+
export type AbiParametersToConditons<
|
|
82
|
+
TAbiParameters extends readonly AbiParameter[]
|
|
83
|
+
> = Pretty<{
|
|
84
|
+
[K in keyof TAbiParameters]: ParamCondition | null;
|
|
85
|
+
}>;
|
|
86
|
+
|
|
87
|
+
export type GetFunctionArgs<
|
|
88
|
+
TAbi extends Abi | readonly unknown[],
|
|
89
|
+
TFunctionName extends string,
|
|
90
|
+
TAbiFunction extends AbiFunction = TAbi extends Abi
|
|
91
|
+
? ExtractAbiFunction<TAbi, TFunctionName>
|
|
92
|
+
: AbiFunction,
|
|
93
|
+
TArgs = AbiParametersToPrimitiveTypes<TAbiFunction["inputs"]>,
|
|
94
|
+
TConditions = AbiParametersToConditons<TAbiFunction["inputs"]>,
|
|
95
|
+
FailedToParseArgs =
|
|
96
|
+
| ([TArgs] extends [never] ? true : false)
|
|
97
|
+
| (readonly unknown[] extends TArgs ? true : false)
|
|
98
|
+
> = true extends FailedToParseArgs
|
|
99
|
+
? {
|
|
100
|
+
args?: readonly unknown[];
|
|
101
|
+
conditions?: readonly unknown[];
|
|
102
|
+
}
|
|
103
|
+
: TArgs extends readonly []
|
|
104
|
+
? { args?: never; conditions?: never }
|
|
105
|
+
: {
|
|
106
|
+
args?: TArgs;
|
|
107
|
+
conditions?: TConditions;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
export type GeneratePermissionFromArgsParameters<
|
|
111
|
+
TAbi extends Abi | readonly unknown[],
|
|
112
|
+
TFunctionName extends string | undefined = string,
|
|
113
|
+
_FunctionName = TAbi extends Abi
|
|
114
|
+
? InferFunctionName<TAbi, TFunctionName>
|
|
115
|
+
: never
|
|
116
|
+
> = Pick<Permission, "operation" | "target" | "valueLimit"> & {
|
|
117
|
+
functionName?: _FunctionName;
|
|
118
|
+
} & (TFunctionName extends string
|
|
119
|
+
? { abi: Narrow<TAbi> } & GetFunctionArgs<TAbi, TFunctionName>
|
|
120
|
+
: _FunctionName extends string
|
|
121
|
+
? { abi: [Narrow<TAbi[number]>] } & GetFunctionArgs<TAbi, _FunctionName>
|
|
122
|
+
: never);
|