@alleyboss/micropay-solana-x402-paywall 3.1.3 → 3.2.0
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/agent/index.cjs +12 -5
- package/dist/agent/index.js +8 -5
- package/dist/client/index.cjs +1605 -0
- package/dist/client/index.d.cts +94 -1
- package/dist/client/index.d.ts +94 -1
- package/dist/client/index.js +1604 -1
- package/dist/index.cjs +1615 -6
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1611 -8
- package/dist/next/index.cjs +1 -2
- package/dist/next/index.js +1 -2
- package/package.json +5 -1
package/dist/client/index.d.cts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { PublicKey, Transaction, Connection, TransactionSignature } from '@solana/web3.js';
|
|
2
|
+
|
|
1
3
|
/** SPL Token asset specification */
|
|
2
4
|
interface SPLTokenAsset {
|
|
3
5
|
/** Token mint address */
|
|
@@ -126,4 +128,95 @@ declare function createPaymentReference(): string;
|
|
|
126
128
|
*/
|
|
127
129
|
declare function createX402AuthorizationHeader(signature: string, paymentRequiredHeader: string): string;
|
|
128
130
|
|
|
129
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Minimal wallet adapter interface compatible with @solana/wallet-adapter-base
|
|
133
|
+
*/
|
|
134
|
+
interface WalletAdapterInterface {
|
|
135
|
+
publicKey: PublicKey | null;
|
|
136
|
+
signTransaction?: (transaction: Transaction) => Promise<Transaction>;
|
|
137
|
+
sendTransaction: (transaction: Transaction, connection: Connection, options?: any) => Promise<TransactionSignature>;
|
|
138
|
+
}
|
|
139
|
+
interface SendPaymentParams {
|
|
140
|
+
/** Solana Connection object */
|
|
141
|
+
connection: Connection;
|
|
142
|
+
/** Connected wallet adapter */
|
|
143
|
+
wallet: WalletAdapterInterface;
|
|
144
|
+
/** Recipient wallet address */
|
|
145
|
+
recipientAddress: string;
|
|
146
|
+
/** Amount in lamports */
|
|
147
|
+
amount: bigint;
|
|
148
|
+
/** Optional memo for the transaction */
|
|
149
|
+
memo?: string;
|
|
150
|
+
/** Commitment level (default: 'confirmed') */
|
|
151
|
+
commitment?: 'processed' | 'confirmed' | 'finalized';
|
|
152
|
+
}
|
|
153
|
+
interface PaymentResult {
|
|
154
|
+
signature: string;
|
|
155
|
+
amountSol: number;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Send a SOL payment from the client-side wallet
|
|
159
|
+
*
|
|
160
|
+
* Handles transaction creation, recent blockhash, and sending.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const result = await sendSolanaPayment({
|
|
165
|
+
* connection,
|
|
166
|
+
* wallet,
|
|
167
|
+
* recipientAddress: '...',
|
|
168
|
+
* amount: 10_000_000n // 0.01 SOL
|
|
169
|
+
* });
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
declare function sendSolanaPayment({ connection, wallet, recipientAddress, amount, commitment }: SendPaymentParams): Promise<PaymentResult>;
|
|
173
|
+
|
|
174
|
+
interface PaywallConfig {
|
|
175
|
+
/** URL to fetch protected content from */
|
|
176
|
+
url: string;
|
|
177
|
+
/** Solana Connection */
|
|
178
|
+
connection: Connection;
|
|
179
|
+
/** Wallet Adapter */
|
|
180
|
+
wallet: WalletAdapterInterface;
|
|
181
|
+
}
|
|
182
|
+
interface PaywallState<T> {
|
|
183
|
+
/** Content data if unlocked */
|
|
184
|
+
data: T | null;
|
|
185
|
+
/** Whether content is currently locked by 402 */
|
|
186
|
+
isLocked: boolean;
|
|
187
|
+
/** Whether an operation is in progress (initial load or unlocking) */
|
|
188
|
+
isLoading: boolean;
|
|
189
|
+
/** Payment amount required (in lamports) */
|
|
190
|
+
price?: bigint;
|
|
191
|
+
/** Recipient address */
|
|
192
|
+
recipient?: string;
|
|
193
|
+
/** Error message */
|
|
194
|
+
error: string | null;
|
|
195
|
+
/** Function to trigger unlock flow */
|
|
196
|
+
unlock: () => Promise<void>;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* React Hook to manage x402 Payment Loop
|
|
200
|
+
*
|
|
201
|
+
* Handles:
|
|
202
|
+
* 1. Initial fetch
|
|
203
|
+
* 2. 402 Payment Required detection
|
|
204
|
+
* 3. Payment execution (via wallet)
|
|
205
|
+
* 4. Auth header creation
|
|
206
|
+
* 5. Re-fetch with proof
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```tsx
|
|
210
|
+
* const { data, isLocked, unlock, price } = usePaywallResource<Article>({
|
|
211
|
+
* url: `/api/articles/${slug}`,
|
|
212
|
+
* connection,
|
|
213
|
+
* wallet
|
|
214
|
+
* });
|
|
215
|
+
*
|
|
216
|
+
* if (isLocked) return <Button onClick={unlock}>Pay {price} Lamports</Button>;
|
|
217
|
+
* return <Article data={data} />;
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
declare function usePaywallResource<T = any>({ url, connection, wallet }: PaywallConfig): PaywallState<T>;
|
|
221
|
+
|
|
222
|
+
export { type PaymentFlowConfig, type PaymentResult, type PaywallConfig, type PaywallState, type SendPaymentParams, type SolanaPayUrlParams, type WalletAdapterInterface, buildSolanaPayUrl, createPaymentFlow, createPaymentReference, createX402AuthorizationHeader, sendSolanaPayment, usePaywallResource };
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { PublicKey, Transaction, Connection, TransactionSignature } from '@solana/web3.js';
|
|
2
|
+
|
|
1
3
|
/** SPL Token asset specification */
|
|
2
4
|
interface SPLTokenAsset {
|
|
3
5
|
/** Token mint address */
|
|
@@ -126,4 +128,95 @@ declare function createPaymentReference(): string;
|
|
|
126
128
|
*/
|
|
127
129
|
declare function createX402AuthorizationHeader(signature: string, paymentRequiredHeader: string): string;
|
|
128
130
|
|
|
129
|
-
|
|
131
|
+
/**
|
|
132
|
+
* Minimal wallet adapter interface compatible with @solana/wallet-adapter-base
|
|
133
|
+
*/
|
|
134
|
+
interface WalletAdapterInterface {
|
|
135
|
+
publicKey: PublicKey | null;
|
|
136
|
+
signTransaction?: (transaction: Transaction) => Promise<Transaction>;
|
|
137
|
+
sendTransaction: (transaction: Transaction, connection: Connection, options?: any) => Promise<TransactionSignature>;
|
|
138
|
+
}
|
|
139
|
+
interface SendPaymentParams {
|
|
140
|
+
/** Solana Connection object */
|
|
141
|
+
connection: Connection;
|
|
142
|
+
/** Connected wallet adapter */
|
|
143
|
+
wallet: WalletAdapterInterface;
|
|
144
|
+
/** Recipient wallet address */
|
|
145
|
+
recipientAddress: string;
|
|
146
|
+
/** Amount in lamports */
|
|
147
|
+
amount: bigint;
|
|
148
|
+
/** Optional memo for the transaction */
|
|
149
|
+
memo?: string;
|
|
150
|
+
/** Commitment level (default: 'confirmed') */
|
|
151
|
+
commitment?: 'processed' | 'confirmed' | 'finalized';
|
|
152
|
+
}
|
|
153
|
+
interface PaymentResult {
|
|
154
|
+
signature: string;
|
|
155
|
+
amountSol: number;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Send a SOL payment from the client-side wallet
|
|
159
|
+
*
|
|
160
|
+
* Handles transaction creation, recent blockhash, and sending.
|
|
161
|
+
*
|
|
162
|
+
* @example
|
|
163
|
+
* ```typescript
|
|
164
|
+
* const result = await sendSolanaPayment({
|
|
165
|
+
* connection,
|
|
166
|
+
* wallet,
|
|
167
|
+
* recipientAddress: '...',
|
|
168
|
+
* amount: 10_000_000n // 0.01 SOL
|
|
169
|
+
* });
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
declare function sendSolanaPayment({ connection, wallet, recipientAddress, amount, commitment }: SendPaymentParams): Promise<PaymentResult>;
|
|
173
|
+
|
|
174
|
+
interface PaywallConfig {
|
|
175
|
+
/** URL to fetch protected content from */
|
|
176
|
+
url: string;
|
|
177
|
+
/** Solana Connection */
|
|
178
|
+
connection: Connection;
|
|
179
|
+
/** Wallet Adapter */
|
|
180
|
+
wallet: WalletAdapterInterface;
|
|
181
|
+
}
|
|
182
|
+
interface PaywallState<T> {
|
|
183
|
+
/** Content data if unlocked */
|
|
184
|
+
data: T | null;
|
|
185
|
+
/** Whether content is currently locked by 402 */
|
|
186
|
+
isLocked: boolean;
|
|
187
|
+
/** Whether an operation is in progress (initial load or unlocking) */
|
|
188
|
+
isLoading: boolean;
|
|
189
|
+
/** Payment amount required (in lamports) */
|
|
190
|
+
price?: bigint;
|
|
191
|
+
/** Recipient address */
|
|
192
|
+
recipient?: string;
|
|
193
|
+
/** Error message */
|
|
194
|
+
error: string | null;
|
|
195
|
+
/** Function to trigger unlock flow */
|
|
196
|
+
unlock: () => Promise<void>;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* React Hook to manage x402 Payment Loop
|
|
200
|
+
*
|
|
201
|
+
* Handles:
|
|
202
|
+
* 1. Initial fetch
|
|
203
|
+
* 2. 402 Payment Required detection
|
|
204
|
+
* 3. Payment execution (via wallet)
|
|
205
|
+
* 4. Auth header creation
|
|
206
|
+
* 5. Re-fetch with proof
|
|
207
|
+
*
|
|
208
|
+
* @example
|
|
209
|
+
* ```tsx
|
|
210
|
+
* const { data, isLocked, unlock, price } = usePaywallResource<Article>({
|
|
211
|
+
* url: `/api/articles/${slug}`,
|
|
212
|
+
* connection,
|
|
213
|
+
* wallet
|
|
214
|
+
* });
|
|
215
|
+
*
|
|
216
|
+
* if (isLocked) return <Button onClick={unlock}>Pay {price} Lamports</Button>;
|
|
217
|
+
* return <Article data={data} />;
|
|
218
|
+
* ```
|
|
219
|
+
*/
|
|
220
|
+
declare function usePaywallResource<T = any>({ url, connection, wallet }: PaywallConfig): PaywallState<T>;
|
|
221
|
+
|
|
222
|
+
export { type PaymentFlowConfig, type PaymentResult, type PaywallConfig, type PaywallState, type SendPaymentParams, type SolanaPayUrlParams, type WalletAdapterInterface, buildSolanaPayUrl, createPaymentFlow, createPaymentReference, createX402AuthorizationHeader, sendSolanaPayment, usePaywallResource };
|