@agentdocumentformat/cli 0.7.8 → 0.8.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.
Files changed (103) hide show
  1. package/README.md +1 -1
  2. package/dist/adf.mjs +59 -8
  3. package/dist/chunks/{APEv2Parser-2CNNHMXV.mjs → APEv2Parser-WIXRJLHB.mjs} +2 -2
  4. package/dist/chunks/{AiffParser-7BR4RL6G.mjs → AiffParser-ZC4QFOVJ.mjs} +5 -5
  5. package/dist/chunks/{App-7RIIOHJJ.mjs → App-4AZZJNN2.mjs} +917 -826
  6. package/dist/chunks/{DsdiffParser-CMD4AX7A.mjs → DsdiffParser-UAPAJHFX.mjs} +5 -5
  7. package/dist/chunks/{DsfParser-UOGZDS2M.mjs → DsfParser-NNYZK2QX.mjs} +6 -6
  8. package/dist/chunks/{FlacParser-HB3T3CD4.mjs → FlacParser-MW2W4LO3.mjs} +6 -6
  9. package/dist/chunks/{MP4Parser-66HBRUSX.mjs → MP4Parser-Z57SYOOQ.mjs} +4 -4
  10. package/dist/chunks/{MpegParser-YW6LIUEW.mjs → MpegParser-XIIPAZVM.mjs} +7 -7
  11. package/dist/chunks/{MusepackParser-PAUSXP7D.mjs → MusepackParser-QWNDEYHJ.mjs} +6 -6
  12. package/dist/chunks/{OggParser-NUBV3GWC.mjs → OggParser-WRX53F77.mjs} +9 -9
  13. package/dist/chunks/{WavPackParser-WQAGT7TC.mjs → WavPackParser-MJ7WCSJ5.mjs} +2 -2
  14. package/dist/chunks/{WaveParser-EWLQVDX4.mjs → WaveParser-RAVLHZ5S.mjs} +7 -7
  15. package/dist/chunks/{adf-schema-US4NFHMR.mjs → adf-schema-AIPBQTR2.mjs} +9 -3
  16. package/dist/chunks/auth-manager-AJ32FZWS.mjs +19 -0
  17. package/dist/chunks/auth-manager-C5OBEQK2.mjs +18 -0
  18. package/dist/chunks/auth-manager-TBNKCJ45.mjs +17 -0
  19. package/dist/chunks/{chatgpt-subscription-E4MXTIAT.mjs → chatgpt-subscription-MMGNW5KJ.mjs} +5 -2
  20. package/dist/chunks/chunk-2Z7X3UUR.mjs +678 -0
  21. package/dist/chunks/chunk-3UGZFWIF.mjs +26 -0
  22. package/dist/chunks/{chunk-XNPZBLYL.mjs → chunk-75DC5EWN.mjs} +13 -2
  23. package/dist/chunks/{chunk-5PO5PKRV.mjs → chunk-7JZXMDDF.mjs} +158 -67
  24. package/dist/chunks/chunk-AEAJDCVK.mjs +517 -0
  25. package/dist/chunks/{chunk-6VQEXLE2.mjs → chunk-BHY7QDCM.mjs} +41 -3
  26. package/dist/chunks/{chunk-CD3ATSXE.mjs → chunk-BR3AD5QZ.mjs} +8 -2
  27. package/dist/chunks/chunk-BS3USVEA.mjs +301 -0
  28. package/dist/chunks/chunk-C2S64Y6F.mjs +203 -0
  29. package/dist/chunks/chunk-D7A77SNL.mjs +976 -0
  30. package/dist/chunks/chunk-DDTTSKGG.mjs +2443 -0
  31. package/dist/chunks/{chunk-VAUOM3IN.mjs → chunk-DLWCKKIO.mjs} +1 -1
  32. package/dist/chunks/{chunk-G6PH7RPW.mjs → chunk-E7LC6SHP.mjs} +3 -3
  33. package/dist/chunks/{chunk-ZESQMP66.mjs → chunk-F3WSCAJD.mjs} +3 -3
  34. package/dist/chunks/{chunk-KXEF4F4E.mjs → chunk-GAZO6UMI.mjs} +1 -1
  35. package/dist/chunks/{chunk-XYTWGHFS.mjs → chunk-H3XLRWVE.mjs} +1 -1
  36. package/dist/chunks/{chunk-7T2YMTWL.mjs → chunk-H4C65MTP.mjs} +4 -4
  37. package/dist/chunks/chunk-HBOFZRUS.mjs +738 -0
  38. package/dist/chunks/{chunk-VN7UH7I5.mjs → chunk-IMVMSU3A.mjs} +251 -68
  39. package/dist/chunks/{chunk-XYV3VCIX.mjs → chunk-JZFONJSL.mjs} +79 -20
  40. package/dist/chunks/chunk-KCIRFUZH.mjs +12799 -0
  41. package/dist/chunks/chunk-KDDVQKCG.mjs +65 -0
  42. package/dist/chunks/chunk-KRPKWOMB.mjs +290 -0
  43. package/dist/chunks/chunk-LKFHERRV.mjs +145 -0
  44. package/dist/chunks/chunk-LTX74NU6.mjs +29 -0
  45. package/dist/chunks/{chunk-HSBV6YFU.mjs → chunk-LVF2DRBR.mjs} +634 -99
  46. package/dist/chunks/chunk-M2F7C2UJ.mjs +425 -0
  47. package/dist/chunks/{chunk-62NE4LG4.mjs → chunk-MQAMI5BF.mjs} +5 -5
  48. package/dist/chunks/chunk-MZRXFWPQ.mjs +278 -0
  49. package/dist/chunks/{chunk-PRMGZZM5.mjs → chunk-NZLEPJ5M.mjs} +2 -0
  50. package/dist/chunks/{chunk-I3UYSITV.mjs → chunk-O7XKQ6CH.mjs} +1 -1
  51. package/dist/chunks/chunk-P3RG5LQA.mjs +244 -0
  52. package/dist/chunks/chunk-PAK5JCO2.mjs +48 -0
  53. package/dist/chunks/chunk-PC63YFB7.mjs +34 -0
  54. package/dist/chunks/{daemon-control-HKFVSQTQ.mjs → chunk-RHBGCOS3.mjs} +67 -26
  55. package/dist/chunks/{chunk-J74STFKE.mjs → chunk-RJDOVMM4.mjs} +362 -58
  56. package/dist/chunks/{chunk-QPLEAE6V.mjs → chunk-SOSPQPEN.mjs} +167 -650
  57. package/dist/chunks/{chunk-LFMB4PAA.mjs → chunk-TKXIH27X.mjs} +974 -113
  58. package/dist/chunks/{chunk-5W7KES6P.mjs → chunk-UZPDETEU.mjs} +1 -1
  59. package/dist/chunks/chunk-V3MM6PCH.mjs +366 -0
  60. package/dist/chunks/chunk-VENQBMOA.mjs +62 -0
  61. package/dist/chunks/chunk-WJGPNHGX.mjs +67 -0
  62. package/dist/chunks/{chunk-Y5ZLKFLE.mjs → chunk-XNNJQCZP.mjs} +196 -165
  63. package/dist/chunks/{chunk-HDBPBORT.mjs → chunk-YRBFIDLB.mjs} +46 -10
  64. package/dist/chunks/{chunk-BNXUAOO4.mjs → chunk-ZGXUOAWZ.mjs} +3186 -959
  65. package/dist/chunks/chunk-ZPB3HYM7.mjs +45 -0
  66. package/dist/chunks/claude-subscription-EB4LAAVV.mjs +29 -0
  67. package/dist/chunks/{cli-NMFIAR7Z.mjs → cli-PCVFB6B4.mjs} +797 -56
  68. package/dist/chunks/{commands-KPJWFRUE.mjs → commands-KOMPXJZS.mjs} +4 -3
  69. package/dist/chunks/{daemon-YDIK3AAM.mjs → daemon-BVDB565V.mjs} +83142 -64424
  70. package/dist/chunks/daemon-control-MKN7G5M3.mjs +59 -0
  71. package/dist/chunks/{daemon-token-WRSULP7G.mjs → daemon-token-L5QKTHU5.mjs} +3 -1
  72. package/dist/chunks/{discord-DSP4HUWI.mjs → discord-IR62565M.mjs} +3 -52
  73. package/dist/chunks/{email-BRG7KUO2.mjs → email-KHHTJBDW.mjs} +4 -2
  74. package/dist/chunks/{grok-subscription-4PYX7TBF.mjs → grok-subscription-E74FS5EG.mjs} +5 -2
  75. package/dist/chunks/{layout-EPJQNFAI.mjs → layout-ECWGJF6M.mjs} +2 -2
  76. package/dist/chunks/{lib-N7FCZWKH.mjs → lib-L27L5PXM.mjs} +22 -22
  77. package/dist/chunks/{open-VAU7PXT6.mjs → open-3OR6WT4T.mjs} +6 -6
  78. package/dist/chunks/{parser-JVY2PWSM.mjs → parser-7GARNT5L.mjs} +1 -1
  79. package/dist/chunks/{pipeline-executor-O77NTGLP.mjs → pipeline-executor-DRYEEFDR.mjs} +6 -5
  80. package/dist/chunks/prompt-RRHZX4YT.mjs +13 -0
  81. package/dist/chunks/remote-access-cli-GLEEP7DI.mjs +268 -0
  82. package/dist/chunks/remote-hello-UFWUBDQI.mjs +37 -0
  83. package/dist/chunks/sdk-OJOAF4DP.mjs +30014 -0
  84. package/dist/chunks/{slack-OCNNF4DX.mjs → slack-IYC5RAB5.mjs} +3 -4
  85. package/dist/chunks/{store-HUVDJPYN.mjs → store-55CQSAOX.mjs} +7 -3
  86. package/dist/chunks/tailscale-WLJATFMB.mjs +25 -0
  87. package/dist/chunks/{theme-SFE3JMA2.mjs → theme-HLBDTF6F.mjs} +1 -1
  88. package/dist/chunks/{themes-YLXLOIJF.mjs → themes-BQ72P446.mjs} +2 -2
  89. package/dist/chunks/{token-6G3HCMNX.mjs → token-6D22WECM.mjs} +20 -16
  90. package/dist/chunks/{token-util-UXYSDQIW.mjs → token-util-YF3ZWBZ4.mjs} +1 -2
  91. package/dist/chunks/{tui-UQJLK7XI.mjs → tui-RAUVFOYY.mjs} +21 -18
  92. package/dist/chunks/{welcome-XHXFV7SH.mjs → welcome-J5JZZAM5.mjs} +1 -1
  93. package/dist/chunks/{whatsapp-AJMRQBT7.mjs → whatsapp-YJFFVN4Q.mjs} +9 -9
  94. package/package.json +1 -1
  95. package/dist/chunks/chunk-GKKCMXIZ.mjs +0 -94
  96. package/dist/chunks/chunk-IHDDCZBS.mjs +0 -112
  97. package/dist/chunks/chunk-KWFOS5WC.mjs +0 -41
  98. package/dist/chunks/chunk-UEZR2CNS.mjs +0 -65
  99. package/dist/chunks/chunk-VMHTYDH4.mjs +0 -172
  100. package/dist/chunks/chunk-Y2QA53AN.mjs +0 -259
  101. package/dist/chunks/{chunk-NBTUWMGP.mjs → chunk-2MTE22CR.mjs} +3 -3
  102. package/dist/chunks/{chunk-APRU6PHC.mjs → chunk-JZ7AQNPM.mjs} +3 -3
  103. package/dist/chunks/{telegram-2EFGKIVK.mjs → telegram-JYY2VDTI.mjs} +5 -5
@@ -0,0 +1,301 @@
1
+ import { createRequire as __adfCreateRequire } from 'node:module';
2
+ import { fileURLToPath as __adfFileURLToPath } from 'node:url';
3
+ import { dirname as __adfDirname } from 'node:path';
4
+ const require = __adfCreateRequire(import.meta.url);
5
+ const __filename = __adfFileURLToPath(import.meta.url);
6
+ const __dirname = __adfDirname(__filename);
7
+ import {
8
+ tokensEqual
9
+ } from "./chunk-WJGPNHGX.mjs";
10
+ import {
11
+ restrictToCurrentUserWindows
12
+ } from "./chunk-LTX74NU6.mjs";
13
+
14
+ // src/main/daemon/local-access.ts
15
+ import { chmodSync, mkdirSync, readFileSync, unlinkSync, writeFileSync } from "node:fs";
16
+ import { join } from "node:path";
17
+ import { randomBytes } from "node:crypto";
18
+ var LOCAL_PROOF_FILENAME = "daemon-local-proof", LOCAL_PROOF_HEADER = "x-adf-local-proof", BEHIND_PROXY_ENV = "ADF_DAEMON_BEHIND_PROXY", PROXY_HEADERS = ["forwarded", "x-forwarded-for", "x-forwarded-host", "x-forwarded-proto", "x-real-ip", "via"];
19
+ function isLoopbackAddress(address) {
20
+ return address ? address === "::1" || address.startsWith("127.") || address.startsWith("::ffff:127.") : !1;
21
+ }
22
+ function hasProxyHeaders(headers) {
23
+ return PROXY_HEADERS.some((name) => headers[name] !== void 0);
24
+ }
25
+ function behindProxyFromEnv(env = process.env) {
26
+ return /^(1|true|yes|on)$/i.test((env[BEHIND_PROXY_ENV] ?? "").trim());
27
+ }
28
+ var DEFAULT_PORT = 7385;
29
+ function localProofPath(settingsDir, port = DEFAULT_PORT) {
30
+ return join(settingsDir, port === DEFAULT_PORT ? LOCAL_PROOF_FILENAME : `${LOCAL_PROOF_FILENAME}-${port}`);
31
+ }
32
+ function mintLocalProof(settingsDir, port = DEFAULT_PORT, platform = process.platform) {
33
+ mkdirSync(settingsDir, { recursive: !0 });
34
+ let proof = randomBytes(32).toString("base64url"), path = localProofPath(settingsDir, port);
35
+ if (platform === "win32") {
36
+ writeFileSync(path, "");
37
+ try {
38
+ restrictToCurrentUserWindows(path);
39
+ } catch (err) {
40
+ try {
41
+ unlinkSync(path);
42
+ } catch {
43
+ }
44
+ throw new Error(`Could not restrict ${path} to the current user (icacls): ${err instanceof Error ? err.message : String(err)}`);
45
+ }
46
+ return writeFileSync(path, `${proof}
47
+ `), { proof, path };
48
+ }
49
+ return writeFileSync(path, `${proof}
50
+ `, { mode: 384 }), chmodSync(path, 384), { proof, path };
51
+ }
52
+ var proofProblem = null;
53
+ function noteLocalProofProblem(problem) {
54
+ proofProblem = problem;
55
+ }
56
+ function localProofProblem() {
57
+ return proofProblem;
58
+ }
59
+ function readLocalProof(settingsDir, port = DEFAULT_PORT) {
60
+ try {
61
+ let proof = readFileSync(localProofPath(settingsDir, port), "utf-8").trim();
62
+ return /^[A-Za-z0-9_-]{32,}$/.test(proof) ? proof : null;
63
+ } catch {
64
+ return null;
65
+ }
66
+ }
67
+ function isLocalOnlyRoute(path) {
68
+ let p = path.split("?")[0];
69
+ return p === "/daemon/shutdown" || p === "/client/reload-credentials" || p === "/client/sessions" || /^\/client\/sessions\/[^/]+\/exit-when-closed$/.test(p) || /^\/client\/sessions\/[^/]+\/quit$/.test(p) || /^\/identity\/(create|restore|import|unlock|lock|confirm-backup|trust-daemon|untrust-daemon)$/.test(p) || /^\/agents\/[^/]+\/identity\/reveal$/.test(p) || p === "/files/agent/identity/reveal" || p === "/settings/providers/keys/reveal" || p === "/remote-access" || p.startsWith("/remote-access/") || p === "/network/peers";
70
+ }
71
+ function isDeviceRefusedRoute(method, path) {
72
+ let p = path.split("?")[0];
73
+ return !(!isLocalOnlyRoute(p) || method === "POST" && p === "/client/sessions" || /^\/client\/sessions\/[^/]+\/(quit|exit-when-closed)$/.test(p));
74
+ }
75
+ function localAccessRefusal(request, opts) {
76
+ if (!isLoopbackAddress(request.remoteAddress)) return "the request did not come from this machine";
77
+ if (hasProxyHeaders(request.headers)) return "the request came through a proxy (forwarded headers)";
78
+ if (opts.behindProxy) {
79
+ let raw = request.headers[LOCAL_PROOF_HEADER], presented = (Array.isArray(raw) ? raw[0] : raw)?.trim();
80
+ if (!presented || !opts.localProof || !tokensEqual(presented, opts.localProof))
81
+ return `the daemon runs behind a proxy (${BEHIND_PROXY_ENV}) and the request lacks this machine's local proof`;
82
+ }
83
+ return null;
84
+ }
85
+
86
+ // src/main/utils/test-seams.ts
87
+ import { basename } from "path";
88
+ import { fileURLToPath } from "url";
89
+ var TEST_SEAMS_ENV = "ADF_TEST_SEAMS";
90
+ function isPackagedModulePath(modulePath) {
91
+ if (modulePath.includes("app.asar")) return !0;
92
+ let segments = modulePath.split(/[\\/]/).map((s) => s.toLowerCase());
93
+ return segments.includes("node_modules") || segments.includes("registry.npmjs.org") ? !0 : segments.some((s, i) => s === "deno" && segments[i + 1] === "npm");
94
+ }
95
+ function isPackagedRuntime(proc = process) {
96
+ return proc.versions.electron && !/[\\/]node_modules[\\/]electron[\\/]/.test(proc.execPath) ? !0 : isPackagedExecutable(proc.execPath, proc.argv[1] ?? "");
97
+ }
98
+ function isPackagedExecutable(execPath, entry) {
99
+ let exe = basename(execPath).toLowerCase().replace(/\.exe$/, "");
100
+ return exe !== "node" && exe !== "electron" ? !0 : /[\\/]app\.asar([\\/]|$)/i.test(entry);
101
+ }
102
+ function currentModulePath() {
103
+ try {
104
+ return fileURLToPath(import.meta.url);
105
+ } catch {
106
+ return null;
107
+ }
108
+ }
109
+ function testSeamsAllowed(input = {}) {
110
+ if ((input.env ?? process.env)[TEST_SEAMS_ENV] !== "1") return !1;
111
+ let modulePath = input.modulePath === void 0 ? currentModulePath() : input.modulePath;
112
+ return !modulePath || isPackagedModulePath(modulePath) ? !1 : !(input.isPackagedRuntime ?? isPackagedRuntime)();
113
+ }
114
+
115
+ // src/main/services/owner-secret-store.ts
116
+ import { createCipheriv, createDecipheriv, randomBytes as randomBytes2, scryptSync, timingSafeEqual } from "crypto";
117
+ import { chmodSync as chmodSync2, existsSync, mkdirSync as mkdirSync2, readFileSync as readFileSync2, renameSync, writeFileSync as writeFileSync2 } from "fs";
118
+ import { dirname } from "path";
119
+ import { createRequire } from "module";
120
+ var KEYCHAIN_SERVICE = "ADF", OWNER_MNEMONIC_ACCOUNT = "owner-mnemonic", WrongPassphraseError = class extends Error {
121
+ constructor() {
122
+ super("Wrong passphrase"), this.name = "WrongPassphraseError";
123
+ }
124
+ }, SecretStoreLockedError = class extends Error {
125
+ constructor(message = "The owner secret file is locked \u2014 unlock it with its passphrase first") {
126
+ super(message), this.name = "SecretStoreLockedError";
127
+ }
128
+ }, keyringCtor;
129
+ function loadKeyring() {
130
+ if (keyringCtor !== void 0) return keyringCtor;
131
+ try {
132
+ keyringCtor = createRequire(import.meta.url)("@napi-rs/keyring").Entry;
133
+ } catch {
134
+ keyringCtor = null;
135
+ }
136
+ return keyringCtor;
137
+ }
138
+ var KeychainSecretBackend = class {
139
+ constructor(Entry, service = KEYCHAIN_SERVICE) {
140
+ this.Entry = Entry;
141
+ this.service = service;
142
+ }
143
+ Entry;
144
+ service;
145
+ kind = "keychain";
146
+ entry(account) {
147
+ return new this.Entry(this.service, account, { linux: { store: "secret-service" } });
148
+ }
149
+ isUnlocked() {
150
+ return !0;
151
+ }
152
+ get(account) {
153
+ let read = prereadValue(this.service, account);
154
+ return read !== void 0 ? read : this.entry(account).getPassword() ?? null;
155
+ }
156
+ set(account, value) {
157
+ this.entry(account).setPassword(value), preread?.service === this.service && preread.values.set(account, value);
158
+ }
159
+ delete(account) {
160
+ try {
161
+ this.entry(account).deleteCredential();
162
+ } catch {
163
+ }
164
+ preread?.service === this.service && preread.values.delete(account);
165
+ }
166
+ }, PREREAD_TTL_MS = 6e4, preread = null;
167
+ function prereadValue(service, account) {
168
+ if (!(!preread || preread.service !== service)) {
169
+ if (Date.now() - preread.at > PREREAD_TTL_MS) {
170
+ preread = null;
171
+ return;
172
+ }
173
+ return preread.values.get(account);
174
+ }
175
+ }
176
+ function openKeychainBackend() {
177
+ if (process.env.ADF_KEYCHAIN === "0" || process.env.ADF_KEYCHAIN === "off") return null;
178
+ let Entry = loadKeyring();
179
+ if (!Entry) return null;
180
+ try {
181
+ let backend = new KeychainSecretBackend(Entry);
182
+ return backend.get(OWNER_MNEMONIC_ACCOUNT), backend;
183
+ } catch {
184
+ return null;
185
+ }
186
+ }
187
+ function probeKeychain() {
188
+ if (process.env.ADF_KEYCHAIN === "0" || process.env.ADF_KEYCHAIN === "off") return { backend: null, present: !1, error: null };
189
+ let Entry = loadKeyring();
190
+ if (!Entry) return { backend: null, present: !1, error: null };
191
+ try {
192
+ let backend = new KeychainSecretBackend(Entry);
193
+ return backend.get(OWNER_MNEMONIC_ACCOUNT), { backend, present: !0, error: null };
194
+ } catch (err) {
195
+ return { backend: null, present: !0, error: err instanceof Error ? err.message : String(err) };
196
+ }
197
+ }
198
+ var SCRYPT = { N: 32768, r: 8, p: 1, maxmem: 64 * 1024 * 1024 }, CHECK_VALUE = "adf-owner-secrets-v1";
199
+ function seal(key, plaintext) {
200
+ let iv = randomBytes2(12), cipher = createCipheriv("aes-256-gcm", key, iv), ct = Buffer.concat([cipher.update(plaintext, "utf-8"), cipher.final()]);
201
+ return { iv: iv.toString("base64"), tag: cipher.getAuthTag().toString("base64"), ct: ct.toString("base64") };
202
+ }
203
+ function open(key, sealed) {
204
+ let decipher = createDecipheriv("aes-256-gcm", key, Buffer.from(sealed.iv, "base64"));
205
+ return decipher.setAuthTag(Buffer.from(sealed.tag, "base64")), Buffer.concat([decipher.update(Buffer.from(sealed.ct, "base64")), decipher.final()]).toString("utf-8");
206
+ }
207
+ var MIN_PASSPHRASE_LENGTH = 8, FileSecretBackend = class {
208
+ constructor(filePath) {
209
+ this.filePath = filePath;
210
+ }
211
+ filePath;
212
+ kind = "file";
213
+ key = null;
214
+ salt = null;
215
+ values = {};
216
+ exists() {
217
+ return existsSync(this.filePath);
218
+ }
219
+ isUnlocked() {
220
+ return this.key !== null;
221
+ }
222
+ /**
223
+ * Unlock an existing file, or create an empty one sealed with `passphrase`
224
+ * when none exists yet. Throws WrongPassphraseError on a mismatch.
225
+ */
226
+ unlock(passphrase) {
227
+ if (!this.exists()) {
228
+ if (passphrase.length < MIN_PASSPHRASE_LENGTH)
229
+ throw new Error(`Passphrase must be at least ${MIN_PASSPHRASE_LENGTH} characters`);
230
+ this.salt = randomBytes2(16), this.key = scryptSync(passphrase, this.salt, 32, SCRYPT), this.values = {}, this.persist();
231
+ return;
232
+ }
233
+ let parsed = JSON.parse(readFileSync2(this.filePath, "utf-8"));
234
+ if (parsed?.v !== 1 || parsed.kdf?.name !== "scrypt") throw new Error(`Unsupported secret file format: ${this.filePath}`);
235
+ let salt = Buffer.from(parsed.kdf.salt, "base64"), key = scryptSync(passphrase, salt, 32, { N: parsed.kdf.N, r: parsed.kdf.r, p: parsed.kdf.p, maxmem: SCRYPT.maxmem }), check;
236
+ try {
237
+ check = open(key, parsed.check);
238
+ } catch {
239
+ throw new WrongPassphraseError();
240
+ }
241
+ let checkBuf = Buffer.from(check), expected = Buffer.from(CHECK_VALUE);
242
+ if (checkBuf.length !== expected.length || !timingSafeEqual(checkBuf, expected)) throw new WrongPassphraseError();
243
+ this.values = JSON.parse(open(key, parsed.data)), this.key = key, this.salt = salt;
244
+ try {
245
+ chmodSync2(this.filePath, 384);
246
+ } catch {
247
+ }
248
+ }
249
+ lock() {
250
+ this.key?.fill(0), this.key = null, this.values = {};
251
+ }
252
+ get(account) {
253
+ return this.key ? this.values[account] ?? null : null;
254
+ }
255
+ set(account, value) {
256
+ if (!this.key) throw new SecretStoreLockedError();
257
+ this.values[account] = value, this.persist();
258
+ }
259
+ delete(account) {
260
+ !this.key || !(account in this.values) || (delete this.values[account], this.persist());
261
+ }
262
+ persist() {
263
+ if (!this.key || !this.salt) throw new SecretStoreLockedError();
264
+ let record = {
265
+ v: 1,
266
+ kdf: { name: "scrypt", N: SCRYPT.N, r: SCRYPT.r, p: SCRYPT.p, salt: this.salt.toString("base64") },
267
+ check: seal(this.key, CHECK_VALUE),
268
+ data: seal(this.key, JSON.stringify(this.values))
269
+ };
270
+ mkdirSync2(dirname(this.filePath), { recursive: !0 });
271
+ let tmp = `${this.filePath}.tmp`;
272
+ writeFileSync2(tmp, JSON.stringify(record, null, 2) + `
273
+ `, { mode: 384 }), renameSync(tmp, this.filePath);
274
+ try {
275
+ chmodSync2(this.filePath, 384);
276
+ } catch {
277
+ }
278
+ }
279
+ };
280
+
281
+ export {
282
+ LOCAL_PROOF_HEADER,
283
+ BEHIND_PROXY_ENV,
284
+ isLoopbackAddress,
285
+ hasProxyHeaders,
286
+ behindProxyFromEnv,
287
+ mintLocalProof,
288
+ noteLocalProofProblem,
289
+ localProofProblem,
290
+ readLocalProof,
291
+ isLocalOnlyRoute,
292
+ isDeviceRefusedRoute,
293
+ localAccessRefusal,
294
+ OWNER_MNEMONIC_ACCOUNT,
295
+ WrongPassphraseError,
296
+ openKeychainBackend,
297
+ probeKeychain,
298
+ MIN_PASSPHRASE_LENGTH,
299
+ FileSecretBackend,
300
+ testSeamsAllowed
301
+ };
@@ -0,0 +1,203 @@
1
+ import { createRequire as __adfCreateRequire } from 'node:module';
2
+ import { fileURLToPath as __adfFileURLToPath } from 'node:url';
3
+ import { dirname as __adfDirname } from 'node:path';
4
+ const require = __adfCreateRequire(import.meta.url);
5
+ const __filename = __adfFileURLToPath(import.meta.url);
6
+ const __dirname = __adfDirname(__filename);
7
+ import {
8
+ getUserDataPath
9
+ } from "./chunk-PAK5JCO2.mjs";
10
+ import {
11
+ protectSecretFile
12
+ } from "./chunk-LTX74NU6.mjs";
13
+ import {
14
+ __require
15
+ } from "./chunk-M2RX3S2T.mjs";
16
+
17
+ // src/main/providers/subscription-token-store.ts
18
+ import { readFileSync as readFileSync2, writeFileSync as writeFileSync2, unlinkSync, existsSync as existsSync2, mkdirSync as mkdirSync2, readdirSync } from "fs";
19
+ import { join as join2 } from "path";
20
+
21
+ // src/main/utils/credential-cipher.ts
22
+ import { randomBytes, createCipheriv, createDecipheriv } from "crypto";
23
+ import { readFileSync, writeFileSync, existsSync, mkdirSync } from "fs";
24
+ import { join } from "path";
25
+ var AES_GCM_PREFIX = "aesgcm:", SAFE_STORAGE_PREFIX = "safe:", KEY_FILE_NAME = "credential.key", KEY_BYTES = 32, IV_BYTES = 12, TAG_BYTES = 16, cachedKey = null, cachedKeyPath = null;
26
+ function getSafeStorage() {
27
+ try {
28
+ return __require("electron").safeStorage ?? null;
29
+ } catch {
30
+ return null;
31
+ }
32
+ }
33
+ function credentialKeyPath() {
34
+ let dir = getUserDataPath();
35
+ return existsSync(dir) || mkdirSync(dir, { recursive: !0 }), join(dir, KEY_FILE_NAME);
36
+ }
37
+ function readKeyFile(path) {
38
+ try {
39
+ let key = Buffer.from(readFileSync(path, "utf-8").trim(), "base64");
40
+ return key.length === KEY_BYTES ? key : null;
41
+ } catch {
42
+ return null;
43
+ }
44
+ }
45
+ function getCredentialKey() {
46
+ let path = credentialKeyPath();
47
+ if (cachedKey && cachedKeyPath === path) return cachedKey;
48
+ let key = existsSync(path) ? readKeyFile(path) : null;
49
+ if (key && protectSecretFile(path), !key && existsSync(path) && console.warn(`[Credentials] Key file at ${path} is unreadable \u2014 regenerating. Stored credentials will need re-authentication.`), !key) {
50
+ let generated = randomBytes(KEY_BYTES);
51
+ try {
52
+ writeFileSync(path, generated.toString("base64"), { mode: 384, flag: "wx" }), protectSecretFile(path), key = generated;
53
+ } catch (err) {
54
+ if (err.code === "EEXIST")
55
+ key = readKeyFile(path), key || (writeFileSync(path, generated.toString("base64"), { mode: 384 }), protectSecretFile(path), key = generated);
56
+ else
57
+ throw err;
58
+ }
59
+ }
60
+ return cachedKey = key, cachedKeyPath = path, key;
61
+ }
62
+ function encryptCredential(value) {
63
+ let iv = randomBytes(IV_BYTES), cipher = createCipheriv("aes-256-gcm", getCredentialKey(), iv), ciphertext = Buffer.concat([cipher.update(value, "utf-8"), cipher.final()]), tag = cipher.getAuthTag();
64
+ return `${AES_GCM_PREFIX}${iv.toString("base64")}.${tag.toString("base64")}.${ciphertext.toString("base64")}`;
65
+ }
66
+ function decryptAesGcm(raw, logPrefix) {
67
+ let parts = raw.slice(AES_GCM_PREFIX.length).split(".");
68
+ if (parts.length !== 3)
69
+ return console.warn(`${logPrefix} Malformed encrypted credential payload`), null;
70
+ try {
71
+ let iv = Buffer.from(parts[0], "base64"), tag = Buffer.from(parts[1], "base64");
72
+ if (iv.length !== IV_BYTES || tag.length !== TAG_BYTES)
73
+ return console.warn(`${logPrefix} Malformed encrypted credential payload`), null;
74
+ let decipher = createDecipheriv("aes-256-gcm", getCredentialKey(), iv);
75
+ return decipher.setAuthTag(tag), Buffer.concat([
76
+ decipher.update(Buffer.from(parts[2], "base64")),
77
+ decipher.final()
78
+ ]).toString("utf-8");
79
+ } catch {
80
+ return console.warn(`${logPrefix} Could not decrypt credential \u2014 the key file may have been regenerated. Sign in again.`), null;
81
+ }
82
+ }
83
+ function decryptCredential(raw, logPrefix = "[Credentials]") {
84
+ if (raw.startsWith(AES_GCM_PREFIX))
85
+ return decryptAesGcm(raw, logPrefix);
86
+ if (raw.startsWith(SAFE_STORAGE_PREFIX)) {
87
+ let safeStorage = getSafeStorage();
88
+ if (!safeStorage?.isEncryptionAvailable())
89
+ return console.warn(`${logPrefix} Credential is safeStorage-encrypted and this process has no Electron keychain access. Start ADF Studio once to migrate it, or sign in here.`), null;
90
+ try {
91
+ return safeStorage.decryptString(Buffer.from(raw.slice(SAFE_STORAGE_PREFIX.length), "base64"));
92
+ } catch (err) {
93
+ return console.warn(`${logPrefix} Failed to decrypt safeStorage credential:`, err), null;
94
+ }
95
+ }
96
+ return raw;
97
+ }
98
+
99
+ // src/main/providers/subscription-token-store.ts
100
+ var STUDIO_FILE = "auth.json", DAEMON_FILE = "auth.daemon.json", REPLACED_FILE_PATTERN = /^auth\.replaced(\.[\w-]+)?\.json$/;
101
+ function getSafeStorage2() {
102
+ try {
103
+ return __require("electron").safeStorage ?? null;
104
+ } catch {
105
+ return null;
106
+ }
107
+ }
108
+ function isElectronSurface() {
109
+ return getSafeStorage2() !== null;
110
+ }
111
+ function createSubscriptionTokenStore(dirName) {
112
+ let logTag = `[${dirName} Auth]`;
113
+ function getDir() {
114
+ let dir = join2(getUserDataPath(), dirName);
115
+ return existsSync2(dir) || mkdirSync2(dir, { recursive: !0 }), dir;
116
+ }
117
+ function getStorePath() {
118
+ return join2(getDir(), isElectronSurface() ? STUDIO_FILE : DAEMON_FILE);
119
+ }
120
+ function encryptValue(value) {
121
+ let safeStorage = getSafeStorage2();
122
+ if (safeStorage?.isEncryptionAvailable()) {
123
+ let encrypted = safeStorage.encryptString(value);
124
+ return SAFE_STORAGE_PREFIX + encrypted.toString("base64");
125
+ }
126
+ return safeStorage && console.warn(`${logTag} safeStorage unavailable \u2014 falling back to key-file encryption`), encryptCredential(value);
127
+ }
128
+ function decryptValue(raw) {
129
+ return decryptCredential(raw, logTag);
130
+ }
131
+ function adoptLegacyFile(ownPath) {
132
+ let legacyPath = join2(getDir(), STUDIO_FILE);
133
+ if (existsSync2(legacyPath))
134
+ try {
135
+ let raw = readFileSync2(legacyPath, "utf-8");
136
+ if (raw.startsWith(SAFE_STORAGE_PREFIX)) {
137
+ console.warn(
138
+ `${logTag} ${STUDIO_FILE} is encrypted by ADF Studio and cannot be used here \u2014 log in from this surface to create its own session`
139
+ );
140
+ return;
141
+ }
142
+ writeFileSync2(ownPath, raw, { mode: 384 }), console.log(`${logTag} Adopted legacy shared token file into ${DAEMON_FILE}`);
143
+ } catch (err) {
144
+ console.warn(`${logTag} Failed to adopt legacy token file:`, err);
145
+ }
146
+ }
147
+ function readTokens() {
148
+ let path = getStorePath();
149
+ if (!existsSync2(path) && !isElectronSurface() && adoptLegacyFile(path), !existsSync2(path)) return null;
150
+ try {
151
+ let raw = readFileSync2(path, "utf-8"), decrypted = decryptValue(raw);
152
+ return decrypted ? JSON.parse(decrypted) : null;
153
+ } catch (err) {
154
+ return console.warn(`${logTag} Failed to read tokens:`, err), null;
155
+ }
156
+ }
157
+ function writeTokens(tokens) {
158
+ let path = getStorePath(), value = encryptValue(JSON.stringify(tokens));
159
+ if (!value.startsWith(SAFE_STORAGE_PREFIX) && existsSync2(path)) {
160
+ let existing = null;
161
+ try {
162
+ existing = readFileSync2(path, "utf-8");
163
+ } catch {
164
+ }
165
+ if (existing?.startsWith(SAFE_STORAGE_PREFIX))
166
+ throw new Error(
167
+ `${logTag} refusing to overwrite a keychain-encrypted session with weaker key-file encryption. Log out (clearing the stored session) and log in again from this surface.`
168
+ );
169
+ }
170
+ writeFileSync2(path, value, { mode: 384 });
171
+ }
172
+ function clearTokens() {
173
+ let path = getStorePath();
174
+ if (existsSync2(path))
175
+ try {
176
+ unlinkSync(path);
177
+ } catch {
178
+ }
179
+ }
180
+ function signedIn(accountId) {
181
+ if (!accountId) return;
182
+ let names;
183
+ try {
184
+ names = readdirSync(getDir()).filter((name) => REPLACED_FILE_PATTERN.test(name));
185
+ } catch (err) {
186
+ console.warn(`${logTag} Could not list the sessions set aside after the sign-in:`, err instanceof Error ? err.message : err);
187
+ return;
188
+ }
189
+ for (let name of names)
190
+ try {
191
+ let path = join2(getDir(), name);
192
+ if (JSON.parse(decryptValue(readFileSync2(path, "utf-8")) ?? "null")?.account_id !== accountId) continue;
193
+ unlinkSync(path), console.log(`${logTag} Deleted ${name}: ${accountId} signed in again, so the session set aside for it is no longer needed`);
194
+ } catch (err) {
195
+ console.warn(`${logTag} Could not check ${name} after the sign-in:`, err instanceof Error ? err.message : err);
196
+ }
197
+ }
198
+ return { readTokens, writeTokens, clearTokens, signedIn };
199
+ }
200
+
201
+ export {
202
+ createSubscriptionTokenStore
203
+ };