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

react-native-otp-detector

v0.2.0

Published

Automatic OTP/SMS detection on Android via both the SMS User Consent API and the SMS Retriever API, with an app-signature-hash helper.

Readme

react-native-otp-detector

Automatic OTP/SMS detection on Android using Google Play services. It supports both of Google's SMS verification APIs in a single package:

  • SMS User Consent API — shows a one-tap dialog asking the user to share a single incoming SMS. No app hash, no special SMS format, works with any sender.
  • SMS Retriever API — fully automatic, zero user interaction. Requires your 11-character app signature hash to be embedded in the SMS and the message to follow Google's format.

Both modes deliver the extracted OTP through the same onSmsReceived event and report problems through onOtpError.

iOS: there is no programmatic equivalent on iOS. All functions are safe no-ops there. Use the system one-time-code autofill instead by setting textContentType="oneTimeCode" on your OTP TextInput.

Installation

npm install react-native-otp-detector

For bare React Native projects, ensure you have installed and configured expo modules. Then run npx pod-install (the iOS side is a no-op but the pod must be present).

Which API should I use?

| | SMS User Consent | SMS Retriever | | --- | --- | --- | | User interaction | One-tap dialog | None (automatic) | | App signature hash | Not required | Required | | SMS format | Any | Must end with the app hash, ≤ 140 bytes | | Control over SMS body | Not needed | You must control it | | Sender filtering | Optional | N/A |

Use Consent when you don't control the SMS format. Use Retriever when your backend can append the app hash and format the message.

Usage

SMS User Consent API

import { useEffect } from "react";
import { Platform } from "react-native";
import OtpDetector from "react-native-otp-detector";

useEffect(() => {
  const received = OtpDetector.addListener("onSmsReceived", ({ otp, message }) => {
    console.log("OTP:", otp, "from message:", message);
    // setOtp(otp)
  });
  const error = OtpDetector.addListener("onOtpError", ({ message }) => {
    console.warn("OTP error:", message);
  });

  if (Platform.OS === "android") {
    // Listen first, then trigger your backend to send the SMS.
    OtpDetector.startSmsConsent({ otpLength: 6 });
  }

  return () => {
    received.remove();
    error.remove();
    OtpDetector.stopListening();
  };
}, []);

SMS Retriever API

if (Platform.OS === "android") {
  OtpDetector.startSmsRetriever({ otpLength: 6 });
}

Your SMS must contain the OTP and end with the app hash, for example:

<#> Your code is 123456
FA+9qCX9VSu

Getting your app signature hash (Retriever only)

const hashes = OtpDetector.getAppSignatureHash();
console.log(hashes); // e.g. ["FA+9qCX9VSu"]

There is one hash per signing certificate, so your debug and release builds produce different hashes — make sure your production SMS uses the release hash.

API

| Method | Description | | --- | --- | | startSmsConsent(options?) | Start the User Consent flow. options: { senderPhoneNumber?, otpLength?, otpRegex? }. | | startSmsRetriever(options?) | Start the automatic Retriever flow. options: { otpLength?, otpRegex? }. | | getAppSignatureHash() | Returns string[] of app signature hashes (empty on iOS). | | stopListening() | Unregister the SMS receiver and stop listening. | | addListener("onSmsReceived", cb) | cb({ otp, message }) when an OTP is detected. | | addListener("onOtpError", cb) | cb({ message }) on timeout, denied consent, or no OTP found. |

OTP extraction defaults to any 4–8 digit sequence. Pass otpLength for an exact length, or otpRegex for full control.

Contributing

Contributions are very welcome! Please open an issue or PR on the repository.