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
:String
Tryte-encoded plain textmerkleTree
:Object
Merkle treeindex
:Int
Index of the merkle tree leaf keynextRoot
:String
Root of the next merkle treechannelKey
:String
Channel key
Object
trytes
:Array
an array of trytesnextKey
:String
Tryte-encoded key for the following message
Parses a Masked Authenticated Message.
MAM.parse(options)
options
:Object
key
:String
Channel keymessage
:Array
Array of trytestag
:String
Tryte-encoded tag field of the transaction (which contains the encryption nonce)
Object
root
:String
Root of the merkle treenextRoot
:String
Root of the next merkle treenextKey
:String
Tryte-encoded key for the next message in this chainmessage
:String
Tryte-encoded message
Creates a channelKey
for a given seed
and nonce
.
MAM.channelKey(key, nonce)
key
:String
81-trytes current channel keynonce
:String
Random 27-tryte string
String
Returns the next channel key.
Returns the message ID for a given channelKey
and keyIndex
MAM.messageID(channelKey, keyIndex)
channelKey
:String
Channel KeykeyIndex
:Int
Key index
String
Returns the message ID.
Creates the hash of a tryte-encoded message
MAM.messageHash(message)
message
:String
Tryte-encoded message
String
Returns the message hash
Creates the signature fragment.
MAM.sign(message, key, bundle)
message
:String
Tryte-encoded messagekey
:String
Signing keybundle
:Object
Optional bundle object
Array
Returns an array of trytes
Creates a Merkle Tree instance.
MerkleTree(seed, start, count, security)
seed
:String
81-trytes seedstart
:Int
count
:Int
Tree sizesecurity
:Int
Security level. Can be 1, 2 or 3
MerkleTree.root
String
Merkle tree root
MerkleTree.get(index)
index
:Int
Object
tree
:Array
key
:String
Encrypts a tryte-encoded plaintext.
Encryption.encrypt(message, key)
message
:String
Tryte-encoded plaintextkey
:String
Encryption key
String
Returns the tryte-encoded ciphertext
Decrypts a tryte-encoded ciphertext.
Encryption.decrypt(message, key)
message
:String
Tryte-encoded plaintextkey
:String
Encryption key
String
Returns the tryte-encoded plaintext
Increments the given subseed
Encryption.increment(subseed, count)
subseed
:String
81-trytes subseedcount
:Int
Optional count
String
Returns the incremented subseed
Creates the hash of the given key
.
Encryption.hash(key, curl)
key
:String
Keycurl
:Object
Optional Curl object
String
Returns the hash of the given key