Skip to content
This repository has been archived by the owner on Jun 7, 2023. It is now read-only.

Latest commit

 

History

History
245 lines (150 loc) · 6.18 KB

api.md

File metadata and controls

245 lines (150 loc) · 6.18 KB

@iota/mam.js

Table of contents

Functions

Interfaces

Type aliases

Classes

Functions

createChannel

createChannel(seed, security, mode, sideKey?): IMamChannelState

Create a new channel object.

Parameters

Name Type Description
seed string The seed for the channel.
security number The security level for the channel.
mode MamMode The mode for the channel.
sideKey? string The side key to use for restricted mode.

Returns

IMamChannelState

The new channel state.


channelRoot

channelRoot(channelState): string

Get the root of the channel.

Parameters

Name Type Description
channelState IMamChannelState The channel state to get the root.

Returns

string

The root.


createMessage

createMessage(channelState, message): IMamMessage

Prepare a message on the mam channel.

Parameters

Name Type Description
channelState IMamChannelState The channel to prepare the message for.
message string The trytes to include in the message.

Returns

IMamMessage

The prepared message, the channel state will also be updated.


mamAttach

mamAttach(client, mamMessage, tag?): Promise<{}>

Attach the mam message to the tangle.

Parameters

Name Type Description
client string | IClient The client or node endpoint to use for sending.
mamMessage IMamMessage The message to attach.
tag? string Optional tag for the transactions.

Returns

Promise<{}>

The transactions that were attached.


mamFetch

mamFetch(client, root, mode, sideKey?): Promise<IMamFetchedMessage | undefined>

Fetch a mam message from a channel.

Parameters

Name Type Description
client string | IClient The client or node endpoint to use for fetching.
root string The root within the mam channel to fetch the message.
mode MamMode The mode to use for fetching.
sideKey? string The sideKey if mode is restricted.

Returns

Promise<IMamFetchedMessage | undefined>

The decoded message and the nextRoot if successful, undefined if no messages found, throws exception if transactions found on address are invalid.


decodeAddress

decodeAddress(root, mode): string

Decodes the root to its associated address.

Parameters

Name Type Description
root string The root to device.
mode MamMode The mode for the channel.

Returns

string

The decoded address.


mamFetchAll

mamFetchAll(client, root, mode, sideKey?, limit?): Promise<IMamFetchedMessage[]>

Fetch all the mam message from a channel. If limit is undefined we use Number.MAX_VALUE, this could potentially take a long time to complete. It is preferable to specify the limit so you read the data in chunks, then if you read and get the same amount of messages as your limit you should probably read again.

Parameters

Name Type Description
client string | IClient The client or node endpoint to use for fetching.
root string The root within the mam channel to fetch the message.
mode MamMode The mode to use for fetching.
sideKey? string The sideKey if mode is restricted.
limit? number Limit the number of messages retrieved.

Returns

Promise<IMamFetchedMessage[]>

The array of retrieved messages.


decodeMessages

decodeMessages(messages, root, sideKey?): Promise<IMamFetchedMessage | undefined>

Decode messages from an address to try and find a MAM message.

Parameters

Name Type Description
messages IMessage[] The objects returned from the fetch.
root string The root within the mam channel to fetch the message.
sideKey? string The sideKey if mode is restricted.

Returns

Promise<IMamFetchedMessage | undefined>

The decoded message and the nextRoot if successful, undefined if no messages found, throws exception if transactions found on address are invalid.


parseMessage

parseMessage(payload, root, channelKey?): Object

Parse the trytes back to the original message.

Parameters

Name Type Description
payload string The trytes to decode.
root string The root for the message.
channelKey? string The key used to encode the data.

Returns

Object

The decoded message.

Name Type Description
nextRoot string The next root.
message string The decoded message.

Type aliases

MamMode

Ƭ MamMode: "public" | "private" | "restricted"

The modes for MAM.