UNPKG

ws402

Version:

WebSocket implementation of X402 protocol for pay-as-you-go digital resources with automatic refunds

147 lines (122 loc) โ€ข 7.02 kB
# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] ## [0.1.4] - 2025-01-13 ### Fixed - ๐Ÿ”ง **Solana RPC compatibility** - Replaced WebSocket subscriptions with HTTP polling for better RPC provider compatibility - ๐Ÿ” **Base58 private key parsing** - Added built-in base58 decoder, eliminating external bs58 dependency requirement - โšก **Transaction verification** - Implemented retry logic (up to 10 attempts) with 2-second intervals for blockchain transaction fetching - ๐Ÿ”„ **Refund confirmations** - Changed from `sendAndConfirmTransaction` to manual polling for Alchemy and other RPC providers without WebSocket support - ๐ŸŽฏ **Transaction structure** - Simplified reference tracking by adding it as readonly key to main instruction instead of creating separate empty instruction - ๐Ÿ’ฐ **Payment amounts** - Fixed display formatting with proper lamports to SOL conversion - ๐Ÿ›ก๏ธ **Error handling** - Improved error messages and fallbacks throughout entire payment flow - ๐ŸŒ **Browser compatibility** - Replaced Node.js `Buffer` with browser-native `Uint8Array` ### Added - ๐Ÿ“Š **Enhanced logging** - Added detailed transaction fetching status and retry attempt tracking - ๐Ÿ” **Debug information** - Comprehensive debug output for payment verification process - โฑ๏ธ **Configurable timeouts** - Transaction verification with exponential backoff and maximum retry limits - ๐ŸŒ **RPC endpoint proxy** - Added `/blockhash` server endpoint for secure blockhash retrieval without exposing API keys to clients - ๐Ÿ“ **Better error messages** - User-friendly error messages for common issues (insufficient balance, network errors, etc.) ### Changed - ๐Ÿ“ฆ **Dependencies** - Removed hard dependency on bs58 package (now uses built-in base58 decoder) - ๐Ÿ”Œ **Connection method** - Improved compatibility with various Solana RPC providers (Alchemy, Helius, QuickNode, public endpoints) - ๐Ÿ’ต **Default pricing** - Reduced example pricing from 0.03 SOL to 0.003 SOL for more accessible testing - ๐Ÿ” **Security** - Merchant RPC endpoint only used server-side via `/blockhash` proxy, never exposed to client ### Technical Details - **RPC provider support** - Works with any Solana RPC provider, including those without WebSocket support (Alchemy, Helius) - **Transaction confirmation** - Uses HTTP polling-based confirmation (getSignatureStatus) instead of WebSocket subscriptions (signatureSubscribe) - **Payment verification** - Retry logic handles transaction propagation delays across RPC nodes - **Refund system** - Automatic refunds work reliably even with rate-limited or WebSocket-less RPC endpoints - **Client architecture** - Browser client uses Phantom's built-in transaction handling, only needs blockhash from server - **Base58 encoding** - Custom implementation included to avoid dependency issues in different environments ### Developer Experience - ๐Ÿš€ **Easier setup** - Fewer dependencies to install and configure - ๐Ÿ› **Better debugging** - Detailed logs show exactly where in the process things succeed or fail - ๐Ÿ“– **Clearer errors** - Actionable error messages guide users to solutions - ๐Ÿ”ง **More flexible** - Works with any Solana RPC provider, not just ones with full WebSocket support ## [0.1.0] - 2025-01-12 ### Added #### Core Features - โœจ Initial release of WS402 library - ๐Ÿ”Œ Core WS402 protocol implementation - ๐ŸŒ WebSocket session management with real-time tracking - โšก Real-time usage metering (time, bytes, messages) - ๐Ÿ’ฐ Automatic refund system for unused balance - ๐Ÿ”’ Payment provider interface with multiple implementations - ๐Ÿ“Š Comprehensive session lifecycle management - ๐ŸŽฏ Event system for monitoring and callbacks - ๐Ÿ“ TypeScript support with full type definitions - ๐Ÿ› ๏ธ Express middleware helpers for easy integration #### Payment Providers - ๐Ÿงช **MockPaymentProvider** - For development and testing - โšก **BasePaymentProvider** - Base blockchain (Ethereum L2) integration - Native ETH payments on Base network - ERC20 token support (USDC, etc.) - On-chain payment verification - Automatic on-chain refunds - Support for Base mainnet, Goerli, and Sepolia testnets - Low fees (~$0.01) and fast confirmations (2-5 seconds) - ๐Ÿš€ **SolanaPaymentProvider** - Solana blockchain integration - Native SOL payments - SPL token support (USDC, USDT, etc.) - Solana Pay QR code generation - On-chain payment verification - Automatic on-chain refunds - Ultra-low fees (~$0.0001) and sub-second confirmations - Support for mainnet-beta, devnet, and testnet - ๐Ÿฆ **ProxyPaymentProvider** - Centralized gateway architecture - Delegates payment operations to external gateway - No private keys on WS402 servers - Horizontal scalability for enterprise deployments - Retry logic with exponential backoff - Health check monitoring - API key authentication #### Architecture & Security - ๐Ÿ—๏ธ Proxy architecture for enterprise deployments - ๐Ÿ” Secure private key management with environment variables - ๐Ÿ›ก๏ธ Comprehensive security documentation - ๐Ÿ“ก Payment gateway server implementation - ๐Ÿ”„ Automatic refund processing on blockchain - โš™๏ธ Configurable conversion rates and pricing #### Examples & Documentation - ๐Ÿ“š Complete working examples for all providers - ๐ŸŽจ HTML client implementations with wallet integrations - ๐Ÿ“– Comprehensive documentation - ๐Ÿ”จ TypeScript compilation with development tools --- ## Future Plans ### [0.2.0] - Planned Q1 2025 - ๐Ÿ”Œ Bitcoin Lightning Network support - ๐Ÿ“Š Enhanced metrics and analytics dashboard - ๐Ÿงช Comprehensive test suite with Jest - ๐Ÿ”„ Session persistence and resumption - โšก Rate limiting and throttling - ๐ŸŒ Additional blockchain integrations - ๐Ÿ“ฑ Client SDK libraries (JavaScript, Python, Go) ### [0.3.0] - Planned Q2 2025 - ๐ŸŽฎ WebRTC support for real-time communications - ๐Ÿ† Distribution pool for maintainer rewards - ๐Ÿ” Multi-signature wallet support - ๐ŸŒ GraphQL API endpoint - ๐Ÿ“Š Built-in analytics and reporting ### [1.0.0] - Planned Q3 2025 - ๐Ÿš€ Production-ready stable release - ๐Ÿข Enterprise features and SLA guarantees - ๐Ÿ”’ Advanced security auditing - ๐Ÿ“Š Comprehensive benchmarking - ๐ŸŒ Multi-region deployment support --- ## Links - ๐Ÿ“ฆ NPM Package: https://npmjs.com/package/ws402 - ๐Ÿ’ป GitHub Repository: https://github.com/ws402/ws402 - ๐ŸŒ Website: https://ws402.org - ๐Ÿ“š Documentation: https://docs.ws402.org - ๐Ÿ’ฌ Community Discord: https://discord.gg/ws402 - ๐Ÿฆ Twitter/X: https://x.com/ws402org - ๐Ÿ”— Farcaster: https://farcaster.xyz/ws402 --- [Unreleased]: https://github.com/ws402/ws402/compare/v0.1.4...HEAD [0.1.4]: https://github.com/ws402/ws402/compare/v0.1.0...v0.1.4 [0.1.0]: https://github.com/ws402/ws402/releases/tag/v0.1.0