remove lndhub (#1523)
This commit is contained in:
parent
451c8f7a9e
commit
4494f473a6
|
@ -1,6 +0,0 @@
|
|||
<h1>lndhub Extension</h1>
|
||||
<h2>*connect to your lnbits wallet from BlueWallet or Zeus*</h2>
|
||||
|
||||
Lndhub has nothing to do with lnd, it is just the name of the HTTP/JSON protocol https://bluewallet.io/ uses to talk to their Lightning custodian server at https://lndhub.io/.
|
||||
|
||||
Despite not having been planned to this, Lndhub because somewhat a standard for custodian wallet communication when https://t.me/lntxbot and https://zeusln.app/ implemented the same interface. And with this extension LNbits joins the same club.
|
|
@ -1,27 +0,0 @@
|
|||
from fastapi import APIRouter
|
||||
from starlette.staticfiles import StaticFiles
|
||||
|
||||
from lnbits.db import Database
|
||||
from lnbits.helpers import template_renderer
|
||||
|
||||
db = Database("ext_lndhub")
|
||||
|
||||
lndhub_ext: APIRouter = APIRouter(prefix="/lndhub", tags=["lndhub"])
|
||||
|
||||
lndhub_static_files = [
|
||||
{
|
||||
"path": "/lndhub/static",
|
||||
"app": StaticFiles(directory="lnbits/extensions/lndhub/static"),
|
||||
"name": "lndhub_static",
|
||||
}
|
||||
]
|
||||
|
||||
|
||||
def lndhub_renderer():
|
||||
return template_renderer(["lnbits/extensions/lndhub/templates"])
|
||||
|
||||
|
||||
from .decorators import * # noqa: F401,F403
|
||||
from .utils import * # noqa: F401,F403
|
||||
from .views import * # noqa: F401,F403
|
||||
from .views_api import * # noqa: F401,F403
|
|
@ -1,6 +0,0 @@
|
|||
{
|
||||
"name": "LndHub",
|
||||
"short_description": "Access lnbits from BlueWallet or Zeus",
|
||||
"tile": "/lndhub/static/image/lndhub.png",
|
||||
"contributors": ["fiatjaf"]
|
||||
}
|
|
@ -1,42 +0,0 @@
|
|||
from base64 import b64decode
|
||||
|
||||
from fastapi import Request, status
|
||||
from fastapi.param_functions import Security
|
||||
from fastapi.security.api_key import APIKeyHeader
|
||||
from starlette.exceptions import HTTPException
|
||||
|
||||
from lnbits.decorators import WalletTypeInfo, get_key_type
|
||||
|
||||
api_key_header_auth = APIKeyHeader(
|
||||
name="AUTHORIZATION",
|
||||
auto_error=False,
|
||||
description="Admin or Invoice key for LNDHub API's",
|
||||
)
|
||||
|
||||
|
||||
async def check_wallet(
|
||||
r: Request, api_key_header_auth: str = Security(api_key_header_auth)
|
||||
) -> WalletTypeInfo:
|
||||
if not api_key_header_auth:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid auth key"
|
||||
)
|
||||
|
||||
t = api_key_header_auth.split(" ")[1]
|
||||
_, token = b64decode(t).decode().split(":")
|
||||
|
||||
return await get_key_type(r, api_key_header=token)
|
||||
|
||||
|
||||
async def require_admin_key(
|
||||
r: Request, api_key_header_auth: str = Security(api_key_header_auth)
|
||||
):
|
||||
wallet = await check_wallet(r, api_key_header_auth)
|
||||
if wallet.wallet_type != 0:
|
||||
# If wallet type is not admin then return the unauthorized status
|
||||
# This also covers when the user passes an invalid key type
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED, detail="Admin key required."
|
||||
)
|
||||
else:
|
||||
return wallet
|
|
@ -1,2 +0,0 @@
|
|||
async def migrate():
|
||||
pass
|
Binary file not shown.
Before Width: | Height: | Size: 31 KiB |
|
@ -1,38 +0,0 @@
|
|||
<q-expansion-item
|
||||
group="extras"
|
||||
icon="info"
|
||||
label="Instructions"
|
||||
default-opened
|
||||
>
|
||||
<q-card>
|
||||
<q-card-section>
|
||||
To access an LNbits wallet from a mobile phone,
|
||||
<ol>
|
||||
<li>
|
||||
Install either
|
||||
<a class="text-secondary" href="https://zeusln.app">Zeus</a> or
|
||||
<a class="text-secondary" href="https://bluewallet.io/">BlueWallet</a
|
||||
>;
|
||||
</li>
|
||||
<li>
|
||||
Go to <code>Add a wallet / Import wallet</code> on BlueWallet or
|
||||
<code>Settings / Add a new node</code> on Zeus.
|
||||
</li>
|
||||
<li>Select the desired wallet on this page;</li>
|
||||
<li>Scan one of the two QR codes from the mobile wallet.</li>
|
||||
</ol>
|
||||
<ul>
|
||||
<li>
|
||||
<em>Invoice</em> URLs mean the mobile wallet will only have the
|
||||
authorization to read your payments and invoices and generate new
|
||||
invoices.
|
||||
</li>
|
||||
<li>
|
||||
<em>Admin</em> URLs mean the mobile wallet will be able to pay
|
||||
invoices..
|
||||
</li>
|
||||
</ul>
|
||||
</q-card-section>
|
||||
<q-btn flat label="Swagger API" type="a" href="../docs#/lndhub"></q-btn>
|
||||
</q-card>
|
||||
</q-expansion-item>
|
|
@ -1,20 +0,0 @@
|
|||
<q-expansion-item group="extras" icon="info" label="LndHub info">
|
||||
<q-card>
|
||||
<q-card-section>
|
||||
<p>
|
||||
LndHub is a protocol invented by
|
||||
<a class="text-secondary" href="https://bluewallet.io/">BlueWallet</a>
|
||||
that allows mobile wallets to query payments and balances, generate
|
||||
invoices and make payments from accounts that exist on a server. The
|
||||
protocol is a collection of HTTP endpoints exposed through the internet.
|
||||
</p>
|
||||
<p>
|
||||
For a wallet that supports it, reading a QR code that contains the URL
|
||||
along with secret access credentials should enable access. Currently it
|
||||
is supported by
|
||||
<a class="text-secondary" href="https://zeusln.app">Zeus</a> and
|
||||
<a class="text-secondary" href="https://bluewallet.io/">BlueWallet</a>.
|
||||
</p>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
</q-expansion-item>
|
|
@ -1,94 +0,0 @@
|
|||
{% extends "base.html" %} {% from "macros.jinja" import window_vars with context
|
||||
%} {% block page %} {% raw %}
|
||||
<div class="row q-col-gutter-md">
|
||||
<div class="col-12 col-md-8 col-lg-7 q-gutter-y-md">
|
||||
<div class="row q-col-gutter-md">
|
||||
<q-card
|
||||
v-for="type in ['invoice', 'admin']"
|
||||
v-bind:key="type"
|
||||
class="q-pa-sm q-ma-sm col-5"
|
||||
>
|
||||
<q-card-section class="q-pa-none">
|
||||
<div class="text-center">
|
||||
<a class="text-secondary" :href="selectedWallet[type]">
|
||||
<q-responsive :ratio="1" class="q-mx-sm">
|
||||
<qrcode
|
||||
:value="selectedWallet[type]"
|
||||
:options="{width: 800}"
|
||||
class="rounded-borders"
|
||||
></qrcode>
|
||||
</q-responsive>
|
||||
</a>
|
||||
</div>
|
||||
<div class="row q-mt-lg items-center justify-center">
|
||||
<q-btn
|
||||
outline
|
||||
color="grey"
|
||||
@click="copyText(selectedWallet[type])"
|
||||
class="text-center q-mb-md"
|
||||
>Copy LndHub {{type}} URL</q-btn
|
||||
>
|
||||
</div>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
</div>
|
||||
|
||||
<q-card class="q-pa-lg q-pt-xl lnbits__dialog-card">
|
||||
<q-form class="q-gutter-md">
|
||||
<q-select
|
||||
filled
|
||||
dense
|
||||
v-model="selectedWallet"
|
||||
:options="wallets"
|
||||
label="Select wallet:"
|
||||
>
|
||||
</q-select>
|
||||
</q-form>
|
||||
</q-card>
|
||||
</div>
|
||||
|
||||
{% endraw %}
|
||||
|
||||
<div class="col-12 col-md-4 col-lg-5 q-gutter-y-md">
|
||||
<q-card>
|
||||
<q-card-section>
|
||||
<h6 class="text-subtitle1 q-my-none">
|
||||
{{SITE_TITLE}} LndHub extension
|
||||
</h6>
|
||||
</q-card-section>
|
||||
<q-card-section class="q-pa-none">
|
||||
<q-separator></q-separator>
|
||||
<q-list>
|
||||
{% include "lndhub/_instructions.html" %}
|
||||
<q-separator></q-separator>
|
||||
{% include "lndhub/_lndhub.html" %}
|
||||
</q-list>
|
||||
</q-card-section>
|
||||
</q-card>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{% endblock %} {% block scripts %} {{ window_vars(user) }}
|
||||
<script>
|
||||
Vue.component(VueQrcode.name, VueQrcode)
|
||||
|
||||
new Vue({
|
||||
el: '#vue',
|
||||
mixins: [windowMixin],
|
||||
data: function () {
|
||||
var wallets = JSON.parse('{{ user.wallets | tojson }}')
|
||||
.map(LNbits.map.wallet)
|
||||
.map(wallet => ({
|
||||
label: wallet.name,
|
||||
admin: `lndhub://admin:${wallet.adminkey}@${location.protocol}//${location.host}/lndhub/ext/`,
|
||||
invoice: `lndhub://invoice:${wallet.inkey}@${location.protocol}//${location.host}/lndhub/ext/`
|
||||
}))
|
||||
|
||||
return {
|
||||
wallets: wallets,
|
||||
selectedWallet: wallets[0]
|
||||
}
|
||||
}
|
||||
})
|
||||
</script>
|
||||
{% endblock %}
|
|
@ -1,19 +0,0 @@
|
|||
from lnbits.bolt11 import Invoice
|
||||
|
||||
|
||||
def to_buffer(payment_hash: str):
|
||||
return {"type": "Buffer", "data": [b for b in bytes.fromhex(payment_hash)]}
|
||||
|
||||
|
||||
def decoded_as_lndhub(invoice: Invoice):
|
||||
return {
|
||||
"destination": invoice.payee,
|
||||
"payment_hash": invoice.payment_hash,
|
||||
"num_satoshis": invoice.amount_msat / 1000,
|
||||
"timestamp": str(invoice.date),
|
||||
"expiry": str(invoice.expiry),
|
||||
"description": invoice.description,
|
||||
"fallback_addr": "",
|
||||
"cltv_expiry": invoice.min_final_cltv_expiry,
|
||||
"route_hints": "",
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
from fastapi import Depends, Request
|
||||
|
||||
from lnbits.core.models import User
|
||||
from lnbits.decorators import check_user_exists
|
||||
|
||||
from . import lndhub_ext, lndhub_renderer
|
||||
|
||||
|
||||
@lndhub_ext.get("/")
|
||||
async def lndhub_index(request: Request, user: User = Depends(check_user_exists)):
|
||||
return lndhub_renderer().TemplateResponse(
|
||||
"lndhub/index.html", {"request": request, "user": user.dict()}
|
||||
)
|
|
@ -1,230 +0,0 @@
|
|||
import time
|
||||
from base64 import urlsafe_b64encode
|
||||
from http import HTTPStatus
|
||||
|
||||
from fastapi import Depends, Query
|
||||
from pydantic import BaseModel
|
||||
from starlette.exceptions import HTTPException
|
||||
|
||||
from lnbits import bolt11
|
||||
from lnbits.core.crud import get_payments
|
||||
from lnbits.core.services import create_invoice, pay_invoice
|
||||
from lnbits.decorators import WalletTypeInfo
|
||||
from lnbits.settings import get_wallet_class, settings
|
||||
|
||||
from . import lndhub_ext
|
||||
from .decorators import check_wallet, require_admin_key
|
||||
from .utils import decoded_as_lndhub, to_buffer
|
||||
|
||||
|
||||
@lndhub_ext.get("/ext/getinfo")
|
||||
async def lndhub_getinfo():
|
||||
return {"alias": settings.lnbits_site_title}
|
||||
|
||||
|
||||
class AuthData(BaseModel):
|
||||
login: str = Query(None)
|
||||
password: str = Query(None)
|
||||
refresh_token: str = Query(None)
|
||||
|
||||
|
||||
@lndhub_ext.post("/ext/auth")
|
||||
async def lndhub_auth(data: AuthData):
|
||||
token = (
|
||||
data.refresh_token
|
||||
if data.refresh_token
|
||||
else urlsafe_b64encode((data.login + ":" + data.password).encode()).decode(
|
||||
"ascii"
|
||||
)
|
||||
)
|
||||
return {"refresh_token": token, "access_token": token}
|
||||
|
||||
|
||||
class AddInvoice(BaseModel):
|
||||
amt: str = Query(...)
|
||||
memo: str = Query(...)
|
||||
preimage: str = Query(None)
|
||||
|
||||
|
||||
@lndhub_ext.post("/ext/addinvoice")
|
||||
async def lndhub_addinvoice(
|
||||
data: AddInvoice, wallet: WalletTypeInfo = Depends(check_wallet)
|
||||
):
|
||||
try:
|
||||
_, pr = await create_invoice(
|
||||
wallet_id=wallet.wallet.id,
|
||||
amount=int(data.amt),
|
||||
memo=data.memo or settings.lnbits_site_title,
|
||||
extra={"tag": "lndhub"},
|
||||
)
|
||||
except:
|
||||
raise HTTPException(
|
||||
status_code=HTTPStatus.NOT_FOUND, detail="Failed to create invoice"
|
||||
)
|
||||
invoice = bolt11.decode(pr)
|
||||
return {
|
||||
"pay_req": pr,
|
||||
"payment_request": pr,
|
||||
"add_index": "500",
|
||||
"r_hash": to_buffer(invoice.payment_hash),
|
||||
"hash": invoice.payment_hash,
|
||||
}
|
||||
|
||||
|
||||
class CreateInvoice(BaseModel):
|
||||
invoice: str = Query(...)
|
||||
|
||||
|
||||
@lndhub_ext.post("/ext/payinvoice")
|
||||
async def lndhub_payinvoice(
|
||||
r_invoice: CreateInvoice, wallet: WalletTypeInfo = Depends(require_admin_key)
|
||||
):
|
||||
try:
|
||||
await pay_invoice(
|
||||
wallet_id=wallet.wallet.id,
|
||||
payment_request=r_invoice.invoice,
|
||||
extra={"tag": "lndhub"},
|
||||
)
|
||||
except:
|
||||
raise HTTPException(status_code=HTTPStatus.NOT_FOUND, detail="Payment failed")
|
||||
|
||||
invoice: bolt11.Invoice = bolt11.decode(r_invoice.invoice)
|
||||
|
||||
return {
|
||||
"payment_error": "",
|
||||
"payment_preimage": "0" * 64,
|
||||
"route": {},
|
||||
"payment_hash": invoice.payment_hash,
|
||||
"decoded": decoded_as_lndhub(invoice),
|
||||
"fee_msat": 0,
|
||||
"type": "paid_invoice",
|
||||
"fee": 0,
|
||||
"value": invoice.amount_msat / 1000,
|
||||
"timestamp": int(time.time()),
|
||||
"memo": invoice.description,
|
||||
}
|
||||
|
||||
|
||||
@lndhub_ext.get("/ext/balance")
|
||||
async def lndhub_balance(
|
||||
wallet: WalletTypeInfo = Depends(check_wallet),
|
||||
):
|
||||
return {"BTC": {"AvailableBalance": wallet.wallet.balance}}
|
||||
|
||||
|
||||
@lndhub_ext.get("/ext/gettxs")
|
||||
async def lndhub_gettxs(
|
||||
wallet: WalletTypeInfo = Depends(check_wallet),
|
||||
limit: int = Query(20, ge=1, le=20),
|
||||
offset: int = Query(0, ge=0),
|
||||
):
|
||||
for payment in await get_payments(
|
||||
wallet_id=wallet.wallet.id,
|
||||
complete=False,
|
||||
pending=True,
|
||||
outgoing=True,
|
||||
incoming=False,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
exclude_uncheckable=True,
|
||||
):
|
||||
await payment.check_status()
|
||||
|
||||
return [
|
||||
{
|
||||
"payment_preimage": payment.preimage,
|
||||
"payment_hash": payment.payment_hash,
|
||||
"fee_msat": payment.fee * 1000,
|
||||
"type": "paid_invoice",
|
||||
"fee": payment.fee,
|
||||
"value": int(payment.amount / 1000),
|
||||
"timestamp": payment.time,
|
||||
"memo": payment.memo if not payment.pending else "Payment in transition",
|
||||
}
|
||||
for payment in reversed(
|
||||
(
|
||||
await get_payments(
|
||||
wallet_id=wallet.wallet.id,
|
||||
pending=True,
|
||||
complete=True,
|
||||
outgoing=True,
|
||||
incoming=False,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
)
|
||||
)
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
@lndhub_ext.get("/ext/getuserinvoices")
|
||||
async def lndhub_getuserinvoices(
|
||||
wallet: WalletTypeInfo = Depends(check_wallet),
|
||||
limit: int = Query(20, ge=1, le=20),
|
||||
offset: int = Query(0, ge=0),
|
||||
):
|
||||
WALLET = get_wallet_class()
|
||||
for invoice in await get_payments(
|
||||
wallet_id=wallet.wallet.id,
|
||||
complete=False,
|
||||
pending=True,
|
||||
outgoing=False,
|
||||
incoming=True,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
exclude_uncheckable=True,
|
||||
):
|
||||
await invoice.set_pending(
|
||||
(await WALLET.get_invoice_status(invoice.checking_id)).pending
|
||||
)
|
||||
|
||||
return [
|
||||
{
|
||||
"r_hash": to_buffer(invoice.payment_hash),
|
||||
"payment_request": invoice.bolt11,
|
||||
"add_index": "500",
|
||||
"description": invoice.memo,
|
||||
"payment_hash": invoice.payment_hash,
|
||||
"ispaid": not invoice.pending,
|
||||
"amt": int(invoice.amount / 1000),
|
||||
"expire_time": int(time.time() + 1800),
|
||||
"timestamp": invoice.time,
|
||||
"type": "user_invoice",
|
||||
}
|
||||
for invoice in reversed(
|
||||
(
|
||||
await get_payments(
|
||||
wallet_id=wallet.wallet.id,
|
||||
pending=True,
|
||||
complete=True,
|
||||
incoming=True,
|
||||
outgoing=False,
|
||||
limit=limit,
|
||||
offset=offset,
|
||||
)
|
||||
)
|
||||
)
|
||||
]
|
||||
|
||||
|
||||
@lndhub_ext.get("/ext/getbtc")
|
||||
async def lndhub_getbtc(wallet: WalletTypeInfo = Depends(check_wallet)):
|
||||
"load an address for incoming onchain btc"
|
||||
return []
|
||||
|
||||
|
||||
@lndhub_ext.get("/ext/getpending")
|
||||
async def lndhub_getpending(wallet: WalletTypeInfo = Depends(check_wallet)):
|
||||
"pending onchain transactions"
|
||||
return []
|
||||
|
||||
|
||||
@lndhub_ext.get("/ext/decodeinvoice")
|
||||
async def lndhub_decodeinvoice(invoice: str = Query(None)):
|
||||
inv = bolt11.decode(invoice)
|
||||
return decoded_as_lndhub(inv)
|
||||
|
||||
|
||||
@lndhub_ext.get("/ext/checkrouteinvoice")
|
||||
async def lndhub_checkrouteinvoice():
|
||||
"not implemented on canonical lndhub"
|
Loading…
Reference in New Issue
Block a user