Code Monkey home page Code Monkey logo

tanglestash's Introduction

license npm npm daviddm

Tanglestash

IOTA meets BitTorrent: An algorithm to persist any file onto the tangle of IOTA

Features

  • Persist any data onto the tangle of IOTA
  • Retrieve data that was persisted with this module beforehand
  • Optionally encrypt your data with a password (via AES)
  • Store a string or even a whole file without any prior conversion

GUI

Check out my other project tanglesta.sh here on GitHub which implements this module into a full-blown desktop app available for Windows, macOS and Linux.

Idea

I really like the idea of the tangle of IOTA and I think that this cryptocurrency has a bright future. I run a full node myself and want the idea to succeed. The more I messed with IOTA, the further this idea formed in my mind to use the 2187 trytes of each transactions signature to store any data on the decentralised tangle.

This module can persist any string or even files directly onto the tangle via creating a torrent-esque chain of transactions that reference other transactions holding the data while also referencing their direct predecessor in the chain. That way, this module can also retrieve any data that was persisted beforehand by just passing the 'entry-hash' into it, which is the first transaction hash of the created chain. The data can be optionally encrypted with a secret via AES so that even if someone gets hold of an 'entry-hash', the data will still be illegible. Data is stored as a Base64 string and files will be automatically encoded if passed into the algorithm as well as decoded if retrieved โ€“ no prior conversion of the file needed.
Here is a diagram of the data structure I came with for this project:

Diagram of the data structure

Disclaimer

I know that primarily the persisting to the tangle is painfully slow compared to a traditional HTTP upload.
Keep in mind though that this project is more of a proof-of-concept rather than a finished product.
The reason that it takes so long is mainly the current speed of the PoW, which might get faster in the future with new techniques.

Additionally, it is important to note that this module just works with Node.js version 8 owing to the fact that a dependency is currently not functioning under version 9.

Installation

NPM

npm install --save tanglestash

Yarn

yarn add tanglestash

Usage

First off, create a new instance of the modules class

let tanglestash = new Tanglestash(provider, datatype, seed);

with the following arguments:

  1. provider: String A URI of an IOTA full node
  2. datatype: String Either 'file' or 'string' based on the data that will later be used
  3. seed: String [Optional] An IOTA wallet seed; will be automatically generated if not passed here

readFromTangle

Retrieves data that was persisted onto the tangle in the past.

Input

tanglestash.readFromTangle(entryHash, secret)
  1. entryHash: String Any transaction hash that was output after successfully persisting data beforehand; called 'entry-hash'
  2. secret: String [Optional] The password the data was encrypted with; if any

Return Value

  1. Promise.<*> - A file buffer of the retrieved data or a string based on this.datatype

saveToTangle

Persists data onto the tangle.

Input

tanglestash.saveToTangle(data, secret)
  1. data: String The data as a string or file path based on this.datatype
  2. secret: String [Optional] The password the data should be encrypted with; if any

Return Value

  1. Promise.<string> - The last transaction hash of the created chain; called 'entry-hash'

getNewIotaAddress

Retrieves a new valid IOTA wallet address based on this.seed.

Input

tanglestash.getNewIotaAddress()

Return Value

  1. Promise.<string> - The retrieved wallet address

getAllMarkyEntries

Returns all the marky entries used to time the main processes. If you've never used marky before, learn more about it here.

Input

tanglestash.getAllMarkyEntries()

Return Value

  1. Array.<object> - All the timing entries created by marky

License

This project is licensed under the MIT license.
The included dynamic libraries are compiled from the ccurl repository licensed under MIT license.

Donations

If you like this module and want to support it, you can of course donate some IOTA ๐Ÿ˜Š
QIFKUOEQBCEV9NKFWDBTQYBHLFFORLVKDQSYDSZQQMKTCBLBFDQMJWIOUDH9DLZXVKGNQGKLSAJCQQMEDESLCTHGZD

tanglestash's People

Contributors

loehnertz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

tanglestash's Issues

How are files handled after snapshot?

I think your module is great. I have had the same idea before but determined that it was useless because after snapshots are created, all history (and arbitrary data) are removed except for where units of IOTA are stored. This is why after snapshots you have to reattach a bunch of times to determine what your last used public address was from your seed. How does your code handle this situation?

edit source: https://forum.helloiota.com/4659/How-do-I-prepare-for-a-snapshot

Invalid Response: Error: Protocol not supported.

Running the following code (on both windows and ubuntu 16.04) with node 8.x:

const stash = require('tanglestash')

let provider = 'mynode:14265'
let seed = 'SOMESEED999999999999999999999999' // not the actual seed
let datatype = 'file' //either 'file' or 'string'
let file = './text.txt'

let test = async () => {

    try {
        let tanglestash = new stash.Tanglestash(provider, datatype, seed)
        let write = await tanglestash.saveToTangle(file)
        // how long will we have to wait for this promise to resolve?
        console.log ('Some stuff is coming...: ', write)
    } catch (e) {
        console.log('error initializing', e)
    }
}

test()

I get repeating blocks that look like the below:

Invalid Response: Error: Protocol not supported. { content: 'YXZvdXJlZCB0byBwcmV2ZW50IHRoZSBwb3B1bGF0aW9uIG9mIHRoZXNlIFN0YXRlczsgZm9yIHRoYXQgcHVycG9zZSBvYnN0cnVjdGluZyB0aGUgTGF3cyBmb3IgTmF0dXJhbGl6YXRpb24gb2YgRm9yZWlnbmVyczsgcmVmdXNpbmcgdG8gcGFzcyBvdGhlcnMgdG8gZW5jb3VyYWdlIHRoZWlyIG1pZ3JhdGlvbnMgaGl0aGVyLCBhbmQgcmFpc2luZyB0aGUgY29uZGl0aW9ucyBvZiBuZXcgQXBwcm9wcmlhdGlvbnMgb2YgTGFuZHMuCgpIZSBoYXMgb2JzdHJ1Y3RlZCB0aGUgQWRtaW5pc3RyYXRpb24gb2YgSnVzdGljZSBieSByZWZ1c2luZyBoaXMgQXNzZW50IHRvIExhd3MgZm9yIGVzdGFibGlzaGluZyBKdWRpY2lhcnkgUG93ZXJzLgoKSGUgaGFzIG1hZGUgSnVkZ2VzIGRlcGVuZGVudCBvbiBoaXMgV2lsbCBhbG9uZSBmb3IgdGhlIHRlbnVyZSBvZiB0aGVpciBvZmZpY2VzLCBhbmQgdGhlIGFtb3VudCBhbmQgcGF5bWVudCBvZiB0aGVpciBzYWxhcmllcy4KCkhlIGhhcyBlcmVjdGVkIGEgbXVsdGl0dWRlIG9mIE5ldyBPZmZpY2VzLCBhbmQgc2VudCBoaXRoZXIgc3dhcm1zIG9mIE9mZmljZXJzIHRvIGhhcmFzcyBvdXIgcGVvcGxlIGFuZCBlYXQgb3V0IHRoZWlyIHN1YnN0YW5jZS4KCkhlIGhhcyBrZXB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ZWUgU3lzdGVtIG9mIEVuZ2xpc2ggTGF3cyBpbiBhIG5laWdoYm91cmluZyBQcm92aW5jZSwgZXN0YWJsaXNoaW5nIHRoZXJlaW4gYW4gQXJiaXRyYXJ5IGdvdmVybm1lbnQsIGFuZCBlbmxhcmdpbmcgaXRzIEJvdW5kYXJpZXMgc28gYXMgdG8gcmVuZGVyIGl0IGF0IG9uY2UgYW4gZXhhbXBsZSBhbmQgZml0IGluc3RydW1lbnQgZm9yIGludHJvZHVj',
  hash: null,
  index: '2',
  persisted: false,
  retrieved: false }

Errors while running npm install

Logs:

  target->ForceSet(Nan::New<String>("RTLD_NEXT").ToLocalChecked(), WrapPointer((char *)RTLD_NEXT), static_cast<PropertyAttribute>(ReadOnly | DontDelete));

.....

24 warnings and 10 errors generated.
make: *** [Release/obj.target/ffi_bindings/src/ffi.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:258:23)
gyp ERR! stack     at ChildProcess.emit (events.js:160:13)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:209:12)
gyp ERR! System Darwin 17.4.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/.../Tanglestash/node_modules/ffi
gyp ERR! node -v v9.4.0
gyp ERR! node-gyp -v v3.6.2
gyp ERR! not ok 
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] install script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/.../.npm/_logs/2018-02-04T20_07_54_871Z-debug.log

The exception `MalformedPersistedDataError` won't bubble up correctly

When one tries to retrieve data which transactions are malformed the module correctly throws the error MalformedPersistedDataError.
The problem though is that the exception doesn't bubble up correctly which causes the exception to be swallowed. Apart from the console.warn() message there is no way to catch that exception.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.