@rotifer/playground 0.34.0 → 0.36.0

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 (83) hide show
  1. package/CHANGELOG.md +33 -0
  2. package/README.md +4 -2
  3. package/README.zh.md +2 -2
  4. package/dist/cloud/auth.d.ts +7 -0
  5. package/dist/cloud/auth.d.ts.map +1 -1
  6. package/dist/cloud/auth.js +35 -35
  7. package/dist/cloud/auth.js.map +1 -1
  8. package/dist/cloud/callback-page.d.ts +2 -0
  9. package/dist/cloud/callback-page.d.ts.map +1 -0
  10. package/dist/cloud/callback-page.js +45 -0
  11. package/dist/cloud/callback-page.js.map +1 -0
  12. package/dist/cloud/gene-availability.d.ts +31 -0
  13. package/dist/cloud/gene-availability.d.ts.map +1 -0
  14. package/dist/cloud/gene-availability.js +75 -0
  15. package/dist/cloud/gene-availability.js.map +1 -0
  16. package/dist/commands/agent-run.d.ts +9 -0
  17. package/dist/commands/agent-run.d.ts.map +1 -1
  18. package/dist/commands/agent-run.js +5 -4
  19. package/dist/commands/agent-run.js.map +1 -1
  20. package/dist/commands/arena-submit.d.ts.map +1 -1
  21. package/dist/commands/arena-submit.js +2 -1
  22. package/dist/commands/arena-submit.js.map +1 -1
  23. package/dist/commands/hello.d.ts +27 -0
  24. package/dist/commands/hello.d.ts.map +1 -1
  25. package/dist/commands/hello.js +286 -59
  26. package/dist/commands/hello.js.map +1 -1
  27. package/dist/commands/init.d.ts +2 -0
  28. package/dist/commands/init.d.ts.map +1 -1
  29. package/dist/commands/init.js +3 -1
  30. package/dist/commands/init.js.map +1 -1
  31. package/dist/commands/login.d.ts.map +1 -1
  32. package/dist/commands/login.js +29 -32
  33. package/dist/commands/login.js.map +1 -1
  34. package/dist/commands/network-attest.d.ts +55 -0
  35. package/dist/commands/network-attest.d.ts.map +1 -0
  36. package/dist/commands/network-attest.js +266 -0
  37. package/dist/commands/network-attest.js.map +1 -0
  38. package/dist/commands/network.d.ts.map +1 -1
  39. package/dist/commands/network.js +11 -0
  40. package/dist/commands/network.js.map +1 -1
  41. package/dist/commands/publish.d.ts.map +1 -1
  42. package/dist/commands/publish.js +2 -1
  43. package/dist/commands/publish.js.map +1 -1
  44. package/dist/commands/run.d.ts.map +1 -1
  45. package/dist/commands/run.js +4 -3
  46. package/dist/commands/run.js.map +1 -1
  47. package/dist/commands/test.js +6 -6
  48. package/dist/commands/test.js.map +1 -1
  49. package/dist/commands/wrap.d.ts +4 -0
  50. package/dist/commands/wrap.d.ts.map +1 -1
  51. package/dist/commands/wrap.js +86 -11
  52. package/dist/commands/wrap.js.map +1 -1
  53. package/dist/testsuite/generate.d.ts.map +1 -1
  54. package/dist/testsuite/generate.js +23 -0
  55. package/dist/testsuite/generate.js.map +1 -1
  56. package/dist/utils/binding.d.ts +9 -0
  57. package/dist/utils/binding.d.ts.map +1 -1
  58. package/dist/utils/binding.js.map +1 -1
  59. package/dist/utils/l0-gate.d.ts +9 -0
  60. package/dist/utils/l0-gate.d.ts.map +1 -1
  61. package/dist/utils/l0-gate.js +27 -0
  62. package/dist/utils/l0-gate.js.map +1 -1
  63. package/dist/utils/open-browser.d.ts +9 -2
  64. package/dist/utils/open-browser.d.ts.map +1 -1
  65. package/dist/utils/open-browser.js +39 -5
  66. package/dist/utils/open-browser.js.map +1 -1
  67. package/dist/utils/p2p-daemon.d.ts +9 -0
  68. package/dist/utils/p2p-daemon.d.ts.map +1 -1
  69. package/dist/utils/p2p-daemon.js +26 -0
  70. package/dist/utils/p2p-daemon.js.map +1 -1
  71. package/dist/utils/por-client.d.ts +86 -0
  72. package/dist/utils/por-client.d.ts.map +1 -0
  73. package/dist/utils/por-client.js +245 -0
  74. package/dist/utils/por-client.js.map +1 -0
  75. package/dist/utils/por-keeper.d.ts +82 -0
  76. package/dist/utils/por-keeper.d.ts.map +1 -0
  77. package/dist/utils/por-keeper.js +237 -0
  78. package/dist/utils/por-keeper.js.map +1 -0
  79. package/dist/utils/zip-safety.d.ts +18 -0
  80. package/dist/utils/zip-safety.d.ts.map +1 -0
  81. package/dist/utils/zip-safety.js +102 -0
  82. package/dist/utils/zip-safety.js.map +1 -0
  83. package/package.json +5 -5
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PorKeeper = exports.RENEW_RETRY_MS = exports.RENEW_CHECK_MS = exports.RENEW_WHEN_REMAINING_S = void 0;
4
+ exports.isRenewalDue = isRenewalDue;
5
+ exports.porStatePath = porStatePath;
6
+ exports.readPorState = readPorState;
7
+ exports.writePorState = writePorState;
8
+ exports.removePorState = removePorState;
9
+ exports.stateFor = stateFor;
10
+ exports.viewOf = viewOf;
11
+ /**
12
+ * The node's certificate on disk, and the daemon's job of keeping it fresh
13
+ * (ADR-300 revision 2).
14
+ *
15
+ * `~/.rotifer/p2p/attestation.json` (mode 0600) exists only while certificates
16
+ * are enabled. Its absence is the default: off.
17
+ *
18
+ * Renewal timing is decided in one place, `isRenewalDue`. The service has its
19
+ * own too-early rule (at most one reissue a day unless under 48 h remain); a
20
+ * node that waits for `isRenewalDue` never meets it.
21
+ */
22
+ const node_fs_1 = require("node:fs");
23
+ const node_path_1 = require("node:path");
24
+ const private_fs_js_1 = require("./private-fs.js");
25
+ const por_client_js_1 = require("./por-client.js");
26
+ exports.RENEW_WHEN_REMAINING_S = 48 * 3600;
27
+ /** How often the daemon looks at the certificate. */
28
+ exports.RENEW_CHECK_MS = 10 * 60 * 1000;
29
+ /** How long the daemon waits after a failed renewal; at most 48 tries before expiry. */
30
+ exports.RENEW_RETRY_MS = 60 * 60 * 1000;
31
+ /** The one judgement of when a certificate should be renewed. */
32
+ function isRenewalDue(expS, nowS) {
33
+ return expS - nowS < exports.RENEW_WHEN_REMAINING_S;
34
+ }
35
+ function porStatePath(rotiferHome) {
36
+ return (0, node_path_1.join)(rotiferHome, "p2p", "attestation.json");
37
+ }
38
+ function isPorState(v) {
39
+ const s = v;
40
+ return (typeof s === "object" &&
41
+ s !== null &&
42
+ typeof s.peerId === "string" &&
43
+ typeof s.token === "string" &&
44
+ typeof s.iat === "number" &&
45
+ typeof s.exp === "number");
46
+ }
47
+ function readPorState(path) {
48
+ if (!(0, node_fs_1.existsSync)(path))
49
+ return null;
50
+ try {
51
+ const parsed = JSON.parse((0, node_fs_1.readFileSync)(path, "utf-8"));
52
+ if (!isPorState(parsed))
53
+ return null;
54
+ return {
55
+ ...parsed,
56
+ lastRenewalAttemptAt: parsed.lastRenewalAttemptAt ?? null,
57
+ lastRenewedAt: parsed.lastRenewedAt ?? null,
58
+ lastFailure: parsed.lastFailure ?? null,
59
+ };
60
+ }
61
+ catch {
62
+ return null;
63
+ }
64
+ }
65
+ function writePorState(path, state) {
66
+ (0, private_fs_js_1.ensurePrivateDir)((0, node_path_1.dirname)(path));
67
+ const tmp = `${path}.${process.pid}.tmp`;
68
+ (0, node_fs_1.writeFileSync)(tmp, JSON.stringify(state, null, 2) + "\n", { mode: 0o600 });
69
+ (0, private_fs_js_1.tightenPrivateFile)(tmp);
70
+ (0, node_fs_1.renameSync)(tmp, path);
71
+ (0, private_fs_js_1.tightenPrivateFile)(path);
72
+ }
73
+ function removePorState(path) {
74
+ (0, node_fs_1.rmSync)(path, { force: true });
75
+ }
76
+ /** State for a fresh certificate, recording when it was obtained. */
77
+ function stateFor(cert, nowMs) {
78
+ return {
79
+ peerId: cert.peerId,
80
+ token: cert.token,
81
+ iat: cert.iat,
82
+ exp: cert.exp,
83
+ lastRenewalAttemptAt: nowMs,
84
+ lastRenewedAt: nowMs,
85
+ lastFailure: null,
86
+ };
87
+ }
88
+ const OFF = {
89
+ state: "off",
90
+ peerId: null,
91
+ issuedAt: null,
92
+ expiresAt: null,
93
+ expiresInSeconds: null,
94
+ autoRenew: false,
95
+ lastRenewalAttemptAt: null,
96
+ lastRenewedAt: null,
97
+ lastFailure: null,
98
+ };
99
+ /** `nodePeerId` is null when no native node is at hand to compare with. */
100
+ function viewOf(state, nodePeerId, nowS) {
101
+ if (!state)
102
+ return OFF;
103
+ const isKeyChanged = nodePeerId !== null && nodePeerId !== state.peerId;
104
+ const remaining = Math.max(0, state.exp - nowS);
105
+ return {
106
+ state: isKeyChanged ? "key_changed" : remaining > 0 ? "active" : "expired",
107
+ peerId: state.peerId,
108
+ issuedAt: state.iat,
109
+ expiresAt: state.exp,
110
+ expiresInSeconds: remaining,
111
+ autoRenew: !isKeyChanged,
112
+ lastRenewalAttemptAt: state.lastRenewalAttemptAt,
113
+ lastRenewedAt: state.lastRenewedAt,
114
+ lastFailure: state.lastFailure,
115
+ };
116
+ }
117
+ /**
118
+ * Keeps a running node's certificate loaded and fresh. A failure is recorded
119
+ * where `status` shows it and tried again later; nothing it does can stop the
120
+ * node, and a failed renewal leaves the current certificate in use.
121
+ */
122
+ class PorKeeper {
123
+ deps;
124
+ now;
125
+ log;
126
+ timer;
127
+ isTicking = false;
128
+ retryAfterMs = 0;
129
+ hasWarnedKeyChange = false;
130
+ constructor(deps) {
131
+ this.deps = deps;
132
+ this.now = deps.now ?? Date.now;
133
+ this.log = deps.log ?? (() => { });
134
+ }
135
+ start() {
136
+ this.reload();
137
+ void this.tick();
138
+ this.timer = setInterval(() => void this.tick(), exports.RENEW_CHECK_MS);
139
+ this.timer.unref?.();
140
+ }
141
+ stop() {
142
+ if (this.timer !== undefined)
143
+ clearInterval(this.timer);
144
+ this.timer = undefined;
145
+ }
146
+ nowS() {
147
+ return Math.floor(this.now() / 1000);
148
+ }
149
+ setToken(token) {
150
+ try {
151
+ this.deps.node.setAttestation(token);
152
+ return true;
153
+ }
154
+ catch {
155
+ return false;
156
+ }
157
+ }
158
+ /** Apply what is on disk: after `start`, and when `attest` changed it. */
159
+ reload() {
160
+ this.retryAfterMs = 0;
161
+ const state = readPorState(this.deps.path);
162
+ const nodePeerId = this.deps.node.peerId();
163
+ const view = viewOf(state, nodePeerId, this.nowS());
164
+ if (view.state === "active" && state) {
165
+ if (!this.setToken(state.token))
166
+ this.log("attestation: the stored certificate could not be loaded");
167
+ }
168
+ else {
169
+ this.setToken(null);
170
+ }
171
+ if (view.state === "key_changed" && !this.hasWarnedKeyChange) {
172
+ this.hasWarnedKeyChange = true;
173
+ this.log(`attestation: ${por_client_js_1.KEY_CHANGE_NOTICE}`);
174
+ }
175
+ return view;
176
+ }
177
+ view() {
178
+ return viewOf(readPorState(this.deps.path), this.deps.node.peerId(), this.nowS());
179
+ }
180
+ /** Stop carrying a lapsed certificate, and renew one that is due. */
181
+ async tick() {
182
+ if (this.isTicking)
183
+ return;
184
+ this.isTicking = true;
185
+ try {
186
+ await this.renewIfDue();
187
+ }
188
+ catch (err) {
189
+ // State-file trouble and the like: the node runs on regardless.
190
+ this.log(`attestation: renewal check failed (${(0, por_client_js_1.asPorError)(err).code})`);
191
+ }
192
+ finally {
193
+ this.isTicking = false;
194
+ }
195
+ }
196
+ async renewIfDue() {
197
+ const state = readPorState(this.deps.path);
198
+ if (!state || state.peerId !== this.deps.node.peerId())
199
+ return;
200
+ if (state.exp <= this.nowS())
201
+ this.setToken(null);
202
+ if (!isRenewalDue(state.exp, this.nowS()) || this.now() < this.retryAfterMs)
203
+ return;
204
+ let failure;
205
+ try {
206
+ const cert = await this.deps.obtain(this.deps.node);
207
+ // `attest disable` may have run during the round: its choice stands.
208
+ if (!readPorState(this.deps.path)) {
209
+ this.log("attestation: certificates were turned off during renewal; the new one was dropped");
210
+ return;
211
+ }
212
+ if (this.setToken(cert.token)) {
213
+ writePorState(this.deps.path, stateFor(cert, this.now()));
214
+ this.retryAfterMs = 0;
215
+ this.log("attestation: certificate renewed");
216
+ return;
217
+ }
218
+ failure = new por_client_js_1.PorError("POR_BAD_RESPONSE");
219
+ }
220
+ catch (err) {
221
+ failure = (0, por_client_js_1.asPorError)(err);
222
+ }
223
+ this.retryAfterMs = this.now() + exports.RENEW_RETRY_MS;
224
+ this.log(`attestation: renewal failed (${failure.code}); will retry`);
225
+ // Read again: `attest disable` may have run during the round.
226
+ const latest = readPorState(this.deps.path);
227
+ if (latest) {
228
+ writePorState(this.deps.path, {
229
+ ...latest,
230
+ lastRenewalAttemptAt: this.now(),
231
+ lastFailure: { code: failure.code, message: failure.message, fix: failure.fix },
232
+ });
233
+ }
234
+ }
235
+ }
236
+ exports.PorKeeper = PorKeeper;
237
+ //# sourceMappingURL=por-keeper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"por-keeper.js","sourceRoot":"","sources":["../../src/utils/por-keeper.ts"],"names":[],"mappings":";;;AA8BA,oCAEC;AAkBD,oCAEC;AAcD,oCAcC;AAED,sCAOC;AAED,wCAEC;AAGD,4BAUC;AAkCD,wBAeC;AA3JD;;;;;;;;;;GAUG;AACH,qCAAsF;AACtF,yCAA0C;AAC1C,mDAAuE;AACvE,mDAOyB;AAEZ,QAAA,sBAAsB,GAAG,EAAE,GAAG,IAAI,CAAC;AAChD,qDAAqD;AACxC,QAAA,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAC7C,wFAAwF;AAC3E,QAAA,cAAc,GAAG,EAAE,GAAG,EAAE,GAAG,IAAI,CAAC;AAE7C,iEAAiE;AACjE,SAAgB,YAAY,CAAC,IAAY,EAAE,IAAY;IACrD,OAAO,IAAI,GAAG,IAAI,GAAG,8BAAsB,CAAC;AAC9C,CAAC;AAkBD,SAAgB,YAAY,CAAC,WAAmB;IAC9C,OAAO,IAAA,gBAAI,EAAC,WAAW,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC;AACtD,CAAC;AAED,SAAS,UAAU,CAAC,CAAU;IAC5B,MAAM,CAAC,GAAG,CAAoB,CAAC;IAC/B,OAAO,CACL,OAAO,CAAC,KAAK,QAAQ;QACrB,CAAC,KAAK,IAAI;QACV,OAAO,CAAC,CAAC,MAAM,KAAK,QAAQ;QAC5B,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ;QAC3B,OAAO,CAAC,CAAC,GAAG,KAAK,QAAQ;QACzB,OAAO,CAAC,CAAC,GAAG,KAAK,QAAQ,CAC1B,CAAC;AAC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,YAAY,GAAG,CAAC,CAAC;gBACtB,IAAI,CAAC,GAAG,CAAC,kCAAkC,CAAC,CAAC;gBAC7C,OAAO;YACT,CAAC;YACD,OAAO,GAAG,IAAI,wBAAQ,CAAC,kBAAkB,CAAC,CAAC;QAC7C,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,GAAG,IAAA,0BAAU,EAAC,GAAG,CAAC,CAAC;QAC5B,CAAC;QACD,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,sBAAc,CAAC;QAChD,IAAI,CAAC,GAAG,CAAC,gCAAgC,OAAO,CAAC,IAAI,eAAe,CAAC,CAAC;QACtE,8DAA8D;QAC9D,MAAM,MAAM,GAAG,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAI,MAAM,EAAE,CAAC;YACX,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE;gBAC5B,GAAG,MAAM;gBACT,oBAAoB,EAAE,IAAI,CAAC,GAAG,EAAE;gBAChC,WAAW,EAAE,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,OAAO,EAAE,GAAG,EAAE,OAAO,CAAC,GAAG,EAAE;aAChF,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF;AA9GD,8BA8GC"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * A downloaded archive is someone else's upload. These two checks stop it from
3
+ * reaching outside its own files: one reads the archive before anything is
4
+ * written, the other inspects what extraction really produced, in case
5
+ * `unzip` read the archive differently than this parser did.
6
+ */
7
+ export declare class UnsafeArchiveError extends Error {
8
+ constructor(message: string);
9
+ }
10
+ /**
11
+ * Throws UnsafeArchiveError when the zip holds a link, a path that leaves the
12
+ * extraction directory, or a structure this parser cannot vouch for. Bytes it
13
+ * cannot read are refused rather than handed to `unzip` on trust.
14
+ */
15
+ export declare function assertSafeZip(zip: Buffer): void;
16
+ /** Throws UnsafeArchiveError when `dir` holds anything but regular files and directories. */
17
+ export declare function assertOnlyRegularFiles(dir: string): void;
18
+ //# sourceMappingURL=zip-safety.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip-safety.d.ts","sourceRoot":"","sources":["../../src/utils/zip-safety.ts"],"names":[],"mappings":"AAGA;;;;;GAKG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;gBAC/B,OAAO,EAAE,MAAM;CAI5B;AAmCD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CA+B/C;AAED,6FAA6F;AAC7F,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,IAAI,CAWxD"}
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UnsafeArchiveError = void 0;
4
+ exports.assertSafeZip = assertSafeZip;
5
+ exports.assertOnlyRegularFiles = assertOnlyRegularFiles;
6
+ const node_fs_1 = require("node:fs");
7
+ const node_path_1 = require("node:path");
8
+ /**
9
+ * A downloaded archive is someone else's upload. These two checks stop it from
10
+ * reaching outside its own files: one reads the archive before anything is
11
+ * written, the other inspects what extraction really produced, in case
12
+ * `unzip` read the archive differently than this parser did.
13
+ */
14
+ class UnsafeArchiveError extends Error {
15
+ constructor(message) {
16
+ super(message);
17
+ this.name = "UnsafeArchiveError";
18
+ }
19
+ }
20
+ exports.UnsafeArchiveError = UnsafeArchiveError;
21
+ const END_RECORD = 0x06054b50;
22
+ const END_RECORD_SIZE = 22;
23
+ const CENTRAL_ENTRY = 0x02014b50;
24
+ const CENTRAL_ENTRY_SIZE = 46;
25
+ const MAX_COMMENT = 0xffff;
26
+ const FILE_TYPE_MASK = 0o170000;
27
+ const SYMLINK_TYPE = 0o120000;
28
+ function unreadable(reason) {
29
+ return new UnsafeArchiveError(`the archive could not be read safely (${reason})`);
30
+ }
31
+ /** Finds the end record the way `unzip` does: the last signature in the tail. */
32
+ function findEndRecord(zip) {
33
+ const lowest = Math.max(0, zip.length - END_RECORD_SIZE - MAX_COMMENT);
34
+ for (let i = zip.length - END_RECORD_SIZE; i >= lowest; i--) {
35
+ if (zip.readUInt32LE(i) === END_RECORD)
36
+ return i;
37
+ }
38
+ throw unreadable("no end-of-archive record");
39
+ }
40
+ function checkEntryName(name) {
41
+ const shown = JSON.stringify(name);
42
+ if (name.includes("\0"))
43
+ throw new UnsafeArchiveError(`entry ${shown} has a NUL byte in its name`);
44
+ const normalized = name.replace(/\\/g, "/");
45
+ if (normalized.startsWith("/") || /^[A-Za-z]:/.test(normalized)) {
46
+ throw new UnsafeArchiveError(`entry ${shown} has an absolute path`);
47
+ }
48
+ if (normalized.split("/").includes("..")) {
49
+ throw new UnsafeArchiveError(`entry ${shown} climbs out of the archive`);
50
+ }
51
+ }
52
+ /**
53
+ * Throws UnsafeArchiveError when the zip holds a link, a path that leaves the
54
+ * extraction directory, or a structure this parser cannot vouch for. Bytes it
55
+ * cannot read are refused rather than handed to `unzip` on trust.
56
+ */
57
+ function assertSafeZip(zip) {
58
+ if (zip.length < END_RECORD_SIZE)
59
+ throw unreadable("too short");
60
+ const end = findEndRecord(zip);
61
+ if (end + END_RECORD_SIZE + zip.readUInt16LE(end + 20) !== zip.length) {
62
+ throw unreadable("bytes after the end of the archive");
63
+ }
64
+ const count = zip.readUInt16LE(end + 10);
65
+ const offset = zip.readUInt32LE(end + 16);
66
+ if (offset >= end && count > 0)
67
+ throw unreadable("directory outside the file");
68
+ let pos = offset;
69
+ for (let i = 0; i < count; i++) {
70
+ if (pos + CENTRAL_ENTRY_SIZE > end || zip.readUInt32LE(pos) !== CENTRAL_ENTRY) {
71
+ throw unreadable("directory shorter than it claims");
72
+ }
73
+ const nameLength = zip.readUInt16LE(pos + 28);
74
+ const extraLength = zip.readUInt16LE(pos + 30);
75
+ const commentLength = zip.readUInt16LE(pos + 32);
76
+ const mode = zip.readUInt32LE(pos + 38) >>> 16;
77
+ const nameEnd = pos + CENTRAL_ENTRY_SIZE + nameLength;
78
+ if (nameEnd > end)
79
+ throw unreadable("entry name past the directory");
80
+ const name = zip.toString("utf-8", pos + CENTRAL_ENTRY_SIZE, nameEnd);
81
+ checkEntryName(name);
82
+ if ((mode & FILE_TYPE_MASK) === SYMLINK_TYPE) {
83
+ throw new UnsafeArchiveError(`entry ${JSON.stringify(name)} is a symbolic link`);
84
+ }
85
+ pos = nameEnd + extraLength + commentLength;
86
+ }
87
+ }
88
+ /** Throws UnsafeArchiveError when `dir` holds anything but regular files and directories. */
89
+ function assertOnlyRegularFiles(dir) {
90
+ for (const entry of (0, node_fs_1.readdirSync)(dir)) {
91
+ const path = (0, node_path_1.join)(dir, entry);
92
+ const stat = (0, node_fs_1.lstatSync)(path);
93
+ if (stat.isDirectory()) {
94
+ assertOnlyRegularFiles(path);
95
+ }
96
+ else if (!stat.isFile()) {
97
+ const kind = stat.isSymbolicLink() ? "a symbolic link" : "not a regular file";
98
+ throw new UnsafeArchiveError(`extracted entry ${JSON.stringify(entry)} is ${kind}`);
99
+ }
100
+ }
101
+ }
102
+ //# sourceMappingURL=zip-safety.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zip-safety.js","sourceRoot":"","sources":["../../src/utils/zip-safety.ts"],"names":[],"mappings":";;;AAsDA,sCA+BC;AAGD,wDAWC;AAnGD,qCAAiD;AACjD,yCAAiC;AAEjC;;;;;GAKG;AACH,MAAa,kBAAmB,SAAQ,KAAK;IAC3C,YAAY,OAAe;QACzB,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF;AALD,gDAKC;AAED,MAAM,UAAU,GAAG,UAAU,CAAC;AAC9B,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,aAAa,GAAG,UAAU,CAAC;AACjC,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,WAAW,GAAG,MAAM,CAAC;AAC3B,MA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ED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rotifer/playground",
3
- "version": "0.34.0",
3
+ "version": "0.36.0",
4
4
  "description": "Rotifer Protocol Playground — local development environment for gene development, Arena competition, and protocol simulation",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Rotifer Protocol Contributors",
@@ -96,10 +96,10 @@
96
96
  "vitest": "^4.1.11"
97
97
  },
98
98
  "optionalDependencies": {
99
- "@rotifer/playground-darwin-arm64": "0.34.0",
100
- "@rotifer/playground-darwin-x64": "0.34.0",
101
- "@rotifer/playground-linux-x64-gnu": "0.34.0",
102
- "@rotifer/playground-win32-x64-msvc": "0.34.0"
99
+ "@rotifer/playground-darwin-arm64": "0.36.0",
100
+ "@rotifer/playground-darwin-x64": "0.36.0",
101
+ "@rotifer/playground-linux-x64-gnu": "0.36.0",
102
+ "@rotifer/playground-win32-x64-msvc": "0.36.0"
103
103
  },
104
104
  "engines": {
105
105
  "node": ">=22.18.0"