encrypt()

Othent JS SDK encrypt() function

The encrypt() function encrypts the data using the active user's private key so that, when stored on Arweave, it is only accessible to that specific user, similarly to the Web Crypto API's encrypt().

This is useful for applications such as private file storage apps or mail/messaging platforms.

API

encrypt(plaintext: string | BinaryDataType): Promise<Uint8Array>;

plaintext: string | BinaryDataType

The data to be encrypted with the user's private key, which can be of type string, ArrayBuffer, TypedArray or DataView.

return Promise<Uint8Array>

A Promise containing the encrypted data as Uint8Array.

Example usage

import { Othent } from "@othent/kms";

const othent = new Othent({ appInfo, throwErrors: false, ... });

// Make sure the user is authenticated, or prompt them to authenticate:
await othent.requireAuth();

// Encrypt data using RSA:
const encrypted = await othent.encrypt("This message will be encrypted");

console.log("Encrypted bytes:", encrypted);

Last updated