2023-05-16 17:20:04 +03:00
# Nostr Wallet Connect
2023-03-21 18:01:09 +01:00
2023-06-05 16:06:25 +02:00
This application allows you to control your Lightning node or wallet over Nostr.
2023-05-16 17:20:04 +03:00
Connect applications like [Damus ](https://damus.io/ ) or [Amethyst ](https://linktr.ee/amethyst.social ) to your node.
2023-03-21 22:05:50 +01:00
2023-04-24 15:51:51 +02:00
2023-04-25 15:54:56 +02:00
2023-05-16 17:20:04 +03:00
**Specification**: [NIP-47 ](https://github.com/nostr-protocol/nips/blob/master/47.md )
2023-04-24 15:51:51 +02:00
2023-05-16 17:20:04 +03:00
## Supported Backends
2023-03-22 15:15:07 +01:00
2023-05-16 17:20:04 +03:00
* [Alby ](https://getalby.com ) (see: alby.go)
* LND (see: lnd.go)
* want more? please open an issue.
2023-04-21 19:14:59 +02:00
## Installation
2023-04-24 15:51:51 +02:00
2023-05-16 17:20:04 +03:00
### Requirements
The application has no runtime dependencies. (simple Go executable).
2023-06-05 16:06:25 +02:00
As data storage SQLite or PostgreSQL (recommended) can be used.
2023-05-16 17:20:04 +03:00
2023-04-29 12:49:29 +02:00
$ cp .env.example .env
# edit the config for your needs
vim .env
2023-04-21 19:14:59 +02:00
2023-04-25 15:54:56 +02:00
To get a new random Nostr key use `openssl rand -hex 32` or similar.
2023-04-21 19:14:59 +02:00
## Development
2023-04-24 15:51:51 +02:00
2023-04-21 19:14:59 +02:00
`go run .`
2023-04-24 15:17:14 +02:00
To build the CSS run:
2023-09-29 12:54:49 +05:30
1. `npm install`
2. `npm run css`
2023-04-25 15:54:56 +02:00
2023-08-08 20:36:03 +07:00
### Testing
`go test`
2023-05-16 17:20:04 +03:00
## Configuration parameters
- `NOSTR_PRIVKEY` : the private key of this service. Should be a securely randomly generated 32 byte hex string.
- `CLIENT_NOSTR_PUBKEY` : if set, this service will only listen to events authored by this public key. You can set this to your own nostr public key.
- `RELAY` : default: "wss://relay.getalby.com/v1"
- `LN_BACKEND_TYPE` : ALBY or LND
- `ALBY_CLIENT_SECRET` = Alby OAuth client secret (used with the Alby backend)
- `ALBY_CLIENT_ID` = Alby OAuth client ID (used with the Alby backend)
- `OAUTH_REDIRECT_URL` = OAuth redirect URL (e.g. http://localhost:8080/alby/callback) (used with the Alby backend)
- `LND_ADDRESS` : the LND gRPC address, eg. `localhost:10009` (used with the LND backend)
- `LND_CERT_FILE` : the location where LND's `tls.cert` file can be found (used with the LND backend)
- `LND_MACAROON_FILE` : the location where LND's `admin.macaroon` file can be found (used with the LND backend)
- `COOKIE_SECRET` : a randomly generated secret string.
- `DATABASE_URI` : a postgres connection string or sqlite filename. Default: nostr-wallet-connect.db (sqlite)
- `PORT` : the port on which the app should listen on (default: 8080)
## Application deeplink options
2023-04-25 15:54:56 +02:00
2023-05-16 17:20:04 +03:00
### `/apps/new` deeplink options
2023-04-25 15:54:56 +02:00
Clients can use a deeplink to allow the user to add a new connection. Depending on the client this URL has different query options:
2023-05-16 17:20:04 +03:00
#### NWC created secret
2023-04-25 15:54:56 +02:00
The default option is that the NWC app creates a secret and the user uses the nostr wallet connect URL string to enable the client application.
2023-05-16 17:20:04 +03:00
##### Query parameter options
2023-04-25 15:54:56 +02:00
- `c` : the name of the client app
Example:
`/apps/new?c=myapp`
2023-05-16 17:20:04 +03:00
#### Client created secret
2023-04-25 15:54:56 +02:00
If the client creates the secret the client only needs to share the public key of that secret for authorization. The user authorized that pubkey and no sensitivate data needs to be shared.
2023-08-03 13:29:43 +02:00
##### Query parameter options for /new
2023-04-25 15:54:56 +02:00
- `c` : the name of the client app
- `pubkey` : the public key of the client's secret for the user to authorize
2023-06-05 16:06:25 +02:00
- `return_to` : (optional) if a `return_to` URL is provided the user will be redirected to that URL after authorization. The `lud16` , `relay` and `pubkey` query parameters will be added to the URL.
2023-06-29 20:22:46 +07:00
- `expires_at` (optional) connection cannot be used after this date. Unix timestamp in seconds.
2023-05-21 21:35:10 +07:00
- `max_amount` (optional) maximum amount in sats that can be sent per renewal period
- `budget_renewal` (optional) reset the budget at the end of the given budget renewal. Can be `never` (default), `daily` , `weekly` , `monthly` , `yearly`
- `editable` (optional) set to `false` to disable form editing by the user
2023-09-22 02:51:23 +09:00
- `request_methods` (optional) url encoded, space separated list of request types that you need permission for: `pay_invoice` (default), `get_balance` (see NIP47). For example: `..&request_methods=pay_invoice%20get_balance`
2023-04-25 15:54:56 +02:00
Example:
`/apps/new?c=myapp&pubkey=47c5a21...&return_to=https://example.com`
2023-05-16 17:20:04 +03:00
#### Web-flow: client created secret
2023-04-25 15:54:56 +02:00
Web clients can open a new prompt popup to load the authorization page.
Once the user has authorized the app connection a `nwc:success` message is sent to the opening page (using `postMessage` ) to indicate that the connection is authorized. See the `initNWC()` function in the [alby-js-sdk ](https://github.com/getAlby/alby-js-sdk#nostr-wallet-connect-documentation )
Example:
```js
import { webln } from "alby-js-sdk";
const nwc = new webln.NWC();
// initNWC opens a prompt with /apps/new?c=myapp& pubkey=xxxx
// the promise resolves once the user has authorized the connection (when the `nwc:success` message is received) and the popup is closed automatically
// the promise rejects if the user cancels by closing the prompt popup
await nwc.initNWC({name: 'myapp'});
````
## Help
2023-09-23 20:25:01 +02:00
If you need help contact support@getalby .com or reach out on Nostr: npub1getal6ykt05fsz5nqu4uld09nfj3y3qxmv8crys4aeut53unfvlqr80nfm
You can also visit the chat of our Community on [Telegram ](https://t.me/getalby ).
2023-04-25 15:54:56 +02:00
## ⚡️ Donations
Want to support the work on Alby?
Support the Alby team ⚡️ hello@getalby .com
You can also contribute to our [bounty program ](https://github.com/getAlby/lightning-browser-extension/wiki/Bounties ): ⚡️ bounties@getalby .com