mam

package
v1.0.0-beta.11....-851daf4 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2020 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package mam provides functions for creating Masked Authentication Messaging messages

Package mam provides functions for creating Masked Authentication Messaging messages

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrPayloadTooShort        = errors.New("payload too short")
	ErrMerkleRootDoesNotMatch = errors.New("Merkle root does not match")
	ErrWrongSecurityLevel     = errors.New("wrong security level")
)
View Source
var (
	ErrUnknownChannelMode = errors.New("Channel mode must be ChannelModePublic, ChannelModePrivate or ChannelModeRestricted")
	ErrNoSideKey          = errors.New("A 81-trytes sideKey must be provided for the restricted mode")
)

Some error definitions.

View Source
var (
	ErrCouldNotParseChannelMode = errors.New("could not parse Channel mode")
)

Error definitions

Functions

func MAMCreate

func MAMCreate(payloadLength uint64,
	message Trytes, sideKey Trytes,
	merkleTree Trits, merkleTreeLength uint64,
	leafCount uint64, index uint64,
	nextRoot Trits, start uint64,
	seed Trytes, security SecurityLevel) (Trits, uint64, error)

MAMCreate creates a signed, encrypted payload from a message.

payloadLength is the length of the payload
message is the message to encrypt
sideKey is the encryption key
merkleTree is the Merkle tree
merkleTreeLength is the length of the Merkle tree
leafCount is the number of leaves of the Merkle tree
index is the leaf index
nextRoot is the Merkle root of the next MAM payload
start is the offset used to generate addresses
seed is the seed used to generate addresses - Not sent over the network
security is the security level used to generate addresses

Returns:

 payload is the payload of the encrypted message
 payloadMinLength is the length of the payload needed to encrypt the message
	err is the error message

func MAMInitEncryption

func MAMInitEncryption(sideKey Trits, merkleRoot Trits, spongeFunc sponge.SpongeFunction)

MAMInitEncryption initializes the encryption/decryption state for a MAM session.

sideKey is the encryption/decryption key
merkleRoot is the Merkle root
spongeFunc is the spongeFunction instance used for encryption/decryption

func MAMParse

func MAMParse(payload Trits, payloadLength uint64, sideKey Trytes, root Trits) (uint64, Trytes, Trytes, SecurityLevel, error)

MAMParse decrypts, parses and validates an encrypted payload.

payload is the payload
payloadLength is the length of the payload
sideKey is the decryption key
root is the Merkle root

Returns:

 parsedIndex is the parsed index of the message
 parsedNextRoot is the Merkle root of the next MAM payload
	parsedMessage is the decrypted message
	parsedSecurity is the parsed security level of the message
	err is the error message

func Mask

func Mask(dest Trits, message Trits, length uint64, c *curl.Curl)

Masks a given message with a curl instance state.

dest is the destination of the masked message
message is the message to be masked
length is the length of the message
c is the curl instance used to mask the message

func PayloadMinLength

func PayloadMinLength(messageLength, merkleTreeLength, index uint64, security SecurityLevel) uint64

PayloadMinLength computes the minimum length of a payload.

messageLength is the length of the message
merkleTreeLength is the length of the Merkle tree
index is the leaf index
security is the security level used to generate addresses

Returns the minimum length of the payload

func Unmask

func Unmask(cipher Trits, length uint64, c *curl.Curl) (dest Trits)

Unmasks a given cipher with a curl instance state.

cipher is the cipher to be unmasked
length is the length of the cipher
c is the curl instance used to unmask the cipher
returns the unmasked cipher

Types

type API

type API interface {
	PrepareTransfers(seed trinary.Trytes, transfers bundle.Transfers, opts api.PrepareTransfersOptions) ([]trinary.Trytes, error)
	SendTrytes(trytes []trinary.Trytes, depth uint64, mwm uint64, reference ...trinary.Hash) (bundle.Bundle, error)
	FindTransactionObjects(query api.FindTransactionsQuery) (transaction.Transactions, error)
}

API defines an interface with a subset of methods of `api.API`.

type Channel

type Channel struct {
	Mode          ChannelMode          `json:"mode"`
	SideKey       trinary.Trytes       `json:"side_key"`
	NextRoot      trinary.Trits        `json:"next_root"`
	SecurityLevel consts.SecurityLevel `json:"security_level"`
	Start         uint64               `json:"start"`
	Count         uint64               `json:"count"`
	NextCount     uint64               `json:"next_count"`
	Index         uint64               `json:"index"`
}

func NewChannel

func NewChannel(securityLevel consts.SecurityLevel) *Channel

type ChannelMode

type ChannelMode string

ChannelMode is an enum of Channel modes.

const (
	ChannelModePublic     ChannelMode = "public"
	ChannelModePrivate    ChannelMode = "private"
	ChannelModeRestricted ChannelMode = "restricted"
)

Definition of possible Channel modes.

func ParseChannelMode

func ParseChannelMode(input string) (ChannelMode, error)

ParseChannelMode parses a Channel mode from the given string.

type Receiver

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

Receiver implements a receiver for MAM-Messages.

func NewReceiver

func NewReceiver(api API) *Receiver

NewReceiver returns a new receiver.

func (*Receiver) Mode

func (r *Receiver) Mode() ChannelMode

Mode returns the Channel mode.

func (*Receiver) Receive

func (r *Receiver) Receive(root trinary.Trytes) (trinary.Trytes, []string, error)

Receive tries to receive all messages from the specified root and returns them along with the next root.

func (*Receiver) SetMode

func (r *Receiver) SetMode(m ChannelMode, sideKey trinary.Trytes) error

SetMode sets the Channel mode.

func (*Receiver) SideKey

func (r *Receiver) SideKey() trinary.Trytes

SideKey returns the Channel's side key.

type Transmitter

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

Transmitter defines the MAM facade transmitter.

func NewTransmitter

func NewTransmitter(api API, seed trinary.Trytes, mwm uint64, securityLevel consts.SecurityLevel) *Transmitter

NewTransmitter returns a new transmitter.

func NewTransmitterWithChannel

func NewTransmitterWithChannel(api API, seed trinary.Trytes, mwm uint64, channel *Channel) *Transmitter

NewTransmitterWithChannel returns a new transmitter with an existing channel.

func (*Transmitter) Channel

func (t *Transmitter) Channel() *Channel

SideKey returns the underlying Channel of this Transmitter.

func (*Transmitter) Mode

func (t *Transmitter) Mode() ChannelMode

Mode returns the Channel mode.

func (*Transmitter) SetMode

func (t *Transmitter) SetMode(m ChannelMode, sideKey trinary.Trytes) error

SetMode sets the Channel mode.

func (*Transmitter) SideKey

func (t *Transmitter) SideKey() trinary.Trytes

SideKey returns the Channel's side key.

func (*Transmitter) Transmit

func (t *Transmitter) Transmit(message string, params ...string) (trinary.Trytes, error)

Transmit creates a MAM message using the given string and transmits it. On success, it returns the addresses root.

Directories

Path Synopsis
Package merkle provides functions for creating and validating MAM compatible Merkle trees.
Package merkle provides functions for creating and validating MAM compatible Merkle trees.
Package signing provides implements the signing scheme used in MAM.
Package signing provides implements the signing scheme used in MAM.

Jump to

Keyboard shortcuts

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