Skip to content

Installation

npm install @muhkoo/connect

ZK login generates a Groth16 proof, which needs snarkjs. It’s imported lazily — you only need it installed if your app calls client.auth.zk.login() / register():

Terminal window
npm install snarkjs

Apps that only read public data or act as a relay don’t need it.

@muhkoo/connect ships three builds, selected automatically by your bundler via the package’s exports map:

EnvironmentNotes
BrowserThe primary target. Needs WebCrypto (every modern browser).
Node 20+globalThis.fetch + WebCrypto are built in.
Edge / serverless runtimesA trimmed build (the edge can’t run snarkjs); use it for verification + relay logic, not ZK proof generation.
import { Client } from "@muhkoo/connect";
const client = new Client({
apiKey: "mk_test_pk_…", // app / publishable key
// baseUrl is optional — it defaults to the hosted accelerator
// (https://api.muhkoo.dev). Set it only to target staging or self-hosting.
});
OptionTypeRequiredDescription
apiKeystringrecommendedApp key. Authenticates + meters the app. See app keys.
baseUrlstringnoAbsolute URL of the accelerator. Defaults to the hosted accelerator (https://api.muhkoo.dev).
circuits{ wasmUrl, zkeyUrl }noZK circuit assets. Defaults to ${baseUrl}/circuits/build/preimagePoK{.wasm,_0001.zkey}.
sessionStoreSessionStorenoToken persistence. Defaults to in-memory; use a localStorage-backed store in browsers.
fetchtypeof fetchnoCustom fetch (tests, proxies).
logLevelstringnoSDK log verbosity.

By default the session lives in memory. To keep users signed in across page reloads, pass a localStorage-backed sessionStore:

import { Client, type SessionStore, type StoredSession } from "@muhkoo/connect";
const localStorageStore: SessionStore = {
load: () => {
const raw = localStorage.getItem("muhkoo.session");
return raw ? (JSON.parse(raw) as StoredSession) : null;
},
save: (s) => localStorage.setItem("muhkoo.session", JSON.stringify(s)),
clear: () => localStorage.removeItem("muhkoo.session"),
};
const client = new Client({ apiKey, baseUrl, sessionStore: localStorageStore });

Then call await client.auth.zk.restore() on boot — see Authentication.