npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-native-nacl-jsi

v0.8.0

Published

Sodium for React Native with JSI binding

Downloads

26

Readme

react-native-nacl-jsi

Sodium library for React Native with JSI binding.

Features

  • ⚡️ High performance integration of the Sodium library written in C++
  • 🔗 Synchronous calls without the bridge, uses JSI
  • 🧩 Compatible with the new architecture

Source compilation

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.

MacOS prerequisites

  • libtool (macports, homebrew)
  • autoconf (macports, homebrew)
  • automake (macports, homebrew)
  • Xcode (12 or newer)

Android prerequisites

  • Android NDK
  • CMake
  • LLDB

Recompile

npm run rebuild

Installation

Using Hermes on Android is required.

npm install react-native-nacl-jsi
npx pod-install

Usage

Encoding/decoding

All functions takes and returns Uint8Array. There are helper functions that support encoding and decoding to and from UTF-8, hexadecimal and base64 strings.

Example

import {
  secretboxGenerateKey,
  secretboxSeal,
  secretboxOpen,
} from 'react-native-nacl-jsi';

const key = secretboxGenerateKey();
const encrypted = secretboxSeal(decodeUtf8('encrypt me'), key);
const decrypted = secretboxOpen(encrypted, key);

console.log(encodeUtf8(decrypted));

Public-key authenticated encryption (box)

Generates a random key pair for box and returns a KeyPair:

function boxGenerateKey(): KeyPair;

// With KeyPair:
type KeyPair = {
  publicKey: Uint8Array;
  secretKey: Uint8Array;
};

Encrypts and authenticates message using the recipient's public key and the sender's secret key:

function boxSeal(
  message: Uint8Array,
  recipientPublicKey: Uint8Array,
  senderSecretKey: Uint8Array
): Uint8Array;

Authenticates and decrypts the encrypted message using the sender's public key and the recipient's secret key:

function boxOpen(
  encryptedMessage: Uint8Array,
  senderPublicKey: Uint8Array,
  recipientSecretKey: Uint8Array
): Uint8Array;

Secret-key authenticated encryption (secretbox)

Generates a random key for secretbox:

function secretboxGenerateKey(): Uint8Array;

Encrypts and authenticates message using the key:

function secretboxSeal(message: Uint8Array, secretKey: Uint8Array): Uint8Array;

Authenticates and decrypts the encrypted message using the key:

function secretboxOpen(
  encryptedMessage: Uint8Array,
  secretKey: Uint8Array
): Uint8Array;

Signature

Generates a signing key pair:

function signGenerateKey(): KeyPair;

// With KeyPair:
type KeyPair = {
  publicKey: Uint8Array;
  secretKey: Uint8Array;
};

Signs a message and returns the signature:

function signDetached(
  messageToSign: Uint8Array,
  secretKey: Uint8Array
): Uint8Array;

Verifies a signature:

function signVerifyDetached(
  message: Uint8Array,
  publicKey: Uint8Array,
  signature: Uint8Array
): boolean;

Password hashing

Hash the password using the Argon2id algorithm:

function argon2idHash(
  password: Uint8Array,
  iterations: BigInt,
  memoryLimit: BigInt
): Promise<string>;

Verifies a hash and returns true if the hash matches the password:

function argon2idVerify(hash: string, password: Uint8Array): Promise<boolean>;

Key derivation

Derives the key using a salt and the Argon2id algorithm:

function argon2idDeriveKey(
  key: Uint8Array,
  salt: Uint8Array,
  keyLength: number,
  iterations: BigInt,
  memoryLimit: BigInt
): Promise<Uint8Array>;

AES256-GCM

Generates a random key to use for AES256-GCM encryption:

function aesGenerateKey(): Uint8Array;

Encrypts the message using the key and returns a AesResult:

function aesEncrypt(message: Uint8Array, key: Uint8Array): Promise<AesResult>;

// With AesResult:
type AesResult = {
  encrypted: Uint8Array;
  iv: Uint8Array;
};

Decrypts the encrypted message using the initialisation vector iv and the key:

function aesDecrypt(
  cipherText: Uint8Array,
  key: Uint8Array,
  iv: Uint8Array
): Promise<Uint8Array>;

Generates random bytes

function getRandomBytes(size: number | BigInt): Uint8Array;

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

Author

Rémy Dautriche (@remydautriche)

PACE, a private fitness tracker, implements its cryptography using react-native-nacl-jsi.

License

MIT