On this page

Guide

How to Add License Keys to a React Native or Expo App

The Keyfern JavaScript SDK runs in React Native 0.74+ and Expo. React Native’s engine (Hermes) has no built-in Ed25519, so you hand the SDK a small verifier and a place to keep the cached license.

Every answer from Keyfern is signed with your product’s Ed25519 key. The app embeds only the public key, checks the signature and a random nonce on every answer, and keeps the last signed answer so it can start offline during the lease you set.

Step 1: Install

npm install keyfern @noble/curves@1 react-native-get-random-values @react-native-async-storage/async-storage

In Expo use npx expo install for the last two packages.

No access to the npm registry? Replace keyfern with https://keyfern.com/dl/keyfern-1.1.0.tgz.

Step 2: Activate and verify

import 'react-native-get-random-values';   // load it first: random nonces need crypto.getRandomValues
import AsyncStorage from '@react-native-async-storage/async-storage';
import { ed25519 } from '@noble/curves/ed25519';
import { Keyfern, KeyfernError } from 'keyfern';

const kf = new Keyfern({
  product: 'prod_xxx',
  publicKey: '<public key from the dashboard>',   // safe to embed in your app
  verifyEd25519: (pub, sig, msg) => ed25519.verify(sig, msg, pub),
  storage: {
    get: () => AsyncStorage.getItem('keyfern.license'),
    set: v => AsyncStorage.setItem('keyfern.license', v),
    remove: () => AsyncStorage.removeItem('keyfern.license'),
  },
});

// a random id for this installation, kept with the app data
async function deviceId() {
  let id = await AsyncStorage.getItem('keyfern.id');
  if (!id) { id = Array.from(crypto.getRandomValues(new Uint8Array(16)), b => b.toString(16).padStart(2, '0')).join(''); await AsyncStorage.setItem('keyfern.id', id); }
  return id;
}

try {
  const lic = await kf.activateOrCached(userKey, await deviceId());
  if (lic.features.includes(1)) unlockPro();         // feature flag F1
} catch (e) {
  if (e instanceof KeyfernError) showLicenseProblem(e.code);   // blocked, expired, invalid_key, machine_limit...
}

The cached license is a signed answer, so plain AsyncStorage is enough: editing it breaks the signature. Offline starts are refused once lease_until has passed, or when the clock was set back more than one hour.

Capacitor and Ionic

Capacitor apps run in the system WebView. Where it has WebCrypto Ed25519 (iOS 17+, Android WebView 137+) the SDK needs nothing extra: use webStorage() for the cache. For older devices pass the same verifyEd25519 as above.

App Store and Google Play rules

Apps sold through the App Store or Google Play must sell digital content and subscriptions inside the app with Apple’s in-app purchase (StoreKit) or Google Play Billing. Keyfern keys on mobile are for licenses bought where the store rules allow it: business and enterprise apps, companion apps of software the customer already bought on the web, and licenses that cover several devices and platforms. Check the App Store Review Guidelines (payments) and the Google Play payments policy for your case before you ship.