Skip to content

Getting Started

This page shows the first steps to install the Wembat Client package and use the Wembat Actions to authenticate users and encrypt data.

Setup Wembat Client

  1. Install the Wembat Client npm package
bash
npm install @wembat/client
  1. Create a Wembat Client instance with you application token create in the setup section https://wembat.dev/setup
ts
import { WembatClient } from "@wembat/client";

const wembatClient = new WembatClient(APPTOKEN);

Authenticate User

WARNING

The following functions must be triggered by a user interaction, a button click for example.

  1. Register the user in your application by calling the Register Action with a user unique identifier as string
ts
async function register() {
  const registerResponse = await wembatClient.register(userId);

  if (registerResponse.success) {
    const verified = registerResponse.result;
  }
}
  1. Login the user in your application by calling the Login Action with the given user unique identifier as string
ts
async function login() {
  const loginResponse = await wembatClient.login(uId);

  if (loginResponse.success) {
    const loginResult = loginResponse.result;

    if (loginResult.verified) {
      const token = loginResult.jwt;
    }
  }
}

Encrypt Data

ts
async function encryptMessage() {
  const encryptMessage : WembatMessage = {
    iv: "",
    message: message.text,
    encrypted: ""
  }

  # sender side
  const publicKey = wembatClient.getCryptoPublicKey();
  const encryptionResult = await wembatClient.encrypt(encryptMessage, publicKey);

  # receiver side
  const publicKey = wembatClient.getCryptoPublicKey();
  const decryptionResult = await wembatClient.decrypt(encryptedMessage, publicKey);
}

Onboard Device

INFO

Onboarding a new device enables you to authenticate and encrypt data with multiple devices. The onboard process can only be started in an active authenticated session. The device to onboard your credentials to must be registered at first hand.

ts
async function onboard() {
  const onboardResponse = await wembatClient.onboard();
  if(onboardResponse.success) {
    appendAlert("Onboarding successful", "success");
  } else {
    const errorResult = onboardResponse.error;
    appendAlert(errorResult.error, "danger");
  }
}