trpc
tRPC v11 API layer with Zod and Ed25519 auth. Use when working on files in src/server/.
When & Why to Use This Skill
This Claude skill facilitates the development of a robust tRPC v11 API layer, integrating Zod for schema validation and Ed25519 for secure authentication. It streamlines the creation of type-safe server-side procedures, ensuring data integrity and cryptographic security within the src/server/ directory while adhering to strict architectural guidelines.
Use Cases
- Case 1: Building type-safe API routers and procedures using tRPC v11 to ensure seamless communication between frontend and backend.
- Case 2: Implementing strict input validation with Zod schemas to prevent malformed data and enhance system reliability.
- Case 3: Securing sensitive mutations with Ed25519 signature verification to authenticate requests and prevent replay attacks.
- Case 4: Standardizing error handling and permission checks across server-side modules to maintain a secure and consistent API architecture.
| name | trpc |
|---|---|
| description | tRPC v11 API layer with Zod and Ed25519 auth. Use when working on files in src/server/. |
tRPC Guidelines
Authentication
All authenticated procedures verify Ed25519 signatures:
- Verify signature matches pubkeyHash
- Verify timestamp is recent (prevent replay)
- Verify message matches request
Patterns
Router:
export const vaultRouter = router({
create: authedProcedure
.input(createVaultSchema)
.mutation(async ({ ctx, input }) => { ... }),
});
Schema:
export const createVaultSchema = z.object({
name: z.string().min(1).max(100),
encryptedSnapshot: z.string(),
wrappedKey: z.string(),
});
Critical Rules
- Never trust client data - always validate with Zod
- Never store unencrypted data - all sensitive data comes pre-encrypted
- Verify signatures - every mutation must be signed
- Check permissions - verify user has vault access
- Use transactions - wrap multi-step operations
Error Handling
throw new TRPCError({
code: "NOT_FOUND", // or "FORBIDDEN"
message: "Vault not found",
});