@alleyboss/micropay-solana-x402-paywall 3.1.0 → 3.1.2
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 +22 -2
- package/dist/next/index.cjs +14 -3
- package/dist/next/index.js +14 -3
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -120,12 +120,32 @@ 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
|
-
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
### 🆚 Hosted vs. Self-Sovereign Mode
|
|
126
|
+
|
|
127
|
+
| Feature | Hosted Mode (Default) | Self-Sovereign Mode |
|
|
128
|
+
|---------|----------------------|---------------------|
|
|
129
|
+
| **Verification** | Verified by x402.org | Verified by **You** (Local RPC) |
|
|
130
|
+
| **Trust** | Trust x402 Facilitator | Trustless / Trust Your Node |
|
|
131
|
+
| **Privacy** | Metadata sent to facilitator | No external data sharing |
|
|
132
|
+
| **Setup** | Zero-config | Requires RPC URL |
|
|
133
|
+
| **Best For** | Quick startups, MVPs | Production, High-Volume, Agents |
|
|
124
134
|
|
|
125
135
|
## 🤖 AI Agent Payments
|
|
126
136
|
|
|
127
137
|
Enable autonomous AI agents to pay for premium API access.
|
|
128
138
|
|
|
139
|
+
```mermaid
|
|
140
|
+
flowchart LR
|
|
141
|
+
A[AI Agent] -->|1. Detects Paywall| B(Check Wallet)
|
|
142
|
+
B -->|2. Sufficient Balance?| C{Pay?}
|
|
143
|
+
C -- Yes --> D[Sign & Send Tx]
|
|
144
|
+
D --> E[Wait for Confirmation]
|
|
145
|
+
E -->|3. Success| F[Retry Request + Proof]
|
|
146
|
+
F --> G((Unlock Data))
|
|
147
|
+
```
|
|
148
|
+
|
|
129
149
|
```typescript
|
|
130
150
|
import { executeAgentPayment } from '@alleyboss/micropay-solana-x402-paywall/agent';
|
|
131
151
|
import { Keypair, Connection } from '@solana/web3.js';
|
|
@@ -137,7 +157,7 @@ const result = await executeAgentPayment({
|
|
|
137
157
|
agentKeypair,
|
|
138
158
|
recipientAddress: 'CREATOR_WALLET',
|
|
139
159
|
amountLamports: 2_000_000n,
|
|
140
|
-
priorityFee: { enabled: true, microLamports: 10000 },
|
|
160
|
+
priorityFee: { enabled: true, microLamports: 10000 },
|
|
141
161
|
});
|
|
142
162
|
|
|
143
163
|
if (result.success) {
|
package/dist/next/index.cjs
CHANGED
|
@@ -65,23 +65,31 @@ 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] Requirements - Amount: ${requiredAmount}, PayTo: ${payTo}`);
|
|
73
|
+
console.log(`[LocalSvmFacilitator] Full Requirements:`, JSON.stringify(requirements));
|
|
68
74
|
const tx = await this.connection.getParsedTransaction(signature, {
|
|
69
75
|
maxSupportedTransactionVersion: 0,
|
|
70
76
|
commitment: "confirmed"
|
|
71
77
|
});
|
|
72
78
|
if (!tx) {
|
|
79
|
+
console.error("[LocalSvmFacilitator] Transaction not found or not confirmed");
|
|
73
80
|
return { isValid: false, invalidReason: "Transaction not found or not confirmed" };
|
|
74
81
|
}
|
|
75
|
-
|
|
76
|
-
const requiredAmount = BigInt(requirements.amount);
|
|
82
|
+
console.log("[LocalSvmFacilitator] Transaction found. Parsing instructions...");
|
|
77
83
|
const instructions = tx.transaction.message.instructions;
|
|
78
84
|
let paidAmount = 0n;
|
|
79
85
|
let payer = void 0;
|
|
80
86
|
for (const ix of instructions) {
|
|
81
87
|
if ("program" in ix && ix.program === "system") {
|
|
82
88
|
const parsed = ix.parsed;
|
|
89
|
+
console.log(`[LocalSvmFacilitator] Inspecting IX:`, JSON.stringify(parsed));
|
|
83
90
|
if (parsed.type === "transfer") {
|
|
84
91
|
const info = parsed.info;
|
|
92
|
+
console.log(`[LocalSvmFacilitator] Found transfer: ${info.lamports} lamports to ${info.destination}`);
|
|
85
93
|
if (info.destination === payTo) {
|
|
86
94
|
paidAmount += BigInt(info.lamports);
|
|
87
95
|
if (!payer) payer = info.source;
|
|
@@ -89,12 +97,15 @@ var LocalSvmFacilitator = class {
|
|
|
89
97
|
}
|
|
90
98
|
}
|
|
91
99
|
}
|
|
100
|
+
console.log(`[LocalSvmFacilitator] Total Paid Correctly: ${paidAmount}`);
|
|
92
101
|
if (paidAmount >= requiredAmount) {
|
|
102
|
+
console.log("[LocalSvmFacilitator] Verification SUCCESS");
|
|
93
103
|
return {
|
|
94
104
|
isValid: true,
|
|
95
105
|
payer: payer || tx.transaction.message.accountKeys[0].pubkey.toBase58()
|
|
96
106
|
};
|
|
97
107
|
}
|
|
108
|
+
console.error(`[LocalSvmFacilitator] Verification FAILED. Paid: ${paidAmount}, Required: ${requiredAmount}`);
|
|
98
109
|
return {
|
|
99
110
|
isValid: false,
|
|
100
111
|
invalidReason: `Insufficient payment. Required: ${requiredAmount}, Found: ${paidAmount}`,
|
|
@@ -149,7 +160,7 @@ function createX402Middleware(config) {
|
|
|
149
160
|
accepts: {
|
|
150
161
|
scheme: "exact",
|
|
151
162
|
payTo: config.walletAddress,
|
|
152
|
-
|
|
163
|
+
amount: config.price?.toString() || "0",
|
|
153
164
|
network: config.network === "mainnet-beta" ? "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp" : "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
|
|
154
165
|
asset: "native"
|
|
155
166
|
}
|
package/dist/next/index.js
CHANGED
|
@@ -64,23 +64,31 @@ 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] Requirements - Amount: ${requiredAmount}, PayTo: ${payTo}`);
|
|
72
|
+
console.log(`[LocalSvmFacilitator] Full Requirements:`, JSON.stringify(requirements));
|
|
67
73
|
const tx = await this.connection.getParsedTransaction(signature, {
|
|
68
74
|
maxSupportedTransactionVersion: 0,
|
|
69
75
|
commitment: "confirmed"
|
|
70
76
|
});
|
|
71
77
|
if (!tx) {
|
|
78
|
+
console.error("[LocalSvmFacilitator] Transaction not found or not confirmed");
|
|
72
79
|
return { isValid: false, invalidReason: "Transaction not found or not confirmed" };
|
|
73
80
|
}
|
|
74
|
-
|
|
75
|
-
const requiredAmount = BigInt(requirements.amount);
|
|
81
|
+
console.log("[LocalSvmFacilitator] Transaction found. Parsing instructions...");
|
|
76
82
|
const instructions = tx.transaction.message.instructions;
|
|
77
83
|
let paidAmount = 0n;
|
|
78
84
|
let payer = void 0;
|
|
79
85
|
for (const ix of instructions) {
|
|
80
86
|
if ("program" in ix && ix.program === "system") {
|
|
81
87
|
const parsed = ix.parsed;
|
|
88
|
+
console.log(`[LocalSvmFacilitator] Inspecting IX:`, JSON.stringify(parsed));
|
|
82
89
|
if (parsed.type === "transfer") {
|
|
83
90
|
const info = parsed.info;
|
|
91
|
+
console.log(`[LocalSvmFacilitator] Found transfer: ${info.lamports} lamports to ${info.destination}`);
|
|
84
92
|
if (info.destination === payTo) {
|
|
85
93
|
paidAmount += BigInt(info.lamports);
|
|
86
94
|
if (!payer) payer = info.source;
|
|
@@ -88,12 +96,15 @@ var LocalSvmFacilitator = class {
|
|
|
88
96
|
}
|
|
89
97
|
}
|
|
90
98
|
}
|
|
99
|
+
console.log(`[LocalSvmFacilitator] Total Paid Correctly: ${paidAmount}`);
|
|
91
100
|
if (paidAmount >= requiredAmount) {
|
|
101
|
+
console.log("[LocalSvmFacilitator] Verification SUCCESS");
|
|
92
102
|
return {
|
|
93
103
|
isValid: true,
|
|
94
104
|
payer: payer || tx.transaction.message.accountKeys[0].pubkey.toBase58()
|
|
95
105
|
};
|
|
96
106
|
}
|
|
107
|
+
console.error(`[LocalSvmFacilitator] Verification FAILED. Paid: ${paidAmount}, Required: ${requiredAmount}`);
|
|
97
108
|
return {
|
|
98
109
|
isValid: false,
|
|
99
110
|
invalidReason: `Insufficient payment. Required: ${requiredAmount}, Found: ${paidAmount}`,
|
|
@@ -148,7 +159,7 @@ function createX402Middleware(config) {
|
|
|
148
159
|
accepts: {
|
|
149
160
|
scheme: "exact",
|
|
150
161
|
payTo: config.walletAddress,
|
|
151
|
-
|
|
162
|
+
amount: config.price?.toString() || "0",
|
|
152
163
|
network: config.network === "mainnet-beta" ? "solana:5eykt4UsFv8P8NJdTREpY1vzqKqZKvdp" : "solana:EtWTRABZaYq6iMfeYKouRu166VU2xqa1",
|
|
153
164
|
asset: "native"
|
|
154
165
|
}
|
package/package.json
CHANGED