rustywallet-lightning
Lightning Network utilities for Bitcoin wallets.
Features
- BOLT11 Invoices: Parse and create Lightning invoices
- Payment Hashes: Generate and verify payment hashes/preimages
- Node Identity: Derive node ID from HD seed
- Route Hints: Parse and create route hints for private channels
- Channel Points: Handle channel point references
Installation
[]
= "0.1"
Quick Start
Payment Hash/Preimage
use *;
// Generate a random payment preimage
let preimage = random;
// Compute the payment hash
let payment_hash = preimage.payment_hash;
println!;
// Verify a preimage matches a hash
assert!;
Parse BOLT11 Invoice
use *;
let invoice = "lnbc1pvjluez..."; // Your invoice string
let parsed = parse.unwrap;
println!;
println!;
println!;
Create Invoice Data
use *;
let preimage = random;
let payment_hash = preimage.payment_hash;
let invoice_data = new
.amount_sats // 10,000 sats
.description
.payment_hash
.expiry // 1 hour
.build
.unwrap;
Node Identity
use NodeIdentity;
use Seed;
// Derive node identity from seed
let seed = random;
let identity = from_seed.unwrap;
println!;
// Sign a message
let signature = identity.sign.unwrap;
Channel Points
use *;
// Parse channel point from string
let cp = parse.unwrap;
println!;
println!;
// Short channel ID
let scid = new;
println!; // "700000x1234x0"
Route Hints
use *;
let node_id = from_bytes;
let scid = new;
let hint = new
.hop
.build;
// Calculate routing fee
let hop = &hint.hops;
let fee = hop.fee_for_amount; // fee for 1M msat
API Reference
Types
| Type | Description |
|---|---|
PaymentPreimage |
32-byte payment secret |
PaymentHash |
SHA256 hash of preimage |
Bolt11Invoice |
Parsed BOLT11 invoice |
InvoiceBuilder |
Builder for invoice data |
NodeIdentity |
Node keypair derived from seed |
NodeId |
33-byte compressed public key |
ChannelPoint |
Funding txid:output reference |
ShortChannelId |
Compact block:tx:output ID |
RouteHint |
Private channel routing info |
RouteHintHop |
Single hop in route hint |
Networks
Network::Mainnet- Bitcoin mainnet (lnbc)Network::Testnet- Bitcoin testnet (lntb)Network::Regtest- Bitcoin regtest (lnbcrt)
Security Notes
PaymentPreimagedebug output is redactedNodeIdentitysecret key is redacted in debug- Use secure random for preimage generation
License
MIT