tenjin-cli 0.1.0-alpha.31 → 0.1.0-alpha.33

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 (270) hide show
  1. package/README.md +45 -26
  2. package/dist/{_esm-MEXZI5DL.js → _esm-BIN7VY2L.js} +128 -132
  3. package/dist/{alive-J64H46HI.js → alive-GSOWKUOY.js} +13 -6
  4. package/dist/auto-update-Y24UL56V.js +24 -0
  5. package/dist/{ccip-7RMRLAGV.js → ccip-DHDFKTQV.js} +2 -2
  6. package/dist/{chunk-TTNESUPQ.js → chunk-2GP3HRYK.js} +2120 -193
  7. package/dist/chunk-2GP3HRYK.js.map +1 -0
  8. package/dist/chunk-2M2VPI2E.js +560 -0
  9. package/dist/chunk-2M2VPI2E.js.map +1 -0
  10. package/dist/{chunk-D65GNPS3.js → chunk-2RWB7RKE.js} +288 -108
  11. package/dist/chunk-2RWB7RKE.js.map +1 -0
  12. package/dist/{chunk-AGZ7PJKY.js → chunk-36RVGZNY.js} +22 -5
  13. package/dist/chunk-36RVGZNY.js.map +1 -0
  14. package/dist/chunk-3AIHRXKO.js +72 -0
  15. package/dist/chunk-3AIHRXKO.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-3GNJXKIT.js +198 -0
  19. package/dist/chunk-3GNJXKIT.js.map +1 -0
  20. package/dist/{chunk-UQUOVWBG.js → chunk-4K7TQHNP.js} +7 -7
  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-KXQ4UIP7.js → chunk-4USCZ2NI.js} +2 -2
  24. package/dist/chunk-4YOZGGTZ.js +247 -0
  25. package/dist/chunk-4YOZGGTZ.js.map +1 -0
  26. package/dist/chunk-62KNUYWD.js +111 -0
  27. package/dist/chunk-62KNUYWD.js.map +1 -0
  28. package/dist/{chunk-POUWHWID.js → chunk-6CMM6YCB.js} +3 -3
  29. package/dist/{chunk-POUWHWID.js.map → chunk-6CMM6YCB.js.map} +1 -1
  30. package/dist/{chunk-5MARFNSB.js → chunk-A5GKIG5O.js} +49 -30
  31. package/dist/chunk-A5GKIG5O.js.map +1 -0
  32. package/dist/{chunk-YFPY4ONH.js → chunk-AGMVASXZ.js} +4 -4
  33. package/dist/chunk-BF4XHEQK.js +116 -0
  34. package/dist/chunk-BF4XHEQK.js.map +1 -0
  35. package/dist/chunk-BFDQ4WNW.js +119 -0
  36. package/dist/chunk-BFDQ4WNW.js.map +1 -0
  37. package/dist/{chunk-P4NH7OUK.js → chunk-C2Q76BVM.js} +49 -50
  38. package/dist/chunk-C2Q76BVM.js.map +1 -0
  39. package/dist/chunk-CEXSOI5R.js +808 -0
  40. package/dist/chunk-CEXSOI5R.js.map +1 -0
  41. package/dist/{chunk-QSCPK4F5.js → chunk-E7SW44LM.js} +4 -11
  42. package/dist/chunk-E7SW44LM.js.map +1 -0
  43. package/dist/chunk-EDJWHDDL.js +33 -0
  44. package/dist/chunk-EDJWHDDL.js.map +1 -0
  45. package/dist/chunk-F3ED5WTR.js +13 -0
  46. package/dist/chunk-F3ED5WTR.js.map +1 -0
  47. package/dist/{chunk-K72RURN3.js → chunk-FVIGCDSV.js} +2 -2
  48. package/dist/chunk-FVIGCDSV.js.map +1 -0
  49. package/dist/{chunk-5K5W4S66.js → chunk-GTTUCOPD.js} +2 -2
  50. package/dist/{chunk-4ZZO6ULA.js → chunk-HDPUXS3Z.js} +19 -48
  51. package/dist/chunk-HDPUXS3Z.js.map +1 -0
  52. package/dist/{chunk-LEFIX6RS.js → chunk-HGGWCP7W.js} +31 -11
  53. package/dist/chunk-HGGWCP7W.js.map +1 -0
  54. package/dist/{chunk-ORWL5BSN.js → chunk-HGZEPQUT.js} +2 -2
  55. package/dist/chunk-HMWYAUA6.js +478 -0
  56. package/dist/chunk-HMWYAUA6.js.map +1 -0
  57. package/dist/{chunk-7QKHZQKW.js → chunk-IADZOXKN.js} +39 -6
  58. package/dist/chunk-IADZOXKN.js.map +1 -0
  59. package/dist/{chunk-7Q5FDF65.js → chunk-IE7P2BZE.js} +3 -3
  60. package/dist/{chunk-77TCKDEC.js → chunk-ILNIZ5I2.js} +788 -508
  61. package/dist/chunk-ILNIZ5I2.js.map +1 -0
  62. package/dist/{hosts-FWZOV26H.js → chunk-INTFHMU4.js} +79 -24
  63. package/dist/chunk-INTFHMU4.js.map +1 -0
  64. package/dist/{chunk-6E5R45ZO.js → chunk-J57UC3DD.js} +4 -4
  65. package/dist/{chunk-6E5R45ZO.js.map → chunk-J57UC3DD.js.map} +1 -1
  66. package/dist/chunk-JNJWBTU2.js +3497 -0
  67. package/dist/chunk-JNJWBTU2.js.map +1 -0
  68. package/dist/{chunk-7WU4OPLP.js → chunk-KM7RY2ZS.js} +5 -3
  69. package/dist/{chunk-7WU4OPLP.js.map → chunk-KM7RY2ZS.js.map} +1 -1
  70. package/dist/chunk-L6JEXB3E.js +293 -0
  71. package/dist/chunk-L6JEXB3E.js.map +1 -0
  72. package/dist/chunk-LRW6S53P.js +450 -0
  73. package/dist/chunk-LRW6S53P.js.map +1 -0
  74. package/dist/{chunk-UKY4CHNC.js → chunk-LXAYUOXI.js} +24 -11
  75. package/dist/chunk-LXAYUOXI.js.map +1 -0
  76. package/dist/{chunk-WJXLQXJY.js → chunk-MPZUYCAP.js} +4 -1
  77. package/dist/{chunk-WJXLQXJY.js.map → chunk-MPZUYCAP.js.map} +1 -1
  78. package/dist/chunk-NDGZDTSJ.js +393 -0
  79. package/dist/chunk-NDGZDTSJ.js.map +1 -0
  80. package/dist/{chunk-SJLTEINJ.js → chunk-OJNTCYQQ.js} +17 -1
  81. package/dist/chunk-OJNTCYQQ.js.map +1 -0
  82. package/dist/{chunk-OHRR5OYM.js → chunk-P3LFTKE7.js} +5 -10
  83. package/dist/chunk-P3LFTKE7.js.map +1 -0
  84. package/dist/{chunk-XZKD7DIF.js → chunk-RL5UUDT4.js} +3 -3
  85. package/dist/{chunk-XZKD7DIF.js.map → chunk-RL5UUDT4.js.map} +1 -1
  86. package/dist/{chunk-5C32RLTA.js → chunk-RVPYTUP4.js} +20 -5
  87. package/dist/chunk-RVPYTUP4.js.map +1 -0
  88. package/dist/{chunk-YVFXE7RR.js → chunk-SNNSAGMT.js} +7279 -2627
  89. package/dist/chunk-SNNSAGMT.js.map +1 -0
  90. package/dist/{chunk-WK7F3B2E.js → chunk-SO3XRZPX.js} +3 -3
  91. package/dist/{chunk-R5LCN54M.js → chunk-TC2WZLSC.js} +13 -17
  92. package/dist/{chunk-R5LCN54M.js.map → chunk-TC2WZLSC.js.map} +1 -1
  93. package/dist/{chunk-B7HUUJOK.js → chunk-TKPF35W6.js} +3 -3
  94. package/dist/{chunk-KXVP2VKA.js → chunk-U3IKUGRP.js} +32 -33
  95. package/dist/chunk-U3IKUGRP.js.map +1 -0
  96. package/dist/{chunk-AKWGE6JQ.js → chunk-UUGOUOVT.js} +37 -2
  97. package/dist/chunk-UUGOUOVT.js.map +1 -0
  98. package/dist/{chunk-2XLC3AEX.js → chunk-UXZONNEQ.js} +536 -510
  99. package/dist/chunk-UXZONNEQ.js.map +1 -0
  100. package/dist/{chunk-7ZRL2LBQ.js → chunk-V2LQLN5H.js} +6 -6
  101. package/dist/{chunk-NEFNKLBE.js → chunk-WFSPCCVW.js} +1536 -423
  102. package/dist/chunk-WFSPCCVW.js.map +1 -0
  103. package/dist/{chunk-27EPWVOY.js → chunk-WXA2BWTE.js} +7 -3
  104. package/dist/chunk-WXA2BWTE.js.map +1 -0
  105. package/dist/chunk-WYXUQGOL.js +191 -0
  106. package/dist/chunk-WYXUQGOL.js.map +1 -0
  107. package/dist/chunk-X5ZBP3IY.js +97 -0
  108. package/dist/chunk-X5ZBP3IY.js.map +1 -0
  109. package/dist/{chunk-MNXS2U45.js → chunk-ZDZERB6L.js} +206 -297
  110. package/dist/chunk-ZDZERB6L.js.map +1 -0
  111. package/dist/chunk-ZNNXRNFD.js +113 -0
  112. package/dist/chunk-ZNNXRNFD.js.map +1 -0
  113. package/dist/{chunk-FW75G2W4.js → chunk-ZURZHELF.js} +5 -5
  114. package/dist/{cli-D5OE3URZ.js → cli-E36SPKBW.js} +145 -64
  115. package/dist/{cli-D5OE3URZ.js.map → cli-E36SPKBW.js.map} +1 -1
  116. package/dist/{codex-event-PPNVRRDH.js → codex-event-ZO2GEFE6.js} +2 -2
  117. package/dist/{codex-host-2RJOJW2B.js → codex-host-KECJVTA2.js} +7 -6
  118. package/dist/codex-install-HQZDGFXW.js +436 -0
  119. package/dist/codex-install-HQZDGFXW.js.map +1 -0
  120. package/dist/{config-ZD4OB2DO.js → config-HY2E4GGW.js} +21 -17
  121. package/dist/doctor-I6XQEKWD.js +1323 -0
  122. package/dist/doctor-I6XQEKWD.js.map +1 -0
  123. package/dist/{env-proxy-XL4P73MZ.js → env-proxy-R6ZMLQTT.js} +6 -2
  124. package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js → ethersCompat-Df4a6QIZ-X6YZWAML.js} +3 -3
  125. package/dist/{fund-5ITKQGYF.js → fund-2QRO7OJL.js} +43 -37
  126. package/dist/{fund-5ITKQGYF.js.map → fund-2QRO7OJL.js.map} +1 -1
  127. package/dist/hook-command-2UBCSZG6.js +43 -0
  128. package/dist/hosts/claude/.claude-plugin/marketplace.json +2 -2
  129. package/dist/hosts/claude/tenjin/.claude-plugin/plugin.json +2 -2
  130. package/dist/hosts/claude/tenjin/hooks/register.tsx +51 -11
  131. package/dist/hosts/claude/tenjin/skills/tenjin-pay/SKILL.md +82 -0
  132. package/dist/hosts/claude/tenjin/types/index.d.ts +2 -1
  133. package/dist/hosts/codex/tenjin/.mcp.json +3 -0
  134. package/dist/hosts/codex/tenjin/hooks/hooks.json +51 -5
  135. package/dist/hosts-DVQJ32QC.js +38 -0
  136. package/dist/index.js +32 -11
  137. package/dist/index.js.map +1 -1
  138. package/dist/install-ILUX5C4A.js +107 -0
  139. package/dist/{install-identity-K7EJIQFP.js → install-identity-TZKGY6LQ.js} +11 -10
  140. package/dist/install-wallet-5M4OTYLX.js +281 -0
  141. package/dist/install-wallet-5M4OTYLX.js.map +1 -0
  142. package/dist/isows-native-Q2UDIVPT.js +9 -0
  143. package/dist/isows-native-Q2UDIVPT.js.map +1 -0
  144. package/dist/{mcp-3LIJSSJB.js → mcp-LE4DUS22.js} +785 -211
  145. package/dist/mcp-LE4DUS22.js.map +1 -0
  146. package/dist/{mine.wasm-6PIT3DK6.js → mine.wasm-QFAHIFPY.js} +2 -2
  147. package/dist/{mine.wasm-6PIT3DK6.js.map → mine.wasm-QFAHIFPY.js.map} +1 -1
  148. package/dist/{package-ZKQFDWLE.js → package-IJFGMWEV.js} +4 -2
  149. package/dist/passphrase-IFTDS3CU.js +44 -0
  150. package/dist/{paths-POPTXJO6.js → paths-XCSAKISU.js} +10 -2
  151. package/dist/{pay-WHBERZ3W.js → pay-WCG3IH4R.js} +29 -29
  152. package/dist/{payments-KVICEKD2.js → payments-HFPPWHTV.js} +15 -14
  153. package/dist/{payments-KVICEKD2.js.map → payments-HFPPWHTV.js.map} +1 -1
  154. package/dist/plugin-registration-PZFI5GZW.js +68 -0
  155. package/dist/{redact-6W23GGJC.js → redact-D7ASVWKL.js} +2 -2
  156. package/dist/runtime-UZOKSUZX.js +1321 -0
  157. package/dist/runtime-UZOKSUZX.js.map +1 -0
  158. package/dist/runtime-fetch-ZSSSK72Y.js +23 -0
  159. package/dist/runtime-layout-WIDILZ6K.js +25 -0
  160. package/dist/{send-7G7Y7DLN.js → send-GCVEAQKL.js} +24 -22
  161. package/dist/{send-7G7Y7DLN.js.map → send-GCVEAQKL.js.map} +1 -1
  162. package/dist/{status-OF7RH5HM.js → status-HCVAOCN7.js} +55 -25
  163. package/dist/status-HCVAOCN7.js.map +1 -0
  164. package/dist/{status-line-XOUE6MPL.js → status-line-OPCXDHL2.js} +10 -9
  165. package/dist/{status-line-XOUE6MPL.js.map → status-line-OPCXDHL2.js.map} +1 -1
  166. package/dist/uninstall-BAWRBXXQ.js +481 -0
  167. package/dist/uninstall-BAWRBXXQ.js.map +1 -0
  168. package/dist/update-CACXLQLR.js +56 -0
  169. package/dist/update-CACXLQLR.js.map +1 -0
  170. package/dist/{usdc-OGOGEHV2.js → usdc-VG4CIOUK.js} +6 -8
  171. package/dist/usdc-VG4CIOUK.js.map +1 -0
  172. package/dist/{viemAdapter-By13KInL-S3DA7DFW.js → viemAdapter-By13KInL-DOFTEIJV.js} +3 -3
  173. package/dist/viemAdapter-By13KInL-DOFTEIJV.js.map +1 -0
  174. package/dist/wallet-QL4UUXEZ.js +55 -0
  175. package/dist/wallet-QL4UUXEZ.js.map +1 -0
  176. package/dist/wallet-kdf-worker.mjs +8 -8
  177. package/docs/agent-permissions.md +50 -28
  178. package/docs/safety-model.md +1 -1
  179. package/docs/troubleshooting.md +72 -1
  180. package/package.json +17 -4
  181. package/scripts/installers/install.ps1 +67 -0
  182. package/scripts/installers/install.sh +68 -0
  183. package/dist/_esm-C5CRWCYU.js +0 -3737
  184. package/dist/_esm-C5CRWCYU.js.map +0 -1
  185. package/dist/ccip-NLCSCHKI.js +0 -19
  186. package/dist/chunk-27EPWVOY.js.map +0 -1
  187. package/dist/chunk-2XLC3AEX.js.map +0 -1
  188. package/dist/chunk-4ZZO6ULA.js.map +0 -1
  189. package/dist/chunk-5C32RLTA.js.map +0 -1
  190. package/dist/chunk-5IEP5EGE.js +0 -5332
  191. package/dist/chunk-5IEP5EGE.js.map +0 -1
  192. package/dist/chunk-5MARFNSB.js.map +0 -1
  193. package/dist/chunk-77TCKDEC.js.map +0 -1
  194. package/dist/chunk-7EKYXMUO.js +0 -7536
  195. package/dist/chunk-7EKYXMUO.js.map +0 -1
  196. package/dist/chunk-7QKHZQKW.js.map +0 -1
  197. package/dist/chunk-AGZ7PJKY.js.map +0 -1
  198. package/dist/chunk-AKWGE6JQ.js.map +0 -1
  199. package/dist/chunk-BL3332HQ.js +0 -7611
  200. package/dist/chunk-BL3332HQ.js.map +0 -1
  201. package/dist/chunk-D65GNPS3.js.map +0 -1
  202. package/dist/chunk-EGELTSPU.js +0 -2865
  203. package/dist/chunk-EGELTSPU.js.map +0 -1
  204. package/dist/chunk-GA7JETVM.js +0 -150
  205. package/dist/chunk-GA7JETVM.js.map +0 -1
  206. package/dist/chunk-I3EQFHCD.js +0 -175
  207. package/dist/chunk-I3EQFHCD.js.map +0 -1
  208. package/dist/chunk-K3I7C2MO.js +0 -1185
  209. package/dist/chunk-K3I7C2MO.js.map +0 -1
  210. package/dist/chunk-K72RURN3.js.map +0 -1
  211. package/dist/chunk-KXVP2VKA.js.map +0 -1
  212. package/dist/chunk-LEFIX6RS.js.map +0 -1
  213. package/dist/chunk-MNXS2U45.js.map +0 -1
  214. package/dist/chunk-NEFNKLBE.js.map +0 -1
  215. package/dist/chunk-OHRR5OYM.js.map +0 -1
  216. package/dist/chunk-P4NH7OUK.js.map +0 -1
  217. package/dist/chunk-QSCPK4F5.js.map +0 -1
  218. package/dist/chunk-SJLTEINJ.js.map +0 -1
  219. package/dist/chunk-TTNESUPQ.js.map +0 -1
  220. package/dist/chunk-UKY4CHNC.js.map +0 -1
  221. package/dist/chunk-V6BSF6OC.js +0 -260
  222. package/dist/chunk-V6BSF6OC.js.map +0 -1
  223. package/dist/chunk-YVFXE7RR.js.map +0 -1
  224. package/dist/codex-install-UUZ6QMBQ.js +0 -221
  225. package/dist/codex-install-UUZ6QMBQ.js.map +0 -1
  226. package/dist/doctor-KBR34Q4B.js +0 -601
  227. package/dist/doctor-KBR34Q4B.js.map +0 -1
  228. package/dist/hook-command-4TYCHHRL.js +0 -39
  229. package/dist/hosts-FWZOV26H.js.map +0 -1
  230. package/dist/install-XWGE4Q7L.js +0 -77
  231. package/dist/install-wallet-XQ6XFZV4.js +0 -117
  232. package/dist/install-wallet-XQ6XFZV4.js.map +0 -1
  233. package/dist/mcp-3LIJSSJB.js.map +0 -1
  234. package/dist/plugin-registration-5TIA564H.js +0 -54
  235. package/dist/status-OF7RH5HM.js.map +0 -1
  236. package/dist/uninstall-JXUAFNDB.js +0 -158
  237. package/dist/uninstall-JXUAFNDB.js.map +0 -1
  238. package/dist/update-ZKUERSO2.js +0 -44
  239. package/dist/wallet-2HA6W4R4.js +0 -43
  240. /package/dist/{_esm-MEXZI5DL.js.map → _esm-BIN7VY2L.js.map} +0 -0
  241. /package/dist/{alive-J64H46HI.js.map → alive-GSOWKUOY.js.map} +0 -0
  242. /package/dist/{ccip-7RMRLAGV.js.map → auto-update-Y24UL56V.js.map} +0 -0
  243. /package/dist/{ccip-NLCSCHKI.js.map → ccip-DHDFKTQV.js.map} +0 -0
  244. /package/dist/{chunk-UQUOVWBG.js.map → chunk-4K7TQHNP.js.map} +0 -0
  245. /package/dist/{chunk-KXQ4UIP7.js.map → chunk-4USCZ2NI.js.map} +0 -0
  246. /package/dist/{chunk-YFPY4ONH.js.map → chunk-AGMVASXZ.js.map} +0 -0
  247. /package/dist/{chunk-5K5W4S66.js.map → chunk-GTTUCOPD.js.map} +0 -0
  248. /package/dist/{chunk-ORWL5BSN.js.map → chunk-HGZEPQUT.js.map} +0 -0
  249. /package/dist/{chunk-7Q5FDF65.js.map → chunk-IE7P2BZE.js.map} +0 -0
  250. /package/dist/{chunk-WK7F3B2E.js.map → chunk-SO3XRZPX.js.map} +0 -0
  251. /package/dist/{chunk-B7HUUJOK.js.map → chunk-TKPF35W6.js.map} +0 -0
  252. /package/dist/{chunk-7ZRL2LBQ.js.map → chunk-V2LQLN5H.js.map} +0 -0
  253. /package/dist/{chunk-FW75G2W4.js.map → chunk-ZURZHELF.js.map} +0 -0
  254. /package/dist/{codex-event-PPNVRRDH.js.map → codex-event-ZO2GEFE6.js.map} +0 -0
  255. /package/dist/{codex-host-2RJOJW2B.js.map → codex-host-KECJVTA2.js.map} +0 -0
  256. /package/dist/{config-ZD4OB2DO.js.map → config-HY2E4GGW.js.map} +0 -0
  257. /package/dist/{env-proxy-XL4P73MZ.js.map → env-proxy-R6ZMLQTT.js.map} +0 -0
  258. /package/dist/{ethersCompat-Df4a6QIZ-THAVUGIJ.js.map → ethersCompat-Df4a6QIZ-X6YZWAML.js.map} +0 -0
  259. /package/dist/{hook-command-4TYCHHRL.js.map → hook-command-2UBCSZG6.js.map} +0 -0
  260. /package/dist/{install-XWGE4Q7L.js.map → hosts-DVQJ32QC.js.map} +0 -0
  261. /package/dist/{install-identity-K7EJIQFP.js.map → install-ILUX5C4A.js.map} +0 -0
  262. /package/dist/{package-ZKQFDWLE.js.map → install-identity-TZKGY6LQ.js.map} +0 -0
  263. /package/dist/{paths-POPTXJO6.js.map → package-IJFGMWEV.js.map} +0 -0
  264. /package/dist/{pay-WHBERZ3W.js.map → passphrase-IFTDS3CU.js.map} +0 -0
  265. /package/dist/{plugin-registration-5TIA564H.js.map → paths-XCSAKISU.js.map} +0 -0
  266. /package/dist/{redact-6W23GGJC.js.map → pay-WCG3IH4R.js.map} +0 -0
  267. /package/dist/{update-ZKUERSO2.js.map → plugin-registration-PZFI5GZW.js.map} +0 -0
  268. /package/dist/{usdc-OGOGEHV2.js.map → redact-D7ASVWKL.js.map} +0 -0
  269. /package/dist/{viemAdapter-By13KInL-S3DA7DFW.js.map → runtime-fetch-ZSSSK72Y.js.map} +0 -0
  270. /package/dist/{wallet-2HA6W4R4.js.map → runtime-layout-WIDILZ6K.js.map} +0 -0
@@ -1,7 +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-7ZRL2LBQ.js";
4
+ } from "./chunk-V2LQLN5H.js";
5
+ import {
6
+ emitNotice
7
+ } from "./chunk-FVIGCDSV.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";
5
20
  import {
6
21
  hashAuthorization,
7
22
  hashMessage,
@@ -10,7 +25,12 @@ import {
10
25
  publicKeyToAddress,
11
26
  serializeSignature,
12
27
  serializeTransaction
13
- } from "./chunk-K3I7C2MO.js";
28
+ } from "./chunk-WFSPCCVW.js";
29
+ import {
30
+ hmac,
31
+ secp256k1,
32
+ sha256
33
+ } from "./chunk-JRGFKVAZ.js";
14
34
  import {
15
35
  InvalidAddressError,
16
36
  concat3 as concat,
@@ -25,12 +45,7 @@ import {
25
45
  slice3 as slice,
26
46
  toHex,
27
47
  toHex2
28
- } from "./chunk-EGELTSPU.js";
29
- import {
30
- hmac,
31
- secp256k1,
32
- sha256
33
- } from "./chunk-JRGFKVAZ.js";
48
+ } from "./chunk-2GP3HRYK.js";
34
49
  import {
35
50
  ahash,
36
51
  anumber,
@@ -44,33 +59,41 @@ import {
44
59
  u32
45
60
  } from "./chunk-BPMWXTFX.js";
46
61
  import {
47
- emitNotice
48
- } from "./chunk-K72RURN3.js";
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
79
  external_exports
54
- } from "./chunk-YVFXE7RR.js";
55
- import {
56
- CliError
57
- } from "./chunk-3UCIG4TG.js";
80
+ } from "./chunk-SNNSAGMT.js";
58
81
  import {
59
82
  fsyncDir,
60
- writeFileAtomic,
61
83
  writeFileAtomicExclusive
62
84
  } from "./chunk-7WEQQJLG.js";
85
+ import {
86
+ CliError
87
+ } from "./chunk-3UCIG4TG.js";
63
88
  import {
64
89
  archivedWalletPath,
65
- passphraseBlobPath,
66
- passphraseBlobPathFor,
90
+ passphraseFilePathFor,
67
91
  spendLedgerPath,
68
92
  walletPath
69
- } from "./chunk-SJLTEINJ.js";
93
+ } from "./chunk-OJNTCYQQ.js";
70
94
 
71
95
  // src/lib/wallet/store.ts
72
96
  import { readFile, stat } from "node:fs/promises";
73
- var PRIVATE_KEY_RE = /^0x[0-9a-f]{64}$/i;
74
97
  var ADDRESS_RE = /^0x[0-9a-fA-F]{40}$/;
75
98
  var KeystoreV3Schema = external_exports.object({
76
99
  crypto: external_exports.object({
@@ -112,7 +135,8 @@ async function readWalletRecord(dir) {
112
135
  if (isNotFound(err)) return null;
113
136
  throw new CliError("WALLET_INVALID_KEY", `Could not read the wallet file at ${path}.`, {
114
137
  fix: `Check file permissions on ${path}.`,
115
- cause: err
138
+ cause: err,
139
+ details: unlockDetails("wallet_corrupt")
116
140
  });
117
141
  }
118
142
  let json;
@@ -121,7 +145,8 @@ async function readWalletRecord(dir) {
121
145
  } catch (err) {
122
146
  throw new CliError("WALLET_INVALID_KEY", `The wallet file at ${path} is not valid JSON.`, {
123
147
  fix: `Move ${path} aside, then run \`tenjin wallet create\`.`,
124
- cause: err
148
+ cause: err,
149
+ details: unlockDetails("wallet_corrupt")
125
150
  });
126
151
  }
127
152
  if (isPreEncryptionRecord(json)) {
@@ -129,7 +154,8 @@ async function readWalletRecord(dir) {
129
154
  "WALLET_INVALID_KEY",
130
155
  `The wallet file at ${path} predates encrypted storage.`,
131
156
  {
132
- 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")
133
159
  }
134
160
  );
135
161
  }
@@ -191,344 +217,8 @@ function isNotFound(err) {
191
217
  return hasCode(err, "ENOENT");
192
218
  }
193
219
 
194
- // src/lib/wallet/passphrase.ts
195
- import { execFile } from "node:child_process";
196
- import { randomBytes } from "node:crypto";
197
- import { readFile as readFile2, unlink } from "node:fs/promises";
198
- var KEYCHAIN_SERVICE = "tenjin-cli";
199
- var LEGACY_ACCOUNT = "wallet";
200
- var ACCOUNT_ADDRESS_RE = /^0x[0-9a-f]{40}$/;
201
- var BASE64URL_RE = /^[A-Za-z0-9_-]+$/;
202
- function walletStoreAccount(address) {
203
- const account = address.toLowerCase();
204
- if (!ACCOUNT_ADDRESS_RE.test(account)) {
205
- throw new CliError("INTERNAL", `Not a valid wallet address for passphrase storage: ${address}`);
206
- }
207
- return account;
208
- }
209
- function defaultExecFor(timeoutMs) {
210
- return (file, args, stdin) => new Promise((resolve, reject) => {
211
- const child = execFile(
212
- file,
213
- args,
214
- { encoding: "utf8", ...timeoutMs !== void 0 ? { timeout: timeoutMs } : {} },
215
- (err, stdout, stderr) => {
216
- if (err) reject(err);
217
- else resolve({ stdout, stderr });
218
- }
219
- );
220
- if (stdin !== void 0) {
221
- child.stdin?.on("error", () => void 0);
222
- child.stdin?.end(stdin);
223
- }
224
- });
225
- }
226
- function storeFor(deps) {
227
- switch (deps.platform ?? process.platform) {
228
- case "darwin":
229
- return keychainStore(deps);
230
- case "win32":
231
- return dpapiStore(deps);
232
- case "linux":
233
- return secretServiceStore(deps);
234
- default:
235
- return null;
236
- }
237
- }
238
- async function resolvePassphrase(deps, address) {
239
- const fromEnv = envPassphrase(deps.env);
240
- if (fromEnv !== null) return { passphrase: fromEnv, source: "env" };
241
- const store = storeFor(deps);
242
- if (store !== null) {
243
- const account = walletStoreAccount(address);
244
- const own = await store.read(account);
245
- if (own !== null) return { passphrase: own, source: store.source };
246
- const legacy = await store.read(LEGACY_ACCOUNT);
247
- if (legacy !== null) {
248
- return {
249
- passphrase: legacy,
250
- source: store.source,
251
- migrateLegacy: () => migrateLegacyEntry(store, account, legacy)
252
- };
253
- }
254
- }
255
- if (canPrompt(deps)) {
256
- const entered = await promptOf(deps)("Wallet passphrase: ");
257
- if (entered.length === 0) throw noPassphraseError();
258
- return { passphrase: entered, source: "prompt" };
259
- }
260
- throw noPassphraseError();
261
- }
262
- async function migrateLegacyEntry(store, account, passphrase) {
263
- if (!await store.store(account, passphrase)) return false;
264
- if (await store.read(account) !== passphrase) return false;
265
- await store.remove(LEGACY_ACCOUNT);
266
- return true;
267
- }
268
- async function storePassphraseForWallet(deps, address, passphrase) {
269
- const store = storeFor(deps);
270
- if (store === null) return "no-store";
271
- const account = walletStoreAccount(address);
272
- if (await store.read(account) === passphrase) return "stored";
273
- if (store.storable !== void 0 && !store.storable(passphrase)) return "rejected-characters";
274
- if (!await store.store(account, passphrase)) return "store-failed";
275
- return await store.read(account) === passphrase ? "stored" : "store-failed";
276
- }
277
- async function resolvePassphraseForCreate(deps, address) {
278
- const fromEnv = envPassphrase(deps.env);
279
- if (fromEnv !== null) return { passphrase: fromEnv, source: "env" };
280
- const store = storeFor(deps);
281
- if (store !== null) {
282
- const account = walletStoreAccount(address);
283
- const generated = randomBytes(32).toString("base64url");
284
- if (await store.store(account, generated) && await store.read(account) === generated) {
285
- return { passphrase: generated, source: store.source };
286
- }
287
- }
288
- if (canPrompt(deps)) {
289
- const prompt = promptOf(deps);
290
- const first = await prompt("Set a wallet passphrase: ");
291
- if (first.length === 0) {
292
- throw new CliError("USAGE", "The wallet passphrase must not be empty.", {
293
- fix: "Enter a non-empty passphrase, or set TENJIN_WALLET_PASSPHRASE."
294
- });
295
- }
296
- const second = await prompt("Confirm passphrase: ");
297
- if (first !== second) {
298
- throw new CliError("USAGE", "The passphrases did not match.", {
299
- fix: "Run `tenjin wallet create` again and enter the same passphrase both times."
300
- });
301
- }
302
- return { passphrase: first, source: "prompt" };
303
- }
304
- throw noPassphraseError();
305
- }
306
- function keychainStore(deps) {
307
- const exec = deps.exec ?? defaultExecFor(deps.timeoutMs);
308
- return {
309
- source: "keychain",
310
- async read(account) {
311
- try {
312
- const { stdout } = await exec("security", [
313
- "find-generic-password",
314
- "-s",
315
- KEYCHAIN_SERVICE,
316
- "-a",
317
- account,
318
- "-w"
319
- ]);
320
- return trimmedNonEmpty(stdout);
321
- } catch {
322
- return null;
323
- }
324
- },
325
- // The one backend that interpolates into a command line, so only base64url
326
- // values pass; escaping is NOT a safe alternative (backslash bites even
327
- // inside single quotes there).
328
- storable: (passphrase) => BASE64URL_RE.test(passphrase),
329
- async store(account, passphrase) {
330
- if (!BASE64URL_RE.test(passphrase) || !BASE64URL_RE.test(account)) return false;
331
- try {
332
- const command = `add-generic-password -s ${KEYCHAIN_SERVICE} -a ${account} -w '${passphrase}'
333
- `;
334
- await exec("security", ["-i"], command);
335
- return true;
336
- } catch {
337
- return false;
338
- }
339
- },
340
- async remove(account) {
341
- try {
342
- await exec("security", ["delete-generic-password", "-s", KEYCHAIN_SERVICE, "-a", account]);
343
- return true;
344
- } catch {
345
- return false;
346
- }
347
- }
348
- };
349
- }
350
- var DPAPI_PROTECT_SCRIPT = [
351
- "Add-Type -AssemblyName System.Security;",
352
- "$in = [Console]::In.ReadToEnd();",
353
- "$bytes = [System.Text.Encoding]::UTF8.GetBytes($in);",
354
- "$prot = [System.Security.Cryptography.ProtectedData]::Protect($bytes, $null, 'CurrentUser');",
355
- "[Console]::Out.Write([Convert]::ToBase64String($prot));"
356
- ].join(" ");
357
- var DPAPI_UNPROTECT_SCRIPT = [
358
- "Add-Type -AssemblyName System.Security;",
359
- "$in = [Console]::In.ReadToEnd();",
360
- "$blob = [Convert]::FromBase64String($in.Trim());",
361
- "$plain = [System.Security.Cryptography.ProtectedData]::Unprotect($blob, $null, 'CurrentUser');",
362
- "[Console]::Out.Write([System.Text.Encoding]::UTF8.GetString($plain));"
363
- ].join(" ");
364
- function powershellArgs(script) {
365
- return ["-NoProfile", "-NonInteractive", "-Command", script];
366
- }
367
- function dpapiStore(deps) {
368
- const exec = deps.exec ?? defaultExecFor(deps.timeoutMs);
369
- const blobPathFor = (account) => account === LEGACY_ACCOUNT ? passphraseBlobPath(deps.dir) : passphraseBlobPathFor(account, deps.dir);
370
- return {
371
- source: "dpapi",
372
- async read(account) {
373
- let blob;
374
- try {
375
- blob = await readFile2(blobPathFor(account), "utf8");
376
- } catch {
377
- return null;
378
- }
379
- try {
380
- const { stdout } = await exec(
381
- "powershell.exe",
382
- powershellArgs(DPAPI_UNPROTECT_SCRIPT),
383
- blob
384
- );
385
- const passphrase = stdout.replace(/\r?\n$/, "");
386
- return passphrase.length > 0 ? passphrase : null;
387
- } catch {
388
- return null;
389
- }
390
- },
391
- async store(account, passphrase) {
392
- try {
393
- const { stdout } = await exec(
394
- "powershell.exe",
395
- powershellArgs(DPAPI_PROTECT_SCRIPT),
396
- passphrase
397
- );
398
- const blob = stdout.replace(/\r?\n$/, "").trim();
399
- if (blob.length === 0) return false;
400
- await writeFileAtomic(blobPathFor(account), blob, { mode: 384 });
401
- return true;
402
- } catch {
403
- return false;
404
- }
405
- },
406
- async remove(account) {
407
- try {
408
- await unlink(blobPathFor(account));
409
- return true;
410
- } catch {
411
- return false;
412
- }
413
- }
414
- };
415
- }
416
- function secretServiceStore(deps) {
417
- const exec = deps.exec ?? defaultExecFor(deps.timeoutMs);
418
- return {
419
- source: "secret-service",
420
- async read(account) {
421
- try {
422
- const { stdout } = await exec("secret-tool", [
423
- "lookup",
424
- "service",
425
- KEYCHAIN_SERVICE,
426
- "account",
427
- account
428
- ]);
429
- return trimmedNonEmpty(stdout);
430
- } catch {
431
- return null;
432
- }
433
- },
434
- async store(account, passphrase) {
435
- try {
436
- await exec(
437
- "secret-tool",
438
- [
439
- "store",
440
- `--label=tenjin-cli wallet ${account}`,
441
- "service",
442
- KEYCHAIN_SERVICE,
443
- "account",
444
- account
445
- ],
446
- passphrase
447
- );
448
- return true;
449
- } catch {
450
- return false;
451
- }
452
- },
453
- async remove(account) {
454
- try {
455
- await exec("secret-tool", ["clear", "service", KEYCHAIN_SERVICE, "account", account]);
456
- return true;
457
- } catch {
458
- return false;
459
- }
460
- }
461
- };
462
- }
463
- function trimmedNonEmpty(stdout) {
464
- const value = stdout.replace(/\r?\n$/, "");
465
- return value.length > 0 ? value : null;
466
- }
467
- function envPassphrase(env) {
468
- const value = env.TENJIN_WALLET_PASSPHRASE;
469
- return value !== void 0 && value.length > 0 ? value : null;
470
- }
471
- function canPrompt(deps) {
472
- return deps.isTTY ?? Boolean(process.stdin.isTTY);
473
- }
474
- function promptOf(deps) {
475
- return deps.prompt ?? promptHidden;
476
- }
477
- function noPassphraseError() {
478
- return new CliError("USAGE", "No wallet passphrase is available.", {
479
- fix: "Set TENJIN_WALLET_PASSPHRASE (headless) or run in a terminal."
480
- });
481
- }
482
- var CTRL_C = 3;
483
- var CTRL_D = 4;
484
- var BACKSPACE = 127;
485
- var BACKSPACE_ALT = 8;
486
- function promptHidden(label) {
487
- return new Promise((resolve, reject) => {
488
- const stdin = process.stdin;
489
- const stderr = process.stderr;
490
- const wasRaw = stdin.isRaw;
491
- let value = "";
492
- const cleanup = () => {
493
- stdin.setRawMode?.(wasRaw ?? false);
494
- stdin.pause();
495
- stdin.removeListener("data", onData);
496
- };
497
- const onData = (chunk) => {
498
- for (const ch of chunk.toString("utf8")) {
499
- const code = ch.charCodeAt(0);
500
- if (ch === "\n" || ch === "\r" || code === CTRL_D) {
501
- cleanup();
502
- stderr.write("\n");
503
- resolve(value);
504
- return;
505
- }
506
- if (code === CTRL_C) {
507
- cleanup();
508
- stderr.write("\n");
509
- reject(
510
- new CliError("USAGE", "Passphrase entry was cancelled.", {
511
- fix: "Run the command again, or set TENJIN_WALLET_PASSPHRASE."
512
- })
513
- );
514
- return;
515
- }
516
- if (code === BACKSPACE || code === BACKSPACE_ALT) {
517
- value = value.slice(0, -1);
518
- } else {
519
- value += ch;
520
- }
521
- }
522
- };
523
- stderr.write(label);
524
- stdin.setRawMode?.(true);
525
- stdin.resume();
526
- stdin.on("data", onData);
527
- });
528
- }
529
-
530
220
  // src/lib/wallet/local.ts
531
- import { link, readdir, unlink as unlink2 } from "node:fs/promises";
221
+ import { link, readdir, stat as stat2, unlink } from "node:fs/promises";
532
222
 
533
223
  // node_modules/.pnpm/@noble+hashes@1.8.0/node_modules/@noble/hashes/esm/pbkdf2.js
534
224
  function pbkdf2Init(hash, _password, _salt, _opts) {
@@ -575,12 +265,12 @@ function pbkdf2(hash, password, salt, opts) {
575
265
  return pbkdf2Output(PRF, PRFSalt, DK, prfW, u);
576
266
  }
577
267
 
578
- // 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
579
269
  function generatePrivateKey() {
580
270
  return toHex(secp256k1.utils.randomPrivateKey());
581
271
  }
582
272
 
583
- // 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
584
274
  function toAccount(source) {
585
275
  if (typeof source === "string") {
586
276
  if (!isAddress(source, { strict: false }))
@@ -605,7 +295,7 @@ function toAccount(source) {
605
295
  };
606
296
  }
607
297
 
608
- // 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
609
299
  var extraEntropy = false;
610
300
  async function sign({ hash, privateKey, to = "object" }) {
611
301
  const { r, s, recovery } = secp256k1.sign(hash.slice(2), privateKey.slice(2), {
@@ -625,7 +315,7 @@ async function sign({ hash, privateKey, to = "object" }) {
625
315
  })();
626
316
  }
627
317
 
628
- // 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
629
319
  async function signAuthorization(parameters) {
630
320
  const { chainId, nonce, privateKey, to = "object" } = parameters;
631
321
  const address = parameters.contractAddress ?? parameters.address;
@@ -644,12 +334,12 @@ async function signAuthorization(parameters) {
644
334
  return signature;
645
335
  }
646
336
 
647
- // 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
648
338
  async function signMessage({ message, privateKey }) {
649
339
  return await sign({ hash: hashMessage(message), privateKey, to: "hex" });
650
340
  }
651
341
 
652
- // 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
653
343
  async function signTransaction(parameters) {
654
344
  const { privateKey, transaction, serializer = serializeTransaction } = parameters;
655
345
  const signableTransaction = (() => {
@@ -667,7 +357,7 @@ async function signTransaction(parameters) {
667
357
  return await serializer(transaction, signature);
668
358
  }
669
359
 
670
- // 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
671
361
  async function signTypedData(parameters) {
672
362
  const { privateKey, ...typedData } = parameters;
673
363
  return await sign({
@@ -677,7 +367,7 @@ async function signTypedData(parameters) {
677
367
  });
678
368
  }
679
369
 
680
- // 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
681
371
  function privateKeyToAccount(privateKey, options = {}) {
682
372
  const { nonceManager } = options;
683
373
  const publicKey = toHex(secp256k1.getPublicKey(privateKey.slice(2), false));
@@ -1122,7 +812,7 @@ async function scryptAsync(password, salt, opts) {
1122
812
  return scryptOutput(password, dkLen, B, V, tmp);
1123
813
  }
1124
814
 
1125
- // 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
1126
816
  function decrypt(keystore, key, options = {}) {
1127
817
  const { as = "Hex" } = options;
1128
818
  const key_ = from(typeof key === "function" ? key() : key);
@@ -1158,21 +848,6 @@ function encrypt2(privateKey, key, options) {
1158
848
  version: 3
1159
849
  };
1160
850
  }
1161
- function pbkdf22(options) {
1162
- const { iv, iterations = 262144, password } = options;
1163
- const salt = options.salt ? from(options.salt) : random(32);
1164
- const key = toHex2(pbkdf2(sha256, password, salt, { c: iterations, dkLen: 32 }));
1165
- return defineKey(() => key, {
1166
- iv,
1167
- kdfparams: {
1168
- c: iterations,
1169
- dklen: 32,
1170
- prf: "hmac-sha256",
1171
- salt: toHex2(salt).slice(2)
1172
- },
1173
- kdf: "pbkdf2"
1174
- });
1175
- }
1176
851
  async function scryptAsync2(options) {
1177
852
  const { iv, n = 262144, password } = options;
1178
853
  const p = 8;
@@ -1191,36 +866,6 @@ async function scryptAsync2(options) {
1191
866
  kdf: "scrypt"
1192
867
  });
1193
868
  }
1194
- async function toKeyAsync(keystore, options) {
1195
- const { crypto: crypto2 } = keystore;
1196
- const { password } = options;
1197
- const { cipherparams, kdf, kdfparams } = crypto2;
1198
- const { iv } = cipherparams;
1199
- const { c, n, p, r, salt } = kdfparams;
1200
- const [key] = await (async () => {
1201
- switch (kdf) {
1202
- case "scrypt":
1203
- return await scryptAsync2({
1204
- iv: from(`0x${iv}`),
1205
- n,
1206
- p,
1207
- r,
1208
- salt: from(`0x${salt}`),
1209
- password
1210
- });
1211
- case "pbkdf2":
1212
- return await pbkdf22({
1213
- iv: from(`0x${iv}`),
1214
- iterations: c,
1215
- password,
1216
- salt: from(`0x${salt}`)
1217
- });
1218
- default:
1219
- throw new Error("unsupported kdf");
1220
- }
1221
- })();
1222
- return key;
1223
- }
1224
869
  function defineKey(key, options) {
1225
870
  const iv = options.iv ? from(options.iv) : random(16);
1226
871
  return [key, { ...options, iv }];
@@ -1277,9 +922,14 @@ function derivationError(name) {
1277
922
  // src/lib/wallet/local.ts
1278
923
  var isWindows = process.platform === "win32";
1279
924
  var KEY_STORAGE = "encrypted (keystore v3, scrypt)";
1280
- var STORE_READ_TIMEOUT_MS = 5e3;
1281
925
  var signerCache = /* @__PURE__ */ new Map();
1282
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
+ };
1283
933
  return {
1284
934
  id: "local",
1285
935
  async describe() {
@@ -1296,7 +946,7 @@ function createLocalProvider(deps) {
1296
946
  },
1297
947
  async getSigner() {
1298
948
  const cred = await credentialOrThrow(deps);
1299
- const account = await accountForSigning(cred, deps);
949
+ const account = await accountForSigning(cred, deps, warnOnce);
1300
950
  return {
1301
951
  address: account.address,
1302
952
  signMessage: (args) => account.signMessage({ message: args.message }),
@@ -1312,70 +962,186 @@ function createLocalProvider(deps) {
1312
962
  }
1313
963
  };
1314
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
+ }
1315
1007
  async function verifyLocalWallet(deps) {
1316
1008
  const cred = await loadCredential(deps);
1317
1009
  if (cred === null) return { status: "unverified", detail: "there is no credential to verify" };
1318
1010
  if (cred.source === "env") {
1319
1011
  accountFromKey(cred.key, "env");
1320
- 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
+ };
1321
1017
  }
1322
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
+ };
1323
1042
  let resolved;
1324
1043
  try {
1325
- resolved = await resolvePassphrase(
1326
- {
1327
- env: deps.env,
1328
- dir: deps.dir,
1329
- ...deps.passphrase,
1330
- isTTY: false,
1331
- timeoutMs: STORE_READ_TIMEOUT_MS
1332
- },
1333
- 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
1334
1060
  );
1335
1061
  } catch {
1062
+ return cancelled;
1063
+ }
1064
+ const origin = resolvedOrigin(resolved, account, deps.dir);
1065
+ if (opened.kind === "ok") {
1336
1066
  return {
1337
- status: "unverified",
1338
- 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)
1339
1070
  };
1340
1071
  }
1341
- let key;
1342
- try {
1343
- const derived = await deriveKeystoreKey(cred.keystore, resolved.passphrase, deps.derivation);
1344
- key = decrypt(cred.keystore, derived);
1345
- } catch (error) {
1346
- if (error instanceof Error && ["AbortError", "TimeoutError"].includes(error.name)) {
1347
- return { status: "unverified", detail: "keystore verification was cancelled or timed out" };
1348
- }
1349
- if (resolved.migrateLegacy !== void 0) {
1350
- return {
1351
- status: "broken",
1352
- detail: `the keystore cannot be decrypted: the only stored passphrase is ${legacyOrigin(resolved.source)}, which does not open it`,
1353
- 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)}.`
1354
- };
1355
- }
1356
- 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) {
1357
1074
  return {
1358
1075
  status: "broken",
1359
- detail: `the keystore cannot be decrypted with the passphrase from ${passphraseOrigin(resolved.source, account)}`,
1360
- 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)
1361
1079
  };
1362
1080
  }
1363
- if (privateKeyToAccount(key).address.toLowerCase() !== account) {
1081
+ if (resolved.source !== "env") {
1364
1082
  return {
1365
1083
  status: "broken",
1366
- detail: `the decrypted key does not derive the wallet file's stored address ${cred.address}`,
1367
- 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
1368
1108
  };
1369
1109
  }
1110
+ if (fallback.kind === "mismatch") return tamperedVerification(cred.address, fallback);
1111
+ return envWrongVerification();
1112
+ }
1113
+ function envWrongVerification() {
1370
1114
  return {
1371
- status: "verified",
1372
- detail: `keystore decrypts with the passphrase from ${passphraseOrigin(resolved.source, account)}`
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
1373
1119
  };
1374
1120
  }
1375
- function passphraseOrigin(source, account) {
1121
+ function tamperedVerification(address, opened) {
1122
+ return {
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."
1127
+ };
1128
+ }
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) {
1376
1141
  if (source === "env") return "TENJIN_WALLET_PASSPHRASE";
1377
1142
  if (source === "prompt") return "the prompt";
1378
1143
  if (source === "dpapi") return `the DPAPI-protected passphrase file for ${account}`;
1144
+ if (source === "file") return describeStoreLocation("file", account, dir);
1379
1145
  return `the OS credential store (service tenjin-cli, account ${account})`;
1380
1146
  }
1381
1147
  function legacyOrigin(source) {
@@ -1400,15 +1166,36 @@ async function localWalletDiagnostics(deps) {
1400
1166
  );
1401
1167
  }
1402
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
+ }
1403
1182
  const passphraseSource = deps.env.TENJIN_WALLET_PASSPHRASE !== void 0 && deps.env.TENJIN_WALLET_PASSPHRASE.length > 0 ? "TENJIN_WALLET_PASSPHRASE" : void 0;
1404
1183
  const archivedWallets = await listArchivedWallets(deps.dir);
1405
1184
  return {
1406
1185
  ...fileExists ? { walletPath: path, keyStorage: KEY_STORAGE } : {},
1407
1186
  ...fileExists && passphraseSource !== void 0 ? { passphraseSource } : {},
1187
+ ...passphraseStore !== null ? { passphraseStore: passphraseStore.store } : {},
1408
1188
  ...archivedWallets.length > 0 ? { archivedWallets } : {},
1409
1189
  warnings
1410
1190
  };
1411
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
+ }
1412
1199
  var ARCHIVED_WALLET_RE = /^wallet\.(0x[0-9a-f]{40})\.json\.bak$/;
1413
1200
  async function listArchivedWallets(dir) {
1414
1201
  let names;
@@ -1443,27 +1230,34 @@ async function verifyAndPreserveOutgoingWallet(deps) {
1443
1230
  const address = record.address;
1444
1231
  const account = walletStoreAccount(address);
1445
1232
  const passphraseDeps = { env: deps.env, dir: deps.dir, ...deps.passphrase };
1446
- const resolved = await resolvePassphrase(passphraseDeps, address);
1447
- let key;
1233
+ const resolved = await resolvePassphrase(passphraseDeps, address, {
1234
+ promptLabel: `Passphrase for the existing wallet ${address}: `
1235
+ });
1236
+ let opened;
1448
1237
  try {
1449
- const derived = await toKeyAsync(record.keystore, { password: resolved.passphrase });
1450
- key = decrypt(record.keystore, derived);
1238
+ opened = await openKeystoreAccount(record.keystore, account, resolved.passphrase);
1451
1239
  } catch (err) {
1452
- 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 ")}`;
1453
1244
  throw new CliError(
1454
1245
  "REFUSED",
1455
1246
  `Cannot verify the passphrase of the existing wallet ${address}; --replace refused.`,
1456
1247
  {
1457
1248
  fix: `Replacing now could strand that wallet's funds. ${escape}, then retry.`,
1458
- cause: err
1249
+ cause: opened.cause
1459
1250
  }
1460
1251
  );
1461
1252
  }
1462
- if (privateKeyToAccount(key).address.toLowerCase() !== account) {
1253
+ if (opened.kind === "mismatch") {
1463
1254
  throw new CliError(
1464
1255
  "REFUSED",
1465
1256
  `The wallet file's stored address ${address} does not match its key; --replace refused.`,
1466
- { 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
+ }
1467
1261
  );
1468
1262
  }
1469
1263
  if (resolved.source === "env") {
@@ -1482,10 +1276,63 @@ async function verifyAndPreserveOutgoingWallet(deps) {
1482
1276
  return { address, account, passphraseLocation: "store" };
1483
1277
  }
1484
1278
  if (resolved.source === "prompt") {
1485
- const outcome = await storePassphraseForWallet(passphraseDeps, address, resolved.passphrase);
1486
- 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 };
1487
1328
  }
1488
- 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
+ );
1489
1336
  }
1490
1337
  async function parkOutgoingWallet(dir, account) {
1491
1338
  const src = walletPath(dir);
@@ -1505,9 +1352,9 @@ async function parkOutgoingWallet(dir, account) {
1505
1352
  });
1506
1353
  }
1507
1354
  try {
1508
- await unlink2(src);
1355
+ await unlink(src);
1509
1356
  } catch (err) {
1510
- await unlink2(dst).catch(() => void 0);
1357
+ await unlink(dst).catch(() => void 0);
1511
1358
  throw new CliError(
1512
1359
  "INTERNAL",
1513
1360
  `Could not clear the active wallet slot ${src} while parking the outgoing wallet.`,
@@ -1522,7 +1369,7 @@ async function parkOutgoingWallet(dir, account) {
1522
1369
  }
1523
1370
  async function restoreParkedWallet(dir, archivedPath) {
1524
1371
  await link(archivedPath, walletPath(dir));
1525
- await unlink2(archivedPath).catch(() => void 0);
1372
+ await unlink(archivedPath).catch(() => void 0);
1526
1373
  await syncWalletDir(dir);
1527
1374
  }
1528
1375
  async function syncWalletDir(dir) {
@@ -1535,7 +1382,8 @@ async function loadCredential(deps) {
1535
1382
  const key = envKey.trim();
1536
1383
  if (!PRIVATE_KEY_RE.test(key)) {
1537
1384
  throw new CliError("WALLET_INVALID_KEY", "TENJIN_WALLET_KEY is not a valid private key.", {
1538
- 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")
1539
1387
  });
1540
1388
  }
1541
1389
  return { source: "env", key };
@@ -1546,64 +1394,112 @@ async function loadCredential(deps) {
1546
1394
  }
1547
1395
  return null;
1548
1396
  }
1549
- async function accountForSigning(cred, deps) {
1397
+ async function accountForSigning(cred, deps, warnOnce) {
1550
1398
  if (cred.source === "env") return accountFromKey(cred.key, "env");
1551
- const cached = signerCache.get(cred.keystore.id);
1552
- if (cached !== void 0) return cached;
1553
- const resolved = await resolvePassphrase(
1554
- {
1555
- env: deps.env,
1556
- dir: deps.dir,
1557
- ...deps.passphrase
1558
- },
1559
- 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
1560
1413
  );
1561
- let key;
1562
- try {
1563
- const derived = await deriveKeystoreKey(cred.keystore, resolved.passphrase, deps.derivation);
1564
- key = decrypt(cred.keystore, derived);
1565
- } catch (err) {
1566
- if (err instanceof Error && ["AbortError", "TimeoutError"].includes(err.name)) throw err;
1567
- if (resolved.migrateLegacy !== void 0) {
1568
- throw new CliError(
1569
- "WALLET_INVALID_KEY",
1570
- 'The legacy shared passphrase entry (service tenjin-cli, account "wallet") does not decrypt this wallet.',
1571
- {
1572
- 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).",
1573
- cause: err
1574
- }
1575
- );
1576
- }
1577
- 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") {
1578
1428
  throw new CliError("WALLET_INVALID_KEY", "Could not decrypt the wallet keystore.", {
1579
- fix: `${escape}.`,
1580
- 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)
1581
1432
  });
1582
1433
  }
1583
- const account = accountFromKey(key, "file");
1584
- 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;
1585
1452
  throw new CliError(
1586
- "WALLET_INVALID_KEY",
1587
- `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)}`,
1588
1455
  {
1589
- 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
1590
1458
  }
1591
1459
  );
1592
1460
  }
1593
- if (resolved.migrateLegacy !== void 0) await resolved.migrateLegacy();
1594
- signerCache.set(cred.keystore.id, account);
1595
- 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
+ );
1596
1488
  }
1597
1489
  function accountFromKey(key, source) {
1598
1490
  try {
1599
1491
  return privateKeyToAccount(key);
1600
1492
  } catch (err) {
1601
- throw new CliError("WALLET_INVALID_KEY", "The private key is not a valid secp256k1 key.", {
1602
- 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.",
1603
- cause: err
1604
- });
1493
+ throw invalidKeyError(source, err);
1605
1494
  }
1606
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
+ }
1607
1503
  async function encryptToKeystore(key, passphrase) {
1608
1504
  const [derivedKey, opts] = await scryptAsync2({ password: passphrase });
1609
1505
  return encrypt2(key, derivedKey, opts);
@@ -1626,6 +1522,131 @@ function walletRecord(address, keystore) {
1626
1522
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
1627
1523
  };
1628
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
+ }
1629
1650
 
1630
1651
  // src/lib/wallet/index.ts
1631
1652
  function resolveWalletProvider(ctx, opts = {}) {
@@ -1633,7 +1654,8 @@ function resolveWalletProvider(ctx, opts = {}) {
1633
1654
  return createLocalProvider({
1634
1655
  dir: ctx.dataDir,
1635
1656
  env: process.env,
1636
- 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 }))
1637
1659
  });
1638
1660
  }
1639
1661
  function resolveSpendAuthorizer(ctx, policy, opts = {}) {
@@ -1663,14 +1685,18 @@ async function describeWallet(provider) {
1663
1685
 
1664
1686
  export {
1665
1687
  walletFileExists,
1688
+ readWalletRecord,
1666
1689
  walletExistsError,
1667
- resolvePassphraseForCreate,
1690
+ createLocalProvider,
1691
+ openKeystore,
1692
+ verifyLocalWallet,
1668
1693
  prepareLocalWallet,
1669
1694
  commitLocalWallet,
1670
1695
  createLocalWallet,
1671
1696
  verifyAndPreserveOutgoingWallet,
1672
1697
  parkOutgoingWallet,
1673
1698
  restoreParkedWallet,
1699
+ repairLocalWalletPassphrase,
1674
1700
  resolveWalletProvider,
1675
1701
  resolveSpendAuthorizer,
1676
1702
  describeWallet
@@ -1680,4 +1706,4 @@ export {
1680
1706
  @noble/ciphers/esm/utils.js:
1681
1707
  (*! noble-ciphers - MIT License (c) 2023 Paul Miller (paulmillr.com) *)
1682
1708
  */
1683
- //# sourceMappingURL=chunk-2XLC3AEX.js.map
1709
+ //# sourceMappingURL=chunk-UXZONNEQ.js.map