lightning-x402
v1.0.0
Published
Lightning Network payment SDK for HTTP 402 Payment Required - Built with Rust + Neon for high performance
Downloads
89
Maintainers
Readme
lightning-x402
Lightning Network payment SDK for HTTP 402 Payment Required - Built with Rust + Neon for high performance.
Installation
npm install lightning-x402Prerequisites
- Node.js >= 14.0.0
- Rust toolchain (for building native module)
- Cargo
Note: This package includes Rust source code. You need to build the native module after installation:
cd node_modules/lightning-x402
npm run buildOr add a postinstall script to your project's package.json:
{
"scripts": {
"postinstall": "cd node_modules/lightning-x402 && npm run build"
}
}Usage
const { createInvoice, verifyPayment } = require('lightning-x402');
// Create a Lightning invoice
const invoice = createInvoice(
'Payment for API access', // memo
1000, // amount in sats
'optional_receiver_pubkey' // optional: Lightning node public key
);
console.log('Invoice:', invoice);
// Verify payment
const verification = verifyPayment(
JSON.stringify(invoice), // invoice JSON string
1000 // paid amount in sats
);
console.log('Payment verified:', verification);API
createInvoice(memo, amountSats, receiverPubkey?)
Creates a Lightning Network invoice.
Parameters:
memo(string): Description for the invoiceamountSats(number): Amount in satoshisreceiverPubkey(string, optional): Lightning node public key to receive the payment
Returns: JSON object with invoice details
verifyPayment(invoiceJson, paidSats)
Verifies that a payment matches the expected amount.
Parameters:
invoiceJson(string): JSON string of the invoicepaidSats(number): Amount paid in satoshis
Returns: JSON object with verification result
Features
- High-performance Rust implementation with Node.js bindings
- Lightning Network invoice creation
- Payment verification
- HTTP 402 Payment Required support
- Minimal dependencies
License
MIT
Author
blockchainjosh
Repository
https://github.com/blockchainjosh/x402-sdk
