|
| 1 | +# dstack KMS auth-eth-bun |
| 2 | + |
| 3 | +a single-file implementation of the dstack KMS ethereum backend using bun + hono + zod. |
| 4 | + |
| 5 | +## features |
| 6 | + |
| 7 | +- 🚀 fast and lightweight with bun runtime |
| 8 | +- 🔧 modern web framework with hono.js |
| 9 | +- ✅ type-safe validation with zod.js |
| 10 | +- 📦 single file implementation |
| 11 | +- 🔐 ethereum smart contract integration with viem |
| 12 | + |
| 13 | +## installation |
| 14 | + |
| 15 | +```bash |
| 16 | +# install dependencies |
| 17 | +bun install |
| 18 | +``` |
| 19 | + |
| 20 | +## usage |
| 21 | + |
| 22 | +### development |
| 23 | +```bash |
| 24 | +# run with hot reload |
| 25 | +bun run dev |
| 26 | +``` |
| 27 | + |
| 28 | +### production |
| 29 | +```bash |
| 30 | +# run directly |
| 31 | +bun run start |
| 32 | + |
| 33 | +# or build first |
| 34 | +bun run build |
| 35 | +``` |
| 36 | + |
| 37 | +### testing |
| 38 | +```bash |
| 39 | +# run tests (watch mode) |
| 40 | +bun run test |
| 41 | + |
| 42 | +# run tests once |
| 43 | +bun run test:run |
| 44 | +``` |
| 45 | + |
| 46 | +### code quality |
| 47 | +```bash |
| 48 | +# run linter |
| 49 | +bun run lint |
| 50 | + |
| 51 | +# run linter and fix issues |
| 52 | +bun run lint:fix |
| 53 | + |
| 54 | +# format code |
| 55 | +bun run format |
| 56 | + |
| 57 | +# run full check (lint + tests) |
| 58 | +bun run check |
| 59 | +``` |
| 60 | + |
| 61 | +## environment variables |
| 62 | + |
| 63 | +- `ETH_RPC_URL` - ethereum RPC endpoint (default: http://localhost:8545) |
| 64 | +- `KMS_CONTRACT_ADDR` - KMS contract address (default: 0x0000000000000000000000000000000000000000) |
| 65 | +- `PORT` - server port (default: 3000) |
| 66 | + |
| 67 | +## API endpoints |
| 68 | + |
| 69 | +### GET / |
| 70 | +health check and system information |
| 71 | + |
| 72 | +### POST /bootAuth/app |
| 73 | +application boot authentication |
| 74 | + |
| 75 | +### POST /bootAuth/kms |
| 76 | +KMS boot authentication |
| 77 | + |
| 78 | +## request format |
| 79 | + |
| 80 | +```json |
| 81 | +{ |
| 82 | + "tcbStatus": "string", |
| 83 | + "advisoryIds": ["string"], |
| 84 | + "mrAggregated": "string", |
| 85 | + "mrSystem": "string", |
| 86 | + "osImageHash": "string", |
| 87 | + "appId": "string", |
| 88 | + "composeHash": "string", |
| 89 | + "instanceId": "string", |
| 90 | + "deviceId": "string" |
| 91 | +} |
| 92 | +``` |
| 93 | + |
| 94 | +## response format |
| 95 | + |
| 96 | +```json |
| 97 | +{ |
| 98 | + "isAllowed": boolean, |
| 99 | + "reason": "string", |
| 100 | + "gatewayAppId": "string" |
| 101 | +} |
| 102 | +``` |
| 103 | + |
| 104 | +## API compatibility |
| 105 | + |
| 106 | +this implementation is fully compatible with the original fastify + ethers version: |
| 107 | + |
| 108 | +- **request/response schemas**: identical to original API |
| 109 | +- **OpenAPI specification**: available in `openapi.json` |
| 110 | +- **comprehensive testing**: vitest test suite validates compatibility |
| 111 | +- **backward compatibility**: supports both minimal and full BootInfo formats |
| 112 | + |
| 113 | +### OpenAPI specification |
| 114 | + |
| 115 | +the complete API specification is available in `openapi.json` and includes: |
| 116 | +- detailed schema definitions |
| 117 | +- request/response examples |
| 118 | +- compatibility notes |
| 119 | + |
| 120 | +### compatibility testing |
| 121 | + |
| 122 | +the test suite (`index.test.ts`) validates: |
| 123 | +- ✅ request/response format compatibility |
| 124 | +- ✅ schema validation using OpenAPI spec |
| 125 | +- ✅ error handling behavior |
| 126 | +- ✅ hex encoding/decoding compatibility |
| 127 | +- ✅ optional field handling |
0 commit comments