Skip to content

Using HALO in Typescript

To create or join a space in ECHO, the user must first establish a HALO identity. This can be done by creating a new identity or accepting a device join invitation.

Obtaining identity

import { Client } from '@dxos/client';
const client = new Client();
await client.initialize();
const _identity = client.halo.identity.get();

The object returned is of type Identity.

Creating an identity

Create a new identity:

import { Client } from '@dxos/client';
const client = new Client();
await client.initialize();
const _identity = await client.halo.createIdentity();

Before data can be manipulated, a space must be obtained.

Receiving a device join invitation

We often want to add a device to the same HALO identity. You can accept a device join invitation by providing the invitation code and the auth code to the DXOS client.

import { type Client } from '@dxos/client';
import { InvitationEncoder } from '@dxos/client-protocol';
/** Accepts a device join invitation by prompting the user for:
* - invitation code
* - authentication code */
export const acceptInvitation = async (
client: Client,
deviceInvitationCode: string,
) => {
const decodedInvitation = InvitationEncoder.decode(deviceInvitationCode);
const invitationResult = client.halo.join(decodedInvitation);
if (decodedInvitation.authCode) {
await invitationResult.authenticate(decodedInvitation.authCode);
} else {
const authCode = '123456'; // Take this as input from the user.
await invitationResult.authenticate(authCode);
}
};