@pafi-dev/issuer 0.5.32 → 0.5.34

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.
package/dist/index.js CHANGED
@@ -1598,6 +1598,106 @@ var TopUpRedemptionHandler = class {
1598
1598
  }
1599
1599
  };
1600
1600
 
1601
+ // src/api/statusHandlers.ts
1602
+ var LockNotFoundError = class extends Error {
1603
+ code = "LOCK_NOT_FOUND";
1604
+ constructor() {
1605
+ super("Lock not found or does not belong to authenticated user");
1606
+ this.name = "LockNotFoundError";
1607
+ }
1608
+ };
1609
+ async function handleClaimStatus(params) {
1610
+ if (!params.ledger.getMintLock) {
1611
+ throw new Error(
1612
+ "handleClaimStatus: ledger does not implement `getMintLock` \u2014 implement the optional method on `IPointLedger` or write a custom status handler."
1613
+ );
1614
+ }
1615
+ const lock = await params.ledger.getMintLock(
1616
+ params.lockId,
1617
+ params.userAddress
1618
+ );
1619
+ if (!lock || lock.userAddress.toLowerCase() !== params.userAddress.toLowerCase()) {
1620
+ throw new LockNotFoundError();
1621
+ }
1622
+ let status = lock.status;
1623
+ let txHash = lock.txHash ?? null;
1624
+ if (status === "PENDING" && lock.userOpHash && params.pafiBackendClient) {
1625
+ try {
1626
+ const receipt = await params.pafiBackendClient.getUserOpReceipt(
1627
+ lock.userOpHash
1628
+ );
1629
+ if (receipt) {
1630
+ status = receipt.success ? "MINTED" : "FAILED";
1631
+ txHash = receipt.txHash;
1632
+ await params.ledger.updateMintStatus(lock.lockId, status, receipt.txHash).catch((err) => {
1633
+ params.onWarning?.(
1634
+ `handleClaimStatus: ledger updateMintStatus failed for lock ${lock.lockId}: ${err}`
1635
+ );
1636
+ });
1637
+ }
1638
+ } catch (err) {
1639
+ params.onWarning?.(
1640
+ `handleClaimStatus: bundler-receipt fallback failed for lock ${lock.lockId}: ${err}`
1641
+ );
1642
+ }
1643
+ }
1644
+ return {
1645
+ lockId: lock.lockId,
1646
+ status,
1647
+ txHash,
1648
+ amount: lock.amount.toString(),
1649
+ createdAt: new Date(lock.createdAt).toISOString(),
1650
+ expiresAt: new Date(lock.expiresAt).toISOString()
1651
+ };
1652
+ }
1653
+ async function handleRedeemStatus(params) {
1654
+ if (!params.ledger.getPendingCredit) {
1655
+ throw new Error(
1656
+ "handleRedeemStatus: ledger does not implement `getPendingCredit` \u2014 implement the optional method on `IPointLedger` or write a custom status handler."
1657
+ );
1658
+ }
1659
+ const credit = await params.ledger.getPendingCredit(
1660
+ params.lockId,
1661
+ params.userAddress
1662
+ );
1663
+ if (!credit || credit.userAddress.toLowerCase() !== params.userAddress.toLowerCase()) {
1664
+ throw new LockNotFoundError();
1665
+ }
1666
+ let status = credit.status;
1667
+ let txHash = credit.txHash ?? null;
1668
+ if (status === "PENDING" && credit.userOpHash && params.pafiBackendClient) {
1669
+ try {
1670
+ const receipt = await params.pafiBackendClient.getUserOpReceipt(
1671
+ credit.userOpHash
1672
+ );
1673
+ if (receipt && receipt.success) {
1674
+ status = "RESOLVED";
1675
+ txHash = receipt.txHash;
1676
+ if (params.ledger.resolveCreditByBurnTx) {
1677
+ await params.ledger.resolveCreditByBurnTx(credit.lockId, receipt.txHash).catch((err) => {
1678
+ params.onWarning?.(
1679
+ `handleRedeemStatus: resolveCreditByBurnTx failed for lock ${credit.lockId}: ${err}`
1680
+ );
1681
+ });
1682
+ }
1683
+ }
1684
+ } catch (err) {
1685
+ params.onWarning?.(
1686
+ `handleRedeemStatus: bundler-receipt fallback failed for lock ${credit.lockId}: ${err}`
1687
+ );
1688
+ }
1689
+ }
1690
+ return {
1691
+ lockId: credit.lockId,
1692
+ status,
1693
+ txHash,
1694
+ amount: credit.amount.toString(),
1695
+ createdAt: new Date(credit.createdAt).toISOString(),
1696
+ expiresAt: new Date(credit.expiresAt).toISOString(),
1697
+ resolvedAt: credit.resolvedAt ? new Date(credit.resolvedAt).toISOString() : null
1698
+ };
1699
+ }
1700
+
1601
1701
  // src/pools/subgraphPoolsProvider.ts
1602
1702
  import { isAddress } from "viem";
1603
1703
  import { PAFI_SUBGRAPH_URL } from "@pafi-dev/core";
@@ -2215,6 +2315,76 @@ var PafiBackendClient = class {
2215
2315
  }
2216
2316
  };
2217
2317
 
2318
+ // src/pafi-backend/helpers.ts
2319
+ var BundlerNotConfiguredError = class extends Error {
2320
+ code = "BUNDLER_NOT_CONFIGURED";
2321
+ constructor() {
2322
+ super(
2323
+ "PAFI backend client not configured \u2014 set PAFI_BACKEND_URL, PAFI_ISSUER_ID, PAFI_API_KEY to enable mobile submit."
2324
+ );
2325
+ this.name = "BundlerNotConfiguredError";
2326
+ }
2327
+ };
2328
+ var BundlerRejectedError = class extends Error {
2329
+ code = "BUNDLER_REJECTED";
2330
+ cause;
2331
+ constructor(message, cause) {
2332
+ super(message);
2333
+ this.name = "BundlerRejectedError";
2334
+ this.cause = cause;
2335
+ }
2336
+ };
2337
+ async function requestPaymaster(params) {
2338
+ if (!params.client) return void 0;
2339
+ const fn = params.functionName ?? defaultFunctionForScenario(params.scenario);
2340
+ try {
2341
+ return await params.client.requestSponsorship({
2342
+ chainId: params.chainId,
2343
+ scenario: params.scenario,
2344
+ userOp: params.userOp,
2345
+ target: {
2346
+ contract: params.pointTokenAddress,
2347
+ function: fn,
2348
+ pointToken: params.pointTokenAddress
2349
+ }
2350
+ });
2351
+ } catch (err) {
2352
+ const msg = err instanceof Error ? err.message : String(err);
2353
+ params.onWarning?.(`Paymaster sponsorship declined: ${msg}`);
2354
+ return void 0;
2355
+ }
2356
+ }
2357
+ function defaultFunctionForScenario(scenario) {
2358
+ switch (scenario) {
2359
+ case "mint":
2360
+ return "mint";
2361
+ case "burn":
2362
+ return "burn";
2363
+ case "swap":
2364
+ return "swap";
2365
+ case "perp-deposit":
2366
+ return "deposit";
2367
+ default:
2368
+ return scenario;
2369
+ }
2370
+ }
2371
+ async function relayUserOp(params) {
2372
+ if (!params.client) {
2373
+ throw new BundlerNotConfiguredError();
2374
+ }
2375
+ try {
2376
+ const result = await params.client.relayUserOperation({
2377
+ userOp: params.userOp,
2378
+ entryPoint: params.entryPoint,
2379
+ eip7702Auth: params.eip7702Auth
2380
+ });
2381
+ return { userOpHash: result.userOpHash };
2382
+ } catch (err) {
2383
+ const msg = err instanceof Error ? err.message : String(err);
2384
+ throw new BundlerRejectedError(msg, err);
2385
+ }
2386
+ }
2387
+
2218
2388
  // src/config.ts
2219
2389
  import { getAddress as getAddress8 } from "viem";
2220
2390
  import { getContractAddresses as getContractAddresses2 } from "@pafi-dev/core";
@@ -2377,6 +2547,99 @@ function serializeEntryToJsonRpc(entry, signature, variant = "sponsored") {
2377
2547
  );
2378
2548
  }
2379
2549
 
2550
+ // src/userop-store/prepareUserOp.ts
2551
+ import {
2552
+ buildUserOpTypedData,
2553
+ computeUserOpHash
2554
+ } from "@pafi-dev/core";
2555
+ function serializeUserOpTypedData(td) {
2556
+ return {
2557
+ domain: td.domain,
2558
+ types: td.types,
2559
+ primaryType: td.primaryType,
2560
+ message: {
2561
+ sender: td.message.sender,
2562
+ nonce: `0x${td.message.nonce.toString(16)}`,
2563
+ initCode: td.message.initCode,
2564
+ callData: td.message.callData,
2565
+ accountGasLimits: td.message.accountGasLimits,
2566
+ preVerificationGas: `0x${td.message.preVerificationGas.toString(
2567
+ 16
2568
+ )}`,
2569
+ gasFees: td.message.gasFees,
2570
+ paymasterAndData: td.message.paymasterAndData
2571
+ }
2572
+ };
2573
+ }
2574
+ function mergePaymasterFields(userOp, paymasterFields) {
2575
+ if (!paymasterFields) return userOp;
2576
+ const merged = {
2577
+ ...userOp
2578
+ };
2579
+ for (const [k, v] of Object.entries(paymasterFields)) {
2580
+ if (v !== void 0) merged[k] = v;
2581
+ }
2582
+ return merged;
2583
+ }
2584
+ async function prepareMobileUserOp(params) {
2585
+ const userOp = mergePaymasterFields(
2586
+ params.partialUserOp,
2587
+ params.paymasterFields
2588
+ );
2589
+ const userOpHash = computeUserOpHash(userOp, params.chainId);
2590
+ const typedData = serializeUserOpTypedData(
2591
+ buildUserOpTypedData(userOp, params.chainId)
2592
+ );
2593
+ let fallback;
2594
+ let fallbackEntry;
2595
+ if (params.partialUserOpFallback) {
2596
+ const fallbackUserOp = {
2597
+ ...params.partialUserOpFallback,
2598
+ maxFeePerGas: userOp.maxFeePerGas,
2599
+ maxPriorityFeePerGas: userOp.maxPriorityFeePerGas
2600
+ };
2601
+ const fallbackHash = computeUserOpHash(fallbackUserOp, params.chainId);
2602
+ const fallbackTypedData = serializeUserOpTypedData(
2603
+ buildUserOpTypedData(fallbackUserOp, params.chainId)
2604
+ );
2605
+ fallback = {
2606
+ userOp: fallbackUserOp,
2607
+ userOpHash: fallbackHash,
2608
+ typedData: fallbackTypedData
2609
+ };
2610
+ fallbackEntry = {
2611
+ callData: fallbackUserOp.callData,
2612
+ callGasLimit: fallbackUserOp.callGasLimit.toString(),
2613
+ verificationGasLimit: fallbackUserOp.verificationGasLimit.toString(),
2614
+ preVerificationGas: fallbackUserOp.preVerificationGas.toString(),
2615
+ userOpHash: fallbackHash
2616
+ };
2617
+ }
2618
+ const entry = {
2619
+ sender: userOp.sender,
2620
+ nonce: userOp.nonce.toString(),
2621
+ callData: userOp.callData,
2622
+ callGasLimit: userOp.callGasLimit.toString(),
2623
+ verificationGasLimit: userOp.verificationGasLimit.toString(),
2624
+ preVerificationGas: userOp.preVerificationGas.toString(),
2625
+ maxFeePerGas: userOp.maxFeePerGas.toString(),
2626
+ maxPriorityFeePerGas: userOp.maxPriorityFeePerGas.toString(),
2627
+ paymaster: userOp.paymaster,
2628
+ paymasterVerificationGasLimit: userOp.paymasterVerificationGasLimit?.toString(),
2629
+ paymasterPostOpGasLimit: userOp.paymasterPostOpGasLimit?.toString(),
2630
+ paymasterData: userOp.paymasterData,
2631
+ chainId: params.chainId,
2632
+ userOpHash,
2633
+ fallback: fallbackEntry
2634
+ };
2635
+ await params.store.save(params.lockId, entry, params.ttlSeconds);
2636
+ return {
2637
+ sponsored: { userOp, userOpHash, typedData },
2638
+ fallback,
2639
+ entry
2640
+ };
2641
+ }
2642
+
2380
2643
  // src/issuer-state/validator.ts
2381
2644
  import { getAddress as getAddress9 } from "viem";
2382
2645
  import {
@@ -2557,6 +2820,8 @@ export {
2557
2820
  AuthError,
2558
2821
  AuthService,
2559
2822
  BalanceAggregator,
2823
+ BundlerNotConfiguredError,
2824
+ BundlerRejectedError,
2560
2825
  BurnIndexer,
2561
2826
  DefaultPolicyEngine,
2562
2827
  FeeManager,
@@ -2564,6 +2829,7 @@ export {
2564
2829
  IssuerApiHandlers,
2565
2830
  IssuerStateError,
2566
2831
  IssuerStateValidator,
2832
+ LockNotFoundError,
2567
2833
  MemorySessionStore,
2568
2834
  NonceManager,
2569
2835
  PAFI_ISSUER_SDK_VERSION,
@@ -2582,6 +2848,13 @@ export {
2582
2848
  createNativePtQuoter,
2583
2849
  createSubgraphNativeUsdtQuoter,
2584
2850
  createSubgraphPoolsProvider,
2585
- serializeEntryToJsonRpc
2851
+ handleClaimStatus,
2852
+ handleRedeemStatus,
2853
+ mergePaymasterFields,
2854
+ prepareMobileUserOp,
2855
+ relayUserOp,
2856
+ requestPaymaster,
2857
+ serializeEntryToJsonRpc,
2858
+ serializeUserOpTypedData
2586
2859
  };
2587
2860
  //# sourceMappingURL=index.js.map