Skip to content

Commit

Permalink
fix: tags in subscriptions (#56)
Browse files Browse the repository at this point in the history
* fix: tags in subscriptions

* chore: tabs instead of spaces

* chore: use nostr.Filter with easyjson

* chore: update README

* chore: add response to webhook url in readme

* chore: minor fix
  • Loading branch information
im-adithya authored May 28, 2024
1 parent 6b0ab5b commit 57fb1fa
Show file tree
Hide file tree
Showing 2 changed files with 128 additions and 66 deletions.
186 changes: 124 additions & 62 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<details>
<summary>
Expand All @@ -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": <signature>
> }
>```
```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": <signature>
}
```
</details>

------------------------------------------------------------------------------------------
Expand All @@ -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/[email protected]#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": "<encrypted content>",
"sig":"<signature>"
}
// Source: https://pkg.go.dev/github.com/nbd-wtf/[email protected]#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": <encrypted content>,
> "sig": <signature>
> }
>```
```json
{
"id": "a16ycf4a01bcxx........xxxxx",
"pubkey": "a16y69effexxxx........xxxxx",
"created_at": 1709033612,
"kind": 23195,
"tags": [
[
"p",
"f490f5xxxxx........xxxxx"
],
[
"e",
"a41aefxxxxx........xxxxx"
]
],
"content": <encrypted content>,
"sig": <signature>
}
```
</details>

------------------------------------------------------------------------------------------
Expand All @@ -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/[email protected]#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/[email protected]#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": <encrypted content>,
"sig": <signature>
}
```

</details>

------------------------------------------------------------------------------------------
Expand All @@ -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"
```
</details>

------------------------------------------------------------------------------------------
Expand Down
8 changes: 4 additions & 4 deletions internal/nostr/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}
}

0 comments on commit 57fb1fa

Please sign in to comment.