tenjin-cli 0.1.0-alpha.3 → 0.1.0-alpha.31
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/NOTICE.md +54 -7
- package/README.md +100 -266
- package/dist/{_esm-FEASBWRP.js → _esm-MEXZI5DL.js} +9 -10
- package/dist/alive-J64H46HI.js +31 -0
- package/dist/{ccip-NQXCEK2U.js → ccip-7RMRLAGV.js} +4 -4
- package/dist/{ccip-XR5NE5QK.js → ccip-NLCSCHKI.js} +5 -5
- package/dist/chunk-27EPWVOY.js +108 -0
- package/dist/chunk-27EPWVOY.js.map +1 -0
- package/dist/chunk-2SNUOHAT.js +75 -0
- package/dist/chunk-2SNUOHAT.js.map +1 -0
- package/dist/{chunk-Z6MFJV5Z.js → chunk-2XLC3AEX.js} +857 -504
- package/dist/chunk-2XLC3AEX.js.map +1 -0
- package/dist/chunk-3623BLPV.js +184 -0
- package/dist/chunk-3623BLPV.js.map +1 -0
- package/dist/chunk-3UCIG4TG.js +65 -0
- package/dist/chunk-3UCIG4TG.js.map +1 -0
- package/dist/chunk-4ZZO6ULA.js +151 -0
- package/dist/chunk-4ZZO6ULA.js.map +1 -0
- package/dist/chunk-5C32RLTA.js +115 -0
- package/dist/chunk-5C32RLTA.js.map +1 -0
- package/dist/{chunk-ZMHYXMO6.js → chunk-5IEP5EGE.js} +3 -3
- package/dist/chunk-5K5W4S66.js +105 -0
- package/dist/chunk-5K5W4S66.js.map +1 -0
- package/dist/chunk-5MARFNSB.js +2018 -0
- package/dist/chunk-5MARFNSB.js.map +1 -0
- package/dist/{chunk-CYOF7ROH.js → chunk-6E5R45ZO.js} +3 -3
- package/dist/chunk-77TCKDEC.js +1987 -0
- package/dist/chunk-77TCKDEC.js.map +1 -0
- package/dist/chunk-7EKYXMUO.js +7536 -0
- package/dist/chunk-7EKYXMUO.js.map +1 -0
- package/dist/chunk-7Q5FDF65.js +159 -0
- package/dist/chunk-7Q5FDF65.js.map +1 -0
- package/dist/chunk-7QKHZQKW.js +1680 -0
- package/dist/chunk-7QKHZQKW.js.map +1 -0
- package/dist/{chunk-MUBUQVC3.js → chunk-7WEQQJLG.js} +6 -5
- package/dist/{chunk-MUBUQVC3.js.map → chunk-7WEQQJLG.js.map} +1 -1
- package/dist/chunk-7WU4OPLP.js +244 -0
- package/dist/chunk-7WU4OPLP.js.map +1 -0
- package/dist/chunk-7ZRL2LBQ.js +192 -0
- package/dist/chunk-7ZRL2LBQ.js.map +1 -0
- package/dist/chunk-A36LQPHV.js +29 -0
- package/dist/chunk-A36LQPHV.js.map +1 -0
- package/dist/chunk-AGZ7PJKY.js +326 -0
- package/dist/chunk-AGZ7PJKY.js.map +1 -0
- package/dist/chunk-AKWGE6JQ.js +49 -0
- package/dist/chunk-AKWGE6JQ.js.map +1 -0
- package/dist/chunk-B7HUUJOK.js +29 -0
- package/dist/chunk-B7HUUJOK.js.map +1 -0
- package/dist/{chunk-S3IGX57D.js → chunk-BL3332HQ.js} +290 -7361
- package/dist/chunk-BL3332HQ.js.map +1 -0
- package/dist/{chunk-5CLSD5YN.js → chunk-BPMWXTFX.js} +2 -2
- package/dist/chunk-D65GNPS3.js +12708 -0
- package/dist/chunk-D65GNPS3.js.map +1 -0
- package/dist/chunk-DOQGNFHM.js +121 -0
- package/dist/chunk-DOQGNFHM.js.map +1 -0
- package/dist/{chunk-YALGASEU.js → chunk-EGELTSPU.js} +2 -2
- package/dist/chunk-FW75G2W4.js +406 -0
- package/dist/chunk-FW75G2W4.js.map +1 -0
- package/dist/chunk-GA7JETVM.js +150 -0
- package/dist/chunk-GA7JETVM.js.map +1 -0
- package/dist/chunk-I3EQFHCD.js +175 -0
- package/dist/chunk-I3EQFHCD.js.map +1 -0
- package/dist/chunk-JKKAIPTU.js +108 -0
- package/dist/chunk-JKKAIPTU.js.map +1 -0
- package/dist/{chunk-QVX5MWJZ.js → chunk-JRGFKVAZ.js} +2 -2
- package/dist/{chunk-NCE5NSN6.js → chunk-K3I7C2MO.js} +142 -12
- package/dist/chunk-K3I7C2MO.js.map +1 -0
- package/dist/chunk-K72RURN3.js +239 -0
- package/dist/chunk-K72RURN3.js.map +1 -0
- package/dist/{chunk-HIVZG55D.js → chunk-KG3D7FIF.js} +2 -2
- package/dist/chunk-KOGZDMHO.js +21 -0
- package/dist/chunk-KOGZDMHO.js.map +1 -0
- package/dist/chunk-KXQ4UIP7.js +228 -0
- package/dist/chunk-KXQ4UIP7.js.map +1 -0
- package/dist/chunk-KXVP2VKA.js +194 -0
- package/dist/chunk-KXVP2VKA.js.map +1 -0
- package/dist/chunk-LEFIX6RS.js +100 -0
- package/dist/chunk-LEFIX6RS.js.map +1 -0
- package/dist/chunk-LHHMV4GU.js +27 -0
- package/dist/chunk-LHHMV4GU.js.map +1 -0
- package/dist/{chunk-YBMMV4Y4.js → chunk-MEFB5KHA.js} +13 -5
- package/dist/chunk-MEFB5KHA.js.map +1 -0
- package/dist/chunk-MNXS2U45.js +1768 -0
- package/dist/chunk-MNXS2U45.js.map +1 -0
- package/dist/{chunk-UGX7YPX2.js → chunk-NEFNKLBE.js} +9 -11
- package/dist/{chunk-UGX7YPX2.js.map → chunk-NEFNKLBE.js.map} +1 -1
- package/dist/chunk-OHRR5OYM.js +63 -0
- package/dist/chunk-OHRR5OYM.js.map +1 -0
- package/dist/chunk-ORWL5BSN.js +269 -0
- package/dist/chunk-ORWL5BSN.js.map +1 -0
- package/dist/chunk-P4NH7OUK.js +398 -0
- package/dist/chunk-P4NH7OUK.js.map +1 -0
- package/dist/{chunk-ZABPQJ3M.js → chunk-POUWHWID.js} +2 -2
- package/dist/chunk-QSCPK4F5.js +145 -0
- package/dist/chunk-QSCPK4F5.js.map +1 -0
- package/dist/chunk-QXP3Z3JN.js +131 -0
- package/dist/chunk-QXP3Z3JN.js.map +1 -0
- package/dist/{chunk-XJIW7USF.js → chunk-R5LCN54M.js} +118 -9
- package/dist/chunk-R5LCN54M.js.map +1 -0
- package/dist/chunk-S4SAZ7OD.js +30 -0
- package/dist/chunk-S4SAZ7OD.js.map +1 -0
- package/dist/chunk-SJLTEINJ.js +117 -0
- package/dist/chunk-SJLTEINJ.js.map +1 -0
- package/dist/{chunk-RRN3YTK7.js → chunk-TTNESUPQ.js} +3 -3
- package/dist/chunk-UKY4CHNC.js +498 -0
- package/dist/chunk-UKY4CHNC.js.map +1 -0
- package/dist/chunk-UQUOVWBG.js +114 -0
- package/dist/chunk-UQUOVWBG.js.map +1 -0
- package/dist/chunk-V6BSF6OC.js +260 -0
- package/dist/chunk-V6BSF6OC.js.map +1 -0
- package/dist/chunk-WJXLQXJY.js +43 -0
- package/dist/chunk-WJXLQXJY.js.map +1 -0
- package/dist/chunk-WK7F3B2E.js +114 -0
- package/dist/chunk-WK7F3B2E.js.map +1 -0
- package/dist/chunk-XKESD27X.js +10 -0
- package/dist/chunk-XKESD27X.js.map +1 -0
- package/dist/chunk-XQJXNMSB.js +23 -0
- package/dist/chunk-XQJXNMSB.js.map +1 -0
- package/dist/{chunk-HSDCI7OV.js → chunk-XZKD7DIF.js} +3 -3
- package/dist/chunk-Y527D4TV.js +56 -0
- package/dist/chunk-Y527D4TV.js.map +1 -0
- package/dist/chunk-YFPY4ONH.js +127 -0
- package/dist/chunk-YFPY4ONH.js.map +1 -0
- package/dist/{chunk-OYMYCW7J.js → chunk-YVFXE7RR.js} +606 -97
- package/dist/chunk-YVFXE7RR.js.map +1 -0
- package/dist/clack-EZ7TDWQU.js +19 -0
- package/dist/claude-cli-2YKABJJZ.js +31 -0
- package/dist/{cli-SBXI5AMS.js → cli-D5OE3URZ.js} +458 -218
- package/dist/cli-D5OE3URZ.js.map +1 -0
- package/dist/codex-event-PPNVRRDH.js +16 -0
- package/dist/codex-host-2RJOJW2B.js +28 -0
- package/dist/codex-install-UUZ6QMBQ.js +221 -0
- package/dist/codex-install-UUZ6QMBQ.js.map +1 -0
- package/dist/config-ZD4OB2DO.js +51 -0
- package/dist/dist-3LOO6M4U.js +2842 -0
- package/dist/dist-3LOO6M4U.js.map +1 -0
- package/dist/doctor-KBR34Q4B.js +601 -0
- package/dist/doctor-KBR34Q4B.js.map +1 -0
- package/dist/env-proxy-XL4P73MZ.js +15 -0
- package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js → ethersCompat-Df4a6QIZ-THAVUGIJ.js} +5 -5
- package/dist/ethersCompat-Df4a6QIZ-THAVUGIJ.js.map +1 -0
- package/dist/fund-5ITKQGYF.js +372 -0
- package/dist/fund-5ITKQGYF.js.map +1 -0
- package/dist/hook-command-4TYCHHRL.js +39 -0
- package/dist/hook-command-4TYCHHRL.js.map +1 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +19 -0
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +15 -0
- package/dist/hosts/claude/tenjin/.mcp.json +12 -0
- package/dist/hosts/claude/tenjin/hooks/hooks.json +224 -0
- package/dist/hosts/claude/tenjin/hooks/register.tsx +589 -0
- package/dist/hosts/claude/tenjin/types/index.d.ts +41 -0
- package/dist/hosts/codex/.agents/plugins/marketplace.json +20 -0
- package/dist/hosts/codex/tenjin/.codex-plugin/plugin.json +16 -0
- package/dist/hosts/codex/tenjin/.mcp.json +12 -0
- package/dist/hosts/codex/tenjin/hooks/hooks.json +52 -0
- package/dist/hosts-FWZOV26H.js +216 -0
- package/dist/hosts-FWZOV26H.js.map +1 -0
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/install-XWGE4Q7L.js +77 -0
- package/dist/install-XWGE4Q7L.js.map +1 -0
- package/dist/install-identity-K7EJIQFP.js +30 -0
- package/dist/install-identity-K7EJIQFP.js.map +1 -0
- package/dist/install-wallet-XQ6XFZV4.js +117 -0
- package/dist/install-wallet-XQ6XFZV4.js.map +1 -0
- package/dist/mcp-3LIJSSJB.js +13553 -0
- package/dist/mcp-3LIJSSJB.js.map +1 -0
- package/dist/package-ZKQFDWLE.js +37 -0
- package/dist/package-ZKQFDWLE.js.map +1 -0
- package/dist/paths-POPTXJO6.js +61 -0
- package/dist/paths-POPTXJO6.js.map +1 -0
- package/dist/pay-WHBERZ3W.js +55 -0
- package/dist/pay-WHBERZ3W.js.map +1 -0
- package/dist/payments-KVICEKD2.js +110 -0
- package/dist/payments-KVICEKD2.js.map +1 -0
- package/dist/plugin-registration-5TIA564H.js +54 -0
- package/dist/plugin-registration-5TIA564H.js.map +1 -0
- package/dist/redact-6W23GGJC.js +15 -0
- package/dist/redact-6W23GGJC.js.map +1 -0
- package/dist/{secp256k1-N3ZHU7LB.js → secp256k1-ZZZT2CAX.js} +3 -3
- package/dist/secp256k1-ZZZT2CAX.js.map +1 -0
- package/dist/send-7G7Y7DLN.js +228 -0
- package/dist/send-7G7Y7DLN.js.map +1 -0
- package/dist/status-OF7RH5HM.js +120 -0
- package/dist/status-OF7RH5HM.js.map +1 -0
- package/dist/status-line-XOUE6MPL.js +90 -0
- package/dist/status-line-XOUE6MPL.js.map +1 -0
- package/dist/uninstall-JXUAFNDB.js +158 -0
- package/dist/uninstall-JXUAFNDB.js.map +1 -0
- package/dist/update-ZKUERSO2.js +44 -0
- package/dist/update-ZKUERSO2.js.map +1 -0
- package/dist/usdc-OGOGEHV2.js +40 -0
- package/dist/usdc-OGOGEHV2.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js → viemAdapter-By13KInL-S3DA7DFW.js} +5 -5
- package/dist/viemAdapter-By13KInL-S3DA7DFW.js.map +1 -0
- package/dist/wallet-2HA6W4R4.js +43 -0
- package/dist/wallet-2HA6W4R4.js.map +1 -0
- package/dist/wallet-kdf-worker.mjs +980 -0
- package/docs/agent-permissions.md +196 -0
- package/docs/safety-model.md +59 -0
- package/docs/troubleshooting.md +13 -0
- package/package.json +28 -19
- package/LICENSE +0 -21
- package/dist/buy-EE6SEXP6.js +0 -1598
- package/dist/buy-EE6SEXP6.js.map +0 -1
- package/dist/candidate-ERMSYYQZ.js +0 -127
- package/dist/candidate-ERMSYYQZ.js.map +0 -1
- package/dist/chunk-3OV7E5G5.js +0 -18
- package/dist/chunk-3OV7E5G5.js.map +0 -1
- package/dist/chunk-4ONXEEQL.js +0 -152
- package/dist/chunk-4ONXEEQL.js.map +0 -1
- package/dist/chunk-662MSGZB.js +0 -286
- package/dist/chunk-662MSGZB.js.map +0 -1
- package/dist/chunk-7KUW4MJD.js +0 -59
- package/dist/chunk-7KUW4MJD.js.map +0 -1
- package/dist/chunk-AWPAWHNX.js +0 -333
- package/dist/chunk-AWPAWHNX.js.map +0 -1
- package/dist/chunk-DXTQ3CSI.js +0 -171
- package/dist/chunk-DXTQ3CSI.js.map +0 -1
- package/dist/chunk-ESPNTPQ2.js +0 -207
- package/dist/chunk-ESPNTPQ2.js.map +0 -1
- package/dist/chunk-FJPLRISB.js +0 -79
- package/dist/chunk-FJPLRISB.js.map +0 -1
- package/dist/chunk-GO75V3NZ.js +0 -160
- package/dist/chunk-GO75V3NZ.js.map +0 -1
- package/dist/chunk-JPHG2JW3.js +0 -96
- package/dist/chunk-JPHG2JW3.js.map +0 -1
- package/dist/chunk-NCE5NSN6.js.map +0 -1
- package/dist/chunk-OYMYCW7J.js.map +0 -1
- package/dist/chunk-RY4XKNV3.js +0 -140
- package/dist/chunk-RY4XKNV3.js.map +0 -1
- package/dist/chunk-S3IGX57D.js.map +0 -1
- package/dist/chunk-TLCMMYLY.js +0 -126
- package/dist/chunk-TLCMMYLY.js.map +0 -1
- package/dist/chunk-UO22YNY4.js +0 -69
- package/dist/chunk-UO22YNY4.js.map +0 -1
- package/dist/chunk-XHC6FCGZ.js +0 -261
- package/dist/chunk-XHC6FCGZ.js.map +0 -1
- package/dist/chunk-XJIW7USF.js.map +0 -1
- package/dist/chunk-YBMMV4Y4.js.map +0 -1
- package/dist/chunk-YN5SHIXQ.js +0 -126
- package/dist/chunk-YN5SHIXQ.js.map +0 -1
- package/dist/chunk-Z52RA3NC.js +0 -137
- package/dist/chunk-Z52RA3NC.js.map +0 -1
- package/dist/chunk-Z6MFJV5Z.js.map +0 -1
- package/dist/cli-SBXI5AMS.js.map +0 -1
- package/dist/config-VELDKLHY.js +0 -21
- package/dist/doctor-T3KWNNP2.js +0 -20
- package/dist/inspect-LMKOXE4Y.js +0 -96
- package/dist/inspect-LMKOXE4Y.js.map +0 -1
- package/dist/install-LEX3ENQ6.js +0 -387
- package/dist/install-LEX3ENQ6.js.map +0 -1
- package/dist/lookup-ZPN2Q67N.js +0 -129
- package/dist/lookup-ZPN2Q67N.js.map +0 -1
- package/dist/outcome-N7TAK6WR.js +0 -66
- package/dist/outcome-N7TAK6WR.js.map +0 -1
- package/dist/publish-BKBQQAW4.js +0 -1478
- package/dist/publish-BKBQQAW4.js.map +0 -1
- package/dist/usdc-JIAJW4SV.js +0 -22
- package/dist/wallet-CWEMYVIH.js +0 -179
- package/dist/wallet-CWEMYVIH.js.map +0 -1
- package/dist/wallet-PA54CRBL.js +0 -30
- package/skills/tenjin/SKILL.md +0 -199
- package/skills/tenjin-publish/SKILL.md +0 -111
- package/skills/tenjin-search/SKILL.md +0 -133
- /package/dist/{_esm-FEASBWRP.js.map → _esm-MEXZI5DL.js.map} +0 -0
- /package/dist/{ccip-NQXCEK2U.js.map → alive-J64H46HI.js.map} +0 -0
- /package/dist/{ccip-XR5NE5QK.js.map → ccip-7RMRLAGV.js.map} +0 -0
- /package/dist/{config-VELDKLHY.js.map → ccip-NLCSCHKI.js.map} +0 -0
- /package/dist/{chunk-ZMHYXMO6.js.map → chunk-5IEP5EGE.js.map} +0 -0
- /package/dist/{chunk-CYOF7ROH.js.map → chunk-6E5R45ZO.js.map} +0 -0
- /package/dist/{chunk-5CLSD5YN.js.map → chunk-BPMWXTFX.js.map} +0 -0
- /package/dist/{chunk-YALGASEU.js.map → chunk-EGELTSPU.js.map} +0 -0
- /package/dist/{chunk-QVX5MWJZ.js.map → chunk-JRGFKVAZ.js.map} +0 -0
- /package/dist/{chunk-HIVZG55D.js.map → chunk-KG3D7FIF.js.map} +0 -0
- /package/dist/{chunk-ZABPQJ3M.js.map → chunk-POUWHWID.js.map} +0 -0
- /package/dist/{chunk-RRN3YTK7.js.map → chunk-TTNESUPQ.js.map} +0 -0
- /package/dist/{chunk-HSDCI7OV.js.map → chunk-XZKD7DIF.js.map} +0 -0
- /package/dist/{doctor-T3KWNNP2.js.map → clack-EZ7TDWQU.js.map} +0 -0
- /package/dist/{ethersCompat-Df4a6QIZ-3YZIAXDK.js.map → claude-cli-2YKABJJZ.js.map} +0 -0
- /package/dist/{secp256k1-N3ZHU7LB.js.map → codex-event-PPNVRRDH.js.map} +0 -0
- /package/dist/{usdc-JIAJW4SV.js.map → codex-host-2RJOJW2B.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-ZZE6UV4Y.js.map → config-ZD4OB2DO.js.map} +0 -0
- /package/dist/{wallet-PA54CRBL.js.map → env-proxy-XL4P73MZ.js.map} +0 -0
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
setTenjinIdentity
|
|
4
|
+
} from "./chunk-AGZ7PJKY.js";
|
|
5
|
+
import {
|
|
6
|
+
hasCode
|
|
7
|
+
} from "./chunk-2I4QTOLB.js";
|
|
8
|
+
import {
|
|
9
|
+
isTeamModeConfig
|
|
10
|
+
} from "./chunk-7WU4OPLP.js";
|
|
11
|
+
import {
|
|
12
|
+
loadRawConfig,
|
|
13
|
+
resolveSettings
|
|
14
|
+
} from "./chunk-YVFXE7RR.js";
|
|
15
|
+
import {
|
|
16
|
+
knownDeploymentOrigins
|
|
17
|
+
} from "./chunk-XQJXNMSB.js";
|
|
18
|
+
import {
|
|
19
|
+
writeFileAtomicExclusive
|
|
20
|
+
} from "./chunk-7WEQQJLG.js";
|
|
21
|
+
import {
|
|
22
|
+
installIdPath
|
|
23
|
+
} from "./chunk-SJLTEINJ.js";
|
|
24
|
+
|
|
25
|
+
// src/lib/install-identity.ts
|
|
26
|
+
import { randomUUID } from "node:crypto";
|
|
27
|
+
import { readFile } from "node:fs/promises";
|
|
28
|
+
var UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
29
|
+
function parseInstallId(raw) {
|
|
30
|
+
const id = raw.trim();
|
|
31
|
+
return UUID_RE.test(id) ? id : void 0;
|
|
32
|
+
}
|
|
33
|
+
async function readOrCreateInstallId(dir) {
|
|
34
|
+
const path = installIdPath(dir);
|
|
35
|
+
try {
|
|
36
|
+
return parseInstallId(await readFile(path, "utf8"));
|
|
37
|
+
} catch (err) {
|
|
38
|
+
if (!hasCode(err, "ENOENT")) return void 0;
|
|
39
|
+
}
|
|
40
|
+
const id = randomUUID();
|
|
41
|
+
try {
|
|
42
|
+
await writeFileAtomicExclusive(path, `${id}
|
|
43
|
+
`, { mode: 384, dirMode: 448 });
|
|
44
|
+
return id;
|
|
45
|
+
} catch (err) {
|
|
46
|
+
if (!hasCode(err, "EEXIST")) return void 0;
|
|
47
|
+
}
|
|
48
|
+
try {
|
|
49
|
+
return parseInstallId(await readFile(path, "utf8"));
|
|
50
|
+
} catch {
|
|
51
|
+
return void 0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function tryOrigin(url) {
|
|
55
|
+
try {
|
|
56
|
+
return new URL(url).origin;
|
|
57
|
+
} catch {
|
|
58
|
+
return void 0;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
function tenjinOrigins(s) {
|
|
62
|
+
const origins = new Set(knownDeploymentOrigins());
|
|
63
|
+
const baseOrigin = tryOrigin(s.baseUrl);
|
|
64
|
+
if (baseOrigin !== void 0 && !s.teamMode) origins.add(baseOrigin);
|
|
65
|
+
return [...origins];
|
|
66
|
+
}
|
|
67
|
+
function identityFor(dir, origins) {
|
|
68
|
+
let install;
|
|
69
|
+
return {
|
|
70
|
+
origins,
|
|
71
|
+
installId: () => install ??= readOrCreateInstallId(dir)
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
var baseUrlFlag;
|
|
75
|
+
function noteBaseUrlFlag(flag) {
|
|
76
|
+
baseUrlFlag = flag;
|
|
77
|
+
}
|
|
78
|
+
function enableCliIdentity(dir, env = process.env) {
|
|
79
|
+
let origins;
|
|
80
|
+
setTenjinIdentity(
|
|
81
|
+
identityFor(dir, () => {
|
|
82
|
+
origins ??= (async () => {
|
|
83
|
+
const config = await loadRawConfig(dir);
|
|
84
|
+
const s = resolveSettings({ config, flags: { baseUrl: baseUrlFlag }, env });
|
|
85
|
+
return tenjinOrigins({
|
|
86
|
+
baseUrl: s.baseUrl.value,
|
|
87
|
+
teamMode: isTeamModeConfig(config)
|
|
88
|
+
});
|
|
89
|
+
})();
|
|
90
|
+
return origins;
|
|
91
|
+
})
|
|
92
|
+
);
|
|
93
|
+
}
|
|
94
|
+
function enableDaemonIdentity(dir, config) {
|
|
95
|
+
setTenjinIdentity(
|
|
96
|
+
identityFor(dir, async () => {
|
|
97
|
+
const c = config();
|
|
98
|
+
return tenjinOrigins({
|
|
99
|
+
baseUrl: c.baseUrl,
|
|
100
|
+
teamMode: isTeamModeConfig(c)
|
|
101
|
+
});
|
|
102
|
+
})
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export {
|
|
107
|
+
readOrCreateInstallId,
|
|
108
|
+
tenjinOrigins,
|
|
109
|
+
identityFor,
|
|
110
|
+
noteBaseUrlFlag,
|
|
111
|
+
enableCliIdentity,
|
|
112
|
+
enableDaemonIdentity
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=chunk-UQUOVWBG.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/install-identity.ts"],"sourcesContent":["import { randomUUID } from 'node:crypto';\nimport { readFile } from 'node:fs/promises';\nimport { writeFileAtomicExclusive } from './atomic-json';\nimport { loadRawConfig, resolveSettings } from './config';\nimport { hasCode } from './errno';\nimport { setTenjinIdentity, type TenjinIdentity } from './http';\nimport { installIdPath } from './paths';\nimport { knownDeploymentOrigins } from './production-origin';\nimport { isTeamModeConfig } from './settings';\n\n/**\n * The install id the transport attaches to Tenjin-bound requests (see\n * `TenjinIdentity` in lib/http), and the rule for which origins are Tenjin's.\n *\n * Nothing here may fail a request: every read that goes wrong is an absent\n * header. There is no opt-out for alpha; the id is random, anonymous, and not a\n * credential.\n */\n\nconst UUID_RE = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;\n\nfunction parseInstallId(raw: string): string | undefined {\n const id = raw.trim();\n return UUID_RE.test(id) ? id : undefined;\n}\n\n/**\n * This data dir's install id, minted on first need. Created no-clobber, so two\n * processes racing on a first run agree on the winner's id rather than each\n * keeping its own. A file that exists but does not hold a UUID is left alone and\n * sends nothing: overwriting it would be a new id for the same install.\n */\nexport async function readOrCreateInstallId(dir: string): Promise<string | undefined> {\n const path = installIdPath(dir);\n try {\n return parseInstallId(await readFile(path, 'utf8'));\n } catch (err) {\n if (!hasCode(err, 'ENOENT')) return undefined;\n }\n const id = randomUUID();\n try {\n await writeFileAtomicExclusive(path, `${id}\\n`, { mode: 0o600, dirMode: 0o700 });\n return id;\n } catch (err) {\n if (!hasCode(err, 'EEXIST')) return undefined;\n }\n try {\n return parseInstallId(await readFile(path, 'utf8'));\n } catch {\n return undefined;\n }\n}\n\nfunction tryOrigin(url: string): string | undefined {\n try {\n return new URL(url).origin;\n } catch {\n return undefined;\n }\n}\n\n/**\n * The origins that get the header: Tenjin's own deployments and the base URL\n * this run is pointed at, overrides included (a local dev server is Tenjin too).\n * Not `publicShelfUrl`: its default is already one of Tenjin's deployments, and\n * a custom one may be a host Tenjin does not run.\n *\n * NOT a team shelf. In team mode `baseUrl` is the team's own deployment, which\n * Tenjin does not operate, so on a team machine the base URL is left out unless\n * it is one of Tenjin's own origins anyway. `isTeamModeConfig` reads the file,\n * so a `--base-url` on one run cannot switch that exclusion off.\n */\nexport function tenjinOrigins(s: { baseUrl: string; teamMode: boolean }): string[] {\n const origins = new Set(knownDeploymentOrigins());\n const baseOrigin = tryOrigin(s.baseUrl);\n if (baseOrigin !== undefined && !s.teamMode) origins.add(baseOrigin);\n return [...origins];\n}\n\n/** An identity for one data dir. The install id is read once per process. */\nexport function identityFor(\n dir: string,\n origins: () => Promise<readonly string[]>,\n): TenjinIdentity {\n let install: Promise<string | undefined> | undefined;\n return {\n origins,\n installId: () => (install ??= readOrCreateInstallId(dir)),\n };\n}\n\n/**\n * The run's `--base-url`, recorded by the CLI once it has parsed the global\n * flags. The origins are resolved on the first request, which comes after that.\n */\nlet baseUrlFlag: string | undefined;\n\nexport function noteBaseUrlFlag(flag: string | undefined): void {\n baseUrlFlag = flag;\n}\n\n/**\n * Turn the header on for this CLI process. Called from the entry only, never\n * from `main`, so in-process tests of the command tree never mint an id.\n */\nexport function enableCliIdentity(dir: string, env: NodeJS.ProcessEnv = process.env): void {\n let origins: Promise<readonly string[]> | undefined;\n setTenjinIdentity(\n identityFor(dir, () => {\n origins ??= (async () => {\n const config = await loadRawConfig(dir);\n const s = resolveSettings({ config, flags: { baseUrl: baseUrlFlag }, env });\n return tenjinOrigins({\n baseUrl: s.baseUrl.value,\n teamMode: isTeamModeConfig(config),\n });\n })();\n return origins;\n }),\n );\n}\n\n/**\n * Turn the header on for the loop daemon. No flag or env layer, like the rest\n * of the daemon's config, and re-read per request because the daemon reloads\n * config.json when it changes.\n */\nexport function enableDaemonIdentity(\n dir: string,\n config: () => { baseUrl: string; publicShelfUrl: string; shelfBypassSecret: string },\n): void {\n setTenjinIdentity(\n identityFor(dir, async () => {\n const c = config();\n return tenjinOrigins({\n baseUrl: c.baseUrl,\n teamMode: isTeamModeConfig(c),\n });\n }),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,kBAAkB;AAC3B,SAAS,gBAAgB;AAkBzB,IAAM,UAAU;AAEhB,SAAS,eAAe,KAAiC;AACvD,QAAM,KAAK,IA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c,GAAG;AACtC,cAAM,IAAI,gBAAgB,EAAE,QAAQ,OAAO,EAAE,SAAS,YAAY,GAAG,IAAI,CAAC;AAC1E,eAAO,cAAc;AAAA,UACnB,SAAS,EAAE,QAAQ;AAAA,UACnB,UAAU,iBAAiB,MAAM;AAAA,QACnC,CAAC;AAAA,MACH,GAAG;AACH,aAAO;AAAA,IACT,CAAC;AAAA,EACH;AACF;AAOO,SAAS,qBACd,KACA,QACM;AACN;AAAA,IACE,YAAY,KAAK,YAAY;AAC3B,YAAM,IAAI,OAAO;AACjB,aAAO,cAAc;AAAA,QACnB,SAAS,EAAE;AAAA,QACX,UAAU,iBAAiB,CAAC;AAAA,MAC9B,CAAC;AAAA,IACH,CAAC;AAAA,EACH;AACF;","names":[]}
|
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
channelCredit
|
|
4
|
+
} from "./chunk-B7HUUJOK.js";
|
|
5
|
+
import {
|
|
6
|
+
addressQrLines
|
|
7
|
+
} from "./chunk-ORWL5BSN.js";
|
|
8
|
+
import {
|
|
9
|
+
commitLocalWallet,
|
|
10
|
+
createLocalWallet,
|
|
11
|
+
describeWallet,
|
|
12
|
+
parkOutgoingWallet,
|
|
13
|
+
prepareLocalWallet,
|
|
14
|
+
resolvePassphraseForCreate,
|
|
15
|
+
resolveWalletProvider,
|
|
16
|
+
restoreParkedWallet,
|
|
17
|
+
verifyAndPreserveOutgoingWallet,
|
|
18
|
+
walletExistsError,
|
|
19
|
+
walletFileExists
|
|
20
|
+
} from "./chunk-2XLC3AEX.js";
|
|
21
|
+
import {
|
|
22
|
+
getUsdcBalance
|
|
23
|
+
} from "./chunk-R5LCN54M.js";
|
|
24
|
+
import {
|
|
25
|
+
SUGGESTED_FUND_USD
|
|
26
|
+
} from "./chunk-4ZZO6ULA.js";
|
|
27
|
+
import {
|
|
28
|
+
LockTimeoutError,
|
|
29
|
+
withFileLock
|
|
30
|
+
} from "./chunk-MEFB5KHA.js";
|
|
31
|
+
import {
|
|
32
|
+
toMoney
|
|
33
|
+
} from "./chunk-Y527D4TV.js";
|
|
34
|
+
import {
|
|
35
|
+
loadRawConfig,
|
|
36
|
+
resolveSettings
|
|
37
|
+
} from "./chunk-YVFXE7RR.js";
|
|
38
|
+
import {
|
|
39
|
+
CliError
|
|
40
|
+
} from "./chunk-3UCIG4TG.js";
|
|
41
|
+
import {
|
|
42
|
+
walletPath
|
|
43
|
+
} from "./chunk-SJLTEINJ.js";
|
|
44
|
+
|
|
45
|
+
// src/commands/wallet.ts
|
|
46
|
+
import { mkdir } from "node:fs/promises";
|
|
47
|
+
import { join } from "node:path";
|
|
48
|
+
var FUNDING_LINE = `Fund it with \`tenjin wallet fund ${SUGGESTED_FUND_USD}\`, or send USDC on Base.`;
|
|
49
|
+
var KEY_STORAGE = "encrypted (keystore v3, scrypt)";
|
|
50
|
+
var isWindows = process.platform === "win32";
|
|
51
|
+
async function runWalletCreate(ctx, opts = {}) {
|
|
52
|
+
const {
|
|
53
|
+
address,
|
|
54
|
+
walletPath: path,
|
|
55
|
+
source,
|
|
56
|
+
replaced
|
|
57
|
+
} = await createWalletLocked(ctx.dataDir, opts);
|
|
58
|
+
const warnings = custodyWarnings();
|
|
59
|
+
return {
|
|
60
|
+
data: {
|
|
61
|
+
address,
|
|
62
|
+
walletPath: path,
|
|
63
|
+
provider: "local",
|
|
64
|
+
policyEnforcement: "client-only",
|
|
65
|
+
keyStorage: KEY_STORAGE,
|
|
66
|
+
passphraseSource: source,
|
|
67
|
+
...replaced !== void 0 ? {
|
|
68
|
+
replaced: {
|
|
69
|
+
address: replaced.address,
|
|
70
|
+
archivedWalletPath: replaced.archivedPath,
|
|
71
|
+
passphrasePreserved: replaced.passphraseLocation,
|
|
72
|
+
...replaced.unarchivedReason !== void 0 ? { unarchivedReason: replaced.unarchivedReason } : {}
|
|
73
|
+
}
|
|
74
|
+
} : {},
|
|
75
|
+
warnings
|
|
76
|
+
},
|
|
77
|
+
humanLines: [
|
|
78
|
+
`Wallet created: ${address}`,
|
|
79
|
+
`Key stored ${KEY_STORAGE}.`,
|
|
80
|
+
passphraseNote(source, address),
|
|
81
|
+
...replaced !== void 0 ? replacedNote(replaced, path) : [],
|
|
82
|
+
FUNDING_LINE,
|
|
83
|
+
...warnings
|
|
84
|
+
]
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function replacedNote(replaced, activeWalletPath) {
|
|
88
|
+
const passphraseLine = replaced.passphraseLocation === "store" ? `its passphrase is preserved in the OS credential store (service tenjin-cli, account ${replaced.account}).` : replaced.passphraseLocation === "env" ? "its passphrase is TENJIN_WALLET_PASSPHRASE \u2014 keep that value." : replaced.unarchivedReason === "rejected-characters" ? "its passphrase was NOT archived: the macOS keychain writer only stores machine-generated (base64url) passphrases, and this typed one contains other characters. Keep it yourself, or set TENJIN_WALLET_PASSPHRASE to it." : replaced.unarchivedReason === "no-store" ? "its passphrase was NOT archived: this platform has no OS credential store. It exists only where you keep it." : "its passphrase was NOT archived: the OS credential store write failed. It exists only where you keep it.";
|
|
89
|
+
return [
|
|
90
|
+
`Previous wallet archived: ${replaced.address} still holds any funds sent to it.`,
|
|
91
|
+
`Its keystore was moved to ${replaced.archivedPath}; ${passphraseLine}`,
|
|
92
|
+
`To make it the active wallet again later: move the current ${activeWalletPath} aside first, then \`mv ${replaced.archivedPath} ${activeWalletPath}\`.`
|
|
93
|
+
];
|
|
94
|
+
}
|
|
95
|
+
async function createWalletLocked(dir, opts) {
|
|
96
|
+
await mkdir(dir, { recursive: true, mode: 448 });
|
|
97
|
+
const lockPath = join(dir, "wallet.create.lock");
|
|
98
|
+
try {
|
|
99
|
+
return await withFileLock(lockPath, async () => {
|
|
100
|
+
const env = opts.env ?? process.env;
|
|
101
|
+
let source = "env";
|
|
102
|
+
const passphraseFor = async (forAddress) => {
|
|
103
|
+
const resolved = await resolvePassphraseForCreate(
|
|
104
|
+
{ env, dir, ...opts.passphrase },
|
|
105
|
+
forAddress
|
|
106
|
+
);
|
|
107
|
+
source = resolved.source;
|
|
108
|
+
return resolved.passphrase;
|
|
109
|
+
};
|
|
110
|
+
if (!await walletFileExists(dir)) {
|
|
111
|
+
const { address, walletPath: path } = await createLocalWallet(dir, passphraseFor);
|
|
112
|
+
return { address, walletPath: path, source };
|
|
113
|
+
}
|
|
114
|
+
if (opts.replace !== true) throw walletExistsError(dir);
|
|
115
|
+
const preserved = await verifyAndPreserveOutgoingWallet({
|
|
116
|
+
dir,
|
|
117
|
+
env,
|
|
118
|
+
...opts.passphrase !== void 0 ? { passphrase: opts.passphrase } : {}
|
|
119
|
+
});
|
|
120
|
+
const prepared = await prepareLocalWallet(passphraseFor);
|
|
121
|
+
const archivedPath = await parkOutgoingWallet(dir, preserved.account);
|
|
122
|
+
try {
|
|
123
|
+
const { address, walletPath: path } = await commitLocalWallet(dir, prepared);
|
|
124
|
+
return { address, walletPath: path, source, replaced: { ...preserved, archivedPath } };
|
|
125
|
+
} catch (err) {
|
|
126
|
+
try {
|
|
127
|
+
await restoreParkedWallet(dir, archivedPath);
|
|
128
|
+
} catch (restoreErr) {
|
|
129
|
+
throw new CliError(
|
|
130
|
+
"INTERNAL",
|
|
131
|
+
"Creating the replacement wallet failed after the old wallet was parked, and restoring it also failed.",
|
|
132
|
+
{
|
|
133
|
+
fix: `Your old wallet ${preserved.address} is intact at ${archivedPath} with its passphrase preserved. If a ${walletPath(dir)} now exists, another process wrote it \u2014 move it aside first. Then restore with \`mv ${archivedPath} ${walletPath(dir)}\`.`,
|
|
134
|
+
cause: restoreErr
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
}
|
|
138
|
+
throw new CliError(
|
|
139
|
+
"INTERNAL",
|
|
140
|
+
"Creating the replacement wallet failed; the previous wallet was restored and is the active wallet again.",
|
|
141
|
+
{
|
|
142
|
+
fix: "Nothing was lost. Fix the underlying error, then retry `tenjin wallet create --replace`.",
|
|
143
|
+
cause: err
|
|
144
|
+
}
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
} catch (err) {
|
|
149
|
+
if (err instanceof LockTimeoutError) {
|
|
150
|
+
throw new CliError("INTERNAL", err.message, {
|
|
151
|
+
fix: `If no other tenjin process is running, remove ${lockPath} and retry.`,
|
|
152
|
+
cause: err
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
throw err;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
function passphraseNote(source, address) {
|
|
159
|
+
const account = address.toLowerCase();
|
|
160
|
+
switch (source) {
|
|
161
|
+
case "keychain":
|
|
162
|
+
return `Passphrase saved to your macOS keychain (service tenjin-cli, account ${account}); signing will be transparent on this machine.`;
|
|
163
|
+
case "dpapi":
|
|
164
|
+
return `Passphrase saved to a DPAPI-encrypted per-wallet file (passphrase.${account}.dpapi), readable only by you on this Windows machine; signing will be transparent here.`;
|
|
165
|
+
case "secret-service":
|
|
166
|
+
return `Passphrase saved to your Linux keyring (Secret Service, service tenjin-cli, account ${account}); signing will be transparent on this machine.`;
|
|
167
|
+
case "env":
|
|
168
|
+
return "Encrypted with TENJIN_WALLET_PASSPHRASE; keep that value to sign.";
|
|
169
|
+
case "prompt":
|
|
170
|
+
return "Remember your passphrase: it is required to sign and cannot be recovered.";
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
async function runWalletShow(ctx, opts = {}) {
|
|
174
|
+
const provider = resolveWalletProvider(ctx, opts);
|
|
175
|
+
const desc = await describeWallet(provider);
|
|
176
|
+
const {
|
|
177
|
+
walletPath: path,
|
|
178
|
+
keyStorage,
|
|
179
|
+
passphraseSource,
|
|
180
|
+
archivedWallets,
|
|
181
|
+
warnings
|
|
182
|
+
} = await provider.diagnostics();
|
|
183
|
+
const humanLines = [
|
|
184
|
+
`Address: ${desc.address}`,
|
|
185
|
+
...opts.qr !== false && ctx.io.isTTY && !ctx.flags.json ? addressQrLines(desc.address, ctx.io.stdout) : [],
|
|
186
|
+
`Key source: ${desc.credentialSource}`
|
|
187
|
+
];
|
|
188
|
+
if (keyStorage !== void 0) humanLines.push(`Key storage: ${keyStorage}`);
|
|
189
|
+
if (passphraseSource !== void 0) humanLines.push(`Passphrase: ${passphraseSource}`);
|
|
190
|
+
if (archivedWallets !== void 0 && archivedWallets.length > 0) {
|
|
191
|
+
humanLines.push(
|
|
192
|
+
`Archived (replaced) wallets, funds recoverable via their preserved passphrases: ${archivedWallets.join(", ")}`
|
|
193
|
+
);
|
|
194
|
+
}
|
|
195
|
+
humanLines.push(...warnings);
|
|
196
|
+
return {
|
|
197
|
+
data: {
|
|
198
|
+
address: desc.address,
|
|
199
|
+
provider: desc.provider,
|
|
200
|
+
credentialSource: desc.credentialSource,
|
|
201
|
+
policyEnforcement: desc.policyEnforcement,
|
|
202
|
+
...path !== void 0 ? { walletPath: path } : {},
|
|
203
|
+
...keyStorage !== void 0 ? { keyStorage } : {},
|
|
204
|
+
...passphraseSource !== void 0 ? { passphraseSource } : {},
|
|
205
|
+
...archivedWallets !== void 0 && archivedWallets.length > 0 ? { archivedWallets } : {},
|
|
206
|
+
warnings
|
|
207
|
+
},
|
|
208
|
+
humanLines
|
|
209
|
+
};
|
|
210
|
+
}
|
|
211
|
+
async function runWalletBalance(ctx, opts = {}) {
|
|
212
|
+
const provider = resolveWalletProvider(ctx, opts);
|
|
213
|
+
const desc = await describeWallet(provider);
|
|
214
|
+
const config = await loadRawConfig(ctx.dataDir);
|
|
215
|
+
const rpcUrl = resolveSettings({
|
|
216
|
+
config,
|
|
217
|
+
flags: { baseUrl: ctx.flags.baseUrl },
|
|
218
|
+
env: process.env
|
|
219
|
+
}).rpcUrl.value;
|
|
220
|
+
let atomic;
|
|
221
|
+
try {
|
|
222
|
+
atomic = await getUsdcBalance(desc.address, rpcUrl);
|
|
223
|
+
} catch (err) {
|
|
224
|
+
throw new CliError("RPC_ERROR", `Could not read the USDC balance from ${rpcUrl}.`, {
|
|
225
|
+
fix: "Check your network, or set a working RPC with `tenjin config set rpcUrl <url>`.",
|
|
226
|
+
cause: err
|
|
227
|
+
});
|
|
228
|
+
}
|
|
229
|
+
const balance = toMoney(atomic.toString());
|
|
230
|
+
const credit = toMoney(
|
|
231
|
+
(await channelCredit(ctx.dataDir, desc.address).catch(() => 0n)).toString()
|
|
232
|
+
);
|
|
233
|
+
return {
|
|
234
|
+
data: { address: desc.address, balance, routingCredit: credit },
|
|
235
|
+
humanLines: [
|
|
236
|
+
`Balance: ${balance.usd} USDC on Base` + (credit.atomic !== "0" ? ` (+${credit.usd} routing credit)` : "")
|
|
237
|
+
]
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
function custodyWarnings() {
|
|
241
|
+
const warnings = [];
|
|
242
|
+
if (hasEnvKey()) {
|
|
243
|
+
warnings.push("TENJIN_WALLET_KEY is set and shadows this file at runtime.");
|
|
244
|
+
}
|
|
245
|
+
if (isWindows) {
|
|
246
|
+
warnings.push("File permissions are not enforced on Windows; the key file is not restricted.");
|
|
247
|
+
}
|
|
248
|
+
return warnings;
|
|
249
|
+
}
|
|
250
|
+
function hasEnvKey() {
|
|
251
|
+
const envKey = process.env.TENJIN_WALLET_KEY;
|
|
252
|
+
return envKey !== void 0 && envKey.length > 0;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
export {
|
|
256
|
+
runWalletCreate,
|
|
257
|
+
runWalletShow,
|
|
258
|
+
runWalletBalance
|
|
259
|
+
};
|
|
260
|
+
//# sourceMappingURL=chunk-V6BSF6OC.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/wallet.ts"],"sourcesContent":["import { mkdir } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { CliError } from '../lib/errors';\nimport { walletPath } from '../lib/paths';\nimport { withFileLock, LockTimeoutError } from '../lib/lock';\nimport { loadRawConfig, resolveSettings } from '../lib/config';\nimport { toMoney } from '../lib/money';\nimport { getUsdcBalance } from '../lib/usdc';\nimport { addressQrLines } from '../lib/qr';\nimport { channelCredit } from '../router/channel-credit';\nimport { SUGGESTED_FUND_USD } from '../router/fee';\nimport {\n commitLocalWallet,\n createLocalWallet,\n describeWallet,\n parkOutgoingWallet,\n prepareLocalWallet,\n resolveWalletProvider,\n restoreParkedWallet,\n verifyAndPreserveOutgoingWallet,\n type ArchivedWalletInfo,\n type ResolveWalletProviderOptions,\n} from '../lib/wallet';\nimport { walletExistsError, walletFileExists } from '../lib/wallet/store';\nimport { resolvePassphraseForCreate, type PassphraseSource } from '../lib/wallet/passphrase';\nimport type { PassphraseOverrides } from '../lib/wallet/local';\nimport type { CommandContext, CommandResult } from '../context';\n\nconst FUNDING_LINE = `Fund it with \\`tenjin wallet fund ${SUGGESTED_FUND_USD}\\`, or send USDC on Base.`;\nconst KEY_STORAGE = 'encrypted (keystore v3, scrypt)';\nconst isWindows = process.platform === 'win32';\n\nexport interface WalletCreateOptions {\n /**\n * Explicitly replace the existing active wallet (mirrors the `--yes`-style\n * explicit-flag precedent): the outgoing wallet is ARCHIVED — passphrase\n * verified against its keystore and preserved under its own address, keystore\n * parked beside the new one — never destroyed. Without it, create refuses\n * when a wallet exists. There is always exactly ONE active wallet.\n */\n replace?: boolean;\n /** Test seam for passphrase resolution (keychain exec, TTY prompt, platform). */\n passphrase?: PassphraseOverrides;\n /**\n * The environment TENJIN_WALLET_PASSPHRASE is read from; defaults to\n * process.env. A seam rather than a global read so a caller (and above all a\n * test) can settle the passphrase source WITHOUT mutating the real process\n * environment, which under a parallel runner leaks across whole test files.\n */\n env?: NodeJS.ProcessEnv;\n}\n\nexport async function runWalletCreate(\n ctx: CommandContext,\n opts: WalletCreateOptions = {},\n): Promise<CommandResult> {\n const {\n address,\n walletPath: path,\n source,\n replaced,\n } = await createWalletLocked(ctx.dataDir, opts);\n\n const warnings = custodyWarnings();\n return {\n data: {\n address,\n walletPath: path,\n provider: 'local',\n policyEnforcement: 'client-only',\n keyStorage: KEY_STORAGE,\n passphraseSource: source,\n ...(replaced !== undefined\n ? {\n replaced: {\n address: replaced.address,\n archivedWalletPath: replaced.archivedPath,\n passphrasePreserved: replaced.passphraseLocation,\n ...(replaced.unarchivedReason !== undefined\n ? { unarchivedReason: replaced.unarchivedReason }\n : {}),\n },\n }\n : {}),\n warnings,\n },\n humanLines: [\n `Wallet created: ${address}`,\n `Key stored ${KEY_STORAGE}.`,\n passphraseNote(source, address),\n ...(replaced !== undefined ? replacedNote(replaced, path) : []),\n FUNDING_LINE,\n ...warnings,\n ],\n };\n}\n\n/** Where the outgoing wallet's funds live, why they remain reachable, and how to restore it. */\nfunction replacedNote(replaced: ArchivedWalletInfo, activeWalletPath: string): string[] {\n const passphraseLine =\n replaced.passphraseLocation === 'store'\n ? `its passphrase is preserved in the OS credential store (service tenjin-cli, account ${replaced.account}).`\n : replaced.passphraseLocation === 'env'\n ? 'its passphrase is TENJIN_WALLET_PASSPHRASE — keep that value.'\n : replaced.unarchivedReason === 'rejected-characters'\n ? 'its passphrase was NOT archived: the macOS keychain writer only stores machine-generated (base64url) passphrases, and this typed one contains other characters. Keep it yourself, or set TENJIN_WALLET_PASSPHRASE to it.'\n : replaced.unarchivedReason === 'no-store'\n ? 'its passphrase was NOT archived: this platform has no OS credential store. It exists only where you keep it.'\n : 'its passphrase was NOT archived: the OS credential store write failed. It exists only where you keep it.';\n return [\n `Previous wallet archived: ${replaced.address} still holds any funds sent to it.`,\n `Its keystore was moved to ${replaced.archivedPath}; ${passphraseLine}`,\n `To make it the active wallet again later: move the current ${activeWalletPath} aside first, then \\`mv ${replaced.archivedPath} ${activeWalletPath}\\`.`,\n ];\n}\n\n/**\n * Run the whole create critical section under a cross-process file lock: the\n * existence pre-check, the passphrase generate-and-store, and the no-clobber\n * write. Without the lock these interleave across two concurrent creates — each\n * generates a distinct passphrase and persists it to the OS store BEFORE the\n * exclusive file write, so a different process could win the file while this\n * one's per-address entry names a wallet that never landed. Serializing means\n * the loser blocks until the winner commits, then trips the exists check and\n * exits WALLET_EXISTS having never generated or stored a passphrase. The\n * store-before-write ordering stays (it still guards the single-process crash\n * window), and the exclusive write stays the final authority.\n *\n * The passphrase is resolved inside the prepare step's address callback so the\n * OS-store entry is keyed to the new wallet's own address (issue #32).\n *\n * `--replace` ordering closes the no-active-wallet window: verify-and-preserve\n * the outgoing wallet (no file moves), fully PREPARE the replacement (key,\n * stored passphrase, encrypted keystore — every fallible step) while the old\n * wallet is still active, and only then park the old keystore and commit the\n * new one. A commit failure rolls the park back, so at every exit either the\n * old or the new wallet is the active one.\n */\nasync function createWalletLocked(\n dir: string,\n opts: WalletCreateOptions,\n): Promise<{\n address: string;\n walletPath: string;\n source: PassphraseSource;\n replaced?: ArchivedWalletInfo;\n}> {\n // Ensure the data dir exists so the lock's own mkdir has a parent on a fresh\n // install; the exclusive wallet write below re-ensures it at 0700 regardless.\n await mkdir(dir, { recursive: true, mode: 0o700 });\n const lockPath = join(dir, 'wallet.create.lock');\n try {\n return await withFileLock(lockPath, async () => {\n const env = opts.env ?? process.env;\n let source: PassphraseSource = 'env';\n const passphraseFor = async (forAddress: string): Promise<string> => {\n const resolved = await resolvePassphraseForCreate(\n { env, dir, ...opts.passphrase },\n forAddress,\n );\n source = resolved.source;\n return resolved.passphrase;\n };\n\n if (!(await walletFileExists(dir))) {\n const { address, walletPath: path } = await createLocalWallet(dir, passphraseFor);\n return { address, walletPath: path, source };\n }\n\n if (opts.replace !== true) throw walletExistsError(dir);\n const preserved = await verifyAndPreserveOutgoingWallet({\n dir,\n env,\n ...(opts.passphrase !== undefined ? { passphrase: opts.passphrase } : {}),\n });\n const prepared = await prepareLocalWallet(passphraseFor);\n const archivedPath = await parkOutgoingWallet(dir, preserved.account);\n try {\n const { address, walletPath: path } = await commitLocalWallet(dir, prepared);\n return { address, walletPath: path, source, replaced: { ...preserved, archivedPath } };\n } catch (err) {\n try {\n await restoreParkedWallet(dir, archivedPath);\n } catch (restoreErr) {\n // The no-clobber restore also refuses when a wallet.json appeared out\n // of band (commit EEXIST) — never overwrite it; name both files.\n throw new CliError(\n 'INTERNAL',\n 'Creating the replacement wallet failed after the old wallet was parked, and restoring it also failed.',\n {\n fix: `Your old wallet ${preserved.address} is intact at ${archivedPath} with its passphrase preserved. If a ${walletPath(dir)} now exists, another process wrote it — move it aside first. Then restore with \\`mv ${archivedPath} ${walletPath(dir)}\\`.`,\n cause: restoreErr,\n },\n );\n }\n // Old wallet restored as the active one; say so rather than surfacing a\n // raw fs error (or a WALLET_EXISTS whose fix suggests re-running --replace).\n throw new CliError(\n 'INTERNAL',\n 'Creating the replacement wallet failed; the previous wallet was restored and is the active wallet again.',\n {\n fix: 'Nothing was lost. Fix the underlying error, then retry `tenjin wallet create --replace`.',\n cause: err,\n },\n );\n }\n });\n } catch (err) {\n // A lock timeout is not the user's error; surface it as INTERNAL with the one\n // manual step (there is no auto-steal), keeping the JSON error contract. Every\n // other error — notably the loser's WALLET_EXISTS — propagates unchanged.\n if (err instanceof LockTimeoutError) {\n throw new CliError('INTERNAL', err.message, {\n fix: `If no other tenjin process is running, remove ${lockPath} and retry.`,\n cause: err,\n });\n }\n throw err;\n }\n}\n\n/** Where the encryption passphrase lives, and what the user must remember. */\nfunction passphraseNote(source: PassphraseSource, address: string): string {\n const account = address.toLowerCase();\n switch (source) {\n case 'keychain':\n return `Passphrase saved to your macOS keychain (service tenjin-cli, account ${account}); signing will be transparent on this machine.`;\n case 'dpapi':\n return `Passphrase saved to a DPAPI-encrypted per-wallet file (passphrase.${account}.dpapi), readable only by you on this Windows machine; signing will be transparent here.`;\n case 'secret-service':\n return `Passphrase saved to your Linux keyring (Secret Service, service tenjin-cli, account ${account}); signing will be transparent on this machine.`;\n case 'env':\n return 'Encrypted with TENJIN_WALLET_PASSPHRASE; keep that value to sign.';\n case 'prompt':\n return 'Remember your passphrase: it is required to sign and cannot be recovered.';\n }\n}\n\nexport interface WalletShowOptions extends ResolveWalletProviderOptions {\n /** `--no-qr`: print the address without the QR block at a TTY. */\n qr?: boolean;\n}\n\nexport async function runWalletShow(\n ctx: CommandContext,\n opts: WalletShowOptions = {},\n): Promise<CommandResult> {\n const provider = resolveWalletProvider(ctx, opts);\n const desc = await describeWallet(provider);\n // Diagnostics are the provider's own: a remote provider reports no local file\n // path or perms warning, so `show` never contaminates a remote wallet's output\n // with a stale local wallet.json's state. keyStorage/passphraseSource are the\n // custody posture reported without decrypting or requiring a passphrase.\n const {\n walletPath: path,\n keyStorage,\n passphraseSource,\n archivedWallets,\n warnings,\n } = await provider.diagnostics();\n\n const humanLines = [\n `Address: ${desc.address}`,\n ...(opts.qr !== false && ctx.io.isTTY && !ctx.flags.json\n ? addressQrLines(desc.address, ctx.io.stdout)\n : []),\n `Key source: ${desc.credentialSource}`,\n ];\n if (keyStorage !== undefined) humanLines.push(`Key storage: ${keyStorage}`);\n if (passphraseSource !== undefined) humanLines.push(`Passphrase: ${passphraseSource}`);\n if (archivedWallets !== undefined && archivedWallets.length > 0) {\n // A recovery hint, not a wallet switcher: exactly one wallet is ever active.\n humanLines.push(\n `Archived (replaced) wallets, funds recoverable via their preserved passphrases: ${archivedWallets.join(', ')}`,\n );\n }\n humanLines.push(...warnings);\n\n return {\n data: {\n address: desc.address,\n provider: desc.provider,\n credentialSource: desc.credentialSource,\n policyEnforcement: desc.policyEnforcement,\n ...(path !== undefined ? { walletPath: path } : {}),\n ...(keyStorage !== undefined ? { keyStorage } : {}),\n ...(passphraseSource !== undefined ? { passphraseSource } : {}),\n ...(archivedWallets !== undefined && archivedWallets.length > 0 ? { archivedWallets } : {}),\n warnings,\n },\n humanLines,\n };\n}\n\nexport async function runWalletBalance(\n ctx: CommandContext,\n opts: ResolveWalletProviderOptions = {},\n): Promise<CommandResult> {\n const provider = resolveWalletProvider(ctx, opts);\n const desc = await describeWallet(provider);\n\n const config = await loadRawConfig(ctx.dataDir);\n const rpcUrl = resolveSettings({\n config,\n flags: { baseUrl: ctx.flags.baseUrl },\n env: process.env,\n }).rpcUrl.value;\n\n let atomic: bigint;\n try {\n atomic = await getUsdcBalance(desc.address, rpcUrl);\n } catch (err) {\n throw new CliError('RPC_ERROR', `Could not read the USDC balance from ${rpcUrl}.`, {\n fix: 'Check your network, or set a working RPC with `tenjin config set rpcUrl <url>`.',\n cause: err,\n });\n }\n\n const balance = toMoney(atomic.toString());\n // THE ROUTING CREDIT IS STILL THE USER'S: a deposit moved it off the wallet\n // into the routing channel, where the next routing fees draw from it.\n const credit = toMoney(\n (await channelCredit(ctx.dataDir, desc.address).catch(() => 0n)).toString(),\n );\n return {\n data: { address: desc.address, balance, routingCredit: credit },\n humanLines: [\n `Balance: ${balance.usd} USDC on Base` +\n (credit.atomic !== '0' ? ` (+${credit.usd} routing credit)` : ''),\n ],\n };\n}\n\nfunction custodyWarnings(): string[] {\n const warnings: string[] = [];\n if (hasEnvKey()) {\n warnings.push('TENJIN_WALLET_KEY is set and shadows this file at runtime.');\n }\n if (isWindows) {\n warnings.push('File permissions are not enforced on Windows; the key file is not restricted.');\n }\n return warnings;\n}\n\nfunction hasEnvKey(): boolean {\n const envKey = process.env.TENJIN_WALLET_KEY;\n return envKey !== undefined && envKey.length > 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,YAAY;AA2BrB,IAAM,eAAe,qCAAqC,kBAAkB;AAC5E,IAAM,cAAc;AACpB,IAAM,YAAY,QAAQ,aAAa;AAsBvC,eAAsB,gBACpB,KACA,OAA4B,CAAC,GACL;AACxB,QAAM;AAAA,IACJ;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,EACF,IAAI,MAAM,mBAAmB,IAAI,SAAS,IAAI;AAE9C,QAAM,WAAW,gBAAgB;AACjC,SAAO;AAAA,IACL,MAAM;AAAA,MACJ;AAAA,MACA,YAAY;AAAA,MACZ,UAAU;AAAA,MACV,mBAAmB;AAAA,MACnB,YAAY;AAAA,MACZ,kBAAkB;AAAA,MAClB,GAAI,aAAa,SACb;AAAA,QACE,U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AA,EAC/F;AACA,SAAO;AACT;AAEA,SAAS,YAAqB;AAC5B,QAAM,SAAS,QAAQ,IAAI;AAC3B,SAAO,WAAW,UAAa,OAAO,SAAS;AACjD;","names":[]}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/router/names.ts
|
|
4
|
+
var PLUGIN_NAME = "tenjin";
|
|
5
|
+
var MCP_SERVER_NAME = "router";
|
|
6
|
+
var MARKETPLACE_NAME = "tenjin";
|
|
7
|
+
var PLUGIN_ID = `${PLUGIN_NAME}@${MARKETPLACE_NAME}`;
|
|
8
|
+
var SKILLS_DIR_PLUGIN_ID = `${PLUGIN_NAME}@skills-dir`;
|
|
9
|
+
var PLUGIN_SERVER = `plugin:${PLUGIN_NAME}:${MCP_SERVER_NAME}`;
|
|
10
|
+
var TOOL_PREFIX = `mcp__plugin_${PLUGIN_NAME}_${MCP_SERVER_NAME}`;
|
|
11
|
+
var REQUEST_TOOL = `${TOOL_PREFIX}__request`;
|
|
12
|
+
var PLUGIN_HOOK_TOOL = `${TOOL_PREFIX}__hook`;
|
|
13
|
+
var LEGACY_MCP_SERVER_NAME = "x402";
|
|
14
|
+
var LEGACY_REQUEST_TOOL = `mcp__${LEGACY_MCP_SERVER_NAME}__request`;
|
|
15
|
+
var LEGACY_HOOK_TOOL = `mcp__${LEGACY_MCP_SERVER_NAME}__hook`;
|
|
16
|
+
function launchedByPlugin(env = process.env) {
|
|
17
|
+
const root = env.CLAUDE_PLUGIN_ROOT;
|
|
18
|
+
return typeof root === "string" && root.length > 0;
|
|
19
|
+
}
|
|
20
|
+
var HARNESSES = ["claude", "codex"];
|
|
21
|
+
var CODEX_REQUEST_TOOL = `mcp__${MCP_SERVER_NAME}__request`;
|
|
22
|
+
function requestToolName(host = "claude", env = process.env) {
|
|
23
|
+
if (host === "codex") return CODEX_REQUEST_TOOL;
|
|
24
|
+
return launchedByPlugin(env) ? REQUEST_TOOL : LEGACY_REQUEST_TOOL;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export {
|
|
28
|
+
PLUGIN_NAME,
|
|
29
|
+
MCP_SERVER_NAME,
|
|
30
|
+
MARKETPLACE_NAME,
|
|
31
|
+
PLUGIN_ID,
|
|
32
|
+
SKILLS_DIR_PLUGIN_ID,
|
|
33
|
+
PLUGIN_SERVER,
|
|
34
|
+
REQUEST_TOOL,
|
|
35
|
+
PLUGIN_HOOK_TOOL,
|
|
36
|
+
LEGACY_MCP_SERVER_NAME,
|
|
37
|
+
LEGACY_REQUEST_TOOL,
|
|
38
|
+
LEGACY_HOOK_TOOL,
|
|
39
|
+
launchedByPlugin,
|
|
40
|
+
HARNESSES,
|
|
41
|
+
requestToolName
|
|
42
|
+
};
|
|
43
|
+
//# sourceMappingURL=chunk-WJXLQXJY.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/router/names.ts"],"sourcesContent":["/**\n * THE NAMES THE HARNESS KNOWS THE ROUTER BY, spelled once. `install` registers\n * the Claude Code plugin {@link PLUGIN_NAME}, whose MCP server is\n * {@link MCP_SERVER_NAME}, and Claude Code names a plugin's tools\n * `mcp__plugin_<plugin>_<server>__<tool>`. The plugin's hooks, the server's own\n * name and every hint line the hooks inject read these, so a rename moves them\n * together.\n *\n * A module of its own because the hooks need the tool name and must not load\n * `install` to get it: their chunk graph is the product's floor.\n */\nexport const PLUGIN_NAME = 'tenjin';\nexport const MCP_SERVER_NAME = 'router';\n/** The marketplace `install` adds from the package, so the plugin id is `tenjin@tenjin`. */\nexport const MARKETPLACE_NAME = 'tenjin';\nexport const PLUGIN_ID = `${PLUGIN_NAME}@${MARKETPLACE_NAME}`;\n/** The id Claude Code gives the same plugin loaded from a skills-directory folder. */\nexport const SKILLS_DIR_PLUGIN_ID = `${PLUGIN_NAME}@skills-dir`;\n/** How a plugin's `hooks.json` and `claude mcp` name the plugin's own server. */\nexport const PLUGIN_SERVER = `plugin:${PLUGIN_NAME}:${MCP_SERVER_NAME}`;\nconst TOOL_PREFIX = `mcp__plugin_${PLUGIN_NAME}_${MCP_SERVER_NAME}`;\nexport const REQUEST_TOOL = `${TOOL_PREFIX}__request`;\n/** The tool the plugin's hook legs call, which its own deny hook keeps from the model. */\nexport const PLUGIN_HOOK_TOOL = `${TOOL_PREFIX}__hook`;\n\n/**\n * THE SETTINGS-BASED INSTALL'S NAMES, for its migration and nothing else.\n * Releases up to alpha.26 registered the server as `x402` through `claude mcp\n * add` and wrote seven hook entries and two permission rules into settings.json.\n *\n * SHIM: remove on or after 2026-12-01, the first release cut 30 or more days\n * after the plugin PR 2 ships. Doctor keeps naming an unmigrated machine after.\n */\nexport const LEGACY_MCP_SERVER_NAME = 'x402';\nexport const LEGACY_REQUEST_TOOL = `mcp__${LEGACY_MCP_SERVER_NAME}__request`;\nexport const LEGACY_HOOK_TOOL = `mcp__${LEGACY_MCP_SERVER_NAME}__hook`;\n\n/**\n * Is this process one Claude Code launched from the plugin? Claude Code sets\n * `CLAUDE_PLUGIN_ROOT` for a plugin's MCP server and its command hooks\n * (checked on 2.1.296), and not for a server registered in `~/.claude.json`.\n */\nexport function launchedByPlugin(env: NodeJS.ProcessEnv = process.env): boolean {\n const root = env.CLAUDE_PLUGIN_ROOT;\n return typeof root === 'string' && root.length > 0;\n}\n\n/** The agent hosts the router serves, as the CLI names them to the server. */\nexport const HARNESSES = ['claude', 'codex'] as const;\nexport type Harness = (typeof HARNESSES)[number];\n\n/**\n * Codex names an MCP tool `mcp__<server>__<tool>`, and its plugin's server is\n * {@link MCP_SERVER_NAME}, so the grant key and the tool name move together.\n */\nexport const CODEX_REQUEST_TOOL = `mcp__${MCP_SERVER_NAME}__request`;\n\n/**\n * The request tool's name as the host exposes it, so an offer line never names\n * a tool the model does not have. In Claude Code: the plugin's tool for a\n * server the plugin launched, and the `x402` server's tool for one a settings\n * install launched.\n *\n * SHIM: the Claude settings branch goes on or after 2026-12-01 (see\n * {@link LEGACY_MCP_SERVER_NAME}); Claude's name is then always {@link REQUEST_TOOL}.\n */\nexport function requestToolName(\n host: Harness = 'claude',\n env: NodeJS.ProcessEnv = process.env,\n): string {\n if (host === 'codex') return CODEX_REQUEST_TOOL;\n return launchedByPlugin(env) ? REQUEST_TOOL : LEGACY_REQUEST_TOOL;\n}\n"],"mappings":";;;AAWO,IAAM,cAAc;AACpB,IAAM,kBAAkB;AAExB,IAAM,mBAAmB;AACzB,IAAM,YAAY,GAAG,WAAW,IAAI,gBAAgB;AAEpD,IAAM,uBAAuB,GAAG,WAAW;AAE3C,IAAM,gBAAgB,UAAU,WAAW,IAAI,eAAe;AACrE,IAAM,cAAc,eAAe,WAAW,IAAI,eAAe;AAC1D,IAAM,eAAe,GAAG,WAAW;AAEnC,IAAM,mBAAmB,GAAG,WAAW;AAUvC,IAAM,yBAAyB;AAC/B,IAAM,sBAAsB,QAAQ,sBAAsB;AAC1D,IAAM,mBAAmB,QAAQ,sBAAsB;AAOvD,SAAS,iBAAiB,MAAyB,QAAQ,KAAc;AAC9E,QAAM,OAAO,IAAI;AACjB,SAAO,OAAO,SAAS,YAAY,KAAK,SAAS;AACnD;AAGO,IAAM,YAAY,CAAC,UAAU,OAAO;AAOpC,IAAM,qBAAqB,QAAQ,eAAe;AAWlD,SAAS,gBACd,OAAgB,UAChB,MAAyB,QAAQ,KACzB;AACR,MAAI,SAAS,QAAS,QAAO;AAC7B,SAAO,iBAAiB,GAAG,IAAI,eAAe;AAChD;","names":[]}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
hasCode
|
|
4
|
+
} from "./chunk-2I4QTOLB.js";
|
|
5
|
+
import {
|
|
6
|
+
external_exports
|
|
7
|
+
} from "./chunk-YVFXE7RR.js";
|
|
8
|
+
import {
|
|
9
|
+
spendLedgerPath
|
|
10
|
+
} from "./chunk-SJLTEINJ.js";
|
|
11
|
+
|
|
12
|
+
// src/lib/spend-ledger.ts
|
|
13
|
+
import { readFile } from "node:fs/promises";
|
|
14
|
+
var DEFAULT_WINDOW_MS = 864e5;
|
|
15
|
+
var RESERVATION_TTL_MS = 6e5;
|
|
16
|
+
var ReservationSchema = external_exports.object({
|
|
17
|
+
id: external_exports.string(),
|
|
18
|
+
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
19
|
+
atMs: external_exports.number(),
|
|
20
|
+
/** Optional so a ledger written by an older build still parses. */
|
|
21
|
+
requestKey: external_exports.string().optional(),
|
|
22
|
+
mode: external_exports.enum(["automatic", "manual"]).optional()
|
|
23
|
+
});
|
|
24
|
+
var ExposureSchema = external_exports.object({
|
|
25
|
+
nonce: external_exports.string(),
|
|
26
|
+
amountAtomic: external_exports.string().regex(/^\d+$/),
|
|
27
|
+
atMs: external_exports.number(),
|
|
28
|
+
mode: external_exports.enum(["automatic", "manual"]).optional()
|
|
29
|
+
});
|
|
30
|
+
var LedgerSchema = external_exports.object({
|
|
31
|
+
schemaVersion: external_exports.literal(2),
|
|
32
|
+
windowStartMs: external_exports.number(),
|
|
33
|
+
/**
|
|
34
|
+
* EXPOSURE: every authorization this window transmitted. A signed EIP-3009
|
|
35
|
+
* authorization is a bearer instrument, so total exposure stays recorded,
|
|
36
|
+
* whatever any counterparty later says it took.
|
|
37
|
+
*/
|
|
38
|
+
committedAtomic: external_exports.string().regex(/^\d+$/),
|
|
39
|
+
automaticCommittedAtomic: external_exports.string().regex(/^\d+$/).optional(),
|
|
40
|
+
/**
|
|
41
|
+
* SETTLED: what counterparties reported actually taking, which the router's
|
|
42
|
+
* waived outcomes made a different number from the line above (2026-09-23
|
|
43
|
+
* lookup contract). Optional so a ledger an older build wrote still parses;
|
|
44
|
+
* absent means "everything committed was settled", which is what that build
|
|
45
|
+
* assumed. Reporting only, never a budget input: under-counting exposure
|
|
46
|
+
* because a server said "no charge" is exactly the hole this avoids.
|
|
47
|
+
*/
|
|
48
|
+
settledAtomic: external_exports.string().regex(/^\d+$/).optional(),
|
|
49
|
+
reservations: external_exports.array(ReservationSchema),
|
|
50
|
+
/** Optional so a ledger an older build wrote still parses; such a ledger
|
|
51
|
+
* simply has nothing a reconcile can release. */
|
|
52
|
+
exposures: external_exports.array(ExposureSchema).optional()
|
|
53
|
+
});
|
|
54
|
+
function emptyLedger(nowMs) {
|
|
55
|
+
return {
|
|
56
|
+
schemaVersion: 2,
|
|
57
|
+
windowStartMs: nowMs,
|
|
58
|
+
committedAtomic: "0",
|
|
59
|
+
automaticCommittedAtomic: "0",
|
|
60
|
+
settledAtomic: "0",
|
|
61
|
+
reservations: []
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
function spentOf(ledger) {
|
|
65
|
+
return ledger.reservations.reduce(
|
|
66
|
+
(sum, r) => sum + (r.mode === "manual" ? 0n : BigInt(r.amountAtomic)),
|
|
67
|
+
BigInt(ledger.automaticCommittedAtomic ?? ledger.committedAtomic)
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
async function readLedger(path) {
|
|
71
|
+
let raw;
|
|
72
|
+
try {
|
|
73
|
+
raw = await readFile(path, "utf8");
|
|
74
|
+
} catch (err) {
|
|
75
|
+
if (hasCode(err, "ENOENT")) return { ledger: null };
|
|
76
|
+
return { ledger: null, corrupt: err instanceof Error ? err.message : String(err) };
|
|
77
|
+
}
|
|
78
|
+
let json;
|
|
79
|
+
try {
|
|
80
|
+
json = JSON.parse(raw);
|
|
81
|
+
} catch {
|
|
82
|
+
return { ledger: null, corrupt: "not valid JSON" };
|
|
83
|
+
}
|
|
84
|
+
const parsed = LedgerSchema.safeParse(json);
|
|
85
|
+
if (parsed.success) return { ledger: parsed.data };
|
|
86
|
+
const issue = parsed.error.issues[0];
|
|
87
|
+
const field = issue?.path.join(".");
|
|
88
|
+
const message = issue?.message ?? "schema mismatch";
|
|
89
|
+
return {
|
|
90
|
+
ledger: null,
|
|
91
|
+
corrupt: field !== void 0 && field.length > 0 ? `${field}: ${message}` : message
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
async function readSpendSummary(dir, opts = {}) {
|
|
95
|
+
const { ledger } = await readLedger(spendLedgerPath(dir));
|
|
96
|
+
if (ledger === null) return null;
|
|
97
|
+
const nowMs = (opts.now ?? Date.now)();
|
|
98
|
+
const windowMs = opts.windowMs ?? DEFAULT_WINDOW_MS;
|
|
99
|
+
if (nowMs - ledger.windowStartMs >= windowMs) return emptyLedger(nowMs);
|
|
100
|
+
return {
|
|
101
|
+
...ledger,
|
|
102
|
+
reservations: ledger.reservations.filter((r) => nowMs - r.atMs < RESERVATION_TTL_MS)
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
export {
|
|
107
|
+
DEFAULT_WINDOW_MS,
|
|
108
|
+
RESERVATION_TTL_MS,
|
|
109
|
+
emptyLedger,
|
|
110
|
+
spentOf,
|
|
111
|
+
readLedger,
|
|
112
|
+
readSpendSummary
|
|
113
|
+
};
|
|
114
|
+
//# sourceMappingURL=chunk-WK7F3B2E.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/lib/spend-ledger.ts"],"sourcesContent":["import { readFile } from 'node:fs/promises';\nimport { z } from 'zod';\nimport { hasCode } from './errno';\nimport { spendLedgerPath } from './paths';\n\n/**\n * The spend ledger's READ side: its shape, the two expiries, and a read-only\n * summary. It lives outside `lib/wallet` so the router hooks can measure an\n * offer against the same session total an authorization would, without the\n * wallet entering their chunk graph (`src/router/dist-chunks.test.ts`). The\n * write side, with its lock and reservations, stays in `lib/wallet/spend.ts`.\n */\n\nexport const DEFAULT_WINDOW_MS = 86_400_000; // 24h rolling day\nexport const RESERVATION_TTL_MS = 600_000; // 10 min: a dangling reservation self-expires\n\nconst ReservationSchema = z.object({\n id: z.string(),\n amountAtomic: z.string().regex(/^\\d+$/),\n atMs: z.number(),\n /** Optional so a ledger written by an older build still parses. */\n requestKey: z.string().optional(),\n mode: z.enum(['automatic', 'manual']).optional(),\n});\nexport type Reservation = z.infer<typeof ReservationSchema>;\n\n/**\n * ONE TRANSMITTED AUTHORIZATION, by its EIP-3009 nonce: what it exposed and\n * when, so a payment the chain later proves was never charged can give back\n * exactly its own amount inside the window it was counted in.\n */\nconst ExposureSchema = z.object({\n nonce: z.string(),\n amountAtomic: z.string().regex(/^\\d+$/),\n atMs: z.number(),\n mode: z.enum(['automatic', 'manual']).optional(),\n});\nexport type Exposure = z.infer<typeof ExposureSchema>;\n\nconst LedgerSchema = z.object({\n schemaVersion: z.literal(2),\n windowStartMs: z.number(),\n /**\n * EXPOSURE: every authorization this window transmitted. A signed EIP-3009\n * authorization is a bearer instrument, so total exposure stays recorded,\n * whatever any counterparty later says it took.\n */\n committedAtomic: z.string().regex(/^\\d+$/),\n automaticCommittedAtomic: z.string().regex(/^\\d+$/).optional(),\n /**\n * SETTLED: what counterparties reported actually taking, which the router's\n * waived outcomes made a different number from the line above (2026-09-23\n * lookup contract). Optional so a ledger an older build wrote still parses;\n * absent means \"everything committed was settled\", which is what that build\n * assumed. Reporting only, never a budget input: under-counting exposure\n * because a server said \"no charge\" is exactly the hole this avoids.\n */\n settledAtomic: z.string().regex(/^\\d+$/).optional(),\n reservations: z.array(ReservationSchema),\n /** Optional so a ledger an older build wrote still parses; such a ledger\n * simply has nothing a reconcile can release. */\n exposures: z.array(ExposureSchema).optional(),\n});\nexport type Ledger = z.infer<typeof LedgerSchema>;\n\nexport function emptyLedger(nowMs: number): Ledger {\n return {\n schemaVersion: 2,\n windowStartMs: nowMs,\n committedAtomic: '0',\n automaticCommittedAtomic: '0',\n settledAtomic: '0',\n reservations: [],\n };\n}\n\n/** Automatic exposure plus automatic pending reservations: the budget's input.\n * Legacy records with no mode/counter conservatively count as automatic. */\nexport function spentOf(ledger: {\n committedAtomic: string;\n automaticCommittedAtomic?: string;\n reservations: { amountAtomic: string; mode?: 'automatic' | 'manual' }[];\n}): bigint {\n return ledger.reservations.reduce(\n (sum, r) => sum + (r.mode === 'manual' ? 0n : BigInt(r.amountAtomic)),\n BigInt(ledger.automaticCommittedAtomic ?? ledger.committedAtomic),\n );\n}\n\n/**\n * ABSENT and CORRUPT both reset the window, but they are not the same fact: the\n * first is a first run, the second is spend that existed and is now gone. Only\n * the second is worth telling anyone about, so the two stay distinguishable here\n * rather than collapsing into one null.\n */\ninterface LedgerRead {\n ledger: Ledger | null;\n /** Set only when the file EXISTS and could not be turned back into a ledger. */\n corrupt?: string;\n}\n\nexport async function readLedger(path: string): Promise<LedgerRead> {\n let raw: string;\n try {\n raw = await readFile(path, 'utf8');\n } catch (err) {\n // A missing file is the ordinary first run. Any other read failure means a\n // file is there and unusable, which is the corrupt case by another name.\n if (hasCode(err, 'ENOENT')) return { ledger: null };\n return { ledger: null, corrupt: err instanceof Error ? err.message : String(err) };\n }\n let json: unknown;\n try {\n json = JSON.parse(raw);\n } catch {\n return { ledger: null, corrupt: 'not valid JSON' };\n }\n const parsed = LedgerSchema.safeParse(json);\n if (parsed.success) return { ledger: parsed.data };\n const issue = parsed.error.issues[0];\n const field = issue?.path.join('.');\n const message = issue?.message ?? 'schema mismatch';\n // Field-qualified: \"expected number, received undefined\" names nothing on its\n // own. zod never echoes the received VALUE, so no spend figure rides along.\n return {\n ledger: null,\n corrupt: field !== undefined && field.length > 0 ? `${field}: ${message}` : message,\n };\n}\n\nexport interface SpendSummary {\n windowStartMs: number;\n committedAtomic: string;\n automaticCommittedAtomic?: string;\n /** The window's transmitted authorizations by key; a routing deposit's is\n * `routing-deposit:<id>`. */\n exposures?: Exposure[];\n reservations: {\n amountAtomic: string;\n atMs: number;\n requestKey?: string;\n mode?: 'automatic' | 'manual';\n }[];\n}\n\n/**\n * The ledger AS AN AUTHORIZATION WOULD SEE IT, for `tenjin status`. Read-only,\n * and it applies the same two expiries the authorizer applies before it\n * evaluates a spend: a rolling window that has run out reads as a fresh one,\n * and reservations past their TTL are gone. Summing the raw file instead\n * reported spend as current, and crashed reservations as open, until the next\n * payment happened to rewrite it.\n *\n * `null` for absent or unreadable, which is the same thing to a report.\n */\nexport async function readSpendSummary(\n dir: string,\n opts: { now?: () => number; windowMs?: number } = {},\n): Promise<SpendSummary | null> {\n const { ledger } = await readLedger(spendLedgerPath(dir));\n if (ledger === null) return null;\n const nowMs = (opts.now ?? Date.now)();\n const windowMs = opts.windowMs ?? DEFAULT_WINDOW_MS;\n if (nowMs - ledger.windowStartMs >= windowMs) return emptyLedger(nowMs);\n return {\n ...ledger,\n reservations: ledger.reservations.filter((r) => nowMs - r.atMs < RESERVATION_TTL_MS),\n };\n}\n"],"mappings":";;;;;;;;;;;;AAAA,SAAS,gBAAgB;AAalB,IAAM,oBAAoB;AAC1B,IAAM,qBAAqB;AAElC,IAAM,oBAAoB,iBAAE,OAAO;AAAA,EACjC,IAAI,iBAAE,OAAO;AAAA,EACb,cAAc,iBAAE,OAAO,EAAE,MAAM,OAAO;AAAA,EACtC,MAAM,iBAAE,OAAO;AAAA;AAAA,EAEf,YAAY,iBAAE,OAAO,EAAE,SAAS;AAAA,EAChC,MAAM,iBAAE,KAAK,CAAC,aAAa,QAAQ,CAAC,EAAE,SAAS;AACjD,CAAC;AAQD,IAAM,iBAAiB,iBAAE,OAAO;AAAA,EAC9B,OAAO,iBAAE,OAAO;AAAA,EAChB,cAAc,iBAAE,OAAO,EAAE,MAAM,OAAO;AAAA,EACtC,MAAM,iBAAE,OAAO;AAAA,EACf,MAAM,iBAAE,KAAK,CAAC,aAAa,QAAQ,CAAC,EAAE,SAAS;AACjD,CAAC;AAGD,IAAM,eAAe,iBAAE,OAAO;AAAA,EAC5B,eAAe,iBAAE,QAAQ,CAAC;AAAA,EAC1B,eAAe,iBAAE,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMxB,iBAAiB,iBAAE,OAAO,EAAE,MAAM,OAAO;AAAA,EACzC,0BAA0B,iBAAE,OAAO,EAAE,MAAM,OAAO,EAAE,SAAS;AAAA;AAAA;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a,MAAM,SAAS,IAAI,GAAG,KAAK,KAAK,OAAO,KAAK;AAAA,EAC9E;AACF;AA2BA,eAAsB,iBACpB,KACA,OAAkD,CAAC,GACrB;AAC9B,QAAM,EAAE,OAAO,IAAI,MAAM,WAAW,gBAAgB,GAAG,CAAC;AACxD,MAAI,WAAW,KAAM,QAAO;AAC5B,QAAM,SAAS,KAAK,OAAO,KAAK,KAAK;AACrC,QAAM,WAAW,KAAK,YAAY;AAClC,MAAI,QAAQ,OAAO,iBAAiB,SAAU,QAAO,YAAY,KAAK;AACtE,SAAO;AAAA,IACL,GAAG;AAAA,IACH,cAAc,OAAO,aAAa,OAAO,CAAC,MAAM,QAAQ,EAAE,OAAO,kBAAkB;AAAA,EACrF;AACF;","names":[]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
|
|
3
|
+
// src/lib/grade.ts
|
|
4
|
+
var ENDED_AFTER_MS = 30 * 6e4;
|
|
5
|
+
var AGENT_ID_RE = /^[A-Za-z0-9_-]{1,128}$/;
|
|
6
|
+
|
|
7
|
+
export {
|
|
8
|
+
AGENT_ID_RE
|
|
9
|
+
};
|
|
10
|
+
//# sourceMappingURL=chunk-XKESD27X.js.map
|