|
| 1 | +--- |
| 2 | +name: multisig |
| 3 | +description: Build and integrate with the Mesh Multisig (Cardano multisig wallet) codebase. Use when working on multisig wallets, bot API, v1 REST endpoints, wallet flows, governance, or Cardano treasury tooling. |
| 4 | +--- |
| 5 | + |
| 6 | +# Multisig (Mesh) |
| 7 | + |
| 8 | +## Project overview |
| 9 | + |
| 10 | +- **Stack**: Next.js (Pages Router), tRPC, Prisma, Cardano (Mesh SDK). |
| 11 | +- **Auth**: NextAuth (user) + JWT for API (wallet sign-in or bot keys). |
| 12 | +- **API**: REST v1 under `/api/v1/*` (Swagger at `/api-docs`, spec at `/api/swagger`). |
| 13 | + |
| 14 | +## Key areas |
| 15 | + |
| 16 | +| Area | Location | Notes | |
| 17 | +|------|----------|--------| |
| 18 | +| Landing page | `src/components/pages/homepage/index.tsx` | Hero, features, DApps, Developers & Bots section | |
| 19 | +| API docs (Swagger) | `src/pages/api-docs.tsx`, `src/utils/swagger.ts` | OpenAPI 3.0; add new paths in `swagger.ts` | |
| 20 | +| Bot API | `src/pages/api/v1/botAuth.ts`, `src/lib/auth/botKey.ts`, `src/lib/auth/botAccess.ts` | Bot auth: POST `/api/v1/botAuth` with `botKeyId`, `secret`, `paymentAddress` | |
| 21 | +| Reference bot client | `scripts/bot-ref/` | `bot-client.ts`; auth → walletIds, pendingTransactions, freeUtxos | |
| 22 | +| Wallet flows | `src/components/pages/homepage/wallets/new-wallet-flow/`, `useWalletFlowState.tsx` | New wallet creation and invite flow | |
| 23 | +| tRPC | `src/server/api/routers/`, `src/server/api/root.ts` | Wallets, bot routers | |
| 24 | +| DB | `prisma/schema.prisma` | Wallet, BotKey, BotUser, etc. | |
| 25 | + |
| 26 | +## Bot integration (machine-friendly) |
| 27 | + |
| 28 | +- **OpenAPI spec (JSON)**: `GET /api/swagger` — use for codegen or automation. |
| 29 | +- **Auth (bots)**: `POST /api/v1/botAuth` |
| 30 | + Body: `{ "botKeyId": string, "secret": string, "paymentAddress": string, "stakeAddress"?: string }` |
| 31 | + Response: `{ "token": string, "botId": string }`. Use `Authorization: Bearer <token>` for v1 endpoints. |
| 32 | +- **Bot keys**: Created in-app (User → Create bot). One bot key can have one `paymentAddress`; same address cannot be used by another bot. |
| 33 | +- **Scopes**: Bot keys have scope (e.g. `multisig:read`); `botAccess.ts` enforces wallet access for bots. |
| 34 | +- **V1 endpoints used by bots**: `walletIds` (query `address` = bot’s `paymentAddress`), `pendingTransactions`, `freeUtxos`, `addTransaction`, `signTransaction`, etc. Same as wallet-authenticated calls but identity is the bot’s registered address. |
| 35 | + |
| 36 | +## Conventions |
| 37 | + |
| 38 | +- **Wallet ID**: UUID from DB; **address**: Cardano payment (or stake) address. |
| 39 | +- **Scripts**: Reference scripts in `scripts/` (e.g. `scripts/bot-ref/`). Use `npx tsx` for TS scripts. |
| 40 | +- **Env**: `JWT_SECRET` required for API tokens; bot keys stored hashed in DB. |
| 41 | + |
| 42 | +## When editing |
| 43 | + |
| 44 | +- Adding a new v1 endpoint: implement in `src/pages/api/v1/<name>.ts`, add path and CORS/rate limits, then add to `src/utils/swagger.ts` and document bot usage if applicable. |
| 45 | +- Changing bot auth or scopes: update `botAuth.ts`, `botAccess.ts`, and landing “Developers & Bots” section plus `scripts/bot-ref/README.md` if needed. |
| 46 | +- Landing page: human and bot-friendly docs live in the “Developers & Bots” section; keep OpenAPI URL and bot auth summary accurate. |
0 commit comments