@sigrex/client 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sigrex
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,179 @@
1
+ # Sigrex API TypeScript Client
2
+
3
+ A fully-typed, isomorphic, zero-dependency TypeScript API client for the **Sigrex API** with built-in support for automatic request signing (HMAC-SHA256 and custom signers like ML-DSA44).
4
+
5
+ ---
6
+
7
+ ## Features
8
+
9
+ - **Fully Typed**: Generated directly from the [Sigrex OpenAPI Specification](https://docs.sigrex.io/api-reference). Every request payload and response body is strongly-typed.
10
+ - **Isomorphic**: Works in Node.js, browsers, Cloudflare Workers, Edge runtimes, and other JS environments.
11
+ - **Automatic Request Signing**: Automatically calculates and attaches required headers (`api-key`, `timestamp`, `signature`) to every request.
12
+ - **Flexible Signatures**: Supports standard **HMAC-SHA256** and provides a callback interface for custom signers (e.g., **ML-DSA44**).
13
+ - **Clean API Hierarchy**: Logical grouping of methods matching the API tag hierarchy (e.g., `client.strategies.llmSessions.list()`).
14
+
15
+ ---
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ npm install @sigrex/client
21
+ ```
22
+
23
+ ---
24
+
25
+ ## Quick Start (HMAC-SHA256)
26
+
27
+ To get started, instantiate the `SigrexClient` using your public **API key** and private **API secret**. All HTTP requests are automatically signed and sent using native `fetch`.
28
+
29
+ ```typescript
30
+ import { SigrexClient } from '@sigrex/client';
31
+
32
+ const client = new SigrexClient({
33
+ apiKey: 'YOUR_PUBLIC_API_KEY',
34
+ apiSecret: 'YOUR_PRIVATE_API_SECRET',
35
+ });
36
+
37
+ // Example: Retrieve all exchanges
38
+ async function getExchanges() {
39
+ try {
40
+ const exchanges = await client.exchanges.list({ enabled: true });
41
+ console.log('Exchanges:', exchanges);
42
+ } catch (error) {
43
+ console.error('Error fetching exchanges:', error);
44
+ }
45
+ }
46
+
47
+ getExchanges();
48
+ ```
49
+
50
+ ---
51
+
52
+ ## Advanced: Post-Quantum Signatures (ML-DSA44)
53
+
54
+ The Sigrex API supports post-quantum **ML-DSA44** signature authentication. You can provide a custom `signer` callback function to sign requests using `@oqs/liboqs-js` (or any other cryptographic engine) without adding heavy WebAssembly or native binaries to your core dependencies.
55
+
56
+ ```typescript
57
+ import { SigrexClient } from '@sigrex/client';
58
+ import { createMLDSA44 } from '@oqs/liboqs-js';
59
+
60
+ const PRIVATE_KEY_B64 = 'YOUR_PRIVATE_KEY_BASE64';
61
+
62
+ const client = new SigrexClient({
63
+ apiKey: 'YOUR_PUBLIC_API_KEY',
64
+ signer: async (message: string) => {
65
+ // Initialize ML-DSA44 signer
66
+ const sig = await createMLDSA44();
67
+
68
+ // Sign the message payload
69
+ const messageBytes = new TextEncoder().encode(message);
70
+ const signature = sig.sign(
71
+ messageBytes,
72
+ Uint8Array.from(Buffer.from(PRIVATE_KEY_B64, 'base64'))
73
+ );
74
+
75
+ // Convert signature to base64
76
+ const signatureB64 = Buffer.from(signature).toString('base64');
77
+
78
+ // Clean up
79
+ sig.destroy();
80
+
81
+ return signatureB64;
82
+ }
83
+ });
84
+
85
+ // Example: Get active LLM Sessions
86
+ async function getLLMSessions() {
87
+ const sessions = await client.strategies.llmSessions.list();
88
+ console.log('Sessions:', sessions);
89
+ }
90
+ ```
91
+
92
+ ---
93
+
94
+ ## API Reference
95
+
96
+ The client exposes nested namespaces to make finding endpoints easy and intuitive:
97
+
98
+ ### 1. Exchanges
99
+
100
+ Exposes CEX, DEX, and Prediction exchanges.
101
+
102
+ - `client.exchanges.list(queryParams?)`
103
+ - `client.exchanges.listCex()`
104
+ - `client.exchanges.getDex(chain)`
105
+ - `client.exchanges.listPrediction()`
106
+ - `client.exchanges.listWithExchangeRate()`
107
+
108
+ ### 2. Strategies
109
+
110
+ Exposes LLM Sessions, Code Strategies, and Reactions (both LLM and Code).
111
+
112
+ - **LLM Sessions**:
113
+ - `client.strategies.llmSessions.list()`
114
+ - `client.strategies.llmSessions.create(body)`
115
+ - `client.strategies.llmSessions.get(id)`
116
+ - `client.strategies.llmSessions.update(id, body)`
117
+ - `client.strategies.llmSessions.delete(id)`
118
+ - `client.strategies.llmSessions.status(id, body)` (Enable/disable session)
119
+ - `client.strategies.llmSessions.public(id, body)` (Set visibility)
120
+ - `client.strategies.llmSessions.listFolder()`
121
+ - `client.strategies.llmSessions.createFolder(body)`
122
+ - **Code Strategies**:
123
+ - `client.strategies.code.list()`
124
+ - `client.strategies.code.create(body)`
125
+ - `client.strategies.code.get(id)`
126
+ - `client.strategies.code.update(id, body)`
127
+ - `client.strategies.code.delete(id)`
128
+ - **Reactions (LLM)**:
129
+ - `client.strategies.reactions.llm.list()`
130
+ - `client.strategies.reactions.llm.create(body)`
131
+ - **Reactions (Code)**:
132
+ - `client.strategies.reactions.code.list()`
133
+ - `client.strategies.reactions.code.create(body)`
134
+
135
+ ### 3. Signal Bots
136
+
137
+ - **CEX Bots**: `client.bots.cex.list()`, `client.bots.cex.create()`, etc.
138
+ - **DEX Bots**: `client.bots.dex.list()`, `client.bots.dex.create()`, etc.
139
+ - **Prediction Bots**: `client.bots.prediction.list()`, `client.bots.prediction.create()`, etc.
140
+
141
+ ### 4. Webhooks
142
+
143
+ - **Bot Hooks**: `client.webhooks.bot.list()`, `client.webhooks.bot.create()`, etc.
144
+ - **Data Hooks**: `client.webhooks.data.list()`, `client.webhooks.data.create()`, etc.
145
+
146
+ ### 5. API Keys Management
147
+
148
+ Exposes key endpoints for managing third-party LLM and CEX keys securely.
149
+
150
+ - **Exchange Keys**: `client.apiKeys.exchange.list()`, `client.apiKeys.exchange.create()`, etc.
151
+ - **LLM Keys**: `client.apiKeys.llm.list()`, `client.apiKeys.llm.create()`, etc.
152
+ - **Prediction Keys**: `client.apiKeys.prediction.list()`, `client.apiKeys.prediction.create()`, etc.
153
+
154
+ ---
155
+
156
+ ## Error Handling
157
+
158
+ All failed HTTP requests (status code outside `2xx`) throw a `SigrexError`. You can inspect the error's status code, status message, and API-returned error details:
159
+
160
+ ```typescript
161
+ import { SigrexError } from '@sigrex/client';
162
+
163
+ try {
164
+ await client.strategies.llmSessions.delete('non-existent-id');
165
+ } catch (error) {
166
+ if (error instanceof SigrexError) {
167
+ console.error(`API Error [${error.status}]: ${error.message}`);
168
+ console.error('Raw Body:', error.body);
169
+ } else {
170
+ console.error('Network or other error:', error);
171
+ }
172
+ }
173
+ ```
174
+
175
+ ---
176
+
177
+ ## License
178
+
179
+ MIT