diff --git a/README.md b/README.md index 97b68fa..aefdf60 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,8 @@ Endpoints: --> ### Fetch NIP-47 Info -Returns a Pubkey's NIP-47 capabilities (if any). +Every NWC-enabled wallet has a pubkey according to the NWC specification. +This `GET` request returns a pubkey's NWC capabilities (if any)
@@ -23,24 +24,24 @@ Returns a Pubkey's NIP-47 capabilities (if any). #### Request Body -> | name | type | data type | description | -> |-----------|-----------|-------------------------|-----------------------------------------------------------------------| -> | relayUrl | optional | string | If no relay is provided, it uses the default relay (wss://relay.getalby.com/v1) | -> | walletPubkey | required | string | Pubkey of the NIP-47 Wallet Provider | +| name | type | data type | description | +|-----------|-----------|-------------------------|-----------------------------------------------------------------------| +| relayUrl | optional | string | If no relay is provided, it uses the default relay (wss://relay.getalby.com/v1) | +| walletPubkey | required | string | Pubkey of the NWC Wallet Provider | #### 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": -> } ->``` +```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": +} +```
------------------------------------------------------------------------------------------ @@ -56,40 +57,59 @@ Returns the response event directly or to the Webhook URL if provided. #### Request Body -> | name | type | data type | description | -> |-----------|-----------|-------------------------|-----------------------------------------------------------------------| -> | relayUrl | optional | string | If no relay is provided, it uses the default relay (wss://relay.getalby.com/v1) | -> | 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 | - +| name | type | data type | description | +|-----------|-----------|-------------------------|-----------------------------------------------------------------------| +| relayUrl | optional | string | If no relay is provided, it uses the default relay (wss://relay.getalby.com/v1) | +| webhookUrl | optional | string | Webhook URL to publish the response event, returns the event directly if not provided | +| walletPubkey | required | string | Pubkey of the NWC Wallet Provider | +| event | required | JSON object (see [example](#event-example)) | **Signed** request event | + + +#### Event Example + +```json +{ + "id":"a16ycf4a01bcxx........xxxxx", + "pubkey":"a16y69effexxxx........xxxxx", + "created_at":1700000021, + "kind":23194, + "tags":[ + ["p","a16y6sfa01bcxx........xxxxx"] + ], + "content": "", + "sig":"" +} +// Source: https://pkg.go.dev/github.com/nbd-wtf/go-nostr@v0.30.0#Event +``` #### Response (with webhook) -> "webhook received" +```json +"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": -> } ->``` +```json +{ + "id": "a16ycf4a01bcxx........xxxxx", + "pubkey": "a16y69effexxxx........xxxxx", + "created_at": 1709033612, + "kind": 23195, + "tags": [ + [ + "p", + "f490f5xxxxx........xxxxx" + ], + [ + "e", + "a41aefxxxxx........xxxxx" + ] + ], + "content": , + "sig": +} +``` ------------------------------------------------------------------------------------------ @@ -105,21 +125,63 @@ Notifies about new events matching the filter provided via webhooks. #### 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 | - +| 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 (see [example](#filter-example)) | Filters to subscribe to | + + +#### Filter Example + +```json +{ + "ids": ["id1", "id2"], + "kinds": [1,2], + "authors": ["author1", "author2"], + "since": 1721212121, + "until": 1721212121, + "limit": 10, + "search": "example search", + "#tag1": ["value1", "value2"], + "#tag2": ["value3"], + "#tag3": ["value4", "value5", "value6"], +} +// Source: https://pkg.go.dev/github.com/nbd-wtf/go-nostr@v0.30.0#Filter +``` #### Response -> ```json -> { -> "subscription_id": "f370d1fc-x0x0-x0x0-x0x0-8f68fa12f32c", -> "webhookUrl": "https://your.webhook.url" -> } ->``` +```json +{ + "subscription_id": "f370d1fc-x0x0-x0x0-x0x0-8f68fa12f32c", + "webhookUrl": "https://your.webhook.url" +} +``` + +#### Response to Webhook URL + +```json +{ + "id": "a16ycf4a01bcxx........xxxxx", + "pubkey": "a16y69effexxxx........xxxxx", + "created_at": 1709033612, + "kind": 23195, + "tags": [ + [ + "p", + "f490f5xxxxx........xxxxx" + ], + [ + "e", + "a41aefxxxxx........xxxxx" + ] + ], + "content": , + "sig": +} +``` + ------------------------------------------------------------------------------------------ @@ -135,16 +197,16 @@ Delete previously requested subscriptions. #### Parameter -> | name | type | data type | description | -> |-----------|-----------|-------------------------|-----------------------------------------------------------------------| -> | id | required | string | UUID received on subscribing to a relay | +| name | type | data type | description | +|-----------|-----------|-------------------------|-----------------------------------------------------------------------| +| id | required | string | UUID received on subscribing to a relay | #### Response -> ```json -> "subscription x stopped" ->``` +```json +"subscription x stopped" +``` ------------------------------------------------------------------------------------------ diff --git a/internal/nostr/models.go b/internal/nostr/models.go index 14cc575..7b1d70a 100644 --- a/internal/nostr/models.go +++ b/internal/nostr/models.go @@ -154,12 +154,12 @@ type NIP47Request struct { } type SubscriptionRequest struct { - RelayUrl string `json:"relayUrl"` - WebhookUrl string `json:"webhookUrl"` - Filter *nostr.Filter `json:"filter"` + RelayUrl string `json:"relayUrl"` + WebhookUrl string `json:"webhookUrl"` + Filter *nostr.Filter `json:"filter"` } type SubscriptionResponse struct { SubscriptionId string `json:"subscription_id"` WebhookUrl string `json:"webhookUrl"` -} \ No newline at end of file +}