@lerna-labs/hydra-sdk 1.0.0-beta.15 → 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.
@@ -5,7 +5,10 @@ import { MeshWallet } from '@meshsdk/core';
5
5
  * Reads the Cardano signing key from `HYDRA_ADMIN_KEY_FILE` (preferred)
6
6
  * or falls back to `HYDRA_ADMIN_CARDANO_PK`. Network is selected via `HYDRA_NETWORK`.
7
7
  *
8
+ * @param blockfrostProjectId - Optional Blockfrost project ID. When provided, the wallet
9
+ * is configured with a Blockfrost fetcher and submitter for L1 operations (e.g. preparing
10
+ * the Hydra head, querying UTxOs, submitting commit transactions).
8
11
  * @returns An initialized MeshWallet ready for signing transactions.
9
12
  * @throws If no signing key is available or the wallet fails to initialize.
10
13
  */
11
- export declare function getAdmin(): Promise<MeshWallet>;
14
+ export declare function getAdmin(blockfrostProjectId?: string): Promise<MeshWallet>;
@@ -1,5 +1,5 @@
1
1
  import { readFileSync } from 'node:fs';
2
- import { MeshWallet } from '@meshsdk/core';
2
+ import { BlockfrostProvider, MeshWallet } from '@meshsdk/core';
3
3
  import { optionalEnv } from '../config.js';
4
4
  /**
5
5
  * Create and initialize a MeshWallet for the Hydra head admin.
@@ -7,10 +7,13 @@ import { optionalEnv } from '../config.js';
7
7
  * Reads the Cardano signing key from `HYDRA_ADMIN_KEY_FILE` (preferred)
8
8
  * or falls back to `HYDRA_ADMIN_CARDANO_PK`. Network is selected via `HYDRA_NETWORK`.
9
9
  *
10
+ * @param blockfrostProjectId - Optional Blockfrost project ID. When provided, the wallet
11
+ * is configured with a Blockfrost fetcher and submitter for L1 operations (e.g. preparing
12
+ * the Hydra head, querying UTxOs, submitting commit transactions).
10
13
  * @returns An initialized MeshWallet ready for signing transactions.
11
14
  * @throws If no signing key is available or the wallet fails to initialize.
12
15
  */
13
- export async function getAdmin() {
16
+ export async function getAdmin(blockfrostProjectId) {
14
17
  let keyCborHex = null;
15
18
  // Preferred: read the instance's cardano.sk file directly (no secrets in .env)
16
19
  const keyFile = process.env.HYDRA_ADMIN_KEY_FILE;
@@ -32,13 +35,19 @@ export async function getAdmin() {
32
35
  else if (networkId > 1) {
33
36
  networkId = 1;
34
37
  }
35
- const wallet = new MeshWallet({
38
+ const walletOptions = {
36
39
  networkId: networkId,
37
40
  key: {
38
41
  type: 'cli',
39
42
  payment: keyCborHex,
40
43
  },
41
- });
44
+ };
45
+ if (blockfrostProjectId) {
46
+ const blockfrost = new BlockfrostProvider(blockfrostProjectId);
47
+ walletOptions.fetcher = blockfrost;
48
+ walletOptions.submitter = blockfrost;
49
+ }
50
+ const wallet = new MeshWallet(walletOptions);
42
51
  await wallet.init();
43
52
  if (!wallet.addresses.enterpriseAddressBech32) {
44
53
  throw new Error('Wallet failed to initialize!');
@@ -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.15",
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",