@decentralized-auth/iota-mam
v1.0.6
Published
Wrapper for the IOTA MAM client that provides convenience methods.
Downloads
5
Readme
@decentralized-auth/iota
Wrapper class for the IOTA client that provides some convenience methods for use in the decentralized-auth project.
Usage
const generateSeed = require('@decentralized-auth/gen-seed');
const IotaClient = require('@decentralized-auth/iota');
const MamClient = require('@decentralized-auth/iota-mam');
// Instantiate a logger that has an info and error method
const consoleLogger = new (function () {
this.info = console.log;
this.error = console.log;
})();
const iota = new IotaClient({
provider: 'http://node01.testnet.iotatoken.nl:16265',
securityLevel: 2,
depth: 5,
minWeightMagnitude: 10,
}, consoleLogger);
const seed = await generateSeed();
const mode = 'restricted';
const sideKey = 'BANANA';
const mam = new MamClient(seed, iotaClient, mode, sideKey);
const message = 'HELLO';
const root = await mam.attach(message);
const res = await mam.fetch(root, 'restricted', sideKey);
console.log(res.messages[0]) // => 'HELLO'
Test
npm run test
Lint
npm run lint
Documentation
Documentation generated from docstrings with jsdoc2md.
iota-mam
Wrapper for the IOTA MAM client that provides some convenience methods.
- iota-mam
- ~MamClient
~init(iota, seed, mode, sideKey)
⇒ Object~changeSideKey(sideKey)
⇒ undefined~attach(packet)
⇒ Promise~fetch(root, mode, sideKey)
⇒ Promise~fetch(root, mode, sideKey)
⇒ Promise
iota-mam~MamClient
Kind: inner class of iota-mam
new MamClient(seed, iotaClient, mamMode, sideKey)
Constructor for a MamClient.
| Param | Type | Description | | --- | --- | --- | | seed | string | IOTA seed of the device client | | iotaClient | object | Instantiated @decentralized-auth/iota-client with logger | | mamMode | string | MAM mode, either 'public' or 'private' or 'restricted' | | sideKey | string | Optional side key (when mode is 'restricted') |
iota-mam~init(iota, seed, mode, sideKey)
⇒ Object
Initialize MAM (mode private or mode restricted if sideKey is provided).
Kind: inner method of iota-mam
Returns: Object - MAM state
| Param | Type | Description | | --- | --- | --- | | iota | Object | Instance of iota.lib.js | | seed | string | Seed to initialize MAM with | | mode | string | Mode to initialize MAM with ('public', 'private' or restricted') | | sideKey | string | Optional side key to initialize MAM with (restricted) |
iota-mam~changeSideKey(sideKey)
⇒ undefined
Sets or changes the MAM side key.
Kind: inner method of iota-mam
| Param | Type | Description | | --- | --- | --- | | sideKey | string | Side key |
iota-mam~attach(packet)
⇒ Promise
Attach MAM messages.
Kind: inner method of iota-mam
Returns: Promise - Containing the root
| Param | Type | Description | | --- | --- | --- | | packet | JSON | JSON packet to attach. |
iota-mam~fetch(root, mode, sideKey)
⇒ Promise
Fetch MAM messages. NOTE: Expects JSON messages only.
Kind: inner method of iota-mam
Returns: Promise - Contains the root and the messages
| Param | Type | Description | | --- | --- | --- | | root | string | Root from where to fetch | | mode | string | Either 'public', 'private' or 'restricted' | | sideKey | string | Optional side key |
iota-mam~fetch(root, mode, sideKey)
⇒ Promise
Fetch a single MAM message. NOTE: Expects JSON MAM message only.
Kind: inner method of iota-mam
Returns: Promise - Contains the root and the parsed message or null
| Param | Type | Description | | --- | --- | --- | | root | string | Root from where to fetch | | mode | string | Either 'public' or 'private' or 'restricted' | | sideKey | string | Optional side key (when mode is 'restricted') |