RIF Communication lib.js
Library for decentralized communication build as part of RIF OS
Table of Contents
Install
npm
> npm install @rsksmart/rif-communications
Usage
Import the library
var RifCommunications = require('@rsksmart/rif-communications');
Initialization
// Create a key or load from a secure storage to skip this step
var key = await RifCommunications.createKey();
// Create peer id
var peerId = await RifCommunications.createPeerIdFromJSON(key);
// Create peer information
var peerInfo = await RifCommunications.createPeerInfo(peerId);
// Create your peer node
var node = RifCommunications.createNode(peerInfo, host, port, sendMsgFunc);
// Connect to a bootnode using a multiaddress string
await RifCommunications.connectToNode(node, BOOTNODE_ADDRESS);
Send a message to another peer
// Create recipient from their public key (<recipientID>)
var recipient = await RifCommunications.createPeerIdFromPublicKey(recipientID);
// Send a message
await RifCommunications.sendMsg(node, recipient, message, msgNonce);
API
Contribute
There are some ways you can make this module better:
- Consult our open issues and take on one of them
- Help our tests reach 100% coverage!