@lerna-labs/hydra-sdk 1.0.0-beta.19 → 1.0.0-beta.20

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.
@@ -1,5 +1,5 @@
1
1
  import { EventEmitter } from 'node:events';
2
- import type { ClientInput, ConnectionState, HydraStatus } from './types.js';
2
+ import type { ClientInput, ConnectionState, HydraStatus, HydraWsMessage } from './types.js';
3
3
  /**
4
4
  * Thin WebSocket wrapper for the Hydra node.
5
5
  *
@@ -16,6 +16,7 @@ export declare class HydraWebSocket extends EventEmitter {
16
16
  private readonly url;
17
17
  private _status;
18
18
  private _connectionState;
19
+ private _lastGreetings;
19
20
  constructor(wsUrl: string);
20
21
  /** Current connection state. */
21
22
  get connectionState(): ConnectionState;
@@ -36,6 +37,8 @@ export declare class HydraWebSocket extends EventEmitter {
36
37
  getStatus(): HydraStatus;
37
38
  /** Register a status-change listener. Returns current status. */
38
39
  onStatusChange(callback: (status: HydraStatus) => void): HydraStatus;
40
+ /** The last Greetings message received, if any. */
41
+ get lastGreetings(): HydraWsMessage | null;
39
42
  private handleMessage;
40
43
  private updateStatus;
41
44
  }
@@ -31,6 +31,7 @@ export class HydraWebSocket extends EventEmitter {
31
31
  url;
32
32
  _status = 'IDLE';
33
33
  _connectionState = 'IDLE';
34
+ _lastGreetings = null;
34
35
  constructor(wsUrl) {
35
36
  super();
36
37
  this.url = wsUrl;
@@ -143,7 +144,14 @@ export class HydraWebSocket extends EventEmitter {
143
144
  this.on('status', callback);
144
145
  return this._status;
145
146
  }
147
+ /** The last Greetings message received, if any. */
148
+ get lastGreetings() {
149
+ return this._lastGreetings;
150
+ }
146
151
  handleMessage(msg) {
152
+ if (msg.tag === 'Greetings') {
153
+ this._lastGreetings = msg;
154
+ }
147
155
  this.emit('message', msg);
148
156
  // Update status from Greetings headStatus
149
157
  if (msg.tag === 'Greetings' && 'headStatus' in msg) {
package/dist/wrangler.js CHANGED
@@ -81,6 +81,12 @@ export class Wrangler {
81
81
  this.connectWithRetry()
82
82
  .then(() => {
83
83
  this.ws.on('message', onMsg);
84
+ // Replay the Greetings message that was consumed during connection.
85
+ // The Hydra node only sends Greetings once, so the handler above
86
+ // would never see it without this replay.
87
+ if (this.ws.lastGreetings) {
88
+ onMsg(this.ws.lastGreetings);
89
+ }
84
90
  })
85
91
  .catch((err) => settle(reject, new Error(`Failed to connect: ${String(err)}`)));
86
92
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lerna-labs/hydra-sdk",
3
- "version": "1.0.0-beta.19",
3
+ "version": "1.0.0-beta.20",
4
4
  "description": "TypeScript SDK for managing Cardano Hydra Heads — lifecycle, UTxO queries, wallet management, transaction submission, and signature verification",
5
5
  "keywords": [
6
6
  "cardano",