msg

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 11, 2024 License: GPL-3.0 Imports: 18 Imported by: 7

Documentation

Index

Constants

View Source
const (

	// Messages which are older than a day should be ignored
	MESSAGE_TTL = ma.MESSAGE_DEFAULT_TTL
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Envelope added in v0.1.0

type Envelope struct {
	EphemeralKey     []byte
	EncryptedContent []byte
	EncryptedHeaders []byte
}

Bask the encrypted message and the encrypted symmetric key in a CBOR envelope.

func UnmarshalAndVerifyEnvelopeFromCBOR added in v0.4.1

func UnmarshalAndVerifyEnvelopeFromCBOR(data []byte) (*Envelope, error)

func UnmarshalEnvelopeFromCBOR added in v0.2.1

func UnmarshalEnvelopeFromCBOR(data []byte) (*Envelope, error)

Takes the envelope as a byte array and returns a pointer to an Envelope struct Basically this is what you do with a receieved message envelope, eg. in an Open() function.

func (*Envelope) IsValid added in v0.4.1

func (e *Envelope) IsValid() bool

func (*Envelope) Open added in v0.2.1

func (e *Envelope) Open(privateKey []byte) (*Message, error)

func (*Envelope) Verify added in v0.4.1

func (e *Envelope) Verify() error

type Headers added in v0.1.0

type Headers struct {
	// Version of the message format
	Version string
	// Unique identifier of the message
	ID string `cbor:"id"`
	// MIME type of the message
	MimeType string `cbor:"mimeType"`
	// Creation time of the message in seconds since Unix epoch
	Created int64 `cbor:"keyasint64"`
	// Expiration time of the message in seconds since Unix epoch
	Expires int64 `cbor:"keyasint64"`
	// Sender of the message
	From string `cbor:"from"`
	// Recipient of the message
	To string `cbor:"to"`
	// MIME type of the message body
	ContentType string `cbor:"contentType"`
	// Hexadecimal string representation of the SHA-256 hash of the message body
	Signature []byte `cbor:"signature"`
}

This struct mimicks the Headers format, but it's *not* Headers. It should enable using Headers later, if that's a good idea. NB! Content is *not* a part of the headers

func (*Headers) CreatedTime added in v0.1.0

func (h *Headers) CreatedTime() time.Time

func (*Headers) ExpiresTime added in v0.1.0

func (h *Headers) ExpiresTime() time.Time

func (*Headers) Recipient added in v0.1.0

func (h *Headers) Recipient() (*did.DID, error)

func (*Headers) SemVersion added in v0.1.0

func (h *Headers) SemVersion() (semver.Version, error)

func (*Headers) Sender added in v0.1.0

func (h *Headers) Sender() (*did.DID, error)

type Message

type Message struct {
	// Version of the message format
	Version string `cbor:"version"`
	// Unique identifier of the message
	ID string `cbor:"id"`
	// MIME type of the message
	MimeType string `cbor:"mimeType"`
	// Sender of the message
	From string `cbor:"from"`
	// Recipient of the message
	To string `cbor:"to"`
	// MIME type of the message body
	ContentType string `cbor:"contentType"`
	// Hexadecimal string representation of the SHA-256 hash of the message body
	Content []byte `cbor:"content"`
	// Signature of the message headers. NB! This includes the ContentHash field,
	// which can be used to verify the integrity of the message body.
	Signature []byte `cbor:"signature"`
}

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,
	content []byte,
	contentType string,
	priv_key *ed25519.PrivateKey) (*Message, error)

New creates a new Message instance

func NewBroadcast added in v0.4.0

func NewBroadcast(
	from string,
	to string,
	content []byte,
	contentType string,
	priv_key *ed25519.PrivateKey) (*Message, error)

func UnmarshalAndVerifyMessageFromCBOR added in v0.4.1

func UnmarshalAndVerifyMessageFromCBOR(b []byte) (*Message, error)

func UnmarshalMessageFromCBOR added in v0.4.1

func UnmarshalMessageFromCBOR(b []byte) (*Message, error)

UnmarshalMessageFromCBOR unmarshals a Message from a CBOR byte slice and verifies the signature

func (*Message) Broadcast added in v0.4.0

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

Send message to a pubsub topic

func (*Message) Headers added in v0.1.0

func (m *Message) Headers() *Headers

Returns the all the imprimatur headers

func (*Message) Send added in v0.0.3

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

EncloseAndSend message to a pubsub topic EncloseAndSend differs from Send in that it encrypts the message and encloses it in an envelope before sending it.

func (*Message) Sign

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

func (*Message) Verify

func (m *Message) Verify() error

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

Jump to

Keyboard shortcuts

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