Documentation
¶
Index ¶
- Constants
- Variables
- func CalcMessageClock(lastObservedValue int64, timeInMs TimestampInMs) int64
- func EncodeMembershipUpdateMessage(value MembershipUpdateMessage) ([]byte, error)
- func EncodeMessage(value Message) ([]byte, error)
- func EncodePairMessage(value PairMessage) ([]byte, error)
- func MessageID(author *ecdsa.PublicKey, data []byte) statusproto.HexBytes
- func NewMessageDecoder(r io.Reader) *transit.Decoder
- func NewMessageEncoder(w io.Writer) *transit.Encoder
- func WrapMessageV1(payload []byte, identity *ecdsa.PrivateKey) ([]byte, error)
- type Content
- type Flags
- type Group
- type MembershipUpdate
- type MembershipUpdateEvent
- func NewAdminRemovedEvent(admin string, clock int64) MembershipUpdateEvent
- func NewAdminsAddedEvent(admins []string, clock int64) MembershipUpdateEvent
- func NewChatCreatedEvent(name string, clock int64) MembershipUpdateEvent
- func NewMemberJoinedEvent(member string, clock int64) MembershipUpdateEvent
- func NewMemberRemovedEvent(member string, clock int64) MembershipUpdateEvent
- func NewMembersAddedEvent(members []string, clock int64) MembershipUpdateEvent
- func NewNameChangedEvent(name string, clock int64) MembershipUpdateEvent
- type MembershipUpdateMessage
- type Message
- type PairMessage
- type StatusMessage
- func (s *StatusMessage) Clone() (*StatusMessage, error)
- func (m *StatusMessage) HandleApplication() error
- func (m *StatusMessage) HandleApplicationMetadata() error
- func (m *StatusMessage) HandleDatasync(datasync *datasync.DataSync) ([]*StatusMessage, error)
- func (m *StatusMessage) HandleEncryption(myKey *ecdsa.PrivateKey, senderKey *ecdsa.PublicKey, enc *encryption.Protocol) error
- func (m *StatusMessage) HandleTransport(shhMessage *whispertypes.Message) error
- func (s *StatusMessage) SigPubKey() *ecdsa.PublicKey
- type StatusProtocolMessage
- func (*StatusProtocolMessage) Descriptor() ([]byte, []int)
- func (m *StatusProtocolMessage) GetPayload() []byte
- func (m *StatusProtocolMessage) GetSignature() []byte
- func (*StatusProtocolMessage) ProtoMessage()
- func (m *StatusProtocolMessage) Reset()
- func (m *StatusProtocolMessage) String() string
- func (m *StatusProtocolMessage) XXX_DiscardUnknown()
- func (m *StatusProtocolMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
- func (m *StatusProtocolMessage) XXX_Merge(src proto.Message)
- func (m *StatusProtocolMessage) XXX_Size() int
- func (m *StatusProtocolMessage) XXX_Unmarshal(b []byte) error
- type TimestampInMs
Constants ¶
const ( MembershipUpdateChatCreated = "chat-created" MembershipUpdateNameChanged = "name-changed" MembershipUpdateMembersAdded = "members-added" MembershipUpdateMemberJoined = "member-joined" MembershipUpdateMemberRemoved = "member-removed" MembershipUpdateAdminsAdded = "admins-added" MembershipUpdateAdminRemoved = "admin-removed" )
const ( MessageTypePublicGroup = "public-group-user-message" MessageTypePrivate = "user-message" MessageTypePrivateGroup = "group-user-message" )
Message types.
const (
// ContentTypeTextPlain means that the message contains plain text.
ContentTypeTextPlain = "text/plain"
)
Variables ¶
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 accomodate the fact that time might be different on each device.
func EncodeMembershipUpdateMessage ¶ added in v0.3.0
func EncodeMembershipUpdateMessage(value MembershipUpdateMessage) ([]byte, error)
EncodeMembershipUpdateMessage encodes a MembershipUpdateMessage using Transit serialization.
func EncodeMessage ¶
EncodeMessage encodes a Message 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) statusproto.HexBytes
MessageID calculates the messageID from author's compressed public key and not encrypted but encoded payload.
func NewMessageDecoder ¶
NewMessageDecoder returns a new Transit decoder that can deserialize Message structs. More about Transit: https://github.com/cognitect/transit-format
func NewMessageEncoder ¶
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 Group ¶ added in v0.3.0
func (*Group) ValidateEvent ¶ added in v0.3.0
func (g *Group) ValidateEvent(from string, event MembershipUpdateEvent) bool
ValidateEvent returns true if a given event is valid.
type MembershipUpdate ¶ added in v0.3.0
type MembershipUpdate struct {
ChatID string `json:"chatId"`
From string `json:"from"`
Signature string `json:"signature"`
Events []MembershipUpdateEvent `json:"events"`
}
func (*MembershipUpdate) Sign ¶ added in v0.3.0
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 ¶ added in v0.3.0
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
}
func NewAdminRemovedEvent ¶ added in v0.3.0
func NewAdminRemovedEvent(admin string, clock int64) MembershipUpdateEvent
func NewAdminsAddedEvent ¶ added in v0.3.0
func NewAdminsAddedEvent(admins []string, clock int64) MembershipUpdateEvent
func NewChatCreatedEvent ¶ added in v0.3.0
func NewChatCreatedEvent(name string, clock int64) MembershipUpdateEvent
func NewMemberJoinedEvent ¶ added in v0.3.0
func NewMemberJoinedEvent(member string, clock int64) MembershipUpdateEvent
func NewMemberRemovedEvent ¶ added in v0.3.0
func NewMemberRemovedEvent(member string, clock int64) MembershipUpdateEvent
func NewMembersAddedEvent ¶ added in v0.3.0
func NewMembersAddedEvent(members []string, clock int64) MembershipUpdateEvent
func NewNameChangedEvent ¶ added in v0.3.0
func NewNameChangedEvent(name string, clock int64) MembershipUpdateEvent
type MembershipUpdateMessage ¶ added in v0.3.0
type MembershipUpdateMessage struct {
ChatID string `json:"chatId"` // UUID concatenated with hex-encoded public key of the creator for the chat
Updates []MembershipUpdate `json:"updates"`
Message *Message `json:"message"` // optional message
}
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.
type Message ¶
type Message struct {
Text string `json:"text"` // TODO: why is this duplicated?
ContentT string `json:"content_type"`
MessageT string `json:"message_type"`
Clock int64 `json:"clock"` // lamport timestamp; see CalcMessageClock for more details
Timestamp TimestampInMs `json:"timestamp"`
Content Content `json:"content"`
Flags Flags `json:"-"`
ID []byte `json:"-"`
SigPubKey *ecdsa.PublicKey `json:"-"`
ChatID string `json:"-"` // reference to Chat.ID; not connected to Content.ChatID which is set by sender
}
Message is a chat message sent by an user.
func CreatePrivateGroupTextMessage ¶ added in v0.3.0
CreatePrivateGroupTextMessage creates a group message.
func CreatePrivateTextMessage ¶
CreatePrivateTextMessage creates a one-to-one message.
func CreatePublicTextMessage ¶
CreatePublicTextMessage creates a public text Message.
func (*Message) MarshalJSON ¶
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 *whispertypes.Message
// ParsedMessage is the parsed message by the application layer, i.e the output
ParsedMessage interface{}
// TransportPayload is the payload as received from the transport layer
TransportPayload []byte
// DecryptedPayload is the payload after having been processed by the encryption layer
DecryptedPayload []byte
// ID is the canonical ID of the message
ID statusproto.HexBytes
// Hash is the transport layer hash
Hash []byte
// TransportLayerSigPubKey contains the public key provided by the transport layer
TransportLayerSigPubKey *ecdsa.PublicKey
// ApplicationMetadataLayerPubKey contains the public key provided by the application metadata layer
ApplicationMetadataLayerSigPubKey *ecdsa.PublicKey
}
StatusMessage is any Status Protocol message.
func (*StatusMessage) Clone ¶
func (s *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 *whispertypes.Message) error
func (*StatusMessage) SigPubKey ¶
func (s *StatusMessage) SigPubKey() *ecdsa.PublicKey
SigPubKey returns the most important signature, from the application layer to transport
type StatusProtocolMessage ¶
type StatusProtocolMessage struct {
Signature []byte `protobuf:"bytes,4001,opt,name=signature,proto3" json:"signature,omitempty"`
Payload []byte `protobuf:"bytes,4002,opt,name=payload,proto3" json:"payload,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (*StatusProtocolMessage) Descriptor ¶
func (*StatusProtocolMessage) Descriptor() ([]byte, []int)
func (*StatusProtocolMessage) GetPayload ¶
func (m *StatusProtocolMessage) GetPayload() []byte
func (*StatusProtocolMessage) GetSignature ¶
func (m *StatusProtocolMessage) GetSignature() []byte
func (*StatusProtocolMessage) ProtoMessage ¶
func (*StatusProtocolMessage) ProtoMessage()
func (*StatusProtocolMessage) Reset ¶
func (m *StatusProtocolMessage) Reset()
func (*StatusProtocolMessage) String ¶
func (m *StatusProtocolMessage) String() string
func (*StatusProtocolMessage) XXX_DiscardUnknown ¶
func (m *StatusProtocolMessage) XXX_DiscardUnknown()
func (*StatusProtocolMessage) XXX_Marshal ¶
func (m *StatusProtocolMessage) XXX_Marshal(b []byte, deterministic bool) ([]byte, error)
func (*StatusProtocolMessage) XXX_Merge ¶
func (m *StatusProtocolMessage) XXX_Merge(src proto.Message)
func (*StatusProtocolMessage) XXX_Size ¶
func (m *StatusProtocolMessage) XXX_Size() int
func (*StatusProtocolMessage) XXX_Unmarshal ¶
func (m *StatusProtocolMessage) XXX_Unmarshal(b []byte) error
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.