Last active
May 12, 2018 18:28
-
-
Save manifest/381239b8a990f051f9397a58b59997f3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const MAM = require('./mam.node.js') | |
| const IOTA = require('iota.node.js') | |
| const iota = new IOTA({ provider: 'https://nodes.testnet.iota.org:443' }) | |
| // Init State | |
| let root = '' | |
| // Initialise MAM State | |
| let mamState = MAM.init(iota) | |
| // Publish to tangle | |
| const publish = async packet => { | |
| const trytes = iota.utils.toTrytes(JSON.stringify(packet)) | |
| const message = MAM.create(mamState, trytes) | |
| mamState = message.state | |
| await MAM.attach(message.payload, message.address) | |
| return message.root | |
| } | |
| // Callback used to pass data out of the fetch | |
| const logData = data => console.log(JSON.parse(iota.utils.fromTrytes(data))) | |
| const execute = async () => { | |
| // Publish and save root. | |
| root = await publish({foo: 'bar-1'}) | |
| // Publish but not save root | |
| await publish({foo: 'bar-2'}) | |
| // Callback used to pass data + returns next_root | |
| const resp = await MAM.fetch(root, 'public', null, logData) | |
| console.log(resp) | |
| } | |
| execute() | |
| // const fetch = async (root) => { | |
| // const resp = await MAM.fetch(root, 'public', null, logData) | |
| // console.log(resp) | |
| // } | |
| // fetch('QEZXKW9HOPYNUGPNLOBXKZJEI9UJTNTACFVFNLYLXVMWRIUBJUKYLJWMAKKOSOEF9TZTINAUQGOUHQWCA') |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://blog.iota.org/introducing-masked-authenticated-messaging-e55c1822d50e
https://medium.com/@abmushi/iota-mam-eloquently-explained-d7505863b413
https://github.com/l3wi/audit-mam