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 🙏

© 2026 – Pkg Stats / Ryan Hefner

expo-crypto-universal

v0.2.12

Published

Universal crypto implementation for Expo that works across all platforms including web

Readme

expo-crypto-universal

A universal crypto implementation for Expo that works across all platforms, including web. This package provides a consistent interface for crypto operations that can be implemented differently based on the platform.

Features

  • Platform-agnostic crypto interface
  • SHA-2 hashing (256, 384, 512 bits)
  • Secure random bytes generation
  • TypeScript support
  • Platform detection utility
  • Separate implementations for Web and Native platforms

Installation

# Install the main package
npm install expo-crypto-universal
# or
yarn add expo-crypto-universal

# Install platform-specific implementation
npm install expo-crypto-universal-web    # For web platform
npm install expo-crypto-universal-native # For native platforms (iOS/Android)

Dependencies

This package requires one of the following platform-specific implementations:

  • expo-crypto-universal-web for web platform
  • expo-crypto-universal-native for native platforms (iOS/Android)

Usage

import { isWeb } from 'expo-crypto-universal';
import { WebCryptoModule } from 'expo-crypto-universal-web';
import { NativeCryptoModule } from 'expo-crypto-universal-native';

// Get the appropriate crypto module for your platform
const crypto = isWeb() ? new WebCryptoModule() : new NativeCryptoModule();

// Generate random bytes
const randomBytes = crypto.getRandomBytes(32);

// Generate SHA-256 hash
const data = new TextEncoder().encode('Hello, World!');
const hash256 = await crypto.sha256Async(data);

// Generate SHA-384 hash
const hash384 = await crypto.sha384Async(data);

// Generate SHA-512 hash
const hash512 = await crypto.sha512Async(data);

// Or use the generic SHA-2 method
const hash = await crypto.sha2Async(256, data); // Same as sha256Async

API

isWeb()

Returns true if the current environment is a web environment, false otherwise.

CryptoModule Interface

The package exports a CryptoModule interface that defines the contract for crypto implementations:

interface CryptoModule {
  getRandomValues(values: Uint8Array): Uint8Array;
  getRandomBytes(size: number): Uint8Array;
  sha256Async(data: Uint8Array): Promise<Uint8Array>;
  sha384Async(data: Uint8Array): Promise<Uint8Array>;
  sha512Async(data: Uint8Array): Promise<Uint8Array>;
  sha2Async(bits: number, data: Uint8Array): Promise<Uint8Array>;
}

getRandomValues(values: Uint8Array): Uint8Array

Fills the provided Uint8Array with cryptographically secure random values.

getRandomBytes(size: number | undefined): Uint8Array

Generates a new Uint8Array of specified size filled with cryptographically secure random bytes. If no size is specified, it defaults to 32 bytes.

sha256Async(data: Uint8Array): Promise<Uint8Array>

Computes the SHA-256 hash of the input data.

sha384Async(data: Uint8Array): Promise<Uint8Array>

Computes the SHA-384 hash of the input data.

sha512Async(data: Uint8Array): Promise<Uint8Array>

Computes the SHA-512 hash of the input data.

sha2Async(bits: number, data: Uint8Array): Promise<Uint8Array>

Computes the SHA-2 hash of the input data with the specified number of bits (256, 384, or 512).

Platform Support

The package provides platform-specific implementations:

  • Web: expo-crypto-universal-web using Web Crypto API
  • Native (iOS/Android): expo-crypto-universal-native using Expo's native crypto implementation

Testing

The package is designed to work seamlessly with Vitest. No special configuration is required as the platform-specific implementations are now separate packages.

License

MIT