@alleyboss/micropay-solana-x402-paywall 3.3.9 → 3.3.11
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/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/dist/next/index.cjs +0 -2
- package/dist/next/index.js +0 -2
- package/package.json +1 -1
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/dist/next/index.cjs
CHANGED
|
@@ -245,7 +245,6 @@ function createX402Middleware(config) {
|
|
|
245
245
|
return async (req, ctx) => {
|
|
246
246
|
const compatibleReq = new Proxy(req, {
|
|
247
247
|
get(target, prop) {
|
|
248
|
-
console.error(`[ProxyDebug] Access req.${String(prop)}`);
|
|
249
248
|
if (prop === "url") {
|
|
250
249
|
return target.nextUrl?.pathname || target.url;
|
|
251
250
|
}
|
|
@@ -253,7 +252,6 @@ function createX402Middleware(config) {
|
|
|
253
252
|
const headers = target.headers;
|
|
254
253
|
return new Proxy(headers, {
|
|
255
254
|
get(hTarget, hProp) {
|
|
256
|
-
console.error(`[ProxyDebug] Access req.headers.${String(hProp)}`);
|
|
257
255
|
if (typeof hProp === "string" && !["get", "set", "has", "delete", "entries", "keys", "values", "forEach", "append"].includes(hProp) && typeof hTarget[hProp] === "undefined") {
|
|
258
256
|
return hTarget.get(hProp) || void 0;
|
|
259
257
|
}
|
package/dist/next/index.js
CHANGED
|
@@ -244,7 +244,6 @@ function createX402Middleware(config) {
|
|
|
244
244
|
return async (req, ctx) => {
|
|
245
245
|
const compatibleReq = new Proxy(req, {
|
|
246
246
|
get(target, prop) {
|
|
247
|
-
console.error(`[ProxyDebug] Access req.${String(prop)}`);
|
|
248
247
|
if (prop === "url") {
|
|
249
248
|
return target.nextUrl?.pathname || target.url;
|
|
250
249
|
}
|
|
@@ -252,7 +251,6 @@ function createX402Middleware(config) {
|
|
|
252
251
|
const headers = target.headers;
|
|
253
252
|
return new Proxy(headers, {
|
|
254
253
|
get(hTarget, hProp) {
|
|
255
|
-
console.error(`[ProxyDebug] Access req.headers.${String(hProp)}`);
|
|
256
254
|
if (typeof hProp === "string" && !["get", "set", "has", "delete", "entries", "keys", "values", "forEach", "append"].includes(hProp) && typeof hTarget[hProp] === "undefined") {
|
|
257
255
|
return hTarget.get(hProp) || void 0;
|
|
258
256
|
}
|
package/package.json
CHANGED