@introspectivelabs/x402-evm 0.1.0-beta.10 → 0.1.0-beta.11

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.
@@ -51,8 +51,13 @@ function encodeContractSignature(ownerAddress, signatureData) {
51
51
 
52
52
  // src/accounts/computeSafeOpHash.ts
53
53
  var import_viem2 = require("viem");
54
- var SAFE_4337_MODULE_DEFAULT = "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226";
55
- var ENTRYPOINT_V07 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
54
+
55
+ // src/constants.ts
56
+ var import_account_abstraction = require("viem/account-abstraction");
57
+ var SAFE_4337_MODULE_ADDRESS = "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226";
58
+ var SAFE_WEBAUTHN_SHARED_SIGNER = "0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9";
59
+
60
+ // src/accounts/computeSafeOpHash.ts
56
61
  var SAFE_OP_TYPES = {
57
62
  SafeOp: [
58
63
  { type: "address", name: "safe" },
@@ -70,7 +75,7 @@ var SAFE_OP_TYPES = {
70
75
  { type: "address", name: "entryPoint" }
71
76
  ]
72
77
  };
73
- function computeSafeOpHash(userOp, chainId, safe4337ModuleAddress = SAFE_4337_MODULE_DEFAULT, entryPointAddress = ENTRYPOINT_V07) {
78
+ function computeSafeOpHash(userOp, chainId, safe4337ModuleAddress = SAFE_4337_MODULE_ADDRESS, entryPointAddress = import_account_abstraction.entryPoint07Address) {
74
79
  const initCode = userOp.factory && (0, import_viem2.isAddress)(userOp.factory) ? (0, import_viem2.concat)([userOp.factory, userOp.factoryData || "0x"]) : "0x";
75
80
  let paymasterAndData = "0x";
76
81
  if (userOp.paymaster && (0, import_viem2.isAddress)(userOp.paymaster)) {
@@ -107,8 +112,6 @@ function computeSafeOpHash(userOp, chainId, safe4337ModuleAddress = SAFE_4337_MO
107
112
  }
108
113
 
109
114
  // src/accounts/toP256SafeSmartAccount.ts
110
- var SAFE_4337_MODULE_DEFAULT2 = "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226";
111
- var ENTRYPOINT_V07_ADDRESS = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
112
115
  function createMockLocalAccount(address) {
113
116
  const notImplemented = () => {
114
117
  throw new Error("P256 contract owner: use signUserOperation instead");
@@ -125,8 +128,8 @@ function createMockLocalAccount(address) {
125
128
  };
126
129
  }
127
130
  async function toP256SafeSmartAccount(params) {
128
- const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_DEFAULT2;
129
- const entryPointAddress = params.entryPoint?.address ?? ENTRYPOINT_V07_ADDRESS;
131
+ const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_ADDRESS;
132
+ const entryPointAddress = params.entryPoint?.address ?? import_account_abstraction.entryPoint07Address;
130
133
  const mockOwner = createMockLocalAccount(params.p256Signer.p256OwnerAddress);
131
134
  const baseAccount = await (0, import_accounts.toSafeSmartAccount)({
132
135
  client: params.client,
@@ -184,11 +187,9 @@ async function toP256SafeSmartAccount(params) {
184
187
 
185
188
  // src/accounts/toWebAuthnSafeSmartAccount.ts
186
189
  var import_accounts2 = require("permissionless/accounts");
187
- var SAFE_4337_MODULE_DEFAULT3 = "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226";
188
- var ENTRYPOINT_V07_ADDRESS2 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
189
190
  async function toWebAuthnSafeSmartAccount(params) {
190
- const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_DEFAULT3;
191
- const entryPointAddress = params.entryPoint?.address ?? ENTRYPOINT_V07_ADDRESS2;
191
+ const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_ADDRESS;
192
+ const entryPointAddress = params.entryPoint?.address ?? import_account_abstraction.entryPoint07Address;
192
193
  const baseAccount = await (0, import_accounts2.toSafeSmartAccount)({
193
194
  client: params.client,
194
195
  owners: [params.webAuthnAccount],
@@ -205,9 +206,6 @@ async function toWebAuthnSafeSmartAccount(params) {
205
206
  }
206
207
 
207
208
  // src/accounts/toSafeSmartAccount.ts
208
- var SAFE_4337_MODULE_DEFAULT4 = "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226";
209
- var ENTRYPOINT_V07_ADDRESS3 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
210
- var SAFE_WEBAUTHN_SHARED_SIGNER = "0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9";
211
209
  async function toSafeSmartAccount3(params) {
212
210
  const { signerConfig } = params;
213
211
  switch (signerConfig.type) {
@@ -292,8 +290,8 @@ async function buildMultiSignerAccount(params, signers, threshold) {
292
290
  }
293
291
  const p256Signer = signers.p256;
294
292
  const webAuthnAccount = signers.webAuthn;
295
- const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_DEFAULT4;
296
- const entryPointAddress = params.entryPoint?.address ?? ENTRYPOINT_V07_ADDRESS3;
293
+ const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_ADDRESS;
294
+ const entryPointAddress = params.entryPoint?.address ?? import_account_abstraction.entryPoint07Address;
297
295
  const mockP256Owner = createMockLocalAccount2(p256Signer.p256OwnerAddress);
298
296
  const baseAccount = await (0, import_accounts3.toSafeSmartAccount)({
299
297
  client: params.client,
@@ -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/accounts/toWebAuthnSafeSmartAccount.ts","../../../src/accounts/extractPasskeyCoordinates.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// 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\";\n\nconst SAFE_4337_MODULE_DEFAULT = \"0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226\" as Hex;\nconst ENTRYPOINT_V07_ADDRESS = \"0x0000000071727De22E5E9d8BAf0edAc6f37da032\" as Hex;\n\n// Safe's SafeWebAuthnSharedSigner deployed address\nconst SAFE_WEBAUTHN_SHARED_SIGNER = \"0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9\" as Hex;\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_DEFAULT;\n const entryPointAddress = params.entryPoint?.address ?? ENTRYPOINT_V07_ADDRESS;\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\";\n\nconst SAFE_4337_MODULE_DEFAULT = \"0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226\" as Hex;\nconst ENTRYPOINT_V07_ADDRESS = \"0x0000000071727De22E5E9d8BAf0edAc6f37da032\" as Hex;\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_DEFAULT;\n const entryPointAddress =\n params.entryPoint?.address ?? ENTRYPOINT_V07_ADDRESS;\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\";\n\nconst SAFE_4337_MODULE_DEFAULT = \"0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226\" as Hex;\nconst ENTRYPOINT_V07 = \"0x0000000071727De22E5E9d8BAf0edAc6f37da032\" as Hex;\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_DEFAULT,\n entryPointAddress: Hex = ENTRYPOINT_V07,\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 type { SmartAccount, WebAuthnAccount } from \"viem/account-abstraction\";\nimport { toSafeSmartAccount } from \"permissionless/accounts\";\nimport type { PublicClient, Transport, Chain } from \"viem\";\n\nconst SAFE_4337_MODULE_DEFAULT = \"0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226\" as Hex;\nconst ENTRYPOINT_V07_ADDRESS = \"0x0000000071727De22E5E9d8BAf0edAc6f37da032\" as Hex;\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_DEFAULT;\n const entryPointAddress = params.entryPoint?.address ?? ENTRYPOINT_V07_ADDRESS;\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"],"mappings":";;;;;;;;;;;;;;;;;;;;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;AAEP,IAAM,2BAA2B;AACjC,IAAM,iBAAiB;AAEvB,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,WAAW;AAAA,IAClC,EAAE,MAAM,WAAW,M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BACxB,OAAO,GAAG,uBAAiC,IAC3C;AAAA,IACJ,eAAgB,GAAG,iBAAyB;AAAA,EAC9C;AACF;;;AKhYA,SAAS,YAAY,QAA6B;AAChD,SAAO,MAAM,KAAK,IAAI,WAAW,MAAM,CAAC,EACrC,IAAI,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAC1C,KAAK,EAAE;AACZ;AAEA,SAAS,eAAe,WAA2B;AACjD,QAAM,SAAS,UAAU,QAAQ,MAAM,GAAG,EAAE,QAAQ,MAAM,GAAG;AAC7D,QAAM,SAAS,KAAK,MAAM;AAC1B,SAAO,MAAM,KAAK,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,SAAS,EAAE,EAAE,SAAS,GAAG,GAAG,CAAC,EAAE,KAAK,EAAE;AACzF;AAQA,eAAsB,0BACpB,YAC4C;AAC5C,QAAM,QAAQ,YAAY,WAAW,KAAK;AAC1C,QAAM,WAAW,WAAW;AAC5B,QAAM,YAAY,SAAS,aAAa;AACxC,MAAI,CAAC,UAAW,OAAM,IAAI,MAAM,8CAA8C;AAE9E,QAAM,MAAM,MAAM,OAAO,OAAO;AAAA,IAC9B;AAAA,IACA;AAAA,IACA,EAAE,MAAM,SAAS,YAAY,QAAQ;AAAA,IACrC;AAAA,IACA,CAAC,QAAQ;AAAA,EACX;AACA,QAAM,MAAM,MAAM,OAAO,OAAO,UAAU,OAAO,GAAG;AACpD,MAAI,CAAC,IAAI,KAAK,CAAC,IAAI,EAAG,OAAM,IAAI,MAAM,4BAA4B;AAElE,SAAO;AAAA,IACL;AAAA,IACA,GAAI,OAAO,eAAe,IAAI,CAAC;AAAA,IAC/B,GAAI,OAAO,eAAe,IAAI,CAAC;AAAA,EACjC;AACF;","names":["toSafeSmartAccount","import_viem","import_accounts","import_viem","import_viem","SAFE_4337_MODULE_DEFAULT","import_accounts","SAFE_4337_MODULE_DEFAULT","ENTRYPOINT_V07_ADDRESS","SAFE_4337_MODULE_DEFAULT","ENTRYPOINT_V07_ADDRESS","toSafeSmartAccount","createMockLocalAccount","toPermissionlessSafeSmartAccount"]}
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"],"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// 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","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"],"mappings":";;;;;;;;;;;;;;;;;;;;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;AACp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AG,OAAM,IAAI,MAAM,4BAA4B;AAElE,SAAO;AAAA,IACL;AAAA,IACA,GAAI,OAAO,eAAe,IAAI,CAAC;AAAA,IAC/B,GAAI,OAAO,eAAe,IAAI,CAAC;AAAA,EACjC;AACF;","names":["toSafeSmartAccount","import_viem","import_accounts","import_viem","import_viem","import_accounts","toSafeSmartAccount","createMockLocalAccount","toPermissionlessSafeSmartAccount"]}
@@ -0,0 +1,7 @@
1
+ declare const SAFE_4337_MODULE_ADDRESS: "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226";
2
+ declare const SAFE_WEBAUTHN_SHARED_SIGNER: "0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9";
3
+ declare const FCL_P256_VERIFIER: "0xA86e0054C51E4894D88762a017ECc5E5235f5DBA";
4
+ declare const P256_OWNER_FACTORY: "0x349c03Eb61e26528cbf79F5D3Ba071FcA2aE82cB";
5
+ declare const WEBAUTHN_SIGNER_FACTORY: "0xF7488fFbe67327ac9f37D5F722d83Fc900852Fbf";
6
+
7
+ export { FCL_P256_VERIFIER as F, P256_OWNER_FACTORY as P, SAFE_4337_MODULE_ADDRESS as S, WEBAUTHN_SIGNER_FACTORY as W, SAFE_WEBAUTHN_SHARED_SIGNER as a };
@@ -1,5 +1,7 @@
1
1
  import { Hex, PublicClient, WalletClient } from 'viem';
2
+ export { F as FCL_P256_VERIFIER, P as P256_OWNER_FACTORY, W as WEBAUTHN_SIGNER_FACTORY } from '../constants-Bl5JlK9d.js';
2
3
 
4
+ declare const FACTORY_ADDRESSES: FactoryAddresses;
3
5
  interface FactoryAddresses {
4
6
  p256OwnerFactory: Hex;
5
7
  webAuthnSignerFactory: Hex;
@@ -126,4 +128,4 @@ declare function computeWebAuthnSignerAddress(client: PublicClient, factoryAddre
126
128
  declare function isWebAuthnSignerDeployed(client: PublicClient, signerAddress: Hex): Promise<boolean>;
127
129
  declare function deployWebAuthnSigner(walletClient: WalletClient, publicClient: PublicClient, factoryAddress: Hex, verifierAddress: Hex, x: bigint, y: bigint, precompile?: bigint | null): Promise<FactoryDeployResult>;
128
130
 
129
- export { type FactoryAddresses, type FactoryDeployResult, type OwnerAddresses, P256_OWNER_FACTORY_ABI, RIP_7212_PRECOMPILE, WEBAUTHN_SIGNER_FACTORY_ABI, computeP256OwnerAddress, computeVerifiers, computeWebAuthnSignerAddress, deployP256Owner, deployWebAuthnSigner, isP256OwnerDeployed, isWebAuthnSignerDeployed };
131
+ export { FACTORY_ADDRESSES, type FactoryAddresses, type FactoryDeployResult, type OwnerAddresses, P256_OWNER_FACTORY_ABI, RIP_7212_PRECOMPILE, WEBAUTHN_SIGNER_FACTORY_ABI, computeP256OwnerAddress, computeVerifiers, computeWebAuthnSignerAddress, deployP256Owner, deployWebAuthnSigner, isP256OwnerDeployed, isWebAuthnSignerDeployed };
@@ -20,8 +20,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/factories/index.ts
21
21
  var factories_exports = {};
22
22
  __export(factories_exports, {
23
+ FACTORY_ADDRESSES: () => FACTORY_ADDRESSES,
24
+ FCL_P256_VERIFIER: () => FCL_P256_VERIFIER,
25
+ P256_OWNER_FACTORY: () => P256_OWNER_FACTORY,
23
26
  P256_OWNER_FACTORY_ABI: () => P256_OWNER_FACTORY_ABI,
24
27
  RIP_7212_PRECOMPILE: () => RIP_7212_PRECOMPILE,
28
+ WEBAUTHN_SIGNER_FACTORY: () => WEBAUTHN_SIGNER_FACTORY,
25
29
  WEBAUTHN_SIGNER_FACTORY_ABI: () => WEBAUTHN_SIGNER_FACTORY_ABI,
26
30
  computeP256OwnerAddress: () => computeP256OwnerAddress,
27
31
  computeVerifiers: () => computeVerifiers,
@@ -177,10 +181,27 @@ async function deployWebAuthnSigner(walletClient, publicClient, factoryAddress,
177
181
  await publicClient.waitForTransactionReceipt({ hash: txHash });
178
182
  return { address: signerAddress, txHash, alreadyDeployed: false };
179
183
  }
184
+
185
+ // src/constants.ts
186
+ var import_account_abstraction = require("viem/account-abstraction");
187
+ var FCL_P256_VERIFIER = "0xA86e0054C51E4894D88762a017ECc5E5235f5DBA";
188
+ var P256_OWNER_FACTORY = "0x349c03Eb61e26528cbf79F5D3Ba071FcA2aE82cB";
189
+ var WEBAUTHN_SIGNER_FACTORY = "0xF7488fFbe67327ac9f37D5F722d83Fc900852Fbf";
190
+
191
+ // src/factories/types.ts
192
+ var FACTORY_ADDRESSES = {
193
+ p256OwnerFactory: P256_OWNER_FACTORY,
194
+ webAuthnSignerFactory: WEBAUTHN_SIGNER_FACTORY,
195
+ fclP256Verifier: FCL_P256_VERIFIER
196
+ };
180
197
  // Annotate the CommonJS export names for ESM import in node:
181
198
  0 && (module.exports = {
199
+ FACTORY_ADDRESSES,
200
+ FCL_P256_VERIFIER,
201
+ P256_OWNER_FACTORY,
182
202
  P256_OWNER_FACTORY_ABI,
183
203
  RIP_7212_PRECOMPILE,
204
+ WEBAUTHN_SIGNER_FACTORY,
184
205
  WEBAUTHN_SIGNER_FACTORY_ABI,
185
206
  computeP256OwnerAddress,
186
207
  computeVerifiers,
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/factories/index.ts","../../../src/factories/p256-owner-factory.ts","../../../src/factories/webauthn-signer-factory.ts"],"sourcesContent":["export {\n P256_OWNER_FACTORY_ABI,\n computeP256OwnerAddress,\n isP256OwnerDeployed,\n deployP256Owner,\n} from \"./p256-owner-factory\";\n\nexport {\n WEBAUTHN_SIGNER_FACTORY_ABI,\n RIP_7212_PRECOMPILE,\n computeVerifiers,\n computeWebAuthnSignerAddress,\n isWebAuthnSignerDeployed,\n deployWebAuthnSigner,\n} from \"./webauthn-signer-factory\";\n\nexport type {\n FactoryAddresses,\n FactoryDeployResult,\n OwnerAddresses,\n} from \"./types\";\n","import type { Hex, PublicClient, WalletClient } from \"viem\";\nimport type { FactoryDeployResult } from \"./types\";\n\nexport const P256_OWNER_FACTORY_ABI = [\n {\n type: \"function\",\n name: \"createP256Owner\",\n inputs: [\n { name: \"x\", type: \"uint256\" },\n { name: \"y\", type: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"address\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"computeAddress\",\n inputs: [\n { name: \"x\", type: \"uint256\" },\n { name: \"y\", type: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"address\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"isDeployed\",\n inputs: [\n { name: \"x\", type: \"uint256\" },\n { name: \"y\", type: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"bool\" }],\n stateMutability: \"view\",\n },\n] as const;\n\nexport async function computeP256OwnerAddress(\n client: PublicClient,\n factoryAddress: Hex,\n x: bigint,\n y: bigint,\n): Promise<Hex> {\n const addr = await client.readContract({\n address: factoryAddress,\n abi: P256_OWNER_FACTORY_ABI,\n functionName: \"computeAddress\",\n args: [x, y],\n });\n return addr as Hex;\n}\n\nexport async function isP256OwnerDeployed(\n client: PublicClient,\n factoryAddress: Hex,\n x: bigint,\n y: bigint,\n): Promise<boolean> {\n return client.readContract({\n address: factoryAddress,\n abi: P256_OWNER_FACTORY_ABI,\n functionName: \"isDeployed\",\n args: [x, y],\n });\n}\n\nexport async function deployP256Owner(\n walletClient: WalletClient,\n publicClient: PublicClient,\n factoryAddress: Hex,\n x: bigint,\n y: bigint,\n): Promise<FactoryDeployResult> {\n const alreadyDeployed = await isP256OwnerDeployed(publicClient, factoryAddress, x, y);\n const address = await computeP256OwnerAddress(publicClient, factoryAddress, x, y);\n\n if (alreadyDeployed) {\n return { address, alreadyDeployed: true };\n }\n\n const account = walletClient.account;\n if (!account) {\n throw new Error(\"WalletClient must have an account configured\");\n }\n\n const txHash = await walletClient.writeContract({\n address: factoryAddress,\n abi: P256_OWNER_FACTORY_ABI,\n functionName: \"createP256Owner\",\n args: [x, y],\n account,\n chain: undefined,\n });\n await publicClient.waitForTransactionReceipt({ hash: txHash });\n\n return { address, txHash, alreadyDeployed: false };\n}\n","import type { Hex, PublicClient, WalletClient } from \"viem\";\nimport type { FactoryDeployResult } from \"./types\";\n\n/**\n * RIP-7212 P256 precompile address, available on L2s (Base, Optimism, Arbitrum, etc.).\n * When set in the top 16 bits of the `verifiers` uint176, the SafeWebAuthnSignerProxy\n * uses this precompile for P256 verification instead of making an external call to the\n * fallback verifier. This is required for ERC-4337 compatibility (ERC-7562 forbids\n * external calls during UserOp validation).\n */\nexport const RIP_7212_PRECOMPILE = 0x100n;\n\n/**\n * Computes the `verifiers` uint176 value for SafeWebAuthnSignerFactory.\n *\n * Layout: top 16 bits = precompile address, bottom 160 bits = fallback verifier.\n * When precompile is set, the signer proxy tries the precompile first (allowed by\n * ERC-7562) and falls back to the contract verifier only if the precompile is\n * unavailable.\n *\n * @param fallbackVerifier - Address of the fallback P256 verifier contract\n * @param precompile - Precompile address (e.g. RIP_7212_PRECOMPILE). Pass null/0n to disable.\n */\nexport function computeVerifiers(\n fallbackVerifier: Hex,\n precompile: bigint | null = RIP_7212_PRECOMPILE,\n): bigint {\n const fallback = BigInt(fallbackVerifier);\n if (!precompile) return fallback;\n return (precompile << 160n) | fallback;\n}\n\nexport const WEBAUTHN_SIGNER_FACTORY_ABI = [\n {\n type: \"function\",\n name: \"createSigner\",\n inputs: [\n { name: \"x\", type: \"uint256\" },\n { name: \"y\", type: \"uint256\" },\n { name: \"verifiers\", type: \"uint176\" },\n ],\n outputs: [{ name: \"signer\", type: \"address\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"getSigner\",\n inputs: [\n { name: \"x\", type: \"uint256\" },\n { name: \"y\", type: \"uint256\" },\n { name: \"verifiers\", type: \"uint176\" },\n ],\n outputs: [{ name: \"signer\", type: \"address\" }],\n stateMutability: \"view\",\n },\n] as const;\n\nexport async function computeWebAuthnSignerAddress(\n client: PublicClient,\n factoryAddress: Hex,\n verifierAddress: Hex,\n x: bigint,\n y: bigint,\n precompile: bigint | null = RIP_7212_PRECOMPILE,\n): Promise<Hex> {\n const verifiers = computeVerifiers(verifierAddress, precompile);\n const addr = await client.readContract({\n address: factoryAddress,\n abi: WEBAUTHN_SIGNER_FACTORY_ABI,\n functionName: \"getSigner\",\n args: [x, y, verifiers],\n });\n return addr as Hex;\n}\n\nexport async function isWebAuthnSignerDeployed(\n client: PublicClient,\n signerAddress: Hex,\n): Promise<boolean> {\n const code = await client.getCode({ address: signerAddress });\n return !!code && code !== \"0x\";\n}\n\nexport async function deployWebAuthnSigner(\n walletClient: WalletClient,\n publicClient: PublicClient,\n factoryAddress: Hex,\n verifierAddress: Hex,\n x: bigint,\n y: bigint,\n precompile: bigint | null = RIP_7212_PRECOMPILE,\n): Promise<FactoryDeployResult> {\n const verifiers = computeVerifiers(verifierAddress, precompile);\n\n const signerAddress = await publicClient.readContract({\n address: factoryAddress,\n abi: WEBAUTHN_SIGNER_FACTORY_ABI,\n functionName: \"getSigner\",\n args: [x, y, verifiers],\n }) as Hex;\n\n const deployed = await isWebAuthnSignerDeployed(publicClient, signerAddress);\n if (deployed) {\n return { address: signerAddress, alreadyDeployed: true };\n }\n\n const account = walletClient.account;\n if (!account) {\n throw new Error(\"WalletClient must have an account configured\");\n }\n\n const txHash = await walletClient.writeContract({\n address: factoryAddress,\n abi: WEBAUTHN_SIGNER_FACTORY_ABI,\n functionName: \"createSigner\",\n args: [x, y, verifiers],\n account,\n chain: undefined,\n });\n await publicClient.waitForTransactionReceipt({ hash: txHash });\n\n return { address: signerAddress, txHash, alreadyDeployed: false };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACGO,IAAM,yBAAyB;AAAA,EACpC;AAAA,IACE,MAAM;AAAA,IACN,MAAM;AAAA,IACN,QAAQ;AAAA,MACN,EAAE,MAAM,KAAK,MAAM,UAAU;AAAA,MAC7B,EAAE,MAAM,KAAK,MAAM,UAAU;AAAA,IAC/B;AAAA,IACA,SAAS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,aAAa;AAAA,IACrC,SAAS;AAAA,IACT,KAAK;AAAA,IACL,cAAc;AAAA,IACd,MAAM,CAAC,GAAG,GAAG,SAAS;AAAA,EACxB,CAAC;AACD,SAAO;AACT;AAEA,eAAsB,yBACpB,QACA,eACkB;AAClB,QAAM,OAAO,MAAM,OAAO,QAAQ,EAAE,SAAS,cAAc,CAAC;AAC5D,SAAO,CAAC,CAAC,QAAQ,SAAS;AAC5B;AAEA,eAAsB,qBACpB,cACA,cACA,gBACA,iBACA,GACA,GACA,aAA4B,qBACE;AAC9B,QAAM,YAAY,iBAAiB,iBAAiB,UAAU;AAE9D,QAAM,gBAAgB,MAAM,aAAa,aAAa;AAAA,IACpD,SAAS;AAAA,IACT,KAAK;AAAA,IACL,cAAc;AAAA,IACd,MAAM,CAAC,GAAG,GAAG,SAAS;AAAA,EACxB,CAAC;AAED,QAAM,WAAW,MAAM,yBAAyB,cAAc,aAAa;AAC3E,MAAI,UAAU;AACZ,WAAO,EAAE,SAAS,eAAe,iBAAiB,KAAK;AAAA,EACzD;AAEA,QAAM,UAAU,aAAa;AAC7B,MAAI,CAAC,SAAS;AACZ,UAAM,IAAI,MAAM,8CAA8C;AAAA,EAChE;AAEA,QAAM,SAAS,MAAM,aAAa,cAAc;AAAA,IAC9C,SAAS;AAAA,IACT,KAAK;AAAA,IACL,cAAc;AAAA,IACd,MAAM,CAAC,GAAG,GAAG,SAAS;AAAA,IACtB;AAAA,IACA,OAAO;AAAA,EACT,CAAC;AACD,QAAM,aAAa,0BAA0B,EAAE,MAAM,OAAO,CAAC;AAE7D,SAAO,EAAE,SAAS,eAAe,QAAQ,iBAAiB,MAAM;AAClE;","names":[]}
1
+ {"version":3,"sources":["../../../src/factories/index.ts","../../../src/factories/p256-owner-factory.ts","../../../src/factories/webauthn-signer-factory.ts","../../../src/constants.ts","../../../src/factories/types.ts"],"sourcesContent":["export {\n P256_OWNER_FACTORY_ABI,\n computeP256OwnerAddress,\n isP256OwnerDeployed,\n deployP256Owner,\n} from \"./p256-owner-factory\";\n\nexport {\n WEBAUTHN_SIGNER_FACTORY_ABI,\n RIP_7212_PRECOMPILE,\n computeVerifiers,\n computeWebAuthnSignerAddress,\n isWebAuthnSignerDeployed,\n deployWebAuthnSigner,\n} from \"./webauthn-signer-factory\";\n\nexport {\n FCL_P256_VERIFIER,\n P256_OWNER_FACTORY,\n WEBAUTHN_SIGNER_FACTORY,\n} from \"../constants\";\n\nexport { FACTORY_ADDRESSES } from \"./types\";\n\nexport type {\n FactoryAddresses,\n FactoryDeployResult,\n OwnerAddresses,\n} from \"./types\";\n","import type { Hex, PublicClient, WalletClient } from \"viem\";\nimport type { FactoryDeployResult } from \"./types\";\n\nexport const P256_OWNER_FACTORY_ABI = [\n {\n type: \"function\",\n name: \"createP256Owner\",\n inputs: [\n { name: \"x\", type: \"uint256\" },\n { name: \"y\", type: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"address\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"computeAddress\",\n inputs: [\n { name: \"x\", type: \"uint256\" },\n { name: \"y\", type: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"address\" }],\n stateMutability: \"view\",\n },\n {\n type: \"function\",\n name: \"isDeployed\",\n inputs: [\n { name: \"x\", type: \"uint256\" },\n { name: \"y\", type: \"uint256\" },\n ],\n outputs: [{ name: \"\", type: \"bool\" }],\n stateMutability: \"view\",\n },\n] as const;\n\nexport async function computeP256OwnerAddress(\n client: PublicClient,\n factoryAddress: Hex,\n x: bigint,\n y: bigint,\n): Promise<Hex> {\n const addr = await client.readContract({\n address: factoryAddress,\n abi: P256_OWNER_FACTORY_ABI,\n functionName: \"computeAddress\",\n args: [x, y],\n });\n return addr as Hex;\n}\n\nexport async function isP256OwnerDeployed(\n client: PublicClient,\n factoryAddress: Hex,\n x: bigint,\n y: bigint,\n): Promise<boolean> {\n return client.readContract({\n address: factoryAddress,\n abi: P256_OWNER_FACTORY_ABI,\n functionName: \"isDeployed\",\n args: [x, y],\n });\n}\n\nexport async function deployP256Owner(\n walletClient: WalletClient,\n publicClient: PublicClient,\n factoryAddress: Hex,\n x: bigint,\n y: bigint,\n): Promise<FactoryDeployResult> {\n const alreadyDeployed = await isP256OwnerDeployed(publicClient, factoryAddress, x, y);\n const address = await computeP256OwnerAddress(publicClient, factoryAddress, x, y);\n\n if (alreadyDeployed) {\n return { address, alreadyDeployed: true };\n }\n\n const account = walletClient.account;\n if (!account) {\n throw new Error(\"WalletClient must have an account configured\");\n }\n\n const txHash = await walletClient.writeContract({\n address: factoryAddress,\n abi: P256_OWNER_FACTORY_ABI,\n functionName: \"createP256Owner\",\n args: [x, y],\n account,\n chain: undefined,\n });\n await publicClient.waitForTransactionReceipt({ hash: txHash });\n\n return { address, txHash, alreadyDeployed: false };\n}\n","import type { Hex, PublicClient, WalletClient } from \"viem\";\nimport type { FactoryDeployResult } from \"./types\";\n\n/**\n * RIP-7212 P256 precompile address, available on L2s (Base, Optimism, Arbitrum, etc.).\n * When set in the top 16 bits of the `verifiers` uint176, the SafeWebAuthnSignerProxy\n * uses this precompile for P256 verification instead of making an external call to the\n * fallback verifier. This is required for ERC-4337 compatibility (ERC-7562 forbids\n * external calls during UserOp validation).\n */\nexport const RIP_7212_PRECOMPILE = 0x100n;\n\n/**\n * Computes the `verifiers` uint176 value for SafeWebAuthnSignerFactory.\n *\n * Layout: top 16 bits = precompile address, bottom 160 bits = fallback verifier.\n * When precompile is set, the signer proxy tries the precompile first (allowed by\n * ERC-7562) and falls back to the contract verifier only if the precompile is\n * unavailable.\n *\n * @param fallbackVerifier - Address of the fallback P256 verifier contract\n * @param precompile - Precompile address (e.g. RIP_7212_PRECOMPILE). Pass null/0n to disable.\n */\nexport function computeVerifiers(\n fallbackVerifier: Hex,\n precompile: bigint | null = RIP_7212_PRECOMPILE,\n): bigint {\n const fallback = BigInt(fallbackVerifier);\n if (!precompile) return fallback;\n return (precompile << 160n) | fallback;\n}\n\nexport const WEBAUTHN_SIGNER_FACTORY_ABI = [\n {\n type: \"function\",\n name: \"createSigner\",\n inputs: [\n { name: \"x\", type: \"uint256\" },\n { name: \"y\", type: \"uint256\" },\n { name: \"verifiers\", type: \"uint176\" },\n ],\n outputs: [{ name: \"signer\", type: \"address\" }],\n stateMutability: \"nonpayable\",\n },\n {\n type: \"function\",\n name: \"getSigner\",\n inputs: [\n { name: \"x\", type: \"uint256\" },\n { name: \"y\", type: \"uint256\" },\n { name: \"verifiers\", type: \"uint176\" },\n ],\n outputs: [{ name: \"signer\", type: \"address\" }],\n stateMutability: \"view\",\n },\n] as const;\n\nexport async function computeWebAuthnSignerAddress(\n client: PublicClient,\n factoryAddress: Hex,\n verifierAddress: Hex,\n x: bigint,\n y: bigint,\n precompile: bigint | null = RIP_7212_PRECOMPILE,\n): Promise<Hex> {\n const verifiers = computeVerifiers(verifierAddress, precompile);\n const addr = await client.readContract({\n address: factoryAddress,\n abi: WEBAUTHN_SIGNER_FACTORY_ABI,\n functionName: \"getSigner\",\n args: [x, y, verifiers],\n });\n return addr as Hex;\n}\n\nexport async function isWebAuthnSignerDeployed(\n client: PublicClient,\n signerAddress: Hex,\n): Promise<boolean> {\n const code = await client.getCode({ address: signerAddress });\n return !!code && code !== \"0x\";\n}\n\nexport async function deployWebAuthnSigner(\n walletClient: WalletClient,\n publicClient: PublicClient,\n factoryAddress: Hex,\n verifierAddress: Hex,\n x: bigint,\n y: bigint,\n precompile: bigint | null = RIP_7212_PRECOMPILE,\n): Promise<FactoryDeployResult> {\n const verifiers = computeVerifiers(verifierAddress, precompile);\n\n const signerAddress = await publicClient.readContract({\n address: factoryAddress,\n abi: WEBAUTHN_SIGNER_FACTORY_ABI,\n functionName: \"getSigner\",\n args: [x, y, verifiers],\n }) as Hex;\n\n const deployed = await isWebAuthnSignerDeployed(publicClient, signerAddress);\n if (deployed) {\n return { address: signerAddress, alreadyDeployed: true };\n }\n\n const account = walletClient.account;\n if (!account) {\n throw new Error(\"WalletClient must have an account configured\");\n }\n\n const txHash = await walletClient.writeContract({\n address: factoryAddress,\n abi: WEBAUTHN_SIGNER_FACTORY_ABI,\n functionName: \"createSigner\",\n args: [x, y, verifiers],\n account,\n chain: undefined,\n });\n await publicClient.waitForTransactionReceipt({ hash: txHash });\n\n return { address: signerAddress, txHash, alreadyDeployed: false };\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","import type { Hex } from \"viem\";\nimport {\n FCL_P256_VERIFIER,\n P256_OWNER_FACTORY,\n WEBAUTHN_SIGNER_FACTORY,\n} from \"../constants\";\n\nexport const FACTORY_ADDRESSES: FactoryAddresses = {\n p256OwnerFactory: P256_OWNER_FACTORY,\n webAuthnSignerFactory: WEBAUTHN_SIGNER_FACTORY,\n fclP256Verifier: FCL_P256_VERIFIER,\n};\n\nexport interface FactoryAddresses {\n p256OwnerFactory: Hex;\n webAuthnSignerFactory: Hex;\n fclP256Verifier: Hex;\n}\n\nexport interface FactoryDeployResult {\n address: Hex;\n txHash?: Hex;\n alreadyDeployed: boolean;\n}\n\nexport interface OwnerAddresses {\n p256OwnerAddress: Hex;\n webAuthnSignerAddress: Hex;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA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AAO,CAAC;AAE7D,SAAO,EAAE,SAAS,eAAe,QAAQ,iBAAiB,MAAM;AAClE;;;ACzHA,iCAAoC;AAU7B,IAAM,oBACX;AAEK,IAAM,qBACX;AAEK,IAAM,0BACX;;;ACXK,IAAM,oBAAsC;AAAA,EACjD,kBAAkB;AAAA,EAClB,uBAAuB;AAAA,EACvB,iBAAiB;AACnB;","names":[]}
@@ -1,3 +1,4 @@
1
+ export { F as FCL_P256_VERIFIER, P as P256_OWNER_FACTORY, S as SAFE_4337_MODULE_ADDRESS, a as SAFE_WEBAUTHN_SHARED_SIGNER, W as WEBAUTHN_SIGNER_FACTORY } from './constants-Bl5JlK9d.js';
1
2
  import { Hex } from 'viem';
2
3
  import { PaymentRequirements } from '@x402/core/types';
3
4
  import { RoutesConfig, RouteConfig } from '@x402/core/server';
@@ -5,12 +6,12 @@ import { ExactEvmSchemeERC4337 } from './exact/server/index.js';
5
6
  export { BundlerError, ExactEvmSchemeNetworkERC4337, ExactEvmSchemeNetworkERC4337Config, BundlerClient as FacilitatorBundlerClient, BundlerClientConfig as FacilitatorBundlerClientConfig, GasEstimate as FacilitatorGasEstimate, UserOperationReceipt } from './exact/facilitator/index.js';
6
7
  export { E as Erc4337Payload, U as UserOperation07Json } from './types-Dk5U6Xnw.js';
7
8
  export { B as ClientBundlerClient, f as ClientBundlerClientConfig, G as ClientGasEstimate, j as ERC20_TRANSFER_ABI, b as ExactEvmSchemeEIP3009, c as ExactEvmSchemeEIP3009Config, E as ExactEvmSchemeERC4337Client, a as ExactEvmSchemeERC4337Config, P as PreparedUserOperation, g as UserOperationCall, U as UserOperationSigner, V as ViemBundlerClient, h as ViemBundlerClientConfig, i as buildERC20TransferCallData, d as createP256SafeMessageSigner, e as createWebAuthnSafeMessageSigner, u as userOpToJson } from './userOperation-bd50ILnY.js';
9
+ export { entryPoint07Address } from 'viem/account-abstraction';
8
10
  export { SafeOpHashParams, ToWebAuthnSafeSmartAccountParams, computeSafeOpHash, encodeContractSignature, extractPasskeyCoordinates, toP256SafeSmartAccount, toSafeSmartAccount, toWebAuthnSafeSmartAccount } from './accounts/index.js';
9
11
  export { P as P256Signer, S as SafeMessageSigner, a as SignerConfig, T as ToP256SafeSmartAccountParams, b as ToSafeSmartAccountParams } from './types-lO5B0FRc.js';
10
12
  export { computeSafeMessageHash } from './stamp/index.js';
11
13
  export { CAIP2Identifier, ChainInfo, NetworkInput, SUPPORTED_CHAINS, V1_NAME_INDEX, getChain, getChainById, getMainnets, getSupportedChains, getTestnets, getV1Name, getV1Names, isSupported, parseCAIP2, resolveChainId, toCAIP2 } from './networks/index.js';
12
14
  import '@x402/evm/exact/server';
13
- import 'viem/account-abstraction';
14
15
 
15
16
  interface UserOperationCapability {
16
17
  /**
package/dist/cjs/index.js CHANGED
@@ -35,16 +35,22 @@ __export(src_exports, {
35
35
  ExactEvmSchemeERC4337Client: () => ExactEvmSchemeERC43372,
36
36
  ExactEvmSchemeERC4337Server: () => ExactEvmSchemeERC4337,
37
37
  ExactEvmSchemeNetworkERC4337: () => ExactEvmSchemeNetworkERC4337,
38
+ FCL_P256_VERIFIER: () => FCL_P256_VERIFIER,
38
39
  FacilitatorBundlerClient: () => BundlerClient,
40
+ P256_OWNER_FACTORY: () => P256_OWNER_FACTORY,
41
+ SAFE_4337_MODULE_ADDRESS: () => SAFE_4337_MODULE_ADDRESS,
42
+ SAFE_WEBAUTHN_SHARED_SIGNER: () => SAFE_WEBAUTHN_SHARED_SIGNER,
39
43
  SUPPORTED_CHAINS: () => SUPPORTED_CHAINS,
40
44
  V1_NAME_INDEX: () => V1_NAME_INDEX,
41
45
  ViemBundlerClient: () => ViemBundlerClient,
46
+ WEBAUTHN_SIGNER_FACTORY: () => WEBAUTHN_SIGNER_FACTORY,
42
47
  buildERC20TransferCallData: () => buildERC20TransferCallData,
43
48
  computeSafeMessageHash: () => computeSafeMessageHash2,
44
49
  computeSafeOpHash: () => computeSafeOpHash,
45
50
  createP256SafeMessageSigner: () => createP256SafeMessageSigner,
46
51
  createWebAuthnSafeMessageSigner: () => createWebAuthnSafeMessageSigner,
47
52
  encodeContractSignature: () => encodeContractSignature,
53
+ entryPoint07Address: () => import_account_abstraction.entryPoint07Address,
48
54
  extractPasskeyCoordinates: () => extractPasskeyCoordinates,
49
55
  extractUserOperationCapability: () => extractUserOperationCapability,
50
56
  getChain: () => getChain,
@@ -67,6 +73,14 @@ __export(src_exports, {
67
73
  });
68
74
  module.exports = __toCommonJS(src_exports);
69
75
 
76
+ // src/constants.ts
77
+ var import_account_abstraction = require("viem/account-abstraction");
78
+ var SAFE_4337_MODULE_ADDRESS = "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226";
79
+ var SAFE_WEBAUTHN_SHARED_SIGNER = "0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9";
80
+ var FCL_P256_VERIFIER = "0xA86e0054C51E4894D88762a017ECc5E5235f5DBA";
81
+ var P256_OWNER_FACTORY = "0x349c03Eb61e26528cbf79F5D3Ba071FcA2aE82cB";
82
+ var WEBAUTHN_SIGNER_FACTORY = "0xF7488fFbe67327ac9f37D5F722d83Fc900852Fbf";
83
+
70
84
  // src/exact/utils.ts
71
85
  function extractUserOperationCapability(requirements) {
72
86
  const userOpExtra = requirements.extra?.userOperation;
@@ -530,7 +544,7 @@ var import_viem5 = require("viem");
530
544
 
531
545
  // src/exact/client/bundler/viem.ts
532
546
  var import_viem = require("viem");
533
- var import_account_abstraction = require("viem/account-abstraction");
547
+ var import_account_abstraction2 = require("viem/account-abstraction");
534
548
  var ViemBundlerClient = class {
535
549
  /**
536
550
  * Creates a new ViemBundlerClient instance.
@@ -540,7 +554,7 @@ var ViemBundlerClient = class {
540
554
  constructor(config) {
541
555
  this.account = config.account;
542
556
  this.entryPoint = "0x5FF137D4b0FDCD49DcA30c7CF57E578a026d2789";
543
- this.bundlerClient = (0, import_account_abstraction.createBundlerClient)({
557
+ this.bundlerClient = (0, import_account_abstraction2.createBundlerClient)({
544
558
  client: config.publicClient,
545
559
  chain: config.chain,
546
560
  account: config.account,
@@ -1262,8 +1276,6 @@ var import_accounts = require("permissionless/accounts");
1262
1276
 
1263
1277
  // src/accounts/computeSafeOpHash.ts
1264
1278
  var import_viem11 = require("viem");
1265
- var SAFE_4337_MODULE_DEFAULT = "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226";
1266
- var ENTRYPOINT_V07 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
1267
1279
  var SAFE_OP_TYPES = {
1268
1280
  SafeOp: [
1269
1281
  { type: "address", name: "safe" },
@@ -1281,7 +1293,7 @@ var SAFE_OP_TYPES = {
1281
1293
  { type: "address", name: "entryPoint" }
1282
1294
  ]
1283
1295
  };
1284
- function computeSafeOpHash(userOp, chainId, safe4337ModuleAddress = SAFE_4337_MODULE_DEFAULT, entryPointAddress = ENTRYPOINT_V07) {
1296
+ function computeSafeOpHash(userOp, chainId, safe4337ModuleAddress = SAFE_4337_MODULE_ADDRESS, entryPointAddress = import_account_abstraction.entryPoint07Address) {
1285
1297
  const initCode = userOp.factory && (0, import_viem11.isAddress)(userOp.factory) ? (0, import_viem11.concat)([userOp.factory, userOp.factoryData || "0x"]) : "0x";
1286
1298
  let paymasterAndData = "0x";
1287
1299
  if (userOp.paymaster && (0, import_viem11.isAddress)(userOp.paymaster)) {
@@ -1318,8 +1330,6 @@ function computeSafeOpHash(userOp, chainId, safe4337ModuleAddress = SAFE_4337_MO
1318
1330
  }
1319
1331
 
1320
1332
  // src/accounts/toP256SafeSmartAccount.ts
1321
- var SAFE_4337_MODULE_DEFAULT2 = "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226";
1322
- var ENTRYPOINT_V07_ADDRESS = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
1323
1333
  function createMockLocalAccount(address) {
1324
1334
  const notImplemented = () => {
1325
1335
  throw new Error("P256 contract owner: use signUserOperation instead");
@@ -1336,8 +1346,8 @@ function createMockLocalAccount(address) {
1336
1346
  };
1337
1347
  }
1338
1348
  async function toP256SafeSmartAccount(params) {
1339
- const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_DEFAULT2;
1340
- const entryPointAddress = params.entryPoint?.address ?? ENTRYPOINT_V07_ADDRESS;
1349
+ const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_ADDRESS;
1350
+ const entryPointAddress = params.entryPoint?.address ?? import_account_abstraction.entryPoint07Address;
1341
1351
  const mockOwner = createMockLocalAccount(params.p256Signer.p256OwnerAddress);
1342
1352
  const baseAccount = await (0, import_accounts.toSafeSmartAccount)({
1343
1353
  client: params.client,
@@ -1395,11 +1405,9 @@ async function toP256SafeSmartAccount(params) {
1395
1405
 
1396
1406
  // src/accounts/toWebAuthnSafeSmartAccount.ts
1397
1407
  var import_accounts2 = require("permissionless/accounts");
1398
- var SAFE_4337_MODULE_DEFAULT3 = "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226";
1399
- var ENTRYPOINT_V07_ADDRESS2 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
1400
1408
  async function toWebAuthnSafeSmartAccount(params) {
1401
- const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_DEFAULT3;
1402
- const entryPointAddress = params.entryPoint?.address ?? ENTRYPOINT_V07_ADDRESS2;
1409
+ const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_ADDRESS;
1410
+ const entryPointAddress = params.entryPoint?.address ?? import_account_abstraction.entryPoint07Address;
1403
1411
  const baseAccount = await (0, import_accounts2.toSafeSmartAccount)({
1404
1412
  client: params.client,
1405
1413
  owners: [params.webAuthnAccount],
@@ -1416,9 +1424,6 @@ async function toWebAuthnSafeSmartAccount(params) {
1416
1424
  }
1417
1425
 
1418
1426
  // src/accounts/toSafeSmartAccount.ts
1419
- var SAFE_4337_MODULE_DEFAULT4 = "0x75cf11467937ce3F2f357CE24ffc3DBF8fD5c226";
1420
- var ENTRYPOINT_V07_ADDRESS3 = "0x0000000071727De22E5E9d8BAf0edAc6f37da032";
1421
- var SAFE_WEBAUTHN_SHARED_SIGNER = "0xfD90FAd33ee8b58f32c00aceEad1358e4AFC23f9";
1422
1427
  async function toSafeSmartAccount3(params) {
1423
1428
  const { signerConfig } = params;
1424
1429
  switch (signerConfig.type) {
@@ -1503,8 +1508,8 @@ async function buildMultiSignerAccount(params, signers, threshold) {
1503
1508
  }
1504
1509
  const p256Signer = signers.p256;
1505
1510
  const webAuthnAccount = signers.webAuthn;
1506
- const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_DEFAULT4;
1507
- const entryPointAddress = params.entryPoint?.address ?? ENTRYPOINT_V07_ADDRESS3;
1511
+ const safe4337ModuleAddress = params.safe4337ModuleAddress ?? SAFE_4337_MODULE_ADDRESS;
1512
+ const entryPointAddress = params.entryPoint?.address ?? import_account_abstraction.entryPoint07Address;
1508
1513
  const mockP256Owner = createMockLocalAccount2(p256Signer.p256OwnerAddress);
1509
1514
  const baseAccount = await (0, import_accounts3.toSafeSmartAccount)({
1510
1515
  client: params.client,
@@ -1730,16 +1735,22 @@ function computeSafeMessageHash2(safeAddress, chainId, messageHash) {
1730
1735
  ExactEvmSchemeERC4337Client,
1731
1736
  ExactEvmSchemeERC4337Server,
1732
1737
  ExactEvmSchemeNetworkERC4337,
1738
+ FCL_P256_VERIFIER,
1733
1739
  FacilitatorBundlerClient,
1740
+ P256_OWNER_FACTORY,
1741
+ SAFE_4337_MODULE_ADDRESS,
1742
+ SAFE_WEBAUTHN_SHARED_SIGNER,
1734
1743
  SUPPORTED_CHAINS,
1735
1744
  V1_NAME_INDEX,
1736
1745
  ViemBundlerClient,
1746
+ WEBAUTHN_SIGNER_FACTORY,
1737
1747
  buildERC20TransferCallData,
1738
1748
  computeSafeMessageHash,
1739
1749
  computeSafeOpHash,
1740
1750
  createP256SafeMessageSigner,
1741
1751
  createWebAuthnSafeMessageSigner,
1742
1752
  encodeContractSignature,
1753
+ entryPoint07Address,
1743
1754
  extractPasskeyCoordinates,
1744
1755
  extractUserOperationCapability,
1745
1756
  getChain,