@alleyboss/micropay-solana-x402-paywall 3.3.8 → 3.3.10

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 CHANGED
@@ -4,9 +4,7 @@ var core = require('@x402/core');
4
4
  var types = require('@x402/core/types');
5
5
  var client = require('@x402/core/client');
6
6
  var svm = require('@x402/svm');
7
- var http = require('@x402/core/http');
8
7
  var web3_js = require('@solana/web3.js');
9
- var react = require('react');
10
8
  var bs58 = require('bs58');
11
9
  var jose = require('jose');
12
10
 
@@ -15,519 +13,6 @@ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
15
13
  var bs58__default = /*#__PURE__*/_interopDefault(bs58);
16
14
 
17
15
  // src/index.ts
18
-
19
- // src/client/types.ts
20
- var TOKEN_MINTS = {
21
- /** USDC on mainnet */
22
- USDC_MAINNET: "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
23
- /** USDC on devnet */
24
- USDC_DEVNET: "4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU",
25
- /** USDT on mainnet */
26
- USDT_MAINNET: "Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB"
27
- };
28
-
29
- // src/client/payment.ts
30
- function buildSolanaPayUrl(params) {
31
- const { recipient, amount, splToken, reference, label, message } = params;
32
- const url = new URL(`solana:${recipient}`);
33
- if (amount !== void 0) {
34
- url.searchParams.set("amount", amount.toString());
35
- }
36
- if (splToken) {
37
- url.searchParams.set("spl-token", splToken);
38
- }
39
- if (reference) {
40
- url.searchParams.set("reference", reference);
41
- }
42
- if (label) {
43
- url.searchParams.set("label", label);
44
- }
45
- if (message) {
46
- url.searchParams.set("message", message);
47
- }
48
- return url.toString();
49
- }
50
- function createPaymentFlow(config) {
51
- const { network, recipientWallet, amount, asset = "native", memo } = config;
52
- let decimals = 9;
53
- let mintAddress;
54
- if (asset === "usdc") {
55
- decimals = 6;
56
- mintAddress = network === "mainnet-beta" ? TOKEN_MINTS.USDC_MAINNET : TOKEN_MINTS.USDC_DEVNET;
57
- } else if (asset === "usdt") {
58
- decimals = 6;
59
- mintAddress = TOKEN_MINTS.USDT_MAINNET;
60
- } else if (typeof asset === "object" && "mint" in asset) {
61
- decimals = asset.decimals ?? 6;
62
- mintAddress = asset.mint;
63
- }
64
- const naturalAmount = Number(amount) / Math.pow(10, decimals);
65
- return {
66
- /** Get the payment configuration */
67
- getConfig: () => ({ ...config }),
68
- /** Get amount in natural display units (e.g., 0.01 SOL) */
69
- getDisplayAmount: () => naturalAmount,
70
- /** Get amount formatted with symbol */
71
- getFormattedAmount: () => {
72
- const symbol = asset === "native" ? "SOL" : asset === "usdc" ? "USDC" : asset === "usdt" ? "USDT" : "tokens";
73
- return `${naturalAmount.toFixed(decimals > 6 ? 4 : 2)} ${symbol}`;
74
- },
75
- /** Generate Solana Pay URL for QR codes */
76
- getSolanaPayUrl: (options = {}) => {
77
- return buildSolanaPayUrl({
78
- recipient: recipientWallet,
79
- amount: naturalAmount,
80
- splToken: mintAddress,
81
- label: options.label,
82
- reference: options.reference,
83
- message: memo
84
- });
85
- },
86
- /** Get the token mint address (undefined for native SOL) */
87
- getMintAddress: () => mintAddress,
88
- /** Check if this is a native SOL payment */
89
- isNativePayment: () => asset === "native",
90
- /** Get network information */
91
- getNetworkInfo: () => ({
92
- network,
93
- isMainnet: network === "mainnet-beta",
94
- explorerUrl: network === "mainnet-beta" ? "https://explorer.solana.com" : "https://explorer.solana.com?cluster=devnet"
95
- }),
96
- /** Build explorer URL for a transaction */
97
- getExplorerUrl: (signature) => {
98
- const baseUrl = "https://explorer.solana.com/tx";
99
- const cluster = network === "mainnet-beta" ? "" : "?cluster=devnet";
100
- return `${baseUrl}/${signature}${cluster}`;
101
- }
102
- };
103
- }
104
- function createPaymentReference() {
105
- if (typeof crypto !== "undefined" && crypto.randomUUID) {
106
- return crypto.randomUUID();
107
- }
108
- return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;
109
- }
110
- function createX402AuthorizationHeader(signature, paymentRequiredHeader) {
111
- const cleanHeader = paymentRequiredHeader.replace(/^[Xx]402\s+/, "");
112
- const required = http.decodePaymentRequiredHeader(cleanHeader);
113
- const accepts = Array.isArray(required.accepts) ? required.accepts[0] : required.accepts;
114
- const payload = {
115
- accepted: accepts,
116
- client: {
117
- scheme: accepts.scheme,
118
- // TypeScript knows this exists on PaymentRequirements
119
- network: accepts.network
120
- },
121
- payment: {
122
- signature
123
- }
124
- };
125
- const token = http.encodePaymentSignatureHeader(payload);
126
- return `x402 ${token}`;
127
- }
128
- async function sendSolanaPayment({
129
- connection,
130
- wallet,
131
- recipientAddress,
132
- amount,
133
- // memo, // TODO: Add memo support to transaction
134
- commitment = "confirmed"
135
- }) {
136
- if (!wallet.publicKey) {
137
- throw new Error("Wallet not connected");
138
- }
139
- if (amount <= 0n) {
140
- throw new Error("Amount must be greater than 0");
141
- }
142
- try {
143
- const recipientPubkey = new web3_js.PublicKey(recipientAddress);
144
- const transaction = new web3_js.Transaction().add(
145
- web3_js.SystemProgram.transfer({
146
- fromPubkey: wallet.publicKey,
147
- toPubkey: recipientPubkey,
148
- lamports: amount
149
- })
150
- );
151
- const { blockhash, lastValidBlockHeight } = await connection.getLatestBlockhash(commitment);
152
- transaction.recentBlockhash = blockhash;
153
- transaction.feePayer = wallet.publicKey;
154
- const signature = await wallet.sendTransaction(transaction, connection);
155
- await connection.confirmTransaction({
156
- signature,
157
- blockhash,
158
- lastValidBlockHeight
159
- }, commitment);
160
- return {
161
- signature,
162
- amountSol: Number(amount) / web3_js.LAMPORTS_PER_SOL
163
- };
164
- } catch (error) {
165
- console.error("Payment failed:", error);
166
- throw new Error(error.message || "Payment failed");
167
- }
168
- }
169
- function usePaywallResource({
170
- url,
171
- connection,
172
- wallet
173
- }) {
174
- const [data, setData] = react.useState(null);
175
- const [isLocked, setIsLocked] = react.useState(true);
176
- const [isLoading, setIsLoading] = react.useState(true);
177
- const [error, setError] = react.useState(null);
178
- const [paymentHeader, setPaymentHeader] = react.useState(null);
179
- const [price, setPrice] = react.useState();
180
- const [recipient, setRecipient] = react.useState();
181
- const fetchData = react.useCallback(async (authHeader) => {
182
- setIsLoading(true);
183
- setError(null);
184
- try {
185
- const headers = {
186
- "Content-Type": "application/json"
187
- };
188
- if (authHeader) {
189
- headers["Authorization"] = authHeader;
190
- }
191
- const res = await fetch(url, {
192
- headers,
193
- credentials: "include"
194
- // Ensure cookies are sent/received
195
- });
196
- if (res.status === 402) {
197
- const wwwAuth = res.headers.get("WWW-Authenticate") || res.headers.get("Payment-Required");
198
- const errorReason = res.headers.get("X-Payment-Error");
199
- console.log("[usePaywallResource] 402 Response. Header:", wwwAuth, "Error:", errorReason);
200
- if (authHeader && errorReason) {
201
- console.error("[usePaywallResource] Verification Failed:", errorReason);
202
- setError(`Verification Failed: ${errorReason}`);
203
- }
204
- if (wwwAuth) {
205
- setPaymentHeader(wwwAuth);
206
- try {
207
- const { decodePaymentRequiredHeader: decodePaymentRequiredHeader2 } = await import('@x402/core/http');
208
- const cleanHeader = wwwAuth.replace(/^[Xx]402\s+/, "");
209
- const decoded = decodePaymentRequiredHeader2(cleanHeader);
210
- console.log("[usePaywallResource] Decoded header:", decoded);
211
- const accepts = Array.isArray(decoded.accepts) ? decoded.accepts[0] : decoded.accepts;
212
- console.log("[usePaywallResource] Accepts:", accepts);
213
- if (accepts) {
214
- const amountStr = accepts.amount || accepts.price || accepts.maxAmountRequired || "0";
215
- setPrice(BigInt(amountStr));
216
- setRecipient(accepts.payTo);
217
- console.log("[usePaywallResource] Set price:", amountStr, "recipient:", accepts.payTo);
218
- } else {
219
- console.warn("[usePaywallResource] No accepts found in header");
220
- }
221
- } catch (e) {
222
- console.warn("[usePaywallResource] Failed to parse x402 header:", e);
223
- }
224
- } else {
225
- console.warn("[usePaywallResource] 402 response missing WWW-Authenticate header");
226
- }
227
- setIsLocked(true);
228
- setData(null);
229
- } else if (res.ok) {
230
- const json = await res.json();
231
- setData(json);
232
- setIsLocked(false);
233
- } else {
234
- throw new Error(`Request failed with status ${res.status}`);
235
- }
236
- } catch (err) {
237
- setError(err.message || "Failed to fetch resource");
238
- } finally {
239
- setIsLoading(false);
240
- }
241
- }, [url]);
242
- react.useEffect(() => {
243
- fetchData();
244
- }, [fetchData]);
245
- const unlock = react.useCallback(async () => {
246
- if (!paymentHeader || !price || !recipient) {
247
- setError("Missing payment requirements");
248
- return;
249
- }
250
- setIsLoading(true);
251
- try {
252
- const { signature } = await sendSolanaPayment({
253
- connection,
254
- wallet,
255
- recipientAddress: recipient,
256
- amount: price
257
- });
258
- const authHeader = createX402AuthorizationHeader(signature, paymentHeader);
259
- await fetchData(authHeader);
260
- } catch (err) {
261
- console.error("Unlock failed", err);
262
- setError(err.message || "Payment/Unlock failed");
263
- setIsLoading(false);
264
- }
265
- }, [connection, wallet, paymentHeader, price, recipient, fetchData]);
266
- return {
267
- data,
268
- isLocked,
269
- isLoading,
270
- price,
271
- recipient,
272
- error,
273
- unlock
274
- };
275
- }
276
-
277
- // src/pricing/utils.ts
278
- function lamportsToSol(lamports) {
279
- return Number(lamports) / 1e9;
280
- }
281
-
282
- // src/pricing/index.ts
283
- var priceCache = null;
284
- var currentConfig = {};
285
- function configurePricing(newConfig) {
286
- currentConfig = { ...currentConfig, ...newConfig };
287
- }
288
- var PROVIDERS = [
289
- {
290
- name: "coincap",
291
- url: "https://api.coincap.io/v2/assets/solana",
292
- parse: (data) => parseFloat(data.data?.priceUsd || "0")
293
- },
294
- {
295
- name: "binance",
296
- url: "https://api.binance.com/api/v3/ticker/price?symbol=SOLUSDT",
297
- parse: (data) => parseFloat(data.price || "0")
298
- },
299
- {
300
- name: "coingecko",
301
- url: "https://api.coingecko.com/api/v3/simple/price?ids=solana&vs_currencies=usd",
302
- parse: (data) => data.solana?.usd || 0
303
- },
304
- {
305
- name: "kraken",
306
- url: "https://api.kraken.com/0/public/Ticker?pair=SOLUSD",
307
- parse: (data) => parseFloat(data.result?.SOLUSD?.c?.[0] || "0")
308
- }
309
- ];
310
- async function fetchFromProvider(provider, timeout) {
311
- const controller = new AbortController();
312
- const timeoutId = setTimeout(() => controller.abort(), timeout);
313
- try {
314
- const response = await fetch(provider.url, {
315
- headers: { "Accept": "application/json" },
316
- signal: controller.signal
317
- });
318
- if (!response.ok) {
319
- throw new Error(`HTTP ${response.status}`);
320
- }
321
- const data = await response.json();
322
- const price = provider.parse(data);
323
- if (!price || price <= 0) {
324
- throw new Error("Invalid price");
325
- }
326
- return { price, source: provider.name };
327
- } finally {
328
- clearTimeout(timeoutId);
329
- }
330
- }
331
- async function fetchPriceParallel(timeout) {
332
- const promises = PROVIDERS.map(
333
- (provider) => fetchFromProvider(provider, timeout).catch(() => null)
334
- );
335
- const results = await Promise.all(promises);
336
- const validResult = results.find((r) => r !== null);
337
- if (validResult) {
338
- return validResult;
339
- }
340
- throw new Error("All providers failed");
341
- }
342
- async function fetchPriceSequential(timeout) {
343
- for (const provider of PROVIDERS) {
344
- try {
345
- return await fetchFromProvider(provider, timeout);
346
- } catch {
347
- continue;
348
- }
349
- }
350
- throw new Error("All providers failed");
351
- }
352
- async function getSolPrice() {
353
- const cacheTTL = currentConfig.cacheTTL ?? 6e4;
354
- const timeout = currentConfig.timeout ?? 3e3;
355
- const useParallel = currentConfig.parallelFetch ?? true;
356
- const now = Date.now();
357
- if (priceCache && now - priceCache.timestamp < cacheTTL) {
358
- return priceCache.data;
359
- }
360
- if (currentConfig.customProvider) {
361
- try {
362
- const price = await currentConfig.customProvider();
363
- if (price > 0) {
364
- const data = {
365
- solPrice: price,
366
- fetchedAt: /* @__PURE__ */ new Date(),
367
- source: "custom"
368
- };
369
- priceCache = { data, timestamp: now };
370
- return data;
371
- }
372
- } catch {
373
- }
374
- }
375
- try {
376
- const result = useParallel ? await fetchPriceParallel(timeout) : await fetchPriceSequential(timeout);
377
- const data = {
378
- solPrice: result.price,
379
- fetchedAt: /* @__PURE__ */ new Date(),
380
- source: result.source
381
- };
382
- priceCache = { data, timestamp: now };
383
- return data;
384
- } catch {
385
- if (priceCache) {
386
- return {
387
- ...priceCache.data,
388
- source: `${priceCache.data.source} (stale)`
389
- };
390
- }
391
- throw new Error(
392
- "Failed to fetch SOL price from all providers. Configure a custom provider or ensure network connectivity."
393
- );
394
- }
395
- }
396
- async function lamportsToUsd(lamports) {
397
- const { solPrice } = await getSolPrice();
398
- const sol = Number(lamports) / 1e9;
399
- return sol * solPrice;
400
- }
401
- async function usdToLamports(usd) {
402
- const { solPrice } = await getSolPrice();
403
- const sol = usd / solPrice;
404
- return BigInt(Math.floor(sol * 1e9));
405
- }
406
- async function formatPriceDisplay(lamports) {
407
- const { solPrice } = await getSolPrice();
408
- const sol = Number(lamports) / 1e9;
409
- const usd = sol * solPrice;
410
- return `${sol.toFixed(4)} SOL (~$${usd.toFixed(2)})`;
411
- }
412
- function formatPriceSync(lamports, solPrice) {
413
- const sol = Number(lamports) / 1e9;
414
- const usd = sol * solPrice;
415
- return {
416
- sol,
417
- usd,
418
- formatted: `${sol.toFixed(4)} SOL (~$${usd.toFixed(2)})`
419
- };
420
- }
421
- function clearPriceCache() {
422
- priceCache = null;
423
- }
424
- function getProviders() {
425
- return PROVIDERS.map((p) => ({ name: p.name, url: p.url }));
426
- }
427
-
428
- // src/client/hooks.ts
429
- function usePricing(refreshIntervalMs = 6e4) {
430
- const [priceData, setPriceData] = react.useState(null);
431
- const [isLoading, setIsLoading] = react.useState(true);
432
- const [error, setError] = react.useState(null);
433
- const intervalRef = react.useRef(null);
434
- const fetchPrice = react.useCallback(async () => {
435
- try {
436
- setIsLoading(true);
437
- setError(null);
438
- const data = await getSolPrice();
439
- setPriceData(data);
440
- } catch (err) {
441
- setError(err instanceof Error ? err.message : "Failed to fetch price");
442
- } finally {
443
- setIsLoading(false);
444
- }
445
- }, []);
446
- react.useEffect(() => {
447
- fetchPrice();
448
- if (refreshIntervalMs > 0) {
449
- intervalRef.current = setInterval(fetchPrice, refreshIntervalMs);
450
- }
451
- return () => {
452
- if (intervalRef.current) {
453
- clearInterval(intervalRef.current);
454
- }
455
- };
456
- }, [fetchPrice, refreshIntervalMs]);
457
- return {
458
- solPrice: priceData?.solPrice ?? null,
459
- source: priceData?.source ?? null,
460
- fetchedAt: priceData?.fetchedAt ?? null,
461
- isLoading,
462
- error,
463
- refresh: fetchPrice
464
- };
465
- }
466
- function useLamportsToUsd(lamports) {
467
- const { solPrice, isLoading } = usePricing();
468
- if (isLoading || !solPrice || lamports === null) {
469
- return { usd: null, formatted: null, isLoading };
470
- }
471
- const lamportsBigInt = typeof lamports === "number" ? BigInt(lamports) : lamports;
472
- const sol = Number(lamportsBigInt) / 1e9;
473
- const usd = sol * solPrice;
474
- return {
475
- usd,
476
- formatted: `$${usd.toFixed(2)}`,
477
- isLoading: false
478
- };
479
- }
480
- function useMicropay() {
481
- const [status, setStatus] = react.useState("idle");
482
- const [error, setError] = react.useState(null);
483
- const [signature, setSignature] = react.useState(null);
484
- const reset = react.useCallback(() => {
485
- setStatus("idle");
486
- setError(null);
487
- setSignature(null);
488
- }, []);
489
- const pay = react.useCallback(async (_options) => {
490
- setStatus("pending");
491
- setError(null);
492
- try {
493
- throw new Error(
494
- "useMicropay requires implementation of onSign/onSend callbacks. See documentation for wallet adapter integration."
495
- );
496
- } catch (err) {
497
- const errorMessage = err instanceof Error ? err.message : "Payment failed";
498
- setError(errorMessage);
499
- setStatus("error");
500
- return { success: false, error: errorMessage };
501
- }
502
- }, []);
503
- return {
504
- status,
505
- error,
506
- signature,
507
- pay,
508
- reset
509
- };
510
- }
511
- function useFormatPrice(lamports) {
512
- const { solPrice, isLoading } = usePricing();
513
- if (isLoading || !solPrice || lamports === null) {
514
- return {
515
- sol: null,
516
- usd: null,
517
- formatted: "Loading...",
518
- isLoading
519
- };
520
- }
521
- const lamportsBigInt = typeof lamports === "number" ? BigInt(lamports) : lamports;
522
- const sol = Number(lamportsBigInt) / 1e9;
523
- const usd = sol * solPrice;
524
- return {
525
- sol,
526
- usd,
527
- formatted: `${sol.toFixed(4)} SOL (~$${usd.toFixed(2)})`,
528
- isLoading: false
529
- };
530
- }
531
16
  var LocalSvmFacilitator = class {
532
17
  scheme = "exact";
533
18
  caipFamily = "solana:*";
@@ -1080,15 +565,162 @@ async function getRemainingCredits(token, secret) {
1080
565
  };
1081
566
  }
1082
567
 
568
+ // src/pricing/utils.ts
569
+ function lamportsToSol(lamports) {
570
+ return Number(lamports) / 1e9;
571
+ }
572
+
573
+ // src/pricing/index.ts
574
+ var priceCache = null;
575
+ var currentConfig = {};
576
+ function configurePricing(newConfig) {
577
+ currentConfig = { ...currentConfig, ...newConfig };
578
+ }
579
+ var PROVIDERS = [
580
+ {
581
+ name: "coincap",
582
+ url: "https://api.coincap.io/v2/assets/solana",
583
+ parse: (data) => parseFloat(data.data?.priceUsd || "0")
584
+ },
585
+ {
586
+ name: "binance",
587
+ url: "https://api.binance.com/api/v3/ticker/price?symbol=SOLUSDT",
588
+ parse: (data) => parseFloat(data.price || "0")
589
+ },
590
+ {
591
+ name: "coingecko",
592
+ url: "https://api.coingecko.com/api/v3/simple/price?ids=solana&vs_currencies=usd",
593
+ parse: (data) => data.solana?.usd || 0
594
+ },
595
+ {
596
+ name: "kraken",
597
+ url: "https://api.kraken.com/0/public/Ticker?pair=SOLUSD",
598
+ parse: (data) => parseFloat(data.result?.SOLUSD?.c?.[0] || "0")
599
+ }
600
+ ];
601
+ async function fetchFromProvider(provider, timeout) {
602
+ const controller = new AbortController();
603
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
604
+ try {
605
+ const response = await fetch(provider.url, {
606
+ headers: { "Accept": "application/json" },
607
+ signal: controller.signal
608
+ });
609
+ if (!response.ok) {
610
+ throw new Error(`HTTP ${response.status}`);
611
+ }
612
+ const data = await response.json();
613
+ const price = provider.parse(data);
614
+ if (!price || price <= 0) {
615
+ throw new Error("Invalid price");
616
+ }
617
+ return { price, source: provider.name };
618
+ } finally {
619
+ clearTimeout(timeoutId);
620
+ }
621
+ }
622
+ async function fetchPriceParallel(timeout) {
623
+ const promises = PROVIDERS.map(
624
+ (provider) => fetchFromProvider(provider, timeout).catch(() => null)
625
+ );
626
+ const results = await Promise.all(promises);
627
+ const validResult = results.find((r) => r !== null);
628
+ if (validResult) {
629
+ return validResult;
630
+ }
631
+ throw new Error("All providers failed");
632
+ }
633
+ async function fetchPriceSequential(timeout) {
634
+ for (const provider of PROVIDERS) {
635
+ try {
636
+ return await fetchFromProvider(provider, timeout);
637
+ } catch {
638
+ continue;
639
+ }
640
+ }
641
+ throw new Error("All providers failed");
642
+ }
643
+ async function getSolPrice() {
644
+ const cacheTTL = currentConfig.cacheTTL ?? 6e4;
645
+ const timeout = currentConfig.timeout ?? 3e3;
646
+ const useParallel = currentConfig.parallelFetch ?? true;
647
+ const now = Date.now();
648
+ if (priceCache && now - priceCache.timestamp < cacheTTL) {
649
+ return priceCache.data;
650
+ }
651
+ if (currentConfig.customProvider) {
652
+ try {
653
+ const price = await currentConfig.customProvider();
654
+ if (price > 0) {
655
+ const data = {
656
+ solPrice: price,
657
+ fetchedAt: /* @__PURE__ */ new Date(),
658
+ source: "custom"
659
+ };
660
+ priceCache = { data, timestamp: now };
661
+ return data;
662
+ }
663
+ } catch {
664
+ }
665
+ }
666
+ try {
667
+ const result = useParallel ? await fetchPriceParallel(timeout) : await fetchPriceSequential(timeout);
668
+ const data = {
669
+ solPrice: result.price,
670
+ fetchedAt: /* @__PURE__ */ new Date(),
671
+ source: result.source
672
+ };
673
+ priceCache = { data, timestamp: now };
674
+ return data;
675
+ } catch {
676
+ if (priceCache) {
677
+ return {
678
+ ...priceCache.data,
679
+ source: `${priceCache.data.source} (stale)`
680
+ };
681
+ }
682
+ throw new Error(
683
+ "Failed to fetch SOL price from all providers. Configure a custom provider or ensure network connectivity."
684
+ );
685
+ }
686
+ }
687
+ async function lamportsToUsd(lamports) {
688
+ const { solPrice } = await getSolPrice();
689
+ const sol = Number(lamports) / 1e9;
690
+ return sol * solPrice;
691
+ }
692
+ async function usdToLamports(usd) {
693
+ const { solPrice } = await getSolPrice();
694
+ const sol = usd / solPrice;
695
+ return BigInt(Math.floor(sol * 1e9));
696
+ }
697
+ async function formatPriceDisplay(lamports) {
698
+ const { solPrice } = await getSolPrice();
699
+ const sol = Number(lamports) / 1e9;
700
+ const usd = sol * solPrice;
701
+ return `${sol.toFixed(4)} SOL (~$${usd.toFixed(2)})`;
702
+ }
703
+ function formatPriceSync(lamports, solPrice) {
704
+ const sol = Number(lamports) / 1e9;
705
+ const usd = sol * solPrice;
706
+ return {
707
+ sol,
708
+ usd,
709
+ formatted: `${sol.toFixed(4)} SOL (~$${usd.toFixed(2)})`
710
+ };
711
+ }
712
+ function clearPriceCache() {
713
+ priceCache = null;
714
+ }
715
+ function getProviders() {
716
+ return PROVIDERS.map((p) => ({ name: p.name, url: p.url }));
717
+ }
718
+
1083
719
  exports.LocalSvmFacilitator = LocalSvmFacilitator;
1084
720
  exports.addCredits = addCredits;
1085
- exports.buildSolanaPayUrl = buildSolanaPayUrl;
1086
721
  exports.clearPriceCache = clearPriceCache;
1087
722
  exports.configurePricing = configurePricing;
1088
723
  exports.createCreditSession = createCreditSession;
1089
- exports.createPaymentFlow = createPaymentFlow;
1090
- exports.createPaymentReference = createPaymentReference;
1091
- exports.createX402AuthorizationHeader = createX402AuthorizationHeader;
1092
724
  exports.executeAgentPayment = executeAgentPayment;
1093
725
  exports.formatPriceDisplay = formatPriceDisplay;
1094
726
  exports.formatPriceSync = formatPriceSync;
@@ -1101,14 +733,8 @@ exports.hasAgentSufficientBalance = hasAgentSufficientBalance;
1101
733
  exports.keypairFromBase58 = keypairFromBase58;
1102
734
  exports.lamportsToSol = lamportsToSol;
1103
735
  exports.lamportsToUsd = lamportsToUsd;
1104
- exports.sendSolanaPayment = sendSolanaPayment;
1105
736
  exports.usdToLamports = usdToLamports;
1106
737
  exports.useCredit = useCredit;
1107
- exports.useFormatPrice = useFormatPrice;
1108
- exports.useLamportsToUsd = useLamportsToUsd;
1109
- exports.useMicropay = useMicropay;
1110
- exports.usePaywallResource = usePaywallResource;
1111
- exports.usePricing = usePricing;
1112
738
  exports.validateCreditSession = validateCreditSession;
1113
739
  Object.keys(core).forEach(function (k) {
1114
740
  if (k !== 'default' && !Object.prototype.hasOwnProperty.call(exports, k)) Object.defineProperty(exports, k, {