Installation
This content is for the 0.2.0-alpha.3 version. Switch to the latest version for up-to-date documentation.
Install
Section titled “Install”npm install @muhkoo/connect pnpm add @muhkoo/connect yarn add @muhkoo/connect Optional peer dependency: snarkjs
Section titled “Optional peer dependency: snarkjs”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():
npm install snarkjsApps that only read public data or act as a relay don’t need it.
Runtime support
Section titled “Runtime support”@muhkoo/connect ships three builds, selected automatically by your bundler
via the package’s exports map:
| Environment | Notes |
|---|---|
| Browser | The primary target. Needs WebCrypto (every modern browser). |
| Node 20+ | globalThis.fetch + WebCrypto are built in. |
| Edge / serverless runtimes | A trimmed build (the edge can’t run snarkjs); use it for verification + relay logic, not ZK proof generation. |
Configure the client
Section titled “Configure the client”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.});| Option | Type | Required | Description |
|---|---|---|---|
apiKey | string | recommended | App key. Authenticates + meters the app. See app keys. |
baseUrl | string | no | Absolute URL of the accelerator. Defaults to the hosted accelerator (https://api.muhkoo.dev). |
circuits | { wasmUrl, zkeyUrl } | no | ZK circuit assets. Defaults to ${baseUrl}/circuits/build/preimagePoK{.wasm,_0001.zkey}. |
sessionStore | SessionStore | no | Token persistence. Defaults to in-memory; use a localStorage-backed store in browsers. |
fetch | typeof fetch | no | Custom fetch (tests, proxies). |
logLevel | string | no | SDK log verbosity. |
Persisting sessions across reloads
Section titled “Persisting sessions across reloads”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.