From 693862bcc869e98756cda89268aa96b381e4ec8c Mon Sep 17 00:00:00 2001 From: im-adithya Date: Tue, 27 Feb 2024 17:49:13 +0530 Subject: [PATCH] chore: add README --- .env.example | 6 +- README.md | 172 +++++++++++++++++++++++++++++++++++++++- internal/nostr/nostr.go | 2 +- 3 files changed, 173 insertions(+), 7 deletions(-) diff --git a/.env.example b/.env.example index 4cb2254..5204f0f 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,3 @@ -SENTRY_DSN= -DATADOG_AGENT_URL= -PORT=8080 \ No newline at end of file +PORT=8080 +DEFAULT_RELAY_URL=wss://relay.getalby.com/v1 +DATABASE_URI=postgresql://user@localhost:5432/httpnostr \ No newline at end of file diff --git a/README.md b/README.md index bb5fbdd..8f490dc 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,175 @@ -# HTTP-Nostr API +# HTTP-Nostr -## Development +HTTP-Nostr is designed to bridge the gap between the decentralized Nostr protocol and traditional HTTP endpoints with NIP-47 in mind. It offers seamless integration, allowing for real-time interaction with the Nostr network through a well-defined HTTP API. Developers/Nostr clients can fetch NIP-47 info, publish NIP-47 requests, or subscribe to events based on filters to create client side applications on Nostr without worrying about websockets. + +For subscriptions/NIP-47 requests, HTTP-Nostr accepts a webhook URL to notify about the new events/response event + + + +## 🤙 Usage + +### Fetch NIP-47 Info + +Returns Relay's NIP-47 capabilities. + +
+ +GET /info + + +#### Parameters + +> None + +#### Response + +> ```json +> { +> "id": "a16ye1391c22xx........xxxxx", +> "pubkey": "a16y69effexxxx........xxxxx", +> "created_at": 1708336682, +> "kind": 13194, +> "tags": [], +> "content": "pay_invoice,pay_keysend,get_balance,get_info,make_invoice,lookup_invoice,list_transactions", +> "sig": +> } +>``` +
+ +------------------------------------------------------------------------------------------ + +### Publish NIP-47 Request + +Returns the response event directly or to the Webhook URL if provided. + +
+ +POST /nip47 + + +#### Request Body + +> | name | type | data type | description | +> |-----------|-----------|-------------------------|-----------------------------------------------------------------------| +> | relayUrl | optional | string | If no relay is provided, it uses the default relay | +> | webhookUrl | optional | string | Webhook URL to publish the response event, returns the event directly if not provided | +> | walletPubkey | required | string | Pubkey of the NIP-47 Wallet Provider | +> | event | required | JSON object ([nostr.Event](https://pkg.go.dev/github.com/nbd-wtf/go-nostr@v0.25.7#Event)) | **Signed** request event | + + +#### Response (with webhook) + +> "webhook received" + +#### Response (without webhook) + +> ```json +> { +> "id": "a16ycf4a01bcxx........xxxxx", +> "pubkey": "a16y69effexxxx........xxxxx", +> "created_at": 1709033612, +> "kind": 23195, +> "tags": [ +> [ +> "p", +> "f490f5xxxxx........xxxxx" +> ], +> [ +> "e", +> "a41aefxxxxx........xxxxx" +> ] +> ], +> "content": , +> "sig": +> } +>``` +
+ +------------------------------------------------------------------------------------------ + +### Subscribe to Events + +Notifies about new events matching the filter provided via webhooks + +
+ +POST /subscribe + + +#### Request Body + +> | name | type | data type | description | +> |-----------|-----------|-------------------------|-----------------------------------------------------------------------| +> | relayUrl | optional | string | If no relay is provided, it uses the default relay | +> | webhookUrl | required | string | Webhook URL to publish events | +> | filter | required | JSON object ([nostr.Filter](https://pkg.go.dev/github.com/nbd-wtf/go-nostr@v0.25.7#Filter)) | Filters to subscribe to | + + +#### Response + +> ```json +> { +> "subscription_id": 1, +> "webhookUrl": "https://your.webhook.url" +> } +>``` +
+ +------------------------------------------------------------------------------------------ + +### Delete Subscriptions + +Delete previously requested subscriptions. + +
+ +DELETE /subscribe/:id + + +#### Parameter + +> | name | type | data type | description | +> |-----------|-----------|-------------------------|-----------------------------------------------------------------------| +> | id | required | string | ID received on subscribing to a relay | + + +#### Response + +> ```json +> "subscription x stopped" +>``` +
+ +------------------------------------------------------------------------------------------ + +## 🚀 Installation + +### Requirements + +The application has no runtime dependencies. (simple Go executable). + +As data storage PostgreSQL should be used. + + $ cp .env.example .env + # edit the config for your needs + vim .env + +## 🛠️ Development `go run cmd/server/main.go` -## Configuration parameters +## ⚙️ Configuration parameters - `PORT`: the port on which the app should listen on (default: 8080) +- `DEFAULT_RELAY_URL`: the relay the app should subscribe to if nothing is provided (default: "wss://relay.getalby.com/v1") +- `DATABASE_URI`: postgres connection string + +## ⭐ Contributing + +Contributions to HTTP-Nostr are welcome! Whether it's bug reports, feature requests, or contributions to code, please feel free to make your suggestions known. + +## 📄 License + +HTTP-Nostr is released under the MIT License. See the [LICENSE file](./LICENSE) for more details. diff --git a/internal/nostr/nostr.go b/internal/nostr/nostr.go index c0f35b5..2151fd6 100644 --- a/internal/nostr/nostr.go +++ b/internal/nostr/nostr.go @@ -30,7 +30,7 @@ import ( type Config struct { SentryDSN string `envconfig:"SENTRY_DSN"` DatadogAgentUrl string `envconfig:"DATADOG_AGENT_URL"` - DefaultRelayURL string `envconfig:"DEFAULT_RELAY_URL"` + DefaultRelayURL string `envconfig:"DEFAULT_RELAY_URL" default:"wss://relay.getalby.com/v1"` DatabaseUri string `envconfig:"DATABASE_URI" default:"http-nostr.db"` DatabaseMaxConns int `envconfig:"DATABASE_MAX_CONNS" default:"10"` DatabaseMaxIdleConns int `envconfig:"DATABASE_MAX_IDLE_CONNS" default:"5"`