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.6.0

Published

Sodium for React Native with JSI binding

Downloads

69

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

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

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

Public-key authenticated encryption (box)

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;

Secret-key authenticated encryption (secretbox)

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;

Signature

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;

Password hashing

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;

Key derivation

Derives the key using a salt and the Argon2id algorithm:

function argon2idDeriveKey(
  key: string,
  salt: string,
  keyLength: number,
  iterations: BigInt,
  memoryLimit: BigInt
): string;

AES256-GCM

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;

Generates random bytes

function getRandomBytes(
  size: number | BigInt,
  encoding: 'base64' | 'hex' = 'base64'
): string;

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