A minimal Node.js/TypeScript project, plus a small Vite browser app, for following the dStorage SDK guides. Clone it and run it, then swap in each guide's adapters as you work through the series. You can also use it as boilerplate for your own app.
- Node.js 22 or later
- npm
git clone https://github.com/dStorageTech/dstorage-starter-template.git
cd dstorage-starter-template
npm install
npm startOut of the box, npm start runs the code from the
Mock Adapters guide. It configures the SDK with
in-memory adapters, stores an encrypted string, retrieves and decrypts it, and prints the result.
No external services are needed.
| Path | Purpose |
|---|---|
src/index.ts |
Node.js entry point (npm start): Mock, Local & Simulator, and Managed Payments guides |
index.html, src/main.ts |
Browser entry point (npm run dev): Midnight Network Adapter, Passkey Encryption, and Managed Payments on Midnight guides |
scripts/copy-zk-artifacts.mjs |
Copies the DataRegistry contract's ZK artifacts (keys/, zkir/, compiler/) into public/ before npm run dev and npm run build |
scripts/clean.mjs |
npm run clean: removes node_modules/, dist/ and the copied ZK artifacts in public/ (keeps package-lock.json) |
vite.config.ts |
Vite plugins the Midnight SDK needs in the browser (WASM, top-level await, Node polyfills) |
| Guide | Entry point | Run with |
|---|---|---|
| Build with AI | any | (prompts for your coding agent) |
| Mock Adapters | src/index.ts |
npm start |
| Core Concepts | conceptual only | (nothing to run) |
| Local & Simulator Adapters | src/index.ts |
npm start |
| Managed Payments Service | src/index.ts |
npm start |
| Midnight Network Adapter | src/main.ts |
npm run dev |
| Passkey Encryption | src/main.ts |
npm run dev |
| Managed Payments on Midnight | src/main.ts |
npm run dev |
Each Node.js guide uses a different combination of adapters, but main() keeps the same shape:
configure, init(), store(), retrieveByRefId(), destroy(). Replace the adapters in
src/index.ts with the ones from the guide you're on. Some guides need local services, such as
arlocal; each guide's Prerequisites section lists them.
The Midnight Network Adapter, Passkey Encryption, and Managed Payments on Midnight guides run in the browser, because they connect to a Midnight wallet extension (1AM by default, or Lace):
npm run devThis copies the compiled DataRegistry contract's ZK artifacts (keys/, zkir/ and
compiler/) from the installed SDK into public/, starts a Vite dev server, and serves a page
with a Run button. The button runs the same init() → store() → retrieveByRefId()
sequence. Before you click it, set up the proof server, arlocal, and the
wallet as described in the guide's Prerequisites section.
npm run build copies the same artifacts and creates a production bundle in dist/, with the
artifacts at its root. Deploy all of dist/: the app fetches the artifacts from its own origin
(zkConfigBaseUrl in src/main.ts), and the Midnight SDK refuses to run without compiler/.
The copied folders are gitignored and re-copied on every run, so after upgrading the SDK just run
npm run dev or npm run build again.
Never commit secrets such as a dStorage Pro ds_* auth token (used by the Managed Payments
Service guide). In Node.js, load them from environment variables instead, for example
authToken: process.env.DSTORAGE_AUTH_TOKEN. .env files are already gitignored.
Never put a ds_* token in browser code (src/main.ts): anything there ships in the bundle. The
Managed Payments on Midnight guide uses a scoped JWT token from the dStorage Pro portal instead,
which is designed to be embedded in a browser app.