@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/README.md
CHANGED
|
@@ -19,7 +19,7 @@ npm install @alleyboss/micropay-solana-x402-paywall @solana/web3.js
|
|
|
19
19
|
| Feature | Description |
|
|
20
20
|
|---------|-------------|
|
|
21
21
|
| 💰 **SOL & USDC Payments** | Native SOL and SPL tokens (USDC, USDT) |
|
|
22
|
-
| 🔐 **x402 Protocol** | HTTP 402 Payment
|
|
22
|
+
| 🔐 **x402 Protocol** | Full HTTP 402 compliance with `X-Payment-Required` headers |
|
|
23
23
|
| 🔑 **JWT Sessions** | Secure unlock tracking with anti-replay |
|
|
24
24
|
| 🛡️ **Signature Store** | Prevent double-spend at app layer |
|
|
25
25
|
| 🔌 **Express & Next.js** | Zero-boilerplate middleware |
|
|
@@ -82,27 +82,42 @@ import { getSolPrice, formatPriceDisplay, configurePricing } from '@alleyboss/mi
|
|
|
82
82
|
import { withRetry } from '@alleyboss/micropay-solana-x402-paywall/utils';
|
|
83
83
|
```
|
|
84
84
|
|
|
85
|
-
## 🔥 New in v2.
|
|
85
|
+
## 🔥 New in v2.2.0
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
- **TDD Test Suite** — Comprehensive tests with vitest (must pass before npm publish)
|
|
87
|
+
### x402 Protocol Compliance
|
|
88
|
+
|
|
89
|
+
Full compliance with the [x402.org](https://x402.org) specification:
|
|
91
90
|
|
|
92
91
|
```typescript
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
92
|
+
import { create402Response, parsePaymentHeader, encodePaymentRequirement } from '@alleyboss/micropay-solana-x402-paywall/x402';
|
|
93
|
+
|
|
94
|
+
// Create 402 response with X-Payment-Required header
|
|
95
|
+
const response = create402Response({
|
|
96
|
+
scheme: 'exact',
|
|
97
|
+
network: 'solana-mainnet',
|
|
98
|
+
maxAmountRequired: '10000000',
|
|
99
|
+
payTo: 'CreatorWallet...',
|
|
100
|
+
resource: '/api/premium',
|
|
101
|
+
description: 'Premium content access',
|
|
102
|
+
maxTimeoutSeconds: 300,
|
|
103
|
+
asset: 'native',
|
|
104
|
+
});
|
|
105
|
+
// Response includes: X-Payment-Required: <base64-encoded-requirement>
|
|
103
106
|
|
|
107
|
+
// Parse X-Payment header from client
|
|
108
|
+
const payload = parsePaymentHeader(request.headers.get('x-payment'));
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Previous Features (v2.1.x)
|
|
112
|
+
|
|
113
|
+
- **RPC Fallback Support** — Automatic failover on primary RPC failure
|
|
114
|
+
- **Priority Fees** — Compute budget instructions for landing transactions faster
|
|
115
|
+
- **Versioned Transactions** — Full v0 transaction support with lookup tables
|
|
116
|
+
- **TDD Test Suite** — Comprehensive tests with vitest
|
|
117
|
+
|
|
118
|
+
```typescript
|
|
104
119
|
// Priority fees
|
|
105
|
-
import { createPriorityFeeInstructions
|
|
120
|
+
import { createPriorityFeeInstructions } from '@alleyboss/micropay-solana-x402-paywall/solana';
|
|
106
121
|
|
|
107
122
|
const instructions = createPriorityFeeInstructions({
|
|
108
123
|
enabled: true,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/payment.ts","../../src/client/payment.ts"],"names":[],"mappings":";;;AAoBO,IAAM,WAAA,GAAc;AAAA;AAAA,EAEvB,YAAA,EAAc,8CAAA;AAAA;AAAA,EAEd,WAAA,EAAa,8CAAA;AAAA;AAAA,EAEb,YAAA,EAAc;AAClB,CAAA;;;AC2BO,SAAS,kBAAkB,MAAA,EAAoC;AAClE,EAAA,MAAM,EAAE,SAAA,EAAW,MAAA,EAAQ,UAAU,SAAA,EAAW,KAAA,EAAO,SAAQ,GAAI,MAAA;AAEnE,EAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,CAAA,OAAA,EAAU,SAAS,CAAA,CAAE,CAAA;AAEzC,EAAA,IAAI,WAAW,MAAA,EAAW;AACtB,IAAA,GAAA,CAAI,YAAA,CAAa,GAAA,CAAI,QAAA,EAAU,MAAA,CAAO,UAAU,CAAA;AAAA,EACpD;AAEA,EAAA,IAAI,QAAA,EAAU;AACV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,CAAA;AAAA,IAC5C;AAAA,GACJ;AACJ;AAMO,SAAS,sBAAA,GAAiC;AAC7C,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,MAAA,CAAO,UAAA,EAAY;AACpD,IAAA,OAAO,OAAO,UAAA,EAAW;AAAA,EAC7B;AAEA,EAAA,OAAO,CAAA,EAAG,IAAA,CAAK,GAAA,EAAK,IAAI,IAAA,CAAK,MAAA,EAAO,CAAE,QAAA,CAAS,EAAE,CAAA,CAAE,KAAA,CAAM,CAAA,EAAG,EAAE,CAAC,CAAA,CAAA;AACnE","file":"index.cjs","sourcesContent":["// Payment-related TypeScript types for x402 protocol\n\n/** x402 network identifiers for Solana */\nexport type X402Network = 'solana-devnet' | 'solana-mainnet';\n\n/** Solana network types */\nexport type SolanaNetwork = 'devnet' | 'mainnet-beta';\n\n/** SPL Token asset specification */\nexport interface SPLTokenAsset {\n /** Token mint address */\n mint: string;\n /** Token decimals (default: 6 for USDC/USDT) */\n decimals?: number;\n}\n\n/** Asset types for payments */\nexport type PaymentAsset = 'native' | 'usdc' | 'usdt' | SPLTokenAsset;\n\n/** Known SPL token mint addresses */\nexport const TOKEN_MINTS = {\n /** USDC on mainnet */\n USDC_MAINNET: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',\n /** USDC on devnet */\n USDC_DEVNET: '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU',\n /** USDT on mainnet */\n USDT_MAINNET: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',\n} as const;\n\n/** Payment requirement for x402 protocol */\nexport interface PaymentRequirement {\n /** Payment scheme - currently only 'exact' is supported */\n scheme: 'exact';\n /** Network identifier for x402 */\n network: X402Network;\n /** Amount in smallest unit as string (lamports for SOL, base units for tokens) */\n maxAmountRequired: string;\n /** URL of the protected resource */\n resource: string;\n /** Human-readable description */\n description: string;\n /** MIME type of the resource */\n mimeType?: string;\n /** Recipient wallet address */\n payTo: string;\n /** Maximum time in seconds to complete payment */\n maxTimeoutSeconds: number;\n /** Asset type - 'native' for SOL, 'usdc', 'usdt', or custom mint */\n asset: PaymentAsset;\n /** Additional metadata */\n extra?: {\n name?: string;\n articleId?: string;\n [key: string]: unknown;\n };\n}\n\n/** Payment payload sent by client after transaction */\nexport interface PaymentPayload {\n /** x402 protocol version */\n x402Version: number;\n /** Payment scheme */\n scheme: 'exact';\n /** Network identifier */\n network: X402Network;\n /** Transaction details */\n payload: {\n /** Transaction signature (base58) */\n signature: string;\n /** Base64 encoded transaction (optional) */\n transaction?: string;\n };\n}\n\n/** Request to verify a payment */\nexport interface VerificationRequest {\n paymentPayload: PaymentPayload;\n paymentRequirements: PaymentRequirement;\n}\n\n/** Response from payment verification */\nexport interface VerificationResponse {\n /** Whether the payment is valid */\n valid: boolean;\n /** Reason for invalid payment */\n invalidReason?: string;\n /** Whether the transaction is settled on-chain */\n settled?: boolean;\n /** Transaction details */\n transaction?: {\n signature: string;\n blockTime?: number;\n slot?: number;\n };\n}\n\n/** Payment status for tracking */\nexport interface PaymentStatus {\n status: 'pending' | 'confirmed' | 'failed' | 'expired';\n signature?: string;\n confirmations?: number;\n error?: string;\n}\n\n/** x402 HTTP header constants */\nexport const X402_HEADERS = {\n PAYMENT_REQUIRED: 'x-payment-required',\n PAYMENT: 'x-payment',\n PAYMENT_RESPONSE: 'x-payment-response',\n} as const;\n\n/** Configuration for article pricing */\nexport interface ArticlePaymentConfig {\n articleId: string;\n priceInLamports: bigint;\n title: string;\n description?: string;\n}\n","// Client-Side Payment Flow Helper\n// Headless payment flow for frontend integration (no Node.js dependencies)\n\nimport { TOKEN_MINTS, type PaymentAsset, type SolanaNetwork } from '../types';\n\n/**\n * Payment flow configuration\n */\nexport interface PaymentFlowConfig {\n /** Solana network */\n network: SolanaNetwork;\n /** Recipient wallet address */\n recipientWallet: string;\n /** Amount in smallest unit (lamports or token base units) */\n amount: bigint;\n /** Asset to pay with */\n asset?: PaymentAsset;\n /** Optional memo for the transaction */\n memo?: string;\n}\n\n/**\n * Solana Pay URL parameters\n */\nexport interface SolanaPayUrlParams {\n /** Recipient address */\n recipient: string;\n /** Amount in token's natural units (e.g., SOL, not lamports) */\n amount?: number;\n /** SPL token mint address */\n splToken?: string;\n /** Transaction reference */\n reference?: string;\n /** Label for the recipient */\n label?: string;\n /** Memo/message */\n message?: string;\n}\n\n/**\n * Build a Solana Pay URL for QR codes and deep linking\n * Compatible with Phantom, Solflare, and other Solana Pay wallets\n * \n * @example\n * ```typescript\n * const url = buildSolanaPayUrl({\n * recipient: 'CreatorWalletAddress',\n * amount: 0.01,\n * label: 'Article Unlock',\n * message: 'Premium Content Access',\n * });\n * // Returns: solana:CreatorWalletAddress?amount=0.01&label=Article%20Unlock&message=Premium%20Content%20Access\n * ```\n */\nexport function buildSolanaPayUrl(params: SolanaPayUrlParams): string {\n const { recipient, amount, splToken, reference, label, message } = params;\n\n const url = new URL(`solana:${recipient}`);\n\n if (amount !== undefined) {\n url.searchParams.set('amount', amount.toString());\n }\n\n if (splToken) {\n url.searchParams.set('spl-token', splToken);\n }\n\n if (reference) {\n url.searchParams.set('reference', reference);\n }\n\n if (label) {\n url.searchParams.set('label', label);\n }\n\n if (message) {\n url.searchParams.set('message', message);\n }\n\n return url.toString();\n}\n\n/**\n * Create a payment flow helper for frontend use\n * Provides utilities for building transactions and generating QR codes\n * \n * @example\n * ```typescript\n * const flow = createPaymentFlow({\n * network: 'devnet',\n * recipientWallet: 'CreatorAddress',\n * amount: 10000000n, // 0.01 SOL\n * });\n * \n * // Generate QR code URL\n * const qrUrl = flow.getSolanaPayUrl({ label: 'Unlock Article' });\n * \n * // Get transaction amount in natural units\n * const amountInSol = flow.getDisplayAmount();\n * ```\n */\nexport function createPaymentFlow(config: PaymentFlowConfig) {\n const { network, recipientWallet, amount, asset = 'native', memo } = config;\n\n // Determine decimals and mint\n let decimals = 9; // SOL default\n let mintAddress: string | undefined;\n\n if (asset === 'usdc') {\n decimals = 6;\n mintAddress = network === 'mainnet-beta' ? TOKEN_MINTS.USDC_MAINNET : TOKEN_MINTS.USDC_DEVNET;\n } else if (asset === 'usdt') {\n decimals = 6;\n mintAddress = TOKEN_MINTS.USDT_MAINNET;\n } else if (typeof asset === 'object' && 'mint' in asset) {\n decimals = asset.decimals ?? 6;\n mintAddress = asset.mint;\n }\n\n // Convert to natural units (from lamports/base units)\n const naturalAmount = Number(amount) / Math.pow(10, decimals);\n\n return {\n /** Get the payment configuration */\n getConfig: () => ({ ...config }),\n\n /** Get amount in natural display units (e.g., 0.01 SOL) */\n getDisplayAmount: () => naturalAmount,\n\n /** Get amount formatted with symbol */\n getFormattedAmount: () => {\n const symbol = asset === 'native' ? 'SOL'\n : asset === 'usdc' ? 'USDC'\n : asset === 'usdt' ? 'USDT'\n : 'tokens';\n return `${naturalAmount.toFixed(decimals > 6 ? 4 : 2)} ${symbol}`;\n },\n\n /** Generate Solana Pay URL for QR codes */\n getSolanaPayUrl: (options: { label?: string; reference?: string } = {}) => {\n return buildSolanaPayUrl({\n recipient: recipientWallet,\n amount: naturalAmount,\n splToken: mintAddress,\n label: options.label,\n reference: options.reference,\n message: memo,\n });\n },\n\n /** Get the token mint address (undefined for native SOL) */\n getMintAddress: () => mintAddress,\n\n /** Check if this is a native SOL payment */\n isNativePayment: () => asset === 'native',\n\n /** Get network information */\n getNetworkInfo: () => ({\n network,\n isMainnet: network === 'mainnet-beta',\n explorerUrl: network === 'mainnet-beta'\n ? 'https://explorer.solana.com'\n : 'https://explorer.solana.com?cluster=devnet',\n }),\n\n /** Build explorer URL for a transaction */\n getExplorerUrl: (signature: string) => {\n const baseUrl = 'https://explorer.solana.com/tx';\n const cluster = network === 'mainnet-beta' ? '' : '?cluster=devnet';\n return `${baseUrl}/${signature}${cluster}`;\n },\n };\n}\n\n/**\n * Create a unique reference for payment tracking\n * Uses crypto.randomUUID when available\n */\nexport function createPaymentReference(): string {\n if (typeof crypto !== 'undefined' && crypto.randomUUID) {\n return crypto.randomUUID();\n }\n // Fallback for environments without crypto.randomUUID\n return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/types/payment.ts","../../src/client/payment.ts"],"names":[],"mappings":";;;AAoBO,IAAM,WAAA,GAAc;AAAA;AAAA,EAEvB,YAAA,EAAc,8CAAA;AAAA;AAAA,EAEd,WAAA,EAAa,8CAAA;AAAA;AAAA,EAEb,YAAA,EAAc;AAClB,CAAA;;;AC2BO,SAAS,kBAAkB,MAAA,EAAoC;AAClE,EAAA,MAAM,EAAE,SAAA,EAAW,MAAA,EAAQ,UAAU,SAAA,EAAW,KAAA,EAAO,SAAQ,GAAI,MAAA;AAEnE,EAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,CAAA,OAAA,EAAU,SAAS,CAAA,CAAE,CAAA;AAEzC,EAAA,IAAI,WAAW,MAAA,EAAW;AACtB,IAAA,GAAA,CAAI,YAAA,CAAa,GAAA,CAAI,QAAA,EAAU,MAAA,CAAO,UAAU,CAAA;AAAA,EACpD;AAEA,EAAA,IAAI,QAAA,EAAU;AACV,IAAA,GAAA,CAAI,YAAA,CAAa,GAAA,CAAI,WAAA,EAAa,QAAQ,CAAA;AAAA,EAC9C;AAEA,EAAA,IAAI,SAAA,EAAW;AACX,IAAA,GAAA,CAAI,YAAA,CAAa,GAAA,CAAI,WAAA,EAAa,SAAS,CAAA;AAAA,EAC/C;AAEA,EAAA,IAAI,KAAA,EAAO;AACP,IAAA,GAAA,CAAI,YAAA,CAAa,GAAA,CAAI,OAAA,EAAS,KAAK,CAAA;AAAA,EACvC;AAEA,EAAA,IAAI,OAAA,EAAS;AACT,IAAA,GAAA,CAAI,YAAA,CAAa,GAAA,CAAI,SAAA,EAAW,OAAO,CAAA;AAAA,EAC3C;AAEA,EAAA,OAAO,IAAI,QAAA,EAAS;AACxB;AAqBO,SAAS,kBAAkB,MAAA,EAA2B;AACzD,EAAA,MAAM,EAAE,OAAA,EAAS,e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eAAA;AAAA,QACX,MAAA,EAAQ,aAAA;AAAA,QACR,QAAA,EAAU,WAAA;AAAA,QACV,OAAO,OAAA,CAAQ,KAAA;AAAA,QACf,WAAW,OAAA,CAAQ,SAAA;AAAA,QACnB,OAAA,EAAS;AAAA,OACZ,CAAA;AAAA,IACL,CAAA;AAAA;AAAA,IAGA,gBAAgB,MAAM,WAAA;AAAA;AAAA,IAGtB,eAAA,EAAiB,MAAM,KAAA,KAAU,QAAA;AAAA;AAAA,IAGjC,gBAAgB,OAAO;AAAA,MACnB,OAAA;AAAA,MACA,WAAW,OAAA,KAAY,cAAA;AAAA,MACvB,WAAA,EAAa,OAAA,KAAY,cAAA,GACnB,6BAAA,GACA;AAAA,KACV,CAAA;AAAA;AAAA,IAGA,cAAA,EAAgB,CAAC,SAAA,KAAsB;AACnC,MAAA,MAAM,OAAA,GAAU,gCAAA;AAChB,MAAA,MAAM,OAAA,GAAU,OAAA,KAAY,cAAA,GAAiB,EAAA,GAAK,iBAAA;AAClD,MAAA,OAAO,CAAA,EAAG,OAAO,CAAA,CAAA,EAAI,SAAS,GAAG,OAAO,CAAA,CAAA;AAAA,IAC5C;AAAA,GACJ;AACJ;AAMO,SAAS,sBAAA,GAAiC;AAC7C,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,MAAA,CAAO,UAAA,EAAY;AACpD,IAAA,OAAO,OAAO,UAAA,EAAW;AAAA,EAC7B;AAEA,EAAA,OAAO,CAAA,EAAG,IAAA,CAAK,GAAA,EAAK,IAAI,IAAA,CAAK,MAAA,EAAO,CAAE,QAAA,CAAS,EAAE,CAAA,CAAE,KAAA,CAAM,CAAA,EAAG,EAAE,CAAC,CAAA,CAAA;AACnE","file":"index.cjs","sourcesContent":["// Payment-related TypeScript types for x402 protocol\n\n/** x402 network identifiers for Solana */\nexport type X402Network = 'solana-devnet' | 'solana-mainnet';\n\n/** Solana network types */\nexport type SolanaNetwork = 'devnet' | 'mainnet-beta';\n\n/** SPL Token asset specification */\nexport interface SPLTokenAsset {\n /** Token mint address */\n mint: string;\n /** Token decimals (default: 6 for USDC/USDT) */\n decimals?: number;\n}\n\n/** Asset types for payments */\nexport type PaymentAsset = 'native' | 'usdc' | 'usdt' | SPLTokenAsset;\n\n/** Known SPL token mint addresses */\nexport const TOKEN_MINTS = {\n /** USDC on mainnet */\n USDC_MAINNET: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',\n /** USDC on devnet */\n USDC_DEVNET: '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU',\n /** USDT on mainnet */\n USDT_MAINNET: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',\n} as const;\n\n/** Payment requirement for x402 protocol */\nexport interface PaymentRequirement {\n /** Payment scheme - currently only 'exact' is supported */\n scheme: 'exact';\n /** Network identifier for x402 */\n network: X402Network;\n /** Amount in smallest unit as string (lamports for SOL, base units for tokens) */\n maxAmountRequired: string;\n /** URL of the protected resource */\n resource: string;\n /** Human-readable description */\n description: string;\n /** MIME type of the resource */\n mimeType?: string;\n /** Recipient wallet address */\n payTo: string;\n /** Maximum time in seconds to complete payment */\n maxTimeoutSeconds: number;\n /** Asset type - 'native' for SOL, 'usdc', 'usdt', or custom mint */\n asset: PaymentAsset;\n /** Additional metadata */\n extra?: {\n name?: string;\n articleId?: string;\n [key: string]: unknown;\n };\n}\n\n/** Payment payload sent by client after transaction */\nexport interface PaymentPayload {\n /** x402 protocol version */\n x402Version: number;\n /** Payment scheme */\n scheme: 'exact';\n /** Network identifier */\n network: X402Network;\n /** Transaction details */\n payload: {\n /** Transaction signature (base58) */\n signature: string;\n /** Base64 encoded transaction (optional) */\n transaction?: string;\n };\n}\n\n/** Request to verify a payment */\nexport interface VerificationRequest {\n paymentPayload: PaymentPayload;\n paymentRequirements: PaymentRequirement;\n}\n\n/** Response from payment verification */\nexport interface VerificationResponse {\n /** Whether the payment is valid */\n valid: boolean;\n /** Reason for invalid payment */\n invalidReason?: string;\n /** Whether the transaction is settled on-chain */\n settled?: boolean;\n /** Sender wallet address (payer) */\n from?: string;\n /** Transaction details */\n transaction?: {\n signature: string;\n blockTime?: number;\n slot?: number;\n };\n}\n\n/** Payment status for tracking */\nexport interface PaymentStatus {\n status: 'pending' | 'confirmed' | 'failed' | 'expired';\n signature?: string;\n confirmations?: number;\n error?: string;\n}\n\n/** x402 HTTP header constants */\nexport const X402_HEADERS = {\n PAYMENT_REQUIRED: 'x-payment-required',\n PAYMENT: 'x-payment',\n PAYMENT_RESPONSE: 'x-payment-response',\n} as const;\n\n/** Configuration for article pricing */\nexport interface ArticlePaymentConfig {\n articleId: string;\n priceInLamports: bigint;\n title: string;\n description?: string;\n}\n","// Client-Side Payment Flow Helper\n// Headless payment flow for frontend integration (no Node.js dependencies)\n\nimport { TOKEN_MINTS, type PaymentAsset, type SolanaNetwork } from '../types';\n\n/**\n * Payment flow configuration\n */\nexport interface PaymentFlowConfig {\n /** Solana network */\n network: SolanaNetwork;\n /** Recipient wallet address */\n recipientWallet: string;\n /** Amount in smallest unit (lamports or token base units) */\n amount: bigint;\n /** Asset to pay with */\n asset?: PaymentAsset;\n /** Optional memo for the transaction */\n memo?: string;\n}\n\n/**\n * Solana Pay URL parameters\n */\nexport interface SolanaPayUrlParams {\n /** Recipient address */\n recipient: string;\n /** Amount in token's natural units (e.g., SOL, not lamports) */\n amount?: number;\n /** SPL token mint address */\n splToken?: string;\n /** Transaction reference */\n reference?: string;\n /** Label for the recipient */\n label?: string;\n /** Memo/message */\n message?: string;\n}\n\n/**\n * Build a Solana Pay URL for QR codes and deep linking\n * Compatible with Phantom, Solflare, and other Solana Pay wallets\n * \n * @example\n * ```typescript\n * const url = buildSolanaPayUrl({\n * recipient: 'CreatorWalletAddress',\n * amount: 0.01,\n * label: 'Article Unlock',\n * message: 'Premium Content Access',\n * });\n * // Returns: solana:CreatorWalletAddress?amount=0.01&label=Article%20Unlock&message=Premium%20Content%20Access\n * ```\n */\nexport function buildSolanaPayUrl(params: SolanaPayUrlParams): string {\n const { recipient, amount, splToken, reference, label, message } = params;\n\n const url = new URL(`solana:${recipient}`);\n\n if (amount !== undefined) {\n url.searchParams.set('amount', amount.toString());\n }\n\n if (splToken) {\n url.searchParams.set('spl-token', splToken);\n }\n\n if (reference) {\n url.searchParams.set('reference', reference);\n }\n\n if (label) {\n url.searchParams.set('label', label);\n }\n\n if (message) {\n url.searchParams.set('message', message);\n }\n\n return url.toString();\n}\n\n/**\n * Create a payment flow helper for frontend use\n * Provides utilities for building transactions and generating QR codes\n * \n * @example\n * ```typescript\n * const flow = createPaymentFlow({\n * network: 'devnet',\n * recipientWallet: 'CreatorAddress',\n * amount: 10000000n, // 0.01 SOL\n * });\n * \n * // Generate QR code URL\n * const qrUrl = flow.getSolanaPayUrl({ label: 'Unlock Article' });\n * \n * // Get transaction amount in natural units\n * const amountInSol = flow.getDisplayAmount();\n * ```\n */\nexport function createPaymentFlow(config: PaymentFlowConfig) {\n const { network, recipientWallet, amount, asset = 'native', memo } = config;\n\n // Determine decimals and mint\n let decimals = 9; // SOL default\n let mintAddress: string | undefined;\n\n if (asset === 'usdc') {\n decimals = 6;\n mintAddress = network === 'mainnet-beta' ? TOKEN_MINTS.USDC_MAINNET : TOKEN_MINTS.USDC_DEVNET;\n } else if (asset === 'usdt') {\n decimals = 6;\n mintAddress = TOKEN_MINTS.USDT_MAINNET;\n } else if (typeof asset === 'object' && 'mint' in asset) {\n decimals = asset.decimals ?? 6;\n mintAddress = asset.mint;\n }\n\n // Convert to natural units (from lamports/base units)\n const naturalAmount = Number(amount) / Math.pow(10, decimals);\n\n return {\n /** Get the payment configuration */\n getConfig: () => ({ ...config }),\n\n /** Get amount in natural display units (e.g., 0.01 SOL) */\n getDisplayAmount: () => naturalAmount,\n\n /** Get amount formatted with symbol */\n getFormattedAmount: () => {\n const symbol = asset === 'native' ? 'SOL'\n : asset === 'usdc' ? 'USDC'\n : asset === 'usdt' ? 'USDT'\n : 'tokens';\n return `${naturalAmount.toFixed(decimals > 6 ? 4 : 2)} ${symbol}`;\n },\n\n /** Generate Solana Pay URL for QR codes */\n getSolanaPayUrl: (options: { label?: string; reference?: string } = {}) => {\n return buildSolanaPayUrl({\n recipient: recipientWallet,\n amount: naturalAmount,\n splToken: mintAddress,\n label: options.label,\n reference: options.reference,\n message: memo,\n });\n },\n\n /** Get the token mint address (undefined for native SOL) */\n getMintAddress: () => mintAddress,\n\n /** Check if this is a native SOL payment */\n isNativePayment: () => asset === 'native',\n\n /** Get network information */\n getNetworkInfo: () => ({\n network,\n isMainnet: network === 'mainnet-beta',\n explorerUrl: network === 'mainnet-beta'\n ? 'https://explorer.solana.com'\n : 'https://explorer.solana.com?cluster=devnet',\n }),\n\n /** Build explorer URL for a transaction */\n getExplorerUrl: (signature: string) => {\n const baseUrl = 'https://explorer.solana.com/tx';\n const cluster = network === 'mainnet-beta' ? '' : '?cluster=devnet';\n return `${baseUrl}/${signature}${cluster}`;\n },\n };\n}\n\n/**\n * Create a unique reference for payment tracking\n * Uses crypto.randomUUID when available\n */\nexport function createPaymentReference(): string {\n if (typeof crypto !== 'undefined' && crypto.randomUUID) {\n return crypto.randomUUID();\n }\n // Fallback for environments without crypto.randomUUID\n return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;\n}\n"]}
|
package/dist/client/index.d.cts
CHANGED
package/dist/client/index.d.ts
CHANGED
package/dist/client/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/types/payment.ts","../../src/client/payment.ts"],"names":[],"mappings":";AAoBO,IAAM,WAAA,GAAc;AAAA;AAAA,EAEvB,YAAA,EAAc,8CAAA;AAAA;AAAA,EAEd,WAAA,EAAa,8CAAA;AAAA;AAAA,EAEb,YAAA,EAAc;AAClB,CAAA;;;AC2BO,SAAS,kBAAkB,MAAA,EAAoC;AAClE,EAAA,MAAM,EAAE,SAAA,EAAW,MAAA,EAAQ,UAAU,SAAA,EAAW,KAAA,EAAO,SAA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GACnB,6BAAA,GACA;AAAA,KACV,CAAA;AAAA;AAAA,IAGA,cAAA,EAAgB,CAAC,SAAA,KAAsB;AACnC,MAAA,MAAM,OAAA,GAAU,gCAAA;AAChB,MAAA,MAAM,OAAA,GAAU,OAAA,KAAY,cAAA,GAAiB,EAAA,GAAK,iBAAA;AAClD,MAAA,OAAO,CAAA,EAAG,OAAO,CAAA,CAAA,EAAI,SAAS,GAAG,OAAO,CAAA,CAAA;AAAA,IAC5C;AAAA,GACJ;AACJ;AAMO,SAAS,sBAAA,GAAiC;AAC7C,EAAA,IAAI,OAAO,MAAA,KAAW,WAAA,IAAe,MAAA,CAAO,UAAA,EAAY;AACpD,IAAA,OAAO,OAAO,UAAA,EAAW;AAAA,EAC7B;AAEA,EAAA,OAAO,CAAA,EAAG,IAAA,CAAK,GAAA,EAAK,IAAI,IAAA,CAAK,MAAA,EAAO,CAAE,QAAA,CAAS,EAAE,CAAA,CAAE,KAAA,CAAM,CAAA,EAAG,EAAE,CAAC,CAAA,CAAA;AACnE","file":"index.js","sourcesContent":["// Payment-related TypeScript types for x402 protocol\n\n/** x402 network identifiers for Solana */\nexport type X402Network = 'solana-devnet' | 'solana-mainnet';\n\n/** Solana network types */\nexport type SolanaNetwork = 'devnet' | 'mainnet-beta';\n\n/** SPL Token asset specification */\nexport interface SPLTokenAsset {\n /** Token mint address */\n mint: string;\n /** Token decimals (default: 6 for USDC/USDT) */\n decimals?: number;\n}\n\n/** Asset types for payments */\nexport type PaymentAsset = 'native' | 'usdc' | 'usdt' | SPLTokenAsset;\n\n/** Known SPL token mint addresses */\nexport const TOKEN_MINTS = {\n /** USDC on mainnet */\n USDC_MAINNET: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',\n /** USDC on devnet */\n USDC_DEVNET: '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU',\n /** USDT on mainnet */\n USDT_MAINNET: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',\n} as const;\n\n/** Payment requirement for x402 protocol */\nexport interface PaymentRequirement {\n /** Payment scheme - currently only 'exact' is supported */\n scheme: 'exact';\n /** Network identifier for x402 */\n network: X402Network;\n /** Amount in smallest unit as string (lamports for SOL, base units for tokens) */\n maxAmountRequired: string;\n /** URL of the protected resource */\n resource: string;\n /** Human-readable description */\n description: string;\n /** MIME type of the resource */\n mimeType?: string;\n /** Recipient wallet address */\n payTo: string;\n /** Maximum time in seconds to complete payment */\n maxTimeoutSeconds: number;\n /** Asset type - 'native' for SOL, 'usdc', 'usdt', or custom mint */\n asset: PaymentAsset;\n /** Additional metadata */\n extra?: {\n name?: string;\n articleId?: string;\n [key: string]: unknown;\n };\n}\n\n/** Payment payload sent by client after transaction */\nexport interface PaymentPayload {\n /** x402 protocol version */\n x402Version: number;\n /** Payment scheme */\n scheme: 'exact';\n /** Network identifier */\n network: X402Network;\n /** Transaction details */\n payload: {\n /** Transaction signature (base58) */\n signature: string;\n /** Base64 encoded transaction (optional) */\n transaction?: string;\n };\n}\n\n/** Request to verify a payment */\nexport interface VerificationRequest {\n paymentPayload: PaymentPayload;\n paymentRequirements: PaymentRequirement;\n}\n\n/** Response from payment verification */\nexport interface VerificationResponse {\n /** Whether the payment is valid */\n valid: boolean;\n /** Reason for invalid payment */\n invalidReason?: string;\n /** Whether the transaction is settled on-chain */\n settled?: boolean;\n /** Transaction details */\n transaction?: {\n signature: string;\n blockTime?: number;\n slot?: number;\n };\n}\n\n/** Payment status for tracking */\nexport interface PaymentStatus {\n status: 'pending' | 'confirmed' | 'failed' | 'expired';\n signature?: string;\n confirmations?: number;\n error?: string;\n}\n\n/** x402 HTTP header constants */\nexport const X402_HEADERS = {\n PAYMENT_REQUIRED: 'x-payment-required',\n PAYMENT: 'x-payment',\n PAYMENT_RESPONSE: 'x-payment-response',\n} as const;\n\n/** Configuration for article pricing */\nexport interface ArticlePaymentConfig {\n articleId: string;\n priceInLamports: bigint;\n title: string;\n description?: string;\n}\n","// Client-Side Payment Flow Helper\n// Headless payment flow for frontend integration (no Node.js dependencies)\n\nimport { TOKEN_MINTS, type PaymentAsset, type SolanaNetwork } from '../types';\n\n/**\n * Payment flow configuration\n */\nexport interface PaymentFlowConfig {\n /** Solana network */\n network: SolanaNetwork;\n /** Recipient wallet address */\n recipientWallet: string;\n /** Amount in smallest unit (lamports or token base units) */\n amount: bigint;\n /** Asset to pay with */\n asset?: PaymentAsset;\n /** Optional memo for the transaction */\n memo?: string;\n}\n\n/**\n * Solana Pay URL parameters\n */\nexport interface SolanaPayUrlParams {\n /** Recipient address */\n recipient: string;\n /** Amount in token's natural units (e.g., SOL, not lamports) */\n amount?: number;\n /** SPL token mint address */\n splToken?: string;\n /** Transaction reference */\n reference?: string;\n /** Label for the recipient */\n label?: string;\n /** Memo/message */\n message?: string;\n}\n\n/**\n * Build a Solana Pay URL for QR codes and deep linking\n * Compatible with Phantom, Solflare, and other Solana Pay wallets\n * \n * @example\n * ```typescript\n * const url = buildSolanaPayUrl({\n * recipient: 'CreatorWalletAddress',\n * amount: 0.01,\n * label: 'Article Unlock',\n * message: 'Premium Content Access',\n * });\n * // Returns: solana:CreatorWalletAddress?amount=0.01&label=Article%20Unlock&message=Premium%20Content%20Access\n * ```\n */\nexport function buildSolanaPayUrl(params: SolanaPayUrlParams): string {\n const { recipient, amount, splToken, reference, label, message } = params;\n\n const url = new URL(`solana:${recipient}`);\n\n if (amount !== undefined) {\n url.searchParams.set('amount', amount.toString());\n }\n\n if (splToken) {\n url.searchParams.set('spl-token', splToken);\n }\n\n if (reference) {\n url.searchParams.set('reference', reference);\n }\n\n if (label) {\n url.searchParams.set('label', label);\n }\n\n if (message) {\n url.searchParams.set('message', message);\n }\n\n return url.toString();\n}\n\n/**\n * Create a payment flow helper for frontend use\n * Provides utilities for building transactions and generating QR codes\n * \n * @example\n * ```typescript\n * const flow = createPaymentFlow({\n * network: 'devnet',\n * recipientWallet: 'CreatorAddress',\n * amount: 10000000n, // 0.01 SOL\n * });\n * \n * // Generate QR code URL\n * const qrUrl = flow.getSolanaPayUrl({ label: 'Unlock Article' });\n * \n * // Get transaction amount in natural units\n * const amountInSol = flow.getDisplayAmount();\n * ```\n */\nexport function createPaymentFlow(config: PaymentFlowConfig) {\n const { network, recipientWallet, amount, asset = 'native', memo } = config;\n\n // Determine decimals and mint\n let decimals = 9; // SOL default\n let mintAddress: string | undefined;\n\n if (asset === 'usdc') {\n decimals = 6;\n mintAddress = network === 'mainnet-beta' ? TOKEN_MINTS.USDC_MAINNET : TOKEN_MINTS.USDC_DEVNET;\n } else if (asset === 'usdt') {\n decimals = 6;\n mintAddress = TOKEN_MINTS.USDT_MAINNET;\n } else if (typeof asset === 'object' && 'mint' in asset) {\n decimals = asset.decimals ?? 6;\n mintAddress = asset.mint;\n }\n\n // Convert to natural units (from lamports/base units)\n const naturalAmount = Number(amount) / Math.pow(10, decimals);\n\n return {\n /** Get the payment configuration */\n getConfig: () => ({ ...config }),\n\n /** Get amount in natural display units (e.g., 0.01 SOL) */\n getDisplayAmount: () => naturalAmount,\n\n /** Get amount formatted with symbol */\n getFormattedAmount: () => {\n const symbol = asset === 'native' ? 'SOL'\n : asset === 'usdc' ? 'USDC'\n : asset === 'usdt' ? 'USDT'\n : 'tokens';\n return `${naturalAmount.toFixed(decimals > 6 ? 4 : 2)} ${symbol}`;\n },\n\n /** Generate Solana Pay URL for QR codes */\n getSolanaPayUrl: (options: { label?: string; reference?: string } = {}) => {\n return buildSolanaPayUrl({\n recipient: recipientWallet,\n amount: naturalAmount,\n splToken: mintAddress,\n label: options.label,\n reference: options.reference,\n message: memo,\n });\n },\n\n /** Get the token mint address (undefined for native SOL) */\n getMintAddress: () => mintAddress,\n\n /** Check if this is a native SOL payment */\n isNativePayment: () => asset === 'native',\n\n /** Get network information */\n getNetworkInfo: () => ({\n network,\n isMainnet: network === 'mainnet-beta',\n explorerUrl: network === 'mainnet-beta'\n ? 'https://explorer.solana.com'\n : 'https://explorer.solana.com?cluster=devnet',\n }),\n\n /** Build explorer URL for a transaction */\n getExplorerUrl: (signature: string) => {\n const baseUrl = 'https://explorer.solana.com/tx';\n const cluster = network === 'mainnet-beta' ? '' : '?cluster=devnet';\n return `${baseUrl}/${signature}${cluster}`;\n },\n };\n}\n\n/**\n * Create a unique reference for payment tracking\n * Uses crypto.randomUUID when available\n */\nexport function createPaymentReference(): string {\n if (typeof crypto !== 'undefined' && crypto.randomUUID) {\n return crypto.randomUUID();\n }\n // Fallback for environments without crypto.randomUUID\n return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/types/payment.ts","../../src/client/payment.ts"],"names":[],"mappings":";AAoBO,IAAM,WAAA,GAAc;AAAA;AAAA,EAEvB,YAAA,EAAc,8CAAA;AAAA;AAAA,EAEd,WAAA,EAAa,8CAAA;AAAA;AAAA,EAEb,YAAA,EAAc;AAClB,CAAA;;;AC2BO,SAAS,kBAAkB,MAAA,EAAoC;AAClE,EAAA,MAAM,EAAE,SAAA,EAAW,MAAA,EAAQ,UAAU,SAAA,EAAW,KAAA,EAAO,SAAQ,GAAI,MAAA;AAEnE,EAAA,MAAM,GAAA,GAAM,IAAI,GAAA,CAAI,CAAA,OAAA,EAAU,SAAS,CAAA,CAAE,CAAA;AAEzC,EAAA,IAAI,WAAW,MAAA,EAAW;AACtB,IAAA,GAAA,CAAI,YAAA,CAAa,GAAA,CAAI,QAAA,EAAU,MAAA,CAAO,UAAU,CAAA;AAAA,EACpD;AAEA,EAAA,IAAI,QAAA,EAAU;AACV,IAAA,GAAA,CAAI,YAAA,CAAa,GAAA,CAAI,WAAA,EAAa,QAAQ,CAAA;AAAA,EAC9C;AAEA,EAAA,IAAI,SAAA,EAAW;AACX,IAAA,GAAA,CAAI,YAAA,CAAa,GAAA,CAAI,WAAA,EAAa,SAAS,CAAA;AAAA,EAC/C;AAEA,EAAA,IAAI,KAAA,EAAO;AACP,IAAA,GAAA,CAAI,YAAA,CAAa,GAAA,C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AO,CAAE,QAAA,CAAS,EAAE,CAAA,CAAE,KAAA,CAAM,CAAA,EAAG,EAAE,CAAC,CAAA,CAAA;AACnE","file":"index.js","sourcesContent":["// Payment-related TypeScript types for x402 protocol\n\n/** x402 network identifiers for Solana */\nexport type X402Network = 'solana-devnet' | 'solana-mainnet';\n\n/** Solana network types */\nexport type SolanaNetwork = 'devnet' | 'mainnet-beta';\n\n/** SPL Token asset specification */\nexport interface SPLTokenAsset {\n /** Token mint address */\n mint: string;\n /** Token decimals (default: 6 for USDC/USDT) */\n decimals?: number;\n}\n\n/** Asset types for payments */\nexport type PaymentAsset = 'native' | 'usdc' | 'usdt' | SPLTokenAsset;\n\n/** Known SPL token mint addresses */\nexport const TOKEN_MINTS = {\n /** USDC on mainnet */\n USDC_MAINNET: 'EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v',\n /** USDC on devnet */\n USDC_DEVNET: '4zMMC9srt5Ri5X14GAgXhaHii3GnPAEERYPJgZJDncDU',\n /** USDT on mainnet */\n USDT_MAINNET: 'Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB',\n} as const;\n\n/** Payment requirement for x402 protocol */\nexport interface PaymentRequirement {\n /** Payment scheme - currently only 'exact' is supported */\n scheme: 'exact';\n /** Network identifier for x402 */\n network: X402Network;\n /** Amount in smallest unit as string (lamports for SOL, base units for tokens) */\n maxAmountRequired: string;\n /** URL of the protected resource */\n resource: string;\n /** Human-readable description */\n description: string;\n /** MIME type of the resource */\n mimeType?: string;\n /** Recipient wallet address */\n payTo: string;\n /** Maximum time in seconds to complete payment */\n maxTimeoutSeconds: number;\n /** Asset type - 'native' for SOL, 'usdc', 'usdt', or custom mint */\n asset: PaymentAsset;\n /** Additional metadata */\n extra?: {\n name?: string;\n articleId?: string;\n [key: string]: unknown;\n };\n}\n\n/** Payment payload sent by client after transaction */\nexport interface PaymentPayload {\n /** x402 protocol version */\n x402Version: number;\n /** Payment scheme */\n scheme: 'exact';\n /** Network identifier */\n network: X402Network;\n /** Transaction details */\n payload: {\n /** Transaction signature (base58) */\n signature: string;\n /** Base64 encoded transaction (optional) */\n transaction?: string;\n };\n}\n\n/** Request to verify a payment */\nexport interface VerificationRequest {\n paymentPayload: PaymentPayload;\n paymentRequirements: PaymentRequirement;\n}\n\n/** Response from payment verification */\nexport interface VerificationResponse {\n /** Whether the payment is valid */\n valid: boolean;\n /** Reason for invalid payment */\n invalidReason?: string;\n /** Whether the transaction is settled on-chain */\n settled?: boolean;\n /** Sender wallet address (payer) */\n from?: string;\n /** Transaction details */\n transaction?: {\n signature: string;\n blockTime?: number;\n slot?: number;\n };\n}\n\n/** Payment status for tracking */\nexport interface PaymentStatus {\n status: 'pending' | 'confirmed' | 'failed' | 'expired';\n signature?: string;\n confirmations?: number;\n error?: string;\n}\n\n/** x402 HTTP header constants */\nexport const X402_HEADERS = {\n PAYMENT_REQUIRED: 'x-payment-required',\n PAYMENT: 'x-payment',\n PAYMENT_RESPONSE: 'x-payment-response',\n} as const;\n\n/** Configuration for article pricing */\nexport interface ArticlePaymentConfig {\n articleId: string;\n priceInLamports: bigint;\n title: string;\n description?: string;\n}\n","// Client-Side Payment Flow Helper\n// Headless payment flow for frontend integration (no Node.js dependencies)\n\nimport { TOKEN_MINTS, type PaymentAsset, type SolanaNetwork } from '../types';\n\n/**\n * Payment flow configuration\n */\nexport interface PaymentFlowConfig {\n /** Solana network */\n network: SolanaNetwork;\n /** Recipient wallet address */\n recipientWallet: string;\n /** Amount in smallest unit (lamports or token base units) */\n amount: bigint;\n /** Asset to pay with */\n asset?: PaymentAsset;\n /** Optional memo for the transaction */\n memo?: string;\n}\n\n/**\n * Solana Pay URL parameters\n */\nexport interface SolanaPayUrlParams {\n /** Recipient address */\n recipient: string;\n /** Amount in token's natural units (e.g., SOL, not lamports) */\n amount?: number;\n /** SPL token mint address */\n splToken?: string;\n /** Transaction reference */\n reference?: string;\n /** Label for the recipient */\n label?: string;\n /** Memo/message */\n message?: string;\n}\n\n/**\n * Build a Solana Pay URL for QR codes and deep linking\n * Compatible with Phantom, Solflare, and other Solana Pay wallets\n * \n * @example\n * ```typescript\n * const url = buildSolanaPayUrl({\n * recipient: 'CreatorWalletAddress',\n * amount: 0.01,\n * label: 'Article Unlock',\n * message: 'Premium Content Access',\n * });\n * // Returns: solana:CreatorWalletAddress?amount=0.01&label=Article%20Unlock&message=Premium%20Content%20Access\n * ```\n */\nexport function buildSolanaPayUrl(params: SolanaPayUrlParams): string {\n const { recipient, amount, splToken, reference, label, message } = params;\n\n const url = new URL(`solana:${recipient}`);\n\n if (amount !== undefined) {\n url.searchParams.set('amount', amount.toString());\n }\n\n if (splToken) {\n url.searchParams.set('spl-token', splToken);\n }\n\n if (reference) {\n url.searchParams.set('reference', reference);\n }\n\n if (label) {\n url.searchParams.set('label', label);\n }\n\n if (message) {\n url.searchParams.set('message', message);\n }\n\n return url.toString();\n}\n\n/**\n * Create a payment flow helper for frontend use\n * Provides utilities for building transactions and generating QR codes\n * \n * @example\n * ```typescript\n * const flow = createPaymentFlow({\n * network: 'devnet',\n * recipientWallet: 'CreatorAddress',\n * amount: 10000000n, // 0.01 SOL\n * });\n * \n * // Generate QR code URL\n * const qrUrl = flow.getSolanaPayUrl({ label: 'Unlock Article' });\n * \n * // Get transaction amount in natural units\n * const amountInSol = flow.getDisplayAmount();\n * ```\n */\nexport function createPaymentFlow(config: PaymentFlowConfig) {\n const { network, recipientWallet, amount, asset = 'native', memo } = config;\n\n // Determine decimals and mint\n let decimals = 9; // SOL default\n let mintAddress: string | undefined;\n\n if (asset === 'usdc') {\n decimals = 6;\n mintAddress = network === 'mainnet-beta' ? TOKEN_MINTS.USDC_MAINNET : TOKEN_MINTS.USDC_DEVNET;\n } else if (asset === 'usdt') {\n decimals = 6;\n mintAddress = TOKEN_MINTS.USDT_MAINNET;\n } else if (typeof asset === 'object' && 'mint' in asset) {\n decimals = asset.decimals ?? 6;\n mintAddress = asset.mint;\n }\n\n // Convert to natural units (from lamports/base units)\n const naturalAmount = Number(amount) / Math.pow(10, decimals);\n\n return {\n /** Get the payment configuration */\n getConfig: () => ({ ...config }),\n\n /** Get amount in natural display units (e.g., 0.01 SOL) */\n getDisplayAmount: () => naturalAmount,\n\n /** Get amount formatted with symbol */\n getFormattedAmount: () => {\n const symbol = asset === 'native' ? 'SOL'\n : asset === 'usdc' ? 'USDC'\n : asset === 'usdt' ? 'USDT'\n : 'tokens';\n return `${naturalAmount.toFixed(decimals > 6 ? 4 : 2)} ${symbol}`;\n },\n\n /** Generate Solana Pay URL for QR codes */\n getSolanaPayUrl: (options: { label?: string; reference?: string } = {}) => {\n return buildSolanaPayUrl({\n recipient: recipientWallet,\n amount: naturalAmount,\n splToken: mintAddress,\n label: options.label,\n reference: options.reference,\n message: memo,\n });\n },\n\n /** Get the token mint address (undefined for native SOL) */\n getMintAddress: () => mintAddress,\n\n /** Check if this is a native SOL payment */\n isNativePayment: () => asset === 'native',\n\n /** Get network information */\n getNetworkInfo: () => ({\n network,\n isMainnet: network === 'mainnet-beta',\n explorerUrl: network === 'mainnet-beta'\n ? 'https://explorer.solana.com'\n : 'https://explorer.solana.com?cluster=devnet',\n }),\n\n /** Build explorer URL for a transaction */\n getExplorerUrl: (signature: string) => {\n const baseUrl = 'https://explorer.solana.com/tx';\n const cluster = network === 'mainnet-beta' ? '' : '?cluster=devnet';\n return `${baseUrl}/${signature}${cluster}`;\n },\n };\n}\n\n/**\n * Create a unique reference for payment tracking\n * Uses crypto.randomUUID when available\n */\nexport function createPaymentReference(): string {\n if (typeof crypto !== 'undefined' && crypto.randomUUID) {\n return crypto.randomUUID();\n }\n // Fallback for environments without crypto.randomUUID\n return `${Date.now()}-${Math.random().toString(36).slice(2, 11)}`;\n}\n"]}
|
package/dist/index.cjs
CHANGED
|
@@ -803,6 +803,7 @@ async function verifyX402Payment(payload, requirement, clientConfig) {
|
|
|
803
803
|
return {
|
|
804
804
|
valid: true,
|
|
805
805
|
settled: verification.confirmed,
|
|
806
|
+
from: verification.from,
|
|
806
807
|
transaction: {
|
|
807
808
|
signature: verification.signature,
|
|
808
809
|
blockTime: verification.blockTime,
|
|
@@ -828,9 +829,28 @@ function parsePaymentHeader(header) {
|
|
|
828
829
|
return null;
|
|
829
830
|
}
|
|
830
831
|
}
|
|
832
|
+
function encodePaymentRequirement(requirement) {
|
|
833
|
+
return Buffer.from(JSON.stringify(requirement)).toString("base64");
|
|
834
|
+
}
|
|
831
835
|
function encodePaymentResponse(response) {
|
|
832
836
|
return Buffer.from(JSON.stringify(response)).toString("base64");
|
|
833
837
|
}
|
|
838
|
+
function create402Response(requirement, body) {
|
|
839
|
+
const headers = new Headers({
|
|
840
|
+
"Content-Type": "application/json",
|
|
841
|
+
"X-Payment-Required": encodePaymentRequirement(requirement)
|
|
842
|
+
});
|
|
843
|
+
const responseBody = body || {
|
|
844
|
+
error: "Payment Required",
|
|
845
|
+
message: "This resource requires payment to access",
|
|
846
|
+
x402Version: 1,
|
|
847
|
+
accepts: [requirement]
|
|
848
|
+
};
|
|
849
|
+
return new Response(JSON.stringify(responseBody), {
|
|
850
|
+
status: 402,
|
|
851
|
+
headers
|
|
852
|
+
});
|
|
853
|
+
}
|
|
834
854
|
|
|
835
855
|
// src/store/memory.ts
|
|
836
856
|
function createMemoryStore(options = {}) {
|
|
@@ -975,16 +995,22 @@ function createPaywallMiddleware(config2) {
|
|
|
975
995
|
const sessionToken = cookies[cookieName];
|
|
976
996
|
const result = await checkPaywallAccess(path, sessionToken, config2);
|
|
977
997
|
if (!result.allowed && result.requiresPayment) {
|
|
998
|
+
const headers = {
|
|
999
|
+
"Content-Type": "application/json"
|
|
1000
|
+
};
|
|
1001
|
+
if (config2.paymentRequirement) {
|
|
1002
|
+
const requirement = typeof config2.paymentRequirement === "function" ? config2.paymentRequirement(path) : config2.paymentRequirement;
|
|
1003
|
+
headers["X-Payment-Required"] = encodePaymentRequirement(requirement);
|
|
1004
|
+
}
|
|
978
1005
|
const body = config2.custom402Response ? config2.custom402Response(path) : {
|
|
979
1006
|
error: "Payment Required",
|
|
980
1007
|
message: "This resource requires payment to access",
|
|
1008
|
+
x402Version: 1,
|
|
981
1009
|
path
|
|
982
1010
|
};
|
|
983
1011
|
return new Response(JSON.stringify(body), {
|
|
984
1012
|
status: 402,
|
|
985
|
-
headers
|
|
986
|
-
"Content-Type": "application/json"
|
|
987
|
-
}
|
|
1013
|
+
headers
|
|
988
1014
|
});
|
|
989
1015
|
}
|
|
990
1016
|
return null;
|
|
@@ -1313,6 +1339,7 @@ exports.checkPaywallAccess = checkPaywallAccess;
|
|
|
1313
1339
|
exports.clearPriceCache = clearPriceCache;
|
|
1314
1340
|
exports.configurePricing = configurePricing;
|
|
1315
1341
|
exports.create402Headers = create402Headers;
|
|
1342
|
+
exports.create402Response = create402Response;
|
|
1316
1343
|
exports.create402ResponseBody = create402ResponseBody;
|
|
1317
1344
|
exports.createMemoryStore = createMemoryStore;
|
|
1318
1345
|
exports.createPaymentFlow = createPaymentFlow;
|
|
@@ -1323,6 +1350,7 @@ exports.createRedisStore = createRedisStore;
|
|
|
1323
1350
|
exports.createSession = createSession;
|
|
1324
1351
|
exports.decodePaymentRequired = decodePaymentRequired;
|
|
1325
1352
|
exports.encodePaymentRequired = encodePaymentRequired;
|
|
1353
|
+
exports.encodePaymentRequirement = encodePaymentRequirement;
|
|
1326
1354
|
exports.encodePaymentResponse = encodePaymentResponse;
|
|
1327
1355
|
exports.estimatePriorityFee = estimatePriorityFee;
|
|
1328
1356
|
exports.fetchLookupTables = fetchLookupTables;
|