0.5.1 • Published 6 years ago

mam.tools.js v0.5.1

Weekly downloads
1
License
ISC
Repository
github
Last release
6 years ago

npm

MAM Tools

A library containing tools to make the use of IOTAs Masked Authenticated Messaging more easy.

Included is a lib for node.js, a js module for mocking a MAM client so that no real IOTA node is needed for the testing of MAM apps and a CLI.

CLI

You can use all functions of the MAM library with a simple CLI. The releases contain binaries for different platforms with that you can use MAM standalone from the command line:

$ mamCli-linux-x86 <command> [options]

It's also possible to run the cli directly with node/npm:

$ npm install
$ npm run cli <command> -- [options]

Note the extra '--' needed before the options.

Setting Node

The option --provider must be set in all commands. It should be set to the URL of an IOTA full node supporting POW.

Commands:

readChannel

Reads the content of a given MAM channel and printing information such as the channelRoot.

ParamTypeDefaultDescription
channelRootstringThe root of the MAM channel. This is shared with others to read messages of a channel.
seedstringThe seed of the MAM channel. It's need to publish new messages to a MAM channel.
modestring'public'The mode of the MAM channel. Allowed are 'public', 'private' and 'restricted'
sideKeystringnullThe sideKey needed for MAM channels in restricted mode. This is needed to read messages from this channel and to publish new ones.

Only channelRoot or seed are needed for reading a channel. The CLI will look for the channelRoot first and then for a seed. If both aren't given a random seed is generated.

Example

$ mamCli-linux-x86 readChannel --seed=THISISTHESEEDOFTHETICACCOUNTANDISHOULDNOTGIVEITTOANYBODYELSE --provider=https://your.favorite.node

publish

Publishes a new message to a specified channel.

ParamTypeDefaultDescription
seedstringThe seed of the MAM channel.
modestring'public'The mode of the MAM channel. Allowed are 'public', 'private' and 'restricted'
sideKeystringnullThe sideKey needed for MAM channels in restricted mode.
toTrytesbooleantrueWhether to convert the given text to trytes.
contentstringThe message to publish. Remember to wrap the content in '' if it contains spaces.
readMessagesbooleanfalseWhether to read the channel's content after publishing

Example

$ mamCli-linux-x86 publish --seed=THISISTHESEEDOFTHETICACCOUNTANDISHOULDNOTGIVEITTOANYBODYELSE --provider=https://your.favorite.node
    -content='Hello World' --readMessages

API Reference

A MAM lib for node.js

Example

const mam = require('mam.tools.js')

mam.changeMode ⇒ Promise.<ChangeModeState>

Changes the mode of a given mam state object. The state is initialized in a way, that the next message will be attached to the next root of the channel even if messages are already existent in the channel.

Kind: static property of mamClient
Returns: Promise.<ChangeModeState> - a Promise awaiting an object containing the mam state with changed mode and the channel root address of the channel in the new mode.

ParamTypeDefaultDescription
mamObjectThe mam state object whose mode should be changed.
modestringthe mode of the MAM channel to read/write. 'public', 'restricted' and 'private' are valid.
sideKeystringnullthe side key when using a restricted channel.

mam.getRoot ⇒ string

Kind: static property of mamClient
Returns: string - the root address of the channels next message.

ParamTypeDescription
mamObjectthe MAM state.

mam.getMessages ⇒ Promise.<MessageResponse>

Retrieves all messages starting from the given channel root using given mode and sideKey.

Kind: static property of mamClient
Returns: Promise.<MessageResponse> - a Promise awaiting an Object containing the messages retrieved from the MAM channel and the next channel root.

ParamTypeDefaultDescription
channelRootstringthe root address of the first message in the channel that should be retrieved.
modestring"'public'"the mode of the retrieved channel.
sideKeystringnullthe sideKey of retrieved restricted channel.

mam.setProvider(url)

Sets the node to use for all requests to the tangle. The given node must support pow.

Kind: static method of mamClient

ParamTypeDescription
urlstringthe url of the node to use.

mam.getIota(url) ⇒ IotaClass

Creates an Object to handle requests to the tangle. An optional url to a node can be given, by default the url set by setProvider is used.

Kind: static method of mamClient
Returns: IotaClass - the newly created iota object.

ParamTypeDefaultDescription
urlstring"provider"the url of the node to use. Default is the url set by setProvider.

mam.createMamFrom(params) ⇒ Promise.<MAMClient>

Initializes a module:types.MAMClient from given parameters. The default uses a randomly generated seed with a iota using the node set by setProvider to access a public MAM channel. The state is initialized in a way, that the next message will be attached to the next root of the channel even if messages are already existent in the channel.

Kind: static method of mamClient
Returns: Promise.<MAMClient> - a Promise awaiting an object containing the MAM state object, the iota client and the root address of the channel.

ParamTypeDefaultDescription
paramsObjectan Object containing seed, iota client, MAM channel mode, and a sideKey if mode is 'restricted'.
params.seedstring"generateSeed()"The seed for the MAM channels.
params.iotaIotaClassgetIota()The iota client for communication with a full node.
params.modestring"'public'"the mode of the MAM channel to read/write. 'public', 'restricted' and 'private' are valid.
params.sideKeystringnullthe side key when using a restricted channel.

mam.createMam(seed, iota, mode, sideKey) ⇒ Promise.<MAMClient>

Initializes a module:types.MAMClient from given parameters. The default uses a randomly generated seed with a iota using the node set by setProvider to access a public MAM channel. The state is initialized in a way, that the next message will be attached to the next root of the channel even if messages are already existent in the channel.

Kind: static method of mamClient
Returns: Promise.<MAMClient> - a Promise awaiting an object containing the MAM state object, the iota client and the root address of the channel.

ParamTypeDefaultDescription
seedstring"generateSeed()"The seed for the MAM channels.
iotaIotaClassgetIota()The iota client for communication with a full node.
modestring"'public'"the mode of the MAM channel to read/write. 'public', 'restricted' and 'private' are valid.
sideKeystringnullthe side key when using a restricted channel.

mam.getChannelMessages(channelRoot, mamState) ⇒ Promise.<MessageResponse>

Retrieves all messages starting from the given channel root using mode and sideKey given by the given mamState Object.

Kind: static method of mamClient
Returns: Promise.<MessageResponse> - a Promise awaiting an Object containing the messages retrieved from the MAM channel and the next channel root.

ParamTypeDescription
channelRootstringthe root address of the first message in the channel that should be retrieved.
mamStateObjectthe initialized MAM state object.

mam.generateSeed(length) ⇒ string

Kind: static method of mamClient
Returns: string - a randomly generated seed with the given length.

ParamTypeDefaultDescription
lengthstring81the wanted length of the generated seed.

mam.publish(text, mamState, iota, toTrytes) ⇒ Promise.<PublishResponse>

Publishes a given text to a MAM channel using the initialized MAM state Object.

Kind: static method of mamClient
Returns: Promise.<PublishResponse> - a Promise containing an Object conaining the root and the address of the published message and the updated MAM State Object.
Asnyc:

ParamTypeDefaultDescription
textstringthe text to publish to the tangle.
mamStateObjectthe MAM state Object.
iotaIotaClassthe initialized iota client.
toTrytesbooleantruewhether to convert the text to trytes.

Types

The types listed below are used by the mam tools.

types~MAMClient : Object

An object containing the MAM client, root of the MAM channel and the iota client.

Kind: inner typedef of types
Properties

NameTypeDescription
iotaIotaClassThe iota client.
mamObjectThe MAM state object used by the client lib for all requests regarding the set channel (by seed and mode).
channelRootstringthe root of the channels first message.

types~ChangeModeState : Object

An object containing the changed mamState an the root to the channels first message.

Kind: inner typedef of types
Properties

NameTypeDescription
mamObjectThe changed MAM state object used by the client lib for all requests regarding the set channel (by seed and mode).
channelRootstringthe root of the channels first message.

types~PublishResponse : Object

An Object conaining the root and the address of the published message and the given MAM State Object.

Kind: inner typedef of types
Properties

NameTypeDescription
rootstringthe root of the published message.
addressstringthe address of the published message.
mamStateObjectthe updated MAM state Object.

types~MessageResponse : Object

An Object containing the messages retrieved from the MAM channel and the next channel root.

Kind: inner typedef of types
Properties

NameTypeDescription
messagesArray.<string>The messages retrieved from the MAM channel.
nextRootstringthe root address of the next message in the mam channel.

© 2018 Robin Lamberti \lamberti.robin@gmail.com\. Documented by jsdoc-to-markdown.