Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Merge pull request #221 from getAlby/feat/info-notifications-tag
Browse files Browse the repository at this point in the history
feat: include supported notification types in wallet service info notifications tag
  • Loading branch information
rolznz authored Apr 10, 2024
2 parents 9ef961f + fd0dfe2 commit fe9d0bb
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 9 deletions.
10 changes: 6 additions & 4 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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;
Expand All @@ -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[] = [
Expand All @@ -78,7 +80,7 @@ export const nip47MethodDescriptions: Record<RequestMethodType, string> = {
// TODO: merge with nip47MethodDescriptions
export const nip47PermissionDescriptions: Record<PermissionType, string> = {
...nip47MethodDescriptions,
[NIP_47_SUBSCRIBE_UPDATES_PERMISSION]: "Subscribe to updates",
[NIP_47_NOTIFICATIONS_PERMISSION]: "Receive wallet notifications",
};

export const expiryOptions: Record<string, number> = {
Expand Down
6 changes: 3 additions & 3 deletions models.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion nip47_notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion nip47_notifier_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit fe9d0bb

Please sign in to comment.