All Projects → lnbits → lnurl

lnbits / lnurl

Licence: MIT license
LNURL implementation for Python.

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to lnurl

lightning-browser-extension
The Bitcoin Lightning Browser extension that connects to different wallet interfaces and brings deep lightning integration to the web
Stars: ✭ 194 (+280.39%)
Mutual labels:  lightning-network, lnurl
lnbits-legend
LNbits, free and open-source lightning-network wallet/accounts system.
Stars: ✭ 405 (+694.12%)
Mutual labels:  lightning-network, lnurl
awesome-lnurl
A curated list of awesome lnurl things.
Stars: ✭ 252 (+394.12%)
Mutual labels:  lightning-network, lnurl
Phoenix
Phoenix is a non custodial Bitcoin wallet using Lightning to send/receive payments.
Stars: ✭ 129 (+152.94%)
Mutual labels:  lightning-network
Thunderhub
ThunderHub LND Lightning Node Manager in your Browser
Stars: ✭ 131 (+156.86%)
Mutual labels:  lightning-network
Ln Service
Node.js interface to LND
Stars: ✭ 191 (+274.51%)
Mutual labels:  lightning-network
pait
Python Modern API Tools, fast to code
Stars: ✭ 24 (-52.94%)
Mutual labels:  pydantic
Plugins
Community curated plugins for c-lightning
Stars: ✭ 120 (+135.29%)
Mutual labels:  lightning-network
Breezmobile
Lightning Network mobile client
Stars: ✭ 225 (+341.18%)
Mutual labels:  lightning-network
Zeus
A mobile Bitcoin/Lightning app for lnd, c-lightning, and Eclair node operators ⚡️
Stars: ✭ 175 (+243.14%)
Mutual labels:  lightning-network
Webln
Spec and client library for WebLN apps and providers
Stars: ✭ 165 (+223.53%)
Mutual labels:  lightning-network
Umbrel Os
Run Umbrel Bitcoin and Lightning node on a Raspberry Pi in one click
Stars: ✭ 132 (+158.82%)
Mutual labels:  lightning-network
Lndhub
Wrapper for Lightning Network Daemon. It provides separate accounts and trust minimization for end users
Stars: ✭ 203 (+298.04%)
Mutual labels:  lightning-network
Awesome Bitcoin Payment Processors
🌟 A curated list of Bitcoin payment processors enabling merchants, businesses and nonprofits to accept Bitcoin payments.
Stars: ✭ 129 (+152.94%)
Mutual labels:  lightning-network
Eclair Mobile
An Android wallet for the Lightning Network
Stars: ✭ 231 (+352.94%)
Mutual labels:  lightning-network
Ptarmigan
Lightning Network (BOLT)
Stars: ✭ 125 (+145.1%)
Mutual labels:  lightning-network
Spark Wallet
⚡️ A minimalistic wallet GUI for c-lightning, accessible over the web or through mobile and desktop apps.
Stars: ✭ 215 (+321.57%)
Mutual labels:  lightning-network
Spec
[OLD!] RGB Protocol specifications for Bitcoin-based digital assets
Stars: ✭ 145 (+184.31%)
Mutual labels:  lightning-network
Paper
Lightning Network Paper
Stars: ✭ 136 (+166.67%)
Mutual labels:  lightning-network
Lncli Web
Light-weight web client for the lnd daemon written in NodeJS / Angular.
Stars: ✭ 181 (+254.9%)
Mutual labels:  lightning-network

LNURL implementation for Python

github-tests-badge github-mypy-badge codecov-badge pypi-badge pypi-versions-badge license-badge

A collection of helpers for building LNURL support into wallets and services.

Configuration

Developers can force strict RFC3986 validation for the URLs that the library encodes/decodes, using this env var:

LNURL_STRICT_RFC3986 = "0" by default (False)

Basic usage

>>> import lnurl
>>> lnurl.encode('https://service.io/?q=3fc3645b439ce8e7')
Lnurl('LNURL1DP68GURN8GHJ7UM9WFMXJCM99E5K7TELWY7NXENRXVMRGDTZXSENJCM98PJNWXQ96S9', bech32=Bech32('LNURL1DP68GURN8GHJ7UM9WFMXJCM99E5K7TELWY7NXENRXVMRGDTZXSENJCM98PJNWXQ96S9', hrp='lnurl', data=[13, 1, 26, 7, 8, 28, 3, 19, 7, 8, 23, 18, 30, 28, 27, 5, 14, 9, 27, 6, 18, 24, 27, 5, 5, 25, 20, 22, 30, 11, 25, 31, 14, 4, 30, 19, 6, 25, 19, 3, 6, 12, 27, 3, 8, 13, 11, 2, 6, 16, 25, 19, 18, 24, 27, 5, 7, 1, 18, 19, 14]), url=WebUrl('https://service.io/?q=3fc3645b439ce8e7', scheme='https', host='service.io', tld='io', host_type='domain', path='/', query='q=3fc3645b439ce8e7'))
>>> lnurl.decode('LNURL1DP68GURN8GHJ7UM9WFMXJCM99E5K7TELWY7NXENRXVMRGDTZXSENJCM98PJNWXQ96S9')
WebUrl('https://service.io/?q=3fc3645b439ce8e7', scheme='https', host='service.io', tld='io', host_type='domain', path='/', query='q=3fc3645b439ce8e7')

The Lnurl object wraps a bech32 LNURL to provide some extra utilities.

from lnurl import Lnurl

lnurl = Lnurl("LNURL1DP68GURN8GHJ7UM9WFMXJCM99E5K7TELWY7NXENRXVMRGDTZXSENJCM98PJNWXQ96S9")
lnurl.bech32  # "LNURL1DP68GURN8GHJ7UM9WFMXJCM99E5K7TELWY7NXENRXVMRGDTZXSENJCM98PJNWXQ96S9"
lnurl.bech32.hrp  # "lnurl"
lnurl.url  # "https://service.io/?q=3fc3645b439ce8e7"
lnurl.url.host  # "service.io"
lnurl.url.base  # "https://service.io/"
lnurl.url.query  # "q=3fc3645b439ce8e7"
lnurl.url.query_params  # {"q": "3fc3645b439ce8e7"}

Parsing LNURL responses

You can use a LnurlResponse to wrap responses you get from a LNURL. The different types of responses defined in the LNURL spec have a different model with different properties (see models.py):

import requests

from lnurl import Lnurl, LnurlResponse

lnurl = Lnurl('LNURL1DP68GURN8GHJ7MRWW4EXCTNZD9NHXATW9EU8J730D3H82UNV94MKJARGV3EXZAELWDJHXUMFDAHR6WFHXQERSVPCA649RV')
r = requests.get(lnurl.url)

res = LnurlResponse.from_dict(r.json())  # LnurlPayResponse
res.ok  # bool
res.max_sendable  # int
res.max_sats  # int
res.callback.base  # str
res.callback.query_params # dict
res.metadata  # str
res.metadata.list()  # list
res.metadata.text  # str
res.metadata.images  # list

If you have already requests installed, you can also use the .handle() function directly. It will return the appropriate response for a LNURL.

>>> import lnurl
>>> lnurl.handle('lightning:LNURL1DP68GURN8GHJ7MRWW4EXCTNZD9NHXATW9EU8J730D3H82UNV94CXZ7FLWDJHXUMFDAHR6V33XCUNSVE38QV6UF')
LnurlPayResponse(tag='payRequest', callback=WebUrl('https://lnurl.bigsun.xyz/lnurl-pay/callback/2169831', scheme='https', host='lnurl.bigsun.xyz', tld='xyz', host_type='domain', path='/lnurl-pay/callback/2169831'), min_sendable=10000, max_sendable=10000, metadata=LnurlPayMetadata('[["text/plain","NgHaEyaZNDnW iI DsFYdkI"],["image/png;base64","iVBOR...uQmCC"]]'))

Building your own LNURL responses

For LNURL services, the lnurl package can be used to build valid responses.

from lnurl import LnurlWithdrawResponse

res = LnurlWithdrawResponse(
    callback="https://lnurl.bigsun.xyz/lnurl-withdraw/callback/9702808",
    k1="38d304051c1b76dcd8c5ee17ee15ff0ebc02090c0afbc6c98100adfa3f920874",
    min_withdrawable=551000,
    max_withdrawable=551000,
    default_description="sample withdraw",
)
res.json()  # str
res.dict()  # dict

All responses are pydantic models, so the information you provide will be validated and you have access to .json() and .dict() methods to export the data.

Data is exported using 🐫 camelCase keys by default, as per spec. You can also use camelCases when you parse the data, and it will be converted to snake_case to make your Python code nicer.

If you want to export the data using 🐍 snake_case (in your Python code, for example), you can change the by_alias parameter: res.dict(by_alias=False) (it is True by default).

CLI

$ poetry run lnurl
Usage: lnurl [OPTIONS] COMMAND [ARGS]...

  Python CLI for LNURL decode and encode lnurls

Options:
  --help  Show this message and exit.

Commands:
  decode           decode a LNURL
  encode           encode a URL
  handle           handle a LNURL
  payment-request  make a payment_request
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].