Encryption

These functions allow you to encrypt/decrypt data.

Encrypt Bytes

bytes
Uint8Array
required

The byte array that you want to encrypt

import {encryptBytes} from "selfguard-client/helpers/encryption.js";

encryptBytes(bytes);

Decrypt Bytes

encrypted_bytes
Uint8Array
required

The byte array returned from encryptBytes

encryption_key
bytes
required

The encryption key returned from encryptBytes

import {decryptBytes} from "selfguard-client/helpers/encryption.js";

decryptBytes(encrypted_bytes, encryption_key)

Encrypt Value

value
string
required

The value that you want to encrypt

import {encryptValue} from "selfguard-client/helpers/encryption.js";

encryptValue(value);

Decrypt Value

encrypted_value
string
required

The value that you want to encrypt

encryption_key
bytes
required

The encryption key returned from encryptValue

import {decryptValue} from "selfguard-client/helpers/encryption.js";

decryptValue(encrypt_value, encryption_key)

Files

These functions allow you to encrypt/decrypt files, where the encryption keys are stored with Lit Protocol if metamask is enabled in the use of these functions.

Stream Encrypt Web

file
File
required

The File you want to encrypt.

public_key
string
required

If this is set to metamask, it will save the encryption key with Lit Protocol.

chunk_function
function
required

This function is called after each file shard is encrypted with three parameters encrypted_bytes, encryption_key, and shard_size.

import {streamEncryptWeb} from "selfguard-client/helpers/encryption.js";

await streamEncryptWeb(file, public_key, chunk_function);

Decrypt Shard

file
File
required

The File you want to decrypt.

encryption_key
string
required

The encryption key for this file shard returned from the chunk_function within streamEncryptWeb

public_key
string
required

If this is set to metamask, it will retrieve the encryption key with Lit Protocol. This meant that the encryption_key provided in this function was the encrypted encryption key returned from Lit during streamEncryptWeb.

import {decryptShard} from "selfguard-client/helpers/encryption.js";

await decryptShard(file, encryption_key, public_key)

Metamask

These functions allow you to perform encryption events with Metamask

Get Public Key

import {getPublicKey} from "selfguard-client/helpers/metamask.js";

await getPublicKey();

Encrypt Data

account
string
required

The address of the metamask user.

publicKey
string
required

The public key of the metamask user retrieved with getPublicKey

data
object | string
required

The data you want to decrypt.

import {encryptData} from "selfguard-client/helpers/metamask.js";

await encryptData(data,{publicKey,account})

Decrypt Data

account
string
required

The address of the metamask user.

data
object | string
required

The data you want to decrypt.

import {decryptData} from "selfguard-client/helpers/metamask.js";

await decryptData(account,data);

Lit Protocol

These functions allow you to save and retrieve encryption keys stored with lit protocol. These will automatically trigger Metamask to open and sign a condition ensuring the wallet owner is able to retrieve the encryption key.

symmetricKey
string
required

The key which you want to save with an access control restriction. Currenty this is based upon the user’s wallet ownership.

chain
string
required

The chain upon which you want to have the access condition be based on. This wil be leveraged for more complex access controls.

Save Lit Encryption Key

import {saveLitEncryptionKey} from 'selfguard-client/helpers/lit.js';

await saveLitEncryptionKey(symmetricKey, chain)

Get Lit Encryption Key

encryptedSymmetricKey
string
required

The encrypted key retrieved from saveLitEncryptionKey

chain
string
required

The chain upon which you want to have the access condition be based on. This wil be leveraged for more complex access controls.

import {getLitEncryptionKey} from 'selfguard-client/helpers/lit.js';

await getLitEncryptionKey(encryptedSymmetricKey, chain)