tenjin-cli 0.1.0-alpha.15 → 0.1.0-alpha.16

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 (267) hide show
  1. package/NOTICE.md +54 -7
  2. package/README.md +41 -310
  3. package/dist/{_esm-N4KAVXQR.js → _esm-CE7KNONL.js} +9 -10
  4. package/dist/{ccip-ZGGWQN4X.js → ccip-7RMRLAGV.js} +4 -4
  5. package/dist/{ccip-RPPPKTJR.js → ccip-NLCSCHKI.js} +5 -5
  6. package/dist/chunk-25TJPVBF.js +353 -0
  7. package/dist/chunk-25TJPVBF.js.map +1 -0
  8. package/dist/chunk-2BKS2FVE.js +93 -0
  9. package/dist/chunk-2BKS2FVE.js.map +1 -0
  10. package/dist/chunk-2QYORQBF.js +55 -0
  11. package/dist/chunk-2QYORQBF.js.map +1 -0
  12. package/dist/{chunk-NIKXHWOL.js → chunk-2U5ZVEV3.js} +16 -16
  13. package/dist/chunk-2U5ZVEV3.js.map +1 -0
  14. package/dist/{chunk-HPJGOLTN.js → chunk-3AJS6LLN.js} +13 -8
  15. package/dist/chunk-3AJS6LLN.js.map +1 -0
  16. package/dist/{chunk-KINZ23CV.js → chunk-3AUDA53C.js} +4740 -23
  17. package/dist/chunk-3AUDA53C.js.map +1 -0
  18. package/dist/{chunk-MJZZTKCC.js → chunk-56MOAIP5.js} +5 -10
  19. package/dist/chunk-56MOAIP5.js.map +1 -0
  20. package/dist/{chunk-U5S527PP.js → chunk-5IEP5EGE.js} +3 -3
  21. package/dist/chunk-5X4SZ5BF.js +227 -0
  22. package/dist/chunk-5X4SZ5BF.js.map +1 -0
  23. package/dist/chunk-7WEQQJLG.js +68 -0
  24. package/dist/chunk-7WEQQJLG.js.map +1 -0
  25. package/dist/{chunk-7FK2UN2T.js → chunk-AWQPGIR6.js} +65 -67
  26. package/dist/{chunk-7FK2UN2T.js.map → chunk-AWQPGIR6.js.map} +1 -1
  27. package/dist/{chunk-ZFJJ3EXC.js → chunk-BBVUVBUO.js} +516 -185
  28. package/dist/chunk-BBVUVBUO.js.map +1 -0
  29. package/dist/{chunk-JBIKAAT3.js → chunk-BFFM2WFK.js} +8 -8
  30. package/dist/chunk-BFFM2WFK.js.map +1 -0
  31. package/dist/{chunk-KYQVEKP5.js → chunk-BPMWXTFX.js} +8 -8
  32. package/dist/chunk-DMZZLPZN.js +205 -0
  33. package/dist/chunk-DMZZLPZN.js.map +1 -0
  34. package/dist/{chunk-47PP7TAG.js → chunk-EGELTSPU.js} +1356 -1356
  35. package/dist/chunk-EGELTSPU.js.map +1 -0
  36. package/dist/chunk-GULLJQXA.js +698 -0
  37. package/dist/chunk-GULLJQXA.js.map +1 -0
  38. package/dist/{chunk-S5RYMCV6.js → chunk-HPWO4O6S.js} +3 -3
  39. package/dist/chunk-HVRC33OL.js +174 -0
  40. package/dist/chunk-HVRC33OL.js.map +1 -0
  41. package/dist/{chunk-W6R3HAAG.js → chunk-JRGFKVAZ.js} +2 -2
  42. package/dist/{chunk-XJN5WUKL.js → chunk-KG3D7FIF.js} +2 -2
  43. package/dist/chunk-L3PVMIYQ.js +10328 -0
  44. package/dist/chunk-L3PVMIYQ.js.map +1 -0
  45. package/dist/{chunk-QW2Q2KAH.js → chunk-LHHMV4GU.js} +2 -2
  46. package/dist/{chunk-ZOBNS7CX.js → chunk-MEFB5KHA.js} +4 -18
  47. package/dist/chunk-MEFB5KHA.js.map +1 -0
  48. package/dist/{chunk-M2O56UK7.js → chunk-N35E6CM2.js} +293 -163
  49. package/dist/chunk-N35E6CM2.js.map +1 -0
  50. package/dist/chunk-OCBHUHWB.js +69 -0
  51. package/dist/chunk-OCBHUHWB.js.map +1 -0
  52. package/dist/chunk-OIM4HLN6.js +1405 -0
  53. package/dist/chunk-OIM4HLN6.js.map +1 -0
  54. package/dist/{chunk-VYOJOX4Z.js → chunk-OJLYNM4Z.js} +54 -33
  55. package/dist/chunk-OJLYNM4Z.js.map +1 -0
  56. package/dist/{chunk-POJRB2AE.js → chunk-POUWHWID.js} +2 -2
  57. package/dist/chunk-PZEN5PHN.js +285 -0
  58. package/dist/chunk-PZEN5PHN.js.map +1 -0
  59. package/dist/chunk-SKAHDQH7.js +1785 -0
  60. package/dist/chunk-SKAHDQH7.js.map +1 -0
  61. package/dist/{chunk-KZAAWQNP.js → chunk-TTNESUPQ.js} +3 -3
  62. package/dist/chunk-U5DXNFJC.js +137 -0
  63. package/dist/chunk-U5DXNFJC.js.map +1 -0
  64. package/dist/chunk-USS336NF.js +165 -0
  65. package/dist/chunk-USS336NF.js.map +1 -0
  66. package/dist/{chunk-UO22YNY4.js → chunk-WH7OWT6G.js} +49 -1
  67. package/dist/chunk-WH7OWT6G.js.map +1 -0
  68. package/dist/chunk-WXC57XGG.js +29 -0
  69. package/dist/chunk-WXC57XGG.js.map +1 -0
  70. package/dist/{chunk-YLYINX2H.js → chunk-XZKD7DIF.js} +3 -3
  71. package/dist/{chunk-CPCX67TI.js → chunk-YEETV6IW.js} +1079 -1039
  72. package/dist/chunk-YEETV6IW.js.map +1 -0
  73. package/dist/{chunk-OLWTRUTS.js → chunk-YJHHCWM3.js} +35 -16
  74. package/dist/chunk-YJHHCWM3.js.map +1 -0
  75. package/dist/{cli-KKRKBU5T.js → cli-M3XCSOU6.js} +289 -374
  76. package/dist/cli-M3XCSOU6.js.map +1 -0
  77. package/dist/config-MXOX7XDR.js +41 -0
  78. package/dist/{dist-U4M6QCKE.js → dist-3LOO6M4U.js} +10 -10
  79. package/dist/doctor-LU4YIZWM.js +349 -0
  80. package/dist/doctor-LU4YIZWM.js.map +1 -0
  81. package/dist/{ethersCompat-Df4a6QIZ-WHYKB6HA.js → ethersCompat-Df4a6QIZ-THAVUGIJ.js} +5 -5
  82. package/dist/{chunk-KAJZHIQ4.js → fund-A54P2QFK.js} +80 -24
  83. package/dist/fund-A54P2QFK.js.map +1 -0
  84. package/dist/hook-command-U6KWPEDQ.js +377 -0
  85. package/dist/hook-command-U6KWPEDQ.js.map +1 -0
  86. package/dist/index.js +8 -3
  87. package/dist/index.js.map +1 -1
  88. package/dist/install-XUM2XSHW.js +53 -0
  89. package/dist/install-wallet-QIOFORTX.js +105 -0
  90. package/dist/install-wallet-QIOFORTX.js.map +1 -0
  91. package/dist/{run-XYTQ5TWQ.js → mcp-HJC2PLRV.js} +3727 -10670
  92. package/dist/mcp-HJC2PLRV.js.map +1 -0
  93. package/dist/paths-P2N4JTDZ.js +49 -0
  94. package/dist/pay-SBXZEPEP.js +37 -0
  95. package/dist/redact-46ZHF2NH.js +17 -0
  96. package/dist/{secp256k1-XRPVBC6V.js → secp256k1-ZZZT2CAX.js} +3 -3
  97. package/dist/{send-G746D7PQ.js → send-ASD2ZXJD.js} +28 -29
  98. package/dist/send-ASD2ZXJD.js.map +1 -0
  99. package/dist/{chunk-QZ6ROAJU.js → skill-placement-NFVHY6A3.js} +157 -11
  100. package/dist/skill-placement-NFVHY6A3.js.map +1 -0
  101. package/dist/status-T2SDB57A.js +63 -0
  102. package/dist/status-T2SDB57A.js.map +1 -0
  103. package/dist/status-line-CGPUSDMC.js +71 -0
  104. package/dist/status-line-CGPUSDMC.js.map +1 -0
  105. package/dist/status-line-wiring-BYPHTYZE.js +30 -0
  106. package/dist/tenjin-daemon.mjs +20060 -0
  107. package/dist/tenjin-shim.mjs +251 -0
  108. package/dist/tenjin-vitest-reporter.mjs +49 -0
  109. package/dist/uninstall-FKYZHAM3.js +144 -0
  110. package/dist/uninstall-FKYZHAM3.js.map +1 -0
  111. package/dist/{update-R76LHOZW.js → update-ANJ2AOTN.js} +133 -16
  112. package/dist/update-ANJ2AOTN.js.map +1 -0
  113. package/dist/{viemAdapter-By13KInL-TUQJBMHM.js → viemAdapter-By13KInL-X2VY6CY3.js} +5 -5
  114. package/dist/wallet-PWAHVKWW.js +31 -0
  115. package/dist/wallet-kdf-worker.mjs +980 -0
  116. package/docs/agent-permissions.md +65 -354
  117. package/docs/safety-model.md +16 -6
  118. package/package.json +8 -7
  119. package/LICENSE +0 -21
  120. package/dist/buy-VIRNSYGN.js +0 -47
  121. package/dist/chunk-2MYQN7HM.js +0 -247
  122. package/dist/chunk-2MYQN7HM.js.map +0 -1
  123. package/dist/chunk-2RF2GIJQ.js +0 -1188
  124. package/dist/chunk-2RF2GIJQ.js.map +0 -1
  125. package/dist/chunk-3GL2Z5QK.js +0 -57
  126. package/dist/chunk-3GL2Z5QK.js.map +0 -1
  127. package/dist/chunk-47PP7TAG.js.map +0 -1
  128. package/dist/chunk-4CQIDQOT.js +0 -167
  129. package/dist/chunk-4CQIDQOT.js.map +0 -1
  130. package/dist/chunk-4KG27W2S.js +0 -614
  131. package/dist/chunk-4KG27W2S.js.map +0 -1
  132. package/dist/chunk-5QQTYWEU.js +0 -199
  133. package/dist/chunk-5QQTYWEU.js.map +0 -1
  134. package/dist/chunk-65DTCCJ7.js +0 -21
  135. package/dist/chunk-65DTCCJ7.js.map +0 -1
  136. package/dist/chunk-A5DKHMUN.js +0 -173
  137. package/dist/chunk-A5DKHMUN.js.map +0 -1
  138. package/dist/chunk-B63XPWQ4.js +0 -246
  139. package/dist/chunk-B63XPWQ4.js.map +0 -1
  140. package/dist/chunk-CAR6FHK6.js +0 -105
  141. package/dist/chunk-CAR6FHK6.js.map +0 -1
  142. package/dist/chunk-CPCX67TI.js.map +0 -1
  143. package/dist/chunk-CQBVCYI2.js +0 -162
  144. package/dist/chunk-CQBVCYI2.js.map +0 -1
  145. package/dist/chunk-DBU5CXBV.js +0 -4731
  146. package/dist/chunk-DBU5CXBV.js.map +0 -1
  147. package/dist/chunk-DHJD77OW.js +0 -81
  148. package/dist/chunk-DHJD77OW.js.map +0 -1
  149. package/dist/chunk-EDZSNPE5.js +0 -35
  150. package/dist/chunk-EDZSNPE5.js.map +0 -1
  151. package/dist/chunk-EFWZPUTC.js +0 -65
  152. package/dist/chunk-EFWZPUTC.js.map +0 -1
  153. package/dist/chunk-EPFL6CTE.js +0 -448
  154. package/dist/chunk-EPFL6CTE.js.map +0 -1
  155. package/dist/chunk-GHLVXVZD.js +0 -142
  156. package/dist/chunk-GHLVXVZD.js.map +0 -1
  157. package/dist/chunk-H3SOOJ2I.js +0 -580
  158. package/dist/chunk-H3SOOJ2I.js.map +0 -1
  159. package/dist/chunk-HPJGOLTN.js.map +0 -1
  160. package/dist/chunk-HRGBS2PA.js +0 -203
  161. package/dist/chunk-HRGBS2PA.js.map +0 -1
  162. package/dist/chunk-ITUXPJIS.js +0 -314
  163. package/dist/chunk-ITUXPJIS.js.map +0 -1
  164. package/dist/chunk-JBIKAAT3.js.map +0 -1
  165. package/dist/chunk-KAJZHIQ4.js.map +0 -1
  166. package/dist/chunk-KINZ23CV.js.map +0 -1
  167. package/dist/chunk-LRYV3SK7.js +0 -235
  168. package/dist/chunk-LRYV3SK7.js.map +0 -1
  169. package/dist/chunk-M2O56UK7.js.map +0 -1
  170. package/dist/chunk-MJZZTKCC.js.map +0 -1
  171. package/dist/chunk-NIKXHWOL.js.map +0 -1
  172. package/dist/chunk-OKDRDT74.js +0 -209
  173. package/dist/chunk-OKDRDT74.js.map +0 -1
  174. package/dist/chunk-OKYSNAS3.js +0 -2144
  175. package/dist/chunk-OKYSNAS3.js.map +0 -1
  176. package/dist/chunk-OLWTRUTS.js.map +0 -1
  177. package/dist/chunk-QQ6ELLSA.js +0 -143
  178. package/dist/chunk-QQ6ELLSA.js.map +0 -1
  179. package/dist/chunk-QZ6ROAJU.js.map +0 -1
  180. package/dist/chunk-R7RSCBI7.js +0 -794
  181. package/dist/chunk-R7RSCBI7.js.map +0 -1
  182. package/dist/chunk-SGK2B724.js +0 -67
  183. package/dist/chunk-SGK2B724.js.map +0 -1
  184. package/dist/chunk-U6VPKMGC.js +0 -390
  185. package/dist/chunk-U6VPKMGC.js.map +0 -1
  186. package/dist/chunk-UHTVXQ2O.js +0 -140
  187. package/dist/chunk-UHTVXQ2O.js.map +0 -1
  188. package/dist/chunk-UO22YNY4.js.map +0 -1
  189. package/dist/chunk-US456VUI.js +0 -149
  190. package/dist/chunk-US456VUI.js.map +0 -1
  191. package/dist/chunk-V44J2MXV.js +0 -400
  192. package/dist/chunk-V44J2MXV.js.map +0 -1
  193. package/dist/chunk-VJQKL3YH.js +0 -216
  194. package/dist/chunk-VJQKL3YH.js.map +0 -1
  195. package/dist/chunk-VJSQSLBM.js +0 -1442
  196. package/dist/chunk-VJSQSLBM.js.map +0 -1
  197. package/dist/chunk-VYOJOX4Z.js.map +0 -1
  198. package/dist/chunk-WY2K35OL.js +0 -269
  199. package/dist/chunk-WY2K35OL.js.map +0 -1
  200. package/dist/chunk-ZFJJ3EXC.js.map +0 -1
  201. package/dist/chunk-ZOBNS7CX.js.map +0 -1
  202. package/dist/cli-KKRKBU5T.js.map +0 -1
  203. package/dist/config-JMRUNYE6.js +0 -37
  204. package/dist/discover-B5HF6SHM.js +0 -102
  205. package/dist/discover-B5HF6SHM.js.map +0 -1
  206. package/dist/doctor-ZBG7X66D.js +0 -32
  207. package/dist/edit-PZJIILQE.js +0 -40
  208. package/dist/fund-EUDH5KPA.js +0 -40
  209. package/dist/inspect-QC6WEQPN.js +0 -37
  210. package/dist/install-GNK2W3PI.js +0 -972
  211. package/dist/install-GNK2W3PI.js.map +0 -1
  212. package/dist/outcome-KSGWZHUS.js +0 -24
  213. package/dist/pay-BC4UICPA.js +0 -361
  214. package/dist/pay-BC4UICPA.js.map +0 -1
  215. package/dist/publish-LXWFDIKF.js +0 -42
  216. package/dist/read-JMNUQ56P.js +0 -160
  217. package/dist/read-JMNUQ56P.js.map +0 -1
  218. package/dist/run-XYTQ5TWQ.js.map +0 -1
  219. package/dist/search-TSQAB45E.js +0 -25
  220. package/dist/secp256k1-XRPVBC6V.js.map +0 -1
  221. package/dist/send-G746D7PQ.js.map +0 -1
  222. package/dist/session-JBKWMJ24.js +0 -89
  223. package/dist/session-JBKWMJ24.js.map +0 -1
  224. package/dist/skill-heal-WKD67SLJ.js +0 -92
  225. package/dist/skill-heal-WKD67SLJ.js.map +0 -1
  226. package/dist/skill-placement-RIU4AMC2.js +0 -20
  227. package/dist/skill-placement-RIU4AMC2.js.map +0 -1
  228. package/dist/uninstall-5E263VTS.js +0 -73
  229. package/dist/uninstall-5E263VTS.js.map +0 -1
  230. package/dist/update-R76LHOZW.js.map +0 -1
  231. package/dist/usdc-4VCDHFWX.js +0 -38
  232. package/dist/usdc-4VCDHFWX.js.map +0 -1
  233. package/dist/viemAdapter-By13KInL-TUQJBMHM.js.map +0 -1
  234. package/dist/wallet-TQ7D5EQ7.js +0 -41
  235. package/dist/wallet-TQ7D5EQ7.js.map +0 -1
  236. package/dist/wallet-ZAVXWLWP.js +0 -32
  237. package/dist/wallet-ZAVXWLWP.js.map +0 -1
  238. package/docs/command-reference.md +0 -303
  239. package/skills/tenjin/SKILL.md +0 -373
  240. package/skills/tenjin-pay/SKILL.md +0 -76
  241. package/skills/tenjin-publish/SKILL.md +0 -227
  242. package/skills/tenjin-publish/references/maintain.md +0 -39
  243. package/skills/tenjin-search/SKILL.md +0 -154
  244. package/skills/tenjin-search/references/permissions.md +0 -112
  245. /package/dist/{_esm-N4KAVXQR.js.map → _esm-CE7KNONL.js.map} +0 -0
  246. /package/dist/{buy-VIRNSYGN.js.map → ccip-7RMRLAGV.js.map} +0 -0
  247. /package/dist/{ccip-RPPPKTJR.js.map → ccip-NLCSCHKI.js.map} +0 -0
  248. /package/dist/{chunk-U5S527PP.js.map → chunk-5IEP5EGE.js.map} +0 -0
  249. /package/dist/{chunk-KYQVEKP5.js.map → chunk-BPMWXTFX.js.map} +0 -0
  250. /package/dist/{chunk-S5RYMCV6.js.map → chunk-HPWO4O6S.js.map} +0 -0
  251. /package/dist/{chunk-W6R3HAAG.js.map → chunk-JRGFKVAZ.js.map} +0 -0
  252. /package/dist/{chunk-XJN5WUKL.js.map → chunk-KG3D7FIF.js.map} +0 -0
  253. /package/dist/{chunk-QW2Q2KAH.js.map → chunk-LHHMV4GU.js.map} +0 -0
  254. /package/dist/{chunk-POJRB2AE.js.map → chunk-POUWHWID.js.map} +0 -0
  255. /package/dist/{chunk-KZAAWQNP.js.map → chunk-TTNESUPQ.js.map} +0 -0
  256. /package/dist/{chunk-YLYINX2H.js.map → chunk-XZKD7DIF.js.map} +0 -0
  257. /package/dist/{ccip-ZGGWQN4X.js.map → config-MXOX7XDR.js.map} +0 -0
  258. /package/dist/{dist-U4M6QCKE.js.map → dist-3LOO6M4U.js.map} +0 -0
  259. /package/dist/{config-JMRUNYE6.js.map → ethersCompat-Df4a6QIZ-THAVUGIJ.js.map} +0 -0
  260. /package/dist/{doctor-ZBG7X66D.js.map → install-XUM2XSHW.js.map} +0 -0
  261. /package/dist/{edit-PZJIILQE.js.map → paths-P2N4JTDZ.js.map} +0 -0
  262. /package/dist/{ethersCompat-Df4a6QIZ-WHYKB6HA.js.map → pay-SBXZEPEP.js.map} +0 -0
  263. /package/dist/{fund-EUDH5KPA.js.map → redact-46ZHF2NH.js.map} +0 -0
  264. /package/dist/{inspect-QC6WEQPN.js.map → secp256k1-ZZZT2CAX.js.map} +0 -0
  265. /package/dist/{outcome-KSGWZHUS.js.map → status-line-wiring-BYPHTYZE.js.map} +0 -0
  266. /package/dist/{publish-LXWFDIKF.js.map → viemAdapter-By13KInL-X2VY6CY3.js.map} +0 -0
  267. /package/dist/{search-TSQAB45E.js.map → wallet-PWAHVKWW.js.map} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/op-stack/contracts.ts","../node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/op-stack/formatters.ts","../node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/op-stack/serializers.ts","../node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/op-stack/chainConfig.ts","../node_modules/.pnpm/viem@2.55.2_typescript@6.0.3_zod@4.4.3/node_modules/viem/chains/definitions/base.ts","../src/lib/usdc.ts"],"sourcesContent":["import type { Chain } from '../types/chain.js'\n\n/**\n * Predeploy contracts for OP Stack.\n * @see https://github.com/ethereum-optimism/optimism/blob/develop/specs/predeploys.md\n */\nexport const contracts = {\n gasPriceOracle: { address: '0x420000000000000000000000000000000000000F' },\n l1Block: { address: '0x4200000000000000000000000000000000000015' },\n l2CrossDomainMessenger: {\n address: '0x4200000000000000000000000000000000000007',\n },\n l2Erc721Bridge: { address: '0x4200000000000000000000000000000000000014' },\n l2StandardBridge: { address: '0x4200000000000000000000000000000000000010' },\n l2ToL1MessagePasser: {\n address: '0x4200000000000000000000000000000000000016',\n },\n} as const satisfies Chain['contracts']\n","import type { ChainFormatters } from '../types/chain.js'\nimport type { RpcTransaction } from '../types/rpc.js'\nimport { hexToBigInt, hexToNumber } from '../utils/encoding/fromHex.js'\nimport { defineBlock } from '../utils/formatters/block.js'\nimport {\n defineTransaction,\n formatTransaction,\n} from '../utils/formatters/transaction.js'\nimport { defineTransactionReceipt } from '../utils/formatters/transactionReceipt.js'\nimport type { OpStackBlock, OpStackRpcBlock } from './types/block.js'\nimport type {\n OpStackRpcTransaction,\n OpStackRpcTransactionReceipt,\n OpStackTransaction,\n OpStackTransactionReceipt,\n} from './types/transaction.js'\n\nexport const formatters = {\n block: /*#__PURE__*/ defineBlock({\n format(args: OpStackRpcBlock): OpStackBlock {\n const transactions = args.transactions?.map((transaction) => {\n if (typeof transaction === 'string') return transaction\n const formatted = formatTransaction(\n transaction as RpcTransaction,\n ) as OpStackTransaction\n if (formatted.typeHex === '0x7e') {\n formatted.isSystemTx = transaction.isSystemTx\n formatted.mint = transaction.mint\n ? hexToBigInt(transaction.mint)\n : undefined\n formatted.sourceHash = transaction.sourceHash\n formatted.type = 'deposit'\n }\n return formatted\n })\n return {\n transactions,\n stateRoot: args.stateRoot,\n } as OpStackBlock\n },\n }),\n transaction: /*#__PURE__*/ defineTransaction({\n format(args: OpStackRpcTransaction): OpStackTransaction {\n const transaction = {} as OpStackTransaction\n if (args.type === '0x7e') {\n transaction.isSystemTx = args.isSystemTx\n transaction.mint = args.mint ? hexToBigInt(args.mint) : undefined\n transaction.sourceHash = args.sourceHash\n transaction.type = 'deposit'\n }\n return transaction\n },\n }),\n transactionReceipt: /*#__PURE__*/ defineTransactionReceipt({\n format(args: OpStackRpcTransactionReceipt): OpStackTransactionReceipt {\n return {\n ...(args.depositNonce\n ? { depositNonce: hexToBigInt(args.depositNonce) }\n : {}),\n ...(args.depositReceiptVersion\n ? { depositReceiptVersion: hexToNumber(args.depositReceiptVersion) }\n : {}),\n l1GasPrice: args.l1GasPrice ? hexToBigInt(args.l1GasPrice) : null,\n l1GasUsed: args.l1GasUsed ? hexToBigInt(args.l1GasUsed) : null,\n l1Fee: args.l1Fee ? hexToBigInt(args.l1Fee) : null,\n l1FeeScalar: args.l1FeeScalar ? Number(args.l1FeeScalar) : null,\n } as OpStackTransactionReceipt\n },\n }),\n} as const satisfies ChainFormatters\n","import { InvalidAddressError } from '../errors/address.js'\nimport type { ErrorType } from '../errors/utils.js'\nimport type { ChainSerializers } from '../types/chain.js'\nimport type { Hex, Signature } from '../types/misc.js'\nimport type { TransactionSerializable } from '../types/transaction.js'\nimport type { RequiredBy } from '../types/utils.js'\nimport { isAddress } from '../utils/address/isAddress.js'\nimport { concatHex } from '../utils/data/concat.js'\nimport { toHex } from '../utils/encoding/toHex.js'\nimport { toRlp } from '../utils/encoding/toRlp.js'\nimport {\n type SerializeTransactionErrorType as SerializeTransactionErrorType_,\n serializeTransaction as serializeTransaction_,\n} from '../utils/transaction/serializeTransaction.js'\nimport type {\n OpStackTransactionSerializable,\n TransactionSerializableDeposit,\n TransactionSerializedDeposit,\n} from './types/transaction.js'\n\nexport type SerializeTransactionReturnType = ReturnType<\n typeof serializeTransaction\n>\n\nexport type SerializeTransactionErrorType =\n | SerializeTransactionErrorType_\n | ErrorType\n\nexport function serializeTransaction(\n transaction: OpStackTransactionSerializable,\n signature?: Signature,\n) {\n if (isDeposit(transaction)) return serializeTransactionDeposit(transaction)\n return serializeTransaction_(\n transaction as TransactionSerializable,\n signature,\n )\n}\n\nexport const serializers = {\n transaction: serializeTransaction,\n} as const satisfies ChainSerializers\n\n//////////////////////////////////////////////////////////////////////////////\n// Serializers\n\nexport type SerializeTransactionDepositReturnType = TransactionSerializedDeposit\n\nfunction serializeTransactionDeposit(\n transaction: TransactionSerializableDeposit,\n): SerializeTransactionDepositReturnType {\n assertTransactionDeposit(transaction)\n\n const { sourceHash, data, from, gas, isSystemTx, mint, to, value } =\n transaction\n\n const serializedTransaction: Hex[] = [\n sourceHash,\n from,\n to ?? '0x',\n mint ? toHex(mint) : '0x',\n value ? toHex(value) : '0x',\n gas ? toHex(gas) : '0x',\n isSystemTx ? '0x1' : '0x',\n data ?? '0x',\n ]\n\n return concatHex([\n '0x7e',\n toRlp(serializedTransaction),\n ]) as SerializeTransactionDepositReturnType\n}\n\nfunction isDeposit(\n transaction: OpStackTransactionSerializable,\n): transaction is RequiredBy<TransactionSerializableDeposit, 'type'> {\n if (transaction.type === 'deposit') return true\n if (typeof transaction.sourceHash !== 'undefined') return true\n return false\n}\n\nexport function assertTransactionDeposit(\n transaction: TransactionSerializableDeposit,\n) {\n const { from, to } = transaction\n if (from && !isAddress(from)) throw new InvalidAddressError({ address: from })\n if (to && !isAddress(to)) throw new InvalidAddressError({ address: to })\n}\n","import { contracts } from './contracts.js'\nimport { formatters } from './formatters.js'\nimport { serializers } from './serializers.js'\n\nexport const chainConfig = {\n blockTime: 2_000,\n contracts,\n formatters,\n serializers,\n} as const\n","import { chainConfig } from '../../op-stack/chainConfig.js'\nimport { defineChain } from '../../utils/chain/defineChain.js'\n\nconst sourceId = 1 // mainnet\n\nexport const base = /*#__PURE__*/ defineChain({\n ...chainConfig,\n id: 8453,\n name: 'Base',\n nativeCurrency: { name: 'Ether', symbol: 'ETH', decimals: 18 },\n rpcUrls: {\n default: {\n http: ['https://mainnet.base.org'],\n },\n },\n blockExplorers: {\n default: {\n name: 'Basescan',\n url: 'https://basescan.org',\n apiUrl: 'https://api.basescan.org/api',\n },\n },\n contracts: {\n ...chainConfig.contracts,\n disputeGameFactory: {\n [sourceId]: {\n address: '0x43edB88C4B80fDD2AdFF2412A7BebF9dF42cB40e',\n },\n },\n l2OutputOracle: {\n [sourceId]: {\n address: '0x56315b90c40730925ec5485cf004d835058518A0',\n },\n },\n multicall3: {\n address: '0xca11bde05977b3631167028862be2a173976ca11',\n blockCreated: 5022,\n },\n portal: {\n [sourceId]: {\n address: '0x49048044D57e1C92A77f79988d21Fa8fAF74E97e',\n blockCreated: 17482143,\n },\n },\n l1StandardBridge: {\n [sourceId]: {\n address: '0x3154Cf16ccdb4C6d922629664174b904d80F2C35',\n blockCreated: 17482143,\n },\n },\n },\n sourceId,\n})\n\nexport const basePreconf = /*#__PURE__*/ defineChain({\n ...base,\n experimental_preconfirmationTime: 200,\n rpcUrls: {\n default: {\n http: ['https://mainnet-preconf.base.org'],\n },\n },\n})\n","import {\n createPublicClient,\n decodeFunctionData,\n encodeFunctionData,\n erc20Abi,\n http,\n type Address,\n type Hex,\n} from 'viem';\nimport { base } from 'viem/chains';\nimport type { TenjinSigner } from './wallet/provider';\n\n// Values mirror the app's lib/chain.ts Base mainnet entry (chain 8453).\nexport const USDC_ADDRESS: Address = '0x833589fCD6eDb6E08f4c7C32D4f71b54bdA02913';\nexport const USDC_DECIMALS = 6;\n\nexport async function getUsdcBalance(address: Address, rpcUrl: string): Promise<bigint> {\n const client = createPublicClient({ chain: base, transport: http(rpcUrl) });\n return client.readContract({\n address: USDC_ADDRESS,\n abi: erc20Abi,\n functionName: 'balanceOf',\n args: [address],\n });\n}\n\n// The chain boundary for `tenjin send`, two-phase around the human confirm:\n// prepareUsdcSend (read-only: encode, nonce, gas, fees, ETH-for-gas balance)\n// runs BEFORE the confirm so the prompt can show the fee, broadcastUsdcSend\n// (sign via the TenjinSigner seam, broadcast, wait for the receipt) runs after.\n// Command tests mock this whole module, so no test can ever reach a real chain.\n\n/**\n * Ceilings on the RPC-supplied gas and fee fields. The RPC endpoint is\n * config-controlled and its estimates go straight into the signed transaction; a\n * hostile or broken endpoint returning huge values would burn the wallet's ETH\n * as fees. An ERC-20 transfer is ~65k gas and Base fees run well under a gwei,\n * so estimates past these bounds mean something is wrong: refuse, never clamp\n * (a clamped maxFeePerGas below the real base fee would just strand the tx).\n * A genuine extreme fee spike on Base trips the same refusal; that is intended\n * — waiting it out beats signing an irreversible transfer at panic prices.\n */\nexport const SEND_GAS_CAP = 150_000n;\nexport const SEND_MAX_FEE_PER_GAS_CAP = 10_000_000_000n; // 10 gwei\nexport const SEND_MAX_PRIORITY_FEE_CAP = 2_000_000_000n; // 2 gwei\n\n/** An RPC gas/fee estimate exceeded the send ceilings; nothing was signed. */\nexport class FeeCapExceededError extends Error {\n constructor(field: string, value: bigint, cap: bigint) {\n super(`${field} estimate ${value} exceeds the send ceiling ${cap}`);\n this.name = 'FeeCapExceededError';\n }\n}\n\n/** The transfer was mined but reverted; the fee was spent, the USDC did not move. */\nexport class SendRevertedError extends Error {\n constructor(readonly txHash: Hex) {\n super(`Transaction ${txHash} reverted`);\n this.name = 'SendRevertedError';\n }\n}\n\n/** Broadcast succeeded but no receipt arrived in time; the tx may still mine. */\nexport class SendPendingError extends Error {\n constructor(readonly txHash: Hex) {\n super(`Transaction ${txHash} was broadcast but not confirmed in time`);\n this.name = 'SendPendingError';\n }\n}\n\nexport interface PrepareUsdcSendArgs {\n from: Address;\n to: Address;\n amountAtomic: bigint;\n rpcUrl: string;\n}\n\n/**\n * Everything signed later, fixed at prepare time, plus the gas-cost preview.\n * The nonce is pinned here, BEFORE the human confirm, so anything else spending\n * from this key during that window makes the later broadcast fail nonce-stale\n * (an RPC_ERROR from the node; nothing double-spends — re-run to re-prepare).\n * `to` and `amountAtomic` are the previewed intent; broadcastUsdcSend re-decodes\n * `data` against them before signing.\n */\nexport interface PreparedUsdcSend {\n to: Address;\n amountAtomic: bigint;\n data: Hex;\n nonce: number;\n gas: bigint;\n maxFeePerGas: bigint;\n maxPriorityFeePerGas: bigint;\n /** Worst-case fee (gas * maxFeePerGas), for the confirm prompt and gas check. */\n feeWei: bigint;\n /** The sender's native ETH balance, for the has-gas pre-check. */\n ethBalanceWei: bigint;\n}\n\nexport async function prepareUsdcSend({\n from,\n to,\n amountAtomic,\n rpcUrl,\n}: PrepareUsdcSendArgs): Promise<PreparedUsdcSend> {\n const client = createPublicClient({ chain: base, transport: http(rpcUrl) });\n const data = encodeFunctionData({\n abi: erc20Abi,\n functionName: 'transfer',\n args: [to, amountAtomic],\n });\n const [nonce, gas, fees, ethBalanceWei] = await Promise.all([\n client.getTransactionCount({ address: from, blockTag: 'pending' }),\n client.estimateGas({ account: from, to: USDC_ADDRESS, data }),\n client.estimateFeesPerGas(),\n client.getBalance({ address: from }),\n ]);\n assertUnderCap('gas', gas, SEND_GAS_CAP);\n assertUnderCap('maxFeePerGas', fees.maxFeePerGas, SEND_MAX_FEE_PER_GAS_CAP);\n assertUnderCap('maxPriorityFeePerGas', fees.maxPriorityFeePerGas, SEND_MAX_PRIORITY_FEE_CAP);\n return {\n to,\n amountAtomic,\n data,\n nonce,\n gas,\n maxFeePerGas: fees.maxFeePerGas,\n maxPriorityFeePerGas: fees.maxPriorityFeePerGas,\n feeWei: gas * fees.maxFeePerGas,\n ethBalanceWei,\n };\n}\n\nexport interface BroadcastUsdcSendArgs {\n signer: TenjinSigner;\n prepared: PreparedUsdcSend;\n rpcUrl: string;\n /** Receipt wait bound in ms; Base blocks are ~2s, so the default is generous. */\n receiptTimeoutMs?: number;\n}\n\n/**\n * Sign the prepared transfer through the TenjinSigner seam (never a raw key),\n * broadcast it, and wait for the receipt so \"sent\" means mined. Throws\n * SendRevertedError (mined but failed) or SendPendingError (no receipt in time);\n * both carry the hash so the caller can report it either way.\n */\nexport async function broadcastUsdcSend({\n signer,\n prepared,\n rpcUrl,\n receiptTimeoutMs = 120_000,\n}: BroadcastUsdcSendArgs): Promise<Hex> {\n const client = createPublicClient({ chain: base, transport: http(rpcUrl) });\n // Pre-sign cross-check, the calldata twin of send.ts's signer/preview match:\n // the bytes about to be signed must still decode to the previewed recipient\n // and amount. Unreachable unless prepare-time state was corrupted; refusing\n // here means nothing is signed against a preview it does not match.\n const decoded = decodeFunctionData({ abi: erc20Abi, data: prepared.data });\n if (\n decoded.functionName !== 'transfer' ||\n decoded.args[0].toLowerCase() !== prepared.to.toLowerCase() ||\n decoded.args[1] !== prepared.amountAtomic\n ) {\n throw new Error(\n 'Prepared calldata does not decode to the previewed recipient and amount; nothing was signed.',\n );\n }\n const serializedTransaction = await signer.signTransaction({\n type: 'eip1559',\n chainId: base.id,\n to: USDC_ADDRESS,\n // Explicitly zero: an ERC-20 transfer carries no native value (test-pinned).\n value: 0n,\n data: prepared.data,\n nonce: prepared.nonce,\n gas: prepared.gas,\n maxFeePerGas: prepared.maxFeePerGas,\n maxPriorityFeePerGas: prepared.maxPriorityFeePerGas,\n });\n const txHash = await client.sendRawTransaction({ serializedTransaction });\n let receipt;\n try {\n receipt = await client.waitForTransactionReceipt({ hash: txHash, timeout: receiptTimeoutMs });\n } catch {\n throw new SendPendingError(txHash);\n }\n if (receipt.status !== 'success') throw new SendRevertedError(txHash);\n return txHash;\n}\n\nfunction assertUnderCap(field: string, value: bigint, cap: bigint): void {\n if (value > cap) throw new FeeCapExceededError(field, value, cap);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAMO,IAAM,YAAY;EACvB,gBAAgB,EAAE,SAAS,6CAA4C;EACvE,SAAS,EAAE,SAAS,6CAA4C;EAChE,wBAAwB;IACtB,SAAS;;EAEX,gBAAgB,EAAE,SAAS,6CAA4C;EACvE,kBAAkB,EAAE,SAAS,6CAA4C;EACzE,qBAAqB;IACnB,SAAS;;;;;ACEN,IAAM,aAAa;EACxB,OAAqB,4BAAY;IAC/B,OAAO,MAAqB;AAC1B,YAAM,eAAe,KAAK,cAAc,IAAI,CAAC,gBAAe;AAC1D,YAAI,OAAO,gBAAgB;AAAU,iBAA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AACF,cAAU,MAAM,OAAO,0BAA0B,EAAE,MAAM,QAAQ,SAAS,iBAAiB,CAAC;AAAA,EAC9F,QAAQ;AACN,UAAM,IAAI,iBAAiB,MAAM;AAAA,EACnC;AACA,MAAI,QAAQ,WAAW,UAAW,OAAM,IAAI,kBAAkB,MAAM;AACpE,SAAO;AACT;AAEA,SAAS,eAAe,OAAe,OAAe,KAAmB;AACvE,MAAI,QAAQ,IAAK,OAAM,IAAI,oBAAoB,OAAO,OAAO,GAAG;AAClE;","names":["serializeTransaction"]}
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/wallet.ts"],"sourcesContent":["import { mkdir } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { CliError } from '../lib/errors';\nimport { walletPath } from '../lib/paths';\nimport { withFileLock, LockTimeoutError } from '../lib/lock';\nimport { loadRawConfig, resolveSettings } from '../lib/config';\nimport { toMoney } from '../lib/money';\nimport { getUsdcBalance } from '../lib/usdc';\nimport {\n commitLocalWallet,\n createLocalWallet,\n describeWallet,\n parkOutgoingWallet,\n prepareLocalWallet,\n resolveWalletProvider,\n restoreParkedWallet,\n verifyAndPreserveOutgoingWallet,\n type ArchivedWalletInfo,\n type ResolveWalletProviderOptions,\n} from '../lib/wallet';\nimport { walletExistsError, walletFileExists } from '../lib/wallet/store';\nimport { resolvePassphraseForCreate, type PassphraseSource } from '../lib/wallet/passphrase';\nimport type { PassphraseOverrides } from '../lib/wallet/local';\nimport type { CommandContext, CommandResult } from '../context';\n\nconst FUNDING_LINE =\n 'Fund it with `tenjin fund` (card via Coinbase), or send USDC on Base. $5 covers ~50 typical resources.';\nconst KEY_STORAGE = 'encrypted (keystore v3, scrypt)';\nconst isWindows = process.platform === 'win32';\n\nexport interface WalletCreateOptions {\n /**\n * Explicitly replace the existing active wallet (mirrors the `--yes`-style\n * explicit-flag precedent): the outgoing wallet is ARCHIVED — passphrase\n * verified against its keystore and preserved under its own address, keystore\n * parked beside the new one — never destroyed. Without it, create refuses\n * when a wallet exists. There is always exactly ONE active wallet.\n */\n replace?: boolean;\n /** Test seam for passphrase resolution (keychain exec, TTY prompt, platform). */\n passphrase?: PassphraseOverrides;\n /**\n * The environment TENJIN_WALLET_PASSPHRASE is read from; defaults to\n * process.env. A seam rather than a global read so a caller (and above all a\n * test) can settle the passphrase source WITHOUT mutating the real process\n * environment, which under a parallel runner leaks across whole test files.\n */\n env?: NodeJS.ProcessEnv;\n}\n\nexport async function runWalletCreate(\n ctx: CommandContext,\n opts: WalletCreateOptions = {},\n): Promise<CommandResult> {\n const {\n address,\n walletPath: path,\n source,\n replaced,\n } = await createWalletLocked(ctx.dataDir, opts);\n\n const warnings = custodyWarnings();\n return {\n data: {\n address,\n walletPath: path,\n provider: 'local',\n policyEnforcement: 'client-only',\n keyStorage: KEY_STORAGE,\n passphraseSource: source,\n ...(replaced !== undefined\n ? {\n replaced: {\n address: replaced.address,\n archivedWalletPath: replaced.archivedPath,\n passphrasePreserved: replaced.passphraseLocation,\n ...(replaced.unarchivedReason !== undefined\n ? { unarchivedReason: replaced.unarchivedReason }\n : {}),\n },\n }\n : {}),\n warnings,\n },\n humanLines: [\n `Wallet created: ${address}`,\n `Key stored ${KEY_STORAGE}.`,\n passphraseNote(source, address),\n ...(replaced !== undefined ? replacedNote(replaced, path) : []),\n FUNDING_LINE,\n ...warnings,\n ],\n };\n}\n\n/** Where the outgoing wallet's funds live, why they remain reachable, and how to restore it. */\nfunction replacedNote(replaced: ArchivedWalletInfo, activeWalletPath: string): string[] {\n const passphraseLine =\n replaced.passphraseLocation === 'store'\n ? `its passphrase is preserved in the OS credential store (service tenjin-cli, account ${replaced.account}).`\n : replaced.passphraseLocation === 'env'\n ? 'its passphrase is TENJIN_WALLET_PASSPHRASE — keep that value.'\n : replaced.unarchivedReason === 'rejected-characters'\n ? 'its passphrase was NOT archived: the macOS keychain writer only stores machine-generated (base64url) passphrases, and this typed one contains other characters. Keep it yourself, or set TENJIN_WALLET_PASSPHRASE to it.'\n : replaced.unarchivedReason === 'no-store'\n ? 'its passphrase was NOT archived: this platform has no OS credential store. It exists only where you keep it.'\n : 'its passphrase was NOT archived: the OS credential store write failed. It exists only where you keep it.';\n return [\n `Previous wallet archived: ${replaced.address} still holds any funds sent to it.`,\n `Its keystore was moved to ${replaced.archivedPath}; ${passphraseLine}`,\n `To make it the active wallet again later: move the current ${activeWalletPath} aside first, then \\`mv ${replaced.archivedPath} ${activeWalletPath}\\`.`,\n ];\n}\n\n/**\n * Run the whole create critical section under a cross-process file lock: the\n * existence pre-check, the passphrase generate-and-store, and the no-clobber\n * write. Without the lock these interleave across two concurrent creates — each\n * generates a distinct passphrase and persists it to the OS store BEFORE the\n * exclusive file write, so a different process could win the file while this\n * one's per-address entry names a wallet that never landed. Serializing means\n * the loser blocks until the winner commits, then trips the exists check and\n * exits WALLET_EXISTS having never generated or stored a passphrase. The\n * store-before-write ordering stays (it still guards the single-process crash\n * window), and the exclusive write stays the final authority.\n *\n * The passphrase is resolved inside the prepare step's address callback so the\n * OS-store entry is keyed to the new wallet's own address (issue #32).\n *\n * `--replace` ordering closes the no-active-wallet window: verify-and-preserve\n * the outgoing wallet (no file moves), fully PREPARE the replacement (key,\n * stored passphrase, encrypted keystore — every fallible step) while the old\n * wallet is still active, and only then park the old keystore and commit the\n * new one. A commit failure rolls the park back, so at every exit either the\n * old or the new wallet is the active one.\n */\nasync function createWalletLocked(\n dir: string,\n opts: WalletCreateOptions,\n): Promise<{\n address: string;\n walletPath: string;\n source: PassphraseSource;\n replaced?: ArchivedWalletInfo;\n}> {\n // Ensure the data dir exists so the lock's own mkdir has a parent on a fresh\n // install; the exclusive wallet write below re-ensures it at 0700 regardless.\n await mkdir(dir, { recursive: true, mode: 0o700 });\n const lockPath = join(dir, 'wallet.create.lock');\n try {\n return await withFileLock(lockPath, async () => {\n const env = opts.env ?? process.env;\n let source: PassphraseSource = 'env';\n const passphraseFor = async (forAddress: string): Promise<string> => {\n const resolved = await resolvePassphraseForCreate(\n { env, dir, ...opts.passphrase },\n forAddress,\n );\n source = resolved.source;\n return resolved.passphrase;\n };\n\n if (!(await walletFileExists(dir))) {\n const { address, walletPath: path } = await createLocalWallet(dir, passphraseFor);\n return { address, walletPath: path, source };\n }\n\n if (opts.replace !== true) throw walletExistsError(dir);\n const preserved = await verifyAndPreserveOutgoingWallet({\n dir,\n env,\n ...(opts.passphrase !== undefined ? { passphrase: opts.passphrase } : {}),\n });\n const prepared = await prepareLocalWallet(passphraseFor);\n const archivedPath = await parkOutgoingWallet(dir, preserved.account);\n try {\n const { address, walletPath: path } = await commitLocalWallet(dir, prepared);\n return { address, walletPath: path, source, replaced: { ...preserved, archivedPath } };\n } catch (err) {\n try {\n await restoreParkedWallet(dir, archivedPath);\n } catch (restoreErr) {\n // The no-clobber restore also refuses when a wallet.json appeared out\n // of band (commit EEXIST) — never overwrite it; name both files.\n throw new CliError(\n 'INTERNAL',\n 'Creating the replacement wallet failed after the old wallet was parked, and restoring it also failed.',\n {\n fix: `Your old wallet ${preserved.address} is intact at ${archivedPath} with its passphrase preserved. If a ${walletPath(dir)} now exists, another process wrote it — move it aside first. Then restore with \\`mv ${archivedPath} ${walletPath(dir)}\\`.`,\n cause: restoreErr,\n },\n );\n }\n // Old wallet restored as the active one; say so rather than surfacing a\n // raw fs error (or a WALLET_EXISTS whose fix suggests re-running --replace).\n throw new CliError(\n 'INTERNAL',\n 'Creating the replacement wallet failed; the previous wallet was restored and is the active wallet again.',\n {\n fix: 'Nothing was lost. Fix the underlying error, then retry `tenjin wallet create --replace`.',\n cause: err,\n },\n );\n }\n });\n } catch (err) {\n // A lock timeout is not the user's error; surface it as INTERNAL with the one\n // manual step (there is no auto-steal), keeping the JSON error contract. Every\n // other error — notably the loser's WALLET_EXISTS — propagates unchanged.\n if (err instanceof LockTimeoutError) {\n throw new CliError('INTERNAL', err.message, {\n fix: `If no other tenjin process is running, remove ${lockPath} and retry.`,\n cause: err,\n });\n }\n throw err;\n }\n}\n\n/** Where the encryption passphrase lives, and what the user must remember. */\nfunction passphraseNote(source: PassphraseSource, address: string): string {\n const account = address.toLowerCase();\n switch (source) {\n case 'keychain':\n return `Passphrase saved to your macOS keychain (service tenjin-cli, account ${account}); signing will be transparent on this machine.`;\n case 'dpapi':\n return `Passphrase saved to a DPAPI-encrypted per-wallet file (passphrase.${account}.dpapi), readable only by you on this Windows machine; signing will be transparent here.`;\n case 'secret-service':\n return `Passphrase saved to your Linux keyring (Secret Service, service tenjin-cli, account ${account}); signing will be transparent on this machine.`;\n case 'env':\n return 'Encrypted with TENJIN_WALLET_PASSPHRASE; keep that value to sign.';\n case 'prompt':\n return 'Remember your passphrase: it is required to sign and cannot be recovered.';\n }\n}\n\nexport async function runWalletShow(\n ctx: CommandContext,\n opts: ResolveWalletProviderOptions = {},\n): Promise<CommandResult> {\n const provider = resolveWalletProvider(ctx, opts);\n const desc = await describeWallet(provider);\n // Diagnostics are the provider's own: a remote provider reports no local file\n // path or perms warning, so `show` never contaminates a remote wallet's output\n // with a stale local wallet.json's state. keyStorage/passphraseSource are the\n // custody posture reported without decrypting or requiring a passphrase.\n const {\n walletPath: path,\n keyStorage,\n passphraseSource,\n archivedWallets,\n warnings,\n } = await provider.diagnostics();\n\n const humanLines = [`Address: ${desc.address}`, `Key source: ${desc.credentialSource}`];\n if (keyStorage !== undefined) humanLines.push(`Key storage: ${keyStorage}`);\n if (passphraseSource !== undefined) humanLines.push(`Passphrase: ${passphraseSource}`);\n if (archivedWallets !== undefined && archivedWallets.length > 0) {\n // A recovery hint, not a wallet switcher: exactly one wallet is ever active.\n humanLines.push(\n `Archived (replaced) wallets, funds recoverable via their preserved passphrases: ${archivedWallets.join(', ')}`,\n );\n }\n humanLines.push(...warnings);\n\n return {\n data: {\n address: desc.address,\n provider: desc.provider,\n credentialSource: desc.credentialSource,\n policyEnforcement: desc.policyEnforcement,\n ...(path !== undefined ? { walletPath: path } : {}),\n ...(keyStorage !== undefined ? { keyStorage } : {}),\n ...(passphraseSource !== undefined ? { passphraseSource } : {}),\n ...(archivedWallets !== undefined && archivedWallets.length > 0 ? { archivedWallets } : {}),\n warnings,\n },\n humanLines,\n };\n}\n\nexport async function runWalletBalance(\n ctx: CommandContext,\n opts: ResolveWalletProviderOptions = {},\n): Promise<CommandResult> {\n const provider = resolveWalletProvider(ctx, opts);\n const desc = await describeWallet(provider);\n\n const config = await loadRawConfig(ctx.dataDir);\n const rpcUrl = resolveSettings({\n config,\n flags: { baseUrl: ctx.flags.baseUrl },\n env: process.env,\n }).rpcUrl.value;\n\n let atomic: bigint;\n try {\n atomic = await getUsdcBalance(desc.address, rpcUrl);\n } catch (err) {\n throw new CliError('RPC_ERROR', `Could not read the USDC balance from ${rpcUrl}.`, {\n fix: 'Check your network, or set a working RPC with `tenjin config set rpcUrl <url>`.',\n cause: err,\n });\n }\n\n const balance = toMoney(atomic.toString());\n return {\n data: { address: desc.address, balance },\n humanLines: [`Balance: ${balance.usd} USDC on Base`],\n };\n}\n\nfunction custodyWarnings(): string[] {\n const warnings: string[] = [];\n if (hasEnvKey()) {\n warnings.push('TENJIN_WALLET_KEY is set and shadows this file at runtime.');\n }\n if (isWindows) {\n warnings.push('File permissions are not enforced on Windows; the key file is not restricted.');\n }\n return warnings;\n}\n\nfunction hasEnvKey(): boolean {\n const envKey = process.env.TENJIN_WALLET_KEY;\n return envKey !== undefined && envKey.length > 0;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,SAAS,aAAa;AACtB,SAAS,YAAY;AAwBrB,IAAM,eACJ;AACF,IAAM,cAAc;AACpB,IAAM,YAAY,QAAQ,aAAa;AAsBvC,eAAsB,gBACpB,KACA,OAA4B,CAAC,GACL;AACxB,QAAM;AAAA,IACJ;AAAA,IACA,YAAY;AAAA,IACZ;AAAA,IACA;AAAA,EACF,IAAI,MAAM,mBAAmB,IAAI,SAAS,IAAI;AAE9C,QAAM,WAAW,gBAAgB;AACjC,SAAO;AAAA,IACL,MAAM;AAAA,MACJ;AAAA,MACA,YAAY;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A,MACjD,GAAI,qBAAqB,SAAY,EAAE,iBAAiB,IAAI,CAAC;AAAA,MAC7D,GAAI,oBAAoB,UAAa,gBAAgB,SAAS,IAAI,EAAE,gBAAgB,IAAI,CAAC;AAAA,MACzF;AAAA,IACF;AAAA,IACA;AAAA,EACF;AACF;AAEA,eAAsB,iBACpB,KACA,OAAqC,CAAC,GACd;AACxB,QAAM,WAAW,sBAAsB,KAAK,IAAI;AAChD,QAAM,OAAO,MAAM,eAAe,QAAQ;AAE1C,QAAM,SAAS,MAAM,cAAc,IAAI,OAAO;AAC9C,QAAM,SAAS,gBAAgB;AAAA,IAC7B;AAAA,IACA,OAAO,EAAE,SAAS,IAAI,MAAM,QAAQ;AAAA,IACpC,KAAK,QAAQ;AAAA,EACf,CAAC,EAAE,OAAO;AAEV,MAAI;AACJ,MAAI;AACF,aAAS,MAAM,eAAe,KAAK,SAAS,MAAM;AAAA,EACpD,SAAS,KAAK;AACZ,UAAM,IAAI,SAAS,aAAa,wCAAwC,MAAM,KAAK;AAAA,MACjF,KAAK;AAAA,MACL,OAAO;AAAA,IACT,CAAC;AAAA,EACH;AAEA,QAAM,UAAU,QAAQ,OAAO,SAAS,CAAC;AACzC,SAAO;AAAA,IACL,MAAM,EAAE,SAAS,KAAK,SAAS,QAAQ;AAAA,IACvC,YAAY,CAAC,YAAY,QAAQ,GAAG,eAAe;AAAA,EACrD;AACF;AAEA,SAAS,kBAA4B;AACnC,QAAM,WAAqB,CAAC;AAC5B,MAAI,UAAU,GAAG;AACf,aAAS,KAAK,4DAA4D;AAAA,EAC5E;AACA,MAAI,WAAW;AACb,aAAS,KAAK,+EAA+E;AAAA,EAC/F;AACA,SAAO;AACT;AAEA,SAAS,YAAqB;AAC5B,QAAM,SAAS,QAAQ,IAAI;AAC3B,SAAO,WAAW,UAAa,OAAO,SAAS;AACjD;","names":[]}
@@ -1,209 +0,0 @@
1
- import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
- import {
3
- deliverExisting,
4
- deliverFresh,
5
- parseSectionsBudget
6
- } from "./chunk-CAR6FHK6.js";
7
- import {
8
- buildExactPayment,
9
- gateSpend
10
- } from "./chunk-2RF2GIJQ.js";
11
- import {
12
- fetchRead
13
- } from "./chunk-LRYV3SK7.js";
14
- import {
15
- buildSiwxHeader
16
- } from "./chunk-KINZ23CV.js";
17
- import {
18
- findDelivered,
19
- findDeliveredByUrl,
20
- resolveResourceRef
21
- } from "./chunk-VJQKL3YH.js";
22
- import {
23
- describeWallet,
24
- resolveSpendAuthorizer,
25
- resolveWalletProvider
26
- } from "./chunk-CPCX67TI.js";
27
- import {
28
- sanitizeForTerminal
29
- } from "./chunk-OLWTRUTS.js";
30
- import {
31
- resolveContextSettings
32
- } from "./chunk-VYOJOX4Z.js";
33
- import {
34
- parseUsdToAtomic
35
- } from "./chunk-EFWZPUTC.js";
36
- import {
37
- findSearchForResource
38
- } from "./chunk-A5DKHMUN.js";
39
- import {
40
- CliError
41
- } from "./chunk-ZFJJ3EXC.js";
42
-
43
- // src/commands/buy.ts
44
- async function runBuy(args, ctx, deps = {}) {
45
- const settings = await resolveContextSettings(ctx);
46
- const sectionsBudget = parseSectionsBudget(args.sections);
47
- const maxPriceAtomic = args.maxPrice !== void 0 ? BigInt(parseUsdToAtomic(args.maxPrice)) : void 0;
48
- const ref = await resolveResourceRef(args.ref, ctx.dataDir, settings.baseUrl);
49
- const existing = ref.resourceId !== void 0 ? await findDelivered(ctx.dataDir, ref.resourceId) : await findDeliveredByUrl(ctx.dataDir, ref.url);
50
- const presentOpts = { printBody: args.printBody === true, sectionsBudget };
51
- if (existing !== null) {
52
- return deliverExisting(existing, presentOpts);
53
- }
54
- const searchId = await findSearchForResource(ctx.dataDir, {
55
- ...ref.resourceId !== void 0 ? { resourceId: ref.resourceId } : {},
56
- url: ref.url
57
- }) ?? void 0;
58
- const fetchOpts = {
59
- timeoutMs: ctx.flags.timeout,
60
- ...deps.fetchImpl !== void 0 ? { fetchImpl: deps.fetchImpl } : {}
61
- };
62
- const first = await fetchRead(ref.url, fetchOpts);
63
- if (first.kind === "entitled") {
64
- return await deliverFresh(ctx.dataDir, ref.url, first.body, "free", void 0, presentOpts);
65
- }
66
- if (first.kind === "already_purchased") {
67
- throw new CliError("API_UNREACHABLE", "Unexpected 409 on an unauthenticated read.", {
68
- fix: "Retry; if it persists, update tenjin-cli."
69
- });
70
- }
71
- const firstRequirement = first.paymentRequired.accepts[0];
72
- if (firstRequirement === void 0) {
73
- throw new CliError("PAYMENT_FAILED", "The 402 advertised no payment requirements.", {
74
- fix: "Try another candidate; this resource looks misconfigured."
75
- });
76
- }
77
- const firstSeenAmount = BigInt(firstRequirement.amount);
78
- const provider = resolveWalletProvider(
79
- ctx,
80
- deps.provider !== void 0 ? { provider: deps.provider } : {}
81
- );
82
- await describeWallet(provider);
83
- const signer = await provider.getSigner();
84
- const siwxHeader = await buildSiwxHeader(signer, {
85
- baseUrl: settings.baseUrl,
86
- chainId: firstRequirement.network
87
- });
88
- const recheck = await fetchRead(ref.url, { ...fetchOpts, siwxHeader });
89
- if (recheck.kind === "entitled") {
90
- return await deliverFresh(
91
- ctx.dataDir,
92
- ref.url,
93
- recheck.body,
94
- "entitled",
95
- void 0,
96
- presentOpts
97
- );
98
- }
99
- if (recheck.kind !== "payment_required") {
100
- throw new CliError(
101
- "API_UNREACHABLE",
102
- "Unexpected read response during the entitlement re-check.",
103
- {
104
- fix: "Retry; if it persists, update tenjin-cli."
105
- }
106
- );
107
- }
108
- const paymentRequired = recheck.paymentRequired;
109
- const requirement = paymentRequired.accepts[0];
110
- if (requirement === void 0) {
111
- throw new CliError("PAYMENT_FAILED", "The fresh 402 advertised no payment requirements.", {
112
- fix: "Try another candidate; this resource looks misconfigured."
113
- });
114
- }
115
- const amountAtomic = BigInt(requirement.amount);
116
- if (amountAtomic > firstSeenAmount) {
117
- throw new CliError("PAYMENT_FAILED", "The price increased before signing; refusing to pay.", {
118
- fix: "Re-run `tenjin buy` to review the new price, and set --max-price to cap it.",
119
- details: {
120
- firstSeenAtomic: firstSeenAmount.toString(),
121
- currentAtomic: amountAtomic.toString()
122
- }
123
- });
124
- }
125
- const network = requirement.network;
126
- const creator = creatorFrom(recheck.preview);
127
- const authorizer = resolveSpendAuthorizer(
128
- ctx,
129
- settings.policy,
130
- deps.authorizer !== void 0 ? { authorizer: deps.authorizer } : {}
131
- );
132
- const reservationId = await gateSpend({
133
- ctx,
134
- authorizer,
135
- amountAtomic,
136
- creator,
137
- ...maxPriceAtomic !== void 0 ? { maxPriceAtomic } : {},
138
- yes: args.yes === true,
139
- ...deps.confirm !== void 0 ? { confirm: deps.confirm } : {},
140
- // The creator label is server-controlled: sanitized so escape sequences
141
- // cannot repaint the price the human is approving.
142
- payeeLabel: sanitizeForTerminal(creator) || "this creator",
143
- allowlistSubject: "the creator",
144
- notConfirmedMessage: "Purchase not confirmed."
145
- });
146
- try {
147
- const payment = await buildExactPayment(paymentRequired, signer);
148
- const paid = await fetchRead(ref.url, {
149
- ...fetchOpts,
150
- paymentHeaders: payment.headers,
151
- ...searchId !== void 0 ? { searchId } : {}
152
- });
153
- if (paid.kind === "entitled") {
154
- await authorizer.commit(reservationId, payment.amountAtomic);
155
- return await deliverFresh(
156
- ctx.dataDir,
157
- ref.url,
158
- paid.body,
159
- "purchased",
160
- { paidAtomic: payment.amountAtomic, settlementTxHash: paid.settlementTxHash },
161
- presentOpts
162
- );
163
- }
164
- if (paid.kind === "already_purchased") {
165
- await authorizer.release(reservationId);
166
- return await siwxRedeliver(
167
- ctx,
168
- ref.url,
169
- settings.baseUrl,
170
- signer,
171
- fetchOpts,
172
- presentOpts,
173
- network
174
- );
175
- }
176
- throw new CliError("PAYMENT_FAILED", "Payment was not accepted by the read route.", {
177
- fix: "Check the wallet balance and network, then retry.",
178
- details: paid.paymentRequired.error
179
- });
180
- } catch (err) {
181
- await authorizer.release(reservationId);
182
- throw err;
183
- }
184
- }
185
- async function siwxRedeliver(ctx, url, baseUrl, signer, fetchOpts, presentOpts, network) {
186
- const siwxHeader = await buildSiwxHeader(signer, { baseUrl, chainId: network });
187
- const res = await fetchRead(url, { ...fetchOpts, siwxHeader });
188
- if (res.kind !== "entitled") {
189
- throw new CliError("PAYMENT_FAILED", "The resource is owned but could not be re-read.", {
190
- fix: "Retry; if it persists the entitlement may not have propagated yet."
191
- });
192
- }
193
- return await deliverFresh(ctx.dataDir, url, res.body, "entitled", void 0, presentOpts);
194
- }
195
- function creatorFrom(preview) {
196
- const creator = preview.creator;
197
- if (creator !== void 0) {
198
- const handle = creator.handle;
199
- const wallet = creator.walletAddress;
200
- if (typeof handle === "string" && handle.length > 0) return handle;
201
- if (typeof wallet === "string" && wallet.length > 0) return wallet;
202
- }
203
- return "";
204
- }
205
-
206
- export {
207
- runBuy
208
- };
209
- //# sourceMappingURL=chunk-OKDRDT74.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/commands/buy.ts"],"sourcesContent":["import { CliError } from '../lib/errors';\nimport { parseUsdToAtomic } from '../lib/money';\nimport { resolveContextSettings } from '../lib/settings';\nimport { resolveResourceRef } from '../lib/resource-ref';\nimport { findSearchForResource } from '../lib/search-store';\nimport { fetchRead, type Preview } from '../lib/read-client';\nimport { buildSiwxHeader } from '../lib/siwx';\nimport { buildExactPayment } from '../lib/x402-pay';\nimport { gateSpend } from '../lib/spend-gate';\nimport { findDelivered, findDeliveredByUrl } from '../lib/library';\nimport {\n deliverExisting,\n deliverFresh,\n parseSectionsBudget,\n type PresentOpts,\n} from '../lib/delivery';\nimport {\n describeWallet,\n resolveSpendAuthorizer,\n resolveWalletProvider,\n type SpendAuthorizer,\n type TenjinSigner,\n type WalletProvider,\n} from '../lib/wallet';\nimport { sanitizeForTerminal } from '../lib/output';\nimport type { CommandContext, CommandResult } from '../context';\n\n/**\n * `tenjin buy <resource-url-or-id>`, the paid read. The ordering is the whole\n * point and is enforced here, never in the wallet:\n * 1. local library (already delivered → re-deliver from disk, no network, no pay)\n * 2. first GET → a FREE resource delivers immediately (no wallet)\n * 3. a PAID resource: SIWX-authenticated re-read FIRST, an entitled wallet\n * re-reads free and NEVER pays twice\n * 4. only a genuinely-unentitled paid read reaches spend policy (provider-side)\n * 5. x402 exact payment, then save + commit the session ledger\n * The 409 owned-re-pay gate is respected: a rejected re-pay falls back to the free\n * SIWX re-read, never a charge.\n *\n * The delivery + rendering half (library write, envelope shape, human lines) lives\n * in lib/delivery.ts, shared with `tenjin read`, the free-only verb (#42). Only the\n * ACCESS half — wallet, SIWX, spend policy, x402 — lives here, which is what keeps\n * the pay module out of read's import graph.\n */\n\nexport interface BuyArgs {\n ref: string;\n /** Decimal USD at the edge (O1); the hard price cap, never bypassed by --yes. */\n maxPrice?: string;\n /** Bypass the interactive confirm only (never the price cap or a hard deny). */\n yes?: boolean;\n /** Include the full body in the machine output (default: outline only). */\n printBody?: boolean;\n /** Include leading sections within this token budget (deterministic split). */\n sections?: string;\n}\n\nexport interface BuyDeps {\n fetchImpl?: typeof fetch;\n provider?: WalletProvider;\n authorizer?: SpendAuthorizer;\n /** Interactive-confirm seam; defaults to a TTY y/n prompt. */\n confirm?: (prompt: string) => Promise<boolean>;\n}\n\nexport async function runBuy(\n args: BuyArgs,\n ctx: CommandContext,\n deps: BuyDeps = {},\n): Promise<CommandResult> {\n const settings = await resolveContextSettings(ctx);\n const sectionsBudget = parseSectionsBudget(args.sections);\n const maxPriceAtomic =\n args.maxPrice !== undefined ? BigInt(parseUsdToAtomic(args.maxPrice)) : undefined;\n const ref = await resolveResourceRef(args.ref, ctx.dataDir, settings.baseUrl);\n\n // 1. Library idempotence, BEFORE any network or pay: a resource already on disk\n // re-delivers from disk. Works for both an id ref and a url ref (the url is\n // matched to a saved receipt by its handle/slug), so a repeat buy of an owned\n // resource never re-pays regardless of how it is addressed.\n const existing =\n ref.resourceId !== undefined\n ? await findDelivered(ctx.dataDir, ref.resourceId)\n : await findDeliveredByUrl(ctx.dataDir, ref.url);\n const presentOpts: PresentOpts = { printBody: args.printBody === true, sectionsBudget };\n if (existing !== null) {\n return deliverExisting(existing, presentOpts);\n }\n\n const searchId =\n (await findSearchForResource(ctx.dataDir, {\n ...(ref.resourceId !== undefined ? { resourceId: ref.resourceId } : {}),\n url: ref.url,\n })) ?? undefined;\n\n // Attribution contract (spec 09 §3): X-Tenjin-Search-Id rides ONLY the paid\n // re-request. The probe and SIWX re-check stay unattributed so a search that\n // never converts is not over-counted if the server ever classifies reads.\n const fetchOpts = {\n timeoutMs: ctx.flags.timeout,\n ...(deps.fetchImpl !== undefined ? { fetchImpl: deps.fetchImpl } : {}),\n };\n\n // 2. First GET, unauthenticated.\n const first = await fetchRead(ref.url, fetchOpts);\n if (first.kind === 'entitled') {\n // A free resource (no payment challenge was issued).\n return await deliverFresh(ctx.dataDir, ref.url, first.body, 'free', undefined, presentOpts);\n }\n if (first.kind === 'already_purchased') {\n // A plain GET does not carry a payment header, so the read route cannot answer\n // the owned-re-pay 409 here; the contract makes this unreachable. Fail loudly\n // rather than guess a chain for a SIWX recovery.\n throw new CliError('API_UNREACHABLE', 'Unexpected 409 on an unauthenticated read.', {\n fix: 'Retry; if it persists, update tenjin-cli.',\n });\n }\n\n // A paid resource. From here a wallet is required. Capture the FIRST-SEEN amount\n // (and the chain to sign SIWX over) so a later price bump is detectable.\n const firstRequirement = first.paymentRequired.accepts[0];\n if (firstRequirement === undefined) {\n throw new CliError('PAYMENT_FAILED', 'The 402 advertised no payment requirements.', {\n fix: 'Try another candidate; this resource looks misconfigured.',\n });\n }\n const firstSeenAmount = BigInt(firstRequirement.amount);\n\n const provider = resolveWalletProvider(\n ctx,\n deps.provider !== undefined ? { provider: deps.provider } : {},\n );\n // describeWallet surfaces WALLET_MISSING with its own fix if no wallet exists.\n await describeWallet(provider);\n const signer = await provider.getSigner();\n\n // 3. Entitlement re-check FIRST (SIWX): an entitled wallet re-reads free. This\n // request is ALSO the fresh 402 refetch, so the challenge signed below is the\n // latest one, never the stale first look.\n const siwxHeader = await buildSiwxHeader(signer, {\n baseUrl: settings.baseUrl,\n chainId: firstRequirement.network,\n });\n const recheck = await fetchRead(ref.url, { ...fetchOpts, siwxHeader });\n if (recheck.kind === 'entitled') {\n return await deliverFresh(\n ctx.dataDir,\n ref.url,\n recheck.body,\n 'entitled',\n undefined,\n presentOpts,\n );\n }\n if (recheck.kind !== 'payment_required') {\n throw new CliError(\n 'API_UNREACHABLE',\n 'Unexpected read response during the entitlement re-check.',\n {\n fix: 'Retry; if it persists, update tenjin-cli.',\n },\n );\n }\n\n // The FRESH challenge the payment is built and priced against.\n const paymentRequired = recheck.paymentRequired;\n const requirement = paymentRequired.accepts[0];\n if (requirement === undefined) {\n throw new CliError('PAYMENT_FAILED', 'The fresh 402 advertised no payment requirements.', {\n fix: 'Try another candidate; this resource looks misconfigured.',\n });\n }\n const amountAtomic = BigInt(requirement.amount);\n // Refuse a price bump between the first look and signing: never sign a challenge\n // that costs more than what was first advertised.\n if (amountAtomic > firstSeenAmount) {\n throw new CliError('PAYMENT_FAILED', 'The price increased before signing; refusing to pay.', {\n fix: 'Re-run `tenjin buy` to review the new price, and set --max-price to cap it.',\n details: {\n firstSeenAtomic: firstSeenAmount.toString(),\n currentAtomic: amountAtomic.toString(),\n },\n });\n }\n const network = requirement.network;\n const creator = creatorFrom(recheck.preview);\n\n // 4. Genuinely unentitled: spend policy, provider-side, on the FRESH amount,\n // BEFORE any payment. A proceeding decision reserves budget atomically.\n // The gate itself (deny/confirm/release shapes) is shared with `pay`.\n const authorizer = resolveSpendAuthorizer(\n ctx,\n settings.policy,\n deps.authorizer !== undefined ? { authorizer: deps.authorizer } : {},\n );\n const reservationId = await gateSpend({\n ctx,\n authorizer,\n amountAtomic,\n creator,\n ...(maxPriceAtomic !== undefined ? { maxPriceAtomic } : {}),\n yes: args.yes === true,\n ...(deps.confirm !== undefined ? { confirm: deps.confirm } : {}),\n // The creator label is server-controlled: sanitized so escape sequences\n // cannot repaint the price the human is approving.\n payeeLabel: sanitizeForTerminal(creator) || 'this creator',\n allowlistSubject: 'the creator',\n notConfirmedMessage: 'Purchase not confirmed.',\n });\n\n // 5. Pay: build the exact-scheme authorization (bound to the FRESH requirement)\n // and re-request with it. Any non-settlement outcome releases the reservation.\n try {\n const payment = await buildExactPayment(paymentRequired, signer);\n const paid = await fetchRead(ref.url, {\n ...fetchOpts,\n paymentHeaders: payment.headers,\n ...(searchId !== undefined ? { searchId } : {}),\n });\n\n if (paid.kind === 'entitled') {\n await authorizer.commit(reservationId, payment.amountAtomic);\n return await deliverFresh(\n ctx.dataDir,\n ref.url,\n paid.body,\n 'purchased',\n { paidAtomic: payment.amountAtomic, settlementTxHash: paid.settlementTxHash },\n presentOpts,\n );\n }\n if (paid.kind === 'already_purchased') {\n // The owned-re-pay gate fired: nothing charged. Release the reservation and\n // recover the body free via SIWX.\n await authorizer.release(reservationId);\n return await siwxRedeliver(\n ctx,\n ref.url,\n settings.baseUrl,\n signer,\n fetchOpts,\n presentOpts,\n network,\n );\n }\n // Still 402 after paying: the payment was not accepted (the catch releases).\n throw new CliError('PAYMENT_FAILED', 'Payment was not accepted by the read route.', {\n fix: 'Check the wallet balance and network, then retry.',\n details: paid.paymentRequired.error,\n });\n } catch (err) {\n // A build/settlement failure must not leave budget reserved.\n await authorizer.release(reservationId);\n throw err;\n }\n}\n\nasync function siwxRedeliver(\n ctx: CommandContext,\n url: string,\n baseUrl: string,\n signer: TenjinSigner,\n fetchOpts: { timeoutMs: number; fetchImpl?: typeof fetch; searchId?: string },\n presentOpts: PresentOpts,\n network: string,\n): Promise<CommandResult> {\n const siwxHeader = await buildSiwxHeader(signer, { baseUrl, chainId: network });\n const res = await fetchRead(url, { ...fetchOpts, siwxHeader });\n if (res.kind !== 'entitled') {\n throw new CliError('PAYMENT_FAILED', 'The resource is owned but could not be re-read.', {\n fix: 'Retry; if it persists the entitlement may not have propagated yet.',\n });\n }\n return await deliverFresh(ctx.dataDir, url, res.body, 'entitled', undefined, presentOpts);\n}\n\nfunction creatorFrom(preview: Preview): string {\n const creator = preview.creator;\n if (creator !== undefined) {\n const handle = creator.handle;\n const wallet = creator.walletAddress;\n if (typeof handle === 'string' && handle.length > 0) return handle;\n if (typeof wallet === 'string' && wallet.length > 0) return wallet;\n }\n return '';\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiEA,eAAsB,OACpB,MACA,KACA,OAAgB,CAAC,GACO;AACxB,QAAM,WAAW,MAAM,uBAAuB,GAAG;AACjD,QAAM,iBAAiB,oBAAoB,KAAK,QAAQ;AACxD,QAAM,iBACJ,KAAK,aAAa,SAAY,OAAO,iBAAiB,KAAK,QAAQ,CAAC,IAAI;AAC1E,QAAM,MAAM,MAAM,mBAAmB,KAAK,KAAK,IAAI,SAAS,SAAS,OAAO;AAM5E,QAAM,WACJ,IAAI,eAAe,SACf,MAAM,cAAc,IAAI,SAAS,IAAI,UAAU,IAC/C,MAAM,mBAAmB,IAAI,SAAS,IAAI,GAAG;AACnD,QAAM,cAA2B,EAAE,WAAW,KAAK,cAAc,MAAM,eAAe;AACtF,MAAI,aAAa,MAAM;AACrB,WAAO,gBAAgB,UAAU,WAAW;AAAA,EAC9C;AAEA,QAAM,WACH,MAAM,sBAAsB,IAAI,SAAS;AAAA,IACxC,GAAI,IAAI,eAAe,SAAY,EAAE,YAAY,IAAI,WAAW,IAAI,CAAC;AAAA,IACrE,KAAK,IAAI;AAAA,EACX,CAAC,KAAM;AAKT,QAAM,YAAY;AAAA,IAChB,WAAW,IAAI,MAAM;AAAA,IACrB,GAAI,KAAK,cAAc,SAAY,EAAE,WAAW,KAAK,UAAU,IAAI,CAAC;AAAA,EACtE;AAGA,QAAM,QAAQ,MAAM,UAAU,IAAI,KAAK,SAAS;AAChD,MAAI,MAAM,SAAS,YAAY;AAE7B,WAAO,MAAM,aAAa,IAAI,SAAS,IAAI,KAAK,MAAM,MAAM,QAAQ,QAAW,WAAW;AAAA,EAC5F;AACA,MAAI,MAAM,SAAS,qBAAqB;AAItC,UAAM,IAA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