Docs / Apps / Isolink Connect

Isolink Connect

Isolink Connect lets other apps keep their data in Isolink. It's end-to-end encrypted and synced between people and devices over Bluetooth, Wi-Fi and relays, with no server of the app's own, and the app's company never sees it. Apps get capabilities, not data: an app sees only its own spaces, and people only as handles that are different in every app.

For developers: quick start Markdown reference Protocol JSON Schema

What it is

Everyone

Some apps are about sharing with people near you: a house splitting bills, a family sharing a fridge, friends planning a trip. Usually that means the app's company runs a server that holds everyone's data. With Isolink Connect, the app keeps its data in Isolink instead, and Isolink carries it between you and the people you share with, the same way it carries your messages.

Allowing an app

The first time an app asks to use Isolink, Isolink asks you. On Android, the sheet opens over the app, and the app's name and icon come from Android itself, so an app can't pretend to be another. Tap Allow or Don't allow. You're only asked once.

On a computer, Isolink shows the question in its own window. A computer can't tell Isolink which program is asking, so the sheet says so. Only allow it if you just opened that app.

BillDue's screen with Isolink's sheet over it: Let BillDue use Isolink? BillDue can keep its data in Isolink and share it with people you pick. It can't see your chats or contacts. Allow and Don't allow buttons
On Android, dark
Isolink's consent sheet for BillDue on Android, light theme
On Android, light
Isolink's consent dialog on a computer, dark theme, with a line saying Isolink can't check which app is asking
On a computer, dark
Isolink's consent dialog on a computer, light theme
On a computer, light

Sharing with people

An app never sees your contacts. When it wants to share with someone, Isolink opens its own picker, and you choose who. The app can then add only the people you picked, and people already sharing with it.

Isolink's Share with BillDue sheet listing four contacts, two of them ticked, and a Share button
Share with BillDue, dark
The Share with BillDue picker, light theme
Share with BillDue, light

Connected apps

Go to Settings › Privacy › Connected apps to see every app that uses Isolink, with how many spaces and records each one keeps.

The Connected apps screen listing BillDue with 1 space and 14 records, Fridgeo with 2 spaces and 63 records, and Trail Notes turned off
Connected apps, dark
The Connected apps screen, light theme
Connected apps, light

Host and embedded mode

Developers

An app uses Isolink in one of two ways, with the same API in both:

Either way, an app can also keep its own server. Isolink then works as the app's offline layer: it carries changes between people when there's no signal, and the server keeps a copy for when there is. See With your own server.

The API is a small protocol of JSON frames, so any language can speak it. There are SDKs for Dart (Flutter included) and TypeScript.

PackageWhat it is
isolink_connectDart SDK: the embedded engine (InProcessPort), Isolink on a computer (SocketPort), and isolink codegen
isolink_connect_flutterFlutter plugin: the installed Isolink app on Android (AndroidHostPort), and connectIsolink, which picks the best way in
@isolink/connectTypeScript SDK, with Node and Electron (@isolink/connect/node) and a React hook (@isolink/connect/react)
isolink_coreThe engine: spaces, records, the protocol, and ConnectServer, which answers apps

Quick start

1. Describe your data

Write an .isoschema.yaml with your app and the record types it keeps. connect.schema.json describes the format.

app:
  id: com.billdue.app        # on Android, your package name
  name: BillDue
types:
  bill:
    title: string
    amount: int
    due: datetime
    paidBy: set<string>      # handles of the people who paid
    reminders: counter
  payment:
    bill: string
    amount: int
    by: string

Field types: string, int, double, bool, datetime, json, list<…> of those, set<…> and counter. How each merges is under Records.

2. Generate models

dart run isolink_connect:isolink codegen billdue.isoschema.yaml --dart lib/billdue.g.dart --ts src/billdue.g.ts

This writes model classes for Dart and TypeScript, and billdue.isoschema.lock beside the schema.

Commit the lock file. It holds every field id, so a field keeps its id forever, and the id of a field you remove is never given to a new one. You can give an id by hand: note: {type: string, id: 9}. Changing a field's type is refused, because data already written wouldn't read; give the field a new name instead. In CI, --check fails if anything is out of date.

3. Connect and use it

Dart and Flutter:

import 'package:isolink_connect_flutter/isolink_connect_flutter.dart';
import 'billdue.g.dart';

// The installed Isolink on Android or a computer, or else an engine inside the app.
final isolink = await connectIsolink(
  billDueApp,
  embedded: () => InProcessPort.open(myStore, app: billDueApp.id, name: 'My phone'),
  token: savedToken,          // on a computer: isolink.token from last time
);

final house = await isolink.spaces.open('house:14-elm', name: '14 Elm St');
final people = await isolink.people.pick();            // the person picks, in Isolink
await isolink.spaces.add(house.id, [for (final p in people) p.handle]);

await Bill.edit(isolink, house.id, 'rent', [Bill.setTitle('Rent'), Bill.setAmount(180000)]);
Bill.watch(isolink, house.id).listen((bills) => print(bills.map((b) => b.title)));

TypeScript, in Node or Electron, reaching Isolink on the computer:

import { IsolinkConnect } from '@isolink/connect';
import { socketPort } from '@isolink/connect/node';
import { Bill, billDueApp } from './billdue.g.js';

const port = await socketPort();
if (!port) throw new Error('Open Isolink first');
const isolink = await IsolinkConnect.connect(port, billDueApp, { token: savedToken });
saveToken(isolink.token);

const house = await isolink.spaces.open('house:14-elm', { name: '14 Elm St' });
await Bill.edit(isolink, house.id, 'rent', [Bill.setTitle('Rent'), Bill.setAmount(180000)]);
const stop = Bill.watch(isolink, house.id, (bills) => render(bills));

React:

import { useRecords } from '@isolink/connect/react';

const bills = useRecords(isolink, house.id, Bill.type, Bill.fromRecord);

Spaces

A space is the people an app shares a set of records with: a house sharing bills, a kitchen sharing meals. Inside Isolink it's a variation of a group chat, with the same members, admins and sealed delivery, so it's relayed, carried by contacts and kept in step across the person's devices. It belongs to one app and never shows in the chat list.

spaces.open(key, name:)
Returns the space your app calls key, and makes it if there isn't one. Use it for things that exist once, like a house.
spaces.create(name, key:, people:)
Makes a new space with people (handles).
spaces.add(space, people)
Adds people to a space.
spaces.leave(space)
Leaves it.
spaces.list(), spaces.get(space)
The app's spaces, or one of them.
spaces.merge(keep:, fold:)
Folds one space into another.

When two people make "the same" space while apart, spaces.duplicates (Dart) or spaces.onDuplicate (TypeScript) says so when they meet. Ask the person, then call spaces.merge. Isolink never merges by itself, because only your app knows whether two spaces are really the same thing.

spaces.changes (onChange) fires when a space is made, joined or changed, and spaces.removed (onRemove) when it's left or the person is taken out.

Records

A record is an id, a type and fields named by number. The generated models handle the numbers for you. Edits arrive in any order and more than once, and every device ends up the same.

FieldEditMerge
ValuesetValue(field, value)The latest write wins. Clocks are hybrid logical clocks, and the device id breaks ties.
CounteraddToCounter(field, by)Every device's additions add up, so two people adding at once both count. Counters only go up; keep a second counter for what's taken away.
SetaddToSet / removeFromSetAn item is in the set while its latest add is later than its latest remove.
records.edit(space, type, id, edits)
Edits a record, and makes it if it's new.
records.delete(space, id)
Leaves a tombstone. A later edit brings the record back.
records.list(space, type:), records.get(space, id)
Reads records.
records.changes, records.watch
Every change, from this device or anyone else's.

Fields an older version of your app doesn't know are kept and passed on. A record holds at most 64 KB, and a space at most 50,000 records on each device.

People

An app sees a person as a handle, h_ and 32 hex characters: the same everywhere in that app, and different in every other app. Each person has a name, and me is true for the person using the app.

On a computer, the first connection gives your app a secret, token. Keep it and pass it next time, or the person is asked again.

With your own server

An app that already has a server and an API can keep both, and use Isolink to move its data when the internet doesn't. The server keeps a copy of each space's records, and Isolink keeps one on every phone in the space. Changes go to the server whenever the phone can reach it, and between people over Bluetooth, Wi-Fi and Isolink's relays when it can't. Every copy ends up the same, because record states merge the same whatever order they arrive in, however often.

The SDKs do this with ServerSync. For each space, your server keeps the latest state of each record by id, merged with mergeRecordStates, and says what changed since a cursor:

class MyServer implements SyncServer {
  @override
  Future<void> upload(Space space, List<Map<String, Object?>> states) =>
      api.post('/spaces/${space.id}/states', states); // the server merges each with mergeRecordStates

  @override
  Future<({List<Map<String, Object?>> states, String? cursor})> download(Space space, String? cursor) async {
    final r = await api.get('/spaces/${space.id}/states', since: cursor);
    return (states: r.states, cursor: r.cursor);
  }
}

final sync = ServerSync(isolink, MyServer(), cursors: saved)..start();
// Later: save sync.cursors, so a restart sends only what changed.
import { ServerSync, mergeRecordStates, recordFromState } from '@isolink/connect/sync';

const sync = new ServerSync(isolink, myServer, { cursors: saved, onError: showOffline });
sync.start();

// On the server (Node): keep the merged state, and read it as a record.
const next = before ? mergeRecordStates(before, incoming) : incoming;
const record = recordFromState(next); // { id, type, fields } or null when deleted

Errors

Every refusal has a code:

CodeMeaning
bad_requestThe request is malformed, or an edit is invalid, like a counter going down or a field of another kind
not_connectedSay hello first, or the connection ended
consent_requiredNobody has allowed this app yet. On Android the SDK asks and tries again
deniedThe person said no, the app was removed, or it isn't the app the system says
turned_offThe person turned this app off
unknown_spaceNo such space, or not this app's
unknown_personA handle this app can't add: pick them first
too_bigThe record would pass 64 KB, or the space is full
not_allowedNot in this mode, like reading the person's code on an installed Isolink
unsupportedA method this engine doesn't have
failedSomething else. On Android, Isolink handed over between its engines: try again

The protocol

Every frame is one JSON object in UTF-8, at most 256 KB. connect.schema.json describes them all.

{"id": 7, "m": "records.edit", "p": {"space": "...", "type": "bill", "id": "rent", "edits": [...]}}
{"id": 7, "r": {...}}
{"id": 7, "e": {"code": "unknown_space", "message": "..."}}
{"ev": "records.changed", "p": {...}}

A request, its answer or its refusal, and an event. The first request is hello: {"protocol": 1, "app": {"id", "name", "publisher"?, "types"?}, "token"?}. It answers {"protocol", "mode": "host" | "embedded", "me": Person, "token"?}.

MethodParamsAnswer
status{running, reachable}
spaces.list[Space]
spaces.getspaceSpace
spaces.openkey, nameSpace
spaces.createname, key?, people?Space
spaces.addspace, peopleSpace
spaces.leavespacenull
spaces.mergekeep, foldSpace
records.listspace, type?[Record]
records.getspace, idRecord or null
records.editspace, type, id, editsRecord
records.deletespace, idnull
sync.pullspace, cursor?{states, cursor, more}: every record state that changed since cursor (all when it's missing or from before a restart), about 192 KB a page
sync.pushspace, states{changed}: joins states from the app's server into the space and sends what's new to everyone in it
people.pickmany?[Person]. Host mode; on Android the SDK opens the picker itself
people.codestring. Embedded mode
people.addcodePerson. Embedded mode
people.list[Person]. Embedded mode
Space
{id, key, name, admin, people: [Person]}
Person
{handle, name, me, admin?}
Record
{id, type, fields: {"1": value, ...}}. A counter's value is its total; a set's is a list.
Edit
{"op": "setValue", "field": 1, "value": ...}, {"op": "addToCounter", "field": 2, "by": 3}, or {"op": "addToSet" | "removeFromSet", "field": 4, "items": [...]}

Events:

records.changed
{space, id, type, deleted, record, by}
spaces.changed
A Space
spaces.removed
{space}
spaces.duplicate
{older, newer}
closed
{reason}, when Isolink ends the connection

Transports

On Android, declare Isolink in your manifest so your app can see it:

<queries><package android:name="dev.isolink.isolink" /></queries>

To write an SDK for another language, speak these frames and run the conformance vectors in packages/isolink_core/test/connect/*.json. They're data, not code, so every SDK runs the same ones.

Not built yet