@lerna-labs/hydra-sdk 1.0.0-beta.26 → 1.0.0-beta.28
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/dist/ipfs/ipfs.js +21 -8
- package/dist/wrangler.d.ts +11 -0
- package/dist/wrangler.js +33 -3
- package/package.json +1 -1
package/dist/ipfs/ipfs.js
CHANGED
|
@@ -35,15 +35,28 @@ export function createIpfsClient(config) {
|
|
|
35
35
|
* @returns The CID of the wrapping IPFS directory.
|
|
36
36
|
*/
|
|
37
37
|
async function pinDirectory(dirPath) {
|
|
38
|
-
const entries = await fs.readdir(dirPath);
|
|
39
38
|
const form = new FormData();
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
const
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
const collectFiles = async (rel) => {
|
|
40
|
+
const out = [];
|
|
41
|
+
const dirents = await fs.readdir(path.join(dirPath, rel), { withFileTypes: true });
|
|
42
|
+
for (const dirent of dirents) {
|
|
43
|
+
const childRel = path.join(rel, dirent.name);
|
|
44
|
+
if (dirent.isDirectory()) {
|
|
45
|
+
out.push(...(await collectFiles(childRel)));
|
|
46
|
+
}
|
|
47
|
+
else if (dirent.isFile()) {
|
|
48
|
+
out.push(childRel);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return out;
|
|
52
|
+
};
|
|
53
|
+
for (const relPath of await collectFiles('')) {
|
|
54
|
+
const buf = await fs.readFile(path.join(dirPath, relPath));
|
|
55
|
+
const content = new Uint8Array(buf).slice().buffer;
|
|
56
|
+
// Kubo reconstructs the directory tree from entry names — always
|
|
57
|
+
// use POSIX separators so Windows callers get the same CID.
|
|
58
|
+
const entryName = relPath.split(path.sep).join('/');
|
|
59
|
+
form.append('file', new Blob([content]), entryName);
|
|
47
60
|
}
|
|
48
61
|
const res = await fetch(`${apiUrl}/api/v0/add?pin=true&wrap-with-directory=true&recursive=true`, {
|
|
49
62
|
method: 'POST',
|
package/dist/wrangler.d.ts
CHANGED
|
@@ -70,11 +70,22 @@ export declare class Wrangler {
|
|
|
70
70
|
shutdownHead(): Promise<void>;
|
|
71
71
|
/**
|
|
72
72
|
* Wait for the Hydra head to fully close and finalize.
|
|
73
|
+
*
|
|
74
|
+
* Resolves on the `HeadIsClosed` / `HeadIsFinalized` transition events, **and**
|
|
75
|
+
* on the initial `Greetings` replay if the head is already at `Closed` or
|
|
76
|
+
* `Final`. Rejects fast if the head is `Idle` (no head exists to close).
|
|
77
|
+
*
|
|
73
78
|
* @param timeoutMs - Maximum time to wait in milliseconds.
|
|
74
79
|
*/
|
|
75
80
|
waitForHeadClose(timeoutMs?: number): Promise<void>;
|
|
76
81
|
/**
|
|
77
82
|
* Wait for the Hydra head to reach the `Open` state.
|
|
83
|
+
*
|
|
84
|
+
* Resolves on the `HeadIsOpen` transition event, **and** on the initial
|
|
85
|
+
* `Greetings` replay if the head is already `Open`. Rejects fast if the
|
|
86
|
+
* head is in a terminal or shutting-down state (`Closed`, `FanoutPossible`,
|
|
87
|
+
* `Final`) — a new head must be started from a fresh node.
|
|
88
|
+
*
|
|
78
89
|
* @param commitArgs - UTxO to commit into the head during initialization.
|
|
79
90
|
* @param timeoutMs - Maximum time to wait in milliseconds.
|
|
80
91
|
*/
|
package/dist/wrangler.js
CHANGED
|
@@ -140,6 +140,11 @@ export class Wrangler {
|
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
142
142
|
* Wait for the Hydra head to fully close and finalize.
|
|
143
|
+
*
|
|
144
|
+
* Resolves on the `HeadIsClosed` / `HeadIsFinalized` transition events, **and**
|
|
145
|
+
* on the initial `Greetings` replay if the head is already at `Closed` or
|
|
146
|
+
* `Final`. Rejects fast if the head is `Idle` (no head exists to close).
|
|
147
|
+
*
|
|
143
148
|
* @param timeoutMs - Maximum time to wait in milliseconds.
|
|
144
149
|
*/
|
|
145
150
|
async waitForHeadClose(timeoutMs = 180000) {
|
|
@@ -153,14 +158,30 @@ export class Wrangler {
|
|
|
153
158
|
case 'ReadyToFanout':
|
|
154
159
|
this.ws.send({ tag: 'Fanout' });
|
|
155
160
|
break;
|
|
156
|
-
case 'Greetings':
|
|
157
|
-
|
|
161
|
+
case 'Greetings': {
|
|
162
|
+
const status = message.headStatus;
|
|
163
|
+
if (status === 'Closed' || status === 'Final') {
|
|
164
|
+
resolve();
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
if (status === 'Idle') {
|
|
168
|
+
reject(new Error(`Cannot wait for head to close: head is "Idle" — no head exists to close`));
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
this.onGreetings(status).catch((err) => reject(new Error(`Greetings handler failed: ${String(err)}`)));
|
|
158
172
|
break;
|
|
173
|
+
}
|
|
159
174
|
}
|
|
160
175
|
}, timeoutMs, 'Timeout waiting for head to close!');
|
|
161
176
|
}
|
|
162
177
|
/**
|
|
163
178
|
* Wait for the Hydra head to reach the `Open` state.
|
|
179
|
+
*
|
|
180
|
+
* Resolves on the `HeadIsOpen` transition event, **and** on the initial
|
|
181
|
+
* `Greetings` replay if the head is already `Open`. Rejects fast if the
|
|
182
|
+
* head is in a terminal or shutting-down state (`Closed`, `FanoutPossible`,
|
|
183
|
+
* `Final`) — a new head must be started from a fresh node.
|
|
184
|
+
*
|
|
164
185
|
* @param commitArgs - UTxO to commit into the head during initialization.
|
|
165
186
|
* @param timeoutMs - Maximum time to wait in milliseconds.
|
|
166
187
|
*/
|
|
@@ -176,7 +197,16 @@ export class Wrangler {
|
|
|
176
197
|
this.doCommit(commitArgs).catch((err) => reject(new Error(`Commit failed: ${String(err)}`)));
|
|
177
198
|
}
|
|
178
199
|
else if (message.tag === 'Greetings') {
|
|
179
|
-
|
|
200
|
+
const status = message.headStatus;
|
|
201
|
+
if (status === 'Open') {
|
|
202
|
+
resolve();
|
|
203
|
+
return;
|
|
204
|
+
}
|
|
205
|
+
if (status === 'Closed' || status === 'FanoutPossible' || status === 'Final') {
|
|
206
|
+
reject(new Error(`Cannot wait for head to open: head is "${status}" (terminal or shutting down)`));
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
this.onGreetings(status, commitArgs).catch((err) => reject(new Error(`Greetings handler failed: ${String(err)}`)));
|
|
180
210
|
}
|
|
181
211
|
}, timeoutMs, 'Timeout waiting for head to open');
|
|
182
212
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lerna-labs/hydra-sdk",
|
|
3
|
-
"version": "1.0.0-beta.
|
|
3
|
+
"version": "1.0.0-beta.28",
|
|
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",
|