@introspectivelabs/x402-evm 0.1.0-beta.16 → 0.1.0-beta.18

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 (31) hide show
  1. package/dist/cjs/accounts/index.js +1 -1
  2. package/dist/cjs/accounts/index.js.map +1 -1
  3. package/dist/cjs/{constants-C31shlNE.d.ts → constants-D7-tmODT.d.ts} +1 -1
  4. package/dist/cjs/exact/client/index.d.ts +3 -3
  5. package/dist/cjs/exact/client/index.js +107 -49
  6. package/dist/cjs/exact/client/index.js.map +1 -1
  7. package/dist/cjs/factories/index.d.ts +1 -1
  8. package/dist/cjs/factories/index.js.map +1 -1
  9. package/dist/cjs/index.d.ts +2 -2
  10. package/dist/cjs/index.js +108 -50
  11. package/dist/cjs/index.js.map +1 -1
  12. package/dist/cjs/{userOpHash-Bzusu9T7.d.ts → userOpHash-CLhOwl2X.d.ts} +46 -27
  13. package/dist/esm/accounts/index.mjs +3 -3
  14. package/dist/esm/{chunk-NLXPSIC6.mjs → chunk-CT6H26MT.mjs} +3 -3
  15. package/dist/esm/{chunk-HZJJGOJY.mjs → chunk-DX5XIR7H.mjs} +2 -2
  16. package/dist/esm/{chunk-GS55RLFG.mjs → chunk-HNYBFTTM.mjs} +109 -51
  17. package/dist/esm/chunk-HNYBFTTM.mjs.map +1 -0
  18. package/dist/esm/{chunk-ZIYQQWOM.mjs → chunk-YDUGJNSU.mjs} +2 -2
  19. package/dist/esm/{chunk-ZIYQQWOM.mjs.map → chunk-YDUGJNSU.mjs.map} +1 -1
  20. package/dist/esm/{constants-C31shlNE.d.mts → constants-D7-tmODT.d.mts} +1 -1
  21. package/dist/esm/exact/client/index.d.mts +3 -3
  22. package/dist/esm/exact/client/index.mjs +3 -3
  23. package/dist/esm/factories/index.d.mts +1 -1
  24. package/dist/esm/factories/index.mjs +1 -1
  25. package/dist/esm/index.d.mts +2 -2
  26. package/dist/esm/index.mjs +4 -4
  27. package/dist/esm/{userOpHash-Cz7aBb3Q.d.mts → userOpHash-CjJpllAn.d.mts} +46 -27
  28. package/package.json +1 -1
  29. package/dist/esm/chunk-GS55RLFG.mjs.map +0 -1
  30. /package/dist/esm/{chunk-NLXPSIC6.mjs.map → chunk-CT6H26MT.mjs.map} +0 -0
  31. /package/dist/esm/{chunk-HZJJGOJY.mjs.map → chunk-DX5XIR7H.mjs.map} +0 -0
@@ -56,7 +56,7 @@ var import_viem2 = require("viem");
56
56
  // src/constants.ts
57
57
  var import_account_abstraction = require("viem/account-abstraction");
58
58
  var SAFE_4337_MODULE_ADDRESS = "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226";
59
- var SAFE_WEBAUTHN_SHARED_SIGNER = "0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9";
59
+ var SAFE_WEBAUTHN_SHARED_SIGNER = "0x94a4F6affBd8975951142c3999aEAB7ecee555c2";
60
60
 
61
61
  // src/accounts/computeSafeOpHash.ts
62
62
  var SAFE_OP_TYPES = {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/accounts/index.ts","../../../src/accounts/toSafeSmartAccount.ts","../../../src/accounts/toP256SafeSmartAccount.ts","../../../src/accounts/encodeContractSignature.ts","../../../src/accounts/computeSafeOpHash.ts","../../../src/constants.ts","../../../src/accounts/toWebAuthnSafeSmartAccount.ts","../../../src/accounts/extractPasskeyCoordinates.ts","../../../src/accounts/toP256ExecutorModuleAccount.ts","../../../src/exact/client/utils/userOpHash.ts"],"sourcesContent":["// Unified API\nexport { toSafeSmartAccount } from \"./toSafeSmartAccount\";\n\n// Individual signer functions\nexport { toP256SafeSmartAccount } from \"./toP256SafeSmartAccount\";\nexport { toWebAuthnSafeSmartAccount } from \"./toWebAuthnSafeSmartAccount\";\n\n// Utilities\nexport { encodeContractSignature } from \"./encodeContractSignature\";\nexport { computeSafeOpHash } from \"./computeSafeOpHash\";\n\nexport { extractPasskeyCoordinates } from \"./extractPasskeyCoordinates\";\n\n// P256ExecutorModule adapter\nexport { toP256ExecutorModuleAccount } from \"./toP256ExecutorModuleAccount\";\nexport type { ToP256ExecutorModuleAccountParams } from \"./toP256ExecutorModuleAccount\";\n\n// Types\nexport type { P256Signer, SafeMessageSigner, ToP256SafeSmartAccountParams } from \"./types\";\nexport type { SignerConfig, ToSafeSmartAccountParams } from \"./types\";\nexport type { ToWebAuthnSafeSmartAccountParams } from \"./toWebAuthnSafeSmartAccount\";\nexport type { SafeOpHashParams } from \"./computeSafeOpHash\";\n","import type { Hex, LocalAccount } from \"viem\";\nimport { concat, encodeAbiParameters, pad, toHex } from \"viem\";\nimport type { SmartAccount, WebAuthnAccount } from \"viem/account-abstraction\";\nimport { toSafeSmartAccount as toPermissionlessSafeSmartAccount } from \"permissionless/accounts\";\n\nimport type { P256Signer, ToSafeSmartAccountParams } from \"./types\";\nimport { toP256SafeSmartAccount } from \"./toP256SafeSmartAccount\";\nimport { toWebAuthnSafeSmartAccount } from \"./toWebAuthnSafeSmartAccount\";\nimport { encodeContractSignature } from \"./encodeContractSignature\";\nimport { computeSafeOpHash } from \"./computeSafeOpHash\";\nimport type { SafeOpHashParams } from \"./computeSafeOpHash\";\nimport {\n SAFE_4337_MODULE_ADDRESS,\n SAFE_WEBAUTHN_SHARED_SIGNER,\n entryPoint07Address,\n} from \"../constants\";\n\n/**\n * Creates a Safe SmartAccount with a unified signer configuration.\n *\n * Dispatches to the appropriate implementation based on `signerConfig.type`:\n * - `\"p256\"`: P256 contract owner (existing `toP256SafeSmartAccount`)\n * - `\"webauthn\"`: WebAuthn passkey via permissionless native support\n * - `\"multi\"`: Both P256 and WebAuthn owners on a single Safe\n *\n * @example\n * ```typescript\n * // P256 only\n * const account = await toSafeSmartAccount({\n * client,\n * signerConfig: { type: \"p256\", p256Signer },\n * });\n *\n * // WebAuthn only\n * const account = await toSafeSmartAccount({\n * client,\n * signerConfig: { type: \"webauthn\", webAuthnAccount },\n * });\n *\n * // Multi-signer (threshold 1, P256 signs by default)\n * const account = await toSafeSmartAccount({\n * client,\n * signerConfig: {\n * type: \"multi\",\n * signers: { p256: p256Signer, webAuthn: webAuthnAccount },\n * threshold: 1,\n * },\n * });\n * ```\n */\nexport async function toSafeSmartAccount(\n params: ToSafeSmartAccountParams,\n): Promise<SmartAccount> {\n const { signerConfig } = params;\n\n switch (signerConfig.type) {\n case \"p256\":\n return toP256SafeSmartAccount({\n client: params.client,\n p256Signer: signerConfig.p256Signer,\n safeAddress: params.safeAddress,\n entryPoint: params.entryPoint,\n safe4337ModuleAddress: params.safe4337ModuleAddress,\n });\n\n case \"webauthn\":\n return toWebAuthnSafeSmartAccount({\n client: params.client,\n webAuthnAccount: signerConfig.webAuthnAccount,\n safeAddress: params.safeAddress,\n entryPoint: params.entryPoint,\n safe4337ModuleAddress: params.safe4337ModuleAddress,\n safeWebAuthnSharedSignerAddress: signerConfig.safeWebAuthnSharedSignerAddress,\n });\n\n case \"multi\":\n return buildMultiSignerAccount(params, signerConfig.signers, signerConfig.threshold ?? 1);\n }\n}\n\nfunction createMockLocalAccount(address: Hex): LocalAccount {\n const notImplemented = () => {\n throw new Error(\"Mock owner: use signUserOperation instead\");\n };\n\n return {\n address,\n type: \"local\",\n source: \"custom\",\n publicKey: \"0x\" as Hex,\n signMessage: notImplemented,\n signTypedData: notImplemented,\n signTransaction: notImplemented,\n sign: notImplemented,\n } as unknown as LocalAccount;\n}\n\n/**\n * Encodes a WebAuthn signature from raw sign() output into the ABI format\n * expected by Safe's WebAuthn verifier:\n * `(bytes authenticatorData, string clientDataFields, uint256[2] signature)`\n *\n * permissionless does not export this helper, so we implement it here.\n */\nasync function encodeWebAuthnSignature(\n owner: WebAuthnAccount,\n hash: Hex,\n): Promise<Hex> {\n const { signature: signatureData, webauthn } = await owner.sign({ hash });\n\n // Extract r, s from the DER-encoded P256 signature\n const sigBytes = signatureData.slice(2);\n const r = BigInt(\"0x\" + sigBytes.slice(0, 64));\n const s = BigInt(\"0x\" + sigBytes.slice(64, 128));\n\n // Extract the fields after \"challenge\":\"...\" from clientDataJSON\n const match = webauthn.clientDataJSON.match(\n /^\\{\"type\":\"webauthn.get\",\"challenge\":\"[A-Za-z0-9\\-_]{43}\",(.*)\\}$/,\n );\n const clientDataFields = match ? match[1] : \"\";\n\n return encodeAbiParameters(\n [\n { name: \"authenticatorData\", type: \"bytes\" },\n { name: \"clientDataFields\", type: \"string\" },\n { name: \"signature\", type: \"uint256[2]\" },\n ],\n [webauthn.authenticatorData, clientDataFields, [r, s]],\n );\n}\n\nasync function buildMultiSignerAccount(\n params: ToSafeSmartAccountParams,\n signers: { p256?: P256Signer; webAuthn?: WebAuthnAccount },\n threshold: number,\n): Promise<SmartAccount> {\n if (!signers.p256 && !signers.webAuthn) {\n throw new Error(\"Multi-signer config requires at least one signer\");\n }\n\n // If only one signer is provided, delegate to the single-signer function\n if (signers.p256 && !signers.webAuthn) {\n return toP256SafeSmartAccount({\n client: params.client,\n p256Signer: signers.p256,\n safeAddress: params.safeAddress,\n entryPoint: params.entryPoint,\n safe4337ModuleAddress: params.safe4337ModuleAddress,\n });\n }\n if (signers.webAuthn && !signers.p256) {\n const signerConfig = params.signerConfig;\n const sharedSignerAddr = signerConfig.type === \"multi\"\n ? signerConfig.safeWebAuthnSharedSignerAddress\n : undefined;\n return toWebAuthnSafeSmartAccount({\n client: params.client,\n webAuthnAccount: signers.webAuthn,\n safeAddress: params.safeAddress,\n entryPoint: params.entryPoint,\n safe4337ModuleAddress: params.safe4337ModuleAddress,\n safeWebAuthnSharedSignerAddress: sharedSignerAddr,\n });\n }\n\n // Both signers present\n const p256Signer = signers.p256!;\n const webAuthnAccount = signers.webAuthn!;\n\n const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_ADDRESS;\n const entryPointAddress = params.entryPoint?.address ?? entryPoint07Address;\n\n const mockP256Owner = createMockLocalAccount(p256Signer.p256OwnerAddress);\n\n // Build account with both owners: mock LocalAccount for P256 + WebAuthnAccount\n const baseAccount = await toPermissionlessSafeSmartAccount({\n client: params.client,\n owners: [mockP256Owner, webAuthnAccount],\n version: \"1.5.0\",\n threshold: BigInt(threshold),\n ...(params.safeAddress ? { address: params.safeAddress } : {}),\n entryPoint: {\n address: entryPointAddress,\n version: \"0.7\",\n },\n safe4337ModuleAddress,\n });\n\n const chainId = await params.client.getChainId();\n\n if (threshold >= 2) {\n return buildThreshold2Account(\n baseAccount as SmartAccount,\n p256Signer,\n webAuthnAccount,\n chainId,\n safe4337ModuleAddress,\n entryPointAddress,\n );\n }\n\n // Threshold 1: P256 signs by default (no browser interaction needed)\n return buildThreshold1Account(\n baseAccount as SmartAccount,\n p256Signer,\n chainId,\n safe4337ModuleAddress,\n entryPointAddress,\n );\n}\n\nfunction buildThreshold1Account(\n baseAccount: SmartAccount,\n p256Signer: P256Signer,\n chainId: number,\n safe4337ModuleAddress: Hex,\n entryPointAddress: Hex,\n): SmartAccount {\n return {\n ...baseAccount,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async signUserOperation(userOp: any) {\n const safeOpHash = computeSafeOpHash(\n extractSafeOpHashParams(userOp),\n chainId,\n safe4337ModuleAddress,\n entryPointAddress,\n );\n\n const { r, s } = await p256Signer.sign(safeOpHash);\n const rPadded = pad(r as Hex, { size: 32 });\n const sPadded = pad(s as Hex, { size: 32 });\n const p256Signature = concat([rPadded, sPadded]);\n\n const contractSig = encodeContractSignature(\n p256Signer.p256OwnerAddress,\n p256Signature,\n );\n\n const validAfter = pad(toHex(0), { size: 6 });\n const validUntil = pad(toHex(0), { size: 6 });\n\n return concat([validAfter, validUntil, contractSig]);\n },\n } as SmartAccount;\n}\n\nfunction buildThreshold2Account(\n baseAccount: SmartAccount,\n p256Signer: P256Signer,\n webAuthnAccount: WebAuthnAccount,\n chainId: number,\n safe4337ModuleAddress: Hex,\n entryPointAddress: Hex,\n): SmartAccount {\n return {\n ...baseAccount,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async signUserOperation(userOp: any) {\n const safeOpHash = computeSafeOpHash(\n extractSafeOpHashParams(userOp),\n chainId,\n safe4337ModuleAddress,\n entryPointAddress,\n );\n\n // Sign with P256\n const { r, s } = await p256Signer.sign(safeOpHash);\n const rPadded = pad(r as Hex, { size: 32 });\n const sPadded = pad(s as Hex, { size: 32 });\n const p256SignatureData = concat([rPadded, sPadded]);\n\n // Sign with WebAuthn\n const webAuthnSignatureData = await encodeWebAuthnSignature(\n webAuthnAccount,\n safeOpHash,\n );\n\n // Build sorted multi-signature\n // Safe requires signatures sorted by signer address (ascending)\n const p256SignerAddress = p256Signer.p256OwnerAddress.toLowerCase();\n const webAuthnSignerAddress = SAFE_WEBAUTHN_SHARED_SIGNER.toLowerCase();\n\n type SignerEntry = {\n address: string;\n data: Hex;\n dynamic: boolean;\n contractOwner: boolean;\n };\n\n const signerEntries: SignerEntry[] = [\n {\n address: p256SignerAddress,\n data: p256SignatureData,\n dynamic: true,\n contractOwner: true,\n },\n {\n address: webAuthnSignerAddress,\n data: webAuthnSignatureData,\n dynamic: true,\n contractOwner: false,\n },\n ].sort((a, b) => (a.address < b.address ? -1 : 1));\n\n const concatenatedSig = concatSafeSignatures(signerEntries);\n\n const validAfter = pad(toHex(0), { size: 6 });\n const validUntil = pad(toHex(0), { size: 6 });\n\n return concat([validAfter, validUntil, concatenatedSig]);\n },\n } as SmartAccount;\n}\n\n/**\n * Concatenates multiple Safe signatures with proper static/dynamic layout.\n *\n * Safe's `checkNSignatures` expects:\n * - N x 65-byte static parts (sorted by signer address)\n * - Dynamic data appended after all static parts\n *\n * For dynamic signatures (contract or WebAuthn):\n * Static: r = address padded to 32 bytes, s = offset to dynamic data, v = 0x00\n * Dynamic: 32-byte length prefix + signature data\n *\n * For ECDSA signatures:\n * Static: r (32 bytes) + s (32 bytes) + v (1 byte)\n */\nfunction concatSafeSignatures(\n entries: { address: string; data: Hex; dynamic: boolean; contractOwner: boolean }[],\n): Hex {\n const staticPartSize = 65; // per signer\n const totalStaticSize = staticPartSize * entries.length;\n\n const staticParts: Hex[] = [];\n const dynamicParts: Hex[] = [];\n let dynamicOffset = totalStaticSize;\n\n for (const entry of entries) {\n if (entry.dynamic) {\n // Dynamic signature: static part points to dynamic data\n const r = pad(entry.address as Hex, { size: 32 });\n const s = pad(toHex(dynamicOffset), { size: 32 });\n const v = \"0x00\" as Hex;\n staticParts.push(concat([r, s, v]));\n\n // Dynamic part: length-prefixed data\n const dataBytes = (entry.data.length - 2) / 2;\n const length = pad(toHex(dataBytes), { size: 32 });\n dynamicParts.push(concat([length, entry.data]));\n\n // Advance offset: 32 bytes for length + actual data length\n dynamicOffset += 32 + dataBytes;\n } else {\n // ECDSA: direct 65-byte signature (not used in current multi-signer paths)\n staticParts.push(entry.data);\n }\n }\n\n return concat([...staticParts, ...dynamicParts]);\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction extractSafeOpHashParams(userOp: any): SafeOpHashParams {\n const op = userOp as Record<string, unknown>;\n return {\n sender: op.sender as Hex,\n nonce: BigInt(op.nonce as bigint),\n factory: (op.factory as Hex) ?? null,\n factoryData: (op.factoryData as Hex) ?? null,\n callData: op.callData as Hex,\n verificationGasLimit: BigInt(op.verificationGasLimit as bigint),\n callGasLimit: BigInt(op.callGasLimit as bigint),\n preVerificationGas: BigInt(op.preVerificationGas as bigint),\n maxPriorityFeePerGas: BigInt(op.maxPriorityFeePerGas as bigint),\n maxFeePerGas: BigInt(op.maxFeePerGas as bigint),\n paymaster: (op.paymaster as Hex) ?? null,\n paymasterVerificationGasLimit: op.paymasterVerificationGasLimit\n ? BigInt(op.paymasterVerificationGasLimit as bigint)\n : null,\n paymasterPostOpGasLimit: op.paymasterPostOpGasLimit\n ? BigInt(op.paymasterPostOpGasLimit as bigint)\n : null,\n paymasterData: (op.paymasterData as Hex) ?? null,\n };\n}\n","import type { Hex, LocalAccount } from \"viem\";\nimport { concat, pad, toHex } from \"viem\";\nimport type { SmartAccount } from \"viem/account-abstraction\";\nimport { toSafeSmartAccount } from \"permissionless/accounts\";\n\nimport type { ToP256SafeSmartAccountParams } from \"./types\";\nimport { encodeContractSignature } from \"./encodeContractSignature\";\nimport type { SafeOpHashParams } from \"./computeSafeOpHash\";\nimport { computeSafeOpHash } from \"./computeSafeOpHash\";\nimport { SAFE_4337_MODULE_ADDRESS, entryPoint07Address } from \"../constants\";\n\n/**\n * Creates a mock LocalAccount that has the P256Owner contract address.\n *\n * This is needed because `toSafeSmartAccount` requires a `LocalAccount` owner,\n * but our actual signer is a P256Owner contract (ERC-1271). The mock provides\n * the correct address so the Safe is configured with the right owner. The\n * signing methods are never called since we override `signUserOperation`.\n */\nfunction createMockLocalAccount(address: Hex): LocalAccount {\n const notImplemented = () => {\n throw new Error(\"P256 contract owner: use signUserOperation instead\");\n };\n\n return {\n address,\n type: \"local\",\n source: \"custom\",\n publicKey: \"0x\" as Hex,\n signMessage: notImplemented,\n signTypedData: notImplemented,\n signTransaction: notImplemented,\n sign: notImplemented,\n } as unknown as LocalAccount;\n}\n\n/**\n * Creates a Safe SmartAccount that signs UserOperations with a P256 contract owner.\n *\n * This wraps permissionless's `toSafeSmartAccount` and overrides `signUserOperation`\n * to produce P256 signatures in Safe's contract signature format (v=0). The resulting\n * account is compatible with `SafeAccountSigner` and `ExactEvmSchemeERC4337`.\n *\n * The caller is responsible for:\n * - Deploying the P256Owner contract (or computing its deterministic address)\n * - Providing the `sign()` function (e.g., using `@noble/curves/p256` with `prehash: false`)\n * - Ensuring the P256Owner is an owner of the Safe\n *\n * @example\n * ```typescript\n * import { toP256SafeSmartAccount } from '@introspectivelabs/x402-evm';\n * import { p256 } from '@noble/curves/p256';\n *\n * const account = await toP256SafeSmartAccount({\n * client: publicClient,\n * p256Signer: {\n * p256OwnerAddress: '0x349c...',\n * sign: async (hash) => {\n * const sig = p256.sign(hash.slice(2), privateKey, { prehash: false, lowS: true });\n * return {\n * r: `0x${sig.r.toString(16).padStart(64, '0')}`,\n * s: `0x${sig.s.toString(16).padStart(64, '0')}`,\n * };\n * },\n * },\n * safeAddress: '0x...',\n * });\n *\n * const scheme = new ExactEvmSchemeERC4337({ account });\n * ```\n */\nexport async function toP256SafeSmartAccount(\n params: ToP256SafeSmartAccountParams,\n): Promise<SmartAccount> {\n const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_ADDRESS;\n const entryPointAddress =\n params.entryPoint?.address ?? entryPoint07Address;\n\n const mockOwner = createMockLocalAccount(params.p256Signer.p256OwnerAddress);\n\n const baseAccount = await toSafeSmartAccount({\n client: params.client,\n owners: [mockOwner],\n version: \"1.5.0\",\n ...(params.safeAddress ? { address: params.safeAddress } : {}),\n entryPoint: {\n address: entryPointAddress,\n version: \"0.7\",\n },\n safe4337ModuleAddress,\n });\n\n const chainId = await params.client.getChainId();\n\n return {\n ...baseAccount,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async signUserOperation(userOp: any) {\n const op = userOp as Record<string, unknown>;\n // Compute the SafeOp EIP-712 hash (what Safe4337Module verifies)\n const hashParams: SafeOpHashParams = {\n sender: op.sender as Hex,\n nonce: BigInt(op.nonce as bigint),\n factory: (op.factory as Hex) ?? null,\n factoryData: (op.factoryData as Hex) ?? null,\n callData: op.callData as Hex,\n verificationGasLimit: BigInt(op.verificationGasLimit as bigint),\n callGasLimit: BigInt(op.callGasLimit as bigint),\n preVerificationGas: BigInt(op.preVerificationGas as bigint),\n maxPriorityFeePerGas: BigInt(op.maxPriorityFeePerGas as bigint),\n maxFeePerGas: BigInt(op.maxFeePerGas as bigint),\n paymaster: (op.paymaster as Hex) ?? null,\n paymasterVerificationGasLimit: op.paymasterVerificationGasLimit\n ? BigInt(op.paymasterVerificationGasLimit as bigint)\n : null,\n paymasterPostOpGasLimit: op.paymasterPostOpGasLimit\n ? BigInt(op.paymasterPostOpGasLimit as bigint)\n : null,\n paymasterData: (op.paymasterData as Hex) ?? null,\n };\n const safeOpHash = computeSafeOpHash(\n hashParams,\n chainId,\n safe4337ModuleAddress,\n entryPointAddress,\n );\n\n // Sign the SafeOp hash with P256\n const { r, s } = await params.p256Signer.sign(safeOpHash);\n\n // Encode r || s as 64-byte signature\n const rPadded = pad(r as Hex, { size: 32 });\n const sPadded = pad(s as Hex, { size: 32 });\n const p256Signature = concat([rPadded, sPadded]);\n\n // Wrap in Safe contract signature format (v=0)\n const contractSig = encodeContractSignature(\n params.p256Signer.p256OwnerAddress,\n p256Signature,\n );\n\n // Safe4337Module expects: validAfter (6 bytes) || validUntil (6 bytes) || signatures\n const validAfter = pad(toHex(0), { size: 6 });\n const validUntil = pad(toHex(0), { size: 6 });\n\n return concat([validAfter, validUntil, contractSig]);\n },\n } as SmartAccount;\n}\n","import { type Hex, concat, pad, toHex } from \"viem\";\n\n/**\n * Encodes a signature in Safe's contract signature format (v=0).\n *\n * Safe's `checkNSignatures` expects this layout for contract owners:\n *\n * Static part (65 bytes):\n * - r (32 bytes): owner address padded to 32 bytes\n * - s (32 bytes): offset to dynamic data (relative to start of signatures)\n * - v (1 byte): 0x00 (indicates contract signature)\n *\n * Dynamic part (at the offset):\n * - length (32 bytes): length of the signature data\n * - data (variable): the actual signature bytes\n *\n * For a single signer, the static part is 65 bytes, so the dynamic data\n * starts at offset 65.\n */\nexport function encodeContractSignature(ownerAddress: Hex, signatureData: Hex): Hex {\n // Static part: r = address padded to 32 bytes\n const r = pad(ownerAddress, { size: 32 });\n\n // For a single signature, dynamic data starts right after the 65-byte static part\n const dynamicOffset = 65;\n const s = pad(toHex(dynamicOffset), { size: 32 });\n\n // v = 0x00 for contract signature\n const v = \"0x00\" as Hex;\n\n // Dynamic part: length-prefixed signature data\n const signatureBytes = (signatureData.length - 2) / 2;\n const length = pad(toHex(signatureBytes), { size: 32 });\n\n return concat([r, s, v, length, signatureData]);\n}\n","import {\n type Hex,\n concat,\n hashTypedData,\n isAddress,\n pad,\n toHex,\n} from \"viem\";\nimport { SAFE_4337_MODULE_ADDRESS, entryPoint07Address } from \"../constants\";\n\nconst SAFE_OP_TYPES = {\n SafeOp: [\n { type: \"address\", name: \"safe\" },\n { type: \"uint256\", name: \"nonce\" },\n { type: \"bytes\", name: \"initCode\" },\n { type: \"bytes\", name: \"callData\" },\n { type: \"uint128\", name: \"verificationGasLimit\" },\n { type: \"uint128\", name: \"callGasLimit\" },\n { type: \"uint256\", name: \"preVerificationGas\" },\n { type: \"uint128\", name: \"maxPriorityFeePerGas\" },\n { type: \"uint128\", name: \"maxFeePerGas\" },\n { type: \"bytes\", name: \"paymasterAndData\" },\n { type: \"uint48\", name: \"validAfter\" },\n { type: \"uint48\", name: \"validUntil\" },\n { type: \"address\", name: \"entryPoint\" },\n ],\n} as const;\n\nexport interface SafeOpHashParams {\n sender: Hex;\n nonce: bigint;\n factory?: Hex | null;\n factoryData?: Hex | null;\n callData: Hex;\n verificationGasLimit: bigint;\n callGasLimit: bigint;\n preVerificationGas: bigint;\n maxPriorityFeePerGas: bigint;\n maxFeePerGas: bigint;\n paymaster?: Hex | null;\n paymasterVerificationGasLimit?: bigint | null;\n paymasterPostOpGasLimit?: bigint | null;\n paymasterData?: Hex | null;\n}\n\n/**\n * Computes the EIP-712 SafeOp hash that Safe4337Module uses for signature verification.\n *\n * The Safe4337Module converts the EntryPoint v0.7 UserOperation into a SafeOp struct,\n * packing initCode and paymasterAndData into their v0.6-style concatenated forms,\n * then hashes the struct using EIP-712.\n */\nexport function computeSafeOpHash(\n userOp: SafeOpHashParams,\n chainId: number,\n safe4337ModuleAddress: Hex = SAFE_4337_MODULE_ADDRESS,\n entryPointAddress: Hex = entryPoint07Address,\n): Hex {\n // Reconstruct initCode: factory || factoryData (v0.7 -> v0.6 style)\n const initCode =\n userOp.factory && isAddress(userOp.factory)\n ? concat([userOp.factory, (userOp.factoryData || \"0x\") as Hex])\n : (\"0x\" as Hex);\n\n // Reconstruct paymasterAndData: paymaster || verificationGasLimit(16) || postOpGasLimit(16) || data\n let paymasterAndData: Hex = \"0x\";\n if (userOp.paymaster && isAddress(userOp.paymaster)) {\n paymasterAndData = concat([\n userOp.paymaster,\n pad(toHex(userOp.paymasterVerificationGasLimit || 0n), { size: 16 }),\n pad(toHex(userOp.paymasterPostOpGasLimit || 0n), { size: 16 }),\n (userOp.paymasterData || \"0x\") as Hex,\n ]);\n }\n\n return hashTypedData({\n domain: {\n chainId,\n verifyingContract: safe4337ModuleAddress,\n },\n types: SAFE_OP_TYPES,\n primaryType: \"SafeOp\",\n message: {\n safe: userOp.sender,\n nonce: userOp.nonce,\n initCode,\n callData: userOp.callData,\n verificationGasLimit: userOp.verificationGasLimit,\n callGasLimit: userOp.callGasLimit,\n preVerificationGas: userOp.preVerificationGas,\n maxPriorityFeePerGas: userOp.maxPriorityFeePerGas,\n maxFeePerGas: userOp.maxFeePerGas,\n paymasterAndData,\n validAfter: 0,\n validUntil: 0,\n entryPoint: entryPointAddress,\n },\n });\n}\n","import type { Hex } from \"viem\";\nimport { entryPoint07Address } from \"viem/account-abstraction\";\n\nexport { entryPoint07Address };\n\nexport const SAFE_4337_MODULE_ADDRESS =\n \"0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226\" as const satisfies Hex;\n\nexport const SAFE_WEBAUTHN_SHARED_SIGNER =\n \"0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9\" as const satisfies Hex;\n\nexport const FCL_P256_VERIFIER =\n \"0xA86e0054C51E4894D88762a017ECc5E5235f5DBA\" as const satisfies Hex;\n\nexport const P256_OWNER_FACTORY =\n \"0x349c03Eb61e26528cbf79F5D3Ba071FcA2aE82cB\" as const satisfies Hex;\n\nexport const WEBAUTHN_SIGNER_FACTORY =\n \"0xF7488fFbe67327ac9f37D5F722d83Fc900852Fbf\" as const satisfies Hex;\n\nexport const GUARD_FACTORY =\n \"0x35E2B487b682029e363BA7f06fD7392834A83077\" as const satisfies Hex;\n","import type { Hex } from \"viem\";\nimport type { SmartAccount, WebAuthnAccount } from \"viem/account-abstraction\";\nimport { toSafeSmartAccount } from \"permissionless/accounts\";\nimport type { PublicClient, Transport, Chain } from \"viem\";\nimport { SAFE_4337_MODULE_ADDRESS, entryPoint07Address } from \"../constants\";\n\nexport type ToWebAuthnSafeSmartAccountParams = {\n client: PublicClient<Transport, Chain>;\n webAuthnAccount: WebAuthnAccount;\n safeAddress?: Hex;\n entryPoint?: { address: Hex; version: \"0.7\" };\n safe4337ModuleAddress?: Hex;\n safeWebAuthnSharedSignerAddress?: Hex;\n};\n\n/**\n * Creates a Safe SmartAccount that signs UserOperations with a WebAuthn passkey.\n */\nexport async function toWebAuthnSafeSmartAccount(\n params: ToWebAuthnSafeSmartAccountParams,\n): Promise<SmartAccount> {\n const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_ADDRESS;\n const entryPointAddress = params.entryPoint?.address ?? entryPoint07Address;\n\n const baseAccount = await toSafeSmartAccount({\n client: params.client,\n owners: [params.webAuthnAccount],\n version: \"1.5.0\",\n ...(params.safeAddress ? { address: params.safeAddress } : {}),\n entryPoint: {\n address: entryPointAddress,\n version: \"0.7\",\n },\n safe4337ModuleAddress,\n ...(params.safeWebAuthnSharedSignerAddress\n ? { safeWebAuthnSharedSignerAddress: params.safeWebAuthnSharedSignerAddress }\n : {}),\n });\n\n return baseAccount as SmartAccount;\n}\n","/// <reference lib=\"dom\" />\nimport type { Hex } from \"viem\";\n\nfunction bufferToHex(buffer: ArrayBuffer): string {\n return Array.from(new Uint8Array(buffer))\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\nfunction base64urlToHex(base64url: string): string {\n const base64 = base64url.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const binary = atob(base64);\n return Array.from(binary, (c) => c.charCodeAt(0).toString(16).padStart(2, \"0\")).join(\"\");\n}\n\n/**\n * Extracts P256 public key coordinates from a WebAuthn credential.\n *\n * Replaces `extractPasskeyData` from `@safe-global/protocol-kit`.\n * Uses only the Web Crypto API (no external dependencies).\n */\nexport async function extractPasskeyCoordinates(\n credential: PublicKeyCredential,\n): Promise<{ rawId: string; x: Hex; y: Hex }> {\n const rawId = bufferToHex(credential.rawId);\n const response = credential.response as AuthenticatorAttestationResponse;\n const publicKey = response.getPublicKey();\n if (!publicKey) throw new Error(\"Failed to extract public key from credential\");\n\n const key = await crypto.subtle.importKey(\n \"spki\",\n publicKey,\n { name: \"ECDSA\", namedCurve: \"P-256\" },\n true,\n [\"verify\"],\n );\n const jwk = await crypto.subtle.exportKey(\"jwk\", key);\n if (!jwk.x || !jwk.y) throw new Error(\"Missing coordinates in JWK\");\n\n return {\n rawId,\n x: (\"0x\" + base64urlToHex(jwk.x)) as Hex,\n y: (\"0x\" + base64urlToHex(jwk.y)) as Hex,\n };\n}\n","import {\n concat,\n encodeFunctionData,\n pad,\n type Chain,\n type Hex,\n type PublicClient,\n type Transport,\n} from \"viem\";\nimport { toSmartAccount, type SmartAccount } from \"viem/account-abstraction\";\nimport { entryPoint07Address } from \"../constants\";\nimport { computeUserOpHash, type PackedUserOp } from \"../exact/client/utils/userOpHash\";\n\nconst P256_EXECUTOR_MODULE_ABI = [\n {\n inputs: [\n { name: \"to\", type: \"address\" },\n { name: \"value\", type: \"uint256\" },\n { name: \"data\", type: \"bytes\" },\n { name: \"operation\", type: \"uint8\" },\n ],\n name: \"execute\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n] as const;\n\nconst ENTRYPOINT_07_ABI = [\n {\n name: \"getNonce\",\n type: \"function\",\n inputs: [\n { name: \"sender\", type: \"address\" },\n { name: \"key\", type: \"uint192\" },\n ],\n outputs: [{ name: \"nonce\", type: \"uint256\" }],\n stateMutability: \"view\",\n },\n] as const;\n\nexport interface ToP256ExecutorModuleAccountParams {\n client: PublicClient<Transport, Chain>;\n moduleAddress: Hex;\n sign: (hash: Hex) => Promise<{ r: Hex; s: Hex }>;\n entryPointAddress?: Hex;\n}\n\n/**\n * Creates a viem SmartAccount adapter for P256ExecutorModule.\n *\n * The module is the UserOp sender (not the Safe). CallData encodes\n * `module.execute(to, value, data, 0)` and the signature is raw\n * P256 `r || s` (64 bytes).\n *\n * Use this with `ExactEvmSchemeERC4337` to handle ERC-4337 payments\n * where the P256ExecutorModule is the account.\n */\nexport async function toP256ExecutorModuleAccount(\n params: ToP256ExecutorModuleAccountParams,\n): Promise<SmartAccount> {\n const { client, moduleAddress, sign } = params;\n const entryPoint = params.entryPointAddress ?? entryPoint07Address;\n\n return toSmartAccount({\n client,\n entryPoint: {\n abi: ENTRYPOINT_07_ABI,\n address: entryPoint,\n version: \"0.7\",\n },\n\n async getAddress() {\n return moduleAddress;\n },\n\n async encodeCalls(calls) {\n if (calls.length !== 1) {\n throw new Error(\n \"P256ExecutorModule does not support batch calls. \" +\n `Received ${calls.length} calls, expected 1.`,\n );\n }\n const { to, value, data } = calls[0];\n return encodeFunctionData({\n abi: P256_EXECUTOR_MODULE_ABI,\n functionName: \"execute\",\n args: [to, value ?? 0n, data ?? \"0x\", 0],\n });\n },\n\n async getNonce() {\n return await client.readContract({\n address: entryPoint,\n abi: ENTRYPOINT_07_ABI,\n functionName: \"getNonce\",\n args: [moduleAddress, 0n],\n }) as bigint;\n },\n\n async getFactoryArgs() {\n return { factory: undefined, factoryData: undefined };\n },\n\n async getStubSignature() {\n return (\"0x\" + \"ff\".repeat(64)) as Hex;\n },\n\n async signMessage() {\n throw new Error(\"P256ExecutorModule does not support signMessage\");\n },\n\n async signTypedData() {\n throw new Error(\"P256ExecutorModule does not support signTypedData\");\n },\n\n async signUserOperation(userOperation) {\n const chainId = client.chain.id;\n\n const factory = userOperation.factory as Hex | undefined;\n const packedUserOp: PackedUserOp = {\n sender: userOperation.sender as Hex,\n nonce: userOperation.nonce,\n initCode: factory\n ? concat([factory, (userOperation.factoryData ?? \"0x\") as Hex])\n : \"0x\",\n callData: userOperation.callData,\n accountGasLimits: packAccountGasLimits(\n userOperation.verificationGasLimit,\n userOperation.callGasLimit,\n ),\n preVerificationGas: userOperation.preVerificationGas,\n gasFees: packGasFees(\n userOperation.maxPriorityFeePerGas,\n userOperation.maxFeePerGas,\n ),\n paymasterAndData: buildPaymasterAndData(userOperation),\n };\n\n const hash = computeUserOpHash(packedUserOp, chainId, entryPoint);\n const { r, s } = await sign(hash);\n return concat([pad(r, { size: 32 }), pad(s, { size: 32 })]);\n },\n });\n}\n\nfunction packAccountGasLimits(\n verificationGasLimit: bigint,\n callGasLimit: bigint,\n): Hex {\n const packed = (verificationGasLimit << 128n) | callGasLimit;\n return pad(`0x${packed.toString(16)}` as Hex, { size: 32 });\n}\n\nfunction packGasFees(\n maxPriorityFeePerGas: bigint,\n maxFeePerGas: bigint,\n): Hex {\n const packed = (maxPriorityFeePerGas << 128n) | maxFeePerGas;\n return pad(`0x${packed.toString(16)}` as Hex, { size: 32 });\n}\n\nfunction buildPaymasterAndData(userOp: {\n paymaster?: Hex;\n paymasterData?: Hex;\n paymasterVerificationGasLimit?: bigint;\n paymasterPostOpGasLimit?: bigint;\n}): Hex {\n if (!userOp.paymaster) return \"0x\";\n const pmGas = packAccountGasLimits(\n userOp.paymasterVerificationGasLimit ?? 0n,\n userOp.paymasterPostOpGasLimit ?? 0n,\n );\n return concat([userOp.paymaster, pmGas, userOp.paymasterData ?? \"0x\"]);\n}\n","import { encodeAbiParameters, keccak256, type Hex } from \"viem\";\nimport { entryPoint07Address } from \"../../../constants\";\n\nexport interface PackedUserOp {\n sender: Hex;\n nonce: bigint;\n initCode: Hex;\n callData: Hex;\n accountGasLimits: Hex;\n preVerificationGas: bigint;\n gasFees: Hex;\n paymasterAndData: Hex;\n}\n\n/**\n * Compute the UserOperation hash for EntryPoint v0.7 packed format.\n *\n * The hash is computed as:\n * keccak256(abi.encode(keccak256(pack(userOp)), entryPoint, chainId))\n *\n * where pack(userOp) encodes the UserOp fields with initCode, callData,\n * and paymasterAndData replaced by their keccak256 hashes.\n */\nexport function computeUserOpHash(\n packedUserOp: PackedUserOp,\n chainId: number,\n entrypoint: Hex = entryPoint07Address,\n): Hex {\n const encoded = encodeAbiParameters(\n [\n { type: \"address\" },\n { type: \"uint256\" },\n { type: \"bytes32\" },\n { type: \"bytes32\" },\n { type: \"bytes32\" },\n { type: \"uint256\" },\n { type: \"bytes32\" },\n { type: \"bytes32\" },\n ],\n [\n packedUserOp.sender,\n packedUserOp.nonce,\n keccak256(packedUserOp.initCode),\n keccak256(packedUserOp.callData),\n packedUserOp.accountGasLimits,\n packedUserOp.preVerificationGas,\n packedUserOp.gasFees,\n keccak256(packedUserOp.paymasterAndData),\n ],\n );\n\n const innerHash = keccak256(encoded);\n\n return keccak256(\n encodeAbiParameters(\n [{ type: \"bytes32\" }, { type: \"address\" }, { type: \"uint256\" }],\n [innerHash, entrypoint, BigInt(chainId)],\n ),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAAA;AAAA,EAAA;AAAA;AAAA;;;ACCA,IAAAC,eAAwD;AAExD,IAAAC,mBAAuE;;;ACFvE,IAAAC,eAAmC;AAEnC,sBAAmC;;;ACHnC,kBAA6C;AAmBtC,SAAS,wBAAwB,cAAmB,eAAyB;AAElF,QAAM,QAAI,iBAAI,cAAc,EAAE,MAAM,GAAG,CAAC;AAGxC,QAAM,gBAAgB;AACtB,QAAM,QAAI,qBAAI,mBAAM,aAAa,GAAG,EAAE,MAAM,GAAG,CAAC;AAGhD,QAAM,IAAI;AAGV,QAAM,kBAAkB,cAAc,SAAS,KAAK;AACpD,QAAM,aAAS,qBAAI,mBAAM,cAAc,GAAG,EAAE,MAAM,GAAG,CAAC;AAEtD,aAAO,oBAAO,CAAC,GAAG,GAAG,GAAG,QAAQ,aAAa,CAAC;AAChD;;;ACnCA,IAAAC,eAOO;;;ACNP,iCAAoC;AAI7B,IAAM,2BACX;AAEK,IAAM,8BACX;;;ADCF,IAAM,gBAAgB;AAAA,EACpB,QAAQ;AAAA,IACN,EAAE,MAAM,WAAW,MAAM,OAAO;AAAA,IAChC,EAAE,MAAM,WAAW,MAAM,QAAQ;AAAA,IACjC,EAAE,MAAM,SAAS,MAAM,WAAW;AAAA,IAClC,EAAE,MAAM,SAAS,MAAM,WAA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AAAA,QACJ,UAAU,cAAc;AAAA,QACxB,kBAAkB;AAAA,UAChB,cAAc;AAAA,UACd,cAAc;AAAA,QAChB;AAAA,QACA,oBAAoB,cAAc;AAAA,QAClC,SAAS;AAAA,UACP,cAAc;AAAA,UACd,cAAc;AAAA,QAChB;AAAA,QACA,kBAAkB,sBAAsB,aAAa;AAAA,MACvD;AAEA,YAAM,OAAO,kBAAkB,cAAc,SAAS,UAAU;AAChE,YAAM,EAAE,GAAG,EAAE,IAAI,MAAM,KAAK,IAAI;AAChC,iBAAO,qBAAO,KAAC,kBAAI,GAAG,EAAE,MAAM,GAAG,CAAC,OAAG,kBAAI,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC,CAAC;AAAA,IAC5D;AAAA,EACF,CAAC;AACH;AAEA,SAAS,qBACP,sBACA,cACK;AACL,QAAM,SAAU,wBAAwB,OAAQ;AAChD,aAAO,kBAAI,KAAK,OAAO,SAAS,EAAE,CAAC,IAAW,EAAE,MAAM,GAAG,CAAC;AAC5D;AAEA,SAAS,YACP,sBACA,cACK;AACL,QAAM,SAAU,wBAAwB,OAAQ;AAChD,aAAO,kBAAI,KAAK,OAAO,SAAS,EAAE,CAAC,IAAW,EAAE,MAAM,GAAG,CAAC;AAC5D;AAEA,SAAS,sBAAsB,QAKvB;AACN,MAAI,CAAC,OAAO,UAAW,QAAO;AAC9B,QAAM,QAAQ;AAAA,IACZ,OAAO,iCAAiC;AAAA,IACxC,OAAO,2BAA2B;AAAA,EACpC;AACA,aAAO,qBAAO,CAAC,OAAO,WAAW,OAAO,OAAO,iBAAiB,IAAI,CAAC;AACvE;","names":["toSafeSmartAccount","import_viem","import_accounts","import_viem","import_viem","import_accounts","toSafeSmartAccount","createMockLocalAccount","toPermissionlessSafeSmartAccount","import_viem","import_account_abstraction","import_viem"]}
1
+ {"version":3,"sources":["../../../src/accounts/index.ts","../../../src/accounts/toSafeSmartAccount.ts","../../../src/accounts/toP256SafeSmartAccount.ts","../../../src/accounts/encodeContractSignature.ts","../../../src/accounts/computeSafeOpHash.ts","../../../src/constants.ts","../../../src/accounts/toWebAuthnSafeSmartAccount.ts","../../../src/accounts/extractPasskeyCoordinates.ts","../../../src/accounts/toP256ExecutorModuleAccount.ts","../../../src/exact/client/utils/userOpHash.ts"],"sourcesContent":["// Unified API\nexport { toSafeSmartAccount } from \"./toSafeSmartAccount\";\n\n// Individual signer functions\nexport { toP256SafeSmartAccount } from \"./toP256SafeSmartAccount\";\nexport { toWebAuthnSafeSmartAccount } from \"./toWebAuthnSafeSmartAccount\";\n\n// Utilities\nexport { encodeContractSignature } from \"./encodeContractSignature\";\nexport { computeSafeOpHash } from \"./computeSafeOpHash\";\n\nexport { extractPasskeyCoordinates } from \"./extractPasskeyCoordinates\";\n\n// P256ExecutorModule adapter\nexport { toP256ExecutorModuleAccount } from \"./toP256ExecutorModuleAccount\";\nexport type { ToP256ExecutorModuleAccountParams } from \"./toP256ExecutorModuleAccount\";\n\n// Types\nexport type { P256Signer, SafeMessageSigner, ToP256SafeSmartAccountParams } from \"./types\";\nexport type { SignerConfig, ToSafeSmartAccountParams } from \"./types\";\nexport type { ToWebAuthnSafeSmartAccountParams } from \"./toWebAuthnSafeSmartAccount\";\nexport type { SafeOpHashParams } from \"./computeSafeOpHash\";\n","import type { Hex, LocalAccount } from \"viem\";\nimport { concat, encodeAbiParameters, pad, toHex } from \"viem\";\nimport type { SmartAccount, WebAuthnAccount } from \"viem/account-abstraction\";\nimport { toSafeSmartAccount as toPermissionlessSafeSmartAccount } from \"permissionless/accounts\";\n\nimport type { P256Signer, ToSafeSmartAccountParams } from \"./types\";\nimport { toP256SafeSmartAccount } from \"./toP256SafeSmartAccount\";\nimport { toWebAuthnSafeSmartAccount } from \"./toWebAuthnSafeSmartAccount\";\nimport { encodeContractSignature } from \"./encodeContractSignature\";\nimport { computeSafeOpHash } from \"./computeSafeOpHash\";\nimport type { SafeOpHashParams } from \"./computeSafeOpHash\";\nimport {\n SAFE_4337_MODULE_ADDRESS,\n SAFE_WEBAUTHN_SHARED_SIGNER,\n entryPoint07Address,\n} from \"../constants\";\n\n/**\n * Creates a Safe SmartAccount with a unified signer configuration.\n *\n * Dispatches to the appropriate implementation based on `signerConfig.type`:\n * - `\"p256\"`: P256 contract owner (existing `toP256SafeSmartAccount`)\n * - `\"webauthn\"`: WebAuthn passkey via permissionless native support\n * - `\"multi\"`: Both P256 and WebAuthn owners on a single Safe\n *\n * @example\n * ```typescript\n * // P256 only\n * const account = await toSafeSmartAccount({\n * client,\n * signerConfig: { type: \"p256\", p256Signer },\n * });\n *\n * // WebAuthn only\n * const account = await toSafeSmartAccount({\n * client,\n * signerConfig: { type: \"webauthn\", webAuthnAccount },\n * });\n *\n * // Multi-signer (threshold 1, P256 signs by default)\n * const account = await toSafeSmartAccount({\n * client,\n * signerConfig: {\n * type: \"multi\",\n * signers: { p256: p256Signer, webAuthn: webAuthnAccount },\n * threshold: 1,\n * },\n * });\n * ```\n */\nexport async function toSafeSmartAccount(\n params: ToSafeSmartAccountParams,\n): Promise<SmartAccount> {\n const { signerConfig } = params;\n\n switch (signerConfig.type) {\n case \"p256\":\n return toP256SafeSmartAccount({\n client: params.client,\n p256Signer: signerConfig.p256Signer,\n safeAddress: params.safeAddress,\n entryPoint: params.entryPoint,\n safe4337ModuleAddress: params.safe4337ModuleAddress,\n });\n\n case \"webauthn\":\n return toWebAuthnSafeSmartAccount({\n client: params.client,\n webAuthnAccount: signerConfig.webAuthnAccount,\n safeAddress: params.safeAddress,\n entryPoint: params.entryPoint,\n safe4337ModuleAddress: params.safe4337ModuleAddress,\n safeWebAuthnSharedSignerAddress: signerConfig.safeWebAuthnSharedSignerAddress,\n });\n\n case \"multi\":\n return buildMultiSignerAccount(params, signerConfig.signers, signerConfig.threshold ?? 1);\n }\n}\n\nfunction createMockLocalAccount(address: Hex): LocalAccount {\n const notImplemented = () => {\n throw new Error(\"Mock owner: use signUserOperation instead\");\n };\n\n return {\n address,\n type: \"local\",\n source: \"custom\",\n publicKey: \"0x\" as Hex,\n signMessage: notImplemented,\n signTypedData: notImplemented,\n signTransaction: notImplemented,\n sign: notImplemented,\n } as unknown as LocalAccount;\n}\n\n/**\n * Encodes a WebAuthn signature from raw sign() output into the ABI format\n * expected by Safe's WebAuthn verifier:\n * `(bytes authenticatorData, string clientDataFields, uint256[2] signature)`\n *\n * permissionless does not export this helper, so we implement it here.\n */\nasync function encodeWebAuthnSignature(\n owner: WebAuthnAccount,\n hash: Hex,\n): Promise<Hex> {\n const { signature: signatureData, webauthn } = await owner.sign({ hash });\n\n // Extract r, s from the DER-encoded P256 signature\n const sigBytes = signatureData.slice(2);\n const r = BigInt(\"0x\" + sigBytes.slice(0, 64));\n const s = BigInt(\"0x\" + sigBytes.slice(64, 128));\n\n // Extract the fields after \"challenge\":\"...\" from clientDataJSON\n const match = webauthn.clientDataJSON.match(\n /^\\{\"type\":\"webauthn.get\",\"challenge\":\"[A-Za-z0-9\\-_]{43}\",(.*)\\}$/,\n );\n const clientDataFields = match ? match[1] : \"\";\n\n return encodeAbiParameters(\n [\n { name: \"authenticatorData\", type: \"bytes\" },\n { name: \"clientDataFields\", type: \"string\" },\n { name: \"signature\", type: \"uint256[2]\" },\n ],\n [webauthn.authenticatorData, clientDataFields, [r, s]],\n );\n}\n\nasync function buildMultiSignerAccount(\n params: ToSafeSmartAccountParams,\n signers: { p256?: P256Signer; webAuthn?: WebAuthnAccount },\n threshold: number,\n): Promise<SmartAccount> {\n if (!signers.p256 && !signers.webAuthn) {\n throw new Error(\"Multi-signer config requires at least one signer\");\n }\n\n // If only one signer is provided, delegate to the single-signer function\n if (signers.p256 && !signers.webAuthn) {\n return toP256SafeSmartAccount({\n client: params.client,\n p256Signer: signers.p256,\n safeAddress: params.safeAddress,\n entryPoint: params.entryPoint,\n safe4337ModuleAddress: params.safe4337ModuleAddress,\n });\n }\n if (signers.webAuthn && !signers.p256) {\n const signerConfig = params.signerConfig;\n const sharedSignerAddr = signerConfig.type === \"multi\"\n ? signerConfig.safeWebAuthnSharedSignerAddress\n : undefined;\n return toWebAuthnSafeSmartAccount({\n client: params.client,\n webAuthnAccount: signers.webAuthn,\n safeAddress: params.safeAddress,\n entryPoint: params.entryPoint,\n safe4337ModuleAddress: params.safe4337ModuleAddress,\n safeWebAuthnSharedSignerAddress: sharedSignerAddr,\n });\n }\n\n // Both signers present\n const p256Signer = signers.p256!;\n const webAuthnAccount = signers.webAuthn!;\n\n const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_ADDRESS;\n const entryPointAddress = params.entryPoint?.address ?? entryPoint07Address;\n\n const mockP256Owner = createMockLocalAccount(p256Signer.p256OwnerAddress);\n\n // Build account with both owners: mock LocalAccount for P256 + WebAuthnAccount\n const baseAccount = await toPermissionlessSafeSmartAccount({\n client: params.client,\n owners: [mockP256Owner, webAuthnAccount],\n version: \"1.5.0\",\n threshold: BigInt(threshold),\n ...(params.safeAddress ? { address: params.safeAddress } : {}),\n entryPoint: {\n address: entryPointAddress,\n version: \"0.7\",\n },\n safe4337ModuleAddress,\n });\n\n const chainId = await params.client.getChainId();\n\n if (threshold >= 2) {\n return buildThreshold2Account(\n baseAccount as SmartAccount,\n p256Signer,\n webAuthnAccount,\n chainId,\n safe4337ModuleAddress,\n entryPointAddress,\n );\n }\n\n // Threshold 1: P256 signs by default (no browser interaction needed)\n return buildThreshold1Account(\n baseAccount as SmartAccount,\n p256Signer,\n chainId,\n safe4337ModuleAddress,\n entryPointAddress,\n );\n}\n\nfunction buildThreshold1Account(\n baseAccount: SmartAccount,\n p256Signer: P256Signer,\n chainId: number,\n safe4337ModuleAddress: Hex,\n entryPointAddress: Hex,\n): SmartAccount {\n return {\n ...baseAccount,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async signUserOperation(userOp: any) {\n const safeOpHash = computeSafeOpHash(\n extractSafeOpHashParams(userOp),\n chainId,\n safe4337ModuleAddress,\n entryPointAddress,\n );\n\n const { r, s } = await p256Signer.sign(safeOpHash);\n const rPadded = pad(r as Hex, { size: 32 });\n const sPadded = pad(s as Hex, { size: 32 });\n const p256Signature = concat([rPadded, sPadded]);\n\n const contractSig = encodeContractSignature(\n p256Signer.p256OwnerAddress,\n p256Signature,\n );\n\n const validAfter = pad(toHex(0), { size: 6 });\n const validUntil = pad(toHex(0), { size: 6 });\n\n return concat([validAfter, validUntil, contractSig]);\n },\n } as SmartAccount;\n}\n\nfunction buildThreshold2Account(\n baseAccount: SmartAccount,\n p256Signer: P256Signer,\n webAuthnAccount: WebAuthnAccount,\n chainId: number,\n safe4337ModuleAddress: Hex,\n entryPointAddress: Hex,\n): SmartAccount {\n return {\n ...baseAccount,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async signUserOperation(userOp: any) {\n const safeOpHash = computeSafeOpHash(\n extractSafeOpHashParams(userOp),\n chainId,\n safe4337ModuleAddress,\n entryPointAddress,\n );\n\n // Sign with P256\n const { r, s } = await p256Signer.sign(safeOpHash);\n const rPadded = pad(r as Hex, { size: 32 });\n const sPadded = pad(s as Hex, { size: 32 });\n const p256SignatureData = concat([rPadded, sPadded]);\n\n // Sign with WebAuthn\n const webAuthnSignatureData = await encodeWebAuthnSignature(\n webAuthnAccount,\n safeOpHash,\n );\n\n // Build sorted multi-signature\n // Safe requires signatures sorted by signer address (ascending)\n const p256SignerAddress = p256Signer.p256OwnerAddress.toLowerCase();\n const webAuthnSignerAddress = SAFE_WEBAUTHN_SHARED_SIGNER.toLowerCase();\n\n type SignerEntry = {\n address: string;\n data: Hex;\n dynamic: boolean;\n contractOwner: boolean;\n };\n\n const signerEntries: SignerEntry[] = [\n {\n address: p256SignerAddress,\n data: p256SignatureData,\n dynamic: true,\n contractOwner: true,\n },\n {\n address: webAuthnSignerAddress,\n data: webAuthnSignatureData,\n dynamic: true,\n contractOwner: false,\n },\n ].sort((a, b) => (a.address < b.address ? -1 : 1));\n\n const concatenatedSig = concatSafeSignatures(signerEntries);\n\n const validAfter = pad(toHex(0), { size: 6 });\n const validUntil = pad(toHex(0), { size: 6 });\n\n return concat([validAfter, validUntil, concatenatedSig]);\n },\n } as SmartAccount;\n}\n\n/**\n * Concatenates multiple Safe signatures with proper static/dynamic layout.\n *\n * Safe's `checkNSignatures` expects:\n * - N x 65-byte static parts (sorted by signer address)\n * - Dynamic data appended after all static parts\n *\n * For dynamic signatures (contract or WebAuthn):\n * Static: r = address padded to 32 bytes, s = offset to dynamic data, v = 0x00\n * Dynamic: 32-byte length prefix + signature data\n *\n * For ECDSA signatures:\n * Static: r (32 bytes) + s (32 bytes) + v (1 byte)\n */\nfunction concatSafeSignatures(\n entries: { address: string; data: Hex; dynamic: boolean; contractOwner: boolean }[],\n): Hex {\n const staticPartSize = 65; // per signer\n const totalStaticSize = staticPartSize * entries.length;\n\n const staticParts: Hex[] = [];\n const dynamicParts: Hex[] = [];\n let dynamicOffset = totalStaticSize;\n\n for (const entry of entries) {\n if (entry.dynamic) {\n // Dynamic signature: static part points to dynamic data\n const r = pad(entry.address as Hex, { size: 32 });\n const s = pad(toHex(dynamicOffset), { size: 32 });\n const v = \"0x00\" as Hex;\n staticParts.push(concat([r, s, v]));\n\n // Dynamic part: length-prefixed data\n const dataBytes = (entry.data.length - 2) / 2;\n const length = pad(toHex(dataBytes), { size: 32 });\n dynamicParts.push(concat([length, entry.data]));\n\n // Advance offset: 32 bytes for length + actual data length\n dynamicOffset += 32 + dataBytes;\n } else {\n // ECDSA: direct 65-byte signature (not used in current multi-signer paths)\n staticParts.push(entry.data);\n }\n }\n\n return concat([...staticParts, ...dynamicParts]);\n}\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nfunction extractSafeOpHashParams(userOp: any): SafeOpHashParams {\n const op = userOp as Record<string, unknown>;\n return {\n sender: op.sender as Hex,\n nonce: BigInt(op.nonce as bigint),\n factory: (op.factory as Hex) ?? null,\n factoryData: (op.factoryData as Hex) ?? null,\n callData: op.callData as Hex,\n verificationGasLimit: BigInt(op.verificationGasLimit as bigint),\n callGasLimit: BigInt(op.callGasLimit as bigint),\n preVerificationGas: BigInt(op.preVerificationGas as bigint),\n maxPriorityFeePerGas: BigInt(op.maxPriorityFeePerGas as bigint),\n maxFeePerGas: BigInt(op.maxFeePerGas as bigint),\n paymaster: (op.paymaster as Hex) ?? null,\n paymasterVerificationGasLimit: op.paymasterVerificationGasLimit\n ? BigInt(op.paymasterVerificationGasLimit as bigint)\n : null,\n paymasterPostOpGasLimit: op.paymasterPostOpGasLimit\n ? BigInt(op.paymasterPostOpGasLimit as bigint)\n : null,\n paymasterData: (op.paymasterData as Hex) ?? null,\n };\n}\n","import type { Hex, LocalAccount } from \"viem\";\nimport { concat, pad, toHex } from \"viem\";\nimport type { SmartAccount } from \"viem/account-abstraction\";\nimport { toSafeSmartAccount } from \"permissionless/accounts\";\n\nimport type { ToP256SafeSmartAccountParams } from \"./types\";\nimport { encodeContractSignature } from \"./encodeContractSignature\";\nimport type { SafeOpHashParams } from \"./computeSafeOpHash\";\nimport { computeSafeOpHash } from \"./computeSafeOpHash\";\nimport { SAFE_4337_MODULE_ADDRESS, entryPoint07Address } from \"../constants\";\n\n/**\n * Creates a mock LocalAccount that has the P256Owner contract address.\n *\n * This is needed because `toSafeSmartAccount` requires a `LocalAccount` owner,\n * but our actual signer is a P256Owner contract (ERC-1271). The mock provides\n * the correct address so the Safe is configured with the right owner. The\n * signing methods are never called since we override `signUserOperation`.\n */\nfunction createMockLocalAccount(address: Hex): LocalAccount {\n const notImplemented = () => {\n throw new Error(\"P256 contract owner: use signUserOperation instead\");\n };\n\n return {\n address,\n type: \"local\",\n source: \"custom\",\n publicKey: \"0x\" as Hex,\n signMessage: notImplemented,\n signTypedData: notImplemented,\n signTransaction: notImplemented,\n sign: notImplemented,\n } as unknown as LocalAccount;\n}\n\n/**\n * Creates a Safe SmartAccount that signs UserOperations with a P256 contract owner.\n *\n * This wraps permissionless's `toSafeSmartAccount` and overrides `signUserOperation`\n * to produce P256 signatures in Safe's contract signature format (v=0). The resulting\n * account is compatible with `SafeAccountSigner` and `ExactEvmSchemeERC4337`.\n *\n * The caller is responsible for:\n * - Deploying the P256Owner contract (or computing its deterministic address)\n * - Providing the `sign()` function (e.g., using `@noble/curves/p256` with `prehash: false`)\n * - Ensuring the P256Owner is an owner of the Safe\n *\n * @example\n * ```typescript\n * import { toP256SafeSmartAccount } from '@introspectivelabs/x402-evm';\n * import { p256 } from '@noble/curves/p256';\n *\n * const account = await toP256SafeSmartAccount({\n * client: publicClient,\n * p256Signer: {\n * p256OwnerAddress: '0x349c...',\n * sign: async (hash) => {\n * const sig = p256.sign(hash.slice(2), privateKey, { prehash: false, lowS: true });\n * return {\n * r: `0x${sig.r.toString(16).padStart(64, '0')}`,\n * s: `0x${sig.s.toString(16).padStart(64, '0')}`,\n * };\n * },\n * },\n * safeAddress: '0x...',\n * });\n *\n * const scheme = new ExactEvmSchemeERC4337({ account });\n * ```\n */\nexport async function toP256SafeSmartAccount(\n params: ToP256SafeSmartAccountParams,\n): Promise<SmartAccount> {\n const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_ADDRESS;\n const entryPointAddress =\n params.entryPoint?.address ?? entryPoint07Address;\n\n const mockOwner = createMockLocalAccount(params.p256Signer.p256OwnerAddress);\n\n const baseAccount = await toSafeSmartAccount({\n client: params.client,\n owners: [mockOwner],\n version: \"1.5.0\",\n ...(params.safeAddress ? { address: params.safeAddress } : {}),\n entryPoint: {\n address: entryPointAddress,\n version: \"0.7\",\n },\n safe4337ModuleAddress,\n });\n\n const chainId = await params.client.getChainId();\n\n return {\n ...baseAccount,\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n async signUserOperation(userOp: any) {\n const op = userOp as Record<string, unknown>;\n // Compute the SafeOp EIP-712 hash (what Safe4337Module verifies)\n const hashParams: SafeOpHashParams = {\n sender: op.sender as Hex,\n nonce: BigInt(op.nonce as bigint),\n factory: (op.factory as Hex) ?? null,\n factoryData: (op.factoryData as Hex) ?? null,\n callData: op.callData as Hex,\n verificationGasLimit: BigInt(op.verificationGasLimit as bigint),\n callGasLimit: BigInt(op.callGasLimit as bigint),\n preVerificationGas: BigInt(op.preVerificationGas as bigint),\n maxPriorityFeePerGas: BigInt(op.maxPriorityFeePerGas as bigint),\n maxFeePerGas: BigInt(op.maxFeePerGas as bigint),\n paymaster: (op.paymaster as Hex) ?? null,\n paymasterVerificationGasLimit: op.paymasterVerificationGasLimit\n ? BigInt(op.paymasterVerificationGasLimit as bigint)\n : null,\n paymasterPostOpGasLimit: op.paymasterPostOpGasLimit\n ? BigInt(op.paymasterPostOpGasLimit as bigint)\n : null,\n paymasterData: (op.paymasterData as Hex) ?? null,\n };\n const safeOpHash = computeSafeOpHash(\n hashParams,\n chainId,\n safe4337ModuleAddress,\n entryPointAddress,\n );\n\n // Sign the SafeOp hash with P256\n const { r, s } = await params.p256Signer.sign(safeOpHash);\n\n // Encode r || s as 64-byte signature\n const rPadded = pad(r as Hex, { size: 32 });\n const sPadded = pad(s as Hex, { size: 32 });\n const p256Signature = concat([rPadded, sPadded]);\n\n // Wrap in Safe contract signature format (v=0)\n const contractSig = encodeContractSignature(\n params.p256Signer.p256OwnerAddress,\n p256Signature,\n );\n\n // Safe4337Module expects: validAfter (6 bytes) || validUntil (6 bytes) || signatures\n const validAfter = pad(toHex(0), { size: 6 });\n const validUntil = pad(toHex(0), { size: 6 });\n\n return concat([validAfter, validUntil, contractSig]);\n },\n } as SmartAccount;\n}\n","import { type Hex, concat, pad, toHex } from \"viem\";\n\n/**\n * Encodes a signature in Safe's contract signature format (v=0).\n *\n * Safe's `checkNSignatures` expects this layout for contract owners:\n *\n * Static part (65 bytes):\n * - r (32 bytes): owner address padded to 32 bytes\n * - s (32 bytes): offset to dynamic data (relative to start of signatures)\n * - v (1 byte): 0x00 (indicates contract signature)\n *\n * Dynamic part (at the offset):\n * - length (32 bytes): length of the signature data\n * - data (variable): the actual signature bytes\n *\n * For a single signer, the static part is 65 bytes, so the dynamic data\n * starts at offset 65.\n */\nexport function encodeContractSignature(ownerAddress: Hex, signatureData: Hex): Hex {\n // Static part: r = address padded to 32 bytes\n const r = pad(ownerAddress, { size: 32 });\n\n // For a single signature, dynamic data starts right after the 65-byte static part\n const dynamicOffset = 65;\n const s = pad(toHex(dynamicOffset), { size: 32 });\n\n // v = 0x00 for contract signature\n const v = \"0x00\" as Hex;\n\n // Dynamic part: length-prefixed signature data\n const signatureBytes = (signatureData.length - 2) / 2;\n const length = pad(toHex(signatureBytes), { size: 32 });\n\n return concat([r, s, v, length, signatureData]);\n}\n","import {\n type Hex,\n concat,\n hashTypedData,\n isAddress,\n pad,\n toHex,\n} from \"viem\";\nimport { SAFE_4337_MODULE_ADDRESS, entryPoint07Address } from \"../constants\";\n\nconst SAFE_OP_TYPES = {\n SafeOp: [\n { type: \"address\", name: \"safe\" },\n { type: \"uint256\", name: \"nonce\" },\n { type: \"bytes\", name: \"initCode\" },\n { type: \"bytes\", name: \"callData\" },\n { type: \"uint128\", name: \"verificationGasLimit\" },\n { type: \"uint128\", name: \"callGasLimit\" },\n { type: \"uint256\", name: \"preVerificationGas\" },\n { type: \"uint128\", name: \"maxPriorityFeePerGas\" },\n { type: \"uint128\", name: \"maxFeePerGas\" },\n { type: \"bytes\", name: \"paymasterAndData\" },\n { type: \"uint48\", name: \"validAfter\" },\n { type: \"uint48\", name: \"validUntil\" },\n { type: \"address\", name: \"entryPoint\" },\n ],\n} as const;\n\nexport interface SafeOpHashParams {\n sender: Hex;\n nonce: bigint;\n factory?: Hex | null;\n factoryData?: Hex | null;\n callData: Hex;\n verificationGasLimit: bigint;\n callGasLimit: bigint;\n preVerificationGas: bigint;\n maxPriorityFeePerGas: bigint;\n maxFeePerGas: bigint;\n paymaster?: Hex | null;\n paymasterVerificationGasLimit?: bigint | null;\n paymasterPostOpGasLimit?: bigint | null;\n paymasterData?: Hex | null;\n}\n\n/**\n * Computes the EIP-712 SafeOp hash that Safe4337Module uses for signature verification.\n *\n * The Safe4337Module converts the EntryPoint v0.7 UserOperation into a SafeOp struct,\n * packing initCode and paymasterAndData into their v0.6-style concatenated forms,\n * then hashes the struct using EIP-712.\n */\nexport function computeSafeOpHash(\n userOp: SafeOpHashParams,\n chainId: number,\n safe4337ModuleAddress: Hex = SAFE_4337_MODULE_ADDRESS,\n entryPointAddress: Hex = entryPoint07Address,\n): Hex {\n // Reconstruct initCode: factory || factoryData (v0.7 -> v0.6 style)\n const initCode =\n userOp.factory && isAddress(userOp.factory)\n ? concat([userOp.factory, (userOp.factoryData || \"0x\") as Hex])\n : (\"0x\" as Hex);\n\n // Reconstruct paymasterAndData: paymaster || verificationGasLimit(16) || postOpGasLimit(16) || data\n let paymasterAndData: Hex = \"0x\";\n if (userOp.paymaster && isAddress(userOp.paymaster)) {\n paymasterAndData = concat([\n userOp.paymaster,\n pad(toHex(userOp.paymasterVerificationGasLimit || 0n), { size: 16 }),\n pad(toHex(userOp.paymasterPostOpGasLimit || 0n), { size: 16 }),\n (userOp.paymasterData || \"0x\") as Hex,\n ]);\n }\n\n return hashTypedData({\n domain: {\n chainId,\n verifyingContract: safe4337ModuleAddress,\n },\n types: SAFE_OP_TYPES,\n primaryType: \"SafeOp\",\n message: {\n safe: userOp.sender,\n nonce: userOp.nonce,\n initCode,\n callData: userOp.callData,\n verificationGasLimit: userOp.verificationGasLimit,\n callGasLimit: userOp.callGasLimit,\n preVerificationGas: userOp.preVerificationGas,\n maxPriorityFeePerGas: userOp.maxPriorityFeePerGas,\n maxFeePerGas: userOp.maxFeePerGas,\n paymasterAndData,\n validAfter: 0,\n validUntil: 0,\n entryPoint: entryPointAddress,\n },\n });\n}\n","import type { Hex } from \"viem\";\nimport { entryPoint07Address } from \"viem/account-abstraction\";\n\nexport { entryPoint07Address };\n\nexport const SAFE_4337_MODULE_ADDRESS =\n \"0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226\" as const satisfies Hex;\n\nexport const SAFE_WEBAUTHN_SHARED_SIGNER =\n \"0x94a4F6affBd8975951142c3999aEAB7ecee555c2\" as const satisfies Hex;\n\nexport const FCL_P256_VERIFIER =\n \"0xA86e0054C51E4894D88762a017ECc5E5235f5DBA\" as const satisfies Hex;\n\nexport const P256_OWNER_FACTORY =\n \"0x349c03Eb61e26528cbf79F5D3Ba071FcA2aE82cB\" as const satisfies Hex;\n\nexport const WEBAUTHN_SIGNER_FACTORY =\n \"0xF7488fFbe67327ac9f37D5F722d83Fc900852Fbf\" as const satisfies Hex;\n\nexport const GUARD_FACTORY =\n \"0x35E2B487b682029e363BA7f06fD7392834A83077\" as const satisfies Hex;\n","import type { Hex } from \"viem\";\nimport type { SmartAccount, WebAuthnAccount } from \"viem/account-abstraction\";\nimport { toSafeSmartAccount } from \"permissionless/accounts\";\nimport type { PublicClient, Transport, Chain } from \"viem\";\nimport { SAFE_4337_MODULE_ADDRESS, entryPoint07Address } from \"../constants\";\n\nexport type ToWebAuthnSafeSmartAccountParams = {\n client: PublicClient<Transport, Chain>;\n webAuthnAccount: WebAuthnAccount;\n safeAddress?: Hex;\n entryPoint?: { address: Hex; version: \"0.7\" };\n safe4337ModuleAddress?: Hex;\n safeWebAuthnSharedSignerAddress?: Hex;\n};\n\n/**\n * Creates a Safe SmartAccount that signs UserOperations with a WebAuthn passkey.\n */\nexport async function toWebAuthnSafeSmartAccount(\n params: ToWebAuthnSafeSmartAccountParams,\n): Promise<SmartAccount> {\n const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_ADDRESS;\n const entryPointAddress = params.entryPoint?.address ?? entryPoint07Address;\n\n const baseAccount = await toSafeSmartAccount({\n client: params.client,\n owners: [params.webAuthnAccount],\n version: \"1.5.0\",\n ...(params.safeAddress ? { address: params.safeAddress } : {}),\n entryPoint: {\n address: entryPointAddress,\n version: \"0.7\",\n },\n safe4337ModuleAddress,\n ...(params.safeWebAuthnSharedSignerAddress\n ? { safeWebAuthnSharedSignerAddress: params.safeWebAuthnSharedSignerAddress }\n : {}),\n });\n\n return baseAccount as SmartAccount;\n}\n","/// <reference lib=\"dom\" />\nimport type { Hex } from \"viem\";\n\nfunction bufferToHex(buffer: ArrayBuffer): string {\n return Array.from(new Uint8Array(buffer))\n .map((b) => b.toString(16).padStart(2, \"0\"))\n .join(\"\");\n}\n\nfunction base64urlToHex(base64url: string): string {\n const base64 = base64url.replace(/-/g, \"+\").replace(/_/g, \"/\");\n const binary = atob(base64);\n return Array.from(binary, (c) => c.charCodeAt(0).toString(16).padStart(2, \"0\")).join(\"\");\n}\n\n/**\n * Extracts P256 public key coordinates from a WebAuthn credential.\n *\n * Replaces `extractPasskeyData` from `@safe-global/protocol-kit`.\n * Uses only the Web Crypto API (no external dependencies).\n */\nexport async function extractPasskeyCoordinates(\n credential: PublicKeyCredential,\n): Promise<{ rawId: string; x: Hex; y: Hex }> {\n const rawId = bufferToHex(credential.rawId);\n const response = credential.response as AuthenticatorAttestationResponse;\n const publicKey = response.getPublicKey();\n if (!publicKey) throw new Error(\"Failed to extract public key from credential\");\n\n const key = await crypto.subtle.importKey(\n \"spki\",\n publicKey,\n { name: \"ECDSA\", namedCurve: \"P-256\" },\n true,\n [\"verify\"],\n );\n const jwk = await crypto.subtle.exportKey(\"jwk\", key);\n if (!jwk.x || !jwk.y) throw new Error(\"Missing coordinates in JWK\");\n\n return {\n rawId,\n x: (\"0x\" + base64urlToHex(jwk.x)) as Hex,\n y: (\"0x\" + base64urlToHex(jwk.y)) as Hex,\n };\n}\n","import {\n concat,\n encodeFunctionData,\n pad,\n type Chain,\n type Hex,\n type PublicClient,\n type Transport,\n} from \"viem\";\nimport { toSmartAccount, type SmartAccount } from \"viem/account-abstraction\";\nimport { entryPoint07Address } from \"../constants\";\nimport { computeUserOpHash, type PackedUserOp } from \"../exact/client/utils/userOpHash\";\n\nconst P256_EXECUTOR_MODULE_ABI = [\n {\n inputs: [\n { name: \"to\", type: \"address\" },\n { name: \"value\", type: \"uint256\" },\n { name: \"data\", type: \"bytes\" },\n { name: \"operation\", type: \"uint8\" },\n ],\n name: \"execute\",\n outputs: [],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n] as const;\n\nconst ENTRYPOINT_07_ABI = [\n {\n name: \"getNonce\",\n type: \"function\",\n inputs: [\n { name: \"sender\", type: \"address\" },\n { name: \"key\", type: \"uint192\" },\n ],\n outputs: [{ name: \"nonce\", type: \"uint256\" }],\n stateMutability: \"view\",\n },\n] as const;\n\nexport interface ToP256ExecutorModuleAccountParams {\n client: PublicClient<Transport, Chain>;\n moduleAddress: Hex;\n sign: (hash: Hex) => Promise<{ r: Hex; s: Hex }>;\n entryPointAddress?: Hex;\n}\n\n/**\n * Creates a viem SmartAccount adapter for P256ExecutorModule.\n *\n * The module is the UserOp sender (not the Safe). CallData encodes\n * `module.execute(to, value, data, 0)` and the signature is raw\n * P256 `r || s` (64 bytes).\n *\n * Use this with `ExactEvmSchemeERC4337` to handle ERC-4337 payments\n * where the P256ExecutorModule is the account.\n */\nexport async function toP256ExecutorModuleAccount(\n params: ToP256ExecutorModuleAccountParams,\n): Promise<SmartAccount> {\n const { client, moduleAddress, sign } = params;\n const entryPoint = params.entryPointAddress ?? entryPoint07Address;\n\n return toSmartAccount({\n client,\n entryPoint: {\n abi: ENTRYPOINT_07_ABI,\n address: entryPoint,\n version: \"0.7\",\n },\n\n async getAddress() {\n return moduleAddress;\n },\n\n async encodeCalls(calls) {\n if (calls.length !== 1) {\n throw new Error(\n \"P256ExecutorModule does not support batch calls. \" +\n `Received ${calls.length} calls, expected 1.`,\n );\n }\n const { to, value, data } = calls[0];\n return encodeFunctionData({\n abi: P256_EXECUTOR_MODULE_ABI,\n functionName: \"execute\",\n args: [to, value ?? 0n, data ?? \"0x\", 0],\n });\n },\n\n async getNonce() {\n return await client.readContract({\n address: entryPoint,\n abi: ENTRYPOINT_07_ABI,\n functionName: \"getNonce\",\n args: [moduleAddress, 0n],\n }) as bigint;\n },\n\n async getFactoryArgs() {\n return { factory: undefined, factoryData: undefined };\n },\n\n async getStubSignature() {\n return (\"0x\" + \"ff\".repeat(64)) as Hex;\n },\n\n async signMessage() {\n throw new Error(\"P256ExecutorModule does not support signMessage\");\n },\n\n async signTypedData() {\n throw new Error(\"P256ExecutorModule does not support signTypedData\");\n },\n\n async signUserOperation(userOperation) {\n const chainId = client.chain.id;\n\n const factory = userOperation.factory as Hex | undefined;\n const packedUserOp: PackedUserOp = {\n sender: userOperation.sender as Hex,\n nonce: userOperation.nonce,\n initCode: factory\n ? concat([factory, (userOperation.factoryData ?? \"0x\") as Hex])\n : \"0x\",\n callData: userOperation.callData,\n accountGasLimits: packAccountGasLimits(\n userOperation.verificationGasLimit,\n userOperation.callGasLimit,\n ),\n preVerificationGas: userOperation.preVerificationGas,\n gasFees: packGasFees(\n userOperation.maxPriorityFeePerGas,\n userOperation.maxFeePerGas,\n ),\n paymasterAndData: buildPaymasterAndData(userOperation),\n };\n\n const hash = computeUserOpHash(packedUserOp, chainId, entryPoint);\n const { r, s } = await sign(hash);\n return concat([pad(r, { size: 32 }), pad(s, { size: 32 })]);\n },\n });\n}\n\nfunction packAccountGasLimits(\n verificationGasLimit: bigint,\n callGasLimit: bigint,\n): Hex {\n const packed = (verificationGasLimit << 128n) | callGasLimit;\n return pad(`0x${packed.toString(16)}` as Hex, { size: 32 });\n}\n\nfunction packGasFees(\n maxPriorityFeePerGas: bigint,\n maxFeePerGas: bigint,\n): Hex {\n const packed = (maxPriorityFeePerGas << 128n) | maxFeePerGas;\n return pad(`0x${packed.toString(16)}` as Hex, { size: 32 });\n}\n\nfunction buildPaymasterAndData(userOp: {\n paymaster?: Hex;\n paymasterData?: Hex;\n paymasterVerificationGasLimit?: bigint;\n paymasterPostOpGasLimit?: bigint;\n}): Hex {\n if (!userOp.paymaster) return \"0x\";\n const pmGas = packAccountGasLimits(\n userOp.paymasterVerificationGasLimit ?? 0n,\n userOp.paymasterPostOpGasLimit ?? 0n,\n );\n return concat([userOp.paymaster, pmGas, userOp.paymasterData ?? \"0x\"]);\n}\n","import { encodeAbiParameters, keccak256, type Hex } from \"viem\";\nimport { entryPoint07Address } from \"../../../constants\";\n\nexport interface PackedUserOp {\n sender: Hex;\n nonce: bigint;\n initCode: Hex;\n callData: Hex;\n accountGasLimits: Hex;\n preVerificationGas: bigint;\n gasFees: Hex;\n paymasterAndData: Hex;\n}\n\n/**\n * Compute the UserOperation hash for EntryPoint v0.7 packed format.\n *\n * The hash is computed as:\n * keccak256(abi.encode(keccak256(pack(userOp)), entryPoint, chainId))\n *\n * where pack(userOp) encodes the UserOp fields with initCode, callData,\n * and paymasterAndData replaced by their keccak256 hashes.\n */\nexport function computeUserOpHash(\n packedUserOp: PackedUserOp,\n chainId: number,\n entrypoint: Hex = entryPoint07Address,\n): Hex {\n const encoded = encodeAbiParameters(\n [\n { type: \"address\" },\n { type: \"uint256\" },\n { type: \"bytes32\" },\n { type: \"bytes32\" },\n { type: \"bytes32\" },\n { type: \"uint256\" },\n { type: \"bytes32\" },\n { type: \"bytes32\" },\n ],\n [\n packedUserOp.sender,\n packedUserOp.nonce,\n keccak256(packedUserOp.initCode),\n keccak256(packedUserOp.callData),\n packedUserOp.accountGasLimits,\n packedUserOp.preVerificationGas,\n packedUserOp.gasFees,\n keccak256(packedUserOp.paymasterAndData),\n ],\n );\n\n const innerHash = keccak256(encoded);\n\n return keccak256(\n encodeAbiParameters(\n [{ type: \"bytes32\" }, { type: \"address\" }, { type: \"uint256\" }],\n [innerHash, entrypoint, BigInt(chainId)],\n ),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,4BAAAA;AAAA,EAAA;AAAA;AAAA;;;ACCA,IAAAC,eAAwD;AAExD,IAAAC,mBAAuE;;;ACFvE,IAAAC,eAAmC;AAEnC,sBAAmC;;;ACHnC,kBAA6C;AAmBtC,SAAS,wBAAwB,cAAmB,eAAyB;AAElF,QAAM,QAAI,iBAAI,cAAc,EAAE,MAAM,GAAG,CAAC;AAGxC,QAAM,gBAAgB;AACtB,QAAM,QAAI,qBAAI,mBAAM,aAAa,GAAG,EAAE,MAAM,GAAG,CAAC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AAM,GAAG,CAAC;AAC5D;AAEA,SAAS,sBAAsB,QAKvB;AACN,MAAI,CAAC,OAAO,UAAW,QAAO;AAC9B,QAAM,QAAQ;AAAA,IACZ,OAAO,iCAAiC;AAAA,IACxC,OAAO,2BAA2B;AAAA,EACpC;AACA,aAAO,qBAAO,CAAC,OAAO,WAAW,OAAO,OAAO,iBAAiB,IAAI,CAAC;AACvE;","names":["toSafeSmartAccount","import_viem","import_accounts","import_viem","import_viem","import_accounts","toSafeSmartAccount","createMockLocalAccount","toPermissionlessSafeSmartAccount","import_viem","import_account_abstraction","import_viem"]}
@@ -1,5 +1,5 @@
1
1
  declare const SAFE_4337_MODULE_ADDRESS: "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226";
2
- declare const SAFE_WEBAUTHN_SHARED_SIGNER: "0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9";
2
+ declare const SAFE_WEBAUTHN_SHARED_SIGNER: "0x94a4F6affBd8975951142c3999aEAB7ecee555c2";
3
3
  declare const FCL_P256_VERIFIER: "0xA86e0054C51E4894D88762a017ECc5E5235f5DBA";
4
4
  declare const P256_OWNER_FACTORY: "0x349c03Eb61e26528cbf79F5D3Ba071FcA2aE82cB";
5
5
  declare const WEBAUTHN_SIGNER_FACTORY: "0xF7488fFbe67327ac9f37D5F722d83Fc900852Fbf";
@@ -1,10 +1,10 @@
1
- import { U as UserOperationSigner, P as PreparedUserOperation } from '../../userOpHash-Bzusu9T7.js';
2
- export { B as BundlerClient, f as BundlerClientConfig, j as ERC20_TRANSFER_ABI, b as ExactEvmSchemeEIP3009, c as ExactEvmSchemeEIP3009Config, E as ExactEvmSchemeERC4337, a as ExactEvmSchemeERC4337Config, G as GasEstimate, l as PackedUserOp, g as UserOperationCall, V as ViemBundlerClient, h as ViemBundlerClientConfig, i as buildERC20TransferCallData, k as computeUserOpHash, d as createP256SafeMessageSigner, e as createWebAuthnSafeMessageSigner, u as userOpToJson } from '../../userOpHash-Bzusu9T7.js';
1
+ import { U as UserOperationSigner, P as PreparedUserOperation } from '../../userOpHash-CLhOwl2X.js';
2
+ export { B as BundlerClient, f as BundlerClientConfig, j as ERC20_TRANSFER_ABI, b as ExactEvmSchemeEIP3009, c as ExactEvmSchemeEIP3009Config, E as ExactEvmSchemeERC4337, a as ExactEvmSchemeERC4337Config, G as GasEstimate, l as PackedUserOp, g as UserOperationCall, V as ViemBundlerClient, h as ViemBundlerClientConfig, i as buildERC20TransferCallData, k as computeUserOpHash, d as createP256SafeMessageSigner, e as createWebAuthnSafeMessageSigner, u as userOpToJson } from '../../userOpHash-CLhOwl2X.js';
3
3
  import { SmartAccount } from 'viem/account-abstraction';
4
4
  import 'viem';
5
- import '../../types-Dk5U6Xnw.js';
6
5
  import '../../types-lO5B0FRc.js';
7
6
  import '@x402/core/types';
7
+ import '../../types-Dk5U6Xnw.js';
8
8
 
9
9
  /**
10
10
  * Adapter to make a SmartAccount (e.g., Safe account) work as a UserOperationSigner.
@@ -53,15 +53,13 @@ var import_viem5 = require("viem");
53
53
  // src/exact/client/bundler/viem.ts
54
54
  var import_viem = require("viem");
55
55
  var import_account_abstraction = require("viem/account-abstraction");
56
+ function bigintToHex(n) {
57
+ return `0x${n.toString(16)}`;
58
+ }
56
59
  var ViemBundlerClient = class {
57
- /**
58
- * Creates a new ViemBundlerClient instance.
59
- *
60
- * @param config - Configuration for the bundler client
61
- */
62
60
  constructor(config) {
63
61
  this.account = config.account;
64
- this.entryPoint = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
62
+ this.usePaymaster = config.paymaster === true;
65
63
  this.bundlerClient = (0, import_account_abstraction.createBundlerClient)({
66
64
  client: config.publicClient,
67
65
  chain: config.chain,
@@ -70,13 +68,91 @@ var ViemBundlerClient = class {
70
68
  });
71
69
  }
72
70
  /**
73
- * Prepares an unsigned user operation for the given calls.
71
+ * Prepares an unsigned user operation using raw RPC calls.
74
72
  *
75
- * @param calls - Array of calls to execute in the user operation
76
- * @param _entryPoint - The entry point address (unused, viem uses the configured entry point)
77
- * @returns Promise resolving to a prepared (unsigned) user operation
73
+ * When paymaster is enabled, uses pm_sponsorUserOperation to get paymaster
74
+ * data and gas estimates in a single call (Pimlico-compatible).
75
+ * The returned UserOp has final paymaster data ready for hash computation and signing.
78
76
  */
79
- async prepareUserOperation(calls, _entryPoint) {
77
+ async prepareUserOperation(calls, entryPoint) {
78
+ if (!this.usePaymaster) {
79
+ return this.prepareWithoutPaymaster(calls);
80
+ }
81
+ const callData = await this.account.encodeCalls(
82
+ calls.map((call) => ({
83
+ to: call.to,
84
+ value: call.value,
85
+ data: call.data
86
+ }))
87
+ );
88
+ const nonce = await this.account.getNonce();
89
+ const sender = await this.account.getAddress();
90
+ const gasPriceResult = await this.bundlerClient.request({
91
+ method: "pimlico_getUserOperationGasPrice",
92
+ params: []
93
+ });
94
+ const maxFeePerGas = BigInt(gasPriceResult.fast.maxFeePerGas);
95
+ const maxPriorityFeePerGas = BigInt(gasPriceResult.fast.maxPriorityFeePerGas);
96
+ const stubSignature = await this.account.getStubSignature();
97
+ {
98
+ const userOpForEstimation = {
99
+ sender,
100
+ nonce: `0x${nonce.toString(16)}`,
101
+ callData,
102
+ signature: stubSignature,
103
+ callGasLimit: bigintToHex(500000n),
104
+ verificationGasLimit: bigintToHex(500000n),
105
+ preVerificationGas: bigintToHex(100000n),
106
+ maxFeePerGas: bigintToHex(maxFeePerGas),
107
+ maxPriorityFeePerGas: bigintToHex(maxPriorityFeePerGas)
108
+ };
109
+ const sponsorResult = await this.bundlerClient.request({
110
+ method: "pm_sponsorUserOperation",
111
+ params: [userOpForEstimation, entryPoint]
112
+ });
113
+ const callGasLimit = BigInt(sponsorResult.callGasLimit);
114
+ const verificationGasLimit = BigInt(sponsorResult.verificationGasLimit);
115
+ const preVerificationGas = BigInt(sponsorResult.preVerificationGas);
116
+ let paymaster;
117
+ let paymasterData;
118
+ let paymasterVerificationGasLimit;
119
+ let paymasterPostOpGasLimit;
120
+ if (sponsorResult.paymaster) {
121
+ paymaster = sponsorResult.paymaster;
122
+ paymasterData = sponsorResult.paymasterData ?? "0x";
123
+ paymasterVerificationGasLimit = BigInt(sponsorResult.paymasterVerificationGasLimit ?? "0x0");
124
+ paymasterPostOpGasLimit = BigInt(sponsorResult.paymasterPostOpGasLimit ?? "0x0");
125
+ } else if (sponsorResult.paymasterAndData && sponsorResult.paymasterAndData !== "0x") {
126
+ const packed = sponsorResult.paymasterAndData;
127
+ paymaster = `0x${packed.slice(2, 42)}`;
128
+ paymasterVerificationGasLimit = BigInt(`0x${packed.slice(42, 74)}`);
129
+ paymasterPostOpGasLimit = BigInt(`0x${packed.slice(74, 106)}`);
130
+ paymasterData = `0x${packed.slice(106)}`;
131
+ }
132
+ return {
133
+ sender,
134
+ nonce,
135
+ // Include factory/factoryData keys so that downstream signers (e.g. permissionless
136
+ // Safe signUserOperation) detect v0.7 format and correctly pack paymasterAndData
137
+ // from the separate v0.7 fields. Without these keys, permissionless defaults to
138
+ // paymasterAndData: "0x" causing SafeOp hash mismatch (AA24).
139
+ factory: void 0,
140
+ factoryData: void 0,
141
+ callData,
142
+ callGasLimit,
143
+ verificationGasLimit,
144
+ preVerificationGas,
145
+ maxFeePerGas,
146
+ maxPriorityFeePerGas,
147
+ ...paymaster ? { paymaster } : {},
148
+ ...paymasterData ? { paymasterData } : {},
149
+ ...paymasterVerificationGasLimit != null ? { paymasterVerificationGasLimit } : {},
150
+ ...paymasterPostOpGasLimit != null ? { paymasterPostOpGasLimit } : {},
151
+ signature: stubSignature
152
+ };
153
+ }
154
+ }
155
+ async prepareWithoutPaymaster(calls) {
80
156
  const prepared = await this.bundlerClient.prepareUserOperation({
81
157
  account: this.account,
82
158
  calls: calls.map((call) => ({
@@ -89,31 +165,20 @@ var ViemBundlerClient = class {
89
165
  return {
90
166
  sender: prepared.sender,
91
167
  nonce: prepared.nonce,
168
+ // Always include factory/factoryData keys for v0.7 format detection by signers
169
+ factory: p.factory ?? void 0,
170
+ factoryData: p.factoryData ?? void 0,
92
171
  callData: prepared.callData,
93
172
  callGasLimit: prepared.callGasLimit,
94
173
  verificationGasLimit: prepared.verificationGasLimit,
95
174
  preVerificationGas: prepared.preVerificationGas,
96
175
  maxFeePerGas: prepared.maxFeePerGas,
97
176
  maxPriorityFeePerGas: prepared.maxPriorityFeePerGas,
98
- // v0.7 factory fields (for account deployment)
99
- ...p.factory ? { factory: p.factory } : {},
100
- ...p.factoryData ? { factoryData: p.factoryData } : {},
101
- // v0.7 paymaster fields (separate, not paymasterAndData)
102
- ...p.paymaster ? { paymaster: p.paymaster } : {},
103
- ...p.paymasterData ? { paymasterData: p.paymasterData } : {},
104
- ...p.paymasterVerificationGasLimit != null ? { paymasterVerificationGasLimit: p.paymasterVerificationGasLimit } : {},
105
- ...p.paymasterPostOpGasLimit != null ? { paymasterPostOpGasLimit: p.paymasterPostOpGasLimit } : {},
106
177
  signature: prepared.signature
107
178
  };
108
179
  }
109
180
  /**
110
- * Estimates gas for a user operation.
111
- * Note: This is typically done as part of prepareUserOperation,
112
- * but is available as a separate method for flexibility.
113
- *
114
- * @param _userOp - The user operation to estimate gas for
115
- * @param _entryPoint - The entry point address
116
- * @returns Promise resolving to gas estimates
181
+ * @deprecated Gas estimation is done as part of prepareUserOperation
117
182
  */
118
183
  async estimateGas(_userOp, _entryPoint) {
119
184
  throw new Error(
@@ -121,26 +186,15 @@ var ViemBundlerClient = class {
121
186
  );
122
187
  }
123
188
  /**
124
- * Sends a user operation to the bundler.
189
+ * Sends a signed user operation to the bundler via raw eth_sendUserOperation RPC.
125
190
  *
126
- * @param userOp - The signed user operation to send
127
- * @param _entryPoint - The entry point address (unused, viem uses the configured entry point)
128
- * @returns Promise resolving to the user operation hash
191
+ * Bypasses viem's middleware to avoid re-calling paymaster RPCs which would
192
+ * change paymaster fields and invalidate the signature.
129
193
  */
130
- async sendUserOperation(userOp, _entryPoint) {
131
- const hash = await this.bundlerClient.sendUserOperation({
132
- account: this.account,
133
- sender: userOp.sender,
134
- nonce: BigInt(userOp.nonce),
135
- callData: userOp.callData,
136
- callGasLimit: BigInt(userOp.callGasLimit),
137
- verificationGasLimit: BigInt(userOp.verificationGasLimit),
138
- preVerificationGas: BigInt(userOp.preVerificationGas),
139
- maxFeePerGas: BigInt(userOp.maxFeePerGas),
140
- maxPriorityFeePerGas: BigInt(userOp.maxPriorityFeePerGas),
141
- // Combine paymaster and paymasterData into paymasterAndData
142
- paymasterAndData: userOp.paymaster && userOp.paymasterData ? userOp.paymaster + userOp.paymasterData.slice(2) : userOp.paymaster ? userOp.paymaster : "0x",
143
- signature: userOp.signature
194
+ async sendUserOperation(userOp, entryPoint) {
195
+ const hash = await this.bundlerClient.request({
196
+ method: "eth_sendUserOperation",
197
+ params: [userOp, entryPoint]
144
198
  });
145
199
  return hash;
146
200
  }
@@ -253,6 +307,7 @@ function userOpToJson(userOp) {
253
307
  const json = {};
254
308
  for (const [key, value] of Object.entries(userOp)) {
255
309
  if (key === "account") continue;
310
+ if (value === void 0) continue;
256
311
  if (typeof value === "bigint") {
257
312
  json[key] = toRpcHex(value);
258
313
  } else if (value && typeof value === "object" && !Array.isArray(value)) {
@@ -458,6 +513,7 @@ var ExactEvmSchemeERC4337 = class {
458
513
  this.publicClient = config.publicClient;
459
514
  this.entrypoint = config.entrypoint;
460
515
  this.bundlerUrl = config.bundlerUrl;
516
+ this.paymaster = config.paymaster;
461
517
  if (!this.bundlerClient && !this.account) {
462
518
  throw new Error(
463
519
  "Either bundlerClient or account must be provided. If bundlerClient is not provided, account (SmartAccount) is required for dynamic bundlerClient creation."
@@ -497,6 +553,9 @@ var ExactEvmSchemeERC4337 = class {
497
553
  */
498
554
  async createPaymentPayload(x402Version, paymentRequirements) {
499
555
  const capability = extractUserOperationCapability(paymentRequirements);
556
+ const chain = resolveChain(paymentRequirements.network);
557
+ const configBundlerUrl = typeof this.bundlerUrl === "function" ? this.bundlerUrl(chain.id, paymentRequirements.network) : this.bundlerUrl;
558
+ const bundlerUrl = configBundlerUrl ?? capability?.bundlerUrl;
500
559
  let bundlerClient;
501
560
  if (this.bundlerClient) {
502
561
  bundlerClient = this.bundlerClient;
@@ -506,8 +565,7 @@ var ExactEvmSchemeERC4337 = class {
506
565
  "Account (SmartAccount) is required when bundlerClient is not provided. Either provide bundlerClient in config or account for dynamic creation."
507
566
  );
508
567
  }
509
- const bundlerUrl2 = this.bundlerUrl ?? capability?.bundlerUrl;
510
- if (!bundlerUrl2) {
568
+ if (!bundlerUrl) {
511
569
  throw new PaymentCreationError(
512
570
  "Bundler URL not provided",
513
571
  {
@@ -517,13 +575,14 @@ var ExactEvmSchemeERC4337 = class {
517
575
  }
518
576
  );
519
577
  }
520
- const chain = resolveChain(paymentRequirements.network);
521
578
  const publicClient = this.publicClient ?? createDefaultPublicClient(paymentRequirements.network);
579
+ const paymaster = this.paymaster ?? true;
522
580
  bundlerClient = new ViemBundlerClient({
523
581
  publicClient,
524
582
  account: this.account,
525
583
  chain,
526
- bundlerUrl: bundlerUrl2
584
+ bundlerUrl,
585
+ paymaster
527
586
  });
528
587
  }
529
588
  const entryPoint = this.entrypoint ?? capability?.entrypoint;
@@ -537,7 +596,6 @@ var ExactEvmSchemeERC4337 = class {
537
596
  }
538
597
  );
539
598
  }
540
- const bundlerUrl = this.bundlerUrl ?? capability?.bundlerUrl;
541
599
  if (!bundlerUrl) {
542
600
  throw new PaymentCreationError(
543
601
  "Bundler URL not provided",