Skip to content

Commit e59e887

Browse files
committed
feat: move to x-ename header and add tests
1 parent 0d77158 commit e59e887

File tree

4 files changed

+66
-12
lines changed

4 files changed

+66
-12
lines changed

infrastructure/evault-core/src/core/protocol/graphql-server.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,12 @@ export class GraphQLServer {
196196
context.eName
197197
);
198198

199+
// Add parsed field to metaEnvelope for GraphQL response
200+
const metaEnvelopeWithParsed = {
201+
...result.metaEnvelope,
202+
parsed: input.payload,
203+
};
204+
199205
// Deliver webhooks for create operation
200206
const requestingPlatform =
201207
context.tokenPayload?.platform || null;
@@ -224,7 +230,10 @@ export class GraphQLServer {
224230
);
225231
}, 3_000);
226232

227-
return result;
233+
return {
234+
...result,
235+
metaEnvelope: metaEnvelopeWithParsed,
236+
};
228237
}
229238
),
230239
updateMetaEnvelopeById: this.accessGuard.middleware(

infrastructure/evault-core/src/core/protocol/vault-access-guard.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,14 @@ export class VaultAccessGuard {
147147
if (!args.id && !args.envelopeId) {
148148
const result = await resolver(parent, args, context);
149149

150-
// If the result is an array of meta envelopes, filter based on access
150+
// If the result is an array
151151
if (Array.isArray(result)) {
152+
// Check if it's an array of Envelopes (no ACL) or MetaEnvelopes (has ACL)
153+
if (result.length > 0 && result[0] && !('acl' in result[0])) {
154+
// It's an array of Envelopes - already filtered by eName, just return as-is
155+
return result;
156+
}
157+
// It's an array of MetaEnvelopes - filter based on access
152158
return this.filterEnvelopesByAccess(result, context);
153159
}
154160

infrastructure/evault-core/src/test-utils/mock-registry-server.ts

Lines changed: 47 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import fastify, { FastifyInstance } from "fastify";
2-
// Mock getJWK - we don't need to import from registry in tests
2+
import { getSharedTestPublicJWK } from "./shared-test-keys";
3+
4+
// In-memory store for registered eVaults
5+
const registeredEVaults = new Map<string, { uri: string; evault: string }>();
6+
7+
// Mock getJWK - returns the public key from the shared test key pair
38
async function mockGetJWK() {
9+
const publicKeyOnly = await getSharedTestPublicJWK();
410
return {
5-
keys: [{
6-
kty: "EC",
7-
crv: "P-256",
8-
x: "test-x",
9-
y: "test-y",
10-
kid: "entropy-key-1",
11-
alg: "ES256",
12-
}],
11+
keys: [publicKeyOnly],
1312
};
1413
}
1514

@@ -31,16 +30,55 @@ export async function createMockRegistryServer(port: number = 4322): Promise<Fas
3130
if (!ename || !uri || !evault) {
3231
return reply.status(400).send({ error: "Missing required fields" });
3332
}
33+
34+
// Store the registered eVault for resolution
35+
registeredEVaults.set(ename, { uri, evault });
36+
3437
return reply.status(201).send({ ename, uri, evault });
3538
});
3639

40+
server.get("/resolve", async (request, reply) => {
41+
const { w3id } = request.query as { w3id?: string };
42+
43+
if (!w3id) {
44+
return reply.status(400).send({ error: "Missing w3id parameter" });
45+
}
46+
47+
// Normalize w3id (remove @ prefix if present for lookup)
48+
const normalizedW3id = w3id.startsWith("@") ? w3id.substring(1) : w3id;
49+
const registered = registeredEVaults.get(normalizedW3id) || registeredEVaults.get(w3id);
50+
51+
if (!registered) {
52+
return reply.status(404).send({ error: "eVault not found" });
53+
}
54+
55+
return reply.status(200).send({ uri: registered.uri });
56+
});
57+
3758
server.get("/platforms", async () => {
3859
return [
3960
"http://localhost:1111",
4061
"http://localhost:3000",
4162
];
4263
});
4364

65+
server.post("/platforms/certification", async (request, reply) => {
66+
const { platform } = request.body as { platform?: string };
67+
68+
if (!platform) {
69+
return reply.status(400).send({ error: "Missing platform parameter" });
70+
}
71+
72+
// Return a mock JWT token for the platform
73+
// In a real scenario, this would be a proper JWT signed by the registry
74+
const mockToken = `mock.jwt.token.${platform}.${Date.now()}`;
75+
76+
return reply.status(200).send({
77+
token: mockToken,
78+
expiresAt: Date.now() + 3600000, // 1 hour from now
79+
});
80+
});
81+
4482
await server.listen({ port, host: "0.0.0.0" });
4583

4684
return server;

infrastructure/web3-adapter/src/evault/evault.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -304,11 +304,12 @@ export class EVaultClient {
304304
const endpoint = await this.resolveEndpoint(w3id).catch(() => null);
305305
if (!endpoint) throw new Error("Failed to resolve endpoint");
306306

307-
// Get platform token and create client with authorization header
307+
// Get platform token and create client with authorization and X-ENAME headers
308308
const token = await this.ensurePlatformToken();
309309
const client = new GraphQLClient(endpoint, {
310310
headers: {
311311
authorization: `Bearer ${token}`,
312+
"X-ENAME": w3id,
312313
},
313314
});
314315

0 commit comments

Comments
 (0)