Clavem

Selling and licensing an Electron app with Stripe

In an Electron app the license check belongs in the main process, not the renderer. Store the key with safeStorage, verify Clavem's signed token with node:crypto, and treat the check as a speed bump, because JavaScript in an app bundle can be edited.

Where the check runs

An Electron app is a Chromium renderer plus a Node main process. Put the licensing module in the main process. The renderer is a web page; if it holds the key, a compromised page, an extension or a stray webview can read it. Expose one channel through the preload script and have it return only a state: licensed, invalid, needs-network or unlicensed.

The License API answers with Access-Control-Allow-Origin: *, so a renderer fetch would work. Being able to is not a reason to. Main-process requests also avoid CORS preflights and let you retry without UI.

Storing the key

Electron’s safeStorage encrypts a string with a key held by the operating system. The docs describe the three cases that matter:

  • macOS keeps the encryption key in the Keychain.
  • Windows uses DPAPI, which protects data from other users of the machine but not from other apps run by the same user.
  • Linux uses a secret store that depends on the desktop, such as KWallet or GNOME’s libsecret. If none is available, items are encrypted with a hardcoded plaintext password, and getSelectedStorageBackend() returns basic_text.

Check for basic_text and decide what you accept. For a license key, an obscured file is better than nothing, but do not promise secrecy you do not have. The docs also say the synchronous API is deprecated and will be removed in Electron 46, with async versions provided, so write new code against those.

Verifying the signed token

Clavem’s token is an Ed25519 signature over a small JSON payload. Electron 37 and later support Ed25519 in Web Crypto; node:crypto handles it in every supported Electron and Node version, which is why the Electron guide uses it. Check the signature, then pid, valid, exp and refresh_by, as on the offline page. Ship the product’s public key inside the app: it is not a secret.

The honest limit of an Electron check

Everything in the app bundle can be read and changed by the person who installed it. Electron offers fuses that make tampering harder, such as validating the contents of app.asar on macOS and Windows, and they are worth turning on. They raise the effort; they do not make a patch impossible. Design the check to be proportionate: a customer who pays, enters a key and never thinks about it should have no friction, and someone determined to bypass it will not be stopped by more code. The piracy article makes that case.

Updates

Electron’s autoUpdater supports macOS and Windows only; there is no built-in support on Linux. On macOS the app must be signed. Clavem’s releases endpoint returns JSON with the latest version and signed download links, which is not the feed format autoUpdater or electron-updater expects. Three workable options:

  1. Check the endpoint at launch and show “Version 3.2.0 is available” with a button that opens the download, the simplest flow.
  2. Put a small endpoint of your own in front that calls Clavem and answers in the updater’s format.
  3. Use your own update host for the files and keep Clavem for the key check only.

Request the download link when the customer clicks, not when the check runs: links last an hour.

Setting Suggested value Why
License type Perpetual with paid major versions, or a subscription A subscription pays for continuous releases; perpetual suits a slower cadence
Device limit 3 A work machine, a personal machine, a spare
Trial 14 days in the app, or a time-limited key An app-side trial needs no license until purchase
Updates Check at launch, notify, open the download Works on all three systems without a feed format

Mac App Store builds

An Electron app packaged for the Mac App Store falls under Apple’s rule against license keys there. Ship a separate direct build for keyed sales. The macOS page has the guideline text.

Doing this with Clavem

Create a product, connect Stripe, map your Stripe product, and copy the product’s public key and id into the app. The activation call needs an instance_name, which os.hostname() supplies, and a fingerprint; the Electron guide uses node-machine-id for it. Without a fingerprint, reinstalling on the same machine uses another seat until the customer removes the old one on the device page.

Guides to follow

Questions

Should the renderer process call the License API?

It can, because the License API allows cross-origin requests, but it should not. Keep the key, the instance id and the token in the main process and let the renderer ask a narrow IPC channel such as license:check for the result.

Can I use Electron's autoUpdater with Clavem releases?

Use the releases endpoint to detect a new version and gate the download. autoUpdater and electron-updater read their own feed formats, so either serve those from a small endpoint of your own or open the download page.

Sources

  1. Electron safeStorage API (checked November 2026)
  2. Electron autoUpdater API (checked November 2026)
  3. Electron fuses, ASAR integrity (checked November 2026)