Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

685 B
Raw Blame
/* The stable per-profile pseudonym a payload carries instead of the uid: never the uid, never
 * reversible, the same across jobs. Keyed on the instance secret so two instances never mint
 * the same handle for the same uid. Node-only — the phone mints its own random handle. */
import crypto from 'node:crypto';
import fs from 'node:fs';
import path from 'node:path';

const DATA = process.env.DATA_DIR || '/data';

export const HANDLE_LENGTH = 16;

export function handleFor(uid) {
  const secret = fs.readFileSync(path.join(DATA, 'secret'), 'utf8').trim();
  return crypto.createHmac('sha256', secret).update('coach-handle:' + uid).digest('base64url').slice(0, HANDLE_LENGTH);
}