1.0.6 • Published 6 years ago

@decentralized-auth/iota-mam v1.0.6

Weekly downloads
2
License
Apache-2.0
Repository
-
Last release
6 years ago

@decentralized-auth/iota

GitHub license

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

Kind: inner class of iota-mam


new MamClient(seed, iotaClient, mamMode, sideKey)

Constructor for a MamClient.

ParamTypeDescription
seedstringIOTA seed of the device client
iotaClientobjectInstantiated @decentralized-auth/iota-client with logger
mamModestringMAM mode, either 'public' or 'private' or 'restricted'
sideKeystringOptional 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

ParamTypeDescription
iotaObjectInstance of iota.lib.js
seedstringSeed to initialize MAM with
modestringMode to initialize MAM with ('public', 'private' or restricted')
sideKeystringOptional 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

ParamTypeDescription
sideKeystringSide key

iota-mam~attach(packet)Promise

Attach MAM messages.

Kind: inner method of iota-mam
Returns: Promise - Containing the root

ParamTypeDescription
packetJSONJSON 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

ParamTypeDescription
rootstringRoot from where to fetch
modestringEither 'public', 'private' or 'restricted'
sideKeystringOptional 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

ParamTypeDescription
rootstringRoot from where to fetch
modestringEither 'public' or 'private' or 'restricted'
sideKeystringOptional side key (when mode is 'restricted')

1.0.6

6 years ago

1.0.5

6 years ago

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago