MCPcopy Create free account
hub / github.com/Dstack-TEE/dstack / build

Function build

kms/auth-eth/src/server.ts:16–120  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

14}
15
16export async function build(): Promise<FastifyInstance> {
17 const server = fastify({
18 logger: true
19 });
20
21 // Register schema for request/response validation
22 server.addSchema({
23 $id: 'bootInfo',
24 type: 'object',
25 required: ['mrAggregated', 'osImageHash', 'appId', 'composeHash', 'instanceId', 'deviceId'],
26 properties: {
27 mrAggregated: { type: 'string', description: 'Aggregated MR measurement' },
28 osImageHash: { type: 'string', description: 'OS Image hash' },
29 appId: { type: 'string', description: 'Application ID' },
30 composeHash: { type: 'string', description: 'Compose hash' },
31 instanceId: { type: 'string', description: 'Instance ID' },
32 deviceId: { type: 'string', description: 'Device ID' }
33 }
34 });
35
36 server.addSchema({
37 $id: 'bootResponse',
38 type: 'object',
39 required: ['isAllowed', 'reason', 'gatewayAppId'],
40 properties: {
41 isAllowed: { type: 'boolean' },
42 reason: { type: 'string' },
43 gatewayAppId: { type: 'string' },
44 }
45 });
46
47 // Initialize backend
48 const rpcUrl = process.env.ETH_RPC_URL || 'http://localhost:8545';
49 const kmsContractAddr = process.env.KMS_CONTRACT_ADDR || '0x0000000000000000000000000000000000000000';
50 const provider = new ethers.JsonRpcProvider(rpcUrl);
51 server.decorate('ethereum', new EthereumBackend(provider, kmsContractAddr));
52
53 server.get('/', async (request, reply) => {
54 const batch = await Promise.all([
55 server.ethereum.getGatewayAppId(),
56 server.ethereum.getChainId(),
57 server.ethereum.getAppImplementation(),
58 ]);
59 return {
60 status: 'ok',
61 kmsContractAddr: kmsContractAddr,
62 ethRpcUrl: rpcUrl,
63 gatewayAppId: batch[0],
64 chainId: batch[1],
65 appAuthImplementation: batch[2], // NOTE: for backward compatibility
66 appImplementation: batch[2],
67 };
68 });
69
70 // Define routes
71 server.post<{
72 Body: BootInfo;
73 Reply: BootResponse;

Callers 2

main.test.tsFile · 0.90
mainFunction · 0.90

Calls 6

sendMethod · 0.80
getMethod · 0.45
getGatewayAppIdMethod · 0.45
getChainIdMethod · 0.45
getAppImplementationMethod · 0.45
checkBootMethod · 0.45

Tested by

no test coverage detected