@alleyboss/micropay-solana-x402-paywall 3.3.7 → 3.3.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.d.cts CHANGED
@@ -1,9 +1,101 @@
1
1
  export * from '@x402/core';
2
+ import { PaymentPayload, PaymentRequirements, VerifyResponse, SettleResponse, SupportedResponse, Network } from '@x402/core/types';
2
3
  export * from '@x402/core/types';
3
4
  export * from '@x402/core/client';
4
5
  export * from '@x402/svm';
5
- export { PaymentFlowConfig, PaymentResult, PaymentStatus, PaywallConfig, PaywallState, SendPaymentParams, SolanaPayUrlParams, WalletAdapterInterface, buildSolanaPayUrl, createPaymentFlow, createPaymentReference, createX402AuthorizationHeader, sendSolanaPayment, useFormatPrice, useLamportsToUsd, useMicropay, usePaywallResource, usePricing } from './client/index.cjs';
6
6
  export { AgentPaymentResult, CreditSessionClaims, CreditSessionConfig, CreditSessionData, CreditValidation, ExecuteAgentPaymentParams, UseCreditResult, addCredits, createCreditSession, executeAgentPayment, generateAgentKeypair, getAgentBalance, getRemainingCredits, hasAgentSufficientBalance, keypairFromBase58, useCredit, validateCreditSession } from './agent/index.cjs';
7
7
  export { CustomPriceProvider, PriceConfig, PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToSol, lamportsToUsd, usdToLamports } from './pricing/index.cjs';
8
8
  import '@solana/web3.js';
9
9
  import './types-BWYQMw03.cjs';
10
+
11
+ interface FacilitatorClient {
12
+ verify(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<VerifyResponse>;
13
+ settle(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<SettleResponse>;
14
+ getSupported(extensionKeys?: string[]): Promise<SupportedResponse>;
15
+ }
16
+ /**
17
+ * Local SVM Facilitator
18
+ *
19
+ * Verifies and settles Solana payments locally using a direct RPC connection,
20
+ * bypassing the need for a hosted facilitator service.
21
+ */
22
+ declare class LocalSvmFacilitator implements FacilitatorClient {
23
+ readonly scheme = "exact";
24
+ readonly caipFamily = "solana:*";
25
+ private connection;
26
+ constructor(rpcUrl: string);
27
+ /**
28
+ * Get supported payment kinds
29
+ * Mocking the response of the /supported endpoint
30
+ */
31
+ /**
32
+ * Network Constants - CAIP-2 format for x402 v2
33
+ * These match the official Solana chain IDs used by x402 protocol
34
+ */
35
+ private readonly NETWORKS;
36
+ /**
37
+ * DUMMY_FEE_PAYER Explanation (for auditors):
38
+ *
39
+ * In a HOSTED facilitator (like x402.org), the `feePayer` field in the
40
+ * SupportedResponse.extra specifies which address will pay transaction fees
41
+ * when the facilitator submits transactions on behalf of users.
42
+ *
43
+ * In LOCAL/SELF-SOVEREIGN mode (this implementation):
44
+ * - The USER pays their own transaction fees directly
45
+ * - The facilitator NEVER submits transactions - it only VERIFIES them
46
+ * - Therefore, no fee payer address is actually used
47
+ *
48
+ * However, the x402 protocol REQUIRES this field in the response schema.
49
+ * We use the System Program address (all 1s) as a placeholder because:
50
+ * 1. It's clearly not a real wallet (obvious placeholder)
51
+ * 2. It cannot receive funds or sign transactions
52
+ * 3. It signals to developers that fee paying is handled differently
53
+ *
54
+ * SECURITY NOTE: This is NOT a security risk because:
55
+ * - The fee payer is never used in verify() or settle() methods
56
+ * - Users sign and pay for their own transactions
57
+ * - The address is just a protocol-required placeholder
58
+ *
59
+ * @see https://docs.x402.org for protocol specification
60
+ */
61
+ private readonly DUMMY_FEE_PAYER;
62
+ /**
63
+ * Get supported payment kinds
64
+ * Returns x402 v2 compatible response with CAIP-2 network identifiers
65
+ *
66
+ * NOTE: The feePayer in extra.feePayer is a placeholder only.
67
+ * In self-sovereign mode, users pay their own transaction fees.
68
+ */
69
+ getSupported(_extensionKeys?: string[]): Promise<SupportedResponse>;
70
+ /**
71
+ * Get mechanism-specific extra data
72
+ */
73
+ getExtra(_network: Network): Record<string, unknown> | undefined;
74
+ /**
75
+ * Get default signers (not used for local verification usually, but required by interface)
76
+ */
77
+ getSigners(_network: string): string[];
78
+ /**
79
+ * Enable debug logging (disable in production)
80
+ */
81
+ private debug;
82
+ /**
83
+ * Verify a payment on-chain
84
+ */
85
+ verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
86
+ /**
87
+ * Fetch transaction with exponential backoff retry
88
+ */
89
+ private fetchTransactionWithRetry;
90
+ /**
91
+ * Sleep helper
92
+ */
93
+ private sleep;
94
+ /**
95
+ * Settle a payment (not applicable for direct chain verification, usually)
96
+ * But we must implement it. For 'exact', settlement is just verification + finality.
97
+ */
98
+ settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
99
+ }
100
+
101
+ export { LocalSvmFacilitator };
package/dist/index.d.ts CHANGED
@@ -1,9 +1,101 @@
1
1
  export * from '@x402/core';
2
+ import { PaymentPayload, PaymentRequirements, VerifyResponse, SettleResponse, SupportedResponse, Network } from '@x402/core/types';
2
3
  export * from '@x402/core/types';
3
4
  export * from '@x402/core/client';
4
5
  export * from '@x402/svm';
5
- export { PaymentFlowConfig, PaymentResult, PaymentStatus, PaywallConfig, PaywallState, SendPaymentParams, SolanaPayUrlParams, WalletAdapterInterface, buildSolanaPayUrl, createPaymentFlow, createPaymentReference, createX402AuthorizationHeader, sendSolanaPayment, useFormatPrice, useLamportsToUsd, useMicropay, usePaywallResource, usePricing } from './client/index.js';
6
6
  export { AgentPaymentResult, CreditSessionClaims, CreditSessionConfig, CreditSessionData, CreditValidation, ExecuteAgentPaymentParams, UseCreditResult, addCredits, createCreditSession, executeAgentPayment, generateAgentKeypair, getAgentBalance, getRemainingCredits, hasAgentSufficientBalance, keypairFromBase58, useCredit, validateCreditSession } from './agent/index.js';
7
7
  export { CustomPriceProvider, PriceConfig, PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToSol, lamportsToUsd, usdToLamports } from './pricing/index.js';
8
8
  import '@solana/web3.js';
9
9
  import './types-BWYQMw03.js';
10
+
11
+ interface FacilitatorClient {
12
+ verify(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<VerifyResponse>;
13
+ settle(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<SettleResponse>;
14
+ getSupported(extensionKeys?: string[]): Promise<SupportedResponse>;
15
+ }
16
+ /**
17
+ * Local SVM Facilitator
18
+ *
19
+ * Verifies and settles Solana payments locally using a direct RPC connection,
20
+ * bypassing the need for a hosted facilitator service.
21
+ */
22
+ declare class LocalSvmFacilitator implements FacilitatorClient {
23
+ readonly scheme = "exact";
24
+ readonly caipFamily = "solana:*";
25
+ private connection;
26
+ constructor(rpcUrl: string);
27
+ /**
28
+ * Get supported payment kinds
29
+ * Mocking the response of the /supported endpoint
30
+ */
31
+ /**
32
+ * Network Constants - CAIP-2 format for x402 v2
33
+ * These match the official Solana chain IDs used by x402 protocol
34
+ */
35
+ private readonly NETWORKS;
36
+ /**
37
+ * DUMMY_FEE_PAYER Explanation (for auditors):
38
+ *
39
+ * In a HOSTED facilitator (like x402.org), the `feePayer` field in the
40
+ * SupportedResponse.extra specifies which address will pay transaction fees
41
+ * when the facilitator submits transactions on behalf of users.
42
+ *
43
+ * In LOCAL/SELF-SOVEREIGN mode (this implementation):
44
+ * - The USER pays their own transaction fees directly
45
+ * - The facilitator NEVER submits transactions - it only VERIFIES them
46
+ * - Therefore, no fee payer address is actually used
47
+ *
48
+ * However, the x402 protocol REQUIRES this field in the response schema.
49
+ * We use the System Program address (all 1s) as a placeholder because:
50
+ * 1. It's clearly not a real wallet (obvious placeholder)
51
+ * 2. It cannot receive funds or sign transactions
52
+ * 3. It signals to developers that fee paying is handled differently
53
+ *
54
+ * SECURITY NOTE: This is NOT a security risk because:
55
+ * - The fee payer is never used in verify() or settle() methods
56
+ * - Users sign and pay for their own transactions
57
+ * - The address is just a protocol-required placeholder
58
+ *
59
+ * @see https://docs.x402.org for protocol specification
60
+ */
61
+ private readonly DUMMY_FEE_PAYER;
62
+ /**
63
+ * Get supported payment kinds
64
+ * Returns x402 v2 compatible response with CAIP-2 network identifiers
65
+ *
66
+ * NOTE: The feePayer in extra.feePayer is a placeholder only.
67
+ * In self-sovereign mode, users pay their own transaction fees.
68
+ */
69
+ getSupported(_extensionKeys?: string[]): Promise<SupportedResponse>;
70
+ /**
71
+ * Get mechanism-specific extra data
72
+ */
73
+ getExtra(_network: Network): Record<string, unknown> | undefined;
74
+ /**
75
+ * Get default signers (not used for local verification usually, but required by interface)
76
+ */
77
+ getSigners(_network: string): string[];
78
+ /**
79
+ * Enable debug logging (disable in production)
80
+ */
81
+ private debug;
82
+ /**
83
+ * Verify a payment on-chain
84
+ */
85
+ verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
86
+ /**
87
+ * Fetch transaction with exponential backoff retry
88
+ */
89
+ private fetchTransactionWithRetry;
90
+ /**
91
+ * Sleep helper
92
+ */
93
+ private sleep;
94
+ /**
95
+ * Settle a payment (not applicable for direct chain verification, usually)
96
+ * But we must implement it. For 'exact', settlement is just verification + finality.
97
+ */
98
+ settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
99
+ }
100
+
101
+ export { LocalSvmFacilitator };