@dexterai/x402 1.8.2 → 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 +27 -17
- package/dist/server/index.cjs.map +1 -1
- package/dist/server/index.d.cts +2 -2
- package/dist/server/index.d.ts +2 -2
- package/dist/server/index.js +25 -15
- 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.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PaymentAccept, V as VerifyResponse, S as SettleResponse, c as PayToProvider, d as PaymentRequired } from '../types-
|
|
2
|
-
export { g as AccessPassClaims, A as AccessPassClientConfig, b as AccessPassInfo, a as AccessPassTier, B as BASE_MAINNET_NETWORK, D as DEXTER_FACILITATOR_URL, e as PayToContext, f as PayToProviderDefaults, h as SOLANA_MAINNET_NETWORK, i as USDC_BASE, U as USDC_MINT } from '../types-
|
|
1
|
+
import { P as PaymentAccept, V as VerifyResponse, S as SettleResponse, c as PayToProvider, d as PaymentRequired } from '../types-BQvaF8lB.cjs';
|
|
2
|
+
export { g as AccessPassClaims, A as AccessPassClientConfig, b as AccessPassInfo, a as AccessPassTier, B as BASE_MAINNET_NETWORK, D as DEXTER_FACILITATOR_URL, e as PayToContext, f as PayToProviderDefaults, h as SOLANA_MAINNET_NETWORK, i as USDC_BASE, U as USDC_MINT } from '../types-BQvaF8lB.cjs';
|
|
3
3
|
import { Request, RequestHandler } from 'express';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/server/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { P as PaymentAccept, V as VerifyResponse, S as SettleResponse, c as PayToProvider, d as PaymentRequired } from '../types-
|
|
2
|
-
export { g as AccessPassClaims, A as AccessPassClientConfig, b as AccessPassInfo, a as AccessPassTier, B as BASE_MAINNET_NETWORK, D as DEXTER_FACILITATOR_URL, e as PayToContext, f as PayToProviderDefaults, h as SOLANA_MAINNET_NETWORK, i as USDC_BASE, U as USDC_MINT } from '../types-
|
|
1
|
+
import { P as PaymentAccept, V as VerifyResponse, S as SettleResponse, c as PayToProvider, d as PaymentRequired } from '../types-BQvaF8lB.js';
|
|
2
|
+
export { g as AccessPassClaims, A as AccessPassClientConfig, b as AccessPassInfo, a as AccessPassTier, B as BASE_MAINNET_NETWORK, D as DEXTER_FACILITATOR_URL, e as PayToContext, f as PayToProviderDefaults, h as SOLANA_MAINNET_NETWORK, i as USDC_BASE, U as USDC_MINT } from '../types-BQvaF8lB.js';
|
|
3
3
|
import { Request, RequestHandler } from 'express';
|
|
4
4
|
|
|
5
5
|
/**
|
package/dist/server/index.js
CHANGED
|
@@ -681,7 +681,7 @@ if (btn) {
|
|
|
681
681
|
if (!accept) throw new Error('No payment method available');
|
|
682
682
|
|
|
683
683
|
const payTo = new PublicKey(accept.payTo);
|
|
684
|
-
const amount = BigInt(accept.amount
|
|
684
|
+
const amount = BigInt(accept.amount ?? accept.maxAmountRequired);
|
|
685
685
|
const mintPubkey = new PublicKey(accept.asset);
|
|
686
686
|
const feePayer = accept.extra?.feePayer ? new PublicKey(accept.extra.feePayer) : provider.publicKey;
|
|
687
687
|
const userPubkey = provider.publicKey;
|
|
@@ -788,7 +788,7 @@ function generatePaywallHtml(paymentRequiredHeader, requestUrl, method, config,
|
|
|
788
788
|
const decoded = JSON.parse(Buffer.from(paymentRequiredHeader, "base64").toString());
|
|
789
789
|
const accept = decoded.accepts?.[0];
|
|
790
790
|
if (accept) {
|
|
791
|
-
const amount = accept.amount
|
|
791
|
+
const amount = accept.amount ?? accept.maxAmountRequired ?? "0";
|
|
792
792
|
const decimals = accept.extra?.decimals || 6;
|
|
793
793
|
price = (Number(amount) / Math.pow(10, decimals)).toFixed(decimals > 4 ? 4 : 2);
|
|
794
794
|
network = accept.network || "";
|
|
@@ -1133,14 +1133,8 @@ function x402AccessPass(config) {
|
|
|
1133
1133
|
}
|
|
1134
1134
|
|
|
1135
1135
|
// src/server/dynamic-pricing.ts
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
for (let i = 0; i < str.length; i++) {
|
|
1139
|
-
hash ^= str.charCodeAt(i);
|
|
1140
|
-
hash = Math.imul(hash, 16777619);
|
|
1141
|
-
}
|
|
1142
|
-
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
1143
|
-
}
|
|
1136
|
+
import { createHmac, randomBytes } from "crypto";
|
|
1137
|
+
var QUOTE_MAX_AGE_SECONDS = 300;
|
|
1144
1138
|
function createDynamicPricing(config) {
|
|
1145
1139
|
const fullConfig = {
|
|
1146
1140
|
unitSize: config.unitSize,
|
|
@@ -1155,7 +1149,8 @@ function createDynamicPricing(config) {
|
|
|
1155
1149
|
if (ratePerUnit <= 0) throw new Error("ratePerUnit must be positive");
|
|
1156
1150
|
if (minUsd < 0) throw new Error("minUsd cannot be negative");
|
|
1157
1151
|
if (maxUsd < minUsd) throw new Error("maxUsd must be >= minUsd");
|
|
1158
|
-
|
|
1152
|
+
const hmacSecret = randomBytes(32);
|
|
1153
|
+
function signQuote(input, timestamp) {
|
|
1159
1154
|
const configStr = JSON.stringify({
|
|
1160
1155
|
unitSize,
|
|
1161
1156
|
ratePerUnit,
|
|
@@ -1163,7 +1158,8 @@ function createDynamicPricing(config) {
|
|
|
1163
1158
|
maxUsd: maxUsd === Infinity ? "none" : maxUsd,
|
|
1164
1159
|
roundingMode
|
|
1165
1160
|
});
|
|
1166
|
-
|
|
1161
|
+
const data = `${input}|${configStr}|${timestamp}`;
|
|
1162
|
+
return createHmac("sha256", hmacSecret).update(data).digest("hex").slice(0, 16);
|
|
1167
1163
|
}
|
|
1168
1164
|
function calculate(input) {
|
|
1169
1165
|
const inputLength = input.length;
|
|
@@ -1188,7 +1184,9 @@ function createDynamicPricing(config) {
|
|
|
1188
1184
|
usdAmount = Math.min(maxUsd, usdAmount);
|
|
1189
1185
|
const multiplier = Math.pow(10, decimals);
|
|
1190
1186
|
const amountAtomic = Math.floor(usdAmount * multiplier).toString();
|
|
1191
|
-
const
|
|
1187
|
+
const timestamp = Math.floor(Date.now() / 1e3);
|
|
1188
|
+
const mac = signQuote(input, timestamp);
|
|
1189
|
+
const quoteHash = `${timestamp}.${mac}`;
|
|
1192
1190
|
return {
|
|
1193
1191
|
amountAtomic,
|
|
1194
1192
|
usdAmount,
|
|
@@ -1199,8 +1197,20 @@ function createDynamicPricing(config) {
|
|
|
1199
1197
|
}
|
|
1200
1198
|
function validateQuote(input, quoteHash) {
|
|
1201
1199
|
if (!quoteHash) return false;
|
|
1202
|
-
const
|
|
1203
|
-
|
|
1200
|
+
const dotIndex = quoteHash.indexOf(".");
|
|
1201
|
+
if (dotIndex === -1) return false;
|
|
1202
|
+
const timestamp = parseInt(quoteHash.slice(0, dotIndex), 10);
|
|
1203
|
+
const mac = quoteHash.slice(dotIndex + 1);
|
|
1204
|
+
if (isNaN(timestamp) || !mac) return false;
|
|
1205
|
+
const age = Math.floor(Date.now() / 1e3) - timestamp;
|
|
1206
|
+
if (age < 0 || age > QUOTE_MAX_AGE_SECONDS) return false;
|
|
1207
|
+
const expectedMac = signQuote(input, timestamp);
|
|
1208
|
+
if (mac.length !== expectedMac.length) return false;
|
|
1209
|
+
let mismatch = 0;
|
|
1210
|
+
for (let i = 0; i < mac.length; i++) {
|
|
1211
|
+
mismatch |= mac.charCodeAt(i) ^ expectedMac.charCodeAt(i);
|
|
1212
|
+
}
|
|
1213
|
+
return mismatch === 0;
|
|
1204
1214
|
}
|
|
1205
1215
|
return {
|
|
1206
1216
|
calculate,
|