Skip to content

Commit 4b6a39d

Browse files
committed
feat: alloc according to entropy and namespace
1 parent 3c664a0 commit 4b6a39d

File tree

11 files changed

+753
-378
lines changed

11 files changed

+753
-378
lines changed
Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,39 @@
11
{
2-
"name": "evault-core",
3-
"version": "0.1.0",
4-
"description": "",
5-
"main": "index.js",
6-
"scripts": {
7-
"test": "vitest --config vitest.config.ts",
8-
"build": "tsc",
9-
"dev": "node --watch --import tsx src/evault.ts",
10-
"start": "node ./dist/evault.js"
11-
},
12-
"packageManager": "[email protected]",
13-
"keywords": [],
14-
"author": "",
15-
"license": "ISC",
16-
"devDependencies": {
17-
"@types/json-schema": "^7.0.15",
18-
"@types/node": "^22.13.10",
19-
"dotenv": "^16.5.0",
20-
"testcontainers": "^10.24.2",
21-
"tsx": "^4.19.3",
22-
"typescript": "^5.8.3",
23-
"uuid": "^11.1.0",
24-
"vitest": "^3.0.9"
25-
},
26-
"dependencies": {
27-
"@testcontainers/neo4j": "^10.24.2",
28-
"graphql": "^16.10.0",
29-
"graphql-type-json": "^0.3.2",
30-
"graphql-voyager": "^2.1.0",
31-
"graphql-yoga": "^5.13.4",
32-
"json-schema": "^0.4.0",
33-
"neo4j-driver": "^5.28.1",
34-
"w3id": "workspace:*"
35-
}
2+
"name": "evault-core",
3+
"version": "0.1.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "vitest --config vitest.config.ts",
8+
"build": "tsc",
9+
"dev": "node --watch --import tsx src/evault.ts",
10+
"start": "node ./dist/evault.js"
11+
},
12+
"packageManager": "[email protected]",
13+
"keywords": [],
14+
"author": "",
15+
"license": "ISC",
16+
"devDependencies": {
17+
"@types/json-schema": "^7.0.15",
18+
"@types/node": "^22.13.10",
19+
"dotenv": "^16.5.0",
20+
"testcontainers": "^10.24.2",
21+
"tsx": "^4.19.3",
22+
"typescript": "^5.8.3",
23+
"uuid": "^11.1.0",
24+
"vitest": "^3.0.9"
25+
},
26+
"dependencies": {
27+
"@testcontainers/neo4j": "^10.24.2",
28+
"@fastify/swagger": "^8.14.0",
29+
"@fastify/swagger-ui": "^3.0.0",
30+
"fastify": "^4.26.2",
31+
"graphql": "^16.10.0",
32+
"graphql-type-json": "^0.3.2",
33+
"graphql-voyager": "^2.1.0",
34+
"graphql-yoga": "^5.13.4",
35+
"json-schema": "^0.4.0",
36+
"neo4j-driver": "^5.28.1",
37+
"w3id": "workspace:*"
38+
}
3639
}

infrastructure/evault-core/src/evault.ts

Lines changed: 73 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,22 @@
1-
import { Server } from "http";
21
import { DbService } from "./db/db.service";
32
import { GraphQLServer } from "./protocol/graphql-server";
3+
import { registerHttpRoutes } from "./http/server";
4+
import fastify, {
5+
FastifyInstance,
6+
FastifyRequest,
7+
FastifyReply,
8+
} from "fastify";
9+
import { renderVoyagerPage } from "graphql-voyager/middleware";
10+
import { createYoga } from "graphql-yoga";
411
import dotenv from "dotenv";
512
import path from "path";
613
import neo4j from "neo4j-driver";
714

815
dotenv.config({ path: path.resolve(__dirname, "../../../.env") });
916

1017
class EVault {
11-
server: Server;
18+
server: FastifyInstance;
19+
graphqlServer: GraphQLServer;
1220

1321
constructor() {
1422
const uri = process.env.NEO4J_URI || "bolt://localhost:7687";
@@ -27,18 +35,73 @@ class EVault {
2735

2836
const driver = neo4j.driver(uri, neo4j.auth.basic(user, password));
2937
const dbService = new DbService(driver);
30-
const gqlServer = new GraphQLServer(dbService);
31-
this.server = gqlServer.server as Server;
38+
this.graphqlServer = new GraphQLServer(dbService);
39+
40+
// Create Fastify server
41+
this.server = fastify({
42+
logger: true,
43+
});
3244
}
3345

34-
start() {
35-
const port = process.env.NOMAD_PORT_http || process.env.PORT || 4000;
36-
this.server.listen(Number(port), "0.0.0.0", () => {
37-
console.log(`GraphQL Server started on http://0.0.0.0:${port}`);
38-
console.log(`Voyager started on http://0.0.0.0:${port}`);
46+
async initialize() {
47+
// Register HTTP routes
48+
await registerHttpRoutes(this.server);
49+
50+
// Create Yoga instance with the schema from GraphQLServer
51+
const yoga = createYoga({
52+
schema: this.graphqlServer.getSchema(),
53+
graphiql: true,
54+
});
55+
56+
// Mount GraphQL endpoint
57+
this.server.route({
58+
url: "/graphql",
59+
method: ["GET", "POST", "OPTIONS"],
60+
handler: async (req: FastifyRequest, reply: FastifyReply) => {
61+
const response = await yoga.handleNodeRequest(
62+
req.raw,
63+
reply.raw,
64+
);
65+
response.headers.forEach((value, key) => {
66+
reply.header(key, value);
67+
});
68+
reply.status(response.status);
69+
reply.send(response.body);
70+
return reply;
71+
},
3972
});
73+
74+
// Mount Voyager endpoint
75+
this.server.get(
76+
"/voyager",
77+
(req: FastifyRequest, reply: FastifyReply) => {
78+
reply.type("text/html").send(
79+
renderVoyagerPage({
80+
endpointUrl: "/graphql",
81+
}),
82+
);
83+
},
84+
);
85+
}
86+
87+
async start() {
88+
await this.initialize();
89+
90+
const port = process.env.NOMAD_PORT_http || process.env.PORT || 4000;
91+
92+
await this.server.listen({ port: Number(port), host: "0.0.0.0" });
93+
console.log(`Server started on http://0.0.0.0:${port}`);
94+
console.log(
95+
`GraphQL endpoint available at http://0.0.0.0:${port}/graphql`,
96+
);
97+
console.log(
98+
`GraphQL Voyager available at http://0.0.0.0:${port}/voyager`,
99+
);
100+
console.log(
101+
`API Documentation available at http://0.0.0.0:${port}/documentation`,
102+
);
40103
}
41104
}
42105

43106
const evault = new EVault();
44-
evault.start();
107+
evault.start().catch(console.error);
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { FastifyReply, FastifyRequest } from "fastify";
2+
3+
export interface WatcherSignatureRequest {
4+
w3id: string;
5+
signature: string;
6+
logEntryId: string;
7+
}
8+
9+
export interface WatcherRequest {
10+
w3id: string;
11+
logEntryId: string;
12+
}
13+
14+
export type TypedRequest<T> = FastifyRequest<{
15+
Body: T;
16+
}>;
17+
18+
export type TypedReply = FastifyReply;

infrastructure/evault-provisioner/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,10 @@
1111
"test": "vitest"
1212
},
1313
"dependencies": {
14-
"express": "^4.18.2",
1514
"axios": "^1.6.7",
1615
"dotenv": "^16.4.5",
16+
"express": "^4.18.2",
17+
"jose": "^5.2.2",
1718
"w3id": "workspace:*"
1819
},
1920
"devDependencies": {

0 commit comments

Comments
 (0)