Skip to content

Instantly share code, notes, and snippets.

@transducer
Created June 4, 2018 16:48
Show Gist options
  • Save transducer/29ddd0cf73df1c393e3f766015000977 to your computer and use it in GitHub Desktop.
Save transducer/29ddd0cf73df1c393e3f766015000977 to your computer and use it in GitHub Desktop.
Send encrypted MAM_DATA to a service provider.
/**
* Send encrypted MAM data to a service provider.
*
* @function sendMamData
* @param {string} seed IOTA seed of sender
* @param {string} address IOTA address of the service provider
* @param {string} publicKey Public key of the service provider in trytes
* @returns {Promise} containing IOTA transactions
*/
async sendMamData(seed, address, publicKey) {
const { channel: { side_key, next_root } } = this.mam.getMamState();
const mamData = {
root: ntru.encrypt(next_root, publicKey),
sideKey: ntru.encrypt(side_key, publicKey),
};
logger.info(`Provide service provider ${address} with MAM data ${JSON.stringify(mamData)}`);
const message = { type: MAM_DATA_TYPE, root: this.root, mamData };
return iota.send(seed, address, message);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment