Browse Source

Add relay identity pubkey and subscription-based profile updates; bump version to v0.8.4.

- Included relay identity public key in `relayinfo` response.
- Added `UpdateRelayProfile` function to dynamically create/update relay's subscription profile.
- Incremented version from v0.8.3 to v0.8.4.
main
mleku 4 months ago
parent
commit
ff017b45d2
No known key found for this signature in database
  1. 15
      app/handle-relayinfo.go
  2. 52
      app/payment_processor.go
  3. 2
      pkg/version/version

15
app/handle-relayinfo.go

@ -4,9 +4,12 @@ import (
"encoding/json" "encoding/json"
"net/http" "net/http"
"sort" "sort"
"strings"
"lol.mleku.dev/chk" "lol.mleku.dev/chk"
"lol.mleku.dev/log" "lol.mleku.dev/log"
"next.orly.dev/pkg/crypto/p256k"
"next.orly.dev/pkg/encoders/hex"
"next.orly.dev/pkg/protocol/relayinfo" "next.orly.dev/pkg/protocol/relayinfo"
"next.orly.dev/pkg/version" "next.orly.dev/pkg/version"
) )
@ -67,12 +70,22 @@ func (s *Server) HandleRelayInfo(w http.ResponseWriter, r *http.Request) {
dashboardURL := s.DashboardURL(r) dashboardURL := s.DashboardURL(r)
description := version.Description + " dashboard: " + dashboardURL description := version.Description + " dashboard: " + dashboardURL
// Get relay identity pubkey as hex
var relayPubkey string
if skb, err := s.D.GetRelayIdentitySecret(); err == nil && len(skb) == 32 {
sign := new(p256k.Signer)
if err := sign.InitSec(skb); err == nil {
relayPubkey = hex.Enc(sign.Pub())
}
}
info = &relayinfo.T{ info = &relayinfo.T{
Name: s.Config.AppName, Name: s.Config.AppName,
Description: description, Description: description,
PubKey: relayPubkey,
Nips: supportedNIPs, Nips: supportedNIPs,
Software: version.URL, Software: version.URL,
Version: version.V, Version: strings.TrimPrefix(version.V, "v"),
Limitation: relayinfo.Limits{ Limitation: relayinfo.Limits{
AuthRequired: s.Config.ACLMode != "none", AuthRequired: s.Config.ACLMode != "none",
RestrictedWrites: s.Config.ACLMode != "none", RestrictedWrites: s.Config.ACLMode != "none",

52
app/payment_processor.go

@ -820,6 +820,58 @@ func (pp *PaymentProcessor) npubToPubkey(npubStr string) ([]byte, error) {
return pubkey, nil return pubkey, nil
} }
// UpdateRelayProfile creates or updates the relay's kind 0 profile with subscription information
func (pp *PaymentProcessor) UpdateRelayProfile() error {
// Get relay identity secret to sign the profile
skb, err := pp.db.GetRelayIdentitySecret()
if err != nil || len(skb) != 32 {
return fmt.Errorf("no relay identity configured")
}
// Initialize signer
sign := new(p256k.Signer)
if err := sign.InitSec(skb); err != nil {
return fmt.Errorf("failed to initialize signer: %w", err)
}
monthlyPrice := pp.config.MonthlyPriceSats
if monthlyPrice <= 0 {
monthlyPrice = 6000
}
// Calculate daily rate
dailyRate := monthlyPrice / 30
// Get relay wss:// URL - use dashboard URL but with wss:// scheme
relayURL := strings.Replace(pp.getDashboardURL(), "https://", "wss://", 1)
// Create profile content as JSON
profileContent := fmt.Sprintf(`{
"name": "Relay Bot",
"about": "This relay requires a subscription to access. Zap any of my notes to pay for access. Monthly price: %d sats (%d sats/day). Relay: %s",
"lud16": "",
"nip05": "",
"website": "%s"
}`, monthlyPrice, dailyRate, relayURL, pp.getDashboardURL())
// Build the profile event
ev := event.New()
ev.Kind = kind.ProfileMetadata.K // Kind 0 for profile metadata
ev.Pubkey = sign.Pub()
ev.CreatedAt = timestamp.Now().V
ev.Content = []byte(profileContent)
ev.Tags = tag.NewS()
// Sign and save the event
ev.Sign(sign)
if _, _, err := pp.db.SaveEvent(pp.ctx, ev); err != nil {
return fmt.Errorf("failed to save relay profile: %w", err)
}
log.I.F("updated relay profile with subscription information")
return nil
}
// decodeAnyPubkey decodes a public key from either hex string or npub format // decodeAnyPubkey decodes a public key from either hex string or npub format
func decodeAnyPubkey(s string) ([]byte, error) { func decodeAnyPubkey(s string) ([]byte, error) {
s = strings.TrimSpace(s) s = strings.TrimSpace(s)

2
pkg/version/version

@ -1 +1 @@
v0.8.3 v0.8.4
Loading…
Cancel
Save