@lerna-labs/hydra-sdk 1.0.0-beta.21 → 1.0.0-beta.22

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,6 +1,6 @@
1
1
  import { EventEmitter } from 'node:events';
2
2
  import { HydraWebSocket } from './hydra-websocket.js';
3
- import type { GreetingsMessage, HeadStatus, HydraMessage, HydraMonitorOptions, HydraStatus, ServerOutput, TimestampedEvent } from './types.js';
3
+ import type { GreetingsMessage, HeadStatus, HydraHeadInfo, HydraMessage, HydraMonitorOptions, HydraStatus, ServerOutput, TimestampedEvent } from './types.js';
4
4
  /**
5
5
  * Persistent WebSocket monitor for a Hydra head.
6
6
  *
@@ -53,6 +53,12 @@ export declare class HydraMonitor extends EventEmitter {
53
53
  get headStatusMixed(): HeadStatus;
54
54
  /** The full Greetings message from the most recent connection. */
55
55
  get greetings(): GreetingsMessage | null;
56
+ /**
57
+ * Summary of Hydra head info extracted from the last Greetings.
58
+ * Excludes the full UTxO snapshot to keep payloads small.
59
+ * Returns `null` if no Greetings has been received yet.
60
+ */
61
+ get headInfo(): HydraHeadInfo | null;
56
62
  /** The last N events (configurable via eventBufferSize). Most recent last. */
57
63
  get recentEvents(): readonly TimestampedEvent[];
58
64
  /**
@@ -92,6 +92,31 @@ export class HydraMonitor extends EventEmitter {
92
92
  get greetings() {
93
93
  return this.ws.lastGreetings;
94
94
  }
95
+ /**
96
+ * Summary of Hydra head info extracted from the last Greetings.
97
+ * Excludes the full UTxO snapshot to keep payloads small.
98
+ * Returns `null` if no Greetings has been received yet.
99
+ */
100
+ get headInfo() {
101
+ const g = this.greetings;
102
+ if (!g)
103
+ return null;
104
+ const peers = g.env?.configuredPeers;
105
+ const peerCount = peers ? peers.split(',').filter(Boolean).length : 0;
106
+ return {
107
+ headStatus: g.headStatus,
108
+ headId: g.hydraHeadId ?? null,
109
+ nodeVersion: g.hydraNodeVersion ?? null,
110
+ me: g.me.vkey,
111
+ contestationPeriod: g.env?.contestationPeriod ?? null,
112
+ depositPeriod: g.env?.depositPeriod ?? null,
113
+ participants: g.env?.participants ?? [],
114
+ networkConnected: g.networkInfo?.networkConnected ?? false,
115
+ peerCount,
116
+ chainSyncedStatus: g.chainSyncedStatus ?? null,
117
+ currentSlot: g.currentSlot ?? null,
118
+ };
119
+ }
95
120
  /** The last N events (configurable via eventBufferSize). Most recent last. */
96
121
  get recentEvents() {
97
122
  return this._events;
@@ -149,10 +149,19 @@ export class HydraWebSocket extends EventEmitter {
149
149
  return this._lastGreetings;
150
150
  }
151
151
  handleMessage(msg) {
152
+ // Strip sensitive fields before caching or emitting
152
153
  if (msg.tag === 'Greetings') {
153
- this._lastGreetings = msg;
154
+ const sanitized = { ...msg };
155
+ if (sanitized.env && typeof sanitized.env === 'object') {
156
+ const { signingKey: _, ...safeEnv } = sanitized.env;
157
+ sanitized.env = safeEnv;
158
+ }
159
+ this._lastGreetings = sanitized;
160
+ this.emit('message', sanitized);
161
+ }
162
+ else {
163
+ this.emit('message', msg);
154
164
  }
155
- this.emit('message', msg);
156
165
  // Update status from Greetings headStatus
157
166
  if (msg.tag === 'Greetings' && 'headStatus' in msg) {
158
167
  const mapped = HEAD_STATUS_TO_HYDRA[msg.headStatus];
@@ -11,4 +11,4 @@
11
11
  * }
12
12
  * ```
13
13
  */
14
- export type { ClientInput, ClientMessage, ConnectionState, HeadStatus, HydraMessage, HydraMonitorOptions, HydraStatus, HydraTransaction, HydraWsMessage, hydraStatus, hydraTransaction, ServerOutput, TimestampedEvent, } from './types.js';
14
+ export type { ClientInput, ClientMessage, ConnectionState, HeadStatus, HydraHeadInfo, HydraMessage, HydraMonitorOptions, HydraStatus, HydraTransaction, HydraWsMessage, hydraStatus, hydraTransaction, ServerOutput, TimestampedEvent, } from './types.js';
@@ -72,6 +72,35 @@ export type ClientInput = {
72
72
  recoverTxId: string;
73
73
  };
74
74
  /** Greetings message received on initial WebSocket connection. */
75
+ /** Hydra node environment info reported in Greetings. */
76
+ export interface HydraEnv {
77
+ /** Configured peer addresses (comma-separated or empty). */
78
+ configuredPeers: string;
79
+ /** Contestation period in seconds. */
80
+ contestationPeriod: number;
81
+ /** Deposit period in seconds. */
82
+ depositPeriod: number;
83
+ /** Other parties' verification keys. */
84
+ otherParties: {
85
+ vkey: string;
86
+ }[];
87
+ /** All participant key hashes. */
88
+ participants: string[];
89
+ /** This node's party identity. */
90
+ party: {
91
+ vkey: string;
92
+ };
93
+ [key: string]: unknown;
94
+ }
95
+ /** Network connectivity info reported in Greetings. */
96
+ export interface HydraNetworkInfo {
97
+ /** Whether the node is connected to the Cardano network. */
98
+ networkConnected: boolean;
99
+ /** Per-peer connection info. */
100
+ peersInfo: Record<string, unknown>;
101
+ [key: string]: unknown;
102
+ }
103
+ /** Greetings message received on initial WebSocket connection. */
75
104
  export interface GreetingsMessage {
76
105
  tag: 'Greetings';
77
106
  me: {
@@ -81,8 +110,40 @@ export interface GreetingsMessage {
81
110
  hydraHeadId?: string;
82
111
  snapshotUtxo?: HydraUTxOs;
83
112
  hydraNodeVersion?: string;
84
- env?: Record<string, unknown>;
85
- networkInfo?: Record<string, unknown>;
113
+ env?: HydraEnv;
114
+ networkInfo?: HydraNetworkInfo;
115
+ /** L1 chain sync status (e.g. `"InSync"`). Available in Hydra >= 1.3.0. */
116
+ chainSyncedStatus?: string;
117
+ /** Current L1 slot number. Available in Hydra >= 1.3.0. */
118
+ currentSlot?: number;
119
+ }
120
+ /**
121
+ * Summary of Hydra head info extracted from the Greetings message.
122
+ * Excludes the full UTxO snapshot to keep payloads small.
123
+ */
124
+ export interface HydraHeadInfo {
125
+ /** Current head status. */
126
+ headStatus: HeadStatus;
127
+ /** On-chain head identifier / policy ID (null when head is Idle / not yet initialized). */
128
+ headId: string | null;
129
+ /** Hydra node version string. */
130
+ nodeVersion: string | null;
131
+ /** This node's verification key. */
132
+ me: string;
133
+ /** Contestation period in seconds. */
134
+ contestationPeriod: number | null;
135
+ /** Deposit period in seconds. */
136
+ depositPeriod: number | null;
137
+ /** All participant key hashes. */
138
+ participants: string[];
139
+ /** Whether the node is connected to the Cardano network. */
140
+ networkConnected: boolean;
141
+ /** Number of configured peers. */
142
+ peerCount: number;
143
+ /** L1 chain sync status (e.g. `"InSync"`). Null if not reported (Hydra < 1.3.0). */
144
+ chainSyncedStatus: string | null;
145
+ /** Current L1 slot number. Null if not reported (Hydra < 1.3.0). */
146
+ currentSlot: number | null;
86
147
  }
87
148
  export interface HeadIsInitializingMessage {
88
149
  tag: 'HeadIsInitializing';
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ export type { DiskCache, DiskCacheConfig } from './cache/disk-cache.js';
2
2
  export { createDiskCache } from './cache/disk-cache.js';
3
3
  export { optionalEnv, requireEnv } from './config.js';
4
4
  export { HydraMonitor } from './hydra/hydra-monitor.js';
5
- export type { HeadStatus, HydraMessage, HydraMonitorOptions, HydraStatus, HydraTransaction, HydraWsMessage, hydraStatus, hydraTransaction, ServerOutput, TimestampedEvent, } from './hydra/messages.js';
5
+ export type { HeadStatus, HydraHeadInfo, HydraMessage, HydraMonitorOptions, HydraStatus, HydraTransaction, HydraWsMessage, hydraStatus, hydraTransaction, ServerOutput, TimestampedEvent, } from './hydra/messages.js';
6
6
  export type { ParsedUtxo, UtxoQueryOptions } from './hydra/utxo.js';
7
7
  export { getUtxoSet, queryUtxoByAddress } from './hydra/utxo.js';
8
8
  export type { IpfsClient, IpfsConfig, PinResult } from './ipfs/ipfs.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lerna-labs/hydra-sdk",
3
- "version": "1.0.0-beta.21",
3
+ "version": "1.0.0-beta.22",
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",