@pafi-dev/issuer 0.5.32 → 0.5.33
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.cjs +209 -7
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +383 -113
- package/dist/index.d.ts +383 -113
- package/dist/index.js +200 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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";
|
|
@@ -2377,6 +2477,99 @@ function serializeEntryToJsonRpc(entry, signature, variant = "sponsored") {
|
|
|
2377
2477
|
);
|
|
2378
2478
|
}
|
|
2379
2479
|
|
|
2480
|
+
// src/userop-store/prepareUserOp.ts
|
|
2481
|
+
import {
|
|
2482
|
+
buildUserOpTypedData,
|
|
2483
|
+
computeUserOpHash
|
|
2484
|
+
} from "@pafi-dev/core";
|
|
2485
|
+
function serializeUserOpTypedData(td) {
|
|
2486
|
+
return {
|
|
2487
|
+
domain: td.domain,
|
|
2488
|
+
types: td.types,
|
|
2489
|
+
primaryType: td.primaryType,
|
|
2490
|
+
message: {
|
|
2491
|
+
sender: td.message.sender,
|
|
2492
|
+
nonce: `0x${td.message.nonce.toString(16)}`,
|
|
2493
|
+
initCode: td.message.initCode,
|
|
2494
|
+
callData: td.message.callData,
|
|
2495
|
+
accountGasLimits: td.message.accountGasLimits,
|
|
2496
|
+
preVerificationGas: `0x${td.message.preVerificationGas.toString(
|
|
2497
|
+
16
|
|
2498
|
+
)}`,
|
|
2499
|
+
gasFees: td.message.gasFees,
|
|
2500
|
+
paymasterAndData: td.message.paymasterAndData
|
|
2501
|
+
}
|
|
2502
|
+
};
|
|
2503
|
+
}
|
|
2504
|
+
function mergePaymasterFields(userOp, paymasterFields) {
|
|
2505
|
+
if (!paymasterFields) return userOp;
|
|
2506
|
+
const merged = {
|
|
2507
|
+
...userOp
|
|
2508
|
+
};
|
|
2509
|
+
for (const [k, v] of Object.entries(paymasterFields)) {
|
|
2510
|
+
if (v !== void 0) merged[k] = v;
|
|
2511
|
+
}
|
|
2512
|
+
return merged;
|
|
2513
|
+
}
|
|
2514
|
+
async function prepareMobileUserOp(params) {
|
|
2515
|
+
const userOp = mergePaymasterFields(
|
|
2516
|
+
params.partialUserOp,
|
|
2517
|
+
params.paymasterFields
|
|
2518
|
+
);
|
|
2519
|
+
const userOpHash = computeUserOpHash(userOp, params.chainId);
|
|
2520
|
+
const typedData = serializeUserOpTypedData(
|
|
2521
|
+
buildUserOpTypedData(userOp, params.chainId)
|
|
2522
|
+
);
|
|
2523
|
+
let fallback;
|
|
2524
|
+
let fallbackEntry;
|
|
2525
|
+
if (params.partialUserOpFallback) {
|
|
2526
|
+
const fallbackUserOp = {
|
|
2527
|
+
...params.partialUserOpFallback,
|
|
2528
|
+
maxFeePerGas: userOp.maxFeePerGas,
|
|
2529
|
+
maxPriorityFeePerGas: userOp.maxPriorityFeePerGas
|
|
2530
|
+
};
|
|
2531
|
+
const fallbackHash = computeUserOpHash(fallbackUserOp, params.chainId);
|
|
2532
|
+
const fallbackTypedData = serializeUserOpTypedData(
|
|
2533
|
+
buildUserOpTypedData(fallbackUserOp, params.chainId)
|
|
2534
|
+
);
|
|
2535
|
+
fallback = {
|
|
2536
|
+
userOp: fallbackUserOp,
|
|
2537
|
+
userOpHash: fallbackHash,
|
|
2538
|
+
typedData: fallbackTypedData
|
|
2539
|
+
};
|
|
2540
|
+
fallbackEntry = {
|
|
2541
|
+
callData: fallbackUserOp.callData,
|
|
2542
|
+
callGasLimit: fallbackUserOp.callGasLimit.toString(),
|
|
2543
|
+
verificationGasLimit: fallbackUserOp.verificationGasLimit.toString(),
|
|
2544
|
+
preVerificationGas: fallbackUserOp.preVerificationGas.toString(),
|
|
2545
|
+
userOpHash: fallbackHash
|
|
2546
|
+
};
|
|
2547
|
+
}
|
|
2548
|
+
const entry = {
|
|
2549
|
+
sender: userOp.sender,
|
|
2550
|
+
nonce: userOp.nonce.toString(),
|
|
2551
|
+
callData: userOp.callData,
|
|
2552
|
+
callGasLimit: userOp.callGasLimit.toString(),
|
|
2553
|
+
verificationGasLimit: userOp.verificationGasLimit.toString(),
|
|
2554
|
+
preVerificationGas: userOp.preVerificationGas.toString(),
|
|
2555
|
+
maxFeePerGas: userOp.maxFeePerGas.toString(),
|
|
2556
|
+
maxPriorityFeePerGas: userOp.maxPriorityFeePerGas.toString(),
|
|
2557
|
+
paymaster: userOp.paymaster,
|
|
2558
|
+
paymasterVerificationGasLimit: userOp.paymasterVerificationGasLimit?.toString(),
|
|
2559
|
+
paymasterPostOpGasLimit: userOp.paymasterPostOpGasLimit?.toString(),
|
|
2560
|
+
paymasterData: userOp.paymasterData,
|
|
2561
|
+
chainId: params.chainId,
|
|
2562
|
+
userOpHash,
|
|
2563
|
+
fallback: fallbackEntry
|
|
2564
|
+
};
|
|
2565
|
+
await params.store.save(params.lockId, entry, params.ttlSeconds);
|
|
2566
|
+
return {
|
|
2567
|
+
sponsored: { userOp, userOpHash, typedData },
|
|
2568
|
+
fallback,
|
|
2569
|
+
entry
|
|
2570
|
+
};
|
|
2571
|
+
}
|
|
2572
|
+
|
|
2380
2573
|
// src/issuer-state/validator.ts
|
|
2381
2574
|
import { getAddress as getAddress9 } from "viem";
|
|
2382
2575
|
import {
|
|
@@ -2564,6 +2757,7 @@ export {
|
|
|
2564
2757
|
IssuerApiHandlers,
|
|
2565
2758
|
IssuerStateError,
|
|
2566
2759
|
IssuerStateValidator,
|
|
2760
|
+
LockNotFoundError,
|
|
2567
2761
|
MemorySessionStore,
|
|
2568
2762
|
NonceManager,
|
|
2569
2763
|
PAFI_ISSUER_SDK_VERSION,
|
|
@@ -2582,6 +2776,11 @@ export {
|
|
|
2582
2776
|
createNativePtQuoter,
|
|
2583
2777
|
createSubgraphNativeUsdtQuoter,
|
|
2584
2778
|
createSubgraphPoolsProvider,
|
|
2585
|
-
|
|
2779
|
+
handleClaimStatus,
|
|
2780
|
+
handleRedeemStatus,
|
|
2781
|
+
mergePaymasterFields,
|
|
2782
|
+
prepareMobileUserOp,
|
|
2783
|
+
serializeEntryToJsonRpc,
|
|
2784
|
+
serializeUserOpTypedData
|
|
2586
2785
|
};
|
|
2587
2786
|
//# sourceMappingURL=index.js.map
|