@pafi-dev/issuer 0.3.0-beta.8 → 0.3.0-beta.9
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 +0 -212
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -193
- package/dist/index.d.ts +3 -193
- package/dist/index.js +0 -211
- package/dist/index.js.map +1 -1
- package/package.json +11 -11
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Address, Hex, PublicClient, Chain, WalletClient } from 'viem';
|
|
2
|
-
import { PointTokenDomainConfig, MintRequest, EIP712Signature, PartialUserOperation, BurnRequest, ReceiverConsent, PathKey, PoolKey
|
|
2
|
+
import { PointTokenDomainConfig, MintRequest, EIP712Signature, PartialUserOperation, BurnRequest, ReceiverConsent, PathKey, PoolKey } from '@pafi-dev/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Lifecycle of a minting request as tracked by the issuer's point ledger.
|
|
@@ -1438,223 +1438,33 @@ declare class BalanceAggregator {
|
|
|
1438
1438
|
}
|
|
1439
1439
|
|
|
1440
1440
|
interface RetryConfig {
|
|
1441
|
-
/**
|
|
1442
|
-
* Max total attempts including the first try. Default: 1 (no retry).
|
|
1443
|
-
* Set to 3 to get 2 retries after the initial call.
|
|
1444
|
-
*
|
|
1445
|
-
* Only applies when the server error body carries `safeToRetry: true`
|
|
1446
|
-
* or the failure is a transient network/timeout error.
|
|
1447
|
-
*/
|
|
1448
1441
|
maxAttempts?: number;
|
|
1449
|
-
/**
|
|
1450
|
-
* Initial backoff delay in ms. Default: 500. Each subsequent retry
|
|
1451
|
-
* doubles this (exponential backoff) and adds ±20% jitter.
|
|
1452
|
-
*/
|
|
1453
1442
|
initialDelayMs?: number;
|
|
1454
|
-
/**
|
|
1455
|
-
* Hard ceiling for a single backoff (ms). Default: 10_000.
|
|
1456
|
-
*/
|
|
1457
1443
|
maxDelayMs?: number;
|
|
1458
|
-
/**
|
|
1459
|
-
* Upper bound on `retryAfter` from the server. If the server asks us
|
|
1460
|
-
* to wait longer than this (e.g. rate limit until UTC midnight), the
|
|
1461
|
-
* client gives up rather than blocking. Default: 30_000.
|
|
1462
|
-
*/
|
|
1463
1444
|
maxRetryAfterMs?: number;
|
|
1464
1445
|
}
|
|
1465
1446
|
interface PafiBackendConfig {
|
|
1466
|
-
/**
|
|
1467
|
-
* PAFI Backend API base URL. Example:
|
|
1468
|
-
* https://api.pacificfinance.org
|
|
1469
|
-
* https://staging-api.pacificfinance.org
|
|
1470
|
-
*/
|
|
1471
1447
|
url: string;
|
|
1472
|
-
/** PAFI-assigned issuer ID (e.g., "gg56"). Sent in X-Issuer-Id header. */
|
|
1473
1448
|
issuerId: string;
|
|
1474
|
-
/** Per-issuer API key (or JWT) for the Authorization header. */
|
|
1475
1449
|
apiKey: string;
|
|
1476
|
-
/** Optional fetch override for tests. */
|
|
1477
1450
|
fetchImpl?: typeof fetch;
|
|
1478
|
-
/**
|
|
1479
|
-
* Timeout (ms) for each request. Default: 10_000. PAFI Backend should
|
|
1480
|
-
* respond in <1s for the happy path; this is just the sanity bound.
|
|
1481
|
-
*/
|
|
1482
1451
|
timeoutMs?: number;
|
|
1483
|
-
/**
|
|
1484
|
-
* Retry policy for transient failures (5xx, 429, timeouts, network).
|
|
1485
|
-
* Omit or pass `{ maxAttempts: 1 }` to disable retry entirely.
|
|
1486
|
-
*/
|
|
1487
1452
|
retry?: RetryConfig;
|
|
1488
1453
|
}
|
|
1489
|
-
|
|
1490
|
-
* @deprecated Coinbase paymaster path — replaced by SponsorAuth in beta.8.
|
|
1491
|
-
* Kept for back-compat with consumers still on Coinbase. Will be removed
|
|
1492
|
-
* in 1.0.
|
|
1493
|
-
*/
|
|
1494
|
-
interface SponsorshipRequest {
|
|
1495
|
-
chainId: number;
|
|
1496
|
-
scenario: SponsorshipScenario;
|
|
1497
|
-
userOp: PartialUserOperation;
|
|
1498
|
-
target: {
|
|
1499
|
-
contract: Address;
|
|
1500
|
-
function: string;
|
|
1501
|
-
pointToken?: Address;
|
|
1502
|
-
};
|
|
1503
|
-
}
|
|
1504
|
-
/** @deprecated See `SponsorshipRequest`. Use `SponsorAuthResponse` in beta.8+. */
|
|
1505
|
-
interface SponsorshipResponse {
|
|
1506
|
-
paymaster: Address;
|
|
1507
|
-
paymasterData: Hex;
|
|
1508
|
-
paymasterVerificationGasLimit: bigint;
|
|
1509
|
-
paymasterPostOpGasLimit: bigint;
|
|
1510
|
-
expiresAt: number;
|
|
1511
|
-
}
|
|
1512
|
-
|
|
1513
|
-
/**
|
|
1514
|
-
* Request body for `POST /sponsor-auth` against PAFI sponsor-relayer.
|
|
1515
|
-
* See `pafi-backend/docs/SPONSOR_AUTH_DESIGN.md` for the full spec.
|
|
1516
|
-
*
|
|
1517
|
-
* The endpoint:
|
|
1518
|
-
* 1. Authenticates user (JWT) + issuer (API key)
|
|
1519
|
-
* 2. Per-(user, scenario) rate-limits
|
|
1520
|
-
* 3. Per-issuer daily budget check
|
|
1521
|
-
* 4. Scenario-specific intent validation (mint cap, KYC, etc.)
|
|
1522
|
-
* 5. Allocates a unique nonce
|
|
1523
|
-
* 6. Signs the SponsorAuth payload via KMS-backed PAFI key
|
|
1524
|
-
* 7. Returns `{ sponsorAuth, payload }` for FE to forward to Privy
|
|
1525
|
-
*/
|
|
1526
|
-
interface SponsorAuthRequest {
|
|
1527
|
-
chainId: number;
|
|
1528
|
-
scenario: SponsorAuthScenario;
|
|
1529
|
-
/** The exact UserOp the FE intends to submit. callDataHash binds to this. */
|
|
1530
|
-
userOp: PartialUserOperation;
|
|
1531
|
-
/** Issuer ID this sponsorship is billed against (e.g. "gg56"). */
|
|
1532
|
-
issuerId: string;
|
|
1533
|
-
/**
|
|
1534
|
-
* Scenario-specific context for intent validation. The relayer reads
|
|
1535
|
-
* these to apply scenario rules — e.g. preValidateMint reads
|
|
1536
|
-
* pointToken + amount to check the issuer cap.
|
|
1537
|
-
*/
|
|
1538
|
-
context?: {
|
|
1539
|
-
pointToken?: Address;
|
|
1540
|
-
/** Decimal string representation (handles bigint over JSON). */
|
|
1541
|
-
amount?: string;
|
|
1542
|
-
brokerHash?: Hex;
|
|
1543
|
-
};
|
|
1544
|
-
}
|
|
1545
|
-
/**
|
|
1546
|
-
* Response from `POST /sponsor-auth`.
|
|
1547
|
-
*
|
|
1548
|
-
* `payload` is returned alongside `sponsorAuth` so the FE doesn't have
|
|
1549
|
-
* to reconstruct the message — just forwards both to Privy. Privy
|
|
1550
|
-
* verifier checks `signature` recovers to PAFI's registered pubkey
|
|
1551
|
-
* over `payload`.
|
|
1552
|
-
*/
|
|
1553
|
-
interface SponsorAuthResponse {
|
|
1554
|
-
/** EIP-712 signature, hex-encoded 65 bytes. */
|
|
1555
|
-
sponsorAuth: Hex;
|
|
1556
|
-
/** The payload that was signed. Pass to Privy alongside the signature. */
|
|
1557
|
-
payload: SponsorAuthPayload;
|
|
1558
|
-
}
|
|
1559
|
-
/**
|
|
1560
|
-
* Machine-readable error codes returned by PAFI sponsor-relayer.
|
|
1561
|
-
*
|
|
1562
|
-
* Source of truth: `apps/sponsor-relayer/src/**` (renamed from
|
|
1563
|
-
* paymaster-proxy in beta.8). Keep in sync.
|
|
1564
|
-
*/
|
|
1565
|
-
type PafiBackendErrorCode = "MISSING_ISSUER_ID" | "MISSING_API_KEY" | "ISSUER_UNAUTHORIZED" | "USER_UNAUTHORIZED" | "INTENT_REJECTED" | "MINT_CAP_EXCEEDED" | "ISSUER_INACTIVE" | "BROKER_NOT_WHITELISTED" | "RATE_LIMIT_EXCEEDED" | "RATE_LIMIT_EXCEEDED_DAILY" | "RATE_LIMIT_EXCEEDED_PER_USER" | "ISSUER_BUDGET_EXCEEDED" | "RATE_LIMITER_UNAVAILABLE" | "KMS_UNAVAILABLE" | "SPONSOR_AUTH_SIGNING_FAILED" | "PAYMASTER_REJECTED" | "PAYMASTER_UNAVAILABLE" | "PAYMASTER_TIMEOUT" | "CALLDATA_INVALID" | "CALLDATA_EMPTY_BATCH" | "TARGET_NOT_ALLOWLISTED" | "FUNCTION_NOT_ALLOWED" | "SCENARIO_MISMATCH" | "SCENARIO_DISABLED" | "BAD_REQUEST" | "INTERNAL_ERROR" | "TIMEOUT" | "NETWORK_ERROR";
|
|
1454
|
+
type PafiBackendErrorCode = "MISSING_ISSUER_ID" | "MISSING_API_KEY" | "ISSUER_UNAUTHORIZED" | "USER_UNAUTHORIZED" | "INTENT_REJECTED" | "MINT_CAP_EXCEEDED" | "ISSUER_INACTIVE" | "BROKER_NOT_WHITELISTED" | "RATE_LIMIT_EXCEEDED" | "RATE_LIMIT_EXCEEDED_DAILY" | "RATE_LIMIT_EXCEEDED_PER_USER" | "ISSUER_BUDGET_EXCEEDED" | "RATE_LIMITER_UNAVAILABLE" | "BAD_REQUEST" | "INTERNAL_ERROR" | "TIMEOUT" | "NETWORK_ERROR";
|
|
1566
1455
|
declare class PafiBackendError extends Error {
|
|
1567
1456
|
code: PafiBackendErrorCode;
|
|
1568
1457
|
httpStatus: number;
|
|
1569
1458
|
details?: unknown | undefined;
|
|
1570
|
-
/**
|
|
1571
|
-
* Seconds to wait before retry. Populated from the server body
|
|
1572
|
-
* (e.g. rate limit returns the number of seconds until UTC midnight).
|
|
1573
|
-
*/
|
|
1574
1459
|
readonly retryAfter?: number;
|
|
1575
|
-
/**
|
|
1576
|
-
* `safeToRetry` as reported by the server body. Prefer this over the
|
|
1577
|
-
* code-based heuristic when available — the server knows more about
|
|
1578
|
-
* whether the same request will succeed on retry.
|
|
1579
|
-
*/
|
|
1580
1460
|
private readonly serverSafeToRetry?;
|
|
1581
1461
|
constructor(code: PafiBackendErrorCode, message: string, httpStatus: number, details?: unknown | undefined, opts?: {
|
|
1582
1462
|
retryAfter?: number;
|
|
1583
1463
|
safeToRetry?: boolean;
|
|
1584
1464
|
});
|
|
1585
|
-
/**
|
|
1586
|
-
* Whether the caller can safely retry the same request.
|
|
1587
|
-
*
|
|
1588
|
-
* If the server provided `safeToRetry` in the body, trust that.
|
|
1589
|
-
* Otherwise fall back to a code-based heuristic.
|
|
1590
|
-
*/
|
|
1591
1465
|
get safeToRetry(): boolean;
|
|
1592
1466
|
}
|
|
1593
1467
|
|
|
1594
|
-
/**
|
|
1595
|
-
* HTTP client for the PAFI Backend paymaster proxy service. See
|
|
1596
|
-
* [SPONSORED_PATH_FLOW.md] for the full flow + API contract.
|
|
1597
|
-
*
|
|
1598
|
-
* This client sits between `@pafi/issuer`'s RelayService and the
|
|
1599
|
-
* PAFI Backend. It does NOT talk to Coinbase Paymaster directly —
|
|
1600
|
-
* PAFI Backend holds that integration.
|
|
1601
|
-
*/
|
|
1602
|
-
declare class PafiBackendClient {
|
|
1603
|
-
private readonly url;
|
|
1604
|
-
private readonly issuerId;
|
|
1605
|
-
private readonly apiKey;
|
|
1606
|
-
private readonly fetchImpl;
|
|
1607
|
-
private readonly timeoutMs;
|
|
1608
|
-
private readonly retry;
|
|
1609
|
-
constructor(config: PafiBackendConfig);
|
|
1610
|
-
/**
|
|
1611
|
-
* Request a SponsorAuth signature from PAFI sponsor-relayer (beta.8+).
|
|
1612
|
-
*
|
|
1613
|
-
* The relayer:
|
|
1614
|
-
* 1. Authenticates user (JWT) + issuer (API key)
|
|
1615
|
-
* 2. Per-(user, scenario) rate limit + per-issuer daily budget
|
|
1616
|
-
* 3. Scenario-specific intent validation (mint cap, KYC, etc.)
|
|
1617
|
-
* 4. Allocates nonce + signs SponsorAuth payload via KMS PAFI key
|
|
1618
|
-
* 5. Returns `{ sponsorAuth, payload }` for the FE to forward to
|
|
1619
|
-
* Privy's `signUserOperation({ sponsorAuth, payload })`.
|
|
1620
|
-
*
|
|
1621
|
-
* Retries on transient failures (5xx, timeouts, KMS unavailable,
|
|
1622
|
-
* rate-limit-with-retryAfter). 4xx that are not `safeToRetry` fail fast.
|
|
1623
|
-
*
|
|
1624
|
-
* See `pafi-backend/docs/SPONSOR_AUTH_DESIGN.md` for the full spec.
|
|
1625
|
-
*
|
|
1626
|
-
* @throws PafiBackendError on final failure after exhausting retries
|
|
1627
|
-
*/
|
|
1628
|
-
requestSponsorAuth(req: SponsorAuthRequest): Promise<SponsorAuthResponse>;
|
|
1629
|
-
/**
|
|
1630
|
-
* @deprecated Coinbase paymaster path — replaced by `requestSponsorAuth`
|
|
1631
|
-
* in beta.8. Will be removed in 1.0. Migrate by:
|
|
1632
|
-
* 1. Switch to `requestSponsorAuth` returning `{ sponsorAuth, payload }`
|
|
1633
|
-
* 2. Pass both to Privy `signUserOperation` instead of merging
|
|
1634
|
-
* paymasterData into the UserOp callData
|
|
1635
|
-
*/
|
|
1636
|
-
requestSponsorship(req: SponsorshipRequest): Promise<SponsorshipResponse>;
|
|
1637
|
-
private postWithRetry;
|
|
1638
|
-
/**
|
|
1639
|
-
* Pick the delay before the next retry.
|
|
1640
|
-
* - If the server sent `retryAfter` (seconds), honor it (capped by
|
|
1641
|
-
* `maxRetryAfterMs`) — returns null if the server wait exceeds the
|
|
1642
|
-
* cap, signalling the caller should give up.
|
|
1643
|
-
* - Otherwise: exponential backoff with ±20% jitter, capped at
|
|
1644
|
-
* `maxDelayMs`.
|
|
1645
|
-
*/
|
|
1646
|
-
private computeBackoff;
|
|
1647
|
-
private sleep;
|
|
1648
|
-
private post;
|
|
1649
|
-
/** JSON replacer that stringifies bigints. Paired with bigintReviver. */
|
|
1650
|
-
private bigintReplacer;
|
|
1651
|
-
/**
|
|
1652
|
-
* JSON reviver that coerces specific numeric-string fields back to
|
|
1653
|
-
* bigint. The server must send these fields as decimal strings.
|
|
1654
|
-
*/
|
|
1655
|
-
private bigintReviver;
|
|
1656
|
-
}
|
|
1657
|
-
|
|
1658
1468
|
/**
|
|
1659
1469
|
* Top-level configuration for `createIssuerService`.
|
|
1660
1470
|
*
|
|
@@ -1751,4 +1561,4 @@ declare function createIssuerService(config: IssuerServiceConfig): IssuerService
|
|
|
1751
1561
|
/** SDK package version — bumped on every release */
|
|
1752
1562
|
declare const PAFI_ISSUER_SDK_VERSION = "0.1.0";
|
|
1753
1563
|
|
|
1754
|
-
export { type ApiBuildConsentTypedDataRequest, type ApiBuildConsentTypedDataResponse, type ApiClaimAndSwapRequest, type ApiClaimAndSwapResponse, type ApiConfigResponse, type ApiGasFeeResponse, type ApiLoginRequest, type ApiLoginResponse, type ApiNonceResponse, type ApiPoolsRequest, type ApiPoolsResponse, type ApiUserRequest, type ApiUserResponse, type AuthContext, AuthError, type AuthErrorCode, AuthService, type AuthServiceConfig, BalanceAggregator, type BalanceAggregatorConfig, type BurnEvent, BurnIndexer, type BurnIndexerConfig, type CombinedBalance, DefaultPolicyEngine, type DefaultPolicyEngineOptions, FeeManager, type FeeManagerConfig, type IIndexerCursorStore, type IIssuerSigner, type IPointLedger, type IPolicyEngine, type ISessionStore, InMemoryCursorStore, IssuerApiHandlers, type IssuerApiHandlersConfig, type IssuerService, type IssuerServiceConfig, type LockedMintRequest, type LoginResult, MemoryPointLedger, MemorySessionStore, type MemorySessionStoreOptions, type MintEvent, type MintingStatus, NonceManager, PAFI_ISSUER_SDK_VERSION, PTRedeemError, PTRedeemHandler, type PTRedeemHandlerConfig, type PTRedeemRequest, type PTRedeemResponse,
|
|
1564
|
+
export { type ApiBuildConsentTypedDataRequest, type ApiBuildConsentTypedDataResponse, type ApiClaimAndSwapRequest, type ApiClaimAndSwapResponse, type ApiConfigResponse, type ApiGasFeeResponse, type ApiLoginRequest, type ApiLoginResponse, type ApiNonceResponse, type ApiPoolsRequest, type ApiPoolsResponse, type ApiUserRequest, type ApiUserResponse, type AuthContext, AuthError, type AuthErrorCode, AuthService, type AuthServiceConfig, BalanceAggregator, type BalanceAggregatorConfig, type BurnEvent, BurnIndexer, type BurnIndexerConfig, type CombinedBalance, DefaultPolicyEngine, type DefaultPolicyEngineOptions, FeeManager, type FeeManagerConfig, type IIndexerCursorStore, type IIssuerSigner, type IPointLedger, type IPolicyEngine, type ISessionStore, InMemoryCursorStore, IssuerApiHandlers, type IssuerApiHandlersConfig, type IssuerService, type IssuerServiceConfig, type LockedMintRequest, type LoginResult, MemoryPointLedger, MemorySessionStore, type MemorySessionStoreOptions, type MintEvent, type MintingStatus, NonceManager, PAFI_ISSUER_SDK_VERSION, PTRedeemError, PTRedeemHandler, type PTRedeemHandlerConfig, type PTRedeemRequest, type PTRedeemResponse, type PafiBackendConfig, PafiBackendError, type PafiBackendErrorCode, PointIndexer, type PointIndexerConfig, type PolicyDecision, type PolicyEvalRequest, type PoolsProvider, type PrepareBurnDirectParams, type PrepareBurnParams, type PrepareBurnWithSigParams, type PrepareMintParams, PrivateKeySigner, type PrivateKeySignerOptions, RelayError, type RelayErrorCode, RelayService, type RetryConfig, type Session, type SubgraphNativeUsdtQuoterConfig, type SubgraphPoolsProviderConfig, TopUpRedemptionError, TopUpRedemptionHandler, type TopUpRedemptionHandlerConfig, type TopUpRedemptionRequest, type TopUpRedemptionResponse, authenticateRequest, createIssuerService, createSubgraphNativeUsdtQuoter, createSubgraphPoolsProvider };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Address, Hex, PublicClient, Chain, WalletClient } from 'viem';
|
|
2
|
-
import { PointTokenDomainConfig, MintRequest, EIP712Signature, PartialUserOperation, BurnRequest, ReceiverConsent, PathKey, PoolKey
|
|
2
|
+
import { PointTokenDomainConfig, MintRequest, EIP712Signature, PartialUserOperation, BurnRequest, ReceiverConsent, PathKey, PoolKey } from '@pafi-dev/core';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Lifecycle of a minting request as tracked by the issuer's point ledger.
|
|
@@ -1438,223 +1438,33 @@ declare class BalanceAggregator {
|
|
|
1438
1438
|
}
|
|
1439
1439
|
|
|
1440
1440
|
interface RetryConfig {
|
|
1441
|
-
/**
|
|
1442
|
-
* Max total attempts including the first try. Default: 1 (no retry).
|
|
1443
|
-
* Set to 3 to get 2 retries after the initial call.
|
|
1444
|
-
*
|
|
1445
|
-
* Only applies when the server error body carries `safeToRetry: true`
|
|
1446
|
-
* or the failure is a transient network/timeout error.
|
|
1447
|
-
*/
|
|
1448
1441
|
maxAttempts?: number;
|
|
1449
|
-
/**
|
|
1450
|
-
* Initial backoff delay in ms. Default: 500. Each subsequent retry
|
|
1451
|
-
* doubles this (exponential backoff) and adds ±20% jitter.
|
|
1452
|
-
*/
|
|
1453
1442
|
initialDelayMs?: number;
|
|
1454
|
-
/**
|
|
1455
|
-
* Hard ceiling for a single backoff (ms). Default: 10_000.
|
|
1456
|
-
*/
|
|
1457
1443
|
maxDelayMs?: number;
|
|
1458
|
-
/**
|
|
1459
|
-
* Upper bound on `retryAfter` from the server. If the server asks us
|
|
1460
|
-
* to wait longer than this (e.g. rate limit until UTC midnight), the
|
|
1461
|
-
* client gives up rather than blocking. Default: 30_000.
|
|
1462
|
-
*/
|
|
1463
1444
|
maxRetryAfterMs?: number;
|
|
1464
1445
|
}
|
|
1465
1446
|
interface PafiBackendConfig {
|
|
1466
|
-
/**
|
|
1467
|
-
* PAFI Backend API base URL. Example:
|
|
1468
|
-
* https://api.pacificfinance.org
|
|
1469
|
-
* https://staging-api.pacificfinance.org
|
|
1470
|
-
*/
|
|
1471
1447
|
url: string;
|
|
1472
|
-
/** PAFI-assigned issuer ID (e.g., "gg56"). Sent in X-Issuer-Id header. */
|
|
1473
1448
|
issuerId: string;
|
|
1474
|
-
/** Per-issuer API key (or JWT) for the Authorization header. */
|
|
1475
1449
|
apiKey: string;
|
|
1476
|
-
/** Optional fetch override for tests. */
|
|
1477
1450
|
fetchImpl?: typeof fetch;
|
|
1478
|
-
/**
|
|
1479
|
-
* Timeout (ms) for each request. Default: 10_000. PAFI Backend should
|
|
1480
|
-
* respond in <1s for the happy path; this is just the sanity bound.
|
|
1481
|
-
*/
|
|
1482
1451
|
timeoutMs?: number;
|
|
1483
|
-
/**
|
|
1484
|
-
* Retry policy for transient failures (5xx, 429, timeouts, network).
|
|
1485
|
-
* Omit or pass `{ maxAttempts: 1 }` to disable retry entirely.
|
|
1486
|
-
*/
|
|
1487
1452
|
retry?: RetryConfig;
|
|
1488
1453
|
}
|
|
1489
|
-
|
|
1490
|
-
* @deprecated Coinbase paymaster path — replaced by SponsorAuth in beta.8.
|
|
1491
|
-
* Kept for back-compat with consumers still on Coinbase. Will be removed
|
|
1492
|
-
* in 1.0.
|
|
1493
|
-
*/
|
|
1494
|
-
interface SponsorshipRequest {
|
|
1495
|
-
chainId: number;
|
|
1496
|
-
scenario: SponsorshipScenario;
|
|
1497
|
-
userOp: PartialUserOperation;
|
|
1498
|
-
target: {
|
|
1499
|
-
contract: Address;
|
|
1500
|
-
function: string;
|
|
1501
|
-
pointToken?: Address;
|
|
1502
|
-
};
|
|
1503
|
-
}
|
|
1504
|
-
/** @deprecated See `SponsorshipRequest`. Use `SponsorAuthResponse` in beta.8+. */
|
|
1505
|
-
interface SponsorshipResponse {
|
|
1506
|
-
paymaster: Address;
|
|
1507
|
-
paymasterData: Hex;
|
|
1508
|
-
paymasterVerificationGasLimit: bigint;
|
|
1509
|
-
paymasterPostOpGasLimit: bigint;
|
|
1510
|
-
expiresAt: number;
|
|
1511
|
-
}
|
|
1512
|
-
|
|
1513
|
-
/**
|
|
1514
|
-
* Request body for `POST /sponsor-auth` against PAFI sponsor-relayer.
|
|
1515
|
-
* See `pafi-backend/docs/SPONSOR_AUTH_DESIGN.md` for the full spec.
|
|
1516
|
-
*
|
|
1517
|
-
* The endpoint:
|
|
1518
|
-
* 1. Authenticates user (JWT) + issuer (API key)
|
|
1519
|
-
* 2. Per-(user, scenario) rate-limits
|
|
1520
|
-
* 3. Per-issuer daily budget check
|
|
1521
|
-
* 4. Scenario-specific intent validation (mint cap, KYC, etc.)
|
|
1522
|
-
* 5. Allocates a unique nonce
|
|
1523
|
-
* 6. Signs the SponsorAuth payload via KMS-backed PAFI key
|
|
1524
|
-
* 7. Returns `{ sponsorAuth, payload }` for FE to forward to Privy
|
|
1525
|
-
*/
|
|
1526
|
-
interface SponsorAuthRequest {
|
|
1527
|
-
chainId: number;
|
|
1528
|
-
scenario: SponsorAuthScenario;
|
|
1529
|
-
/** The exact UserOp the FE intends to submit. callDataHash binds to this. */
|
|
1530
|
-
userOp: PartialUserOperation;
|
|
1531
|
-
/** Issuer ID this sponsorship is billed against (e.g. "gg56"). */
|
|
1532
|
-
issuerId: string;
|
|
1533
|
-
/**
|
|
1534
|
-
* Scenario-specific context for intent validation. The relayer reads
|
|
1535
|
-
* these to apply scenario rules — e.g. preValidateMint reads
|
|
1536
|
-
* pointToken + amount to check the issuer cap.
|
|
1537
|
-
*/
|
|
1538
|
-
context?: {
|
|
1539
|
-
pointToken?: Address;
|
|
1540
|
-
/** Decimal string representation (handles bigint over JSON). */
|
|
1541
|
-
amount?: string;
|
|
1542
|
-
brokerHash?: Hex;
|
|
1543
|
-
};
|
|
1544
|
-
}
|
|
1545
|
-
/**
|
|
1546
|
-
* Response from `POST /sponsor-auth`.
|
|
1547
|
-
*
|
|
1548
|
-
* `payload` is returned alongside `sponsorAuth` so the FE doesn't have
|
|
1549
|
-
* to reconstruct the message — just forwards both to Privy. Privy
|
|
1550
|
-
* verifier checks `signature` recovers to PAFI's registered pubkey
|
|
1551
|
-
* over `payload`.
|
|
1552
|
-
*/
|
|
1553
|
-
interface SponsorAuthResponse {
|
|
1554
|
-
/** EIP-712 signature, hex-encoded 65 bytes. */
|
|
1555
|
-
sponsorAuth: Hex;
|
|
1556
|
-
/** The payload that was signed. Pass to Privy alongside the signature. */
|
|
1557
|
-
payload: SponsorAuthPayload;
|
|
1558
|
-
}
|
|
1559
|
-
/**
|
|
1560
|
-
* Machine-readable error codes returned by PAFI sponsor-relayer.
|
|
1561
|
-
*
|
|
1562
|
-
* Source of truth: `apps/sponsor-relayer/src/**` (renamed from
|
|
1563
|
-
* paymaster-proxy in beta.8). Keep in sync.
|
|
1564
|
-
*/
|
|
1565
|
-
type PafiBackendErrorCode = "MISSING_ISSUER_ID" | "MISSING_API_KEY" | "ISSUER_UNAUTHORIZED" | "USER_UNAUTHORIZED" | "INTENT_REJECTED" | "MINT_CAP_EXCEEDED" | "ISSUER_INACTIVE" | "BROKER_NOT_WHITELISTED" | "RATE_LIMIT_EXCEEDED" | "RATE_LIMIT_EXCEEDED_DAILY" | "RATE_LIMIT_EXCEEDED_PER_USER" | "ISSUER_BUDGET_EXCEEDED" | "RATE_LIMITER_UNAVAILABLE" | "KMS_UNAVAILABLE" | "SPONSOR_AUTH_SIGNING_FAILED" | "PAYMASTER_REJECTED" | "PAYMASTER_UNAVAILABLE" | "PAYMASTER_TIMEOUT" | "CALLDATA_INVALID" | "CALLDATA_EMPTY_BATCH" | "TARGET_NOT_ALLOWLISTED" | "FUNCTION_NOT_ALLOWED" | "SCENARIO_MISMATCH" | "SCENARIO_DISABLED" | "BAD_REQUEST" | "INTERNAL_ERROR" | "TIMEOUT" | "NETWORK_ERROR";
|
|
1454
|
+
type PafiBackendErrorCode = "MISSING_ISSUER_ID" | "MISSING_API_KEY" | "ISSUER_UNAUTHORIZED" | "USER_UNAUTHORIZED" | "INTENT_REJECTED" | "MINT_CAP_EXCEEDED" | "ISSUER_INACTIVE" | "BROKER_NOT_WHITELISTED" | "RATE_LIMIT_EXCEEDED" | "RATE_LIMIT_EXCEEDED_DAILY" | "RATE_LIMIT_EXCEEDED_PER_USER" | "ISSUER_BUDGET_EXCEEDED" | "RATE_LIMITER_UNAVAILABLE" | "BAD_REQUEST" | "INTERNAL_ERROR" | "TIMEOUT" | "NETWORK_ERROR";
|
|
1566
1455
|
declare class PafiBackendError extends Error {
|
|
1567
1456
|
code: PafiBackendErrorCode;
|
|
1568
1457
|
httpStatus: number;
|
|
1569
1458
|
details?: unknown | undefined;
|
|
1570
|
-
/**
|
|
1571
|
-
* Seconds to wait before retry. Populated from the server body
|
|
1572
|
-
* (e.g. rate limit returns the number of seconds until UTC midnight).
|
|
1573
|
-
*/
|
|
1574
1459
|
readonly retryAfter?: number;
|
|
1575
|
-
/**
|
|
1576
|
-
* `safeToRetry` as reported by the server body. Prefer this over the
|
|
1577
|
-
* code-based heuristic when available — the server knows more about
|
|
1578
|
-
* whether the same request will succeed on retry.
|
|
1579
|
-
*/
|
|
1580
1460
|
private readonly serverSafeToRetry?;
|
|
1581
1461
|
constructor(code: PafiBackendErrorCode, message: string, httpStatus: number, details?: unknown | undefined, opts?: {
|
|
1582
1462
|
retryAfter?: number;
|
|
1583
1463
|
safeToRetry?: boolean;
|
|
1584
1464
|
});
|
|
1585
|
-
/**
|
|
1586
|
-
* Whether the caller can safely retry the same request.
|
|
1587
|
-
*
|
|
1588
|
-
* If the server provided `safeToRetry` in the body, trust that.
|
|
1589
|
-
* Otherwise fall back to a code-based heuristic.
|
|
1590
|
-
*/
|
|
1591
1465
|
get safeToRetry(): boolean;
|
|
1592
1466
|
}
|
|
1593
1467
|
|
|
1594
|
-
/**
|
|
1595
|
-
* HTTP client for the PAFI Backend paymaster proxy service. See
|
|
1596
|
-
* [SPONSORED_PATH_FLOW.md] for the full flow + API contract.
|
|
1597
|
-
*
|
|
1598
|
-
* This client sits between `@pafi/issuer`'s RelayService and the
|
|
1599
|
-
* PAFI Backend. It does NOT talk to Coinbase Paymaster directly —
|
|
1600
|
-
* PAFI Backend holds that integration.
|
|
1601
|
-
*/
|
|
1602
|
-
declare class PafiBackendClient {
|
|
1603
|
-
private readonly url;
|
|
1604
|
-
private readonly issuerId;
|
|
1605
|
-
private readonly apiKey;
|
|
1606
|
-
private readonly fetchImpl;
|
|
1607
|
-
private readonly timeoutMs;
|
|
1608
|
-
private readonly retry;
|
|
1609
|
-
constructor(config: PafiBackendConfig);
|
|
1610
|
-
/**
|
|
1611
|
-
* Request a SponsorAuth signature from PAFI sponsor-relayer (beta.8+).
|
|
1612
|
-
*
|
|
1613
|
-
* The relayer:
|
|
1614
|
-
* 1. Authenticates user (JWT) + issuer (API key)
|
|
1615
|
-
* 2. Per-(user, scenario) rate limit + per-issuer daily budget
|
|
1616
|
-
* 3. Scenario-specific intent validation (mint cap, KYC, etc.)
|
|
1617
|
-
* 4. Allocates nonce + signs SponsorAuth payload via KMS PAFI key
|
|
1618
|
-
* 5. Returns `{ sponsorAuth, payload }` for the FE to forward to
|
|
1619
|
-
* Privy's `signUserOperation({ sponsorAuth, payload })`.
|
|
1620
|
-
*
|
|
1621
|
-
* Retries on transient failures (5xx, timeouts, KMS unavailable,
|
|
1622
|
-
* rate-limit-with-retryAfter). 4xx that are not `safeToRetry` fail fast.
|
|
1623
|
-
*
|
|
1624
|
-
* See `pafi-backend/docs/SPONSOR_AUTH_DESIGN.md` for the full spec.
|
|
1625
|
-
*
|
|
1626
|
-
* @throws PafiBackendError on final failure after exhausting retries
|
|
1627
|
-
*/
|
|
1628
|
-
requestSponsorAuth(req: SponsorAuthRequest): Promise<SponsorAuthResponse>;
|
|
1629
|
-
/**
|
|
1630
|
-
* @deprecated Coinbase paymaster path — replaced by `requestSponsorAuth`
|
|
1631
|
-
* in beta.8. Will be removed in 1.0. Migrate by:
|
|
1632
|
-
* 1. Switch to `requestSponsorAuth` returning `{ sponsorAuth, payload }`
|
|
1633
|
-
* 2. Pass both to Privy `signUserOperation` instead of merging
|
|
1634
|
-
* paymasterData into the UserOp callData
|
|
1635
|
-
*/
|
|
1636
|
-
requestSponsorship(req: SponsorshipRequest): Promise<SponsorshipResponse>;
|
|
1637
|
-
private postWithRetry;
|
|
1638
|
-
/**
|
|
1639
|
-
* Pick the delay before the next retry.
|
|
1640
|
-
* - If the server sent `retryAfter` (seconds), honor it (capped by
|
|
1641
|
-
* `maxRetryAfterMs`) — returns null if the server wait exceeds the
|
|
1642
|
-
* cap, signalling the caller should give up.
|
|
1643
|
-
* - Otherwise: exponential backoff with ±20% jitter, capped at
|
|
1644
|
-
* `maxDelayMs`.
|
|
1645
|
-
*/
|
|
1646
|
-
private computeBackoff;
|
|
1647
|
-
private sleep;
|
|
1648
|
-
private post;
|
|
1649
|
-
/** JSON replacer that stringifies bigints. Paired with bigintReviver. */
|
|
1650
|
-
private bigintReplacer;
|
|
1651
|
-
/**
|
|
1652
|
-
* JSON reviver that coerces specific numeric-string fields back to
|
|
1653
|
-
* bigint. The server must send these fields as decimal strings.
|
|
1654
|
-
*/
|
|
1655
|
-
private bigintReviver;
|
|
1656
|
-
}
|
|
1657
|
-
|
|
1658
1468
|
/**
|
|
1659
1469
|
* Top-level configuration for `createIssuerService`.
|
|
1660
1470
|
*
|
|
@@ -1751,4 +1561,4 @@ declare function createIssuerService(config: IssuerServiceConfig): IssuerService
|
|
|
1751
1561
|
/** SDK package version — bumped on every release */
|
|
1752
1562
|
declare const PAFI_ISSUER_SDK_VERSION = "0.1.0";
|
|
1753
1563
|
|
|
1754
|
-
export { type ApiBuildConsentTypedDataRequest, type ApiBuildConsentTypedDataResponse, type ApiClaimAndSwapRequest, type ApiClaimAndSwapResponse, type ApiConfigResponse, type ApiGasFeeResponse, type ApiLoginRequest, type ApiLoginResponse, type ApiNonceResponse, type ApiPoolsRequest, type ApiPoolsResponse, type ApiUserRequest, type ApiUserResponse, type AuthContext, AuthError, type AuthErrorCode, AuthService, type AuthServiceConfig, BalanceAggregator, type BalanceAggregatorConfig, type BurnEvent, BurnIndexer, type BurnIndexerConfig, type CombinedBalance, DefaultPolicyEngine, type DefaultPolicyEngineOptions, FeeManager, type FeeManagerConfig, type IIndexerCursorStore, type IIssuerSigner, type IPointLedger, type IPolicyEngine, type ISessionStore, InMemoryCursorStore, IssuerApiHandlers, type IssuerApiHandlersConfig, type IssuerService, type IssuerServiceConfig, type LockedMintRequest, type LoginResult, MemoryPointLedger, MemorySessionStore, type MemorySessionStoreOptions, type MintEvent, type MintingStatus, NonceManager, PAFI_ISSUER_SDK_VERSION, PTRedeemError, PTRedeemHandler, type PTRedeemHandlerConfig, type PTRedeemRequest, type PTRedeemResponse,
|
|
1564
|
+
export { type ApiBuildConsentTypedDataRequest, type ApiBuildConsentTypedDataResponse, type ApiClaimAndSwapRequest, type ApiClaimAndSwapResponse, type ApiConfigResponse, type ApiGasFeeResponse, type ApiLoginRequest, type ApiLoginResponse, type ApiNonceResponse, type ApiPoolsRequest, type ApiPoolsResponse, type ApiUserRequest, type ApiUserResponse, type AuthContext, AuthError, type AuthErrorCode, AuthService, type AuthServiceConfig, BalanceAggregator, type BalanceAggregatorConfig, type BurnEvent, BurnIndexer, type BurnIndexerConfig, type CombinedBalance, DefaultPolicyEngine, type DefaultPolicyEngineOptions, FeeManager, type FeeManagerConfig, type IIndexerCursorStore, type IIssuerSigner, type IPointLedger, type IPolicyEngine, type ISessionStore, InMemoryCursorStore, IssuerApiHandlers, type IssuerApiHandlersConfig, type IssuerService, type IssuerServiceConfig, type LockedMintRequest, type LoginResult, MemoryPointLedger, MemorySessionStore, type MemorySessionStoreOptions, type MintEvent, type MintingStatus, NonceManager, PAFI_ISSUER_SDK_VERSION, PTRedeemError, PTRedeemHandler, type PTRedeemHandlerConfig, type PTRedeemRequest, type PTRedeemResponse, type PafiBackendConfig, PafiBackendError, type PafiBackendErrorCode, PointIndexer, type PointIndexerConfig, type PolicyDecision, type PolicyEvalRequest, type PoolsProvider, type PrepareBurnDirectParams, type PrepareBurnParams, type PrepareBurnWithSigParams, type PrepareMintParams, PrivateKeySigner, type PrivateKeySignerOptions, RelayError, type RelayErrorCode, RelayService, type RetryConfig, type Session, type SubgraphNativeUsdtQuoterConfig, type SubgraphPoolsProviderConfig, TopUpRedemptionError, TopUpRedemptionHandler, type TopUpRedemptionHandlerConfig, type TopUpRedemptionRequest, type TopUpRedemptionResponse, authenticateRequest, createIssuerService, createSubgraphNativeUsdtQuoter, createSubgraphPoolsProvider };
|