protocol

package
v0.181.35 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: MPL-2.0, MPL-2.0 Imports: 25 Imported by: 0

README

v1 protocol package folder

This folder contains only data types mentioned in the specification and required for its implementation.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrInvalidDecodedValue means that the decoded message is of wrong type.
	// This might mean that the status message serialization tag changed.
	ErrInvalidDecodedValue = errors.New("invalid decoded value type")
)

Functions

func CalcMessageClock

func CalcMessageClock(lastObservedValue uint64, timeInMs uint64) uint64

CalcMessageClock calculates a new clock value for Message. It is used to properly sort messages and accommodate the fact that time might be different on each device.

func EncodeMembershipUpdateMessage

func EncodeMembershipUpdateMessage(value MembershipUpdateMessage) ([]byte, error)

EncodeMembershipUpdateMessage encodes a MembershipUpdateMessage using protobuf serialization.

func EncodePairMessage

func EncodePairMessage(value PairMessage) ([]byte, error)

EncodePairMessage encodes a PairMessage using Transit serialization.

func MessageID

func MessageID(author *ecdsa.PublicKey, data []byte) types.HexBytes

MessageID calculates the messageID from author's compressed public key and not encrypted but encoded payload.

func NewMessageDecoder

func NewMessageDecoder(r io.Reader) *transit.Decoder

NewMessageDecoder returns a new Transit decoder that can deserialize Message structs. More about Transit: https://github.com/cognitect/transit-format

func NewMessageEncoder

func NewMessageEncoder(w io.Writer) *transit.Encoder

NewMessageEncoder returns a new Transit encoder that can encode Message values. More about Transit: https://github.com/cognitect/transit-format

func TimestampInMsFromTime

func TimestampInMsFromTime(t time.Time) uint64

TimestampInMsFromTime returns a TimestampInMs from a time.Time instance.

func WrapMessageV1

func WrapMessageV1(payload []byte, messageType protobuf.ApplicationMetadataMessage_Type, identity *ecdsa.PrivateKey) ([]byte, error)

WrapMessageV1 wraps a payload into a protobuf message and signs it if an identity is provided

Types

type ApplicationLayer added in v0.171.12

type ApplicationLayer struct {
	// Payload after having been unwrapped from the application layer
	Payload   []byte                                   `json:"-"`
	ID        types.HexBytes                           `json:"id"`
	SigPubKey *ecdsa.PublicKey                         `json:"-"`
	Type      protobuf.ApplicationMetadataMessage_Type `json:"-"`
}

ApplicationLayer is the topmost layer and represents the application message.

type EncryptionLayer added in v0.171.12

type EncryptionLayer struct {
	// Payload after having been processed by the encryption layer
	Payload         []byte `json:"-"`
	Installations   []*multidevice.Installation
	SharedSecrets   []*sharedsecret.Secret
	HashRatchetInfo []*encryption.HashRatchetInfo
}

EncryptionLayer handles optional encryption. It is not mandatory and can be omitted, also its presence does not guarantee encryption.

type Group

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

func NewGroupWithCreator

func NewGroupWithCreator(name string, color string, clock uint64, creator *ecdsa.PrivateKey) (*Group, error)

func NewGroupWithEvents

func NewGroupWithEvents(chatID string, events []MembershipUpdateEvent) (*Group, error)

func (Group) AbridgedEvents added in v0.69.0

func (g Group) AbridgedEvents() []MembershipUpdateEvent

AbridgedEvents returns the minimum set of events for a user to publish a post The events we want to keep: 1) Chat created 2) Latest color changed 3) Latest image changed 4) For each admin, the latest admins added event that contains them 5) For each member, the latest members added event that contains them 4 & 5, might bring removed admins or removed members, for those, we also need to keep the event that removes them

func (Group) Admins

func (g Group) Admins() []string

func (Group) ChatID

func (g Group) ChatID() string

func (Group) Color added in v0.105.1

func (g Group) Color() string

func (Group) Creator added in v0.117.3

func (g Group) Creator() (string, error)

func (Group) Events

func (g Group) Events() []MembershipUpdateEvent

func (Group) Image added in v0.108.2

func (g Group) Image() []byte

func (Group) IsMember

func (g Group) IsMember(id string) bool

func (Group) LastClockValue

func (g Group) LastClockValue() uint64

func (Group) MemberPublicKeys added in v0.171.6

func (g Group) MemberPublicKeys() ([]*ecdsa.PublicKey, error)

func (Group) Members

func (g Group) Members() []string

func (Group) Name

func (g Group) Name() string

func (*Group) ProcessEvent

func (g *Group) ProcessEvent(event MembershipUpdateEvent) error

func (*Group) ProcessEvents

func (g *Group) ProcessEvents(events []MembershipUpdateEvent) error

func (Group) WasEverMember added in v0.166.2

func (g Group) WasEverMember(id string) (bool, error)

type MembershipUpdateEvent

type MembershipUpdateEvent struct {
	Type       protobuf.MembershipUpdateEvent_EventType `json:"type"`
	ClockValue uint64                                   `json:"clockValue"`
	Members    []string                                 `json:"members,omitempty"` // in "members-added" and "admins-added" events
	Name       string                                   `json:"name,omitempty"`    // name of the group chat
	Color      string                                   `json:"color,omitempty"`   // color of the group chat
	Image      []byte                                   `json:"image,omitempty"`   // image of the group chat
	From       string                                   `json:"from,omitempty"`
	Signature  []byte                                   `json:"signature,omitempty"`
	ChatID     string                                   `json:"chatId"`
	RawPayload []byte                                   `json:"rawPayload"`
}

MembershipUpdateEvent contains an event information. Member and Members are hex-encoded values with 0x prefix.

func MembershipUpdateEventFromProtobuf

func MembershipUpdateEventFromProtobuf(chatID string, raw []byte) (*MembershipUpdateEvent, error)

func NewAdminRemovedEvent

func NewAdminRemovedEvent(admin string, clock uint64) MembershipUpdateEvent

func NewAdminsAddedEvent

func NewAdminsAddedEvent(admins []string, clock uint64) MembershipUpdateEvent

func NewChatCreatedEvent

func NewChatCreatedEvent(name string, color string, clock uint64) MembershipUpdateEvent

func NewColorChangedEvent added in v0.105.1

func NewColorChangedEvent(color string, clock uint64) MembershipUpdateEvent

func NewImageChangedEvent added in v0.108.2

func NewImageChangedEvent(image []byte, clock uint64) MembershipUpdateEvent

func NewMemberJoinedEvent

func NewMemberJoinedEvent(clock uint64) MembershipUpdateEvent

func NewMemberRemovedEvent

func NewMemberRemovedEvent(member string, clock uint64) MembershipUpdateEvent

func NewMembersAddedEvent

func NewMembersAddedEvent(members []string, clock uint64) MembershipUpdateEvent

func NewNameChangedEvent

func NewNameChangedEvent(name string, clock uint64) MembershipUpdateEvent

func (*MembershipUpdateEvent) Equal

func (*MembershipUpdateEvent) Sign

func (*MembershipUpdateEvent) ToProtobuf

type MembershipUpdateMessage

type MembershipUpdateMessage struct {
	ChatID        string                  `json:"chatId"` // UUID concatenated with hex-encoded public key of the creator for the chat
	Events        []MembershipUpdateEvent `json:"events"`
	Message       *protobuf.ChatMessage   `json:"-"`
	EmojiReaction *protobuf.EmojiReaction `json:"-"`
}

MembershipUpdateMessage is a message used to propagate information about group membership changes. For more information, see https://github.com/status-im/specs/blob/master/status-group-chats-spec.md.

func (*MembershipUpdateMessage) ToProtobuf

type PairMessage

type PairMessage struct {
	InstallationID string `json:"installationId"`
	// The type of the device
	DeviceType string `json:"deviceType"`
	// Name the user set name
	Name string `json:"name"`
	// The FCMToken for mobile platforms
	FCMToken string `json:"fcmToken"`

	// not protocol defined fields
	ID []byte `json:"-"`
}

PairMessage contains all message details.

func CreatePairMessage

func CreatePairMessage(installationID string, name string, deviceType string, fcmToken string) PairMessage

CreatePairMessage creates a PairMessage which is used to pair devices.

func DecodePairMessage

func DecodePairMessage(data []byte) (message PairMessage, err error)

DecodePairMessage decodes a raw payload to Message struct.

func (*PairMessage) MarshalJSON

func (m *PairMessage) MarshalJSON() ([]byte, error)

type StatusMessage

type StatusMessage struct {
	TransportLayer   TransportLayer   `json:"transportLayer"`
	EncryptionLayer  EncryptionLayer  `json:"encryptionLayer"`
	ApplicationLayer ApplicationLayer `json:"applicationLayer"`
}

StatusMessage encapsulates all layers of the protocol

func (*StatusMessage) Clone

func (m *StatusMessage) Clone() (*StatusMessage, error)

func (*StatusMessage) HandleApplicationLayer added in v0.171.12

func (m *StatusMessage) HandleApplicationLayer() error

func (*StatusMessage) HandleEncryptionLayer added in v0.171.12

func (m *StatusMessage) HandleEncryptionLayer(myKey *ecdsa.PrivateKey, senderKey *ecdsa.PublicKey, enc *encryption.Protocol, skipNegotiation bool) error

func (*StatusMessage) HandleTransportLayer added in v0.171.12

func (m *StatusMessage) HandleTransportLayer(wakuMessage *types.Message) error

func (*StatusMessage) MarshalJSON

func (m *StatusMessage) MarshalJSON() ([]byte, error)

Temporary JSON marshaling for those messages that are not yet processed by the go code

func (*StatusMessage) SigPubKey

func (m *StatusMessage) SigPubKey() *ecdsa.PublicKey

SigPubKey returns the most important signature, from the application layer to transport

type TransportLayer added in v0.171.12

type TransportLayer struct {
	// Payload as received from the transport layer
	Payload   []byte           `json:"-"`
	Hash      []byte           `json:"-"`
	SigPubKey *ecdsa.PublicKey `json:"-"`
	Dst       *ecdsa.PublicKey
	Message   *types.Message `json:"message"`
}

TransportLayer is the lowest layer and represents waku message.

Jump to

Keyboard shortcuts

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