Skip to content

Commit 8546b0d

Browse files
committed
feat: OpenAPI docs & JS Client
1 parent 4cbd147 commit 8546b0d

File tree

9 files changed

+2155
-1
lines changed

9 files changed

+2155
-1
lines changed

.cspell/custom-dictionary.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ Solana
1717
struct
1818
structs
1919
Unichain
20+
Redoc

.gitattributes

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Ensure all text files use LF line endings
2+
* text=auto eol=lf
3+
4+
# Explicitly set text files
5+
*.md text eol=lf
6+
*.json text eol=lf
7+
*.js text eol=lf
8+
*.ts text eol=lf
9+
*.tsx text eol=lf
10+
*.jsx text eol=lf
11+
*.css text eol=lf
12+
*.scss text eol=lf
13+
*.html text eol=lf
14+
*.yml text eol=lf
15+
*.yaml text eol=lf
16+
*.toml text eol=lf
17+
*.rs text eol=lf
18+
*.move text eol=lf
19+
*.sol text eol=lf
20+
21+
# Binary files
22+
*.png binary
23+
*.jpg binary
24+
*.jpeg binary
25+
*.gif binary
26+
*.ico binary
27+
*.pdf binary

README.md

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,96 @@ The API spec (TBD) for the off-chain service should be adhered to by all Relay P
162162

163163
Explorers should be updated to track execution requests and link to their designated provider via quoter address.
164164

165+
## API Documentation
166+
167+
The Messaging Executor provides HTTP APIs for interacting with the relay service. The API specification is defined using [TypeSpec](https://typespec.io/) and can be generated as OpenAPI documentation.
168+
169+
### Building API Documentation
170+
171+
```bash
172+
# Navigate to the api-docs directory
173+
cd api-docs
174+
175+
# Install dependencies
176+
npm install
177+
178+
# Compile TypeSpec to generate OpenAPI spec and JS client & models
179+
npm run compile
180+
# or
181+
tsp compile .
182+
```
183+
184+
This will generate:
185+
186+
- **OpenAPI Specification**: `tsp-output/schema/openapi.yaml`
187+
- **JavaScript Client & Models**: `tsp-output/clients/js/`
188+
189+
### Viewing API Documentation
190+
191+
After building, you can view the API documentation using:
192+
193+
1. **Swagger Editor** (Online)
194+
- Visit https://editor.swagger.io/
195+
- Copy and paste the contents of `tsp-output/schema/openapi.yaml`
196+
197+
2. **Redoc** (Online)
198+
- Visit https://redocly.github.io/redoc/
199+
- Upload your `openapi.yaml` file
200+
201+
### API Endpoints
202+
203+
The API provides three main endpoints:
204+
205+
#### GET `/capabilities`
206+
207+
Returns the capabilities for all supported chains, including:
208+
209+
- Supported request prefixes (ERV1, ERN1, ERC1, ERC2)
210+
- Gas limits and message value limits
211+
- Supported destination chains
212+
213+
#### POST `/quote`
214+
215+
Generates a signed quote for cross-chain execution:
216+
217+
- **Request**: Source chain, destination chain, optional relay instructions
218+
- **Response**: Signed quote and estimated cost
219+
220+
#### POST `/status/tx`
221+
222+
Retrieves the status of an execution request:
223+
224+
- **Request**: Transaction hash and optional chain ID
225+
- **Response**: Relay transaction details including status, costs, and execution results
226+
227+
### Using the JavaScript Client
228+
229+
The generated JavaScript client can be used to interact with the API programmatically:
230+
231+
```javascript
232+
// Import the generated client
233+
import { Client } from "./api-docs/tsp-output/clients/js";
234+
235+
// Create a client instance
236+
const client = new Client({ baseUrl: "http://localhost:3000/v0" });
237+
238+
// Get capabilities
239+
const capabilities = await client.capabilities.list();
240+
241+
// Generate a quote
242+
const quote = await client.quote.create({
243+
srcChain: 1,
244+
dstChain: 2,
245+
relayInstructions: "0x...",
246+
});
247+
248+
// Check transaction status
249+
const status = await client.status.getTransaction({
250+
txHash: "0x...",
251+
chainId: 1,
252+
});
253+
```
254+
165255
### API / Database Schema
166256

167257
#### Off-Chain Quote

api-docs/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# MacOS
2+
.DS_Store
3+
4+
# Default TypeSpec output
5+
tsp-output/
6+
dist/
7+
8+
# Dependency directories
9+
node_modules/

0 commit comments

Comments
 (0)