@agentdocumentformat/cli 0.7.7 → 0.8.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.
- package/README.md +1 -1
- package/dist/adf.mjs +59 -8
- package/dist/chunks/{APEv2Parser-2CNNHMXV.mjs → APEv2Parser-WIXRJLHB.mjs} +2 -2
- package/dist/chunks/{AiffParser-7BR4RL6G.mjs → AiffParser-ZC4QFOVJ.mjs} +5 -5
- package/dist/chunks/{App-5KXVPMBV.mjs → App-A5GUFCFJ.mjs} +279 -291
- package/dist/chunks/{DsdiffParser-CMD4AX7A.mjs → DsdiffParser-UAPAJHFX.mjs} +5 -5
- package/dist/chunks/{DsfParser-UOGZDS2M.mjs → DsfParser-NNYZK2QX.mjs} +6 -6
- package/dist/chunks/{FlacParser-HB3T3CD4.mjs → FlacParser-MW2W4LO3.mjs} +6 -6
- package/dist/chunks/{MP4Parser-66HBRUSX.mjs → MP4Parser-Z57SYOOQ.mjs} +4 -4
- package/dist/chunks/{MpegParser-YW6LIUEW.mjs → MpegParser-XIIPAZVM.mjs} +7 -7
- package/dist/chunks/{MusepackParser-PAUSXP7D.mjs → MusepackParser-QWNDEYHJ.mjs} +6 -6
- package/dist/chunks/{OggParser-NUBV3GWC.mjs → OggParser-WRX53F77.mjs} +9 -9
- package/dist/chunks/{WavPackParser-WQAGT7TC.mjs → WavPackParser-MJ7WCSJ5.mjs} +2 -2
- package/dist/chunks/{WaveParser-EWLQVDX4.mjs → WaveParser-RAVLHZ5S.mjs} +7 -7
- package/dist/chunks/{adf-schema-US4NFHMR.mjs → adf-schema-YJSGLMA4.mjs} +2 -2
- package/dist/chunks/auth-manager-AJ32FZWS.mjs +19 -0
- package/dist/chunks/auth-manager-C5OBEQK2.mjs +18 -0
- package/dist/chunks/auth-manager-TBNKCJ45.mjs +17 -0
- package/dist/chunks/{chatgpt-subscription-E4MXTIAT.mjs → chatgpt-subscription-MMGNW5KJ.mjs} +5 -2
- package/dist/chunks/chunk-3UGZFWIF.mjs +26 -0
- package/dist/chunks/{chunk-5PO5PKRV.mjs → chunk-4OGZFUKA.mjs} +126 -67
- package/dist/chunks/{chunk-VN7UH7I5.mjs → chunk-6XQZGYMK.mjs} +246 -67
- package/dist/chunks/{chunk-XNPZBLYL.mjs → chunk-75DC5EWN.mjs} +13 -2
- package/dist/chunks/chunk-AZYOXXVL.mjs +865 -0
- package/dist/chunks/{chunk-6VQEXLE2.mjs → chunk-BHY7QDCM.mjs} +41 -3
- package/dist/chunks/chunk-C2S64Y6F.mjs +203 -0
- package/dist/chunks/chunk-C4GA5SI4.mjs +12799 -0
- package/dist/chunks/chunk-DDTTSKGG.mjs +2443 -0
- package/dist/chunks/{chunk-VAUOM3IN.mjs → chunk-DLWCKKIO.mjs} +1 -1
- package/dist/chunks/{chunk-HPVFJYXR.mjs → chunk-ESP3VNMX.mjs} +1 -1
- package/dist/chunks/{chunk-QPLEAE6V.mjs → chunk-G6NBFYG5.mjs} +152 -824
- package/dist/chunks/{chunk-KXEF4F4E.mjs → chunk-GAZO6UMI.mjs} +1 -1
- package/dist/chunks/{chunk-XYTWGHFS.mjs → chunk-H3XLRWVE.mjs} +1 -1
- package/dist/chunks/{chunk-7T2YMTWL.mjs → chunk-H4C65MTP.mjs} +4 -4
- package/dist/chunks/chunk-HBOFZRUS.mjs +738 -0
- package/dist/chunks/chunk-JVPZIMXW.mjs +976 -0
- package/dist/chunks/{chunk-XYV3VCIX.mjs → chunk-JZFONJSL.mjs} +79 -20
- package/dist/chunks/chunk-KDDVQKCG.mjs +65 -0
- package/dist/chunks/chunk-KRPKWOMB.mjs +290 -0
- package/dist/chunks/{chunk-4N4ASPH6.mjs → chunk-LCMANRYY.mjs} +4 -254
- package/dist/chunks/{chunk-TPRZQ7Z4.mjs → chunk-LGL6ML37.mjs} +4 -4
- package/dist/chunks/chunk-LKFHERRV.mjs +145 -0
- package/dist/chunks/chunk-LTX74NU6.mjs +29 -0
- package/dist/chunks/chunk-M2F7C2UJ.mjs +425 -0
- package/dist/chunks/{chunk-62NE4LG4.mjs → chunk-MQAMI5BF.mjs} +5 -5
- package/dist/chunks/chunk-MZRXFWPQ.mjs +278 -0
- package/dist/chunks/{chunk-PRMGZZM5.mjs → chunk-NZLEPJ5M.mjs} +2 -0
- package/dist/chunks/{chunk-CD3ATSXE.mjs → chunk-NZO5O4VN.mjs} +1 -1
- package/dist/chunks/{chunk-I3UYSITV.mjs → chunk-O7XKQ6CH.mjs} +1 -1
- package/dist/chunks/chunk-P3RG5LQA.mjs +244 -0
- package/dist/chunks/chunk-PAK5JCO2.mjs +48 -0
- package/dist/chunks/chunk-PC63YFB7.mjs +34 -0
- package/dist/chunks/{daemon-control-HKFVSQTQ.mjs → chunk-PRPTKMQW.mjs} +67 -26
- package/dist/chunks/{chunk-LFMB4PAA.mjs → chunk-TKXIH27X.mjs} +974 -113
- package/dist/chunks/{chunk-5W7KES6P.mjs → chunk-UZPDETEU.mjs} +1 -1
- package/dist/chunks/chunk-V2T6NZX2.mjs +517 -0
- package/dist/chunks/chunk-V3MM6PCH.mjs +366 -0
- package/dist/chunks/chunk-WJGPNHGX.mjs +67 -0
- package/dist/chunks/chunk-WVTPPOKK.mjs +290 -0
- package/dist/chunks/{chunk-J74STFKE.mjs → chunk-WX6QCUWI.mjs} +272 -51
- package/dist/chunks/{chunk-Y5ZLKFLE.mjs → chunk-XNNJQCZP.mjs} +196 -165
- package/dist/chunks/{chunk-HDBPBORT.mjs → chunk-XT2BJUFC.mjs} +15 -6
- package/dist/chunks/chunk-YRMKSHW3.mjs +9076 -0
- package/dist/chunks/{chunk-BNXUAOO4.mjs → chunk-ZGXUOAWZ.mjs} +3186 -959
- package/dist/chunks/chunk-ZPB3HYM7.mjs +45 -0
- package/dist/chunks/claude-subscription-33BMZB6I.mjs +29 -0
- package/dist/chunks/{cli-AFHQ2XTN.mjs → cli-I47IFDHJ.mjs} +797 -56
- package/dist/chunks/{commands-XNJMCD5L.mjs → commands-E4EQUHE5.mjs} +5 -2
- package/dist/chunks/{daemon-CHZHTLGR.mjs → daemon-FQ5BV3AP.mjs} +84550 -70518
- package/dist/chunks/daemon-control-L3CLG63P.mjs +59 -0
- package/dist/chunks/{daemon-token-WRSULP7G.mjs → daemon-token-L5QKTHU5.mjs} +3 -1
- package/dist/chunks/{discord-DSP4HUWI.mjs → discord-IR62565M.mjs} +3 -52
- package/dist/chunks/{email-BRG7KUO2.mjs → email-KHHTJBDW.mjs} +4 -2
- package/dist/chunks/{environment-NX277MQG.mjs → environment-R47X44GM.mjs} +1 -1
- package/dist/chunks/{grok-subscription-4PYX7TBF.mjs → grok-subscription-E74FS5EG.mjs} +5 -2
- package/dist/chunks/{lib-N7FCZWKH.mjs → lib-L27L5PXM.mjs} +22 -22
- package/dist/chunks/{open-VAU7PXT6.mjs → open-TLGS2Z3Q.mjs} +4 -4
- package/dist/chunks/{parser-JVY2PWSM.mjs → parser-7GARNT5L.mjs} +1 -1
- package/dist/chunks/{pipeline-executor-U6IMCCP3.mjs → pipeline-executor-FD4FBWQA.mjs} +8 -5
- package/dist/chunks/prompt-RRHZX4YT.mjs +13 -0
- package/dist/chunks/remote-access-cli-XXAPQWH6.mjs +268 -0
- package/dist/chunks/remote-hello-UFWUBDQI.mjs +37 -0
- package/dist/chunks/sdk-5FD2ZP7N.mjs +28422 -0
- package/dist/chunks/{slack-OCNNF4DX.mjs → slack-IYC5RAB5.mjs} +3 -4
- package/dist/chunks/{store-HUVDJPYN.mjs → store-ZRN2WCFB.mjs} +6 -3
- package/dist/chunks/tailscale-WLJATFMB.mjs +25 -0
- package/dist/chunks/{theme-SFE3JMA2.mjs → theme-HLBDTF6F.mjs} +1 -1
- package/dist/chunks/{themes-YLXLOIJF.mjs → themes-BQ72P446.mjs} +2 -2
- package/dist/chunks/{token-6G3HCMNX.mjs → token-6D22WECM.mjs} +20 -16
- package/dist/chunks/{token-util-UXYSDQIW.mjs → token-util-YF3ZWBZ4.mjs} +1 -2
- package/dist/chunks/{tui-4ZWZKD4C.mjs → tui-SPSPDADM.mjs} +17 -14
- package/dist/chunks/{welcome-XHXFV7SH.mjs → welcome-J5JZZAM5.mjs} +1 -1
- package/dist/chunks/{whatsapp-AVKT3CTJ.mjs → whatsapp-YJFFVN4Q.mjs} +8 -8
- package/package.json +1 -1
- package/dist/chunks/chunk-GKKCMXIZ.mjs +0 -94
- package/dist/chunks/chunk-IHDDCZBS.mjs +0 -112
- package/dist/chunks/chunk-KWFOS5WC.mjs +0 -41
- package/dist/chunks/chunk-UEZR2CNS.mjs +0 -65
- package/dist/chunks/chunk-VMHTYDH4.mjs +0 -172
- package/dist/chunks/chunk-ZROSGV65.mjs +0 -3112
- package/dist/chunks/{chunk-NBTUWMGP.mjs → chunk-2MTE22CR.mjs} +3 -3
- package/dist/chunks/{telegram-YI2OHNTD.mjs → telegram-JYY2VDTI.mjs} +4 -4
|
@@ -0,0 +1,290 @@
|
|
|
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
|
+
return this.entry(account).getPassword() ?? null;
|
|
154
|
+
}
|
|
155
|
+
set(account, value) {
|
|
156
|
+
this.entry(account).setPassword(value);
|
|
157
|
+
}
|
|
158
|
+
delete(account) {
|
|
159
|
+
try {
|
|
160
|
+
this.entry(account).deleteCredential();
|
|
161
|
+
} catch {
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
};
|
|
165
|
+
function openKeychainBackend() {
|
|
166
|
+
if (process.env.ADF_KEYCHAIN === "0" || process.env.ADF_KEYCHAIN === "off") return null;
|
|
167
|
+
let Entry = loadKeyring();
|
|
168
|
+
if (!Entry) return null;
|
|
169
|
+
try {
|
|
170
|
+
let backend = new KeychainSecretBackend(Entry);
|
|
171
|
+
return backend.get(OWNER_MNEMONIC_ACCOUNT), backend;
|
|
172
|
+
} catch {
|
|
173
|
+
return null;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
function probeKeychain() {
|
|
177
|
+
if (process.env.ADF_KEYCHAIN === "0" || process.env.ADF_KEYCHAIN === "off") return { backend: null, present: !1, error: null };
|
|
178
|
+
let Entry = loadKeyring();
|
|
179
|
+
if (!Entry) return { backend: null, present: !1, error: null };
|
|
180
|
+
try {
|
|
181
|
+
let backend = new KeychainSecretBackend(Entry);
|
|
182
|
+
return backend.get(OWNER_MNEMONIC_ACCOUNT), { backend, present: !0, error: null };
|
|
183
|
+
} catch (err) {
|
|
184
|
+
return { backend: null, present: !0, error: err instanceof Error ? err.message : String(err) };
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
var SCRYPT = { N: 32768, r: 8, p: 1, maxmem: 64 * 1024 * 1024 }, CHECK_VALUE = "adf-owner-secrets-v1";
|
|
188
|
+
function seal(key, plaintext) {
|
|
189
|
+
let iv = randomBytes2(12), cipher = createCipheriv("aes-256-gcm", key, iv), ct = Buffer.concat([cipher.update(plaintext, "utf-8"), cipher.final()]);
|
|
190
|
+
return { iv: iv.toString("base64"), tag: cipher.getAuthTag().toString("base64"), ct: ct.toString("base64") };
|
|
191
|
+
}
|
|
192
|
+
function open(key, sealed) {
|
|
193
|
+
let decipher = createDecipheriv("aes-256-gcm", key, Buffer.from(sealed.iv, "base64"));
|
|
194
|
+
return decipher.setAuthTag(Buffer.from(sealed.tag, "base64")), Buffer.concat([decipher.update(Buffer.from(sealed.ct, "base64")), decipher.final()]).toString("utf-8");
|
|
195
|
+
}
|
|
196
|
+
var MIN_PASSPHRASE_LENGTH = 8, FileSecretBackend = class {
|
|
197
|
+
constructor(filePath) {
|
|
198
|
+
this.filePath = filePath;
|
|
199
|
+
}
|
|
200
|
+
filePath;
|
|
201
|
+
kind = "file";
|
|
202
|
+
key = null;
|
|
203
|
+
salt = null;
|
|
204
|
+
values = {};
|
|
205
|
+
exists() {
|
|
206
|
+
return existsSync(this.filePath);
|
|
207
|
+
}
|
|
208
|
+
isUnlocked() {
|
|
209
|
+
return this.key !== null;
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
* Unlock an existing file, or create an empty one sealed with `passphrase`
|
|
213
|
+
* when none exists yet. Throws WrongPassphraseError on a mismatch.
|
|
214
|
+
*/
|
|
215
|
+
unlock(passphrase) {
|
|
216
|
+
if (!this.exists()) {
|
|
217
|
+
if (passphrase.length < MIN_PASSPHRASE_LENGTH)
|
|
218
|
+
throw new Error(`Passphrase must be at least ${MIN_PASSPHRASE_LENGTH} characters`);
|
|
219
|
+
this.salt = randomBytes2(16), this.key = scryptSync(passphrase, this.salt, 32, SCRYPT), this.values = {}, this.persist();
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
let parsed = JSON.parse(readFileSync2(this.filePath, "utf-8"));
|
|
223
|
+
if (parsed?.v !== 1 || parsed.kdf?.name !== "scrypt") throw new Error(`Unsupported secret file format: ${this.filePath}`);
|
|
224
|
+
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;
|
|
225
|
+
try {
|
|
226
|
+
check = open(key, parsed.check);
|
|
227
|
+
} catch {
|
|
228
|
+
throw new WrongPassphraseError();
|
|
229
|
+
}
|
|
230
|
+
let checkBuf = Buffer.from(check), expected = Buffer.from(CHECK_VALUE);
|
|
231
|
+
if (checkBuf.length !== expected.length || !timingSafeEqual(checkBuf, expected)) throw new WrongPassphraseError();
|
|
232
|
+
this.values = JSON.parse(open(key, parsed.data)), this.key = key, this.salt = salt;
|
|
233
|
+
try {
|
|
234
|
+
chmodSync2(this.filePath, 384);
|
|
235
|
+
} catch {
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
lock() {
|
|
239
|
+
this.key?.fill(0), this.key = null, this.values = {};
|
|
240
|
+
}
|
|
241
|
+
get(account) {
|
|
242
|
+
return this.key ? this.values[account] ?? null : null;
|
|
243
|
+
}
|
|
244
|
+
set(account, value) {
|
|
245
|
+
if (!this.key) throw new SecretStoreLockedError();
|
|
246
|
+
this.values[account] = value, this.persist();
|
|
247
|
+
}
|
|
248
|
+
delete(account) {
|
|
249
|
+
!this.key || !(account in this.values) || (delete this.values[account], this.persist());
|
|
250
|
+
}
|
|
251
|
+
persist() {
|
|
252
|
+
if (!this.key || !this.salt) throw new SecretStoreLockedError();
|
|
253
|
+
let record = {
|
|
254
|
+
v: 1,
|
|
255
|
+
kdf: { name: "scrypt", N: SCRYPT.N, r: SCRYPT.r, p: SCRYPT.p, salt: this.salt.toString("base64") },
|
|
256
|
+
check: seal(this.key, CHECK_VALUE),
|
|
257
|
+
data: seal(this.key, JSON.stringify(this.values))
|
|
258
|
+
};
|
|
259
|
+
mkdirSync2(dirname(this.filePath), { recursive: !0 });
|
|
260
|
+
let tmp = `${this.filePath}.tmp`;
|
|
261
|
+
writeFileSync2(tmp, JSON.stringify(record, null, 2) + `
|
|
262
|
+
`, { mode: 384 }), renameSync(tmp, this.filePath);
|
|
263
|
+
try {
|
|
264
|
+
chmodSync2(this.filePath, 384);
|
|
265
|
+
} catch {
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
export {
|
|
271
|
+
LOCAL_PROOF_HEADER,
|
|
272
|
+
BEHIND_PROXY_ENV,
|
|
273
|
+
isLoopbackAddress,
|
|
274
|
+
hasProxyHeaders,
|
|
275
|
+
behindProxyFromEnv,
|
|
276
|
+
mintLocalProof,
|
|
277
|
+
noteLocalProofProblem,
|
|
278
|
+
localProofProblem,
|
|
279
|
+
readLocalProof,
|
|
280
|
+
isLocalOnlyRoute,
|
|
281
|
+
isDeviceRefusedRoute,
|
|
282
|
+
localAccessRefusal,
|
|
283
|
+
OWNER_MNEMONIC_ACCOUNT,
|
|
284
|
+
WrongPassphraseError,
|
|
285
|
+
openKeychainBackend,
|
|
286
|
+
probeKeychain,
|
|
287
|
+
MIN_PASSPHRASE_LENGTH,
|
|
288
|
+
FileSecretBackend,
|
|
289
|
+
testSeamsAllowed
|
|
290
|
+
};
|