From fd0dfe21eb39e8242727942bf8d052823579e1c6 Mon Sep 17 00:00:00 2001 From: Roland Bewick Date: Wed, 10 Apr 2024 10:48:37 +0700 Subject: [PATCH] feat: include supported notification types in wallet service info notifications tag also change notifications permission name to "notifications" --- frontend/src/types.ts | 10 ++++++---- models.go | 6 +++--- nip47_notifier.go | 2 +- nip47_notifier_test.go | 2 +- service.go | 1 + 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/frontend/src/types.ts b/frontend/src/types.ts index 201d238c..714e30ff 100644 --- a/frontend/src/types.ts +++ b/frontend/src/types.ts @@ -18,7 +18,7 @@ export const NIP_47_LOOKUP_INVOICE_METHOD = "lookup_invoice"; export const NIP_47_LIST_TRANSACTIONS_METHOD = "list_transactions"; export const NIP_47_SIGN_MESSAGE_METHOD = "sign_message"; -export const NIP_47_SUBSCRIBE_UPDATES_PERMISSION = "subscribe_updates"; +export const NIP_47_NOTIFICATIONS_PERMISSION = "notifications"; export type BackendType = "LND" | "BREEZ" | "GREENLIGHT" | "LDK"; @@ -40,7 +40,9 @@ export type BudgetRenewalType = | ""; // TODO: move other permissions -export type PermissionType = RequestMethodType | "subscribe_updates"; +export type PermissionType = + | RequestMethodType + | typeof NIP_47_NOTIFICATIONS_PERMISSION; export type IconMap = { [key in PermissionType]: LucideIcon; @@ -54,7 +56,7 @@ export const iconMap: IconMap = { [NIP_47_MAKE_INVOICE_METHOD]: CirclePlus, [NIP_47_PAY_INVOICE_METHOD]: HandCoins, [NIP_47_SIGN_MESSAGE_METHOD]: PenLine, - [NIP_47_SUBSCRIBE_UPDATES_PERMISSION]: Bell, + [NIP_47_NOTIFICATIONS_PERMISSION]: Bell, }; export const validBudgetRenewals: BudgetRenewalType[] = [ @@ -78,7 +80,7 @@ export const nip47MethodDescriptions: Record = { // TODO: merge with nip47MethodDescriptions export const nip47PermissionDescriptions: Record = { ...nip47MethodDescriptions, - [NIP_47_SUBSCRIBE_UPDATES_PERMISSION]: "Subscribe to updates", + [NIP_47_NOTIFICATIONS_PERMISSION]: "Receive wallet notifications", }; export const expiryOptions: Record = { diff --git a/models.go b/models.go index 97f1eaa0..a7ed2208 100644 --- a/models.go +++ b/models.go @@ -31,13 +31,13 @@ const ( NIP_47_ERROR_RESTRICTED = "RESTRICTED" NIP_47_ERROR_BAD_REQUEST = "BAD_REQUEST" NIP_47_OTHER = "OTHER" - NIP_47_CAPABILITIES = "pay_invoice pay_keysend get_balance get_info make_invoice lookup_invoice list_transactions multi_pay_invoice multi_pay_keysend sign_message subscribe_updates" + NIP_47_CAPABILITIES = "pay_invoice pay_keysend get_balance get_info make_invoice lookup_invoice list_transactions multi_pay_invoice multi_pay_keysend sign_message notifications" + NIP_47_NOTIFICATION_TYPES = "payment_received" // same format as above e.g. "payment_received balance_updated payment_sent channel_opened channel_closed ..." ) // TODO: move other permissions here (e.g. all payment methods use pay_invoice) const ( - // TODO: should there be one permission for each types of subscription? - NIP_47_SUBSCRIBE_UPDATES_PERMISSION = "subscribe_updates" + NIP_47_NOTIFICATIONS_PERMISSION = "notifications" ) const ( diff --git a/nip47_notifier.go b/nip47_notifier.go index 1eef81ef..512253d9 100644 --- a/nip47_notifier.go +++ b/nip47_notifier.go @@ -65,7 +65,7 @@ func (notifier *Nip47Notifier) notifySubscribers(ctx context.Context, notificati notifier.svc.db.Find(&apps) for _, app := range apps { - hasPermission, _, _ := notifier.svc.hasPermission(&app, NIP_47_SUBSCRIBE_UPDATES_PERMISSION, 0) + hasPermission, _, _ := notifier.svc.hasPermission(&app, NIP_47_NOTIFICATIONS_PERMISSION, 0) if !hasPermission { continue } diff --git a/nip47_notifier_test.go b/nip47_notifier_test.go index 16e54025..9430f3ef 100644 --- a/nip47_notifier_test.go +++ b/nip47_notifier_test.go @@ -27,7 +27,7 @@ func TestSendNotification(t *testing.T) { appPermission := &AppPermission{ AppId: app.ID, App: *app, - RequestMethod: NIP_47_SUBSCRIBE_UPDATES_PERMISSION, + RequestMethod: NIP_47_NOTIFICATIONS_PERMISSION, } err = svc.db.Create(appPermission).Error assert.NoError(t, err) diff --git a/service.go b/service.go index 267b746a..f2937c6d 100644 --- a/service.go +++ b/service.go @@ -751,6 +751,7 @@ func (svc *Service) PublishNip47Info(ctx context.Context, relay *nostr.Relay) er ev.Content = NIP_47_CAPABILITIES ev.CreatedAt = nostr.Now() ev.PubKey = svc.cfg.NostrPublicKey + ev.Tags = nostr.Tags{[]string{"notifications", NIP_47_NOTIFICATION_TYPES}} err := ev.Sign(svc.cfg.NostrSecretKey) if err != nil { return err