tenjin-cli 0.1.0-alpha.30 → 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.
Files changed (280) hide show
  1. package/README.md +65 -116
  2. package/dist/{_esm-CE7KNONL.js → _esm-RLLC72MS.js} +127 -131
  3. package/dist/alive-MROUMFH3.js +38 -0
  4. package/dist/auto-update-OPWMRZLS.js +22 -0
  5. package/dist/{ccip-7RMRLAGV.js → ccip-DHDFKTQV.js} +2 -2
  6. package/dist/chunk-2GNOFONN.js +560 -0
  7. package/dist/chunk-2GNOFONN.js.map +1 -0
  8. package/dist/{chunk-TTNESUPQ.js → chunk-2GP3HRYK.js} +2120 -193
  9. package/dist/chunk-2GP3HRYK.js.map +1 -0
  10. package/dist/chunk-3623BLPV.js +184 -0
  11. package/dist/chunk-3623BLPV.js.map +1 -0
  12. package/dist/chunk-3AIHRXKO.js +72 -0
  13. package/dist/chunk-3AIHRXKO.js.map +1 -0
  14. package/dist/chunk-3DIL66VX.js +120 -0
  15. package/dist/chunk-3DIL66VX.js.map +1 -0
  16. package/dist/{chunk-S4SAZ7OD.js → chunk-3FMZGI7I.js} +12 -2
  17. package/dist/{chunk-S4SAZ7OD.js.map → chunk-3FMZGI7I.js.map} +1 -1
  18. package/dist/chunk-3UCIG4TG.js +65 -0
  19. package/dist/chunk-3UCIG4TG.js.map +1 -0
  20. package/dist/{chunk-LFZJM56J.js → chunk-445VQTVM.js} +3 -3
  21. package/dist/{chunk-A36LQPHV.js → chunk-4LMUQMBH.js} +1 -1
  22. package/dist/{chunk-A36LQPHV.js.map → chunk-4LMUQMBH.js.map} +1 -1
  23. package/dist/{chunk-RAULEAZ6.js → chunk-4USCZ2NI.js} +3 -3
  24. package/dist/chunk-62KNUYWD.js +111 -0
  25. package/dist/chunk-62KNUYWD.js.map +1 -0
  26. package/dist/{chunk-POUWHWID.js → chunk-6CMM6YCB.js} +3 -3
  27. package/dist/{chunk-POUWHWID.js.map → chunk-6CMM6YCB.js.map} +1 -1
  28. package/dist/chunk-7WEQQJLG.js +68 -0
  29. package/dist/chunk-7WEQQJLG.js.map +1 -0
  30. package/dist/{chunk-3O2BQIF6.js → chunk-AD226HDR.js} +344 -534
  31. package/dist/chunk-AD226HDR.js.map +1 -0
  32. package/dist/chunk-ADV4LDTB.js +106 -0
  33. package/dist/chunk-ADV4LDTB.js.map +1 -0
  34. package/dist/{chunk-AWFUPKTM.js → chunk-AV5NZMYO.js} +15 -7
  35. package/dist/{chunk-AWFUPKTM.js.map → chunk-AV5NZMYO.js.map} +1 -1
  36. package/dist/chunk-B7EM4GGF.js +198 -0
  37. package/dist/chunk-B7EM4GGF.js.map +1 -0
  38. package/dist/chunk-BFDQ4WNW.js +119 -0
  39. package/dist/chunk-BFDQ4WNW.js.map +1 -0
  40. package/dist/{chunk-OSYTBCUC.js → chunk-BI673VEJ.js} +531 -503
  41. package/dist/chunk-BI673VEJ.js.map +1 -0
  42. package/dist/chunk-CEXSOI5R.js +808 -0
  43. package/dist/chunk-CEXSOI5R.js.map +1 -0
  44. package/dist/{chunk-OK2TDZQU.js → chunk-CISYM4EO.js} +9 -7
  45. package/dist/chunk-CISYM4EO.js.map +1 -0
  46. package/dist/{chunk-VFMQTSXG.js → chunk-D3ZURCG7.js} +3 -3
  47. package/dist/chunk-D5TOQSO4.js +474 -0
  48. package/dist/chunk-D5TOQSO4.js.map +1 -0
  49. package/dist/{chunk-P7LABKCW.js → chunk-DOQGNFHM.js} +33 -2
  50. package/dist/{chunk-P7LABKCW.js.map → chunk-DOQGNFHM.js.map} +1 -1
  51. package/dist/{chunk-QUVVWYJW.js → chunk-DRDUIZIA.js} +11 -9
  52. package/dist/{chunk-QUVVWYJW.js.map → chunk-DRDUIZIA.js.map} +1 -1
  53. package/dist/{chunk-O2FRQ2L2.js → chunk-DW4YTVR3.js} +5 -65
  54. package/dist/chunk-DW4YTVR3.js.map +1 -0
  55. package/dist/chunk-E7LGOMH6.js +449 -0
  56. package/dist/chunk-E7LGOMH6.js.map +1 -0
  57. package/dist/chunk-E7SW44LM.js +138 -0
  58. package/dist/chunk-E7SW44LM.js.map +1 -0
  59. package/dist/chunk-EDJWHDDL.js +33 -0
  60. package/dist/chunk-EDJWHDDL.js.map +1 -0
  61. package/dist/chunk-F3ED5WTR.js +13 -0
  62. package/dist/chunk-F3ED5WTR.js.map +1 -0
  63. package/dist/chunk-G75OPGAK.js +111 -0
  64. package/dist/chunk-G75OPGAK.js.map +1 -0
  65. package/dist/{chunk-YFQOA5AU.js → chunk-GAKUQHKA.js} +13 -17
  66. package/dist/{chunk-YFQOA5AU.js.map → chunk-GAKUQHKA.js.map} +1 -1
  67. package/dist/{chunk-PAYV4XUA.js → chunk-HDPUXS3Z.js} +20 -49
  68. package/dist/chunk-HDPUXS3Z.js.map +1 -0
  69. package/dist/{chunk-ORWL5BSN.js → chunk-HGZEPQUT.js} +2 -2
  70. package/dist/{chunk-HPWO4O6S.js → chunk-HREHWL32.js} +4 -4
  71. package/dist/{chunk-HPWO4O6S.js.map → chunk-HREHWL32.js.map} +1 -1
  72. package/dist/{chunk-VZGAONSJ.js → chunk-I5TDIUKM.js} +16 -35
  73. package/dist/chunk-I5TDIUKM.js.map +1 -0
  74. package/dist/{chunk-7QKHZQKW.js → chunk-IADZOXKN.js} +39 -6
  75. package/dist/chunk-IADZOXKN.js.map +1 -0
  76. package/dist/{chunk-U6YQ6FRI.js → chunk-IDTRSAHE.js} +32 -12
  77. package/dist/chunk-IDTRSAHE.js.map +1 -0
  78. package/dist/{chunk-SPAVAYSW.js → chunk-JEVQ5LKO.js} +7 -5
  79. package/dist/{chunk-SPAVAYSW.js.map → chunk-JEVQ5LKO.js.map} +1 -1
  80. package/dist/{chunk-EBVIKMCH.js → chunk-JKKAIPTU.js} +2 -2
  81. package/dist/chunk-JNJWBTU2.js +3497 -0
  82. package/dist/chunk-JNJWBTU2.js.map +1 -0
  83. package/dist/{chunk-TTBKWWTV.js → chunk-JRZBBPO6.js} +390 -146
  84. package/dist/chunk-JRZBBPO6.js.map +1 -0
  85. package/dist/{chunk-WVUSXNIE.js → chunk-MPZUYCAP.js} +9 -2
  86. package/dist/{chunk-WVUSXNIE.js.map → chunk-MPZUYCAP.js.map} +1 -1
  87. package/dist/{chunk-SJLTEINJ.js → chunk-OJNTCYQQ.js} +17 -1
  88. package/dist/chunk-OJNTCYQQ.js.map +1 -0
  89. package/dist/{chunk-IOODYAXL.js → chunk-OTWLERSW.js} +25 -6
  90. package/dist/chunk-OTWLERSW.js.map +1 -0
  91. package/dist/{chunk-AWQPGIR6.js → chunk-PJNENX2A.js} +1535 -422
  92. package/dist/chunk-PJNENX2A.js.map +1 -0
  93. package/dist/{chunk-KHE6L6TD.js → chunk-PKHI276N.js} +97 -11
  94. package/dist/chunk-PKHI276N.js.map +1 -0
  95. package/dist/{chunk-YHKXNYTB.js → chunk-QF3LSMGS.js} +2 -2
  96. package/dist/chunk-QXP3Z3JN.js +131 -0
  97. package/dist/chunk-QXP3Z3JN.js.map +1 -0
  98. package/dist/{chunk-XZKD7DIF.js → chunk-RL5UUDT4.js} +3 -3
  99. package/dist/{chunk-XZKD7DIF.js.map → chunk-RL5UUDT4.js.map} +1 -1
  100. package/dist/chunk-SFASB5FL.js +69 -0
  101. package/dist/chunk-SFASB5FL.js.map +1 -0
  102. package/dist/{chunk-WO5BJNIB.js → chunk-SNNSAGMT.js} +7273 -2741
  103. package/dist/chunk-SNNSAGMT.js.map +1 -0
  104. package/dist/{chunk-NZIP4PA2.js → chunk-SO3XRZPX.js} +3 -3
  105. package/dist/chunk-SYOS5CAC.js +176 -0
  106. package/dist/chunk-SYOS5CAC.js.map +1 -0
  107. package/dist/chunk-TAW4UFFF.js +293 -0
  108. package/dist/chunk-TAW4UFFF.js.map +1 -0
  109. package/dist/chunk-TF5HCP33.js +271 -0
  110. package/dist/chunk-TF5HCP33.js.map +1 -0
  111. package/dist/{chunk-AKWGE6JQ.js → chunk-UUGOUOVT.js} +37 -2
  112. package/dist/chunk-UUGOUOVT.js.map +1 -0
  113. package/dist/{chunk-AEG2PXBP.js → chunk-V2LQLN5H.js} +7 -7
  114. package/dist/{chunk-KYFZTGMC.js → chunk-VJUVFZ2D.js} +5 -3
  115. package/dist/{chunk-KYFZTGMC.js.map → chunk-VJUVFZ2D.js.map} +1 -1
  116. package/dist/{chunk-JMM6YE7J.js → chunk-VOZA6O7K.js} +708 -709
  117. package/dist/chunk-VOZA6O7K.js.map +1 -0
  118. package/dist/{chunk-5LJCEMFD.js → chunk-VUGQTZ2L.js} +209 -77
  119. package/dist/chunk-VUGQTZ2L.js.map +1 -0
  120. package/dist/chunk-WOM257PW.js +393 -0
  121. package/dist/chunk-WOM257PW.js.map +1 -0
  122. package/dist/chunk-WYXUQGOL.js +191 -0
  123. package/dist/chunk-WYXUQGOL.js.map +1 -0
  124. package/dist/chunk-X5ZBP3IY.js +97 -0
  125. package/dist/chunk-X5ZBP3IY.js.map +1 -0
  126. package/dist/chunk-XQJXNMSB.js +23 -0
  127. package/dist/chunk-XQJXNMSB.js.map +1 -0
  128. package/dist/chunk-Y527D4TV.js +56 -0
  129. package/dist/chunk-Y527D4TV.js.map +1 -0
  130. package/dist/{chunk-VUFAK2LW.js → chunk-YUY4SAGM.js} +17 -2
  131. package/dist/chunk-YUY4SAGM.js.map +1 -0
  132. package/dist/clack-EZ7TDWQU.js +19 -0
  133. package/dist/claude-cli-2YKABJJZ.js +31 -0
  134. package/dist/{cli-O5SN7ZJ4.js → cli-FB4LOA5A.js} +221 -68
  135. package/dist/{cli-O5SN7ZJ4.js.map → cli-FB4LOA5A.js.map} +1 -1
  136. package/dist/codex-event-TYVES3UX.js +16 -0
  137. package/dist/codex-host-WW4H2SKT.js +29 -0
  138. package/dist/codex-install-2C623HPW.js +393 -0
  139. package/dist/codex-install-2C623HPW.js.map +1 -0
  140. package/dist/{config-OJQI27LT.js → config-HOVJFEKD.js} +25 -15
  141. package/dist/doctor-NKU4V5OV.js +1312 -0
  142. package/dist/doctor-NKU4V5OV.js.map +1 -0
  143. package/dist/{env-proxy-XL4P73MZ.js → env-proxy-R6ZMLQTT.js} +6 -2
  144. package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js → ethersCompat-Df4a6QIZ-X6YZWAML.js} +3 -3
  145. package/dist/{fund-WEV6DMTD.js → fund-WEBHTZGN.js} +38 -30
  146. package/dist/{fund-WEV6DMTD.js.map → fund-WEBHTZGN.js.map} +1 -1
  147. package/dist/hook-command-ZA2PNKS6.js +44 -0
  148. package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
  149. package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +3 -2
  150. package/dist/hosts/claude/tenjin/hooks/hooks.json +4 -1
  151. package/dist/hosts/claude/tenjin/hooks/register.tsx +589 -0
  152. package/dist/hosts/claude/tenjin/skills/tenjin-pay/SKILL.md +82 -0
  153. package/dist/hosts/claude/tenjin/types/index.d.ts +41 -0
  154. package/dist/hosts/codex/.agents/plugins/marketplace.json +20 -0
  155. package/dist/hosts/codex/tenjin/.codex-plugin/plugin.json +16 -0
  156. package/dist/hosts/codex/tenjin/.mcp.json +15 -0
  157. package/dist/hosts/codex/tenjin/hooks/hooks.json +98 -0
  158. package/dist/hosts-AV5MHBAU.js +38 -0
  159. package/dist/index.js +28 -8
  160. package/dist/index.js.map +1 -1
  161. package/dist/install-PT4EZS4R.js +100 -0
  162. package/dist/{install-identity-WHPNMNMQ.js → install-identity-5A4OE6YC.js} +13 -8
  163. package/dist/install-wallet-SAAPKB73.js +281 -0
  164. package/dist/install-wallet-SAAPKB73.js.map +1 -0
  165. package/dist/{mcp-QML7ZMPH.js → mcp-HAWKCTPQ.js} +909 -208
  166. package/dist/mcp-HAWKCTPQ.js.map +1 -0
  167. package/dist/{mine.wasm-6PIT3DK6.js → mine.wasm-QFAHIFPY.js} +2 -2
  168. package/dist/{mine.wasm-6PIT3DK6.js.map → mine.wasm-QFAHIFPY.js.map} +1 -1
  169. package/dist/{package-LGKYOEPV.js → package-SR2WB6MK.js} +4 -2
  170. package/dist/passphrase-IFTDS3CU.js +44 -0
  171. package/dist/{paths-POPTXJO6.js → paths-XCSAKISU.js} +10 -2
  172. package/dist/pay-OXC3WKYV.js +55 -0
  173. package/dist/pay-OXC3WKYV.js.map +1 -0
  174. package/dist/{payments-C44QUFXU.js → payments-3KHMP2MG.js} +18 -13
  175. package/dist/{payments-C44QUFXU.js.map → payments-3KHMP2MG.js.map} +1 -1
  176. package/dist/plugin-registration-N3GRIZVM.js +67 -0
  177. package/dist/plugin-registration-N3GRIZVM.js.map +1 -0
  178. package/dist/{redact-6W23GGJC.js → redact-D7ASVWKL.js} +2 -2
  179. package/dist/redact-D7ASVWKL.js.map +1 -0
  180. package/dist/runtime-UVNUA3AS.js +1203 -0
  181. package/dist/runtime-UVNUA3AS.js.map +1 -0
  182. package/dist/runtime-fetch-EKFRNR6Z.js +20 -0
  183. package/dist/runtime-fetch-EKFRNR6Z.js.map +1 -0
  184. package/dist/runtime-layout-BDWZG2TQ.js +25 -0
  185. package/dist/runtime-layout-BDWZG2TQ.js.map +1 -0
  186. package/dist/{send-KVJX4XIR.js → send-HMKJLT34.js} +26 -18
  187. package/dist/{send-KVJX4XIR.js.map → send-HMKJLT34.js.map} +1 -1
  188. package/dist/{status-S7C3WMSH.js → status-RWXIIWYS.js} +57 -22
  189. package/dist/status-RWXIIWYS.js.map +1 -0
  190. package/dist/{status-line-YR2T5HC4.js → status-line-77XYZP7E.js} +13 -8
  191. package/dist/{status-line-YR2T5HC4.js.map → status-line-77XYZP7E.js.map} +1 -1
  192. package/dist/uninstall-D5G67UJH.js +480 -0
  193. package/dist/uninstall-D5G67UJH.js.map +1 -0
  194. package/dist/update-LRNOEGSB.js +53 -0
  195. package/dist/update-LRNOEGSB.js.map +1 -0
  196. package/dist/{usdc-JK4RRFFQ.js → usdc-D6X7EIQ2.js} +7 -8
  197. package/dist/usdc-D6X7EIQ2.js.map +1 -0
  198. package/dist/{viemAdapter-By13KInL-X2VY6CY3.js → viemAdapter-By13KInL-RL742ETX.js} +3 -3
  199. package/dist/viemAdapter-By13KInL-RL742ETX.js.map +1 -0
  200. package/dist/wallet-XFYC27BR.js +55 -0
  201. package/dist/wallet-XFYC27BR.js.map +1 -0
  202. package/dist/wallet-kdf-worker.mjs +8 -8
  203. package/docs/agent-permissions.md +56 -22
  204. package/docs/safety-model.md +1 -1
  205. package/docs/troubleshooting.md +72 -1
  206. package/package.json +14 -1
  207. package/dist/alive-3J3CHOQP.js +0 -21
  208. package/dist/ccip-NLCSCHKI.js +0 -19
  209. package/dist/chunk-3O2BQIF6.js.map +0 -1
  210. package/dist/chunk-5IEP5EGE.js +0 -5332
  211. package/dist/chunk-5IEP5EGE.js.map +0 -1
  212. package/dist/chunk-5LJCEMFD.js.map +0 -1
  213. package/dist/chunk-6W5GYG3W.js +0 -128
  214. package/dist/chunk-6W5GYG3W.js.map +0 -1
  215. package/dist/chunk-7EKYXMUO.js +0 -7536
  216. package/dist/chunk-7EKYXMUO.js.map +0 -1
  217. package/dist/chunk-7QKHZQKW.js.map +0 -1
  218. package/dist/chunk-AKWGE6JQ.js.map +0 -1
  219. package/dist/chunk-AWQPGIR6.js.map +0 -1
  220. package/dist/chunk-EGELTSPU.js +0 -2865
  221. package/dist/chunk-EGELTSPU.js.map +0 -1
  222. package/dist/chunk-EL56RW2J.js +0 -7611
  223. package/dist/chunk-EL56RW2J.js.map +0 -1
  224. package/dist/chunk-HE2MS4QO.js +0 -256
  225. package/dist/chunk-HE2MS4QO.js.map +0 -1
  226. package/dist/chunk-IOODYAXL.js.map +0 -1
  227. package/dist/chunk-JMM6YE7J.js.map +0 -1
  228. package/dist/chunk-KHE6L6TD.js.map +0 -1
  229. package/dist/chunk-N35E6CM2.js +0 -1185
  230. package/dist/chunk-N35E6CM2.js.map +0 -1
  231. package/dist/chunk-O2FRQ2L2.js.map +0 -1
  232. package/dist/chunk-OK2TDZQU.js.map +0 -1
  233. package/dist/chunk-OSYTBCUC.js.map +0 -1
  234. package/dist/chunk-PAYV4XUA.js.map +0 -1
  235. package/dist/chunk-SJLTEINJ.js.map +0 -1
  236. package/dist/chunk-TTBKWWTV.js.map +0 -1
  237. package/dist/chunk-TTNESUPQ.js.map +0 -1
  238. package/dist/chunk-U6YQ6FRI.js.map +0 -1
  239. package/dist/chunk-VUFAK2LW.js.map +0 -1
  240. package/dist/chunk-VZGAONSJ.js.map +0 -1
  241. package/dist/chunk-WO5BJNIB.js.map +0 -1
  242. package/dist/doctor-IQQJHGGM.js +0 -590
  243. package/dist/doctor-IQQJHGGM.js.map +0 -1
  244. package/dist/hook-command-D2P3ILRV.js +0 -32
  245. package/dist/install-TUCRF32I.js +0 -60
  246. package/dist/install-wallet-MA27FTQ5.js +0 -113
  247. package/dist/install-wallet-MA27FTQ5.js.map +0 -1
  248. package/dist/mcp-QML7ZMPH.js.map +0 -1
  249. package/dist/pay-2C2UBBXJ.js +0 -51
  250. package/dist/status-S7C3WMSH.js.map +0 -1
  251. package/dist/uninstall-HY6LKIIT.js +0 -149
  252. package/dist/uninstall-HY6LKIIT.js.map +0 -1
  253. package/dist/update-OJV22LR3.js +0 -36
  254. package/dist/wallet-PD2IMZDU.js +0 -39
  255. /package/dist/{_esm-CE7KNONL.js.map → _esm-RLLC72MS.js.map} +0 -0
  256. /package/dist/{alive-3J3CHOQP.js.map → alive-MROUMFH3.js.map} +0 -0
  257. /package/dist/{ccip-7RMRLAGV.js.map → auto-update-OPWMRZLS.js.map} +0 -0
  258. /package/dist/{ccip-NLCSCHKI.js.map → ccip-DHDFKTQV.js.map} +0 -0
  259. /package/dist/{chunk-LFZJM56J.js.map → chunk-445VQTVM.js.map} +0 -0
  260. /package/dist/{chunk-RAULEAZ6.js.map → chunk-4USCZ2NI.js.map} +0 -0
  261. /package/dist/{chunk-VFMQTSXG.js.map → chunk-D3ZURCG7.js.map} +0 -0
  262. /package/dist/{chunk-ORWL5BSN.js.map → chunk-HGZEPQUT.js.map} +0 -0
  263. /package/dist/{chunk-EBVIKMCH.js.map → chunk-JKKAIPTU.js.map} +0 -0
  264. /package/dist/{chunk-YHKXNYTB.js.map → chunk-QF3LSMGS.js.map} +0 -0
  265. /package/dist/{chunk-NZIP4PA2.js.map → chunk-SO3XRZPX.js.map} +0 -0
  266. /package/dist/{chunk-AEG2PXBP.js.map → chunk-V2LQLN5H.js.map} +0 -0
  267. /package/dist/{config-OJQI27LT.js.map → clack-EZ7TDWQU.js.map} +0 -0
  268. /package/dist/{env-proxy-XL4P73MZ.js.map → claude-cli-2YKABJJZ.js.map} +0 -0
  269. /package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js.map → codex-event-TYVES3UX.js.map} +0 -0
  270. /package/dist/{hook-command-D2P3ILRV.js.map → codex-host-WW4H2SKT.js.map} +0 -0
  271. /package/dist/{install-TUCRF32I.js.map → config-HOVJFEKD.js.map} +0 -0
  272. /package/dist/{install-identity-WHPNMNMQ.js.map → env-proxy-R6ZMLQTT.js.map} +0 -0
  273. /package/dist/{package-LGKYOEPV.js.map → ethersCompat-Df4a6QIZ-X6YZWAML.js.map} +0 -0
  274. /package/dist/{paths-POPTXJO6.js.map → hook-command-ZA2PNKS6.js.map} +0 -0
  275. /package/dist/{pay-2C2UBBXJ.js.map → hosts-AV5MHBAU.js.map} +0 -0
  276. /package/dist/{redact-6W23GGJC.js.map → install-PT4EZS4R.js.map} +0 -0
  277. /package/dist/{update-OJV22LR3.js.map → install-identity-5A4OE6YC.js.map} +0 -0
  278. /package/dist/{usdc-JK4RRFFQ.js.map → package-SR2WB6MK.js.map} +0 -0
  279. /package/dist/{viemAdapter-By13KInL-X2VY6CY3.js.map → passphrase-IFTDS3CU.js.map} +0 -0
  280. /package/dist/{wallet-PD2IMZDU.js.map → paths-XCSAKISU.js.map} +0 -0
@@ -1,10 +1,22 @@
1
1
  import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
2
  import {
3
3
  createLocalSpendAuthorizer
4
- } from "./chunk-AEG2PXBP.js";
4
+ } from "./chunk-V2LQLN5H.js";
5
5
  import {
6
6
  emitNotice
7
- } from "./chunk-KYFZTGMC.js";
7
+ } from "./chunk-VJUVFZ2D.js";
8
+ import {
9
+ STORE_TIMEOUTS,
10
+ describeStoreLocation,
11
+ probeDurableStore,
12
+ readStoredPassphrase,
13
+ resolvePassphrase,
14
+ storeDurablyDetailed,
15
+ storeNoun,
16
+ toStoreOutcome,
17
+ unstorableWhy,
18
+ walletStoreAccount
19
+ } from "./chunk-CEXSOI5R.js";
8
20
  import {
9
21
  hashAuthorization,
10
22
  hashMessage,
@@ -13,7 +25,7 @@ import {
13
25
  publicKeyToAddress,
14
26
  serializeSignature,
15
27
  serializeTransaction
16
- } from "./chunk-N35E6CM2.js";
28
+ } from "./chunk-PJNENX2A.js";
17
29
  import {
18
30
  hmac,
19
31
  secp256k1,
@@ -33,7 +45,7 @@ import {
33
45
  slice3 as slice,
34
46
  toHex,
35
47
  toHex2
36
- } from "./chunk-EGELTSPU.js";
48
+ } from "./chunk-2GP3HRYK.js";
37
49
  import {
38
50
  ahash,
39
51
  anumber,
@@ -46,29 +58,42 @@ import {
46
58
  swap32IfBE,
47
59
  u32
48
60
  } from "./chunk-BPMWXTFX.js";
61
+ import {
62
+ readPassphraseRecord,
63
+ writePassphraseRecord
64
+ } from "./chunk-3AIHRXKO.js";
65
+ import {
66
+ ENV_PASSPHRASE_WRONG,
67
+ FILE_STORE_FAILED_FIX,
68
+ KEYCHAIN_LOCKED_FIX,
69
+ PRIVATE_KEY_RE,
70
+ REPAIR_CLAUSE,
71
+ REPAIR_IN_TERMINAL,
72
+ unlockDetails,
73
+ unlockReasonOf
74
+ } from "./chunk-X5ZBP3IY.js";
49
75
  import {
50
76
  hasCode
51
77
  } from "./chunk-2I4QTOLB.js";
52
78
  import {
53
- CliError,
54
79
  external_exports
55
- } from "./chunk-WO5BJNIB.js";
80
+ } from "./chunk-SNNSAGMT.js";
56
81
  import {
57
82
  fsyncDir,
58
- writeFileAtomic,
59
83
  writeFileAtomicExclusive
60
- } from "./chunk-O2FRQ2L2.js";
84
+ } from "./chunk-7WEQQJLG.js";
85
+ import {
86
+ CliError
87
+ } from "./chunk-3UCIG4TG.js";
61
88
  import {
62
89
  archivedWalletPath,
63
- passphraseBlobPath,
64
- passphraseBlobPathFor,
90
+ passphraseFilePathFor,
65
91
  spendLedgerPath,
66
92
  walletPath
67
- } from "./chunk-SJLTEINJ.js";
93
+ } from "./chunk-OJNTCYQQ.js";
68
94
 
69
95
  // src/lib/wallet/store.ts
70
96
  import { readFile, stat } from "node:fs/promises";
71
- var PRIVATE_KEY_RE = /^0x[0-9a-f]{64}$/i;
72
97
  var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
73
98
  var KeystoreV3Schema = external_exports.object({
74
99
  crypto: external_exports.object({
@@ -110,7 +135,8 @@ async function readWalletRecord(dir) {
110
135
  if (isNotFound(err)) return null;
111
136
  throw new CliError("WALLET_INVALID_KEY", `Could not read the wallet file at ${path}.`, {
112
137
  fix: `Check file permissions on ${path}.`,
113
- cause: err
138
+ cause: err,
139
+ details: unlockDetails("wallet_corrupt")
114
140
  });
115
141
  }
116
142
  let json;
@@ -119,7 +145,8 @@ async function readWalletRecord(dir) {
119
145
  } catch (err) {
120
146
  throw new CliError("WALLET_INVALID_KEY", `The wallet file at ${path} is not valid JSON.`, {
121
147
  fix: `Move ${path} aside, then run \`tenjin wallet create\`.`,
122
- cause: err
148
+ cause: err,
149
+ details: unlockDetails("wallet_corrupt")
123
150
  });
124
151
  }
125
152
  if (isPreEncryptionRecord(json)) {
@@ -127,7 +154,8 @@ async function readWalletRecord(dir) {
127
154
  "WALLET_INVALID_KEY",
128
155
  `The wallet file at ${path} predates encrypted storage.`,
129
156
  {
130
- fix: `Move ${path} aside and run \`tenjin wallet create\`; sweep any funds from the old address first.`
157
+ fix: `Move ${path} aside and run \`tenjin wallet create\`; sweep any funds from the old address first.`,
158
+ details: unlockDetails("wallet_corrupt")
131
159
  }
132
160
  );
133
161
  }
@@ -189,344 +217,8 @@ function isNotFound(err) {
189
217
  return hasCode(err, "ENOENT");
190
218
  }
191
219
 
192
- // src/lib/wallet/passphrase.ts
193
- import { execFile } from "node:child_process";
194
- import { randomBytes } from "node:crypto";
195
- import { readFile as readFile2, unlink } from "node:fs/promises";
196
- var KEYCHAIN_SERVICE = "tenjin-cli";
197
- var LEGACY_ACCOUNT = "wallet";
198
- var ACCOUNT_ADDRESS_RE = /^0x[0-9a-f]{40}$/;
199
- var BASE64URL_RE = /^[A-Za-z0-9_-]+$/;
200
- function walletStoreAccount(address) {
201
- const account = address.toLowerCase();
202
- if (!ACCOUNT_ADDRESS_RE.test(account)) {
203
- throw new CliError("INTERNAL", `Not a valid wallet address for passphrase storage: ${address}`);
204
- }
205
- return account;
206
- }
207
- function defaultExecFor(timeoutMs) {
208
- return (file, args, stdin) => new Promise((resolve, reject) => {
209
- const child = execFile(
210
- file,
211
- args,
212
- { encoding: "utf8", ...timeoutMs !== void 0 ? { timeout: timeoutMs } : {} },
213
- (err, stdout, stderr) => {
214
- if (err) reject(err);
215
- else resolve({ stdout, stderr });
216
- }
217
- );
218
- if (stdin !== void 0) {
219
- child.stdin?.on("error", () => void 0);
220
- child.stdin?.end(stdin);
221
- }
222
- });
223
- }
224
- function storeFor(deps) {
225
- switch (deps.platform ?? process.platform) {
226
- case "darwin":
227
- return keychainStore(deps);
228
- case "win32":
229
- return dpapiStore(deps);
230
- case "linux":
231
- return secretServiceStore(deps);
232
- default:
233
- return null;
234
- }
235
- }
236
- async function resolvePassphrase(deps, address) {
237
- const fromEnv = envPassphrase(deps.env);
238
- if (fromEnv !== null) return { passphrase: fromEnv, source: "env" };
239
- const store = storeFor(deps);
240
- if (store !== null) {
241
- const account = walletStoreAccount(address);
242
- const own = await store.read(account);
243
- if (own !== null) return { passphrase: own, source: store.source };
244
- const legacy = await store.read(LEGACY_ACCOUNT);
245
- if (legacy !== null) {
246
- return {
247
- passphrase: legacy,
248
- source: store.source,
249
- migrateLegacy: () => migrateLegacyEntry(store, account, legacy)
250
- };
251
- }
252
- }
253
- if (canPrompt(deps)) {
254
- const entered = await promptOf(deps)("Wallet passphrase: ");
255
- if (entered.length === 0) throw noPassphraseError();
256
- return { passphrase: entered, source: "prompt" };
257
- }
258
- throw noPassphraseError();
259
- }
260
- async function migrateLegacyEntry(store, account, passphrase) {
261
- if (!await store.store(account, passphrase)) return false;
262
- if (await store.read(account) !== passphrase) return false;
263
- await store.remove(LEGACY_ACCOUNT);
264
- return true;
265
- }
266
- async function storePassphraseForWallet(deps, address, passphrase) {
267
- const store = storeFor(deps);
268
- if (store === null) return "no-store";
269
- const account = walletStoreAccount(address);
270
- if (await store.read(account) === passphrase) return "stored";
271
- if (store.storable !== void 0 && !store.storable(passphrase)) return "rejected-characters";
272
- if (!await store.store(account, passphrase)) return "store-failed";
273
- return await store.read(account) === passphrase ? "stored" : "store-failed";
274
- }
275
- async function resolvePassphraseForCreate(deps, address) {
276
- const fromEnv = envPassphrase(deps.env);
277
- if (fromEnv !== null) return { passphrase: fromEnv, source: "env" };
278
- const store = storeFor(deps);
279
- if (store !== null) {
280
- const account = walletStoreAccount(address);
281
- const generated = randomBytes(32).toString("base64url");
282
- if (await store.store(account, generated) && await store.read(account) === generated) {
283
- return { passphrase: generated, source: store.source };
284
- }
285
- }
286
- if (canPrompt(deps)) {
287
- const prompt = promptOf(deps);
288
- const first = await prompt("Set a wallet passphrase: ");
289
- if (first.length === 0) {
290
- throw new CliError("USAGE", "The wallet passphrase must not be empty.", {
291
- fix: "Enter a non-empty passphrase, or set TENJIN_WALLET_PASSPHRASE."
292
- });
293
- }
294
- const second = await prompt("Confirm passphrase: ");
295
- if (first !== second) {
296
- throw new CliError("USAGE", "The passphrases did not match.", {
297
- fix: "Run `tenjin wallet create` again and enter the same passphrase both times."
298
- });
299
- }
300
- return { passphrase: first, source: "prompt" };
301
- }
302
- throw noPassphraseError();
303
- }
304
- function keychainStore(deps) {
305
- const exec = deps.exec ?? defaultExecFor(deps.timeoutMs);
306
- return {
307
- source: "keychain",
308
- async read(account) {
309
- try {
310
- const { stdout } = await exec("security", [
311
- "find-generic-password",
312
- "-s",
313
- KEYCHAIN_SERVICE,
314
- "-a",
315
- account,
316
- "-w"
317
- ]);
318
- return trimmedNonEmpty(stdout);
319
- } catch {
320
- return null;
321
- }
322
- },
323
- // The one backend that interpolates into a command line, so only base64url
324
- // values pass; escaping is NOT a safe alternative (backslash bites even
325
- // inside single quotes there).
326
- storable: (passphrase) => BASE64URL_RE.test(passphrase),
327
- async store(account, passphrase) {
328
- if (!BASE64URL_RE.test(passphrase) || !BASE64URL_RE.test(account)) return false;
329
- try {
330
- const command = `add-generic-password -s ${KEYCHAIN_SERVICE} -a ${account} -w '${passphrase}'
331
- `;
332
- await exec("security", ["-i"], command);
333
- return true;
334
- } catch {
335
- return false;
336
- }
337
- },
338
- async remove(account) {
339
- try {
340
- await exec("security", ["delete-generic-password", "-s", KEYCHAIN_SERVICE, "-a", account]);
341
- return true;
342
- } catch {
343
- return false;
344
- }
345
- }
346
- };
347
- }
348
- var DPAPI_PROTECT_SCRIPT = [
349
- "Add-Type -AssemblyName System.Security;",
350
- "$in = [Console]::In.ReadToEnd();",
351
- "$bytes = [System.Text.Encoding]::UTF8.GetBytes($in);",
352
- "$prot = [System.Security.Cryptography.ProtectedData]::Protect($bytes, $null, 'CurrentUser');",
353
- "[Console]::Out.Write([Convert]::ToBase64String($prot));"
354
- ].join(" ");
355
- var DPAPI_UNPROTECT_SCRIPT = [
356
- "Add-Type -AssemblyName System.Security;",
357
- "$in = [Console]::In.ReadToEnd();",
358
- "$blob = [Convert]::FromBase64String($in.Trim());",
359
- "$plain = [System.Security.Cryptography.ProtectedData]::Unprotect($blob, $null, 'CurrentUser');",
360
- "[Console]::Out.Write([System.Text.Encoding]::UTF8.GetString($plain));"
361
- ].join(" ");
362
- function powershellArgs(script) {
363
- return ["-NoProfile", "-NonInteractive", "-Command", script];
364
- }
365
- function dpapiStore(deps) {
366
- const exec = deps.exec ?? defaultExecFor(deps.timeoutMs);
367
- const blobPathFor = (account) => account === LEGACY_ACCOUNT ? passphraseBlobPath(deps.dir) : passphraseBlobPathFor(account, deps.dir);
368
- return {
369
- source: "dpapi",
370
- async read(account) {
371
- let blob;
372
- try {
373
- blob = await readFile2(blobPathFor(account), "utf8");
374
- } catch {
375
- return null;
376
- }
377
- try {
378
- const { stdout } = await exec(
379
- "powershell.exe",
380
- powershellArgs(DPAPI_UNPROTECT_SCRIPT),
381
- blob
382
- );
383
- const passphrase = stdout.replace(/\r?\n$/, "");
384
- return passphrase.length > 0 ? passphrase : null;
385
- } catch {
386
- return null;
387
- }
388
- },
389
- async store(account, passphrase) {
390
- try {
391
- const { stdout } = await exec(
392
- "powershell.exe",
393
- powershellArgs(DPAPI_PROTECT_SCRIPT),
394
- passphrase
395
- );
396
- const blob = stdout.replace(/\r?\n$/, "").trim();
397
- if (blob.length === 0) return false;
398
- await writeFileAtomic(blobPathFor(account), blob, { mode: 384 });
399
- return true;
400
- } catch {
401
- return false;
402
- }
403
- },
404
- async remove(account) {
405
- try {
406
- await unlink(blobPathFor(account));
407
- return true;
408
- } catch {
409
- return false;
410
- }
411
- }
412
- };
413
- }
414
- function secretServiceStore(deps) {
415
- const exec = deps.exec ?? defaultExecFor(deps.timeoutMs);
416
- return {
417
- source: "secret-service",
418
- async read(account) {
419
- try {
420
- const { stdout } = await exec("secret-tool", [
421
- "lookup",
422
- "service",
423
- KEYCHAIN_SERVICE,
424
- "account",
425
- account
426
- ]);
427
- return trimmedNonEmpty(stdout);
428
- } catch {
429
- return null;
430
- }
431
- },
432
- async store(account, passphrase) {
433
- try {
434
- await exec(
435
- "secret-tool",
436
- [
437
- "store",
438
- `--label=tenjin-cli wallet ${account}`,
439
- "service",
440
- KEYCHAIN_SERVICE,
441
- "account",
442
- account
443
- ],
444
- passphrase
445
- );
446
- return true;
447
- } catch {
448
- return false;
449
- }
450
- },
451
- async remove(account) {
452
- try {
453
- await exec("secret-tool", ["clear", "service", KEYCHAIN_SERVICE, "account", account]);
454
- return true;
455
- } catch {
456
- return false;
457
- }
458
- }
459
- };
460
- }
461
- function trimmedNonEmpty(stdout) {
462
- const value = stdout.replace(/\r?\n$/, "");
463
- return value.length > 0 ? value : null;
464
- }
465
- function envPassphrase(env) {
466
- const value = env.TENJIN_WALLET_PASSPHRASE;
467
- return value !== void 0 && value.length > 0 ? value : null;
468
- }
469
- function canPrompt(deps) {
470
- return deps.isTTY ?? Boolean(process.stdin.isTTY);
471
- }
472
- function promptOf(deps) {
473
- return deps.prompt ?? promptHidden;
474
- }
475
- function noPassphraseError() {
476
- return new CliError("USAGE", "No wallet passphrase is available.", {
477
- fix: "Set TENJIN_WALLET_PASSPHRASE (headless) or run in a terminal."
478
- });
479
- }
480
- var CTRL_C = 3;
481
- var CTRL_D = 4;
482
- var BACKSPACE = 127;
483
- var BACKSPACE_ALT = 8;
484
- function promptHidden(label) {
485
- return new Promise((resolve, reject) => {
486
- const stdin = process.stdin;
487
- const stderr = process.stderr;
488
- const wasRaw = stdin.isRaw;
489
- let value = "";
490
- const cleanup = () => {
491
- stdin.setRawMode?.(wasRaw ?? false);
492
- stdin.pause();
493
- stdin.removeListener("data", onData);
494
- };
495
- const onData = (chunk) => {
496
- for (const ch of chunk.toString("utf8")) {
497
- const code = ch.charCodeAt(0);
498
- if (ch === "\n" || ch === "\r" || code === CTRL_D) {
499
- cleanup();
500
- stderr.write("\n");
501
- resolve(value);
502
- return;
503
- }
504
- if (code === CTRL_C) {
505
- cleanup();
506
- stderr.write("\n");
507
- reject(
508
- new CliError("USAGE", "Passphrase entry was cancelled.", {
509
- fix: "Run the command again, or set TENJIN_WALLET_PASSPHRASE."
510
- })
511
- );
512
- return;
513
- }
514
- if (code === BACKSPACE || code === BACKSPACE_ALT) {
515
- value = value.slice(0, -1);
516
- } else {
517
- value += ch;
518
- }
519
- }
520
- };
521
- stderr.write(label);
522
- stdin.setRawMode?.(true);
523
- stdin.resume();
524
- stdin.on("data", onData);
525
- });
526
- }
527
-
528
220
  // src/lib/wallet/local.ts
529
- import { link, readdir, unlink as unlink2 } from "node:fs/promises";
221
+ import { link, readdir, stat as stat2, unlink } from "node:fs/promises";
530
222
 
531
223
  // node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/pbkdf2.js
532
224
  function pbkdf2Init(hash, _password, _salt, _opts) {
@@ -573,12 +265,12 @@ function pbkdf2(hash, password, salt, opts) {
573
265
  return pbkdf2Output(PRF, PRFSalt, DK, prfW, u);
574
266
  }
575
267
 
576
- // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/_esm/accounts/generatePrivateKey.js
268
+ // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.6.7/node_modules/viem/_esm/accounts/generatePrivateKey.js
577
269
  function generatePrivateKey() {
578
270
  return toHex(secp256k1.utils.randomPrivateKey());
579
271
  }
580
272
 
581
- // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/_esm/accounts/toAccount.js
273
+ // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.6.7/node_modules/viem/_esm/accounts/toAccount.js
582
274
  function toAccount(source) {
583
275
  if (typeof source === "string") {
584
276
  if (!isAddress(source, { strict: false }))
@@ -603,7 +295,7 @@ function toAccount(source) {
603
295
  };
604
296
  }
605
297
 
606
- // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/_esm/accounts/utils/sign.js
298
+ // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.6.7/node_modules/viem/_esm/accounts/utils/sign.js
607
299
  var extraEntropy = false;
608
300
  async function sign({ hash, privateKey, to = "object" }) {
609
301
  const { r, s, recovery } = secp256k1.sign(hash.slice(2), privateKey.slice(2), {
@@ -623,7 +315,7 @@ async function sign({ hash, privateKey, to = "object" }) {
623
315
  })();
624
316
  }
625
317
 
626
- // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/_esm/accounts/utils/signAuthorization.js
318
+ // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.6.7/node_modules/viem/_esm/accounts/utils/signAuthorization.js
627
319
  async function signAuthorization(parameters) {
628
320
  const { chainId, nonce, privateKey, to = "object" } = parameters;
629
321
  const address = parameters.contractAddress ?? parameters.address;
@@ -642,12 +334,12 @@ async function signAuthorization(parameters) {
642
334
  return signature;
643
335
  }
644
336
 
645
- // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/_esm/accounts/utils/signMessage.js
337
+ // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.6.7/node_modules/viem/_esm/accounts/utils/signMessage.js
646
338
  async function signMessage({ message, privateKey }) {
647
339
  return await sign({ hash: hashMessage(message), privateKey, to: "hex" });
648
340
  }
649
341
 
650
- // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/_esm/accounts/utils/signTransaction.js
342
+ // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.6.7/node_modules/viem/_esm/accounts/utils/signTransaction.js
651
343
  async function signTransaction(parameters) {
652
344
  const { privateKey, transaction, serializer = serializeTransaction } = parameters;
653
345
  const signableTransaction = (() => {
@@ -665,7 +357,7 @@ async function signTransaction(parameters) {
665
357
  return await serializer(transaction, signature);
666
358
  }
667
359
 
668
- // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/_esm/accounts/utils/signTypedData.js
360
+ // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.6.7/node_modules/viem/_esm/accounts/utils/signTypedData.js
669
361
  async function signTypedData(parameters) {
670
362
  const { privateKey, ...typedData } = parameters;
671
363
  return await sign({
@@ -675,7 +367,7 @@ async function signTypedData(parameters) {
675
367
  });
676
368
  }
677
369
 
678
- // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/_esm/accounts/privateKeyToAccount.js
370
+ // node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.6.7/node_modules/viem/_esm/accounts/privateKeyToAccount.js
679
371
  function privateKeyToAccount(privateKey, options = {}) {
680
372
  const { nonceManager } = options;
681
373
  const publicKey = toHex(secp256k1.getPublicKey(privateKey.slice(2), false));
@@ -1120,7 +812,7 @@ async function scryptAsync(password, salt, opts) {
1120
812
  return scryptOutput(password, dkLen, B, V, tmp);
1121
813
  }
1122
814
 
1123
- // node_modules/.pnpm/ox@0.14.30_typescript@6.0.3_zod@4.4.3/node_modules/ox/_esm/core/Keystore.js
815
+ // node_modules/.pnpm/ox@0.14.30_typescript@6.0.3_zod@4.6.7/node_modules/ox/_esm/core/Keystore.js
1124
816
  function decrypt(keystore, key, options = {}) {
1125
817
  const { as = "Hex" } = options;
1126
818
  const key_ = from(typeof key === "function" ? key() : key);
@@ -1156,21 +848,6 @@ function encrypt2(privateKey, key, options) {
1156
848
  version: 3
1157
849
  };
1158
850
  }
1159
- function pbkdf22(options) {
1160
- const { iv, iterations = 262144, password } = options;
1161
- const salt = options.salt ? from(options.salt) : random(32);
1162
- const key = toHex2(pbkdf2(sha256, password, salt, { c: iterations, dkLen: 32 }));
1163
- return defineKey(() => key, {
1164
- iv,
1165
- kdfparams: {
1166
- c: iterations,
1167
- dklen: 32,
1168
- prf: "hmac-sha256",
1169
- salt: toHex2(salt).slice(2)
1170
- },
1171
- kdf: "pbkdf2"
1172
- });
1173
- }
1174
851
  async function scryptAsync2(options) {
1175
852
  const { iv, n = 262144, password } = options;
1176
853
  const p = 8;
@@ -1189,36 +866,6 @@ async function scryptAsync2(options) {
1189
866
  kdf: "scrypt"
1190
867
  });
1191
868
  }
1192
- async function toKeyAsync(keystore, options) {
1193
- const { crypto: crypto2 } = keystore;
1194
- const { password } = options;
1195
- const { cipherparams, kdf, kdfparams } = crypto2;
1196
- const { iv } = cipherparams;
1197
- const { c, n, p, r, salt } = kdfparams;
1198
- const [key] = await (async () => {
1199
- switch (kdf) {
1200
- case "scrypt":
1201
- return await scryptAsync2({
1202
- iv: from(`0x${iv}`),
1203
- n,
1204
- p,
1205
- r,
1206
- salt: from(`0x${salt}`),
1207
- password
1208
- });
1209
- case "pbkdf2":
1210
- return await pbkdf22({
1211
- iv: from(`0x${iv}`),
1212
- iterations: c,
1213
- password,
1214
- salt: from(`0x${salt}`)
1215
- });
1216
- default:
1217
- throw new Error("unsupported kdf");
1218
- }
1219
- })();
1220
- return key;
1221
- }
1222
869
  function defineKey(key, options) {
1223
870
  const iv = options.iv ? from(options.iv) : random(16);
1224
871
  return [key, { ...options, iv }];
@@ -1275,9 +922,14 @@ function derivationError(name) {
1275
922
  // src/lib/wallet/local.ts
1276
923
  var isWindows = process.platform === "win32";
1277
924
  var KEY_STORAGE = "encrypted (keystore v3, scrypt)";
1278
- var STORE_READ_TIMEOUT_MS = 5e3;
1279
925
  var signerCache = /* @__PURE__ */ new Map();
1280
926
  function createLocalProvider(deps) {
927
+ const warned = /* @__PURE__ */ new Set();
928
+ const warnOnce = (keystoreId) => {
929
+ if (warned.has(keystoreId)) return;
930
+ warned.add(keystoreId);
931
+ deps.onWarning?.({ code: "env_passphrase_wrong", message: ENV_PASSPHRASE_WRONG });
932
+ };
1281
933
  return {
1282
934
  id: "local",
1283
935
  async describe() {
@@ -1294,7 +946,7 @@ function createLocalProvider(deps) {
1294
946
  },
1295
947
  async getSigner() {
1296
948
  const cred = await credentialOrThrow(deps);
1297
- const account = await accountForSigning(cred, deps);
949
+ const account = await accountForSigning(cred, deps, warnOnce);
1298
950
  return {
1299
951
  address: account.address,
1300
952
  signMessage: (args) => account.signMessage({ message: args.message }),
@@ -1310,70 +962,186 @@ function createLocalProvider(deps) {
1310
962
  }
1311
963
  };
1312
964
  }
965
+ async function openKeystoreAccount(keystore, address, passphrase, derivation) {
966
+ let key;
967
+ try {
968
+ const derived = await deriveKeystoreKey(keystore, passphrase, derivation);
969
+ key = decrypt(keystore, derived);
970
+ } catch (err) {
971
+ if (isCancellation(err)) throw err;
972
+ return { kind: "wrong", cause: err };
973
+ }
974
+ let account;
975
+ try {
976
+ account = privateKeyToAccount(key);
977
+ } catch (err) {
978
+ return { kind: "mismatch", derived: null, cause: err };
979
+ }
980
+ if (account.address.toLowerCase() !== address.toLowerCase()) {
981
+ return { kind: "mismatch", derived: account.address };
982
+ }
983
+ return { kind: "ok", account };
984
+ }
985
+ async function openKeystore(keystore, address, passphrase, derivation) {
986
+ return (await openKeystoreAccount(keystore, address, passphrase, derivation)).kind;
987
+ }
988
+ function isCancellation(err) {
989
+ return err instanceof Error && ["AbortError", "TimeoutError"].includes(err.name);
990
+ }
991
+ var ENV_WRONG_FIX = `TENJIN_WALLET_PASSPHRASE is set but does not open this wallet. Remove it from the environment, then: ${REPAIR_IN_TERMINAL}`;
992
+ function storedWrongFix(source, account, dir) {
993
+ return `${storedEntryText(source, account, dir)} does not decrypt it. ${REPAIR_IN_TERMINAL}`;
994
+ }
995
+ function storedEntryText(source, account, dir) {
996
+ if (source === "keychain" || source === "secret-service") {
997
+ return `The OS credential store entry (service tenjin-cli, account ${account})`;
998
+ }
999
+ if (source === "dpapi" || source === "file") {
1000
+ return `The passphrase in ${describeStoreLocation(source, account, dir)}`;
1001
+ }
1002
+ return `The passphrase from ${passphraseOrigin(source, account, dir)}`;
1003
+ }
1004
+ function legacyWrongFix(source, account, dir) {
1005
+ return `That passphrase likely belongs to a wallet created later, and the entry was left untouched. If you know this wallet's passphrase: ${REPAIR_IN_TERMINAL} Otherwise restore ${passphraseOrigin(source, account, dir)} from a backup.`;
1006
+ }
1313
1007
  async function verifyLocalWallet(deps) {
1314
1008
  const cred = await loadCredential(deps);
1315
1009
  if (cred === null) return { status: "unverified", detail: "there is no credential to verify" };
1316
1010
  if (cred.source === "env") {
1317
1011
  accountFromKey(cred.key, "env");
1318
- return { status: "verified", detail: "TENJIN_WALLET_KEY derives a valid signing key" };
1012
+ return {
1013
+ status: "verified",
1014
+ detail: "TENJIN_WALLET_KEY derives a valid signing key",
1015
+ source: "key-env"
1016
+ };
1319
1017
  }
1320
1018
  const account = walletStoreAccount(cred.address);
1019
+ const passphraseDeps = {
1020
+ env: deps.env,
1021
+ dir: deps.dir,
1022
+ ...deps.passphrase,
1023
+ isTTY: false,
1024
+ readDeadlineMs: deps.passphrase?.timeouts?.verifyReadMs ?? STORE_TIMEOUTS.verifyReadMs
1025
+ };
1026
+ const unreachable = (err) => {
1027
+ if (unlockReasonOf(err) === "keychain_locked") {
1028
+ const store = err.details;
1029
+ const noun = isDurableStore(store.unlock?.source) ? storeNoun(store.unlock.source) : "keychain";
1030
+ return {
1031
+ status: "unverified",
1032
+ reason: "keychain_locked",
1033
+ detail: `the ${noun} did not answer (${store.storeDetail ?? "no answer"}), so the keystore was not opened`
1034
+ };
1035
+ }
1036
+ return {
1037
+ status: "unverified",
1038
+ reason: "passphrase_missing",
1039
+ detail: "no passphrase is reachable without prompting, so the keystore was not opened"
1040
+ };
1041
+ };
1321
1042
  let resolved;
1322
1043
  try {
1323
- resolved = await resolvePassphrase(
1324
- {
1325
- env: deps.env,
1326
- dir: deps.dir,
1327
- ...deps.passphrase,
1328
- isTTY: false,
1329
- timeoutMs: STORE_READ_TIMEOUT_MS
1330
- },
1331
- cred.address
1044
+ resolved = await resolvePassphrase(passphraseDeps, cred.address);
1045
+ } catch (err) {
1046
+ return unreachable(err);
1047
+ }
1048
+ const cancelled = {
1049
+ status: "unverified",
1050
+ reason: "unlock_timeout",
1051
+ detail: "keystore verification was cancelled or timed out"
1052
+ };
1053
+ let opened;
1054
+ try {
1055
+ opened = await openKeystoreAccount(
1056
+ cred.keystore,
1057
+ account,
1058
+ resolved.passphrase,
1059
+ deps.derivation
1332
1060
  );
1333
1061
  } catch {
1062
+ return cancelled;
1063
+ }
1064
+ const origin = resolvedOrigin(resolved, account, deps.dir);
1065
+ if (opened.kind === "ok") {
1334
1066
  return {
1335
- status: "unverified",
1336
- detail: "no passphrase is reachable without prompting, so the keystore was not opened"
1067
+ status: "verified",
1068
+ detail: `keystore decrypts with the passphrase from ${origin}`,
1069
+ source: signingSourceOf(resolved)
1337
1070
  };
1338
1071
  }
1339
- let key;
1340
- try {
1341
- const derived = await deriveKeystoreKey(cred.keystore, resolved.passphrase, deps.derivation);
1342
- key = decrypt(cred.keystore, derived);
1343
- } catch (error) {
1344
- if (error instanceof Error && ["AbortError", "TimeoutError"].includes(error.name)) {
1345
- return { status: "unverified", detail: "keystore verification was cancelled or timed out" };
1346
- }
1347
- if (resolved.migrateLegacy !== void 0) {
1348
- return {
1349
- status: "broken",
1350
- detail: `the keystore cannot be decrypted: the only stored passphrase is ${legacyOrigin(resolved.source)}, which does not open it`,
1351
- fix: `That passphrase likely belongs to a wallet created later. Set TENJIN_WALLET_PASSPHRASE to this wallet's own passphrase, or restore ${passphraseOrigin(resolved.source, account)}.`
1352
- };
1353
- }
1354
- const escape = resolved.source === "env" ? "TENJIN_WALLET_PASSPHRASE is set but does not open it; set it to the correct passphrase" : `The passphrase from ${passphraseOrigin(resolved.source, account)} does not open it; set TENJIN_WALLET_PASSPHRASE to the correct passphrase`;
1072
+ if (opened.kind === "mismatch") return tamperedVerification(cred.address, opened);
1073
+ if (resolved.migrateLegacy !== void 0) {
1355
1074
  return {
1356
1075
  status: "broken",
1357
- detail: `the keystore cannot be decrypted with the passphrase from ${passphraseOrigin(resolved.source, account)}`,
1358
- fix: `${escape}. Without it the key is unrecoverable and this address can no longer sign or publish.`
1076
+ reason: "passphrase_wrong",
1077
+ detail: `the keystore cannot be decrypted: the only stored passphrase is ${legacyOrigin(resolved.source)}, which does not open it`,
1078
+ fix: legacyWrongFix(resolved.source, account, deps.dir)
1359
1079
  };
1360
1080
  }
1361
- if (privateKeyToAccount(key).address.toLowerCase() !== account) {
1081
+ if (resolved.source !== "env") {
1362
1082
  return {
1363
1083
  status: "broken",
1364
- detail: `the decrypted key does not derive the wallet file's stored address ${cred.address}`,
1365
- fix: "The wallet file may be tampered. Move it aside, then run `tenjin wallet create` for a fresh key or set TENJIN_WALLET_KEY to use the intended one."
1084
+ reason: "passphrase_wrong",
1085
+ detail: `the keystore cannot be decrypted with the passphrase from ${origin}`,
1086
+ fix: storedWrongFix(resolved.source, account, deps.dir)
1087
+ };
1088
+ }
1089
+ let saved;
1090
+ try {
1091
+ saved = await resolvePassphrase(passphraseDeps, cred.address, { skipEnv: true });
1092
+ } catch (err) {
1093
+ if (unlockReasonOf(err) === "keychain_locked") return unreachable(err);
1094
+ return envWrongVerification();
1095
+ }
1096
+ let fallback;
1097
+ try {
1098
+ fallback = await openKeystoreAccount(cred.keystore, account, saved.passphrase, deps.derivation);
1099
+ } catch {
1100
+ return cancelled;
1101
+ }
1102
+ if (fallback.kind === "ok") {
1103
+ return {
1104
+ status: "verified",
1105
+ detail: `keystore decrypts with the passphrase from ${resolvedOrigin(saved, account, deps.dir)}; TENJIN_WALLET_PASSPHRASE does not open it`,
1106
+ source: signingSourceOf(saved),
1107
+ warning: ENV_PASSPHRASE_WRONG
1366
1108
  };
1367
1109
  }
1110
+ if (fallback.kind === "mismatch") return tamperedVerification(cred.address, fallback);
1111
+ return envWrongVerification();
1112
+ }
1113
+ function envWrongVerification() {
1114
+ return {
1115
+ status: "broken",
1116
+ reason: "env_passphrase_wrong",
1117
+ detail: "the keystore cannot be decrypted with the passphrase from TENJIN_WALLET_PASSPHRASE",
1118
+ fix: ENV_WRONG_FIX
1119
+ };
1120
+ }
1121
+ function tamperedVerification(address, opened) {
1368
1122
  return {
1369
- status: "verified",
1370
- detail: `keystore decrypts with the passphrase from ${passphraseOrigin(resolved.source, account)}`
1123
+ status: "broken",
1124
+ reason: "wallet_corrupt",
1125
+ detail: opened.derived === null ? "the decrypted key is not a valid secp256k1 key" : `the decrypted key does not derive the wallet file's stored address ${address}`,
1126
+ fix: "The wallet file may be tampered. Move it aside, then run `tenjin wallet create` for a fresh key or set TENJIN_WALLET_KEY to use the intended one."
1371
1127
  };
1372
1128
  }
1373
- function passphraseOrigin(source, account) {
1129
+ function signingSourceOf(resolved) {
1130
+ if (resolved.migrateLegacy !== void 0) return "legacy";
1131
+ if (resolved.source === "env") return "passphrase-env";
1132
+ return resolved.source === "prompt" ? "file" : resolved.source;
1133
+ }
1134
+ function isDurableStore(value) {
1135
+ return value === "keychain" || value === "secret-service" || value === "dpapi" || value === "file";
1136
+ }
1137
+ function resolvedOrigin(resolved, account, dir) {
1138
+ return resolved.migrateLegacy !== void 0 ? legacyOrigin(resolved.source) : passphraseOrigin(resolved.source, account, dir);
1139
+ }
1140
+ function passphraseOrigin(source, account, dir) {
1374
1141
  if (source === "env") return "TENJIN_WALLET_PASSPHRASE";
1375
1142
  if (source === "prompt") return "the prompt";
1376
1143
  if (source === "dpapi") return `the DPAPI-protected passphrase file for ${account}`;
1144
+ if (source === "file") return describeStoreLocation("file", account, dir);
1377
1145
  return `the OS credential store (service tenjin-cli, account ${account})`;
1378
1146
  }
1379
1147
  function legacyOrigin(source) {
@@ -1398,15 +1166,36 @@ async function localWalletDiagnostics(deps) {
1398
1166
  );
1399
1167
  }
1400
1168
  }
1169
+ const passphraseStore = fileExists ? await recordedStore(deps.dir) : null;
1170
+ if (passphraseStore?.store === "file" && !isWindows) {
1171
+ const plain = passphraseFilePathFor(passphraseStore.account, deps.dir);
1172
+ const plainMode = await stat2(plain).then(
1173
+ (s) => s.mode & 511,
1174
+ () => null
1175
+ );
1176
+ if (plainMode !== null && plainMode !== 384) {
1177
+ warnings.push(
1178
+ `Passphrase file permissions are ${plainMode.toString(8)}, expected 600. Run \`chmod 600 ${plain}\`.`
1179
+ );
1180
+ }
1181
+ }
1401
1182
  const passphraseSource = deps.env.TENJIN_WALLET_PASSPHRASE !== void 0 && deps.env.TENJIN_WALLET_PASSPHRASE.length > 0 ? "TENJIN_WALLET_PASSPHRASE" : void 0;
1402
1183
  const archivedWallets = await listArchivedWallets(deps.dir);
1403
1184
  return {
1404
1185
  ...fileExists ? { walletPath: path, keyStorage: KEY_STORAGE } : {},
1405
1186
  ...fileExists && passphraseSource !== void 0 ? { passphraseSource } : {},
1187
+ ...passphraseStore !== null ? { passphraseStore: passphraseStore.store } : {},
1406
1188
  ...archivedWallets.length > 0 ? { archivedWallets } : {},
1407
1189
  warnings
1408
1190
  };
1409
1191
  }
1192
+ async function recordedStore(dir) {
1193
+ const record = await readWalletRecord(dir).catch(() => null);
1194
+ if (record === null) return null;
1195
+ const account = record.address.toLowerCase();
1196
+ const entry = await readPassphraseRecord(dir, account);
1197
+ return entry === null ? null : { store: entry.store, account };
1198
+ }
1410
1199
  var ARCHIVED_WALLET_RE = /^wallet\.(0x[0-9a-f]{40})\.json\.bak$/;
1411
1200
  async function listArchivedWallets(dir) {
1412
1201
  let names;
@@ -1441,27 +1230,34 @@ async function verifyAndPreserveOutgoingWallet(deps) {
1441
1230
  const address = record.address;
1442
1231
  const account = walletStoreAccount(address);
1443
1232
  const passphraseDeps = { env: deps.env, dir: deps.dir, ...deps.passphrase };
1444
- const resolved = await resolvePassphrase(passphraseDeps, address);
1445
- let key;
1233
+ const resolved = await resolvePassphrase(passphraseDeps, address, {
1234
+ promptLabel: `Passphrase for the existing wallet ${address}: `
1235
+ });
1236
+ let opened;
1446
1237
  try {
1447
- const derived = await toKeyAsync(record.keystore, { password: resolved.passphrase });
1448
- key = decrypt(record.keystore, derived);
1238
+ opened = await openKeystoreAccount(record.keystore, account, resolved.passphrase);
1449
1239
  } catch (err) {
1450
- const escape = resolved.source === "prompt" ? "Retry and enter that wallet's correct passphrase at the prompt, or set TENJIN_WALLET_PASSPHRASE to it" : resolved.source === "env" ? "TENJIN_WALLET_PASSPHRASE is set but does not decrypt it; set it to the correct passphrase" : `Set TENJIN_WALLET_PASSPHRASE to its passphrase, or fix its OS credential store entry (service tenjin-cli, account ${account})`;
1240
+ opened = { kind: "wrong", cause: err };
1241
+ }
1242
+ if (opened.kind === "wrong") {
1243
+ const escape = resolved.source === "prompt" ? "Retry and enter that wallet's correct passphrase at the prompt, or set TENJIN_WALLET_PASSPHRASE to it" : resolved.source === "env" ? "TENJIN_WALLET_PASSPHRASE is set but does not decrypt it; set it to the correct passphrase" : `Set TENJIN_WALLET_PASSPHRASE to its passphrase, or fix ${storedEntryText(resolved.source, account, deps.dir).replace(/^The /, "the ")}`;
1451
1244
  throw new CliError(
1452
1245
  "REFUSED",
1453
1246
  `Cannot verify the passphrase of the existing wallet ${address}; --replace refused.`,
1454
1247
  {
1455
1248
  fix: `Replacing now could strand that wallet's funds. ${escape}, then retry.`,
1456
- cause: err
1249
+ cause: opened.cause
1457
1250
  }
1458
1251
  );
1459
1252
  }
1460
- if (privateKeyToAccount(key).address.toLowerCase() !== account) {
1253
+ if (opened.kind === "mismatch") {
1461
1254
  throw new CliError(
1462
1255
  "REFUSED",
1463
1256
  `The wallet file's stored address ${address} does not match its key; --replace refused.`,
1464
- { fix: "The wallet file may be tampered. Resolve that before replacing it." }
1257
+ {
1258
+ fix: "The wallet file may be tampered. Resolve that before replacing it.",
1259
+ details: unlockDetails("wallet_corrupt")
1260
+ }
1465
1261
  );
1466
1262
  }
1467
1263
  if (resolved.source === "env") {
@@ -1480,10 +1276,63 @@ async function verifyAndPreserveOutgoingWallet(deps) {
1480
1276
  return { address, account, passphraseLocation: "store" };
1481
1277
  }
1482
1278
  if (resolved.source === "prompt") {
1483
- const outcome = await storePassphraseForWallet(passphraseDeps, address, resolved.passphrase);
1484
- return outcome === "stored" ? { address, account, passphraseLocation: "store" } : { address, account, passphraseLocation: "unarchived", unarchivedReason: outcome };
1279
+ return archivePromptedPassphrase(
1280
+ passphraseDeps,
1281
+ deps.dir,
1282
+ address,
1283
+ account,
1284
+ resolved.passphrase
1285
+ );
1286
+ }
1287
+ return {
1288
+ address,
1289
+ account,
1290
+ passphraseLocation: "store",
1291
+ location: describeStoreLocation(resolved.source, account, deps.dir)
1292
+ };
1293
+ }
1294
+ async function archivePromptedPassphrase(passphraseDeps, dir, address, account, passphrase) {
1295
+ const probed = await probeDurableStore(passphraseDeps);
1296
+ if (probed.probe === "uncertain") throw outgoingUncertainError(probed.store);
1297
+ const target = probed.probe === "available" ? probed.store : "file";
1298
+ const written = await storeDurablyDetailed(passphraseDeps, target, address, passphrase);
1299
+ const outcome = target === "file" && written.outcome === "uncertain" ? "store-failed" : toStoreOutcome(written.outcome);
1300
+ switch (outcome) {
1301
+ case "stored":
1302
+ await writePassphraseRecord(dir, account, { store: target, by: "replace" });
1303
+ return {
1304
+ address,
1305
+ account,
1306
+ passphraseLocation: "store",
1307
+ location: describeStoreLocation(target, account, dir)
1308
+ };
1309
+ case "uncertain":
1310
+ throw outgoingUncertainError(target);
1311
+ case "store-failed": {
1312
+ const detail = written.detail ?? `the ${storeNoun(target)} write failed`;
1313
+ const message = `Could not save the existing wallet's passphrase (${detail}); --replace refused.`;
1314
+ if (target === "file") {
1315
+ const path = describeStoreLocation("file", account, dir);
1316
+ throw new CliError("REFUSED", message, {
1317
+ fix: FILE_STORE_FAILED_FIX(path),
1318
+ details: { passphraseStore: { kind: "file-write-failed", path } }
1319
+ });
1320
+ }
1321
+ throw new CliError("REFUSED", message, {
1322
+ fix: KEYCHAIN_LOCKED_FIX,
1323
+ details: unlockDetails("keychain_locked", target)
1324
+ });
1325
+ }
1326
+ case "rejected-characters":
1327
+ return { address, account, passphraseLocation: "unarchived", unarchivedReason: outcome };
1485
1328
  }
1486
- return { address, account, passphraseLocation: "store" };
1329
+ }
1330
+ function outgoingUncertainError(store) {
1331
+ return new CliError(
1332
+ "REFUSED",
1333
+ `Could not save the existing wallet's passphrase (the ${storeNoun(store)} did not answer); --replace refused.`,
1334
+ { fix: KEYCHAIN_LOCKED_FIX, details: unlockDetails("keychain_locked", store) }
1335
+ );
1487
1336
  }
1488
1337
  async function parkOutgoingWallet(dir, account) {
1489
1338
  const src = walletPath(dir);
@@ -1503,9 +1352,9 @@ async function parkOutgoingWallet(dir, account) {
1503
1352
  });
1504
1353
  }
1505
1354
  try {
1506
- await unlink2(src);
1355
+ await unlink(src);
1507
1356
  } catch (err) {
1508
- await unlink2(dst).catch(() => void 0);
1357
+ await unlink(dst).catch(() => void 0);
1509
1358
  throw new CliError(
1510
1359
  "INTERNAL",
1511
1360
  `Could not clear the active wallet slot ${src} while parking the outgoing wallet.`,
@@ -1520,7 +1369,7 @@ async function parkOutgoingWallet(dir, account) {
1520
1369
  }
1521
1370
  async function restoreParkedWallet(dir, archivedPath) {
1522
1371
  await link(archivedPath, walletPath(dir));
1523
- await unlink2(archivedPath).catch(() => void 0);
1372
+ await unlink(archivedPath).catch(() => void 0);
1524
1373
  await syncWalletDir(dir);
1525
1374
  }
1526
1375
  async function syncWalletDir(dir) {
@@ -1533,7 +1382,8 @@ async function loadCredential(deps) {
1533
1382
  const key = envKey.trim();
1534
1383
  if (!PRIVATE_KEY_RE.test(key)) {
1535
1384
  throw new CliError("WALLET_INVALID_KEY", "TENJIN_WALLET_KEY is not a valid private key.", {
1536
- fix: "Set TENJIN_WALLET_KEY to a 0x-prefixed 32-byte hex key, or unset it to use the wallet file."
1385
+ fix: "Set TENJIN_WALLET_KEY to a 0x-prefixed 32-byte hex key, or unset it to use the wallet file.",
1386
+ details: unlockDetails("env_key_invalid")
1537
1387
  });
1538
1388
  }
1539
1389
  return { source: "env", key };
@@ -1544,64 +1394,112 @@ async function loadCredential(deps) {
1544
1394
  }
1545
1395
  return null;
1546
1396
  }
1547
- async function accountForSigning(cred, deps) {
1397
+ async function accountForSigning(cred, deps, warnOnce) {
1548
1398
  if (cred.source === "env") return accountFromKey(cred.key, "env");
1549
- const cached = signerCache.get(cred.keystore.id);
1550
- if (cached !== void 0) return cached;
1551
- const resolved = await resolvePassphrase(
1552
- {
1553
- env: deps.env,
1554
- dir: deps.dir,
1555
- ...deps.passphrase
1556
- },
1557
- cred.address
1399
+ const id = cred.keystore.id;
1400
+ const cached = signerCache.get(id);
1401
+ if (cached !== void 0) {
1402
+ if (cached.envShadowed) warnOnce(id);
1403
+ return cached.account;
1404
+ }
1405
+ const account = walletStoreAccount(cred.address);
1406
+ const passphraseDeps = { env: deps.env, dir: deps.dir, ...deps.passphrase };
1407
+ const resolved = await resolvePassphrase(passphraseDeps, cred.address);
1408
+ const opened = await openKeystoreAccount(
1409
+ cred.keystore,
1410
+ account,
1411
+ resolved.passphrase,
1412
+ deps.derivation
1558
1413
  );
1559
- let key;
1560
- try {
1561
- const derived = await deriveKeystoreKey(cred.keystore, resolved.passphrase, deps.derivation);
1562
- key = decrypt(cred.keystore, derived);
1563
- } catch (err) {
1564
- if (err instanceof Error && ["AbortError", "TimeoutError"].includes(err.name)) throw err;
1565
- if (resolved.migrateLegacy !== void 0) {
1566
- throw new CliError(
1567
- "WALLET_INVALID_KEY",
1568
- 'The legacy shared passphrase entry (service tenjin-cli, account "wallet") does not decrypt this wallet.',
1569
- {
1570
- fix: "That entry likely belongs to a different wallet created later and was left untouched. If you know this wallet's passphrase, set TENJIN_WALLET_PASSPHRASE to it (a store-served passphrase is never re-asked at a prompt).",
1571
- cause: err
1572
- }
1573
- );
1574
- }
1575
- const escape = resolved.source === "env" ? "TENJIN_WALLET_PASSPHRASE is set but does not decrypt it; set it to the correct passphrase" : resolved.source === "prompt" ? "Retry and enter the correct passphrase at the prompt, or set TENJIN_WALLET_PASSPHRASE to it" : `The OS credential store entry (service tenjin-cli, account ${cred.address.toLowerCase()}) does not decrypt it; set TENJIN_WALLET_PASSPHRASE to the correct passphrase`;
1414
+ if (opened.kind === "ok") return unlocked(resolved, opened.account, false);
1415
+ if (opened.kind === "mismatch") throw tamperedError(cred.address, opened);
1416
+ if (resolved.migrateLegacy !== void 0) {
1417
+ throw new CliError(
1418
+ "WALLET_INVALID_KEY",
1419
+ 'The legacy shared passphrase entry (service tenjin-cli, account "wallet") does not decrypt this wallet.',
1420
+ {
1421
+ fix: `That entry likely belongs to a different wallet created later and was left untouched. If you know this wallet's passphrase: ${REPAIR_IN_TERMINAL}`,
1422
+ cause: opened.cause,
1423
+ details: unlockDetails("passphrase_wrong", "legacy")
1424
+ }
1425
+ );
1426
+ }
1427
+ if (resolved.source !== "env") {
1576
1428
  throw new CliError("WALLET_INVALID_KEY", "Could not decrypt the wallet keystore.", {
1577
- fix: `${escape}.`,
1578
- cause: err
1429
+ fix: resolved.source === "prompt" ? "Retry and enter the correct passphrase at the prompt." : storedWrongFix(resolved.source, account, deps.dir),
1430
+ cause: opened.cause,
1431
+ details: unlockDetails("passphrase_wrong", resolved.source)
1579
1432
  });
1580
1433
  }
1581
- const account = accountFromKey(key, "file");
1582
- if (account.address.toLowerCase() !== cred.address.toLowerCase()) {
1434
+ const saved = await resolvePassphrase({ ...passphraseDeps, isTTY: false }, cred.address, {
1435
+ skipEnv: true
1436
+ }).catch((err) => err);
1437
+ if (!(saved instanceof Error) && isResolved(saved)) {
1438
+ const fallback = await openKeystoreAccount(
1439
+ cred.keystore,
1440
+ account,
1441
+ saved.passphrase,
1442
+ deps.derivation
1443
+ );
1444
+ if (fallback.kind === "ok") {
1445
+ const result = await unlocked(saved, fallback.account, true);
1446
+ warnOnce(id);
1447
+ return result;
1448
+ }
1449
+ if (fallback.kind === "mismatch") throw tamperedError(cred.address, fallback);
1450
+ } else if (unlockReasonOf(saved) === "keychain_locked") {
1451
+ const locked = saved;
1583
1452
  throw new CliError(
1584
- "WALLET_INVALID_KEY",
1585
- `The decrypted key derives ${account.address}, not the wallet file's stored address ${cred.address}.`,
1453
+ locked.code,
1454
+ `TENJIN_WALLET_PASSPHRASE does not open the wallet, and ${lowerFirst(locked.message)}`,
1586
1455
  {
1587
- fix: "The wallet file may be tampered. Move it aside, then run `tenjin wallet create` for a fresh key or set TENJIN_WALLET_KEY to use the intended one."
1456
+ ...locked.fix !== void 0 ? { fix: locked.fix } : {},
1457
+ details: locked.details
1588
1458
  }
1589
1459
  );
1590
1460
  }
1591
- if (resolved.migrateLegacy !== void 0) await resolved.migrateLegacy();
1592
- signerCache.set(cred.keystore.id, account);
1593
- return account;
1461
+ throw new CliError("WALLET_INVALID_KEY", "Could not decrypt the wallet keystore.", {
1462
+ fix: ENV_WRONG_FIX,
1463
+ cause: opened.cause,
1464
+ details: unlockDetails("env_passphrase_wrong", "env")
1465
+ });
1466
+ async function unlocked(from2, signer, envShadowed) {
1467
+ if (from2.migrateLegacy !== void 0) await from2.migrateLegacy();
1468
+ signerCache.set(id, { account: signer, envShadowed });
1469
+ return signer;
1470
+ }
1471
+ }
1472
+ function isResolved(value) {
1473
+ return typeof value === "object" && value !== null && "passphrase" in value;
1474
+ }
1475
+ function lowerFirst(text) {
1476
+ return text.length > 0 ? `${text.charAt(0).toLowerCase()}${text.slice(1)}` : text;
1477
+ }
1478
+ function tamperedError(address, opened) {
1479
+ if (opened.derived === null) return invalidKeyError("file", opened.cause);
1480
+ return new CliError(
1481
+ "WALLET_INVALID_KEY",
1482
+ `The decrypted key derives ${opened.derived}, not the wallet file's stored address ${address}.`,
1483
+ {
1484
+ fix: "The wallet file may be tampered. Move it aside, then run `tenjin wallet create` for a fresh key or set TENJIN_WALLET_KEY to use the intended one.",
1485
+ details: unlockDetails("wallet_corrupt")
1486
+ }
1487
+ );
1594
1488
  }
1595
1489
  function accountFromKey(key, source) {
1596
1490
  try {
1597
1491
  return privateKeyToAccount(key);
1598
1492
  } catch (err) {
1599
- throw new CliError("WALLET_INVALID_KEY", "The private key is not a valid secp256k1 key.", {
1600
- fix: source === "file" ? "Move the wallet file aside, then run `tenjin wallet create` for a fresh key or set TENJIN_WALLET_KEY to use the intended one." : "Set TENJIN_WALLET_KEY to a valid 0x-prefixed 32-byte hex key.",
1601
- cause: err
1602
- });
1493
+ throw invalidKeyError(source, err);
1603
1494
  }
1604
1495
  }
1496
+ function invalidKeyError(source, cause) {
1497
+ return new CliError("WALLET_INVALID_KEY", "The private key is not a valid secp256k1 key.", {
1498
+ fix: source === "file" ? "Move the wallet file aside, then run `tenjin wallet create` for a fresh key or set TENJIN_WALLET_KEY to use the intended one." : "Set TENJIN_WALLET_KEY to a valid 0x-prefixed 32-byte hex key.",
1499
+ cause,
1500
+ details: unlockDetails(source === "file" ? "wallet_corrupt" : "env_key_invalid")
1501
+ });
1502
+ }
1605
1503
  async function encryptToKeystore(key, passphrase) {
1606
1504
  const [derivedKey, opts] = await scryptAsync2({ password: passphrase });
1607
1505
  return encrypt2(key, derivedKey, opts);
@@ -1624,6 +1522,131 @@ function walletRecord(address, keystore) {
1624
1522
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
1625
1523
  };
1626
1524
  }
1525
+ async function repairLocalWalletPassphrase(deps, passphrase, opts = {}) {
1526
+ const record = await readWalletRecord(deps.dir);
1527
+ if (record === null) {
1528
+ throw new CliError("WALLET_MISSING", "No wallet found to repair.", {
1529
+ fix: "Run `tenjin wallet create` to create one."
1530
+ });
1531
+ }
1532
+ const address = record.address;
1533
+ const account = walletStoreAccount(address);
1534
+ const opened = await openKeystoreAccount(record.keystore, account, passphrase, deps.derivation);
1535
+ if (opened.kind === "wrong") {
1536
+ throw new CliError(
1537
+ "WALLET_INVALID_KEY",
1538
+ `That passphrase does not open wallet ${address}; nothing was saved.`,
1539
+ {
1540
+ fix: `Check the passphrase, then: ${REPAIR_IN_TERMINAL}`,
1541
+ details: unlockDetails("passphrase_wrong", "prompt")
1542
+ }
1543
+ );
1544
+ }
1545
+ if (opened.kind === "mismatch") throw tamperedError(address, opened);
1546
+ const passphraseDeps = { env: deps.env, dir: deps.dir, ...deps.passphrase };
1547
+ const location = (store) => describeStoreLocation(store, account, deps.dir);
1548
+ const done = (store, fields) => ({
1549
+ address,
1550
+ account,
1551
+ store,
1552
+ location: location(store),
1553
+ alreadySaved: fields.alreadySaved ?? false,
1554
+ replacedUnusableEntry: fields.replacedUnusableEntry ?? false,
1555
+ ...fields.fileReason !== void 0 ? { fileReason: fields.fileReason } : {}
1556
+ });
1557
+ const recorded = await readPassphraseRecord(deps.dir, account);
1558
+ if (recorded !== null) {
1559
+ const timeouts = { ...STORE_TIMEOUTS, ...passphraseDeps.timeouts };
1560
+ const bound = passphraseDeps.isTTY === true ? timeouts.interactiveWriteMs : timeouts.writeMs;
1561
+ const held = await readStoredPassphrase(passphraseDeps, recorded.store, address, {
1562
+ timeoutMs: bound
1563
+ });
1564
+ if (held.kind === "hit" && held.value === passphrase) {
1565
+ return done(recorded.store, { alreadySaved: true });
1566
+ }
1567
+ }
1568
+ let target;
1569
+ let fileReason;
1570
+ if (opts.insecureStorage === true) {
1571
+ target = "file";
1572
+ fileReason = "insecure-storage";
1573
+ } else {
1574
+ const probed = await probeDurableStore(passphraseDeps);
1575
+ if (probed.probe === "uncertain") {
1576
+ throw new CliError(
1577
+ "REFUSED",
1578
+ `The ${storeNoun(probed.store)} did not answer; nothing was saved.`,
1579
+ { fix: KEYCHAIN_LOCKED_FIX, details: unlockDetails("keychain_locked", probed.store) }
1580
+ );
1581
+ }
1582
+ if (probed.probe === "available") {
1583
+ target = probed.store;
1584
+ } else {
1585
+ target = "file";
1586
+ fileReason = "no-keyring";
1587
+ }
1588
+ }
1589
+ let replaced = false;
1590
+ const written = await storeDurablyDetailed(passphraseDeps, target, address, passphrase, {
1591
+ // Replace an existing entry only once it is PROVEN not to open this wallet.
1592
+ replaceIf: async (existing) => {
1593
+ replaced = await openKeystore(record.keystore, account, existing, deps.derivation) !== "ok";
1594
+ return replaced;
1595
+ }
1596
+ });
1597
+ const reason = fileReason !== void 0 ? { fileReason } : {};
1598
+ const outcome = target === "file" && written.outcome === "uncertain" ? "store-failed" : written.outcome;
1599
+ switch (outcome) {
1600
+ case "stored":
1601
+ await writePassphraseRecord(deps.dir, account, { store: target, by: "repair" });
1602
+ return done(target, { replacedUnusableEntry: replaced, ...reason });
1603
+ case "already-stored":
1604
+ case "kept-existing":
1605
+ await writePassphraseRecord(deps.dir, account, { store: target, by: "repair" });
1606
+ return done(target, { alreadySaved: true, ...reason });
1607
+ case "uncertain":
1608
+ throw new CliError("REFUSED", `The ${storeNoun(target)} did not answer; nothing was saved.`, {
1609
+ fix: KEYCHAIN_LOCKED_FIX,
1610
+ details: unlockDetails("keychain_locked", target)
1611
+ });
1612
+ case "conflict":
1613
+ throw new CliError(
1614
+ "REFUSED",
1615
+ `The ${storeNoun(target)} holds a different passphrase for wallet ${address} after the write; nothing was confirmed.`,
1616
+ {
1617
+ fix: `Run \`tenjin wallet repair\` again yourself ${REPAIR_CLAUSE}; if this repeats, another program is writing that entry: run \`tenjin doctor\`.`,
1618
+ details: unlockDetails("keychain_locked", target)
1619
+ }
1620
+ );
1621
+ case "rejected-characters":
1622
+ throw new CliError(
1623
+ "REFUSED",
1624
+ `This passphrase cannot be saved: ${unstorableWhy(target)}; nothing was saved.`,
1625
+ {
1626
+ fix: "Keep TENJIN_WALLET_PASSPHRASE set in the environment Claude Code starts from."
1627
+ }
1628
+ );
1629
+ case "store-failed": {
1630
+ const detail = written.detail ?? `the ${storeNoun(target)} write failed`;
1631
+ if (target === "file") {
1632
+ const path = location("file");
1633
+ throw new CliError(
1634
+ "REFUSED",
1635
+ `Could not save the passphrase to ${path} (${detail}); nothing was saved.`,
1636
+ {
1637
+ fix: FILE_STORE_FAILED_FIX(path),
1638
+ details: { passphraseStore: { kind: "file-write-failed", path } }
1639
+ }
1640
+ );
1641
+ }
1642
+ throw new CliError(
1643
+ "REFUSED",
1644
+ `Could not save the passphrase to ${location(target)} (${detail}); nothing was saved.`,
1645
+ { fix: KEYCHAIN_LOCKED_FIX, details: unlockDetails("keychain_locked", target) }
1646
+ );
1647
+ }
1648
+ }
1649
+ }
1627
1650
 
1628
1651
  // src/lib/wallet/index.ts
1629
1652
  function resolveWalletProvider(ctx, opts = {}) {
@@ -1631,7 +1654,8 @@ function resolveWalletProvider(ctx, opts = {}) {
1631
1654
  return createLocalProvider({
1632
1655
  dir: ctx.dataDir,
1633
1656
  env: process.env,
1634
- passphrase: { ...opts.passphrase, isTTY: ctx.io.isTTY ? void 0 : false }
1657
+ passphrase: { ...opts.passphrase, isTTY: ctx.io.isTTY ? void 0 : false },
1658
+ onWarning: opts.onWarning ?? ((w) => emitNotice(ctx.io, w.message, { json: ctx.flags.json }))
1635
1659
  });
1636
1660
  }
1637
1661
  function resolveSpendAuthorizer(ctx, policy, opts = {}) {
@@ -1661,14 +1685,18 @@ async function describeWallet(provider) {
1661
1685
 
1662
1686
  export {
1663
1687
  walletFileExists,
1688
+ readWalletRecord,
1664
1689
  walletExistsError,
1665
- resolvePassphraseForCreate,
1690
+ createLocalProvider,
1691
+ openKeystore,
1692
+ verifyLocalWallet,
1666
1693
  prepareLocalWallet,
1667
1694
  commitLocalWallet,
1668
1695
  createLocalWallet,
1669
1696
  verifyAndPreserveOutgoingWallet,
1670
1697
  parkOutgoingWallet,
1671
1698
  restoreParkedWallet,
1699
+ repairLocalWalletPassphrase,
1672
1700
  resolveWalletProvider,
1673
1701
  resolveSpendAuthorizer,
1674
1702
  describeWallet
@@ -1678,4 +1706,4 @@ export {
1678
1706
  @noble/ciphers/esm/utils.js:
1679
1707
  (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
1680
1708
  */
1681
- //# sourceMappingURL=chunk-OSYTBCUC.js.map
1709
+ //# sourceMappingURL=chunk-BI673VEJ.js.map