├── packages ├── core │ ├── utils │ │ └── index.ts │ ├── providers │ │ └── index.ts │ ├── README.md │ ├── clients │ │ ├── decorators │ │ │ └── index.ts │ │ ├── index.ts │ │ └── utils.ts │ ├── accounts │ │ ├── kernel │ │ │ ├── utils │ │ │ │ ├── types.ts │ │ │ │ ├── ep0_7 │ │ │ │ │ ├── hashKernelSignatureWrapper.ts │ │ │ │ │ ├── encodeExecuteSingleCall.ts │ │ │ │ │ ├── encodeExecuteDelegateCall.ts │ │ │ │ │ └── encodeExecuteBatchCall.ts │ │ │ │ ├── ep0_6 │ │ │ │ │ ├── encodeExecuteSingleCall.ts │ │ │ │ │ ├── encodeExecuteDelegateCall.ts │ │ │ │ │ └── encodeExecuteBatchCall.ts │ │ │ │ ├── common │ │ │ │ │ ├── encodeSafeCreateCall.ts │ │ │ │ │ ├── getActionSelector.ts │ │ │ │ │ ├── getUpgradeKernelCall.ts │ │ │ │ │ ├── eip712WrapHash.ts │ │ │ │ │ └── accountMetadata.ts │ │ │ │ ├── plugins │ │ │ │ │ ├── ep0_7 │ │ │ │ │ │ ├── getPluginInstallCallData.ts │ │ │ │ │ │ ├── isPluginInitialized.ts │ │ │ │ │ │ ├── getValidatorPluginInstallCallData.ts │ │ │ │ │ │ ├── getEncodedPluginsData.ts │ │ │ │ │ │ └── getValidatorPluginInstallModuleData.ts │ │ │ │ │ └── ep0_6 │ │ │ │ │ │ ├── getEncodedPluginsData.ts │ │ │ │ │ │ └── getPluginsEnableTypedData.ts │ │ │ │ └── account │ │ │ │ │ ├── ep0_7 │ │ │ │ │ ├── getKernelV3Nonce.ts │ │ │ │ │ ├── encodeDeployCallData.ts │ │ │ │ │ └── encodeCallData.ts │ │ │ │ │ └── ep0_6 │ │ │ │ │ ├── encodeDeployCallData.ts │ │ │ │ │ ├── encodeModuleInstallCallData.ts │ │ │ │ │ └── encodeCallData.ts │ │ │ └── abi │ │ │ │ ├── SafeCreateCallAbi.ts │ │ │ │ ├── EIP1271Abi.ts │ │ │ │ └── kernel_v_3_0_0 │ │ │ │ ├── KernelFactoryAbi.ts │ │ │ │ └── KernelModuleAbi.ts │ │ ├── utils │ │ │ ├── index.ts │ │ │ ├── getCustomNonceKeyFromString.ts │ │ │ └── multisend.ts │ │ ├── addressToEmptyAccount.ts │ │ └── index.ts │ ├── tsconfig.build.json │ ├── .changeset │ │ ├── config.json │ │ └── README.md │ ├── types │ │ ├── utils.ts │ │ └── index.ts │ ├── actions │ │ ├── public │ │ │ ├── isSmartAccountDeployed.ts │ │ │ ├── index.ts │ │ │ ├── getKernelImplementationAddress.ts │ │ │ └── isPluginInstalled.ts │ │ ├── account-client │ │ │ ├── getUserOperationGasPrice.ts │ │ │ ├── getKernelV3ModuleCurrentNonce.ts │ │ │ ├── upgradeKernel.ts │ │ │ └── signUserOperation.ts │ │ ├── index.ts │ │ └── paymaster │ │ │ └── estimateGasInERC20.ts │ └── errors │ │ └── index.ts └── test │ ├── utils_0_6 │ ├── index.ts │ ├── recovery.ts │ └── modularPermissionUtils.ts │ ├── v0.7 │ └── utils │ │ ├── index.ts │ │ ├── session.ts │ │ ├── recovery.ts │ │ └── remoteSigner.ts │ ├── tsconfig.build.json │ ├── package.json │ ├── actions │ └── utils │ │ └── deployAccount.ts │ ├── abis │ ├── TokenActionsAbi.ts │ └── SimpleAccountFactory.ts │ └── config.ts ├── bun.lockb ├── plugins ├── multi-chain-ecdsa │ ├── actions │ │ └── index.ts │ ├── constants.ts │ ├── tsconfig.build.json │ ├── index.ts │ ├── utils │ │ └── ecdsaGetMultiUserOpDummySignature.ts │ └── package.json ├── multi-chain-web-authn │ ├── actions │ │ └── index.ts │ ├── tsconfig.build.json │ ├── constants.ts │ ├── utils │ │ └── decodeSignature.ts │ ├── index.ts │ └── package.json ├── hooks │ ├── index.ts │ ├── constants.ts │ ├── tsconfig.build.json │ ├── CHANGELOG.md │ ├── toSpendingLimitHook.ts │ └── package.json ├── webauthn-key │ ├── index.ts │ ├── tsconfig.build.json │ ├── CHANGELOG.md │ └── package.json ├── multi-tenant-session-account │ ├── clients │ │ └── index.ts │ ├── enforcers │ │ ├── allowed-params │ │ │ ├── index.ts │ │ │ ├── constants.ts │ │ │ └── toAllowedParamsEnforcer.ts │ │ ├── cab-paymaster │ │ │ ├── type.ts │ │ │ └── index.ts │ │ ├── index.ts │ │ └── allowed-targets │ │ │ └── toAllowedTargetsEnforcer.ts │ ├── utils │ │ └── index.ts │ ├── tsconfig.build.json │ ├── index.ts │ ├── types.ts │ ├── actions │ │ ├── index.ts │ │ └── installDMAsExecutor.ts │ ├── CHANGELOG.md │ ├── constants.ts │ └── abi │ │ └── YiSubAccountAbi.ts ├── remoteSigner │ ├── index.ts │ ├── tsconfig.build.json │ ├── CHANGELOG.md │ └── package.json ├── react-native-passkeys-utils │ ├── index.ts │ ├── tsconfig.build.json │ ├── CHANGELOG.md │ └── package.json ├── social │ ├── index.ts │ ├── tsconfig.build.json │ ├── CHANGELOG.md │ └── package.json ├── smart-account │ ├── CHANGELOG.md │ ├── constants.ts │ ├── tsconfig.build.json │ ├── index.ts │ └── package.json ├── modularPermission │ ├── policies │ │ ├── index.ts │ │ ├── toSudoPolicy.ts │ │ ├── toSignaturePolicy.ts │ │ ├── types.ts │ │ └── toGasPolicy.ts │ ├── tsconfig.build.json │ ├── signers │ │ ├── types.ts │ │ ├── index.ts │ │ └── toECDSASigner.ts │ ├── index.ts │ ├── constants.ts │ ├── CHANGELOG.md │ ├── serializeModularPermissionAccount.ts │ └── utils.ts ├── ecdsa │ ├── tsconfig.build.json │ ├── constants.ts │ ├── index.ts │ ├── package.json │ └── CHANGELOG.md ├── passkey │ ├── tsconfig.build.json │ └── package.json ├── permission │ ├── tsconfig.build.json │ ├── signers │ │ ├── utils │ │ │ └── toSignerId.ts │ │ ├── index.ts │ │ ├── toEmptyECDSASigner.ts │ │ └── toECDSASigner.ts │ ├── policies │ │ ├── utils │ │ │ └── toPolicyId.ts │ │ ├── index.ts │ │ ├── toSudoPolicy.ts │ │ ├── toSignatureCallerPolicy.ts │ │ ├── toTimestampPolicy.ts │ │ └── toGasPolicy.ts │ ├── index.ts │ ├── migration │ │ └── isPermissionMigrated.ts │ ├── utils.ts │ └── toInitConfig.ts ├── session-key │ ├── tsconfig.build.json │ ├── index.ts │ ├── CHANGELOG.md │ ├── serializeSessionKeyAccount.ts │ └── package.json ├── weighted-ecdsa │ ├── tsconfig.build.json │ ├── index.ts │ ├── CHANGELOG.md │ ├── package.json │ └── constants.ts ├── weighted-r1-k1 │ ├── tsconfig.build.json │ ├── utils.ts │ ├── signers │ │ └── toECDSASigner.ts │ ├── package.json │ └── index.ts └── multi-chain-weighted-validator │ ├── tsconfig.build.json │ ├── constants.ts │ ├── utils.ts │ ├── signers │ └── toECDSASigner.ts │ ├── package.json │ ├── CHANGELOG.md │ └── clients │ └── decorators │ └── multiChainWeightedKernelAccountClient.ts ├── templates └── typescript │ └── tsconfig.build.json ├── .gitignore ├── tsconfig.build.json ├── .changeset ├── config.json └── README.md ├── .github ├── actions │ └── install-dependencies │ │ └── action.yml └── workflows │ ├── on-pull-request.yml │ └── on-push-to-main.yml ├── .size-limit.json ├── .env.example ├── remove-type.sh ├── restore-type.sh ├── LICENSE ├── biome.json ├── package.json └── README.md /packages/core/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./toSigner.js" 2 | -------------------------------------------------------------------------------- /bun.lockb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/zerodevapp/sdk/HEAD/bun.lockb -------------------------------------------------------------------------------- /plugins/multi-chain-ecdsa/actions/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./signUserOperations.js" 2 | -------------------------------------------------------------------------------- /plugins/multi-chain-web-authn/actions/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./signUserOperations.js" 2 | -------------------------------------------------------------------------------- /packages/core/providers/index.ts: -------------------------------------------------------------------------------- 1 | export { KernelEIP1193Provider } from "./KernelEIP1193Provider.js" 2 | -------------------------------------------------------------------------------- /plugins/hooks/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./constants.js" 2 | export * from "./toSpendingLimitHook.js" 3 | -------------------------------------------------------------------------------- /plugins/webauthn-key/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./toWebAuthnKey.js" 2 | export * from "./utils.js" 3 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/clients/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./decorators/dmActionsEip7710.js" 2 | -------------------------------------------------------------------------------- /packages/core/README.md: -------------------------------------------------------------------------------- 1 | # ZeroDev SDK 2 | 3 | See [ZeroDev docs](https://docs.zerodev.app/) for details. 4 | -------------------------------------------------------------------------------- /plugins/hooks/constants.ts: -------------------------------------------------------------------------------- 1 | export const SPENDING_LIMIT_HOOK_V07 = 2 | "0xb6D6B30C9E1A28E8044F4cCB48A63A423Ee3D70E" 3 | -------------------------------------------------------------------------------- /plugins/multi-chain-ecdsa/constants.ts: -------------------------------------------------------------------------------- 1 | export const MULTI_CHAIN_ECDSA_VALIDATOR_ADDRESS = 2 | "0x5C97aA67Ba578E3c54ec5942A7563Ea9130E4f5F" 3 | -------------------------------------------------------------------------------- /packages/core/clients/decorators/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | zerodevPaymasterActions, 3 | type ZeroDevPaymasterClientActions 4 | } from "./kernel.js" 5 | -------------------------------------------------------------------------------- /plugins/remoteSigner/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | toRemoteSigner, 3 | RemoteSignerMode, 4 | type RemoteSignerParams 5 | } from "./toRemoteSigner.js" 6 | -------------------------------------------------------------------------------- /plugins/react-native-passkeys-utils/index.ts: -------------------------------------------------------------------------------- 1 | export { signMessageWithReactNativePasskeys } from "./signMessageWithReactNativePasskeys.js" 2 | export { parsePasskeyCred, parseLoginCred } from "./utils.js" 3 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/enforcers/allowed-params/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./toAllowedParamsEnforcer.js" 2 | export * from "./utils.js" 3 | export type * from "./types.js" 4 | export * from "./constants.js" 5 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/enforcers/cab-paymaster/type.ts: -------------------------------------------------------------------------------- 1 | import type { Address } from "viem" 2 | 3 | export type RepayTokenInfo = { 4 | amount: bigint 5 | vault: Address 6 | chainId: bigint 7 | } 8 | -------------------------------------------------------------------------------- /plugins/social/index.ts: -------------------------------------------------------------------------------- 1 | import { 2 | getSocialValidator, 3 | initiateLogin, 4 | isAuthorized, 5 | logout 6 | } from "./toSocialValidatorPlugin.js" 7 | 8 | export { getSocialValidator, isAuthorized, initiateLogin, logout } 9 | -------------------------------------------------------------------------------- /packages/test/utils_0_6/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./common" 2 | export * from "./ecdsaUtils" 3 | export * from "./sessionKeyUtils" 4 | export * from "./modularPermissionUtils" 5 | export * from "./weightedEcdsa" 6 | export * from "./recovery" 7 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/types.ts: -------------------------------------------------------------------------------- 1 | import type { Address, Hex } from "viem" 2 | 3 | export type CallArgs = { 4 | to: Address 5 | data?: Hex 6 | value?: bigint 7 | } 8 | export type DelegateCallArgs = Omit 9 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/utils/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | getDelegationTupleType, 3 | toDelegationHash, 4 | getCaveatPackedHash, 5 | getCaveatsPackedHash, 6 | getInstallDMAsExecutorCallData 7 | } from "./delegationManager.js" 8 | -------------------------------------------------------------------------------- /packages/test/v0.7/utils/index.ts: -------------------------------------------------------------------------------- 1 | export * from "./common" 2 | export * from "./ecdsaUtils" 3 | export * from "./permissionUtils" 4 | export * from "./session" 5 | export * from "./weightedEcdsa" 6 | export * from "./recovery" 7 | export * from "./remoteSigner" 8 | -------------------------------------------------------------------------------- /plugins/smart-account/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @zerodev/smart-account-validator 2 | 3 | ## 5.4.1 4 | 5 | ### Patch Changes 6 | 7 | - fix: signTypedData suppport in toSmartAccountValidatorPlugin 8 | 9 | ## 5.4.0 10 | 11 | ### Patch Changes 12 | 13 | - Initial release 14 | -------------------------------------------------------------------------------- /packages/core/accounts/utils/index.ts: -------------------------------------------------------------------------------- 1 | export { toKernelPluginManager } from "./toKernelPluginManager.js" 2 | 3 | export { verifyEIP6492Signature, universalValidatorByteCode } from "./6492.js" 4 | 5 | export { getCustomNonceKeyFromString } from "./getCustomNonceKeyFromString.js" 6 | -------------------------------------------------------------------------------- /templates/typescript/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | // This file is used to compile the for cjs and esm (see package.json build scripts). It should exclude all test files. 3 | "extends": "./tsconfig.base.json", 4 | "compilerOptions": { 5 | "moduleResolution": "node", 6 | "sourceMap": true, 7 | } 8 | } -------------------------------------------------------------------------------- /plugins/modularPermission/policies/index.ts: -------------------------------------------------------------------------------- 1 | export { toGasPolicy } from "./toGasPolicy.js" 2 | export { toMerklePolicy, Operation, ParamOperator } from "./toMerklePolicy.js" 3 | export { toSignaturePolicy } from "./toSignaturePolicy.js" 4 | export { toSudoPolicy } from "./toSudoPolicy.js" 5 | export type * from "./types.js" 6 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/enforcers/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | type AllowedTargetsEnforcerAddress, 3 | type AllowedTargetsEnforcerParams, 4 | toAllowedTargetsEnforcer 5 | } from "./allowed-targets/toAllowedTargetsEnforcer.js" 6 | export * from "./allowed-params/index.js" 7 | export * from "./cab-paymaster/index.js" 8 | -------------------------------------------------------------------------------- /packages/test/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./" 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | _cjs 2 | _esm 3 | _types 4 | *.local 5 | .DS_Store 6 | .eslintcache 7 | .next 8 | bench 9 | cache 10 | coverage 11 | node_modules 12 | tsconfig*.tsbuildinfo 13 | esbuild-why-permissionless* 14 | 15 | # local env files 16 | .env 17 | .env.local 18 | .env.development.local 19 | .env.test.local 20 | .env.production.local 21 | .envrc 22 | .vscode -------------------------------------------------------------------------------- /tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "./templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "outDir": "./", 9 | // "test": "./**/*.test.ts" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/core/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./", 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/ecdsa/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/hooks/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/social/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/ecdsa/constants.ts: -------------------------------------------------------------------------------- 1 | import type { Address } from "viem" 2 | 3 | export const kernelVersionRangeToValidator: { 4 | [key: string]: Address 5 | } = { 6 | "0.0.2 - 0.2.4": "0xd9AB5096a832b9ce79914329DAEE236f8Eea0390", 7 | "0.3.0": "0x8104e3Ad430EA6d354d013A6789fDFc71E671c43", 8 | ">=0.3.1": "0x845ADb2C711129d4f3966735eD98a9F09fC4cE57" 9 | } 10 | -------------------------------------------------------------------------------- /plugins/passkey/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/permission/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/session-key/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/smart-account/constants.ts: -------------------------------------------------------------------------------- 1 | import type { Address } from "viem" 2 | 3 | export const validatorAddresses: { 4 | [key: string]: Address 5 | } = { 6 | "0.0.1": "0xBF997aC6751e3aC5Ed7c22e358A1D536680Bb8e3" 7 | } 8 | 9 | export const kernelVersionRangeToValidatorVersion: { 10 | [key: string]: string 11 | } = { 12 | ">=0.3.0": "0.0.1" 13 | } 14 | -------------------------------------------------------------------------------- /plugins/remoteSigner/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/smart-account/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/webauthn-key/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/weighted-ecdsa/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/weighted-r1-k1/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /packages/core/.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@3.0.0/schema.json", 3 | "changelog": "@changesets/cli/changelog", 4 | "commit": false, 5 | "fixed": [], 6 | "linked": [], 7 | "access": "restricted", 8 | "baseBranch": "main", 9 | "updateInternalDependencies": "patch", 10 | "ignore": [] 11 | } 12 | -------------------------------------------------------------------------------- /plugins/modularPermission/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/multi-chain-ecdsa/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/multi-chain-web-authn/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/modularPermission/signers/types.ts: -------------------------------------------------------------------------------- 1 | import type { Address, Hex, LocalAccount } from "viem" 2 | 3 | export type ModularSignerParams = { 4 | signerContractAddress?: Address 5 | } 6 | 7 | export type ModularSigner = { 8 | account: LocalAccount 9 | signerContractAddress: Address 10 | getSignerData: () => Hex 11 | getDummySignature: () => Hex 12 | } 13 | -------------------------------------------------------------------------------- /plugins/smart-account/index.ts: -------------------------------------------------------------------------------- 1 | import type { KernelValidator } from "@zerodev/sdk/types" 2 | import { 3 | getValidatorAddress, 4 | signerToSmartAccountValidator 5 | } from "./toSmartAccountValidatorPlugin.js" 6 | 7 | export { 8 | getValidatorAddress, 9 | signerToSmartAccountValidator, 10 | type KernelValidator 11 | } 12 | export * from "./constants.js" 13 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/abi/SafeCreateCallAbi.ts: -------------------------------------------------------------------------------- 1 | import { parseAbi } from "viem" 2 | 3 | export const SafeCreateCallAbi = parseAbi([ 4 | "function performCreate(uint256 value, bytes memory deploymentData) public returns (address newContract)", 5 | "function performCreate2(uint256 value, bytes memory deploymentData, bytes32 salt) public returns (address newContract)" 6 | ]) 7 | -------------------------------------------------------------------------------- /plugins/multi-chain-weighted-validator/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./", 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/react-native-passkeys-utils/tsconfig.build.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../templates/typescript/tsconfig.build.json", 3 | "include": ["./"], 4 | "exclude": ["./**/*.test.ts", "./**/*.test-d.ts", "./**/*.bench.ts"], 5 | "compilerOptions": { 6 | "moduleResolution": "node", 7 | "sourceMap": true, 8 | "rootDir": "./", 9 | "baseUrl": "./" 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /plugins/modularPermission/signers/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | toECDSASigner, 3 | type ECDSAModularSignerParams 4 | } from "./toECDSASigner.js" 5 | export { 6 | toWebAuthnSigner, 7 | type WebAuthnKey, 8 | type WebAuthnModularSignerParams 9 | } from "./toWebAuthnSigner.js" 10 | export { toWebAuthnPubKey, WebAuthnMode } from "./toWebAuthnPubKey.js" 11 | export type * from "./types.js" 12 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/enforcers/cab-paymaster/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | CABPaymasterEnforcerAddressV0_1, 3 | CABPaymasterEnforcerAddressV0_2, 4 | type ENFORCER_VERSION, 5 | getEnforcerAddress, 6 | type CABPaymasterEnforcerArgs, 7 | type CABPaymasterEnforcerParams, 8 | toCABPaymasterEnforcer 9 | } from "./toCABPaymasterEnforcer.js" 10 | export * from "./utils.js" 11 | -------------------------------------------------------------------------------- /packages/core/clients/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | createZeroDevPaymasterClient, 3 | type ZeroDevPaymasterClient 4 | } from "./paymasterClient.js" 5 | 6 | export { 7 | createKernelAccountClient, 8 | type KernelAccountClient, 9 | type SmartAccountClientConfig 10 | } from "./kernelAccountClient.js" 11 | 12 | export { createFallbackKernelAccountClient } from "./fallbackKernelAccountClient.js" 13 | -------------------------------------------------------------------------------- /plugins/permission/signers/utils/toSignerId.ts: -------------------------------------------------------------------------------- 1 | import { type Hex, concat, encodeAbiParameters } from "viem" 2 | import type { ModularSigner } from "../../types.js" 3 | 4 | export const toSignerId = (signer: ModularSigner): Hex => { 5 | return encodeAbiParameters( 6 | [{ name: "signerData", type: "bytes" }], 7 | [concat([signer.signerContractAddress, signer.getSignerData()])] 8 | ) 9 | } 10 | -------------------------------------------------------------------------------- /plugins/multi-chain-web-authn/constants.ts: -------------------------------------------------------------------------------- 1 | export const MULTI_CHAIN_WEBAUTHN_VALIDATOR_ADDRESS = 2 | "0x56Bf68A3Eb0b95A4EC0880E5F39Cf45CF58dAe70" 3 | 4 | export const MULTI_CHAIN_WEBAUTHN_VALIDATOR_ADDRESS_V_0_0_2 = 5 | "0xF98365FAD8403C340b1D5F017b2EBdaE641104ff" 6 | 7 | export enum MultiChainWebAuthnValidatorContractVersion { 8 | V0_0_1_UNPATCHED = "0.0.1", 9 | V0_0_2_PATCHED = "0.0.2" 10 | } 11 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | type CreateSessionAccountParameters, 3 | type CreateSessionAccountReturnType, 4 | type SessionAccountEncodeCallDataArgs, 5 | type SessionAccountImplementation, 6 | createSessionAccount 7 | } from "./account/createSessionAccount.js" 8 | 9 | export * from "./utils/index.js" 10 | export * from "./constants.js" 11 | export type * from "./types.js" 12 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/types.ts: -------------------------------------------------------------------------------- 1 | import type { Address, Hex } from "viem" 2 | 3 | export type DM_VERSION_TYPE = "1.0.0" 4 | 5 | export type Caveat = { 6 | enforcer: Address 7 | args: Hex 8 | terms: Hex 9 | } 10 | 11 | export type Delegation = { 12 | delegate: Address 13 | delegator: Address 14 | authority: Hex 15 | caveats: Caveat[] 16 | salt: bigint 17 | signature: Hex 18 | } 19 | -------------------------------------------------------------------------------- /plugins/weighted-ecdsa/index.ts: -------------------------------------------------------------------------------- 1 | import type { KernelValidator } from "@zerodev/sdk/types" 2 | import { 3 | createWeightedECDSAValidator, 4 | getCurrentSigners, 5 | getUpdateConfigCall 6 | } from "./toWeightedECDSAValidatorPlugin.js" 7 | 8 | export { 9 | createWeightedECDSAValidator, 10 | getUpdateConfigCall, 11 | getCurrentSigners, 12 | type KernelValidator 13 | } 14 | export * from "./constants.js" 15 | -------------------------------------------------------------------------------- /packages/core/types/utils.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | Account, 3 | Chain, 4 | EIP1193Provider, 5 | LocalAccount, 6 | OneOf, 7 | Transport, 8 | WalletClient 9 | } from "viem" 10 | import type { SmartAccount } from "viem/account-abstraction" 11 | 12 | export type Signer = OneOf< 13 | | EIP1193Provider 14 | | WalletClient 15 | | LocalAccount 16 | | SmartAccount 17 | > 18 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@2.1.0/schema.json", 3 | "changelog": "@changesets/changelog-git", 4 | "commit": false, 5 | "access": "public", 6 | "baseBranch": "main", 7 | "updateInternalDependencies": "patch", 8 | "___experimentalUnsafeOptions_WILL_CHANGE_IN_PATCH": { 9 | "onlyUpdatePeerDependentsWhenOutOfRange": true 10 | }, 11 | "ignore": ["@zerodev/sdk-test"] 12 | } 13 | -------------------------------------------------------------------------------- /plugins/modularPermission/index.ts: -------------------------------------------------------------------------------- 1 | export { createPermissionValidator } from "./toModularPermissionValidatorPlugin.js" 2 | export * as constants from "./constants.js" 3 | export type * from "./types.js" 4 | export { ModularPermissionValidatorAbi } from "./abi/ModularPermissionValidatorAbi.js" 5 | export { serializeModularPermissionAccount } from "./serializeModularPermissionAccount.js" 6 | export { deserializeModularPermissionAccount } from "./deserializeModularPermissionAccount.js" 7 | -------------------------------------------------------------------------------- /plugins/permission/signers/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | toECDSASigner, 3 | type ECDSAModularSignerParams 4 | } from "./toECDSASigner.js" 5 | export { 6 | toWebAuthnSigner, 7 | type WebAuthnModularSignerParams, 8 | WebAuthnSignerVersion 9 | } from "./toWebAuthnSigner.js" 10 | export { WebAuthnMode, toWebAuthnKey } from "@zerodev/webauthn-key" 11 | export { toSignerId } from "./utils/toSignerId.js" 12 | export { toEmptyECDSASigner } from "./toEmptyECDSASigner.js" 13 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/ep0_7/hashKernelSignatureWrapper.ts: -------------------------------------------------------------------------------- 1 | import type { Hex } from "viem" 2 | import { encodeAbiParameters, keccak256, stringToHex } from "viem" 3 | 4 | export const hashKernelMessageHashWrapper = (messageHash: Hex) => { 5 | return keccak256( 6 | encodeAbiParameters( 7 | [{ type: "bytes32" }, { type: "bytes32" }], 8 | [keccak256(stringToHex("Kernel(bytes32 hash)")), messageHash] 9 | ) 10 | ) 11 | } 12 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/ep0_6/encodeExecuteSingleCall.ts: -------------------------------------------------------------------------------- 1 | import { encodeFunctionData } from "viem" 2 | import { KernelExecuteAbi } from "../../abi/KernelAccountAbi.js" 3 | import type { CallArgs } from "../types.js" 4 | 5 | export const encodeExecuteSingleCall = (args: CallArgs) => { 6 | return encodeFunctionData({ 7 | abi: KernelExecuteAbi, 8 | functionName: "execute", 9 | args: [args.to, args.value || 0n, args.data || "0x", 0] 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /.github/actions/install-dependencies/action.yml: -------------------------------------------------------------------------------- 1 | name: "Install dependencies" 2 | description: "Prepare repository and all dependencies" 3 | 4 | runs: 5 | using: "composite" 6 | steps: 7 | - name: Set up Bun 8 | uses: oven-sh/setup-bun@v1 9 | with: 10 | bun-version: 1.2.18 11 | 12 | - name: Set up foundry 13 | uses: foundry-rs/foundry-toolchain@v1 14 | 15 | - name: Install dependencies 16 | shell: bash 17 | run: bun install --ignore-scripts 18 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/ep0_6/encodeExecuteDelegateCall.ts: -------------------------------------------------------------------------------- 1 | import { encodeFunctionData } from "viem" 2 | import { KernelExecuteAbi } from "../../abi/KernelAccountAbi.js" 3 | import type { DelegateCallArgs } from "../types.js" 4 | 5 | export const encodeExecuteDelegateCall = (args: DelegateCallArgs) => { 6 | return encodeFunctionData({ 7 | abi: KernelExecuteAbi, 8 | functionName: "executeDelegateCall", 9 | args: [args.to, args.data || "0x"] 10 | }) 11 | } 12 | -------------------------------------------------------------------------------- /plugins/permission/policies/utils/toPolicyId.ts: -------------------------------------------------------------------------------- 1 | import { type Hex, concat, encodeAbiParameters } from "viem" 2 | import type { Policy } from "../../types.js" 3 | 4 | export const toPolicyId = (policies: Policy[]): Hex => { 5 | return encodeAbiParameters( 6 | [{ name: "policiesData", type: "bytes[]" }], 7 | [ 8 | policies.map((policy) => 9 | concat([policy.getPolicyInfoInBytes(), policy.getPolicyData()]) 10 | ) 11 | ] 12 | ) 13 | } 14 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/enforcers/allowed-params/constants.ts: -------------------------------------------------------------------------------- 1 | export enum CallType { 2 | CALL = "0x00", 3 | BATCH_CALL = "0x01", 4 | DELEGATE_CALL = "0xff" 5 | } 6 | 7 | export enum ParamCondition { 8 | EQUAL = 0, 9 | GREATER_THAN = 1, 10 | LESS_THAN = 2, 11 | GREATER_THAN_OR_EQUAL = 3, 12 | LESS_THAN_OR_EQUAL = 4, 13 | NOT_EQUAL = 5, 14 | ONE_OF = 6 15 | } 16 | 17 | export const AllowedParamsEnforcerAddress = 18 | "0xC54Aa21377FbCA9540054098088Ef508C7afc5e1" 19 | -------------------------------------------------------------------------------- /packages/core/actions/public/isSmartAccountDeployed.ts: -------------------------------------------------------------------------------- 1 | import type { Address, Client } from "viem" 2 | import { getCode } from "viem/actions" 3 | import { getAction } from "viem/utils" 4 | 5 | export const isSmartAccountDeployed = async ( 6 | client: Client, 7 | address: Address 8 | ): Promise => { 9 | const code = await getAction( 10 | client, 11 | getCode, 12 | "getCode" 13 | )({ 14 | address 15 | }) 16 | const deployed = Boolean(code) 17 | return deployed 18 | } 19 | -------------------------------------------------------------------------------- /.size-limit.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "name": "permissionless (esm)", 4 | "path": "./src/_esm/index.js", 5 | "limit": "30 kB", 6 | "import": "*" 7 | }, 8 | { 9 | "name": "permissionless (cjs)", 10 | "path": "./src/_cjs/index.js", 11 | "limit": "150 kB" 12 | }, 13 | { 14 | "name": "permissionless (minimal surface - tree-shaking)", 15 | "path": "./src/_esm/index.js", 16 | "limit": "4.1 kB", 17 | "import": "{ bundlerActions }" 18 | } 19 | ] 20 | -------------------------------------------------------------------------------- /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /packages/core/.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /plugins/react-native-passkeys-utils/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @zerodev/react-native-passkeys-utils 2 | 3 | ## 5.4.4 4 | 5 | ### Patch Changes 6 | 7 | - updated to use latest viem 2.28.0 and support for 7702 8 | 9 | ## 5.4.3 10 | 11 | ### Patch Changes 12 | 13 | - chore: update viem version 14 | 15 | ## 5.4.2 16 | 17 | ### Patch Changes 18 | 19 | - feat: export parseLoginCred 20 | 21 | ## 5.4.1 22 | 23 | ### Patch Changes 24 | 25 | - feat: add parseLoginCred 26 | 27 | ## 5.4.0 28 | 29 | ### Patch Changes 30 | 31 | - feat: add react native passkeys support 32 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/common/encodeSafeCreateCall.ts: -------------------------------------------------------------------------------- 1 | import { encodeFunctionData } from "viem" 2 | import { SafeCreateCallAbi } from "../../abi/SafeCreateCallAbi.js" 3 | 4 | type EncodeExecuteDelegateCallArgs = Parameters< 5 | typeof encodeFunctionData 6 | >[0]["args"] 7 | 8 | export const encodeSafeCreateCall = (args: EncodeExecuteDelegateCallArgs) => { 9 | return encodeFunctionData({ 10 | abi: SafeCreateCallAbi, 11 | functionName: "performCreate", 12 | args 13 | }) 14 | } 15 | -------------------------------------------------------------------------------- /plugins/multi-chain-web-authn/utils/decodeSignature.ts: -------------------------------------------------------------------------------- 1 | import type { Hex } from "viem" 2 | import { decodeAbiParameters } from "viem/utils" 3 | 4 | export function decodeSignature(signature: Hex) { 5 | const [_, passkeySig] = decodeAbiParameters( 6 | [ 7 | { 8 | name: "merkleData", 9 | type: "bytes" 10 | }, 11 | { 12 | name: "signature", 13 | type: "bytes" 14 | } 15 | ], 16 | signature 17 | ) 18 | return passkeySig 19 | } 20 | -------------------------------------------------------------------------------- /packages/core/actions/public/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | type GetAccountNonceParams, 3 | getAccountNonce 4 | } from "./getAccountNonce.js" 5 | export { 6 | type GetSenderAddressParams, 7 | type InvalidEntryPointError, 8 | getSenderAddress 9 | } from "./getSenderAddress.js" 10 | export { isSmartAccountDeployed } from "./isSmartAccountDeployed.js" 11 | export { getKernelImplementationAddress } from "./getKernelImplementationAddress.js" 12 | export { getKernelVersion } from "./getKernelVersion.js" 13 | export { isPluginInstalled } from "./isPluginInstalled.js" 14 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/ep0_7/encodeExecuteSingleCall.ts: -------------------------------------------------------------------------------- 1 | import { CALL_TYPE } from "../../../../constants.js" 2 | import type { CallArgs } from "../types.js" 3 | import { 4 | type EncodeExecuteOptions, 5 | encodeExecuteCall 6 | } from "./encodeExecuteCall.js" 7 | 8 | export const encodeExecuteSingleCall = ( 9 | args: CallArgs, 10 | options: Omit, 11 | includeHooks?: boolean 12 | ) => { 13 | return encodeExecuteCall( 14 | args, 15 | { 16 | callType: CALL_TYPE.SINGLE, 17 | execType: options.execType 18 | }, 19 | includeHooks 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /packages/test/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zerodev/sdk-test", 3 | "private": true, 4 | "devDependencies": { 5 | "bun-types": "^1.0.7" 6 | }, 7 | "scripts": { 8 | "lint": "biome check .", 9 | "format": "biome format . --write", 10 | "lint:fix": "bun run lint --apply" 11 | }, 12 | "dependencies": { 13 | "dotenv": "^16.3.1", 14 | "viem": "^2.28.0", 15 | "@zerodev/sdk": "workspace:*", 16 | "@zerodev/ecdsa-validator": "workspace:*", 17 | "@zerodev/session-key": "workspace:*", 18 | "@zerodev/modular-permission": "workspace:*" 19 | }, 20 | "type": "module" 21 | } 22 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/actions/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | type SignDelegationParameters, 3 | signDelegation 4 | } from "./signDelegation.js" 5 | // export { 6 | // type EncodeCallDataWithCABParameters, 7 | // encodeCallDataWithCAB 8 | // } from "./encodeCallDataWithCAB.js" 9 | export { 10 | type SendDelegateUserOperationParameters, 11 | delegate 12 | } from "./delegate.js" 13 | export { 14 | type SendInstallDMAndDelegateUserOperationParameters, 15 | installDMAndDelegate 16 | } from "./installDMAndDelegate.js" 17 | export { 18 | type SendInstallDMAsExecutorUserOperationParameters, 19 | installDMAsExecutor 20 | } from "./installDMAsExecutor.js" 21 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/ep0_7/encodeExecuteDelegateCall.ts: -------------------------------------------------------------------------------- 1 | import { CALL_TYPE } from "../../../../constants.js" 2 | import type { DelegateCallArgs } from "../types.js" 3 | import { 4 | type EncodeExecuteOptions, 5 | encodeExecuteCall 6 | } from "./encodeExecuteCall.js" 7 | 8 | export const encodeExecuteDelegateCall = ( 9 | args: DelegateCallArgs, 10 | options: Omit, 11 | includeHooks?: boolean 12 | ) => { 13 | return encodeExecuteCall( 14 | args, 15 | { 16 | callType: CALL_TYPE.DELEGATE_CALL, 17 | execType: options.execType 18 | }, 19 | includeHooks 20 | ) 21 | } 22 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/ep0_6/encodeExecuteBatchCall.ts: -------------------------------------------------------------------------------- 1 | import { encodeFunctionData } from "viem" 2 | import { KernelExecuteAbi } from "../../abi/KernelAccountAbi.js" 3 | import type { CallArgs } from "../types.js" 4 | 5 | export const encodeExecuteBatchCall = (args: readonly CallArgs[]) => { 6 | return encodeFunctionData({ 7 | abi: KernelExecuteAbi, 8 | functionName: "executeBatch", 9 | args: [ 10 | args.map((arg) => { 11 | return { 12 | to: arg.to, 13 | value: arg.value || 0n, 14 | data: arg.data || "0x" 15 | } 16 | }) 17 | ] 18 | }) 19 | } 20 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/enforcers/allowed-targets/toAllowedTargetsEnforcer.ts: -------------------------------------------------------------------------------- 1 | import { type Address, concatHex } from "viem" 2 | import type { Caveat } from "../../types.js" 3 | 4 | export type AllowedTargetsEnforcerParams = { 5 | targets: Address[] 6 | enforcerAddress?: Address 7 | } 8 | 9 | export const AllowedTargetsEnforcerAddress = 10 | "0x518d39bC3F1598512Bd5D323e5e9228CC47732b4" 11 | 12 | export function toAllowedTargetsEnforcer({ 13 | targets, 14 | enforcerAddress = AllowedTargetsEnforcerAddress 15 | }: AllowedTargetsEnforcerParams): Caveat { 16 | return { 17 | enforcer: enforcerAddress, 18 | terms: concatHex([...targets]), 19 | args: "0x" 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /packages/test/v0.7/utils/session.ts: -------------------------------------------------------------------------------- 1 | import { type Delegation, createSessionAccount } from "@zerodev/session-account" 2 | import type { Hex } from "viem" 3 | import { privateKeyToAccount } from "viem/accounts" 4 | import { getEntryPoint, getPublicClient } from "./common" 5 | 6 | export const getSessionAccount = async ( 7 | delegations: Delegation[], 8 | privateKey: Hex, 9 | delegatorInitCode?: Hex 10 | ) => { 11 | const sessionKeySigner = privateKeyToAccount(privateKey) 12 | const publicClient = await getPublicClient() 13 | 14 | return createSessionAccount(publicClient, { 15 | entryPoint: getEntryPoint(), 16 | sessionKeySigner, 17 | delegations, 18 | delegatorInitCode 19 | }) 20 | } 21 | -------------------------------------------------------------------------------- /packages/core/accounts/utils/getCustomNonceKeyFromString.ts: -------------------------------------------------------------------------------- 1 | import { keccak256, toHex } from "viem" 2 | import type { EntryPointVersion } from "viem/account-abstraction" 3 | 4 | const hashAndTruncate = (input: string, byteSize: number): bigint => { 5 | const hash = keccak256(toHex(input)) 6 | const truncatedHash = hash.substring(2, byteSize * 2 + 2) // 2 hex characters per byte 7 | return BigInt(`0x${truncatedHash}`) 8 | } 9 | 10 | export const getCustomNonceKeyFromString = ( 11 | input: string, 12 | entryPointVersion: EntryPointVersion 13 | ) => { 14 | if (entryPointVersion === "0.6") { 15 | return hashAndTruncate(input, 24) // 24 bytes for v0.6 16 | } 17 | return hashAndTruncate(input, 2) // 2 bytes for v0.7 18 | } 19 | -------------------------------------------------------------------------------- /plugins/multi-chain-ecdsa/index.ts: -------------------------------------------------------------------------------- 1 | export { toMultiChainECDSAValidator } from "./toMultiChainECDSAValidator.js" 2 | export { 3 | type SignUserOperationsParameters, 4 | type SignUserOperationsRequest, 5 | type SignUserOperationsReturnType, 6 | signUserOperations 7 | } from "./actions/index.js" 8 | 9 | export { 10 | prepareAndSignUserOperations, 11 | type PrepareAndSignUserOperationsParameters 12 | } from "./actions/prepareAndSignUserOperations.js" 13 | 14 | export { ecdsaGetMultiUserOpDummySignature } from "./utils/ecdsaGetMultiUserOpDummySignature.js" 15 | export { 16 | type MultiChainUserOpConfigForEnable, 17 | ecdsaSignUserOpsWithEnable 18 | } from "./utils/ecdsaSignUserOpsWithEnable.js" 19 | 20 | export * from "./constants.js" 21 | -------------------------------------------------------------------------------- /plugins/permission/index.ts: -------------------------------------------------------------------------------- 1 | export type * from "./types.js" 2 | export { toPermissionValidator } from "./toPermissionValidator.js" 3 | export { serializePermissionAccount } from "./serializePermissionAccount.js" 4 | export { 5 | type MultiChainPermissionAccountsParams, 6 | serializeMultiChainPermissionAccounts 7 | } from "./serializeMultiChainPermissionAccounts.js" 8 | export { 9 | deserializePermissionAccount, 10 | decodeParamsFromInitCode 11 | } from "./deserializePermissionAccount.js" 12 | export * from "./constants.js" 13 | export { toInitConfig } from "./toInitConfig.js" 14 | export { migrationSessionKeyAccount } from "./migration/migrationSessionKeyAccount.js" 15 | export { isPermissionMigrated } from "./migration/isPermissionMigrated.js" 16 | -------------------------------------------------------------------------------- /plugins/permission/policies/index.ts: -------------------------------------------------------------------------------- 1 | export { toGasPolicy, type GasPolicyParams } from "./toGasPolicy.js" 2 | export { 3 | toSignatureCallerPolicy, 4 | type SignatureCallerPolicyParams 5 | } from "./toSignatureCallerPolicy.js" 6 | export { 7 | toRateLimitPolicy, 8 | type RateLimitPolicyParams 9 | } from "./toRateLimitPolicy.js" 10 | export { 11 | toCallPolicy, 12 | type CallPolicyParams, 13 | CallPolicyVersion 14 | } from "./toCallPolicy.js" 15 | export { toPolicyId } from "./utils/toPolicyId.js" 16 | export { toSudoPolicy, type SudoPolicyParams } from "./toSudoPolicy.js" 17 | export { CallType, ParamCondition } from "./types.js" 18 | export { 19 | toTimestampPolicy, 20 | type TimestampPolicyParams 21 | } from "./toTimestampPolicy.js" 22 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/plugins/ep0_7/getPluginInstallCallData.ts: -------------------------------------------------------------------------------- 1 | import { type Address, encodeFunctionData } from "viem" 2 | import type { PluginMigrationData } from "../../../../../types/kernel.js" 3 | import { KernelModuleInstallAbi } from "../../../abi/kernel_v_3_0_0/KernelModuleAbi.js" 4 | import type { CallArgs } from "../../types.js" 5 | 6 | export const getPluginInstallCallData = ( 7 | accountAddress: Address, 8 | plugin: PluginMigrationData 9 | ): CallArgs => { 10 | const data = encodeFunctionData({ 11 | abi: KernelModuleInstallAbi, 12 | functionName: "installModule", 13 | args: [plugin.type, plugin.address, plugin.data] 14 | }) 15 | return { 16 | to: accountAddress, 17 | data 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /plugins/multi-chain-web-authn/index.ts: -------------------------------------------------------------------------------- 1 | export { toMultiChainWebAuthnValidator } from "./toMultiChainWebAuthnValidator.js" 2 | export { 3 | type PrepareAndSignUserOperationsParameters, 4 | prepareAndSignUserOperations 5 | } from "./actions/prepareAndSignUserOperations.js" 6 | export { 7 | type SignUserOperationsParameters, 8 | type SignUserOperationsRequest, 9 | type SignUserOperationsReturnType, 10 | signUserOperations 11 | } from "./actions/index.js" 12 | 13 | export { webauthnGetMultiUserOpDummySignature } from "./utils/webauthnGetMultiUserOpDummySignature.js" 14 | export { 15 | type MultiChainUserOpConfigForEnable, 16 | webauthnSignUserOpsWithEnable 17 | } from "./utils/webauthnSignUserOpsWithEnable.js" 18 | 19 | export * from "./constants.js" 20 | -------------------------------------------------------------------------------- /packages/core/accounts/addressToEmptyAccount.ts: -------------------------------------------------------------------------------- 1 | import type { Address, LocalAccount } from "viem" 2 | import { toAccount } from "viem/accounts" 3 | 4 | export type EmptyAccount = LocalAccount<"empty"> 5 | export function addressToEmptyAccount(address: Address): EmptyAccount { 6 | const account = toAccount({ 7 | address, 8 | async signMessage() { 9 | throw new Error("Method not supported") 10 | }, 11 | async signTransaction(_transaction) { 12 | throw new Error("Method not supported") 13 | }, 14 | async signTypedData(_typedData) { 15 | throw new Error("Method not supported") 16 | } 17 | }) 18 | 19 | return { 20 | ...account, 21 | publicKey: "0x", 22 | source: "empty" 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /plugins/session-key/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | signerToSessionKeyValidator, 3 | ParamOperator, 4 | anyPaymaster, 5 | Operation 6 | } from "./toSessionKeyValidatorPlugin.js" 7 | export { SessionKeyValidatorAbi } from "./abi/SessionKeyValidatorAbi.js" 8 | export * from "./utils.js" 9 | export type * from "./types.js" 10 | export const SESSION_KEY_VALIDATOR_ADDRESS = 11 | "0x8Df2bf61F849676f00C6883743E077d391da1dDA" 12 | export { serializeSessionKeyAccount } from "./serializeSessionKeyAccount.js" 13 | export { deserializeSessionKeyAccount } from "./deserializeSessionKeyAccount.js" 14 | export { deserializeSessionKeyAccountV0_2 } from "./deserializeSessionKeyAccountV0_2.js" 15 | export { revokeSessionKey } from "./revokeSessionKey.js" 16 | 17 | export const oneAddress = "0x0000000000000000000000000000000000000001" 18 | -------------------------------------------------------------------------------- /packages/core/types/index.ts: -------------------------------------------------------------------------------- 1 | export type { 2 | KernelValidator, 3 | ZeroDevPaymasterRpcSchema, 4 | Action, 5 | KernelPluginManager, 6 | ValidatorInitData, 7 | CallType, 8 | KernelEncodeCallDataArgs, 9 | PluginValidityData, 10 | ZeroDevAccountClientRpcSchema, 11 | ZeroDevUserOperationGasPriceWithBigIntAsHex, 12 | KERNEL_V2_VERSION_TYPE, 13 | KERNEL_V3_VERSION_TYPE, 14 | KERNEL_VERSION_TYPE, 15 | GetKernelVersion, 16 | GetEntryPointAbi, 17 | EntryPointType, 18 | PluginMigrationData 19 | } from "./kernel.js" 20 | 21 | export { ValidatorMode } from "./kernel.js" 22 | 23 | export type { Signer } from "./utils.js" 24 | 25 | export type WithRequired = Required> 26 | 27 | export type PartialPick = Partial> 28 | -------------------------------------------------------------------------------- /plugins/permission/policies/toSudoPolicy.ts: -------------------------------------------------------------------------------- 1 | import { concatHex } from "viem" 2 | import { PolicyFlags, SUDO_POLICY_CONTRACT } from "../constants.js" 3 | import type { Policy, PolicyParams } from "../types.js" 4 | 5 | export type SudoPolicyParams = PolicyParams 6 | 7 | export function toSudoPolicy({ 8 | policyAddress = SUDO_POLICY_CONTRACT, 9 | policyFlag = PolicyFlags.FOR_ALL_VALIDATION 10 | }: SudoPolicyParams): Policy { 11 | return { 12 | getPolicyData: () => { 13 | return "0x" 14 | }, 15 | getPolicyInfoInBytes: () => { 16 | return concatHex([policyFlag, policyAddress]) 17 | }, 18 | policyParams: { 19 | type: "sudo", 20 | policyAddress, 21 | policyFlag 22 | } as SudoPolicyParams & { type: "sudo" } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /.env.example: -------------------------------------------------------------------------------- 1 | TEST_PRIVATE_KEY= 2 | ENTRYPOINT_ADDRESS= 3 | PIMLICO_API_KEY= 4 | STACKUP_API_KEY= 5 | TEST_CHAIN_ID= 6 | FACTORY_ADDRESS= 7 | RPC_URL= 8 | PIMLICO_BUNDLER_RPC_HOST= 9 | PIMLICO_PAYMASTER_RPC_HOST= 10 | GREETER_ADDRESS= 11 | ZERODEV_PROJECT_ID= 12 | ZERODEV_PAYMASTER_RPC_HOST= 13 | ZERODEV_BUNDLER_RPC_HOST= 14 | ZERODEV_API_KEY= 15 | 16 | # For fallback e2e tests 17 | ZERODEV_RPC_URL= 18 | PIMLICO_RPC_URL= 19 | STACKUP_RPC_URL= 20 | ZERODEV_PAYMASTER_RPC_URL= 21 | PIMLICO_PAYMASTER_RPC_URL= 22 | STACKUP_PAYMASTER_RPC_URL= 23 | 24 | # For multi-chain tests 25 | SEPOLIA_RPC_URL= 26 | SEPOLIA_ZERODEV_RPC_URL= 27 | SEPOLIA_ZERODEV_PAYMASTER_RPC_URL= 28 | OPTIMISM_SEPOLIA_RPC_URL= 29 | OPTIMISM_SEPOLIA_ZERODEV_RPC_URL= 30 | OPTIMISM_SEPOLIA_ZERODEV_PAYMASTER_RPC_URL= 31 | 32 | # For 5792 wallet tests 33 | ZERODEV_7677_PAYMASTER_RPC_URL= -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/plugins/ep0_7/isPluginInitialized.ts: -------------------------------------------------------------------------------- 1 | import type { Address, Client } from "viem" 2 | import { readContract } from "viem/actions" 3 | import { getAction } from "viem/utils" 4 | import { KernelModuleIsInitializedAbi } from "../../../abi/kernel_v_3_0_0/KernelModuleAbi.js" 5 | 6 | export const isPluginInitialized = async ( 7 | client: Client, 8 | accountAddress: Address, 9 | pluginAddress: Address 10 | ) => { 11 | try { 12 | return await getAction( 13 | client, 14 | readContract, 15 | "readContract" 16 | )({ 17 | abi: KernelModuleIsInitializedAbi, 18 | address: pluginAddress, 19 | functionName: "isInitialized", 20 | args: [accountAddress] 21 | }) 22 | } catch (error) {} 23 | return false 24 | } 25 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/account/ep0_7/getKernelV3Nonce.ts: -------------------------------------------------------------------------------- 1 | import type { Address, Client } from "viem" 2 | import { readContract } from "viem/actions" 3 | import { getAction } from "viem/utils" 4 | import { KernelV3AccountAbi } from "../../../abi/kernel_v_3_0_0/KernelAccountAbi.js" 5 | 6 | export const getKernelV3Nonce = async ( 7 | client: Client, 8 | accountAddress: Address 9 | ): Promise => { 10 | try { 11 | const nonce = await getAction( 12 | client, 13 | readContract, 14 | "readContract" 15 | )({ 16 | abi: KernelV3AccountAbi, 17 | address: accountAddress, 18 | functionName: "currentNonce", 19 | args: [] 20 | }) 21 | return nonce === 0 ? 1 : nonce 22 | } catch (error) { 23 | return 1 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /plugins/remoteSigner/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @zerodev/remote-signer 2 | 3 | ## 5.3.3 4 | 5 | ### Patch Changes 6 | 7 | - updated to use latest viem 2.28.0 and support for 7702 8 | 9 | ## 5.3.2 10 | 11 | ### Patch Changes 12 | 13 | - chore: update viem version 14 | 15 | ## 5.3.1 16 | 17 | ### Patch Changes 18 | 19 | - feat: remove "type" field 20 | 21 | ## 5.3.0 22 | 23 | ### Minor Changes 24 | 25 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 26 | 27 | ## 5.2.4 28 | 29 | ### Patch Changes 30 | 31 | - Patch for latest permissionless 0.1.45 support 32 | 33 | ## 5.2.3 34 | 35 | ### Patch Changes 36 | 37 | - Pinned permissionless version >=0.1.18 <=0.1.29 38 | 39 | ## 5.2.2 40 | 41 | ### Patch Changes 42 | 43 | - Update viem to 2.16.3 44 | 45 | ## 5.2.0 46 | 47 | ### Patch Changes 48 | 49 | - Add remote-signer package 50 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/common/getActionSelector.ts: -------------------------------------------------------------------------------- 1 | import { type Hex, getAbiItem, toFunctionSelector } from "viem" 2 | import type { EntryPointVersion } from "viem/account-abstraction" 3 | import { KernelAccountAbi } from "../../abi/KernelAccountAbi.js" 4 | import { KernelV3AccountAbi } from "../../abi/kernel_v_3_0_0/KernelAccountAbi.js" 5 | 6 | export const getActionSelector = ( 7 | entryPointVersion: EntryPointVersion 8 | ): Hex => { 9 | if (entryPointVersion === "0.6") { 10 | return toFunctionSelector( 11 | getAbiItem({ abi: KernelAccountAbi, name: "execute" }) 12 | ) 13 | } else if (entryPointVersion === "0.7") { 14 | return toFunctionSelector( 15 | getAbiItem({ abi: KernelV3AccountAbi, name: "execute" }) 16 | ) 17 | } else { 18 | throw new Error("Unsupported entry point version") 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /plugins/modularPermission/policies/toSudoPolicy.ts: -------------------------------------------------------------------------------- 1 | import { concatHex } from "viem" 2 | import { PolicyFlags, SUDO_POLICY_CONTRACT } from "../constants.js" 3 | import type { Policy, SudoPolicyParams } from "./types.js" 4 | 5 | export async function toSudoPolicy({ 6 | policyAddress = SUDO_POLICY_CONTRACT, 7 | policyFlag = PolicyFlags.FOR_ALL_VALIDATION 8 | }: SudoPolicyParams): Promise { 9 | return { 10 | getPolicyData: () => { 11 | return "0x" 12 | }, 13 | getSignaturePolicyData: () => { 14 | return "0x" 15 | }, 16 | getPolicyInfoInBytes: () => { 17 | return concatHex([policyFlag, policyAddress]) 18 | }, 19 | policyParams: { 20 | type: "sudo", 21 | policyAddress, 22 | policyFlag 23 | } as SudoPolicyParams & { type: "sudo" } 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /.github/workflows/on-pull-request.yml: -------------------------------------------------------------------------------- 1 | name: Pull request 2 | on: 3 | pull_request: 4 | types: [opened, reopened, synchronize, ready_for_review] 5 | 6 | concurrency: 7 | group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} 8 | cancel-in-progress: true 9 | 10 | jobs: 11 | verify: 12 | name: Verify 13 | uses: ./.github/workflows/verify.yml 14 | secrets: inherit 15 | 16 | size: 17 | if: false 18 | name: Size 19 | runs-on: ubuntu-latest 20 | timeout-minutes: 5 21 | 22 | steps: 23 | - name: Clone repository 24 | uses: actions/checkout@v3 25 | 26 | - name: Install dependencies 27 | uses: ./.github/actions/install-dependencies 28 | 29 | - name: Report bundle size 30 | uses: andresz1/size-limit-action@master 31 | with: 32 | github_token: ${{ secrets.GITHUB_TOKEN }} 33 | package_manager: bun -------------------------------------------------------------------------------- /packages/core/errors/index.ts: -------------------------------------------------------------------------------- 1 | import { BaseError } from "viem" 2 | 3 | export class AccountNotFoundError extends BaseError { 4 | constructor({ docsPath }: { docsPath?: string | undefined } = {}) { 5 | super( 6 | [ 7 | "Could not find an Account to execute with this Action.", 8 | "Please provide an Account with the `account` argument on the Action, or by supplying an `account` to the Client." 9 | ].join("\n"), 10 | { 11 | docsPath, 12 | docsSlug: "account", 13 | name: "AccountNotFoundError" 14 | } 15 | ) 16 | } 17 | } 18 | 19 | export class SignTransactionNotSupportedBySmartAccountError extends BaseError { 20 | constructor() { 21 | super("Smart account signer doesn't need to sign transactions", { 22 | name: "SignTransactionNotSupportedError" 23 | }) 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /packages/core/clients/utils.ts: -------------------------------------------------------------------------------- 1 | export const setPimlicoAsProvider = (urlString: string): string => { 2 | const url = new URL(urlString) 3 | 4 | const params = url.searchParams 5 | 6 | if (params.has("bundlerProvider")) { 7 | params.set("bundlerProvider", "PIMLICO") 8 | } else if (params.has("paymasterProvider")) { 9 | params.set("paymasterProvider", "PIMLICO") 10 | } else { 11 | params.set("provider", "PIMLICO") 12 | } 13 | 14 | url.search = params.toString() 15 | 16 | return url.toString() 17 | } 18 | 19 | export const isProviderSet = (urlString: string, provider: string): boolean => { 20 | const url = new URL(urlString) 21 | const params = url.searchParams 22 | const _provider = 23 | params.get("provider") ?? 24 | params.get("bundlerProvider") ?? 25 | params.get("paymasterProvider") 26 | if (_provider === provider) return true 27 | return false 28 | } 29 | -------------------------------------------------------------------------------- /packages/test/actions/utils/deployAccount.ts: -------------------------------------------------------------------------------- 1 | import type { KernelAccountClient } from "@zerodev/sdk" 2 | import { type Address, zeroAddress } from "viem" 3 | import { publicClient } from "./config" 4 | 5 | export async function createAccountIfNotDeployed( 6 | kernelClient: KernelAccountClient 7 | ) { 8 | const deployed = await publicClient.getCode({ 9 | address: kernelClient.account?.address as Address 10 | }) 11 | 12 | if (!deployed || deployed === "0x") { 13 | console.log("deploying kernel account...") 14 | const userOpHash = await kernelClient.sendUserOperation({ 15 | calls: [ 16 | { 17 | to: zeroAddress, 18 | value: 0n, 19 | data: "0x" 20 | } 21 | ] 22 | }) 23 | await kernelClient.waitForUserOperationReceipt({ 24 | hash: userOpHash 25 | }) 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /plugins/modularPermission/constants.ts: -------------------------------------------------------------------------------- 1 | export const MODULAR_PERMISSION_VALIDATOR_ADDRESS = 2 | "0xfdDE9a26b6c3B7ca4b52C5f010d5B9Fb67e09E5A" 3 | export const MAX_FLAG = "0xffffffffffffffffffffffff" 4 | export const ECDSA_SIGNER_CONTRACT = 5 | "0x5569b550050F6537D9ac3329001be7F4C6659Cb0" 6 | export const WEBAUTHN_SIGNER_CONTRACT = 7 | "0xb280205eE78a4BE2F3677eABf9ffa38cc838268D" 8 | export const GAS_POLICY_CONTRACT = "0x62868E950Efbb336DCFf033598Ee5E602f0a93cD" 9 | export const SUDO_POLICY_CONTRACT = "0x9262C3A894328f9036Aa7a3f0f2cE8CF684ad20f" 10 | export const MERKLE_POLICY_CONTRACT = 11 | "0xb808d75b5acf6b5513eb816d3980c733ae6be468" 12 | export const SIGNATURE_POLICY_CONTRACT = 13 | "0xdb5F74349Dd2FB2A09eEc2C6A39e77B68ca2852C" 14 | export enum PolicyFlags { 15 | FOR_ALL_VALIDATION = "0x000000000000000000000000", 16 | NOT_FOR_VALIDATE_USEROP = "0x000000000000000000000001", 17 | NOT_FOR_VALIDATE_SIG = "0x000000000000000000000002" 18 | } 19 | -------------------------------------------------------------------------------- /plugins/webauthn-key/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @zerodev/passkey-validator 2 | 3 | ## 5.5.0 4 | 5 | ### Minor Changes 6 | 7 | - updated chain list for precompile 8 | 9 | ## 5.4.4 10 | 11 | ### Patch Changes 12 | 13 | - updated to use latest viem 2.28.0 and support for 7702 14 | 15 | ## 5.4.3 16 | 17 | ### Patch Changes 18 | 19 | - chore: update viem version 20 | 21 | ## 5.4.1 22 | 23 | ### Patch Changes 24 | 25 | - feat: remove "type" field 26 | 27 | ## 5.4.0 28 | 29 | ### Minor Changes 30 | 31 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 32 | 33 | ## 5.4.0-beta.0 34 | 35 | ### Minor Changes 36 | 37 | - Update for `viem@2.18.x` 38 | 39 | ## 5.3.3 40 | 41 | ### Patch Changes 42 | 43 | - Patch for latest permissionless 0.1.45 support 44 | 45 | ## 5.3.2 46 | 47 | ### Patch Changes 48 | 49 | - Added custome rpId param 50 | 51 | ## 5.3.1 52 | 53 | ### Patch Changes 54 | 55 | - Made passkeys server headers more flexible 56 | 57 | ## 5.3.0 58 | 59 | ### Patch Changes 60 | 61 | - Add `toWebAuthnKey` function 62 | -------------------------------------------------------------------------------- /remove-type.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Define the list of directories containing package.json files 4 | DIRECTORIES=("packages/*" "plugins/*") 5 | 6 | remove_type_field() { 7 | local dir=$1 8 | local package_file="$dir/package.json" 9 | 10 | if TYPE=$(jq -r '.type // empty' "$package_file"); then 11 | echo "📦 Removing type field from $package_file" 12 | # Convert to array of key-value pairs, filter out type, convert back while preserving order 13 | jq 'to_entries | map(select(.key != "type")) | from_entries' "$package_file" > "$package_file.tmp" && mv "$package_file.tmp" "$package_file" 14 | echo "$TYPE" > "$package_file.type" 15 | fi 16 | } 17 | 18 | # Process all packages 19 | for DIR in ${DIRECTORIES[@]}; do 20 | if [ -f "$DIR/package.json" ]; then 21 | remove_type_field "$DIR" 22 | else 23 | for SUBDIR in $DIR/*; do 24 | if [ -f "$SUBDIR/package.json" ]; then 25 | remove_type_field "$SUBDIR" 26 | fi 27 | done 28 | fi 29 | done -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/account/ep0_6/encodeDeployCallData.ts: -------------------------------------------------------------------------------- 1 | import { encodeDeployData } from "viem" 2 | import type { EntryPointVersion } from "viem/account-abstraction" 3 | import { safeCreateCallAddress } from "../../../../../constants.js" 4 | import type { KernelSmartAccountImplementation } from "../../../createKernelAccount.js" 5 | import { encodeSafeCreateCall } from "../../common/encodeSafeCreateCall.js" 6 | import { encodeExecuteDelegateCall } from "../../ep0_6/encodeExecuteDelegateCall.js" 7 | import type { DelegateCallArgs } from "../../types.js" 8 | 9 | export const encodeDeployCallData = < 10 | entryPointVersion extends EntryPointVersion = EntryPointVersion 11 | >( 12 | tx: Parameters< 13 | KernelSmartAccountImplementation["encodeDeployCallData"] 14 | >[0] 15 | ) => { 16 | const deployCalldataArgs: DelegateCallArgs = { 17 | to: safeCreateCallAddress, 18 | data: encodeSafeCreateCall([0n, encodeDeployData(tx)]) 19 | } 20 | return encodeExecuteDelegateCall(deployCalldataArgs) 21 | } 22 | -------------------------------------------------------------------------------- /plugins/social/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @zerodev/social-validator 2 | 3 | ## 5.2.3 4 | 5 | ### Patch Changes 6 | 7 | - updated to use latest viem 2.28.0 and support for 7702 8 | 9 | ## 5.2.2 10 | 11 | ### Patch Changes 12 | 13 | - chore: update viem version 14 | 15 | ## 5.2.1 16 | 17 | ### Patch Changes 18 | 19 | - feat: remove "type" field 20 | 21 | ## 5.2.0 22 | 23 | ### Minor Changes 24 | 25 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 26 | 27 | ## 5.1.3 28 | 29 | ### Patch Changes 30 | 31 | - Patch for latest permissionless 0.1.45 support 32 | 33 | ## 5.1.2 34 | 35 | ### Patch Changes 36 | 37 | - Pinned permissionless version >=0.1.18 <=0.1.29 38 | 39 | ## 5.1.1 40 | 41 | ### Patch Changes 42 | 43 | - Update viem to 2.16.3 44 | 45 | ## 5.1.0 46 | 47 | ### Minor Changes 48 | 49 | - Kernel v3.1 released. And kernel versioning update. Added kernelVersion param in the interface. 50 | 51 | ## 5.1.0-alpha-0 52 | 53 | ### Minor Changes 54 | 55 | - Integrated Kernel v3.1 and added kernelVersion param in account and plugins interface 56 | -------------------------------------------------------------------------------- /packages/core/actions/account-client/getUserOperationGasPrice.ts: -------------------------------------------------------------------------------- 1 | import type { Account, Chain, Client, Transport } from "viem" 2 | import type { Prettify } from "viem/chains" 3 | import type { ZeroDevAccountClientRpcSchema } from "../../types/kernel.js" 4 | 5 | export type GetUserOperationGasPriceReturnType = { 6 | maxFeePerGas: bigint 7 | maxPriorityFeePerGas: bigint 8 | } 9 | 10 | export const getUserOperationGasPrice = async < 11 | TTransport extends Transport = Transport, 12 | TChain extends Chain | undefined = Chain | undefined, 13 | TAccount extends Account | undefined = Account | undefined 14 | >( 15 | client: Client 16 | ): Promise> => { 17 | const gasPrice = await client.request({ 18 | method: "zd_getUserOperationGasPrice", 19 | params: [] 20 | }) 21 | 22 | return { 23 | maxFeePerGas: BigInt(gasPrice.standard.maxFeePerGas), 24 | maxPriorityFeePerGas: BigInt(gasPrice.standard.maxPriorityFeePerGas) 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /plugins/ecdsa/index.ts: -------------------------------------------------------------------------------- 1 | import type { KernelValidator } from "@zerodev/sdk/types" 2 | import { 3 | type GetKernelAddressFromECDSAParams, 4 | getKernelAddressFromECDSA 5 | } from "./getAddress.js" 6 | import { 7 | getValidatorAddress, 8 | signerToEcdsaValidator 9 | } from "./toECDSAValidatorPlugin.js" 10 | 11 | export { 12 | getValidatorAddress, 13 | signerToEcdsaValidator, 14 | type KernelValidator, 15 | getKernelAddressFromECDSA, 16 | type GetKernelAddressFromECDSAParams 17 | } 18 | export * from "./constants.js" 19 | export { 20 | createEcdsaKernelMigrationAccount, 21 | type CreateEcdsaKernelMigrationAccountParameters, 22 | type CreateEcdsaKernelMigrationAccountReturnType 23 | } from "./account/createEcdsaKernelMigrationAccount.js" 24 | export { 25 | create7702KernelAccountClient, 26 | type Create7702KernelAccountClientParameters 27 | } from "./clients/kernel7702AccountClient.js" 28 | export { 29 | create7702KernelAccount, 30 | type Create7702KernelAccountParameters, 31 | type Create7702KernelAccountReturnType 32 | } from "./account/create7702KernelAccount.js" 33 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/account/ep0_7/encodeDeployCallData.ts: -------------------------------------------------------------------------------- 1 | import { encodeDeployData } from "viem" 2 | import type { EntryPointVersion } from "viem/account-abstraction" 3 | import { EXEC_TYPE, safeCreateCallAddress } from "../../../../../constants.js" 4 | import type { KernelSmartAccountImplementation } from "../../../createKernelAccount.js" 5 | import { encodeSafeCreateCall } from "../../common/encodeSafeCreateCall.js" 6 | import { encodeExecuteDelegateCall } from "../../ep0_7/encodeExecuteDelegateCall.js" 7 | import type { DelegateCallArgs } from "../../types.js" 8 | 9 | export const encodeDeployCallData = < 10 | entryPointVersion extends EntryPointVersion = EntryPointVersion 11 | >( 12 | tx: Parameters< 13 | KernelSmartAccountImplementation["encodeDeployCallData"] 14 | >[0] 15 | ) => { 16 | const deployCalldataArgs: DelegateCallArgs = { 17 | to: safeCreateCallAddress, 18 | data: encodeSafeCreateCall([0n, encodeDeployData(tx)]) 19 | } 20 | return encodeExecuteDelegateCall(deployCalldataArgs, { 21 | execType: EXEC_TYPE.DEFAULT 22 | }) 23 | } 24 | -------------------------------------------------------------------------------- /restore-type.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Define the list of directories containing package.json files 4 | DIRECTORIES=("packages/*" "plugins/*") 5 | 6 | restore_type_field() { 7 | local dir=$1 8 | local package_file="$dir/package.json" 9 | local type_file="$package_file.type" 10 | 11 | if [ -f "$type_file" ]; then 12 | TYPE=$(cat "$type_file") 13 | echo "📦 Restoring type field to $package_file" 14 | # Restore type field in its original position by converting to entries again 15 | jq --arg type "$TYPE" 'to_entries | map(select(.key != "type")) | . + [{"key": "type", "value": $type}] | from_entries' "$package_file" > "$package_file.tmp" && mv "$package_file.tmp" "$package_file" 16 | rm "$type_file" 17 | fi 18 | } 19 | 20 | # Process all packages 21 | for DIR in ${DIRECTORIES[@]}; do 22 | if [ -f "$DIR/package.json" ]; then 23 | restore_type_field "$DIR" 24 | else 25 | for SUBDIR in $DIR/*; do 26 | if [ -f "$SUBDIR/package.json" ]; then 27 | restore_type_field "$SUBDIR" 28 | fi 29 | done 30 | fi 31 | done -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @zerodev/session-account 2 | 3 | ## 5.4.4 4 | 5 | ### Patch Changes 6 | 7 | - updated to use latest viem 2.28.0 and support for 7702 8 | 9 | ## 5.4.3 10 | 11 | ### Patch Changes 12 | 13 | - chore: update viem version 14 | 15 | ## 5.4.2 16 | 17 | ### Patch Changes 18 | 19 | - feat: remove "type" field 20 | 21 | ## 5.4.1 22 | 23 | ### Patch Changes 24 | 25 | - Use .js imports to fix build issues in all environments 26 | 27 | ## 5.4.0 28 | 29 | ### Minor Changes 30 | 31 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 32 | 33 | ## 5.4.0-beta.1 34 | 35 | ### Patch Changes 36 | 37 | - Update `@zerodev/sdk` to `5.4.0-beta.x` and remove `permissionless` from peer deps 38 | 39 | ## 5.4.0-beta.0 40 | 41 | ### Minor Changes 42 | 43 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 44 | 45 | ## 5.3.2 46 | 47 | ### Patch Changes 48 | 49 | - Fix bug in fetching indexes based on allowances in cabEnforcer session-account 50 | 51 | ## 5.3.1 52 | 53 | ### Patch Changes 54 | 55 | - Added support for CABv2.1 56 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 ZeroDev 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /plugins/permission/migration/isPermissionMigrated.ts: -------------------------------------------------------------------------------- 1 | import { 2 | MIGRATION_HELPER_ADDRESS, 3 | MigrationHelperAbi 4 | } from "@zerodev/sdk/accounts" 5 | import type { 6 | Address, 7 | Chain, 8 | Client, 9 | Hex, 10 | JsonRpcAccount, 11 | LocalAccount, 12 | Transport 13 | } from "viem" 14 | import { readContract } from "viem/actions" 15 | import { getAction } from "viem/utils" 16 | 17 | export const isPermissionMigrated = async ( 18 | client: Client< 19 | Transport, 20 | Chain | undefined, 21 | JsonRpcAccount | LocalAccount | undefined 22 | >, 23 | params: { account: Address; permissionId: Hex } 24 | ): Promise => { 25 | try { 26 | const [, , p] = await getAction( 27 | client, 28 | readContract, 29 | "readContract" 30 | )({ 31 | address: MIGRATION_HELPER_ADDRESS, 32 | abi: MigrationHelperAbi, 33 | functionName: "isMigrated", 34 | args: [params.account, [], [params.permissionId]] 35 | }) 36 | return p[0] 37 | } catch { 38 | return false 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /plugins/modularPermission/policies/toSignaturePolicy.ts: -------------------------------------------------------------------------------- 1 | import { concatHex, encodeAbiParameters } from "viem" 2 | import { PolicyFlags, SIGNATURE_POLICY_CONTRACT } from "../constants.js" 3 | import type { Policy, SignaturePolicyParams } from "./types.js" 4 | 5 | export async function toSignaturePolicy({ 6 | policyAddress = SIGNATURE_POLICY_CONTRACT, 7 | policyFlag = PolicyFlags.NOT_FOR_VALIDATE_USEROP, 8 | allowedRequestors 9 | }: SignaturePolicyParams): Promise { 10 | return { 11 | getPolicyData: () => { 12 | return encodeAbiParameters( 13 | [{ name: "allowedSigners", type: "address[]" }], 14 | [allowedRequestors] 15 | ) 16 | }, 17 | getSignaturePolicyData: () => { 18 | return "0x" 19 | }, 20 | getPolicyInfoInBytes: () => { 21 | return concatHex([policyFlag, policyAddress]) 22 | }, 23 | policyParams: { 24 | type: "signature", 25 | policyAddress, 26 | policyFlag, 27 | allowedRequestors 28 | } as SignaturePolicyParams & { type: "signature" } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/plugins/ep0_7/getValidatorPluginInstallCallData.ts: -------------------------------------------------------------------------------- 1 | import { 2 | type Address, 3 | type Hex, 4 | concatHex, 5 | encodeFunctionData, 6 | zeroAddress 7 | } from "viem" 8 | import { VALIDATOR_TYPE } from "../../../../../constants.js" 9 | import type { PluginMigrationData } from "../../../../../types/kernel.js" 10 | import { KernelV3_1AccountAbi } from "../../../abi/kernel_v_3_1/KernelAccountAbi.js" 11 | import type { CallArgs } from "../../types.js" 12 | 13 | export const getValidatorPluginInstallCallData = ( 14 | accountAddress: Address, 15 | plugin: PluginMigrationData, 16 | nonce: number 17 | ): CallArgs => { 18 | const vIds = [concatHex([VALIDATOR_TYPE.SECONDARY, plugin.address])] 19 | const configs = [{ nonce, hook: zeroAddress }] 20 | const validationData = [plugin.data] 21 | const hookData: Hex[] = ["0x"] 22 | const data = encodeFunctionData({ 23 | abi: KernelV3_1AccountAbi, 24 | functionName: "installValidations", 25 | args: [vIds, configs, validationData, hookData] 26 | }) 27 | return { 28 | to: accountAddress, 29 | data 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/common/getUpgradeKernelCall.ts: -------------------------------------------------------------------------------- 1 | import { encodeFunctionData } from "viem" 2 | import type { SmartAccount } from "viem/account-abstraction" 3 | import { KernelVersionToAddressesMap } from "../../../../constants.js" 4 | import type { KERNEL_VERSION_TYPE } from "../../../../types/kernel.js" 5 | import { validateKernelVersionWithEntryPoint } from "../../../../utils.js" 6 | import { KernelV3AccountAbi } from "../../abi/kernel_v_3_0_0/KernelAccountAbi.js" 7 | import type { CallArgs } from "../types.js" 8 | 9 | export function getUpgradeKernelCall( 10 | account: SmartAccount, 11 | kernelVersion: KERNEL_VERSION_TYPE 12 | ): CallArgs { 13 | validateKernelVersionWithEntryPoint( 14 | account.entryPoint.version, 15 | kernelVersion 16 | ) 17 | const implementation = 18 | KernelVersionToAddressesMap[kernelVersion].accountImplementationAddress 19 | 20 | return { 21 | to: account.address, 22 | data: encodeFunctionData({ 23 | abi: KernelV3AccountAbi, 24 | functionName: "upgradeTo", 25 | args: [implementation] 26 | }), 27 | value: 0n 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /plugins/permission/policies/toSignatureCallerPolicy.ts: -------------------------------------------------------------------------------- 1 | import { type Address, concatHex, encodeAbiParameters } from "viem" 2 | import { PolicyFlags } from "../constants.js" 3 | import { SIGNATURE_POLICY_CONTRACT } from "../constants.js" 4 | import type { Policy, PolicyParams } from "../types.js" 5 | 6 | export type SignatureCallerPolicyParams = PolicyParams & { 7 | allowedCallers: Address[] 8 | } 9 | 10 | export function toSignatureCallerPolicy({ 11 | policyAddress = SIGNATURE_POLICY_CONTRACT, 12 | policyFlag = PolicyFlags.FOR_ALL_VALIDATION, 13 | allowedCallers 14 | }: SignatureCallerPolicyParams): Policy { 15 | return { 16 | getPolicyData: () => { 17 | return encodeAbiParameters( 18 | [{ name: "allowedCallers", type: "address[]" }], 19 | [allowedCallers] 20 | ) 21 | }, 22 | getPolicyInfoInBytes: () => { 23 | return concatHex([policyFlag, policyAddress]) 24 | }, 25 | policyParams: { 26 | type: "signature-caller", 27 | policyAddress, 28 | policyFlag, 29 | allowedCallers 30 | } as SignatureCallerPolicyParams & { type: "signature-caller" } 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/constants.ts: -------------------------------------------------------------------------------- 1 | import type { Address } from "viem" 2 | import type { DM_VERSION_TYPE } from "./types.js" 3 | 4 | export const MAGIC_BYTES = 5 | "0x6492649264926492649264926492649264926492649264926492649264926492" 6 | 7 | export const SUBACCOUNT_API_URL = 8 | "https://yield-api-kgjy.onrender.com/subaccount/transfers-data" 9 | 10 | export const MULTI_TENANT_SESSION_ACCOUNT_ADDRESS = 11 | "0x16c15c5349eB67185b8A58020E57D71F57105f6d" 12 | 13 | export const CAB_PAYMASTER_SERVER_URL = 14 | "https://cab-paymaster-service.onrender.com/paymaster/api" 15 | 16 | export const ROOT_AUTHORITY = 17 | "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff" 18 | 19 | export const DELEGATION_TYPE_STRING = 20 | "Delegation(address delegate,address delegator,bytes32 authority,Caveat[] caveats,uint256 salt)Caveat(address enforcer,bytes terms)" 21 | 22 | export const DMVersionToAddressMap: { 23 | [key in DM_VERSION_TYPE]: { 24 | delegationManagerAddress: Address 25 | } 26 | } = { 27 | "1.0.0": { 28 | delegationManagerAddress: "0x942Eb55c0dD36297bdCd622cb3E2A5f4D6c750CD" 29 | // delegationManagerAddress: "0x77dB450f40737F53b63170A8A9cdb93FaDE366D1" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /plugins/hooks/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @zerodev/hooks 2 | 3 | ## 5.3.4 4 | 5 | ### Patch Changes 6 | 7 | - updated to use latest viem 2.28.0 and support for 7702 8 | 9 | ## 5.3.3 10 | 11 | ### Patch Changes 12 | 13 | - chore: update viem version 14 | 15 | ## 5.3.2 16 | 17 | ### Patch Changes 18 | 19 | - feat: remove "type" field 20 | 21 | ## 5.3.1 22 | 23 | ### Patch Changes 24 | 25 | - Use .js imports to fix build issues in all environments 26 | 27 | ## 5.3.0 28 | 29 | ### Minor Changes 30 | 31 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 32 | 33 | ## 5.3.0-beta.0 34 | 35 | ### Minor Changes 36 | 37 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 38 | 39 | ## 5.2.5 40 | 41 | ### Patch Changes 42 | 43 | - Patch for latest permissionless 0.1.45 support 44 | 45 | ## 5.2.4 46 | 47 | ### Patch Changes 48 | 49 | - Pinned permissionless version >=0.1.18 <=0.1.29 50 | 51 | ## 5.2.3 52 | 53 | ### Patch Changes 54 | 55 | - Update viem to 2.16.3 56 | 57 | ## 5.2.2 58 | 59 | ### Patch Changes 60 | 61 | - Fixed contract issue 62 | 63 | ## 5.2.1 64 | 65 | ### Patch Changes 66 | 67 | - Fixed export issue 68 | 69 | ## 5.2.0 70 | 71 | ### Patch Changes 72 | 73 | - Added spending limit hook 74 | -------------------------------------------------------------------------------- /plugins/multi-chain-weighted-validator/constants.ts: -------------------------------------------------------------------------------- 1 | import { constants } from "@zerodev/sdk" 2 | import type { Action } from "@zerodev/sdk/types" 3 | import { toFunctionSelector } from "viem" 4 | import type { EntryPointVersion } from "viem/account-abstraction" 5 | 6 | const RECOVERY_ACTION_ADDRESS_V06 = "0x2f65dB8039fe5CAEE0a8680D2879deB800F31Ae1" 7 | const RECOVERY_ACTION_ADDRESS_V07 = "0xe884C2868CC82c16177eC73a93f7D9E6F3A5DC6E" 8 | const RECOVERY_ACTION_SELECTOR = toFunctionSelector( 9 | "doRecovery(address, bytes)" 10 | ) 11 | 12 | export const getRecoveryAction = ( 13 | entryPointVersion: EntryPointVersion 14 | ): Action => { 15 | if (entryPointVersion === "0.6") { 16 | return { 17 | address: RECOVERY_ACTION_ADDRESS_V06, 18 | selector: RECOVERY_ACTION_SELECTOR 19 | } 20 | } 21 | return { 22 | address: RECOVERY_ACTION_ADDRESS_V07, 23 | selector: RECOVERY_ACTION_SELECTOR, 24 | hook: { 25 | address: constants.ONLY_ENTRYPOINT_HOOK_ADDRESS 26 | } 27 | } 28 | } 29 | 30 | export const MULTI_CHAIN_WEIGHTED_VALIDATOR_ADDRESS_V07 = 31 | "0xA99cD3c93773dA7f321A28a97648b608f347E6A1" 32 | 33 | export enum SIGNER_TYPE { 34 | ECDSA = "0x01", 35 | PASSKEY = "0x02" 36 | } 37 | -------------------------------------------------------------------------------- /biome.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://biomejs.dev/schemas/1.0.0/schema.json", 3 | "files": { 4 | "ignore": [ 5 | "node_modules", 6 | "**/node_modules", 7 | "cache", 8 | "coverage", 9 | "tsconfig.json", 10 | "tsconfig.*.json", 11 | "_cjs", 12 | "_esm", 13 | "_types", 14 | "bun.lockb" 15 | ] 16 | }, 17 | "organizeImports": { 18 | "enabled": true 19 | }, 20 | "linter": { 21 | "enabled": true, 22 | "rules": { 23 | "recommended": true, 24 | "suspicious": { 25 | "noExplicitAny": "warn" 26 | }, 27 | "style": { 28 | "noUnusedTemplateLiteral": "warn", 29 | "noUselessElse": "off", 30 | "useNodejsImportProtocol": "off" 31 | } 32 | } 33 | }, 34 | "formatter": { 35 | "enabled": true, 36 | "formatWithErrors": true, 37 | "lineWidth": 80, 38 | "indentWidth": 4, 39 | "indentStyle": "space" 40 | }, 41 | "javascript": { 42 | "formatter": { 43 | "semicolons": "asNeeded", 44 | "trailingCommas": "none" 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/account/ep0_6/encodeModuleInstallCallData.ts: -------------------------------------------------------------------------------- 1 | import { type Address, type Hex, encodeFunctionData } from "viem" 2 | import type { PluginInstallData } from "../../../../../types/kernel.js" 3 | import { KernelAccountAbi } from "../../../abi/KernelAccountAbi.js" 4 | import { encodeCallData } from "./encodeCallData.js" 5 | 6 | export const encodeModuleInstallCallData = async ({ 7 | accountAddress, 8 | enableData, 9 | executor, 10 | selector, 11 | validAfter, 12 | validUntil, 13 | validator 14 | }: { 15 | accountAddress: Address 16 | } & PluginInstallData<"0.6">): Promise => { 17 | return encodeCallData( 18 | [ 19 | { 20 | to: accountAddress, 21 | value: 0n, 22 | data: encodeFunctionData({ 23 | abi: KernelAccountAbi, 24 | functionName: "setExecution", 25 | args: [ 26 | selector, 27 | executor, 28 | validator, 29 | validUntil, 30 | validAfter, 31 | enableData 32 | ] 33 | }) 34 | } 35 | ], 36 | "call" 37 | ) 38 | } 39 | -------------------------------------------------------------------------------- /plugins/permission/policies/toTimestampPolicy.ts: -------------------------------------------------------------------------------- 1 | import { concatHex, encodeAbiParameters } from "viem" 2 | import { PolicyFlags, TIMESTAMP_POLICY_CONTRACT } from "../constants.js" 3 | import type { Policy, PolicyParams } from "../types.js" 4 | 5 | export type TimestampPolicyParams = PolicyParams & { 6 | validAfter?: number 7 | validUntil?: number 8 | } 9 | 10 | export function toTimestampPolicy({ 11 | policyAddress = TIMESTAMP_POLICY_CONTRACT, 12 | policyFlag = PolicyFlags.FOR_ALL_VALIDATION, 13 | validAfter = 0, 14 | validUntil = 0 15 | }: TimestampPolicyParams): Policy { 16 | return { 17 | getPolicyData: () => { 18 | return encodeAbiParameters( 19 | [ 20 | { name: "validAfter", type: "uint48" }, 21 | { name: "validUntil", type: "uint48" } 22 | ], 23 | [validAfter, validUntil] 24 | ) 25 | }, 26 | getPolicyInfoInBytes: () => { 27 | return concatHex([policyFlag, policyAddress]) 28 | }, 29 | policyParams: { 30 | type: "timestamp", 31 | policyAddress, 32 | policyFlag, 33 | validAfter, 34 | validUntil 35 | } as TimestampPolicyParams & { type: "timestamp" } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/abi/EIP1271Abi.ts: -------------------------------------------------------------------------------- 1 | export const EIP1271Abi = [ 2 | { 3 | type: "function", 4 | name: "eip712Domain", 5 | inputs: [], 6 | outputs: [ 7 | { name: "fields", type: "bytes1", internalType: "bytes1" }, 8 | { name: "name", type: "string", internalType: "string" }, 9 | { name: "version", type: "string", internalType: "string" }, 10 | { name: "chainId", type: "uint256", internalType: "uint256" }, 11 | { 12 | name: "verifyingContract", 13 | type: "address", 14 | internalType: "address" 15 | }, 16 | { name: "salt", type: "bytes32", internalType: "bytes32" }, 17 | { name: "extensions", type: "uint256[]", internalType: "uint256[]" } 18 | ], 19 | stateMutability: "view" 20 | }, 21 | { 22 | type: "function", 23 | name: "isValidSignature", 24 | inputs: [ 25 | { name: "data", type: "bytes32", internalType: "bytes32" }, 26 | { name: "signature", type: "bytes", internalType: "bytes" } 27 | ], 28 | outputs: [ 29 | { name: "magicValue", type: "bytes4", internalType: "bytes4" } 30 | ], 31 | stateMutability: "view" 32 | } 33 | ] as const 34 | -------------------------------------------------------------------------------- /plugins/weighted-r1-k1/utils.ts: -------------------------------------------------------------------------------- 1 | import { type Hex, decodeAbiParameters, encodeAbiParameters } from "viem" 2 | 3 | export const encodeSignatures = (signatures: Hex[], sort = false) => { 4 | let signatures_ = signatures 5 | if (sort) { 6 | signatures_ = signatures.sort((a, b) => 7 | a.toLowerCase().localeCompare(b.toLowerCase()) 8 | ) 9 | } 10 | return encodeAbiParameters( 11 | [{ name: "signatures", type: "bytes[]" }], 12 | [signatures_] 13 | ) 14 | } 15 | 16 | export const decodeSignatures = (signaturesData: Hex): Hex[] => { 17 | const [signatures] = decodeAbiParameters( 18 | [{ name: "signatures", type: "bytes[]" }], 19 | signaturesData 20 | ) 21 | return [...signatures] 22 | } 23 | 24 | // Sort addresses in descending order 25 | export const sortByPublicKey = ( 26 | a: { publicKey: Hex } | { getPublicKey: () => Hex }, 27 | b: { publicKey: Hex } | { getPublicKey: () => Hex } 28 | ) => { 29 | if ("publicKey" in a && "publicKey" in b) 30 | return a.publicKey.toLowerCase() < b.publicKey.toLowerCase() ? 1 : -1 31 | else if ("getPublicKey" in a && "getPublicKey" in b) 32 | return a.getPublicKey().toLowerCase() < b.getPublicKey().toLowerCase() 33 | ? 1 34 | : -1 35 | else return 0 36 | } 37 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/abi/kernel_v_3_0_0/KernelFactoryAbi.ts: -------------------------------------------------------------------------------- 1 | export const KernelV3FactoryAbi = [ 2 | { 3 | type: "constructor", 4 | inputs: [{ name: "_impl", type: "address", internalType: "address" }], 5 | stateMutability: "nonpayable" 6 | }, 7 | { 8 | type: "function", 9 | name: "createAccount", 10 | inputs: [ 11 | { name: "data", type: "bytes", internalType: "bytes" }, 12 | { name: "salt", type: "bytes32", internalType: "bytes32" } 13 | ], 14 | outputs: [{ name: "", type: "address", internalType: "address" }], 15 | stateMutability: "payable" 16 | }, 17 | { 18 | type: "function", 19 | name: "getAddress", 20 | inputs: [ 21 | { name: "data", type: "bytes", internalType: "bytes" }, 22 | { name: "salt", type: "bytes32", internalType: "bytes32" } 23 | ], 24 | outputs: [{ name: "", type: "address", internalType: "address" }], 25 | stateMutability: "view" 26 | }, 27 | { 28 | type: "function", 29 | name: "implementation", 30 | inputs: [], 31 | outputs: [{ name: "", type: "address", internalType: "address" }], 32 | stateMutability: "view" 33 | }, 34 | { type: "error", name: "InitializeError", inputs: [] } 35 | ] as const 36 | -------------------------------------------------------------------------------- /packages/test/utils_0_6/recovery.ts: -------------------------------------------------------------------------------- 1 | import { createKernelAccount } from "@zerodev/sdk" 2 | import { 3 | createWeightedECDSAValidator, 4 | getRecoveryAction 5 | } from "@zerodev/weighted-ecdsa-validator" 6 | import type { Address } from "viem" 7 | import { generatePrivateKey, privateKeyToAccount } from "viem/accounts" 8 | import { getEntryPoint, getPublicClient, index, kernelVersion } from "./common" 9 | 10 | export const getRecoveryKernelAccount = async ( 11 | deployedAccountAddress: Address 12 | ) => { 13 | const privateKey1 = generatePrivateKey() 14 | const signer1 = privateKeyToAccount(privateKey1) 15 | const recoveryPlugin = await createWeightedECDSAValidator( 16 | await getPublicClient(), 17 | { 18 | entryPoint: getEntryPoint(), 19 | kernelVersion, 20 | config: { 21 | threshold: 100, 22 | delay: 0, 23 | signers: [{ address: signer1.address, weight: 100 }] 24 | }, 25 | signers: [signer1] 26 | } 27 | ) 28 | return await createKernelAccount(await getPublicClient(), { 29 | entryPoint: getEntryPoint(), 30 | address: deployedAccountAddress, 31 | plugins: { 32 | regular: recoveryPlugin, 33 | action: getRecoveryAction(getEntryPoint().version) 34 | }, 35 | index, 36 | kernelVersion 37 | }) 38 | } 39 | -------------------------------------------------------------------------------- /plugins/modularPermission/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @zerodev/modular-permission 2 | 3 | ## 5.4.3 4 | 5 | ### Patch Changes 6 | 7 | - updated to use latest viem 2.28.0 and support for 7702 8 | 9 | ## 5.4.2 10 | 11 | ### Patch Changes 12 | 13 | - chore: update viem version 14 | 15 | ## 5.4.1 16 | 17 | ### Patch Changes 18 | 19 | - feat: remove "type" field 20 | 21 | ## 5.4.0 22 | 23 | ### Minor Changes 24 | 25 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 26 | 27 | ## 5.4.0-beta.0 28 | 29 | ### Minor Changes 30 | 31 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 32 | 33 | ## 5.3.4 34 | 35 | ### Patch Changes 36 | 37 | - Patch for latest permissionless 0.1.45 support 38 | 39 | ## 5.3.3 40 | 41 | ### Patch Changes 42 | 43 | - Pinned permissionless version >=0.1.18 <=0.1.29 44 | 45 | ## 5.3.2 46 | 47 | ### Patch Changes 48 | 49 | - Made passkeys server headers more flexible 50 | 51 | ## 5.3.1 52 | 53 | ### Patch Changes 54 | 55 | - Update viem to 2.16.3 56 | 57 | ## 5.3.0 58 | 59 | ### Minor Changes 60 | 61 | - Kernel v3.1 released. And kernel versioning update. Added kernelVersion param in the interface. 62 | 63 | ## 5.3.0-alpha-0 64 | 65 | ### Minor Changes 66 | 67 | - Integrated Kernel v3.1 and added kernelVersion param in account and plugins interface 68 | 69 | ## 5.2.2 70 | 71 | ### Patch Changes 72 | 73 | - Update permissionless@0.1.18 74 | -------------------------------------------------------------------------------- /plugins/permission/signers/toEmptyECDSASigner.ts: -------------------------------------------------------------------------------- 1 | import { constants } from "@zerodev/sdk" 2 | import type { TypedData } from "abitype" 3 | import type { Address, TypedDataDefinition } from "viem" 4 | import { toAccount } from "viem/accounts" 5 | import { ECDSA_SIGNER_CONTRACT } from "../constants.js" 6 | import type { ModularSigner } from "../types.js" 7 | 8 | export function toEmptyECDSASigner( 9 | address: Address, 10 | signerContractAddress: Address = ECDSA_SIGNER_CONTRACT 11 | ): ModularSigner { 12 | const account = toAccount({ 13 | address, 14 | async signMessage() { 15 | throw new Error("Method not supported") 16 | }, 17 | async signTransaction(_, __) { 18 | throw new Error("Method not supported") 19 | }, 20 | async signTypedData< 21 | const TTypedData extends TypedData | Record, 22 | TPrimaryType extends 23 | | keyof TTypedData 24 | | "EIP712Domain" = keyof TTypedData 25 | >(_typedData: TypedDataDefinition) { 26 | throw new Error("Method not supported") 27 | } 28 | }) 29 | return { 30 | account, 31 | signerContractAddress: signerContractAddress, 32 | getSignerData: () => { 33 | return address 34 | }, 35 | getDummySignature: () => constants.DUMMY_ECDSA_SIG 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /packages/core/accounts/utils/multisend.ts: -------------------------------------------------------------------------------- 1 | import { type Address, type Hex, encodePacked, toBytes } from "viem" 2 | import type { CallType } from "../../types/index.js" 3 | import type { KernelSmartAccountImplementation } from "../kernel/createKernelAccount.js" 4 | 5 | export const MULTISEND_ADDRESS = "0x8ae01fcf7c655655ff2c6ef907b8b4718ab4e17c" 6 | 7 | export const multiSendAbi = [ 8 | { 9 | type: "function", 10 | name: "multiSend", 11 | inputs: [{ type: "bytes", name: "transactions" }] 12 | } 13 | ] 14 | 15 | const encodeCall = (call: { 16 | to: Address 17 | value: bigint 18 | data: Hex 19 | callType: CallType | undefined 20 | }): string => { 21 | const data = toBytes(call.data) 22 | const encoded = encodePacked( 23 | ["uint8", "address", "uint256", "uint256", "bytes"], 24 | [ 25 | call.callType === "delegatecall" ? 1 : 0, 26 | call.to, 27 | call.value || 0n, 28 | BigInt(data.length), 29 | call.data 30 | ] 31 | ) 32 | return encoded.slice(2) 33 | } 34 | 35 | export const encodeMultiSend = ( 36 | calls: Parameters["encodeCalls"]>[0] 37 | ): Hex => { 38 | if (!Array.isArray(calls)) { 39 | throw new Error("Invalid multiSend calls, should use an array of calls") 40 | } 41 | 42 | return `0x${calls.map((call) => encodeCall(call)).join("")}` 43 | } 44 | -------------------------------------------------------------------------------- /packages/core/actions/account-client/getKernelV3ModuleCurrentNonce.ts: -------------------------------------------------------------------------------- 1 | import type { Chain, Client, Transport } from "viem" 2 | import type { SmartAccount } from "viem/account-abstraction" 3 | import { readContract } from "viem/actions" 4 | import { getAction, parseAccount } from "viem/utils" 5 | import { KernelV3AccountAbi } from "../../accounts/kernel/abi/kernel_v_3_0_0/KernelAccountAbi.js" 6 | import { AccountNotFoundError } from "../../errors/index.js" 7 | 8 | export async function getKernelV3ModuleCurrentNonce< 9 | TTransport extends Transport = Transport, 10 | TChain extends Chain | undefined = Chain | undefined, 11 | TAccount extends SmartAccount | undefined = SmartAccount | undefined 12 | >(client: Client): Promise { 13 | const account_ = client.account 14 | if (!account_) 15 | throw new AccountNotFoundError({ 16 | docsPath: "/docs/actions/wallet/sendTransaction" 17 | }) 18 | 19 | const account = parseAccount(account_) as SmartAccount 20 | 21 | try { 22 | const nonce = await getAction( 23 | client, 24 | readContract, 25 | "readContract" 26 | )({ 27 | abi: KernelV3AccountAbi, 28 | address: account.address, 29 | functionName: "currentNonce", 30 | args: [] 31 | }) 32 | return nonce 33 | } catch (error) { 34 | return 1 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /plugins/multi-chain-weighted-validator/utils.ts: -------------------------------------------------------------------------------- 1 | import { type Hex, decodeAbiParameters, encodeAbiParameters } from "viem" 2 | 3 | export const encodeSignatures = (merkleData: Hex, signatures: Hex[]) => { 4 | return encodeAbiParameters( 5 | [ 6 | { name: "merkleData", type: "bytes" }, 7 | { name: "signatures", type: "bytes[]" } 8 | ], 9 | [merkleData, signatures] 10 | ) 11 | } 12 | 13 | export const decodeSignatures = ( 14 | signaturesData: Hex 15 | ): { merkleData: Hex; signatures: Hex[] } => { 16 | const [merkleData, signatures] = decodeAbiParameters( 17 | [ 18 | { name: "merkleData", type: "bytes" }, 19 | { name: "signatures", type: "bytes[]" } 20 | ], 21 | signaturesData 22 | ) 23 | return { 24 | merkleData, 25 | signatures: [...signatures] 26 | } 27 | } 28 | 29 | // Sort addresses in descending order 30 | export const sortByPublicKey = ( 31 | a: { publicKey: Hex } | { getPublicKey: () => Hex }, 32 | b: { publicKey: Hex } | { getPublicKey: () => Hex } 33 | ) => { 34 | if ("publicKey" in a && "publicKey" in b) 35 | return a.publicKey.toLowerCase() < b.publicKey.toLowerCase() ? 1 : -1 36 | else if ("getPublicKey" in a && "getPublicKey" in b) 37 | return a.getPublicKey().toLowerCase() < b.getPublicKey().toLowerCase() 38 | ? 1 39 | : -1 40 | else return 0 41 | } 42 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "workspaces": ["packages/*", "templates/*", "plugins/*"], 3 | "private": true, 4 | "author": "ZeroDev", 5 | "type": "module", 6 | "sideEffects": false, 7 | "devDependencies": { 8 | "@ambire/signature-validator": "^1.3.1", 9 | "@biomejs/biome": "^1.0.0", 10 | "@changesets/changelog-git": "^0.1.14", 11 | "@changesets/changelog-github": "^0.4.8", 12 | "@changesets/cli": "^2.26.2", 13 | "@size-limit/esbuild-why": "^9.0.0", 14 | "@size-limit/preset-small-lib": "^9.0.0", 15 | "@types/semver": "^7.5.8", 16 | "ethers": "5", 17 | "rimraf": "^5.0.1", 18 | "simple-git-hooks": "^2.9.0", 19 | "size-limit": "^9.0.0", 20 | "tslib": "^2.6.2", 21 | "typescript": "~5.3.0" 22 | }, 23 | "description": "", 24 | "keywords": [], 25 | "license": "MIT", 26 | "scripts": { 27 | "build": "bash build-all.sh", 28 | "format": "biome format . --write", 29 | "lint": "biome check .", 30 | "lint:fix": "bun run lint --write", 31 | "changeset": "changeset", 32 | "changeset:release": "bash remove-type.sh && bun run build && changeset publish && bash restore-type.sh && bun run format", 33 | "changeset:version": "changeset version && bun install --lockfile-only" 34 | }, 35 | "simple-git-hooks": { 36 | "pre-commit": "bun run format && bun run lint:fix" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /plugins/modularPermission/policies/types.ts: -------------------------------------------------------------------------------- 1 | import type { Abi, Address, Hex } from "viem" 2 | import type { UserOperation } from "viem/account-abstraction" 3 | import type { PolicyFlags } from "../constants.js" 4 | import type { Permission } from "../types.js" 5 | 6 | export type PolicyParams = { 7 | policyAddress?: Address 8 | policyFlag?: PolicyFlags 9 | } 10 | 11 | export type SudoPolicyParams = PolicyParams 12 | 13 | export type SignaturePolicyParams = PolicyParams & { 14 | allowedRequestors: Address[] 15 | } 16 | 17 | export type MerklePolicyParams< 18 | TAbi extends Abi | readonly unknown[], 19 | TFunctionName extends string | undefined = string 20 | > = PolicyParams & { 21 | permissions?: Permission[] 22 | } 23 | 24 | export type GasPolicyParams = PolicyParams & { 25 | maxGasAllowedInWei: bigint 26 | enforcePaymaster?: boolean 27 | paymasterAddress?: Address 28 | } 29 | 30 | export type Policy = { 31 | getPolicyData: () => Hex 32 | getSignaturePolicyData: (userOperation: UserOperation) => Hex 33 | getPolicyInfoInBytes: () => Hex 34 | // return params directly to serialize/deserialize Policy 35 | policyParams: 36 | | (SudoPolicyParams & { type: "sudo" }) 37 | | (SignaturePolicyParams & { type: "signature" }) 38 | | (MerklePolicyParams & { 39 | type: "merkle" 40 | }) 41 | | (GasPolicyParams & { type: "gas" }) 42 | } 43 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/plugins/ep0_6/getEncodedPluginsData.ts: -------------------------------------------------------------------------------- 1 | import { type Address, type Hex, concat, pad, toHex } from "viem" 2 | import { 3 | type PluginValidityData, 4 | ValidatorMode 5 | } from "../../../../../types/index.js" 6 | import type { Kernel2_0_plugins } from "./getPluginsEnableTypedData.js" 7 | 8 | export const getEncodedPluginsData = async ({ 9 | accountAddress, 10 | enableSignature, 11 | action, 12 | validator, 13 | validUntil, 14 | validAfter 15 | }: { 16 | accountAddress: Address 17 | enableSignature: Hex 18 | } & Kernel2_0_plugins & 19 | PluginValidityData) => { 20 | const enableData = await validator.getEnableData(accountAddress) 21 | const enableDataLength = enableData.length / 2 - 1 22 | return concat([ 23 | ValidatorMode.enable, 24 | pad(toHex(validUntil, { size: 6 }), { size: 6 }), // 6 bytes 4 - 10 25 | pad(toHex(validAfter), { size: 6 }), // 6 bytes 10 - 16 26 | pad(validator.address, { size: 20 }), // 20 bytes 16 - 36 27 | pad(action.address, { size: 20 }), // 20 bytes 36 - 56 28 | pad(toHex(enableDataLength), { size: 32 }), // 32 bytes 56 - 88 29 | enableData, // 88 - 88 + enableData.length 30 | pad(toHex(enableSignature.length / 2 - 1), { size: 32 }), // 32 bytes 88 + enableData.length - 120 + enableData.length 31 | enableSignature // 120 + enableData.length - 120 + enableData.length + enableSignature.length 32 | ]) 33 | } 34 | -------------------------------------------------------------------------------- /packages/test/abis/TokenActionsAbi.ts: -------------------------------------------------------------------------------- 1 | export const TokenActionsAbi = [ 2 | { 3 | type: "function", 4 | name: "transferERC1155Action", 5 | inputs: [ 6 | { name: "_token", type: "address", internalType: "address" }, 7 | { name: "_id", type: "uint256", internalType: "uint256" }, 8 | { name: "_to", type: "address", internalType: "address" }, 9 | { name: "amount", type: "uint256", internalType: "uint256" }, 10 | { name: "data", type: "bytes", internalType: "bytes" } 11 | ], 12 | outputs: [], 13 | stateMutability: "nonpayable" 14 | }, 15 | { 16 | type: "function", 17 | name: "transferERC20Action", 18 | inputs: [ 19 | { name: "_token", type: "address", internalType: "address" }, 20 | { name: "_amount", type: "uint256", internalType: "uint256" }, 21 | { name: "_to", type: "address", internalType: "address" } 22 | ], 23 | outputs: [], 24 | stateMutability: "nonpayable" 25 | }, 26 | { 27 | type: "function", 28 | name: "transferERC721Action", 29 | inputs: [ 30 | { name: "_token", type: "address", internalType: "address" }, 31 | { name: "_id", type: "uint256", internalType: "uint256" }, 32 | { name: "_to", type: "address", internalType: "address" } 33 | ], 34 | outputs: [], 35 | stateMutability: "nonpayable" 36 | } 37 | ] as const 38 | -------------------------------------------------------------------------------- /plugins/modularPermission/policies/toGasPolicy.ts: -------------------------------------------------------------------------------- 1 | import { concatHex, encodeAbiParameters, zeroAddress } from "viem" 2 | import { PolicyFlags } from "../constants.js" 3 | import { GAS_POLICY_CONTRACT } from "../constants.js" 4 | import type { GasPolicyParams, Policy } from "./types.js" 5 | 6 | export async function toGasPolicy({ 7 | policyAddress = GAS_POLICY_CONTRACT, 8 | policyFlag = PolicyFlags.FOR_ALL_VALIDATION, 9 | maxGasAllowedInWei, 10 | enforcePaymaster = false, 11 | paymasterAddress = zeroAddress 12 | }: GasPolicyParams): Promise { 13 | return { 14 | getPolicyData: () => { 15 | return encodeAbiParameters( 16 | [ 17 | { name: "maxGasAllowedInWei", type: "uint128" }, 18 | { name: "enforcePaymaster", type: "bool" }, 19 | { name: "paymasterAddress", type: "address" } 20 | ], 21 | [maxGasAllowedInWei, enforcePaymaster, paymasterAddress] 22 | ) 23 | }, 24 | getSignaturePolicyData: () => { 25 | return "0x" 26 | }, 27 | getPolicyInfoInBytes: () => { 28 | return concatHex([policyFlag, policyAddress]) 29 | }, 30 | policyParams: { 31 | type: "gas", 32 | policyAddress, 33 | policyFlag, 34 | maxGasAllowedInWei, 35 | enforcePaymaster, 36 | paymasterAddress 37 | } as GasPolicyParams & { type: "gas" } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ZeroDev SDK 2 | 3 | [![Main](https://github.com/zerodevapp/sdk/actions/workflows/on-push-to-main.yml/badge.svg)](https://github.com/zerodevapp/sdk/actions/workflows/on-push-to-main.yml) 4 | 5 | [See here for detailed documentation.](https://docs.zerodev.app) 6 | 7 | ## Examples 8 | 9 | For examples using ZeroDev, check out [the examples repo](https://github.com/zerodevapp/zerodev-examples). 10 | 11 | ## Installation 12 | 13 | ```bash 14 | npm install @zerodev/sdk 15 | ``` 16 | 17 | ```bash 18 | yarn add @zerodev/sdk 19 | ``` 20 | 21 | ```bash 22 | bun install @zerodev/sdk 23 | ``` 24 | 25 | ## Building and Testing 26 | 27 | Before running the tests, ensure you have installed [bun](https://bun.sh/) and all the necessary dependencies and built the core package: 28 | 29 | ```bash 30 | bun install 31 | bun run build 32 | ``` 33 | 34 | Then, copy the `.env.example` file to `.env` and define all necessary environment variables: 35 | 36 | ```bash 37 | cp .env.example .env 38 | ``` 39 | 40 | Now you can run the tests: 41 | 42 | ```bash 43 | bun test 44 | ``` 45 | 46 | ## Contributing 47 | 48 | Contributions are welcome! Please read our [contributing guidelines](./CONTRIBUTING.md) for details on how to contribute to the project. 49 | 50 | ## License 51 | 52 | The @zerodev packages are released under the MIT License. See the [LICENSE](./LICENSE) file for more details. 53 | 54 | ## Contact 55 | 56 | If you have any questions or would like to get in touch with the team, please join our [Discord channel](https://discord.gg/KS9MRaTSjx). 57 | -------------------------------------------------------------------------------- /plugins/permission/policies/toGasPolicy.ts: -------------------------------------------------------------------------------- 1 | import { type Address, concatHex, encodeAbiParameters, zeroAddress } from "viem" 2 | import { PolicyFlags } from "../constants.js" 3 | import { GAS_POLICY_CONTRACT } from "../constants.js" 4 | import type { Policy, PolicyParams } from "../types.js" 5 | 6 | export type GasPolicyParams = PolicyParams & { 7 | allowed?: bigint 8 | enforcePaymaster?: boolean 9 | allowedPaymaster?: Address 10 | } 11 | 12 | export function toGasPolicy({ 13 | policyAddress = GAS_POLICY_CONTRACT, 14 | policyFlag = PolicyFlags.FOR_ALL_VALIDATION, 15 | allowed = 0n, 16 | enforcePaymaster = false, 17 | allowedPaymaster = zeroAddress 18 | }: GasPolicyParams): Policy { 19 | return { 20 | getPolicyData: () => { 21 | return encodeAbiParameters( 22 | [ 23 | { name: "allowed", type: "uint128" }, 24 | { name: "enforcePaymaster", type: "bool" }, 25 | { name: "allowedPaymaster", type: "address" } 26 | ], 27 | [allowed, enforcePaymaster, allowedPaymaster] 28 | ) 29 | }, 30 | getPolicyInfoInBytes: () => { 31 | return concatHex([policyFlag, policyAddress]) 32 | }, 33 | policyParams: { 34 | type: "gas", 35 | policyAddress, 36 | policyFlag, 37 | allowed, 38 | enforcePaymaster, 39 | allowedPaymaster 40 | } as GasPolicyParams & { type: "gas" } 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /plugins/session-key/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @zerodev/session-key 2 | 3 | ## 5.5.4 4 | 5 | ### Patch Changes 6 | 7 | - fix: typecast `toSigner` return value to LocalAccount 8 | 9 | ## 5.5.3 10 | 11 | ### Patch Changes 12 | 13 | - updated to use latest viem 2.28.0 and support for 7702 14 | 15 | ## 5.5.2 16 | 17 | ### Patch Changes 18 | 19 | - chore: update viem version 20 | 21 | ## 5.5.1 22 | 23 | ### Patch Changes 24 | 25 | - feat: remove "type" field 26 | 27 | ## 5.5.0 28 | 29 | ### Minor Changes 30 | 31 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 32 | 33 | ## 5.5.0-beta.0 34 | 35 | ### Minor Changes 36 | 37 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 38 | 39 | ## 5.4.4 40 | 41 | ### Patch Changes 42 | 43 | - Patch for latest permissionless 0.1.45 support 44 | 45 | ## 5.4.3 46 | 47 | ### Patch Changes 48 | 49 | - Pinned permissionless version >=0.1.18 <=0.1.29 50 | 51 | ## 5.4.1 52 | 53 | ### Patch Changes 54 | 55 | - Update viem to 2.16.3 56 | 57 | ## 5.4.0 58 | 59 | ### Minor Changes 60 | 61 | - Kernel v3.1 released. And kernel versioning update. Added kernelVersion param in the interface. 62 | 63 | ## 5.4.0-alpha-0 64 | 65 | ### Minor Changes 66 | 67 | - Integrated Kernel v3.1 and added kernelVersion param in account and plugins interface 68 | 69 | ## 5.3.0 70 | 71 | ### Minor Changes 72 | 73 | - Updated SessionKey contract address with native token transfer support 74 | 75 | ## 5.2.2 76 | 77 | ### Patch Changes 78 | 79 | - Update permissionless@0.1.18 80 | -------------------------------------------------------------------------------- /plugins/session-key/serializeSessionKeyAccount.ts: -------------------------------------------------------------------------------- 1 | import type { KernelSmartAccountImplementation } from "@zerodev/sdk" 2 | import type { Hex } from "viem" 3 | import type { EntryPointVersion, SmartAccount } from "viem/account-abstraction" 4 | import { 5 | isSessionKeyValidatorPlugin, 6 | serializeSessionKeyAccountParams 7 | } from "./utils.js" 8 | 9 | export const serializeSessionKeyAccount = async < 10 | entryPointVersion extends EntryPointVersion 11 | >( 12 | account: SmartAccount>, 13 | privateKey?: Hex 14 | ): Promise => { 15 | if (!isSessionKeyValidatorPlugin(account.kernelPluginManager)) 16 | throw new Error("Account plugin is not a session key validator") 17 | const sessionKeyParams = 18 | account.kernelPluginManager.getPluginSerializationParams() 19 | const action = account.kernelPluginManager.getAction() 20 | const validityData = account.kernelPluginManager.getValidityData() 21 | const enableSignature = 22 | await account.kernelPluginManager.getPluginEnableSignature( 23 | account.address 24 | ) 25 | const accountParams = { 26 | initCode: await account.generateInitCode(), 27 | accountAddress: account.address 28 | } 29 | 30 | const paramsToBeSerialized = { 31 | sessionKeyParams, 32 | action, 33 | validityData, 34 | accountParams, 35 | enableSignature, 36 | privateKey 37 | } 38 | 39 | return serializeSessionKeyAccountParams(paramsToBeSerialized) 40 | } 41 | -------------------------------------------------------------------------------- /packages/core/actions/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | sponsorUserOperation, 3 | type SponsorUserOperationParameters, 4 | type SponsorUserOperationReturnType 5 | } from "./paymaster/sponsorUserOperation.js" 6 | 7 | export { 8 | signUserOperation, 9 | type SignUserOperationParameters, 10 | type SignUserOperationReturnType 11 | } from "./account-client/signUserOperation.js" 12 | 13 | export { 14 | getUserOperationGasPrice, 15 | type GetUserOperationGasPriceReturnType 16 | } from "./account-client/getUserOperationGasPrice.js" 17 | 18 | export { 19 | uninstallPlugin, 20 | type UninstallPluginParameters 21 | } from "./account-client/uninstallPlugin.js" 22 | 23 | export { getKernelV3ModuleCurrentNonce } from "./account-client/getKernelV3ModuleCurrentNonce.js" 24 | 25 | export { 26 | type InvalidateNonceParameters, 27 | invalidateNonce 28 | } from "./account-client/invalidateNonce.js" 29 | 30 | export { sendTransaction } from "./account-client/sendTransaction.js" 31 | 32 | export { signMessage } from "./account-client/signMessage.js" 33 | 34 | export { signTypedData } from "./account-client/signTypedData.js" 35 | 36 | export { writeContract } from "./account-client/writeContract.js" 37 | 38 | export { 39 | changeSudoValidator, 40 | type ChangeSudoValidatorParameters 41 | } from "./account-client/changeSudoValidator.js" 42 | 43 | export { 44 | estimateGasInERC20, 45 | type EstimateGasInERC20Parameters, 46 | type EstimateGasInERC20ReturnType 47 | } from "./paymaster/estimateGasInERC20.js" 48 | 49 | export * from "./public/index.js" 50 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/account/ep0_6/encodeCallData.ts: -------------------------------------------------------------------------------- 1 | import type { EntryPointVersion } from "viem/account-abstraction" 2 | import type { CallType } from "../../../../../types/kernel.js" 3 | import type { KernelSmartAccountImplementation } from "../../../createKernelAccount.js" 4 | import { encodeExecuteBatchCall } from "../../ep0_6/encodeExecuteBatchCall.js" 5 | import { encodeExecuteDelegateCall } from "../../ep0_6/encodeExecuteDelegateCall.js" 6 | import { encodeExecuteSingleCall } from "../../ep0_6/encodeExecuteSingleCall.js" 7 | 8 | export const encodeCallData = async < 9 | entryPointVersion extends EntryPointVersion = EntryPointVersion 10 | >( 11 | calls: Parameters< 12 | KernelSmartAccountImplementation["encodeCalls"] 13 | >[0], 14 | callType?: CallType | undefined 15 | ) => { 16 | if (calls.length > 1) { 17 | if (callType === "delegatecall") { 18 | throw new Error("Cannot batch delegatecall") 19 | } 20 | return encodeExecuteBatchCall(calls) 21 | } 22 | 23 | const call = calls.length === 0 ? undefined : calls[0] 24 | 25 | if (!call) { 26 | throw new Error("No calls to encode") 27 | } 28 | 29 | // Default to `call` 30 | if (!callType || callType === "call") { 31 | return encodeExecuteSingleCall(call) 32 | } 33 | 34 | if (callType === "delegatecall") { 35 | return encodeExecuteDelegateCall({ 36 | to: call.to, 37 | data: call.data 38 | }) 39 | } 40 | 41 | throw new Error("Invalid call type") 42 | } 43 | -------------------------------------------------------------------------------- /plugins/hooks/toSpendingLimitHook.ts: -------------------------------------------------------------------------------- 1 | import type { KernelValidatorHook } from "@zerodev/sdk" 2 | import { 3 | type Address, 4 | concatHex, 5 | encodeAbiParameters, 6 | encodePacked 7 | } from "viem" 8 | import { SPENDING_LIMIT_HOOK_V07 } from "./constants.js" 9 | 10 | export type SpendingLimit = { 11 | token: Address 12 | allowance: bigint 13 | } 14 | 15 | export async function toSpendingLimitHook({ 16 | limits, 17 | hookAddress 18 | }: { 19 | limits: SpendingLimit[] 20 | hookAddress?: Address 21 | }): Promise { 22 | return { 23 | getIdentifier() { 24 | return hookAddress ?? SPENDING_LIMIT_HOOK_V07 25 | }, 26 | async getEnableData() { 27 | const encodedLimits = limits.map((limit) => { 28 | const encodedToken = encodePacked(["address"], [limit.token]) 29 | const encodedAllowance = encodePacked( 30 | ["uint256"], 31 | [limit.allowance] 32 | ) 33 | 34 | return concatHex([encodedToken, encodedAllowance]) 35 | }) 36 | 37 | const encodedData = encodeAbiParameters( 38 | [{ name: "arr", type: "bytes[]" }], 39 | [encodedLimits] 40 | ) 41 | 42 | // hookData is encoded into (1bytes flag + actual hookdata) 43 | // flag is for identifying if the hook has to be initialized or not 44 | // 0xff means you want to explicitly call install hook 45 | return concatHex(["0xaa", encodedData]) 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /plugins/weighted-ecdsa/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @zerodev/weighted-ecdsa-validator 2 | 3 | ## 5.4.4 4 | 5 | ### Patch Changes 6 | 7 | - fix: typecast `toSigner` return value to LocalAccount 8 | 9 | ## 5.4.3 10 | 11 | ### Patch Changes 12 | 13 | - updated to use latest viem 2.28.0 and support for 7702 14 | 15 | ## 5.4.2 16 | 17 | ### Patch Changes 18 | 19 | - chore: update viem version 20 | 21 | ## 5.4.1 22 | 23 | ### Patch Changes 24 | 25 | - feat: remove "type" field 26 | 27 | ## 5.4.0 28 | 29 | ### Minor Changes 30 | 31 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 32 | 33 | ## 5.3.3 34 | 35 | ### Patch Changes 36 | 37 | - Patch for latest permissionless 0.1.45 support 38 | 39 | ## 5.3.2 40 | 41 | ### Patch Changes 42 | 43 | - Pinned permissionless version >=0.1.18 <=0.1.29 44 | 45 | ## 5.3.1 46 | 47 | ### Patch Changes 48 | 49 | - Update viem to 2.16.3 50 | 51 | ## 5.3.0 52 | 53 | ### Minor Changes 54 | 55 | - Kernel v3.1 released. And kernel versioning update. Added kernelVersion param in the interface. 56 | 57 | ## 5.3.0-alpha-0 58 | 59 | ### Minor Changes 60 | 61 | - Integrated Kernel v3.1 and added kernelVersion param in account and plugins interface 62 | 63 | ## 5.2.5 64 | 65 | ### Patch Changes 66 | 67 | - Fixed entryPoint param type 68 | 69 | ## 5.2.4 70 | 71 | ### Patch Changes 72 | 73 | - Added default only entrypoint hook integration for custom action in kernel v3 74 | 75 | ## 5.2.3 76 | 77 | ### Patch Changes 78 | 79 | - Update WeigthedECDSAValidator contract address for kernel v3 80 | 81 | ## 5.2.2 82 | 83 | ### Patch Changes 84 | 85 | - Update permissionless@0.1.18 86 | -------------------------------------------------------------------------------- /plugins/modularPermission/serializeModularPermissionAccount.ts: -------------------------------------------------------------------------------- 1 | import type { KernelSmartAccountImplementation } from "@zerodev/sdk" 2 | import type { Hex } from "viem" 3 | import type { EntryPointVersion, SmartAccount } from "viem/account-abstraction" 4 | import { 5 | isModularPermissionValidatorPlugin, 6 | serializeModularPermissionAccountParams 7 | } from "./utils.js" 8 | 9 | export const serializeModularPermissionAccount = async < 10 | entryPointVersion extends EntryPointVersion 11 | >( 12 | account: SmartAccount>, 13 | privateKey?: Hex 14 | ): Promise => { 15 | if (!isModularPermissionValidatorPlugin(account.kernelPluginManager)) 16 | throw new Error("Account plugin is not a modular permission validator") 17 | const modularPermissionParams = 18 | account.kernelPluginManager.getPluginSerializationParams() 19 | const action = account.kernelPluginManager.getAction() 20 | const validityData = account.kernelPluginManager.getValidityData() 21 | const enableSignature = 22 | await account.kernelPluginManager.getPluginEnableSignature( 23 | account.address 24 | ) 25 | const accountParams = { 26 | initCode: await account.generateInitCode(), 27 | accountAddress: account.address 28 | } 29 | 30 | const paramsToBeSerialized = { 31 | modularPermissionParams, 32 | action, 33 | validityData, 34 | accountParams, 35 | enableSignature, 36 | privateKey 37 | } 38 | 39 | return serializeModularPermissionAccountParams(paramsToBeSerialized) 40 | } 41 | -------------------------------------------------------------------------------- /plugins/modularPermission/utils.ts: -------------------------------------------------------------------------------- 1 | import type { 2 | ModularPermissionAccountParams, 3 | ModularPermissionPlugin 4 | } from "./types.js" 5 | 6 | export function base64ToBytes(base64: string) { 7 | const binString = atob(base64) 8 | return Uint8Array.from(binString, (m) => m.codePointAt(0) as number) 9 | } 10 | 11 | export function bytesToBase64(bytes: Uint8Array) { 12 | const binString = Array.from(bytes, (x) => String.fromCodePoint(x)).join("") 13 | return btoa(binString) 14 | } 15 | 16 | export function isModularPermissionValidatorPlugin( 17 | // biome-ignore lint/suspicious/noExplicitAny: 18 | plugin: any 19 | ): plugin is ModularPermissionPlugin { 20 | return plugin?.getPluginSerializationParams !== undefined 21 | } 22 | 23 | export const serializeModularPermissionAccountParams = ( 24 | params: ModularPermissionAccountParams 25 | ) => { 26 | // biome-ignore lint/suspicious/noExplicitAny: 27 | const replacer = (_: string, value: any) => { 28 | if (typeof value === "bigint") { 29 | return value.toString() 30 | } 31 | return value 32 | } 33 | 34 | const jsonString = JSON.stringify(params, replacer) 35 | const uint8Array = new TextEncoder().encode(jsonString) 36 | const base64String = bytesToBase64(uint8Array) 37 | return base64String 38 | } 39 | 40 | export const deserializeModularPermissionAccountParams = (params: string) => { 41 | const uint8Array = base64ToBytes(params) 42 | const jsonString = new TextDecoder().decode(uint8Array) 43 | return JSON.parse(jsonString) as ModularPermissionAccountParams 44 | } 45 | -------------------------------------------------------------------------------- /packages/core/accounts/index.ts: -------------------------------------------------------------------------------- 1 | export { 2 | createKernelAccount, 3 | type CreateKernelAccountParameters, 4 | type CreateKernelAccountReturnType, 5 | type KernelSmartAccountImplementation, 6 | KERNEL_ADDRESSES 7 | } from "./kernel/createKernelAccount.js" 8 | export { 9 | createKernelAccountV1, 10 | type CreateKernelAccountV1ReturnType, 11 | type KernelSmartAccountV1Implementation 12 | } from "./kernel/v1/createKernelAccountV1.js" 13 | export { 14 | MIGRATION_HELPER_ADDRESS, 15 | createKernelMigrationAccount, 16 | type CreateKernelMigrationAccountParameters 17 | } from "./kernel/createKernelMigrationAccount.js" 18 | export { MigrationHelperAbi } from "./kernel/abi/MigrationHelperAbi.js" 19 | export { createKernelAccountV0_2 } from "./kernel/v2/createKernelAccountV0_2.js" 20 | export { KernelAccountV2Abi } from "./kernel/v2/abi/KernelAccountV2Abi.js" 21 | export { KernelFactoryV2Abi } from "./kernel/v2/abi/KernelFactoryV2Abi.js" 22 | export { EIP1271Abi } from "./kernel/abi/EIP1271Abi.js" 23 | export { addressToEmptyAccount } from "./addressToEmptyAccount.js" 24 | export * from "./utils/index.js" 25 | export { accountMetadata } from "./kernel/utils/common/accountMetadata.js" 26 | export { getActionSelector } from "./kernel/utils/common/getActionSelector.js" 27 | export { getPluginsEnableTypedData } from "./kernel/utils/plugins/ep0_7/getPluginsEnableTypedData.js" 28 | export { getKernelV3Nonce } from "./kernel/utils/account/ep0_7/getKernelV3Nonce.js" 29 | export { getPluginInstallCallData } from "./kernel/utils/plugins/ep0_7/getPluginInstallCallData.js" 30 | export type { CallArgs, DelegateCallArgs } from "./kernel/utils/types.js" 31 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.ts: -------------------------------------------------------------------------------- 1 | export const KernelModuleIsInitializedAbi = [ 2 | { 3 | type: "function", 4 | name: "isInitialized", 5 | inputs: [ 6 | { name: "smartAccount", type: "address", internalType: "address" } 7 | ], 8 | outputs: [{ name: "", type: "bool", internalType: "bool" }], 9 | stateMutability: "view" 10 | } 11 | ] as const 12 | 13 | export const KernelModuleInstallAbi = [ 14 | { 15 | inputs: [ 16 | { 17 | internalType: "uint256", 18 | name: "moduleType", 19 | type: "uint256" 20 | }, 21 | { internalType: "address", name: "module", type: "address" }, 22 | { internalType: "bytes", name: "initData", type: "bytes" } 23 | ], 24 | stateMutability: "payable", 25 | type: "function", 26 | name: "installModule" 27 | } 28 | ] as const 29 | 30 | export const KernelModuleIsModuleInstalledAbi = [ 31 | { 32 | inputs: [ 33 | { 34 | internalType: "uint256", 35 | name: "moduleType", 36 | type: "uint256" 37 | }, 38 | { internalType: "address", name: "module", type: "address" }, 39 | { 40 | internalType: "bytes", 41 | name: "additionalContext", 42 | type: "bytes" 43 | } 44 | ], 45 | stateMutability: "view", 46 | type: "function", 47 | name: "isModuleInstalled", 48 | outputs: [{ internalType: "bool", name: "", type: "bool" }] 49 | } 50 | ] as const 51 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/ep0_7/encodeExecuteBatchCall.ts: -------------------------------------------------------------------------------- 1 | import { encodeAbiParameters } from "viem" 2 | import { CALL_TYPE } from "../../../../constants.js" 3 | import type { CallArgs } from "../types.js" 4 | import { 5 | type EncodeExecuteOptions, 6 | encodeExecuteCall 7 | } from "./encodeExecuteCall.js" 8 | 9 | export const encodeExecuteBatchCall = ( 10 | args: readonly CallArgs[], 11 | options: Omit, 12 | includeHooks?: boolean 13 | ) => { 14 | const calldata = encodeAbiParameters( 15 | [ 16 | { 17 | name: "executionBatch", 18 | type: "tuple[]", 19 | components: [ 20 | { 21 | name: "target", 22 | type: "address" 23 | }, 24 | { 25 | name: "value", 26 | type: "uint256" 27 | }, 28 | { 29 | name: "callData", 30 | type: "bytes" 31 | } 32 | ] 33 | } 34 | ], 35 | [ 36 | args.map((arg) => { 37 | return { 38 | target: arg.to, 39 | value: arg.value || 0n, 40 | callData: arg.data || "0x" 41 | } 42 | }) 43 | ] 44 | ) 45 | return encodeExecuteCall( 46 | { calldata }, 47 | { 48 | callType: CALL_TYPE.BATCH, 49 | execType: options.execType 50 | }, 51 | includeHooks 52 | ) 53 | } 54 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/common/eip712WrapHash.ts: -------------------------------------------------------------------------------- 1 | import { 2 | type Hex, 3 | type TypedDataDomain, 4 | concatHex, 5 | domainSeparator, 6 | keccak256 7 | } from "viem" 8 | import type { WithRequired } from "../../../../types/index.js" 9 | import { KERNEL_FEATURES, hasKernelFeature } from "../../../../utils.js" 10 | import { hashKernelMessageHashWrapper } from "../ep0_7/hashKernelSignatureWrapper.js" 11 | 12 | export const eip712WrapHash = async ( 13 | messageHash: Hex, 14 | domain: WithRequired< 15 | TypedDataDomain, 16 | "name" | "chainId" | "verifyingContract" | "version" 17 | >, 18 | useReplayableSignature?: boolean 19 | ): Promise => { 20 | const { name, version, chainId, verifyingContract } = domain 21 | 22 | if (!hasKernelFeature(KERNEL_FEATURES.ERC1271_SIG_WRAPPER, version)) { 23 | return messageHash 24 | } 25 | 26 | const _chainId = 27 | hasKernelFeature(KERNEL_FEATURES.ERC1271_REPLAYABLE, version) && 28 | useReplayableSignature 29 | ? 0 30 | : chainId 31 | 32 | const _domainSeparator = domainSeparator({ 33 | domain: { 34 | name, 35 | version, 36 | chainId: _chainId, 37 | verifyingContract 38 | } 39 | }) 40 | 41 | let finalMessageHash = messageHash 42 | if ( 43 | hasKernelFeature( 44 | KERNEL_FEATURES.ERC1271_SIG_WRAPPER_WITH_WRAPPED_HASH, 45 | version 46 | ) 47 | ) { 48 | finalMessageHash = hashKernelMessageHashWrapper(finalMessageHash) 49 | } 50 | 51 | const digest = keccak256( 52 | concatHex(["0x1901", _domainSeparator, finalMessageHash]) 53 | ) 54 | return digest 55 | } 56 | -------------------------------------------------------------------------------- /.github/workflows/on-push-to-main.yml: -------------------------------------------------------------------------------- 1 | name: Main 2 | on: 3 | push: 4 | branches: [main] 5 | workflow_dispatch: 6 | 7 | concurrency: 8 | group: ${{ github.workflow }}-${{ github.ref }} 9 | cancel-in-progress: true 10 | 11 | jobs: 12 | verify: 13 | name: Verify 14 | uses: ./.github/workflows/verify.yml 15 | secrets: inherit 16 | 17 | changesets: 18 | if: false 19 | name: Changesets 20 | runs-on: ubuntu-latest 21 | timeout-minutes: 5 22 | 23 | steps: 24 | - name: Clone repository 25 | uses: actions/checkout@v3 26 | with: 27 | # This makes Actions fetch all Git history so that Changesets can generate changelogs with the correct commits 28 | fetch-depth: 0 29 | 30 | - name: Install dependencies 31 | uses: ./.github/actions/install-dependencies 32 | 33 | - name: Create Version Pull Request 34 | uses: changesets/action@v1 35 | with: 36 | version: bun run changeset:version 37 | commit: 'chore: version package' 38 | title: 'chore: version package' 39 | env: 40 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 41 | 42 | release: 43 | if: false 44 | name: Release 45 | needs: verify 46 | runs-on: ubuntu-latest 47 | timeout-minutes: 5 48 | 49 | steps: 50 | - name: Clone repository 51 | uses: actions/checkout@v3 52 | 53 | - name: Install dependencies 54 | uses: ./.github/actions/install-dependencies 55 | 56 | - name: Publish to NPM 57 | uses: changesets/action@v1 58 | with: 59 | publish: bun run changeset:release 60 | env: 61 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 62 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 63 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/plugins/ep0_7/getEncodedPluginsData.ts: -------------------------------------------------------------------------------- 1 | import { 2 | type Hex, 3 | concat, 4 | encodeAbiParameters, 5 | parseAbiParameters, 6 | zeroAddress 7 | } from "viem" 8 | import { CALL_TYPE } from "../../../../../constants.js" 9 | import type { 10 | Action, 11 | KernelValidatorHook 12 | } from "../../../../../types/kernel.js" 13 | 14 | export const getEncodedPluginsData = async ({ 15 | enableSignature, 16 | userOpSignature, 17 | action, 18 | enableData, 19 | hook 20 | }: { 21 | enableSignature: Hex 22 | userOpSignature: Hex 23 | action: Action 24 | enableData: Hex 25 | hook?: KernelValidatorHook 26 | }) => { 27 | return concat([ 28 | hook?.getIdentifier() ?? zeroAddress, // hook address 20 bytes 29 | encodeAbiParameters( 30 | parseAbiParameters( 31 | "bytes validatorData, bytes hookData, bytes selectorData, bytes enableSig, bytes userOpSig" 32 | ), 33 | [ 34 | enableData, 35 | (await hook?.getEnableData()) ?? "0x", 36 | concat([ 37 | action.selector, 38 | action.address, 39 | action.hook?.address ?? zeroAddress, 40 | encodeAbiParameters( 41 | parseAbiParameters( 42 | "bytes selectorInitData, bytes hookInitData" 43 | ), 44 | // [TODO]: Add support for other call_type 45 | [CALL_TYPE.DELEGATE_CALL, "0x0000"] 46 | ) 47 | ]), 48 | enableSignature, 49 | userOpSignature 50 | ] 51 | ) 52 | ]) 53 | } 54 | -------------------------------------------------------------------------------- /packages/test/v0.7/utils/recovery.ts: -------------------------------------------------------------------------------- 1 | import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator" 2 | import { createKernelAccount } from "@zerodev/sdk" 3 | import { 4 | createWeightedECDSAValidator, 5 | getRecoveryAction 6 | } from "@zerodev/weighted-ecdsa-validator" 7 | import type { Address } from "viem" 8 | import { generatePrivateKey, privateKeyToAccount } from "viem/accounts" 9 | import { getEntryPoint, getPublicClient, index, kernelVersion } from "./common" 10 | 11 | export const getRecoveryKernelAccount = async ( 12 | deployedAccountAddress?: Address 13 | ) => { 14 | const privateKey1 = generatePrivateKey() 15 | const privateKey2 = generatePrivateKey() 16 | const signer1 = privateKeyToAccount(privateKey1) 17 | const signer2 = privateKeyToAccount(privateKey2) 18 | const publicClient = await getPublicClient() 19 | const ecdsaPlugin = await signerToEcdsaValidator(publicClient, { 20 | entryPoint: getEntryPoint(), 21 | signer: signer1, 22 | kernelVersion 23 | }) 24 | const recoveryPlugin = await createWeightedECDSAValidator(publicClient, { 25 | entryPoint: getEntryPoint(), 26 | kernelVersion, 27 | config: { 28 | threshold: 100, 29 | delay: 0, 30 | signers: [{ address: signer2.address, weight: 100 }] 31 | }, 32 | signers: [signer2] 33 | }) 34 | return await createKernelAccount(await getPublicClient(), { 35 | entryPoint: getEntryPoint(), 36 | address: deployedAccountAddress, 37 | plugins: { 38 | sudo: ecdsaPlugin, 39 | regular: recoveryPlugin, 40 | action: getRecoveryAction(getEntryPoint().version) 41 | }, 42 | index, 43 | kernelVersion 44 | }) 45 | } 46 | -------------------------------------------------------------------------------- /plugins/weighted-r1-k1/signers/toECDSASigner.ts: -------------------------------------------------------------------------------- 1 | import { constants, fixSignedData, toSigner } from "@zerodev/sdk" 2 | import type { Signer } from "@zerodev/sdk/types" 3 | import type { TypedData } from "abitype" 4 | import type { TypedDataDefinition } from "viem" 5 | import { toAccount } from "viem/accounts" 6 | import { SIGNER_TYPE } from "../constants.js" 7 | import type { WeightedSigner } from "../toWeightedValidatorPlugin.js" 8 | 9 | export type ECDSASignerParams = { 10 | signer: Signer 11 | } 12 | 13 | export async function toECDSASigner({ 14 | signer 15 | }: ECDSASignerParams): Promise { 16 | const viemSigner = await toSigner({ signer }) 17 | const account = toAccount({ 18 | address: viemSigner.address, 19 | async signMessage({ message }) { 20 | return fixSignedData(await viemSigner.signMessage({ message })) 21 | }, 22 | async signTransaction(_, __) { 23 | throw new Error( 24 | "Smart account signer doesn't need to sign transactions" 25 | ) 26 | }, 27 | async signTypedData< 28 | const TTypedData extends TypedData | Record, 29 | TPrimaryType extends 30 | | keyof TTypedData 31 | | "EIP712Domain" = keyof TTypedData 32 | >(typedData: TypedDataDefinition) { 33 | return fixSignedData( 34 | await viemSigner.signTypedData({ 35 | ...typedData 36 | }) 37 | ) 38 | } 39 | }) 40 | return { 41 | type: SIGNER_TYPE.ECDSA, 42 | getPublicKey: () => account.address, 43 | account, 44 | getDummySignature: () => constants.DUMMY_ECDSA_SIG 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /plugins/hooks/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zerodev/hooks", 3 | "version": "5.3.4", 4 | "author": "ZeroDev", 5 | "main": "./_cjs/index.js", 6 | "module": "./_esm/index.js", 7 | "types": "./_types/index.d.ts", 8 | "typings": "./_types/index.d.ts", 9 | "sideEffects": false, 10 | "license": "MIT", 11 | "files": [ 12 | "_esm", 13 | "_cjs", 14 | "_types", 15 | "./**/*.ts", 16 | "!_esm/**/*.tsbuildinfo", 17 | "!_cjs/**/*.tsbuildinfo", 18 | "!_types/**/*.tsbuildinfo", 19 | "!.env", 20 | "!./**/*.test.ts", 21 | "!.changeset" 22 | ], 23 | "scripts": { 24 | "build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types", 25 | "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./_cjs/package.json", 26 | "build:esm": "tsc --project ./tsconfig.build.json --module es2015 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json", 27 | "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap", 28 | "clean": "rimraf _esm _cjs _types", 29 | "changeset": "changeset", 30 | "changeset:release": "bun run build && changeset publish", 31 | "changeset:version": "changeset version && bun install --lockfile-only", 32 | "format": "biome format . --write", 33 | "lint": "biome check .", 34 | "lint:fix": "bun run lint --apply" 35 | }, 36 | "peerDependencies": { 37 | "viem": "^2.28.0", 38 | "@zerodev/sdk": "^5.4.0" 39 | }, 40 | "type": "module" 41 | } 42 | -------------------------------------------------------------------------------- /packages/test/config.ts: -------------------------------------------------------------------------------- 1 | import type { EntryPointVersion } from "viem/account-abstraction" 2 | import { 3 | baseSepolia, 4 | optimismSepolia, 5 | polygonMumbai, 6 | sepolia 7 | } from "viem/chains" 8 | 9 | export const config: { 10 | [key in EntryPointVersion]: { 11 | [key in number]: { 12 | rpcUrl: string 13 | chainId: number 14 | bundlerUrl: string 15 | projectId: string 16 | } 17 | } 18 | } = { 19 | "0.6": { 20 | [sepolia.id]: { 21 | rpcUrl: process.env.RPC_URL_SEPOLIA || "", 22 | bundlerUrl: process.env.ZERODEV_BUNDLER_RPC_HOST_EPV07 || "", 23 | chainId: sepolia.id, 24 | projectId: process.env.ZERODEV_PROJECT_ID_SEPOLIA || "" 25 | } 26 | }, 27 | "0.7": { 28 | [sepolia.id]: { 29 | rpcUrl: process.env.RPC_URL_SEPOLIA || "", 30 | bundlerUrl: process.env.ZERODEV_BUNDLER_RPC_HOST_EPV07 || "", 31 | chainId: sepolia.id, 32 | projectId: process.env.ZERODEV_PROJECT_ID_SEPOLIA || "" 33 | }, 34 | [optimismSepolia.id]: { 35 | rpcUrl: process.env.RPC_URL_OP_SEPOLIA || "", 36 | bundlerUrl: process.env.ZERODEV_BUNDLER_RPC_HOST_EPV07 || "", 37 | chainId: optimismSepolia.id, 38 | projectId: process.env.ZERODEV_PROJECT_ID_OP_SEPOLIA || "" 39 | }, 40 | [baseSepolia.id]: { 41 | rpcUrl: process.env.RPC_URL_BASE_SEPOLIA || "", 42 | bundlerUrl: process.env.ZERODEV_BUNDLER_RPC_HOST_EPV07 || "", 43 | chainId: baseSepolia.id, 44 | projectId: process.env.ZERODEV_PROJECT_ID_BASE_SEPOLIA || "" 45 | } 46 | } 47 | } 48 | 49 | export const TOKEN_ACTION_ADDRESS = "0xA015bd458DbAc61c254104099f544dB6ef570c7C" 50 | -------------------------------------------------------------------------------- /plugins/ecdsa/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zerodev/ecdsa-validator", 3 | "version": "5.4.9", 4 | "author": "ZeroDev", 5 | "main": "./_cjs/index.js", 6 | "module": "./_esm/index.js", 7 | "types": "./_types/index.d.ts", 8 | "typings": "./_types/index.d.ts", 9 | "sideEffects": false, 10 | "license": "MIT", 11 | "files": [ 12 | "_esm", 13 | "_cjs", 14 | "_types", 15 | "./**/*.ts", 16 | "!_esm/**/*.tsbuildinfo", 17 | "!_cjs/**/*.tsbuildinfo", 18 | "!_types/**/*.tsbuildinfo", 19 | "!.env", 20 | "!./**/*.test.ts", 21 | "!.changeset" 22 | ], 23 | "scripts": { 24 | "build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types", 25 | "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./_cjs/package.json", 26 | "build:esm": "tsc --project ./tsconfig.build.json --module es2015 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json", 27 | "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap", 28 | "clean": "rimraf _esm _cjs _types", 29 | "changeset": "changeset", 30 | "changeset:release": "bun run build && changeset publish", 31 | "changeset:version": "changeset version && bun install --lockfile-only", 32 | "format": "biome format . --write", 33 | "lint": "biome check .", 34 | "lint:fix": "bun run lint --apply" 35 | }, 36 | "peerDependencies": { 37 | "viem": "^2.28.0", 38 | "@zerodev/sdk": "^5.4.13" 39 | }, 40 | "type": "module" 41 | } 42 | -------------------------------------------------------------------------------- /plugins/remoteSigner/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zerodev/remote-signer", 3 | "version": "5.3.3", 4 | "author": "ZeroDev", 5 | "main": "./_cjs/index.js", 6 | "module": "./_esm/index.js", 7 | "types": "./_types/index.d.ts", 8 | "typings": "./_types/index.d.ts", 9 | "sideEffects": false, 10 | "license": "MIT", 11 | "files": [ 12 | "_esm", 13 | "_cjs", 14 | "_types", 15 | "./**/*.ts", 16 | "!_esm/**/*.tsbuildinfo", 17 | "!_cjs/**/*.tsbuildinfo", 18 | "!_types/**/*.tsbuildinfo", 19 | "!.env", 20 | "!./**/*.test.ts", 21 | "!.changeset" 22 | ], 23 | "scripts": { 24 | "build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types", 25 | "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./_cjs/package.json", 26 | "build:esm": "tsc --project ./tsconfig.build.json --module es2015 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json", 27 | "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap", 28 | "clean": "rimraf _esm _cjs _types", 29 | "changeset": "changeset", 30 | "changeset:release": "bun run build && changeset publish", 31 | "changeset:version": "changeset version && bun install --lockfile-only", 32 | "format": "biome format . --write", 33 | "lint": "biome check .", 34 | "lint:fix": "bun run lint --apply" 35 | }, 36 | "peerDependencies": { 37 | "viem": "^2.28.0", 38 | "@zerodev/sdk": "^5.4.0" 39 | }, 40 | "type": "module" 41 | } 42 | -------------------------------------------------------------------------------- /plugins/multi-chain-weighted-validator/signers/toECDSASigner.ts: -------------------------------------------------------------------------------- 1 | import { constants, fixSignedData, toSigner } from "@zerodev/sdk" 2 | import type { Signer } from "@zerodev/sdk/types" 3 | import type { TypedData } from "abitype" 4 | import type { TypedDataDefinition } from "viem" 5 | import { toAccount } from "viem/accounts" 6 | import { SIGNER_TYPE } from "../constants.js" 7 | import type { WeightedSigner } from "../toMultiChainWeightedValidatorPlugin.js" 8 | 9 | export type ECDSASignerParams = { 10 | signer: Signer 11 | } 12 | 13 | export async function toECDSASigner({ 14 | signer 15 | }: ECDSASignerParams): Promise { 16 | const viemSigner = await toSigner({ signer }) 17 | const account = toAccount({ 18 | address: viemSigner.address, 19 | async signMessage({ message }) { 20 | return fixSignedData(await viemSigner.signMessage({ message })) 21 | }, 22 | async signTransaction(_, __) { 23 | throw new Error( 24 | "Smart account signer doesn't need to sign transactions" 25 | ) 26 | }, 27 | async signTypedData< 28 | const TTypedData extends TypedData | Record, 29 | TPrimaryType extends 30 | | keyof TTypedData 31 | | "EIP712Domain" = keyof TTypedData 32 | >(typedData: TypedDataDefinition) { 33 | return fixSignedData( 34 | await viemSigner.signTypedData({ 35 | ...typedData 36 | }) 37 | ) 38 | } 39 | }) 40 | return { 41 | type: SIGNER_TYPE.ECDSA, 42 | getPublicKey: () => account.address, 43 | account, 44 | getDummySignature: () => constants.DUMMY_ECDSA_SIG 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /plugins/smart-account/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zerodev/smart-account-validator", 3 | "version": "5.4.1", 4 | "author": "ZeroDev", 5 | "main": "./_cjs/index.js", 6 | "module": "./_esm/index.js", 7 | "types": "./_types/index.d.ts", 8 | "typings": "./_types/index.d.ts", 9 | "sideEffects": false, 10 | "license": "MIT", 11 | "files": [ 12 | "_esm", 13 | "_cjs", 14 | "_types", 15 | "./**/*.ts", 16 | "!_esm/**/*.tsbuildinfo", 17 | "!_cjs/**/*.tsbuildinfo", 18 | "!_types/**/*.tsbuildinfo", 19 | "!.env", 20 | "!./**/*.test.ts", 21 | "!.changeset" 22 | ], 23 | "scripts": { 24 | "build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types", 25 | "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./_cjs/package.json", 26 | "build:esm": "tsc --project ./tsconfig.build.json --module es2015 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json", 27 | "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap", 28 | "clean": "rimraf _esm _cjs _types", 29 | "changeset": "changeset", 30 | "changeset:release": "bun run build && changeset publish", 31 | "changeset:version": "changeset version && bun install --lockfile-only", 32 | "format": "biome format . --write", 33 | "lint": "biome check .", 34 | "lint:fix": "bun run lint --apply" 35 | }, 36 | "peerDependencies": { 37 | "viem": "^2.28.0", 38 | "@zerodev/sdk": "^5.4.13" 39 | }, 40 | "type": "module" 41 | } 42 | -------------------------------------------------------------------------------- /plugins/weighted-ecdsa/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zerodev/weighted-ecdsa-validator", 3 | "version": "5.4.4", 4 | "author": "ZeroDev", 5 | "main": "./_cjs/index.js", 6 | "module": "./_esm/index.js", 7 | "types": "./_types/index.d.ts", 8 | "typings": "./_types/index.d.ts", 9 | "sideEffects": false, 10 | "license": "MIT", 11 | "files": [ 12 | "_esm", 13 | "_cjs", 14 | "_types", 15 | "./**/*.ts", 16 | "!_esm/**/*.tsbuildinfo", 17 | "!_cjs/**/*.tsbuildinfo", 18 | "!_types/**/*.tsbuildinfo", 19 | "!.env", 20 | "!./**/*.test.ts", 21 | "!.changeset" 22 | ], 23 | "scripts": { 24 | "build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types", 25 | "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./_cjs/package.json", 26 | "build:esm": "tsc --project ./tsconfig.build.json --module es2015 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json", 27 | "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap", 28 | "clean": "rimraf _esm _cjs _types", 29 | "changeset": "changeset", 30 | "changeset:release": "bun run build && changeset publish", 31 | "changeset:version": "changeset version && bun install --lockfile-only", 32 | "format": "biome format . --write", 33 | "lint": "biome check .", 34 | "lint:fix": "bun run lint --apply" 35 | }, 36 | "peerDependencies": { 37 | "viem": "^2.28.0", 38 | "@zerodev/sdk": "^5.4.0" 39 | }, 40 | "type": "module" 41 | } 42 | -------------------------------------------------------------------------------- /packages/core/actions/public/getKernelImplementationAddress.ts: -------------------------------------------------------------------------------- 1 | import type { Address, Client } from "viem" 2 | import { getStorageAt } from "viem/actions" 3 | import { getAction, getAddress, isHex, slice, toHex } from "viem/utils" 4 | import { KERNEL_IMPLEMENTATION_SLOT } from "../../constants.js" 5 | 6 | export type GetKernelImplementationAddressParams = { 7 | address: Address 8 | } 9 | 10 | /** 11 | * Returns the address of the kernel implementation. 12 | * 13 | * @param client {@link client} that you created using viem's createPublicClient. 14 | * @param args {@link GetKernelImplementationAddressParams} address 15 | * @returns Address 16 | * 17 | * @example 18 | * import { createPublicClient } from "viem" 19 | * import { getKernelImplementationAddress } from "@zerodev/sdk/actions" 20 | * 21 | * const client = createPublicClient({ 22 | * chain: goerli, 23 | * transport: http("https://goerli.infura.io/v3/your-infura-key") 24 | * }) 25 | * 26 | * const kernelImplementationAddress = await getKernelImplementationAddress(client, { 27 | * address, 28 | * }) 29 | * 30 | * // Return 0x0000000000000000000000000000000000000000 31 | */ 32 | export const getKernelImplementationAddress = async ( 33 | client: Client, 34 | args: GetKernelImplementationAddressParams 35 | ): Promise
=> { 36 | const { address } = args 37 | 38 | const storageValue = await getAction( 39 | client, 40 | getStorageAt, 41 | "getStorageAt" 42 | )({ 43 | address, 44 | slot: KERNEL_IMPLEMENTATION_SLOT 45 | }) 46 | if (!storageValue) { 47 | throw new Error("Kernel implementation address not found") 48 | } 49 | const addressSlice = slice(storageValue, 12) 50 | const addressHex = isHex(addressSlice) ? addressSlice : toHex(addressSlice) 51 | return getAddress(addressHex) 52 | } 53 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/enforcers/allowed-params/toAllowedParamsEnforcer.ts: -------------------------------------------------------------------------------- 1 | import { type Abi, type Address, pad } from "viem" 2 | import type { Caveat } from "../../types.js" 3 | import { AllowedParamsEnforcerAddress, CallType } from "./constants.js" 4 | import type { Permission } from "./types.js" 5 | import { encodePermissionData, getPermissionFromABI } from "./utils.js" 6 | 7 | export type AllowedParamsEnforcerParams< 8 | TAbi extends Abi | readonly unknown[], 9 | TFunctionName extends string | undefined = string 10 | > = { 11 | permissions?: Permission[] 12 | enforcerAddress?: Address 13 | } 14 | 15 | export function toAllowedParamsEnforcer< 16 | TAbi extends Abi | readonly unknown[], 17 | TFunctionName extends string | undefined = string 18 | >({ 19 | permissions, 20 | enforcerAddress = AllowedParamsEnforcerAddress 21 | }: AllowedParamsEnforcerParams): Caveat { 22 | const generatedPermissionParams = permissions?.map((perm) => 23 | getPermissionFromABI({ 24 | abi: perm.abi as Abi, 25 | functionName: perm.functionName as string, 26 | args: perm.args as [] 27 | }) 28 | ) 29 | 30 | permissions = 31 | permissions?.map((perm, index) => ({ 32 | ...perm, 33 | callType: perm.callType ?? CallType.CALL, 34 | selector: 35 | perm.selector ?? 36 | generatedPermissionParams?.[index]?.selector ?? 37 | pad("0x", { size: 4 }), 38 | rules: perm.rules ?? generatedPermissionParams?.[index]?.rules ?? [] 39 | })) ?? [] 40 | 41 | const encodedPermissionData = encodePermissionData(permissions) 42 | return { 43 | enforcer: enforcerAddress, 44 | terms: encodedPermissionData, 45 | args: "0x" 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /plugins/permission/utils.ts: -------------------------------------------------------------------------------- 1 | import { coerce, gt } from "semver" 2 | import type { PermissionAccountParams, PermissionPlugin } from "./types.js" 3 | 4 | export function base64ToBytes(base64: string) { 5 | const binString = atob(base64) 6 | return Uint8Array.from(binString, (m) => m.codePointAt(0) as number) 7 | } 8 | 9 | export function bytesToBase64(bytes: Uint8Array) { 10 | const binString = Array.from(bytes, (x) => String.fromCodePoint(x)).join("") 11 | return btoa(binString) 12 | } 13 | 14 | export function isPermissionValidatorPlugin( 15 | // biome-ignore lint/suspicious/noExplicitAny: 16 | plugin: any 17 | ): plugin is PermissionPlugin { 18 | return plugin?.getPluginSerializationParams !== undefined 19 | } 20 | 21 | export const serializePermissionAccountParams = ( 22 | params: PermissionAccountParams 23 | ) => { 24 | // biome-ignore lint/suspicious/noExplicitAny: 25 | const replacer = (_: string, value: any) => { 26 | if (typeof value === "bigint") { 27 | return value.toString() 28 | } 29 | return value 30 | } 31 | 32 | const jsonString = JSON.stringify(params, replacer) 33 | const uint8Array = new TextEncoder().encode(jsonString) 34 | const base64String = bytesToBase64(uint8Array) 35 | return base64String 36 | } 37 | 38 | export const deserializePermissionAccountParams = (params: string) => { 39 | const uint8Array = base64ToBytes(params) 40 | const jsonString = new TextDecoder().decode(uint8Array) 41 | return JSON.parse(jsonString) as PermissionAccountParams 42 | } 43 | 44 | export const isKernelVersionAfter = ( 45 | kernelVersion: string, 46 | version: string 47 | ): boolean => { 48 | const coercedKernelVersion = coerce(kernelVersion) 49 | if (!coercedKernelVersion) return false 50 | return gt(coercedKernelVersion, version) 51 | } 52 | -------------------------------------------------------------------------------- /plugins/session-key/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zerodev/session-key", 3 | "version": "5.5.4", 4 | "author": "ZeroDev", 5 | "main": "./_cjs/index.js", 6 | "module": "./_esm/index.js", 7 | "types": "./_types/index.d.ts", 8 | "typings": "./_types/index.d.ts", 9 | "sideEffects": false, 10 | "license": "MIT", 11 | "files": [ 12 | "_esm", 13 | "_cjs", 14 | "_types", 15 | "./**/*.ts", 16 | "!_esm/**/*.tsbuildinfo", 17 | "!_cjs/**/*.tsbuildinfo", 18 | "!_types/**/*.tsbuildinfo", 19 | "!.env", 20 | "!./**/*.test.ts", 21 | "!.changeset" 22 | ], 23 | "scripts": { 24 | "build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types", 25 | "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./_cjs/package.json", 26 | "build:esm": "tsc --project ./tsconfig.build.json --module es2015 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json", 27 | "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap", 28 | "clean": "rimraf _esm _cjs _types", 29 | "changeset": "changeset", 30 | "changeset:release": "bun run build && changeset publish", 31 | "changeset:version": "changeset version && bun install --lockfile-only", 32 | "format": "biome format . --write", 33 | "lint": "biome check .", 34 | "lint:fix": "bun run lint --apply" 35 | }, 36 | "dependencies": { 37 | "merkletreejs": "^0.3.11" 38 | }, 39 | "peerDependencies": { 40 | "viem": "^2.28.0", 41 | "@zerodev/sdk": "^5.4.0" 42 | }, 43 | "type": "module" 44 | } 45 | -------------------------------------------------------------------------------- /packages/test/v0.7/utils/remoteSigner.ts: -------------------------------------------------------------------------------- 1 | import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator" 2 | import { type Policy, toPermissionValidator } from "@zerodev/permissions" 3 | import { toECDSASigner } from "@zerodev/permissions/signers" 4 | import { 5 | type KernelSmartAccountImplementation, 6 | createKernelAccount 7 | } from "@zerodev/sdk" 8 | import type { LocalAccount } from "viem" 9 | import type { SmartAccount } from "viem/account-abstraction" 10 | import { getEntryPoint, getPublicClient, index, kernelVersion } from "./common" 11 | 12 | export const getEcdsaKernelAccountWithRemoteSigner = async ( 13 | remoteSigner: LocalAccount 14 | ) => { 15 | const publicClient = await getPublicClient() 16 | const ecdsaValidatorPlugin = await signerToEcdsaValidator(publicClient, { 17 | entryPoint: getEntryPoint(), 18 | signer: remoteSigner, 19 | kernelVersion 20 | }) 21 | 22 | return createKernelAccount(publicClient, { 23 | entryPoint: getEntryPoint(), 24 | plugins: { 25 | sudo: ecdsaValidatorPlugin 26 | }, 27 | index, 28 | kernelVersion 29 | }) 30 | } 31 | 32 | export const getPermissionKernelAccountWithRemoteSigner = async ( 33 | remoteSigner: LocalAccount, 34 | policies: Policy[] 35 | ): Promise> => { 36 | const publicClient = await getPublicClient() 37 | const ecdsaSigner = await toECDSASigner({ signer: remoteSigner }) 38 | const permissionPlugin = await toPermissionValidator(publicClient, { 39 | entryPoint: getEntryPoint(), 40 | kernelVersion, 41 | signer: ecdsaSigner, 42 | policies 43 | }) 44 | 45 | return createKernelAccount(publicClient, { 46 | entryPoint: getEntryPoint(), 47 | plugins: { 48 | sudo: permissionPlugin 49 | }, 50 | index, 51 | kernelVersion 52 | }) 53 | } 54 | -------------------------------------------------------------------------------- /plugins/multi-chain-ecdsa/utils/ecdsaGetMultiUserOpDummySignature.ts: -------------------------------------------------------------------------------- 1 | import type { EntryPointType } from "@zerodev/sdk/types" 2 | import { MerkleTree } from "merkletreejs" 3 | import { type Hex, concatHex, encodeAbiParameters, keccak256 } from "viem" 4 | import { 5 | type EntryPointVersion, 6 | type UserOperation, 7 | getUserOperationHash 8 | } from "viem/account-abstraction" 9 | 10 | export const ecdsaGetMultiUserOpDummySignature = < 11 | entryPointVersion extends EntryPointVersion 12 | >( 13 | userOperation: UserOperation, 14 | numOfUserOps: number, 15 | entryPoint: EntryPointType, 16 | chainId: number 17 | ): Hex => { 18 | const userOpHash = getUserOperationHash({ 19 | userOperation, 20 | entryPointAddress: entryPoint.address, 21 | entryPointVersion: entryPoint.version, 22 | chainId 23 | }) 24 | 25 | const dummyUserOpHash = `0x${"a".repeat(64)}` 26 | const dummyLeaves = Array(numOfUserOps - 1).fill(dummyUserOpHash) 27 | 28 | const leaves = [userOpHash, ...dummyLeaves] 29 | 30 | const merkleTree = new MerkleTree(leaves, keccak256, { 31 | sortPairs: true 32 | }) 33 | 34 | const merkleRoot = merkleTree.getHexRoot() as Hex 35 | const merkleProof = merkleTree.getHexProof(userOpHash) as Hex[] 36 | 37 | const dummyEcdsaSig = 38 | "0xfffffffffffffffffffffffffffffff0000000000000000000000000000000007aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa1c" 39 | 40 | const encodedMerkleProof = encodeAbiParameters( 41 | [ 42 | { name: "dummyUserOpHash", type: "bytes32" }, 43 | { name: "proof", type: "bytes32[]" } 44 | ], 45 | [userOpHash, merkleProof] 46 | ) 47 | 48 | const finalDummySig = concatHex([ 49 | dummyEcdsaSig, 50 | merkleRoot, 51 | encodedMerkleProof 52 | ]) 53 | 54 | return finalDummySig 55 | } 56 | -------------------------------------------------------------------------------- /plugins/permission/signers/toECDSASigner.ts: -------------------------------------------------------------------------------- 1 | import { constants, fixSignedData, toSigner } from "@zerodev/sdk" 2 | import type { Signer } from "@zerodev/sdk/types" 3 | import type { TypedData } from "abitype" 4 | import type { TypedDataDefinition } from "viem" 5 | import { toAccount } from "viem/accounts" 6 | import { ECDSA_SIGNER_CONTRACT } from "../constants.js" 7 | import type { ModularSigner, ModularSignerParams } from "../types.js" 8 | 9 | export type ECDSAModularSignerParams = ModularSignerParams & { 10 | signer: Signer 11 | } 12 | 13 | export async function toECDSASigner({ 14 | signer, 15 | signerContractAddress = ECDSA_SIGNER_CONTRACT 16 | }: ECDSAModularSignerParams): Promise { 17 | const viemSigner = await toSigner({ signer }) 18 | const account = toAccount({ 19 | address: viemSigner.address, 20 | async signMessage({ message }) { 21 | return fixSignedData(await viemSigner.signMessage({ message })) 22 | }, 23 | async signTransaction(_, __) { 24 | throw new Error( 25 | "Smart account signer doesn't need to sign transactions" 26 | ) 27 | }, 28 | async signTypedData< 29 | const TTypedData extends TypedData | Record, 30 | TPrimaryType extends 31 | | keyof TTypedData 32 | | "EIP712Domain" = keyof TTypedData 33 | >(typedData: TypedDataDefinition) { 34 | return fixSignedData( 35 | await viemSigner.signTypedData({ 36 | ...typedData 37 | }) 38 | ) 39 | } 40 | }) 41 | return { 42 | account, 43 | signerContractAddress, 44 | getSignerData: () => { 45 | return viemSigner.address 46 | }, 47 | getDummySignature: () => constants.DUMMY_ECDSA_SIG 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/plugins/ep0_7/getValidatorPluginInstallModuleData.ts: -------------------------------------------------------------------------------- 1 | import { 2 | type RequiredBy, 3 | concatHex, 4 | encodeAbiParameters, 5 | parseAbiParameters, 6 | zeroAddress 7 | } from "viem" 8 | import { PLUGIN_TYPE } from "../../../../../constants.js" 9 | import type { 10 | KernelValidator, 11 | PluginMigrationData 12 | } from "../../../../../types/index.js" 13 | import type { 14 | Action, 15 | EntryPointType, 16 | KERNEL_V3_VERSION_TYPE, 17 | KernelValidatorHook 18 | } from "../../../../../types/kernel.js" 19 | import { satisfiesRange } from "../../../../../utils.js" 20 | import { getActionSelector } from "../../common/getActionSelector.js" 21 | 22 | export const getValidatorPluginInstallModuleData = async ({ 23 | plugin, 24 | entryPoint, 25 | kernelVersion, 26 | hook, 27 | action 28 | }: { 29 | plugin: RequiredBy, "address" | "getEnableData"> 30 | entryPoint: EntryPointType<"0.7"> 31 | kernelVersion: KERNEL_V3_VERSION_TYPE 32 | hook?: KernelValidatorHook 33 | action?: Pick 34 | }): Promise => { 35 | if (!satisfiesRange(kernelVersion, ">0.3.0")) { 36 | throw new Error("Kernel version must be greater than 0.3.0") 37 | } 38 | return { 39 | type: PLUGIN_TYPE.VALIDATOR, 40 | address: plugin.address, 41 | data: concatHex([ 42 | hook?.getIdentifier() ?? zeroAddress, 43 | encodeAbiParameters( 44 | parseAbiParameters( 45 | "bytes validatorData, bytes hookData, bytes selectorData" 46 | ), 47 | [ 48 | await plugin.getEnableData(), 49 | (await hook?.getEnableData()) ?? "0x", 50 | action?.selector ?? getActionSelector(entryPoint.version) 51 | ] 52 | ) 53 | ]) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /plugins/modularPermission/signers/toECDSASigner.ts: -------------------------------------------------------------------------------- 1 | import { constants, fixSignedData, toSigner } from "@zerodev/sdk" 2 | import type { Signer } from "@zerodev/sdk/types" 3 | import type { TypedData } from "abitype" 4 | import type { TypedDataDefinition } from "viem" 5 | import { toAccount } from "viem/accounts" 6 | import { ECDSA_SIGNER_CONTRACT } from "../constants.js" 7 | import type { ModularSigner, ModularSignerParams } from "./types.js" 8 | 9 | export type ECDSAModularSignerParams = ModularSignerParams & { 10 | signer: Signer 11 | } 12 | 13 | export async function toECDSASigner({ 14 | signer, 15 | signerContractAddress = ECDSA_SIGNER_CONTRACT 16 | }: ECDSAModularSignerParams): Promise { 17 | const viemSigner = await toSigner({ signer }) 18 | const account = toAccount({ 19 | address: viemSigner.address, 20 | async signMessage({ message }) { 21 | return fixSignedData(await viemSigner.signMessage({ message })) 22 | }, 23 | async signTransaction(_, __) { 24 | throw new Error( 25 | "Smart account signer doesn't need to sign transactions" 26 | ) 27 | }, 28 | async signTypedData< 29 | const TTypedData extends TypedData | Record, 30 | TPrimaryType extends 31 | | keyof TTypedData 32 | | "EIP712Domain" = keyof TTypedData 33 | >(typedData: TypedDataDefinition) { 34 | return fixSignedData( 35 | await viemSigner.signTypedData({ 36 | ...typedData 37 | }) 38 | ) 39 | } 40 | }) 41 | return { 42 | account, 43 | signerContractAddress, 44 | getSignerData: () => { 45 | return viemSigner.address 46 | }, 47 | getDummySignature: () => constants.DUMMY_ECDSA_SIG 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /plugins/webauthn-key/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zerodev/webauthn-key", 3 | "version": "5.5.0", 4 | "author": "ZeroDev", 5 | "main": "./_cjs/index.js", 6 | "module": "./_esm/index.js", 7 | "types": "./_types/index.d.ts", 8 | "typings": "./_types/index.d.ts", 9 | "sideEffects": false, 10 | "license": "MIT", 11 | "files": [ 12 | "_esm", 13 | "_cjs", 14 | "_types", 15 | "./**/*.ts", 16 | "!_esm/**/*.tsbuildinfo", 17 | "!_cjs/**/*.tsbuildinfo", 18 | "!_types/**/*.tsbuildinfo", 19 | "!.env", 20 | "!./**/*.test.ts", 21 | "!.changeset" 22 | ], 23 | "scripts": { 24 | "build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types", 25 | "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./_cjs/package.json", 26 | "build:esm": "tsc --project ./tsconfig.build.json --module es2020 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json", 27 | "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap", 28 | "clean": "rimraf _esm _cjs _types", 29 | "changeset": "changeset", 30 | "changeset:release": "bun run build && changeset publish", 31 | "changeset:version": "changeset version && bun install --lockfile-only", 32 | "format": "biome format . --write", 33 | "lint": "biome check .", 34 | "lint:fix": "bun run lint --apply" 35 | }, 36 | "dependencies": { 37 | "@noble/curves": "^1.3.0", 38 | "@simplewebauthn/browser": "^8.3.4", 39 | "@simplewebauthn/types": "^12.0.0" 40 | }, 41 | "peerDependencies": { 42 | "viem": "^2.28.0" 43 | }, 44 | "type": "module" 45 | } 46 | -------------------------------------------------------------------------------- /packages/core/actions/account-client/upgradeKernel.ts: -------------------------------------------------------------------------------- 1 | import type { Chain, Client, Hash, Prettify, Transport } from "viem" 2 | import { 3 | type SendUserOperationParameters, 4 | type SmartAccount, 5 | sendUserOperation 6 | } from "viem/account-abstraction" 7 | import { getAction, parseAccount } from "viem/utils" 8 | import { getUpgradeKernelCall } from "../../accounts/kernel/utils/common/getUpgradeKernelCall.js" 9 | import { AccountNotFoundError } from "../../errors/index.js" 10 | import type { KERNEL_VERSION_TYPE } from "../../types/kernel.js" 11 | 12 | export type UpgradeKernelParameters< 13 | account extends SmartAccount | undefined, 14 | accountOverride extends SmartAccount | undefined = undefined, 15 | calls extends readonly unknown[] = readonly unknown[] 16 | > = Prettify< 17 | Partial> & { 18 | kernelVersion: KERNEL_VERSION_TYPE 19 | } 20 | > 21 | 22 | export async function upgradeKernel< 23 | account extends SmartAccount | undefined, 24 | chain extends Chain | undefined, 25 | accountOverride extends SmartAccount | undefined = undefined, 26 | calls extends readonly unknown[] = readonly unknown[] 27 | >( 28 | client: Client, 29 | args: Prettify> 30 | ): Promise { 31 | const { account: account_ = client.account, kernelVersion } = args 32 | if (!account_) 33 | throw new AccountNotFoundError({ 34 | docsPath: "/docs/actions/wallet/sendTransaction" 35 | }) 36 | 37 | const account = parseAccount(account_) as SmartAccount 38 | const call = getUpgradeKernelCall(account, kernelVersion) 39 | 40 | return await getAction( 41 | client, 42 | sendUserOperation, 43 | "sendUserOperation" 44 | )({ 45 | ...args, 46 | calls: [call], 47 | account 48 | } as SendUserOperationParameters) 49 | } 50 | -------------------------------------------------------------------------------- /packages/core/actions/paymaster/estimateGasInERC20.ts: -------------------------------------------------------------------------------- 1 | import type { Address, Hex } from "viem" 2 | import { 3 | type EntryPointVersion, 4 | type UserOperation, 5 | entryPoint06Address 6 | } from "viem/account-abstraction" 7 | import type { ZeroDevPaymasterClient } from "../../clients/paymasterClient.js" 8 | import { deepHexlify } from "../../utils.js" 9 | 10 | export type EstimateGasInERC20Parameters = { 11 | userOperation: UserOperation 12 | gasTokenAddress: Hex 13 | entryPoint: Address 14 | } 15 | 16 | export type GetERC20TokenQuotesReturnType = { 17 | maxGasCostToken: string 18 | tokenDecimals: string 19 | } 20 | 21 | export type EstimateGasInERC20ReturnType = { 22 | amount: number 23 | } 24 | 25 | /** 26 | * Returns paymasterAndData & updated gas parameters required to sponsor a userOperation. 27 | */ 28 | 29 | export const estimateGasInERC20 = async < 30 | entryPointVersion extends EntryPointVersion 31 | >( 32 | client: ZeroDevPaymasterClient, 33 | args: EstimateGasInERC20Parameters 34 | ): Promise => { 35 | const response = await client.request({ 36 | method: "stackup_getERC20TokenQuotes", 37 | params: [ 38 | { 39 | chainId: client.chain?.id as number, 40 | userOp: { 41 | ...deepHexlify(args.userOperation), 42 | initCode: args.userOperation.initCode || "0x" 43 | }, 44 | tokenAddress: args.gasTokenAddress, 45 | entryPointAddress: args.entryPoint ?? entryPoint06Address 46 | } 47 | ] 48 | }) 49 | 50 | const result: GetERC20TokenQuotesReturnType = { 51 | maxGasCostToken: response.maxGasCostToken, 52 | tokenDecimals: response.tokenDecimals 53 | } 54 | 55 | const amount = 56 | Number(result.maxGasCostToken) / 10 ** Number(result.tokenDecimals) 57 | 58 | return { amount } 59 | } 60 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/common/accountMetadata.ts: -------------------------------------------------------------------------------- 1 | import { 2 | type Address, 3 | type Client, 4 | decodeFunctionResult, 5 | encodeFunctionData, 6 | publicActions 7 | } from "viem" 8 | import { KERNEL_NAME } from "../../../../constants.js" 9 | import type { KERNEL_VERSION_TYPE } from "../../../../types/kernel.js" 10 | import { EIP1271Abi } from "../../abi/EIP1271Abi.js" 11 | 12 | export type AccountMetadata = { 13 | name: string 14 | version: string 15 | chainId: bigint 16 | } 17 | export const accountMetadata = async ( 18 | client: Client, 19 | accountAddress: Address, 20 | kernelVersion: KERNEL_VERSION_TYPE, 21 | chainId?: number 22 | ): Promise => { 23 | try { 24 | const domain = await client.request({ 25 | method: "eth_call", 26 | params: [ 27 | { 28 | to: accountAddress, 29 | data: encodeFunctionData({ 30 | abi: EIP1271Abi, 31 | functionName: "eip712Domain" 32 | }) 33 | }, 34 | "latest" 35 | ] 36 | }) 37 | if (domain !== "0x") { 38 | const decoded = decodeFunctionResult({ 39 | abi: [...EIP1271Abi], 40 | functionName: "eip712Domain", 41 | data: domain 42 | }) 43 | return { 44 | name: decoded[1], 45 | version: decoded[2], 46 | chainId: decoded[3] 47 | } 48 | } 49 | } catch (error) {} 50 | return { 51 | name: KERNEL_NAME, 52 | version: kernelVersion === "0.3.0" ? "0.3.0-beta" : kernelVersion, 53 | chainId: BigInt( 54 | chainId ?? 55 | (client.chain 56 | ? client.chain.id 57 | : await client.extend(publicActions).getChainId()) 58 | ) 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /plugins/social/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zerodev/social-validator", 3 | "version": "5.2.3", 4 | "author": "ZeroDev", 5 | "main": "./_cjs/index.js", 6 | "module": "./_esm/index.js", 7 | "types": "./_types/index.d.ts", 8 | "typings": "./_types/index.d.ts", 9 | "sideEffects": false, 10 | "license": "MIT", 11 | "files": [ 12 | "_esm", 13 | "_cjs", 14 | "_types", 15 | "./**/*.ts", 16 | "!_esm/**/*.tsbuildinfo", 17 | "!_cjs/**/*.tsbuildinfo", 18 | "!_types/**/*.tsbuildinfo", 19 | "!.env", 20 | "!./**/*.test.ts", 21 | "!.changeset" 22 | ], 23 | "scripts": { 24 | "build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types", 25 | "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./_cjs/package.json", 26 | "build:esm": "tsc --project ./tsconfig.build.json --module es2015 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json", 27 | "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap", 28 | "clean": "rimraf _esm _cjs _types", 29 | "changeset": "changeset", 30 | "changeset:release": "bun run build && changeset publish", 31 | "changeset:version": "changeset version && bun install --lockfile-only", 32 | "format": "biome format . --write", 33 | "lint": "biome check .", 34 | "lint:fix": "bun run lint --apply" 35 | }, 36 | "peerDependencies": { 37 | "@zerodev/ecdsa-validator": "^5.4.0", 38 | "@zerodev/sdk": "^5.4.0", 39 | "viem": "^2.28.0" 40 | }, 41 | "dependencies": { 42 | "@magic-ext/oauth": "^22.0.3", 43 | "magic-sdk": "^28.0.3" 44 | }, 45 | "type": "module" 46 | } 47 | -------------------------------------------------------------------------------- /plugins/passkey/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zerodev/passkey-validator", 3 | "version": "5.6.0", 4 | "author": "ZeroDev", 5 | "main": "./_cjs/index.js", 6 | "module": "./_esm/index.js", 7 | "types": "./_types/index.d.ts", 8 | "typings": "./_types/index.d.ts", 9 | "sideEffects": false, 10 | "license": "MIT", 11 | "files": [ 12 | "_esm", 13 | "_cjs", 14 | "_types", 15 | "./**/*.ts", 16 | "!_esm/**/*.tsbuildinfo", 17 | "!_cjs/**/*.tsbuildinfo", 18 | "!_types/**/*.tsbuildinfo", 19 | "!.env", 20 | "!./**/*.test.ts", 21 | "!.changeset" 22 | ], 23 | "scripts": { 24 | "build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types", 25 | "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./_cjs/package.json", 26 | "build:esm": "tsc --project ./tsconfig.build.json --module es2020 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json", 27 | "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap", 28 | "clean": "rimraf _esm _cjs _types", 29 | "changeset": "changeset", 30 | "changeset:release": "bun run build && changeset publish", 31 | "changeset:version": "changeset version && bun install --lockfile-only", 32 | "format": "biome format . --write", 33 | "lint": "biome check .", 34 | "lint:fix": "bun run lint --apply" 35 | }, 36 | "dependencies": { 37 | "@noble/curves": "^1.3.0", 38 | "@simplewebauthn/browser": "^8.3.4" 39 | }, 40 | "peerDependencies": { 41 | "viem": "^2.28.0", 42 | "@zerodev/sdk": "^5.4.0", 43 | "@zerodev/webauthn-key": "^5.4.2" 44 | }, 45 | "type": "module" 46 | } 47 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/actions/installDMAsExecutor.ts: -------------------------------------------------------------------------------- 1 | import { AccountNotFoundError } from "@zerodev/sdk" 2 | import { sendTransaction } from "@zerodev/sdk/actions" 3 | import type { 4 | Chain, 5 | Client, 6 | Hash, 7 | Prettify, 8 | SendTransactionParameters, 9 | Transport 10 | } from "viem" 11 | import type { 12 | SendUserOperationParameters, 13 | SmartAccount 14 | } from "viem/account-abstraction" 15 | import { getAction, parseAccount } from "viem/utils" 16 | import type { SessionAccountImplementation } from "../account/createSessionAccount.js" 17 | import { getInstallDMAsExecutorCallData } from "../utils/delegationManager.js" 18 | 19 | export type SendInstallDMAsExecutorUserOperationParameters< 20 | account extends SmartAccount | undefined = SmartAccount | undefined, 21 | chain extends Chain | undefined = Chain | undefined, 22 | chainOverride extends Chain | undefined = Chain | undefined 23 | > = Prettify>> 24 | 25 | export async function installDMAsExecutor< 26 | account extends SmartAccount | undefined, 27 | chain extends Chain | undefined 28 | >( 29 | client: Client, 30 | args: SendInstallDMAsExecutorUserOperationParameters 31 | ): Promise { 32 | const { account: account_ = client.account } = args 33 | 34 | if (!account_) { 35 | throw new AccountNotFoundError() 36 | } 37 | 38 | const account = parseAccount( 39 | account_ 40 | ) as SmartAccount 41 | 42 | return await getAction( 43 | client, 44 | sendTransaction, 45 | "sendTransaction" 46 | )({ 47 | ...args, 48 | calls: [ 49 | { 50 | to: account.address, 51 | data: getInstallDMAsExecutorCallData(), 52 | value: 0n 53 | } 54 | ] 55 | } as SendTransactionParameters | SendUserOperationParameters) 56 | } 57 | -------------------------------------------------------------------------------- /plugins/weighted-r1-k1/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zerodev/weighted-validator", 3 | "version": "5.5.1", 4 | "author": "ZeroDev", 5 | "main": "./_cjs/index.js", 6 | "module": "./_esm/index.js", 7 | "types": "./_types/index.d.ts", 8 | "typings": "./_types/index.d.ts", 9 | "sideEffects": false, 10 | "license": "MIT", 11 | "files": [ 12 | "_esm", 13 | "_cjs", 14 | "_types", 15 | "./**/*.ts", 16 | "!_esm/**/*.tsbuildinfo", 17 | "!_cjs/**/*.tsbuildinfo", 18 | "!_types/**/*.tsbuildinfo", 19 | "!.env", 20 | "!./**/*.test.ts", 21 | "!.changeset" 22 | ], 23 | "scripts": { 24 | "build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types", 25 | "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./_cjs/package.json", 26 | "build:esm": "tsc --project ./tsconfig.build.json --module es2020 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json", 27 | "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap", 28 | "clean": "rimraf _esm _cjs _types", 29 | "changeset": "changeset", 30 | "changeset:release": "bun run build && changeset publish", 31 | "changeset:version": "changeset version && bun install --lockfile-only", 32 | "format": "biome format . --write", 33 | "lint": "biome check .", 34 | "lint:fix": "bun run lint --apply" 35 | }, 36 | "dependencies": { 37 | "@noble/curves": "^1.3.0", 38 | "@simplewebauthn/browser": "^8.3.4" 39 | }, 40 | "peerDependencies": { 41 | "viem": "^2.28.0", 42 | "@zerodev/sdk": "^5.4.0", 43 | "@zerodev/webauthn-key": "^5.4.2" 44 | }, 45 | "type": "module" 46 | } 47 | -------------------------------------------------------------------------------- /packages/core/actions/account-client/signUserOperation.ts: -------------------------------------------------------------------------------- 1 | import type { Chain, Client, Transport } from "viem" 2 | import { 3 | type PrepareUserOperationParameters, 4 | type PrepareUserOperationReturnType, 5 | type SmartAccount, 6 | type UserOperation, 7 | prepareUserOperation 8 | } from "viem/account-abstraction" 9 | import { getAction, parseAccount } from "viem/utils" 10 | import { AccountNotFoundError } from "../../errors/index.js" 11 | 12 | export type SignUserOperationParameters< 13 | account extends SmartAccount | undefined = SmartAccount | undefined, 14 | accountOverride extends SmartAccount | undefined = SmartAccount | undefined, 15 | calls extends readonly unknown[] = readonly unknown[] 16 | > = PrepareUserOperationParameters 17 | 18 | export type SignUserOperationReturnType = PrepareUserOperationReturnType 19 | 20 | export async function signUserOperation< 21 | account extends SmartAccount | undefined = SmartAccount | undefined, 22 | chain extends Chain | undefined = Chain | undefined, 23 | accountOverride extends SmartAccount | undefined = undefined, 24 | calls extends readonly unknown[] = readonly unknown[] 25 | >( 26 | client: Client, 27 | args: SignUserOperationParameters 28 | ): Promise { 29 | const { account: account_ = client.account } = args 30 | if (!account_) 31 | throw new AccountNotFoundError({ 32 | docsPath: "/docs/actions/wallet/sendTransaction" 33 | }) 34 | 35 | const account = parseAccount(account_) as SmartAccount 36 | 37 | const userOperation = await getAction( 38 | client, 39 | prepareUserOperation, 40 | "prepareUserOperation" 41 | )({ ...args, account } as PrepareUserOperationParameters) 42 | 43 | userOperation.signature = await account.signUserOperation( 44 | userOperation as UserOperation 45 | ) 46 | 47 | return userOperation 48 | } 49 | -------------------------------------------------------------------------------- /packages/core/actions/public/isPluginInstalled.ts: -------------------------------------------------------------------------------- 1 | import type { Address, Client, Hex } from "viem" 2 | import { readContract } from "viem/actions" 3 | import { getAction } from "viem/utils" 4 | import { KernelModuleIsModuleInstalledAbi } from "../../accounts/kernel/abi/kernel_v_3_0_0/KernelModuleAbi.js" 5 | import type { PLUGIN_TYPE } from "../../constants.js" 6 | 7 | export type IsPluginInstalledParams = { 8 | address: Address 9 | plugin: { 10 | type: (typeof PLUGIN_TYPE)[keyof typeof PLUGIN_TYPE] 11 | address: Address 12 | data?: Hex 13 | } 14 | } 15 | 16 | /** 17 | * Returns whether a plugin is installed on the account. 18 | * 19 | * @param client - Client to use 20 | * @param args - {@link IsPluginInstalledParams} address and plugin details 21 | * @returns boolean indicating if plugin is installed 22 | * 23 | * @example 24 | * import { createPublicClient } from "viem" 25 | * import { isPluginInstalled } from "@zerodev/sdk" 26 | * 27 | * const client = createPublicClient({ 28 | * chain: mainnet, 29 | * transport: http() 30 | * }) 31 | * 32 | * const isInstalled = await isPluginInstalled(client, { 33 | * address: accountAddress, 34 | * plugin: { 35 | * type: PLUGIN_TYPE.VALIDATOR, 36 | * address: validatorAddress, 37 | * data: "0x" 38 | * } 39 | * }) 40 | */ 41 | export const isPluginInstalled = async ( 42 | client: Client, 43 | args: IsPluginInstalledParams 44 | ): Promise => { 45 | const { address, plugin } = args 46 | const { type, address: pluginAddress, data = "0x" } = plugin 47 | 48 | try { 49 | return await getAction( 50 | client, 51 | readContract, 52 | "readContract" 53 | )({ 54 | address, 55 | abi: KernelModuleIsModuleInstalledAbi, 56 | functionName: "isModuleInstalled", 57 | args: [BigInt(type), pluginAddress, data] 58 | }) 59 | } catch (error) { 60 | return false 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /plugins/ecdsa/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @zerodev/ecdsa-validator 2 | 3 | ## 5.4.9 4 | 5 | ### Patch Changes 6 | 7 | - feat: add eip7702Auth param in `create7702KernelAccount` 8 | 9 | ## 5.4.8 10 | 11 | ### Patch Changes 12 | 13 | - client action extends issue fixed 14 | 15 | ## 5.4.7 16 | 17 | ### Patch Changes 18 | 19 | - fixed import issue 20 | 21 | ## 5.4.6 22 | 23 | ### Patch Changes 24 | 25 | - updated to use latest viem 2.28.0 and support for 7702 26 | 27 | ## 5.4.5 28 | 29 | ### Patch Changes 30 | 31 | - chore: update viem version 32 | 33 | ## 5.4.4 34 | 35 | ### Patch Changes 36 | 37 | - chore: change the semantic versioning to use the latest validator for Kernel v3.1 and above 38 | 39 | ## 5.4.3 40 | 41 | ### Patch Changes 42 | 43 | - Added createEcdsaKernelMigrationAccount 44 | 45 | ## 5.4.2 46 | 47 | ### Patch Changes 48 | 49 | - feat: remove "type" field 50 | 51 | ## 5.4.1 52 | 53 | ### Patch Changes 54 | 55 | - Integrated KernelV3.2 support 56 | 57 | ## 5.4.0 58 | 59 | ### Minor Changes 60 | 61 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 62 | 63 | ## 5.4.0-beta.0 64 | 65 | ### Minor Changes 66 | 67 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 68 | 69 | ## 5.3.3 70 | 71 | ### Patch Changes 72 | 73 | - Patch for latest permissionless 0.1.45 support 74 | 75 | ## 5.3.2 76 | 77 | ### Patch Changes 78 | 79 | - Pinned permissionless version >=0.1.18 <=0.1.29 80 | 81 | ## 5.3.1 82 | 83 | ### Patch Changes 84 | 85 | - Update viem to 2.16.3 86 | 87 | ## 5.3.0 88 | 89 | ### Minor Changes 90 | 91 | - Kernel v3.1 released. And kernel versioning update. Added kernelVersion param in the interface. 92 | 93 | ## 5.3.0-alpha-0 94 | 95 | ### Minor Changes 96 | 97 | - Integrated Kernel v3.1 and added kernelVersion param in account and plugins interface 98 | 99 | ## 5.2.3 100 | 101 | ### Patch Changes 102 | 103 | - Update permissionless@0.1.18 104 | -------------------------------------------------------------------------------- /plugins/react-native-passkeys-utils/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zerodev/react-native-passkeys-utils", 3 | "version": "5.4.4", 4 | "author": "ZeroDev", 5 | "main": "./_cjs/index.js", 6 | "module": "./_esm/index.js", 7 | "types": "./_types/index.d.ts", 8 | "typings": "./_types/index.d.ts", 9 | "sideEffects": false, 10 | "license": "MIT", 11 | "files": [ 12 | "_esm", 13 | "_cjs", 14 | "_types", 15 | "./**/*.ts", 16 | "!_esm/**/*.tsbuildinfo", 17 | "!_cjs/**/*.tsbuildinfo", 18 | "!_types/**/*.tsbuildinfo", 19 | "!.env", 20 | "!./**/*.test.ts", 21 | "!.changeset" 22 | ], 23 | "scripts": { 24 | "build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types", 25 | "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./_cjs/package.json", 26 | "build:esm": "tsc --project ./tsconfig.build.json --module es2020 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json", 27 | "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap", 28 | "clean": "rimraf _esm _cjs _types", 29 | "changeset": "changeset", 30 | "changeset:release": "bun run build && changeset publish", 31 | "changeset:version": "changeset version && bun install --lockfile-only", 32 | "format": "biome format . --write", 33 | "lint": "biome check .", 34 | "lint:fix": "bun run lint --apply" 35 | }, 36 | "dependencies": { 37 | "@noble/curves": "^1.3.0", 38 | "@simplewebauthn/types": "^12.0.0", 39 | "asn1js": "^3.0.5", 40 | "react-native-passkeys": "^0.3.1" 41 | }, 42 | "peerDependencies": { 43 | "viem": "^2.28.0", 44 | "@zerodev/webauthn-key": "^5.4.2" 45 | }, 46 | "type": "module" 47 | } 48 | -------------------------------------------------------------------------------- /plugins/multi-chain-ecdsa/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zerodev/multi-chain-ecdsa-validator", 3 | "version": "5.4.5", 4 | "author": "ZeroDev", 5 | "main": "./_cjs/index.js", 6 | "module": "./_esm/index.js", 7 | "types": "./_types/index.d.ts", 8 | "typings": "./_types/index.d.ts", 9 | "sideEffects": false, 10 | "license": "MIT", 11 | "files": [ 12 | "_esm", 13 | "_cjs", 14 | "_types", 15 | "./**/*.ts", 16 | "!_esm/**/*.tsbuildinfo", 17 | "!_cjs/**/*.tsbuildinfo", 18 | "!_types/**/*.tsbuildinfo", 19 | "!.env", 20 | "!./**/*.test.ts", 21 | "!.changeset" 22 | ], 23 | "scripts": { 24 | "build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types", 25 | "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./_cjs/package.json", 26 | "build:esm": "tsc --project ./tsconfig.build.json --module es2020 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json", 27 | "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap", 28 | "clean": "rimraf _esm _cjs _types", 29 | "changeset": "changeset", 30 | "changeset:release": "bun run build && changeset publish", 31 | "changeset:version": "changeset version && bun install --lockfile-only", 32 | "format": "biome format . --write", 33 | "lint": "biome check .", 34 | "lint:fix": "bun run lint --apply" 35 | }, 36 | "peerDependencies": { 37 | "viem": "^2.28.0", 38 | "@zerodev/sdk": "^5.4.0", 39 | "@zerodev/webauthn-key": "^5.4.0" 40 | }, 41 | "dependencies": { 42 | "@simplewebauthn/browser": "^9.0.1", 43 | "@simplewebauthn/typescript-types": "^8.3.4", 44 | "merkletreejs": "^0.3.11" 45 | }, 46 | "type": "module" 47 | } 48 | -------------------------------------------------------------------------------- /plugins/multi-chain-weighted-validator/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zerodev/multi-chain-weighted-validator", 3 | "version": "5.4.5", 4 | "author": "ZeroDev", 5 | "main": "./_cjs/index.js", 6 | "module": "./_esm/index.js", 7 | "types": "./_types/index.d.ts", 8 | "typings": "./_types/index.d.ts", 9 | "sideEffects": false, 10 | "license": "MIT", 11 | "files": [ 12 | "_esm", 13 | "_cjs", 14 | "_types", 15 | "./**/*.ts", 16 | "!_esm/**/*.tsbuildinfo", 17 | "!_cjs/**/*.tsbuildinfo", 18 | "!_types/**/*.tsbuildinfo", 19 | "!.env", 20 | "!./**/*.test.ts", 21 | "!.changeset" 22 | ], 23 | "scripts": { 24 | "build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types", 25 | "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./_cjs/package.json", 26 | "build:esm": "tsc --project ./tsconfig.build.json --module es2020 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json", 27 | "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap", 28 | "clean": "rimraf _esm _cjs _types", 29 | "changeset": "changeset", 30 | "changeset:release": "bun run build && changeset publish", 31 | "changeset:version": "changeset version && bun install --lockfile-only", 32 | "format": "biome format . --write", 33 | "lint": "biome check .", 34 | "lint:fix": "bun run lint --apply" 35 | }, 36 | "dependencies": { 37 | "@noble/curves": "^1.3.0", 38 | "@simplewebauthn/browser": "^8.3.4", 39 | "merkletreejs": "^0.3.11" 40 | }, 41 | "peerDependencies": { 42 | "viem": "^2.28.0", 43 | "@zerodev/sdk": "^5.4.0", 44 | "@zerodev/webauthn-key": "^5.4.2" 45 | }, 46 | "type": "module" 47 | } 48 | -------------------------------------------------------------------------------- /packages/test/abis/SimpleAccountFactory.ts: -------------------------------------------------------------------------------- 1 | export const SimpleAccountFactoryAbi = [ 2 | { 3 | inputs: [ 4 | { 5 | internalType: "contract IEntryPoint", 6 | name: "_entryPoint", 7 | type: "address" 8 | } 9 | ], 10 | stateMutability: "nonpayable", 11 | type: "constructor" 12 | }, 13 | { 14 | inputs: [], 15 | name: "accountImplementation", 16 | outputs: [ 17 | { 18 | internalType: "contract SimpleAccount", 19 | name: "", 20 | type: "address" 21 | } 22 | ], 23 | stateMutability: "view", 24 | type: "function" 25 | }, 26 | { 27 | inputs: [ 28 | { 29 | internalType: "address", 30 | name: "owner", 31 | type: "address" 32 | }, 33 | { 34 | internalType: "uint256", 35 | name: "salt", 36 | type: "uint256" 37 | } 38 | ], 39 | name: "createAccount", 40 | outputs: [ 41 | { 42 | internalType: "contract SimpleAccount", 43 | name: "ret", 44 | type: "address" 45 | } 46 | ], 47 | stateMutability: "nonpayable", 48 | type: "function" 49 | }, 50 | { 51 | inputs: [ 52 | { 53 | internalType: "address", 54 | name: "owner", 55 | type: "address" 56 | }, 57 | { 58 | internalType: "uint256", 59 | name: "salt", 60 | type: "uint256" 61 | } 62 | ], 63 | name: "getAddress", 64 | outputs: [ 65 | { 66 | internalType: "address", 67 | name: "", 68 | type: "address" 69 | } 70 | ], 71 | stateMutability: "view", 72 | type: "function" 73 | } 74 | ] as const 75 | -------------------------------------------------------------------------------- /plugins/multi-chain-web-authn/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@zerodev/multi-chain-web-authn-validator", 3 | "version": "5.5.0", 4 | "author": "ZeroDev", 5 | "main": "./_cjs/index.js", 6 | "module": "./_esm/index.js", 7 | "types": "./_types/index.d.ts", 8 | "typings": "./_types/index.d.ts", 9 | "sideEffects": false, 10 | "license": "MIT", 11 | "files": [ 12 | "_esm", 13 | "_cjs", 14 | "_types", 15 | "./**/*.ts", 16 | "!_esm/**/*.tsbuildinfo", 17 | "!_cjs/**/*.tsbuildinfo", 18 | "!_types/**/*.tsbuildinfo", 19 | "!.env", 20 | "!./**/*.test.ts", 21 | "!.changeset" 22 | ], 23 | "scripts": { 24 | "build": "bun run clean && bun run build:cjs && bun run build:esm && bun run build:types", 25 | "build:cjs": "tsc --project ./tsconfig.build.json --module commonjs --outDir ./_cjs --removeComments --verbatimModuleSyntax false && printf '{\"type\":\"commonjs\"}' > ./_cjs/package.json", 26 | "build:esm": "tsc --project ./tsconfig.build.json --module es2020 --outDir ./_esm && printf '{\"type\": \"module\",\"sideEffects\":false}' > ./_esm/package.json", 27 | "build:types": "tsc --project ./tsconfig.build.json --module esnext --declarationDir ./_types --emitDeclarationOnly --declaration --declarationMap", 28 | "clean": "rimraf _esm _cjs _types", 29 | "changeset": "changeset", 30 | "changeset:release": "bun run build && changeset publish", 31 | "changeset:version": "changeset version && bun install --lockfile-only", 32 | "format": "biome format . --write", 33 | "lint": "biome check .", 34 | "lint:fix": "bun run lint --apply" 35 | }, 36 | "peerDependencies": { 37 | "viem": "^2.28.0", 38 | "@zerodev/sdk": "^5.4.0", 39 | "@zerodev/webauthn-key": "^5.4.2" 40 | }, 41 | "dependencies": { 42 | "@simplewebauthn/browser": "^9.0.1", 43 | "@simplewebauthn/typescript-types": "^8.3.4", 44 | "merkletreejs": "^0.3.11" 45 | }, 46 | "type": "module" 47 | } 48 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/plugins/ep0_6/getPluginsEnableTypedData.ts: -------------------------------------------------------------------------------- 1 | import { 2 | type Address, 3 | type CustomSource, 4 | concatHex, 5 | hexToBigInt, 6 | pad, 7 | toHex 8 | } from "viem" 9 | import type { 10 | Action, 11 | KernelValidator, 12 | PluginValidityData 13 | } from "../../../../../types/index.js" 14 | 15 | export type Kernel2_0_plugins = { 16 | validator: KernelValidator 17 | action: Action 18 | } 19 | export const getPluginsEnableTypedData = async ({ 20 | accountAddress, 21 | chainId, 22 | kernelVersion, 23 | action, 24 | validator, 25 | validUntil, 26 | validAfter 27 | }: { 28 | accountAddress: Address 29 | chainId: number 30 | kernelVersion: string 31 | } & Kernel2_0_plugins & 32 | PluginValidityData): Promise< 33 | Parameters[0] 34 | > => { 35 | return { 36 | domain: { 37 | name: "Kernel", 38 | version: kernelVersion, 39 | chainId, 40 | verifyingContract: accountAddress 41 | }, 42 | types: { 43 | ValidatorApproved: [ 44 | { name: "sig", type: "bytes4" }, 45 | { name: "validatorData", type: "uint256" }, 46 | { name: "executor", type: "address" }, 47 | { name: "enableData", type: "bytes" } 48 | ] 49 | }, 50 | message: { 51 | sig: action.selector, 52 | validatorData: hexToBigInt( 53 | concatHex([ 54 | pad(toHex(validUntil ?? 0), { 55 | size: 6 56 | }), 57 | pad(toHex(validAfter ?? 0), { 58 | size: 6 59 | }), 60 | validator.address 61 | ]), 62 | { size: 32 } 63 | ), 64 | executor: action.address as Address, 65 | enableData: await validator.getEnableData(accountAddress) 66 | }, 67 | primaryType: "ValidatorApproved" 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /packages/core/accounts/kernel/utils/account/ep0_7/encodeCallData.ts: -------------------------------------------------------------------------------- 1 | import type { EntryPointVersion } from "viem/account-abstraction" 2 | import { EXEC_TYPE } from "../../../../../constants.js" 3 | import type { CallType } from "../../../../../types/kernel.js" 4 | import type { KernelSmartAccountImplementation } from "../../../createKernelAccount.js" 5 | import { encodeExecuteBatchCall } from "../../ep0_7/encodeExecuteBatchCall.js" 6 | import { encodeExecuteDelegateCall } from "../../ep0_7/encodeExecuteDelegateCall.js" 7 | import { encodeExecuteSingleCall } from "../../ep0_7/encodeExecuteSingleCall.js" 8 | 9 | export const encodeCallData = async < 10 | entryPointVersion extends EntryPointVersion = EntryPointVersion 11 | >( 12 | calls: Parameters< 13 | KernelSmartAccountImplementation["encodeCalls"] 14 | >[0], 15 | callType?: CallType | undefined, 16 | includeHooks?: boolean, 17 | execType: EXEC_TYPE = EXEC_TYPE.DEFAULT 18 | ) => { 19 | if (calls.length > 1) { 20 | if (callType === "delegatecall") { 21 | throw new Error("Cannot batch delegatecall") 22 | } 23 | // Encode a batched call 24 | return encodeExecuteBatchCall( 25 | calls, 26 | { 27 | execType 28 | }, 29 | includeHooks 30 | ) 31 | } 32 | 33 | const call = calls.length === 0 ? undefined : calls[0] 34 | 35 | if (!call) { 36 | throw new Error("No calls to encode") 37 | } 38 | 39 | // Default to `call` 40 | if (!callType || callType === "call") { 41 | return encodeExecuteSingleCall( 42 | call, 43 | { 44 | execType 45 | }, 46 | includeHooks 47 | ) 48 | } 49 | 50 | if (callType === "delegatecall") { 51 | return encodeExecuteDelegateCall( 52 | { to: call.to, data: call.data }, 53 | { 54 | execType 55 | }, 56 | includeHooks 57 | ) 58 | } 59 | 60 | throw new Error("Invalid call type") 61 | } 62 | -------------------------------------------------------------------------------- /plugins/weighted-r1-k1/index.ts: -------------------------------------------------------------------------------- 1 | import type { KernelValidator } from "@zerodev/sdk/types" 2 | import { 3 | type ApprovePluginParameters, 4 | approvePlugin 5 | } from "./actions/approvePlugin.js" 6 | import { 7 | type ApproveUserOperationParameters, 8 | approveUserOperation 9 | } from "./actions/approveUserOperation.js" 10 | import { 11 | type SendUserOperationWithSignaturesParameters, 12 | sendUserOperationWithSignatures 13 | } from "./actions/sendUserOperationWithSignatures.js" 14 | import { 15 | type WeightedKernelAccountClientActions, 16 | weightedKernelAccountClientActions 17 | } from "./clients/decorators/weightedKernelAccountClient.js" 18 | import { 19 | type WeightedKernelAccountClient, 20 | createWeightedKernelAccountClient 21 | } from "./clients/weightedKernelAccountClient.js" 22 | import { 23 | type ECDSASignerParams, 24 | toECDSASigner 25 | } from "./signers/toECDSASigner.js" 26 | import { 27 | type WebAuthnModularSignerParams, 28 | toWebAuthnSigner 29 | } from "./signers/toWebAuthnSigner.js" 30 | import { 31 | type WeightedSigner, 32 | type WeightedValidatorConfig, 33 | WeightedValidatorContractVersion, 34 | createWeightedValidator, 35 | getValidatorAddress 36 | } from "./toWeightedValidatorPlugin.js" 37 | 38 | export { 39 | createWeightedValidator, 40 | type WeightedValidatorConfig, 41 | type WeightedSigner, 42 | getValidatorAddress, 43 | type KernelValidator, 44 | toECDSASigner, 45 | type ECDSASignerParams, 46 | type WebAuthnModularSignerParams, 47 | toWebAuthnSigner, 48 | type ApprovePluginParameters, 49 | approvePlugin, 50 | type ApproveUserOperationParameters, 51 | approveUserOperation, 52 | type SendUserOperationWithSignaturesParameters, 53 | sendUserOperationWithSignatures, 54 | type WeightedKernelAccountClient, 55 | createWeightedKernelAccountClient, 56 | type WeightedKernelAccountClientActions, 57 | weightedKernelAccountClientActions, 58 | WeightedValidatorContractVersion 59 | } 60 | export * from "./constants.js" 61 | export * from "./utils.js" 62 | -------------------------------------------------------------------------------- /plugins/multi-chain-weighted-validator/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # @zerodev/multi-chain-weighted-validator 2 | 3 | ## 5.4.5 4 | 5 | ### Patch Changes 6 | 7 | - updated to use latest viem 2.28.0 and support for 7702 8 | 9 | ## 5.4.4 10 | 11 | ### Patch Changes 12 | 13 | - chore: update viem version 14 | 15 | ## 5.4.3 16 | 17 | ### Patch Changes 18 | 19 | - feat: add custom signing method support 20 | 21 | ## 5.4.2 22 | 23 | ### Patch Changes 24 | 25 | - feat: remove "type" field 26 | 27 | ## 5.4.1 28 | 29 | ### Patch Changes 30 | 31 | - Use .js imports to fix build issues in all environments 32 | 33 | ## 5.4.0 34 | 35 | ### Minor Changes 36 | 37 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 38 | 39 | ## 5.4.0-beta.0 40 | 41 | ### Minor Changes 42 | 43 | - Migrate to using `viem@2.18.x` with native AA modules instead of `permissionless` 44 | 45 | ## 5.3.1 46 | 47 | ### Patch Changes 48 | 49 | - Patch for latest permissionless 0.1.45 support 50 | 51 | ## 5.3.0 52 | 53 | ### Patch Changes 54 | 55 | - Pinned permissionless version >=0.1.18 <=0.1.29 56 | 57 | ## 5.3.0-alpha-7 58 | 59 | ### Patch Changes 60 | 61 | - Update contract address 62 | 63 | ## 5.3.0-alpha-6 64 | 65 | ### Patch Changes 66 | 67 | - Rollback contract version to 5.3.0-alpha-4 68 | 69 | ## 5.3.0-alpha-5 70 | 71 | ### Patch Changes 72 | 73 | - Added support for `renew` signers config. 74 | 75 | ## 5.3.0-alpha-4 76 | 77 | ### Patch Changes 78 | 79 | - Simplified the process by making the `getChainId` call the only required action. 80 | 81 | ## 5.3.0-alpha-3 82 | 83 | ### Patch Changes 84 | 85 | - Moved calling fetch chain id to signMessage 86 | 87 | ## 5.3.0-alpha-2 88 | 89 | ### Patch Changes 90 | 91 | - Separated webauthn signer and webauthn key module 92 | 93 | ## 5.3.0-alpha-1 94 | 95 | ### Patch Changes 96 | 97 | - Update viem to 2.16.3 98 | 99 | ## 5.3.0-alpha-0 100 | 101 | ### Minor Changes 102 | 103 | - Kernel v3.1 released. And kernel versioning update. Added kernelVersion param in the interface. 104 | -------------------------------------------------------------------------------- /packages/test/utils_0_6/modularPermissionUtils.ts: -------------------------------------------------------------------------------- 1 | import { signerToEcdsaValidator } from "@zerodev/ecdsa-validator" 2 | import { createPermissionValidator } from "@zerodev/modular-permission" 3 | import type { Policy } from "@zerodev/modular-permission/policies" 4 | import { toECDSASigner } from "@zerodev/modular-permission/signers" 5 | import type { KernelSmartAccountImplementation } from "@zerodev/sdk" 6 | import { createKernelAccount } from "@zerodev/sdk" 7 | import type { Hex } from "viem" 8 | import type { SmartAccount } from "viem/account-abstraction" 9 | import { generatePrivateKey, privateKeyToAccount } from "viem/accounts" 10 | import { getEntryPoint, getPublicClient, index, kernelVersion } from "./common" 11 | 12 | export const getSignerToModularPermissionKernelAccount = async ( 13 | policies: Policy[] 14 | ): Promise>> => { 15 | const privateKey = process.env.TEST_PRIVATE_KEY as Hex 16 | if (!privateKey) { 17 | throw new Error("TEST_PRIVATE_KEY environment variable not set") 18 | } 19 | 20 | const publicClient = await getPublicClient() 21 | const signer = privateKeyToAccount(privateKey) 22 | const sessionPrivateKey = generatePrivateKey() 23 | const sessionKey = privateKeyToAccount(sessionPrivateKey) 24 | const ecdsaValidatorPlugin = await signerToEcdsaValidator(publicClient, { 25 | entryPoint: getEntryPoint(), 26 | signer, 27 | kernelVersion 28 | }) 29 | 30 | const ecdsaModularSigner = toECDSASigner({ signer: sessionKey }) 31 | const modularPermissionPlugin = await createPermissionValidator( 32 | publicClient, 33 | { 34 | entryPoint: getEntryPoint(), 35 | kernelVersion, 36 | signer: ecdsaModularSigner, 37 | policies 38 | } 39 | ) 40 | 41 | return await createKernelAccount(publicClient, { 42 | entryPoint: getEntryPoint(), 43 | plugins: { 44 | regular: modularPermissionPlugin, 45 | sudo: ecdsaValidatorPlugin 46 | }, 47 | index, 48 | kernelVersion 49 | }) 50 | } 51 | -------------------------------------------------------------------------------- /plugins/multi-tenant-session-account/abi/YiSubAccountAbi.ts: -------------------------------------------------------------------------------- 1 | export const YiSubAccountAbi = [ 2 | { 3 | type: "constructor", 4 | inputs: [ 5 | { 6 | name: "_dm", 7 | type: "address", 8 | internalType: "contract IDelegationManager" 9 | } 10 | ], 11 | stateMutability: "nonpayable" 12 | }, 13 | { 14 | type: "function", 15 | name: "dm", 16 | inputs: [], 17 | outputs: [ 18 | { 19 | name: "", 20 | type: "address", 21 | internalType: "contract IDelegationManager" 22 | } 23 | ], 24 | stateMutability: "view" 25 | }, 26 | { 27 | type: "function", 28 | name: "executeDelegatedAction", 29 | inputs: [ 30 | { 31 | name: "_action", 32 | type: "tuple", 33 | internalType: "struct Action", 34 | components: [ 35 | { name: "to", type: "address", internalType: "address" }, 36 | { name: "value", type: "uint256", internalType: "uint256" }, 37 | { name: "data", type: "bytes", internalType: "bytes" } 38 | ] 39 | } 40 | ], 41 | outputs: [], 42 | stateMutability: "nonpayable" 43 | }, 44 | { 45 | type: "function", 46 | name: "initialize", 47 | inputs: [{ name: "_root", type: "address", internalType: "address" }], 48 | outputs: [], 49 | stateMutability: "nonpayable" 50 | }, 51 | { 52 | type: "function", 53 | name: "isValidSignature", 54 | inputs: [ 55 | { name: "hash", type: "bytes32", internalType: "bytes32" }, 56 | { name: "sig", type: "bytes", internalType: "bytes" } 57 | ], 58 | outputs: [{ name: "", type: "bytes4", internalType: "bytes4" }], 59 | stateMutability: "view" 60 | }, 61 | { type: "error", name: "AlreadyInitialized", inputs: [] }, 62 | { type: "error", name: "Forbidden", inputs: [] } 63 | ] as const 64 | -------------------------------------------------------------------------------- /plugins/weighted-ecdsa/constants.ts: -------------------------------------------------------------------------------- 1 | import { 2 | satisfiesRange, 3 | validateKernelVersionWithEntryPoint 4 | } from "@zerodev/sdk" 5 | import type { 6 | Action, 7 | EntryPointType, 8 | GetKernelVersion 9 | } from "@zerodev/sdk/types" 10 | import { type Address, toFunctionSelector, zeroAddress } from "viem" 11 | import type { EntryPointVersion } from "viem/account-abstraction" 12 | 13 | const RECOVERY_ACTION_ADDRESS_V06 = "0x2f65dB8039fe5CAEE0a8680D2879deB800F31Ae1" 14 | const RECOVERY_ACTION_ADDRESS_V07 = "0xe884C2868CC82c16177eC73a93f7D9E6F3A5DC6E" 15 | const RECOVERY_ACTION_SELECTOR = toFunctionSelector( 16 | "doRecovery(address, bytes)" 17 | ) 18 | 19 | export const getRecoveryAction = ( 20 | entryPointVersion: EntryPointVersion 21 | ): Action => { 22 | if (entryPointVersion === "0.6") { 23 | return { 24 | address: RECOVERY_ACTION_ADDRESS_V06, 25 | selector: RECOVERY_ACTION_SELECTOR 26 | } 27 | } 28 | return { 29 | address: RECOVERY_ACTION_ADDRESS_V07, 30 | selector: RECOVERY_ACTION_SELECTOR 31 | } 32 | } 33 | 34 | export const kernelVersionRangeToValidator: { 35 | [key: string]: Address 36 | } = { 37 | "0.0.2 - 0.2.4": "0x8012D9ee59176Cb01a4aa80fCFE6f5E8bA58d4fb", 38 | "0.3.0 - 0.3.3": "0xeD89244160CfE273800B58b1B534031699dFeEEE" 39 | } 40 | 41 | export const getValidatorAddress = < 42 | entryPointVersion extends EntryPointVersion 43 | >( 44 | entryPoint: EntryPointType, 45 | kernelVersion: GetKernelVersion, 46 | validatorAddress?: Address 47 | ): Address => { 48 | validateKernelVersionWithEntryPoint(entryPoint.version, kernelVersion) 49 | const weightedEcdsaValidatorAddress = Object.entries( 50 | kernelVersionRangeToValidator 51 | ).find(([range]) => satisfiesRange(kernelVersion, range))?.[1] 52 | 53 | if (!weightedEcdsaValidatorAddress && !validatorAddress) { 54 | throw new Error( 55 | `Validator not found for Kernel version: ${kernelVersion}` 56 | ) 57 | } 58 | 59 | return validatorAddress ?? weightedEcdsaValidatorAddress ?? zeroAddress 60 | } 61 | -------------------------------------------------------------------------------- /plugins/multi-chain-weighted-validator/clients/decorators/multiChainWeightedKernelAccountClient.ts: -------------------------------------------------------------------------------- 1 | import type { Chain, Client, Hash, Transport } from "viem" 2 | import type { SmartAccount } from "viem/account-abstraction" 3 | import { 4 | type ApproveUserOperationParameters, 5 | type ApproveUserOperationReturnType, 6 | approveUserOperation 7 | } from "../../actions/approveUserOperation.js" 8 | import { 9 | type SendUserOperationWithApprovalsParameters, 10 | sendUserOperationWithApprovals 11 | } from "../../actions/sendUserOperationWithApprovals.js" 12 | 13 | export type MultiChainWeightedKernelAccountClientActions = { 14 | /** 15 | * Approve a user operation with the given transport, chain, smart account and signer. 16 | * 17 | * @param args - Parameters for the approveUserOperation function 18 | * @returns A promise that resolves to the result of the approveUserOperation function 19 | */ 20 | approveUserOperation: ( 21 | args: ApproveUserOperationParameters 22 | ) => Promise 23 | /** 24 | * Sends a user operation with the given transport, chain, smart account and signer. 25 | * 26 | * @param args - Parameters for the sendUserOperationWithSignatures function 27 | * @returns A promise that resolves to the result of the sendUserOperationWithSignatures function 28 | */ 29 | sendUserOperationWithApprovals: ( 30 | args: SendUserOperationWithApprovalsParameters 31 | ) => Promise 32 | } 33 | export function multiChainWeightedKernelAccountClientActions() { 34 | return < 35 | TChain extends Chain | undefined = Chain | undefined, 36 | TSmartAccount extends SmartAccount | undefined = 37 | | SmartAccount 38 | | undefined 39 | >( 40 | client: Client 41 | ): MultiChainWeightedKernelAccountClientActions => { 42 | return { 43 | approveUserOperation: (args) => approveUserOperation(client, args), 44 | sendUserOperationWithApprovals: (args) => 45 | sendUserOperationWithApprovals(client, args) 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /plugins/permission/toInitConfig.ts: -------------------------------------------------------------------------------- 1 | import { KernelV3_3AccountAbi, encodeCallDataEpV07 } from "@zerodev/sdk" 2 | import { 3 | KernelVersionToAddressesMap, 4 | VALIDATOR_TYPE 5 | } from "@zerodev/sdk/constants" 6 | import { 7 | type Hex, 8 | concat, 9 | encodeFunctionData, 10 | getAbiItem, 11 | pad, 12 | toFunctionSelector, 13 | zeroAddress 14 | } from "viem" 15 | import type { PermissionPlugin } from "./types.js" 16 | 17 | export async function toInitConfig( 18 | permissionPlugin: PermissionPlugin 19 | ): Promise { 20 | const permissionInstallFunctionData = encodeFunctionData({ 21 | abi: KernelV3_3AccountAbi, 22 | functionName: "installValidations", 23 | args: [ 24 | [ 25 | pad( 26 | concat([ 27 | VALIDATOR_TYPE.PERMISSION, 28 | permissionPlugin.getIdentifier() 29 | ]), 30 | { size: 21, dir: "right" } 31 | ) 32 | ], 33 | [{ nonce: 1, hook: zeroAddress }], 34 | [await permissionPlugin.getEnableData()], 35 | ["0x"] 36 | ] 37 | }) 38 | const grantAccessFunctionData = encodeFunctionData({ 39 | abi: KernelV3_3AccountAbi, 40 | functionName: "grantAccess", 41 | args: [ 42 | pad( 43 | concat([ 44 | VALIDATOR_TYPE.PERMISSION, 45 | permissionPlugin.getIdentifier() 46 | ]), 47 | { size: 21, dir: "right" } 48 | ), 49 | toFunctionSelector( 50 | getAbiItem({ abi: KernelV3_3AccountAbi, name: "execute" }) 51 | ), 52 | true 53 | ] 54 | }) 55 | const delegateCall = await encodeCallDataEpV07( 56 | [ 57 | { 58 | to: KernelVersionToAddressesMap["0.3.3"] 59 | .accountImplementationAddress, 60 | data: grantAccessFunctionData 61 | } 62 | ], 63 | "delegatecall" 64 | ) 65 | return [permissionInstallFunctionData, delegateCall] 66 | } 67 | --------------------------------------------------------------------------------