sigild 0.0.11 → 0.0.13

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.
Files changed (180) hide show
  1. package/README.md +43 -13
  2. package/SECURITY.md +69 -0
  3. package/THREAT_MODEL.md +5 -3
  4. package/dist/src/audit/index.d.ts +2 -1
  5. package/dist/src/audit/index.d.ts.map +1 -1
  6. package/dist/src/audit/index.js +1 -0
  7. package/dist/src/audit/index.js.map +1 -1
  8. package/dist/src/audit/log.d.ts +37 -3
  9. package/dist/src/audit/log.d.ts.map +1 -1
  10. package/dist/src/audit/log.js +227 -41
  11. package/dist/src/audit/log.js.map +1 -1
  12. package/dist/src/bin/sigil-mcp.js +23 -6
  13. package/dist/src/bin/sigil-mcp.js.map +1 -1
  14. package/dist/src/cli/args.d.ts.map +1 -1
  15. package/dist/src/cli/args.js.map +1 -1
  16. package/dist/src/cli/index.d.ts +1 -1
  17. package/dist/src/cli/index.d.ts.map +1 -1
  18. package/dist/src/cli/index.js +1 -1
  19. package/dist/src/cli/index.js.map +1 -1
  20. package/dist/src/cli/main.d.ts.map +1 -1
  21. package/dist/src/cli/main.js +76 -4
  22. package/dist/src/cli/main.js.map +1 -1
  23. package/dist/src/cli/paths.d.ts +2 -0
  24. package/dist/src/cli/paths.d.ts.map +1 -1
  25. package/dist/src/cli/paths.js +1 -0
  26. package/dist/src/cli/paths.js.map +1 -1
  27. package/dist/src/cli/portal.d.ts.map +1 -1
  28. package/dist/src/cli/portal.js +17 -3
  29. package/dist/src/cli/portal.js.map +1 -1
  30. package/dist/src/cli/rpc.d.ts +24 -0
  31. package/dist/src/cli/rpc.d.ts.map +1 -0
  32. package/dist/src/cli/rpc.js +68 -0
  33. package/dist/src/cli/rpc.js.map +1 -0
  34. package/dist/src/cli/status.d.ts.map +1 -1
  35. package/dist/src/cli/status.js +1 -1
  36. package/dist/src/cli/status.js.map +1 -1
  37. package/dist/src/cli/unlock.d.ts.map +1 -1
  38. package/dist/src/cli/unlock.js +1 -1
  39. package/dist/src/cli/unlock.js.map +1 -1
  40. package/dist/src/confirm/config.d.ts.map +1 -1
  41. package/dist/src/confirm/config.js.map +1 -1
  42. package/dist/src/confirm/index.d.ts +2 -2
  43. package/dist/src/confirm/index.d.ts.map +1 -1
  44. package/dist/src/confirm/index.js +1 -1
  45. package/dist/src/confirm/index.js.map +1 -1
  46. package/dist/src/confirm/ntfy.d.ts.map +1 -1
  47. package/dist/src/confirm/ntfy.js +5 -5
  48. package/dist/src/confirm/ntfy.js.map +1 -1
  49. package/dist/src/control/broadcast.d.ts.map +1 -1
  50. package/dist/src/control/broadcast.js +7 -4
  51. package/dist/src/control/broadcast.js.map +1 -1
  52. package/dist/src/control/client.d.ts.map +1 -1
  53. package/dist/src/control/client.js +5 -2
  54. package/dist/src/control/client.js.map +1 -1
  55. package/dist/src/control/protocol.d.ts.map +1 -1
  56. package/dist/src/control/protocol.js.map +1 -1
  57. package/dist/src/control/server.d.ts.map +1 -1
  58. package/dist/src/control/server.js +17 -4
  59. package/dist/src/control/server.js.map +1 -1
  60. package/dist/src/crypto/aead.d.ts.map +1 -1
  61. package/dist/src/crypto/aead.js.map +1 -1
  62. package/dist/src/crypto/index.d.ts +1 -1
  63. package/dist/src/crypto/index.d.ts.map +1 -1
  64. package/dist/src/crypto/index.js +1 -1
  65. package/dist/src/crypto/index.js.map +1 -1
  66. package/dist/src/crypto/keyfile.d.ts.map +1 -1
  67. package/dist/src/crypto/keyfile.js +1 -0
  68. package/dist/src/crypto/keyfile.js.map +1 -1
  69. package/dist/src/daemon/handles.d.ts.map +1 -1
  70. package/dist/src/daemon/handles.js +1 -1
  71. package/dist/src/daemon/handles.js.map +1 -1
  72. package/dist/src/daemon/index.d.ts +1 -1
  73. package/dist/src/daemon/index.d.ts.map +1 -1
  74. package/dist/src/daemon/index.js +1 -1
  75. package/dist/src/daemon/index.js.map +1 -1
  76. package/dist/src/daemon/methods.d.ts +8 -1
  77. package/dist/src/daemon/methods.d.ts.map +1 -1
  78. package/dist/src/daemon/methods.js +133 -13
  79. package/dist/src/daemon/methods.js.map +1 -1
  80. package/dist/src/daemon/passphrase.d.ts.map +1 -1
  81. package/dist/src/daemon/passphrase.js.map +1 -1
  82. package/dist/src/eth/address.d.ts.map +1 -1
  83. package/dist/src/eth/address.js +1 -1
  84. package/dist/src/eth/address.js.map +1 -1
  85. package/dist/src/eth/index.d.ts +2 -2
  86. package/dist/src/eth/index.d.ts.map +1 -1
  87. package/dist/src/eth/index.js +2 -2
  88. package/dist/src/eth/index.js.map +1 -1
  89. package/dist/src/eth/rlp.js +1 -1
  90. package/dist/src/eth/rlp.js.map +1 -1
  91. package/dist/src/eth/secp.d.ts.map +1 -1
  92. package/dist/src/eth/secp.js.map +1 -1
  93. package/dist/src/eth/sign-message.d.ts.map +1 -1
  94. package/dist/src/eth/sign-message.js.map +1 -1
  95. package/dist/src/eth/sign-tx.d.ts.map +1 -1
  96. package/dist/src/eth/sign-tx.js +13 -4
  97. package/dist/src/eth/sign-tx.js.map +1 -1
  98. package/dist/src/eth/sign-typed.d.ts.map +1 -1
  99. package/dist/src/eth/sign-typed.js.map +1 -1
  100. package/dist/src/fs/index.d.ts +2 -0
  101. package/dist/src/fs/index.d.ts.map +1 -0
  102. package/dist/src/fs/index.js +2 -0
  103. package/dist/src/fs/index.js.map +1 -0
  104. package/dist/src/fs/lock.d.ts +84 -0
  105. package/dist/src/fs/lock.d.ts.map +1 -0
  106. package/dist/src/fs/lock.js +329 -0
  107. package/dist/src/fs/lock.js.map +1 -0
  108. package/dist/src/hooks/bip39-wordlist.d.ts +12 -0
  109. package/dist/src/hooks/bip39-wordlist.d.ts.map +1 -0
  110. package/dist/src/hooks/bip39-wordlist.js +2061 -0
  111. package/dist/src/hooks/bip39-wordlist.js.map +1 -0
  112. package/dist/src/hooks/bip39.d.ts +19 -0
  113. package/dist/src/hooks/bip39.d.ts.map +1 -0
  114. package/dist/src/hooks/bip39.js +101 -0
  115. package/dist/src/hooks/bip39.js.map +1 -0
  116. package/dist/src/hooks/command-scanner.d.ts.map +1 -1
  117. package/dist/src/hooks/command-scanner.js +45 -9
  118. package/dist/src/hooks/command-scanner.js.map +1 -1
  119. package/dist/src/hooks/index.d.ts +1 -1
  120. package/dist/src/hooks/index.d.ts.map +1 -1
  121. package/dist/src/hooks/index.js +1 -1
  122. package/dist/src/hooks/index.js.map +1 -1
  123. package/dist/src/hooks/install.js +1 -1
  124. package/dist/src/hooks/install.js.map +1 -1
  125. package/dist/src/hooks/protocol.d.ts.map +1 -1
  126. package/dist/src/hooks/protocol.js +1 -1
  127. package/dist/src/hooks/protocol.js.map +1 -1
  128. package/dist/src/hooks/redactor.d.ts +10 -1
  129. package/dist/src/hooks/redactor.d.ts.map +1 -1
  130. package/dist/src/hooks/redactor.js +34 -3
  131. package/dist/src/hooks/redactor.js.map +1 -1
  132. package/dist/src/mcp/protocol.d.ts.map +1 -1
  133. package/dist/src/mcp/protocol.js +5 -1
  134. package/dist/src/mcp/protocol.js.map +1 -1
  135. package/dist/src/mcp/tools.d.ts.map +1 -1
  136. package/dist/src/mcp/tools.js +6 -3
  137. package/dist/src/mcp/tools.js.map +1 -1
  138. package/dist/src/policy/evaluate.d.ts.map +1 -1
  139. package/dist/src/policy/evaluate.js +71 -6
  140. package/dist/src/policy/evaluate.js.map +1 -1
  141. package/dist/src/policy/index.d.ts +3 -1
  142. package/dist/src/policy/index.d.ts.map +1 -1
  143. package/dist/src/policy/index.js +3 -1
  144. package/dist/src/policy/index.js.map +1 -1
  145. package/dist/src/policy/ledger.d.ts +83 -0
  146. package/dist/src/policy/ledger.d.ts.map +1 -0
  147. package/dist/src/policy/ledger.js +250 -0
  148. package/dist/src/policy/ledger.js.map +1 -0
  149. package/dist/src/policy/loader.d.ts.map +1 -1
  150. package/dist/src/policy/loader.js +45 -0
  151. package/dist/src/policy/loader.js.map +1 -1
  152. package/dist/src/policy/template.d.ts +2 -2
  153. package/dist/src/policy/template.d.ts.map +1 -1
  154. package/dist/src/policy/template.js +32 -0
  155. package/dist/src/policy/template.js.map +1 -1
  156. package/dist/src/policy/types.d.ts +26 -0
  157. package/dist/src/policy/types.d.ts.map +1 -1
  158. package/dist/src/policy/types.js.map +1 -1
  159. package/dist/src/policy/window.d.ts +22 -0
  160. package/dist/src/policy/window.d.ts.map +1 -0
  161. package/dist/src/policy/window.js +66 -0
  162. package/dist/src/policy/window.js.map +1 -0
  163. package/dist/src/qr/encode.d.ts +10 -1
  164. package/dist/src/qr/encode.d.ts.map +1 -1
  165. package/dist/src/qr/encode.js +2 -2
  166. package/dist/src/qr/encode.js.map +1 -1
  167. package/dist/src/qr/index.d.ts +1 -1
  168. package/dist/src/qr/index.d.ts.map +1 -1
  169. package/dist/src/qr/index.js.map +1 -1
  170. package/dist/src/rpc/fill.d.ts.map +1 -1
  171. package/dist/src/rpc/fill.js.map +1 -1
  172. package/dist/src/rpc/server.d.ts.map +1 -1
  173. package/dist/src/rpc/server.js +4 -2
  174. package/dist/src/rpc/server.js.map +1 -1
  175. package/dist/src/rpc/upstream.d.ts.map +1 -1
  176. package/dist/src/rpc/upstream.js.map +1 -1
  177. package/dist/src/svm/transaction.d.ts.map +1 -1
  178. package/dist/src/svm/transaction.js +13 -4
  179. package/dist/src/svm/transaction.js.map +1 -1
  180. package/package.json +16 -7
@@ -0,0 +1,329 @@
1
+ import { closeSync, mkdirSync, openSync, readdirSync, unlinkSync, writeSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { randomBytes } from 'node:crypto';
4
+ /**
5
+ * Cross-process mutex for the files several `sigil-mcp` instances append
6
+ * to concurrently (one per Claude window: the audit log, the per-portal
7
+ * spend ledgers). Node core has no flock(2) and sigil takes no native
8
+ * deps, so this is built from two atomic filesystem operations only:
9
+ * exclusive create and unlink of a process's *own* files.
10
+ *
11
+ * It is Lamport's bakery algorithm on a directory:
12
+ *
13
+ * 1. create c-<pid>-<token> "I am choosing a number"
14
+ * 2. read the directory; my number is 1 + the largest ticket number
15
+ * 3. create t-<number>-<pid>-<token> my ticket
16
+ * 4. unlink c-<pid>-<token>
17
+ * 5. wait until no other live process is choosing, and no other live
18
+ * process holds a ticket ordered before mine (number, pid, token)
19
+ * 6. critical section
20
+ * 7. unlink my ticket
21
+ *
22
+ * Why this and not a single lock file: with one file, recovering from a
23
+ * holder that died means deleting a path some other process may just
24
+ * have re-created, and every "check, then unlink" sequence is a race —
25
+ * in the lock, and again in any sidecar used to serialise the breaking.
26
+ * Here no process ever unlinks a live process's file. Tickets of dead
27
+ * pids are simply ignored (and swept, which is safe because their owner
28
+ * cannot act), so a crashed holder costs nothing and there is nothing to
29
+ * "break". Correctness needs only that a file present for the whole of a
30
+ * readdir is listed, which every filesystem gives.
31
+ *
32
+ * A process also recognises files carrying its own pid that no live
33
+ * acquisition in it holds: an orphan of its own (a release that failed)
34
+ * or a dead predecessor that had this pid. Both are swept.
35
+ *
36
+ * Residual gap, documented rather than hidden: pid reuse across
37
+ * *different* processes. A dead holder whose pid was recycled by an
38
+ * unrelated live process looks alive, and its ticket blocks everyone
39
+ * until that process exits or a human removes the file. That is an
40
+ * availability limit, not an exclusion failure; closing it needs OS-level
41
+ * locking.
42
+ *
43
+ * Upgrading: a daemon built before this change locks a single file
44
+ * `<target>.lock` and knows nothing of this directory, and its writer also
45
+ * has a currency check that a fresh chain can fool. Running old and new
46
+ * daemons against one log is therefore unsupported, and no bridge here can
47
+ * make it safe. This is not a new requirement: a running sigil-mcp never
48
+ * reloads code, so every Claude window must restart its sigil-mcp after any
49
+ * upgrade anyway (see README, "Multi-window behaviour").
50
+ */
51
+ export class FileLockError extends Error {
52
+ constructor(msg) {
53
+ super(`file lock error: ${msg}`);
54
+ this.name = 'FileLockError';
55
+ }
56
+ }
57
+ /** @deprecated alias kept for the audit module's public surface. */
58
+ export const AuditLockError = FileLockError;
59
+ const DEFAULT_TIMEOUT_MS = 5_000;
60
+ const DEFAULT_POLL_MS = 25;
61
+ /**
62
+ * Test-only seams. `afterTicket` runs once our ticket exists (before the
63
+ * choosing marker is withdrawn); `betweenScans` runs between the marker
64
+ * scan and the ticket scan of each admission check. Either may throw to
65
+ * simulate a failure at that point. Never set by production code.
66
+ */
67
+ export const _testHooks = {};
68
+ // Tokens this process currently holds (ticket or marker on disk that a
69
+ // live acquisition in this module instance owns). One module instance per
70
+ // process is assumed: worker threads or a second copy of this module would
71
+ // keep separate sets and could sweep each other's live files. sigil-mcp
72
+ // is single-threaded and loads this once.
73
+ const held = new Set();
74
+ function sleepSync(ms) {
75
+ Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, ms);
76
+ }
77
+ export function writeAllSync(fd, data) {
78
+ const buf = Buffer.from(data, 'utf8');
79
+ let written = 0;
80
+ while (written < buf.length) {
81
+ const n = writeSync(fd, buf, written, buf.length - written);
82
+ if (n <= 0)
83
+ throw new Error(`short write (${written}/${buf.length} bytes)`);
84
+ written += n;
85
+ }
86
+ }
87
+ function isAlive(pid) {
88
+ try {
89
+ process.kill(pid, 0);
90
+ return true;
91
+ }
92
+ catch (err) {
93
+ // EPERM means the pid exists but belongs to another user — still alive.
94
+ return err.code === 'EPERM';
95
+ }
96
+ }
97
+ const TICKET_RE = /^t-(\d+)-(\d+)-([0-9a-f]{16})$/;
98
+ const CHOOSING_RE = /^c-(\d+)-([0-9a-f]{16})$/;
99
+ function parseEntry(name) {
100
+ const t = TICKET_RE.exec(name);
101
+ if (t)
102
+ return { name, kind: 'ticket', seq: Number(t[1]), pid: Number(t[2]), token: t[3] };
103
+ const c = CHOOSING_RE.exec(name);
104
+ if (c)
105
+ return { name, kind: 'choosing', seq: 0, pid: Number(c[1]), token: c[2] };
106
+ return null; // not ours to interpret, never touched
107
+ }
108
+ function before(a, b) {
109
+ if (a.seq !== b.seq)
110
+ return a.seq < b.seq;
111
+ if (a.pid !== b.pid)
112
+ return a.pid < b.pid;
113
+ return a.token < b.token;
114
+ }
115
+ /** Exclusive create of an empty file; if close fails the file is removed. */
116
+ function createExclusive(path) {
117
+ const fd = openSync(path, 'wx', 0o600);
118
+ try {
119
+ closeSync(fd);
120
+ }
121
+ catch (err) {
122
+ unlinkQuiet(path);
123
+ throw err;
124
+ }
125
+ }
126
+ function unlinkQuiet(path) {
127
+ try {
128
+ unlinkSync(path);
129
+ }
130
+ catch {
131
+ /* already gone, or will be swept later */
132
+ }
133
+ }
134
+ /** Unlink that treats ENOENT as success and rethrows anything else. */
135
+ function unlinkOwn(path) {
136
+ try {
137
+ unlinkSync(path);
138
+ }
139
+ catch (err) {
140
+ if (err.code !== 'ENOENT')
141
+ throw err;
142
+ }
143
+ }
144
+ /**
145
+ * List the live contenders in `dir`, sweeping entries whose owner cannot
146
+ * act: dead pids, and this pid's own files that no live acquisition holds
147
+ * (an orphan of a failed release, or a dead predecessor that had this
148
+ * pid). Our own held entries are returned too, so a nested acquire sees
149
+ * the outer ticket as a contender and times out rather than deadlocking
150
+ * silently or entering twice.
151
+ */
152
+ function liveEntries(dir) {
153
+ const out = [];
154
+ for (const name of readdirSync(dir)) {
155
+ const e = parseEntry(name);
156
+ if (!e)
157
+ continue;
158
+ const sweep = e.pid === process.pid ? !held.has(e.token) : !isAlive(e.pid);
159
+ if (sweep) {
160
+ unlinkQuiet(join(dir, name));
161
+ continue;
162
+ }
163
+ out.push(e);
164
+ }
165
+ return out;
166
+ }
167
+ /**
168
+ * Admission check. Two separate enumerations, in this order:
169
+ * 1. is any other live process choosing? (if so, not admitted)
170
+ * 2. does any other live ticket order before mine?
171
+ *
172
+ * Why two: readdir is not a snapshot. A contender that withdraws its
173
+ * marker and publishes its ticket while one enumeration is in flight can
174
+ * be missed by that enumeration on both counts. With the marker read
175
+ * strictly before the ticket read, the argument is:
176
+ * - If C's marker existed for the whole of scan 1, we see it and retry.
177
+ * - If C's marker was created after scan 1 began, C picks its number
178
+ * after that, and our ticket (created before scan 1) is present for
179
+ * the whole of C's selection scan, so C's number is larger than ours.
180
+ * - If C's marker was withdrawn during scan 1, C's ticket already existed
181
+ * when scan 1 ended, so it is present for the whole of scan 2 and we
182
+ * see it.
183
+ * This is exactly Lamport's per-variable "wait until not choosing, then
184
+ * read number", with each variable read as one enumeration.
185
+ */
186
+ function admitted(dir, mine) {
187
+ const others = (es) => es.filter((e) => e.token !== mine.token);
188
+ if (others(liveEntries(dir)).some((e) => e.kind === 'choosing'))
189
+ return false;
190
+ _testHooks.betweenScans?.(dir);
191
+ return !others(liveEntries(dir)).some((e) => e.kind === 'ticket' && before(e, mine));
192
+ }
193
+ /**
194
+ * Acquire an exclusive cross-process lock over `lockDir` (created if
195
+ * absent). Returns an idempotent, retryable release function. Throws
196
+ * FileLockError if the lock cannot be acquired within `timeoutMs`. Any
197
+ * failure to acquire — timeout or error — withdraws our files first.
198
+ */
199
+ export function acquireLockSync(lockDir, opts = {}) {
200
+ const timeoutMs = opts.timeoutMs ?? DEFAULT_TIMEOUT_MS;
201
+ const pollMs = opts.pollMs ?? DEFAULT_POLL_MS;
202
+ const deadline = Date.now() + timeoutMs;
203
+ mkdirSync(lockDir, { recursive: true, mode: 0o700 });
204
+ const token = randomBytes(8).toString('hex');
205
+ const markerPath = join(lockDir, `c-${process.pid}-${token}`);
206
+ let ticketPath;
207
+ let markerOnDisk = false;
208
+ // Withdraw everything we put on disk. Throws if something we own could
209
+ // not be removed (the caller's retry path handles that); the held flag
210
+ // is dropped first so a leftover is recognisably our own orphan.
211
+ const withdraw = () => {
212
+ held.delete(token);
213
+ if (ticketPath)
214
+ unlinkOwn(ticketPath);
215
+ if (markerOnDisk)
216
+ unlinkOwn(markerPath);
217
+ markerOnDisk = false;
218
+ };
219
+ let mine;
220
+ try {
221
+ held.add(token);
222
+ createExclusive(markerPath);
223
+ markerOnDisk = true;
224
+ let max = 0;
225
+ for (const e of liveEntries(lockDir))
226
+ if (e.kind === 'ticket' && e.seq > max)
227
+ max = e.seq;
228
+ const seq = max + 1;
229
+ // Fail closed rather than hand out a number that isn't strictly larger
230
+ // than a live holder's: past MAX_SAFE_INTEGER, max + 1 === max, and two
231
+ // holders with the same number could both be admitted. One line per
232
+ // sign op, so this is unreachable in practice; refusing is still safer
233
+ // than a silent tie. (Withdraw runs via the catch below.)
234
+ if (!Number.isSafeInteger(seq) || seq <= max) {
235
+ throw new FileLockError(`ticket number space exhausted in ${lockDir}`);
236
+ }
237
+ mine = {
238
+ name: `t-${seq}-${process.pid}-${token}`,
239
+ kind: 'ticket',
240
+ seq,
241
+ pid: process.pid,
242
+ token,
243
+ };
244
+ ticketPath = join(lockDir, mine.name);
245
+ createExclusive(ticketPath);
246
+ _testHooks.afterTicket?.(lockDir);
247
+ // A marker we fail to withdraw now is retried at release; meanwhile it
248
+ // is ours (held), so our own admission check ignores it.
249
+ try {
250
+ unlinkOwn(markerPath);
251
+ markerOnDisk = false;
252
+ }
253
+ catch {
254
+ /* release() will retry */
255
+ }
256
+ for (;;) {
257
+ if (admitted(lockDir, mine))
258
+ break;
259
+ const remaining = deadline - Date.now();
260
+ if (remaining <= 0) {
261
+ throw new FileLockError(`timed out after ${timeoutMs}ms waiting for ${lockDir}`);
262
+ }
263
+ sleepSync(Math.min(pollMs, remaining));
264
+ }
265
+ }
266
+ catch (err) {
267
+ try {
268
+ withdraw();
269
+ }
270
+ catch {
271
+ /* our leftovers are held-less now; this process sweeps them next time */
272
+ }
273
+ throw err;
274
+ }
275
+ let released = false;
276
+ return () => {
277
+ if (released)
278
+ return;
279
+ withdraw(); // throws on failure, leaving the closure retryable
280
+ released = true;
281
+ };
282
+ }
283
+ /** Sidecar lock directory for a data file: `<target>.lock.d`. */
284
+ export function lockPathFor(target) {
285
+ return `${target}.lock.d`;
286
+ }
287
+ /**
288
+ * Run `fn` while holding the sidecar lock for `target`. Synchronous by
289
+ * design (callers are synchronous append paths) and therefore not
290
+ * re-entrant: a nested acquire of the same target times out.
291
+ */
292
+ export function withFileLock(target, fn, opts = {}) {
293
+ const lockDir = lockPathFor(target);
294
+ const release = acquireLockSync(lockDir, opts);
295
+ try {
296
+ return fn();
297
+ }
298
+ finally {
299
+ releaseWithRetry(release, lockDir);
300
+ }
301
+ }
302
+ /**
303
+ * A ticket or marker with a live pid blocks every other session until it
304
+ * is gone, so a release that fails would stall them until this process
305
+ * exits. Retry a transient failure with backoff; if it still won't go,
306
+ * report on stderr — never replace fn's outcome (a committed append must
307
+ * not be reported as a failure, and fn's own error must not be masked).
308
+ * The files are not lost for good: no live acquisition holds their token
309
+ * any more, so this process sweeps them as its own orphans on its next
310
+ * acquire.
311
+ */
312
+ const RELEASE_ATTEMPTS = 5;
313
+ export function releaseWithRetry(release, lockDir) {
314
+ let last;
315
+ for (let i = 0; i < RELEASE_ATTEMPTS; i++) {
316
+ try {
317
+ release();
318
+ return;
319
+ }
320
+ catch (err) {
321
+ last = err;
322
+ sleepSync(10 * (i + 1));
323
+ }
324
+ }
325
+ process.stderr.write(`sigil: failed to release a ticket in ${lockDir} after ${RELEASE_ATTEMPTS} attempts ` +
326
+ `(${last?.message ?? String(last)}); this process will sweep it on its ` +
327
+ `next acquire, other sessions will wait until then\n`);
328
+ }
329
+ //# sourceMappingURL=lock.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lock.js","sourceRoot":"","sources":["../../../src/fs/lock.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAC7F,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IACtC,YAAY,GAAW;QACrB,KAAK,CAAC,oBAAoB,GAAG,EAAE,CAAC,CAAC;QACjC,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AACD,oEAAoE;AACpE,MAAM,CAAC,MAAM,cAAc,GAAG,aAAa,CAAC;AAO5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/C,IAAI,CAAC;QACH,OAAO,EAAE,EAAE,CAAC;IACd,CAAC;YAAS,CAAC;QACT,gBAAgB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACrC,CAAC;AACH,CAAC;AAED;;;;;;;;;GASG;AACH,MAAM,gBAAgB,GAAG,CAAC,CAAC;AAC3B,MAAM,UAAU,gBAAgB,CAAC,OAAmB,EAAE,OAAe;IACnE,IAAI,IAAa,CAAC;IAClB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,gBAAgB,EAAE,CAAC,EAAE,EAAE,CAAC;QAC1C,IAAI,CAAC;YACH,OAAO,EAAE,CAAC;YACV,OAAO;QACT,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,GAAG,GAAG,CAAC;YACX,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IACD,OAAO,CAAC,MAAM,CAAC,KAAK,CAClB,wCAAwC,OAAO,UAAU,gBAAgB,YAAY;QACnF,IAAK,IAAc,EAAE,OAAO,IAAI,MAAM,CAAC,IAAI,CAAC,uCAAuC;QACnF,qDAAqD,CACxD,CAAC;AACJ,CAAC"}
@@ -0,0 +1,12 @@
1
+ /**
2
+ * BIP-39 English wordlist (2048 words), vendored — not an npm dependency, in
3
+ * keeping with sigil's supply-chain posture. Used only by the output redactor
4
+ * to checksum-validate candidate seed phrases before redacting them.
5
+ *
6
+ * Provenance: bitcoin/bips bip-0039/english.txt
7
+ * sha256 = 2f5eed53a4727b4bf8880d8f3f199efc90e58503646d9ff8eff3a2ed3b24dbda
8
+ * The accompanying test re-asserts this hash AND the official BIP-39 test
9
+ * vectors, so correctness rests on those checks, not on the vendoring step.
10
+ */
11
+ export declare const BIP39_WORDLIST: readonly string[];
12
+ //# sourceMappingURL=bip39-wordlist.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bip39-wordlist.d.ts","sourceRoot":"","sources":["../../../src/hooks/bip39-wordlist.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc,EAAE,SAAS,MAAM,EAigE1C,CAAC"}