|
| 1 | +import fastify, { FastifyInstance } from "fastify"; |
| 2 | +import swagger from "@fastify/swagger"; |
| 3 | +import swaggerUi from "@fastify/swagger-ui"; |
| 4 | +import { W3ID } from "w3id"; |
| 5 | +import { |
| 6 | + WatcherSignatureRequest, |
| 7 | + WatcherRequest, |
| 8 | + TypedRequest, |
| 9 | + TypedReply, |
| 10 | +} from "./types"; |
| 11 | + |
| 12 | +export async function registerHttpRoutes( |
| 13 | + server: FastifyInstance |
| 14 | +): Promise<void> { |
| 15 | + // Register Swagger |
| 16 | + await server.register(swagger, { |
| 17 | + swagger: { |
| 18 | + info: { |
| 19 | + title: "eVault Core API", |
| 20 | + description: "API documentation for eVault Core HTTP endpoints", |
| 21 | + version: "1.0.0", |
| 22 | + }, |
| 23 | + tags: [ |
| 24 | + { name: "identity", description: "Identity related endpoints" }, |
| 25 | + { |
| 26 | + name: "watchers", |
| 27 | + description: "Watcher signature related endpoints", |
| 28 | + }, |
| 29 | + ], |
| 30 | + }, |
| 31 | + }); |
| 32 | + |
| 33 | + await server.register(swaggerUi, { |
| 34 | + routePrefix: "/docs", |
| 35 | + }); |
| 36 | + |
| 37 | + // Whois endpoint |
| 38 | + server.get( |
| 39 | + "/whois", |
| 40 | + { |
| 41 | + schema: { |
| 42 | + tags: ["identity"], |
| 43 | + description: "Get W3ID response with logs", |
| 44 | + response: { |
| 45 | + 200: { |
| 46 | + type: "object", |
| 47 | + properties: { |
| 48 | + w3id: { type: "object" }, |
| 49 | + logs: { |
| 50 | + type: "array", |
| 51 | + items: { type: "object" }, |
| 52 | + }, |
| 53 | + }, |
| 54 | + }, |
| 55 | + }, |
| 56 | + }, |
| 57 | + }, |
| 58 | + async (request: TypedRequest<{}>, reply: TypedReply) => { |
| 59 | + // TODO: Implement actual W3ID verification and log retrieval |
| 60 | + const w3id = new W3ID({} as any); // TODO: Add proper W3ID initialization |
| 61 | + return { |
| 62 | + w3id: w3id, |
| 63 | + logs: [], // TODO: Implement log retrieval |
| 64 | + }; |
| 65 | + } |
| 66 | + ); |
| 67 | + |
| 68 | + // Watchers signature endpoint |
| 69 | + server.post<{ Body: WatcherSignatureRequest }>( |
| 70 | + "/watchers/sign", |
| 71 | + { |
| 72 | + schema: { |
| 73 | + tags: ["watchers"], |
| 74 | + description: "Post a signature for a specific log entry", |
| 75 | + body: { |
| 76 | + type: "object", |
| 77 | + required: ["w3id", "signature", "logEntryId"], |
| 78 | + properties: { |
| 79 | + w3id: { type: "string" }, |
| 80 | + signature: { type: "string" }, |
| 81 | + logEntryId: { type: "string" }, |
| 82 | + }, |
| 83 | + }, |
| 84 | + response: { |
| 85 | + 200: { |
| 86 | + type: "object", |
| 87 | + properties: { |
| 88 | + success: { type: "boolean" }, |
| 89 | + message: { type: "string" }, |
| 90 | + }, |
| 91 | + }, |
| 92 | + }, |
| 93 | + }, |
| 94 | + }, |
| 95 | + async ( |
| 96 | + request: TypedRequest<WatcherSignatureRequest>, |
| 97 | + reply: TypedReply |
| 98 | + ) => { |
| 99 | + const { w3id, signature, logEntryId } = request.body; |
| 100 | + // TODO: Implement signature verification and storage |
| 101 | + return { |
| 102 | + success: true, |
| 103 | + message: "Signature stored successfully", |
| 104 | + }; |
| 105 | + } |
| 106 | + ); |
| 107 | + |
| 108 | + // Watchers request endpoint |
| 109 | + server.post<{ Body: WatcherRequest }>( |
| 110 | + "/watchers/request", |
| 111 | + { |
| 112 | + schema: { |
| 113 | + tags: ["watchers"], |
| 114 | + description: "Request signature for a log entry", |
| 115 | + body: { |
| 116 | + type: "object", |
| 117 | + required: ["w3id", "logEntryId"], |
| 118 | + properties: { |
| 119 | + w3id: { type: "string" }, |
| 120 | + logEntryId: { type: "string" }, |
| 121 | + }, |
| 122 | + }, |
| 123 | + response: { |
| 124 | + 200: { |
| 125 | + type: "object", |
| 126 | + properties: { |
| 127 | + success: { type: "boolean" }, |
| 128 | + message: { type: "string" }, |
| 129 | + requestId: { type: "string" }, |
| 130 | + }, |
| 131 | + }, |
| 132 | + }, |
| 133 | + }, |
| 134 | + }, |
| 135 | + async (request: TypedRequest<WatcherRequest>, reply: TypedReply) => { |
| 136 | + const { w3id, logEntryId } = request.body; |
| 137 | + // TODO: Implement signature request logic |
| 138 | + return { |
| 139 | + success: true, |
| 140 | + message: "Signature request created", |
| 141 | + requestId: "req_" + Date.now(), |
| 142 | + }; |
| 143 | + } |
| 144 | + ); |
| 145 | +} |
0 commit comments