@dexterai/x402 1.8.1 → 1.9.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/adapters/index.cjs +15 -3
- package/dist/adapters/index.cjs.map +1 -1
- package/dist/adapters/index.d.cts +5 -5
- package/dist/adapters/index.d.ts +5 -5
- package/dist/adapters/index.js +5 -3
- package/dist/adapters/index.js.map +1 -1
- package/dist/client/index.cjs +22 -9
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +6 -6
- package/dist/client/index.d.ts +6 -6
- package/dist/client/index.js +12 -9
- package/dist/client/index.js.map +1 -1
- package/dist/react/index.cjs +24 -11
- package/dist/react/index.cjs.map +1 -1
- package/dist/react/index.d.cts +4 -4
- package/dist/react/index.d.ts +4 -4
- package/dist/react/index.js +14 -11
- package/dist/react/index.js.map +1 -1
- package/dist/server/index.cjs +30 -20
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +3 -3
- package/dist/server/index.d.ts +3 -3
- package/dist/server/index.js +28 -18
- package/dist/server/index.js.map +1 -1
- package/dist/{solana-BeGAqPta.d.cts → solana-CfHuiW2H.d.cts} +2 -2
- package/dist/{solana-CQD9yMju.d.ts → solana-kZcwbUK9.d.ts} +2 -2
- package/dist/{types-DYLi7SuF.d.cts → types-BQvaF8lB.d.cts} +7 -5
- package/dist/{types-DYLi7SuF.d.ts → types-BQvaF8lB.d.ts} +7 -5
- package/dist/{types-B477nBpg.d.cts → types-DmqH9yD8.d.cts} +1 -1
- package/dist/{types-BWnUAPvD.d.ts → types-ENcnkof8.d.ts} +1 -1
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/{x402-client-Dk9q2QQF.d.cts → x402-client-BDaOwfgE.d.cts} +2 -2
- package/dist/{x402-client-D9b3PHai.d.ts → x402-client-DIcp-PvX.d.ts} +2 -2
- package/package.json +1 -1
package/dist/server/index.cjs
CHANGED
|
@@ -193,12 +193,12 @@ var FacilitatorClient = class {
|
|
|
193
193
|
const kind = supported.kinds.find(
|
|
194
194
|
(k) => k.x402Version === 2 && k.scheme === "exact" && k.network === network
|
|
195
195
|
);
|
|
196
|
-
if (!kind
|
|
196
|
+
if (!kind) {
|
|
197
197
|
throw new Error(
|
|
198
|
-
`Facilitator does not support network "${network}" with scheme "exact"
|
|
198
|
+
`Facilitator does not support network "${network}" with scheme "exact"`
|
|
199
199
|
);
|
|
200
200
|
}
|
|
201
|
-
return kind.extra
|
|
201
|
+
return kind.extra?.feePayer;
|
|
202
202
|
}
|
|
203
203
|
/**
|
|
204
204
|
* Get extra data for a network (feePayer, decimals, EIP-712 data, etc.)
|
|
@@ -748,7 +748,7 @@ if (btn) {
|
|
|
748
748
|
if (!accept) throw new Error('No payment method available');
|
|
749
749
|
|
|
750
750
|
const payTo = new PublicKey(accept.payTo);
|
|
751
|
-
const amount = BigInt(accept.amount
|
|
751
|
+
const amount = BigInt(accept.amount ?? accept.maxAmountRequired);
|
|
752
752
|
const mintPubkey = new PublicKey(accept.asset);
|
|
753
753
|
const feePayer = accept.extra?.feePayer ? new PublicKey(accept.extra.feePayer) : provider.publicKey;
|
|
754
754
|
const userPubkey = provider.publicKey;
|
|
@@ -855,7 +855,7 @@ function generatePaywallHtml(paymentRequiredHeader, requestUrl, method, config,
|
|
|
855
855
|
const decoded = JSON.parse(Buffer.from(paymentRequiredHeader, "base64").toString());
|
|
856
856
|
const accept = decoded.accepts?.[0];
|
|
857
857
|
if (accept) {
|
|
858
|
-
const amount = accept.amount
|
|
858
|
+
const amount = accept.amount ?? accept.maxAmountRequired ?? "0";
|
|
859
859
|
const decimals = accept.extra?.decimals || 6;
|
|
860
860
|
price = (Number(amount) / Math.pow(10, decimals)).toFixed(decimals > 4 ? 4 : 2);
|
|
861
861
|
network = accept.network || "";
|
|
@@ -1200,14 +1200,8 @@ function x402AccessPass(config) {
|
|
|
1200
1200
|
}
|
|
1201
1201
|
|
|
1202
1202
|
// src/server/dynamic-pricing.ts
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
for (let i = 0; i < str.length; i++) {
|
|
1206
|
-
hash ^= str.charCodeAt(i);
|
|
1207
|
-
hash = Math.imul(hash, 16777619);
|
|
1208
|
-
}
|
|
1209
|
-
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
1210
|
-
}
|
|
1203
|
+
var import_crypto2 = require("crypto");
|
|
1204
|
+
var QUOTE_MAX_AGE_SECONDS = 300;
|
|
1211
1205
|
function createDynamicPricing(config) {
|
|
1212
1206
|
const fullConfig = {
|
|
1213
1207
|
unitSize: config.unitSize,
|
|
@@ -1222,7 +1216,8 @@ function createDynamicPricing(config) {
|
|
|
1222
1216
|
if (ratePerUnit <= 0) throw new Error("ratePerUnit must be positive");
|
|
1223
1217
|
if (minUsd < 0) throw new Error("minUsd cannot be negative");
|
|
1224
1218
|
if (maxUsd < minUsd) throw new Error("maxUsd must be >= minUsd");
|
|
1225
|
-
|
|
1219
|
+
const hmacSecret = (0, import_crypto2.randomBytes)(32);
|
|
1220
|
+
function signQuote(input, timestamp) {
|
|
1226
1221
|
const configStr = JSON.stringify({
|
|
1227
1222
|
unitSize,
|
|
1228
1223
|
ratePerUnit,
|
|
@@ -1230,7 +1225,8 @@ function createDynamicPricing(config) {
|
|
|
1230
1225
|
maxUsd: maxUsd === Infinity ? "none" : maxUsd,
|
|
1231
1226
|
roundingMode
|
|
1232
1227
|
});
|
|
1233
|
-
|
|
1228
|
+
const data = `${input}|${configStr}|${timestamp}`;
|
|
1229
|
+
return (0, import_crypto2.createHmac)("sha256", hmacSecret).update(data).digest("hex").slice(0, 16);
|
|
1234
1230
|
}
|
|
1235
1231
|
function calculate(input) {
|
|
1236
1232
|
const inputLength = input.length;
|
|
@@ -1255,7 +1251,9 @@ function createDynamicPricing(config) {
|
|
|
1255
1251
|
usdAmount = Math.min(maxUsd, usdAmount);
|
|
1256
1252
|
const multiplier = Math.pow(10, decimals);
|
|
1257
1253
|
const amountAtomic = Math.floor(usdAmount * multiplier).toString();
|
|
1258
|
-
const
|
|
1254
|
+
const timestamp = Math.floor(Date.now() / 1e3);
|
|
1255
|
+
const mac = signQuote(input, timestamp);
|
|
1256
|
+
const quoteHash = `${timestamp}.${mac}`;
|
|
1259
1257
|
return {
|
|
1260
1258
|
amountAtomic,
|
|
1261
1259
|
usdAmount,
|
|
@@ -1266,8 +1264,20 @@ function createDynamicPricing(config) {
|
|
|
1266
1264
|
}
|
|
1267
1265
|
function validateQuote(input, quoteHash) {
|
|
1268
1266
|
if (!quoteHash) return false;
|
|
1269
|
-
const
|
|
1270
|
-
|
|
1267
|
+
const dotIndex = quoteHash.indexOf(".");
|
|
1268
|
+
if (dotIndex === -1) return false;
|
|
1269
|
+
const timestamp = parseInt(quoteHash.slice(0, dotIndex), 10);
|
|
1270
|
+
const mac = quoteHash.slice(dotIndex + 1);
|
|
1271
|
+
if (isNaN(timestamp) || !mac) return false;
|
|
1272
|
+
const age = Math.floor(Date.now() / 1e3) - timestamp;
|
|
1273
|
+
if (age < 0 || age > QUOTE_MAX_AGE_SECONDS) return false;
|
|
1274
|
+
const expectedMac = signQuote(input, timestamp);
|
|
1275
|
+
if (mac.length !== expectedMac.length) return false;
|
|
1276
|
+
let mismatch = 0;
|
|
1277
|
+
for (let i = 0; i < mac.length; i++) {
|
|
1278
|
+
mismatch |= mac.charCodeAt(i) ^ expectedMac.charCodeAt(i);
|
|
1279
|
+
}
|
|
1280
|
+
return mismatch === 0;
|
|
1271
1281
|
}
|
|
1272
1282
|
return {
|
|
1273
1283
|
calculate,
|
|
@@ -1282,7 +1292,7 @@ function formatPricing(config) {
|
|
|
1282
1292
|
}
|
|
1283
1293
|
|
|
1284
1294
|
// src/server/token-pricing.ts
|
|
1285
|
-
var
|
|
1295
|
+
var import_crypto3 = require("crypto");
|
|
1286
1296
|
var import_tiktoken = require("tiktoken");
|
|
1287
1297
|
|
|
1288
1298
|
// src/server/model-registry.ts
|
|
@@ -1880,7 +1890,7 @@ function countTokens(text, model = DEFAULT_MODEL) {
|
|
|
1880
1890
|
}
|
|
1881
1891
|
function generateQuoteHash(prompt, model, rate, tokens) {
|
|
1882
1892
|
const configString = JSON.stringify({ model, rate, tokens });
|
|
1883
|
-
return (0,
|
|
1893
|
+
return (0, import_crypto3.createHash)("sha256").update(prompt + configString).digest("hex").slice(0, 16);
|
|
1884
1894
|
}
|
|
1885
1895
|
function createTokenPricing(config = {}) {
|
|
1886
1896
|
const model = config.model ?? DEFAULT_MODEL;
|