1.0.0-beta • Published 6 years ago

@bitbounti-oss/tangly v1.0.0-beta

Weekly downloads
-
License
ISC
Repository
github
Last release
6 years ago

Tangly: Identity library for the IOTA Tangle

Tangly (tangle + identity) interfaces with the IOTA Tangle; allowing for storing and retrieving data based on a seed. Instead of a user registering and sending sensitive data to a centralized data store, user data is encrypted based off of the user's seed that only the user knows and stored in the decentralized Tangle. The Tangle has the unique property of having free transactions which allows for data to be stored through Tangly one field at a time. Data is then retrieved and decrypted based off of a user's seed. No sensitive data needs to touch a centralized database, not even a username and password.

It is sometimes necessary to store meta data like user reputation and stats. Tangly allows you to add an "anchor" ID to the Tangle which can be stored in a centralized database. This anchor ID can be retrieved from the tangle to be used to send meta data to a database.

Quick Start

Installation

npm install --save tangly

Demo

npm run demo

Client-side usage

<--! example.html -->
<script src="./node_modules/iota.lib.js/dist/iota.js"></script>
<script src="./node_modules/crypto-js/crypto-js.js"></script>
<script src="./node_modules/tangly/dist/tangly.js"></script>
// example.js
const tangly = new window.tangly({
  seed: 'your_seed',
  node: 'https://testnet140.tangle.works'  // testnet node. Can use testnet or mainnet
})

tangly.find({}).then(data => data)

Server-side usage

// server.js
const Tangly = require('tangly');

const tangly = new Tangly({
  seed: 'your_seed',
  node: 'https://testnet140.tangle.works'  // testnet node. Can use any testnet or mainnet node
});

tangly.insert({ firstName: "Jane" })
  .then(data => data)

API

tangly.generateSeed()

Generate a random seed.

Input

tangly.generateSeed()
Example
const seed = tangly.generateSeed()

Return Value

  • String: Generated seed
Example
'VOOGDWRRNECRXZTAASVMYZPONDFBAURNFPLFHKIBKXYCIKPISAIXIGCWVNERD9OUEIBZUZCVCRSFFJHGY'

tangly.insert()

Insert an object into the Tangle by attaching a zero-value transaction.

Input

tangly.insert(data, options)
  • data (Object) required: Data you will be attaching to the tangle.
  • options (Object) optional: Tangle meta data.
    • tag (String): Tryte-encoded tag. Maximum value is 27 trytes.
Example
tangly.insert(
    {
      firstName: "Jane",
      lastName: "Doe"
    },
    {
      tag: 'SuperDescriptiveTag'
    }
  ).then(data => data)

Return Value

  • Object
    • address (String): Address that was used to insert data into the Tangle.
    • tag (String): Tag that was assigned.
Example
{
  address: 'W9AZFNWZZZNTAQIOOGYZHKYJHSVMALVTWJSSZDDRVEIXXWPNWEALONZLPQPTCDZRZLHNIHSUKZRSZAZ9W',
  tag: 'SUPER9DESCRIPTIVE9TAG'
}

tangly.find()

Find data that was inserted by the specified seed.

Input

tangly.find(field, options)
  • field (String) required: The name of the field you are attempting to find. An empty string will return all fields.
  • options (Object) optional: Optional search parameters.
    • history (Boolean) default false: Flag to return a field's history.
Example
Single field query
tangly.find('firstName', { history: false }).then(data => data)
All fields query
tangly.find('', { history: true }).then(data => data)

Return Value

  • Object
    • fieldName (Object)
      • value (Any)
      • timestamp (String)
Example
Without history
{
  firstName: {
    value: "Jane",
    timestamp: '3534534234'
  }
  lastName: {
    value: "Doe",
    timestamp: '3534534234'
  }
}
With history
{
  firstName: {
    value: 'Jane',
    timestamp: '34567893233',
    history: [
      {
        value: 'jaane'
        timestamp: '3456789876'
      }
    ]
  }
}

TODO: tangly.addAnchorId()


TODO: tangly.getAnchorId()