Development on this repository will not continue; further development can be found on (in-progress) github.com/iotaledger/MAM
This is the official Javascript library for MAM(Masked Authenticated Messaging).
It is possible to publish transactions to the Tangle that contain only messages, with no value. This introduces many possibilities for data integrity and communication, but comes with the caveat that message-only signatures are not checked. What we introduce is a method of symmetric-key encrypted, signed data that takes advantage of merkle-tree winternitz signatures for extended public key usability, that can be found trivially by those who know to look for it.
For more details, take a look at the Overview.
It should be noted that the Javascript MAM Client is an early beta release. There is no assurance that unexpected issues will not occur. Please join the community and post issues on here.
Join the Discussion
If you want to get involved in the community, need help with getting setup, have any issues related with the library or just want to discuss Blockchain, Distributed Ledgers and IoT with other people, feel free to join our Slack. You can also ask questions on our dedicated forum at: IOTA Forum.
Use npm to install:
npm install mam.client.js
const seed = 'XXMPUFDZTAWNORLGZT9SZXHXXMSINBQVPCJITKOGIIPPUCARZEATSCUBMRXXQTXYRUTXUCBEV9YUMIFJB';
const start = 3;
const count = 4;
const security = 2;
const tree0 = new MerkleTree(seed, start, count, security);
const tree1 = new MerkleTree(seed, start + count, count, security);const mam = MAM.create({
message: 'WCTC9D9DCDFAEADBNA',
merkleTree: tree0,
index: index,
nextRoot: tree1.root.hash.toString(),
channelKey: 'EJTKEICAUGQFUHZNTYMVUDJLFYQAMYUZOJSCDBTXE9CMZGYUVFIHGDVHCLHJCEGDZGXJKJZKQADZBSFEL'
});
// Prints an array of trytes
console.log(mam);Use MAM.parse to get a parsed object of a MAM containing the root, signingKey, nextRoot & message
const parsed = MAM.parse({key: channelKey, message: message, tag: tag});
// Prints an object of the parsed MAM
console.log(parsed);Creates the trytes of a Masked Authenticated Message for the given options.
MAM.create(options)options: Object
message:StringTryte-encoded plain textmerkleTree:ObjectMerkle treeindex:IntIndex of the merkle tree leaf keynextRoot:StringRoot of the next merkle treechannelKey:StringChannel key
Object
trytes:Arrayan array of trytesnextKey:StringTryte-encoded key for the following message
Parses a Masked Authenticated Message.
MAM.parse(options)options:Object
key:StringChannel keymessage:ArrayArray of trytestag:StringTryte-encoded tag field of the transaction (which contains the encryption nonce)
Object
root:StringRoot of the merkle treenextRoot:StringRoot of the next merkle treenextKey:StringTryte-encoded key for the next message in this chainmessage:StringTryte-encoded message
Creates a channelKey for a given seed and nonce.
MAM.channelKey(key, nonce)key:String81-trytes current channel keynonce:StringRandom 27-tryte string
String Returns the next channel key.
Returns the message ID for a given channelKey and keyIndex
MAM.messageID(channelKey, keyIndex)channelKey:StringChannel KeykeyIndex:IntKey index
String Returns the message ID.
Creates the hash of a tryte-encoded message
MAM.messageHash(message)message:StringTryte-encoded message
String Returns the message hash
Creates the signature fragment.
MAM.sign(message, key, bundle)message:StringTryte-encoded messagekey:StringSigning keybundle:ObjectOptional bundle object
Array Returns an array of trytes
Creates a Merkle Tree instance.
MerkleTree(seed, start, count, security)seed:String81-trytes seedstart:Intcount:IntTree sizesecurity:IntSecurity level. Can be 1, 2 or 3
MerkleTree.rootString Merkle tree root
MerkleTree.get(index)index:Int
Object
tree:Arraykey:String
Encrypts a tryte-encoded plaintext.
Encryption.encrypt(message, key)message:StringTryte-encoded plaintextkey:StringEncryption key
String Returns the tryte-encoded ciphertext
Decrypts a tryte-encoded ciphertext.
Encryption.decrypt(message, key)message:StringTryte-encoded plaintextkey:StringEncryption key
String Returns the tryte-encoded plaintext
Increments the given subseed
Encryption.increment(subseed, count)subseed:String81-trytes subseedcount:IntOptional count
String Returns the incremented subseed
Creates the hash of the given key.
Encryption.hash(key, curl)key:StringKeycurl:ObjectOptional Curl object
String Returns the hash of the given key