messaging

package
v0.0.0-...-96bc9f9 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: MIT Imports: 12 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrBadJSONPayload       = errors.New("bad json payload")
	ErrResponseBadSignature = errors.New("bad response signature")
	ErrRequestTimeout       = errors.New("request timeout")
	ErrMessageBadIssuer     = errors.New("bad response issuer")
	ErrMessageBadAudience   = errors.New("bad response audience")
	ErrMessageBadStatus     = errors.New("bad response status")
	ErrMessageExpired       = errors.New("response has expired")
	ErrMessageIssuedTooSoon = errors.New("response was issued in the future")
)

Functions

This section is empty.

Types

type Config

type Config struct {
	SelfID     string
	DeviceID   string
	KeyID      string
	PrivateKey ed25519.PrivateKey
	PKI        pkiClient
	Messaging  messagingClient
	Rest       restTransport
}

Config stores all configuration needed by the messaging service

type Message

type Message struct {
	Sender         string
	ConversationID string
	Payload        []byte
}

Message message

type Service

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

Service handles all messaging operations

func NewService

func NewService(cfg Config) *Service

NewService creates a new client for interacting with messaging

func (*Service) BuildRequest

func (s *Service) BuildRequest(payload map[string]interface{}) (map[string]interface{}, error)

BuildRequest constructs a request map based on the given payload and returns it along with an error. - payload (map[string]interface{}): the payload to include in the request Returns: - (map[string]interface{}): the constructed request map - (error): an error if the "typ" key is not present in the request map

func (*Service) BuildSignedRequest

func (s *Service) BuildSignedRequest(payload map[string]interface{}) ([]byte, error)

BuildSignedRequest creates a request payload with the given payload, and returns the payload as a byte array. It generates a new request ID, JWT ID, and timestamps for the request. If the payload does not contain a "typ" key, it returns an empty byte array and an error. If the payload contains a "sub" key but not an "aud" key, it sets the "aud" key to the value of "sub". It then calls the PrepareJWS function to prepare a JWS token with the request payload, and returns the JWS token as a byte array.

Parameters:

  • payload: A map of string keys to interface{} values representing the payload of the request.

Returns:

  • []byte: A byte array representing the prepared JWS token.
  • error: An error that is non-nil if the payload does not contain a "typ" key.

func (*Service) Notify

func (s *Service) Notify(selfID, content string) error

Notify sends a notification to a given self ID

func (*Service) Request

func (s *Service) Request(recipients []string, req []byte) ([]byte, error)

Request make a request to an identity

func (*Service) Respond

func (s *Service) Respond(recipient, conversationID string, response []byte) error

Respond sends a message to a given sender

func (*Service) Send

func (s *Service) Send(recipients []string, conversationID string, body []byte) error

Send sends a message to the given recipient

func (*Service) SendAsync

func (s *Service) SendAsync(recipients []string, conversationID string, body []byte, callback func(err error))

Send sends a message to the given recipient

func (*Service) Start

func (s *Service) Start() bool

func (*Service) Subscribe

func (s *Service) Subscribe(messageType string, h func(m *Message))

Subscribe subscribe to messages of a given type

Jump to

Keyboard shortcuts

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