The Ed25519 check itself is the same in every Rust program, so it lives on offline verification in Rust: Verifier::new, claims, check and the Check enum. This page does not repeat it. It covers what Tauri adds: where the key and token live in a Tauri build, how the webview learns the result, and a countdown for the 14-day window. The online call that refreshes the token is in license key validation in Tauri.
Why verify in Rust
A Tauri window is a system webview: WKWebView on macOS, WebView2 on Windows and WebKitGTK on Linux. Which Web Crypto algorithms it supports depends on the version of the operating system’s webview, which you do not control. A Rust verifier is the same on every machine, and it keeps the token and the result out of scripts that run in the page. Be honest about the limit: the front end and the Rust code both ship in a binary on the customer’s machine, so a determined user can patch either. The signature makes a forged or edited token fail, and refresh_by makes a stale one fail. It cannot defend against a patched executable.
Compile the public key into the build
The public key is safe to ship. Read it at compile time so a missing key fails the build, not a customer’s launch:
// The CI job sets CLAVEM_PUBLIC_KEY and CLAVEM_PRODUCT_ID from your product page.
const PUBLIC_KEY: &str = env!("CLAVEM_PUBLIC_KEY");
const PRODUCT_ID: u64 = match u64::from_str_radix(env!("CLAVEM_PRODUCT_ID"), 10) {
Ok(id) => id,
Err(_) => panic!("CLAVEM_PRODUCT_ID must be a number"),
};
env! stops compilation if the variable is unset, and the match turns a typo in the id into a compile error. Verifier::new trims the key and returns None unless it decodes to 32 bytes, so build the verifier once in setup and keep it in managed state.
A status for the webview
The webview does not need claims. It needs “licensed or not”, why, and how long the offline window has left. This function reads the token from a file, runs check, and keeps the clock-rollback guard from the Rust page in a second file:
use serde::Serialize;
use std::{fs, io, path::Path};
#[derive(Serialize)]
#[serde(rename_all = "camelCase")]
pub struct OfflineStatus {
pub ok: bool,
pub reason: Check, // add #[derive(Serialize)] and #[serde(rename_all = "kebab-case")] to Check
/// Days, rounded up, until the app must validate online again. Negative when it already must.
pub days_left: Option<i64>,
}
pub fn offline_status(dir: &Path, verifier: &Verifier, now: i64) -> OfflineStatus {
let token = fs::read_to_string(dir.join("license.token")).unwrap_or_default();
let highest = fs::read_to_string(dir.join("highest_iat")).ok().and_then(|s| s.trim().parse().ok()).unwrap_or(0);
let reason = verifier.check(token.trim(), now, highest);
let claims = verifier.claims(token.trim()).ok();
let days_left = claims.as_ref().map(|c| (c.refresh_by - now + 86_399).div_euclid(86_400));
if let (Check::Ok, Some(c)) = (&reason, &claims) {
let _ = write_atomic(&dir.join("highest_iat"), &c.iat.to_string());
}
OfflineStatus { ok: reason == Check::Ok, reason, days_left }
}
fn write_atomic(path: &Path, text: &str) -> io::Result<()> {
let tmp = path.with_extension("tmp");
fs::write(&tmp, text)?;
fs::rename(tmp, path)
}
#[tauri::command]
pub fn offline_status_cmd(app: tauri::AppHandle, verifier: tauri::State<'_, Verifier>) -> Result<OfflineStatus, String> {
use tauri::Manager;
let dir = app.path().app_data_dir().map_err(|e| e.to_string())?;
let now = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_err(|e| e.to_string())?.as_secs() as i64;
Ok(offline_status(&dir, &verifier, now))
}
The guard file only moves forward. In this sketch it is rewritten on every Ok, which is cheap at launch. Write the guard only from a token that passed, or a bad token could raise it. The token file itself is written by the validate path, with the same atomic write, whenever Clavem answers.
Test results
offline_status run with the test tokens from the Rust page, the verifier built from the matching public key, outside Tauri. The JSON is what the webview receives:
good {"ok":true,"reason":"ok","daysLeft":14}
stale {"ok":false,"reason":"stale","daysLeft":-6}
expiredExp {"ok":false,"reason":"expired","daysLeft":14}
tampered {"ok":false,"reason":"bad-signature","daysLeft":null}
wrongProduct {"ok":false,"reason":"wrong-product","daysLeft":14}
clock back {"ok":false,"reason":"clock-set-back","daysLeft":15}
no file {"ok":false,"reason":"malformed","daysLeft":null}
daysLeft stays at 14 for an expired exp: it counts only the refresh_by window, so show the reason first.
Show the countdown
A customer on a plane should see a warning before the lock, not after:
import { invoke } from '@tauri-apps/api/core';
const status = await invoke('offline_status_cmd');
if (status.ok && status.daysLeft <= 3) {
showBanner(`Connect to the internet within ${status.daysLeft} days to keep your license active.`);
} else if (!status.ok && status.reason === 'stale') {
showDialog('Your license needs to be checked online. Connect and restart the app.');
}
Call it at launch and when the window regains focus. It reads two small files and does no network I/O.
Traps in Tauri
- Do not verify in two places. If the webview also checks a token in JavaScript, the two checks can disagree after an operating-system update. Keep one.
app_data_dircan fail. It returns aResult, so surface the error, not an empty status.- A signed token holds the buyer’s email in plain text. Keep it out of
console.logand out of crash reports. - Windows and Linux paths differ, which is why the code takes the directory from Tauri’s path resolver and never builds one.
Doing this with Clavem
Each product has its own key pair. The public key is on the product page and in GET /v1/admin/products, and every activate and validate response carries a token signed with the private half. See the offline verification reference for the claims and the API reference for the endpoints.
Questions
Should a Tauri app verify the license token in JavaScript or Rust?
In Rust. The ed25519-dalek check does not depend on which webview engine the customer's operating system ships, and the public key and the result stay out of page scripts. WebCrypto support for Ed25519 differs between webview versions.
Can the check be bypassed in a Tauri app?
Anyone who controls the machine can patch the binary, so no offline check is tamper-proof. The signature stops a forged or edited token, and the refresh date stops an old one. It does not stop a patched executable.
Where should the token file go?
In the app data directory that Tauri's path resolver returns. The token is signed, not secret, so a plain file is fine. Keep the license key itself in the keyring.