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,1188 +0,0 @@
1
- import { createRequire as __tenjinCreateRequire } from 'node:module'; const require = __tenjinCreateRequire(import.meta.url);
2
- import {
3
- promptYesNo
4
- } from "./chunk-QW2Q2KAH.js";
5
- import {
6
- createPublicClient,
7
- http
8
- } from "./chunk-KINZ23CV.js";
9
- import {
10
- findByNetworkAndScheme,
11
- findSchemesByNetwork,
12
- x402HTTPClient,
13
- x402Version
14
- } from "./chunk-DBU5CXBV.js";
15
- import {
16
- encodeFunctionData,
17
- getAddress as getAddress2,
18
- keccak256,
19
- maxUint256,
20
- toBytes,
21
- toHex
22
- } from "./chunk-KZAAWQNP.js";
23
- import {
24
- USDC_ADDRESS
25
- } from "./chunk-MJZZTKCC.js";
26
- import {
27
- toMoney
28
- } from "./chunk-EFWZPUTC.js";
29
- import {
30
- CliError
31
- } from "./chunk-ZFJJ3EXC.js";
32
- import {
33
- getAddress
34
- } from "./chunk-47PP7TAG.js";
35
-
36
- // src/lib/spend-gate.ts
37
- async function gateSpend(input) {
38
- const { authorizer, amountAtomic } = input;
39
- const authorization = await authorizer.authorize({
40
- amountAtomic,
41
- creator: input.creator,
42
- ...input.maxPriceAtomic !== void 0 ? { maxPriceAtomic: input.maxPriceAtomic } : {}
43
- });
44
- if (authorization.decision === "deny") {
45
- throw new CliError("POLICY_REFUSED", authorization.message, {
46
- fix: policyFix(authorization.reason, input.allowlistSubject),
47
- details: { reason: authorization.reason, amountAtomic: amountAtomic.toString() }
48
- });
49
- }
50
- const reservationId = authorization.reservationId;
51
- if (authorization.decision === "confirm") {
52
- const approved = await confirmSpend(input);
53
- if (!approved) {
54
- await authorizer.release(reservationId);
55
- throw new CliError("POLICY_REFUSED", input.notConfirmedMessage, {
56
- fix: "Re-run with --yes, or set a policy that auto-approves this spend.",
57
- details: { reason: authorization.reason, amountAtomic: amountAtomic.toString() }
58
- });
59
- }
60
- }
61
- return reservationId;
62
- }
63
- function policyFix(reason, allowlistSubject) {
64
- switch (reason) {
65
- case "price_cap_exceeded":
66
- return "Raise --max-price if this price is acceptable.";
67
- case "not_allowlisted":
68
- return `Add ${allowlistSubject} to allowlistCreators, or clear the allowlist.`;
69
- case "session_budget_exceeded":
70
- return "Raise sessionBudget with `tenjin config set sessionBudget <usd>`, or wait for the window to roll over.";
71
- default:
72
- return "Adjust your spend policy with `tenjin config set`.";
73
- }
74
- }
75
- async function confirmSpend(input) {
76
- if (input.yes) return true;
77
- const prompt = `Pay ${toMoney(input.amountAtomic.toString()).usd} USD to ${input.payeeLabel}? [y/N] `;
78
- if (input.confirm !== void 0) return input.confirm(prompt);
79
- if (!input.ctx.io.isTTY) return false;
80
- if (!process.stdin.isTTY) return false;
81
- return promptYesNo(prompt);
82
- }
83
-
84
- // node_modules/.pnpm/@x402+core@2.17.0/node_modules/@x402/core/dist/esm/client/index.mjs
85
- var x402Client = class _x402Client {
86
- /**
87
- * Creates a new x402Client instance.
88
- *
89
- * @param paymentRequirementsSelector - Function to select payment requirements from available options
90
- */
91
- constructor(paymentRequirementsSelector) {
92
- this.registeredClientSchemes = /* @__PURE__ */ new Map();
93
- this.schemeClientHookAdapters = /* @__PURE__ */ new Map();
94
- this.policies = [];
95
- this.registeredExtensions = /* @__PURE__ */ new Map();
96
- this.beforePaymentCreationHooks = [];
97
- this.afterPaymentCreationHooks = [];
98
- this.onPaymentCreationFailureHooks = [];
99
- this.paymentResponseHooks = [];
100
- this.paymentRequirementsSelector = paymentRequirementsSelector || ((x402Version2, accepts) => accepts[0]);
101
- }
102
- /**
103
- * Creates a new x402Client instance from a configuration object.
104
- *
105
- * @param config - The client configuration including schemes, policies, and payment requirements selector
106
- * @returns A configured x402Client instance
107
- */
108
- static fromConfig(config) {
109
- const client = new _x402Client(config.paymentRequirementsSelector);
110
- config.schemes.forEach((scheme) => {
111
- if (scheme.x402Version === 1) {
112
- client.registerV1(scheme.network, scheme.client);
113
- } else {
114
- client.register(scheme.network, scheme.client);
115
- }
116
- });
117
- config.policies?.forEach((policy) => {
118
- client.registerPolicy(policy);
119
- });
120
- return client;
121
- }
122
- /**
123
- * Registers a scheme client for the current x402 version.
124
- *
125
- * @param network - The network to register the client for
126
- * @param client - The scheme network client to register
127
- * @returns The x402Client instance for chaining
128
- */
129
- register(network, client) {
130
- return this._registerScheme(x402Version, network, client);
131
- }
132
- /**
133
- * Registers a scheme client for x402 version 1.
134
- *
135
- * @param network - The v1 network identifier (e.g., 'base-sepolia', 'solana-devnet')
136
- * @param client - The scheme network client to register
137
- * @returns The x402Client instance for chaining
138
- */
139
- registerV1(network, client) {
140
- return this._registerScheme(1, network, client);
141
- }
142
- /**
143
- * Registers a policy to filter or transform payment requirements.
144
- *
145
- * Policies are applied in order after filtering by registered schemes
146
- * and before the selector chooses the final payment requirement.
147
- *
148
- * @param policy - Function to filter/transform payment requirements
149
- * @returns The x402Client instance for chaining
150
- *
151
- * @example
152
- * ```typescript
153
- * // Prefer cheaper options
154
- * client.registerPolicy((version, reqs) =>
155
- * reqs.filter(r => BigInt(r.value) < BigInt('1000000'))
156
- * );
157
- *
158
- * // Prefer specific networks
159
- * client.registerPolicy((version, reqs) =>
160
- * reqs.filter(r => r.network.startsWith('eip155:'))
161
- * );
162
- * ```
163
- */
164
- registerPolicy(policy) {
165
- this.policies.push(policy);
166
- return this;
167
- }
168
- /**
169
- * Registers a client extension that can enrich payment payloads.
170
- *
171
- * Extensions are invoked after the scheme creates the base payload and the
172
- * payload is wrapped with extensions/resource/accepted data. If the extension's
173
- * key is present in `paymentRequired.extensions`, the extension's
174
- * `enrichPaymentPayload` hook is called to modify the payload.
175
- *
176
- * @param extension - The client extension to register
177
- * @returns The x402Client instance for chaining
178
- */
179
- registerExtension(extension) {
180
- this.registeredExtensions.set(extension.key, extension);
181
- return this;
182
- }
183
- /**
184
- * Get all registered client extensions.
185
- *
186
- * @returns Array of registered extensions
187
- */
188
- getExtensions() {
189
- return Array.from(this.registeredExtensions.values());
190
- }
191
- /**
192
- * Register a hook to execute before payment payload creation.
193
- * Can abort creation by returning { abort: true, reason: string }
194
- *
195
- * @param hook - The hook function to register
196
- * @returns The x402Client instance for chaining
197
- */
198
- onBeforePaymentCreation(hook) {
199
- this.beforePaymentCreationHooks.push(hook);
200
- return this;
201
- }
202
- /**
203
- * Register a hook to execute after successful payment payload creation.
204
- *
205
- * @param hook - The hook function to register
206
- * @returns The x402Client instance for chaining
207
- */
208
- onAfterPaymentCreation(hook) {
209
- this.afterPaymentCreationHooks.push(hook);
210
- return this;
211
- }
212
- /**
213
- * Register a hook to execute when payment payload creation fails.
214
- * Can recover from failure by returning { recovered: true, payload: PaymentPayload }
215
- *
216
- * @param hook - The hook function to register
217
- * @returns The x402Client instance for chaining
218
- */
219
- onPaymentCreationFailure(hook) {
220
- this.onPaymentCreationFailureHooks.push(hook);
221
- return this;
222
- }
223
- /**
224
- * Register a hook to execute after a paid request completes.
225
- * Can signal recovery by returning { recovered: true }, causing the transport to retry.
226
- *
227
- * @param hook - The hook function to register
228
- * @returns The x402Client instance for chaining
229
- */
230
- onPaymentResponse(hook) {
231
- this.paymentResponseHooks.push(hook);
232
- return this;
233
- }
234
- /**
235
- * Fires all registered payment response hooks in order.
236
- * Returns `{ recovered: true }` if any hook signals recovery (first wins).
237
- *
238
- * @param ctx - The payment response context
239
- * @returns Recovery signal or undefined
240
- */
241
- async handlePaymentResponse(ctx) {
242
- for (const hook of this.getLabeledHooks(
243
- "onPaymentResponse",
244
- ctx.paymentPayload.x402Version,
245
- ctx.requirements,
246
- ctx.paymentRequired?.extensions ?? ctx.paymentPayload.extensions
247
- )) {
248
- const result = await hook(ctx);
249
- if (result && "recovered" in result && result.recovered) {
250
- return { recovered: true };
251
- }
252
- }
253
- return void 0;
254
- }
255
- /**
256
- * Creates a payment payload based on a PaymentRequired response.
257
- *
258
- * Automatically extracts x402Version, resource, and extensions from the PaymentRequired
259
- * response and constructs a complete PaymentPayload with the accepted requirements.
260
- *
261
- * @param paymentRequired - The PaymentRequired response from the server
262
- * @returns Promise resolving to the complete payment payload
263
- */
264
- async createPaymentPayload(paymentRequired) {
265
- const clientSchemesByNetwork = this.registeredClientSchemes.get(paymentRequired.x402Version);
266
- if (!clientSchemesByNetwork) {
267
- throw new Error(`No client registered for x402 version: ${paymentRequired.x402Version}`);
268
- }
269
- const requirements = this.selectPaymentRequirements(paymentRequired.x402Version, paymentRequired.accepts);
270
- const context = {
271
- paymentRequired,
272
- selectedRequirements: requirements
273
- };
274
- for (const hook of this.getLabeledHooks(
275
- "beforePaymentCreation",
276
- paymentRequired.x402Version,
277
- requirements,
278
- paymentRequired.extensions
279
- )) {
280
- const result = await hook(context);
281
- if (result && "abort" in result && result.abort) {
282
- throw new Error(`Payment creation aborted: ${result.reason}`);
283
- }
284
- }
285
- try {
286
- const schemeNetworkClient = findByNetworkAndScheme(clientSchemesByNetwork, requirements.scheme, requirements.network);
287
- if (!schemeNetworkClient) {
288
- throw new Error(`No client registered for scheme: ${requirements.scheme} and network: ${requirements.network}`);
289
- }
290
- const partialPayload = await schemeNetworkClient.createPaymentPayload(
291
- paymentRequired.x402Version,
292
- requirements,
293
- { extensions: paymentRequired.extensions }
294
- );
295
- let paymentPayload;
296
- if (partialPayload.x402Version == 1) {
297
- paymentPayload = partialPayload;
298
- } else {
299
- const mergedExtensions = this.mergeExtensions(
300
- paymentRequired.extensions,
301
- partialPayload.extensions
302
- );
303
- paymentPayload = {
304
- x402Version: partialPayload.x402Version,
305
- payload: partialPayload.payload,
306
- extensions: mergedExtensions,
307
- resource: paymentRequired.resource,
308
- accepted: requirements
309
- };
310
- }
311
- paymentPayload = await this.enrichPaymentPayloadWithExtensions(paymentPayload, paymentRequired);
312
- const createdContext = {
313
- ...context,
314
- paymentPayload
315
- };
316
- for (const hook of this.getLabeledHooks(
317
- "afterPaymentCreation",
318
- paymentRequired.x402Version,
319
- requirements,
320
- paymentRequired.extensions
321
- )) {
322
- await hook(createdContext);
323
- }
324
- return paymentPayload;
325
- } catch (error) {
326
- const failureContext = {
327
- ...context,
328
- error
329
- };
330
- for (const hook of this.getLabeledHooks(
331
- "onPaymentCreationFailure",
332
- paymentRequired.x402Version,
333
- requirements,
334
- paymentRequired.extensions
335
- )) {
336
- const result = await hook(failureContext);
337
- if (result && "recovered" in result && result.recovered) {
338
- return result.payload;
339
- }
340
- }
341
- throw error;
342
- }
343
- }
344
- /**
345
- * Merges server-declared extensions with client extension echoes.
346
- * Client extension data may add fields, but server-declared fields remain intact.
347
- *
348
- * @param serverExtensions - Extensions declared by the server in the 402 response
349
- * @param clientExtensions - Extensions provided by the client or scheme
350
- * @returns The merged extensions object, or undefined if both inputs are undefined
351
- */
352
- mergeExtensions(serverExtensions, clientExtensions) {
353
- if (!clientExtensions) return serverExtensions;
354
- if (!serverExtensions) return clientExtensions;
355
- const merged = { ...serverExtensions };
356
- for (const [key, clientValue] of Object.entries(clientExtensions)) {
357
- const serverValue = merged[key];
358
- if (serverValue === null || typeof serverValue !== "object" || Array.isArray(serverValue) || clientValue === null || typeof clientValue !== "object" || Array.isArray(clientValue)) {
359
- merged[key] = clientValue;
360
- continue;
361
- }
362
- const serverRecord = serverValue;
363
- const clientRecord = clientValue;
364
- const extensionValue = { ...serverRecord };
365
- const pending = [{ target: extensionValue, source: clientRecord }];
366
- for (const item of pending) {
367
- for (const [fieldKey, clientFieldValue] of Object.entries(item.source)) {
368
- const serverFieldValue = item.target[fieldKey];
369
- if (serverFieldValue !== null && typeof serverFieldValue === "object" && !Array.isArray(serverFieldValue) && clientFieldValue !== null && typeof clientFieldValue === "object" && !Array.isArray(clientFieldValue)) {
370
- const nestedValue = { ...serverFieldValue };
371
- item.target[fieldKey] = nestedValue;
372
- pending.push({
373
- target: nestedValue,
374
- source: clientFieldValue
375
- });
376
- continue;
377
- }
378
- if (!Object.prototype.hasOwnProperty.call(item.target, fieldKey)) {
379
- item.target[fieldKey] = clientFieldValue;
380
- }
381
- }
382
- }
383
- merged[key] = extensionValue;
384
- }
385
- return merged;
386
- }
387
- /**
388
- * Enriches a payment payload by calling registered extension hooks.
389
- * For each extension key present in the PaymentRequired response,
390
- * invokes the corresponding extension's enrichPaymentPayload callback.
391
- *
392
- * @param paymentPayload - The payment payload to enrich with extension data
393
- * @param paymentRequired - The PaymentRequired response containing extension declarations
394
- * @returns The enriched payment payload with extension data applied
395
- */
396
- async enrichPaymentPayloadWithExtensions(paymentPayload, paymentRequired) {
397
- if (!paymentRequired.extensions || this.registeredExtensions.size === 0) {
398
- return paymentPayload;
399
- }
400
- let enriched = paymentPayload;
401
- for (const [key, extension] of this.registeredExtensions) {
402
- if (key in paymentRequired.extensions && extension.enrichPaymentPayload) {
403
- enriched = await extension.enrichPaymentPayload(enriched, paymentRequired);
404
- }
405
- }
406
- return {
407
- ...enriched,
408
- extensions: this.mergeExtensions(paymentRequired.extensions, enriched.extensions)
409
- };
410
- }
411
- /**
412
- * Selects appropriate payment requirements based on registered clients and policies.
413
- *
414
- * Selection process:
415
- * 1. Filter by registered schemes (network + scheme support)
416
- * 2. Apply all registered policies in order
417
- * 3. Use selector to choose final requirement
418
- *
419
- * @param x402Version - The x402 protocol version
420
- * @param paymentRequirements - Array of available payment requirements
421
- * @returns The selected payment requirements
422
- */
423
- selectPaymentRequirements(x402Version2, paymentRequirements) {
424
- const clientSchemesByNetwork = this.registeredClientSchemes.get(x402Version2);
425
- if (!clientSchemesByNetwork) {
426
- throw new Error(`No client registered for x402 version: ${x402Version2}`);
427
- }
428
- const supportedPaymentRequirements = paymentRequirements.filter((requirement) => {
429
- let clientSchemes = findSchemesByNetwork(clientSchemesByNetwork, requirement.network);
430
- if (!clientSchemes) {
431
- return false;
432
- }
433
- return clientSchemes.has(requirement.scheme);
434
- });
435
- if (supportedPaymentRequirements.length === 0) {
436
- throw new Error(`No network/scheme registered for x402 version: ${x402Version2} which comply with the payment requirements. ${JSON.stringify({
437
- x402Version: x402Version2,
438
- paymentRequirements,
439
- x402Versions: Array.from(this.registeredClientSchemes.keys()),
440
- networks: Array.from(clientSchemesByNetwork.keys()),
441
- schemes: Array.from(clientSchemesByNetwork.values()).map((schemes) => Array.from(schemes.keys())).flat()
442
- })}`);
443
- }
444
- let filteredRequirements = supportedPaymentRequirements;
445
- for (const policy of this.policies) {
446
- filteredRequirements = policy(x402Version2, filteredRequirements);
447
- if (filteredRequirements.length === 0) {
448
- throw new Error(`All payment requirements were filtered out by policies for x402 version: ${x402Version2}`);
449
- }
450
- }
451
- return this.paymentRequirementsSelector(x402Version2, filteredRequirements);
452
- }
453
- /**
454
- * Internal method to register a scheme client.
455
- *
456
- * @param x402Version - The x402 protocol version
457
- * @param network - The network to register the client for
458
- * @param client - The scheme network client to register
459
- * @returns The x402Client instance for chaining
460
- */
461
- _registerScheme(x402Version2, network, client) {
462
- if (!this.registeredClientSchemes.has(x402Version2)) {
463
- this.registeredClientSchemes.set(x402Version2, /* @__PURE__ */ new Map());
464
- }
465
- const clientSchemesByNetwork = this.registeredClientSchemes.get(x402Version2);
466
- if (!clientSchemesByNetwork.has(network)) {
467
- clientSchemesByNetwork.set(network, /* @__PURE__ */ new Map());
468
- }
469
- const clientByScheme = clientSchemesByNetwork.get(network);
470
- clientByScheme.set(client.scheme, client);
471
- if (!this.schemeClientHookAdapters.has(x402Version2)) {
472
- this.schemeClientHookAdapters.set(x402Version2, /* @__PURE__ */ new Map());
473
- }
474
- const adaptersByNetwork = this.schemeClientHookAdapters.get(x402Version2);
475
- if (!adaptersByNetwork.has(network)) {
476
- adaptersByNetwork.set(network, /* @__PURE__ */ new Map());
477
- }
478
- const adaptersByScheme = adaptersByNetwork.get(network);
479
- const hooks = client.schemeHooks;
480
- if (!hooks) {
481
- adaptersByScheme.delete(client.scheme);
482
- return this;
483
- }
484
- const handles = {};
485
- if (hooks.onBeforePaymentCreation) {
486
- handles.beforePaymentCreation = hooks.onBeforePaymentCreation;
487
- }
488
- if (hooks.onAfterPaymentCreation) {
489
- handles.afterPaymentCreation = hooks.onAfterPaymentCreation;
490
- }
491
- if (hooks.onPaymentCreationFailure) {
492
- handles.onPaymentCreationFailure = hooks.onPaymentCreationFailure;
493
- }
494
- if (hooks.onPaymentResponse) {
495
- handles.onPaymentResponse = hooks.onPaymentResponse;
496
- }
497
- if (Object.keys(handles).length > 0) {
498
- adaptersByScheme.set(client.scheme, handles);
499
- } else {
500
- adaptersByScheme.delete(client.scheme);
501
- }
502
- return this;
503
- }
504
- /**
505
- * Returns manual hooks followed by the selected scheme hook and declared extension hooks.
506
- *
507
- * @param phase - Hook slot to collect
508
- * @param x402Version - Protocol version for the selected requirement
509
- * @param requirements - Selected payment requirement
510
- * @param declaredExtensions - Extension declarations that scope extension hooks
511
- * @returns Hooks in invocation order
512
- */
513
- getLabeledHooks(phase, x402Version2, requirements, declaredExtensions) {
514
- let manual;
515
- switch (phase) {
516
- case "beforePaymentCreation":
517
- manual = this.beforePaymentCreationHooks;
518
- break;
519
- case "afterPaymentCreation":
520
- manual = this.afterPaymentCreationHooks;
521
- break;
522
- case "onPaymentCreationFailure":
523
- manual = this.onPaymentCreationFailureHooks;
524
- break;
525
- case "onPaymentResponse":
526
- manual = this.paymentResponseHooks;
527
- break;
528
- }
529
- const out = [...manual];
530
- const adaptersByNetwork = this.schemeClientHookAdapters.get(x402Version2);
531
- const schemeAdapter = adaptersByNetwork ? findByNetworkAndScheme(adaptersByNetwork, requirements.scheme, requirements.network) : void 0;
532
- const hook = schemeAdapter?.[phase];
533
- if (hook !== void 0) {
534
- out.push(hook);
535
- }
536
- if (!declaredExtensions) {
537
- return out;
538
- }
539
- const extensionHookKey = this.getClientExtensionHookKey(phase);
540
- for (const [extensionKey, extension] of this.registeredExtensions) {
541
- if (!(extensionKey in declaredExtensions)) continue;
542
- const extensionHook = extension.hooks?.[extensionHookKey];
543
- if (!extensionHook) continue;
544
- out.push((async (ctx) => {
545
- return extensionHook(declaredExtensions[extensionKey], ctx);
546
- }));
547
- }
548
- return out;
549
- }
550
- /**
551
- * Maps internal hook phases to extension hook names.
552
- *
553
- * @param phase - Internal hook phase
554
- * @returns Extension hook key for the phase
555
- */
556
- getClientExtensionHookKey(phase) {
557
- switch (phase) {
558
- case "beforePaymentCreation":
559
- return "onBeforePaymentCreation";
560
- case "afterPaymentCreation":
561
- return "onAfterPaymentCreation";
562
- case "onPaymentCreationFailure":
563
- return "onPaymentCreationFailure";
564
- case "onPaymentResponse":
565
- return "onPaymentResponse";
566
- }
567
- }
568
- };
569
-
570
- // node_modules/.pnpm/@x402+evm@2.17.0_typescript@6.0.3/node_modules/@x402/evm/dist/esm/chunk-MACPBXCT.mjs
571
- var authorizationTypes = {
572
- TransferWithAuthorization: [
573
- { name: "from", type: "address" },
574
- { name: "to", type: "address" },
575
- { name: "value", type: "uint256" },
576
- { name: "validAfter", type: "uint256" },
577
- { name: "validBefore", type: "uint256" },
578
- { name: "nonce", type: "bytes32" }
579
- ]
580
- };
581
- var permit2WitnessTypes = {
582
- PermitWitnessTransferFrom: [
583
- { name: "permitted", type: "TokenPermissions" },
584
- { name: "spender", type: "address" },
585
- { name: "nonce", type: "uint256" },
586
- { name: "deadline", type: "uint256" },
587
- { name: "witness", type: "Witness" }
588
- ],
589
- TokenPermissions: [
590
- { name: "token", type: "address" },
591
- { name: "amount", type: "uint256" }
592
- ],
593
- Witness: [
594
- { name: "to", type: "address" },
595
- { name: "validAfter", type: "uint256" }
596
- ]
597
- };
598
- var eip2612PermitTypes = {
599
- Permit: [
600
- { name: "owner", type: "address" },
601
- { name: "spender", type: "address" },
602
- { name: "value", type: "uint256" },
603
- { name: "nonce", type: "uint256" },
604
- { name: "deadline", type: "uint256" }
605
- ]
606
- };
607
- var eip2612NoncesAbi = [
608
- {
609
- type: "function",
610
- name: "nonces",
611
- inputs: [{ name: "owner", type: "address" }],
612
- outputs: [{ type: "uint256" }],
613
- stateMutability: "view"
614
- }
615
- ];
616
- var erc20ApproveAbi = [
617
- {
618
- type: "function",
619
- name: "approve",
620
- inputs: [
621
- { name: "spender", type: "address" },
622
- { name: "amount", type: "uint256" }
623
- ],
624
- outputs: [{ type: "bool" }],
625
- stateMutability: "nonpayable"
626
- }
627
- ];
628
- var erc20AllowanceAbi = [
629
- {
630
- type: "function",
631
- name: "allowance",
632
- inputs: [
633
- { name: "owner", type: "address" },
634
- { name: "spender", type: "address" }
635
- ],
636
- outputs: [{ type: "uint256" }],
637
- stateMutability: "view"
638
- }
639
- ];
640
- var ERC20_APPROVE_GAS_LIMIT = 70000n;
641
- var DEFAULT_MAX_FEE_PER_GAS = 1000000000n;
642
- var DEFAULT_MAX_PRIORITY_FEE_PER_GAS = 100000000n;
643
- var PERMIT2_ADDRESS = "0x000000000022D473030F116dDEE9F6B43aC78BA3";
644
- var x402ExactPermit2ProxyAddress = "0x402085c248EeA27D92E8b30b2C58ed07f9E20001";
645
-
646
- // node_modules/.pnpm/@x402+evm@2.17.0_typescript@6.0.3/node_modules/@x402/evm/dist/esm/chunk-7KTOBWB2.mjs
647
- var PAYMENT_INFO_TYPEHASH = keccak256(
648
- new TextEncoder().encode(
649
- "PaymentInfo(address operator,address payer,address receiver,address token,uint120 maxAmount,uint48 preApprovalExpiry,uint48 authorizationExpiry,uint48 refundExpiry,uint16 minFeeBps,uint16 maxFeeBps,address feeReceiver,uint256 salt)"
650
- )
651
- );
652
-
653
- // node_modules/.pnpm/@x402+evm@2.17.0_typescript@6.0.3/node_modules/@x402/evm/dist/esm/chunk-TW7Z65AO.mjs
654
- function getEvmChainId(network) {
655
- if (network.startsWith("eip155:")) {
656
- const idStr = network.split(":")[1];
657
- const chainId = parseInt(idStr, 10);
658
- if (isNaN(chainId)) {
659
- throw new Error(`Invalid CAIP-2 chain ID: ${network}`);
660
- }
661
- return chainId;
662
- }
663
- throw new Error(`Unsupported network format: ${network} (expected eip155:CHAIN_ID)`);
664
- }
665
- function getCrypto() {
666
- const cryptoObj = globalThis.crypto;
667
- if (!cryptoObj) {
668
- throw new Error("Crypto API not available");
669
- }
670
- return cryptoObj;
671
- }
672
- function createNonce() {
673
- return toHex(getCrypto().getRandomValues(new Uint8Array(32)));
674
- }
675
- function createPermit2Nonce() {
676
- const randomBytes = getCrypto().getRandomValues(new Uint8Array(32));
677
- return BigInt(toHex(randomBytes)).toString();
678
- }
679
-
680
- // node_modules/.pnpm/@x402+evm@2.17.0_typescript@6.0.3/node_modules/@x402/evm/dist/esm/chunk-BQS2RW2S.mjs
681
- var CHANNEL_CONFIG_TYPEHASH = keccak256(
682
- toBytes(
683
- "ChannelConfig(address payer,address payerAuthorizer,address receiver,address receiverAuthorizer,address token,uint40 withdrawDelay,bytes32 salt)"
684
- )
685
- );
686
-
687
- // node_modules/.pnpm/@x402+evm@2.17.0_typescript@6.0.3/node_modules/@x402/evm/dist/esm/chunk-27MWX225.mjs
688
- var EIP2612_GAS_SPONSORING_KEY = "eip2612GasSponsoring";
689
- var ERC20_APPROVAL_GAS_SPONSORING_KEY = "erc20ApprovalGasSponsoring";
690
- var ERC20_APPROVAL_GAS_SPONSORING_VERSION = "1";
691
- async function signEip2612Permit(signer, tokenAddress, tokenName, tokenVersion, chainId, deadline, permittedAmount) {
692
- const owner = signer.address;
693
- const spender = getAddress2(PERMIT2_ADDRESS);
694
- const nonce = await signer.readContract({
695
- address: tokenAddress,
696
- abi: eip2612NoncesAbi,
697
- functionName: "nonces",
698
- args: [owner]
699
- });
700
- const domain = {
701
- name: tokenName,
702
- version: tokenVersion,
703
- chainId,
704
- verifyingContract: tokenAddress
705
- };
706
- const approvalAmount = BigInt(permittedAmount);
707
- const message = {
708
- owner,
709
- spender,
710
- value: approvalAmount,
711
- nonce,
712
- deadline: BigInt(deadline)
713
- };
714
- const signature = await signer.signTypedData({
715
- domain,
716
- types: eip2612PermitTypes,
717
- primaryType: "Permit",
718
- message
719
- });
720
- return {
721
- from: owner,
722
- asset: tokenAddress,
723
- spender,
724
- amount: approvalAmount.toString(),
725
- nonce: nonce.toString(),
726
- deadline,
727
- signature,
728
- version: "1"
729
- };
730
- }
731
- async function signErc20ApprovalTransaction(signer, tokenAddress, chainId) {
732
- const from = signer.address;
733
- const spender = getAddress2(PERMIT2_ADDRESS);
734
- const data = encodeFunctionData({
735
- abi: erc20ApproveAbi,
736
- functionName: "approve",
737
- args: [spender, maxUint256]
738
- });
739
- const nonce = await signer.getTransactionCount({ address: from });
740
- let maxFeePerGas;
741
- let maxPriorityFeePerGas;
742
- try {
743
- const fees = await signer.estimateFeesPerGas?.();
744
- if (!fees) {
745
- throw new Error("no fee estimates available");
746
- }
747
- maxFeePerGas = fees.maxFeePerGas;
748
- maxPriorityFeePerGas = fees.maxPriorityFeePerGas;
749
- } catch {
750
- maxFeePerGas = DEFAULT_MAX_FEE_PER_GAS;
751
- maxPriorityFeePerGas = DEFAULT_MAX_PRIORITY_FEE_PER_GAS;
752
- }
753
- const signedTransaction = await signer.signTransaction({
754
- to: tokenAddress,
755
- data,
756
- nonce,
757
- gas: ERC20_APPROVE_GAS_LIMIT,
758
- maxFeePerGas,
759
- maxPriorityFeePerGas,
760
- chainId
761
- });
762
- return {
763
- from,
764
- asset: tokenAddress,
765
- spender,
766
- amount: maxUint256.toString(),
767
- signedTransaction,
768
- version: ERC20_APPROVAL_GAS_SPONSORING_VERSION
769
- };
770
- }
771
- var rpcClientCache = /* @__PURE__ */ new Map();
772
- function isConfigByChainId(options) {
773
- const keys = Object.keys(options);
774
- return keys.length > 0 && keys.every((key) => /^\d+$/.test(key));
775
- }
776
- function getRpcClient(rpcUrl) {
777
- const existing = rpcClientCache.get(rpcUrl);
778
- if (existing) {
779
- return existing;
780
- }
781
- const client = createPublicClient({
782
- transport: http(rpcUrl)
783
- });
784
- rpcClientCache.set(rpcUrl, client);
785
- return client;
786
- }
787
- function resolveRpcUrl(network, options) {
788
- if (!options) {
789
- return void 0;
790
- }
791
- if (isConfigByChainId(options)) {
792
- const chainId = getEvmChainId(network);
793
- const optionsByChainId = options;
794
- return optionsByChainId[chainId]?.rpcUrl;
795
- }
796
- return options.rpcUrl;
797
- }
798
- function resolveExtensionRpcCapabilities(network, signer, options) {
799
- const capabilities = {
800
- signTransaction: signer.signTransaction,
801
- readContract: signer.readContract,
802
- getTransactionCount: signer.getTransactionCount,
803
- estimateFeesPerGas: signer.estimateFeesPerGas
804
- };
805
- const needsRpcBackfill = !capabilities.readContract || !capabilities.getTransactionCount || !capabilities.estimateFeesPerGas;
806
- if (!needsRpcBackfill) {
807
- return capabilities;
808
- }
809
- const rpcUrl = resolveRpcUrl(network, options);
810
- if (!rpcUrl) {
811
- return capabilities;
812
- }
813
- const rpcClient = getRpcClient(rpcUrl);
814
- if (!capabilities.readContract) {
815
- capabilities.readContract = (args) => rpcClient.readContract(args);
816
- }
817
- if (!capabilities.getTransactionCount) {
818
- capabilities.getTransactionCount = async (args) => rpcClient.getTransactionCount({ address: args.address });
819
- }
820
- if (!capabilities.estimateFeesPerGas) {
821
- capabilities.estimateFeesPerGas = async () => rpcClient.estimateFeesPerGas();
822
- }
823
- return capabilities;
824
- }
825
- async function trySignEip2612PermitExtension(signer, options, requirements, result, context, approvalAmount) {
826
- const capabilities = resolveExtensionRpcCapabilities(requirements.network, signer, options);
827
- if (!capabilities.readContract) {
828
- return void 0;
829
- }
830
- if (!context?.extensions?.[EIP2612_GAS_SPONSORING_KEY]) {
831
- return void 0;
832
- }
833
- const tokenName = requirements.extra?.name;
834
- const tokenVersion = requirements.extra?.version;
835
- if (!tokenName || !tokenVersion) {
836
- return void 0;
837
- }
838
- const chainId = getEvmChainId(requirements.network);
839
- const tokenAddress = getAddress2(requirements.asset);
840
- const requiredAllowance = approvalAmount ?? requirements.amount;
841
- try {
842
- const allowance = await capabilities.readContract({
843
- address: tokenAddress,
844
- abi: erc20AllowanceAbi,
845
- functionName: "allowance",
846
- args: [signer.address, PERMIT2_ADDRESS]
847
- });
848
- if (allowance >= BigInt(requiredAllowance)) {
849
- return void 0;
850
- }
851
- } catch {
852
- }
853
- const permit2Auth = result.payload?.permit2Authorization;
854
- const deadline = permit2Auth?.deadline ?? Math.floor(Date.now() / 1e3 + requirements.maxTimeoutSeconds).toString();
855
- const info = await signEip2612Permit(
856
- {
857
- address: signer.address,
858
- signTypedData: (msg) => signer.signTypedData(msg),
859
- readContract: capabilities.readContract
860
- },
861
- tokenAddress,
862
- tokenName,
863
- tokenVersion,
864
- chainId,
865
- deadline,
866
- requiredAllowance
867
- );
868
- return {
869
- [EIP2612_GAS_SPONSORING_KEY]: { info }
870
- };
871
- }
872
- async function trySignErc20ApprovalExtension(signer, options, requirements, context, approvalAmount) {
873
- const capabilities = resolveExtensionRpcCapabilities(requirements.network, signer, options);
874
- if (!capabilities.readContract) {
875
- return void 0;
876
- }
877
- if (!context?.extensions?.[ERC20_APPROVAL_GAS_SPONSORING_KEY]) {
878
- return void 0;
879
- }
880
- if (!capabilities.signTransaction || !capabilities.getTransactionCount) {
881
- return void 0;
882
- }
883
- const chainId = getEvmChainId(requirements.network);
884
- const tokenAddress = getAddress2(requirements.asset);
885
- const requiredAllowance = approvalAmount ?? requirements.amount;
886
- try {
887
- const allowance = await capabilities.readContract({
888
- address: tokenAddress,
889
- abi: erc20AllowanceAbi,
890
- functionName: "allowance",
891
- args: [signer.address, PERMIT2_ADDRESS]
892
- });
893
- if (allowance >= BigInt(requiredAllowance)) {
894
- return void 0;
895
- }
896
- } catch {
897
- }
898
- const info = await signErc20ApprovalTransaction(
899
- {
900
- address: signer.address,
901
- signTransaction: capabilities.signTransaction,
902
- getTransactionCount: capabilities.getTransactionCount,
903
- estimateFeesPerGas: capabilities.estimateFeesPerGas
904
- },
905
- tokenAddress,
906
- chainId
907
- );
908
- return {
909
- [ERC20_APPROVAL_GAS_SPONSORING_KEY]: { info }
910
- };
911
- }
912
-
913
- // node_modules/.pnpm/@x402+evm@2.17.0_typescript@6.0.3/node_modules/@x402/evm/dist/esm/chunk-2GHXG5WB.mjs
914
- var EVM_NETWORK_CHAIN_ID_MAP = {
915
- ethereum: 1,
916
- sepolia: 11155111,
917
- abstract: 2741,
918
- "abstract-testnet": 11124,
919
- "base-sepolia": 84532,
920
- base: 8453,
921
- "avalanche-fuji": 43113,
922
- avalanche: 43114,
923
- iotex: 4689,
924
- sei: 1329,
925
- "sei-testnet": 1328,
926
- polygon: 137,
927
- "polygon-amoy": 80002,
928
- peaq: 3338,
929
- story: 1514,
930
- educhain: 41923,
931
- "skale-base-sepolia": 324705682,
932
- megaeth: 4326,
933
- monad: 143,
934
- stable: 988,
935
- "stable-testnet": 2201
936
- };
937
- var NETWORKS = Object.keys(EVM_NETWORK_CHAIN_ID_MAP);
938
-
939
- // node_modules/.pnpm/@x402+evm@2.17.0_typescript@6.0.3/node_modules/@x402/evm/dist/esm/chunk-4NBQRJBB.mjs
940
- async function createPermit2PayloadForProxy(proxyAddress, signer, x402Version2, paymentRequirements) {
941
- const now = Math.floor(Date.now() / 1e3);
942
- const nonce = createPermit2Nonce();
943
- const validAfter = "0";
944
- const deadline = (now + paymentRequirements.maxTimeoutSeconds).toString();
945
- const permit2Authorization = {
946
- from: signer.address,
947
- permitted: {
948
- token: getAddress2(paymentRequirements.asset),
949
- amount: paymentRequirements.amount
950
- },
951
- spender: proxyAddress,
952
- nonce,
953
- deadline,
954
- witness: {
955
- to: getAddress2(paymentRequirements.payTo),
956
- validAfter
957
- }
958
- };
959
- const signature = await signPermit2Authorization(
960
- signer,
961
- permit2Authorization,
962
- paymentRequirements
963
- );
964
- return {
965
- x402Version: x402Version2,
966
- payload: { signature, permit2Authorization }
967
- };
968
- }
969
- async function signPermit2Authorization(signer, permit2Authorization, requirements) {
970
- const chainId = getEvmChainId(requirements.network);
971
- return await signer.signTypedData({
972
- domain: { name: "Permit2", chainId, verifyingContract: PERMIT2_ADDRESS },
973
- types: permit2WitnessTypes,
974
- primaryType: "PermitWitnessTransferFrom",
975
- message: {
976
- permitted: {
977
- token: getAddress2(permit2Authorization.permitted.token),
978
- amount: BigInt(permit2Authorization.permitted.amount)
979
- },
980
- spender: getAddress2(permit2Authorization.spender),
981
- nonce: BigInt(permit2Authorization.nonce),
982
- deadline: BigInt(permit2Authorization.deadline),
983
- witness: {
984
- to: getAddress2(permit2Authorization.witness.to),
985
- validAfter: BigInt(permit2Authorization.witness.validAfter)
986
- }
987
- }
988
- });
989
- }
990
-
991
- // node_modules/.pnpm/@x402+evm@2.17.0_typescript@6.0.3/node_modules/@x402/evm/dist/esm/chunk-UUEZJ3RH.mjs
992
- var MAX_UINT256 = BigInt("0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
993
- async function createPermit2Payload(signer, x402Version2, paymentRequirements) {
994
- return createPermit2PayloadForProxy(
995
- x402ExactPermit2ProxyAddress,
996
- signer,
997
- x402Version2,
998
- paymentRequirements
999
- );
1000
- }
1001
-
1002
- // node_modules/.pnpm/@x402+evm@2.17.0_typescript@6.0.3/node_modules/@x402/evm/dist/esm/chunk-VFVBY5MG.mjs
1003
- async function createEIP3009Payload(signer, x402Version2, paymentRequirements) {
1004
- const nonce = createNonce();
1005
- const now = Math.floor(Date.now() / 1e3);
1006
- const authorization = {
1007
- from: signer.address,
1008
- to: getAddress2(paymentRequirements.payTo),
1009
- value: paymentRequirements.amount,
1010
- validAfter: "0",
1011
- validBefore: (now + paymentRequirements.maxTimeoutSeconds).toString(),
1012
- nonce
1013
- };
1014
- const signature = await signEIP3009Authorization(signer, authorization, paymentRequirements);
1015
- const payload = {
1016
- authorization,
1017
- signature
1018
- };
1019
- return {
1020
- x402Version: x402Version2,
1021
- payload
1022
- };
1023
- }
1024
- async function signEIP3009Authorization(signer, authorization, requirements) {
1025
- const chainId = getEvmChainId(requirements.network);
1026
- if (!requirements.extra?.name || !requirements.extra?.version) {
1027
- throw new Error(
1028
- `EIP-712 domain parameters (name, version) are required in payment requirements for asset ${requirements.asset}`
1029
- );
1030
- }
1031
- const { name, version } = requirements.extra;
1032
- const domain = {
1033
- name,
1034
- version,
1035
- chainId,
1036
- verifyingContract: getAddress2(requirements.asset)
1037
- };
1038
- const message = {
1039
- from: getAddress2(authorization.from),
1040
- to: getAddress2(authorization.to),
1041
- value: BigInt(authorization.value),
1042
- validAfter: BigInt(authorization.validAfter),
1043
- validBefore: BigInt(authorization.validBefore),
1044
- nonce: authorization.nonce
1045
- };
1046
- return await signer.signTypedData({
1047
- domain,
1048
- types: authorizationTypes,
1049
- primaryType: "TransferWithAuthorization",
1050
- message
1051
- });
1052
- }
1053
- var ExactEvmScheme = class {
1054
- /**
1055
- * Creates a new ExactEvmClient instance.
1056
- *
1057
- * @param signer - The EVM signer for client operations.
1058
- * Base flow only requires `address` + `signTypedData`.
1059
- * Extension enrichment (EIP-2612 / ERC-20 approval sponsoring) additionally
1060
- * requires optional capabilities like `readContract` and tx signing helpers.
1061
- * @param options - Optional RPC configuration used to backfill extension capabilities.
1062
- */
1063
- constructor(signer, options) {
1064
- this.signer = signer;
1065
- this.options = options;
1066
- this.scheme = "exact";
1067
- }
1068
- /**
1069
- * Creates a payment payload for the Exact scheme.
1070
- * Routes to EIP-3009 or Permit2 based on requirements.extra.assetTransferMethod.
1071
- *
1072
- * For Permit2 flows, if the server advertises `eip2612GasSponsoring` and the
1073
- * signer supports `readContract`, automatically signs an EIP-2612 permit
1074
- * when Permit2 allowance is insufficient.
1075
- *
1076
- * @param x402Version - The x402 protocol version
1077
- * @param paymentRequirements - The payment requirements
1078
- * @param context - Optional context with server-declared extensions
1079
- * @returns Promise resolving to a payment payload result (with optional extensions)
1080
- */
1081
- async createPaymentPayload(x402Version2, paymentRequirements, context) {
1082
- const assetTransferMethod = paymentRequirements.extra?.assetTransferMethod ?? "eip3009";
1083
- if (assetTransferMethod === "permit2") {
1084
- const result = await createPermit2Payload(this.signer, x402Version2, paymentRequirements);
1085
- const eip2612Extensions = await trySignEip2612PermitExtension(
1086
- this.signer,
1087
- this.options,
1088
- paymentRequirements,
1089
- result,
1090
- context
1091
- );
1092
- if (eip2612Extensions) {
1093
- return {
1094
- ...result,
1095
- extensions: eip2612Extensions
1096
- };
1097
- }
1098
- const erc20Extensions = await trySignErc20ApprovalExtension(
1099
- this.signer,
1100
- this.options,
1101
- paymentRequirements,
1102
- context
1103
- );
1104
- if (erc20Extensions) {
1105
- return {
1106
- ...result,
1107
- extensions: erc20Extensions
1108
- };
1109
- }
1110
- return result;
1111
- }
1112
- return createEIP3009Payload(this.signer, x402Version2, paymentRequirements);
1113
- }
1114
- };
1115
-
1116
- // src/lib/x402-pay.ts
1117
- function toClientSigner(signer) {
1118
- return {
1119
- address: signer.address,
1120
- signTypedData: (message) => signer.signTypedData(message)
1121
- };
1122
- }
1123
- var ALLOWED_USDC_BY_NETWORK = {
1124
- "eip155:8453": USDC_ADDRESS,
1125
- "eip155:84532": "0x036CbD53842c5426634e7929541eC2318f3dCF7e"
1126
- };
1127
- async function buildExactPayment(paymentRequired, signer) {
1128
- const requirement = paymentRequired.accepts[0];
1129
- if (requirement === void 0) {
1130
- throw new CliError("PAYMENT_FAILED", "The 402 advertised no payment requirements.", {
1131
- fix: "The resource may be misconfigured; try another candidate."
1132
- });
1133
- }
1134
- if (requirement.scheme !== "exact") {
1135
- throw new CliError("PAYMENT_FAILED", `Unsupported payment scheme "${requirement.scheme}".`, {
1136
- fix: "This CLI pays the x402 exact scheme only."
1137
- });
1138
- }
1139
- const allowedAsset = ALLOWED_USDC_BY_NETWORK[requirement.network];
1140
- if (allowedAsset === void 0) {
1141
- throw new CliError(
1142
- "PAYMENT_FAILED",
1143
- `The 402 names a chain this CLI will not pay on: ${requirement.network}.`,
1144
- {
1145
- fix: "Only USDC on Base (eip155:8453) or Base Sepolia previews (eip155:84532) is supported."
1146
- }
1147
- );
1148
- }
1149
- let assetChecksummed;
1150
- try {
1151
- assetChecksummed = getAddress(requirement.asset);
1152
- } catch {
1153
- throw new CliError(
1154
- "PAYMENT_FAILED",
1155
- `The 402 names an invalid asset address: ${JSON.stringify(requirement.asset)}.`
1156
- );
1157
- }
1158
- if (assetChecksummed !== getAddress(allowedAsset)) {
1159
- throw new CliError(
1160
- "PAYMENT_FAILED",
1161
- `The 402 names an asset this CLI will not pay: ${assetChecksummed} on ${requirement.network}.`,
1162
- {
1163
- fix: "Only canonical USDC is supported; the resource or server looks misconfigured or hostile."
1164
- }
1165
- );
1166
- }
1167
- const core = new x402Client();
1168
- core.register(requirement.network, new ExactEvmScheme(toClientSigner(signer)));
1169
- const http2 = new x402HTTPClient(core);
1170
- const bound = { ...paymentRequired, accepts: [requirement] };
1171
- let headers;
1172
- try {
1173
- const payload = await http2.createPaymentPayload(bound);
1174
- headers = http2.encodePaymentSignatureHeader(payload);
1175
- } catch (err) {
1176
- throw new CliError("PAYMENT_FAILED", "Could not build the x402 payment authorization.", {
1177
- fix: "Confirm the wallet is a supported EVM account on the advertised network.",
1178
- cause: err
1179
- });
1180
- }
1181
- return { headers, amountAtomic: BigInt(requirement.amount) };
1182
- }
1183
-
1184
- export {
1185
- gateSpend,
1186
- buildExactPayment
1187
- };
1188
- //# sourceMappingURL=chunk-2RF2GIJQ.js.map