@alleyboss/micropay-solana-x402-paywall 2.0.1 β 2.0.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 +63 -115
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,165 +1,113 @@
|
|
|
1
1
|
# @alleyboss/micropay-solana-x402-paywall
|
|
2
2
|
|
|
3
|
-
> Production-ready Solana micropayments library implementing the x402 protocol
|
|
3
|
+
> Production-ready Solana micropayments library implementing the x402 protocol.
|
|
4
4
|
|
|
5
|
-
[](https://www.npmjs.com/package/@alleyboss/micropay-solana-x402-paywall)
|
|
6
6
|
[](https://opensource.org/licenses/MIT)
|
|
7
|
+
[](https://bundlephobia.com/package/@alleyboss/micropay-solana-x402-paywall)
|
|
7
8
|
|
|
8
|
-
##
|
|
9
|
+
## π What It Does
|
|
9
10
|
|
|
10
|
-
|
|
11
|
-
- β‘ **Solana Native** β Fast, low-cost SOL & USDC micropayments
|
|
12
|
-
- π **JWT Sessions** β Secure unlock tracking with anti-replay
|
|
13
|
-
- π¦ **Framework Agnostic** β Express, Next.js, Fastify ready
|
|
14
|
-
- π³ **Tree-shakeable** β Import only what you need (35KB full, 1-13KB per module)
|
|
15
|
-
- π° **SPL Tokens** β USDC, USDT, and custom token support
|
|
16
|
-
- π **Retry Logic** β Built-in resilience for RPC failures
|
|
17
|
-
|
|
18
|
-
## Installation
|
|
11
|
+
Turn any content into paid content with **one-time micropayments** on Solana. No subscriptions, no recurring chargesβjust pay to unlock.
|
|
19
12
|
|
|
20
13
|
```bash
|
|
21
14
|
npm install @alleyboss/micropay-solana-x402-paywall @solana/web3.js
|
|
22
15
|
```
|
|
23
16
|
|
|
24
|
-
##
|
|
17
|
+
## β¨ Features
|
|
18
|
+
|
|
19
|
+
| Feature | Description |
|
|
20
|
+
|---------|-------------|
|
|
21
|
+
| π° **SOL & USDC Payments** | Native SOL and SPL tokens (USDC, USDT) |
|
|
22
|
+
| π **x402 Protocol** | HTTP 402 Payment Required standard |
|
|
23
|
+
| π **JWT Sessions** | Secure unlock tracking with anti-replay |
|
|
24
|
+
| οΏ½οΈ **Signature Store** | Prevent double-spend at app layer |
|
|
25
|
+
| π **Express & Next.js** | Zero-boilerplate middleware |
|
|
26
|
+
| οΏ½ **Price Conversion** | USDβSOL with multi-provider fallback |
|
|
27
|
+
| π³ **Tree-Shakeable** | Import only what you need |
|
|
25
28
|
|
|
26
|
-
|
|
29
|
+
## π¦ Quick Example
|
|
27
30
|
|
|
28
31
|
```typescript
|
|
29
|
-
import { verifyPayment,
|
|
32
|
+
import { verifyPayment, createSession } from '@alleyboss/micropay-solana-x402-paywall';
|
|
30
33
|
|
|
31
|
-
//
|
|
34
|
+
// Verify on-chain payment
|
|
32
35
|
const result = await verifyPayment({
|
|
33
36
|
signature: 'tx...',
|
|
34
37
|
expectedRecipient: 'CreatorWallet',
|
|
35
38
|
expectedAmount: 10_000_000n, // 0.01 SOL
|
|
36
|
-
clientConfig: { network: 'devnet' },
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
// USDC payment
|
|
40
|
-
const usdcResult = await verifySPLPayment({
|
|
41
|
-
signature: 'tx...',
|
|
42
|
-
expectedRecipient: 'CreatorWallet',
|
|
43
|
-
expectedAmount: 1_000_000n, // 1 USDC
|
|
44
|
-
asset: 'usdc',
|
|
45
39
|
clientConfig: { network: 'mainnet-beta' },
|
|
46
40
|
});
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
### Express Middleware (Zero Boilerplate)
|
|
50
41
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
protectedPaths: ['/**'],
|
|
60
|
-
}));
|
|
61
|
-
|
|
62
|
-
app.get('/api/premium/content', (req, res) => {
|
|
63
|
-
res.json({ content: 'Premium!', wallet: req.session?.walletAddress });
|
|
64
|
-
});
|
|
42
|
+
// Create session for unlocked content
|
|
43
|
+
if (result.valid) {
|
|
44
|
+
const { token } = await createSession(
|
|
45
|
+
result.from!,
|
|
46
|
+
'article-123',
|
|
47
|
+
{ secret: process.env.SESSION_SECRET!, durationHours: 24 }
|
|
48
|
+
);
|
|
49
|
+
}
|
|
65
50
|
```
|
|
66
51
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
```typescript
|
|
70
|
-
// middleware.ts
|
|
71
|
-
import { createPaywallMiddleware } from '@alleyboss/micropay-solana-x402-paywall/middleware';
|
|
72
|
-
|
|
73
|
-
export const middleware = createPaywallMiddleware({
|
|
74
|
-
sessionSecret: process.env.SESSION_SECRET!,
|
|
75
|
-
protectedPaths: ['/api/premium/*', '/api/content/*'],
|
|
76
|
-
});
|
|
77
|
-
|
|
78
|
-
export const config = { matcher: ['/api/premium/:path*'] };
|
|
79
|
-
```
|
|
52
|
+
## π§ Modules
|
|
80
53
|
|
|
81
|
-
|
|
54
|
+
9 tree-shakeable entry points for minimal bundle size:
|
|
82
55
|
|
|
83
56
|
```typescript
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
// Development
|
|
87
|
-
const store = createMemoryStore();
|
|
57
|
+
// Core verification
|
|
58
|
+
import { verifyPayment, verifySPLPayment } from '@alleyboss/micropay-solana-x402-paywall/solana';
|
|
88
59
|
|
|
89
|
-
//
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
// Check before verification
|
|
93
|
-
if (await store.hasBeenUsed(signature)) {
|
|
94
|
-
throw new Error('Payment already used');
|
|
95
|
-
}
|
|
60
|
+
// Session management
|
|
61
|
+
import { createSession, validateSession } from '@alleyboss/micropay-solana-x402-paywall/session';
|
|
96
62
|
|
|
97
|
-
//
|
|
98
|
-
|
|
99
|
-
```
|
|
63
|
+
// x402 protocol
|
|
64
|
+
import { buildPaymentRequirement } from '@alleyboss/micropay-solana-x402-paywall/x402';
|
|
100
65
|
|
|
101
|
-
|
|
66
|
+
// Express/Next.js middleware
|
|
67
|
+
import { createExpressMiddleware, createPaywallMiddleware } from '@alleyboss/micropay-solana-x402-paywall/middleware';
|
|
102
68
|
|
|
103
|
-
|
|
104
|
-
import {
|
|
69
|
+
// Anti-replay signature store
|
|
70
|
+
import { createMemoryStore, createRedisStore } from '@alleyboss/micropay-solana-x402-paywall/store';
|
|
105
71
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
recipientWallet: 'CreatorWallet',
|
|
109
|
-
amount: 10_000_000n,
|
|
110
|
-
});
|
|
72
|
+
// Client-side helpers
|
|
73
|
+
import { createPaymentFlow, buildSolanaPayUrl } from '@alleyboss/micropay-solana-x402-paywall/client';
|
|
111
74
|
|
|
112
|
-
//
|
|
113
|
-
|
|
75
|
+
// Price conversion (4-provider rotation)
|
|
76
|
+
import { getSolPrice, formatPriceDisplay, configurePricing } from '@alleyboss/micropay-solana-x402-paywall/pricing';
|
|
114
77
|
|
|
115
|
-
//
|
|
116
|
-
|
|
117
|
-
// "0.0100 SOL (~$1.50)"
|
|
78
|
+
// Retry utilities
|
|
79
|
+
import { withRetry } from '@alleyboss/micropay-solana-x402-paywall/utils';
|
|
118
80
|
```
|
|
119
81
|
|
|
120
|
-
##
|
|
121
|
-
|
|
122
|
-
Import only what you need for minimal bundle size:
|
|
82
|
+
## π₯ New in v2.0
|
|
123
83
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
| `@.../store` | 2.6KB | `createMemoryStore`, `createRedisStore` |
|
|
131
|
-
| `@.../client` | 3.3KB | `createPaymentFlow`, `buildSolanaPayUrl` |
|
|
132
|
-
| `@.../pricing` | 2KB | `getSolPrice`, `formatPriceDisplay` |
|
|
133
|
-
| `@.../utils` | 1.7KB | `withRetry`, `isRetryableRPCError` |
|
|
84
|
+
- **SPL Token Support** β USDC, USDT, custom tokens
|
|
85
|
+
- **Multi-Provider Pricing** β CoinCap β Binance β CoinGecko β Kraken fallback
|
|
86
|
+
- **Custom Price API** β `configurePricing({ customProvider: yourFn })`
|
|
87
|
+
- **Express Middleware** β Works with Express, Fastify, Polka
|
|
88
|
+
- **Signature Store** β Memory & Redis adapters for anti-replay
|
|
89
|
+
- **Client Helpers** β Solana Pay URLs for QR codes
|
|
134
90
|
|
|
135
|
-
##
|
|
91
|
+
## π Documentation
|
|
136
92
|
|
|
137
|
-
Full
|
|
93
|
+
**Full documentation, API reference, and examples:**
|
|
138
94
|
|
|
139
|
-
|
|
140
|
-
import type {
|
|
141
|
-
PaymentRequirement,
|
|
142
|
-
PaymentAsset,
|
|
143
|
-
SessionData,
|
|
144
|
-
SignatureStore,
|
|
145
|
-
PaywallMiddlewareConfig,
|
|
146
|
-
} from '@alleyboss/micropay-solana-x402-paywall';
|
|
147
|
-
```
|
|
95
|
+
π **[solana-x402-paywall.vercel.app/docs](https://solana-x402-paywall.vercel.app/docs)**
|
|
148
96
|
|
|
149
|
-
## RPC
|
|
97
|
+
## π οΈ RPC Providers
|
|
150
98
|
|
|
151
|
-
|
|
99
|
+
Works with any Solana RPC provider:
|
|
152
100
|
|
|
153
101
|
```typescript
|
|
154
|
-
const
|
|
102
|
+
const config = {
|
|
155
103
|
network: 'mainnet-beta',
|
|
156
|
-
//
|
|
157
|
-
tatumApiKey: 'your-
|
|
158
|
-
//
|
|
159
|
-
rpcUrl: 'https://your-rpc
|
|
104
|
+
// Tatum.io
|
|
105
|
+
tatumApiKey: 'your-key',
|
|
106
|
+
// Or custom (Helius, QuickNode, etc.)
|
|
107
|
+
rpcUrl: 'https://your-rpc.com',
|
|
160
108
|
};
|
|
161
109
|
```
|
|
162
110
|
|
|
163
|
-
## License
|
|
111
|
+
## π License
|
|
164
112
|
|
|
165
113
|
MIT Β© AlleyBoss
|
package/package.json
CHANGED