@lerna-labs/hydra-sdk 1.0.0-beta.16 → 1.0.0-beta.17

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.
@@ -81,11 +81,19 @@ export class Wrangler {
81
81
  clearTimeout(timer);
82
82
  fn(value);
83
83
  };
84
- this.provider.onMessage((message) => {
85
- handler(message, (value) => settle(resolve, value), (reason) => settle(reject, reason));
86
- });
87
84
  const timer = setTimeout(() => settle(reject, new Error(timeoutMessage)), timeoutMs);
88
- this.connectWithRetry().catch((err) => settle(reject, new Error(`Failed to connect: ${String(err)}`)));
85
+ // Connect first, then register the message handler. HydraProvider.isConnected()
86
+ // internally calls onMessage() (single-callback replacement), which would overwrite
87
+ // any handler set beforehand. By connecting first, isConnected() consumes the
88
+ // Greetings message via its own handler. Once connected, we register our handler —
89
+ // onMessage() replays the _messageQueue, so the Greetings is re-delivered to us.
90
+ this.connectWithRetry()
91
+ .then(() => {
92
+ this.provider.onMessage((message) => {
93
+ handler(message, (value) => settle(resolve, value), (reason) => settle(reject, reason));
94
+ });
95
+ })
96
+ .catch((err) => settle(reject, new Error(`Failed to connect: ${String(err)}`)));
89
97
  });
90
98
  }
91
99
  /** Connect the underlying HydraProvider WebSocket with retry logic. */
@@ -107,14 +115,14 @@ export class Wrangler {
107
115
  /** Begin the head-opening sequence: init, commit, and listen for state changes. */
108
116
  async startHead(commitArgs) {
109
117
  this.mode = 'start';
110
- this.provider.onMessage((msg) => this.handleIncoming(msg, commitArgs));
111
118
  await this.connectWithRetry();
119
+ this.provider.onMessage((msg) => this.handleIncoming(msg, commitArgs));
112
120
  }
113
121
  /** Begin the head-closing sequence: close, fanout, and finalize. */
114
122
  async shutdownHead() {
115
123
  this.mode = 'shutdown';
116
- this.provider.onMessage((msg) => this.handleIncoming(msg));
117
124
  await this.connectWithRetry();
125
+ this.provider.onMessage((msg) => this.handleIncoming(msg));
118
126
  }
119
127
  /**
120
128
  * Wait for the Hydra head to fully close and finalize.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lerna-labs/hydra-sdk",
3
- "version": "1.0.0-beta.16",
3
+ "version": "1.0.0-beta.17",
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",