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

sodium-react-native-direct

v0.4.4

Published

React native wrapper for libsodium crypto library

Downloads

337

Readme

sodium-react-native

A port of Frank Denis' libsodium cryptography library for React Native. This library is intended to be a drop-in replacement for pre-existing NodeJs and JavaScript ports.

Only a subset of the functions have been exposed, however, contributions are most welcome.

Notes

The goal of this project is to be thin, stable, unopionated wrapper around libsodium.

All methods exposed are more or less a direct translation of the libsodium C API. This means that most data types are buffers and you have to manage allocating return values and passing them in as arguments instead of receiving them as return values.

This makes this API harder to use than other libsodium wrappers out there, but also means that you'll be able to get a lot of performance / memory improvements as you can do stuff like inline encryption / decryption, re-use buffers etc.

Installation

npm install sodium-react-native-direct

Usage

import sodium from "sodium-react-native-direct";

const key = sodium_malloc(sodium.crypto_kdf_KEYBYTES)
const subkey = sodium_malloc(sodium.crypto_kdf_BYTES_MAX)
const ctx = sodium_malloc(sodium.crypto_kdf_CONTEXTBYTES

sodium.crypto_kdf_keygen(key);
sodium.crypto_kdf_derive_from_key(subkey, 1, ctx, key)

Use as a drop-in for sodium-universal

In your metro.config.js add a mapping to resolve modules:

...

const config = {
  resolver: {
    extraNodeModules: {
      'sodium-universal': path.resolve(__dirname, './node_modules/sodium-react-native-direct'),
    },
    blacklistRE: exclusionList([
      /\/node_modules\/sodium-universal\/.*/,
    ]),
  },
};

API

Full API documentation for each method may be found under the links in each section.

crypto_aead_xchacha20poly1305

Authenticated encryption

Methods

  crypto_aead_xchacha20poly1305_ietf_keygen
  crypto_aead_xchacha20poly1305_ietf_encrypt
  crypto_aead_xchacha20poly1305_ietf_decrypt

  crypto_aead_chacha20poly1305_ietf_keygen
  crypto_aead_chacha20poly1305_ietf_encrypt
  crypto_aead_chacha20poly1305_ietf_decrypt

Constants

  crypto_aead_xchacha20poly1305_ietf_KEYBYTES
  crypto_aead_xchacha20poly1305_ietf_NPUBBYTES
  crypto_aead_xchacha20poly1305_ietf_ABYTES

  crypto_aead_chacha20poly1305_ietf_KEYBYTES
  crypto_aead_chacha20poly1305_ietf_NPUBBYTES
  crypto_aead_chacha20poly1305_ietf_ABYTES

Curve arithemetic

Curve25519 & Ed25519 arithmetic

Methods

  crypto_core_ed25519_scalar_random
  crypto_core_ed25519_add
  crypto_core_ed25519_sub
  crypto_core_ed25519_from_uniform

  crypto_scalarmult
  crypto_scalarmult_base

  crypto_scalarmult_ed25519
  crypto_scalarmult_ed25519_base

Clamping involves clearing the lowest 3 bits of the result, ensuring the result lies on the main subgroup of the curve. However, this breaks point inversion which is undesireable for some protcocols. See here for a more detailed explanation.

  crypto_scalarmult_ed25519_noclamp
  crypto_scalarmult_ed25519_base_noclamp

Constants

  crypto_core_ed25519_SCALARBYTES
  crypto_core_ed25519_BYTES
  crypto_core_ed25519_UNIFORMBYTES

  crypto_scalarmult_ed25519_BYTES
  crypto_scalarmult_ed25519_SCALARBYTES

crypto_pwhash

Password Hashing

Methods

  crypto_pwhash
  crypto_pwhash_async

Constants

  crypto_pwhash_BYTES_MIN
  crypto_pwhash_BYTES_MAX
  crypto_pwhash_PASSWD_MIN
  crypto_pwhash_PASSWD_MAX
  crypto_pwhash_SALTBYTES
  crypto_pwhash_OPSLIMIT_MIN
  crypto_pwhash_OPSLIMIT_MAX
  crypto_pwhash_MEMLIMIT_MIN
  crypto_pwhash_MEMLIMIT_MAX
  crypto_pwhash_ALG_DEFAULT
  crypto_pwhash_ALG_ARGON2I13
  crypto_pwhash_ALG_ARGON2ID13
  crypto_pwhash_BYTES_MIN
  crypto_pwhash_BYTES_MAX
  crypto_pwhash_PASSWD_MIN
  crypto_pwhash_PASSWD_MAX
  crypto_pwhash_SALTBYTES
  crypto_pwhash_STRBYTES
  crypto_pwhash_OPSLIMIT_MIN
  crypto_pwhash_OPSLIMIT_MAX
  crypto_pwhash_MEMLIMIT_MIN
  crypto_pwhash_MEMLIMIT_MAX
  crypto_pwhash_OPSLIMIT_INTERACTIVE
  crypto_pwhash_MEMLIMIT_INTERACTIVE
  crypto_pwhash_OPSLIMIT_MODERATE
  crypto_pwhash_MEMLIMIT_MODERATE
  crypto_pwhash_OPSLIMIT_SENSITIVE
  crypto_pwhash_MEMLIMIT_SENSITIVE

crypto_generichash

Blake2b hashing

Methods

  crypto_generichash
  crypto_generichash_init
  crypto_generichash_update
  crypto_generichash_final
  crypto_generichash_batch

Constants

  crypto_generichash_STATEBYTES
  crypto_generichash_KEYBYTES_MIN
  crypto_generichash_KEYBYTES_MAX
  crypto_generichash_BYTES
  crypto_generichash_BYTES_MIN
  crypto_generichash_BYTES_MAX

crypto_kx

Key exchange

Methods

  crypto_kx_keypair

Constants

  crypto_kx_PUBLICKEYBYTES
  crypto_kx_SECRETKEYBYTES

crypto_kdf

Key derivation

Methods

  crypto_kdf_keygen
  crypto_kdf_derive_from_key

Constants

  crypto_kdf_KEYBYTES
  crypto_kdf_BYTES_MIN
  crypto_kdf_BYTES_MAX
  crypto_kdf_CONTEXTBYTES

crypto_secretstream_xchacha20poly1305

Stream encryption

Methods

  crypto_secretstream_xchacha20poly1305_keygen
  crypto_secretstream_xchacha20poly1305_init_push
  crypto_secretstream_xchacha20poly1305_push
  crypto_secretstream_xchacha20poly1305_init_pull
  crypto_secretstream_xchacha20poly1305_pull

Constants

  crypto_secretstream_xchacha20poly1305_STATEBYTES
  crypto_secretstream_xchacha20poly1305_ABYTES
  crypto_secretstream_xchacha20poly1305_HEADERBYTES
  crypto_secretstream_xchacha20poly1305_KEYBYTES
  crypto_secretstream_xchacha20poly1305_TAGBYTES
  crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX

  crypto_secretstream_xchacha20poly1305_TAG_MESSAGE
  crypto_secretstream_xchacha20poly1305_TAG_PUSH
  crypto_secretstream_xchacha20poly1305_TAG_REKEY
  crypto_secretstream_xchacha20poly1305_TAG_FINAL

crypto_box

Sealed box encryption

Methods

  crypto_box_keypair
  crypto_box_seal
  crypto_box_seal_open

Constants

  crypto_box_SEALBYTES
  crypto_box_PUBLICKEYBYTES
  crypto_box_SECRETKEYBYTES
  crypto_box_SEEDBYTES
  crypto_box_NONCEBYTES
  crypto_box_MACBYTES

crypto_secretbox

Secret key box encryption

Methods

  crypto_secretbox_easy

randombytes_buf

Generating random data

  randombytes_buf

Padding

Padding.

  sodium_pad
  sodium_unpad

Utilities

Various helpers for securely handling memory.

  sodium_memcmp  // constant time
  sodium_memzero
  sodium_free
  sodium_malloc

License

MIT


Made with create-react-native-library