tenjin-cli 0.1.0-alpha.31 → 0.1.0-alpha.32
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 +5 -5
- package/dist/{_esm-MEXZI5DL.js → _esm-RLLC72MS.js} +128 -132
- package/dist/{alive-J64H46HI.js → alive-MROUMFH3.js} +13 -6
- package/dist/auto-update-OPWMRZLS.js +22 -0
- package/dist/{ccip-7RMRLAGV.js → ccip-DHDFKTQV.js} +2 -2
- package/dist/chunk-2GNOFONN.js +560 -0
- package/dist/chunk-2GNOFONN.js.map +1 -0
- package/dist/{chunk-TTNESUPQ.js → chunk-2GP3HRYK.js} +2120 -193
- package/dist/chunk-2GP3HRYK.js.map +1 -0
- package/dist/chunk-3AIHRXKO.js +72 -0
- package/dist/chunk-3AIHRXKO.js.map +1 -0
- package/dist/{chunk-LEFIX6RS.js → chunk-3DIL66VX.js} +31 -11
- package/dist/chunk-3DIL66VX.js.map +1 -0
- package/dist/{chunk-S4SAZ7OD.js → chunk-3FMZGI7I.js} +12 -2
- package/dist/{chunk-S4SAZ7OD.js.map → chunk-3FMZGI7I.js.map} +1 -1
- package/dist/{chunk-7Q5FDF65.js → chunk-445VQTVM.js} +3 -3
- package/dist/{chunk-A36LQPHV.js → chunk-4LMUQMBH.js} +1 -1
- package/dist/{chunk-A36LQPHV.js.map → chunk-4LMUQMBH.js.map} +1 -1
- package/dist/{chunk-KXQ4UIP7.js → chunk-4USCZ2NI.js} +2 -2
- package/dist/chunk-62KNUYWD.js +111 -0
- package/dist/chunk-62KNUYWD.js.map +1 -0
- package/dist/{chunk-POUWHWID.js → chunk-6CMM6YCB.js} +3 -3
- package/dist/{chunk-POUWHWID.js.map → chunk-6CMM6YCB.js.map} +1 -1
- package/dist/{chunk-5MARFNSB.js → chunk-AD226HDR.js} +49 -30
- package/dist/chunk-AD226HDR.js.map +1 -0
- package/dist/chunk-ADV4LDTB.js +106 -0
- package/dist/chunk-ADV4LDTB.js.map +1 -0
- package/dist/{chunk-7WU4OPLP.js → chunk-AV5NZMYO.js} +5 -3
- package/dist/{chunk-7WU4OPLP.js.map → chunk-AV5NZMYO.js.map} +1 -1
- package/dist/chunk-B7EM4GGF.js +198 -0
- package/dist/chunk-B7EM4GGF.js.map +1 -0
- package/dist/chunk-BFDQ4WNW.js +119 -0
- package/dist/chunk-BFDQ4WNW.js.map +1 -0
- package/dist/{chunk-2XLC3AEX.js → chunk-BI673VEJ.js} +536 -510
- package/dist/chunk-BI673VEJ.js.map +1 -0
- package/dist/chunk-CEXSOI5R.js +808 -0
- package/dist/chunk-CEXSOI5R.js.map +1 -0
- package/dist/{chunk-FW75G2W4.js → chunk-CISYM4EO.js} +5 -5
- package/dist/{chunk-B7HUUJOK.js → chunk-D3ZURCG7.js} +3 -3
- package/dist/chunk-D5TOQSO4.js +474 -0
- package/dist/chunk-D5TOQSO4.js.map +1 -0
- package/dist/{chunk-UQUOVWBG.js → chunk-DRDUIZIA.js} +7 -7
- package/dist/{chunk-27EPWVOY.js → chunk-DW4YTVR3.js} +2 -2
- package/dist/chunk-E7LGOMH6.js +449 -0
- package/dist/chunk-E7LGOMH6.js.map +1 -0
- package/dist/{chunk-QSCPK4F5.js → chunk-E7SW44LM.js} +4 -11
- package/dist/chunk-E7SW44LM.js.map +1 -0
- package/dist/chunk-EDJWHDDL.js +33 -0
- package/dist/chunk-EDJWHDDL.js.map +1 -0
- package/dist/chunk-F3ED5WTR.js +13 -0
- package/dist/chunk-F3ED5WTR.js.map +1 -0
- package/dist/chunk-G75OPGAK.js +111 -0
- package/dist/chunk-G75OPGAK.js.map +1 -0
- package/dist/{chunk-R5LCN54M.js → chunk-GAKUQHKA.js} +13 -17
- package/dist/{chunk-R5LCN54M.js.map → chunk-GAKUQHKA.js.map} +1 -1
- package/dist/{chunk-4ZZO6ULA.js → chunk-HDPUXS3Z.js} +19 -48
- package/dist/chunk-HDPUXS3Z.js.map +1 -0
- package/dist/{chunk-ORWL5BSN.js → chunk-HGZEPQUT.js} +2 -2
- package/dist/{chunk-6E5R45ZO.js → chunk-HREHWL32.js} +4 -4
- package/dist/{chunk-6E5R45ZO.js.map → chunk-HREHWL32.js.map} +1 -1
- package/dist/{chunk-KXVP2VKA.js → chunk-I5TDIUKM.js} +15 -34
- package/dist/chunk-I5TDIUKM.js.map +1 -0
- package/dist/{chunk-7QKHZQKW.js → chunk-IADZOXKN.js} +39 -6
- package/dist/chunk-IADZOXKN.js.map +1 -0
- package/dist/{chunk-P4NH7OUK.js → chunk-IDTRSAHE.js} +2 -2
- package/dist/{chunk-YFPY4ONH.js → chunk-JEVQ5LKO.js} +4 -4
- package/dist/chunk-JNJWBTU2.js +3497 -0
- package/dist/chunk-JNJWBTU2.js.map +1 -0
- package/dist/{chunk-MNXS2U45.js → chunk-JRZBBPO6.js} +167 -86
- package/dist/chunk-JRZBBPO6.js.map +1 -0
- package/dist/{chunk-WJXLQXJY.js → chunk-MPZUYCAP.js} +4 -1
- package/dist/{chunk-WJXLQXJY.js.map → chunk-MPZUYCAP.js.map} +1 -1
- package/dist/{chunk-SJLTEINJ.js → chunk-OJNTCYQQ.js} +17 -1
- package/dist/chunk-OJNTCYQQ.js.map +1 -0
- package/dist/{chunk-AGZ7PJKY.js → chunk-OTWLERSW.js} +22 -5
- package/dist/chunk-OTWLERSW.js.map +1 -0
- package/dist/{chunk-NEFNKLBE.js → chunk-PJNENX2A.js} +1535 -422
- package/dist/chunk-PJNENX2A.js.map +1 -0
- package/dist/{chunk-UKY4CHNC.js → chunk-PKHI276N.js} +8 -4
- package/dist/chunk-PKHI276N.js.map +1 -0
- package/dist/{chunk-5K5W4S66.js → chunk-QF3LSMGS.js} +2 -2
- package/dist/{chunk-XZKD7DIF.js → chunk-RL5UUDT4.js} +3 -3
- package/dist/{chunk-XZKD7DIF.js.map → chunk-RL5UUDT4.js.map} +1 -1
- package/dist/{chunk-OHRR5OYM.js → chunk-SFASB5FL.js} +10 -4
- package/dist/chunk-SFASB5FL.js.map +1 -0
- package/dist/{chunk-YVFXE7RR.js → chunk-SNNSAGMT.js} +7279 -2627
- package/dist/chunk-SNNSAGMT.js.map +1 -0
- package/dist/{chunk-WK7F3B2E.js → chunk-SO3XRZPX.js} +3 -3
- package/dist/chunk-SYOS5CAC.js +176 -0
- package/dist/chunk-SYOS5CAC.js.map +1 -0
- package/dist/chunk-TAW4UFFF.js +293 -0
- package/dist/chunk-TAW4UFFF.js.map +1 -0
- package/dist/{hosts-FWZOV26H.js → chunk-TF5HCP33.js} +79 -24
- package/dist/chunk-TF5HCP33.js.map +1 -0
- package/dist/{chunk-AKWGE6JQ.js → chunk-UUGOUOVT.js} +37 -2
- package/dist/chunk-UUGOUOVT.js.map +1 -0
- package/dist/{chunk-7ZRL2LBQ.js → chunk-V2LQLN5H.js} +6 -6
- package/dist/{chunk-K72RURN3.js → chunk-VJUVFZ2D.js} +2 -2
- package/dist/{chunk-77TCKDEC.js → chunk-VOZA6O7K.js} +663 -477
- package/dist/chunk-VOZA6O7K.js.map +1 -0
- package/dist/{chunk-D65GNPS3.js → chunk-VUGQTZ2L.js} +208 -84
- package/dist/chunk-VUGQTZ2L.js.map +1 -0
- package/dist/chunk-WOM257PW.js +393 -0
- package/dist/chunk-WOM257PW.js.map +1 -0
- package/dist/chunk-WYXUQGOL.js +191 -0
- package/dist/chunk-WYXUQGOL.js.map +1 -0
- package/dist/chunk-X5ZBP3IY.js +97 -0
- package/dist/chunk-X5ZBP3IY.js.map +1 -0
- package/dist/{chunk-5C32RLTA.js → chunk-YUY4SAGM.js} +17 -2
- package/dist/chunk-YUY4SAGM.js.map +1 -0
- package/dist/{cli-D5OE3URZ.js → cli-FB4LOA5A.js} +144 -63
- package/dist/{cli-D5OE3URZ.js.map → cli-FB4LOA5A.js.map} +1 -1
- package/dist/{codex-event-PPNVRRDH.js → codex-event-TYVES3UX.js} +2 -2
- package/dist/{codex-host-2RJOJW2B.js → codex-host-WW4H2SKT.js} +7 -6
- package/dist/codex-install-2C623HPW.js +393 -0
- package/dist/codex-install-2C623HPW.js.map +1 -0
- package/dist/{config-ZD4OB2DO.js → config-HOVJFEKD.js} +21 -17
- package/dist/doctor-NKU4V5OV.js +1312 -0
- package/dist/doctor-NKU4V5OV.js.map +1 -0
- package/dist/{env-proxy-XL4P73MZ.js → env-proxy-R6ZMLQTT.js} +6 -2
- package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js → ethersCompat-Df4a6QIZ-X6YZWAML.js} +3 -3
- package/dist/{fund-5ITKQGYF.js → fund-WEBHTZGN.js} +37 -36
- package/dist/{fund-5ITKQGYF.js.map → fund-WEBHTZGN.js.map} +1 -1
- package/dist/hook-command-ZA2PNKS6.js +44 -0
- package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
- package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +2 -2
- package/dist/hosts/claude/tenjin/skills/tenjin-pay/SKILL.md +82 -0
- package/dist/hosts/codex/tenjin/.mcp.json +3 -0
- package/dist/hosts/codex/tenjin/hooks/hooks.json +51 -5
- package/dist/hosts-AV5MHBAU.js +38 -0
- package/dist/index.js +28 -8
- package/dist/index.js.map +1 -1
- package/dist/{install-XWGE4Q7L.js → install-PT4EZS4R.js} +53 -30
- package/dist/{install-identity-K7EJIQFP.js → install-identity-5A4OE6YC.js} +11 -10
- package/dist/install-wallet-SAAPKB73.js +281 -0
- package/dist/install-wallet-SAAPKB73.js.map +1 -0
- package/dist/{mcp-3LIJSSJB.js → mcp-HAWKCTPQ.js} +785 -210
- package/dist/mcp-HAWKCTPQ.js.map +1 -0
- package/dist/{mine.wasm-6PIT3DK6.js → mine.wasm-QFAHIFPY.js} +2 -2
- package/dist/{mine.wasm-6PIT3DK6.js.map → mine.wasm-QFAHIFPY.js.map} +1 -1
- package/dist/{package-ZKQFDWLE.js → package-SR2WB6MK.js} +4 -2
- package/dist/passphrase-IFTDS3CU.js +44 -0
- package/dist/{paths-POPTXJO6.js → paths-XCSAKISU.js} +10 -2
- package/dist/{pay-WHBERZ3W.js → pay-OXC3WKYV.js} +29 -29
- package/dist/{payments-KVICEKD2.js → payments-3KHMP2MG.js} +15 -14
- package/dist/{payments-KVICEKD2.js.map → payments-3KHMP2MG.js.map} +1 -1
- package/dist/plugin-registration-N3GRIZVM.js +67 -0
- package/dist/{redact-6W23GGJC.js → redact-D7ASVWKL.js} +2 -2
- package/dist/runtime-UVNUA3AS.js +1203 -0
- package/dist/runtime-UVNUA3AS.js.map +1 -0
- package/dist/runtime-fetch-EKFRNR6Z.js +20 -0
- package/dist/runtime-layout-BDWZG2TQ.js +25 -0
- package/dist/{send-7G7Y7DLN.js → send-HMKJLT34.js} +24 -22
- package/dist/{send-7G7Y7DLN.js.map → send-HMKJLT34.js.map} +1 -1
- package/dist/{status-OF7RH5HM.js → status-RWXIIWYS.js} +55 -25
- package/dist/status-RWXIIWYS.js.map +1 -0
- package/dist/{status-line-XOUE6MPL.js → status-line-77XYZP7E.js} +10 -9
- package/dist/{status-line-XOUE6MPL.js.map → status-line-77XYZP7E.js.map} +1 -1
- package/dist/uninstall-D5G67UJH.js +480 -0
- package/dist/uninstall-D5G67UJH.js.map +1 -0
- package/dist/update-LRNOEGSB.js +53 -0
- package/dist/update-LRNOEGSB.js.map +1 -0
- package/dist/{usdc-OGOGEHV2.js → usdc-D6X7EIQ2.js} +6 -8
- package/dist/usdc-D6X7EIQ2.js.map +1 -0
- package/dist/{viemAdapter-By13KInL-S3DA7DFW.js → viemAdapter-By13KInL-RL742ETX.js} +3 -3
- package/dist/viemAdapter-By13KInL-RL742ETX.js.map +1 -0
- package/dist/wallet-XFYC27BR.js +55 -0
- package/dist/wallet-XFYC27BR.js.map +1 -0
- package/dist/wallet-kdf-worker.mjs +8 -8
- package/docs/agent-permissions.md +40 -22
- package/docs/safety-model.md +1 -1
- package/docs/troubleshooting.md +72 -1
- package/package.json +14 -1
- package/dist/ccip-NLCSCHKI.js +0 -19
- package/dist/chunk-2XLC3AEX.js.map +0 -1
- package/dist/chunk-4ZZO6ULA.js.map +0 -1
- package/dist/chunk-5C32RLTA.js.map +0 -1
- package/dist/chunk-5IEP5EGE.js +0 -5332
- package/dist/chunk-5IEP5EGE.js.map +0 -1
- package/dist/chunk-5MARFNSB.js.map +0 -1
- package/dist/chunk-77TCKDEC.js.map +0 -1
- package/dist/chunk-7EKYXMUO.js +0 -7536
- package/dist/chunk-7EKYXMUO.js.map +0 -1
- package/dist/chunk-7QKHZQKW.js.map +0 -1
- package/dist/chunk-AGZ7PJKY.js.map +0 -1
- package/dist/chunk-AKWGE6JQ.js.map +0 -1
- package/dist/chunk-BL3332HQ.js +0 -7611
- package/dist/chunk-BL3332HQ.js.map +0 -1
- package/dist/chunk-D65GNPS3.js.map +0 -1
- package/dist/chunk-EGELTSPU.js +0 -2865
- package/dist/chunk-EGELTSPU.js.map +0 -1
- package/dist/chunk-GA7JETVM.js +0 -150
- package/dist/chunk-GA7JETVM.js.map +0 -1
- package/dist/chunk-I3EQFHCD.js +0 -175
- package/dist/chunk-I3EQFHCD.js.map +0 -1
- package/dist/chunk-K3I7C2MO.js +0 -1185
- package/dist/chunk-K3I7C2MO.js.map +0 -1
- package/dist/chunk-KXVP2VKA.js.map +0 -1
- package/dist/chunk-LEFIX6RS.js.map +0 -1
- package/dist/chunk-MNXS2U45.js.map +0 -1
- package/dist/chunk-NEFNKLBE.js.map +0 -1
- package/dist/chunk-OHRR5OYM.js.map +0 -1
- package/dist/chunk-QSCPK4F5.js.map +0 -1
- package/dist/chunk-SJLTEINJ.js.map +0 -1
- package/dist/chunk-TTNESUPQ.js.map +0 -1
- package/dist/chunk-UKY4CHNC.js.map +0 -1
- package/dist/chunk-V6BSF6OC.js +0 -260
- package/dist/chunk-V6BSF6OC.js.map +0 -1
- package/dist/chunk-YVFXE7RR.js.map +0 -1
- package/dist/codex-install-UUZ6QMBQ.js +0 -221
- package/dist/codex-install-UUZ6QMBQ.js.map +0 -1
- package/dist/doctor-KBR34Q4B.js +0 -601
- package/dist/doctor-KBR34Q4B.js.map +0 -1
- package/dist/hook-command-4TYCHHRL.js +0 -39
- package/dist/hosts-FWZOV26H.js.map +0 -1
- package/dist/install-wallet-XQ6XFZV4.js +0 -117
- package/dist/install-wallet-XQ6XFZV4.js.map +0 -1
- package/dist/mcp-3LIJSSJB.js.map +0 -1
- package/dist/plugin-registration-5TIA564H.js +0 -54
- package/dist/status-OF7RH5HM.js.map +0 -1
- package/dist/uninstall-JXUAFNDB.js +0 -158
- package/dist/uninstall-JXUAFNDB.js.map +0 -1
- package/dist/update-ZKUERSO2.js +0 -44
- package/dist/wallet-2HA6W4R4.js +0 -43
- /package/dist/{_esm-MEXZI5DL.js.map → _esm-RLLC72MS.js.map} +0 -0
- /package/dist/{alive-J64H46HI.js.map → alive-MROUMFH3.js.map} +0 -0
- /package/dist/{ccip-7RMRLAGV.js.map → auto-update-OPWMRZLS.js.map} +0 -0
- /package/dist/{ccip-NLCSCHKI.js.map → ccip-DHDFKTQV.js.map} +0 -0
- /package/dist/{chunk-7Q5FDF65.js.map → chunk-445VQTVM.js.map} +0 -0
- /package/dist/{chunk-KXQ4UIP7.js.map → chunk-4USCZ2NI.js.map} +0 -0
- /package/dist/{chunk-FW75G2W4.js.map → chunk-CISYM4EO.js.map} +0 -0
- /package/dist/{chunk-B7HUUJOK.js.map → chunk-D3ZURCG7.js.map} +0 -0
- /package/dist/{chunk-UQUOVWBG.js.map → chunk-DRDUIZIA.js.map} +0 -0
- /package/dist/{chunk-27EPWVOY.js.map → chunk-DW4YTVR3.js.map} +0 -0
- /package/dist/{chunk-ORWL5BSN.js.map → chunk-HGZEPQUT.js.map} +0 -0
- /package/dist/{chunk-P4NH7OUK.js.map → chunk-IDTRSAHE.js.map} +0 -0
- /package/dist/{chunk-YFPY4ONH.js.map → chunk-JEVQ5LKO.js.map} +0 -0
- /package/dist/{chunk-5K5W4S66.js.map → chunk-QF3LSMGS.js.map} +0 -0
- /package/dist/{chunk-WK7F3B2E.js.map → chunk-SO3XRZPX.js.map} +0 -0
- /package/dist/{chunk-7ZRL2LBQ.js.map → chunk-V2LQLN5H.js.map} +0 -0
- /package/dist/{chunk-K72RURN3.js.map → chunk-VJUVFZ2D.js.map} +0 -0
- /package/dist/{codex-event-PPNVRRDH.js.map → codex-event-TYVES3UX.js.map} +0 -0
- /package/dist/{codex-host-2RJOJW2B.js.map → codex-host-WW4H2SKT.js.map} +0 -0
- /package/dist/{config-ZD4OB2DO.js.map → config-HOVJFEKD.js.map} +0 -0
- /package/dist/{env-proxy-XL4P73MZ.js.map → env-proxy-R6ZMLQTT.js.map} +0 -0
- /package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js.map → ethersCompat-Df4a6QIZ-X6YZWAML.js.map} +0 -0
- /package/dist/{hook-command-4TYCHHRL.js.map → hook-command-ZA2PNKS6.js.map} +0 -0
- /package/dist/{install-XWGE4Q7L.js.map → hosts-AV5MHBAU.js.map} +0 -0
- /package/dist/{install-identity-K7EJIQFP.js.map → install-PT4EZS4R.js.map} +0 -0
- /package/dist/{package-ZKQFDWLE.js.map → install-identity-5A4OE6YC.js.map} +0 -0
- /package/dist/{paths-POPTXJO6.js.map → package-SR2WB6MK.js.map} +0 -0
- /package/dist/{pay-WHBERZ3W.js.map → passphrase-IFTDS3CU.js.map} +0 -0
- /package/dist/{plugin-registration-5TIA564H.js.map → paths-XCSAKISU.js.map} +0 -0
- /package/dist/{redact-6W23GGJC.js.map → pay-OXC3WKYV.js.map} +0 -0
- /package/dist/{update-ZKUERSO2.js.map → plugin-registration-N3GRIZVM.js.map} +0 -0
- /package/dist/{usdc-OGOGEHV2.js.map → redact-D7ASVWKL.js.map} +0 -0
- /package/dist/{viemAdapter-By13KInL-S3DA7DFW.js.map → runtime-fetch-EKFRNR6Z.js.map} +0 -0
- /package/dist/{wallet-2HA6W4R4.js.map → runtime-layout-BDWZG2TQ.js.map} +0 -0
|
@@ -0,0 +1,808 @@
|
|
|
1
|
+
import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
|
|
2
|
+
import {
|
|
3
|
+
readPassphraseRecord
|
|
4
|
+
} from "./chunk-3AIHRXKO.js";
|
|
5
|
+
import {
|
|
6
|
+
FILE_STORE_FAILED_FIX,
|
|
7
|
+
KEYCHAIN_LOCKED_FIX,
|
|
8
|
+
KEYCHAIN_WAIT_LINE,
|
|
9
|
+
REPAIR_IN_TERMINAL,
|
|
10
|
+
unlockDetails
|
|
11
|
+
} from "./chunk-X5ZBP3IY.js";
|
|
12
|
+
import {
|
|
13
|
+
hasCode
|
|
14
|
+
} from "./chunk-2I4QTOLB.js";
|
|
15
|
+
import {
|
|
16
|
+
writeFileAtomic,
|
|
17
|
+
writeFileAtomicExclusive
|
|
18
|
+
} from "./chunk-7WEQQJLG.js";
|
|
19
|
+
import {
|
|
20
|
+
CliError
|
|
21
|
+
} from "./chunk-3UCIG4TG.js";
|
|
22
|
+
import {
|
|
23
|
+
dataDir,
|
|
24
|
+
passphraseBlobPath,
|
|
25
|
+
passphraseBlobPathFor,
|
|
26
|
+
passphraseFilePathFor
|
|
27
|
+
} from "./chunk-OJNTCYQQ.js";
|
|
28
|
+
|
|
29
|
+
// src/lib/wallet/passphrase.ts
|
|
30
|
+
import { execFile } from "node:child_process";
|
|
31
|
+
import { randomBytes } from "node:crypto";
|
|
32
|
+
import { readFile, stat, unlink } from "node:fs/promises";
|
|
33
|
+
import { homedir } from "node:os";
|
|
34
|
+
var KEYCHAIN_SERVICE = "tenjin-cli";
|
|
35
|
+
var LEGACY_ACCOUNT = "wallet";
|
|
36
|
+
var PROBE_ACCOUNT = "0x0000000000000000000000000000000000000000";
|
|
37
|
+
var ACCOUNT_ADDRESS_RE = /^0x[0-9a-f]{40}$/;
|
|
38
|
+
var BASE64URL_RE = /^[A-Za-z0-9_-]+$/;
|
|
39
|
+
var PRINTABLE_ASCII_RE = /^[\x20-\x7e]+$/;
|
|
40
|
+
function walletStoreAccount(address) {
|
|
41
|
+
const account = address.toLowerCase();
|
|
42
|
+
if (!ACCOUNT_ADDRESS_RE.test(account)) {
|
|
43
|
+
throw new CliError("INTERNAL", `Not a valid wallet address for passphrase storage: ${address}`);
|
|
44
|
+
}
|
|
45
|
+
return account;
|
|
46
|
+
}
|
|
47
|
+
var StoreExecError = class extends Error {
|
|
48
|
+
code;
|
|
49
|
+
signal;
|
|
50
|
+
killed;
|
|
51
|
+
enoent;
|
|
52
|
+
constructor(file, fields = {}) {
|
|
53
|
+
const code = fields.code ?? null;
|
|
54
|
+
const signal = fields.signal ?? null;
|
|
55
|
+
super(`${file} failed (${code ?? signal ?? "no exit code"})`);
|
|
56
|
+
this.name = "StoreExecError";
|
|
57
|
+
this.code = code;
|
|
58
|
+
this.signal = signal;
|
|
59
|
+
this.killed = fields.killed ?? false;
|
|
60
|
+
this.enoent = fields.enoent ?? code === "ENOENT";
|
|
61
|
+
Object.defineProperty(this, "stderr", {
|
|
62
|
+
value: fields.stderr ?? "",
|
|
63
|
+
enumerable: false,
|
|
64
|
+
writable: false
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
var STORE_TIMEOUTS = {
|
|
69
|
+
verifyReadMs: 5e3,
|
|
70
|
+
writeMs: 1e4,
|
|
71
|
+
interactiveWriteMs: 6e4,
|
|
72
|
+
probeMs: 3e3,
|
|
73
|
+
waitLineAfterMs: 1e3
|
|
74
|
+
};
|
|
75
|
+
function defaultExecFor() {
|
|
76
|
+
return (file, args, stdin, opts) => new Promise((resolve, reject) => {
|
|
77
|
+
const child = execFile(
|
|
78
|
+
file,
|
|
79
|
+
args,
|
|
80
|
+
{
|
|
81
|
+
encoding: "utf8",
|
|
82
|
+
killSignal: "SIGKILL",
|
|
83
|
+
// 0 would mean "no timeout" to Node; a spent deadline is still a deadline.
|
|
84
|
+
...opts?.timeoutMs !== void 0 ? { timeout: Math.max(1, opts.timeoutMs) } : {}
|
|
85
|
+
},
|
|
86
|
+
(err, stdout, stderr) => {
|
|
87
|
+
if (err) reject(toStoreExecError(file, err, stderr));
|
|
88
|
+
else resolve({ stdout, stderr });
|
|
89
|
+
}
|
|
90
|
+
);
|
|
91
|
+
if (stdin !== void 0) {
|
|
92
|
+
child.stdin?.on("error", () => void 0);
|
|
93
|
+
child.stdin?.end(stdin);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function toStoreExecError(file, err, stderr) {
|
|
98
|
+
const e = err;
|
|
99
|
+
const code = typeof e.code === "number" || typeof e.code === "string" ? e.code : null;
|
|
100
|
+
return new StoreExecError(file, {
|
|
101
|
+
code,
|
|
102
|
+
signal: typeof e.signal === "string" ? e.signal : null,
|
|
103
|
+
killed: e.killed === true,
|
|
104
|
+
enoent: code === "ENOENT",
|
|
105
|
+
stderr: typeof stderr === "string" ? stderr : ""
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
function timeoutsOf(deps) {
|
|
109
|
+
return { ...STORE_TIMEOUTS, ...deps.timeouts };
|
|
110
|
+
}
|
|
111
|
+
function storeNoun(store) {
|
|
112
|
+
switch (store) {
|
|
113
|
+
case "keychain":
|
|
114
|
+
return "macOS keychain";
|
|
115
|
+
case "secret-service":
|
|
116
|
+
return "Linux keyring";
|
|
117
|
+
case "dpapi":
|
|
118
|
+
return "Windows DPAPI store";
|
|
119
|
+
case "file":
|
|
120
|
+
return "passphrase file";
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
function classifyStoreFailure(store, err) {
|
|
124
|
+
if (store === "file") {
|
|
125
|
+
if (hasCode(err, "ENOENT")) return { kind: "miss" };
|
|
126
|
+
const code = err?.code;
|
|
127
|
+
const errno = typeof code === "string" && /^E[A-Z]+$/.test(code) ? ` (${code})` : "";
|
|
128
|
+
return { kind: "locked", detail: `the passphrase file could not be read${errno}` };
|
|
129
|
+
}
|
|
130
|
+
if (!(err instanceof StoreExecError)) {
|
|
131
|
+
return {
|
|
132
|
+
kind: "locked",
|
|
133
|
+
detail: `the ${storeNoun(store)} failed for a reason Tenjin could not classify`
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
if (err.killed || err.signal !== null) {
|
|
137
|
+
return {
|
|
138
|
+
kind: "locked",
|
|
139
|
+
detail: `the ${storeNoun(store)} did not answer (killed by ${err.signal ?? "SIGKILL"})`
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
switch (store) {
|
|
143
|
+
case "keychain":
|
|
144
|
+
if (err.enoent) return { kind: "absent", detail: "the `security` tool is not installed" };
|
|
145
|
+
if (err.code === 44) return { kind: "miss" };
|
|
146
|
+
if (/default keychain could not be found/i.test(err.stderr)) {
|
|
147
|
+
return { kind: "absent", detail: "there is no default keychain" };
|
|
148
|
+
}
|
|
149
|
+
if (/User interaction is not allowed/.test(err.stderr)) {
|
|
150
|
+
return { kind: "locked", detail: "the keychain refused (user interaction is not allowed)" };
|
|
151
|
+
}
|
|
152
|
+
return { kind: "locked", detail: `security exited ${String(err.code)}` };
|
|
153
|
+
case "secret-service":
|
|
154
|
+
if (err.enoent) return { kind: "absent", detail: "secret-tool is not installed" };
|
|
155
|
+
if (/Cannot autolaunch D-Bus|org\.freedesktop\.secrets was not provided|Could not connect/.test(
|
|
156
|
+
err.stderr
|
|
157
|
+
)) {
|
|
158
|
+
return { kind: "absent", detail: "no Secret Service is reachable from this session" };
|
|
159
|
+
}
|
|
160
|
+
if (err.code === 1 && err.stderr.trim() === "") return { kind: "miss" };
|
|
161
|
+
return { kind: "locked", detail: `secret-tool exited ${String(err.code)}` };
|
|
162
|
+
case "dpapi":
|
|
163
|
+
if (err.enoent) return { kind: "absent", detail: "powershell.exe is not available" };
|
|
164
|
+
return {
|
|
165
|
+
kind: "locked",
|
|
166
|
+
detail: `the DPAPI unprotect failed (powershell.exe exited ${String(err.code)})`
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
function storeFor(deps) {
|
|
171
|
+
switch (deps.platform ?? process.platform) {
|
|
172
|
+
case "darwin":
|
|
173
|
+
return keychainStore(deps);
|
|
174
|
+
case "win32":
|
|
175
|
+
return dpapiStore(deps);
|
|
176
|
+
case "linux":
|
|
177
|
+
return secretServiceStore(deps);
|
|
178
|
+
default:
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
function storeByName(deps, name) {
|
|
183
|
+
switch (name) {
|
|
184
|
+
case "keychain":
|
|
185
|
+
return keychainStore(deps);
|
|
186
|
+
case "secret-service":
|
|
187
|
+
return secretServiceStore(deps);
|
|
188
|
+
case "dpapi":
|
|
189
|
+
return dpapiStore(deps);
|
|
190
|
+
case "file":
|
|
191
|
+
return fileStore(deps);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
function readStoredPassphrase(deps, store, address, o) {
|
|
195
|
+
return storeByName(deps, store).read(walletStoreAccount(address), o);
|
|
196
|
+
}
|
|
197
|
+
async function resolvePassphrase(deps, address, opts = {}) {
|
|
198
|
+
if (opts.skipEnv !== true) {
|
|
199
|
+
const fromEnv = envPassphrase(deps.env);
|
|
200
|
+
if (fromEnv !== null) return { passphrase: fromEnv, source: "env" };
|
|
201
|
+
}
|
|
202
|
+
const account = walletStoreAccount(address);
|
|
203
|
+
const readOpts = deps.readDeadlineMs !== void 0 ? { timeoutMs: deps.readDeadlineMs } : void 0;
|
|
204
|
+
const prompted = async () => {
|
|
205
|
+
const entered = await promptOf(deps)(opts.promptLabel ?? "Wallet passphrase: ");
|
|
206
|
+
if (entered.length === 0) throw noPassphraseError();
|
|
207
|
+
return { passphrase: entered, source: "prompt" };
|
|
208
|
+
};
|
|
209
|
+
const entry = await readPassphraseRecord(deps.dir ?? dataDir(), account);
|
|
210
|
+
if (entry !== null) {
|
|
211
|
+
const got = await storeByName(deps, entry.store).read(account, readOpts);
|
|
212
|
+
if (got.kind === "hit") return { passphrase: got.value, source: entry.store, recorded: true };
|
|
213
|
+
if (canPrompt(deps)) return prompted();
|
|
214
|
+
if (got.kind === "miss") {
|
|
215
|
+
throw noPassphraseError(describeStoreLocation(entry.store, account, deps.dir));
|
|
216
|
+
}
|
|
217
|
+
throw storeLockedError(entry.store, account, got.detail, deps.dir, true);
|
|
218
|
+
}
|
|
219
|
+
const store = storeFor(deps);
|
|
220
|
+
let legacyLocked = null;
|
|
221
|
+
if (store !== null) {
|
|
222
|
+
const own = await store.read(account, readOpts);
|
|
223
|
+
if (own.kind === "hit") return { passphrase: own.value, source: store.source };
|
|
224
|
+
if (own.kind === "locked") {
|
|
225
|
+
if (canPrompt(deps)) return prompted();
|
|
226
|
+
throw storeLockedError(store.source, account, own.detail, deps.dir, false);
|
|
227
|
+
}
|
|
228
|
+
if (own.kind === "miss") {
|
|
229
|
+
const legacy = await store.read(LEGACY_ACCOUNT, readOpts);
|
|
230
|
+
if (legacy.kind === "hit") {
|
|
231
|
+
return {
|
|
232
|
+
passphrase: legacy.value,
|
|
233
|
+
source: store.source,
|
|
234
|
+
migrateLegacy: () => migrateLegacyEntry(legacyOps(store, deps), account, legacy.value)
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
if (legacy.kind === "locked") legacyLocked = { source: store.source, detail: legacy.detail };
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const file = await fileStore(deps).read(account);
|
|
241
|
+
if (file.kind === "hit") return { passphrase: file.value, source: "file" };
|
|
242
|
+
if (canPrompt(deps)) return prompted();
|
|
243
|
+
if (legacyLocked !== null) {
|
|
244
|
+
throw storeLockedError(
|
|
245
|
+
legacyLocked.source,
|
|
246
|
+
LEGACY_ACCOUNT,
|
|
247
|
+
legacyLocked.detail,
|
|
248
|
+
deps.dir,
|
|
249
|
+
false
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
throw noPassphraseError();
|
|
253
|
+
}
|
|
254
|
+
function legacyOps(store, deps) {
|
|
255
|
+
const timeoutMs = timeoutsOf(deps).writeMs;
|
|
256
|
+
return {
|
|
257
|
+
async copy(account, value) {
|
|
258
|
+
if (store.storable !== void 0 && !store.storable(value)) return false;
|
|
259
|
+
try {
|
|
260
|
+
await store.store(account, value, { timeoutMs });
|
|
261
|
+
return true;
|
|
262
|
+
} catch {
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
},
|
|
266
|
+
async readBack(account) {
|
|
267
|
+
const got = await store.read(account, { timeoutMs });
|
|
268
|
+
return got.kind === "hit" ? got.value : null;
|
|
269
|
+
},
|
|
270
|
+
removeLegacy: () => store.remove(LEGACY_ACCOUNT, { timeoutMs })
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
async function migrateLegacyEntry(ops, account, passphrase) {
|
|
274
|
+
if (!await ops.copy(account, passphrase)) return false;
|
|
275
|
+
if (await ops.readBack(account) !== passphrase) return false;
|
|
276
|
+
await ops.removeLegacy();
|
|
277
|
+
return true;
|
|
278
|
+
}
|
|
279
|
+
async function storeDurablyDetailed(deps, storeName, address, secret, opts = {}) {
|
|
280
|
+
const store = storeByName(deps, storeName);
|
|
281
|
+
const account = walletStoreAccount(address);
|
|
282
|
+
const t = timeoutsOf(deps);
|
|
283
|
+
const end = Date.now() + (deps.isTTY === true ? t.interactiveWriteMs : t.writeMs);
|
|
284
|
+
const left = () => end - Date.now();
|
|
285
|
+
const outOfTime = {
|
|
286
|
+
outcome: "uncertain",
|
|
287
|
+
detail: `the ${storeNoun(storeName)} did not answer in time`
|
|
288
|
+
};
|
|
289
|
+
let timer;
|
|
290
|
+
if (deps.isTTY === true && storeName !== "file" && deps.onWait !== void 0) {
|
|
291
|
+
const onWait = deps.onWait;
|
|
292
|
+
timer = setTimeout(() => onWait(KEYCHAIN_WAIT_LINE), t.waitLineAfterMs);
|
|
293
|
+
timer.unref?.();
|
|
294
|
+
}
|
|
295
|
+
try {
|
|
296
|
+
if (left() <= 0) return outOfTime;
|
|
297
|
+
const pre = await store.read(account, { timeoutMs: left() });
|
|
298
|
+
if (pre.kind === "locked" || pre.kind === "absent") {
|
|
299
|
+
return { outcome: "uncertain", detail: pre.detail };
|
|
300
|
+
}
|
|
301
|
+
let update = false;
|
|
302
|
+
if (pre.kind === "hit") {
|
|
303
|
+
if (pre.value === secret) return { outcome: "already-stored" };
|
|
304
|
+
if (opts.replaceIf === void 0) {
|
|
305
|
+
return { outcome: "conflict", detail: "a different passphrase is already saved there" };
|
|
306
|
+
}
|
|
307
|
+
if (!await opts.replaceIf(pre.value)) return { outcome: "kept-existing" };
|
|
308
|
+
update = true;
|
|
309
|
+
}
|
|
310
|
+
if (store.storable !== void 0 && !store.storable(secret)) {
|
|
311
|
+
return { outcome: "rejected-characters" };
|
|
312
|
+
}
|
|
313
|
+
if (left() <= 0) return outOfTime;
|
|
314
|
+
let writeError;
|
|
315
|
+
let wrote = true;
|
|
316
|
+
try {
|
|
317
|
+
await store.store(account, secret, {
|
|
318
|
+
timeoutMs: left(),
|
|
319
|
+
...update ? { update: true } : {}
|
|
320
|
+
});
|
|
321
|
+
} catch (err) {
|
|
322
|
+
wrote = false;
|
|
323
|
+
writeError = err;
|
|
324
|
+
}
|
|
325
|
+
if (left() <= 0) return outOfTime;
|
|
326
|
+
const back = await store.read(account, { timeoutMs: left() });
|
|
327
|
+
if (back.kind === "hit") {
|
|
328
|
+
return back.value === secret ? { outcome: "stored" } : { outcome: "conflict", detail: "a different passphrase is saved there after the write" };
|
|
329
|
+
}
|
|
330
|
+
if (back.kind !== "miss") return { outcome: "uncertain", detail: back.detail };
|
|
331
|
+
if (wrote) return { outcome: "store-failed", detail: "the saved passphrase did not read back" };
|
|
332
|
+
const failure = classifyStoreFailure(storeName, writeError);
|
|
333
|
+
if (isKilled(writeError)) {
|
|
334
|
+
return { outcome: "uncertain", detail: "detail" in failure ? failure.detail : void 0 };
|
|
335
|
+
}
|
|
336
|
+
return {
|
|
337
|
+
outcome: "store-failed",
|
|
338
|
+
detail: writeFailureDetail(storeName, writeError, failure)
|
|
339
|
+
};
|
|
340
|
+
} finally {
|
|
341
|
+
if (timer !== void 0) clearTimeout(timer);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
function isKilled(err) {
|
|
345
|
+
return err instanceof StoreExecError && (err.killed || err.signal !== null);
|
|
346
|
+
}
|
|
347
|
+
function writeFailureDetail(store, err, failure) {
|
|
348
|
+
if (store === "file") {
|
|
349
|
+
const code = err?.code;
|
|
350
|
+
return typeof code === "string" && /^E[A-Z]+$/.test(code) ? `the passphrase file could not be written (${code})` : "the passphrase file could not be written";
|
|
351
|
+
}
|
|
352
|
+
return "detail" in failure ? failure.detail : `the ${storeNoun(store)} write failed`;
|
|
353
|
+
}
|
|
354
|
+
function toStoreOutcome(w) {
|
|
355
|
+
switch (w) {
|
|
356
|
+
case "stored":
|
|
357
|
+
return "stored";
|
|
358
|
+
case "already-stored":
|
|
359
|
+
return "stored";
|
|
360
|
+
case "kept-existing":
|
|
361
|
+
return "store-failed";
|
|
362
|
+
case "conflict":
|
|
363
|
+
return "store-failed";
|
|
364
|
+
case "uncertain":
|
|
365
|
+
return "uncertain";
|
|
366
|
+
case "store-failed":
|
|
367
|
+
return "store-failed";
|
|
368
|
+
case "rejected-characters":
|
|
369
|
+
return "rejected-characters";
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
async function probeDurableStore(deps) {
|
|
373
|
+
const store = storeFor(deps);
|
|
374
|
+
if (store === null) {
|
|
375
|
+
return { store: "file", probe: "absent", detail: "this platform has no OS credential store" };
|
|
376
|
+
}
|
|
377
|
+
const result = await store.probe({ timeoutMs: timeoutsOf(deps).probeMs });
|
|
378
|
+
return { store: store.source, ...result };
|
|
379
|
+
}
|
|
380
|
+
async function resolvePassphraseForCreate(deps, address, opts = {}) {
|
|
381
|
+
const fromEnv = envPassphrase(deps.env);
|
|
382
|
+
const origin = fromEnv !== null ? "env" : "generated";
|
|
383
|
+
const secret = fromEnv ?? randomBytes(32).toString("base64url");
|
|
384
|
+
const account = walletStoreAccount(address);
|
|
385
|
+
const envOnly = (attempted, notSaved) => ({
|
|
386
|
+
passphrase: secret,
|
|
387
|
+
source: "env",
|
|
388
|
+
origin,
|
|
389
|
+
location: "TENJIN_WALLET_PASSPHRASE",
|
|
390
|
+
durable: false,
|
|
391
|
+
attempted,
|
|
392
|
+
notSaved
|
|
393
|
+
});
|
|
394
|
+
let target;
|
|
395
|
+
let fileReason;
|
|
396
|
+
if (opts.insecureStorage === true) {
|
|
397
|
+
target = "file";
|
|
398
|
+
fileReason = "insecure-storage";
|
|
399
|
+
} else {
|
|
400
|
+
const probed = await probeDurableStore(deps);
|
|
401
|
+
if (probed.probe === "available") {
|
|
402
|
+
target = probed.store;
|
|
403
|
+
} else if (probed.probe === "absent") {
|
|
404
|
+
target = "file";
|
|
405
|
+
fileReason = "no-keyring";
|
|
406
|
+
} else {
|
|
407
|
+
if (origin === "env") return envOnly(probed.store, "uncertain");
|
|
408
|
+
throw new CliError(
|
|
409
|
+
"REFUSED",
|
|
410
|
+
`The ${storeNoun(probed.store)} did not answer within ${Math.round(timeoutsOf(deps).probeMs / 1e3)} s; it may be locked. No wallet was created.`,
|
|
411
|
+
{ fix: KEYCHAIN_LOCKED_FIX, details: unlockDetails("keychain_locked") }
|
|
412
|
+
);
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
const written = await storeDurablyDetailed(deps, target, address, secret);
|
|
416
|
+
if (written.outcome === "stored" || written.outcome === "already-stored") {
|
|
417
|
+
return {
|
|
418
|
+
passphrase: secret,
|
|
419
|
+
source: target,
|
|
420
|
+
origin,
|
|
421
|
+
location: describeStoreLocation(target, account, deps.dir),
|
|
422
|
+
durable: true,
|
|
423
|
+
...fileReason !== void 0 ? { fileReason } : {}
|
|
424
|
+
};
|
|
425
|
+
}
|
|
426
|
+
if (origin === "env") return envOnly(target, written.outcome);
|
|
427
|
+
const detail = written.detail ?? `the ${storeNoun(target)} write failed`;
|
|
428
|
+
if (target === "file") {
|
|
429
|
+
const path = describeStoreLocation("file", account, deps.dir);
|
|
430
|
+
throw new CliError(
|
|
431
|
+
"REFUSED",
|
|
432
|
+
`Could not save the wallet passphrase to ${path} (${detail}); no wallet was created.`,
|
|
433
|
+
{
|
|
434
|
+
fix: FILE_STORE_FAILED_FIX(path),
|
|
435
|
+
details: { passphraseStore: { kind: "file-write-failed", path } }
|
|
436
|
+
}
|
|
437
|
+
);
|
|
438
|
+
}
|
|
439
|
+
throw new CliError(
|
|
440
|
+
"REFUSED",
|
|
441
|
+
`Could not save the wallet passphrase to ${describeStoreLocation(target, account, deps.dir)} (${detail}); no wallet was created.`,
|
|
442
|
+
{ fix: KEYCHAIN_LOCKED_FIX, details: unlockDetails("keychain_locked", target) }
|
|
443
|
+
);
|
|
444
|
+
}
|
|
445
|
+
function describeStoreLocation(store, account, dir) {
|
|
446
|
+
switch (store) {
|
|
447
|
+
case "keychain":
|
|
448
|
+
return `your macOS keychain (service ${KEYCHAIN_SERVICE}, account ${account})`;
|
|
449
|
+
case "secret-service":
|
|
450
|
+
return `your Linux keyring (Secret Service, service ${KEYCHAIN_SERVICE}, account ${account})`;
|
|
451
|
+
case "dpapi":
|
|
452
|
+
return `a DPAPI-encrypted file (passphrase.${account}.dpapi)`;
|
|
453
|
+
case "file":
|
|
454
|
+
return tildePath(passphraseFilePathFor(account, dir));
|
|
455
|
+
}
|
|
456
|
+
}
|
|
457
|
+
function tildePath(path) {
|
|
458
|
+
const home = homedir();
|
|
459
|
+
if (home.length > 1 && (path === home || path.startsWith(`${home}/`))) {
|
|
460
|
+
return `~${path.slice(home.length)}`;
|
|
461
|
+
}
|
|
462
|
+
return path;
|
|
463
|
+
}
|
|
464
|
+
function promptPassphrase(deps, label) {
|
|
465
|
+
return promptOf(deps)(label);
|
|
466
|
+
}
|
|
467
|
+
function keychainStore(deps) {
|
|
468
|
+
const exec = deps.exec ?? defaultExecFor();
|
|
469
|
+
return {
|
|
470
|
+
source: "keychain",
|
|
471
|
+
async read(account, o) {
|
|
472
|
+
try {
|
|
473
|
+
const { stdout } = await exec(
|
|
474
|
+
"security",
|
|
475
|
+
["find-generic-password", "-s", KEYCHAIN_SERVICE, "-a", account, "-w"],
|
|
476
|
+
void 0,
|
|
477
|
+
callOpts(o)
|
|
478
|
+
);
|
|
479
|
+
const value = oneNewlineStripped(stdout);
|
|
480
|
+
return value.length > 0 ? { kind: "hit", value } : { kind: "miss" };
|
|
481
|
+
} catch (err) {
|
|
482
|
+
return classifyStoreFailure("keychain", err);
|
|
483
|
+
}
|
|
484
|
+
},
|
|
485
|
+
// The one backend that interpolates into a command line. base64url values
|
|
486
|
+
// keep today's exact `-w '<value>'` line; any other printable-ASCII value is
|
|
487
|
+
// sent as hex, so no character of it is ever syntax. Escaping is NOT a safe
|
|
488
|
+
// alternative (backslash bites even inside single quotes there).
|
|
489
|
+
storable: (value) => PRINTABLE_ASCII_RE.test(value),
|
|
490
|
+
async store(account, value, o) {
|
|
491
|
+
if (!ACCOUNT_ADDRESS_RE.test(account) || !PRINTABLE_ASCII_RE.test(value)) {
|
|
492
|
+
throw new CliError("INTERNAL", "Refusing to send this value to the keychain writer.");
|
|
493
|
+
}
|
|
494
|
+
const secret = BASE64URL_RE.test(value) ? `-w '${value}'` : `-X ${Buffer.from(value, "utf8").toString("hex")}`;
|
|
495
|
+
const update = o?.update === true ? " -U" : "";
|
|
496
|
+
const command = `add-generic-password -s ${KEYCHAIN_SERVICE} -a ${account} ${secret}${update}
|
|
497
|
+
`;
|
|
498
|
+
await exec("security", ["-i"], command, callOpts(o));
|
|
499
|
+
},
|
|
500
|
+
async remove(account, o) {
|
|
501
|
+
try {
|
|
502
|
+
await exec(
|
|
503
|
+
"security",
|
|
504
|
+
["delete-generic-password", "-s", KEYCHAIN_SERVICE, "-a", account],
|
|
505
|
+
void 0,
|
|
506
|
+
callOpts(o)
|
|
507
|
+
);
|
|
508
|
+
return true;
|
|
509
|
+
} catch {
|
|
510
|
+
return false;
|
|
511
|
+
}
|
|
512
|
+
},
|
|
513
|
+
async probe(o) {
|
|
514
|
+
try {
|
|
515
|
+
await exec("security", ["default-keychain"], void 0, callOpts(o));
|
|
516
|
+
return { probe: "available" };
|
|
517
|
+
} catch (err) {
|
|
518
|
+
const failure = classifyStoreFailure("keychain", err);
|
|
519
|
+
if (failure.kind === "absent") return { probe: "absent", detail: failure.detail };
|
|
520
|
+
return {
|
|
521
|
+
probe: "uncertain",
|
|
522
|
+
..."detail" in failure ? { detail: failure.detail } : {}
|
|
523
|
+
};
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
}
|
|
528
|
+
var DPAPI_PROTECT_SCRIPT = [
|
|
529
|
+
"Add-Type -AssemblyName System.Security;",
|
|
530
|
+
"$in = [Console]::In.ReadToEnd();",
|
|
531
|
+
"$bytes = [System.Text.Encoding]::UTF8.GetBytes($in);",
|
|
532
|
+
"$prot = [System.Security.Cryptography.ProtectedData]::Protect($bytes, $null, 'CurrentUser');",
|
|
533
|
+
"[Console]::Out.Write([Convert]::ToBase64String($prot));"
|
|
534
|
+
].join(" ");
|
|
535
|
+
var DPAPI_UNPROTECT_SCRIPT = [
|
|
536
|
+
"Add-Type -AssemblyName System.Security;",
|
|
537
|
+
"$in = [Console]::In.ReadToEnd();",
|
|
538
|
+
"$blob = [Convert]::FromBase64String($in.Trim());",
|
|
539
|
+
"$plain = [System.Security.Cryptography.ProtectedData]::Unprotect($blob, $null, 'CurrentUser');",
|
|
540
|
+
"[Console]::Out.Write([System.Text.Encoding]::UTF8.GetString($plain));"
|
|
541
|
+
].join(" ");
|
|
542
|
+
function powershellArgs(script) {
|
|
543
|
+
return ["-NoProfile", "-NonInteractive", "-Command", script];
|
|
544
|
+
}
|
|
545
|
+
function dpapiStore(deps) {
|
|
546
|
+
const exec = deps.exec ?? defaultExecFor();
|
|
547
|
+
const blobPathFor = (account) => account === LEGACY_ACCOUNT ? passphraseBlobPath(deps.dir) : passphraseBlobPathFor(account, deps.dir);
|
|
548
|
+
return {
|
|
549
|
+
source: "dpapi",
|
|
550
|
+
async read(account, o) {
|
|
551
|
+
let blob;
|
|
552
|
+
try {
|
|
553
|
+
blob = await readFile(blobPathFor(account), "utf8");
|
|
554
|
+
} catch (err) {
|
|
555
|
+
if (hasCode(err, "ENOENT")) return { kind: "miss" };
|
|
556
|
+
return { kind: "locked", detail: "the DPAPI passphrase file could not be read" };
|
|
557
|
+
}
|
|
558
|
+
try {
|
|
559
|
+
const { stdout } = await exec(
|
|
560
|
+
"powershell.exe",
|
|
561
|
+
powershellArgs(DPAPI_UNPROTECT_SCRIPT),
|
|
562
|
+
blob,
|
|
563
|
+
callOpts(o)
|
|
564
|
+
);
|
|
565
|
+
const value = stdout.replace(/\r?\n$/, "");
|
|
566
|
+
return value.length > 0 ? { kind: "hit", value } : { kind: "miss" };
|
|
567
|
+
} catch (err) {
|
|
568
|
+
return classifyStoreFailure("dpapi", err);
|
|
569
|
+
}
|
|
570
|
+
},
|
|
571
|
+
storable: readsBackFromStdout,
|
|
572
|
+
async store(account, passphrase, o) {
|
|
573
|
+
const { stdout } = await exec(
|
|
574
|
+
"powershell.exe",
|
|
575
|
+
powershellArgs(DPAPI_PROTECT_SCRIPT),
|
|
576
|
+
passphrase,
|
|
577
|
+
callOpts(o)
|
|
578
|
+
);
|
|
579
|
+
const blob = stdout.replace(/\r?\n$/, "").trim();
|
|
580
|
+
if (blob.length === 0) throw new StoreExecError("powershell.exe", { code: 0 });
|
|
581
|
+
await writeFileAtomic(blobPathFor(account), blob, { mode: 384 });
|
|
582
|
+
},
|
|
583
|
+
async remove(account) {
|
|
584
|
+
try {
|
|
585
|
+
await unlink(blobPathFor(account));
|
|
586
|
+
return true;
|
|
587
|
+
} catch {
|
|
588
|
+
return false;
|
|
589
|
+
}
|
|
590
|
+
},
|
|
591
|
+
async probe(o) {
|
|
592
|
+
try {
|
|
593
|
+
await exec(
|
|
594
|
+
"powershell.exe",
|
|
595
|
+
["-NoProfile", "-NonInteractive", "-Command", "$null"],
|
|
596
|
+
void 0,
|
|
597
|
+
callOpts(o)
|
|
598
|
+
);
|
|
599
|
+
return { probe: "available" };
|
|
600
|
+
} catch (err) {
|
|
601
|
+
const failure = classifyStoreFailure("dpapi", err);
|
|
602
|
+
if (failure.kind === "absent") return { probe: "absent", detail: failure.detail };
|
|
603
|
+
return { probe: "available" };
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
function secretServiceStore(deps) {
|
|
609
|
+
const exec = deps.exec ?? defaultExecFor();
|
|
610
|
+
const read = async (account, o) => {
|
|
611
|
+
try {
|
|
612
|
+
const { stdout } = await exec(
|
|
613
|
+
"secret-tool",
|
|
614
|
+
["lookup", "service", KEYCHAIN_SERVICE, "account", account],
|
|
615
|
+
void 0,
|
|
616
|
+
callOpts(o)
|
|
617
|
+
);
|
|
618
|
+
const value = oneNewlineStripped(stdout);
|
|
619
|
+
return value.length > 0 ? { kind: "hit", value } : { kind: "miss" };
|
|
620
|
+
} catch (err) {
|
|
621
|
+
return classifyStoreFailure("secret-service", err);
|
|
622
|
+
}
|
|
623
|
+
};
|
|
624
|
+
return {
|
|
625
|
+
source: "secret-service",
|
|
626
|
+
read,
|
|
627
|
+
storable: readsBackFromStdout,
|
|
628
|
+
async store(account, passphrase, o) {
|
|
629
|
+
await exec(
|
|
630
|
+
"secret-tool",
|
|
631
|
+
[
|
|
632
|
+
"store",
|
|
633
|
+
`--label=tenjin-cli wallet ${account}`,
|
|
634
|
+
"service",
|
|
635
|
+
KEYCHAIN_SERVICE,
|
|
636
|
+
"account",
|
|
637
|
+
account
|
|
638
|
+
],
|
|
639
|
+
passphrase,
|
|
640
|
+
callOpts(o)
|
|
641
|
+
);
|
|
642
|
+
},
|
|
643
|
+
async remove(account, o) {
|
|
644
|
+
try {
|
|
645
|
+
await exec(
|
|
646
|
+
"secret-tool",
|
|
647
|
+
["clear", "service", KEYCHAIN_SERVICE, "account", account],
|
|
648
|
+
void 0,
|
|
649
|
+
callOpts(o)
|
|
650
|
+
);
|
|
651
|
+
return true;
|
|
652
|
+
} catch {
|
|
653
|
+
return false;
|
|
654
|
+
}
|
|
655
|
+
},
|
|
656
|
+
async probe(o) {
|
|
657
|
+
const got = await read(PROBE_ACCOUNT, o);
|
|
658
|
+
if (got.kind === "hit" || got.kind === "miss") return { probe: "available" };
|
|
659
|
+
if (got.kind === "absent") return { probe: "absent", detail: got.detail };
|
|
660
|
+
return { probe: "uncertain", detail: got.detail };
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
function fileStore(deps) {
|
|
665
|
+
const pathFor = (account) => passphraseFilePathFor(account, deps.dir);
|
|
666
|
+
return {
|
|
667
|
+
source: "file",
|
|
668
|
+
async read(account) {
|
|
669
|
+
try {
|
|
670
|
+
const value = oneLfStripped(await readFile(pathFor(account), "utf8"));
|
|
671
|
+
return value.length > 0 ? { kind: "hit", value } : { kind: "miss" };
|
|
672
|
+
} catch (err) {
|
|
673
|
+
return classifyStoreFailure("file", err);
|
|
674
|
+
}
|
|
675
|
+
},
|
|
676
|
+
// The read strips one trailing LF, so a value ending in one never reads back.
|
|
677
|
+
storable: (value) => !value.endsWith("\n"),
|
|
678
|
+
async store(account, value, o) {
|
|
679
|
+
const path = pathFor(account);
|
|
680
|
+
const mode = { mode: 384, dirMode: 448 };
|
|
681
|
+
if (o?.update === true) return writeFileAtomic(path, value, mode);
|
|
682
|
+
try {
|
|
683
|
+
await writeFileAtomicExclusive(path, value, mode);
|
|
684
|
+
} catch (err) {
|
|
685
|
+
if (!hasCode(err, "EEXIST") || (await stat(path).catch(() => null))?.size !== 0) throw err;
|
|
686
|
+
await writeFileAtomic(path, value, mode);
|
|
687
|
+
}
|
|
688
|
+
},
|
|
689
|
+
async remove(account) {
|
|
690
|
+
try {
|
|
691
|
+
await unlink(pathFor(account));
|
|
692
|
+
return true;
|
|
693
|
+
} catch {
|
|
694
|
+
return false;
|
|
695
|
+
}
|
|
696
|
+
},
|
|
697
|
+
probe: async () => ({ probe: "available" })
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
function callOpts(o) {
|
|
701
|
+
return o?.timeoutMs !== void 0 ? { timeoutMs: o.timeoutMs } : void 0;
|
|
702
|
+
}
|
|
703
|
+
function readsBackFromStdout(value) {
|
|
704
|
+
return !/[\r\n]$/.test(value);
|
|
705
|
+
}
|
|
706
|
+
function unstorableWhy(store) {
|
|
707
|
+
return store === "keychain" ? "the macOS keychain writer only stores printable ASCII passphrases" : `a passphrase that ends in a line break does not read back from the ${storeNoun(store)}`;
|
|
708
|
+
}
|
|
709
|
+
function oneNewlineStripped(stdout) {
|
|
710
|
+
return stdout.replace(/\r?\n$/, "");
|
|
711
|
+
}
|
|
712
|
+
function oneLfStripped(text) {
|
|
713
|
+
return text.endsWith("\n") ? text.slice(0, -1) : text;
|
|
714
|
+
}
|
|
715
|
+
function envPassphrase(env) {
|
|
716
|
+
const value = env.TENJIN_WALLET_PASSPHRASE;
|
|
717
|
+
return value !== void 0 && value.length > 0 ? value : null;
|
|
718
|
+
}
|
|
719
|
+
function canPrompt(deps) {
|
|
720
|
+
return deps.isTTY ?? Boolean(process.stdin.isTTY);
|
|
721
|
+
}
|
|
722
|
+
function promptOf(deps) {
|
|
723
|
+
return deps.prompt ?? promptHidden;
|
|
724
|
+
}
|
|
725
|
+
function noPassphraseError(location) {
|
|
726
|
+
return new CliError(
|
|
727
|
+
"USAGE",
|
|
728
|
+
location === void 0 ? "No wallet passphrase is available." : `No wallet passphrase is available: ${location} has no entry for this wallet.`,
|
|
729
|
+
{ fix: REPAIR_IN_TERMINAL, details: unlockDetails("passphrase_missing") }
|
|
730
|
+
);
|
|
731
|
+
}
|
|
732
|
+
function storeLockedError(store, account, detail, dir, recorded) {
|
|
733
|
+
const where = describeStoreLocation(store, account, dir);
|
|
734
|
+
return new CliError(
|
|
735
|
+
"USAGE",
|
|
736
|
+
`The passphrase store ${recorded ? "recorded " : ""}for this wallet, ${where}, did not answer (${detail}).`,
|
|
737
|
+
{
|
|
738
|
+
fix: KEYCHAIN_LOCKED_FIX,
|
|
739
|
+
details: { ...unlockDetails("keychain_locked", store), storeDetail: detail }
|
|
740
|
+
}
|
|
741
|
+
);
|
|
742
|
+
}
|
|
743
|
+
var CTRL_C = 3;
|
|
744
|
+
var CTRL_D = 4;
|
|
745
|
+
var BACKSPACE = 127;
|
|
746
|
+
var BACKSPACE_ALT = 8;
|
|
747
|
+
function promptHidden(label) {
|
|
748
|
+
return new Promise((resolve, reject) => {
|
|
749
|
+
const stdin = process.stdin;
|
|
750
|
+
const stderr = process.stderr;
|
|
751
|
+
const wasRaw = stdin.isRaw;
|
|
752
|
+
let value = "";
|
|
753
|
+
const cleanup = () => {
|
|
754
|
+
stdin.setRawMode?.(wasRaw ?? false);
|
|
755
|
+
stdin.pause();
|
|
756
|
+
stdin.removeListener("data", onData);
|
|
757
|
+
};
|
|
758
|
+
const onData = (chunk) => {
|
|
759
|
+
for (const ch of chunk.toString("utf8")) {
|
|
760
|
+
const code = ch.charCodeAt(0);
|
|
761
|
+
if (ch === "\n" || ch === "\r" || code === CTRL_D) {
|
|
762
|
+
cleanup();
|
|
763
|
+
stderr.write("\n");
|
|
764
|
+
resolve(value);
|
|
765
|
+
return;
|
|
766
|
+
}
|
|
767
|
+
if (code === CTRL_C) {
|
|
768
|
+
cleanup();
|
|
769
|
+
stderr.write("\n");
|
|
770
|
+
reject(
|
|
771
|
+
new CliError("USAGE", "Passphrase entry was cancelled.", {
|
|
772
|
+
fix: "Run the command again, or set TENJIN_WALLET_PASSPHRASE."
|
|
773
|
+
})
|
|
774
|
+
);
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
if (code === BACKSPACE || code === BACKSPACE_ALT) {
|
|
778
|
+
value = value.slice(0, -1);
|
|
779
|
+
} else {
|
|
780
|
+
value += ch;
|
|
781
|
+
}
|
|
782
|
+
}
|
|
783
|
+
};
|
|
784
|
+
stderr.write(label);
|
|
785
|
+
stdin.setRawMode?.(true);
|
|
786
|
+
stdin.resume();
|
|
787
|
+
stdin.on("data", onData);
|
|
788
|
+
});
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
export {
|
|
792
|
+
walletStoreAccount,
|
|
793
|
+
StoreExecError,
|
|
794
|
+
STORE_TIMEOUTS,
|
|
795
|
+
defaultExecFor,
|
|
796
|
+
storeNoun,
|
|
797
|
+
classifyStoreFailure,
|
|
798
|
+
readStoredPassphrase,
|
|
799
|
+
resolvePassphrase,
|
|
800
|
+
storeDurablyDetailed,
|
|
801
|
+
toStoreOutcome,
|
|
802
|
+
probeDurableStore,
|
|
803
|
+
resolvePassphraseForCreate,
|
|
804
|
+
describeStoreLocation,
|
|
805
|
+
promptPassphrase,
|
|
806
|
+
unstorableWhy
|
|
807
|
+
};
|
|
808
|
+
//# sourceMappingURL=chunk-CEXSOI5R.js.map
|