@alleyboss/micropay-solana-x402-paywall 3.3.10 → 3.3.12
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 +26 -0
- package/dist/index.cjs +89 -0
- package/dist/index.d.cts +32 -3
- package/dist/index.d.ts +32 -3
- package/dist/index.js +89 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -133,6 +133,32 @@ const withMicropay = createX402Middleware({
|
|
|
133
133
|
| **Setup** | Zero-config | Requires RPC URL |
|
|
134
134
|
| **Best For** | Quick startups, MVPs | Production, High-Volume, Agents |
|
|
135
135
|
|
|
136
|
+
## 🌐 Public Facilitator Mode (New in v3.3.12)
|
|
137
|
+
|
|
138
|
+
Use a public facilitator service like [x402.org](https://x402.org) or [PayAI Network](https://facilitator.payai.network) without running your own RPC node:
|
|
139
|
+
|
|
140
|
+
```typescript
|
|
141
|
+
import { RemoteSvmFacilitator } from '@alleyboss/micropay-solana-x402-paywall';
|
|
142
|
+
|
|
143
|
+
// Use a public facilitator for verification
|
|
144
|
+
const facilitator = new RemoteSvmFacilitator('https://x402.org/facilitator');
|
|
145
|
+
|
|
146
|
+
// Or in middleware config
|
|
147
|
+
const withMicropay = createX402Middleware({
|
|
148
|
+
walletAddress: 'YOUR_WALLET',
|
|
149
|
+
network: 'mainnet-beta',
|
|
150
|
+
facilitatorUrl: 'https://facilitator.payai.network'
|
|
151
|
+
// No rpcUrl = uses remote facilitator
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### 🆚 Verification Modes Comparison
|
|
156
|
+
|
|
157
|
+
| Mode | Class | Best For |
|
|
158
|
+
|------|-------|----------|
|
|
159
|
+
| **Self-Sovereign** | `LocalSvmFacilitator` | Full control, privacy, production |
|
|
160
|
+
| **Public Facilitator** | `RemoteSvmFacilitator` | Quick setup, no RPC management |
|
|
161
|
+
|
|
136
162
|
## 🤖 AI Agent Payments
|
|
137
163
|
|
|
138
164
|
Enable autonomous AI agents to pay for premium API access.
|
package/dist/index.cjs
CHANGED
|
@@ -223,6 +223,94 @@ var LocalSvmFacilitator = class {
|
|
|
223
223
|
};
|
|
224
224
|
}
|
|
225
225
|
};
|
|
226
|
+
var RemoteSvmFacilitator = class {
|
|
227
|
+
scheme = "exact";
|
|
228
|
+
facilitatorUrl;
|
|
229
|
+
constructor(facilitatorUrl = "https://facilitator.payai.network") {
|
|
230
|
+
this.facilitatorUrl = facilitatorUrl.replace(/\/$/, "");
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Get supported payment kinds
|
|
234
|
+
*/
|
|
235
|
+
async getSupported(extensionKeys = []) {
|
|
236
|
+
try {
|
|
237
|
+
const response = await fetch(`${this.facilitatorUrl}/supported`, {
|
|
238
|
+
method: "POST",
|
|
239
|
+
headers: { "Content-Type": "application/json" },
|
|
240
|
+
body: JSON.stringify({ extensionKeys })
|
|
241
|
+
});
|
|
242
|
+
if (!response.ok) {
|
|
243
|
+
throw new Error(`Facilitator error: ${response.statusText}`);
|
|
244
|
+
}
|
|
245
|
+
return await response.json();
|
|
246
|
+
} catch (error) {
|
|
247
|
+
throw error;
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Verify a payment remotely
|
|
252
|
+
*/
|
|
253
|
+
async verify(payload, requirements) {
|
|
254
|
+
try {
|
|
255
|
+
const response = await fetch(`${this.facilitatorUrl}/verify`, {
|
|
256
|
+
method: "POST",
|
|
257
|
+
headers: { "Content-Type": "application/json" },
|
|
258
|
+
body: JSON.stringify({
|
|
259
|
+
payload,
|
|
260
|
+
requirements
|
|
261
|
+
})
|
|
262
|
+
});
|
|
263
|
+
if (!response.ok) {
|
|
264
|
+
const errorBody = await response.text();
|
|
265
|
+
return {
|
|
266
|
+
isValid: false,
|
|
267
|
+
invalidReason: `Remote Verify Failed (${response.status}): ${errorBody}`
|
|
268
|
+
};
|
|
269
|
+
}
|
|
270
|
+
const result = await response.json();
|
|
271
|
+
return result;
|
|
272
|
+
} catch (error) {
|
|
273
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
274
|
+
throw new types.VerifyError(500, {
|
|
275
|
+
isValid: false,
|
|
276
|
+
invalidReason: `Network error: ${errorMessage}`
|
|
277
|
+
});
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Settle a payment remotely
|
|
282
|
+
*/
|
|
283
|
+
async settle(payload, requirements) {
|
|
284
|
+
try {
|
|
285
|
+
const response = await fetch(`${this.facilitatorUrl}/settle`, {
|
|
286
|
+
method: "POST",
|
|
287
|
+
headers: { "Content-Type": "application/json" },
|
|
288
|
+
body: JSON.stringify({
|
|
289
|
+
payload,
|
|
290
|
+
requirements
|
|
291
|
+
})
|
|
292
|
+
});
|
|
293
|
+
if (!response.ok) {
|
|
294
|
+
const errorBody = await response.text();
|
|
295
|
+
throw new types.SettleError(response.status, {
|
|
296
|
+
success: false,
|
|
297
|
+
errorReason: errorBody,
|
|
298
|
+
transaction: payload.payload.signature,
|
|
299
|
+
network: requirements.network
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
return await response.json();
|
|
303
|
+
} catch (error) {
|
|
304
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
305
|
+
throw new types.SettleError(500, {
|
|
306
|
+
success: false,
|
|
307
|
+
errorReason: errorMessage,
|
|
308
|
+
transaction: payload.payload.signature,
|
|
309
|
+
network: requirements.network
|
|
310
|
+
});
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
};
|
|
226
314
|
var DEFAULT_COMPUTE_UNITS = 2e5;
|
|
227
315
|
var DEFAULT_MICRO_LAMPORTS = 1e3;
|
|
228
316
|
function createPriorityFeeInstructions(config = {}) {
|
|
@@ -717,6 +805,7 @@ function getProviders() {
|
|
|
717
805
|
}
|
|
718
806
|
|
|
719
807
|
exports.LocalSvmFacilitator = LocalSvmFacilitator;
|
|
808
|
+
exports.RemoteSvmFacilitator = RemoteSvmFacilitator;
|
|
720
809
|
exports.addCredits = addCredits;
|
|
721
810
|
exports.clearPriceCache = clearPriceCache;
|
|
722
811
|
exports.configurePricing = configurePricing;
|
package/dist/index.d.cts
CHANGED
|
@@ -8,7 +8,7 @@ export { CustomPriceProvider, PriceConfig, PriceData, clearPriceCache, configure
|
|
|
8
8
|
import '@solana/web3.js';
|
|
9
9
|
import './types-BWYQMw03.cjs';
|
|
10
10
|
|
|
11
|
-
interface FacilitatorClient {
|
|
11
|
+
interface FacilitatorClient$1 {
|
|
12
12
|
verify(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<VerifyResponse>;
|
|
13
13
|
settle(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<SettleResponse>;
|
|
14
14
|
getSupported(extensionKeys?: string[]): Promise<SupportedResponse>;
|
|
@@ -19,7 +19,7 @@ interface FacilitatorClient {
|
|
|
19
19
|
* Verifies and settles Solana payments locally using a direct RPC connection,
|
|
20
20
|
* bypassing the need for a hosted facilitator service.
|
|
21
21
|
*/
|
|
22
|
-
declare class LocalSvmFacilitator implements FacilitatorClient {
|
|
22
|
+
declare class LocalSvmFacilitator implements FacilitatorClient$1 {
|
|
23
23
|
readonly scheme = "exact";
|
|
24
24
|
readonly caipFamily = "solana:*";
|
|
25
25
|
private connection;
|
|
@@ -98,4 +98,33 @@ declare class LocalSvmFacilitator implements FacilitatorClient {
|
|
|
98
98
|
settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
interface FacilitatorClient {
|
|
102
|
+
verify(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<VerifyResponse>;
|
|
103
|
+
settle(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<SettleResponse>;
|
|
104
|
+
getSupported(extensionKeys?: string[]): Promise<SupportedResponse>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Remote SVM Facilitator
|
|
108
|
+
*
|
|
109
|
+
* Verifies payments by delegating to a hosted facilitator service (e.g. PayAI or x402.org).
|
|
110
|
+
* This allows using advanced features like cross-chain swaps or fiat abstraction handled by the facilitator.
|
|
111
|
+
*/
|
|
112
|
+
declare class RemoteSvmFacilitator implements FacilitatorClient {
|
|
113
|
+
readonly scheme = "exact";
|
|
114
|
+
private facilitatorUrl;
|
|
115
|
+
constructor(facilitatorUrl?: string);
|
|
116
|
+
/**
|
|
117
|
+
* Get supported payment kinds
|
|
118
|
+
*/
|
|
119
|
+
getSupported(extensionKeys?: string[]): Promise<SupportedResponse>;
|
|
120
|
+
/**
|
|
121
|
+
* Verify a payment remotely
|
|
122
|
+
*/
|
|
123
|
+
verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
|
|
124
|
+
/**
|
|
125
|
+
* Settle a payment remotely
|
|
126
|
+
*/
|
|
127
|
+
settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { LocalSvmFacilitator, RemoteSvmFacilitator };
|
package/dist/index.d.ts
CHANGED
|
@@ -8,7 +8,7 @@ export { CustomPriceProvider, PriceConfig, PriceData, clearPriceCache, configure
|
|
|
8
8
|
import '@solana/web3.js';
|
|
9
9
|
import './types-BWYQMw03.js';
|
|
10
10
|
|
|
11
|
-
interface FacilitatorClient {
|
|
11
|
+
interface FacilitatorClient$1 {
|
|
12
12
|
verify(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<VerifyResponse>;
|
|
13
13
|
settle(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<SettleResponse>;
|
|
14
14
|
getSupported(extensionKeys?: string[]): Promise<SupportedResponse>;
|
|
@@ -19,7 +19,7 @@ interface FacilitatorClient {
|
|
|
19
19
|
* Verifies and settles Solana payments locally using a direct RPC connection,
|
|
20
20
|
* bypassing the need for a hosted facilitator service.
|
|
21
21
|
*/
|
|
22
|
-
declare class LocalSvmFacilitator implements FacilitatorClient {
|
|
22
|
+
declare class LocalSvmFacilitator implements FacilitatorClient$1 {
|
|
23
23
|
readonly scheme = "exact";
|
|
24
24
|
readonly caipFamily = "solana:*";
|
|
25
25
|
private connection;
|
|
@@ -98,4 +98,33 @@ declare class LocalSvmFacilitator implements FacilitatorClient {
|
|
|
98
98
|
settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
-
|
|
101
|
+
interface FacilitatorClient {
|
|
102
|
+
verify(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<VerifyResponse>;
|
|
103
|
+
settle(paymentPayload: PaymentPayload, paymentRequirements: PaymentRequirements): Promise<SettleResponse>;
|
|
104
|
+
getSupported(extensionKeys?: string[]): Promise<SupportedResponse>;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Remote SVM Facilitator
|
|
108
|
+
*
|
|
109
|
+
* Verifies payments by delegating to a hosted facilitator service (e.g. PayAI or x402.org).
|
|
110
|
+
* This allows using advanced features like cross-chain swaps or fiat abstraction handled by the facilitator.
|
|
111
|
+
*/
|
|
112
|
+
declare class RemoteSvmFacilitator implements FacilitatorClient {
|
|
113
|
+
readonly scheme = "exact";
|
|
114
|
+
private facilitatorUrl;
|
|
115
|
+
constructor(facilitatorUrl?: string);
|
|
116
|
+
/**
|
|
117
|
+
* Get supported payment kinds
|
|
118
|
+
*/
|
|
119
|
+
getSupported(extensionKeys?: string[]): Promise<SupportedResponse>;
|
|
120
|
+
/**
|
|
121
|
+
* Verify a payment remotely
|
|
122
|
+
*/
|
|
123
|
+
verify(payload: PaymentPayload, requirements: PaymentRequirements): Promise<VerifyResponse>;
|
|
124
|
+
/**
|
|
125
|
+
* Settle a payment remotely
|
|
126
|
+
*/
|
|
127
|
+
settle(payload: PaymentPayload, requirements: PaymentRequirements): Promise<SettleResponse>;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export { LocalSvmFacilitator, RemoteSvmFacilitator };
|
package/dist/index.js
CHANGED
|
@@ -218,6 +218,94 @@ var LocalSvmFacilitator = class {
|
|
|
218
218
|
};
|
|
219
219
|
}
|
|
220
220
|
};
|
|
221
|
+
var RemoteSvmFacilitator = class {
|
|
222
|
+
scheme = "exact";
|
|
223
|
+
facilitatorUrl;
|
|
224
|
+
constructor(facilitatorUrl = "https://facilitator.payai.network") {
|
|
225
|
+
this.facilitatorUrl = facilitatorUrl.replace(/\/$/, "");
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Get supported payment kinds
|
|
229
|
+
*/
|
|
230
|
+
async getSupported(extensionKeys = []) {
|
|
231
|
+
try {
|
|
232
|
+
const response = await fetch(`${this.facilitatorUrl}/supported`, {
|
|
233
|
+
method: "POST",
|
|
234
|
+
headers: { "Content-Type": "application/json" },
|
|
235
|
+
body: JSON.stringify({ extensionKeys })
|
|
236
|
+
});
|
|
237
|
+
if (!response.ok) {
|
|
238
|
+
throw new Error(`Facilitator error: ${response.statusText}`);
|
|
239
|
+
}
|
|
240
|
+
return await response.json();
|
|
241
|
+
} catch (error) {
|
|
242
|
+
throw error;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Verify a payment remotely
|
|
247
|
+
*/
|
|
248
|
+
async verify(payload, requirements) {
|
|
249
|
+
try {
|
|
250
|
+
const response = await fetch(`${this.facilitatorUrl}/verify`, {
|
|
251
|
+
method: "POST",
|
|
252
|
+
headers: { "Content-Type": "application/json" },
|
|
253
|
+
body: JSON.stringify({
|
|
254
|
+
payload,
|
|
255
|
+
requirements
|
|
256
|
+
})
|
|
257
|
+
});
|
|
258
|
+
if (!response.ok) {
|
|
259
|
+
const errorBody = await response.text();
|
|
260
|
+
return {
|
|
261
|
+
isValid: false,
|
|
262
|
+
invalidReason: `Remote Verify Failed (${response.status}): ${errorBody}`
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
const result = await response.json();
|
|
266
|
+
return result;
|
|
267
|
+
} catch (error) {
|
|
268
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
269
|
+
throw new VerifyError(500, {
|
|
270
|
+
isValid: false,
|
|
271
|
+
invalidReason: `Network error: ${errorMessage}`
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
/**
|
|
276
|
+
* Settle a payment remotely
|
|
277
|
+
*/
|
|
278
|
+
async settle(payload, requirements) {
|
|
279
|
+
try {
|
|
280
|
+
const response = await fetch(`${this.facilitatorUrl}/settle`, {
|
|
281
|
+
method: "POST",
|
|
282
|
+
headers: { "Content-Type": "application/json" },
|
|
283
|
+
body: JSON.stringify({
|
|
284
|
+
payload,
|
|
285
|
+
requirements
|
|
286
|
+
})
|
|
287
|
+
});
|
|
288
|
+
if (!response.ok) {
|
|
289
|
+
const errorBody = await response.text();
|
|
290
|
+
throw new SettleError(response.status, {
|
|
291
|
+
success: false,
|
|
292
|
+
errorReason: errorBody,
|
|
293
|
+
transaction: payload.payload.signature,
|
|
294
|
+
network: requirements.network
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
return await response.json();
|
|
298
|
+
} catch (error) {
|
|
299
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
300
|
+
throw new SettleError(500, {
|
|
301
|
+
success: false,
|
|
302
|
+
errorReason: errorMessage,
|
|
303
|
+
transaction: payload.payload.signature,
|
|
304
|
+
network: requirements.network
|
|
305
|
+
});
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
};
|
|
221
309
|
var DEFAULT_COMPUTE_UNITS = 2e5;
|
|
222
310
|
var DEFAULT_MICRO_LAMPORTS = 1e3;
|
|
223
311
|
function createPriorityFeeInstructions(config = {}) {
|
|
@@ -711,4 +799,4 @@ function getProviders() {
|
|
|
711
799
|
return PROVIDERS.map((p) => ({ name: p.name, url: p.url }));
|
|
712
800
|
}
|
|
713
801
|
|
|
714
|
-
export { LocalSvmFacilitator, addCredits, clearPriceCache, configurePricing, createCreditSession, executeAgentPayment, formatPriceDisplay, formatPriceSync, generateAgentKeypair, getAgentBalance, getProviders, getRemainingCredits, getSolPrice, hasAgentSufficientBalance, keypairFromBase58, lamportsToSol, lamportsToUsd, usdToLamports, useCredit, validateCreditSession };
|
|
802
|
+
export { LocalSvmFacilitator, RemoteSvmFacilitator, addCredits, clearPriceCache, configurePricing, createCreditSession, executeAgentPayment, formatPriceDisplay, formatPriceSync, generateAgentKeypair, getAgentBalance, getProviders, getRemainingCredits, getSolPrice, hasAgentSufficientBalance, keypairFromBase58, lamportsToSol, lamportsToUsd, usdToLamports, useCredit, validateCreditSession };
|
package/package.json
CHANGED