msg

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2023 License: GPL-3.0 Imports: 23 Imported by: 7

Documentation

Index

Constants

View Source
const (

	// Messages which are older than a day should be ignored
	MESSAGE_TTL = time.Hour * 24

	// How we identify the messages we support
	MESSAGE_ENCRYPTION_LABEL = mime.MESSAGE_MIME_TYPE
)
View Source
const (
	// This is the packed message. You can generate it using cmd/pack_valid_message.go
	Message_test_packed_valid_message = "" /* 359-byte string literal not displayed */
)

It's really meant for testing, but we might want to use it in other places too.

Variables

This section is empty.

Functions

func IsValidPack added in v0.0.3

func IsValidPack(data string) bool

Types

type Message

type Message struct {
	ID           string `cbor:"id" json:"id"`
	MimeType     string `cbor:"type" json:"type"`
	From         string `cbor:"from" json:"from"`
	To           string `cbor:"to" json:"to"`
	Created      int64  `cbor:"created_time,keyasint64" json:"created_time"`
	Expires      int64  `cbor:"expires_time,keyasint64" json:"expires_time"`
	BodyMimeType string `cbor:"body_mime_type" json:"body_mime_type"`
	Body         []byte `cbor:"body" json:"body"`
	Version      string `cbor:"versionId" json:"versionId"`
	Signature    string `cbor:"signature" json:"signature"`
	// contains filtered or unexported fields
}

This struct mimicks the Message format, but it's *not* Message. It should enable using Message later, if that's a good idea.

func New

func New(
	from string,
	to string,
	body []byte,
	mime_type string) (*Message, error)

New creates a new Message instance Message is a string for now, but it should be JSON.

func OpenEnvelope added in v0.0.3

func OpenEnvelope(e *envelope.Envelope, privKey []byte) (*Message, error)

Takes an envelope an an x25519 privkey byte[] and returns a decrypted message

func Parse

func Parse(data string) (*Message, error)

Parses a received message in form of a multibase encoded JSON string

func Signed

func Signed(
	from string,
	to string,
	body []byte,
	mime_type string,
	priv_key *ed25519.PrivateKey) (*Message, error)

func UnmarshalFromCBOR added in v0.0.3

func UnmarshalFromCBOR(data []byte) (*Message, error)

func Unpack

func Unpack(data string) (*Message, error)

func ValidExampleMessage

func ValidExampleMessage() *Message

func (*Message) Bytes added in v0.0.3

func (m *Message) Bytes() []byte

Returns a copy of the Message payload as a byte slice No error messages, just nil Try with IsValidPack() first, if you need to make sure.

func (*Message) CreatedTime

func (m *Message) CreatedTime() (time.Time, error)

func (*Message) Enclose added in v0.0.3

func (m *Message) Enclose() (*envelope.Envelope, error)

func (*Message) ExpiresTime

func (m *Message) ExpiresTime() (time.Time, error)

func (*Message) IsValid

func (m *Message) IsValid() bool

func (*Message) MarshalToCBOR

func (m *Message) MarshalToCBOR() ([]byte, error)

func (*Message) MarshalToJSON

func (m *Message) MarshalToJSON() ([]byte, error)

func (*Message) MarshalUnsignedToCBOR added in v0.0.3

func (m *Message) MarshalUnsignedToCBOR() ([]byte, error)

func (*Message) MultibaseEncodedPayloadHash added in v0.0.3

func (m *Message) MultibaseEncodedPayloadHash() string

Returns the multibase-encoded hash of the Message payload Or empty string if an error occurs This is mostly intended for debugging purposes

func (*Message) Pack

func (m *Message) Pack() (string, error)

func (*Message) Recipient

func (m *Message) Recipient() (*did.DID, error)

func (*Message) SemVersion

func (m *Message) SemVersion() (semver.Version, error)

func (*Message) Send added in v0.0.3

func (m *Message) Send(ctx context.Context, t *pubsub.Topic) error

Send message to a pubsub topic We could have done p2p here, but it's much cleaner to take a topic as an argument. The topic is just a medium for sending messages, not actually the recipient necessarily.

func (*Message) Sender

func (m *Message) Sender() (*did.DID, error)

func (*Message) Sign

func (m *Message) Sign(privKey *ed25519.PrivateKey) error

func (*Message) SignatureBytes added in v0.0.3

func (m *Message) SignatureBytes() []byte

SignatureBytes returns the signature bytes It doesn't return an error, but logs it instead

func (*Message) Unsigned added in v0.0.3

func (m *Message) Unsigned() (Message, error)

Returns a copy of the Message payload This is just meant to be used for signatures.

func (*Message) Validate added in v0.0.3

func (m *Message) Validate() error

Validate checks if a Message instance is valid

func (*Message) VerifyActors

func (m *Message) VerifyActors() error

func (*Message) VerifyID

func (m *Message) VerifyID() error

Check that ID is valid

func (*Message) VerifyMessageVersion

func (m *Message) VerifyMessageVersion() error

Compare messageVersion. Return nil if ok else an error

func (*Message) VerifySignature added in v0.0.3

func (m *Message) VerifySignature() error

VerifySignature verifies the Message's signature Returns nil if the signature is valid

func (*Message) VerifyTimestamps

func (m *Message) VerifyTimestamps() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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