Skip to content

@seald-io/react-native-accelerator

This module is a package for the Seald SDK : @seald-io/sdk.

The @seald-io/react-native-accelerator module exposes helper functions to greatly accelerate file encryption and decryption while using the Seald SDK in a React-Native application. Encrypting and decrypting files natively allows for much better memory management.

The package exposes four functions: encryptString, decryptString, encryptURI, decryptURI. These functions need an encryption session to be used.

Example:

javascript
import SealdSDK from '@seald-io/sdk/react-native/seald-sdk-react-native.bundle.js' // Seald SDK bundle for react native
import { encryptString, decryptString, encryptURI, decryptURI } from '@seald-io/react-native-accelerator' // accelerator functions

const seald = SealdSDK({
  appId,
  apiURL
})

// Creating a Seald identity
await seald.initiateIdentity({ signupJWT })
// Creating an encryption session
const encryptionSession = await sdk.createEncryptionSession({})

// Encrypt file from an URI
const encryptedFileUri = await encryptURI(URI_TO_ENCRYPT, FILENAME, encryptionSession)
// Decrypt file from an URI
const decryptedFileObject = await decryptURI(URI_TO_DECRYPT, encryptionSession)
// `decryptedFileObject.path`: URI to the decrypted file
// `decryptedFileObject.filename`: decrypted file name

// File already loaded in JS engine
const filename = 'myFilename.ext'
const fileContent = 'File data as string.'

// Encrypt file
const encryptedFile = await encryptString(fileContent, filename, encryptionSession)

// Decrypt the encrypted string:
const clearFile = await decryptString(encryptedFile, encryptionSession)
// `decryptedFileObject.fileContent`: content of the decrypted file
// `decryptedFileObject.filename`: decrypted file name

Table of contents

Type Aliases

Functions

Type Aliases

ClearFileString

Ƭ ClearFileString: Object

Type declaration

NameTypeDescription
fileContentstringContent of the decrypted file as Base64 encoded string
filenamestringName of the decrypted file
messageIdstringId of the encryptionSession used to encrypt the file

ClearFileURI

Ƭ ClearFileURI: Object

Type declaration

NameTypeDescription
filenamestringName of the decrypted file
messageIdstringId of the encryptionSession used to encrypt the file
pathstringURI of the decrypted file

Functions

decryptFileAsString

decryptFileAsString(fileContent, encryptionSession): Promise<ClearFileString>

Try to decrypt fileContent, using the EncryptionSession. Return a ClearFileString object.

Parameters

NameTypeDescription
fileContentstringBase64 encoded string
encryptionSessionEncryptionSession

Returns

Promise<ClearFileString>


decryptFileURI

decryptFileURI(fileURI, encryptionSession): Promise<ClearFileURI>

Try to decrypt the file at the given fileURI, using the EncryptionSession. Return a ClearFileURI object.

Parameters

NameType
fileURIstring
encryptionSessionEncryptionSession

Returns

Promise<ClearFileURI>


encryptFileAsString

encryptFileAsString(fileContent, filename, encryptionSession): Promise<string>

Encrypt fileContent, with fileName, using the EncryptionSession, and return the encrypted file as a Base64 encoded string.

Parameters

NameTypeDescription
fileContentstringMust be a base64 encoded string
filenamestring
encryptionSessionEncryptionSession

Returns

Promise<string>


encryptFileURI

encryptFileURI(fileURI, filename, encryptionSession): Promise<string>

Encrypt the file at the given fileURI, with filename, using the EncryptionSession. Return the URI of the encrypted file.

Parameters

NameType
fileURIstring
filenamestring
encryptionSessionEncryptionSession

Returns

Promise<string>