@pafi-dev/core 0.7.7 → 0.8.0

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 (63) hide show
  1. package/dist/abi/index.cjs +7 -3
  2. package/dist/abi/index.cjs.map +1 -1
  3. package/dist/abi/index.d.cts +451 -2
  4. package/dist/abi/index.d.ts +451 -2
  5. package/dist/abi/index.js +7 -3
  6. package/dist/auth/index.cjs +6 -2
  7. package/dist/auth/index.cjs.map +1 -1
  8. package/dist/auth/index.d.cts +21 -9
  9. package/dist/auth/index.d.ts +21 -9
  10. package/dist/auth/index.js +5 -1
  11. package/dist/{chunk-6UX2IFA2.js → chunk-4EGXLYMM.js} +20 -2
  12. package/dist/chunk-4EGXLYMM.js.map +1 -0
  13. package/dist/chunk-644KZUKR.cjs +519 -0
  14. package/dist/chunk-644KZUKR.cjs.map +1 -0
  15. package/dist/{chunk-5254AG3Z.cjs → chunk-75JWR5SA.cjs} +21 -3
  16. package/dist/chunk-75JWR5SA.cjs.map +1 -0
  17. package/dist/{chunk-6CXTFOIH.js → chunk-ABNM6LMP.js} +266 -1
  18. package/dist/chunk-ABNM6LMP.js.map +1 -0
  19. package/dist/{chunk-M5ULOZ3A.cjs → chunk-ACQHZWHP.cjs} +55 -3
  20. package/dist/chunk-ACQHZWHP.cjs.map +1 -0
  21. package/dist/{chunk-5JZOJIBT.js → chunk-B2NDSIAI.js} +1 -1095
  22. package/dist/chunk-B2NDSIAI.js.map +1 -0
  23. package/dist/{chunk-WJSIB5GF.js → chunk-BB5YW57R.js} +53 -1
  24. package/dist/chunk-BB5YW57R.js.map +1 -0
  25. package/dist/chunk-CUVUSVWR.js +519 -0
  26. package/dist/chunk-CUVUSVWR.js.map +1 -0
  27. package/dist/chunk-JEWSN7Q3.cjs +1059 -0
  28. package/dist/chunk-JEWSN7Q3.cjs.map +1 -0
  29. package/dist/{chunk-Q6WCDZXI.cjs → chunk-RFANYF24.cjs} +267 -2
  30. package/dist/chunk-RFANYF24.cjs.map +1 -0
  31. package/dist/{chunk-YDLMVWDH.js → chunk-Y4CFC4OC.js} +5 -3
  32. package/dist/{chunk-YDLMVWDH.js.map → chunk-Y4CFC4OC.js.map} +1 -1
  33. package/dist/{chunk-CLPRSQT2.cjs → chunk-YCY7MBSJ.cjs} +14 -12
  34. package/dist/chunk-YCY7MBSJ.cjs.map +1 -0
  35. package/dist/contract/index.cjs +4 -3
  36. package/dist/contract/index.cjs.map +1 -1
  37. package/dist/contract/index.d.cts +1 -1
  38. package/dist/contract/index.d.ts +1 -1
  39. package/dist/contract/index.js +3 -2
  40. package/dist/eip712/index.cjs +7 -2
  41. package/dist/eip712/index.cjs.map +1 -1
  42. package/dist/eip712/index.d.cts +39 -4
  43. package/dist/eip712/index.d.ts +39 -4
  44. package/dist/eip712/index.js +6 -1
  45. package/dist/index.cjs +169 -60
  46. package/dist/index.cjs.map +1 -1
  47. package/dist/index.d.cts +112 -31
  48. package/dist/index.d.ts +112 -31
  49. package/dist/index.js +132 -23
  50. package/dist/index.js.map +1 -1
  51. package/dist/{types-BAkmxgVo.d.cts → types-BS4kpO4Z.d.cts} +62 -5
  52. package/dist/{types-BAkmxgVo.d.ts → types-BS4kpO4Z.d.ts} +62 -5
  53. package/package.json +1 -1
  54. package/dist/chunk-5254AG3Z.cjs.map +0 -1
  55. package/dist/chunk-5JZOJIBT.js.map +0 -1
  56. package/dist/chunk-6CXTFOIH.js.map +0 -1
  57. package/dist/chunk-6UX2IFA2.js.map +0 -1
  58. package/dist/chunk-CLPRSQT2.cjs.map +0 -1
  59. package/dist/chunk-LRHY7GOR.cjs +0 -2153
  60. package/dist/chunk-LRHY7GOR.cjs.map +0 -1
  61. package/dist/chunk-M5ULOZ3A.cjs.map +0 -1
  62. package/dist/chunk-Q6WCDZXI.cjs.map +0 -1
  63. package/dist/chunk-WJSIB5GF.js.map +0 -1
package/dist/index.js CHANGED
@@ -1,11 +1,13 @@
1
1
  import {
2
2
  erc20Abi,
3
+ mintFeeWrapperAbi,
3
4
  permit2Abi,
4
5
  pointTokenFactoryAbi,
5
6
  universalRouterAbi,
6
7
  v4QuoterAbi
7
- } from "./chunk-6CXTFOIH.js";
8
+ } from "./chunk-ABNM6LMP.js";
8
9
  import {
10
+ SPONSOR_AUTH_DOMAIN_ANCHOR_BASE_MAINNET,
9
11
  SPONSOR_AUTH_DOMAIN_NAME,
10
12
  SPONSOR_AUTH_TYPES,
11
13
  buildAndSignSponsorAuth,
@@ -14,11 +16,12 @@ import {
14
16
  computeCallDataHash,
15
17
  createLoginMessage,
16
18
  generateSponsorAuthNonce,
19
+ getSponsorAuthDomainAnchor,
17
20
  parseLoginMessage,
18
21
  signSponsorAuth,
19
22
  verifyLoginMessage,
20
23
  verifySponsorAuth
21
- } from "./chunk-6UX2IFA2.js";
24
+ } from "./chunk-4EGXLYMM.js";
22
25
  import {
23
26
  getBurnRequestNonce,
24
27
  getIssuer,
@@ -32,22 +35,23 @@ import {
32
35
  isMinter,
33
36
  issuerRegistryGetIssuerFlatAbi,
34
37
  verifyMintCap
35
- } from "./chunk-YDLMVWDH.js";
38
+ } from "./chunk-Y4CFC4OC.js";
36
39
  import {
37
40
  issuerRegistryAbi,
38
- mintingOracleAbi,
39
- pointTokenAbi
40
- } from "./chunk-5JZOJIBT.js";
41
+ mintingOracleAbi
42
+ } from "./chunk-B2NDSIAI.js";
41
43
  import {
42
44
  COMMON_POOLS,
43
45
  COMMON_TOKENS,
44
46
  ENTRY_POINT_V07,
45
47
  ENTRY_POINT_V08,
48
+ Eip712DomainMismatchError,
46
49
  PERMIT2_ADDRESS,
47
50
  POINT_TOKEN_POOLS,
48
51
  SUPPORTED_CHAINS,
49
52
  UNIVERSAL_ROUTER_ADDRESSES,
50
53
  V4_QUOTER_ADDRESSES,
54
+ assertDomainMatchesContract,
51
55
  buildBurnRequestTypedData,
52
56
  buildDomain,
53
57
  buildMintRequestTypedData,
@@ -61,13 +65,32 @@ import {
61
65
  verifyBurnRequest,
62
66
  verifyMintRequest,
63
67
  verifyReceiverConsent
64
- } from "./chunk-WJSIB5GF.js";
68
+ } from "./chunk-BB5YW57R.js";
69
+ import {
70
+ pointTokenAbi
71
+ } from "./chunk-CUVUSVWR.js";
65
72
  import "./chunk-DGUM43GV.js";
66
73
 
67
74
  // src/index.ts
68
75
  import { createPublicClient, http as http2 } from "viem";
69
76
 
70
77
  // src/errors.ts
78
+ var SDK_ERROR_HTTP_STATUS_CODE = {
79
+ not_found: 404,
80
+ forbidden: 403,
81
+ unprocessable: 422,
82
+ service_unavailable: 503
83
+ };
84
+ function defaultErrorTypeForStatus(status) {
85
+ if (status === 400) return "validation_error";
86
+ if (status === 401) return "authentication_error";
87
+ if (status === 403) return "authorization_error";
88
+ if (status === 404) return "not_found_error";
89
+ if (status === 422) return "business_logic_error";
90
+ if (status === 429) return "rate_limit_error";
91
+ if (status === 503) return "service_unavailable_error";
92
+ return "server_error";
93
+ }
71
94
  var PafiSdkError = class extends Error {
72
95
  /**
73
96
  * `true` when the FE should consider a retry safe — typically because
@@ -75,6 +98,24 @@ var PafiSdkError = class extends Error {
75
98
  */
76
99
  safeToRetry = false;
77
100
  details;
101
+ /**
102
+ * Optional Stripe-style taxonomy override. Defaults to the type
103
+ * implied by `httpStatus` (forbidden→authorization_error,
104
+ * unprocessable→business_logic_error, etc).
105
+ */
106
+ type;
107
+ /**
108
+ * Optional name of the request field that triggered the error (e.g.
109
+ * `"amount"`, `"chainId"`). Surfaced on validation failures so the
110
+ * client can highlight the offending field.
111
+ */
112
+ param;
113
+ /**
114
+ * Optional structured context (e.g. `{ available, requested }` for a
115
+ * cap denial). Distinct from `details` — `metadata` is meant for
116
+ * UI consumption; `details` carries raw debug info.
117
+ */
118
+ metadata;
78
119
  constructor(message) {
79
120
  super(message);
80
121
  this.name = new.target.name;
@@ -129,12 +170,18 @@ var OracleStaleError = class extends PafiSdkError {
129
170
  };
130
171
  var ValidationError = class extends PafiSdkError {
131
172
  httpStatus = "unprocessable";
173
+ type = "validation_error";
132
174
  code;
133
- details;
134
- constructor(code, message, details) {
175
+ constructor(code, message, details, options) {
135
176
  super(message);
136
177
  this.code = code;
137
178
  this.details = details;
179
+ if (options?.param) {
180
+ this.param = options.param;
181
+ }
182
+ if (options?.metadata) {
183
+ this.metadata = options.metadata;
184
+ }
138
185
  }
139
186
  };
140
187
 
@@ -582,7 +629,16 @@ function getDummySignatureFor7702(impl) {
582
629
 
583
630
  // src/paymaster/config.ts
584
631
  var _config = null;
632
+ var _deprecationWarned = false;
633
+ function warnDeprecated(fn) {
634
+ if (_deprecationWarned) return;
635
+ _deprecationWarned = true;
636
+ console.warn(
637
+ `[PAFI] DEPRECATION (v0.7.1+): \`${fn}\` from @pafi-dev/core/paymaster is deprecated and will be removed in v0.8. Use \`PafiBackendClient\` from @pafi-dev/issuer/pafi-backend instead.`
638
+ );
639
+ }
585
640
  function setPaymasterConfig(config) {
641
+ warnDeprecated("setPaymasterConfig");
586
642
  if (!config.pafiBackendUrl) {
587
643
  throw new Error("setPaymasterConfig: pafiBackendUrl is required");
588
644
  }
@@ -598,6 +654,7 @@ function setPaymasterConfig(config) {
598
654
  _config = { ...config };
599
655
  }
600
656
  function getPaymasterConfig() {
657
+ warnDeprecated("getPaymasterConfig");
601
658
  if (!_config) {
602
659
  throw new Error(
603
660
  "PaymasterConfig not initialized \u2014 call setPaymasterConfig() at application boot before invoking any batch builder"
@@ -1058,7 +1115,8 @@ async function quoteOperatorFeeUsdt(config) {
1058
1115
  const ethPrice8dec = await getEthPrice8dec(
1059
1116
  provider,
1060
1117
  chainlinkFeedAddress,
1061
- allowStaleFallback ? fallbackEthPriceUsd : null
1118
+ allowStaleFallback ? fallbackEthPriceUsd : null,
1119
+ config.onFallback
1062
1120
  );
1063
1121
  const denomExp = 18 + 8 - usdtDecimals;
1064
1122
  return withPremium * ethPrice8dec / 10n ** BigInt(denomExp);
@@ -1086,18 +1144,20 @@ async function quoteOperatorFeePt(config) {
1086
1144
  getEthPrice8dec(
1087
1145
  provider,
1088
1146
  chainlinkFeedAddress,
1089
- allowStaleFallback ? fallbackEthPriceUsd : null
1147
+ allowStaleFallback ? fallbackEthPriceUsd : null,
1148
+ config.onFallback
1090
1149
  ),
1091
1150
  getPtPerUsdt18dec(
1092
1151
  fetchImpl,
1093
1152
  subgraphUrl,
1094
1153
  pointTokenAddress,
1095
- allowStaleFallback ? fallbackPtPriceUsdt : null
1154
+ allowStaleFallback ? fallbackPtPriceUsdt : null,
1155
+ config.onFallback
1096
1156
  )
1097
1157
  ]);
1098
1158
  return withPremium * ethPrice8dec * ptPerUsdt18dec / 10n ** 26n;
1099
1159
  }
1100
- async function getEthPrice8dec(provider, feed, fallback) {
1160
+ async function getEthPrice8dec(provider, feed, fallback, onFallback) {
1101
1161
  try {
1102
1162
  const result = await provider.readContract({
1103
1163
  address: feed,
@@ -1117,14 +1177,18 @@ async function getEthPrice8dec(provider, feed, fallback) {
1117
1177
  if (fallback === null) {
1118
1178
  throw new OracleStaleError("chainlink", reason);
1119
1179
  }
1120
- console.warn(
1121
- "[quoteOperatorFee] Chainlink unavailable, using opt-in fallback:",
1122
- reason
1123
- );
1180
+ if (onFallback) {
1181
+ onFallback({ source: "chainlink", reason, fallbackValue: fallback });
1182
+ } else {
1183
+ console.warn(
1184
+ "[quoteOperatorFee] Chainlink unavailable, using opt-in fallback:",
1185
+ reason
1186
+ );
1187
+ }
1124
1188
  return BigInt(Math.round(fallback * 1e8));
1125
1189
  }
1126
1190
  }
1127
- async function getPtPerUsdt18dec(fetchImpl, subgraphUrl, pointTokenAddress, fallbackPtPriceUsdt) {
1191
+ async function getPtPerUsdt18dec(fetchImpl, subgraphUrl, pointTokenAddress, fallbackPtPriceUsdt, onFallback) {
1128
1192
  try {
1129
1193
  const response = await fetchImpl(subgraphUrl, {
1130
1194
  method: "POST",
@@ -1156,10 +1220,18 @@ async function getPtPerUsdt18dec(fetchImpl, subgraphUrl, pointTokenAddress, fall
1156
1220
  if (fallbackPtPriceUsdt === null) {
1157
1221
  throw new OracleStaleError("subgraph", reason);
1158
1222
  }
1159
- console.warn(
1160
- "[quoteOperatorFeePt] subgraph unavailable, using opt-in fallback:",
1161
- reason
1162
- );
1223
+ if (onFallback) {
1224
+ onFallback({
1225
+ source: "subgraph",
1226
+ reason,
1227
+ fallbackValue: fallbackPtPriceUsdt
1228
+ });
1229
+ } else {
1230
+ console.warn(
1231
+ "[quoteOperatorFeePt] subgraph unavailable, using opt-in fallback:",
1232
+ reason
1233
+ );
1234
+ }
1163
1235
  const ptPerUsdtHuman = 1 / fallbackPtPriceUsdt;
1164
1236
  return parseBigDecimalTo18(ptPerUsdtHuman.toFixed(18));
1165
1237
  }
@@ -1175,6 +1247,29 @@ function parseBigDecimalTo18(s) {
1175
1247
  var BATCH_EXECUTOR_ADDRESS_BASE_MAINNET = getContractAddresses(8453).batchExecutor;
1176
1248
  var BATCH_EXECUTOR_ADDRESS_BASE_SEPOLIA = getContractAddresses(84532).batchExecutor;
1177
1249
 
1250
+ // src/contracts/real/pafi-services.ts
1251
+ var PAFI_SERVICE_URLS = {
1252
+ // Base mainnet
1253
+ 8453: {
1254
+ sponsorRelayer: "https://api-dev.pacificfinance.org/api/sponsor",
1255
+ issuerApi: "https://api-dev.pacificfinance.org/api/issuer"
1256
+ },
1257
+ // Base sepolia
1258
+ 84532: {
1259
+ sponsorRelayer: "https://api-dev.pacificfinance.org/api/sponsor",
1260
+ issuerApi: "https://api-dev.pacificfinance.org/api/issuer"
1261
+ }
1262
+ };
1263
+ function getPafiServiceUrls(chainId) {
1264
+ const urls = PAFI_SERVICE_URLS[chainId];
1265
+ if (!urls) {
1266
+ throw new Error(
1267
+ `getPafiServiceUrls: no PAFI service URLs for chainId ${chainId}. Supported: ${Object.keys(PAFI_SERVICE_URLS).join(", ")}`
1268
+ );
1269
+ }
1270
+ return urls;
1271
+ }
1272
+
1178
1273
  // src/web-handoff/webPopup.ts
1179
1274
  var DEFAULT_WIDTH = 900;
1180
1275
  var DEFAULT_HEIGHT = 700;
@@ -1231,10 +1326,15 @@ function openWebPopup(url, options = {}) {
1231
1326
  }, 500);
1232
1327
  if (options.onMessage) {
1233
1328
  const allowed = options.allowedOrigins ?? [];
1329
+ if (allowed.length === 0) {
1330
+ throw new Error(
1331
+ "openPafiWebModal: `allowedOrigins` is empty/missing while `onMessage` is supplied. The popup-message listener would silently reject every message \u2014 caller must explicitly whitelist PAFI Web's host (e.g. `['https://app.pacificfinance.org']`) before any payload reaches the callback. To accept any origin (insecure), pass an explicit list containing '*' or omit `onMessage` entirely."
1332
+ );
1333
+ }
1234
1334
  const onMessage = options.onMessage;
1235
1335
  messageListener = (event) => {
1236
1336
  if (event.source !== popup) return;
1237
- if (!allowed.includes(event.origin)) return;
1337
+ if (!allowed.includes("*") && !allowed.includes(event.origin)) return;
1238
1338
  onMessage(event.data, event.origin);
1239
1339
  };
1240
1340
  window.addEventListener("message", messageListener);
@@ -1467,11 +1567,13 @@ export {
1467
1567
  DUMMY_SIGNATURE_V07,
1468
1568
  ENTRY_POINT_V07,
1469
1569
  ENTRY_POINT_V08,
1570
+ Eip712DomainMismatchError,
1470
1571
  ORDERLY_RELAY_ABI,
1471
1572
  ORDERLY_VAULT_ABI,
1472
1573
  ORDERLY_VAULT_ADDRESSES,
1473
1574
  ORDERLY_VAULT_BASE_MAINNET,
1474
1575
  OracleStaleError,
1576
+ PAFI_SERVICE_URLS,
1475
1577
  PAFI_SUBGRAPH_URL,
1476
1578
  PERMIT2_ADDRESS,
1477
1579
  POINT_TOKEN_FACTORY_ADDRESSES,
@@ -1481,7 +1583,9 @@ export {
1481
1583
  PafiSDK,
1482
1584
  PafiSDKError,
1483
1585
  PafiSdkError,
1586
+ SDK_ERROR_HTTP_STATUS_CODE,
1484
1587
  SIMPLE_7702_IMPL_BASE_MAINNET,
1588
+ SPONSOR_AUTH_DOMAIN_ANCHOR_BASE_MAINNET,
1485
1589
  SPONSOR_AUTH_DOMAIN_NAME,
1486
1590
  SPONSOR_AUTH_TYPES,
1487
1591
  SUPPORTED_CHAINS,
@@ -1494,6 +1598,7 @@ export {
1494
1598
  ZERO_VALUE,
1495
1599
  _resetPaymasterConfigForTests,
1496
1600
  assembleUserOperation,
1601
+ assertDomainMatchesContract,
1497
1602
  buildAndSignSponsorAuth,
1498
1603
  buildBurnRequestTypedData,
1499
1604
  buildDelegationUserOp,
@@ -1517,6 +1622,7 @@ export {
1517
1622
  createLoginMessage,
1518
1623
  createPafiProxyTransport,
1519
1624
  decodeBatchExecuteCalls,
1625
+ defaultErrorTypeForStatus,
1520
1626
  delegateDirect,
1521
1627
  detectDelegateImpl,
1522
1628
  encodeBatchExecute,
@@ -1532,12 +1638,14 @@ export {
1532
1638
  getDummySignatureFor7702,
1533
1639
  getIssuer2 as getIssuer,
1534
1640
  getMintRequestNonce,
1641
+ getPafiServiceUrls,
1535
1642
  getPafiWebModalAdapter,
1536
1643
  getPaymasterConfig,
1537
1644
  getPointTokenBalance,
1538
1645
  getPointTokenIssuer,
1539
1646
  getIssuer as getPointTokenIssuerAddress,
1540
1647
  getReceiverConsentNonce,
1648
+ getSponsorAuthDomainAnchor,
1541
1649
  getTokenName,
1542
1650
  isActiveIssuer,
1543
1651
  isDelegatedTo,
@@ -1547,6 +1655,7 @@ export {
1547
1655
  isPaymasterError,
1548
1656
  issuerRegistryAbi,
1549
1657
  issuerRegistryGetIssuerFlatAbi,
1658
+ mintFeeWrapperAbi,
1550
1659
  mintRequestTypes,
1551
1660
  mintingOracleAbi,
1552
1661
  openPafiWebModal,