0.1.7
User session management utilities.
Log in with a key from localStorage.
If no key is found and options.autologin is not false, a new user will be created.
If options.autofollow is not false, the default follow will be added.
(any
= {}
)
Log in with a private key.
(any)
(any)
Get the keypair of the logged in user.
any
:
Get the public key of the logged in user.
any
:
Get the name of the logged in user.
any
:
Known private channels with other users
Get a public space where only the specified user (public key) can write. Others can read.
(string?)
The public key of the user. Defaults to the current user from session.
Node
:
The user space.
Private channel that only you and publicKey can read/write.
(any
= session.getKey()
)
(string?)
Channel
:
Aggregates public data from all users in the group.
For example, the public message feed, message replies and likes are aggregated using this.
(any
= 'everyone'
)
any
:
object
Get a state that is only synced in memory and local storage.
Useful for storing things like UI state, local indexes or logged in user.
Node
:
Content-addressed storage
Networking and peer management utilities
Our very own implementation of the Gun API
Signed message object. Your friends can index and relay your messages, while others can still verify that they were signed by you.
Fields: signedData, signer (public key) and signature.
signedData has an author, signer, type, time and optionally other fields.
signature covers the utf8 string representation of signedData. Since messages are digitally signed, users only need to care about the message signer and not who relayed it or whose index it was found from.
signer is the entity that verified its origin. In other words: message author and signer can be different entities, and only the signer needs to use Iris.
For example, a crawler can import and sign other people's messages from Twitter. Only the users who trust the crawler will see the messages.
Constructor: creates a message from the param obj.signedData that must contain at least the mandatory fields: author, type and time.
(any)
https://github.com/irislib/iris-lib/blob/master/__tests__/SignedMessage.js
Verification message:
{
signedData: {
author: {name:'Alice', key:'ABCD1234'},
recipient: {
name: 'Bob',
email: ['bob@example.com', 'bob.saget@example.com'],
bitcoin: '1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa'
},
type: 'verification'
},
signer: 'ABCD1234',
signature: '1234ABCD'
}
Create an iris message. SignedMessage time is automatically set. If signingKey is specified and author omitted, signingKey will be used as author.
(Object)
message data object including author, recipient and other possible attributes
(Object)
optionally, you can set the key to sign the message with
Promise<SignedMessage>
:
message
(any)
Promise<SignedMessage>
:
Derive a key from bytes. For example, sign a login prompt string with metamask and pass the signature to this function to derive a key.
(Uint8Array)
Promise<MyKey>
Private communication channel between two or more participants (Gun public keys). Can be used independently of other Iris stuff.
Used as a core element of iris-messenger.
You can use iris.private(pub) to always use the same Channel object for a given pub.
channel.put(key, value)
and channel.on(key, callback)
.
Note that each participant has their own versions of each key-value — they don't overwrite each other. channel.on()
callback returns them all by default and has a parameter that indicates whose value you got.
While values are encrypted, encryption of keys is not implemented yet.
channel.send()
and channel.getMessages()
for timestamp-indexed chat-style messaging.
Message data is encrypted, but timestamps are public so that peers can return your messages in a sequential order.
You can open a channel with yourself for a private key-value space or a "note to self" type chat with yourself.
Privacy disclaimer: Channel ids, data values and messages are encrypted, but message timestamps are unencrypted so that peers can return them to you in a sequential order. By looking at the unencrypted timestamps (or Gun subscriptions), it is possible to guess who are communicating with each other. This could be improved by indexing messages by day only, so making the guess would be more difficult, while you could still return them in a semi-sequential order.
(Object)
Name | Description |
---|---|
options.key string
|
your keypair |
options.gun Object
|
gun instance |
options.participants any
|
(optional) string or string array or permissions object ({'pub1':{read:true,write:true,admin:false},'pub2'...}) of participant public keys (your own key is included by default) |
options.chatLink string
|
(optional) chat link instead of participants list |
options.uuid string
|
(group channels only) unique channel identifier. Leave out for new channel. |
options.name string
|
(group channels only) channel name |
// 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.getCurrentParticipants()[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');
https://github.com/irislib/iris-lib/blob/master/__tests__/Channel.js
(any)
(any)
(any)
(any)
Calls back with Channels that you have initiated or written to.
(any)
callback function that is called for each public key you have a channel with
(any
= true
)
(Object)
Gun.SEA keypair that the gun instance is authenticated with
Add a chat button to page
(any
= {}
)
{label, channelOptions}
Creates a channel link that can be used for two-way communication, i.e. only one link needs to be exchanged.
(any
= 'https://iris.to/'
)
(any)
(any)
(any)
(any)
(any)
(any)
List participants of the channel (other than you)
Subscribe to the changing list of participants by channel admins
(any)
Returns either the uuid of a group channel or the public key of a direct channel.
Get messages from the channel
(any)
Get latest message in this channel. Useful for channel listing.
(any)
Useful for notifications
(integer)
last seen msg time (default: now)
Useful for notifications
(any)
For "seen" status indicator
(any)
Send a message to the channel
(any)
string or {time, text, ...} object
Save the channel to our channels list without sending a message
Subscribe to a key-value pair. Callback returns every participant's value unless you limit it with from param.
Set typing status
(any)
(any
= 5
)
Get typing status
(any)
(any
= 5
)
Get a simple link that points to the channel.
Direct channel: both users need to give their simple links. Use createChatLink() to get a two-way link that needs to be given by one user only.
Group channel: Works only if the link recipient has been already added onto the channel participants list.
(any
= 'https://iris.to/'
)
(any
= {}
)
Get a channel box element that you can add to your page
(any)