protocol

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 9, 2019 License: MPL-2.0 Imports: 23 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

View Source
const (
	MembershipUpdateChatCreated   = "chat-created"
	MembershipUpdateNameChanged   = "name-changed"
	MembershipUpdateMembersAdded  = "members-added"
	MembershipUpdateMemberJoined  = "member-joined"
	MembershipUpdateMemberRemoved = "member-removed"
	MembershipUpdateAdminsAdded   = "admins-added"
	MembershipUpdateAdminRemoved  = "admin-removed"
)

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 int64, timeInMs TimestampInMs) int64

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 Transit 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 WrapMessageV1

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

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

Types

type Flags

type Flags uint64

Flags define various boolean properties of a message.

const (
	MessageRead Flags = 1 << iota
)

A list of Message flags. By default, a message is unread.

func (*Flags) Clear

func (f *Flags) Clear(val Flags)

func (Flags) Has

func (f Flags) Has(val Flags) bool

func (*Flags) Set

func (f *Flags) Set(val Flags)

func (*Flags) Toggle

func (f *Flags) Toggle(val Flags)

type Group

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

func NewGroup

func NewGroup(chatID string, updates []MembershipUpdateFlat) (*Group, error)

func NewGroupWithCreator

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

func NewGroupWithMembershipUpdates

func NewGroupWithMembershipUpdates(chatID string, updates []MembershipUpdate) (*Group, error)

func (Group) Admins

func (g Group) Admins() []string

func (Group) ChatID

func (g Group) ChatID() string

func (Group) Joined

func (g Group) Joined() []string

func (Group) LastClockValue

func (g Group) LastClockValue() int64

func (Group) Members

func (g Group) Members() []string

func (Group) Name

func (g Group) Name() string

func (Group) NextClockValue

func (g Group) NextClockValue() int64

func (*Group) ProcessEvent

func (g *Group) ProcessEvent(from *ecdsa.PublicKey, event MembershipUpdateEvent) error

func (*Group) ProcessEvents

func (g *Group) ProcessEvents(from *ecdsa.PublicKey, events []MembershipUpdateEvent) error

func (Group) Updates

func (g Group) Updates() []MembershipUpdateFlat

type MembershipUpdate

type MembershipUpdate struct {
	ChatID    string                  `json:"chatId"`
	Signature string                  `json:"signature"` // hex-encoded without 0x prefix
	Events    []MembershipUpdateEvent `json:"events"`
	From      string                  `json:"from"` // hex-encoded with 0x prefix
}

func (*MembershipUpdate) Flat

func (*MembershipUpdate) Sign

func (u *MembershipUpdate) Sign(identity *ecdsa.PrivateKey) error

Sign creates a signature from MembershipUpdateEvents and updates MembershipUpdate's signature. It follows the algorithm describe in the spec: https://github.com/status-im/specs/blob/master/status-group-chats-spec.md#signature.

type MembershipUpdateEvent

type MembershipUpdateEvent struct {
	Type       string   `json:"type"`
	ClockValue int64    `json:"clockValue"`
	Member     string   `json:"member,omitempty"`  // in "member-joined", "member-removed" and "admin-removed" events
	Members    []string `json:"members,omitempty"` // in "members-added" and "admins-added" events
	Name       string   `json:"name,omitempty"`    // name of the group chat
}

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

func NewAdminRemovedEvent

func NewAdminRemovedEvent(admin string, clock int64) MembershipUpdateEvent

func NewAdminsAddedEvent

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

func NewChatCreatedEvent

func NewChatCreatedEvent(name string, admin string, clock int64) MembershipUpdateEvent

func NewMemberJoinedEvent

func NewMemberJoinedEvent(member string, clock int64) MembershipUpdateEvent

func NewMemberRemovedEvent

func NewMemberRemovedEvent(member string, clock int64) MembershipUpdateEvent

func NewMembersAddedEvent

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

func NewNameChangedEvent

func NewNameChangedEvent(name string, clock int64) MembershipUpdateEvent

func (MembershipUpdateEvent) Equal

type MembershipUpdateFlat

type MembershipUpdateFlat struct {
	MembershipUpdateEvent
	ChatID    string `json:"chatId"`
	Signature string `json:"signature"`
	From      string `json:"from"`
}

func MergeFlatMembershipUpdates

func MergeFlatMembershipUpdates(dest []MembershipUpdateFlat, src []MembershipUpdateFlat) []MembershipUpdateFlat

func (MembershipUpdateFlat) Equal

type MembershipUpdateMessage

type MembershipUpdateMessage struct {
	ChatID  string             `json:"chatId"` // UUID concatenated with hex-encoded public key of the creator for the chat
	Updates []MembershipUpdate `json:"updates"`
}

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) Verify

func (m *MembershipUpdateMessage) Verify() error

Verify makes sure that the received update message has a valid signature. It also extracts public key from the signature available as From field. It does not verify the updates and their events. This should be done separately using Group struct.

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 {
	// TransportMessage is the parsed message received from the transport layer, i.e the input
	TransportMessage *types.Message `json:"transportMessage"`
	// MessageType is the type of application message contained
	MessageType StatusMessageT `json:"-"`
	// ParsedMessage is the parsed message by the application layer, i.e the output
	ParsedMessage interface{} `json:"-"`

	// TransportPayload is the payload as received from the transport layer
	TransportPayload []byte `json:"-"`
	// DecryptedPayload is the payload after having been processed by the encryption layer
	DecryptedPayload []byte `json:"decryptedPayload"`

	// ID is the canonical ID of the message
	ID types.HexBytes `json:"id"`
	// Hash is the transport layer hash
	Hash []byte `json:"-"`

	// TransportLayerSigPubKey contains the public key provided by the transport layer
	TransportLayerSigPubKey *ecdsa.PublicKey `json:"-"`
	// ApplicationMetadataLayerPubKey contains the public key provided by the application metadata layer
	ApplicationMetadataLayerSigPubKey *ecdsa.PublicKey `json:"-"`
}

StatusMessage is any Status Protocol message.

func (*StatusMessage) Clone

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

func (*StatusMessage) HandleApplication

func (m *StatusMessage) HandleApplication() error

func (*StatusMessage) HandleApplicationMetadata

func (m *StatusMessage) HandleApplicationMetadata() error

func (*StatusMessage) HandleDatasync

func (m *StatusMessage) HandleDatasync(datasync *datasync.DataSync) ([]*StatusMessage, error)

HandleDatasync processes StatusMessage through data sync layer. This is optional and DataSync might be nil. In such a case, only one payload will be returned equal to DecryptedPayload.

func (*StatusMessage) HandleEncryption

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

func (*StatusMessage) HandleTransport

func (m *StatusMessage) HandleTransport(shhMessage *types.Message) error

func (*StatusMessage) MarshalJSON added in v1.0.0

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 StatusMessageT

type StatusMessageT int
const (
	MessageT StatusMessageT = iota + 1
	MembershipUpdateMessageT
	PairMessageT
)

type TimestampInMs

type TimestampInMs int64

TimestampInMs is a timestamp in milliseconds.

func TimestampInMsFromTime

func TimestampInMsFromTime(t time.Time) TimestampInMs

TimestampInMsFromTime returns a TimestampInMs from a time.Time instance.

func (TimestampInMs) Time

func (t TimestampInMs) Time() time.Time

Time returns a time.Time instance.

Jump to

Keyboard shortcuts

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