tenjin-cli 0.1.0-alpha.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/LICENSE +21 -0
- package/NOTICE.md +52 -0
- package/README.md +124 -0
- package/dist/_esm-ZH2J4QEH.js +3737 -0
- package/dist/_esm-ZH2J4QEH.js.map +1 -0
- package/dist/ccip-FXWZDDF5.js +17 -0
- package/dist/ccip-FXWZDDF5.js.map +1 -0
- package/dist/chunk-376LHMK2.js +100 -0
- package/dist/chunk-376LHMK2.js.map +1 -0
- package/dist/chunk-3IMLRUZE.js +44 -0
- package/dist/chunk-3IMLRUZE.js.map +1 -0
- package/dist/chunk-CPUZRZ2A.js +410 -0
- package/dist/chunk-CPUZRZ2A.js.map +1 -0
- package/dist/chunk-F5DZJLU3.js +2058 -0
- package/dist/chunk-F5DZJLU3.js.map +1 -0
- package/dist/chunk-FIYZLITH.js +14577 -0
- package/dist/chunk-FIYZLITH.js.map +1 -0
- package/dist/chunk-LTTRND4A.js +135 -0
- package/dist/chunk-LTTRND4A.js.map +1 -0
- package/dist/chunk-PAAL45FJ.js +7307 -0
- package/dist/chunk-PAAL45FJ.js.map +1 -0
- package/dist/chunk-QHIEYBLV.js +320 -0
- package/dist/chunk-QHIEYBLV.js.map +1 -0
- package/dist/chunk-SXQQ2ZSR.js +887 -0
- package/dist/chunk-SXQQ2ZSR.js.map +1 -0
- package/dist/chunk-TX5T3LKJ.js +2249 -0
- package/dist/chunk-TX5T3LKJ.js.map +1 -0
- package/dist/chunk-WOHCAMDQ.js +4474 -0
- package/dist/chunk-WOHCAMDQ.js.map +1 -0
- package/dist/chunk-ZPZFPVDN.js +67 -0
- package/dist/chunk-ZPZFPVDN.js.map +1 -0
- package/dist/cli-LMHGCZ5S.js +3763 -0
- package/dist/cli-LMHGCZ5S.js.map +1 -0
- package/dist/config-XVXZ3V2Q.js +206 -0
- package/dist/config-XVXZ3V2Q.js.map +1 -0
- package/dist/doctor-MVLZRVPU.js +338 -0
- package/dist/doctor-MVLZRVPU.js.map +1 -0
- package/dist/index.js +26 -0
- package/dist/index.js.map +1 -0
- package/dist/mine.wasm-GQECMSGN.js +11 -0
- package/dist/mine.wasm-GQECMSGN.js.map +1 -0
- package/dist/secp256k1-35YNNB6F.js +18 -0
- package/dist/secp256k1-35YNNB6F.js.map +1 -0
- package/dist/usdc-OQUOFF6R.js +18 -0
- package/dist/usdc-OQUOFF6R.js.map +1 -0
- package/dist/wallet-NRKWLKHX.js +153 -0
- package/dist/wallet-NRKWLKHX.js.map +1 -0
- package/dist/wallet-QUWK2PA4.js +22 -0
- package/dist/wallet-QUWK2PA4.js.map +1 -0
- package/package.json +63 -0
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/lib/atomic-json.ts
|
|
4
|
+
import { chmod, link, mkdir, open, rename, rm, writeFile } from "fs/promises";
|
|
5
|
+
import { randomBytes } from "crypto";
|
|
6
|
+
import { basename, dirname, join } from "path";
|
|
7
|
+
var isWindows = process.platform === "win32";
|
|
8
|
+
async function writeFileAtomic(targetPath, data, opts = {}) {
|
|
9
|
+
const dir = dirname(targetPath);
|
|
10
|
+
const fileMode = opts.mode ?? 420;
|
|
11
|
+
const dirMode = opts.dirMode ?? 493;
|
|
12
|
+
await mkdir(dir, { recursive: true, ...isWindows ? {} : { mode: dirMode } });
|
|
13
|
+
const tmpPath = join(dir, `.${basename(targetPath)}.${randomBytes(6).toString("hex")}.tmp`);
|
|
14
|
+
try {
|
|
15
|
+
await writeFile(tmpPath, data, isWindows ? void 0 : { mode: fileMode });
|
|
16
|
+
if (!isWindows) await chmod(tmpPath, fileMode);
|
|
17
|
+
await rename(tmpPath, targetPath);
|
|
18
|
+
} catch (err) {
|
|
19
|
+
await rm(tmpPath, { force: true }).catch(() => void 0);
|
|
20
|
+
throw err;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
async function writeFileAtomicExclusive(targetPath, data, opts = {}) {
|
|
24
|
+
const dir = dirname(targetPath);
|
|
25
|
+
const fileMode = opts.mode ?? 420;
|
|
26
|
+
const dirMode = opts.dirMode ?? 493;
|
|
27
|
+
await mkdir(dir, { recursive: true, ...isWindows ? {} : { mode: dirMode } });
|
|
28
|
+
if (isWindows) {
|
|
29
|
+
const handle = await open(targetPath, "wx");
|
|
30
|
+
try {
|
|
31
|
+
await handle.writeFile(data);
|
|
32
|
+
await handle.sync();
|
|
33
|
+
} finally {
|
|
34
|
+
await handle.close();
|
|
35
|
+
}
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
const tmpPath = join(dir, `.${basename(targetPath)}.${randomBytes(6).toString("hex")}.tmp`);
|
|
39
|
+
try {
|
|
40
|
+
const handle = await open(tmpPath, "wx", fileMode);
|
|
41
|
+
try {
|
|
42
|
+
await handle.writeFile(data);
|
|
43
|
+
await handle.chmod(fileMode);
|
|
44
|
+
await handle.sync();
|
|
45
|
+
} finally {
|
|
46
|
+
await handle.close();
|
|
47
|
+
}
|
|
48
|
+
await link(tmpPath, targetPath);
|
|
49
|
+
await fsyncDir(dir);
|
|
50
|
+
} finally {
|
|
51
|
+
await rm(tmpPath, { force: true }).catch(() => void 0);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
async function fsyncDir(dir) {
|
|
55
|
+
const handle = await open(dir, "r");
|
|
56
|
+
try {
|
|
57
|
+
await handle.sync();
|
|
58
|
+
} finally {
|
|
59
|
+
await handle.close();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export {
|
|
64
|
+
writeFileAtomic,
|
|
65
|
+
writeFileAtomicExclusive
|
|
66
|
+
};
|
|
67
|
+
//# sourceMappingURL=chunk-ZPZFPVDN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/atomic-json.ts"],"sourcesContent":["import { chmod, link, mkdir, open, rename, rm, writeFile } from 'node:fs/promises';\nimport { randomBytes } from 'node:crypto';\nimport { basename, dirname, join } from 'node:path';\n\n/** fs modes are no-ops on Windows; the 0600/0700 custody story does not apply. */\nconst isWindows = process.platform === 'win32';\n\nexport interface AtomicWriteOptions {\n /** Mode for the written file (ignored on win32). Default 0o644. */\n mode?: number;\n /** Mode for the parent dir when this call creates it (ignored on win32). Default 0o755. */\n dirMode?: number;\n}\n\n/**\n * Write `data` to `targetPath` atomically: a uniquely-named temp file is created\n * in the SAME directory (so the rename is atomic — a cross-filesystem rename is\n * not), given the final mode at open time, then renamed over the target. A\n * reader therefore sees either the old file or the fully-written new one, never\n * a partial write.\n *\n * The temp file is born with the caller's `mode` (0o600 for a wallet key) so the\n * bytes are never written through a world-readable descriptor; the follow-up\n * chmod only makes the mode exact under an unusual umask and only ever touches\n * the temp path, so the live target still appears atomically at its final mode.\n */\nexport async function writeFileAtomic(\n targetPath: string,\n data: string,\n opts: AtomicWriteOptions = {},\n): Promise<void> {\n const dir = dirname(targetPath);\n const fileMode = opts.mode ?? 0o644;\n const dirMode = opts.dirMode ?? 0o755;\n\n await mkdir(dir, { recursive: true, ...(isWindows ? {} : { mode: dirMode }) });\n\n const tmpPath = join(dir, `.${basename(targetPath)}.${randomBytes(6).toString('hex')}.tmp`);\n try {\n await writeFile(tmpPath, data, isWindows ? undefined : { mode: fileMode });\n if (!isWindows) await chmod(tmpPath, fileMode);\n await rename(tmpPath, targetPath);\n } catch (err) {\n await rm(tmpPath, { force: true }).catch(() => undefined);\n throw err;\n }\n}\n\n/**\n * Like {@link writeFileAtomic} but NO-CLOBBER and crash-durable: the commit fails\n * with `EEXIST` when `targetPath` already exists instead of replacing it, and the\n * new entry is fsynced before returning. This is what a wallet key needs — two\n * concurrent `create`/`import` runs must not both \"succeed\" and silently lose one\n * key; the loser gets a distinguishable EEXIST the wallet layer maps to\n * WALLET_EXISTS.\n *\n * The temp file is fsynced, then `link()` commits it — link is atomic and throws\n * EEXIST if the target already exists, so the check-then-write race is closed at\n * the filesystem, not by an earlier stat. The parent dir is then fsynced so the\n * new entry survives a crash. On win32, link semantics differ and a directory\n * cannot be fsynced, so we fall back to an exclusive `wx` open (still atomic\n * create-or-EEXIST, just not crash-durable — win32 has no 0600 custody story to\n * protect anyway).\n */\nexport async function writeFileAtomicExclusive(\n targetPath: string,\n data: string,\n opts: AtomicWriteOptions = {},\n): Promise<void> {\n const dir = dirname(targetPath);\n const fileMode = opts.mode ?? 0o644;\n const dirMode = opts.dirMode ?? 0o755;\n\n await mkdir(dir, { recursive: true, ...(isWindows ? {} : { mode: dirMode }) });\n\n if (isWindows) {\n const handle = await open(targetPath, 'wx');\n try {\n await handle.writeFile(data);\n await handle.sync();\n } finally {\n await handle.close();\n }\n return;\n }\n\n const tmpPath = join(dir, `.${basename(targetPath)}.${randomBytes(6).toString('hex')}.tmp`);\n try {\n const handle = await open(tmpPath, 'wx', fileMode);\n try {\n await handle.writeFile(data);\n await handle.chmod(fileMode); // exact mode even under an unusual umask\n await handle.sync();\n } finally {\n await handle.close();\n }\n await link(tmpPath, targetPath); // atomic; throws EEXIST when the target exists\n await fsyncDir(dir);\n } finally {\n // On success the temp is now a redundant link to the target; on EEXIST it is\n // the orphaned write. Either way remove it before returning/throwing.\n await rm(tmpPath, { force: true }).catch(() => undefined);\n }\n}\n\n/** fsync a directory so a freshly linked entry is durable. Never called on win32. */\nasync function fsyncDir(dir: string): Promise<void> {\n const handle = await open(dir, 'r');\n try {\n await handle.sync();\n } finally {\n await handle.close();\n }\n}\n"],"mappings":";;;AAAA,SAAS,OAAO,MAAM,OAAO,MAAM,QAAQ,IAAI,iBAAiB;AAChE,SAAS,mBAAmB;AAC5B,SAAS,UAAU,SAAS,YAAY;AAGxC,IAAM,YAAY,QAAQ,aAAa;AAqBvC,eAAsB,gBACpB,YACA,MACA,OAA2B,CAAC,GACb;AACf,QAAM,MAAM,QAAQ,UAAU;AAC9B,QAAM,WAAW,KAAK,QAAQ;AAC9B,QAAM,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