{"id":20597006,"url":"https://github.com/tradle/tim-old-engine","last_synced_at":"2025-10-04T22:08:45.778Z","repository":{"id":33910961,"uuid":"37628382","full_name":"tradle/tim-old-engine","owner":"tradle","description":"[DEPRECATED] SDK for real-rime auditable blockchain-based messaging","archived":false,"fork":false,"pushed_at":"2016-06-24T19:29:25.000Z","size":622,"stargazers_count":29,"open_issues_count":3,"forks_count":5,"subscribers_count":10,"default_branch":"master","last_synced_at":"2025-04-14T23:52:03.290Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"http://tradle.io","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tradle.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-06-18T00:26:59.000Z","updated_at":"2021-08-08T16:27:41.000Z","dependencies_parsed_at":"2022-09-24T09:25:07.715Z","dependency_job_id":null,"html_url":"https://github.com/tradle/tim-old-engine","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tradle%2Ftim-old-engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tradle%2Ftim-old-engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tradle%2Ftim-old-engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tradle%2Ftim-old-engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tradle","download_url":"https://codeload.github.com/tradle/tim-old-engine/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248981260,"owners_count":21193144,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-16T08:19:50.183Z","updated_at":"2025-10-04T22:08:40.729Z","avatar_url":"https://github.com/tradle.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Trust in Motion (TiM)\n\n[![Build status](https://travis-ci.org/tradle/tim.svg)](https://travis-ci.org/tradle/tim)\n\nTiM is Tradle's SDK that provides real-time messaging with an option for messages to be sealed on the blockchain. Mesages can be plain or structured messages. TiM is designed to work on mobiles, desktops and servers. Having one code base is important to minimize security reviews. \n\nTiM is designed to work with intermittent connections, common on mobile devices. For that it keeps an internal log of all actions and events, and resumes operations as soon as network connection is restored.\n\nTiM's operations are covered by a patent. The tatent is filed only for defensive purposes, so you are welcome to use it in your open source projects.\n\n_this module is used by [Tradle](https://github.com/tradle/about/wiki)_  \n_this npm module's name was graciously donated by [Sean Robertson](https://www.npmjs.com/~spro)_\n\nTiM provides a higher level API to a number of low level Tradle components. A UI is developed separately. Currently we focus on [React Native based UI](https://github.com/pgmemk/TiM) (on iOS, the Android version of TiM is in works), see the [preview video](https://www.youtube.com/watch?v=S66T0dPNn5I) and the [screenshots](https://docs.google.com/document/d/10eV6wgKr_vmfrXR4bDZ5XuylWJMNIJxziXM9T2CzCew). \n\nPrior to React Native, we developed the UI for Tim as a [Chrome App](https://github.com/tradle/chromeapp), see this [Identity verification video](https://www.youtube.com/watch?v=rrt8U4M-yMg) and a [work completion video](https://www.youtube.com/watch?v=mRnaw4pdifA). And prior to that we developed a very cool node-webkit-based [craigslist on-chain concept app](https://github.com/tradle/craigslist-on-chain) on TiM, but it is very much behind now. We plan work on desktop version of TiM soon, let us know if you are interested in these environments and we will prioritize this work for you.\n\n## TiM uses the following Tradle components:\n\n### [zlorp](https://github.com/tradle/zlorp)\n\n[Zlorp](https://github.com/tradle/zlorp) is just the core chat module. It uses OTR for secure sessions (later will add support for Axolotl, used in [TextSecure](https://github.com/WhisperSystems/TextSecure/) and [Pond](https://pond.imperialviolet.org/)). Peer discovery today is done via bittorrent-dht. But DHT's regular announce messages leak IP/Port, so we will see if we can use BEP 44 to encrypt them. Zlorp provides UDP NAT traversal (firewall hole-punching), and a direct connection via rUDP (later via uTP). We plan to further investigate anonymous packet delivery, possibly via I2P (TOR does not support UDP).\n\n### [bitkeeper-js](https://github.com/tradle/bitkeeper-js)\n\n[Bitkeeper](https://github.com/tradle/bitkeeper-js) module uses [WebTorrent](https://github.com/feross/webtorrent) for storing and ensuring replication of arbitrary files. In Tradle, bitkeeper is used to store the original (encrypted) versions of on-chain objects (structured messages).\n\n### [chained-obj](https://github.com/tradle/chained-obj)\n\n[Chained-obj](https://github.com/tradle/chained-obj) is object builder and parser. Currently uses multipart to store arbitrary JSON data + attachments. These objects are later encrypted and put on-chain.\n\n### [bitjoe-js](https://github.com/tradle/bitjoe-js) (to be renamed to: chainwriter)\n\nA collection of requests that can be used to put an object \"on chain\": encrypt an object for its recipients, store/seed it from a bitkeeper node and put private links on blockchain.\n\n### [tradle-constants](https://github.com/tradle/tradle-constants)\n\nWait for it...a bunch of constants\n\n### [tradle-utils](https://github.com/tradle/tradle-utils)\n\nA small set of crypto and torrent-related functions used by a number of Tradle components\n\n### [Identity](https://github.com/tradle/identity)\n\n[Identity](https://github.com/tradle/identity) is wrapper around an OpenName-compatible Identity schema. Used for building/parsing/validating identity objects.\n\n### [kiki](https://github.com/tradle/kiki)\n\n[kiki](https://github.com/tradle/kiki) Wrappers for DSA, EC, Bitcoin and other keys to provide a common API for signing/verifying/importing/exporting.\n\n### [chainloader](https://github.com/tradle/chainloader)\n\nParses bitcoin transactions, attempts to process embedded links, loads intermediate files and original files from a bitkeeper node, decrypts and returns files and metadata. Implements stream.Transform.\n\n### [simple-wallet](https://github.com/tradle/simple-wallet)\n\nOne-key [common blockchain](https://github.com/common-blockchain/common-blockchain) based wallet.\n\n### [tradle-tx-data](https://github.com/tradle/tx-data)\n\nFor building/parsing bitcoin-transaction-embedded data\n\n### [tradle-verifier](https://github.com/tradle/tradle-verifier)\n\nPlugin-based verifier for on-chain objects. Implements several default plugins:  \n    Signature Check  \n    Identity verification  \n    Previous Version verification  \n\n## Exports\n\n### Datalog\n\nThis module uses a datalog, a log-based database of experienced activity that you can write to and use to bootstrap your own databases from.\n\n### Messaging API\n\nDetails to follow\n\n## Usage\n\n### Identity Identifiers\n\nWhen you want to communicate with someone else on the network, you need to identify them uniquely. You can identify them by a fingerprint of one of their public keys, a public key string, or by their identity's root hash:\n\n```js\n// if this is the identity of your friend Bill:\n{\n  \"_t\": \"tradle.Identity\",\n  \"pubkeys\": [\n    {\n      \"fingerprint\": \"mvDNdZFbCCmnAPCBmLY91LnfKWoMH39Q2c\",\n      \"networkName\": \"testnet\",\n      \"purpose\": \"payment\",\n      \"type\": \"bitcoin\",\n      \"value\": \"03a45ede4be12a812e6e2ef1650ecbd8900152b1c6e3fe47f427ee5d9323759fe3\"\n    }\n  ]\n}\n\n// the following are equivalent identifiers for Bill:\n{\n  fingerprint: 'mvDNdZFbCCmnAPCBmLY91LnfKWoMH39Q2c' \n}\n\n{\n  _r: 'whatever the infoHash of the above JSON object is'\n}\n```\n\n### Initialization\n\n```js\nvar path = require('path')\nvar levelup = require('levelup')\nvar leveldown = require('leveldown') // or asyncstorage-down or whatever you're using\nvar Blockchain = require('cb-blockr') // use tradle/cb-blockr fork\nvar Identity = require('@tradle/identity').Identity\nvar defaultKeySet = require('@tradle/identity').defaultKeySet\nvar Keeper = require('@tradle/http-keeper')\nvar Tim = require('tim')\n\n// Setup components:\nvar networkName = 'testnet'\nvar blockchain = new Blockchain(networkName)\n//   Create an identity or load an existing one (see tradle/identity readme):\nvar jack = new Identity()\nvar jackPrivKeys = defaultKeySet({ networkName: networkName })\njackPrivKeys.forEach(jack.addKey, jack)\n//   to export private keys:    jackPrivKeys.forEach(k =\u003e k.exportPrivate())\n//   to export public identity: jack.toJSON()\n\nvar myDir = path.join(process.env.HOME, 'myTradle')\n//   content-address storage for your encrypted messages\nvar keeper = new Keeper({\n  db: levelup(path.resolve(myDir, 'keeper'), { db: leveldown, valueEncoding: 'binary' }),\n  fallbacks: ['http://tradle.io:25667']\n})\n\n// the API\nvar tim = new Tim({\n  pathPrefix: path.join(myDir, 'tim'), // for playing nice with other levelup-based storage\n  leveldown: leveldown,\n  networkName: networkName,\n  identity: jack,\n  keys: jackPrivKeys, \n  keeper: keeper,\n  blockchain: blockchain,\n  // optional\n  syncInterval: 600000 // how often to bother cb-blockr\n})\n\n// define a _send function that will determine the transport to use\n// to deliver a message to a particular recipient\ntim._send = function (recipientRootHash, msg, recipientInfo) {\n  // return a Promise that resolves when the message is delivered\n  // e.g. tim2.receiveMsg(msg, { _r: recipientRootHash })\n  // \n  // tradle has several network-adapters for message delivery that you can use here. \n  // They are all open source on Github:\n  //   tradle/zlorp - pure p2p messaging with OTR over UDP\n  //   tradle/http-client \u0026 tradle/http-server\n  //   tradle/ws-client \u0026 tradle/ws-relay - OTR over websockets\n  //   \n  //   latest, but unstable:\n  //   tradle/sendy, tradle/sendy-otr\n  //     reliable delivery over network of choice. \n  //     websockets implementation: tradle/sendy-ws, tradle/sendy-ws-relay\n}\n\ntim.send({\n  to: [{ fingerprint: 'one of their fingerprints' }],\n  msg: { hey: 'ho' },\n  deliver: true,  \n  chain: false\n})\n\n```\n\n### Publishing your identity\n\n```js\ntim.publishMyIdentity()\n```\n\n### Sending messages\n\n```js\n\ntim.send({\n  msg: Object|Buffer,\n  // record message on chain\n  chain: true,\n  // send message p2p\n  deliver: true,\n  to: [\n    identityIdentitifier // see Identity Identifiers\n  ]\n})\n\n```\n\n### Sharing existing messages (via the blockchain)\n\n```js\n\nvar constants = require('@tradle/constants')\nvar curHash = '...' // the infoHash of the existing message, see tradle/utils `getStorageKeyFor`\nvar shareOpts = {\n  // record message on chain\n  chain: true,\n  // send message p2p\n  deliver: true,\n  to: [\n    identityIdentitifier // see Identity Identifiers  \n  ]\n}\n\nshareOpts[constants.CUR_HASH] = curHash\ntim.share(shareOpts)\n\n```\n\n### Publishing on chain\n\nSame as sending a message, but use tim.publish instead of tim.send\n\n```js\n\ntim.publish({\n  msg: Object|Buffer,\n  to: [\n    identityIdentitifier // see Identity Identifiers\n  ]\n})\n\n```\n\n## Messages\n\n```js\nvar db = tim.messages() // read-only levelup instance\n\n// e.g.\ndb.createValueStream()\n  .on('data', function (err, msg) {\n    // issue tim.lookupObject(msg) to get decrypted metadata and contents\n  })\n```\n\n## Identities (loaded from chain)\n\n```js\nvar db = tim.identities() // read-only levelup instance\n\n// e.g.\ndb.createValueStream()\n  .on('data', function (err, identityJSON) {\n    // do something with \"identity\"\n    // console.log('yo', identityJSON.name.firstName)\n  })\n\n// additional convenience methods\ndb.byRootHash(identityRootHash, callback)\ndb.byFingerprint(fingerprint, callback)\n```\n\n## Events\n\n### tim.on('ready', function () {...})\n\nTim's ready to do stuff\n\n### tim.on('chained', function (info) {...}\n\nAn object was successfully put on chain\u003csup\u003e1\u003c/sup\u003e\n\n### tim.on('unchained', function (info) {...}\n\nAn object was read off chain\u003csup\u003e1\u003c/sup\u003e\n\n### tim.on('message', function (info) {...}\n\nA message was received peer-to-peer\u003csup\u003e1\u003c/sup\u003e\n\n### tim.on('sent', function (info) {...}\n\nA message was delivered\u003csup\u003e1\u003c/sup\u003e\n\n### tim.on('resolved', function (info) {...}\n\nAn object was both received peer-to-peer and read from the chain\u003csup\u003e1\u003c/sup\u003e\n\n\u003csup\u003e1\u003c/sup\u003e Note: does NOT contain chained-object contents. Use tim.lookupObject(info) to obtain those.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftradle%2Ftim-old-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftradle%2Ftim-old-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftradle%2Ftim-old-engine/lists"}