iris-messenger/iris-lib
2022-10-11 11:02:45 +03:00
..
dist . 2022-10-10 16:36:33 +03:00
example . 2022-10-10 16:36:33 +03:00
src restore default peer 2022-10-11 11:02:45 +03:00
tests move Session, State and PeerManager to iris-lib (#157) 2022-10-03 16:05:54 +03:00
.babelrc ./iris-lib, restore lib build stuff 2022-09-22 10:30:46 +03:00
.eslintignore ./iris-lib, restore lib build stuff 2022-09-22 10:30:46 +03:00
.gitignore ./iris-lib, restore lib build stuff 2022-09-22 10:30:46 +03:00
.npmignore ./iris-lib, restore lib build stuff 2022-09-22 10:30:46 +03:00
documentation.yml Api refactor (#158) 2022-10-10 15:12:02 +03:00
package.json Api refactor (#158) 2022-10-10 15:12:02 +03:00
README.md ./iris-lib, restore lib build stuff 2022-09-22 10:30:46 +03:00
rollup.config.js . 2022-10-10 16:36:33 +03:00
yarn.lock Api refactor (#158) 2022-10-10 15:12:02 +03:00

iris-lib

Node NPM Travis David Coverage Status Gitmoji

BTC donations: 3GopC1ijpZktaGLXHb7atugPj9zPGyQeST

Description

Iris-lib allows you to integrate decentralized social networking features into your application.

Public messaging: Add a troll-free comment box to your website or app.

Private chats: Don't reinvent the wheel - just deploy iris-lib for real-time private and group discussions. No phone number or other "account" needed - just generate a public key that your friends can optionally verify.

Web of trust: Filter out spam and other unwanted content, without giving power to central moderators. Iris public and private messages are automatically filtered. You can also filter your own datasets by user's web of trust distance.

Contacts management: Ask friends to verify your public key or cryptocurrency address and changes to them. Use verified payment addresses in crypto wallets. Use verified public keys for authentication instead of relying on centralized email addresses, domain names and passwords. Any other types of attributes can also be added and verified.

Iris-lib runs in the browser and on Node.js.

Documentation

Example

Private channel:

// Copy & paste this to console at https://iris.to or other page that has gun, sea and iris-lib
// Due to an unsolved bug, someoneElse's messages only start showing up after a reload

var gun1 = new Gun('https://gun-us.herokuapp.com/gun');
var gun2 = new Gun('https://gun-us.herokuapp.com/gun');
var myKey = await iris.Key.getDefault();
var someoneElse = localStorage.getItem('someoneElsesKey');
if (someoneElse) {
 someoneElse = JSON.parse(someoneElse);
} else {
 someoneElse = await iris.Key.generate();
 localStorage.setItem('someoneElsesKey', JSON.stringify(someoneElse));
}

iris.Channel.initUser(gun1, myKey); // saves myKey.epub to gun.user().get('epub')
iris.Channel.initUser(gun2, someoneElse);

var ourChannel = new iris.Channel({key: myKey, gun: gun1, participants: someoneElse.pub});
var theirChannel = new iris.Channel({key: someoneElse, gun: gun2, participants: myKey.pub});

var myChannels = {}; // you can list them in a user interface
function printMessage(msg, info) {
 console.log(`[${new Date(msg.time).toLocaleString()}] ${info.from.slice(0,8)}: ${msg.text}`)
}
iris.Channel.getChannels(gun1, myKey, channel => {
 var pub = channel.getParticipants()[0];
 gun1.user(pub).get('profile').get('name').on(name => channel.name = name);
 myChannels[pub] = channel;
 channel.getMessages(printMessage);
 channel.on('mood', (mood, from) => console.log(from.slice(0,8) + ' is feeling ' + mood));
});

// you can play with these in the console:
ourChannel.send('message from myKey');
theirChannel.send('message from someoneElse');

ourChannel.put('mood', 'blessed');
theirChannel.put('mood', 'happy');

More examples: tests

Tech

Data storage and networking are outsourced to GUN, which manages the synchronization of data between different storages: RAM, localstorage, GUN websocket server, WebRTC peers, LAN multicast peers, IPFS (no adapter yet), S3 or others.

GUN enables subscription to data changes, so message feeds and contact details just update real-time without having to hit f5 or writing complex update logic.

IPFS is used to store file attachments and optional message backups.

Installation

Install via yarn

yarn add iris-lib (--dev)

or npm

npm install iris-lib (--save-dev)

Builds

If you don't use a package manager, you can access iris-lib via unpkg (CDN), download the source, or point your package manager to the url.

iris-lib is compiled as a collection of CommonJS modules & ES2015 modules for bundlers that support the jsnext:main or module field in package.json (Rollup, Webpack 2)

The iris-lib package includes precompiled production and development UMD builds in the dist folder. They can be used directly without a bundler and are thus compatible with many popular JavaScript module loaders and environments. You can drop a UMD build as a <script> tag on your page. The UMD builds make iris-lib available as a window.iris global variable. Be sure to include gun.js and sea.js first.

<script src="https://cdn.jsdelivr.net/npm/gun/gun.js"></script>
<script src="https://cdn.jsdelivr.net/npm/gun/sea.js"></script>
<script src="https://cdn.jsdelivr.net/npm/iris-lib@latest/dist/iris.min.js"></script>

License

The code is available under the MIT license.

Contributing

Please do integrate iris-lib with your existing application or with a test application and create Github issues for the bugs and other problems you may encounter. Your help is much appreciated!

TODO list is also available on Trello.

Majestic is a handy tool for viewing jest test results and coverage.

Misc

This module was created using generator-module-boilerplate.