@lerna-labs/hydra-sdk 1.0.0-beta.8 → 2.0.0-beta.1
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 +159 -0
- package/dist/cache/disk-cache.d.ts +37 -0
- package/dist/cache/disk-cache.js +84 -0
- package/dist/config.d.ts +4 -0
- package/dist/config.js +12 -0
- package/dist/hydra/hydra-http-client.d.ts +36 -0
- package/dist/hydra/hydra-http-client.js +66 -0
- package/dist/hydra/hydra-monitor.d.ts +88 -0
- package/dist/hydra/hydra-monitor.js +270 -0
- package/dist/hydra/hydra-websocket.d.ts +46 -0
- package/dist/hydra/hydra-websocket.js +181 -0
- package/dist/hydra/messages.d.ts +14 -0
- package/dist/hydra/messages.js +1 -0
- package/dist/hydra/types.d.ts +486 -0
- package/dist/hydra/types.js +2 -0
- package/dist/hydra/utxo-conversion.d.ts +10 -0
- package/dist/hydra/utxo-conversion.js +111 -0
- package/dist/hydra/utxo.d.ts +25 -5
- package/dist/hydra/utxo.js +37 -31
- package/dist/index.d.ts +15 -7
- package/dist/index.js +11 -7
- package/dist/ipfs/ipfs.d.ts +22 -0
- package/dist/ipfs/ipfs.js +90 -0
- package/dist/mesh/get-admin.d.ts +13 -1
- package/dist/mesh/get-admin.js +37 -7
- package/dist/mesh/native-script.d.ts +30 -5
- package/dist/mesh/native-script.js +38 -10
- package/dist/test.js +3 -3
- package/dist/tx3/submit-tx.d.ts +8 -0
- package/dist/tx3/submit-tx.js +8 -0
- package/dist/utils/chunk-string.d.ts +7 -0
- package/dist/utils/chunk-string.js +7 -0
- package/dist/utils/verify-signature.d.ts +28 -5
- package/dist/utils/verify-signature.js +39 -18
- package/dist/wrangler.d.ts +179 -0
- package/dist/wrangler.js +452 -0
- package/package.json +25 -6
- package/dist/mesh/wrangler.d.ts +0 -29
- package/dist/mesh/wrangler.js +0 -277
|
@@ -0,0 +1,486 @@
|
|
|
1
|
+
/** A Cardano transaction in Hydra's wire format. */
|
|
2
|
+
export type HydraTransaction = {
|
|
3
|
+
type: 'Tx ConwayEra' | 'Unwitnessed Tx ConwayEra' | 'Witnessed Tx ConwayEra';
|
|
4
|
+
description: string;
|
|
5
|
+
cborHex: string;
|
|
6
|
+
txId?: string;
|
|
7
|
+
};
|
|
8
|
+
/** @deprecated Use HydraTransaction */
|
|
9
|
+
export type hydraTransaction = HydraTransaction;
|
|
10
|
+
/** Hydra's nested asset value format: `{ lovelace: N, policyId: { assetNameHex: N } }`. */
|
|
11
|
+
export type HydraAssets = {
|
|
12
|
+
lovelace: number;
|
|
13
|
+
} & {
|
|
14
|
+
[policyId: string]: number | {
|
|
15
|
+
[assetNameHex: string]: number;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
export interface HydraReferenceScript {
|
|
19
|
+
script: {
|
|
20
|
+
cborHex: string;
|
|
21
|
+
description: string;
|
|
22
|
+
type: string | null;
|
|
23
|
+
};
|
|
24
|
+
scriptLanguage: string;
|
|
25
|
+
}
|
|
26
|
+
/** A single UTxO entry in Hydra's wire format. */
|
|
27
|
+
export interface HydraUTxOEntry {
|
|
28
|
+
address: string;
|
|
29
|
+
datum: string | null;
|
|
30
|
+
inlineDatum: object | null;
|
|
31
|
+
inlineDatumRaw: string | null;
|
|
32
|
+
inlineDatumhash: string | null;
|
|
33
|
+
referenceScript: HydraReferenceScript | null;
|
|
34
|
+
value: HydraAssets;
|
|
35
|
+
}
|
|
36
|
+
/** A set of UTxOs keyed by `"txHash#outputIndex"`. */
|
|
37
|
+
export type HydraUTxOs = {
|
|
38
|
+
[txRef: string]: HydraUTxOEntry;
|
|
39
|
+
};
|
|
40
|
+
/** Payload for blueprint-based commits. */
|
|
41
|
+
export interface CommitBlueprintPayload {
|
|
42
|
+
blueprintTx: HydraTransaction;
|
|
43
|
+
utxo: HydraUTxOs;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Possible Hydra head states as reported in the `Greetings` message (mixed-case).
|
|
47
|
+
*
|
|
48
|
+
* As of Hydra v2 (ADR-33) the head opens directly into `Open` — there is no
|
|
49
|
+
* longer an `Initializing` phase.
|
|
50
|
+
*/
|
|
51
|
+
export type HeadStatus = 'Idle' | 'Open' | 'Closed' | 'FanoutPossible' | 'Final';
|
|
52
|
+
/** Hydra status values (uppercase, as used by HydraProvider status tracking). */
|
|
53
|
+
export type HydraStatus = 'IDLE' | 'OPEN' | 'CLOSED' | 'FANOUT_POSSIBLE' | 'FINAL';
|
|
54
|
+
/** @deprecated Use HydraStatus */
|
|
55
|
+
export type hydraStatus = HydraStatus;
|
|
56
|
+
/** Connection state of the WebSocket. */
|
|
57
|
+
export type ConnectionState = 'IDLE' | 'CONNECTING' | 'CONNECTED' | 'FAILED' | 'DISCONNECTED';
|
|
58
|
+
/** A confirmed Hydra L2 snapshot. */
|
|
59
|
+
export interface HydraSnapshot {
|
|
60
|
+
headId: string;
|
|
61
|
+
version: number;
|
|
62
|
+
number: number;
|
|
63
|
+
confirmed: HydraTransaction[];
|
|
64
|
+
utxo: HydraUTxOs;
|
|
65
|
+
utxoToCommit: HydraUTxOs | null;
|
|
66
|
+
utxoToDecommit: HydraUTxOs | null;
|
|
67
|
+
}
|
|
68
|
+
/** Multi-party aggregate signature map. */
|
|
69
|
+
export type MultiSignature = Record<string, string>;
|
|
70
|
+
/** Discriminated union for confirmed snapshot variants. */
|
|
71
|
+
export type ConfirmedSnapshot = {
|
|
72
|
+
tag: 'InitialSnapshot';
|
|
73
|
+
headId: string;
|
|
74
|
+
initialUTxO?: HydraUTxOs;
|
|
75
|
+
} | {
|
|
76
|
+
tag: 'ConfirmedSnapshot';
|
|
77
|
+
snapshot: HydraSnapshot;
|
|
78
|
+
signatures: MultiSignature;
|
|
79
|
+
};
|
|
80
|
+
/** Messages that can be sent to the Hydra node over WebSocket. */
|
|
81
|
+
export type ClientInput = {
|
|
82
|
+
tag: 'Init';
|
|
83
|
+
} | {
|
|
84
|
+
tag: 'NewTx';
|
|
85
|
+
transaction: HydraTransaction;
|
|
86
|
+
} | {
|
|
87
|
+
tag: 'Close';
|
|
88
|
+
} | {
|
|
89
|
+
tag: 'SafeClose';
|
|
90
|
+
} | {
|
|
91
|
+
tag: 'Contest';
|
|
92
|
+
} | {
|
|
93
|
+
tag: 'Fanout';
|
|
94
|
+
} | {
|
|
95
|
+
tag: 'Decommit';
|
|
96
|
+
decommitTx: HydraTransaction;
|
|
97
|
+
} | {
|
|
98
|
+
tag: 'Recover';
|
|
99
|
+
recoverTxId: string;
|
|
100
|
+
} | {
|
|
101
|
+
tag: 'SideLoadSnapshot';
|
|
102
|
+
snapshot: ConfirmedSnapshot;
|
|
103
|
+
};
|
|
104
|
+
/** Hydra node environment info reported in Greetings. */
|
|
105
|
+
export interface HydraEnv {
|
|
106
|
+
party: {
|
|
107
|
+
vkey: string;
|
|
108
|
+
};
|
|
109
|
+
signingKey?: string;
|
|
110
|
+
otherParties: {
|
|
111
|
+
vkey: string;
|
|
112
|
+
}[];
|
|
113
|
+
participants: string[];
|
|
114
|
+
contestationPeriod: number;
|
|
115
|
+
depositPeriod: number;
|
|
116
|
+
unsyncedPeriod?: number;
|
|
117
|
+
configuredPeers: string;
|
|
118
|
+
[key: string]: unknown;
|
|
119
|
+
}
|
|
120
|
+
/** Network connectivity info reported in Greetings. */
|
|
121
|
+
export interface HydraNetworkInfo {
|
|
122
|
+
networkConnected: boolean;
|
|
123
|
+
peersInfo: Record<string, unknown>;
|
|
124
|
+
[key: string]: unknown;
|
|
125
|
+
}
|
|
126
|
+
/** Greetings message received on initial WebSocket connection. */
|
|
127
|
+
export interface GreetingsMessage {
|
|
128
|
+
tag: 'Greetings';
|
|
129
|
+
me: {
|
|
130
|
+
vkey: string;
|
|
131
|
+
};
|
|
132
|
+
headStatus: HeadStatus;
|
|
133
|
+
hydraHeadId?: string;
|
|
134
|
+
snapshotUtxo?: HydraUTxOs;
|
|
135
|
+
timestamp?: string;
|
|
136
|
+
hydraNodeVersion: string;
|
|
137
|
+
env: HydraEnv;
|
|
138
|
+
networkInfo: HydraNetworkInfo;
|
|
139
|
+
chainSyncedStatus: string;
|
|
140
|
+
currentSlot: number;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Summary of Hydra head info extracted from the Greetings message.
|
|
144
|
+
* Excludes the full UTxO snapshot to keep payloads small.
|
|
145
|
+
*/
|
|
146
|
+
export interface HydraHeadInfo {
|
|
147
|
+
headStatus: HeadStatus;
|
|
148
|
+
headId: string | null;
|
|
149
|
+
nodeVersion: string | null;
|
|
150
|
+
me: string;
|
|
151
|
+
contestationPeriod: number | null;
|
|
152
|
+
depositPeriod: number | null;
|
|
153
|
+
participants: string[];
|
|
154
|
+
networkConnected: boolean;
|
|
155
|
+
peerCount: number;
|
|
156
|
+
chainSyncedStatus: string | null;
|
|
157
|
+
currentSlot: number | null;
|
|
158
|
+
}
|
|
159
|
+
export interface HeadIsOpenMessage {
|
|
160
|
+
tag: 'HeadIsOpen';
|
|
161
|
+
headId: string;
|
|
162
|
+
utxo: HydraUTxOs;
|
|
163
|
+
seq: number;
|
|
164
|
+
timestamp: string;
|
|
165
|
+
[key: string]: unknown;
|
|
166
|
+
}
|
|
167
|
+
export interface HeadIsClosedMessage {
|
|
168
|
+
tag: 'HeadIsClosed';
|
|
169
|
+
headId: string;
|
|
170
|
+
snapshotNumber: number;
|
|
171
|
+
contestationDeadline: string;
|
|
172
|
+
seq: number;
|
|
173
|
+
timestamp: string;
|
|
174
|
+
[key: string]: unknown;
|
|
175
|
+
}
|
|
176
|
+
export interface HeadIsContestedMessage {
|
|
177
|
+
tag: 'HeadIsContested';
|
|
178
|
+
headId: string;
|
|
179
|
+
snapshotNumber: number;
|
|
180
|
+
contestationDeadline: string;
|
|
181
|
+
seq: number;
|
|
182
|
+
timestamp: string;
|
|
183
|
+
[key: string]: unknown;
|
|
184
|
+
}
|
|
185
|
+
export interface ReadyToFanoutMessage {
|
|
186
|
+
tag: 'ReadyToFanout';
|
|
187
|
+
headId: string;
|
|
188
|
+
seq: number;
|
|
189
|
+
timestamp: string;
|
|
190
|
+
[key: string]: unknown;
|
|
191
|
+
}
|
|
192
|
+
export interface HeadIsFinalizedMessage {
|
|
193
|
+
tag: 'HeadIsFinalized';
|
|
194
|
+
headId: string;
|
|
195
|
+
utxo: HydraUTxOs;
|
|
196
|
+
seq: number;
|
|
197
|
+
timestamp: string;
|
|
198
|
+
[key: string]: unknown;
|
|
199
|
+
}
|
|
200
|
+
export interface TxValidMessage {
|
|
201
|
+
tag: 'TxValid';
|
|
202
|
+
headId: string;
|
|
203
|
+
transactionId: string;
|
|
204
|
+
seq: number;
|
|
205
|
+
timestamp: string;
|
|
206
|
+
[key: string]: unknown;
|
|
207
|
+
}
|
|
208
|
+
export interface TxInvalidMessage {
|
|
209
|
+
tag: 'TxInvalid';
|
|
210
|
+
headId: string;
|
|
211
|
+
utxo: HydraUTxOs;
|
|
212
|
+
transaction: HydraTransaction;
|
|
213
|
+
validationError: {
|
|
214
|
+
reason: string;
|
|
215
|
+
};
|
|
216
|
+
seq: number;
|
|
217
|
+
timestamp: string;
|
|
218
|
+
[key: string]: unknown;
|
|
219
|
+
}
|
|
220
|
+
export interface SnapshotConfirmedMessage {
|
|
221
|
+
tag: 'SnapshotConfirmed';
|
|
222
|
+
headId: string;
|
|
223
|
+
snapshot: HydraSnapshot;
|
|
224
|
+
seq: number;
|
|
225
|
+
timestamp: string;
|
|
226
|
+
[key: string]: unknown;
|
|
227
|
+
}
|
|
228
|
+
export interface SnapshotSideLoadedMessage {
|
|
229
|
+
tag: 'SnapshotSideLoaded';
|
|
230
|
+
headId: string;
|
|
231
|
+
snapshotNumber: number;
|
|
232
|
+
seq: number;
|
|
233
|
+
timestamp: string;
|
|
234
|
+
[key: string]: unknown;
|
|
235
|
+
}
|
|
236
|
+
export interface CommitRecordedMessage {
|
|
237
|
+
tag: 'CommitRecorded';
|
|
238
|
+
headId: string;
|
|
239
|
+
utxoToCommit: HydraUTxOs;
|
|
240
|
+
pendingDeposit: string;
|
|
241
|
+
deadline: string;
|
|
242
|
+
seq: number;
|
|
243
|
+
timestamp: string;
|
|
244
|
+
[key: string]: unknown;
|
|
245
|
+
}
|
|
246
|
+
export interface CommitApprovedMessage {
|
|
247
|
+
tag: 'CommitApproved';
|
|
248
|
+
headId: string;
|
|
249
|
+
utxoToCommit: HydraUTxOs;
|
|
250
|
+
seq: number;
|
|
251
|
+
timestamp: string;
|
|
252
|
+
[key: string]: unknown;
|
|
253
|
+
}
|
|
254
|
+
export interface CommitFinalizedMessage {
|
|
255
|
+
tag: 'CommitFinalized';
|
|
256
|
+
headId: string;
|
|
257
|
+
depositTxId: string;
|
|
258
|
+
seq: number;
|
|
259
|
+
timestamp: string;
|
|
260
|
+
[key: string]: unknown;
|
|
261
|
+
}
|
|
262
|
+
export interface CommitRecoveredMessage {
|
|
263
|
+
tag: 'CommitRecovered';
|
|
264
|
+
headId: string;
|
|
265
|
+
recoveredUTxO: HydraUTxOs;
|
|
266
|
+
recoveredTxId: string;
|
|
267
|
+
seq: number;
|
|
268
|
+
timestamp: string;
|
|
269
|
+
[key: string]: unknown;
|
|
270
|
+
}
|
|
271
|
+
export interface DepositActivatedMessage {
|
|
272
|
+
tag: 'DepositActivated';
|
|
273
|
+
headId: string;
|
|
274
|
+
depositTxId: string;
|
|
275
|
+
deadline: string;
|
|
276
|
+
chainTime: string;
|
|
277
|
+
seq: number;
|
|
278
|
+
timestamp: string;
|
|
279
|
+
[key: string]: unknown;
|
|
280
|
+
}
|
|
281
|
+
export interface DepositExpiredMessage {
|
|
282
|
+
tag: 'DepositExpired';
|
|
283
|
+
headId: string;
|
|
284
|
+
depositTxId: string;
|
|
285
|
+
deadline: string;
|
|
286
|
+
chainTime: string;
|
|
287
|
+
seq: number;
|
|
288
|
+
timestamp: string;
|
|
289
|
+
[key: string]: unknown;
|
|
290
|
+
}
|
|
291
|
+
export interface DecommitRequestedMessage {
|
|
292
|
+
tag: 'DecommitRequested';
|
|
293
|
+
headId: string;
|
|
294
|
+
decommitTx: HydraTransaction;
|
|
295
|
+
utxoToDecommit: HydraUTxOs;
|
|
296
|
+
seq: number;
|
|
297
|
+
timestamp: string;
|
|
298
|
+
[key: string]: unknown;
|
|
299
|
+
}
|
|
300
|
+
export interface DecommitApprovedMessage {
|
|
301
|
+
tag: 'DecommitApproved';
|
|
302
|
+
headId: string;
|
|
303
|
+
decommitTxId: string;
|
|
304
|
+
utxoToDecommit: HydraUTxOs;
|
|
305
|
+
seq: number;
|
|
306
|
+
timestamp: string;
|
|
307
|
+
[key: string]: unknown;
|
|
308
|
+
}
|
|
309
|
+
export interface DecommitFinalizedMessage {
|
|
310
|
+
tag: 'DecommitFinalized';
|
|
311
|
+
headId: string;
|
|
312
|
+
distributedUTxO: HydraUTxOs;
|
|
313
|
+
seq: number;
|
|
314
|
+
timestamp: string;
|
|
315
|
+
[key: string]: unknown;
|
|
316
|
+
}
|
|
317
|
+
export interface DecommitInvalidMessage {
|
|
318
|
+
tag: 'DecommitInvalid';
|
|
319
|
+
headId: string;
|
|
320
|
+
decommitTx: HydraTransaction;
|
|
321
|
+
decommitInvalidReason: {
|
|
322
|
+
tag: 'DecommitTxInvalid';
|
|
323
|
+
localUTxO: HydraUTxOs;
|
|
324
|
+
validationError: {
|
|
325
|
+
reason: string;
|
|
326
|
+
};
|
|
327
|
+
} | {
|
|
328
|
+
tag: 'DecommitAlreadyInFlight';
|
|
329
|
+
otherDecommitTxId: string;
|
|
330
|
+
};
|
|
331
|
+
seq: number;
|
|
332
|
+
timestamp: string;
|
|
333
|
+
[key: string]: unknown;
|
|
334
|
+
}
|
|
335
|
+
export interface CommandFailedMessage {
|
|
336
|
+
tag: 'CommandFailed';
|
|
337
|
+
clientInput: ClientInput;
|
|
338
|
+
state: unknown;
|
|
339
|
+
[key: string]: unknown;
|
|
340
|
+
}
|
|
341
|
+
export interface PostTxOnChainFailedMessage {
|
|
342
|
+
tag: 'PostTxOnChainFailed';
|
|
343
|
+
postChainTx: unknown;
|
|
344
|
+
postTxError: unknown;
|
|
345
|
+
[key: string]: unknown;
|
|
346
|
+
}
|
|
347
|
+
export interface InvalidInputMessage {
|
|
348
|
+
tag: 'InvalidInput';
|
|
349
|
+
reason: string;
|
|
350
|
+
input: string;
|
|
351
|
+
[key: string]: unknown;
|
|
352
|
+
}
|
|
353
|
+
export interface RejectedInputBecauseUnsyncedMessage {
|
|
354
|
+
tag: 'RejectedInputBecauseUnsynced';
|
|
355
|
+
clientInput: ClientInput;
|
|
356
|
+
drift: number;
|
|
357
|
+
[key: string]: unknown;
|
|
358
|
+
}
|
|
359
|
+
export interface SideLoadSnapshotRejectedMessage {
|
|
360
|
+
tag: 'SideLoadSnapshotRejected';
|
|
361
|
+
clientInput: ClientInput;
|
|
362
|
+
requirementFailure: unknown;
|
|
363
|
+
[key: string]: unknown;
|
|
364
|
+
}
|
|
365
|
+
export interface PeerConnectedMessage {
|
|
366
|
+
tag: 'PeerConnected';
|
|
367
|
+
peer: string;
|
|
368
|
+
seq: number;
|
|
369
|
+
timestamp: string;
|
|
370
|
+
[key: string]: unknown;
|
|
371
|
+
}
|
|
372
|
+
export interface PeerDisconnectedMessage {
|
|
373
|
+
tag: 'PeerDisconnected';
|
|
374
|
+
peer: string;
|
|
375
|
+
seq: number;
|
|
376
|
+
timestamp: string;
|
|
377
|
+
[key: string]: unknown;
|
|
378
|
+
}
|
|
379
|
+
export interface NetworkConnectedMessage {
|
|
380
|
+
tag: 'NetworkConnected';
|
|
381
|
+
seq: number;
|
|
382
|
+
timestamp: string;
|
|
383
|
+
[key: string]: unknown;
|
|
384
|
+
}
|
|
385
|
+
export interface NetworkDisconnectedMessage {
|
|
386
|
+
tag: 'NetworkDisconnected';
|
|
387
|
+
seq: number;
|
|
388
|
+
timestamp: string;
|
|
389
|
+
[key: string]: unknown;
|
|
390
|
+
}
|
|
391
|
+
export interface NetworkVersionMismatchMessage {
|
|
392
|
+
tag: 'NetworkVersionMismatch';
|
|
393
|
+
ourVersion: unknown;
|
|
394
|
+
theirVersion: unknown;
|
|
395
|
+
seq: number;
|
|
396
|
+
timestamp: string;
|
|
397
|
+
[key: string]: unknown;
|
|
398
|
+
}
|
|
399
|
+
export interface NetworkClusterIDMismatchMessage {
|
|
400
|
+
tag: 'NetworkClusterIDMismatch';
|
|
401
|
+
clusterPeers?: unknown;
|
|
402
|
+
misconfiguredPeers?: unknown;
|
|
403
|
+
seq: number;
|
|
404
|
+
timestamp: string;
|
|
405
|
+
[key: string]: unknown;
|
|
406
|
+
}
|
|
407
|
+
export interface SyncedStatusReportMessage {
|
|
408
|
+
tag: 'SyncedStatusReport';
|
|
409
|
+
chainSlot: number;
|
|
410
|
+
chainTime: string;
|
|
411
|
+
drift: number;
|
|
412
|
+
synced: string;
|
|
413
|
+
[key: string]: unknown;
|
|
414
|
+
}
|
|
415
|
+
export interface NodeSyncedMessage {
|
|
416
|
+
tag: 'NodeSynced';
|
|
417
|
+
chainSlot: number;
|
|
418
|
+
chainTime: string;
|
|
419
|
+
drift: number;
|
|
420
|
+
seq: number;
|
|
421
|
+
timestamp: string;
|
|
422
|
+
[key: string]: unknown;
|
|
423
|
+
}
|
|
424
|
+
export interface NodeUnsyncedMessage {
|
|
425
|
+
tag: 'NodeUnsynced';
|
|
426
|
+
chainSlot: number;
|
|
427
|
+
chainTime: string;
|
|
428
|
+
drift: number;
|
|
429
|
+
seq: number;
|
|
430
|
+
timestamp: string;
|
|
431
|
+
[key: string]: unknown;
|
|
432
|
+
}
|
|
433
|
+
export interface EventLogRotatedMessage {
|
|
434
|
+
tag: 'EventLogRotated';
|
|
435
|
+
seq: number;
|
|
436
|
+
checkpoint: unknown;
|
|
437
|
+
timestamp: string;
|
|
438
|
+
[key: string]: unknown;
|
|
439
|
+
}
|
|
440
|
+
/** Catch-all for message types not explicitly defined above. */
|
|
441
|
+
export interface UnknownMessage {
|
|
442
|
+
tag: string;
|
|
443
|
+
[key: string]: unknown;
|
|
444
|
+
}
|
|
445
|
+
/** All possible messages the Hydra node can send over its WebSocket API. */
|
|
446
|
+
export type ServerOutput = GreetingsMessage | HeadIsOpenMessage | HeadIsClosedMessage | HeadIsContestedMessage | ReadyToFanoutMessage | HeadIsFinalizedMessage | TxValidMessage | TxInvalidMessage | SnapshotConfirmedMessage | SnapshotSideLoadedMessage | CommitRecordedMessage | CommitApprovedMessage | CommitFinalizedMessage | CommitRecoveredMessage | DepositActivatedMessage | DepositExpiredMessage | DecommitRequestedMessage | DecommitApprovedMessage | DecommitFinalizedMessage | DecommitInvalidMessage | CommandFailedMessage | PostTxOnChainFailedMessage | InvalidInputMessage | RejectedInputBecauseUnsyncedMessage | SideLoadSnapshotRejectedMessage | PeerConnectedMessage | PeerDisconnectedMessage | NetworkConnectedMessage | NetworkDisconnectedMessage | NetworkVersionMismatchMessage | NetworkClusterIDMismatchMessage | SyncedStatusReportMessage | NodeSyncedMessage | NodeUnsyncedMessage | EventLogRotatedMessage | UnknownMessage;
|
|
447
|
+
/** Client echo messages (errors, command failures). */
|
|
448
|
+
export type ClientMessage = CommandFailedMessage | PostTxOnChainFailedMessage;
|
|
449
|
+
/** Any message received via the Hydra WebSocket. */
|
|
450
|
+
export type HydraWsMessage = ServerOutput | ClientMessage;
|
|
451
|
+
/**
|
|
452
|
+
* Extract a specific message type from the `ServerOutput` union by its `tag`.
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```ts
|
|
456
|
+
* type Greetings = HydraMessage<"Greetings">;
|
|
457
|
+
* ```
|
|
458
|
+
*/
|
|
459
|
+
export type HydraMessage<T extends ServerOutput['tag']> = Extract<ServerOutput, {
|
|
460
|
+
tag: T;
|
|
461
|
+
}>;
|
|
462
|
+
/** Configuration options for HydraMonitor. */
|
|
463
|
+
export interface HydraMonitorOptions {
|
|
464
|
+
/** Hydra node WebSocket URL. */
|
|
465
|
+
wsUrl: string;
|
|
466
|
+
/** Auto-reconnect configuration. */
|
|
467
|
+
reconnect?: {
|
|
468
|
+
/** Whether to reconnect on unexpected close. Default: `true`. */
|
|
469
|
+
enabled?: boolean;
|
|
470
|
+
/** Initial retry delay in milliseconds. Default: `1000`. */
|
|
471
|
+
baseDelayMs?: number;
|
|
472
|
+
/** Maximum retry delay in milliseconds. Default: `30000`. */
|
|
473
|
+
maxDelayMs?: number;
|
|
474
|
+
/** Maximum reconnect attempts. Default: `Infinity` (keep trying forever). */
|
|
475
|
+
maxAttempts?: number;
|
|
476
|
+
};
|
|
477
|
+
/** Number of recent events to retain in the ring buffer. Default: `100`. */
|
|
478
|
+
eventBufferSize?: number;
|
|
479
|
+
}
|
|
480
|
+
/** A timestamped Hydra WebSocket event for the recent events buffer. */
|
|
481
|
+
export interface TimestampedEvent {
|
|
482
|
+
/** Unix timestamp (ms) when the message was received. */
|
|
483
|
+
timestamp: number;
|
|
484
|
+
/** The raw Hydra message. */
|
|
485
|
+
message: HydraWsMessage;
|
|
486
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Asset, UTxO } from '@meshsdk/common';
|
|
2
|
+
import type { HydraAssets, HydraUTxOEntry, HydraUTxOs } from './types.js';
|
|
3
|
+
/** Convert MeshSDK `Asset[]` to Hydra's nested value format. */
|
|
4
|
+
export declare function toHydraAssets(assets: Asset[]): HydraAssets;
|
|
5
|
+
/** Convert Hydra's nested value format back to MeshSDK `Asset[]`. */
|
|
6
|
+
export declare function fromHydraAssets(assetsObj: HydraAssets): Asset[];
|
|
7
|
+
/** Convert a single MeshSDK UTxO to Hydra wire format. */
|
|
8
|
+
export declare function toHydraUTxO(utxo: UTxO): HydraUTxOEntry;
|
|
9
|
+
/** Convert multiple MeshSDK UTxOs to Hydra wire format (keyed by `"txHash#outputIndex"`). */
|
|
10
|
+
export declare function toHydraUTxOs(utxos: UTxO[]): HydraUTxOs;
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
import { fromScriptRef, parseDatumCbor } from '@meshsdk/core-cst';
|
|
2
|
+
// ── Asset Conversion ─────────────────────────────────────────────────
|
|
3
|
+
/** Convert MeshSDK `Asset[]` to Hydra's nested value format. */
|
|
4
|
+
export function toHydraAssets(assets) {
|
|
5
|
+
return assets.reduce((acc, asset) => {
|
|
6
|
+
if (asset.unit === '' || asset.unit === 'lovelace') {
|
|
7
|
+
acc.lovelace += Number(asset.quantity);
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
const policyId = asset.unit.slice(0, 56);
|
|
11
|
+
const assetNameHex = asset.unit.slice(56) || '';
|
|
12
|
+
if (!acc[policyId] || typeof acc[policyId] === 'number') {
|
|
13
|
+
acc[policyId] = {};
|
|
14
|
+
}
|
|
15
|
+
const policy = acc[policyId];
|
|
16
|
+
policy[assetNameHex] = (policy[assetNameHex] ?? 0) + Number(asset.quantity);
|
|
17
|
+
}
|
|
18
|
+
return acc;
|
|
19
|
+
}, { lovelace: 0 });
|
|
20
|
+
}
|
|
21
|
+
/** Convert Hydra's nested value format back to MeshSDK `Asset[]`. */
|
|
22
|
+
export function fromHydraAssets(assetsObj) {
|
|
23
|
+
const result = [];
|
|
24
|
+
if (assetsObj.lovelace && assetsObj.lovelace > 0) {
|
|
25
|
+
result.push({ unit: 'lovelace', quantity: String(assetsObj.lovelace) });
|
|
26
|
+
}
|
|
27
|
+
for (const [policyId, assets] of Object.entries(assetsObj)) {
|
|
28
|
+
if (policyId === 'lovelace')
|
|
29
|
+
continue;
|
|
30
|
+
if (typeof assets !== 'object')
|
|
31
|
+
continue;
|
|
32
|
+
for (const [assetNameHex, quantity] of Object.entries(assets)) {
|
|
33
|
+
result.push({ unit: policyId + assetNameHex, quantity: String(quantity) });
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
// ── Reference Script Conversion ──────────────────────────────────────
|
|
39
|
+
function resolveReferenceScript(scriptRef) {
|
|
40
|
+
if (!scriptRef)
|
|
41
|
+
return null;
|
|
42
|
+
const scriptInstance = fromScriptRef(scriptRef);
|
|
43
|
+
if (!scriptInstance)
|
|
44
|
+
return null;
|
|
45
|
+
let scriptType = 'Unknown';
|
|
46
|
+
let scriptLanguage = null;
|
|
47
|
+
if ('code' in scriptInstance) {
|
|
48
|
+
switch (scriptInstance.version) {
|
|
49
|
+
case 'V1':
|
|
50
|
+
scriptType = 'PlutusScriptV1';
|
|
51
|
+
scriptLanguage = 'PlutusScriptLanguage PlutusScriptV1';
|
|
52
|
+
break;
|
|
53
|
+
case 'V2':
|
|
54
|
+
scriptType = 'PlutusScriptV2';
|
|
55
|
+
scriptLanguage = 'PlutusScriptLanguage PlutusScriptV2';
|
|
56
|
+
break;
|
|
57
|
+
case 'V3':
|
|
58
|
+
scriptType = 'PlutusScriptV3';
|
|
59
|
+
scriptLanguage = 'PlutusScriptLanguage PlutusScriptV3';
|
|
60
|
+
break;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
scriptType = 'SimpleScript';
|
|
65
|
+
scriptLanguage = 'NativeScriptLanguage SimpleScript';
|
|
66
|
+
}
|
|
67
|
+
if (!scriptLanguage || scriptType === 'Unknown')
|
|
68
|
+
return null;
|
|
69
|
+
return {
|
|
70
|
+
script: {
|
|
71
|
+
cborHex: scriptRef,
|
|
72
|
+
description: '',
|
|
73
|
+
type: scriptType,
|
|
74
|
+
},
|
|
75
|
+
scriptLanguage,
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
// ── Datum Resolution ─────────────────────────────────────────────────
|
|
79
|
+
function resolvePlutusData(datumCbor) {
|
|
80
|
+
const data = parseDatumCbor(datumCbor);
|
|
81
|
+
function normalize(value) {
|
|
82
|
+
if (typeof value === 'bigint') {
|
|
83
|
+
return value <= Number.MAX_SAFE_INTEGER && value >= Number.MIN_SAFE_INTEGER ? Number(value) : value.toString();
|
|
84
|
+
}
|
|
85
|
+
if (Array.isArray(value)) {
|
|
86
|
+
return value.map(normalize);
|
|
87
|
+
}
|
|
88
|
+
if (value && typeof value === 'object') {
|
|
89
|
+
return Object.fromEntries(Object.entries(value).map(([k, v]) => [k, normalize(v)]));
|
|
90
|
+
}
|
|
91
|
+
return value;
|
|
92
|
+
}
|
|
93
|
+
return { inlineDatum: normalize(data) };
|
|
94
|
+
}
|
|
95
|
+
// ── UTxO Conversion ──────────────────────────────────────────────────
|
|
96
|
+
/** Convert a single MeshSDK UTxO to Hydra wire format. */
|
|
97
|
+
export function toHydraUTxO(utxo) {
|
|
98
|
+
return {
|
|
99
|
+
address: utxo.output.address,
|
|
100
|
+
datum: null,
|
|
101
|
+
inlineDatum: utxo.output.plutusData ? resolvePlutusData(utxo.output.plutusData).inlineDatum : null,
|
|
102
|
+
inlineDatumRaw: utxo.output.plutusData ?? null,
|
|
103
|
+
inlineDatumhash: utxo.output.dataHash ?? null,
|
|
104
|
+
referenceScript: utxo.output.scriptRef ? resolveReferenceScript(utxo.output.scriptRef) : null,
|
|
105
|
+
value: toHydraAssets(utxo.output.amount),
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** Convert multiple MeshSDK UTxOs to Hydra wire format (keyed by `"txHash#outputIndex"`). */
|
|
109
|
+
export function toHydraUTxOs(utxos) {
|
|
110
|
+
return Object.fromEntries(utxos.map((utxo) => [`${utxo.input.txHash}#${utxo.input.outputIndex}`, toHydraUTxO(utxo)]));
|
|
111
|
+
}
|
package/dist/hydra/utxo.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
|
|
1
|
+
/** A UTxO entry parsed from the Hydra snapshot. */
|
|
2
|
+
export interface ParsedUtxo {
|
|
2
3
|
tx_hash: string;
|
|
3
4
|
output_index: number;
|
|
4
5
|
address: string;
|
|
@@ -6,10 +7,29 @@ interface ParsedUtxo {
|
|
|
6
7
|
unit: string;
|
|
7
8
|
quantity: string;
|
|
8
9
|
}[];
|
|
10
|
+
datum?: string | null;
|
|
11
|
+
datumHash?: string | null;
|
|
12
|
+
inlineDatum?: unknown | null;
|
|
13
|
+
referenceScript?: unknown | null;
|
|
9
14
|
}
|
|
10
|
-
|
|
15
|
+
/** Options for UTxO query functions. */
|
|
16
|
+
export interface UtxoQueryOptions {
|
|
17
|
+
/** Include datum, datumHash, inlineDatum, and referenceScript fields. Defaults to `false`. */
|
|
18
|
+
includeDatums?: boolean;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Fetch the full UTxO set from the Hydra head snapshot.
|
|
22
|
+
*
|
|
23
|
+
* Reads `HYDRA_API_URL` from the environment.
|
|
24
|
+
*
|
|
25
|
+
* @param options - Query options. Set `includeDatums: true` to include datum/script fields.
|
|
26
|
+
* @returns All UTxOs currently held in the Hydra head.
|
|
27
|
+
*/
|
|
28
|
+
export declare function getUtxoSet(options?: UtxoQueryOptions): Promise<ParsedUtxo[]>;
|
|
11
29
|
/**
|
|
12
|
-
*
|
|
30
|
+
* Fetch UTxOs belonging to a specific address from the Hydra head snapshot.
|
|
31
|
+
*
|
|
32
|
+
* @param address - Bech32 address to filter by.
|
|
33
|
+
* @returns UTxOs matching the given address.
|
|
13
34
|
*/
|
|
14
|
-
export declare function queryUtxoByAddress(address: string): Promise<ParsedUtxo[]>;
|
|
15
|
-
export {};
|
|
35
|
+
export declare function queryUtxoByAddress(address: string, options?: UtxoQueryOptions): Promise<ParsedUtxo[]>;
|