nostr

package
v0.0.0-...-0269a1e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 5, 2023 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// size of a subscription id
	SUB_ID_LENGTH = 10

	DEFAULT_LIMIT = 100
)
View Source
const BUFFER_SIZE = 1000

Size of the buffer

Variables

View Source
var (

	// ErrRelayAuthFailed indicates the authentication on a relay completed, but failed
	ErrRelayAuthFailed = errors.New("failed to authenticate to the relay")
	// ErrRelayAuthTimeout indicates the authentication on a relay did not complete in time
	ErrRelayAuthTimeout = errors.New("timeout authenticating to the relay")
	// ErrFailedToPublishEvent indicates the event could not be published to the relay
	ErrFailedToPublishEvent = errors.New("failed to publish event to relay")
	/// ErrNoRelayConnected inidcates that we try to perform an action on a realay, but we aren't connected to any.
	ErrNoRelayConnected = errors.New("no relay connected currently")
)
View Source
var (
	// TagTftAtomicSwapSale is the searchable tag for atomic swaps in tft
	TagTftAtomicSwapSale = []string{"t", "tft_atomic_swap_sale_order"}
)

Functions

func GenerateKeyPair

func GenerateKeyPair() string

Types

type Channel

type Channel struct {
	Name    string `json:"name"`
	About   string `json:"about"`
	Picture string `json:"picture"`
}

type ChannelMessage

type ChannelMessage struct {
	// Content of the message
	Content   string `json:"content"`
	ChannelID string `json:"channel_id"`
	// MessageID is used for replies
	MessageID string `json:"message_id"`
	// PublicKey of author to reply to
	PublicKey string `json:"public_key"`
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client for nostr protocol

func (*Client) CloseSubscription

func (c *Client) CloseSubscription(id string)

CloseSubscription managed by the server for this client, based on its ID.

func (*Client) ConnectAuthRelay

func (c *Client) ConnectAuthRelay(ctx context.Context, relayURL string) error

ConnectAuthRelay connect and authenticates to a NIP42 authenticated relay

func (*Client) ConnectRelay

func (c *Client) ConnectRelay(ctx context.Context, relayURL string) error

func (*Client) CreateChannel

func (c *Client) CreateChannel(ctx context.Context, tags []string, content Channel) (string, error)

CreateChannel creates a new channel

func (*Client) CreateChannelRootMessage

func (c *Client) CreateChannelRootMessage(ctx context.Context, message ChannelMessage) (string, error)

CreateChannelRootMessage creates a message in channel. If replyTo is the empty string, it is marked as a root

func (*Client) FetchChannelCreation

func (c *Client) FetchChannelCreation() ([]RelayChannel, error)

FetchChannelCreation fetches and returns channel creation events

func (*Client) FetchChannelMessages

func (c *Client) FetchChannelMessages(channelID string) ([]RelayChannelMessage, error)

SubscribeChannelMessages subsribes to messages which are a reply to the given chanMessageId

func (*Client) GetEvents

func (c *Client) GetEvents() []NostrEvent

Get all historic events on active subscriptions for the client. Note that only a limited amount of events are kept. If the actual client waits too long to call this, events might be dropped. returned events are sorted from oldes to newest

func (*Client) GetSubscriptionEvents

func (c *Client) GetSubscriptionEvents(id string) []NostrEvent

GetSubscriptionEvents for a subscription with the given ID. Events are removed from the subscription

func (*Client) GetSubscriptionEventsWithCount

func (c *Client) GetSubscriptionEventsWithCount(id string, count uint32) []NostrEvent

GetSubscriptionEventsWithCount returns a number of events for a subscription with the given ID. Returned events are removed from the subscription

func (*Client) HideMessage

func (c *Client) HideMessage(ctx context.Context, tags []string, messageID string, content string) error

HideMessage marks a message as hidden for the user. It should be noted that properly handling this is mostly up to the clients

func (*Client) Id

func (c *Client) Id() string

Id of the client, this is the enocded public key in NIP19 format

func (*Client) MuteUser

func (c *Client) MuteUser(ctx context.Context, tags []string, user string, content string) error

MuteUser marks a user as muted for the current user. It should be noted that properly handling this is mostly up to the clients. The user to mute is identified by it's pubkey

func (*Client) PublicKey

func (c *Client) PublicKey() string

func (*Client) PublishDirectMessage

func (c *Client) PublishDirectMessage(ctx context.Context, receiver string, tags []string, content string) error

/ PublishDirectMessage publishes a direct message for a given peer identified by the given pubkey on the connected relays

func (*Client) PublishEventDeletion

func (c *Client) PublishEventDeletion(ctx context.Context, tags []string, id string) error

PublishEventDeletion to connected relays. If an event with the given ID was already published, conforming relays should delete it

func (*Client) PublishMetadata

func (c *Client) PublishMetadata(ctx context.Context, tags []string, content Metadata) error

PublishMetadata to connected relays. If metadata was published previously, the old metadata should be overwritten conforming relays

func (*Client) PublishProduct

func (c *Client) PublishProduct(ctx context.Context, tags []string, content Product) error

PublishProduct to connected relays. If a product with the given ID was already published, conforming relays should update it

func (*Client) PublishRecommendServer

func (c *Client) PublishRecommendServer(ctx context.Context, tags []string, content string) error

PublishRecommendServer to connected relays. The content is supposed to be the URL of the relay being recommended

func (*Client) PublishStall

func (c *Client) PublishStall(ctx context.Context, tags []string, content Stall) error

PublishStall to connected relays. If a stall with the given ID was already published, conforming relays should update it

func (*Client) PublishTextNote

func (c *Client) PublishTextNote(ctx context.Context, tags []string, content string) error

PublishTextNote to connected relays

func (*Client) SubscribeChannelCreation

func (c *Client) SubscribeChannelCreation() (string, error)

func (*Client) SubscribeChannelMessages

func (c *Client) SubscribeChannelMessages(id string) (string, error)

SubscribeChannelMessages subsribes to a messages sent to a channel with id `id`, or reply messages to the message with id `id`

func (*Client) SubscribeDirectMessagesDirect

func (c *Client) SubscribeDirectMessagesDirect(swapTag string) (<-chan NostrEvent, error)

TODO: Remove once subsciptions are more porper

func (*Client) SubscribeMessages

func (c *Client) SubscribeMessages() (string, error)

SubscribeMessages subscribes to direct messages (Kind 4) on all relays and decrypts them if they are addressed to the client

func (*Client) SubscribeProductCreation

func (c *Client) SubscribeProductCreation(tag string) (string, error)

Subscribe ProductCreation subscribes to product creation events (Kind 30018) on all relays

func (*Client) SubscribeStallCreation

func (c *Client) SubscribeStallCreation(tag string) (string, error)

SubscribeStallCreation subscribes to stall creation events (Kind 30017) on all relays

func (*Client) SubscribeTextNotes

func (c *Client) SubscribeTextNotes() (string, error)

SubscribeTextNotes to textnote events on a relay

func (*Client) SubscriptionIds

func (c *Client) SubscriptionIds() []string

Get the ID's of all active subscriptions

func (*Client) UpdateChannelMetadata

func (c *Client) UpdateChannelMetadata(ctx context.Context, tags []string, channelID string, content Channel) error

UpdateChannelMetadata updates the channel metdata. ChannelID is the event ID of the create channel event used to create the channel to update

type Metadata

type Metadata struct {
	Name    string `json:"name"`
	About   string `json:"about"`
	Picture string `json:"picture"`
}

Metadata used when setting metadata, see [nip01](https://github.com/nostr-protocol/nips/blob/master/01.md)

type NostrEvent

type NostrEvent = nostr.Event

type Product

type Product struct {
	Id          string   `json:"id"`
	StallId     string   `json:"stall_id"`
	Name        string   `json:"name"`
	Description string   `json:"description,omitempty"`
	Images      []string `json:"images,omitempty"`
	Currency    string   `json:"currency"`
	Price       float64  `json:"price"`
	Quantity    uint     `json:"quantity"`
	// Specs is an array of key value pairs
	Specs [][]string `json:"specs"`
}

Product for sale in a stall

type RelayChannel

type RelayChannel struct {
	Channel
	Relay string `json:"relay"`
	Id    string `json:"id"`
}

type RelayChannelMessage

type RelayChannelMessage struct {
	Content string     `json:"content"`
	Tags    [][]string `json:"tags"`
	Relay   string     `json:"relay"`
	Id      string     `json:"id"`
}

type RelayEvent

type RelayEvent struct {
	Relay string     `json:"relay"`
	Event NostrEvent `json:"event"`
}

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server is a persistent client keeping open connections to relays.

func NewServer

func NewServer() *Server

NewServer managing relay connections and subscriptions for possibly different peers

func (*Server) NewClient

func (s *Server) NewClient(sk string) (*Client, error)

NewClient for a server, authenticated by the private key of the client. Private key is passed as hex bytes

type Shipping

type Shipping struct {
	Id        string   `json:"id"`
	Name      string   `json:"name,omitempty"`
	Cost      float64  `json:"cost"`
	Countries []string `json:"countries"`
}

Shipping information for a Stall

type Stall

type Stall struct {
	Id          string     `json:"id"`
	Name        string     `json:"name"`
	Description string     `json:"description,omitempty"`
	Currency    string     `json:"currency"`
	Shipping    []Shipping `json:"shipping"`
}

Stall of products for sale

type Subscription

type Subscription struct {
	// contains filtered or unexported fields
}

Subscription for events on a relay

func (*Subscription) Close

func (s *Subscription) Close()

Close an open subscription

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL