relays.go raw

   1  package nostr
   2  
   3  // Nip65Relay represents a relay from a user's NIP-65 relay list
   4  type Nip65Relay struct {
   5  	URL   string `json:"url"`
   6  	Read  bool   `json:"read"`
   7  	Write bool   `json:"write"`
   8  }
   9  
  10  // ProfileMetadata represents parsed kind 0 profile data
  11  type ProfileMetadata struct {
  12  	Pubkey      string `json:"pubkey"`
  13  	Name        string `json:"name,omitempty"`
  14  	DisplayName string `json:"display_name,omitempty"`
  15  	Picture     string `json:"picture,omitempty"`
  16  	Banner      string `json:"banner,omitempty"`
  17  	About       string `json:"about,omitempty"`
  18  	Website     string `json:"website,omitempty"`
  19  	Nip05       string `json:"nip05,omitempty"`
  20  	Lud06       string `json:"lud06,omitempty"`
  21  	Lud16       string `json:"lud16,omitempty"`
  22  }
  23  
  24  // GetUsername returns the best username from profile metadata
  25  func (p *ProfileMetadata) GetUsername() string {
  26  	// Prefer NIP-05 identifier (without domain for uniqueness)
  27  	if p.Nip05 != "" {
  28  		return p.Nip05
  29  	}
  30  	// Then name
  31  	if p.Name != "" {
  32  		return p.Name
  33  	}
  34  	// Then display_name
  35  	if p.DisplayName != "" {
  36  		return p.DisplayName
  37  	}
  38  	// Fallback to truncated npub
  39  	return GenerateUsername(p.Pubkey)
  40  }
  41  
  42  // GetDisplayName returns the best display name
  43  func (p *ProfileMetadata) GetDisplayName() string {
  44  	if p.DisplayName != "" {
  45  		return p.DisplayName
  46  	}
  47  	if p.Name != "" {
  48  		return p.Name
  49  	}
  50  	return TruncateNpub(PubkeyToNpub(p.Pubkey))
  51  }
  52