@pepu-chain/sdk 0.2.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/README.md +1 -2
  2. package/dist/aa/kernel.cjs +10 -9
  3. package/dist/aa/kernel.js +5 -4
  4. package/dist/aa/react-direct.cjs +10 -9
  5. package/dist/aa/react-direct.cjs.map +1 -1
  6. package/dist/aa/react-direct.js +5 -4
  7. package/dist/aa/react-direct.js.map +1 -1
  8. package/dist/aa/react.cjs +5 -4
  9. package/dist/aa/react.cjs.map +1 -1
  10. package/dist/aa/react.js +3 -2
  11. package/dist/aa/react.js.map +1 -1
  12. package/dist/aa.cjs +18 -17
  13. package/dist/aa.js +5 -4
  14. package/dist/chunk-4GEC7GUU.cjs +283 -0
  15. package/dist/chunk-4GEC7GUU.cjs.map +1 -0
  16. package/dist/{chunk-PHM3ZORG.cjs → chunk-4L4CHIXE.cjs} +9 -9
  17. package/dist/{chunk-PHM3ZORG.cjs.map → chunk-4L4CHIXE.cjs.map} +1 -1
  18. package/dist/{chunk-A5LP2UCS.cjs → chunk-65Y5UCQ7.cjs} +2 -276
  19. package/dist/chunk-65Y5UCQ7.cjs.map +1 -0
  20. package/dist/{chunk-7MNJF2OB.cjs → chunk-DNWWZWUW.cjs} +4 -4
  21. package/dist/{chunk-7MNJF2OB.cjs.map → chunk-DNWWZWUW.cjs.map} +1 -1
  22. package/dist/{chunk-D52PADVY.js → chunk-GFKIM7HT.js} +25 -2
  23. package/dist/chunk-GFKIM7HT.js.map +1 -0
  24. package/dist/{chunk-IY3ALPUJ.js → chunk-GIZNH65Q.js} +5 -273
  25. package/dist/chunk-GIZNH65Q.js.map +1 -0
  26. package/dist/{chunk-WANILJZQ.cjs → chunk-HTCX46RJ.cjs} +25 -2
  27. package/dist/chunk-HTCX46RJ.cjs.map +1 -0
  28. package/dist/{chunk-KVG3AYYR.js → chunk-NHPWXIA2.js} +4 -4
  29. package/dist/{chunk-KVG3AYYR.js.map → chunk-NHPWXIA2.js.map} +1 -1
  30. package/dist/{chunk-ZB6SVBK4.js → chunk-QIDMFFAQ.js} +4 -4
  31. package/dist/{chunk-ZB6SVBK4.js.map → chunk-QIDMFFAQ.js.map} +1 -1
  32. package/dist/{chunk-IB2FSPMJ.js → chunk-QZKUPCUD.js} +3 -3
  33. package/dist/{chunk-IB2FSPMJ.js.map → chunk-QZKUPCUD.js.map} +1 -1
  34. package/dist/chunk-RSPAN44L.js +276 -0
  35. package/dist/chunk-RSPAN44L.js.map +1 -0
  36. package/dist/{chunk-NVOPDXTA.cjs → chunk-UQH4ZAXD.cjs} +10 -10
  37. package/dist/{chunk-NVOPDXTA.cjs.map → chunk-UQH4ZAXD.cjs.map} +1 -1
  38. package/dist/{chunk-BGALSKAF.cjs → chunk-VYMAZVIK.cjs} +4 -4
  39. package/dist/{chunk-BGALSKAF.cjs.map → chunk-VYMAZVIK.cjs.map} +1 -1
  40. package/dist/{chunk-F2R473FR.js → chunk-XR5ONV2Y.js} +3 -3
  41. package/dist/{chunk-F2R473FR.js.map → chunk-XR5ONV2Y.js.map} +1 -1
  42. package/dist/combo/react.cjs +61 -13
  43. package/dist/combo/react.cjs.map +1 -1
  44. package/dist/combo/react.d.cts +14 -2
  45. package/dist/combo/react.d.ts +14 -2
  46. package/dist/combo/react.guard.js +1 -1
  47. package/dist/combo/react.js +58 -11
  48. package/dist/combo/react.js.map +1 -1
  49. package/dist/combo.cjs +41 -26
  50. package/dist/combo.cjs.map +1 -1
  51. package/dist/combo.d.cts +11 -0
  52. package/dist/combo.d.ts +11 -0
  53. package/dist/combo.js +31 -16
  54. package/dist/combo.js.map +1 -1
  55. package/dist/index.cjs +10 -9
  56. package/dist/index.cjs.map +1 -1
  57. package/dist/index.js +3 -2
  58. package/dist/index.js.map +1 -1
  59. package/dist/paymaster.cjs +37 -36
  60. package/dist/paymaster.cjs.map +1 -1
  61. package/dist/paymaster.js +3 -2
  62. package/dist/paymaster.js.map +1 -1
  63. package/dist/react.cjs +4 -3
  64. package/dist/react.cjs.map +1 -1
  65. package/dist/react.js +3 -2
  66. package/dist/react.js.map +1 -1
  67. package/dist/session/kernel.cjs +18 -17
  68. package/dist/session/kernel.js +6 -5
  69. package/package.json +1 -1
  70. package/dist/chunk-A5LP2UCS.cjs.map +0 -1
  71. package/dist/chunk-D52PADVY.js.map +0 -1
  72. package/dist/chunk-IY3ALPUJ.js.map +0 -1
  73. package/dist/chunk-WANILJZQ.cjs.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/aa/clients.ts"],"names":["resolvePepuEndpoints","PepuConfigError","PEPU_ENV","buildErc7677Url","createPaymasterClient","http","createPublicClient","pepuMainnet","createBundlerClient"],"mappings":";;;;;;;;;AAYO,IAAM,eAAA,GAAkB;AAAA,EAC7B,OAAA,EAAS,4CAAA;AAAA,EACT,OAAA,EAAS;AACX;AAGA,IAAM,gBAAA,GAAmB,GAAA;AACzB,IAAM,gBAAA,GAAmB,GAAA;AAWzB,eAAsB,uBACpB,YAAA,EACiE;AACjE,EAAA,MAAM,IAAA,GAAO,MAAM,YAAA,CAAa,kBAAA,EAAmB;AACnD,EAAA,OAAO;AAAA,IACL,YAAA,EAAe,IAAA,CAAK,YAAA,GAAe,gBAAA,GAAoB,gBAAA;AAAA,IACvD,sBAAsB,IAAA,CAAK;AAAA,GAC7B;AACF;AAGO,SAAS,kBAAkB,QAAA,EAA2B;AAC3D,EAAA,MAAM,EAAE,UAAA,EAAW,GAAIA,sCAAA,CAAqB,QAAA,KAAa,MAAA,GAAY,EAAC,GAAI,EAAE,UAAA,EAAY,QAAA,EAAU,CAAA;AAClG,EAAA,IAAI,eAAe,IAAA,EAAM;AACvB,IAAA,MAAM,IAAIC,iCAAA,CAAgB,oBAAA,EAAsB,CAAA,oBAAA,EAAuBC,0BAAA,CAAS,UAAU,CAAA,oBAAA,CAAA,EAAwB;AAAA,MAChH,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACA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A,EAAK;AAAA,GAC9F;AACF;AAUO,SAAS,wBAAwB,CAAA,EAMtB;AAChB,EAAA,MAAM,MAAA,GAASL,wCAAqB,CAAE,MAAA;AACtC,EAAA,MAAM,YAAA,GAAe,CAAA,CAAE,YAAA,IAAgBM,uBAAA,CAAmB,EAAE,KAAA,EAAOC,6BAAA,EAAa,SAAA,EAAWF,SAAA,CAAK,MAAM,CAAA,EAAG,CAAA;AACzG,EAAA,OAAOG,sCAAA,CAAoB;AAAA,IACzB,SAAS,CAAA,CAAE,OAAA;AAAA,IACX,KAAA,EAAOD,6BAAA;AAAA,IACP,MAAA,EAAQ,YAAA;AAAA,IACR,SAAA,EAAWF,SAAA,CAAK,iBAAA,CAAkB,CAAA,CAAE,UAAU,CAAC,CAAA;AAAA,IAC/C,GAAI,EAAE,SAAA,GAAY,EAAE,WAAW,CAAA,CAAE,SAAA,KAAc,EAAC;AAAA,IAChD,GAAI,EAAE,gBAAA,GAAmB,EAAE,kBAAkB,CAAA,CAAE,gBAAA,KAAqB,EAAC;AAAA,IACrE,eAAe,EAAE,kBAAA,EAAoB,YAAY,sBAAA,CAAuB,YAAY,CAAA;AAAE,GACvF,CAAA;AACH","file":"chunk-7MNJF2OB.cjs","sourcesContent":["import { createPublicClient, http } from \"viem\";\nimport type { PublicClient } from \"viem\";\nimport { createBundlerClient, createPaymasterClient } from \"viem/account-abstraction\";\nimport type { BundlerClient, PaymasterClient, SmartAccount } from \"viem/account-abstraction\";\n\nimport { pepuMainnet } from \"../chains.js\";\nimport { PEPU_ENV, resolvePepuEndpoints } from \"../endpoints.js\";\nimport { PepuConfigError } from \"../errors.js\";\nimport type { PaymasterContext } from \"../erc7677.js\";\nimport { buildErc7677Url } from \"../paymaster/api.js\";\n\n/** EntryPoint v0.7, the only version PEPU's bundler and paymaster speak. */\nexport const ENTRY_POINT_V07 = {\n address: \"0x0000000071727De22E5E9d8BAf0edAc6f37da032\",\n version: \"0.7\",\n} as const;\n\n/** Fee headroom numerator/denominator: 12/10 = +20%. */\nconst FEE_HEADROOM_NUM = 12n;\nconst FEE_HEADROOM_DEN = 10n;\n\n/**\n * The Alto-compatible fee estimator: the chain's own `estimateFeesPerGas`,\n * with `maxFeePerGas` x 1.2. Alto does not implement ZeroDev's\n * `zd_getUserOperationGasPrice`, so the default estimator would fail.\n * Ported from `templates/sponsored-session-app/lib/kernel.ts`.\n *\n * @example\n * const fees = await estimatePepuUserOpFees(publicClient);\n */\nexport async function estimatePepuUserOpFees(\n publicClient: Pick<PublicClient, \"estimateFeesPerGas\">,\n): Promise<{ maxFeePerGas: bigint; maxPriorityFeePerGas: bigint }> {\n const fees = await publicClient.estimateFeesPerGas();\n return {\n maxFeePerGas: (fees.maxFeePerGas * FEE_HEADROOM_NUM) / FEE_HEADROOM_DEN,\n maxPriorityFeePerGas: fees.maxPriorityFeePerGas,\n };\n}\n\n/** Resolve the bundler URL or throw `CONFIG_MISSING_ENV` naming the variable. */\nexport function requireBundlerUrl(explicit?: string): string {\n const { bundlerUrl } = resolvePepuEndpoints(explicit === undefined ? {} : { bundlerUrl: explicit });\n if (bundlerUrl === null) {\n throw new PepuConfigError(\"CONFIG_MISSING_ENV\", `No bundler URL. Set ${PEPU_ENV.bundlerUrl} or pass bundlerUrl.`, {\n hint: \"The hosted PEPU bundler is the default; if it was cleared, set PEPU_BUNDLER_URL to https://bundler.pepeunchained.com or your own bundler.\",\n });\n }\n return bundlerUrl;\n}\n\n/**\n * Resolve the complete ERC-7677 paymaster URL or throw `CONFIG_MISSING_ENV`.\n * Order: `explicit` URL, then `PEPU_PAYMASTER_URL`, then `token` (a project client token, built against the\n * paymaster base: the hosted service unless a custom URL is configured). The hosted paymaster has no tokenless\n * ERC-7677 URL, because the token names the project (or free-tier app) that is billed.\n */\nexport function requirePaymasterUrl(explicit?: string, token?: string): string {\n const { paymasterUrl, paymasterBaseUrl } = resolvePepuEndpoints(explicit === undefined ? {} : { paymasterUrl: explicit });\n if (paymasterUrl !== null) return paymasterUrl;\n if (token !== undefined && token.trim() !== \"\" && paymasterBaseUrl !== null) {\n return buildErc7677Url({ baseUrl: paymasterBaseUrl, token });\n }\n throw new PepuConfigError(\"CONFIG_MISSING_ENV\", `No ERC-7677 paymaster URL. Set ${PEPU_ENV.paymasterUrl} or pass paymasterUrl / paymasterToken.`, {\n hint: \"The hosted paymaster (https://paymaster.pepeunchained.com) needs your project's client token: set PEPU_PAYMASTER_URL to https://paymaster.pepeunchained.com/v2/paymaster/<client token>.\",\n });\n}\n\n/**\n * An ERC-7677 paymaster client for PEPU (viem `createPaymasterClient`), using\n * the endpoints registry for the URL. A `context` (for example\n * `buildPaymasterContext({ privyAccessToken })`) is injected into every\n * `pm_getPaymasterStubData` and `pm_getPaymasterData` call unless the caller\n * passes one.\n *\n * @example\n * const paymaster = createPepuPaymasterClient({\n * context: buildPaymasterContext({ privyAccessToken }),\n * });\n */\nexport function createPepuPaymasterClient(\n o: { paymasterUrl?: string; paymasterToken?: string; context?: PaymasterContext } = {},\n): PaymasterClient {\n const client = createPaymasterClient({ transport: http(requirePaymasterUrl(o.paymasterUrl, o.paymasterToken)) });\n const ctx = o.context;\n if (!ctx) return client;\n return {\n ...client,\n getPaymasterData: (p) => client.getPaymasterData({ ...p, context: p.context ?? ctx }),\n getPaymasterStubData: (p) => client.getPaymasterStubData({ ...p, context: p.context ?? ctx }),\n };\n}\n\n/**\n * A viem bundler client for PEPU's bundler, with the fee estimator\n * pre-wired ({@link estimatePepuUserOpFees}).\n *\n * @example\n * const bundler = createPepuBundlerClient({ account, paymaster: createPepuPaymasterClient() });\n * const hash = await bundler.sendUserOperation({ calls: [{ to, data }] });\n */\nexport function createPepuBundlerClient(o: {\n bundlerUrl?: string;\n account: SmartAccount;\n paymaster?: PaymasterClient;\n paymasterContext?: PaymasterContext;\n publicClient?: PublicClient;\n}): BundlerClient {\n const rpcUrl = resolvePepuEndpoints().rpcUrl;\n const publicClient = o.publicClient ?? createPublicClient({ chain: pepuMainnet, transport: http(rpcUrl) });\n return createBundlerClient({\n account: o.account,\n chain: pepuMainnet,\n client: publicClient,\n transport: http(requireBundlerUrl(o.bundlerUrl)),\n ...(o.paymaster ? { paymaster: o.paymaster } : {}),\n ...(o.paymasterContext ? { paymasterContext: o.paymasterContext } : {}),\n userOperation: { estimateFeesPerGas: async () => estimatePepuUserOpFees(publicClient) },\n }) as BundlerClient;\n}\n"]}
1
+ {"version":3,"sources":["../src/aa/clients.ts"],"names":["resolvePepuEndpoints","PepuConfigError","PEPU_ENV","buildErc7677Url","createPaymasterClient","http","createPublicClient","pepuMainnet","createBundlerClient"],"mappings":";;;;;;;;;AAYO,IAAM,eAAA,GAAkB;AAAA,EAC7B,OAAA,EAAS,4CAAA;AAAA,EACT,OAAA,EAAS;AACX;AAGA,IAAM,gBAAA,GAAmB,GAAA;AACzB,IAAM,gBAAA,GAAmB,GAAA;AAWzB,eAAsB,uBACpB,YAAA,EACiE;AACjE,EAAA,MAAM,IAAA,GAAO,MAAM,YAAA,CAAa,kBAAA,EAAmB;AACnD,EAAA,OAAO;AAAA,IACL,YAAA,EAAe,IAAA,CAAK,YAAA,GAAe,gBAAA,GAAoB,gBAAA;AAAA,IACvD,sBAAsB,IAAA,CAAK;AAAA,GAC7B;AACF;AAGO,SAAS,kBAAkB,QAAA,EAA2B;AAC3D,EAAA,MAAM,EAAE,UAAA,EAAW,GAAIA,sCAAA,CAAqB,QAAA,KAAa,MAAA,GAAY,EAAC,GAAI,EAAE,UAAA,EAAY,QAAA,EAAU,CAAA;AAClG,EAAA,IAAI,eAAe,IAAA,EAAM;AACvB,IAAA,MAAM,IAAIC,iCAAA,CAAgB,oBAAA,EAAsB,CAAA,oBAAA,EAAuBC,0BAAA,CAAS,UAAU,CAAA,oBAAA,CAAA,EAAwB;AAAA,MAChH,IAAA,EAAM;AAAA,KACP,CAAA;AAAA,EACH;AACA,EAAA,OAAO,UAAA;AACT;AAQO,SAAS,mBAAA,CAAoB,UAAmB,KAAA,EAAwB;AAC7E,EAAA,MAAM,EAAE,YAA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AAE,MAAA;AACtC,EAAA,MAAM,YAAA,GAAe,CAAA,CAAE,YAAA,IAAgBM,uBAAA,CAAmB,EAAE,KAAA,EAAOC,6BAAA,EAAa,SAAA,EAAWF,SAAA,CAAK,MAAM,CAAA,EAAG,CAAA;AACzG,EAAA,OAAOG,sCAAA,CAAoB;AAAA,IACzB,SAAS,CAAA,CAAE,OAAA;AAAA,IACX,KAAA,EAAOD,6BAAA;AAAA,IACP,MAAA,EAAQ,YAAA;AAAA,IACR,SAAA,EAAWF,SAAA,CAAK,iBAAA,CAAkB,CAAA,CAAE,UAAU,CAAC,CAAA;AAAA,IAC/C,GAAI,EAAE,SAAA,GAAY,EAAE,WAAW,CAAA,CAAE,SAAA,KAAc,EAAC;AAAA,IAChD,GAAI,EAAE,gBAAA,GAAmB,EAAE,kBAAkB,CAAA,CAAE,gBAAA,KAAqB,EAAC;AAAA,IACrE,eAAe,EAAE,kBAAA,EAAoB,YAAY,sBAAA,CAAuB,YAAY,CAAA;AAAE,GACvF,CAAA;AACH","file":"chunk-DNWWZWUW.cjs","sourcesContent":["import { createPublicClient, http } from \"viem\";\nimport type { PublicClient } from \"viem\";\nimport { createBundlerClient, createPaymasterClient } from \"viem/account-abstraction\";\nimport type { BundlerClient, PaymasterClient, SmartAccount } from \"viem/account-abstraction\";\n\nimport { pepuMainnet } from \"../chains.js\";\nimport { PEPU_ENV, resolvePepuEndpoints } from \"../endpoints.js\";\nimport { PepuConfigError } from \"../errors.js\";\nimport type { PaymasterContext } from \"../erc7677.js\";\nimport { buildErc7677Url } from \"../paymaster/api.js\";\n\n/** EntryPoint v0.7, the only version PEPU's bundler and paymaster speak. */\nexport const ENTRY_POINT_V07 = {\n address: \"0x0000000071727De22E5E9d8BAf0edAc6f37da032\",\n version: \"0.7\",\n} as const;\n\n/** Fee headroom numerator/denominator: 12/10 = +20%. */\nconst FEE_HEADROOM_NUM = 12n;\nconst FEE_HEADROOM_DEN = 10n;\n\n/**\n * The Alto-compatible fee estimator: the chain's own `estimateFeesPerGas`,\n * with `maxFeePerGas` x 1.2. Alto does not implement ZeroDev's\n * `zd_getUserOperationGasPrice`, so the default estimator would fail.\n * Ported from `templates/sponsored-session-app/lib/kernel.ts`.\n *\n * @example\n * const fees = await estimatePepuUserOpFees(publicClient);\n */\nexport async function estimatePepuUserOpFees(\n publicClient: Pick<PublicClient, \"estimateFeesPerGas\">,\n): Promise<{ maxFeePerGas: bigint; maxPriorityFeePerGas: bigint }> {\n const fees = await publicClient.estimateFeesPerGas();\n return {\n maxFeePerGas: (fees.maxFeePerGas * FEE_HEADROOM_NUM) / FEE_HEADROOM_DEN,\n maxPriorityFeePerGas: fees.maxPriorityFeePerGas,\n };\n}\n\n/** Resolve the bundler URL or throw `CONFIG_MISSING_ENV` naming the variable. */\nexport function requireBundlerUrl(explicit?: string): string {\n const { bundlerUrl } = resolvePepuEndpoints(explicit === undefined ? {} : { bundlerUrl: explicit });\n if (bundlerUrl === null) {\n throw new PepuConfigError(\"CONFIG_MISSING_ENV\", `No bundler URL. Set ${PEPU_ENV.bundlerUrl} or pass bundlerUrl.`, {\n hint: \"The hosted PEPU bundler is the default; if it was cleared, set PEPU_BUNDLER_URL to https://bundler.pepeunchained.com or your own bundler.\",\n });\n }\n return bundlerUrl;\n}\n\n/**\n * Resolve the complete ERC-7677 paymaster URL or throw `CONFIG_MISSING_ENV`.\n * Order: `explicit` URL, then `PEPU_PAYMASTER_URL`, then `token` (a project client token, built against the\n * paymaster base: the hosted service unless a custom URL is configured). The hosted paymaster has no tokenless\n * ERC-7677 URL, because the token names the project (or free-tier app) that is billed.\n */\nexport function requirePaymasterUrl(explicit?: string, token?: string): string {\n const { paymasterUrl, paymasterBaseUrl } = resolvePepuEndpoints(explicit === undefined ? {} : { paymasterUrl: explicit });\n if (paymasterUrl !== null) return paymasterUrl;\n if (token !== undefined && token.trim() !== \"\" && paymasterBaseUrl !== null) {\n return buildErc7677Url({ baseUrl: paymasterBaseUrl, token });\n }\n throw new PepuConfigError(\"CONFIG_MISSING_ENV\", `No ERC-7677 paymaster URL. Set ${PEPU_ENV.paymasterUrl} or pass paymasterUrl / paymasterToken.`, {\n hint: \"The hosted paymaster (https://paymaster.pepeunchained.com) needs your project's client token: set PEPU_PAYMASTER_URL to https://paymaster.pepeunchained.com/v2/paymaster/<client token>.\",\n });\n}\n\n/**\n * An ERC-7677 paymaster client for PEPU (viem `createPaymasterClient`), using\n * the endpoints registry for the URL. A `context` (for example\n * `buildPaymasterContext({ privyAccessToken })`) is injected into every\n * `pm_getPaymasterStubData` and `pm_getPaymasterData` call unless the caller\n * passes one.\n *\n * @example\n * const paymaster = createPepuPaymasterClient({\n * context: buildPaymasterContext({ privyAccessToken }),\n * });\n */\nexport function createPepuPaymasterClient(\n o: { paymasterUrl?: string; paymasterToken?: string; context?: PaymasterContext } = {},\n): PaymasterClient {\n const client = createPaymasterClient({ transport: http(requirePaymasterUrl(o.paymasterUrl, o.paymasterToken)) });\n const ctx = o.context;\n if (!ctx) return client;\n return {\n ...client,\n getPaymasterData: (p) => client.getPaymasterData({ ...p, context: p.context ?? ctx }),\n getPaymasterStubData: (p) => client.getPaymasterStubData({ ...p, context: p.context ?? ctx }),\n };\n}\n\n/**\n * A viem bundler client for PEPU's bundler, with the fee estimator\n * pre-wired ({@link estimatePepuUserOpFees}).\n *\n * @example\n * const bundler = createPepuBundlerClient({ account, paymaster: createPepuPaymasterClient() });\n * const hash = await bundler.sendUserOperation({ calls: [{ to, data }] });\n */\nexport function createPepuBundlerClient(o: {\n bundlerUrl?: string;\n account: SmartAccount;\n paymaster?: PaymasterClient;\n paymasterContext?: PaymasterContext;\n publicClient?: PublicClient;\n}): BundlerClient {\n const rpcUrl = resolvePepuEndpoints().rpcUrl;\n const publicClient = o.publicClient ?? createPublicClient({ chain: pepuMainnet, transport: http(rpcUrl) });\n return createBundlerClient({\n account: o.account,\n chain: pepuMainnet,\n client: publicClient,\n transport: http(requireBundlerUrl(o.bundlerUrl)),\n ...(o.paymaster ? { paymaster: o.paymaster } : {}),\n ...(o.paymasterContext ? { paymasterContext: o.paymasterContext } : {}),\n userOperation: { estimateFeesPerGas: async () => estimatePepuUserOpFees(publicClient) },\n }) as BundlerClient;\n}\n"]}
@@ -1,3 +1,4 @@
1
+ import { PAYMASTER_DENIAL_REASONS, paymasterReasonToError } from './chunk-GIZNH65Q.js';
1
2
  import { PepuPaymasterError, PepuBundlerError, explainError, toPepuError, getErrorEntry } from './chunk-6DSZ4Z2N.js';
2
3
 
3
4
  // src/aa/describe.ts
@@ -28,6 +29,26 @@ var AA_HINTS = {
28
29
  function redactSecrets(text) {
29
30
  return text.replace(/\/paymaster\/[^\s/"'`)\]?#]+/gi, "/paymaster/[redacted]").replace(/(bearer\s+)[A-Za-z0-9._~+/=-]+/gi, "$1[redacted]").replace(/(x-api-key["']?\s*[:=]\s*["']?)[^\s"',}]+/gi, "$1[redacted]").replace(/(privyAccessToken["']?\s*[:=]\s*["']?)[^\s"',}]+/gi, "$1[redacted]").replace(/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]*/g, "[redacted-jwt]").replace(/(https?:\/\/)[^\s/@]+:[^\s/@]+@/gi, "$1[redacted]@");
30
31
  }
32
+ var DENIAL_HINTS = {
33
+ sender_not_owned_by_token_user: "The smart account is not one of the signed-in user's accounts. Send the access token of the user who owns this account, and build the account from that user's embedded wallet.",
34
+ free_tier_identity_required: "The free tier needs a verified Privy access token. Forward it to the paymaster as context.privyAccessToken (the SDK combo routes do this by default)."
35
+ };
36
+ function paymasterDenial(text) {
37
+ const message = /Sponsorship denied:\s*([^\r\n]+)/i.exec(text)?.[1]?.trim();
38
+ let reason;
39
+ let at = Infinity;
40
+ for (const r of PAYMASTER_DENIAL_REASONS) {
41
+ const i = text.search(new RegExp(`(?<![a-z_])${r}(?![a-z_])`));
42
+ if (i >= 0 && i < at) {
43
+ at = i;
44
+ reason = r;
45
+ }
46
+ }
47
+ if (message === void 0 && reason === void 0) return null;
48
+ const err = paymasterReasonToError(reason, message);
49
+ const hint = (reason && DENIAL_HINTS[reason]) ?? getErrorEntry(err.code).fix;
50
+ return new PepuPaymasterError(err.code, err.message, { hint, details: err.details, ...err.retryable ? { retryable: true } : {} });
51
+ }
31
52
  function collect(e) {
32
53
  const seen = /* @__PURE__ */ new Set();
33
54
  const parts = [];
@@ -67,6 +88,8 @@ function describeUserOpFailure(e) {
67
88
  }
68
89
  return new PepuBundlerError("BUNDLER_AA_FAILED", `${key}: ${headline}`, opts());
69
90
  }
91
+ const denial = paymasterDenial(text);
92
+ if (denial) return denial;
70
93
  const explained = explainError(text);
71
94
  if (explained.code.startsWith("PAYMASTER_")) {
72
95
  return new PepuPaymasterError(explained.code, headline, opts(explained.fix));
@@ -80,5 +103,5 @@ function describeUserOpFailure(e) {
80
103
  }
81
104
 
82
105
  export { describeUserOpFailure, redactSecrets };
83
- //# sourceMappingURL=chunk-D52PADVY.js.map
84
- //# sourceMappingURL=chunk-D52PADVY.js.map
106
+ //# sourceMappingURL=chunk-GFKIM7HT.js.map
107
+ //# sourceMappingURL=chunk-GFKIM7HT.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/aa/describe.ts"],"names":[],"mappings":";;;;AAcA,IAAM,QAAA,GAA6C;AAAA,EACjD,IAAA,EAAM,EAAE,IAAA,EAAM,mBAAA,EAAqB,MAAM,gFAAA,EAAiF;AAAA,EAC1H,IAAA,EAAM,EAAE,IAAA,EAAM,mBAAA,EAAqB,MAAM,sFAAA,EAAuF;AAAA,EAChI,IAAA,EAAM,EAAE,IAAA,EAAM,mBAAA,EAAqB,MAAM,2GAAA,EAA4G;AAAA,EACrJ,IAAA,EAAM,EAAE,IAAA,EAAM,mBAAA,EAAqB,MAAM,sHAAA,EAAuH;AAAA,EAChK,IAAA,EAAM,EAAE,IAAA,EAAM,mBAAA,EAAqB,MAAM,6EAAA,EAA8E;AAAA,EACvH,IAAA,EAAM,EAAE,IAAA,EAAM,mBAAA,EAAqB,MAAM,k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AAA,EAAA,EAAK,QAAQ,CAAA,CAAA,EAAI,IAAA,EAAM,CAAA;AAAA,EAChF;AAEA,EAAA,MAAM,MAAA,GAAS,gBAAgB,IAAI,CAAA;AACnC,EAAA,IAAI,QAAQ,OAAO,MAAA;AAEnB,EAAA,MAAM,SAAA,GAAY,aAAa,IAAI,CAAA;AACnC,EAAA,IAAI,SAAA,CAAU,IAAA,CAAK,UAAA,CAAW,YAAY,CAAA,EAAG;AAC3C,IAAA,OAAO,IAAI,mBAAmB,SAAA,CAAU,IAAA,EAAM,UAAU,IAAA,CAAK,SAAA,CAAU,GAAG,CAAC,CAAA;AAAA,EAC7E;AACA,EAAA,IAAI,SAAA,CAAU,SAAS,SAAA,EAAW;AAChC,IAAA,OAAO,IAAI,iBAAiB,SAAA,CAAU,IAAA,EAAM,UAAU,IAAA,CAAK,SAAA,CAAU,GAAG,CAAC,CAAA;AAAA,EAC3E;AACA,EAAA,MAAM,EAAA,GAAK,YAAY,CAAC,CAAA;AACxB,EAAA,IAAI,EAAA,CAAG,IAAA,KAAS,SAAA,EAAW,OAAO,IAAI,gBAAA,CAAiB,EAAA,CAAG,IAAA,EAAM,aAAA,CAAc,GAAG,OAAO,CAAA,EAAG,IAAA,CAAK,EAAA,CAAG,IAAI,CAAC,CAAA;AACxG,EAAA,OAAO,IAAI,iBAAiB,SAAA,EAAW,QAAA,EAAU,KAAK,aAAA,CAAc,SAAS,CAAA,CAAE,GAAG,CAAC,CAAA;AACrF","file":"chunk-GFKIM7HT.js","sourcesContent":["import { PepuBundlerError, PepuPaymasterError, explainError, getErrorEntry, toPepuError } from \"../errors.js\";\nimport type { PepuErrorCode } from \"../errors.js\";\nimport { PAYMASTER_DENIAL_REASONS, paymasterReasonToError } from \"../paymaster/reasons.js\";\n\ninterface AaInfo {\n code: PepuErrorCode;\n paymaster?: boolean;\n hint: string;\n}\n\n/**\n * AAxx meaning, per the EntryPoint v0.7 revert reasons, with the PEPU-specific\n * fix. Ported from the sponsored-demo and sponsored-session-app runs.\n */\nconst AA_HINTS: Readonly<Record<string, AaInfo>> = {\n AA10: { code: \"BUNDLER_AA_FAILED\", hint: \"The sender is already deployed but initCode was sent. Drop the factory fields.\" },\n AA13: { code: \"BUNDLER_AA_FAILED\", hint: \"initCode (account factory) reverted. Check the Kernel factory address and the owner.\" },\n AA14: { code: \"BUNDLER_AA_FAILED\", hint: \"initCode deployed a different address than the sender. Rebuild the account with the same owner and index.\" },\n AA20: { code: \"BUNDLER_AA_FAILED\", hint: \"The account is not deployed and no initCode was sent. Use a fresh account object so the factory fields are included.\" },\n AA21: { code: \"BUNDLER_AA_FAILED\", hint: \"The account cannot pay its prefund. Use the paymaster, or fund the account.\" },\n AA22: { code: \"BUNDLER_AA_FAILED\", hint: \"The UserOperation's validity window expired. Resend a fresh one.\" },\n AA23: { code: \"BUNDLER_AA_FAILED\", hint: \"Account validation reverted: wrong signer, wrong signature format, or a session policy rejected the call.\" },\n AA24: { code: \"BUNDLER_AA_FAILED\", hint: \"Signature rejected by the account. Sign with the owner the account was built for.\" },\n AA25: { code: \"BUNDLER_AA_FAILED\", hint: \"Invalid nonce: another UserOperation from this account is pending. Wait for it, then retry.\" },\n AA26: { code: \"BUNDLER_AA_FAILED\", hint: \"verificationGasLimit too low. Re-estimate gas.\" },\n AA31: { code: \"PAYMASTER_NO_BALANCE\", paymaster: true, hint: \"The paymaster's EntryPoint deposit is too low. Deposit more PEPU to the paymaster.\" },\n AA32: { code: \"PAYMASTER_DENIED\", paymaster: true, hint: \"The paymaster signature expired. Request paymaster data again.\" },\n AA33: { code: \"PAYMASTER_DENIED\", paymaster: true, hint: \"Paymaster validation reverted. Check the paymaster contract and that its signer matches the policy service.\" },\n AA34: { code: \"PAYMASTER_DENIED\", paymaster: true, hint: \"Paymaster signature rejected. The policy service signer does not match the paymaster contract.\" },\n AA36: { code: \"BUNDLER_AA_FAILED\", paymaster: true, hint: \"Paymaster gas limits too low. Re-estimate with the paymaster stub data.\" },\n AA40: { code: \"BUNDLER_AA_FAILED\", hint: \"Verification used more gas than verificationGasLimit. Re-estimate gas.\" },\n AA41: { code: \"BUNDLER_AA_FAILED\", hint: \"Paymaster verification used more gas than its limit. Re-estimate gas.\" },\n AA50: { code: \"BUNDLER_AA_FAILED\", hint: \"The postOp reverted. Check the paymaster's postOp path.\" },\n AA51: { code: \"BUNDLER_AA_FAILED\", hint: \"Prefund below actualGasCost. Re-estimate fees; PEPU needs fee headroom (the SDK applies 20%).\" },\n AA90: { code: \"BUNDLER_AA_FAILED\", hint: \"Invalid beneficiary on handleOps. This is a bundler configuration problem.\" },\n AA91: { code: \"BUNDLER_AA_FAILED\", hint: \"Failed to send funds to the beneficiary. This is a bundler configuration problem.\" },\n AA95: { code: \"BUNDLER_AA_FAILED\", hint: \"Out of gas in handleOps. Raise the gas limits.\" },\n};\n\n/**\n * Remove anything credential-shaped from text that may reach a message:\n * `/paymaster/<token>` URL paths, bearer tokens, API keys, JWTs and URL\n * credentials.\n *\n * @example\n * redactSecrets(\"POST https://pm.example/paymaster/sk_live_123 failed\");\n * // \"POST https://pm.example/paymaster/[redacted] failed\"\n */\nexport function redactSecrets(text: string): string {\n return text\n .replace(/\\/paymaster\\/[^\\s/\"'`)\\]?#]+/gi, \"/paymaster/[redacted]\")\n .replace(/(bearer\\s+)[A-Za-z0-9._~+/=-]+/gi, \"$1[redacted]\")\n .replace(/(x-api-key[\"']?\\s*[:=]\\s*[\"']?)[^\\s\"',}]+/gi, \"$1[redacted]\")\n .replace(/(privyAccessToken[\"']?\\s*[:=]\\s*[\"']?)[^\\s\"',}]+/gi, \"$1[redacted]\")\n .replace(/\\beyJ[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]{8,}\\.[A-Za-z0-9_-]*/g, \"[redacted-jwt]\")\n .replace(/(https?:\\/\\/)[^\\s/@]+:[^\\s/@]+@/gi, \"$1[redacted]@\");\n}\n\n/** Fix text for denial reasons where the catalog's generic fix for the code is not specific enough. */\nconst DENIAL_HINTS: Readonly<Record<string, string>> = {\n sender_not_owned_by_token_user:\n \"The smart account is not one of the signed-in user's accounts. Send the access token of the user who owns this account, and build the account from that user's embedded wallet.\",\n free_tier_identity_required:\n \"The free tier needs a verified Privy access token. Forward it to the paymaster as context.privyAccessToken (the SDK combo routes do this by default).\",\n};\n\n/**\n * The paymaster's denial, if this failure is one. viem maps the service's JSON-RPC -32000 to a generic\n * \"Missing or invalid parameters.\" whose real text is in `details` (\"Sponsorship denied: ...\") and `data.reason`.\n */\nfunction paymasterDenial(text: string): PepuPaymasterError | null {\n const message = /Sponsorship denied:\\s*([^\\r\\n]+)/i.exec(text)?.[1]?.trim();\n let reason: string | undefined;\n let at = Infinity;\n for (const r of PAYMASTER_DENIAL_REASONS) {\n const i = text.search(new RegExp(`(?<![a-z_])${r}(?![a-z_])`));\n if (i >= 0 && i < at) {\n at = i;\n reason = r;\n }\n }\n if (message === undefined && reason === undefined) return null;\n const err = paymasterReasonToError(reason, message);\n const hint = (reason && DENIAL_HINTS[reason]) ?? getErrorEntry(err.code).fix;\n return new PepuPaymasterError(err.code, err.message, { hint, details: err.details, ...(err.retryable ? { retryable: true } : {}) });\n}\n\nfunction collect(e: unknown): string {\n const seen = new Set<unknown>();\n const parts: string[] = [];\n let cur: unknown = e;\n for (let d = 0; d < 8 && cur !== undefined && cur !== null && !seen.has(cur); d++) {\n seen.add(cur);\n if (typeof cur === \"object\") {\n const o = cur as Record<string, unknown>;\n for (const k of [\"shortMessage\", \"message\", \"details\", \"reason\"]) {\n const v = o[k];\n if (typeof v === \"string\" && v.length > 0 && !parts.includes(v)) parts.push(v);\n }\n const data = o[\"data\"];\n if (data && typeof data === \"object\") {\n const r = (data as Record<string, unknown>)[\"reason\"];\n if (typeof r === \"string\") parts.push(r);\n }\n cur = o[\"cause\"];\n } else {\n parts.push(String(cur));\n break;\n }\n }\n return parts.join(\"\\n\");\n}\n\n/**\n * Turn anything thrown by the bundler, paymaster or viem/Privy stack into a\n * typed PepuError. Walks the `cause` chain (viem's `details` is where the\n * paymaster's real denial reason lives; Privy's own log prints\n * `[object Error]`), maps `AA10`..`AA9x` to a fix, maps paymaster reason codes\n * through the error catalog, and redacts tokens and URL credentials.\n * Port of `templates/sponsored-demo/lib/describe-error.ts`.\n *\n * @example\n * try { await sendSponsored({ client, calls }); }\n * catch (e) { const err = describeUserOpFailure(e); console.log(err.code, err.hint); }\n */\nexport function describeUserOpFailure(e: unknown): PepuBundlerError | PepuPaymasterError {\n const text = redactSecrets(collect(e));\n const headline = text.split(\"\\n\")[0]?.trim() || \"UserOperation failed\";\n const opts = (hint?: string) => ({ ...(hint ? { hint } : {}), cause: e });\n\n const aa = /\\bAA(\\d{2})\\b/.exec(text);\n if (aa) {\n const key = `AA${aa[1]}`;\n const info = AA_HINTS[key];\n if (info) {\n const msg = `${key}: ${headline}`;\n return info.paymaster && info.code !== \"BUNDLER_AA_FAILED\"\n ? new PepuPaymasterError(info.code, msg, opts(info.hint))\n : new PepuBundlerError(info.code, msg, opts(info.hint));\n }\n return new PepuBundlerError(\"BUNDLER_AA_FAILED\", `${key}: ${headline}`, opts());\n }\n\n const denial = paymasterDenial(text);\n if (denial) return denial;\n\n const explained = explainError(text);\n if (explained.code.startsWith(\"PAYMASTER_\")) {\n return new PepuPaymasterError(explained.code, headline, opts(explained.fix));\n }\n if (explained.code !== \"UNKNOWN\") {\n return new PepuBundlerError(explained.code, headline, opts(explained.fix));\n }\n const pe = toPepuError(e);\n if (pe.code !== \"UNKNOWN\") return new PepuBundlerError(pe.code, redactSecrets(pe.message), opts(pe.hint));\n return new PepuBundlerError(\"UNKNOWN\", headline, opts(getErrorEntry(\"UNKNOWN\").fix));\n}\n"]}
@@ -1,8 +1,5 @@
1
- import { PEPU_HOSTED, resolvePepuEndpoints } from './chunk-XC4IBCI2.js';
2
- import { pepuMainnet } from './chunk-VTQIHMF3.js';
3
- import { PepuPaymasterError, PepuConfigError } from './chunk-6DSZ4Z2N.js';
4
- import { decodeErrorResult, isAddress, toHex } from 'viem';
5
- import { createSiweMessage } from 'viem/siwe';
1
+ import { PepuPaymasterError } from './chunk-6DSZ4Z2N.js';
2
+ import { decodeErrorResult } from 'viem';
6
3
 
7
4
  // src/paymaster/abi.ts
8
5
  var pepuSponsoredPaymasterV2Abi = [
@@ -2445,272 +2442,7 @@ function decodePaymasterRevert(data) {
2445
2442
  return null;
2446
2443
  }
2447
2444
  }
2448
- var CLIENT_TOKEN_PREFIX = "ppt_";
2449
- var SERVER_KEY_PREFIX = "ppk_";
2450
- function credentialKind(credential) {
2451
- if (credential.startsWith(CLIENT_TOKEN_PREFIX)) return "client";
2452
- if (credential.startsWith(SERVER_KEY_PREFIX)) return "server";
2453
- return null;
2454
- }
2455
- function trimBase(url) {
2456
- return url.replace(/\/+$/, "");
2457
- }
2458
- function buildErc7677Url(options) {
2459
- const token = options.token.trim();
2460
- if (token === "") {
2461
- throw new PepuConfigError("CONFIG_MISSING_ENV", "buildErc7677Url needs a project client token or server key.");
2462
- }
2463
- if (credentialKind(token) === "server" && globalThis.window !== void 0) {
2464
- throw new PepuConfigError(
2465
- "CONFIG_SERVER_ONLY",
2466
- "Refusing to build an ERC-7677 URL from a server key (ppk_) in a browser: the URL embeds the secret. Use the client token (ppt_)."
2467
- );
2468
- }
2469
- let base;
2470
- try {
2471
- base = new URL(options.baseUrl);
2472
- } catch {
2473
- throw new PepuConfigError("CONFIG_BAD_URL", "buildErc7677Url: baseUrl is not a valid URL.");
2474
- }
2475
- if (base.protocol !== "http:" && base.protocol !== "https:") {
2476
- throw new PepuConfigError("CONFIG_BAD_URL", "buildErc7677Url: baseUrl must be an http(s) URL.");
2477
- }
2478
- const prefix = (options.version ?? 2) === 2 ? "/v2/paymaster/" : "/paymaster/";
2479
- return `${trimBase(options.baseUrl)}${prefix}${encodeURIComponent(token)}`;
2480
- }
2481
- function hostedErc7677Url(token) {
2482
- if (PEPU_HOSTED.paymasterBaseUrl === null) {
2483
- throw new PepuConfigError("CONFIG_MISSING_ENV", "No hosted paymaster base URL is set.");
2484
- }
2485
- return buildErc7677Url({ baseUrl: PEPU_HOSTED.paymasterBaseUrl, token });
2486
- }
2487
- function toQuantity(v) {
2488
- return typeof v === "bigint" ? toHex(v) : v;
2489
- }
2490
- function serializeUserOp(op) {
2491
- const out = {
2492
- sender: op.sender,
2493
- nonce: toQuantity(op.nonce),
2494
- callData: op.callData,
2495
- callGasLimit: toQuantity(op.callGasLimit),
2496
- verificationGasLimit: toQuantity(op.verificationGasLimit),
2497
- preVerificationGas: toQuantity(op.preVerificationGas),
2498
- maxFeePerGas: toQuantity(op.maxFeePerGas),
2499
- maxPriorityFeePerGas: toQuantity(op.maxPriorityFeePerGas)
2500
- };
2501
- if (op.factory !== void 0) out["factory"] = op.factory;
2502
- if (op.factoryData !== void 0) out["factoryData"] = op.factoryData;
2503
- return out;
2504
- }
2505
- function assertApproved(result) {
2506
- if (result.status === "approved") return result;
2507
- throw paymasterReasonToError(result.reason, result.message, result.detail ? { detail: result.detail } : void 0);
2508
- }
2509
- function retryAfter(res) {
2510
- const raw = res.headers.get("retry-after");
2511
- const n = raw === null ? NaN : Number(raw);
2512
- return Number.isFinite(n) ? n : void 0;
2513
- }
2514
- function isRecord(v) {
2515
- return typeof v === "object" && v !== null && !Array.isArray(v);
2516
- }
2517
- function missingBaseUrl() {
2518
- return new PepuConfigError(
2519
- "CONFIG_MISSING_ENV",
2520
- "No paymaster URL configured. Set PEPU_PAYMASTER_URL (or NEXT_PUBLIC_PEPU_PAYMASTER_URL), or pass baseUrl to createPaymasterApi."
2521
- );
2522
- }
2523
- function createPaymasterApi(options = {}) {
2524
- const resolved = options.baseUrl ?? resolvePepuEndpoints(options.env ? { env: options.env } : {}).paymasterBaseUrl;
2525
- if (resolved === null || resolved === void 0 || resolved.trim() === "") throw missingBaseUrl();
2526
- try {
2527
- const u = new URL(resolved);
2528
- if (u.protocol !== "http:" && u.protocol !== "https:") throw new Error("protocol");
2529
- } catch {
2530
- throw new PepuConfigError("CONFIG_BAD_URL", "The paymaster baseUrl is not a valid http(s) URL.");
2531
- }
2532
- const baseUrl = trimBase(resolved.trim());
2533
- const doFetch = options.fetch ?? ((...args) => fetch(...args));
2534
- const timeoutMs = options.timeoutMs ?? 15e3;
2535
- let sessionToken = options.sessionToken ?? null;
2536
- async function send(url, init) {
2537
- try {
2538
- return await doFetch(url, { ...init, signal: AbortSignal.timeout(timeoutMs) });
2539
- } catch (e) {
2540
- const timedOut = e instanceof Error && (e.name === "TimeoutError" || e.name === "AbortError");
2541
- throw new PepuPaymasterError(
2542
- "BUNDLER_UNREACHABLE",
2543
- timedOut ? "The paymaster did not answer in time." : "Could not reach the paymaster service.",
2544
- { details: { path: new URL(url).pathname.replace(/\/(ppt_|ppk_)[^/]*/, "/<credential>") } }
2545
- );
2546
- }
2547
- }
2548
- async function readJson(res) {
2549
- const text = await res.text().catch(() => "");
2550
- if (text === "") return void 0;
2551
- try {
2552
- return JSON.parse(text);
2553
- } catch {
2554
- return void 0;
2555
- }
2556
- }
2557
- function apiError(res, body, quiet) {
2558
- const rec = isRecord(body) ? body : {};
2559
- const errorCode = typeof rec["error"] === "string" ? rec["error"] : void 0;
2560
- const reason = typeof rec["reason"] === "string" ? rec["reason"] : void 0;
2561
- const serverMessage = typeof rec["message"] === "string" && !quiet ? rec["message"] : void 0;
2562
- const details = { status: res.status, error: errorCode, reason, retryAfterSeconds: retryAfter(res) };
2563
- const tagged = reason ?? errorCode;
2564
- let code;
2565
- if (res.status === 401 && errorCode === "unauthenticated") code = "PAYMASTER_SESSION_REQUIRED";
2566
- else if (tagged !== void 0 && mapPaymasterReason(tagged) !== "PAYMASTER_DENIED") code = mapPaymasterReason(tagged);
2567
- else if (res.status === 401 && errorCode !== "login_failed") code = "PAYMASTER_SESSION_REQUIRED";
2568
- else if (res.status === 401) code = "PAYMASTER_DENIED";
2569
- else if (res.status === 429) code = "PAYMASTER_RATE_LIMITED";
2570
- else if (res.status === 403) code = "PAYMASTER_DENIED";
2571
- else code = "PAYMASTER_API_ERROR";
2572
- const label = `Paymaster API ${res.status}${errorCode ? ` ${errorCode}` : ""}${reason && reason !== errorCode ? ` (${reason})` : ""}`;
2573
- return new PepuPaymasterError(code, serverMessage ? `${label}: ${serverMessage}` : `${label}.`, {
2574
- details,
2575
- ...res.status === 429 || res.status === 503 ? { retryable: true } : {}
2576
- });
2577
- }
2578
- async function request(method, path, o = {}) {
2579
- const headers = { accept: "application/json" };
2580
- if (o.body !== void 0) headers["content-type"] = "application/json";
2581
- if (o.session) {
2582
- if (!sessionToken) {
2583
- throw new PepuPaymasterError("PAYMASTER_SESSION_REQUIRED", "This call needs a SIWE session. Call loginWithWallet() first.");
2584
- }
2585
- headers["authorization"] = `Bearer ${sessionToken}`;
2586
- }
2587
- let url = `${baseUrl}${path}`;
2588
- if (o.query) {
2589
- const qs = new URLSearchParams();
2590
- for (const [k, v] of Object.entries(o.query)) if (v !== void 0) qs.set(k, String(v));
2591
- const s = qs.toString();
2592
- if (s) url += `?${s}`;
2593
- }
2594
- const res = await send(url, { method, headers, ...o.body !== void 0 ? { body: JSON.stringify(o.body) } : {} });
2595
- const body = await readJson(res);
2596
- if (!res.ok) throw apiError(res, body, o.quietErrors === true);
2597
- return body;
2598
- }
2599
- async function sponsor(path, userOp, auth) {
2600
- if (!auth.apiKey) {
2601
- throw new PepuConfigError("CONFIG_MISSING_ENV", "sponsor needs auth.apiKey (the project server key or client token).");
2602
- }
2603
- const headers = {
2604
- accept: "application/json",
2605
- "content-type": "application/json",
2606
- "x-api-key": auth.apiKey
2607
- };
2608
- if (auth.privyAccessToken) headers["authorization"] = `Bearer ${auth.privyAccessToken}`;
2609
- if (auth.origin) headers["origin"] = auth.origin;
2610
- const res = await send(`${baseUrl}${path}`, {
2611
- method: "POST",
2612
- headers,
2613
- body: JSON.stringify({ userOp: serializeUserOp(userOp) })
2614
- });
2615
- const body = await readJson(res);
2616
- if (isRecord(body) && (body["status"] === "approved" || body["status"] === "denied")) {
2617
- return body;
2618
- }
2619
- throw apiError(res, body, false);
2620
- }
2621
- const projectPath = (id, sub = "") => {
2622
- if (!/^0x[0-9a-fA-F]{64}$/.test(id)) {
2623
- throw new PepuPaymasterError("PAYMASTER_DENIED", "projectId must be a 0x-prefixed 32-byte hex string.");
2624
- }
2625
- return `/v2/projects/${id}${sub}`;
2626
- };
2627
- const v1 = {
2628
- sponsor: async (userOp, auth) => {
2629
- if (!auth.privyAccessToken) {
2630
- throw new PepuPaymasterError(
2631
- "PAYMASTER_IDENTITY_REQUIRED",
2632
- "The v1 /sponsor endpoint requires the user's Privy access token (auth.privyAccessToken)."
2633
- );
2634
- }
2635
- return sponsor("/sponsor", userOp, auth);
2636
- },
2637
- health: async () => {
2638
- const res = await send(`${baseUrl}/health`, { method: "GET" });
2639
- const body = await readJson(res);
2640
- if (!res.ok) throw apiError(res, body, false);
2641
- return isRecord(body) ? body : { status: "ok" };
2642
- },
2643
- erc7677Url: (token) => buildErc7677Url({ baseUrl, token, version: 1 })
2644
- };
2645
- const v2 = {
2646
- sponsor: (userOp, auth) => sponsor("/v2/sponsor", userOp, auth),
2647
- erc7677Url: (token) => buildErc7677Url({ baseUrl, token, version: 2 }),
2648
- config: () => request("GET", "/v2/config"),
2649
- contract: () => request("GET", "/v2/contract"),
2650
- freeTier: () => request("GET", "/v2/free-tier"),
2651
- auth: {
2652
- nonce: () => request("GET", "/v2/auth/nonce"),
2653
- login: async (message, signature) => {
2654
- const r = await request("POST", "/v2/auth/login", { body: { message, signature } });
2655
- sessionToken = r.token;
2656
- return r;
2657
- },
2658
- logout: async () => {
2659
- await request("POST", "/v2/auth/logout", { session: true });
2660
- sessionToken = null;
2661
- }
2662
- },
2663
- me: () => request("GET", "/v2/me", { session: true }),
2664
- loginWithWallet: async (sign, o) => {
2665
- if (!isAddress(o.address, { strict: false })) {
2666
- throw new PepuPaymasterError("PAYMASTER_DENIED", "loginWithWallet: address is not a valid address.");
2667
- }
2668
- const { nonce } = await v2.auth.nonce();
2669
- const now = (o.now ?? Date.now)();
2670
- const message = createSiweMessage({
2671
- address: o.address,
2672
- chainId: o.chainId ?? pepuMainnet.id,
2673
- domain: o.domain,
2674
- nonce,
2675
- uri: o.uri ?? `https://${o.domain}`,
2676
- version: "1",
2677
- statement: o.statement ?? "Sign in to manage your PEPU gas sponsorship project. This does not move any funds.",
2678
- issuedAt: new Date(now),
2679
- expirationTime: new Date(now + (o.lifetimeSeconds ?? 300) * 1e3)
2680
- });
2681
- const signature = await sign(message);
2682
- return v2.auth.login(message, signature);
2683
- },
2684
- getSessionToken: () => sessionToken,
2685
- setSessionToken: (t) => {
2686
- sessionToken = t;
2687
- },
2688
- projects: {
2689
- prepare: (body) => request("POST", "/v2/projects/prepare", { session: true, body }),
2690
- register: (body) => request("POST", "/v2/projects", { session: true, body }),
2691
- list: () => request("GET", "/v2/projects", { session: true }),
2692
- get: async (id) => request("GET", projectPath(id), { session: true }),
2693
- rotateClientToken: async (id) => request("POST", projectPath(id, "/token/rotate"), { session: true }),
2694
- rotateServerKey: async (id) => request("POST", projectPath(id, "/server-key/rotate"), { session: true }),
2695
- updateSettings: async (id, body) => request("PATCH", projectPath(id, "/settings"), { session: true, body }),
2696
- usage: async (id, q = {}) => request("GET", projectPath(id, "/usage"), { session: true, query: { ...q } }),
2697
- events: async (id, q = {}) => request("GET", projectPath(id, "/events"), { session: true, query: { ...q } }),
2698
- allowlist: async (id) => request("GET", projectPath(id, "/allowlist"), { session: true })
2699
- },
2700
- request
2701
- };
2702
- return { baseUrl, v1, v2 };
2703
- }
2704
- function serializeAttestation(a) {
2705
- return {
2706
- appId: a.appId,
2707
- newOwner: a.newOwner,
2708
- nonce: a.nonce.toString(),
2709
- deadline: a.deadline.toString(),
2710
- signature: a.signature
2711
- };
2712
- }
2713
2445
 
2714
- export { PAYMASTER_DENIAL_REASONS, PAYMASTER_REASON_CODES, assertApproved, buildErc7677Url, createPaymasterApi, credentialKind, decodePaymasterRevert, hostedErc7677Url, mapPaymasterReason, paymasterReasonToError, pepuSponsoredPaymasterV2Abi, serializeAttestation };
2715
- //# sourceMappingURL=chunk-IY3ALPUJ.js.map
2716
- //# sourceMappingURL=chunk-IY3ALPUJ.js.map
2446
+ export { PAYMASTER_DENIAL_REASONS, PAYMASTER_REASON_CODES, decodePaymasterRevert, mapPaymasterReason, paymasterReasonToError, pepuSponsoredPaymasterV2Abi };
2447
+ //# sourceMappingURL=chunk-GIZNH65Q.js.map
2448
+ //# sourceMappingURL=chunk-GIZNH65Q.js.map