@alleyboss/micropay-solana-x402-paywall 3.1.0 → 3.1.1

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/README.md CHANGED
@@ -120,12 +120,51 @@ const withMicropay = createX402Middleware({
120
120
  // The library will verify transactions locally using this RPC connection.
121
121
  rpcUrl: process.env.NEXT_PUBLIC_RPC_URL
122
122
  });
123
+ ### 🛡️ Verification Flow (Self-Sovereign Mode)
124
+
125
+ ```mermaid
126
+ sequenceDiagram
127
+ participant User
128
+ participant App
129
+ participant Lib as x402 Lib
130
+ participant RPC as Solana RPC
131
+
132
+ User->>App: Request Premium Content
133
+ App->>Lib: Create Payment Options
134
+ Lib-->>User: Return 402 + Payment Link
135
+ User->>RPC: Submit Transaction
136
+ User->>App: Send Receipt/Signature
137
+ App->>Lib: Verify Transaction
138
+ Lib->>RPC: Get Transaction Status (Local)
139
+ RPC-->>Lib: Confirmed
140
+ Lib-->>App: Valid Session Token
141
+ App-->>User: Unlock Content
123
142
  ```
124
143
 
144
+ ### 🆚 Hosted vs. Self-Sovereign Mode
145
+
146
+ | Feature | Hosted Mode (Default) | Self-Sovereign Mode |
147
+ |---------|----------------------|---------------------|
148
+ | **Verification** | Verified by x402.org | Verified by **You** (Local RPC) |
149
+ | **Trust** | Trust x402 Facilitator | Trustless / Trust Your Node |
150
+ | **Privacy** | Metadata sent to facilitator | No external data sharing |
151
+ | **Setup** | Zero-config | Requires RPC URL |
152
+ | **Best For** | Quick startups, MVPs | Production, High-Volume, Agents |
153
+
125
154
  ## 🤖 AI Agent Payments
126
155
 
127
156
  Enable autonomous AI agents to pay for premium API access.
128
157
 
158
+ ```mermaid
159
+ flowchart LR
160
+ A[AI Agent] -->|1. Detects Paywall| B(Check Wallet)
161
+ B -->|2. Sufficient Balance?| C{Pay?}
162
+ C -- Yes --> D[Sign & Send Tx]
163
+ D --> E[Wait for Confirmation]
164
+ E -->|3. Success| F[Retry Request + Proof]
165
+ F --> G((Unlock Data))
166
+ ```
167
+
129
168
  ```typescript
130
169
  import { executeAgentPayment } from '@alleyboss/micropay-solana-x402-paywall/agent';
131
170
  import { Keypair, Connection } from '@solana/web3.js';
@@ -137,7 +176,7 @@ const result = await executeAgentPayment({
137
176
  agentKeypair,
138
177
  recipientAddress: 'CREATOR_WALLET',
139
178
  amountLamports: 2_000_000n,
140
- priorityFee: { enabled: true, microLamports: 10000 }, // Priority Fees Supported
179
+ priorityFee: { enabled: true, microLamports: 10000 },
141
180
  });
142
181
 
143
182
  if (result.success) {
@@ -65,15 +65,20 @@ var LocalSvmFacilitator = class {
65
65
  if (!signature) {
66
66
  return { isValid: false, invalidReason: "Missing signature in payment payload" };
67
67
  }
68
+ const payTo = requirements.payTo;
69
+ const amountVal = requirements.amount || requirements.maxAmountRequired || "0";
70
+ const requiredAmount = BigInt(amountVal);
71
+ console.log(`[LocalSvmFacilitator] Verifying signature: ${signature}`);
72
+ console.log(`[LocalSvmFacilitator] Required Amount: ${requiredAmount}, PayTo: ${payTo}`);
68
73
  const tx = await this.connection.getParsedTransaction(signature, {
69
74
  maxSupportedTransactionVersion: 0,
70
75
  commitment: "confirmed"
71
76
  });
72
77
  if (!tx) {
78
+ console.error("[LocalSvmFacilitator] Transaction not found or not confirmed");
73
79
  return { isValid: false, invalidReason: "Transaction not found or not confirmed" };
74
80
  }
75
- const payTo = requirements.payTo;
76
- const requiredAmount = BigInt(requirements.amount);
81
+ console.log("[LocalSvmFacilitator] Transaction found. Parsing instructions...");
77
82
  const instructions = tx.transaction.message.instructions;
78
83
  let paidAmount = 0n;
79
84
  let payer = void 0;
@@ -82,6 +87,7 @@ var LocalSvmFacilitator = class {
82
87
  const parsed = ix.parsed;
83
88
  if (parsed.type === "transfer") {
84
89
  const info = parsed.info;
90
+ console.log(`[LocalSvmFacilitator] Found transfer: ${info.lamports} lamports to ${info.destination}`);
85
91
  if (info.destination === payTo) {
86
92
  paidAmount += BigInt(info.lamports);
87
93
  if (!payer) payer = info.source;
@@ -89,12 +95,15 @@ var LocalSvmFacilitator = class {
89
95
  }
90
96
  }
91
97
  }
98
+ console.log(`[LocalSvmFacilitator] Total Paid Correctly: ${paidAmount}`);
92
99
  if (paidAmount >= requiredAmount) {
100
+ console.log("[LocalSvmFacilitator] Verification SUCCESS");
93
101
  return {
94
102
  isValid: true,
95
103
  payer: payer || tx.transaction.message.accountKeys[0].pubkey.toBase58()
96
104
  };
97
105
  }
106
+ console.error(`[LocalSvmFacilitator] Verification FAILED. Paid: ${paidAmount}, Required: ${requiredAmount}`);
98
107
  return {
99
108
  isValid: false,
100
109
  invalidReason: `Insufficient payment. Required: ${requiredAmount}, Found: ${paidAmount}`,
@@ -149,7 +158,7 @@ function createX402Middleware(config) {
149
158
  accepts: {
150
159
  scheme: "exact",
151
160
  payTo: config.walletAddress,
152
- maxAmountRequired: config.price?.toString() || "0",
161
+ amount: config.price?.toString() || "0",
153
162
  network: config.network === "mainnet-beta" ? "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp" : "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
154
163
  asset: "native"
155
164
  }
@@ -64,15 +64,20 @@ var LocalSvmFacilitator = class {
64
64
  if (!signature) {
65
65
  return { isValid: false, invalidReason: "Missing signature in payment payload" };
66
66
  }
67
+ const payTo = requirements.payTo;
68
+ const amountVal = requirements.amount || requirements.maxAmountRequired || "0";
69
+ const requiredAmount = BigInt(amountVal);
70
+ console.log(`[LocalSvmFacilitator] Verifying signature: ${signature}`);
71
+ console.log(`[LocalSvmFacilitator] Required Amount: ${requiredAmount}, PayTo: ${payTo}`);
67
72
  const tx = await this.connection.getParsedTransaction(signature, {
68
73
  maxSupportedTransactionVersion: 0,
69
74
  commitment: "confirmed"
70
75
  });
71
76
  if (!tx) {
77
+ console.error("[LocalSvmFacilitator] Transaction not found or not confirmed");
72
78
  return { isValid: false, invalidReason: "Transaction not found or not confirmed" };
73
79
  }
74
- const payTo = requirements.payTo;
75
- const requiredAmount = BigInt(requirements.amount);
80
+ console.log("[LocalSvmFacilitator] Transaction found. Parsing instructions...");
76
81
  const instructions = tx.transaction.message.instructions;
77
82
  let paidAmount = 0n;
78
83
  let payer = void 0;
@@ -81,6 +86,7 @@ var LocalSvmFacilitator = class {
81
86
  const parsed = ix.parsed;
82
87
  if (parsed.type === "transfer") {
83
88
  const info = parsed.info;
89
+ console.log(`[LocalSvmFacilitator] Found transfer: ${info.lamports} lamports to ${info.destination}`);
84
90
  if (info.destination === payTo) {
85
91
  paidAmount += BigInt(info.lamports);
86
92
  if (!payer) payer = info.source;
@@ -88,12 +94,15 @@ var LocalSvmFacilitator = class {
88
94
  }
89
95
  }
90
96
  }
97
+ console.log(`[LocalSvmFacilitator] Total Paid Correctly: ${paidAmount}`);
91
98
  if (paidAmount >= requiredAmount) {
99
+ console.log("[LocalSvmFacilitator] Verification SUCCESS");
92
100
  return {
93
101
  isValid: true,
94
102
  payer: payer || tx.transaction.message.accountKeys[0].pubkey.toBase58()
95
103
  };
96
104
  }
105
+ console.error(`[LocalSvmFacilitator] Verification FAILED. Paid: ${paidAmount}, Required: ${requiredAmount}`);
97
106
  return {
98
107
  isValid: false,
99
108
  invalidReason: `Insufficient payment. Required: ${requiredAmount}, Found: ${paidAmount}`,
@@ -148,7 +157,7 @@ function createX402Middleware(config) {
148
157
  accepts: {
149
158
  scheme: "exact",
150
159
  payTo: config.walletAddress,
151
- maxAmountRequired: config.price?.toString() || "0",
160
+ amount: config.price?.toString() || "0",
152
161
  network: config.network === "mainnet-beta" ? "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp" : "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
153
162
  asset: "native"
154
163
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alleyboss/micropay-solana-x402-paywall",
3
- "version": "3.1.0",
3
+ "version": "3.1.1",
4
4
  "description": "Production-ready Solana micropayments library wrapper for official x402 SDK",
5
5
  "author": "AlleyBoss",
6
6
  "license": "MIT",