Sodium library for React Native with JSI binding.
- ⚡️ High performance integration of the Sodium library written in C++
- 🔗 Synchronous calls without the bridge, uses JSI
- 🧩 Compatible with the new architecture
Precompiled binaries of libsodium will be linked by default. Optionally, you can choose to compile libsodium by yourself (run npm run rebuild in package directory). Source code will be downloaded and verified before compilation.
- libtool (macports, homebrew)
- autoconf (macports, homebrew)
- automake (macports, homebrew)
- Xcode (12 or newer)
- Android NDK
- CMake
- LLDB
npm run rebuild
Using Hermes on Android is required.
npm install react-native-nacl-jsi
npx pod-install
import {
secretboxGenerateKey,
secretboxSeal,
secretboxOpen,
} from 'react-native-nacl-jsi';
const key = secretboxGenerateKey();
const encrypted = secretboxSeal('encrypt me', key);
const decrypted = secretboxOpen(encrypted, key);
Generates a random key pair for box and returns a KeyPair
:
function boxGenerateKey(): KeyPair;
// With KeyPair:
type KeyPair = {
publicKey: string;
secretKey: string;
};
Encrypts and authenticates message using the recipient's public key and the sender's secret key:
function boxSeal(
message: string,
recipientPublicKey: string,
senderSecretKey: string
): string;
Authenticates and decrypts the encrypted message using the sender's public key and the recipient's secret key:
function boxOpen(
encryptedMessage: string,
senderPublicKey: string,
recipientSecretKey
): string;
Generates a random key for secretbox:
function secretboxGenerateKey(): string;
Encrypts and authenticates message using the key:
function secretboxSeal(message: string, secretKey: string): string;
Authenticates and decrypts the encrypted message using the key:
function secretboxOpen(encryptedMessage: string, secretKey: string): string;
Generates a signing key pair:
function signGenerateKey(): KeyPair;
// With KeyPair:
type KeyPair = {
publicKey: string;
secretKey: string;
};
Signs a message and returns the signature:
function signDetached(messageToSign: string, secretKey: string): string | null;
Verifies a signature:
function signVerifyDetached(
message: string,
publicKey: string,
signature: string
): boolean;
Hash the password using the Argon2id algorithm:
function argon2idHash(
password: string,
iterations: BigInt,
memoryLimit: BigInt
): string;
Verifies a hash and returns true
if the hash matches the password:
function argon2idVerify(hash: string, password: string): boolean;
Derives the key using a salt and the Argon2id algorithm:
function argon2idDeriveKey(
key: string,
salt: string,
keyLength: number,
iterations: BigInt,
memoryLimit: BigInt
): string;
Generates a random key to use for AES256-GCM encryption:
function aesGenerateKey(): string;
Encrypts the message using the key and returns a AesResult
:
function aesEncrypt(message: string, key: string): AesResult | null;
// With AesResult:
type AesResult = {
encrypted: string;
iv: string;
};
Decrypts the encrypted message using the initialisation vector iv
and the key:
function aesDecrypt(
encryptedMessage: string,
key: string,
iv: string
): string | null;
function getRandomBytes(
size: number | BigInt,
encoding: 'base64' | 'hex' = 'base64'
): string;
See the contributing guide to learn how to contribute to the repository and the development workflow.
Rémy Dautriche (@remydautriche)
PACE, a private fitness tracker, implements its cryptography using react-native-nacl-jsi
.
MIT