lnurl

Crates.iolnurl
lib.rslnurl
version0.2.0
sourcesrc
created_at2019-11-10 13:24:53.881509
updated_at2021-06-19 16:34:58.237702
descriptionHelpers for LNURL
homepage
repositoryhttps://github.com/edouardparis/rust-lnurl.git
max_upload_size
id179929
size58,074
Édouard (edouardparis)

documentation

https://docs.rs/lnurl/

README

lnurl

MIT licensed lnurl on crates.io lnurl on docs.rs

Documentation

Readings about lnurl

Progress

  • lnurl-withdraw
  • lnurl-auth
  • lnurl-pay
  • lnurl-channel

Usage

You will certainly need some crates like:

bech32 = "0.7.1"
lightning-invoice = "0.2.0"
serde = { version = "1.0.93", features =["derive"]}
serde_json = "1.0.39"

Create a bech32 QRCode:

use bech32::ToBase32;
use image::Luma;
use qrcode::QrCode;

pub fn create_lnurl_qrcode(url: &str, path: &str) {
    let encoded = bech32::encode("lnurl", url.as_bytes().to_base32()).unwrap();
    let code = QrCode::new(encoded.to_string()).unwrap();
    let image = code.render::<Luma<u8>>().build();
    image.save(path).unwrap();
}

Use serde_json to encode your LNRUL object in the HTTP response body of your server.

if let Err(_) = invoice.parse::<lightning_invoice::SignedRawInvoice>() {
    let res = serde_json::to_string(
        &lnurl::Response::Error{reason: "your invoice is wrong".to_string()}
    ).unwrap();
    return Ok(Response::builder()
        .status(StatusCode::BAD_REQUEST)
        .header(header::CONTENT_TYPE, "application/json")
        .body(Body::from(res)).unwrap())
}
Commit count: 15

cargo fmt