@alleyboss/micropay-solana-x402-paywall 2.1.1 → 2.2.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/README.md +32 -17
- package/dist/client/index.cjs.map +1 -1
- package/dist/client/index.d.cts +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/index.js.map +1 -1
- package/dist/{client-Blkcv17a.d.cts → client-D-dteoJw.d.cts} +1 -1
- package/dist/{client-xhJSoeOH.d.ts → client-DfCIRrNG.d.ts} +1 -1
- package/dist/index.cjs +31 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +30 -4
- package/dist/index.js.map +1 -1
- package/dist/middleware/index.cjs +15 -3
- package/dist/middleware/index.cjs.map +1 -1
- package/dist/middleware/index.d.cts +2 -1
- package/dist/middleware/index.d.ts +2 -1
- package/dist/middleware/index.js +15 -3
- package/dist/middleware/index.js.map +1 -1
- package/dist/{nextjs-Bm272Jkj.d.cts → nextjs-BDyOqGAq.d.cts} +4 -1
- package/dist/{nextjs-BK0pVb9Y.d.ts → nextjs-CbX8_9yK.d.ts} +4 -1
- package/dist/{payment-CTxdtqmc.d.cts → payment-BGp7eMQl.d.cts} +2 -0
- package/dist/{payment-CTxdtqmc.d.ts → payment-BGp7eMQl.d.ts} +2 -0
- package/dist/solana/index.cjs.map +1 -1
- package/dist/solana/index.d.cts +3 -3
- package/dist/solana/index.d.ts +3 -3
- package/dist/solana/index.js.map +1 -1
- package/dist/x402/index.cjs +22 -0
- package/dist/x402/index.cjs.map +1 -1
- package/dist/x402/index.d.cts +25 -5
- package/dist/x402/index.d.ts +25 -5
- package/dist/x402/index.js +21 -1
- package/dist/x402/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { A as ArticlePaymentConfig, d as PaymentAsset, a as PaymentPayload, P as PaymentRequirement, c as PaymentStatus, e as SPLTokenAsset, S as SolanaNetwork, T as TOKEN_MINTS, V as VerificationRequest, b as VerificationResponse, X as X402Network } from './payment-
|
|
1
|
+
export { A as ArticlePaymentConfig, d as PaymentAsset, a as PaymentPayload, P as PaymentRequirement, c as PaymentStatus, e as SPLTokenAsset, S as SolanaNetwork, T as TOKEN_MINTS, V as VerificationRequest, b as VerificationResponse, X as X402Network } from './payment-BGp7eMQl.cjs';
|
|
2
2
|
export { a as SessionConfig, S as SessionData, c as SessionJWTPayload, b as SessionValidation } from './session-D2IoWAWV.cjs';
|
|
3
|
-
export { R as RpcConnectionWithFallback, S as SolanaClientConfig, g as getConnection, a as getConnectionWithFallback, i as isMainnet, r as resetConnection, t as toX402Network, w as withFallback } from './client-
|
|
3
|
+
export { R as RpcConnectionWithFallback, S as SolanaClientConfig, g as getConnection, a as getConnectionWithFallback, i as isMainnet, r as resetConnection, t as toX402Network, w as withFallback } from './client-D-dteoJw.cjs';
|
|
4
4
|
export { PriorityFeeConfig, SPLVerificationResult, TransactionVerificationResult, VerifyPaymentParams, VerifySPLPaymentParams, VersionedTransactionConfig, VersionedTransactionResult, buildVersionedTransaction, calculatePriorityFeeCost, createPriorityFeeInstructions, estimatePriorityFee, fetchLookupTables, getTokenDecimals, getWalletTransactions, isNativeAsset, isVersionedTransaction, lamportsToSol, resolveMintAddress, solToLamports, verifyPayment, verifySPLPayment, waitForConfirmation } from './solana/index.cjs';
|
|
5
5
|
export { addArticleToSession, createSession, isArticleUnlocked, validateSession } from './session/index.cjs';
|
|
6
|
-
export { BuildPaymentParams, X402_HEADERS, buildPaymentRequirement, create402Headers, create402ResponseBody, decodePaymentRequired, encodePaymentRequired, encodePaymentResponse, parsePaymentHeader, verifyX402Payment } from './x402/index.cjs';
|
|
6
|
+
export { BuildPaymentParams, X402_HEADERS, buildPaymentRequirement, create402Headers, create402Response, create402ResponseBody, decodePaymentRequired, encodePaymentRequired, encodePaymentRequirement, encodePaymentResponse, parsePaymentHeader, verifyX402Payment } from './x402/index.cjs';
|
|
7
7
|
export { StoreConfig, createRedisStore } from './store/index.cjs';
|
|
8
|
-
export { M as MiddlewareResult, P as PaywallMiddlewareConfig, a as checkPaywallAccess, c as createPaywallMiddleware, w as withPaywall } from './nextjs-
|
|
8
|
+
export { M as MiddlewareResult, P as PaywallMiddlewareConfig, a as checkPaywallAccess, c as createPaywallMiddleware, w as withPaywall } from './nextjs-BDyOqGAq.cjs';
|
|
9
9
|
export { RetryOptions, isRetryableRPCError, withRetry } from './utils/index.cjs';
|
|
10
10
|
export { PaymentFlowConfig, SolanaPayUrlParams, buildSolanaPayUrl, createPaymentFlow, createPaymentReference } from './client/index.cjs';
|
|
11
11
|
export { CustomPriceProvider, PriceConfig, PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToUsd, usdToLamports } from './pricing/index.cjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
export { A as ArticlePaymentConfig, d as PaymentAsset, a as PaymentPayload, P as PaymentRequirement, c as PaymentStatus, e as SPLTokenAsset, S as SolanaNetwork, T as TOKEN_MINTS, V as VerificationRequest, b as VerificationResponse, X as X402Network } from './payment-
|
|
1
|
+
export { A as ArticlePaymentConfig, d as PaymentAsset, a as PaymentPayload, P as PaymentRequirement, c as PaymentStatus, e as SPLTokenAsset, S as SolanaNetwork, T as TOKEN_MINTS, V as VerificationRequest, b as VerificationResponse, X as X402Network } from './payment-BGp7eMQl.js';
|
|
2
2
|
export { a as SessionConfig, S as SessionData, c as SessionJWTPayload, b as SessionValidation } from './session-D2IoWAWV.js';
|
|
3
|
-
export { R as RpcConnectionWithFallback, S as SolanaClientConfig, g as getConnection, a as getConnectionWithFallback, i as isMainnet, r as resetConnection, t as toX402Network, w as withFallback } from './client-
|
|
3
|
+
export { R as RpcConnectionWithFallback, S as SolanaClientConfig, g as getConnection, a as getConnectionWithFallback, i as isMainnet, r as resetConnection, t as toX402Network, w as withFallback } from './client-DfCIRrNG.js';
|
|
4
4
|
export { PriorityFeeConfig, SPLVerificationResult, TransactionVerificationResult, VerifyPaymentParams, VerifySPLPaymentParams, VersionedTransactionConfig, VersionedTransactionResult, buildVersionedTransaction, calculatePriorityFeeCost, createPriorityFeeInstructions, estimatePriorityFee, fetchLookupTables, getTokenDecimals, getWalletTransactions, isNativeAsset, isVersionedTransaction, lamportsToSol, resolveMintAddress, solToLamports, verifyPayment, verifySPLPayment, waitForConfirmation } from './solana/index.js';
|
|
5
5
|
export { addArticleToSession, createSession, isArticleUnlocked, validateSession } from './session/index.js';
|
|
6
|
-
export { BuildPaymentParams, X402_HEADERS, buildPaymentRequirement, create402Headers, create402ResponseBody, decodePaymentRequired, encodePaymentRequired, encodePaymentResponse, parsePaymentHeader, verifyX402Payment } from './x402/index.js';
|
|
6
|
+
export { BuildPaymentParams, X402_HEADERS, buildPaymentRequirement, create402Headers, create402Response, create402ResponseBody, decodePaymentRequired, encodePaymentRequired, encodePaymentRequirement, encodePaymentResponse, parsePaymentHeader, verifyX402Payment } from './x402/index.js';
|
|
7
7
|
export { StoreConfig, createRedisStore } from './store/index.js';
|
|
8
|
-
export { M as MiddlewareResult, P as PaywallMiddlewareConfig, a as checkPaywallAccess, c as createPaywallMiddleware, w as withPaywall } from './nextjs-
|
|
8
|
+
export { M as MiddlewareResult, P as PaywallMiddlewareConfig, a as checkPaywallAccess, c as createPaywallMiddleware, w as withPaywall } from './nextjs-CbX8_9yK.js';
|
|
9
9
|
export { RetryOptions, isRetryableRPCError, withRetry } from './utils/index.js';
|
|
10
10
|
export { PaymentFlowConfig, SolanaPayUrlParams, buildSolanaPayUrl, createPaymentFlow, createPaymentReference } from './client/index.js';
|
|
11
11
|
export { CustomPriceProvider, PriceConfig, PriceData, clearPriceCache, configurePricing, formatPriceDisplay, formatPriceSync, getProviders, getSolPrice, lamportsToUsd, usdToLamports } from './pricing/index.js';
|
package/dist/index.js
CHANGED
|
@@ -801,6 +801,7 @@ async function verifyX402Payment(payload, requirement, clientConfig) {
|
|
|
801
801
|
return {
|
|
802
802
|
valid: true,
|
|
803
803
|
settled: verification.confirmed,
|
|
804
|
+
from: verification.from,
|
|
804
805
|
transaction: {
|
|
805
806
|
signature: verification.signature,
|
|
806
807
|
blockTime: verification.blockTime,
|
|
@@ -826,9 +827,28 @@ function parsePaymentHeader(header) {
|
|
|
826
827
|
return null;
|
|
827
828
|
}
|
|
828
829
|
}
|
|
830
|
+
function encodePaymentRequirement(requirement) {
|
|
831
|
+
return Buffer.from(JSON.stringify(requirement)).toString("base64");
|
|
832
|
+
}
|
|
829
833
|
function encodePaymentResponse(response) {
|
|
830
834
|
return Buffer.from(JSON.stringify(response)).toString("base64");
|
|
831
835
|
}
|
|
836
|
+
function create402Response(requirement, body) {
|
|
837
|
+
const headers = new Headers({
|
|
838
|
+
"Content-Type": "application/json",
|
|
839
|
+
"X-Payment-Required": encodePaymentRequirement(requirement)
|
|
840
|
+
});
|
|
841
|
+
const responseBody = body || {
|
|
842
|
+
error: "Payment Required",
|
|
843
|
+
message: "This resource requires payment to access",
|
|
844
|
+
x402Version: 1,
|
|
845
|
+
accepts: [requirement]
|
|
846
|
+
};
|
|
847
|
+
return new Response(JSON.stringify(responseBody), {
|
|
848
|
+
status: 402,
|
|
849
|
+
headers
|
|
850
|
+
});
|
|
851
|
+
}
|
|
832
852
|
|
|
833
853
|
// src/store/memory.ts
|
|
834
854
|
function createMemoryStore(options = {}) {
|
|
@@ -973,16 +993,22 @@ function createPaywallMiddleware(config2) {
|
|
|
973
993
|
const sessionToken = cookies[cookieName];
|
|
974
994
|
const result = await checkPaywallAccess(path, sessionToken, config2);
|
|
975
995
|
if (!result.allowed && result.requiresPayment) {
|
|
996
|
+
const headers = {
|
|
997
|
+
"Content-Type": "application/json"
|
|
998
|
+
};
|
|
999
|
+
if (config2.paymentRequirement) {
|
|
1000
|
+
const requirement = typeof config2.paymentRequirement === "function" ? config2.paymentRequirement(path) : config2.paymentRequirement;
|
|
1001
|
+
headers["X-Payment-Required"] = encodePaymentRequirement(requirement);
|
|
1002
|
+
}
|
|
976
1003
|
const body = config2.custom402Response ? config2.custom402Response(path) : {
|
|
977
1004
|
error: "Payment Required",
|
|
978
1005
|
message: "This resource requires payment to access",
|
|
1006
|
+
x402Version: 1,
|
|
979
1007
|
path
|
|
980
1008
|
};
|
|
981
1009
|
return new Response(JSON.stringify(body), {
|
|
982
1010
|
status: 402,
|
|
983
|
-
headers
|
|
984
|
-
"Content-Type": "application/json"
|
|
985
|
-
}
|
|
1011
|
+
headers
|
|
986
1012
|
});
|
|
987
1013
|
}
|
|
988
1014
|
return null;
|
|
@@ -1300,6 +1326,6 @@ function getProviders() {
|
|
|
1300
1326
|
return PROVIDERS.map((p) => ({ name: p.name, url: p.url }));
|
|
1301
1327
|
}
|
|
1302
1328
|
|
|
1303
|
-
export { TOKEN_MINTS, X402_HEADERS, addArticleToSession, buildPaymentRequirement, buildSolanaPayUrl, buildVersionedTransaction, calculatePriorityFeeCost, checkPaywallAccess, clearPriceCache, configurePricing, create402Headers, create402ResponseBody, createMemoryStore, createPaymentFlow, createPaymentReference, createPaywallMiddleware, createPriorityFeeInstructions, createRedisStore, createSession, decodePaymentRequired, encodePaymentRequired, encodePaymentResponse, estimatePriorityFee, fetchLookupTables, formatPriceDisplay, formatPriceSync, getConnection, getConnectionWithFallback, getProviders, getSolPrice, getTokenDecimals, getWalletTransactions, isArticleUnlocked, isMainnet, isNativeAsset, isRetryableRPCError, isVersionedTransaction, lamportsToSol, lamportsToUsd, parsePaymentHeader, resetConnection, resolveMintAddress, solToLamports, toX402Network, usdToLamports, validateSession, verifyPayment, verifySPLPayment, verifyX402Payment, waitForConfirmation, withFallback, withPaywall, withRetry };
|
|
1329
|
+
export { TOKEN_MINTS, X402_HEADERS, addArticleToSession, buildPaymentRequirement, buildSolanaPayUrl, buildVersionedTransaction, calculatePriorityFeeCost, checkPaywallAccess, clearPriceCache, configurePricing, create402Headers, create402Response, create402ResponseBody, createMemoryStore, createPaymentFlow, createPaymentReference, createPaywallMiddleware, createPriorityFeeInstructions, createRedisStore, createSession, decodePaymentRequired, encodePaymentRequired, encodePaymentRequirement, encodePaymentResponse, estimatePriorityFee, fetchLookupTables, formatPriceDisplay, formatPriceSync, getConnection, getConnectionWithFallback, getProviders, getSolPrice, getTokenDecimals, getWalletTransactions, isArticleUnlocked, isMainnet, isNativeAsset, isRetryableRPCError, isVersionedTransaction, lamportsToSol, lamportsToUsd, parsePaymentHeader, resetConnection, resolveMintAddress, solToLamports, toX402Network, usdToLamports, validateSession, verifyPayment, verifySPLPayment, verifyX402Payment, waitForConfirmation, withFallback, withPaywall, withRetry };
|
|
1304
1330
|
//# sourceMappingURL=index.js.map
|
|
1305
1331
|
//# sourceMappingURL=index.js.map
|