Skip to content

Commit dfd8716

Browse files
committed
add eth rpc url to auth-eth-bun info endpoint
1 parent f57d4d0 commit dfd8716

4 files changed

Lines changed: 36 additions & 28 deletions

File tree

kms/auth-eth-bun/bun.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

kms/auth-eth-bun/index.test.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ beforeAll(async () => {
2626
process.env.ETH_RPC_URL = 'http://localhost:8545';
2727
process.env.KMS_CONTRACT_ADDR = '0x1234567890123456789012345678901234567890';
2828
process.env.PORT = '3001';
29-
29+
3030
// Import the app after mocking
3131
const indexModule = await import('./index.ts');
3232
appFetch = indexModule.default.fetch;
@@ -58,6 +58,7 @@ describe('API Compatibility Tests', () => {
5858
expect(data).toMatchObject({
5959
status: 'ok',
6060
kmsContractAddr: '0x1234567890123456789012345678901234567890',
61+
ethRpcUrl: 'http://localhost:8545',
6162
gatewayAppId: expect.any(String),
6263
chainId: expect.any(Number),
6364
appAuthImplementation: expect.any(String),
@@ -67,7 +68,7 @@ describe('API Compatibility Tests', () => {
6768
// Verify response structure matches OpenAPI spec
6869
const systemInfoSchema = openApiSpec.components.schemas.SystemInfo;
6970
const requiredFields = systemInfoSchema.required;
70-
71+
7172
requiredFields.forEach(field => {
7273
expect(data).toHaveProperty(field);
7374
});
@@ -128,7 +129,7 @@ describe('API Compatibility Tests', () => {
128129
// Verify response matches OpenAPI spec
129130
const bootResponseSchema = openApiSpec.components.schemas.BootResponse;
130131
const requiredFields = bootResponseSchema.required;
131-
132+
132133
requiredFields.forEach(field => {
133134
expect(data).toHaveProperty(field);
134135
});
@@ -263,7 +264,7 @@ describe('API Compatibility Tests', () => {
263264

264265
it('should not log "Test backend error" messages', async () => {
265266
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
266-
267+
267268
mockReadContract.mockRejectedValue(new Error('Test backend error'));
268269

269270
const response = await appFetch(new Request('http://localhost:3001/bootAuth/kms', {
@@ -277,16 +278,16 @@ describe('API Compatibility Tests', () => {
277278
expect(response.status).toBe(200);
278279
expect(data.isAllowed).toBe(false);
279280
expect(data.reason).toBe('Test backend error');
280-
281+
281282
// Verify that console.error was not called for test errors
282283
expect(consoleSpy).not.toHaveBeenCalled();
283-
284+
284285
consoleSpy.mockRestore();
285286
});
286287

287288
it('should log other error messages', async () => {
288289
const consoleSpy = vi.spyOn(console, 'error').mockImplementation(() => {});
289-
290+
290291
mockReadContract.mockRejectedValue(new Error('real error'));
291292

292293
const response = await appFetch(new Request('http://localhost:3001/bootAuth/kms', {
@@ -300,10 +301,10 @@ describe('API Compatibility Tests', () => {
300301
expect(response.status).toBe(200);
301302
expect(data.isAllowed).toBe(false);
302303
expect(data.reason).toBe('real error');
303-
304+
304305
// Verify that console.error was called for real errors
305306
expect(consoleSpy).toHaveBeenCalledWith('error in KMS boot auth:', expect.any(Error));
306-
307+
307308
consoleSpy.mockRestore();
308309
});
309310
});
@@ -312,7 +313,7 @@ describe('API Compatibility Tests', () => {
312313
describe('API Schema Compatibility', () => {
313314
it('should match BootInfo schema requirements', () => {
314315
const bootInfoSchema = openApiSpec.components.schemas.BootInfo;
315-
316+
316317
// Required fields should match original fastify schema
317318
expect(bootInfoSchema.required).toEqual([
318319
'mrAggregated',
@@ -331,7 +332,7 @@ describe('API Schema Compatibility', () => {
331332

332333
it('should match BootResponse schema requirements', () => {
333334
const bootResponseSchema = openApiSpec.components.schemas.BootResponse;
334-
335+
335336
expect(bootResponseSchema.required).toEqual([
336337
'isAllowed',
337338
'reason',
@@ -341,10 +342,11 @@ describe('API Schema Compatibility', () => {
341342

342343
it('should match SystemInfo schema requirements', () => {
343344
const systemInfoSchema = openApiSpec.components.schemas.SystemInfo;
344-
345+
345346
expect(systemInfoSchema.required).toEqual([
346347
'status',
347348
'kmsContractAddr',
349+
'ethRpcUrl',
348350
'gatewayAppId',
349351
'chainId',
350352
'appAuthImplementation',
@@ -385,4 +387,4 @@ describe('Hex Decoding Compatibility', () => {
385387

386388
expect(response.status).toBe(200);
387389
});
388-
});
390+
});

kms/auth-eth-bun/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ class EthereumBackend {
150150
args: [bootInfoStruct]
151151
});
152152
}
153-
153+
154154
const [isAllowed, reason] = response;
155155
const gatewayAppId = await this.client.readContract({
156156
address: this.kmsContractAddr,
157157
abi: DSTACK_KMS_ABI,
158158
functionName: 'gatewayAppId'
159159
});
160-
160+
161161
return {
162162
isAllowed,
163163
reason,
@@ -209,26 +209,27 @@ app.get('/', async (c) => {
209209
ethereum.getAppImplementation(),
210210
]);
211211
console.log('batch', batch);
212-
212+
213213
return c.json({
214214
status: 'ok',
215215
kmsContractAddr: kmsContractAddr,
216+
ethRpcUrl: rpcUrl,
216217
gatewayAppId: batch[0],
217218
chainId: batch[1],
218219
appAuthImplementation: batch[2], // NOTE: for backward compatibility
219220
appImplementation: batch[2],
220221
});
221222
} catch (error) {
222223
console.error('error in health check:', error);
223-
return c.json({
224-
status: 'error',
225-
message: error instanceof Error ? error.message : String(error)
224+
return c.json({
225+
status: 'error',
226+
message: error instanceof Error ? error.message : String(error)
226227
}, 500);
227228
}
228229
});
229230

230231
// app boot authentication
231-
app.post('/bootAuth/app',
232+
app.post('/bootAuth/app',
232233
zValidator('json', BootInfoSchema),
233234
async (c) => {
234235
try {
@@ -275,4 +276,4 @@ console.log(`starting server on port ${port}`);
275276
export default {
276277
port,
277278
fetch: app.fetch,
278-
};
279+
};

kms/auth-eth-bun/openapi.json

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@
106106
"type": "object",
107107
"required": [
108108
"mrAggregated",
109-
"osImageHash",
109+
"osImageHash",
110110
"appId",
111111
"composeHash",
112112
"instanceId",
@@ -118,7 +118,7 @@
118118
"description": "Aggregated MR measurement"
119119
},
120120
"osImageHash": {
121-
"type": "string",
121+
"type": "string",
122122
"description": "OS Image hash"
123123
},
124124
"appId": {
@@ -158,7 +158,7 @@
158158
"type": "object",
159159
"required": [
160160
"isAllowed",
161-
"reason",
161+
"reason",
162162
"gatewayAppId"
163163
],
164164
"properties": {
@@ -181,6 +181,7 @@
181181
"required": [
182182
"status",
183183
"kmsContractAddr",
184+
"ethRpcUrl",
184185
"gatewayAppId",
185186
"chainId",
186187
"appAuthImplementation",
@@ -196,8 +197,12 @@
196197
"type": "string",
197198
"description": "KMS contract address"
198199
},
200+
"ethRpcUrl": {
201+
"type": "string",
202+
"description": "Ethereum RPC URL"
203+
},
199204
"gatewayAppId": {
200-
"type": "string",
205+
"type": "string",
201206
"description": "Gateway application ID"
202207
},
203208
"chainId": {
@@ -233,4 +238,4 @@
233238
}
234239
}
235240
}
236-
}
241+
}

0 commit comments

Comments
 (0)