Code Monkey home page Code Monkey logo

nip57-server's Introduction

NIP57 Server

A python server for lightning zaps in the Nostr network, facilitating a self hosted LND instance behind Tor. Use it to set up a server to recieve lightning zaps in The Nostr. Go self custody - not your keys, not your coins :-) It's an alternative for Wallet Of Satoshi or getalby.com - but only for tec people.

image info

โš ๏ธ This is As-Is: It worked from 9/23 till 4/24 without bugs. Now it's not maintained in this repo anymore, may or may not work. I dev it at another place to be a zap-bank.

NIP-57 protocol flow

The protocol is documented in Nostr NIP-57 - my implementation looks like this:

image info

What it does

  • Be a server
  • Provide a lnurl pay endpoint like in LUD-16, extended by the requirements in NIP-57
  • Listen for zap requests kind 9734, REST - send them to the LND, proxy that requests with Tor socks5h
  • Deliver the bech32-serialized lightning invoice to the wallet LUD-06
  • Listen at REST LND for invoice updates
  • Create the NIP-57 kind 9735 Event and deliver it to the relays.

Prerequisites

You'll need a macaroon for your lnd. Bake it like lncli bakemacaroon --save_to=./nip57macaroon invoices:write invoices:read

You'll need the onion address of your rest lnd interface, can find it usually in /var/lib/tor/lnd/hostname

You'll need a tor proxy in SOCKS5H_PROXY. Use the docker compose if you don't have tor running on your host.

  • create the users.json with the users you provide the service for
  • cp the tls.cert from your lnd instance to here
  • cp .env.example to .env and adjust the settings

Startup

Start up and test looks like this:

docker logs nip57-server-server-1
[2023-12-07 08:53:08,658 - INFO] nip57_server NIP57S V1.0.1 starting on port 9080
[2023-12-07 08:53:08,658 - INFO] author contact: nostr:npub1c3lf9hdmghe4l7xcy8phlhepr66hz7wp5dnkpwxjvw8x7hzh0pesc9mpv4
[2023-12-07 08:53:08,658 - INFO] GitHub: https://github.com/raymonostr/nip57-server
[2023-12-07 08:53:08,658 - INFO] A server to receive nostr nip-57 zaps to my own self-custodial LND server.
[2023-12-07 08:53:08,658 - INFO] This software is provided AS IS without any warranty. Use it at your own risk.
[2023-12-07 08:53:08,658 - INFO] Config LNURL_ORIGIN: https://nostrich.house
[2023-12-07 08:53:08,659 - INFO] Config MIN_SENDABLE: 1000
[2023-12-07 08:53:08,659 - INFO] Config MAX_SENDABLE: 400000000
[2023-12-07 08:53:08,659 - INFO] Config DEFAULT_RELAYS: ['wss://nostr.mom/', 'wss://nostr-pub.wellorder.net/', 'wss://relay.damus.io/', 'wss://nos.lol/']
[2023-12-07 08:53:08,659 - INFO] Config SOCKS5H_PROXY: socks5h://tor_proxy:9150
[2023-12-07 08:53:08,659 - INFO] Config LND_RESTADDR: https://xxxxxxck...
[2023-12-07 08:53:08,659 - INFO] Config INVOICE_MACAROON: xxxxxxx6e6402...
[2023-12-07 08:53:08,659 - INFO] Config ZAPPER_KEY: xxxxxxxe05dab...
[2023-12-07 08:53:08,659 - INFO] Config DYNIP_SECRET: 7fH...
[2023-12-07 08:53:08,659 - INFO] Config TLS_VERIFY: ./tls.cert
[2023-12-07 08:53:08,662 - INFO] Serving on http://0.0.0.0:9080

# dynIP coming in:
[2023-12-07 08:53:49,457 - INFO] LND Rest addr set to https://y.z.29.216:8080

# zap coming in
[2023-12-07 08:55:46,177 - INFO] got invoice request for siddhartha amount 21000 msats
[2023-12-07 08:55:46,398 - INFO] Invoice cache length is 1
[2023-12-07 08:55:46,398 - INFO] Starting LND invoice listener
[2023-12-07 08:56:01,465 - INFO] Got payment of 21000 msats for idx 573
[2023-12-07 08:56:01,468 - INFO] Sending 9735 event to relays now
[2023-12-07 08:56:01,488 - INFO] LND invoice listener closed


raymon# curl localhost:9080/lnurlp/state
{"state":"SERVER_ACTIVE"}

The state request forwards to lnd rest /v1/state

Dial-Up lines, Dyn-Ip

Tor is sometimes slow, to slow for some zap clients like damus or Amethyst. With the Dial-Up Dyn-Ip feature, you can connect the nip57-server to lnd via clearnet.

Path for this is /lnurlp/set_clearnet?secret=xyz&ipv4=18.19.20.21&port=8080&tls_verify=False

The secret must be set in env.

Issues welcome

Feel free to post issues or merge requests or zap me.

Raymon@nostr

nostr:npub1c3lf9hdmghe4l7xcy8phlhepr66hz7wp5dnkpwxjvw8x7hzh0pesc9mpv4

Version history

NIP57S V0.8.0 beta

  • added DynIp DialUp feature

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.