@metamask/smart-accounts-kit 1.0.0 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. package/CHANGELOG.md +12 -1
  2. package/dist/actions/index.d.cts +2 -2
  3. package/dist/actions/index.d.ts +2 -2
  4. package/dist/{chunk-XN36L4RX.cjs → chunk-F2RG26RH.cjs} +2 -3
  5. package/dist/chunk-F2RG26RH.cjs.map +1 -0
  6. package/dist/{chunk-33AMUJBJ.mjs → chunk-YSBBRLMT.mjs} +1 -2
  7. package/dist/contracts/index.cjs +2 -2
  8. package/dist/contracts/index.d.cts +3 -3
  9. package/dist/contracts/index.d.ts +3 -3
  10. package/dist/contracts/index.mjs +1 -1
  11. package/dist/{delegation-DIriDFkq.d.cts → delegation-Ci3me5Rg.d.cts} +2 -2
  12. package/dist/{delegation-CvVXs0PO.d.ts → delegation-DgmIOh21.d.ts} +2 -2
  13. package/dist/experimental/index.d.cts +1 -1
  14. package/dist/experimental/index.d.ts +1 -1
  15. package/dist/{index-ChTryO1-.d.ts → index-CSjEW7MJ.d.cts} +3 -3
  16. package/dist/{index-5EdxVa_d.d.ts → index-D7fBuNV-.d.ts} +3 -3
  17. package/dist/{index-DC9baw8F.d.cts → index-UF6eCzBC.d.ts} +3 -3
  18. package/dist/{index-Dvc4ir4O.d.cts → index-Uj_xXVko.d.cts} +3 -3
  19. package/dist/index.cjs +5 -11
  20. package/dist/index.cjs.map +1 -1
  21. package/dist/index.d.cts +8 -8
  22. package/dist/index.d.ts +8 -8
  23. package/dist/index.mjs +5 -11
  24. package/dist/index.mjs.map +1 -1
  25. package/dist/{smartAccountsEnvironment-Czw9KUYZ.d.cts → smartAccountsEnvironment-BIcho7e0.d.cts} +1 -1
  26. package/dist/{smartAccountsEnvironment-u1CcFcGE.d.ts → smartAccountsEnvironment-Bso0CIWt.d.ts} +1 -1
  27. package/dist/{types-qdEHxd5Q.d.cts → types-BWaH4KH1.d.cts} +3 -2
  28. package/dist/{types-qdEHxd5Q.d.ts → types-BWaH4KH1.d.ts} +3 -2
  29. package/dist/utils/index.d.cts +3 -3
  30. package/dist/utils/index.d.ts +3 -3
  31. package/package.json +2 -2
  32. package/dist/chunk-XN36L4RX.cjs.map +0 -1
  33. /package/dist/{chunk-33AMUJBJ.mjs.map → chunk-YSBBRLMT.mjs.map} +0 -0
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/index.cjs","../src/toMetaMaskSmartAccount.ts","../src/signer.ts","../src/signatures.ts","../src/actions/caveatEnforcerClient.ts","../src/actions/infuraBundlerClient.ts"],"names":["signTypedData","signMessage","getStubSignature","signUserOperation","signDelegation"],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;AC3CA;AACE;AACA;AACA;AAAA,2DACK;AAEP;AACE;AACA;AACA;AAAA,8DACK;AD4CP;AACA;AEvDA,4BAAuB;AFyDvB;AACA;AGzDA;AAEA,IAAM,eAAA,EAAiB,CAAC,OAAO,CAAA;AAoBxB,IAAM,mBAAA,EAAqB,CAAC;AAAA,EACjC;AACF,CAAA,EAAA,GAEW;AACT,EAAA,GAAA,CAAI,UAAA,CAAW,OAAA,IAAW,CAAA,EAAG;AAC3B,IAAA,OAAO,IAAA;AAAA,EACT;AAEA,EAAA,IAAA,CAAA,MAAW,EAAE,KAAK,EAAA,GAAK,UAAA,EAAY;AACjC,IAAA,GAAA,CAAI,CAAC,cAAA,CAAe,QAAA,CAAS,IAAI,C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A;AACF,EAAA;AAGO,EAAA;AACT;ADgJsD;AACA;AIvWpD;AACA,EAAA;AACA,EAAA;AAIqD;AACR,EAAA;AAC/C;AJsWsD;AACA;AK9YtD;AACE;AAIK;AAyCiD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYmB,EAAA;AACjD,IAAA;AAOa,IAAA;AACzB,MAAA;AACC,MAAA;AACV,IAAA;AACH,EAAA;AACF;AA0DqD;AAEC,EAAA;AAG3B,EAAA;AACF,IAAA;AACvB,EAAA;AACF;ALmSsD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/index.cjs","sourcesContent":[null,"import {\n EIP7702StatelessDeleGator,\n HybridDeleGator,\n MultiSigDeleGator,\n} from '@metamask/delegation-abis';\nimport { type Address, type Hex } from 'viem';\nimport {\n entryPoint07Abi,\n toPackedUserOperation,\n toSmartAccount,\n} from 'viem/account-abstraction';\n\nimport { isValid7702Implementation } from './actions/isValid7702Implementation';\nimport { Implementation } from './constants';\nimport { getCounterfactualAccountData } from './counterfactualAccountData';\nimport {\n SIGNABLE_DELEGATION_TYPED_DATA,\n toDelegationStruct,\n} from './delegation';\nimport { entryPointGetNonce as _getNonce } from './DelegationFramework/EntryPoint/read';\nimport { encodeCallsForCaller } from './encodeCalls';\nimport { resolveSigner } from './signer';\nimport { getSmartAccountsEnvironment } from './smartAccountsEnvironment';\nimport type {\n Call,\n ToMetaMaskSmartAccountParameters,\n ToMetaMaskSmartAccountReturnType,\n SignDelegationParams,\n SignUserOperationParams,\n AbiByImplementation,\n} from './types';\nimport { SIGNABLE_USER_OP_TYPED_DATA } from './userOp';\n\nconst ENTRYPOINT_VERSION = '0.7' as const;\n\n/**\n * Creates a MetaMask DeleGator smart account instance.\n *\n * @template TImplementation - The type of implementation, extending Implementation.\n * @param params - The parameters for creating the smart account.\n * @returns A promise that resolves to a MetaMaskSmartAccount instance.\n * @description\n * This function sets up a MetaMask DeleGator smart account with the specified implementation.\n * It handles both deployed accounts, and counterfactual accounts.\n * A caller may specify a SmartAccountsEnvironment, otherwise the environment will be inferred from the chain.\n */\nexport async function toMetaMaskSmartAccount<\n TImplementation extends Implementation,\n>(\n params: ToMetaMaskSmartAccountParameters<TImplementation>,\n): Promise<ToMetaMaskSmartAccountReturnType<TImplementation>> {\n const {\n client,\n client: { chain },\n implementation,\n } = params;\n\n if (!chain) {\n throw new Error('Chain not specified');\n }\n\n const signer = resolveSigner({\n implementation,\n signer: params.signer,\n });\n\n const environment =\n params.environment ?? getSmartAccountsEnvironment(chain.id);\n\n let address: Address, factoryData: Hex | undefined;\n\n if (params.address) {\n factoryData = undefined;\n address = params.address;\n } else {\n if (implementation === Implementation.Stateless7702) {\n throw new Error('Stateless7702 does not support counterfactual accounts');\n }\n\n const accountData = await getCounterfactualAccountData({\n factory: environment.SimpleFactory,\n implementations: environment.implementations,\n implementation,\n deployParams: params.deployParams,\n deploySalt: params.deploySalt,\n });\n\n address = accountData.address;\n factoryData = accountData.factoryData;\n }\n\n const entryPoint = {\n abi: entryPoint07Abi,\n address: environment.EntryPoint,\n version: ENTRYPOINT_VERSION,\n } as const;\n\n const { abi, contractName } = {\n [Implementation.Hybrid]: {\n contractName: 'HybridDeleGator',\n abi: HybridDeleGator,\n },\n [Implementation.MultiSig]: {\n contractName: 'MultiSigDeleGator',\n abi: MultiSigDeleGator,\n },\n [Implementation.Stateless7702]: {\n contractName: 'EIP7702StatelessDeleGator',\n abi: EIP7702StatelessDeleGator,\n },\n }[implementation] as {\n contractName: string;\n abi: AbiByImplementation[TImplementation];\n };\n\n const getFactoryArgs = async () => {\n if (factoryData === undefined) {\n throw new Error(\n 'Deploy params were not provided, so factory args cannot be inferred',\n );\n }\n return {\n factoryData,\n factory: environment.SimpleFactory,\n };\n };\n\n const signDelegation = async (delegationParams: SignDelegationParams) => {\n if (!signer) {\n throw new Error(\n 'Cannot sign delegation: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n }\n\n const { delegation, chainId } = delegationParams;\n\n const delegationStruct = toDelegationStruct({\n ...delegation,\n signature: '0x',\n });\n\n const signature = await signer.signTypedData({\n domain: {\n chainId: chainId ?? chain.id,\n name: 'DelegationManager',\n version: '1',\n verifyingContract: environment.DelegationManager,\n },\n types: SIGNABLE_DELEGATION_TYPED_DATA,\n primaryType: 'Delegation',\n message: delegationStruct,\n });\n\n return signature;\n };\n\n const signUserOperation = async (userOpParams: SignUserOperationParams) => {\n if (!signer) {\n throw new Error(\n 'Cannot sign user operation: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n }\n\n const { chainId } = userOpParams;\n\n const packedUserOp = toPackedUserOperation({\n sender: address,\n ...userOpParams,\n signature: '0x',\n });\n\n const signature = await signer.signTypedData({\n domain: {\n chainId: chainId ?? chain.id,\n name: contractName,\n version: '1',\n verifyingContract: address,\n },\n types: SIGNABLE_USER_OP_TYPED_DATA,\n primaryType: 'PackedUserOperation',\n message: { ...packedUserOp, entryPoint: entryPoint.address },\n });\n\n return signature;\n };\n\n const getAddress = async () => address;\n\n const getNonce = async () =>\n _getNonce({\n client,\n entryPoint: environment.EntryPoint,\n contractAddress: address,\n key: 0n,\n });\n\n const encodeCalls = async (calls: readonly Call[]) =>\n encodeCallsForCaller(address, calls);\n\n const signerMethods = signer ?? {\n signMessage: async () => {\n throw new Error(\n 'Cannot sign message: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n signTypedData: async () => {\n throw new Error(\n 'Cannot sign typed data: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n getStubSignature: async () => {\n throw new Error(\n 'Cannot get stub signature: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n };\n\n const smartAccount = await toSmartAccount({\n abi,\n client,\n entryPoint,\n environment,\n getAddress,\n getFactoryArgs,\n encodeCalls,\n getNonce,\n signUserOperation,\n signDelegation,\n ...signerMethods,\n });\n\n // Override isDeployed only for EIP-7702 implementation to check proper delegation code\n if (implementation === Implementation.Stateless7702) {\n return {\n ...smartAccount,\n isDeployed: async () =>\n isValid7702Implementation({\n client,\n accountAddress: address,\n environment,\n }),\n };\n }\n\n // For other implementations, use the default isDeployed behavior\n return smartAccount;\n}\n","import { concat } from 'viem';\nimport type {\n Address,\n SignableMessage,\n TypedData,\n TypedDataDefinition,\n} from 'viem';\nimport type { WebAuthnAccount } from 'viem/account-abstraction';\n\nimport { Implementation } from './constants';\nimport { aggregateSignature } from './signatures';\nimport type {\n AccountSignerConfig,\n HybridSignerConfig,\n InternalSigner,\n MultiSigSignerConfig,\n SignerConfigByImplementation,\n Stateless7702SignerConfig,\n WalletSignerConfig,\n} from './types';\nimport {\n createDummyWebAuthnSignature,\n encodeDeleGatorSignature,\n} from './webAuthn';\n\n// A valid ECDSA signature, this must be able to ecrecover an address, otherwise the contracts will revert in isValidSignature\nconst EOA_STUB_SIGNATURE =\n '0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000011b' as const;\n\nconst resolveSignerFromWalletConfig = (\n config: WalletSignerConfig,\n): InternalSigner => {\n return {\n signMessage: config.walletClient.signMessage,\n signTypedData: async (typedData) => {\n // todo: figure out this type so that we don't need the type assertion\n return config.walletClient.signTypedData(typedData as any);\n },\n getStubSignature: async () => EOA_STUB_SIGNATURE,\n };\n};\n\nconst resolveSignerFromAccountConfig = (config: AccountSignerConfig) => {\n return {\n signMessage: config.account.signMessage,\n signTypedData: config.account.signTypedData,\n getStubSignature: async () => EOA_STUB_SIGNATURE,\n };\n};\n\nconst resolveHybridSigner = (config: HybridSignerConfig): InternalSigner => {\n if ('walletClient' in config) {\n return resolveSignerFromWalletConfig(config);\n } else if ('account' in config) {\n const { signMessage, signTypedData, getStubSignature } =\n resolveSignerFromAccountConfig(config);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n }\n const { keyId, webAuthnAccount } = config;\n\n if (webAuthnAccount.type !== 'webAuthn') {\n throw new Error('Account is not a webAuthn account');\n }\n\n const encodeSignature = (\n result: Awaited<ReturnType<WebAuthnAccount['signMessage']>>,\n ) =>\n encodeDeleGatorSignature(\n keyId,\n result.signature,\n result.webauthn.clientDataJSON,\n result.webauthn.authenticatorData,\n );\n\n const signMessage = async (args: { message: SignableMessage }) =>\n webAuthnAccount.signMessage(args).then(encodeSignature);\n const signTypedData = async <\n const TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(\n typedDataDefinition: TypedDataDefinition<TTypedData, TPrimaryType>,\n ) => webAuthnAccount.signTypedData(typedDataDefinition).then(encodeSignature);\n\n const getStubSignature = async () => createDummyWebAuthnSignature(keyId);\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n};\n\nconst resolveMultiSigSigner = (\n config: MultiSigSignerConfig,\n): InternalSigner => {\n const resolvedSigners = config.map((signer) => {\n let individualSignMessage: InternalSigner['signMessage'];\n let individualSignTypedData: InternalSigner['signTypedData'];\n let address: Address;\n if ('walletClient' in signer) {\n const { signMessage, signTypedData } =\n resolveSignerFromWalletConfig(signer);\n individualSignMessage = signMessage;\n individualSignTypedData = signTypedData;\n\n address = signer.walletClient.account.address;\n } else {\n const { signMessage, signTypedData } =\n resolveSignerFromAccountConfig(signer);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n\n individualSignMessage = signMessage;\n individualSignTypedData = signTypedData;\n\n address = signer.account.address;\n }\n return {\n address,\n individualSignMessage,\n individualSignTypedData,\n };\n });\n\n const signMessage = async (args: { message: SignableMessage }) => {\n const addressAndSignatures = resolvedSigners.map(\n async ({ individualSignMessage, address }) => ({\n signature: await individualSignMessage(args),\n signer: address,\n type: 'ECDSA' as const,\n }),\n );\n\n const signatures = await Promise.all(addressAndSignatures);\n\n return aggregateSignature({\n signatures,\n });\n };\n\n const signTypedData = async <\n const TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(\n typedDataDefinition: TypedDataDefinition<TTypedData, TPrimaryType>,\n ) => {\n const addressAndSignatures = resolvedSigners.map(\n async ({ individualSignTypedData, address }) => ({\n signature: await individualSignTypedData(typedDataDefinition),\n signer: address,\n type: 'ECDSA' as const,\n }),\n );\n\n const signatures = await Promise.all(addressAndSignatures);\n\n return aggregateSignature({\n signatures,\n });\n };\n\n const getStubSignature = async () =>\n concat(resolvedSigners.map(() => EOA_STUB_SIGNATURE));\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n};\n\nconst resolveStateless7702Signer = (\n config: Stateless7702SignerConfig,\n): InternalSigner => {\n if ('walletClient' in config) {\n return resolveSignerFromWalletConfig(config);\n } else if ('account' in config) {\n const { signMessage, signTypedData, getStubSignature } =\n resolveSignerFromAccountConfig(config);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n }\n\n throw new Error('Invalid signer config');\n};\n\n/**\n * Resolve a signer from a configuration object.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner;\n\n/**\n * Resolve a signer from a configuration object. If no signer is provided, return null.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer or null if no signer is provided.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer?: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner | null;\n\n/**\n * Resolve a signer from a configuration object. If no signer is provided, return null.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer or null if no signer is provided.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer?: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner | null {\n const { implementation, signer } = config;\n\n if (!signer) {\n return null;\n }\n\n if (implementation === Implementation.Hybrid) {\n return resolveHybridSigner(signer as HybridSignerConfig);\n } else if (implementation === Implementation.MultiSig) {\n return resolveMultiSigSigner(signer as MultiSigSignerConfig);\n } else if (implementation === Implementation.Stateless7702) {\n return resolveStateless7702Signer(signer as Stateless7702SignerConfig);\n }\n throw new Error(`Implementation type '${implementation}' not supported`);\n}\n","import type { Address, Hex } from 'viem';\nimport { concat } from 'viem';\n\nconst signatureTypes = ['ECDSA'] as const;\n\nexport type SignatureType = (typeof signatureTypes)[number];\n\n/**\n * Represents a partial signature that can be aggregated with others.\n */\nexport type PartialSignature = {\n signer: Address;\n signature: Hex;\n type: SignatureType;\n};\n\n/**\n * Aggregates signatures into a single signature as expected by the MultiSig implementation.\n *\n * @param params - The parameters for signature aggregation.\n * @param params.signatures - The array of partial signatures to aggregate.\n * @returns The aggregated signature.\n */\nexport const aggregateSignature = ({\n signatures,\n}: {\n signatures: PartialSignature[];\n}): Hex => {\n if (signatures.length === 0) {\n return '0x';\n }\n\n for (const { type } of signatures) {\n if (!signatureTypes.includes(type)) {\n throw new Error(`Invalid signature type: ${type}`);\n }\n }\n\n // Sort signatures by signer address as required by MultiSig implementation\n const sortedSignatures = [...signatures].sort((a, b) =>\n a.signer.localeCompare(b.signer),\n );\n\n // Concatenate all signatures\n return concat(sortedSignatures.map(({ signature }) => signature));\n};\n\n/**\n * Type definition for the aggregateSignature function parameters.\n */\nexport type AggregateSignatureParams = {\n signatures: PartialSignature[];\n};\n","import type { Client, Transport, Chain, Account } from 'viem';\n\nimport type { SmartAccountsEnvironment } from '../types';\nimport {\n caveatEnforcerActions,\n type CaveatEnforcerParams,\n type PeriodTransferResult,\n type StreamingResult,\n} from './getCaveatAvailableAmount';\n\n/**\n * Type for client extended with caveat enforcer actions.\n */\nexport type CaveatEnforcerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends Account | undefined = Account | undefined,\n> = Client<TTransport, TChain, TAccount> &\n ReturnType<ReturnType<typeof caveatEnforcerActions>>;\n\n/**\n * Create a viem client extended with caveat enforcer actions.\n *\n * @param params - The parameters object.\n * @param params.client - The viem client.\n * @param params.environment - The SmartAccountsEnvironment.\n * @returns The extended client with caveat enforcer actions.\n */\nexport function createCaveatEnforcerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends Account | undefined = Account | undefined,\n>({\n client,\n environment,\n}: {\n client: Client<TTransport, TChain, TAccount>;\n environment: SmartAccountsEnvironment;\n}): CaveatEnforcerClient<TTransport, TChain, TAccount> {\n return client.extend(caveatEnforcerActions({ environment }));\n}\n\n// Re-export types for convenience\nexport type { CaveatEnforcerParams, PeriodTransferResult, StreamingResult };\n","import type { Transport, Chain, Hex, Client, Account } from 'viem';\nimport {\n createBundlerClient,\n type BundlerClient,\n type BundlerClientConfig,\n type SmartAccount,\n} from 'viem/account-abstraction';\n\n/**\n * Gas price tiers returned by pimlico_getUserOperationGasPrice\n */\nexport type GasPriceTier = {\n /** Maximum fee per gas in hex format */\n maxFeePerGas: Hex;\n /** Maximum priority fee per gas in hex format */\n maxPriorityFeePerGas: Hex;\n};\n\n/**\n * Response from pimlico_getUserOperationGasPrice RPC method\n */\nexport type UserOperationGasPriceResponse = {\n /** Slow gas price tier */\n slow: GasPriceTier;\n /** Standard gas price tier */\n standard: GasPriceTier;\n /** Fast gas price tier */\n fast: GasPriceTier;\n};\n\n/**\n * Pimlico bundler schema for type-safe RPC method calls\n */\n/* eslint-disable @typescript-eslint/naming-convention */\ntype PimlicoBundlerSchema = [\n {\n Method: 'pimlico_getUserOperationGasPrice';\n Parameters: [];\n ReturnType: UserOperationGasPriceResponse;\n },\n];\n\n/**\n * Infura bundler actions for extending bundler clients.\n *\n * @returns A function that takes a client and returns the client extension with Infura bundler actions.\n */\nconst infuraBundlerActions = () => (client: Client) => ({\n /**\n * Get user operation gas prices from Infura bundler.\n * Calls the pimlico_getUserOperationGasPrice RPC method.\n *\n * @returns Promise resolving to gas price tiers (slow, standard, fast).\n * @example\n * ```typescript\n * const gasPrices = await bundlerClient.getUserOperationGasPrice();\n * console.log(gasPrices.standard.maxFeePerGas);\n * ```\n */\n async getUserOperationGasPrice(): Promise<UserOperationGasPriceResponse> {\n const pimlicoClient = client as Client<\n Transport,\n Chain | undefined,\n Account | undefined,\n PimlicoBundlerSchema\n >;\n\n return await pimlicoClient.request({\n method: 'pimlico_getUserOperationGasPrice',\n params: [],\n });\n },\n});\n\n/**\n * Type for bundler client extended with Infura bundler actions.\n */\nexport type InfuraBundlerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = BundlerClient<TTransport, TChain, TAccount> & {\n /**\n * Get user operation gas prices from Infura bundler.\n * Calls the pimlico_getUserOperationGasPrice RPC method.\n *\n * @returns Promise resolving to gas price tiers (slow, standard, fast).\n */\n getUserOperationGasPrice(): Promise<UserOperationGasPriceResponse>;\n};\n\n/**\n * Creates an Infura bundler client extended with Infura bundler actions.\n *\n * This is a wrapper around viem's createBundlerClient that extends it with\n * the getUserOperationGasPrice method for retrieving gas prices from Pimlico's\n * bundler infrastructure via Infura's proxy.\n *\n * @param config - Configuration for the bundler client.\n * @returns Extended bundler client with Infura bundler actions.\n * @example\n * ```typescript\n * import { createPublicClient, http } from 'viem';\n * import { sepolia } from 'viem/chains';\n * import { createInfuraBundlerClient } from '@metamask/smart-accounts-kit';\n *\n * const publicClient = createPublicClient({\n * chain: sepolia,\n * transport: http('https://sepolia.infura.io/v3/YOUR_API_KEY'),\n * });\n *\n * const bundlerClient = createInfuraBundlerClient({\n * client: publicClient,\n * transport: http('https://sepolia.infura.io/v3/YOUR_API_KEY'),\n * chain: sepolia,\n * });\n *\n * // Use standard bundler methods\n * const userOpHash = await bundlerClient.sendUserOperation({...});\n *\n * // Use Infura specific methods\n * const gasPrices = await bundlerClient.getUserOperationGasPrice();\n * ```\n */\nexport function createInfuraBundlerClient<\n TTransport extends Transport,\n TChain extends Chain | undefined = undefined,\n TAccount extends SmartAccount | undefined = undefined,\n>(\n config: BundlerClientConfig<TTransport, TChain, TAccount>,\n): InfuraBundlerClient<TTransport, TChain, TAccount> {\n // Create the base bundler client using viem's function\n const baseBundlerClient = createBundlerClient(config);\n\n // Extend the client with Infura bundler actions\n return baseBundlerClient.extend(\n infuraBundlerActions(),\n ) as unknown as InfuraBundlerClient<TTransport, TChain, TAccount>;\n}\n"]}
1
+ {"version":3,"sources":["/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/index.cjs","../src/toMetaMaskSmartAccount.ts","../src/signer.ts","../src/signatures.ts","../src/actions/caveatEnforcerClient.ts","../src/actions/infuraBundlerClient.ts"],"names":["signTypedData","signMessage","getStubSignature","signUserOperation","signDelegation"],"mappings":"AAAA;AACE;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACF,wDAA6B;AAC7B,gCAA6B;AAC7B;AACE;AACA;AACF,wDAA6B;AAC7B;AACE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACF,wDAA6B;AAC7B;AACA;AC1CA;AACE;AACA;AACA;AAAA,2DACK;AAEP;AACE;AACA;A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;AACF,MAAA;AACF,IAAA;AAC8B,IAAA;AAClB,MAAA;AACR,QAAA;AACF,MAAA;AACF,IAAA;AACF,EAAA;AAE0C,EAAA;AACxC,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACA,IAAA;AACAG,IAAAA;AACAC,IAAAA;AACA,IAAA;AACG,IAAA;AACJ,EAAA;AAGG,EAAA;AACK,IAAA;AACF,MAAA;AAED,MAAA;AACE,QAAA;AACgB,QAAA;AAChB,QAAA;AACD,MAAA;AACL,IAAA;AACF,EAAA;AAGO,EAAA;AACT;ADkJsD;AACA;AIjWpD;AACA,EAAA;AACA,EAAA;AAIqD;AACR,EAAA;AAC/C;AJgWsD;AACA;AKxYtD;AACE;AAIK;AAyCiD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAYmB,EAAA;AACjD,IAAA;AAOa,IAAA;AACzB,MAAA;AACC,MAAA;AACV,IAAA;AACH,EAAA;AACF;AA0DqD;AAEC,EAAA;AAG3B,EAAA;AACF,IAAA;AACvB,EAAA;AACF;AL6RsD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA","file":"/home/runner/work/smart-accounts-kit/smart-accounts-kit/packages/smart-accounts-kit/dist/index.cjs","sourcesContent":[null,"import {\n EIP7702StatelessDeleGator,\n HybridDeleGator,\n MultiSigDeleGator,\n} from '@metamask/delegation-abis';\nimport { type Address, type Hex } from 'viem';\nimport {\n entryPoint07Abi,\n toPackedUserOperation,\n toSmartAccount,\n} from 'viem/account-abstraction';\n\nimport { isValid7702Implementation } from './actions/isValid7702Implementation';\nimport { Implementation } from './constants';\nimport { getCounterfactualAccountData } from './counterfactualAccountData';\nimport {\n SIGNABLE_DELEGATION_TYPED_DATA,\n toDelegationStruct,\n} from './delegation';\nimport { encodeCallsForCaller } from './encodeCalls';\nimport { resolveSigner } from './signer';\nimport { getSmartAccountsEnvironment } from './smartAccountsEnvironment';\nimport type {\n Call,\n ToMetaMaskSmartAccountParameters,\n ToMetaMaskSmartAccountReturnType,\n SignDelegationParams,\n SignUserOperationParams,\n AbiByImplementation,\n} from './types';\nimport { SIGNABLE_USER_OP_TYPED_DATA } from './userOp';\n\nconst ENTRYPOINT_VERSION = '0.7' as const;\n\n/**\n * Creates a MetaMask DeleGator smart account instance.\n *\n * @template TImplementation - The type of implementation, extending Implementation.\n * @param params - The parameters for creating the smart account.\n * @returns A promise that resolves to a MetaMaskSmartAccount instance.\n * @description\n * This function sets up a MetaMask DeleGator smart account with the specified implementation.\n * It handles both deployed accounts, and counterfactual accounts.\n * A caller may specify a SmartAccountsEnvironment, otherwise the environment will be inferred from the chain.\n */\nexport async function toMetaMaskSmartAccount<\n TImplementation extends Implementation,\n>(\n params: ToMetaMaskSmartAccountParameters<TImplementation>,\n): Promise<ToMetaMaskSmartAccountReturnType<TImplementation>> {\n const {\n client,\n client: { chain },\n implementation,\n nonceKeyManager,\n } = params;\n\n if (!chain) {\n throw new Error('Chain not specified');\n }\n\n const signer = resolveSigner({\n implementation,\n signer: params.signer,\n });\n\n const environment =\n params.environment ?? getSmartAccountsEnvironment(chain.id);\n\n let address: Address, factoryData: Hex | undefined;\n\n if (params.address) {\n factoryData = undefined;\n address = params.address;\n } else {\n if (implementation === Implementation.Stateless7702) {\n throw new Error('Stateless7702 does not support counterfactual accounts');\n }\n\n const accountData = await getCounterfactualAccountData({\n factory: environment.SimpleFactory,\n implementations: environment.implementations,\n implementation,\n deployParams: params.deployParams,\n deploySalt: params.deploySalt,\n });\n\n address = accountData.address;\n factoryData = accountData.factoryData;\n }\n\n const entryPoint = {\n abi: entryPoint07Abi,\n address: environment.EntryPoint,\n version: ENTRYPOINT_VERSION,\n } as const;\n\n const { abi, contractName } = {\n [Implementation.Hybrid]: {\n contractName: 'HybridDeleGator',\n abi: HybridDeleGator,\n },\n [Implementation.MultiSig]: {\n contractName: 'MultiSigDeleGator',\n abi: MultiSigDeleGator,\n },\n [Implementation.Stateless7702]: {\n contractName: 'EIP7702StatelessDeleGator',\n abi: EIP7702StatelessDeleGator,\n },\n }[implementation] as {\n contractName: string;\n abi: AbiByImplementation[TImplementation];\n };\n\n const getFactoryArgs = async () => {\n if (factoryData === undefined) {\n throw new Error(\n 'Deploy params were not provided, so factory args cannot be inferred',\n );\n }\n return {\n factoryData,\n factory: environment.SimpleFactory,\n };\n };\n\n const signDelegation = async (delegationParams: SignDelegationParams) => {\n if (!signer) {\n throw new Error(\n 'Cannot sign delegation: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n }\n\n const { delegation, chainId } = delegationParams;\n\n const delegationStruct = toDelegationStruct({\n ...delegation,\n signature: '0x',\n });\n\n const signature = await signer.signTypedData({\n domain: {\n chainId: chainId ?? chain.id,\n name: 'DelegationManager',\n version: '1',\n verifyingContract: environment.DelegationManager,\n },\n types: SIGNABLE_DELEGATION_TYPED_DATA,\n primaryType: 'Delegation',\n message: delegationStruct,\n });\n\n return signature;\n };\n\n const signUserOperation = async (userOpParams: SignUserOperationParams) => {\n if (!signer) {\n throw new Error(\n 'Cannot sign user operation: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n }\n\n const { chainId } = userOpParams;\n\n const packedUserOp = toPackedUserOperation({\n sender: address,\n ...userOpParams,\n signature: '0x',\n });\n\n const signature = await signer.signTypedData({\n domain: {\n chainId: chainId ?? chain.id,\n name: contractName,\n version: '1',\n verifyingContract: address,\n },\n types: SIGNABLE_USER_OP_TYPED_DATA,\n primaryType: 'PackedUserOperation',\n message: { ...packedUserOp, entryPoint: entryPoint.address },\n });\n\n return signature;\n };\n\n const getAddress = async () => address;\n\n const encodeCalls = async (calls: readonly Call[]) =>\n encodeCallsForCaller(address, calls);\n\n const signerMethods = signer ?? {\n signMessage: async () => {\n throw new Error(\n 'Cannot sign message: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n signTypedData: async () => {\n throw new Error(\n 'Cannot sign typed data: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n getStubSignature: async () => {\n throw new Error(\n 'Cannot get stub signature: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n };\n\n const smartAccount = await toSmartAccount({\n abi,\n client,\n entryPoint,\n environment,\n getAddress,\n getFactoryArgs,\n encodeCalls,\n signUserOperation,\n signDelegation,\n nonceKeyManager,\n ...signerMethods,\n });\n\n // Override isDeployed only for EIP-7702 implementation to check proper delegation code\n if (implementation === Implementation.Stateless7702) {\n return {\n ...smartAccount,\n isDeployed: async () =>\n isValid7702Implementation({\n client,\n accountAddress: address,\n environment,\n }),\n };\n }\n\n // For other implementations, use the default isDeployed behavior\n return smartAccount;\n}\n","import { concat } from 'viem';\nimport type {\n Address,\n SignableMessage,\n TypedData,\n TypedDataDefinition,\n} from 'viem';\nimport type { WebAuthnAccount } from 'viem/account-abstraction';\n\nimport { Implementation } from './constants';\nimport { aggregateSignature } from './signatures';\nimport type {\n AccountSignerConfig,\n HybridSignerConfig,\n InternalSigner,\n MultiSigSignerConfig,\n SignerConfigByImplementation,\n Stateless7702SignerConfig,\n WalletSignerConfig,\n} from './types';\nimport {\n createDummyWebAuthnSignature,\n encodeDeleGatorSignature,\n} from './webAuthn';\n\n// A valid ECDSA signature, this must be able to ecrecover an address, otherwise the contracts will revert in isValidSignature\nconst EOA_STUB_SIGNATURE =\n '0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000011b' as const;\n\nconst resolveSignerFromWalletConfig = (\n config: WalletSignerConfig,\n): InternalSigner => {\n return {\n signMessage: config.walletClient.signMessage,\n signTypedData: async (typedData) => {\n // todo: figure out this type so that we don't need the type assertion\n return config.walletClient.signTypedData(typedData as any);\n },\n getStubSignature: async () => EOA_STUB_SIGNATURE,\n };\n};\n\nconst resolveSignerFromAccountConfig = (config: AccountSignerConfig) => {\n return {\n signMessage: config.account.signMessage,\n signTypedData: config.account.signTypedData,\n getStubSignature: async () => EOA_STUB_SIGNATURE,\n };\n};\n\nconst resolveHybridSigner = (config: HybridSignerConfig): InternalSigner => {\n if ('walletClient' in config) {\n return resolveSignerFromWalletConfig(config);\n } else if ('account' in config) {\n const { signMessage, signTypedData, getStubSignature } =\n resolveSignerFromAccountConfig(config);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n }\n const { keyId, webAuthnAccount } = config;\n\n if (webAuthnAccount.type !== 'webAuthn') {\n throw new Error('Account is not a webAuthn account');\n }\n\n const encodeSignature = (\n result: Awaited<ReturnType<WebAuthnAccount['signMessage']>>,\n ) =>\n encodeDeleGatorSignature(\n keyId,\n result.signature,\n result.webauthn.clientDataJSON,\n result.webauthn.authenticatorData,\n );\n\n const signMessage = async (args: { message: SignableMessage }) =>\n webAuthnAccount.signMessage(args).then(encodeSignature);\n const signTypedData = async <\n const TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(\n typedDataDefinition: TypedDataDefinition<TTypedData, TPrimaryType>,\n ) => webAuthnAccount.signTypedData(typedDataDefinition).then(encodeSignature);\n\n const getStubSignature = async () => createDummyWebAuthnSignature(keyId);\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n};\n\nconst resolveMultiSigSigner = (\n config: MultiSigSignerConfig,\n): InternalSigner => {\n const resolvedSigners = config.map((signer) => {\n let individualSignMessage: InternalSigner['signMessage'];\n let individualSignTypedData: InternalSigner['signTypedData'];\n let address: Address;\n if ('walletClient' in signer) {\n const { signMessage, signTypedData } =\n resolveSignerFromWalletConfig(signer);\n individualSignMessage = signMessage;\n individualSignTypedData = signTypedData;\n\n address = signer.walletClient.account.address;\n } else {\n const { signMessage, signTypedData } =\n resolveSignerFromAccountConfig(signer);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n\n individualSignMessage = signMessage;\n individualSignTypedData = signTypedData;\n\n address = signer.account.address;\n }\n return {\n address,\n individualSignMessage,\n individualSignTypedData,\n };\n });\n\n const signMessage = async (args: { message: SignableMessage }) => {\n const addressAndSignatures = resolvedSigners.map(\n async ({ individualSignMessage, address }) => ({\n signature: await individualSignMessage(args),\n signer: address,\n type: 'ECDSA' as const,\n }),\n );\n\n const signatures = await Promise.all(addressAndSignatures);\n\n return aggregateSignature({\n signatures,\n });\n };\n\n const signTypedData = async <\n const TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(\n typedDataDefinition: TypedDataDefinition<TTypedData, TPrimaryType>,\n ) => {\n const addressAndSignatures = resolvedSigners.map(\n async ({ individualSignTypedData, address }) => ({\n signature: await individualSignTypedData(typedDataDefinition),\n signer: address,\n type: 'ECDSA' as const,\n }),\n );\n\n const signatures = await Promise.all(addressAndSignatures);\n\n return aggregateSignature({\n signatures,\n });\n };\n\n const getStubSignature = async () =>\n concat(resolvedSigners.map(() => EOA_STUB_SIGNATURE));\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n};\n\nconst resolveStateless7702Signer = (\n config: Stateless7702SignerConfig,\n): InternalSigner => {\n if ('walletClient' in config) {\n return resolveSignerFromWalletConfig(config);\n } else if ('account' in config) {\n const { signMessage, signTypedData, getStubSignature } =\n resolveSignerFromAccountConfig(config);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n }\n\n throw new Error('Invalid signer config');\n};\n\n/**\n * Resolve a signer from a configuration object.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner;\n\n/**\n * Resolve a signer from a configuration object. If no signer is provided, return null.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer or null if no signer is provided.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer?: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner | null;\n\n/**\n * Resolve a signer from a configuration object. If no signer is provided, return null.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer or null if no signer is provided.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer?: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner | null {\n const { implementation, signer } = config;\n\n if (!signer) {\n return null;\n }\n\n if (implementation === Implementation.Hybrid) {\n return resolveHybridSigner(signer as HybridSignerConfig);\n } else if (implementation === Implementation.MultiSig) {\n return resolveMultiSigSigner(signer as MultiSigSignerConfig);\n } else if (implementation === Implementation.Stateless7702) {\n return resolveStateless7702Signer(signer as Stateless7702SignerConfig);\n }\n throw new Error(`Implementation type '${implementation}' not supported`);\n}\n","import type { Address, Hex } from 'viem';\nimport { concat } from 'viem';\n\nconst signatureTypes = ['ECDSA'] as const;\n\nexport type SignatureType = (typeof signatureTypes)[number];\n\n/**\n * Represents a partial signature that can be aggregated with others.\n */\nexport type PartialSignature = {\n signer: Address;\n signature: Hex;\n type: SignatureType;\n};\n\n/**\n * Aggregates signatures into a single signature as expected by the MultiSig implementation.\n *\n * @param params - The parameters for signature aggregation.\n * @param params.signatures - The array of partial signatures to aggregate.\n * @returns The aggregated signature.\n */\nexport const aggregateSignature = ({\n signatures,\n}: {\n signatures: PartialSignature[];\n}): Hex => {\n if (signatures.length === 0) {\n return '0x';\n }\n\n for (const { type } of signatures) {\n if (!signatureTypes.includes(type)) {\n throw new Error(`Invalid signature type: ${type}`);\n }\n }\n\n // Sort signatures by signer address as required by MultiSig implementation\n const sortedSignatures = [...signatures].sort((a, b) =>\n a.signer.localeCompare(b.signer),\n );\n\n // Concatenate all signatures\n return concat(sortedSignatures.map(({ signature }) => signature));\n};\n\n/**\n * Type definition for the aggregateSignature function parameters.\n */\nexport type AggregateSignatureParams = {\n signatures: PartialSignature[];\n};\n","import type { Client, Transport, Chain, Account } from 'viem';\n\nimport type { SmartAccountsEnvironment } from '../types';\nimport {\n caveatEnforcerActions,\n type CaveatEnforcerParams,\n type PeriodTransferResult,\n type StreamingResult,\n} from './getCaveatAvailableAmount';\n\n/**\n * Type for client extended with caveat enforcer actions.\n */\nexport type CaveatEnforcerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends Account | undefined = Account | undefined,\n> = Client<TTransport, TChain, TAccount> &\n ReturnType<ReturnType<typeof caveatEnforcerActions>>;\n\n/**\n * Create a viem client extended with caveat enforcer actions.\n *\n * @param params - The parameters object.\n * @param params.client - The viem client.\n * @param params.environment - The SmartAccountsEnvironment.\n * @returns The extended client with caveat enforcer actions.\n */\nexport function createCaveatEnforcerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends Account | undefined = Account | undefined,\n>({\n client,\n environment,\n}: {\n client: Client<TTransport, TChain, TAccount>;\n environment: SmartAccountsEnvironment;\n}): CaveatEnforcerClient<TTransport, TChain, TAccount> {\n return client.extend(caveatEnforcerActions({ environment }));\n}\n\n// Re-export types for convenience\nexport type { CaveatEnforcerParams, PeriodTransferResult, StreamingResult };\n","import type { Transport, Chain, Hex, Client, Account } from 'viem';\nimport {\n createBundlerClient,\n type BundlerClient,\n type BundlerClientConfig,\n type SmartAccount,\n} from 'viem/account-abstraction';\n\n/**\n * Gas price tiers returned by pimlico_getUserOperationGasPrice\n */\nexport type GasPriceTier = {\n /** Maximum fee per gas in hex format */\n maxFeePerGas: Hex;\n /** Maximum priority fee per gas in hex format */\n maxPriorityFeePerGas: Hex;\n};\n\n/**\n * Response from pimlico_getUserOperationGasPrice RPC method\n */\nexport type UserOperationGasPriceResponse = {\n /** Slow gas price tier */\n slow: GasPriceTier;\n /** Standard gas price tier */\n standard: GasPriceTier;\n /** Fast gas price tier */\n fast: GasPriceTier;\n};\n\n/**\n * Pimlico bundler schema for type-safe RPC method calls\n */\n/* eslint-disable @typescript-eslint/naming-convention */\ntype PimlicoBundlerSchema = [\n {\n Method: 'pimlico_getUserOperationGasPrice';\n Parameters: [];\n ReturnType: UserOperationGasPriceResponse;\n },\n];\n\n/**\n * Infura bundler actions for extending bundler clients.\n *\n * @returns A function that takes a client and returns the client extension with Infura bundler actions.\n */\nconst infuraBundlerActions = () => (client: Client) => ({\n /**\n * Get user operation gas prices from Infura bundler.\n * Calls the pimlico_getUserOperationGasPrice RPC method.\n *\n * @returns Promise resolving to gas price tiers (slow, standard, fast).\n * @example\n * ```typescript\n * const gasPrices = await bundlerClient.getUserOperationGasPrice();\n * console.log(gasPrices.standard.maxFeePerGas);\n * ```\n */\n async getUserOperationGasPrice(): Promise<UserOperationGasPriceResponse> {\n const pimlicoClient = client as Client<\n Transport,\n Chain | undefined,\n Account | undefined,\n PimlicoBundlerSchema\n >;\n\n return await pimlicoClient.request({\n method: 'pimlico_getUserOperationGasPrice',\n params: [],\n });\n },\n});\n\n/**\n * Type for bundler client extended with Infura bundler actions.\n */\nexport type InfuraBundlerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = BundlerClient<TTransport, TChain, TAccount> & {\n /**\n * Get user operation gas prices from Infura bundler.\n * Calls the pimlico_getUserOperationGasPrice RPC method.\n *\n * @returns Promise resolving to gas price tiers (slow, standard, fast).\n */\n getUserOperationGasPrice(): Promise<UserOperationGasPriceResponse>;\n};\n\n/**\n * Creates an Infura bundler client extended with Infura bundler actions.\n *\n * This is a wrapper around viem's createBundlerClient that extends it with\n * the getUserOperationGasPrice method for retrieving gas prices from Pimlico's\n * bundler infrastructure via Infura's proxy.\n *\n * @param config - Configuration for the bundler client.\n * @returns Extended bundler client with Infura bundler actions.\n * @example\n * ```typescript\n * import { createPublicClient, http } from 'viem';\n * import { sepolia } from 'viem/chains';\n * import { createInfuraBundlerClient } from '@metamask/smart-accounts-kit';\n *\n * const publicClient = createPublicClient({\n * chain: sepolia,\n * transport: http('https://sepolia.infura.io/v3/YOUR_API_KEY'),\n * });\n *\n * const bundlerClient = createInfuraBundlerClient({\n * client: publicClient,\n * transport: http('https://sepolia.infura.io/v3/YOUR_API_KEY'),\n * chain: sepolia,\n * });\n *\n * // Use standard bundler methods\n * const userOpHash = await bundlerClient.sendUserOperation({...});\n *\n * // Use Infura specific methods\n * const gasPrices = await bundlerClient.getUserOperationGasPrice();\n * ```\n */\nexport function createInfuraBundlerClient<\n TTransport extends Transport,\n TChain extends Chain | undefined = undefined,\n TAccount extends SmartAccount | undefined = undefined,\n>(\n config: BundlerClientConfig<TTransport, TChain, TAccount>,\n): InfuraBundlerClient<TTransport, TChain, TAccount> {\n // Create the base bundler client using viem's function\n const baseBundlerClient = createBundlerClient(config);\n\n // Extend the client with Infura bundler actions\n return baseBundlerClient.extend(\n infuraBundlerActions(),\n ) as unknown as InfuraBundlerClient<TTransport, TChain, TAccount>;\n}\n"]}
package/dist/index.d.cts CHANGED
@@ -1,13 +1,13 @@
1
- import { I as Implementation, T as ToMetaMaskSmartAccountParameters, a as ToMetaMaskSmartAccountReturnType, C as Caveat, S as SmartAccountsEnvironment } from './types-qdEHxd5Q.cjs';
2
- export { A as AccountSignerConfig, k as CaveatType, D as Delegation, H as HybridDeleGatorDeployParams, g as HybridSignerConfig, e as MetaMaskSmartAccount, d as MetaMaskSmartAccountImplementation, M as MultiSigDeleGatorDeployParams, h as MultiSigSignerConfig, P as PermissionContext, j as ScopeType, c as SignDelegationParams, b as SignUserOperationParams, i as TransferWindow, W as WalletSignerConfig, f as WebAuthnSignerConfig } from './types-qdEHxd5Q.cjs';
3
- export { B as BalanceChangeType, g as Caveats, C as CreateDelegationOptions, f as CreateExecutionArgs, b as CreateOpenDelegationOptions, E as ExecutionMode, e as ExecutionStruct, c as createDelegation, d as createExecution, a as createOpenDelegation, s as signDelegation } from './delegation-DIriDFkq.cjs';
4
- export { P as PREFERRED_VERSION, g as getSmartAccountsEnvironment } from './smartAccountsEnvironment-Czw9KUYZ.cjs';
1
+ import { I as Implementation, T as ToMetaMaskSmartAccountParameters, a as ToMetaMaskSmartAccountReturnType, C as Caveat, S as SmartAccountsEnvironment } from './types-BWaH4KH1.cjs';
2
+ export { A as AccountSignerConfig, b as CaveatType, D as Delegation, H as HybridDeleGatorDeployParams, c as HybridSignerConfig, M as MetaMaskSmartAccount, d as MetaMaskSmartAccountImplementation, e as MultiSigDeleGatorDeployParams, f as MultiSigSignerConfig, P as PermissionContext, g as ScopeType, h as SignDelegationParams, i as SignUserOperationParams, j as TransferWindow, W as WalletSignerConfig, k as WebAuthnSignerConfig } from './types-BWaH4KH1.cjs';
3
+ export { B as BalanceChangeType, C as Caveats, a as CreateDelegationOptions, b as CreateExecutionArgs, c as CreateOpenDelegationOptions, E as ExecutionMode, d as ExecutionStruct, e as createDelegation, f as createExecution, g as createOpenDelegation, s as signDelegation } from './delegation-Ci3me5Rg.cjs';
4
+ export { P as PREFERRED_VERSION, g as getSmartAccountsEnvironment } from './smartAccountsEnvironment-BIcho7e0.cjs';
5
5
  import { Hex, Address, Transport, Chain, Account, Client } from 'viem';
6
6
  export { s as signUserOperation } from './userOp-DKgjzz7B.cjs';
7
- export { i as contracts } from './index-DC9baw8F.cjs';
8
- import { c as caveatEnforcerActions } from './index-Dvc4ir4O.cjs';
9
- export { i as actions } from './index-Dvc4ir4O.cjs';
10
- import { SmartAccount, BundlerClientConfig, BundlerClient } from 'viem/account-abstraction';
7
+ export { i as contracts } from './index-CSjEW7MJ.cjs';
8
+ import { c as caveatEnforcerActions } from './index-Uj_xXVko.cjs';
9
+ export { i as actions } from './index-Uj_xXVko.cjs';
10
+ import { SmartAccount, BundlerClient, BundlerClientConfig } from 'viem/account-abstraction';
11
11
  export { ANY_BENEFICIARY, ROOT_AUTHORITY } from '@metamask/delegation-core';
12
12
  import '@metamask/delegation-abis';
13
13
  import 'viem/chains';
package/dist/index.d.ts CHANGED
@@ -1,13 +1,13 @@
1
- import { I as Implementation, T as ToMetaMaskSmartAccountParameters, a as ToMetaMaskSmartAccountReturnType, C as Caveat, S as SmartAccountsEnvironment } from './types-qdEHxd5Q.js';
2
- export { A as AccountSignerConfig, k as CaveatType, D as Delegation, H as HybridDeleGatorDeployParams, g as HybridSignerConfig, e as MetaMaskSmartAccount, d as MetaMaskSmartAccountImplementation, M as MultiSigDeleGatorDeployParams, h as MultiSigSignerConfig, P as PermissionContext, j as ScopeType, c as SignDelegationParams, b as SignUserOperationParams, i as TransferWindow, W as WalletSignerConfig, f as WebAuthnSignerConfig } from './types-qdEHxd5Q.js';
3
- export { B as BalanceChangeType, g as Caveats, C as CreateDelegationOptions, f as CreateExecutionArgs, b as CreateOpenDelegationOptions, E as ExecutionMode, e as ExecutionStruct, c as createDelegation, d as createExecution, a as createOpenDelegation, s as signDelegation } from './delegation-CvVXs0PO.js';
4
- export { P as PREFERRED_VERSION, g as getSmartAccountsEnvironment } from './smartAccountsEnvironment-u1CcFcGE.js';
1
+ import { I as Implementation, T as ToMetaMaskSmartAccountParameters, a as ToMetaMaskSmartAccountReturnType, C as Caveat, S as SmartAccountsEnvironment } from './types-BWaH4KH1.js';
2
+ export { A as AccountSignerConfig, b as CaveatType, D as Delegation, H as HybridDeleGatorDeployParams, c as HybridSignerConfig, M as MetaMaskSmartAccount, d as MetaMaskSmartAccountImplementation, e as MultiSigDeleGatorDeployParams, f as MultiSigSignerConfig, P as PermissionContext, g as ScopeType, h as SignDelegationParams, i as SignUserOperationParams, j as TransferWindow, W as WalletSignerConfig, k as WebAuthnSignerConfig } from './types-BWaH4KH1.js';
3
+ export { B as BalanceChangeType, C as Caveats, a as CreateDelegationOptions, b as CreateExecutionArgs, c as CreateOpenDelegationOptions, E as ExecutionMode, d as ExecutionStruct, e as createDelegation, f as createExecution, g as createOpenDelegation, s as signDelegation } from './delegation-DgmIOh21.js';
4
+ export { P as PREFERRED_VERSION, g as getSmartAccountsEnvironment } from './smartAccountsEnvironment-Bso0CIWt.js';
5
5
  import { Hex, Address, Transport, Chain, Account, Client } from 'viem';
6
6
  export { s as signUserOperation } from './userOp-DKgjzz7B.js';
7
- export { i as contracts } from './index-ChTryO1-.js';
8
- import { c as caveatEnforcerActions } from './index-5EdxVa_d.js';
9
- export { i as actions } from './index-5EdxVa_d.js';
10
- import { SmartAccount, BundlerClientConfig, BundlerClient } from 'viem/account-abstraction';
7
+ export { i as contracts } from './index-UF6eCzBC.js';
8
+ import { c as caveatEnforcerActions } from './index-D7fBuNV-.js';
9
+ export { i as actions } from './index-D7fBuNV-.js';
10
+ import { SmartAccount, BundlerClient, BundlerClientConfig } from 'viem/account-abstraction';
11
11
  export { ANY_BENEFICIARY, ROOT_AUTHORITY } from '@metamask/delegation-core';
12
12
  import '@metamask/delegation-abis';
13
13
  import 'viem/chains';
package/dist/index.mjs CHANGED
@@ -4,9 +4,8 @@ import {
4
4
  isValid7702Implementation
5
5
  } from "./chunk-NOCLGZGB.mjs";
6
6
  import {
7
- contracts_exports,
8
- read
9
- } from "./chunk-33AMUJBJ.mjs";
7
+ contracts_exports
8
+ } from "./chunk-YSBBRLMT.mjs";
10
9
  import "./chunk-YTELOQ4I.mjs";
11
10
  import {
12
11
  createDummyWebAuthnSignature,
@@ -231,7 +230,8 @@ async function toMetaMaskSmartAccount(params) {
231
230
  const {
232
231
  client,
233
232
  client: { chain },
234
- implementation
233
+ implementation,
234
+ nonceKeyManager
235
235
  } = params;
236
236
  if (!chain) {
237
237
  throw new Error("Chain not specified");
@@ -339,12 +339,6 @@ async function toMetaMaskSmartAccount(params) {
339
339
  return signature;
340
340
  };
341
341
  const getAddress = async () => address;
342
- const getNonce = async () => read({
343
- client,
344
- entryPoint: environment.EntryPoint,
345
- contractAddress: address,
346
- key: 0n
347
- });
348
342
  const encodeCalls = async (calls) => encodeCallsForCaller(address, calls);
349
343
  const signerMethods = signer ?? {
350
344
  signMessage: async () => {
@@ -371,9 +365,9 @@ async function toMetaMaskSmartAccount(params) {
371
365
  getAddress,
372
366
  getFactoryArgs,
373
367
  encodeCalls,
374
- getNonce,
375
368
  signUserOperation: signUserOperation2,
376
369
  signDelegation: signDelegation2,
370
+ nonceKeyManager,
377
371
  ...signerMethods
378
372
  });
379
373
  if (implementation === "Stateless7702" /* Stateless7702 */) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/toMetaMaskSmartAccount.ts","../src/signer.ts","../src/signatures.ts","../src/actions/caveatEnforcerClient.ts","../src/actions/infuraBundlerClient.ts"],"sourcesContent":["import {\n EIP7702StatelessDeleGator,\n HybridDeleGator,\n MultiSigDeleGator,\n} from '@metamask/delegation-abis';\nimport { type Address, type Hex } from 'viem';\nimport {\n entryPoint07Abi,\n toPackedUserOperation,\n toSmartAccount,\n} from 'viem/account-abstraction';\n\nimport { isValid7702Implementation } from './actions/isValid7702Implementation';\nimport { Implementation } from './constants';\nimport { getCounterfactualAccountData } from './counterfactualAccountData';\nimport {\n SIGNABLE_DELEGATION_TYPED_DATA,\n toDelegationStruct,\n} from './delegation';\nimport { entryPointGetNonce as _getNonce } from './DelegationFramework/EntryPoint/read';\nimport { encodeCallsForCaller } from './encodeCalls';\nimport { resolveSigner } from './signer';\nimport { getSmartAccountsEnvironment } from './smartAccountsEnvironment';\nimport type {\n Call,\n ToMetaMaskSmartAccountParameters,\n ToMetaMaskSmartAccountReturnType,\n SignDelegationParams,\n SignUserOperationParams,\n AbiByImplementation,\n} from './types';\nimport { SIGNABLE_USER_OP_TYPED_DATA } from './userOp';\n\nconst ENTRYPOINT_VERSION = '0.7' as const;\n\n/**\n * Creates a MetaMask DeleGator smart account instance.\n *\n * @template TImplementation - The type of implementation, extending Implementation.\n * @param params - The parameters for creating the smart account.\n * @returns A promise that resolves to a MetaMaskSmartAccount instance.\n * @description\n * This function sets up a MetaMask DeleGator smart account with the specified implementation.\n * It handles both deployed accounts, and counterfactual accounts.\n * A caller may specify a SmartAccountsEnvironment, otherwise the environment will be inferred from the chain.\n */\nexport async function toMetaMaskSmartAccount<\n TImplementation extends Implementation,\n>(\n params: ToMetaMaskSmartAccountParameters<TImplementation>,\n): Promise<ToMetaMaskSmartAccountReturnType<TImplementation>> {\n const {\n client,\n client: { chain },\n implementation,\n } = params;\n\n if (!chain) {\n throw new Error('Chain not specified');\n }\n\n const signer = resolveSigner({\n implementation,\n signer: params.signer,\n });\n\n const environment =\n params.environment ?? getSmartAccountsEnvironment(chain.id);\n\n let address: Address, factoryData: Hex | undefined;\n\n if (params.address) {\n factoryData = undefined;\n address = params.address;\n } else {\n if (implementation === Implementation.Stateless7702) {\n throw new Error('Stateless7702 does not support counterfactual accounts');\n }\n\n const accountData = await getCounterfactualAccountData({\n factory: environment.SimpleFactory,\n implementations: environment.implementations,\n implementation,\n deployParams: params.deployParams,\n deploySalt: params.deploySalt,\n });\n\n address = accountData.address;\n factoryData = accountData.factoryData;\n }\n\n const entryPoint = {\n abi: entryPoint07Abi,\n address: environment.EntryPoint,\n version: ENTRYPOINT_VERSION,\n } as const;\n\n const { abi, contractName } = {\n [Implementation.Hybrid]: {\n contractName: 'HybridDeleGator',\n abi: HybridDeleGator,\n },\n [Implementation.MultiSig]: {\n contractName: 'MultiSigDeleGator',\n abi: MultiSigDeleGator,\n },\n [Implementation.Stateless7702]: {\n contractName: 'EIP7702StatelessDeleGator',\n abi: EIP7702StatelessDeleGator,\n },\n }[implementation] as {\n contractName: string;\n abi: AbiByImplementation[TImplementation];\n };\n\n const getFactoryArgs = async () => {\n if (factoryData === undefined) {\n throw new Error(\n 'Deploy params were not provided, so factory args cannot be inferred',\n );\n }\n return {\n factoryData,\n factory: environment.SimpleFactory,\n };\n };\n\n const signDelegation = async (delegationParams: SignDelegationParams) => {\n if (!signer) {\n throw new Error(\n 'Cannot sign delegation: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n }\n\n const { delegation, chainId } = delegationParams;\n\n const delegationStruct = toDelegationStruct({\n ...delegation,\n signature: '0x',\n });\n\n const signature = await signer.signTypedData({\n domain: {\n chainId: chainId ?? chain.id,\n name: 'DelegationManager',\n version: '1',\n verifyingContract: environment.DelegationManager,\n },\n types: SIGNABLE_DELEGATION_TYPED_DATA,\n primaryType: 'Delegation',\n message: delegationStruct,\n });\n\n return signature;\n };\n\n const signUserOperation = async (userOpParams: SignUserOperationParams) => {\n if (!signer) {\n throw new Error(\n 'Cannot sign user operation: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n }\n\n const { chainId } = userOpParams;\n\n const packedUserOp = toPackedUserOperation({\n sender: address,\n ...userOpParams,\n signature: '0x',\n });\n\n const signature = await signer.signTypedData({\n domain: {\n chainId: chainId ?? chain.id,\n name: contractName,\n version: '1',\n verifyingContract: address,\n },\n types: SIGNABLE_USER_OP_TYPED_DATA,\n primaryType: 'PackedUserOperation',\n message: { ...packedUserOp, entryPoint: entryPoint.address },\n });\n\n return signature;\n };\n\n const getAddress = async () => address;\n\n const getNonce = async () =>\n _getNonce({\n client,\n entryPoint: environment.EntryPoint,\n contractAddress: address,\n key: 0n,\n });\n\n const encodeCalls = async (calls: readonly Call[]) =>\n encodeCallsForCaller(address, calls);\n\n const signerMethods = signer ?? {\n signMessage: async () => {\n throw new Error(\n 'Cannot sign message: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n signTypedData: async () => {\n throw new Error(\n 'Cannot sign typed data: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n getStubSignature: async () => {\n throw new Error(\n 'Cannot get stub signature: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n };\n\n const smartAccount = await toSmartAccount({\n abi,\n client,\n entryPoint,\n environment,\n getAddress,\n getFactoryArgs,\n encodeCalls,\n getNonce,\n signUserOperation,\n signDelegation,\n ...signerMethods,\n });\n\n // Override isDeployed only for EIP-7702 implementation to check proper delegation code\n if (implementation === Implementation.Stateless7702) {\n return {\n ...smartAccount,\n isDeployed: async () =>\n isValid7702Implementation({\n client,\n accountAddress: address,\n environment,\n }),\n };\n }\n\n // For other implementations, use the default isDeployed behavior\n return smartAccount;\n}\n","import { concat } from 'viem';\nimport type {\n Address,\n SignableMessage,\n TypedData,\n TypedDataDefinition,\n} from 'viem';\nimport type { WebAuthnAccount } from 'viem/account-abstraction';\n\nimport { Implementation } from './constants';\nimport { aggregateSignature } from './signatures';\nimport type {\n AccountSignerConfig,\n HybridSignerConfig,\n InternalSigner,\n MultiSigSignerConfig,\n SignerConfigByImplementation,\n Stateless7702SignerConfig,\n WalletSignerConfig,\n} from './types';\nimport {\n createDummyWebAuthnSignature,\n encodeDeleGatorSignature,\n} from './webAuthn';\n\n// A valid ECDSA signature, this must be able to ecrecover an address, otherwise the contracts will revert in isValidSignature\nconst EOA_STUB_SIGNATURE =\n '0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000011b' as const;\n\nconst resolveSignerFromWalletConfig = (\n config: WalletSignerConfig,\n): InternalSigner => {\n return {\n signMessage: config.walletClient.signMessage,\n signTypedData: async (typedData) => {\n // todo: figure out this type so that we don't need the type assertion\n return config.walletClient.signTypedData(typedData as any);\n },\n getStubSignature: async () => EOA_STUB_SIGNATURE,\n };\n};\n\nconst resolveSignerFromAccountConfig = (config: AccountSignerConfig) => {\n return {\n signMessage: config.account.signMessage,\n signTypedData: config.account.signTypedData,\n getStubSignature: async () => EOA_STUB_SIGNATURE,\n };\n};\n\nconst resolveHybridSigner = (config: HybridSignerConfig): InternalSigner => {\n if ('walletClient' in config) {\n return resolveSignerFromWalletConfig(config);\n } else if ('account' in config) {\n const { signMessage, signTypedData, getStubSignature } =\n resolveSignerFromAccountConfig(config);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n }\n const { keyId, webAuthnAccount } = config;\n\n if (webAuthnAccount.type !== 'webAuthn') {\n throw new Error('Account is not a webAuthn account');\n }\n\n const encodeSignature = (\n result: Awaited<ReturnType<WebAuthnAccount['signMessage']>>,\n ) =>\n encodeDeleGatorSignature(\n keyId,\n result.signature,\n result.webauthn.clientDataJSON,\n result.webauthn.authenticatorData,\n );\n\n const signMessage = async (args: { message: SignableMessage }) =>\n webAuthnAccount.signMessage(args).then(encodeSignature);\n const signTypedData = async <\n const TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(\n typedDataDefinition: TypedDataDefinition<TTypedData, TPrimaryType>,\n ) => webAuthnAccount.signTypedData(typedDataDefinition).then(encodeSignature);\n\n const getStubSignature = async () => createDummyWebAuthnSignature(keyId);\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n};\n\nconst resolveMultiSigSigner = (\n config: MultiSigSignerConfig,\n): InternalSigner => {\n const resolvedSigners = config.map((signer) => {\n let individualSignMessage: InternalSigner['signMessage'];\n let individualSignTypedData: InternalSigner['signTypedData'];\n let address: Address;\n if ('walletClient' in signer) {\n const { signMessage, signTypedData } =\n resolveSignerFromWalletConfig(signer);\n individualSignMessage = signMessage;\n individualSignTypedData = signTypedData;\n\n address = signer.walletClient.account.address;\n } else {\n const { signMessage, signTypedData } =\n resolveSignerFromAccountConfig(signer);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n\n individualSignMessage = signMessage;\n individualSignTypedData = signTypedData;\n\n address = signer.account.address;\n }\n return {\n address,\n individualSignMessage,\n individualSignTypedData,\n };\n });\n\n const signMessage = async (args: { message: SignableMessage }) => {\n const addressAndSignatures = resolvedSigners.map(\n async ({ individualSignMessage, address }) => ({\n signature: await individualSignMessage(args),\n signer: address,\n type: 'ECDSA' as const,\n }),\n );\n\n const signatures = await Promise.all(addressAndSignatures);\n\n return aggregateSignature({\n signatures,\n });\n };\n\n const signTypedData = async <\n const TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(\n typedDataDefinition: TypedDataDefinition<TTypedData, TPrimaryType>,\n ) => {\n const addressAndSignatures = resolvedSigners.map(\n async ({ individualSignTypedData, address }) => ({\n signature: await individualSignTypedData(typedDataDefinition),\n signer: address,\n type: 'ECDSA' as const,\n }),\n );\n\n const signatures = await Promise.all(addressAndSignatures);\n\n return aggregateSignature({\n signatures,\n });\n };\n\n const getStubSignature = async () =>\n concat(resolvedSigners.map(() => EOA_STUB_SIGNATURE));\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n};\n\nconst resolveStateless7702Signer = (\n config: Stateless7702SignerConfig,\n): InternalSigner => {\n if ('walletClient' in config) {\n return resolveSignerFromWalletConfig(config);\n } else if ('account' in config) {\n const { signMessage, signTypedData, getStubSignature } =\n resolveSignerFromAccountConfig(config);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n }\n\n throw new Error('Invalid signer config');\n};\n\n/**\n * Resolve a signer from a configuration object.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner;\n\n/**\n * Resolve a signer from a configuration object. If no signer is provided, return null.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer or null if no signer is provided.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer?: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner | null;\n\n/**\n * Resolve a signer from a configuration object. If no signer is provided, return null.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer or null if no signer is provided.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer?: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner | null {\n const { implementation, signer } = config;\n\n if (!signer) {\n return null;\n }\n\n if (implementation === Implementation.Hybrid) {\n return resolveHybridSigner(signer as HybridSignerConfig);\n } else if (implementation === Implementation.MultiSig) {\n return resolveMultiSigSigner(signer as MultiSigSignerConfig);\n } else if (implementation === Implementation.Stateless7702) {\n return resolveStateless7702Signer(signer as Stateless7702SignerConfig);\n }\n throw new Error(`Implementation type '${implementation}' not supported`);\n}\n","import type { Address, Hex } from 'viem';\nimport { concat } from 'viem';\n\nconst signatureTypes = ['ECDSA'] as const;\n\nexport type SignatureType = (typeof signatureTypes)[number];\n\n/**\n * Represents a partial signature that can be aggregated with others.\n */\nexport type PartialSignature = {\n signer: Address;\n signature: Hex;\n type: SignatureType;\n};\n\n/**\n * Aggregates signatures into a single signature as expected by the MultiSig implementation.\n *\n * @param params - The parameters for signature aggregation.\n * @param params.signatures - The array of partial signatures to aggregate.\n * @returns The aggregated signature.\n */\nexport const aggregateSignature = ({\n signatures,\n}: {\n signatures: PartialSignature[];\n}): Hex => {\n if (signatures.length === 0) {\n return '0x';\n }\n\n for (const { type } of signatures) {\n if (!signatureTypes.includes(type)) {\n throw new Error(`Invalid signature type: ${type}`);\n }\n }\n\n // Sort signatures by signer address as required by MultiSig implementation\n const sortedSignatures = [...signatures].sort((a, b) =>\n a.signer.localeCompare(b.signer),\n );\n\n // Concatenate all signatures\n return concat(sortedSignatures.map(({ signature }) => signature));\n};\n\n/**\n * Type definition for the aggregateSignature function parameters.\n */\nexport type AggregateSignatureParams = {\n signatures: PartialSignature[];\n};\n","import type { Client, Transport, Chain, Account } from 'viem';\n\nimport type { SmartAccountsEnvironment } from '../types';\nimport {\n caveatEnforcerActions,\n type CaveatEnforcerParams,\n type PeriodTransferResult,\n type StreamingResult,\n} from './getCaveatAvailableAmount';\n\n/**\n * Type for client extended with caveat enforcer actions.\n */\nexport type CaveatEnforcerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends Account | undefined = Account | undefined,\n> = Client<TTransport, TChain, TAccount> &\n ReturnType<ReturnType<typeof caveatEnforcerActions>>;\n\n/**\n * Create a viem client extended with caveat enforcer actions.\n *\n * @param params - The parameters object.\n * @param params.client - The viem client.\n * @param params.environment - The SmartAccountsEnvironment.\n * @returns The extended client with caveat enforcer actions.\n */\nexport function createCaveatEnforcerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends Account | undefined = Account | undefined,\n>({\n client,\n environment,\n}: {\n client: Client<TTransport, TChain, TAccount>;\n environment: SmartAccountsEnvironment;\n}): CaveatEnforcerClient<TTransport, TChain, TAccount> {\n return client.extend(caveatEnforcerActions({ environment }));\n}\n\n// Re-export types for convenience\nexport type { CaveatEnforcerParams, PeriodTransferResult, StreamingResult };\n","import type { Transport, Chain, Hex, Client, Account } from 'viem';\nimport {\n createBundlerClient,\n type BundlerClient,\n type BundlerClientConfig,\n type SmartAccount,\n} from 'viem/account-abstraction';\n\n/**\n * Gas price tiers returned by pimlico_getUserOperationGasPrice\n */\nexport type GasPriceTier = {\n /** Maximum fee per gas in hex format */\n maxFeePerGas: Hex;\n /** Maximum priority fee per gas in hex format */\n maxPriorityFeePerGas: Hex;\n};\n\n/**\n * Response from pimlico_getUserOperationGasPrice RPC method\n */\nexport type UserOperationGasPriceResponse = {\n /** Slow gas price tier */\n slow: GasPriceTier;\n /** Standard gas price tier */\n standard: GasPriceTier;\n /** Fast gas price tier */\n fast: GasPriceTier;\n};\n\n/**\n * Pimlico bundler schema for type-safe RPC method calls\n */\n/* eslint-disable @typescript-eslint/naming-convention */\ntype PimlicoBundlerSchema = [\n {\n Method: 'pimlico_getUserOperationGasPrice';\n Parameters: [];\n ReturnType: UserOperationGasPriceResponse;\n },\n];\n\n/**\n * Infura bundler actions for extending bundler clients.\n *\n * @returns A function that takes a client and returns the client extension with Infura bundler actions.\n */\nconst infuraBundlerActions = () => (client: Client) => ({\n /**\n * Get user operation gas prices from Infura bundler.\n * Calls the pimlico_getUserOperationGasPrice RPC method.\n *\n * @returns Promise resolving to gas price tiers (slow, standard, fast).\n * @example\n * ```typescript\n * const gasPrices = await bundlerClient.getUserOperationGasPrice();\n * console.log(gasPrices.standard.maxFeePerGas);\n * ```\n */\n async getUserOperationGasPrice(): Promise<UserOperationGasPriceResponse> {\n const pimlicoClient = client as Client<\n Transport,\n Chain | undefined,\n Account | undefined,\n PimlicoBundlerSchema\n >;\n\n return await pimlicoClient.request({\n method: 'pimlico_getUserOperationGasPrice',\n params: [],\n });\n },\n});\n\n/**\n * Type for bundler client extended with Infura bundler actions.\n */\nexport type InfuraBundlerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = BundlerClient<TTransport, TChain, TAccount> & {\n /**\n * Get user operation gas prices from Infura bundler.\n * Calls the pimlico_getUserOperationGasPrice RPC method.\n *\n * @returns Promise resolving to gas price tiers (slow, standard, fast).\n */\n getUserOperationGasPrice(): Promise<UserOperationGasPriceResponse>;\n};\n\n/**\n * Creates an Infura bundler client extended with Infura bundler actions.\n *\n * This is a wrapper around viem's createBundlerClient that extends it with\n * the getUserOperationGasPrice method for retrieving gas prices from Pimlico's\n * bundler infrastructure via Infura's proxy.\n *\n * @param config - Configuration for the bundler client.\n * @returns Extended bundler client with Infura bundler actions.\n * @example\n * ```typescript\n * import { createPublicClient, http } from 'viem';\n * import { sepolia } from 'viem/chains';\n * import { createInfuraBundlerClient } from '@metamask/smart-accounts-kit';\n *\n * const publicClient = createPublicClient({\n * chain: sepolia,\n * transport: http('https://sepolia.infura.io/v3/YOUR_API_KEY'),\n * });\n *\n * const bundlerClient = createInfuraBundlerClient({\n * client: publicClient,\n * transport: http('https://sepolia.infura.io/v3/YOUR_API_KEY'),\n * chain: sepolia,\n * });\n *\n * // Use standard bundler methods\n * const userOpHash = await bundlerClient.sendUserOperation({...});\n *\n * // Use Infura specific methods\n * const gasPrices = await bundlerClient.getUserOperationGasPrice();\n * ```\n */\nexport function createInfuraBundlerClient<\n TTransport extends Transport,\n TChain extends Chain | undefined = undefined,\n TAccount extends SmartAccount | undefined = undefined,\n>(\n config: BundlerClientConfig<TTransport, TChain, TAccount>,\n): InfuraBundlerClient<TTransport, TChain, TAccount> {\n // Create the base bundler client using viem's function\n const baseBundlerClient = createBundlerClient(config);\n\n // Extend the client with Infura bundler actions\n return baseBundlerClient.extend(\n infuraBundlerActions(),\n ) as unknown as InfuraBundlerClient<TTransport, TChain, TAccount>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAEP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;;;ACVP,SAAS,UAAAA,eAAc;;;ACCvB,SAAS,cAAc;AAEvB,IAAM,iBAAiB,CAAC,OAAO;AAoBxB,IAAM,qBAAqB,CAAC;AAAA,EACjC;AACF,MAEW;AACT,MAAI,WAAW,WAAW,GAAG;AAC3B,WAAO;AAAA,EACT;AAEA,aAAW,EAAE,KAAK,KAAK,YAAY;AACjC,QAAI,CAAC,eAAe,SAAS,IAAI,GAAG;AAClC,YAAM,IAAI,MAAM,2BAA2B,IAAI,EAAE;AAAA,IACnD;AAAA,EACF;AAGA,QAAM,mBAAmB,CAAC,GAAG,UAAU,EAA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,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,IACA,kBAAkB,YAAY;AAC5B,YAAM,IAAI;AAAA,QACR;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAEA,QAAM,eAAe,MAAM,eAAe;AAAA,IACxC;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA,mBAAAA;AAAA,IACA,gBAAAD;AAAA,IACA,GAAG;AAAA,EACL,CAAC;AAGD,MAAI,wDAAiD;AACnD,WAAO;AAAA,MACL,GAAG;AAAA,MACH,YAAY,YACV,0BAA0B;AAAA,QACxB;AAAA,QACA,gBAAgB;AAAA,QAChB;AAAA,MACF,CAAC;AAAA,IACL;AAAA,EACF;AAGA,SAAO;AACT;;;AG1NO,SAAS,2BAId;AAAA,EACA;AAAA,EACA;AACF,GAGuD;AACrD,SAAO,OAAO,OAAO,sBAAsB,EAAE,YAAY,CAAC,CAAC;AAC7D;;;ACvCA;AAAA,EACE;AAAA,OAIK;AAyCP,IAAM,uBAAuB,MAAM,CAAC,YAAoB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAYtD,MAAM,2BAAmE;AACvE,UAAM,gBAAgB;AAOtB,WAAO,MAAM,cAAc,QAAQ;AAAA,MACjC,QAAQ;AAAA,MACR,QAAQ,CAAC;AAAA,IACX,CAAC;AAAA,EACH;AACF;AAoDO,SAAS,0BAKd,QACmD;AAEnD,QAAM,oBAAoB,oBAAoB,MAAM;AAGpD,SAAO,kBAAkB;AAAA,IACvB,qBAAqB;AAAA,EACvB;AACF;","names":["concat","signMessage","signTypedData","getStubSignature","concat","signDelegation","signUserOperation"]}
1
+ {"version":3,"sources":["../src/toMetaMaskSmartAccount.ts","../src/signer.ts","../src/signatures.ts","../src/actions/caveatEnforcerClient.ts","../src/actions/infuraBundlerClient.ts"],"sourcesContent":["import {\n EIP7702StatelessDeleGator,\n HybridDeleGator,\n MultiSigDeleGator,\n} from '@metamask/delegation-abis';\nimport { type Address, type Hex } from 'viem';\nimport {\n entryPoint07Abi,\n toPackedUserOperation,\n toSmartAccount,\n} from 'viem/account-abstraction';\n\nimport { isValid7702Implementation } from './actions/isValid7702Implementation';\nimport { Implementation } from './constants';\nimport { getCounterfactualAccountData } from './counterfactualAccountData';\nimport {\n SIGNABLE_DELEGATION_TYPED_DATA,\n toDelegationStruct,\n} from './delegation';\nimport { encodeCallsForCaller } from './encodeCalls';\nimport { resolveSigner } from './signer';\nimport { getSmartAccountsEnvironment } from './smartAccountsEnvironment';\nimport type {\n Call,\n ToMetaMaskSmartAccountParameters,\n ToMetaMaskSmartAccountReturnType,\n SignDelegationParams,\n SignUserOperationParams,\n AbiByImplementation,\n} from './types';\nimport { SIGNABLE_USER_OP_TYPED_DATA } from './userOp';\n\nconst ENTRYPOINT_VERSION = '0.7' as const;\n\n/**\n * Creates a MetaMask DeleGator smart account instance.\n *\n * @template TImplementation - The type of implementation, extending Implementation.\n * @param params - The parameters for creating the smart account.\n * @returns A promise that resolves to a MetaMaskSmartAccount instance.\n * @description\n * This function sets up a MetaMask DeleGator smart account with the specified implementation.\n * It handles both deployed accounts, and counterfactual accounts.\n * A caller may specify a SmartAccountsEnvironment, otherwise the environment will be inferred from the chain.\n */\nexport async function toMetaMaskSmartAccount<\n TImplementation extends Implementation,\n>(\n params: ToMetaMaskSmartAccountParameters<TImplementation>,\n): Promise<ToMetaMaskSmartAccountReturnType<TImplementation>> {\n const {\n client,\n client: { chain },\n implementation,\n nonceKeyManager,\n } = params;\n\n if (!chain) {\n throw new Error('Chain not specified');\n }\n\n const signer = resolveSigner({\n implementation,\n signer: params.signer,\n });\n\n const environment =\n params.environment ?? getSmartAccountsEnvironment(chain.id);\n\n let address: Address, factoryData: Hex | undefined;\n\n if (params.address) {\n factoryData = undefined;\n address = params.address;\n } else {\n if (implementation === Implementation.Stateless7702) {\n throw new Error('Stateless7702 does not support counterfactual accounts');\n }\n\n const accountData = await getCounterfactualAccountData({\n factory: environment.SimpleFactory,\n implementations: environment.implementations,\n implementation,\n deployParams: params.deployParams,\n deploySalt: params.deploySalt,\n });\n\n address = accountData.address;\n factoryData = accountData.factoryData;\n }\n\n const entryPoint = {\n abi: entryPoint07Abi,\n address: environment.EntryPoint,\n version: ENTRYPOINT_VERSION,\n } as const;\n\n const { abi, contractName } = {\n [Implementation.Hybrid]: {\n contractName: 'HybridDeleGator',\n abi: HybridDeleGator,\n },\n [Implementation.MultiSig]: {\n contractName: 'MultiSigDeleGator',\n abi: MultiSigDeleGator,\n },\n [Implementation.Stateless7702]: {\n contractName: 'EIP7702StatelessDeleGator',\n abi: EIP7702StatelessDeleGator,\n },\n }[implementation] as {\n contractName: string;\n abi: AbiByImplementation[TImplementation];\n };\n\n const getFactoryArgs = async () => {\n if (factoryData === undefined) {\n throw new Error(\n 'Deploy params were not provided, so factory args cannot be inferred',\n );\n }\n return {\n factoryData,\n factory: environment.SimpleFactory,\n };\n };\n\n const signDelegation = async (delegationParams: SignDelegationParams) => {\n if (!signer) {\n throw new Error(\n 'Cannot sign delegation: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n }\n\n const { delegation, chainId } = delegationParams;\n\n const delegationStruct = toDelegationStruct({\n ...delegation,\n signature: '0x',\n });\n\n const signature = await signer.signTypedData({\n domain: {\n chainId: chainId ?? chain.id,\n name: 'DelegationManager',\n version: '1',\n verifyingContract: environment.DelegationManager,\n },\n types: SIGNABLE_DELEGATION_TYPED_DATA,\n primaryType: 'Delegation',\n message: delegationStruct,\n });\n\n return signature;\n };\n\n const signUserOperation = async (userOpParams: SignUserOperationParams) => {\n if (!signer) {\n throw new Error(\n 'Cannot sign user operation: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n }\n\n const { chainId } = userOpParams;\n\n const packedUserOp = toPackedUserOperation({\n sender: address,\n ...userOpParams,\n signature: '0x',\n });\n\n const signature = await signer.signTypedData({\n domain: {\n chainId: chainId ?? chain.id,\n name: contractName,\n version: '1',\n verifyingContract: address,\n },\n types: SIGNABLE_USER_OP_TYPED_DATA,\n primaryType: 'PackedUserOperation',\n message: { ...packedUserOp, entryPoint: entryPoint.address },\n });\n\n return signature;\n };\n\n const getAddress = async () => address;\n\n const encodeCalls = async (calls: readonly Call[]) =>\n encodeCallsForCaller(address, calls);\n\n const signerMethods = signer ?? {\n signMessage: async () => {\n throw new Error(\n 'Cannot sign message: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n signTypedData: async () => {\n throw new Error(\n 'Cannot sign typed data: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n getStubSignature: async () => {\n throw new Error(\n 'Cannot get stub signature: signer not provided. Specify a signer in toMetaMaskSmartAccount() to perform signing operations.',\n );\n },\n };\n\n const smartAccount = await toSmartAccount({\n abi,\n client,\n entryPoint,\n environment,\n getAddress,\n getFactoryArgs,\n encodeCalls,\n signUserOperation,\n signDelegation,\n nonceKeyManager,\n ...signerMethods,\n });\n\n // Override isDeployed only for EIP-7702 implementation to check proper delegation code\n if (implementation === Implementation.Stateless7702) {\n return {\n ...smartAccount,\n isDeployed: async () =>\n isValid7702Implementation({\n client,\n accountAddress: address,\n environment,\n }),\n };\n }\n\n // For other implementations, use the default isDeployed behavior\n return smartAccount;\n}\n","import { concat } from 'viem';\nimport type {\n Address,\n SignableMessage,\n TypedData,\n TypedDataDefinition,\n} from 'viem';\nimport type { WebAuthnAccount } from 'viem/account-abstraction';\n\nimport { Implementation } from './constants';\nimport { aggregateSignature } from './signatures';\nimport type {\n AccountSignerConfig,\n HybridSignerConfig,\n InternalSigner,\n MultiSigSignerConfig,\n SignerConfigByImplementation,\n Stateless7702SignerConfig,\n WalletSignerConfig,\n} from './types';\nimport {\n createDummyWebAuthnSignature,\n encodeDeleGatorSignature,\n} from './webAuthn';\n\n// A valid ECDSA signature, this must be able to ecrecover an address, otherwise the contracts will revert in isValidSignature\nconst EOA_STUB_SIGNATURE =\n '0x000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000000011b' as const;\n\nconst resolveSignerFromWalletConfig = (\n config: WalletSignerConfig,\n): InternalSigner => {\n return {\n signMessage: config.walletClient.signMessage,\n signTypedData: async (typedData) => {\n // todo: figure out this type so that we don't need the type assertion\n return config.walletClient.signTypedData(typedData as any);\n },\n getStubSignature: async () => EOA_STUB_SIGNATURE,\n };\n};\n\nconst resolveSignerFromAccountConfig = (config: AccountSignerConfig) => {\n return {\n signMessage: config.account.signMessage,\n signTypedData: config.account.signTypedData,\n getStubSignature: async () => EOA_STUB_SIGNATURE,\n };\n};\n\nconst resolveHybridSigner = (config: HybridSignerConfig): InternalSigner => {\n if ('walletClient' in config) {\n return resolveSignerFromWalletConfig(config);\n } else if ('account' in config) {\n const { signMessage, signTypedData, getStubSignature } =\n resolveSignerFromAccountConfig(config);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n }\n const { keyId, webAuthnAccount } = config;\n\n if (webAuthnAccount.type !== 'webAuthn') {\n throw new Error('Account is not a webAuthn account');\n }\n\n const encodeSignature = (\n result: Awaited<ReturnType<WebAuthnAccount['signMessage']>>,\n ) =>\n encodeDeleGatorSignature(\n keyId,\n result.signature,\n result.webauthn.clientDataJSON,\n result.webauthn.authenticatorData,\n );\n\n const signMessage = async (args: { message: SignableMessage }) =>\n webAuthnAccount.signMessage(args).then(encodeSignature);\n const signTypedData = async <\n const TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(\n typedDataDefinition: TypedDataDefinition<TTypedData, TPrimaryType>,\n ) => webAuthnAccount.signTypedData(typedDataDefinition).then(encodeSignature);\n\n const getStubSignature = async () => createDummyWebAuthnSignature(keyId);\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n};\n\nconst resolveMultiSigSigner = (\n config: MultiSigSignerConfig,\n): InternalSigner => {\n const resolvedSigners = config.map((signer) => {\n let individualSignMessage: InternalSigner['signMessage'];\n let individualSignTypedData: InternalSigner['signTypedData'];\n let address: Address;\n if ('walletClient' in signer) {\n const { signMessage, signTypedData } =\n resolveSignerFromWalletConfig(signer);\n individualSignMessage = signMessage;\n individualSignTypedData = signTypedData;\n\n address = signer.walletClient.account.address;\n } else {\n const { signMessage, signTypedData } =\n resolveSignerFromAccountConfig(signer);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n\n individualSignMessage = signMessage;\n individualSignTypedData = signTypedData;\n\n address = signer.account.address;\n }\n return {\n address,\n individualSignMessage,\n individualSignTypedData,\n };\n });\n\n const signMessage = async (args: { message: SignableMessage }) => {\n const addressAndSignatures = resolvedSigners.map(\n async ({ individualSignMessage, address }) => ({\n signature: await individualSignMessage(args),\n signer: address,\n type: 'ECDSA' as const,\n }),\n );\n\n const signatures = await Promise.all(addressAndSignatures);\n\n return aggregateSignature({\n signatures,\n });\n };\n\n const signTypedData = async <\n const TTypedData extends TypedData | Record<string, unknown>,\n TPrimaryType extends keyof TTypedData | 'EIP712Domain' = keyof TTypedData,\n >(\n typedDataDefinition: TypedDataDefinition<TTypedData, TPrimaryType>,\n ) => {\n const addressAndSignatures = resolvedSigners.map(\n async ({ individualSignTypedData, address }) => ({\n signature: await individualSignTypedData(typedDataDefinition),\n signer: address,\n type: 'ECDSA' as const,\n }),\n );\n\n const signatures = await Promise.all(addressAndSignatures);\n\n return aggregateSignature({\n signatures,\n });\n };\n\n const getStubSignature = async () =>\n concat(resolvedSigners.map(() => EOA_STUB_SIGNATURE));\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n};\n\nconst resolveStateless7702Signer = (\n config: Stateless7702SignerConfig,\n): InternalSigner => {\n if ('walletClient' in config) {\n return resolveSignerFromWalletConfig(config);\n } else if ('account' in config) {\n const { signMessage, signTypedData, getStubSignature } =\n resolveSignerFromAccountConfig(config);\n if (!signMessage) {\n throw new Error('Account does not support signMessage');\n }\n if (!signTypedData) {\n throw new Error('Account does not support signTypedData');\n }\n\n return {\n signMessage,\n signTypedData,\n getStubSignature,\n };\n }\n\n throw new Error('Invalid signer config');\n};\n\n/**\n * Resolve a signer from a configuration object.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner;\n\n/**\n * Resolve a signer from a configuration object. If no signer is provided, return null.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer or null if no signer is provided.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer?: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner | null;\n\n/**\n * Resolve a signer from a configuration object. If no signer is provided, return null.\n *\n * @param config - The configuration object.\n * @param config.implementation - The implementation type.\n * @param config.signer - The signer configuration object.\n * @returns The resolved signer or null if no signer is provided.\n */\nexport function resolveSigner<TImplementation extends Implementation>(config: {\n implementation: TImplementation;\n signer?: SignerConfigByImplementation<TImplementation>;\n}): InternalSigner | null {\n const { implementation, signer } = config;\n\n if (!signer) {\n return null;\n }\n\n if (implementation === Implementation.Hybrid) {\n return resolveHybridSigner(signer as HybridSignerConfig);\n } else if (implementation === Implementation.MultiSig) {\n return resolveMultiSigSigner(signer as MultiSigSignerConfig);\n } else if (implementation === Implementation.Stateless7702) {\n return resolveStateless7702Signer(signer as Stateless7702SignerConfig);\n }\n throw new Error(`Implementation type '${implementation}' not supported`);\n}\n","import type { Address, Hex } from 'viem';\nimport { concat } from 'viem';\n\nconst signatureTypes = ['ECDSA'] as const;\n\nexport type SignatureType = (typeof signatureTypes)[number];\n\n/**\n * Represents a partial signature that can be aggregated with others.\n */\nexport type PartialSignature = {\n signer: Address;\n signature: Hex;\n type: SignatureType;\n};\n\n/**\n * Aggregates signatures into a single signature as expected by the MultiSig implementation.\n *\n * @param params - The parameters for signature aggregation.\n * @param params.signatures - The array of partial signatures to aggregate.\n * @returns The aggregated signature.\n */\nexport const aggregateSignature = ({\n signatures,\n}: {\n signatures: PartialSignature[];\n}): Hex => {\n if (signatures.length === 0) {\n return '0x';\n }\n\n for (const { type } of signatures) {\n if (!signatureTypes.includes(type)) {\n throw new Error(`Invalid signature type: ${type}`);\n }\n }\n\n // Sort signatures by signer address as required by MultiSig implementation\n const sortedSignatures = [...signatures].sort((a, b) =>\n a.signer.localeCompare(b.signer),\n );\n\n // Concatenate all signatures\n return concat(sortedSignatures.map(({ signature }) => signature));\n};\n\n/**\n * Type definition for the aggregateSignature function parameters.\n */\nexport type AggregateSignatureParams = {\n signatures: PartialSignature[];\n};\n","import type { Client, Transport, Chain, Account } from 'viem';\n\nimport type { SmartAccountsEnvironment } from '../types';\nimport {\n caveatEnforcerActions,\n type CaveatEnforcerParams,\n type PeriodTransferResult,\n type StreamingResult,\n} from './getCaveatAvailableAmount';\n\n/**\n * Type for client extended with caveat enforcer actions.\n */\nexport type CaveatEnforcerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends Account | undefined = Account | undefined,\n> = Client<TTransport, TChain, TAccount> &\n ReturnType<ReturnType<typeof caveatEnforcerActions>>;\n\n/**\n * Create a viem client extended with caveat enforcer actions.\n *\n * @param params - The parameters object.\n * @param params.client - The viem client.\n * @param params.environment - The SmartAccountsEnvironment.\n * @returns The extended client with caveat enforcer actions.\n */\nexport function createCaveatEnforcerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends Account | undefined = Account | undefined,\n>({\n client,\n environment,\n}: {\n client: Client<TTransport, TChain, TAccount>;\n environment: SmartAccountsEnvironment;\n}): CaveatEnforcerClient<TTransport, TChain, TAccount> {\n return client.extend(caveatEnforcerActions({ environment }));\n}\n\n// Re-export types for convenience\nexport type { CaveatEnforcerParams, PeriodTransferResult, StreamingResult };\n","import type { Transport, Chain, Hex, Client, Account } from 'viem';\nimport {\n createBundlerClient,\n type BundlerClient,\n type BundlerClientConfig,\n type SmartAccount,\n} from 'viem/account-abstraction';\n\n/**\n * Gas price tiers returned by pimlico_getUserOperationGasPrice\n */\nexport type GasPriceTier = {\n /** Maximum fee per gas in hex format */\n maxFeePerGas: Hex;\n /** Maximum priority fee per gas in hex format */\n maxPriorityFeePerGas: Hex;\n};\n\n/**\n * Response from pimlico_getUserOperationGasPrice RPC method\n */\nexport type UserOperationGasPriceResponse = {\n /** Slow gas price tier */\n slow: GasPriceTier;\n /** Standard gas price tier */\n standard: GasPriceTier;\n /** Fast gas price tier */\n fast: GasPriceTier;\n};\n\n/**\n * Pimlico bundler schema for type-safe RPC method calls\n */\n/* eslint-disable @typescript-eslint/naming-convention */\ntype PimlicoBundlerSchema = [\n {\n Method: 'pimlico_getUserOperationGasPrice';\n Parameters: [];\n ReturnType: UserOperationGasPriceResponse;\n },\n];\n\n/**\n * Infura bundler actions for extending bundler clients.\n *\n * @returns A function that takes a client and returns the client extension with Infura bundler actions.\n */\nconst infuraBundlerActions = () => (client: Client) => ({\n /**\n * Get user operation gas prices from Infura bundler.\n * Calls the pimlico_getUserOperationGasPrice RPC method.\n *\n * @returns Promise resolving to gas price tiers (slow, standard, fast).\n * @example\n * ```typescript\n * const gasPrices = await bundlerClient.getUserOperationGasPrice();\n * console.log(gasPrices.standard.maxFeePerGas);\n * ```\n */\n async getUserOperationGasPrice(): Promise<UserOperationGasPriceResponse> {\n const pimlicoClient = client as Client<\n Transport,\n Chain | undefined,\n Account | undefined,\n PimlicoBundlerSchema\n >;\n\n return await pimlicoClient.request({\n method: 'pimlico_getUserOperationGasPrice',\n params: [],\n });\n },\n});\n\n/**\n * Type for bundler client extended with Infura bundler actions.\n */\nexport type InfuraBundlerClient<\n TTransport extends Transport = Transport,\n TChain extends Chain | undefined = Chain | undefined,\n TAccount extends SmartAccount | undefined = SmartAccount | undefined,\n> = BundlerClient<TTransport, TChain, TAccount> & {\n /**\n * Get user operation gas prices from Infura bundler.\n * Calls the pimlico_getUserOperationGasPrice RPC method.\n *\n * @returns Promise resolving to gas price tiers (slow, standard, fast).\n */\n getUserOperationGasPrice(): Promise<UserOperationGasPriceResponse>;\n};\n\n/**\n * Creates an Infura bundler client extended with Infura bundler actions.\n *\n * This is a wrapper around viem's createBundlerClient that extends it with\n * the getUserOperationGasPrice method for retrieving gas prices from Pimlico's\n * bundler infrastructure via Infura's proxy.\n *\n * @param config - Configuration for the bundler client.\n * @returns Extended bundler client with Infura bundler actions.\n * @example\n * ```typescript\n * import { createPublicClient, http } from 'viem';\n * import { sepolia } from 'viem/chains';\n * import { createInfuraBundlerClient } from '@metamask/smart-accounts-kit';\n *\n * const publicClient = createPublicClient({\n * chain: sepolia,\n * transport: http('https://sepolia.infura.io/v3/YOUR_API_KEY'),\n * });\n *\n * const bundlerClient = createInfuraBundlerClient({\n * client: publicClient,\n * transport: http('https://sepolia.infura.io/v3/YOUR_API_KEY'),\n * chain: sepolia,\n * });\n *\n * // Use standard bundler methods\n * const userOpHash = await bundlerClient.sendUserOperation({...});\n *\n * // Use Infura specific methods\n * const gasPrices = await bundlerClient.getUserOperationGasPrice();\n * ```\n */\nexport function createInfuraBundlerClient<\n TTransport extends Transport,\n TChain extends Chain | undefined = undefined,\n TAccount extends SmartAccount | undefined = undefined,\n>(\n config: BundlerClientConfig<TTransport, TChain, TAccount>,\n): InfuraBundlerClient<TTransport, TChain, TAccount> {\n // Create the base bundler client using viem's function\n const baseBundlerClient = createBundlerClient(config);\n\n // Extend the client with Infura bundler actions\n return baseBundlerClient.extend(\n infuraBundlerActions(),\n ) as unknown as InfuraBundlerClient<TTransport, TChain, TAccount>;\n}\n"],"mappings":";;;;;;;;;;;;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QAAQ;AAAA,MACjC,QAAQ;AAAA,MACR,QAAQ,CAAC;AAAA,IACX,CAAC;AAAA,EACH;AACF;AAoDO,SAAS,0BAKd,QACmD;AAEnD,QAAM,oBAAoB,oBAAoB,MAAM;AAGpD,SAAO,kBAAkB;AAAA,IACvB,qBAAqB;AAAA,EACvB;AACF;","names":["concat","signMessage","signTypedData","getStubSignature","concat","signDelegation","signUserOperation"]}
@@ -1,5 +1,5 @@
1
1
  import { WalletClient, PublicClient, Chain, Hex } from 'viem';
2
- import { S as SmartAccountsEnvironment } from './types-qdEHxd5Q.cjs';
2
+ import { S as SmartAccountsEnvironment } from './types-BWaH4KH1.cjs';
3
3
 
4
4
  type SupportedVersion = '1.0.0' | '1.1.0' | '1.2.0' | '1.3.0';
5
5
  declare const PREFERRED_VERSION: SupportedVersion;
@@ -1,5 +1,5 @@
1
1
  import { WalletClient, PublicClient, Chain, Hex } from 'viem';
2
- import { S as SmartAccountsEnvironment } from './types-qdEHxd5Q.js';
2
+ import { S as SmartAccountsEnvironment } from './types-BWaH4KH1.js';
3
3
 
4
4
  type SupportedVersion = '1.0.0' | '1.1.0' | '1.2.0' | '1.3.0';
5
5
  declare const PREFERRED_VERSION: SupportedVersion;
@@ -1,5 +1,5 @@
1
1
  import { HybridDeleGator, MultiSigDeleGator, EIP7702StatelessDeleGator } from '@metamask/delegation-abis';
2
- import { PublicClient, WalletClient, Transport, Chain, Account, Hex, OneOf, Address } from 'viem';
2
+ import { Account, Hex, WalletClient, Transport, Chain, PublicClient, NonceManager, OneOf, Address } from 'viem';
3
3
  import { WebAuthnAccount, SmartAccount, SmartAccountImplementation, entryPoint07Abi } from 'viem/account-abstraction';
4
4
  import { Prettify } from 'viem/chains';
5
5
 
@@ -104,6 +104,7 @@ type ToMetaMaskSmartAccountParameters<TImplementation extends Implementation> =
104
104
  implementation: TImplementation;
105
105
  signer?: SignerConfigByImplementation<TImplementation>;
106
106
  environment?: SmartAccountsEnvironment;
107
+ nonceKeyManager?: NonceManager;
107
108
  } & OneOf<{
108
109
  deployParams: DeployParams<TImplementation>;
109
110
  deploySalt: Hex;
@@ -151,4 +152,4 @@ type Call = {
151
152
  value?: bigint | undefined;
152
153
  };
153
154
 
154
- export { type AccountSignerConfig as A, type Caveat as C, type Delegation as D, type HybridDeleGatorDeployParams as H, Implementation as I, type MultiSigDeleGatorDeployParams as M, type PermissionContext as P, type SmartAccountsEnvironment as S, type ToMetaMaskSmartAccountParameters as T, type WalletSignerConfig as W, type ToMetaMaskSmartAccountReturnType as a, type SignUserOperationParams as b, type SignDelegationParams as c, type MetaMaskSmartAccountImplementation as d, type MetaMaskSmartAccount as e, type WebAuthnSignerConfig as f, type HybridSignerConfig as g, type MultiSigSignerConfig as h, TransferWindow as i, ScopeType as j, CaveatType as k, type Call as l, type DeployParams as m };
155
+ export { type AccountSignerConfig as A, type Caveat as C, type Delegation as D, type HybridDeleGatorDeployParams as H, Implementation as I, type MetaMaskSmartAccount as M, type PermissionContext as P, type SmartAccountsEnvironment as S, type ToMetaMaskSmartAccountParameters as T, type WalletSignerConfig as W, type ToMetaMaskSmartAccountReturnType as a, CaveatType as b, type HybridSignerConfig as c, type MetaMaskSmartAccountImplementation as d, type MultiSigDeleGatorDeployParams as e, type MultiSigSignerConfig as f, ScopeType as g, type SignDelegationParams as h, type SignUserOperationParams as i, TransferWindow as j, type WebAuthnSignerConfig as k, type Call as l, type DeployParams as m };
@@ -1,5 +1,5 @@
1
1
  import { HybridDeleGator, MultiSigDeleGator, EIP7702StatelessDeleGator } from '@metamask/delegation-abis';
2
- import { PublicClient, WalletClient, Transport, Chain, Account, Hex, OneOf, Address } from 'viem';
2
+ import { Account, Hex, WalletClient, Transport, Chain, PublicClient, NonceManager, OneOf, Address } from 'viem';
3
3
  import { WebAuthnAccount, SmartAccount, SmartAccountImplementation, entryPoint07Abi } from 'viem/account-abstraction';
4
4
  import { Prettify } from 'viem/chains';
5
5
 
@@ -104,6 +104,7 @@ type ToMetaMaskSmartAccountParameters<TImplementation extends Implementation> =
104
104
  implementation: TImplementation;
105
105
  signer?: SignerConfigByImplementation<TImplementation>;
106
106
  environment?: SmartAccountsEnvironment;
107
+ nonceKeyManager?: NonceManager;
107
108
  } & OneOf<{
108
109
  deployParams: DeployParams<TImplementation>;
109
110
  deploySalt: Hex;
@@ -151,4 +152,4 @@ type Call = {
151
152
  value?: bigint | undefined;
152
153
  };
153
154
 
154
- export { type AccountSignerConfig as A, type Caveat as C, type Delegation as D, type HybridDeleGatorDeployParams as H, Implementation as I, type MultiSigDeleGatorDeployParams as M, type PermissionContext as P, type SmartAccountsEnvironment as S, type ToMetaMaskSmartAccountParameters as T, type WalletSignerConfig as W, type ToMetaMaskSmartAccountReturnType as a, type SignUserOperationParams as b, type SignDelegationParams as c, type MetaMaskSmartAccountImplementation as d, type MetaMaskSmartAccount as e, type WebAuthnSignerConfig as f, type HybridSignerConfig as g, type MultiSigSignerConfig as h, TransferWindow as i, ScopeType as j, CaveatType as k, type Call as l, type DeployParams as m };
155
+ export { type AccountSignerConfig as A, type Caveat as C, type Delegation as D, type HybridDeleGatorDeployParams as H, Implementation as I, type MetaMaskSmartAccount as M, type PermissionContext as P, type SmartAccountsEnvironment as S, type ToMetaMaskSmartAccountParameters as T, type WalletSignerConfig as W, type ToMetaMaskSmartAccountReturnType as a, CaveatType as b, type HybridSignerConfig as c, type MetaMaskSmartAccountImplementation as d, type MultiSigDeleGatorDeployParams as e, type MultiSigSignerConfig as f, ScopeType as g, type SignDelegationParams as h, type SignUserOperationParams as i, TransferWindow as j, type WebAuthnSignerConfig as k, type Call as l, type DeployParams as m };
@@ -1,8 +1,8 @@
1
- export { z as CaveatBuilder, x as CaveatBuilderConfig, w as CoreCaveatBuilder, m as DELEGATION_ABI_TYPE, n as DELEGATION_ABI_TYPE_COMPONENTS, D as DELEGATION_ARRAY_ABI_TYPE, p as DelegationStruct, e as ExecutionStruct, S as SIGNABLE_DELEGATION_TYPED_DATA, y as createCaveatBuilder, k as decodeDelegation, i as decodeDelegations, v as encodeBatchExecution, j as encodeDelegation, h as encodeDelegations, q as encodeExecutionCalldata, r as encodeExecutionCalldatas, u as encodeSingleExecution, o as hashDelegation, l as toDelegation, t as toDelegationStruct } from '../delegation-DIriDFkq.cjs';
1
+ export { h as CaveatBuilder, i as CaveatBuilderConfig, j as CoreCaveatBuilder, D as DELEGATION_ABI_TYPE, k as DELEGATION_ABI_TYPE_COMPONENTS, l as DELEGATION_ARRAY_ABI_TYPE, m as DelegationStruct, d as ExecutionStruct, S as SIGNABLE_DELEGATION_TYPED_DATA, n as createCaveatBuilder, o as decodeDelegation, p as decodeDelegations, q as encodeBatchExecution, r as encodeDelegation, t as encodeDelegations, u as encodeExecutionCalldata, v as encodeExecutionCalldatas, w as encodeSingleExecution, x as hashDelegation, y as toDelegation, z as toDelegationStruct } from '../delegation-Ci3me5Rg.cjs';
2
2
  export { S as SIGNABLE_USER_OP_TYPED_DATA } from '../userOp-DKgjzz7B.cjs';
3
3
  import { Address, Hex } from 'viem';
4
- import { l as Call, I as Implementation, S as SmartAccountsEnvironment, m as DeployParams } from '../types-qdEHxd5Q.cjs';
5
- export { d as deploySmartAccountsEnvironment, o as overrideDeployedEnvironment } from '../smartAccountsEnvironment-Czw9KUYZ.cjs';
4
+ import { l as Call, I as Implementation, S as SmartAccountsEnvironment, m as DeployParams } from '../types-BWaH4KH1.cjs';
5
+ export { d as deploySmartAccountsEnvironment, o as overrideDeployedEnvironment } from '../smartAccountsEnvironment-BIcho7e0.cjs';
6
6
  export { DELEGATION_TYPEHASH } from '@metamask/delegation-core';
7
7
  import '@metamask/delegation-abis';
8
8
  import 'viem/account-abstraction';
@@ -1,8 +1,8 @@
1
- export { z as CaveatBuilder, x as CaveatBuilderConfig, w as CoreCaveatBuilder, m as DELEGATION_ABI_TYPE, n as DELEGATION_ABI_TYPE_COMPONENTS, D as DELEGATION_ARRAY_ABI_TYPE, p as DelegationStruct, e as ExecutionStruct, S as SIGNABLE_DELEGATION_TYPED_DATA, y as createCaveatBuilder, k as decodeDelegation, i as decodeDelegations, v as encodeBatchExecution, j as encodeDelegation, h as encodeDelegations, q as encodeExecutionCalldata, r as encodeExecutionCalldatas, u as encodeSingleExecution, o as hashDelegation, l as toDelegation, t as toDelegationStruct } from '../delegation-CvVXs0PO.js';
1
+ export { h as CaveatBuilder, i as CaveatBuilderConfig, j as CoreCaveatBuilder, D as DELEGATION_ABI_TYPE, k as DELEGATION_ABI_TYPE_COMPONENTS, l as DELEGATION_ARRAY_ABI_TYPE, m as DelegationStruct, d as ExecutionStruct, S as SIGNABLE_DELEGATION_TYPED_DATA, n as createCaveatBuilder, o as decodeDelegation, p as decodeDelegations, q as encodeBatchExecution, r as encodeDelegation, t as encodeDelegations, u as encodeExecutionCalldata, v as encodeExecutionCalldatas, w as encodeSingleExecution, x as hashDelegation, y as toDelegation, z as toDelegationStruct } from '../delegation-DgmIOh21.js';
2
2
  export { S as SIGNABLE_USER_OP_TYPED_DATA } from '../userOp-DKgjzz7B.js';
3
3
  import { Address, Hex } from 'viem';
4
- import { l as Call, I as Implementation, S as SmartAccountsEnvironment, m as DeployParams } from '../types-qdEHxd5Q.js';
5
- export { d as deploySmartAccountsEnvironment, o as overrideDeployedEnvironment } from '../smartAccountsEnvironment-u1CcFcGE.js';
4
+ import { l as Call, I as Implementation, S as SmartAccountsEnvironment, m as DeployParams } from '../types-BWaH4KH1.js';
5
+ export { d as deploySmartAccountsEnvironment, o as overrideDeployedEnvironment } from '../smartAccountsEnvironment-Bso0CIWt.js';
6
6
  export { DELEGATION_TYPEHASH } from '@metamask/delegation-core';
7
7
  import '@metamask/delegation-abis';
8
8
  import 'viem/account-abstraction';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@metamask/smart-accounts-kit",
3
- "version": "1.0.0",
3
+ "version": "1.1.0",
4
4
  "type": "module",
5
5
  "description": "Toolkit for managing and interacting with MetaMask Smart Accounts, built on Viem",
6
6
  "license": "(MIT-0 OR Apache-2.0)",
@@ -127,7 +127,7 @@
127
127
  "@metamask/7715-permission-types": "^0.5.0",
128
128
  "@metamask/delegation-abis": "^1.0.0",
129
129
  "@metamask/delegation-core": "^1.0.0",
130
- "@metamask/delegation-deployments": "^1.0.0",
130
+ "@metamask/delegation-deployments": "^1.1.0",
131
131
  "buffer": "^6.0.3",
132
132
  "ox": "0.8.1"
133
133
  },