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

rn-crypto-polyfill

v1.0.4

Published

Comprehensive crypto polyfills for React Native - provides crypto.getRandomValues, TextEncoder, TextDecoder, and ReadableStream for AWS SDK and other libraries

Readme

rn-crypto-polyfill

[npm version][npm] [license]

Comprehensive crypto polyfills for React Native applications. Provides implementations for crypto.getRandomValues, TextEncoder, TextDecoder, and ReadableStream that are required by AWS SDK and other libraries.

🚀 Features

  • crypto.getRandomValues() - Secure random number generation
  • TextEncoder - UTF-8 string encoding
  • TextDecoder - UTF-8 string decoding
  • ReadableStream - Stream API polyfill
  • TypeScript support - Full type definitions included
  • Configurable - Customize behavior via configuration
  • Lightweight - No native dependencies
  • Battle-tested - Used in production apps

📦 Installation

npm install rn-crypto-polyfill

or

yarn add rn-crypto-polyfill

🔧 Usage

Basic Usage

Import the polyfill at the very beginning of your app's entry point (usually index.js):

// index.js
import 'rn-crypto-polyfill';

import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';

AppRegistry.registerComponent(appName, () => App);

That's it! All polyfills are now available globally.

Advanced Configuration

You can customize the behavior of the polyfills:

import { configure } from 'rn-crypto-polyfill';

configure({
  enableLogging: true,      // Enable debug logging (default: false)
  useSecureRandom: true,    // Use more secure random generation (default: true)
});

🎯 Use Cases

AWS SDK S3 Operations

import 'rn-crypto-polyfill';
import { S3Client, PutObjectCommand } from '@aws-sdk/client-s3';
import { Sha256 } from '@aws-crypto/sha256-js';

const client = new S3Client({
  region: 'us-east-1',
  credentials: {
    accessKeyId: 'YOUR_ACCESS_KEY',
    secretAccessKey: 'YOUR_SECRET_KEY',
  },
  sha256: Sha256, // Required for React Native
});

// Now you can use S3 operations!

UUID Generation

import 'rn-crypto-polyfill';
import { v4 as uuidv4 } from 'uuid';

const id = uuidv4(); // Works perfectly!

Text Encoding/Decoding

const encoder = new TextEncoder();
const bytes = encoder.encode('Hello, World!');
console.log(bytes); // Uint8Array

const decoder = new TextDecoder();
const text = decoder.decode(bytes);
console.log(text); // "Hello, World!"

📋 Requirements

  • React Native >= 0.60.0
  • Node.js >= 14.0.0

🔍 What's Polyfilled?

crypto.getRandomValues()

Implements the Web Crypto API's getRandomValues() method. Uses a combination of Math.random() with XOR and timestamps for better entropy.

const array = new Uint8Array(16);
crypto.getRandomValues(array);

TextEncoder

Converts JavaScript strings to UTF-8 encoded Uint8Array.

const encoder = new TextEncoder();
const encoded = encoder.encode('Hello 👋');

TextDecoder

Converts UTF-8 encoded bytes back to JavaScript strings.

const decoder = new TextDecoder();
const decoded = decoder.decode(uint8Array);

ReadableStream

Minimal implementation of the Streams API ReadableStream. Primarily used for AWS SDK type checking.

const stream = new ReadableStream();

🤝 Compatibility

This library is compatible with:

  • ✅ AWS SDK v3 (@aws-sdk/client-s3, etc.)
  • ✅ uuid
  • ✅ crypto-js
  • ✅ Any library requiring crypto.getRandomValues
  • ✅ Any library requiring TextEncoder/TextDecoder

📝 API Reference

configure(config)

Configure the polyfill behavior.

Parameters:

  • config.enableLogging (boolean): Enable debug console logging
  • config.useSecureRandom (boolean): Use enhanced random number generation

Example:

import { configure } from 'rn-crypto-polyfill';

configure({
  enableLogging: __DEV__,
  useSecureRandom: true,
});

🐛 Troubleshooting

Polyfill not working

Make sure the import is at the very top of your entry file, before any other imports that might use crypto APIs.

❌ Wrong:

import { S3Client } from '@aws-sdk/client-s3';
import 'rn-crypto-polyfill'; // Too late!

✅ Correct:

import 'rn-crypto-polyfill'; // First!
import { S3Client } from '@aws-sdk/client-s3';

AWS SDK errors

For AWS SDK, make sure to also import the SHA256 implementation:

import { Sha256 } from '@aws-crypto/sha256-js';

const client = new S3Client({
  // ... other config
  sha256: Sha256,
});

📄 License

MIT © Binarywise

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

🙏 Acknowledgments

Inspired by the React Native community's need for Web Crypto API compatibility.

📚 See Also