common

package
v0.56.3 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: MPL-2.0, MPL-2.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidCiphertextLength = errors.New("invalid cyphertext length")

Functions

func Decrypt

func Decrypt(cyphertext []byte, key []byte) ([]byte, error)

func Encrypt

func Encrypt(plaintext []byte, key []byte, reader io.Reader) ([]byte, error)

func HashPublicKey

func HashPublicKey(pk *ecdsa.PublicKey) []byte

func IsPubKeyEqual

func IsPubKeyEqual(a, b *ecdsa.PublicKey) bool

IsPubKeyEqual checks that two public keys are equal

func MessageSpecToWhisper

func MessageSpecToWhisper(spec *encryption.ProtocolMessageSpec) (*types.NewMessage, error)

func Shake256

func Shake256(buf []byte) []byte

Types

type FeatureFlags

type FeatureFlags struct {
	// Datasync indicates whether direct messages should be sent exclusively
	// using datasync, breaking change for non-v1 clients. Public messages
	// are not impacted
	Datasync bool

	// PushNotification indicates whether we should be enabling the push notification feature
	PushNotifications bool
}

type MessageProcessor

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

func NewMessageProcessor

func NewMessageProcessor(
	identity *ecdsa.PrivateKey,
	database *sql.DB,
	enc *encryption.Protocol,
	transport transport.Transport,
	logger *zap.Logger,
	features FeatureFlags,
) (*MessageProcessor, error)

func (*MessageProcessor) AddEphemeralKey

func (p *MessageProcessor) AddEphemeralKey(privateKey *ecdsa.PrivateKey) (*transport.Filter, error)

AddEphemeralKey adds an ephemeral key that we will be listening to note that we never removed them from now, as waku/whisper does not recalculate topics on removal, so effectively there's no benefit. On restart they will be gone.

func (*MessageProcessor) EncodeMembershipUpdate

func (p *MessageProcessor) EncodeMembershipUpdate(
	group *v1protocol.Group,
	chatMessage *protobuf.ChatMessage,
) ([]byte, error)

EncodeMembershipUpdate takes a group and an optional chat message and returns the protobuf representation to be sent on the wire. All the events in a group are encoded and added to the payload

func (*MessageProcessor) HandleMessages

func (p *MessageProcessor) HandleMessages(shhMessage *types.Message, applicationLayer bool) ([]*v1protocol.StatusMessage, error)

HandleMessages expects a whisper message as input, and it will go through a series of transformations until the message is parsed into an application layer message, or in case of Raw methods, the processing stops at the layer before. It returns an error only if the processing of required steps failed.

func (*MessageProcessor) JoinPublic

func (p *MessageProcessor) JoinPublic(chatID string) error

func (*MessageProcessor) SendGroup

func (p *MessageProcessor) SendGroup(
	ctx context.Context,
	recipients []*ecdsa.PublicKey,
	rawMessage RawMessage,
) ([]byte, error)

SendGroup takes encoded data, encrypts it and sends through the wire, always return the messageID

func (*MessageProcessor) SendPairInstallation

func (p *MessageProcessor) SendPairInstallation(
	ctx context.Context,
	recipient *ecdsa.PublicKey,
	rawMessage RawMessage,
) ([]byte, error)

sendPairInstallation sends data to the recipients, using DH

func (*MessageProcessor) SendPrivate

func (p *MessageProcessor) SendPrivate(
	ctx context.Context,
	recipient *ecdsa.PublicKey,
	rawMessage RawMessage,
) ([]byte, error)

SendPrivate takes encoded data, encrypts it and sends through the wire.

func (*MessageProcessor) SendPublic

func (p *MessageProcessor) SendPublic(
	ctx context.Context,
	chatName string,
	rawMessage RawMessage,
) ([]byte, error)

SendPublic takes encoded data, encrypts it and sends through the wire.

func (*MessageProcessor) Stop

func (p *MessageProcessor) Stop()

func (*MessageProcessor) SubscribeToScheduledMessages

func (p *MessageProcessor) SubscribeToScheduledMessages() <-chan *RawMessage

SubscribeToScheduledMessages returns a channel where we publish every time a message is scheduled for sending

func (*MessageProcessor) SubscribeToSentMessages

func (p *MessageProcessor) SubscribeToSentMessages() <-chan *SentMessage

SubscribeToSentMessages returns a channel where we publish every time a message is sent

type RawMessage

type RawMessage struct {
	ID                   string
	LocalChatID          string
	LastSent             uint64
	SendCount            int
	Sent                 bool
	ResendAutomatically  bool
	SkipEncryption       bool
	SendPushNotification bool
	MessageType          protobuf.ApplicationMetadataMessage_Type
	Payload              []byte
	Sender               *ecdsa.PrivateKey
	Recipients           []*ecdsa.PublicKey
}

RawMessage represent a sent or received message, kept for being able to re-send/propagate

type SentMessage

type SentMessage struct {
	PublicKey  *ecdsa.PublicKey
	Spec       *encryption.ProtocolMessageSpec
	MessageIDs [][]byte
}

SentMessage reprent a message that has been passed to the transport layer

Jump to

Keyboard shortcuts

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