@joe-broadhead/messaging 0.0.0-stage → 0.7.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/CHANGELOG.md +220 -0
- package/LICENSE +21 -0
- package/NOTICE +12 -0
- package/README.md +36 -2
- package/dist/bin/messaging-mcp.js +26524 -0
- package/dist/bin/messaging-relay.js +19768 -0
- package/dist/bin/messaging.js +15465 -0
- package/dist/bin/messagingd.js +29449 -0
- package/dist/lib/core-testing.js +1 -0
- package/dist/lib/core.js +1 -0
- package/dist/lib/ipc-testing.js +1 -0
- package/dist/lib/ipc.js +1 -0
- package/dist/lib/modules/core/address.js +42 -0
- package/dist/lib/modules/core/agent/operations.js +595 -0
- package/dist/lib/modules/core/agent/present.js +244 -0
- package/dist/lib/modules/core/agent/text.js +79 -0
- package/dist/lib/modules/core/agent-tools.js +477 -0
- package/dist/lib/modules/core/b64u.js +20 -0
- package/dist/lib/modules/core/cards.js +55 -0
- package/dist/lib/modules/core/check.js +20 -0
- package/dist/lib/modules/core/consent.js +199 -0
- package/dist/lib/modules/core/contact-card.js +74 -0
- package/dist/lib/modules/core/conversation/context.js +80 -0
- package/dist/lib/modules/core/conversation/event.js +100 -0
- package/dist/lib/modules/core/conversation/ids.js +38 -0
- package/dist/lib/modules/core/conversation/link.js +35 -0
- package/dist/lib/modules/core/conversation/log.js +766 -0
- package/dist/lib/modules/core/conversation/ratchet.js +243 -0
- package/dist/lib/modules/core/conversation/seal.js +198 -0
- package/dist/lib/modules/core/delegation.js +174 -0
- package/dist/lib/modules/core/directory/device-log.js +258 -0
- package/dist/lib/modules/core/directory/epoch.js +103 -0
- package/dist/lib/modules/core/directory/handle.js +29 -0
- package/dist/lib/modules/core/directory/jelly-device.js +204 -0
- package/dist/lib/modules/core/directory/jelly-issuer.js +12 -0
- package/dist/lib/modules/core/directory/jelly-token.js +305 -0
- package/dist/lib/modules/core/directory/keys-statement.js +43 -0
- package/dist/lib/modules/core/directory/link.js +81 -0
- package/dist/lib/modules/core/directory/merkle-log.js +250 -0
- package/dist/lib/modules/core/directory/person-view.js +197 -0
- package/dist/lib/modules/core/directory/person.js +40 -0
- package/dist/lib/modules/core/directory/realm.js +59 -0
- package/dist/lib/modules/core/directory/smt.js +266 -0
- package/dist/lib/modules/core/envelope.js +320 -0
- package/dist/lib/modules/core/hash.js +5 -0
- package/dist/lib/modules/core/head.js +27 -0
- package/dist/lib/modules/core/identity.js +71 -0
- package/dist/lib/modules/core/index.js +53 -0
- package/dist/lib/modules/core/jcs.js +96 -0
- package/dist/lib/modules/core/jelly-host-double.js +35 -0
- package/dist/lib/modules/core/jelly-host.js +211 -0
- package/dist/lib/modules/core/keys.js +79 -0
- package/dist/lib/modules/core/peer-text.js +563 -0
- package/dist/lib/modules/core/realm.js +1 -0
- package/dist/lib/modules/core/roster.js +454 -0
- package/dist/lib/modules/core/schema/a2a.js +85 -0
- package/dist/lib/modules/core/schema/common.js +310 -0
- package/dist/lib/modules/core/schema/consent.js +120 -0
- package/dist/lib/modules/core/schema/conversation.js +292 -0
- package/dist/lib/modules/core/schema/delegation.js +58 -0
- package/dist/lib/modules/core/schema/directory-frames.js +270 -0
- package/dist/lib/modules/core/schema/directory.js +169 -0
- package/dist/lib/modules/core/schema/envelope.js +211 -0
- package/dist/lib/modules/core/schema/errors.js +104 -0
- package/dist/lib/modules/core/schema/index.js +16 -0
- package/dist/lib/modules/core/schema/ipc/consent.js +181 -0
- package/dist/lib/modules/core/schema/ipc/device.js +276 -0
- package/dist/lib/modules/core/schema/ipc/jelly.js +189 -0
- package/dist/lib/modules/core/schema/ipc/shapes.js +185 -0
- package/dist/lib/modules/core/schema/ipc/surfaces.js +223 -0
- package/dist/lib/modules/core/schema/ipc.js +451 -0
- package/dist/lib/modules/core/schema/jelly.js +122 -0
- package/dist/lib/modules/core/schema/realm.js +27 -0
- package/dist/lib/modules/core/schema/relay.js +112 -0
- package/dist/lib/modules/core/schema/roster.js +126 -0
- package/dist/lib/modules/core/sign.js +43 -0
- package/dist/lib/modules/core/task.js +37 -0
- package/dist/lib/modules/core/testing.js +21 -0
- package/dist/lib/modules/core/ulid.js +36 -0
- package/dist/lib/modules/core/version.js +6 -0
- package/dist/lib/modules/core/wire.js +255 -0
- package/dist/lib/modules/ipc/client.js +289 -0
- package/dist/lib/modules/ipc/framing.js +33 -0
- package/dist/lib/modules/ipc/index.js +6 -0
- package/dist/lib/modules/ipc/paths.js +102 -0
- package/dist/lib/modules/ipc/pipes.js +65 -0
- package/dist/lib/modules/ipc/rpc.js +8 -0
- package/dist/lib/modules/ipc/server.js +317 -0
- package/dist/lib/modules/ipc/testing.js +145 -0
- package/dist/lib/modules/ipc/trust.js +166 -0
- package/dist/lib/modules/ipc/windows-acl.js +275 -0
- package/dist/lib/modules/vendor/zod/index.js +7 -0
- package/dist/lib/modules/vendor/zod/v4/classic/checks.js +1 -0
- package/dist/lib/modules/vendor/zod/v4/classic/coerce.js +17 -0
- package/dist/lib/modules/vendor/zod/v4/classic/compat.js +31 -0
- package/dist/lib/modules/vendor/zod/v4/classic/deep-partial.js +13 -0
- package/dist/lib/modules/vendor/zod/v4/classic/errors.js +57 -0
- package/dist/lib/modules/vendor/zod/v4/classic/external.js +17 -0
- package/dist/lib/modules/vendor/zod/v4/classic/from-json-schema.js +881 -0
- package/dist/lib/modules/vendor/zod/v4/classic/in-out.js +36 -0
- package/dist/lib/modules/vendor/zod/v4/classic/iso.js +15 -0
- package/dist/lib/modules/vendor/zod/v4/classic/parse.js +16 -0
- package/dist/lib/modules/vendor/zod/v4/classic/schemas.js +1535 -0
- package/dist/lib/modules/vendor/zod/v4/core/api.js +1107 -0
- package/dist/lib/modules/vendor/zod/v4/core/checks.js +516 -0
- package/dist/lib/modules/vendor/zod/v4/core/compile.js +1866 -0
- package/dist/lib/modules/vendor/zod/v4/core/core.js +141 -0
- package/dist/lib/modules/vendor/zod/v4/core/doc.js +38 -0
- package/dist/lib/modules/vendor/zod/v4/core/errors.js +267 -0
- package/dist/lib/modules/vendor/zod/v4/core/index.js +19 -0
- package/dist/lib/modules/vendor/zod/v4/core/json-schema-generator.js +99 -0
- package/dist/lib/modules/vendor/zod/v4/core/json-schema-processors.js +843 -0
- package/dist/lib/modules/vendor/zod/v4/core/json-schema.js +1 -0
- package/dist/lib/modules/vendor/zod/v4/core/memoizer.js +311 -0
- package/dist/lib/modules/vendor/zod/v4/core/parse.js +175 -0
- package/dist/lib/modules/vendor/zod/v4/core/regexes.js +156 -0
- package/dist/lib/modules/vendor/zod/v4/core/registries.js +51 -0
- package/dist/lib/modules/vendor/zod/v4/core/schemas.js +2636 -0
- package/dist/lib/modules/vendor/zod/v4/core/to-json-schema.js +651 -0
- package/dist/lib/modules/vendor/zod/v4/core/util.js +873 -0
- package/dist/lib/modules/vendor/zod/v4/core/versions.js +5 -0
- package/dist/lib/modules/vendor/zod/v4/core/visit.js +169 -0
- package/dist/lib/modules/vendor/zod/v4/locales/ar.js +111 -0
- package/dist/lib/modules/vendor/zod/v4/locales/az.js +110 -0
- package/dist/lib/modules/vendor/zod/v4/locales/be.js +168 -0
- package/dist/lib/modules/vendor/zod/v4/locales/bg.js +125 -0
- package/dist/lib/modules/vendor/zod/v4/locales/bn.js +113 -0
- package/dist/lib/modules/vendor/zod/v4/locales/ca.js +112 -0
- package/dist/lib/modules/vendor/zod/v4/locales/ckb.js +133 -0
- package/dist/lib/modules/vendor/zod/v4/locales/cs.js +116 -0
- package/dist/lib/modules/vendor/zod/v4/locales/da.js +120 -0
- package/dist/lib/modules/vendor/zod/v4/locales/de.js +113 -0
- package/dist/lib/modules/vendor/zod/v4/locales/el.js +112 -0
- package/dist/lib/modules/vendor/zod/v4/locales/en.js +125 -0
- package/dist/lib/modules/vendor/zod/v4/locales/eo.js +114 -0
- package/dist/lib/modules/vendor/zod/v4/locales/es.js +136 -0
- package/dist/lib/modules/vendor/zod/v4/locales/fa.js +119 -0
- package/dist/lib/modules/vendor/zod/v4/locales/fi.js +117 -0
- package/dist/lib/modules/vendor/zod/v4/locales/fr-CA.js +112 -0
- package/dist/lib/modules/vendor/zod/v4/locales/fr.js +129 -0
- package/dist/lib/modules/vendor/zod/v4/locales/gu.js +113 -0
- package/dist/lib/modules/vendor/zod/v4/locales/he.js +221 -0
- package/dist/lib/modules/vendor/zod/v4/locales/hi.js +111 -0
- package/dist/lib/modules/vendor/zod/v4/locales/hr.js +126 -0
- package/dist/lib/modules/vendor/zod/v4/locales/hu.js +113 -0
- package/dist/lib/modules/vendor/zod/v4/locales/hy.js +158 -0
- package/dist/lib/modules/vendor/zod/v4/locales/id.js +111 -0
- package/dist/lib/modules/vendor/zod/v4/locales/index.js +63 -0
- package/dist/lib/modules/vendor/zod/v4/locales/is.js +114 -0
- package/dist/lib/modules/vendor/zod/v4/locales/it.js +113 -0
- package/dist/lib/modules/vendor/zod/v4/locales/ja.js +112 -0
- package/dist/lib/modules/vendor/zod/v4/locales/ka.js +117 -0
- package/dist/lib/modules/vendor/zod/v4/locales/kh.js +5 -0
- package/dist/lib/modules/vendor/zod/v4/locales/km.js +115 -0
- package/dist/lib/modules/vendor/zod/v4/locales/kn.js +116 -0
- package/dist/lib/modules/vendor/zod/v4/locales/ko.js +116 -0
- package/dist/lib/modules/vendor/zod/v4/locales/lt.js +207 -0
- package/dist/lib/modules/vendor/zod/v4/locales/mk.js +114 -0
- package/dist/lib/modules/vendor/zod/v4/locales/ms.js +112 -0
- package/dist/lib/modules/vendor/zod/v4/locales/ne.js +111 -0
- package/dist/lib/modules/vendor/zod/v4/locales/nl.js +115 -0
- package/dist/lib/modules/vendor/zod/v4/locales/nn.js +113 -0
- package/dist/lib/modules/vendor/zod/v4/locales/no.js +113 -0
- package/dist/lib/modules/vendor/zod/v4/locales/ota.js +114 -0
- package/dist/lib/modules/vendor/zod/v4/locales/pl.js +114 -0
- package/dist/lib/modules/vendor/zod/v4/locales/ps.js +119 -0
- package/dist/lib/modules/vendor/zod/v4/locales/pt-BR.js +143 -0
- package/dist/lib/modules/vendor/zod/v4/locales/pt.js +142 -0
- package/dist/lib/modules/vendor/zod/v4/locales/ro.js +122 -0
- package/dist/lib/modules/vendor/zod/v4/locales/ru.js +168 -0
- package/dist/lib/modules/vendor/zod/v4/locales/sk.js +116 -0
- package/dist/lib/modules/vendor/zod/v4/locales/sl.js +114 -0
- package/dist/lib/modules/vendor/zod/v4/locales/sv.js +115 -0
- package/dist/lib/modules/vendor/zod/v4/locales/ta.js +115 -0
- package/dist/lib/modules/vendor/zod/v4/locales/tg.js +117 -0
- package/dist/lib/modules/vendor/zod/v4/locales/th.js +115 -0
- package/dist/lib/modules/vendor/zod/v4/locales/tk.js +107 -0
- package/dist/lib/modules/vendor/zod/v4/locales/tr.js +110 -0
- package/dist/lib/modules/vendor/zod/v4/locales/ua.js +5 -0
- package/dist/lib/modules/vendor/zod/v4/locales/uk.js +113 -0
- package/dist/lib/modules/vendor/zod/v4/locales/ur.js +115 -0
- package/dist/lib/modules/vendor/zod/v4/locales/uz.js +113 -0
- package/dist/lib/modules/vendor/zod/v4/locales/vi.js +113 -0
- package/dist/lib/modules/vendor/zod/v4/locales/yo.js +112 -0
- package/dist/lib/modules/vendor/zod/v4/locales/zh-CN.js +114 -0
- package/dist/lib/modules/vendor/zod/v4/locales/zh-TW.js +112 -0
- package/dist/lib/testing-jelly-id.js +1219 -0
- package/dist/lib/zod.js +1 -0
- package/dist/spec/messaging-v1.md +3744 -0
- package/dist/third-party-notices.md +239 -0
- package/dist/third-party.json +88 -0
- package/dist/types/core/address.d.ts +16 -0
- package/dist/types/core/agent/operations.d.ts +129 -0
- package/dist/types/core/agent/present.d.ts +57 -0
- package/dist/types/core/agent/text.d.ts +62 -0
- package/dist/types/core/agent-tools.d.ts +966 -0
- package/dist/types/core/b64u.d.ts +6 -0
- package/dist/types/core/cards.d.ts +21 -0
- package/dist/types/core/check.d.ts +10 -0
- package/dist/types/core/consent.d.ts +132 -0
- package/dist/types/core/contact-card.d.ts +34 -0
- package/dist/types/core/conversation/context.d.ts +56 -0
- package/dist/types/core/conversation/event.d.ts +36 -0
- package/dist/types/core/conversation/ids.d.ts +18 -0
- package/dist/types/core/conversation/link.d.ts +16 -0
- package/dist/types/core/conversation/log.d.ts +142 -0
- package/dist/types/core/conversation/ratchet.d.ts +95 -0
- package/dist/types/core/conversation/seal.d.ts +47 -0
- package/dist/types/core/delegation.d.ts +71 -0
- package/dist/types/core/directory/device-log.d.ts +119 -0
- package/dist/types/core/directory/epoch.d.ts +53 -0
- package/dist/types/core/directory/handle.d.ts +11 -0
- package/dist/types/core/directory/jelly-device.d.ts +88 -0
- package/dist/types/core/directory/jelly-issuer.d.ts +8 -0
- package/dist/types/core/directory/jelly-token.d.ts +116 -0
- package/dist/types/core/directory/keys-statement.d.ts +22 -0
- package/dist/types/core/directory/link.d.ts +36 -0
- package/dist/types/core/directory/merkle-log.d.ts +40 -0
- package/dist/types/core/directory/person-view.d.ts +90 -0
- package/dist/types/core/directory/person.d.ts +8 -0
- package/dist/types/core/directory/realm.d.ts +23 -0
- package/dist/types/core/directory/smt.d.ts +52 -0
- package/dist/types/core/envelope.d.ts +68 -0
- package/dist/types/core/hash.d.ts +2 -0
- package/dist/types/core/head.d.ts +34 -0
- package/dist/types/core/identity.d.ts +35 -0
- package/dist/types/core/index.d.ts +45 -0
- package/dist/types/core/jcs.d.ts +12 -0
- package/dist/types/core/jelly-host-double.d.ts +21 -0
- package/dist/types/core/jelly-host.d.ts +86 -0
- package/dist/types/core/keys.d.ts +16 -0
- package/dist/types/core/peer-text.d.ts +87 -0
- package/dist/types/core/realm.d.ts +36 -0
- package/dist/types/core/roster.d.ts +146 -0
- package/dist/types/core/schema/a2a.d.ts +251 -0
- package/dist/types/core/schema/common.d.ts +328 -0
- package/dist/types/core/schema/consent.d.ts +140 -0
- package/dist/types/core/schema/conversation.d.ts +1657 -0
- package/dist/types/core/schema/delegation.d.ts +58 -0
- package/dist/types/core/schema/directory-frames.d.ts +1301 -0
- package/dist/types/core/schema/directory.d.ts +375 -0
- package/dist/types/core/schema/envelope.d.ts +756 -0
- package/dist/types/core/schema/errors.d.ts +142 -0
- package/dist/types/core/schema/index.d.ts +16 -0
- package/dist/types/core/schema/ipc/consent.d.ts +555 -0
- package/dist/types/core/schema/ipc/device.d.ts +735 -0
- package/dist/types/core/schema/ipc/jelly.d.ts +501 -0
- package/dist/types/core/schema/ipc/shapes.d.ts +414 -0
- package/dist/types/core/schema/ipc/surfaces.d.ts +680 -0
- package/dist/types/core/schema/ipc.d.ts +3146 -0
- package/dist/types/core/schema/jelly.d.ts +160 -0
- package/dist/types/core/schema/realm.d.ts +38 -0
- package/dist/types/core/schema/relay.d.ts +1134 -0
- package/dist/types/core/schema/roster.d.ts +347 -0
- package/dist/types/core/sign.d.ts +13 -0
- package/dist/types/core/task.d.ts +6 -0
- package/dist/types/core/testing.d.ts +19 -0
- package/dist/types/core/ulid.d.ts +5 -0
- package/dist/types/core/version.d.ts +6 -0
- package/dist/types/core/wire.d.ts +14 -0
- package/dist/types/ipc/client.d.ts +85 -0
- package/dist/types/ipc/framing.d.ts +12 -0
- package/dist/types/ipc/index.d.ts +6 -0
- package/dist/types/ipc/paths.d.ts +39 -0
- package/dist/types/ipc/pipes.d.ts +16 -0
- package/dist/types/ipc/rpc.d.ts +13 -0
- package/dist/types/ipc/server.d.ts +94 -0
- package/dist/types/ipc/testing.d.ts +89 -0
- package/dist/types/ipc/trust.d.ts +49 -0
- package/dist/types/ipc/windows-acl.d.ts +56 -0
- package/dist/types/testing/jelly-id.d.ts +518 -0
- package/dist/types/zod.d.ts +1 -0
- package/package.json +77 -4
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Windows access control for the Messaging home (spec §8.1, §8.2): the analogue of "a real directory owned by
|
|
3
|
+
* this user that no group or other user can write", and of `mkdir 0700` / `chmod 0700`.
|
|
4
|
+
*
|
|
5
|
+
* Node has no API for Windows ACLs, so this reads and writes them with the system's own tools, run by absolute
|
|
6
|
+
* path (never through PATH): `icacls <path> /save` writes a DACL as SDDL, which is locale-independent, and
|
|
7
|
+
* `whoami /user` names this user's SID. The parser and the policy are pure functions, tested on every
|
|
8
|
+
* platform; only `readDacl`, `currentUserSid` and `securePrivate` run the tools, and only on Windows.
|
|
9
|
+
*
|
|
10
|
+
* The policy (`daclProblem`), "private" on Windows:
|
|
11
|
+
* 1. the object has a DACL (a NULL DACL lets everyone do anything);
|
|
12
|
+
* 2. no allow entry that applies to the object grants a write-class right to anyone but this user, SYSTEM
|
|
13
|
+
* or Administrators (Windows' root equivalents);
|
|
14
|
+
* 3. with `pinnedOwner`, an OWNER RIGHTS (S-1-3-4) entry applies to the object and grants no write-class
|
|
15
|
+
* right. Node cannot read an object's owner cheaply; an OWNER RIGHTS entry replaces the owner's implicit
|
|
16
|
+
* WRITE_DAC, so whoever owns the directory (for example someone who created a shared MESSAGING_HOME
|
|
17
|
+
* first) cannot rewrite its DACL later. That is what the POSIX owner check is for.
|
|
18
|
+
*/
|
|
19
|
+
import { spawnSync } from "node:child_process";
|
|
20
|
+
import { randomBytes } from "node:crypto";
|
|
21
|
+
import { existsSync, readFileSync, rmSync } from "node:fs";
|
|
22
|
+
import { tmpdir } from "node:os";
|
|
23
|
+
import { join } from "node:path";
|
|
24
|
+
import { MessagingError } from "../core/index.js";
|
|
25
|
+
export const SID_SYSTEM = "S-1-5-18";
|
|
26
|
+
export const SID_ADMINISTRATORS = "S-1-5-32-544";
|
|
27
|
+
export const SID_OWNER_RIGHTS = "S-1-3-4";
|
|
28
|
+
/** SDDL account aliases this module needs to tell apart; any other alias is some other principal. */
|
|
29
|
+
const ALIASES = {
|
|
30
|
+
SY: SID_SYSTEM,
|
|
31
|
+
BA: SID_ADMINISTRATORS,
|
|
32
|
+
OW: SID_OWNER_RIGHTS,
|
|
33
|
+
CO: "S-1-3-0",
|
|
34
|
+
WD: "S-1-1-0",
|
|
35
|
+
AU: "S-1-5-11",
|
|
36
|
+
BU: "S-1-5-32-545",
|
|
37
|
+
AN: "S-1-5-7",
|
|
38
|
+
NU: "S-1-5-2",
|
|
39
|
+
IU: "S-1-5-4",
|
|
40
|
+
};
|
|
41
|
+
/** SDDL right codes and their masks. An unknown code is taken as every right (refused as a write). */
|
|
42
|
+
const RIGHTS = {
|
|
43
|
+
GA: 0x1000_0000,
|
|
44
|
+
GR: 0x8000_0000,
|
|
45
|
+
GW: 0x4000_0000,
|
|
46
|
+
GX: 0x2000_0000,
|
|
47
|
+
RC: 0x0002_0000,
|
|
48
|
+
SD: 0x0001_0000,
|
|
49
|
+
WD: 0x0004_0000,
|
|
50
|
+
WO: 0x0008_0000,
|
|
51
|
+
RP: 0x10,
|
|
52
|
+
WP: 0x20,
|
|
53
|
+
CC: 0x1,
|
|
54
|
+
DC: 0x2,
|
|
55
|
+
LC: 0x4,
|
|
56
|
+
SW: 0x8,
|
|
57
|
+
LO: 0x80,
|
|
58
|
+
DT: 0x40,
|
|
59
|
+
CR: 0x100,
|
|
60
|
+
FA: 0x001f_01ff,
|
|
61
|
+
FR: 0x0012_0089,
|
|
62
|
+
FW: 0x0012_0116,
|
|
63
|
+
FX: 0x0012_00a0,
|
|
64
|
+
KA: 0x000f_003f,
|
|
65
|
+
KR: 0x0002_0019,
|
|
66
|
+
KW: 0x0002_0006,
|
|
67
|
+
KX: 0x0002_0019,
|
|
68
|
+
NR: 0,
|
|
69
|
+
NW: 0,
|
|
70
|
+
NX: 0,
|
|
71
|
+
};
|
|
72
|
+
/**
|
|
73
|
+
* Rights that let a principal change a file or directory, its entries, or who may: write data or add a file
|
|
74
|
+
* (0x2), append or add a subdirectory (0x4), write extended attributes (0x10), delete a child (0x40), write
|
|
75
|
+
* attributes (0x100), DELETE, WRITE_DAC, WRITE_OWNER, GENERIC_WRITE and GENERIC_ALL.
|
|
76
|
+
*/
|
|
77
|
+
export const WRITE_RIGHTS = 0x2 | 0x4 | 0x10 | 0x40 | 0x100 | 0x0001_0000 | 0x0004_0000 | 0x0008_0000 | 0x4000_0000 | 0x1000_0000;
|
|
78
|
+
const ALLOW_TYPES = new Set(["A", "OA", "XA", "ZA"]);
|
|
79
|
+
/** The DACL part of an SDDL string, or undefined when it has none. Throws on text that is not SDDL. */
|
|
80
|
+
export function parseSddlDacl(sddl) {
|
|
81
|
+
const text = sddl.trim();
|
|
82
|
+
let i = 0;
|
|
83
|
+
let dacl;
|
|
84
|
+
while (i < text.length) {
|
|
85
|
+
const tag = text[i];
|
|
86
|
+
if (text[i + 1] !== ":" || (tag !== "O" && tag !== "G" && tag !== "D" && tag !== "S"))
|
|
87
|
+
throw new Error("not SDDL");
|
|
88
|
+
i += 2;
|
|
89
|
+
if (tag === "O" || tag === "G") {
|
|
90
|
+
const sid = /^(S-1-[0-9-]+|[A-Z]{2})/.exec(text.slice(i));
|
|
91
|
+
if (!sid)
|
|
92
|
+
throw new Error("not SDDL: owner or group");
|
|
93
|
+
i += sid[0].length;
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
// A component's flags end where its first entry starts, or where the next component's tag starts.
|
|
97
|
+
let flagText = /^[A-Z_]*/.exec(text.slice(i))[0];
|
|
98
|
+
if (text[i + flagText.length] === ":")
|
|
99
|
+
flagText = flagText.slice(0, -1);
|
|
100
|
+
i += flagText.length;
|
|
101
|
+
const aces = [];
|
|
102
|
+
while (text[i] === "(") {
|
|
103
|
+
let depth = 0;
|
|
104
|
+
let end = i;
|
|
105
|
+
for (; end < text.length; end++) {
|
|
106
|
+
if (text[end] === "(")
|
|
107
|
+
depth++;
|
|
108
|
+
else if (text[end] === ")" && --depth === 0)
|
|
109
|
+
break;
|
|
110
|
+
}
|
|
111
|
+
if (end >= text.length)
|
|
112
|
+
throw new Error("not SDDL: an unclosed entry");
|
|
113
|
+
aces.push(parseAce(text.slice(i + 1, end)));
|
|
114
|
+
i = end + 1;
|
|
115
|
+
}
|
|
116
|
+
if (tag === "D")
|
|
117
|
+
dacl = { nullDacl: flagText.includes("NO_ACCESS_CONTROL"), protected: flagText.replace("NO_ACCESS_CONTROL", "").includes("P"), aces };
|
|
118
|
+
}
|
|
119
|
+
return dacl;
|
|
120
|
+
}
|
|
121
|
+
function parseAce(body) {
|
|
122
|
+
const fields = body.split(";");
|
|
123
|
+
if (fields.length < 6)
|
|
124
|
+
throw new Error("not SDDL: an entry");
|
|
125
|
+
const [type = "", flagText = "", rightsText = "", , , sidText = ""] = fields;
|
|
126
|
+
const flags = flagText.match(/.{1,2}/g) ?? [];
|
|
127
|
+
return { type, flags, rights: parseRights(rightsText), sid: ALIASES[sidText] ?? sidText };
|
|
128
|
+
}
|
|
129
|
+
function parseRights(text) {
|
|
130
|
+
if (/^0[xX][0-9a-fA-F]+$/.test(text))
|
|
131
|
+
return Number.parseInt(text.slice(2), 16);
|
|
132
|
+
if (/^\d+$/.test(text))
|
|
133
|
+
return Number(text);
|
|
134
|
+
let mask = 0;
|
|
135
|
+
for (const code of text.match(/.{1,2}/g) ?? [])
|
|
136
|
+
mask |= RIGHTS[code] ?? 0xffff_ffff;
|
|
137
|
+
return mask >>> 0;
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Aliases SDDL writes for accounts of the user's own machine or domain: `LA` is its Administrator account (RID
|
|
141
|
+
* 500), `LG` its Guest (501). This user may be one of them (a CI runner's user is often the built-in
|
|
142
|
+
* Administrator), so they are resolved against the domain part of `self`'s SID; any other alias stays as written.
|
|
143
|
+
*/
|
|
144
|
+
const DOMAIN_RIDS = { LA: 500, LG: 501 };
|
|
145
|
+
/** `sid` as a full SID when it is a domain-relative alias of `self`'s domain; otherwise unchanged. */
|
|
146
|
+
export function resolveSid(sid, self) {
|
|
147
|
+
const rid = DOMAIN_RIDS[sid];
|
|
148
|
+
const domain = /^(S-1-5-21-\d+-\d+-\d+)-\d+$/.exec(self)?.[1];
|
|
149
|
+
return rid !== undefined && domain !== undefined ? `${domain}-${rid}` : sid;
|
|
150
|
+
}
|
|
151
|
+
/** Whether an entry applies to the object itself (not only to what inherits it). */
|
|
152
|
+
function applies(ace) {
|
|
153
|
+
return !ace.flags.includes("IO");
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Why `dacl` is not private to `self` (a SID), or undefined when it is (the rules in this module's comment).
|
|
157
|
+
* `pinnedOwner`: also require an OWNER RIGHTS entry that grants no write-class right.
|
|
158
|
+
*/
|
|
159
|
+
export function daclProblem(dacl, self, { pinnedOwner }) {
|
|
160
|
+
if (dacl === undefined || dacl.nullDacl)
|
|
161
|
+
return "has no access control list, so anyone may write it";
|
|
162
|
+
const trusted = new Set([self, SID_SYSTEM, SID_ADMINISTRATORS]);
|
|
163
|
+
let ownerPinned = false;
|
|
164
|
+
for (const ace of dacl.aces) {
|
|
165
|
+
if (!ALLOW_TYPES.has(ace.type) || !applies(ace))
|
|
166
|
+
continue;
|
|
167
|
+
const writes = (ace.rights & WRITE_RIGHTS) !== 0;
|
|
168
|
+
const sid = resolveSid(ace.sid, self);
|
|
169
|
+
if (sid === SID_OWNER_RIGHTS) {
|
|
170
|
+
if (writes)
|
|
171
|
+
return "lets its owner write it";
|
|
172
|
+
ownerPinned = true;
|
|
173
|
+
continue;
|
|
174
|
+
}
|
|
175
|
+
if (writes && !trusted.has(sid))
|
|
176
|
+
return `is writable by ${/^S-1-[0-9-]+$/.test(sid) ? sid : `another principal (${sid.slice(0, 8)})`}`;
|
|
177
|
+
}
|
|
178
|
+
if (pinnedOwner && !ownerPinned)
|
|
179
|
+
return "does not pin its owner's rights (no OWNER RIGHTS entry)";
|
|
180
|
+
return undefined;
|
|
181
|
+
}
|
|
182
|
+
/** `%SystemRoot%\System32\<exe>`: the system's own tools, never one found on PATH. */
|
|
183
|
+
function system32(exe) {
|
|
184
|
+
return join(process.env.SystemRoot || process.env.windir || "C:\\Windows", "System32", exe);
|
|
185
|
+
}
|
|
186
|
+
/** A system tool that failed, with its exit status (a Win32 error code for icacls: 2 file not found, 3 path not found). */
|
|
187
|
+
class ToolFailed extends MessagingError {
|
|
188
|
+
status;
|
|
189
|
+
constructor(exe, status, why) {
|
|
190
|
+
super("forbidden", `${exe} failed (${why})`);
|
|
191
|
+
this.status = status;
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function run(exe, args) {
|
|
195
|
+
const result = spawnSync(system32(exe), args, { encoding: "utf8", windowsHide: true, timeout: 15_000 });
|
|
196
|
+
if (result.error)
|
|
197
|
+
throw new ToolFailed(exe, null, result.error.code ?? "error");
|
|
198
|
+
if (result.status !== 0)
|
|
199
|
+
throw new ToolFailed(exe, result.status, `exit ${result.status}`);
|
|
200
|
+
return result.stdout;
|
|
201
|
+
}
|
|
202
|
+
let userSid;
|
|
203
|
+
/** This process's user SID (`whoami /user`), read once. */
|
|
204
|
+
export function currentUserSid() {
|
|
205
|
+
if (userSid !== undefined)
|
|
206
|
+
return userSid;
|
|
207
|
+
const out = run("whoami.exe", ["/user", "/fo", "csv", "/nh"]);
|
|
208
|
+
const sid = /"(S-1-[0-9-]+)"\s*$/.exec(out.trim())?.[1];
|
|
209
|
+
if (!sid)
|
|
210
|
+
throw new MessagingError("forbidden", "cannot tell this user's SID");
|
|
211
|
+
userSid = sid;
|
|
212
|
+
return sid;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* The DACL of `path`, read with `icacls /save` (SDDL; locale-independent). A path that is gone by the time icacls
|
|
216
|
+
* reads it is `daemon_unavailable`, not `forbidden`: a daemon that stops or restarts removes its pipe file between a
|
|
217
|
+
* client's `lstat` and this read, and that client has found no daemon, not an unsafe one.
|
|
218
|
+
*/
|
|
219
|
+
export function readDacl(path) {
|
|
220
|
+
const out = join(tmpdir(), `messaging-acl-${process.pid}-${randomBytes(8).toString("hex")}.txt`);
|
|
221
|
+
try {
|
|
222
|
+
run("icacls.exe", [path, "/save", out, "/q"]);
|
|
223
|
+
return parseSddlDacl(sddlLine(readFileSync(out)));
|
|
224
|
+
}
|
|
225
|
+
catch (error) {
|
|
226
|
+
if (error instanceof ToolFailed && (error.status === 2 || error.status === 3 || !existsSync(path))) {
|
|
227
|
+
throw new MessagingError("daemon_unavailable", `${path} does not exist`);
|
|
228
|
+
}
|
|
229
|
+
if (error instanceof MessagingError)
|
|
230
|
+
throw error;
|
|
231
|
+
throw new MessagingError("forbidden", "cannot read an access control list");
|
|
232
|
+
}
|
|
233
|
+
finally {
|
|
234
|
+
rmSync(out, { force: true });
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
/** The SDDL line of an `icacls /save` file: the object's name, then its SDDL (UTF-16LE, with or without a BOM). */
|
|
238
|
+
export function sddlLine(bytes) {
|
|
239
|
+
const utf16 = bytes.length >= 2 && (bytes[0] === 0xff && bytes[1] === 0xfe ? true : bytes.includes(0));
|
|
240
|
+
const text = (utf16 ? bytes.toString("utf16le") : bytes.toString("utf8")).replace(/^\uFEFF/, "");
|
|
241
|
+
const line = text.split(/\r?\n/).find((l) => /^(?:[OGDS]:)/.test(l.trim()));
|
|
242
|
+
if (line === undefined)
|
|
243
|
+
throw new MessagingError("forbidden", "cannot read an access control list");
|
|
244
|
+
return line.trim();
|
|
245
|
+
}
|
|
246
|
+
/** Why `path`'s ACL is not private to this user (see `daclProblem`), or undefined. */
|
|
247
|
+
export function aclProblem(path, options) {
|
|
248
|
+
return daclProblem(readDacl(path), currentUserSid(), options);
|
|
249
|
+
}
|
|
250
|
+
/**
|
|
251
|
+
* Makes `path` (a directory) private to this user, as `chmod 0700` does on POSIX: inheritance from the parent
|
|
252
|
+
* removed, full control to this user and an OWNER RIGHTS entry that only reads the ACL, both inherited by
|
|
253
|
+
* everything created inside, and every other entry removed. Then reads the ACL back and checks it. Fails with
|
|
254
|
+
* `forbidden` when this user may not change the ACL.
|
|
255
|
+
*/
|
|
256
|
+
export function securePrivate(path, what) {
|
|
257
|
+
const self = currentUserSid();
|
|
258
|
+
let others;
|
|
259
|
+
try {
|
|
260
|
+
others = [...new Set((readDacl(path)?.aces ?? []).map((ace) => resolveSid(ace.sid, self)))].filter((sid) => sid !== self && sid !== SID_OWNER_RIGHTS && /^S-1-[0-9-]+$/.test(sid));
|
|
261
|
+
run("icacls.exe", [path, "/inheritance:r", "/grant:r", `*${self}:(OI)(CI)(F)`, `*${SID_OWNER_RIGHTS}:(OI)(CI)(RC)`, "/q"]);
|
|
262
|
+
if (others.length > 0)
|
|
263
|
+
run("icacls.exe", [path, "/remove", ...others.map((sid) => `*${sid}`), "/q"]);
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
throw new MessagingError("forbidden", `cannot make ${what} private: ${error instanceof Error ? error.message : "icacls failed"}`);
|
|
267
|
+
}
|
|
268
|
+
const dacl = readDacl(path);
|
|
269
|
+
const problem = daclProblem(dacl, self, { pinnedOwner: true });
|
|
270
|
+
if (problem !== undefined)
|
|
271
|
+
throw new MessagingError("forbidden", `${what} is not private: it ${problem}`);
|
|
272
|
+
const strangers = (dacl?.aces ?? []).map((ace) => resolveSid(ace.sid, self)).filter((sid) => sid !== self && sid !== SID_OWNER_RIGHTS);
|
|
273
|
+
if (strangers.length > 0)
|
|
274
|
+
throw new MessagingError("forbidden", `${what} is not private: other entries remain in its access control list`);
|
|
275
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import * as z from "./v4/classic/external.js";
|
|
2
|
+
export * from "./v4/classic/external.js";
|
|
3
|
+
// Aliasing the binding, instead of `export default z`, keeps the default export a
|
|
4
|
+
// re-export of `z` rather than a fresh namespace value. Rollup and Webpack can then
|
|
5
|
+
// shake `import z from "zod"` as they already shake `import { z } from "zod"` — without
|
|
6
|
+
// this they pull in every locale. See #6050.
|
|
7
|
+
export { z, z as default };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { _lt as lt, _lte as lte, _gt as gt, _gte as gte, _positive as positive, _negative as negative, _nonpositive as nonpositive, _nonnegative as nonnegative, _multipleOf as multipleOf, _maxSize as maxSize, _minSize as minSize, _size as size, _maxLength as maxLength, _minLength as minLength, _length as length, _regex as regex, _lowercase as lowercase, _uppercase as uppercase, _includes as includes, _startsWith as startsWith, _endsWith as endsWith, _property as property, _properties as properties, _mime as mime, _overwrite as overwrite, _normalize as normalize, _trim as trim, _toLowerCase as toLowerCase, _toUpperCase as toUpperCase, _slugify as slugify, } from "../core/index.js";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as core from "../core/index.js";
|
|
2
|
+
import * as schemas from "./schemas.js";
|
|
3
|
+
export function string(params) {
|
|
4
|
+
return core._coercedString(schemas.ZodString, params);
|
|
5
|
+
}
|
|
6
|
+
export function number(params) {
|
|
7
|
+
return core._coercedNumber(schemas.ZodNumber, params);
|
|
8
|
+
}
|
|
9
|
+
export function boolean(params) {
|
|
10
|
+
return core._coercedBoolean(schemas.ZodBoolean, params);
|
|
11
|
+
}
|
|
12
|
+
export function bigint(params) {
|
|
13
|
+
return core._coercedBigint(schemas.ZodBigInt, params);
|
|
14
|
+
}
|
|
15
|
+
export function date(params) {
|
|
16
|
+
return core._coercedDate(schemas.ZodDate, params);
|
|
17
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
// Zod 3 compat layer
|
|
2
|
+
import * as core from "../core/index.js";
|
|
3
|
+
/** @deprecated Use the raw string literal codes instead, e.g. "invalid_type". */
|
|
4
|
+
export const ZodIssueCode = {
|
|
5
|
+
invalid_type: "invalid_type",
|
|
6
|
+
too_big: "too_big",
|
|
7
|
+
too_small: "too_small",
|
|
8
|
+
invalid_format: "invalid_format",
|
|
9
|
+
not_multiple_of: "not_multiple_of",
|
|
10
|
+
unrecognized_keys: "unrecognized_keys",
|
|
11
|
+
invalid_union: "invalid_union",
|
|
12
|
+
invalid_key: "invalid_key",
|
|
13
|
+
invalid_element: "invalid_element",
|
|
14
|
+
invalid_value: "invalid_value",
|
|
15
|
+
custom: "custom",
|
|
16
|
+
};
|
|
17
|
+
export { $brand, config } from "../core/index.js";
|
|
18
|
+
/** @deprecated Use `z.config(params)` instead. */
|
|
19
|
+
export function setErrorMap(map) {
|
|
20
|
+
core.config({
|
|
21
|
+
customError: map,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
/** @deprecated Use `z.config()` instead. */
|
|
25
|
+
export function getErrorMap() {
|
|
26
|
+
return core.config().customError;
|
|
27
|
+
}
|
|
28
|
+
/** @deprecated Do not use. Stub definition, only included for zod-to-json-schema compatibility. */
|
|
29
|
+
export var ZodFirstPartyTypeKind;
|
|
30
|
+
(function (ZodFirstPartyTypeKind) {
|
|
31
|
+
})(ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {}));
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { visit } from "../core/visit.js";
|
|
2
|
+
import * as schemas from "./schemas.js";
|
|
3
|
+
/** Returns a copy of the schema with every nested object's properties made optional. */
|
|
4
|
+
export function deepPartial(schema) {
|
|
5
|
+
return visit(schema, {
|
|
6
|
+
object: (s) => s.partial(),
|
|
7
|
+
// Every partialed option now admits `undefined`, which the constructor rejects as a duplicate.
|
|
8
|
+
union: (s) => {
|
|
9
|
+
const def = s._zod.def;
|
|
10
|
+
return def.discriminator === undefined ? s : schemas.union(def.options);
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as core from "../core/index.js";
|
|
2
|
+
import { $ZodError } from "../core/index.js";
|
|
3
|
+
import * as util from "../core/util.js";
|
|
4
|
+
/* Prototypes that already carry the lazy helper methods. Seeded with the
|
|
5
|
+
* intrinsics so that `init` on a foreign object — it accepts any object —
|
|
6
|
+
* can never install an accessor onto a prototype we do not own. */
|
|
7
|
+
const _installedErrorProtos = /* @__PURE__ */ new WeakSet([Object.prototype, Error.prototype]);
|
|
8
|
+
/* Helper methods live as non-enumerable lazy getters on the shared
|
|
9
|
+
* prototype instead of own properties on every instance. On first
|
|
10
|
+
* access the getter allocates the per-instance closure and caches it
|
|
11
|
+
* as a non-enumerable own property, so detached usage still works and
|
|
12
|
+
* the allocation only happens for methods actually touched. */
|
|
13
|
+
function _lazyMethod(proto, key, make) {
|
|
14
|
+
Object.defineProperty(proto, key, {
|
|
15
|
+
configurable: true,
|
|
16
|
+
enumerable: false,
|
|
17
|
+
get() {
|
|
18
|
+
const value = make(this);
|
|
19
|
+
Object.defineProperty(this, key, { value, configurable: true, writable: true });
|
|
20
|
+
return value;
|
|
21
|
+
},
|
|
22
|
+
set(value) {
|
|
23
|
+
Object.defineProperty(this, key, { value, configurable: true, writable: true });
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
const initializer = (inst, issues) => {
|
|
28
|
+
$ZodError.init(inst, issues);
|
|
29
|
+
inst.name = "ZodError";
|
|
30
|
+
const proto = Object.getPrototypeOf(inst);
|
|
31
|
+
if (_installedErrorProtos.has(proto))
|
|
32
|
+
return;
|
|
33
|
+
_installedErrorProtos.add(proto);
|
|
34
|
+
_lazyMethod(proto, "format", (self) => (mapper) => core.formatError(self, mapper));
|
|
35
|
+
_lazyMethod(proto, "flatten", (self) => (mapper) => core.flattenError(self, mapper));
|
|
36
|
+
_lazyMethod(proto, "addIssue", (self) => (issue) => {
|
|
37
|
+
self.issues.push(issue);
|
|
38
|
+
self.message = JSON.stringify(self.issues, util.jsonStringifyReplacer, 2);
|
|
39
|
+
});
|
|
40
|
+
_lazyMethod(proto, "addIssues", (self) => (issues) => {
|
|
41
|
+
self.issues.push(...issues);
|
|
42
|
+
self.message = JSON.stringify(self.issues, util.jsonStringifyReplacer, 2);
|
|
43
|
+
});
|
|
44
|
+
Object.defineProperty(proto, "isEmpty", {
|
|
45
|
+
configurable: true,
|
|
46
|
+
enumerable: false,
|
|
47
|
+
get() {
|
|
48
|
+
return this.issues.length === 0;
|
|
49
|
+
},
|
|
50
|
+
});
|
|
51
|
+
};
|
|
52
|
+
export const ZodError = /*@__PURE__*/ core.$constructor("ZodError", initializer);
|
|
53
|
+
export const ZodRealError = /*@__PURE__*/ core.$constructor("ZodError", initializer, undefined, {
|
|
54
|
+
Parent: Error,
|
|
55
|
+
});
|
|
56
|
+
// /** @deprecated Use `z.core.$ZodErrorMapCtx` instead. */
|
|
57
|
+
// export type ErrorMapCtx = core.$ZodErrorMapCtx;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export * as core from "../core/index.js";
|
|
2
|
+
export * from "./schemas.js";
|
|
3
|
+
export * from "./checks.js";
|
|
4
|
+
export * from "./errors.js";
|
|
5
|
+
export * from "./parse.js";
|
|
6
|
+
export * from "./compat.js";
|
|
7
|
+
export { globalRegistry, registry, config, memoizer, $output, $input, $brand, clone, regexes, treeifyError, prettifyError, formatError, flattenError, TimePrecision, util, NEVER, INVALID, toZod, compile, withParser, ZodCompileAsyncError, ZodCompileUnsupportedError, getDiscriminatedOption, } from "../core/index.js";
|
|
8
|
+
export { toJSONSchema } from "../core/json-schema-processors.js";
|
|
9
|
+
export { fromJSONSchema } from "./from-json-schema.js";
|
|
10
|
+
export { deepPartial } from "./deep-partial.js";
|
|
11
|
+
// Types and values both, from one module — re-exporting the types from core would collide.
|
|
12
|
+
export { input, output } from "./in-out.js";
|
|
13
|
+
export * as locales from "../locales/index.js";
|
|
14
|
+
// iso must be exported from top-level https://github.com/colinhacks/zod/issues/4491
|
|
15
|
+
export { ZodISODateTime, ZodISODate, ZodISOTime, ZodISODuration } from "./iso.js";
|
|
16
|
+
export * as iso from "./iso.js";
|
|
17
|
+
export * as coerce from "./coerce.js";
|