@alleyboss/micropay-solana-x402-paywall 2.2.0 → 2.3.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/index.cjs +44 -11
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +44 -11
- package/dist/index.js.map +1 -1
- package/dist/pricing/index.cjs +7 -7
- package/dist/pricing/index.cjs.map +1 -1
- package/dist/pricing/index.js +7 -7
- package/dist/pricing/index.js.map +1 -1
- package/dist/solana/index.cjs +37 -2
- package/dist/solana/index.cjs.map +1 -1
- package/dist/solana/index.d.cts +5 -0
- package/dist/solana/index.d.ts +5 -0
- package/dist/solana/index.js +37 -2
- package/dist/solana/index.js.map +1 -1
- package/dist/x402/index.cjs +8 -1
- package/dist/x402/index.cjs.map +1 -1
- package/dist/x402/index.js +8 -1
- package/dist/x402/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -148,7 +148,8 @@ async function verifyPayment(params) {
|
|
|
148
148
|
expectedRecipient,
|
|
149
149
|
expectedAmount,
|
|
150
150
|
maxAgeSeconds = 300,
|
|
151
|
-
clientConfig
|
|
151
|
+
clientConfig,
|
|
152
|
+
signatureStore
|
|
152
153
|
} = params;
|
|
153
154
|
if (!isValidSignature(signature)) {
|
|
154
155
|
return { valid: false, confirmed: false, signature, error: "Invalid signature format" };
|
|
@@ -159,6 +160,12 @@ async function verifyPayment(params) {
|
|
|
159
160
|
if (expectedAmount <= 0n) {
|
|
160
161
|
return { valid: false, confirmed: false, signature, error: "Invalid expected amount" };
|
|
161
162
|
}
|
|
163
|
+
if (signatureStore) {
|
|
164
|
+
const isUsed = await signatureStore.hasBeenUsed(signature);
|
|
165
|
+
if (isUsed) {
|
|
166
|
+
return { valid: false, confirmed: true, signature, error: "Signature already used" };
|
|
167
|
+
}
|
|
168
|
+
}
|
|
162
169
|
const effectiveMaxAge = Math.min(Math.max(maxAgeSeconds, 60), 3600);
|
|
163
170
|
const connection = getConnection(clientConfig);
|
|
164
171
|
try {
|
|
@@ -267,8 +274,6 @@ function solToLamports(sol) {
|
|
|
267
274
|
}
|
|
268
275
|
return BigInt(Math.floor(sol * web3_js.LAMPORTS_PER_SOL));
|
|
269
276
|
}
|
|
270
|
-
|
|
271
|
-
// src/solana/spl.ts
|
|
272
277
|
var SIGNATURE_REGEX2 = /^[1-9A-HJ-NP-Za-km-z]{87,88}$/;
|
|
273
278
|
var WALLET_REGEX2 = /^[1-9A-HJ-NP-Za-km-z]{32,44}$/;
|
|
274
279
|
function resolveMintAddress(asset, network) {
|
|
@@ -362,8 +367,15 @@ async function verifySPLPayment(params) {
|
|
|
362
367
|
expectedAmount,
|
|
363
368
|
asset,
|
|
364
369
|
clientConfig,
|
|
365
|
-
maxAgeSeconds = 300
|
|
370
|
+
maxAgeSeconds = 300,
|
|
371
|
+
signatureStore
|
|
366
372
|
} = params;
|
|
373
|
+
if (signatureStore) {
|
|
374
|
+
const isUsed = await signatureStore.hasBeenUsed(signature);
|
|
375
|
+
if (isUsed) {
|
|
376
|
+
return { valid: false, confirmed: true, signature, error: "Signature already used" };
|
|
377
|
+
}
|
|
378
|
+
}
|
|
367
379
|
if (!SIGNATURE_REGEX2.test(signature)) {
|
|
368
380
|
return { valid: false, confirmed: false, signature, error: "Invalid signature format" };
|
|
369
381
|
}
|
|
@@ -408,6 +420,27 @@ async function verifySPLPayment(params) {
|
|
|
408
420
|
error: "No valid token transfer to recipient found"
|
|
409
421
|
};
|
|
410
422
|
}
|
|
423
|
+
if (transfer.to) {
|
|
424
|
+
try {
|
|
425
|
+
const destinationInfo = await connection.getParsedAccountInfo(new web3_js.PublicKey(transfer.to));
|
|
426
|
+
const owner = destinationInfo.value?.data?.parsed?.info?.owner;
|
|
427
|
+
if (owner && owner !== expectedRecipient) {
|
|
428
|
+
return {
|
|
429
|
+
valid: false,
|
|
430
|
+
confirmed: true,
|
|
431
|
+
signature,
|
|
432
|
+
error: "Recipient mismatch: Token account not owned by merchant"
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
} catch (e) {
|
|
436
|
+
return {
|
|
437
|
+
valid: false,
|
|
438
|
+
confirmed: true,
|
|
439
|
+
signature,
|
|
440
|
+
error: "Could not verify token account owner"
|
|
441
|
+
};
|
|
442
|
+
}
|
|
443
|
+
}
|
|
411
444
|
if (transfer.mint !== mintAddress) {
|
|
412
445
|
return {
|
|
413
446
|
valid: false,
|
|
@@ -1286,14 +1319,14 @@ async function getSolPrice() {
|
|
|
1286
1319
|
}
|
|
1287
1320
|
}
|
|
1288
1321
|
if (cachedPrice) {
|
|
1289
|
-
return
|
|
1322
|
+
return {
|
|
1323
|
+
...cachedPrice,
|
|
1324
|
+
source: `${cachedPrice.source} (stale)`
|
|
1325
|
+
};
|
|
1290
1326
|
}
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
fetchedAt: /* @__PURE__ */ new Date(),
|
|
1295
|
-
source: "fallback"
|
|
1296
|
-
};
|
|
1327
|
+
throw new Error(
|
|
1328
|
+
"Failed to fetch SOL price from all providers. Configure a custom provider or ensure network connectivity."
|
|
1329
|
+
);
|
|
1297
1330
|
}
|
|
1298
1331
|
async function lamportsToUsd(lamports) {
|
|
1299
1332
|
const { solPrice } = await getSolPrice();
|