ws402
Version:
WebSocket implementation of X402 protocol for pay-as-you-go digital resources with automatic refunds
98 lines (97 loc) • 2.84 kB
TypeScript
import { PaymentProvider, PaymentVerification } from '../types';
import { PublicKey } from '@solana/web3.js';
import BigNumber from 'bignumber.js';
export interface SolanaPaymentProviderConfig {
/** Solana RPC endpoint URL */
rpcEndpoint: string;
/** Merchant wallet address to receive payments */
merchantWallet: string;
/** Merchant private key for refunds (optional - array of numbers from wallet JSON) */
merchantPrivateKey?: number[];
/** Network: 'mainnet-beta' | 'devnet' | 'testnet' */
network?: 'mainnet-beta' | 'devnet' | 'testnet';
/** Conversion rate: wei/sat/etc to SOL */
conversionRate?: number;
/** SPL Token mint address (optional, for token payments) */
splToken?: string;
/** Payment timeout in milliseconds */
paymentTimeout?: number;
/** Label for Solana Pay QR code */
label?: string;
/** Message for Solana Pay */
message?: string;
/** Memo for transaction */
memo?: string;
/** Enable automatic refunds (requires merchantPrivateKey) */
autoRefund?: boolean;
}
/**
* Solana Payment Provider for WS402
*
* Supports:
* - Native SOL payments
* - SPL Token payments
* - Solana Pay QR codes
* - On-chain payment verification
* - Automatic refunds
*/
export declare class SolanaPaymentProvider implements PaymentProvider {
private connection;
private merchantWallet;
private merchantKeypair;
private config;
private pendingPayments;
constructor(config: SolanaPaymentProviderConfig);
/**
* Validate amount is positive
*/
private validateAmount;
/**
* Log payment activity
*/
private log;
/**
* Generate payment details with Solana Pay QR code
*/
generatePaymentDetails(amount: number): any;
/**
* Verify Solana payment on-chain
*/
verifyPayment(proof: any): Promise<PaymentVerification>;
/**
* Issue refund via Solana transaction
*/
issueRefund(proof: any, amount: number): Promise<void>;
/**
* Verify transaction details match expected payment
*/
private verifyTransactionDetails;
/**
* Generate unique reference for payment tracking
*/
private generateReference;
/**
* Get pending payment info
*/
getPendingPayment(reference: string): {
amount: number;
amountSOL: BigNumber;
timestamp: number;
recipient: PublicKey;
} | undefined;
/**
* Clean up expired pending payments
*/
cleanupExpiredPayments(): number;
/**
* Get connection info
*/
getConnectionInfo(): {
rpcEndpoint: string;
network: "mainnet-beta" | "devnet" | "testnet";
merchantWallet: string;
splToken: string | undefined;
autoRefundEnabled: boolean;
hasKeypair: boolean;
};
}