A tiny Express server for the privacy‑first demo (handles key generation, encryption, etc.)
npm install @suman-jangili/privacy-first-server
📄 privacy‑first‑server
@suman-jangili/privacy‑first‑client).---
- Installation
- Running Locally
- API Endpoints
- Scripts Overview
- Building & Publishing
- Contributing
- License
- Related Projects
---
bash
npm install @suman-jangili/privacy-first-server
`
Or add it as a dependency in your own project
`bash
npm i @suman-jangili/privacy-first-server
`
To develop the server yourself, clone the repo and install dev dependencies:
`bash
git clone https://github.com/sumanjangili/privacy-first.git
cd privacy-first/server
npm ci # installs exact versions from lockfile
`---
$3
1. Build the TypeScript sources
`bash
npm run build
`
2. Start the server (defaults to PORT 3000)
`bash
npm start
`
3. The server will listen on http://localhost:3000. You can also use the development script for hot‑reloading:
`bash
npm run dev
`
---#### API Endpoints
Method Path Description
- GET /health Simple health check ({ ok: true }).
- POST /keypair Returns a freshly generated NaCl key pair (publicKey, secretKey).
- POST /encrypt Body: { publicKey, secretKey?, message } → Returns { ciphertext, nonce }.
- POST /decrypt Body: { publicKey, secretKey, ciphertext, nonce } → Returns { message }.
- All payloads and responses are JSON‑encoded. Errors are returned with a 400 status and an error field describing the problem.
---
#### Scripts Overview
- dev Runs ts-node-dev for live reload while developing.
- build Compiles TypeScript to dist/ (tsc).
- start Executes the compiled server (node dist/index.js).
- gen:keypair Utility script to generate a key pair from the CLI:
`bash
npm run gen:keypair
`---
$3
When you’re ready to publish a new version to npm:
1. Bump the version (patch, minor, or major)
`bash
npm version patch # → e.g., 0.1.6 → 0.1.7
`
2. Compile the code
`bash
npm run build
`
3. Publish (public)
`bash
npm publish --access public
`
The package ships type declarations (*.d.ts) automatically, so consumers get full TypeScript support.---
$3
We love contributions! Follow these steps:
1. Fork the repository.
2. Create a feature branch
`bash
git checkout -b feat/awesome-feature
`
3. Implement your change and run the test suite and lint to ensure TypeScript compiles:
`bash
npm test && npm run lint && npm run typecheck
``---
---
#### Related Projects
- Client – the React front‑end that talks to this API.
- See Full Demo Repo