ault-sdk-ts 0.0.2-alpha.6 → 0.0.2-alpha.7
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/README.md +6 -15
- package/dist/index.cjs +4 -41
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -41
- package/dist/index.js.map +1 -1
- package/dist/ws/client.d.ts +0 -3
- package/dist/ws/types.d.ts +1 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -370,35 +370,26 @@ client.ws.subscribe(
|
|
|
370
370
|
);
|
|
371
371
|
```
|
|
372
372
|
|
|
373
|
-
###
|
|
373
|
+
### Address Topics
|
|
374
374
|
|
|
375
|
-
|
|
375
|
+
Address topics (`orders`, `balances`, `mytrades`) expose read-only projections
|
|
376
|
+
of public on-chain state — no authentication is required:
|
|
376
377
|
|
|
377
378
|
```typescript
|
|
378
|
-
const ws = createDexWs("wss://my-dex-api.example.com/ws", {
|
|
379
|
-
address: "ault1...",
|
|
380
|
-
signMessage: async (msg) => {
|
|
381
|
-
// Sign the message and return base64 signature
|
|
382
|
-
return await wallet.signArbitrary(msg);
|
|
383
|
-
},
|
|
384
|
-
});
|
|
385
|
-
await ws.connect();
|
|
386
|
-
await ws.authenticate();
|
|
387
|
-
|
|
388
379
|
// Orders (data typed as OrderResponse[])
|
|
389
|
-
ws.subscribe("orders:ault1...", {
|
|
380
|
+
client.ws.subscribe("orders:ault1...", {
|
|
390
381
|
onData: (orders) => {
|
|
391
382
|
for (const o of orders) console.log(o.id, o.status, o.filled);
|
|
392
383
|
},
|
|
393
384
|
});
|
|
394
385
|
|
|
395
386
|
// Balances (data typed as BalancesResponse)
|
|
396
|
-
ws.subscribe("balances:ault1...", {
|
|
387
|
+
client.ws.subscribe("balances:ault1...", {
|
|
397
388
|
onData: (balances) => console.log(balances.free),
|
|
398
389
|
});
|
|
399
390
|
|
|
400
391
|
// User trades (data typed as TradeResponse[])
|
|
401
|
-
ws.subscribe("mytrades:ault1...", {
|
|
392
|
+
client.ws.subscribe("mytrades:ault1...", {
|
|
402
393
|
onData: (trades) => console.log(trades[0].order, trades[0].price),
|
|
403
394
|
});
|
|
404
395
|
```
|
package/dist/index.cjs
CHANGED
|
@@ -5280,16 +5280,13 @@ var DexWsClient = class {
|
|
|
5280
5280
|
this.pendingCommands = /* @__PURE__ */ new Map();
|
|
5281
5281
|
this.reconnectAttempt = 0;
|
|
5282
5282
|
this.reconnectTimer = null;
|
|
5283
|
-
this.authenticated = false;
|
|
5284
5283
|
this.connectResolvers = [];
|
|
5285
5284
|
this.url = url;
|
|
5286
5285
|
this.options = {
|
|
5287
5286
|
reconnect: opts?.reconnect ?? true,
|
|
5288
5287
|
maxReconnectAttempts: opts?.maxReconnectAttempts ?? Infinity,
|
|
5289
5288
|
reconnectDelay: opts?.reconnectDelay ?? 1e3,
|
|
5290
|
-
maxReconnectDelay: opts?.maxReconnectDelay ?? 3e4
|
|
5291
|
-
signMessage: opts?.signMessage,
|
|
5292
|
-
address: opts?.address
|
|
5289
|
+
maxReconnectDelay: opts?.maxReconnectDelay ?? 3e4
|
|
5293
5290
|
};
|
|
5294
5291
|
}
|
|
5295
5292
|
// -----------------------------------------------------------------------
|
|
@@ -5298,9 +5295,6 @@ var DexWsClient = class {
|
|
|
5298
5295
|
get state() {
|
|
5299
5296
|
return this.connectionState;
|
|
5300
5297
|
}
|
|
5301
|
-
get isAuthenticated() {
|
|
5302
|
-
return this.authenticated;
|
|
5303
|
-
}
|
|
5304
5298
|
connect() {
|
|
5305
5299
|
if (this.connectionState === "connected") return Promise.resolve();
|
|
5306
5300
|
if (this.connectionState === "connecting") {
|
|
@@ -5317,7 +5311,6 @@ var DexWsClient = class {
|
|
|
5317
5311
|
disconnect() {
|
|
5318
5312
|
this.clearReconnectTimer();
|
|
5319
5313
|
this.connectionState = "disconnected";
|
|
5320
|
-
this.authenticated = false;
|
|
5321
5314
|
if (this.ws) {
|
|
5322
5315
|
this.ws.close(NORMAL_CLOSURE);
|
|
5323
5316
|
this.ws = null;
|
|
@@ -5352,26 +5345,6 @@ var DexWsClient = class {
|
|
|
5352
5345
|
this.send({ action: "unsubscribe", topic });
|
|
5353
5346
|
}
|
|
5354
5347
|
}
|
|
5355
|
-
async authenticate(address, signMessage) {
|
|
5356
|
-
const addr = address ?? this.options.address;
|
|
5357
|
-
const signer = signMessage ?? this.options.signMessage;
|
|
5358
|
-
if (!addr || !signer) {
|
|
5359
|
-
throw new WebSocketError("address and signMessage are required for authentication");
|
|
5360
|
-
}
|
|
5361
|
-
const timestamp = Math.floor(Date.now() / 1e3);
|
|
5362
|
-
const message = `ault-dex-auth:${timestamp}`;
|
|
5363
|
-
const signature = await signer(message);
|
|
5364
|
-
const resp = await this.sendCommand({
|
|
5365
|
-
action: "authenticate",
|
|
5366
|
-
address: addr,
|
|
5367
|
-
signature,
|
|
5368
|
-
message
|
|
5369
|
-
});
|
|
5370
|
-
if (!resp.success) {
|
|
5371
|
-
throw new WebSocketError(resp.error ?? "Authentication failed");
|
|
5372
|
-
}
|
|
5373
|
-
this.authenticated = true;
|
|
5374
|
-
}
|
|
5375
5348
|
on(event, handler) {
|
|
5376
5349
|
let set = this.listeners.get(event);
|
|
5377
5350
|
if (!set) {
|
|
@@ -5504,15 +5477,8 @@ var DexWsClient = class {
|
|
|
5504
5477
|
this.createSocket();
|
|
5505
5478
|
}, jitteredDelay);
|
|
5506
5479
|
}
|
|
5507
|
-
|
|
5480
|
+
resubscribeAll() {
|
|
5508
5481
|
this.emit("reconnected");
|
|
5509
|
-
if (this.authenticated) {
|
|
5510
|
-
this.authenticated = false;
|
|
5511
|
-
try {
|
|
5512
|
-
await this.authenticate();
|
|
5513
|
-
} catch {
|
|
5514
|
-
}
|
|
5515
|
-
}
|
|
5516
5482
|
for (const [topic, sub] of this.subscriptions) {
|
|
5517
5483
|
this.send({ action: "subscribe", topic, ttl: sub.ttl });
|
|
5518
5484
|
}
|
|
@@ -16125,10 +16091,7 @@ function createAultClient(options) {
|
|
|
16125
16091
|
"WebSocket URL not configured. Set dexWsUrl or dexApiUrl in your network config."
|
|
16126
16092
|
);
|
|
16127
16093
|
}
|
|
16128
|
-
wsClient = new DexWsClient(wsUrl,
|
|
16129
|
-
address: options.signerAddress,
|
|
16130
|
-
...options.wsOptions
|
|
16131
|
-
});
|
|
16094
|
+
wsClient = new DexWsClient(wsUrl, options.wsOptions);
|
|
16132
16095
|
}
|
|
16133
16096
|
return wsClient;
|
|
16134
16097
|
},
|
|
@@ -18196,7 +18159,7 @@ function createDexWs(url, options) {
|
|
|
18196
18159
|
}
|
|
18197
18160
|
|
|
18198
18161
|
// src/index.ts
|
|
18199
|
-
var SDK_VERSION = "0.0.2-alpha.
|
|
18162
|
+
var SDK_VERSION = "0.0.2-alpha.7";
|
|
18200
18163
|
// Annotate the CommonJS export names for ESM import in node:
|
|
18201
18164
|
0 && (module.exports = {
|
|
18202
18165
|
AGENT_DEFAULTS,
|