mppx 0.0.1 → 0.1.1

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 (446) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +195 -0
  3. package/dist/BodyDigest.d.ts +42 -0
  4. package/dist/BodyDigest.d.ts.map +1 -0
  5. package/dist/BodyDigest.js +40 -0
  6. package/dist/BodyDigest.js.map +1 -0
  7. package/dist/Challenge.d.ts +271 -0
  8. package/dist/Challenge.d.ts.map +1 -0
  9. package/dist/Challenge.js +291 -0
  10. package/dist/Challenge.js.map +1 -0
  11. package/dist/Credential.d.ts +91 -0
  12. package/dist/Credential.d.ts.map +1 -0
  13. package/dist/Credential.js +122 -0
  14. package/dist/Credential.js.map +1 -0
  15. package/dist/Errors.d.ts +243 -0
  16. package/dist/Errors.d.ts.map +1 -0
  17. package/dist/Errors.js +201 -0
  18. package/dist/Errors.js.map +1 -0
  19. package/dist/Expires.d.ts +15 -0
  20. package/dist/Expires.d.ts.map +1 -0
  21. package/dist/Expires.js +29 -0
  22. package/dist/Expires.js.map +1 -0
  23. package/dist/Intent.d.ts +101 -0
  24. package/dist/Intent.d.ts.map +1 -0
  25. package/dist/Intent.js +83 -0
  26. package/dist/Intent.js.map +1 -0
  27. package/dist/Mcp.d.ts +74 -0
  28. package/dist/Mcp.d.ts.map +1 -0
  29. package/dist/Mcp.js +9 -0
  30. package/dist/Mcp.js.map +1 -0
  31. package/dist/MethodIntent.d.ts +225 -0
  32. package/dist/MethodIntent.d.ts.map +1 -0
  33. package/dist/MethodIntent.js +156 -0
  34. package/dist/MethodIntent.js.map +1 -0
  35. package/dist/PaymentRequest.d.ts +88 -0
  36. package/dist/PaymentRequest.d.ts.map +1 -0
  37. package/dist/PaymentRequest.js +81 -0
  38. package/dist/PaymentRequest.js.map +1 -0
  39. package/dist/Receipt.d.ts +110 -0
  40. package/dist/Receipt.d.ts.map +1 -0
  41. package/dist/Receipt.js +105 -0
  42. package/dist/Receipt.js.map +1 -0
  43. package/dist/Store.d.ts +28 -0
  44. package/dist/Store.d.ts.map +1 -0
  45. package/dist/Store.js +61 -0
  46. package/dist/Store.js.map +1 -0
  47. package/dist/cli.d.ts +3 -0
  48. package/dist/cli.d.ts.map +1 -0
  49. package/dist/cli.js +1219 -0
  50. package/dist/cli.js.map +1 -0
  51. package/dist/client/Methods.d.ts +4 -0
  52. package/dist/client/Methods.d.ts.map +1 -0
  53. package/dist/client/Methods.js +4 -0
  54. package/dist/client/Methods.js.map +1 -0
  55. package/dist/client/Mppx.d.ts +89 -0
  56. package/dist/client/Mppx.d.ts.map +1 -0
  57. package/dist/client/Mppx.js +69 -0
  58. package/dist/client/Mppx.js.map +1 -0
  59. package/dist/client/Transport.d.ts +56 -0
  60. package/dist/client/Transport.d.ts.map +1 -0
  61. package/dist/client/Transport.js +81 -0
  62. package/dist/client/Transport.js.map +1 -0
  63. package/dist/client/index.d.ts +5 -0
  64. package/dist/client/index.d.ts.map +1 -0
  65. package/dist/client/index.js +5 -0
  66. package/dist/client/index.js.map +1 -0
  67. package/dist/client/internal/Fetch.d.ts +87 -0
  68. package/dist/client/internal/Fetch.d.ts.map +1 -0
  69. package/dist/client/internal/Fetch.js +99 -0
  70. package/dist/client/internal/Fetch.js.map +1 -0
  71. package/dist/index.d.ts +13 -0
  72. package/dist/index.d.ts.map +1 -0
  73. package/dist/index.js +13 -0
  74. package/dist/index.js.map +1 -0
  75. package/dist/internal/types.d.ts +302 -0
  76. package/dist/internal/types.d.ts.map +1 -0
  77. package/dist/internal/types.js +2 -0
  78. package/dist/internal/types.js.map +1 -0
  79. package/dist/mcp-sdk/client/McpClient.d.ts +78 -0
  80. package/dist/mcp-sdk/client/McpClient.d.ts.map +1 -0
  81. package/dist/mcp-sdk/client/McpClient.js +98 -0
  82. package/dist/mcp-sdk/client/McpClient.js.map +1 -0
  83. package/dist/mcp-sdk/client/index.d.ts +3 -0
  84. package/dist/mcp-sdk/client/index.d.ts.map +1 -0
  85. package/dist/mcp-sdk/client/index.js +3 -0
  86. package/dist/mcp-sdk/client/index.js.map +1 -0
  87. package/dist/mcp-sdk/server/Transport.d.ts +43 -0
  88. package/dist/mcp-sdk/server/Transport.d.ts.map +1 -0
  89. package/dist/mcp-sdk/server/Transport.js +71 -0
  90. package/dist/mcp-sdk/server/Transport.js.map +1 -0
  91. package/dist/mcp-sdk/server/index.d.ts +2 -0
  92. package/dist/mcp-sdk/server/index.d.ts.map +1 -0
  93. package/dist/mcp-sdk/server/index.js +2 -0
  94. package/dist/mcp-sdk/server/index.js.map +1 -0
  95. package/dist/middlewares/elysia.d.ts +51 -0
  96. package/dist/middlewares/elysia.d.ts.map +1 -0
  97. package/dist/middlewares/elysia.js +59 -0
  98. package/dist/middlewares/elysia.js.map +1 -0
  99. package/dist/middlewares/express.d.ts +46 -0
  100. package/dist/middlewares/express.d.ts.map +1 -0
  101. package/dist/middlewares/express.js +69 -0
  102. package/dist/middlewares/express.js.map +1 -0
  103. package/dist/middlewares/hono.d.ts +46 -0
  104. package/dist/middlewares/hono.d.ts.map +1 -0
  105. package/dist/middlewares/hono.js +57 -0
  106. package/dist/middlewares/hono.js.map +1 -0
  107. package/dist/middlewares/internal/mppx.d.ts +16 -0
  108. package/dist/middlewares/internal/mppx.d.ts.map +1 -0
  109. package/dist/middlewares/internal/mppx.js +16 -0
  110. package/dist/middlewares/internal/mppx.js.map +1 -0
  111. package/dist/middlewares/nextjs.d.ts +45 -0
  112. package/dist/middlewares/nextjs.d.ts.map +1 -0
  113. package/dist/middlewares/nextjs.js +57 -0
  114. package/dist/middlewares/nextjs.js.map +1 -0
  115. package/dist/proxy/Proxy.d.ts +47 -0
  116. package/dist/proxy/Proxy.d.ts.map +1 -0
  117. package/dist/proxy/Proxy.js +126 -0
  118. package/dist/proxy/Proxy.js.map +1 -0
  119. package/dist/proxy/Service.d.ts +100 -0
  120. package/dist/proxy/Service.d.ts.map +1 -0
  121. package/dist/proxy/Service.js +147 -0
  122. package/dist/proxy/Service.js.map +1 -0
  123. package/dist/proxy/index.d.ts +7 -0
  124. package/dist/proxy/index.d.ts.map +1 -0
  125. package/dist/proxy/index.js +7 -0
  126. package/dist/proxy/index.js.map +1 -0
  127. package/dist/proxy/internal/Headers.d.ts +3 -0
  128. package/dist/proxy/internal/Headers.d.ts.map +1 -0
  129. package/dist/proxy/internal/Headers.js +41 -0
  130. package/dist/proxy/internal/Headers.js.map +1 -0
  131. package/dist/proxy/internal/Route.d.ts +14 -0
  132. package/dist/proxy/internal/Route.d.ts.map +1 -0
  133. package/dist/proxy/internal/Route.js +47 -0
  134. package/dist/proxy/internal/Route.js.map +1 -0
  135. package/dist/proxy/services/anthropic.d.ts +29 -0
  136. package/dist/proxy/services/anthropic.d.ts.map +1 -0
  137. package/dist/proxy/services/anthropic.js +30 -0
  138. package/dist/proxy/services/anthropic.js.map +1 -0
  139. package/dist/proxy/services/openai.d.ts +29 -0
  140. package/dist/proxy/services/openai.d.ts.map +1 -0
  141. package/dist/proxy/services/openai.js +30 -0
  142. package/dist/proxy/services/openai.js.map +1 -0
  143. package/dist/proxy/services/stripe.d.ts +29 -0
  144. package/dist/proxy/services/stripe.d.ts.map +1 -0
  145. package/dist/proxy/services/stripe.js +30 -0
  146. package/dist/proxy/services/stripe.js.map +1 -0
  147. package/dist/server/Methods.d.ts +3 -0
  148. package/dist/server/Methods.d.ts.map +1 -0
  149. package/dist/server/Methods.js +3 -0
  150. package/dist/server/Methods.js.map +1 -0
  151. package/dist/server/Mppx.d.ts +116 -0
  152. package/dist/server/Mppx.d.ts.map +1 -0
  153. package/dist/server/Mppx.js +207 -0
  154. package/dist/server/Mppx.js.map +1 -0
  155. package/dist/server/NodeListener.d.ts +3 -0
  156. package/dist/server/NodeListener.d.ts.map +1 -0
  157. package/dist/server/NodeListener.js +3 -0
  158. package/dist/server/NodeListener.js.map +1 -0
  159. package/dist/server/Request.d.ts +24 -0
  160. package/dist/server/Request.d.ts.map +1 -0
  161. package/dist/server/Request.js +26 -0
  162. package/dist/server/Request.js.map +1 -0
  163. package/dist/server/Response.d.ts +10 -0
  164. package/dist/server/Response.d.ts.map +1 -0
  165. package/dist/server/Response.js +15 -0
  166. package/dist/server/Response.js.map +1 -0
  167. package/dist/server/Transport.d.ts +93 -0
  168. package/dist/server/Transport.d.ts.map +1 -0
  169. package/dist/server/Transport.js +132 -0
  170. package/dist/server/Transport.js.map +1 -0
  171. package/dist/server/index.d.ts +9 -0
  172. package/dist/server/index.d.ts.map +1 -0
  173. package/dist/server/index.js +9 -0
  174. package/dist/server/index.js.map +1 -0
  175. package/dist/stripe/Intents.d.ts +54 -0
  176. package/dist/stripe/Intents.d.ts.map +1 -0
  177. package/dist/stripe/Intents.js +27 -0
  178. package/dist/stripe/Intents.js.map +1 -0
  179. package/dist/stripe/client/Charge.d.ts +105 -0
  180. package/dist/stripe/client/Charge.d.ts.map +1 -0
  181. package/dist/stripe/client/Charge.js +74 -0
  182. package/dist/stripe/client/Charge.js.map +1 -0
  183. package/dist/stripe/client/MethodIntents.d.ts +80 -0
  184. package/dist/stripe/client/MethodIntents.d.ts.map +1 -0
  185. package/dist/stripe/client/MethodIntents.js +34 -0
  186. package/dist/stripe/client/MethodIntents.js.map +1 -0
  187. package/dist/stripe/client/index.d.ts +3 -0
  188. package/dist/stripe/client/index.d.ts.map +1 -0
  189. package/dist/stripe/client/index.js +3 -0
  190. package/dist/stripe/client/index.js.map +1 -0
  191. package/dist/stripe/index.d.ts +2 -0
  192. package/dist/stripe/index.d.ts.map +1 -0
  193. package/dist/stripe/index.js +2 -0
  194. package/dist/stripe/index.js.map +1 -0
  195. package/dist/stripe/server/Charge.d.ts +74 -0
  196. package/dist/stripe/server/Charge.d.ts.map +1 -0
  197. package/dist/stripe/server/Charge.js +79 -0
  198. package/dist/stripe/server/Charge.js.map +1 -0
  199. package/dist/stripe/server/MethodIntents.d.ts +65 -0
  200. package/dist/stripe/server/MethodIntents.d.ts.map +1 -0
  201. package/dist/stripe/server/MethodIntents.js +21 -0
  202. package/dist/stripe/server/MethodIntents.js.map +1 -0
  203. package/dist/stripe/server/index.d.ts +3 -0
  204. package/dist/stripe/server/index.d.ts.map +1 -0
  205. package/dist/stripe/server/index.js +3 -0
  206. package/dist/stripe/server/index.js.map +1 -0
  207. package/dist/tempo/Attribution.d.ts +101 -0
  208. package/dist/tempo/Attribution.d.ts.map +1 -0
  209. package/dist/tempo/Attribution.js +124 -0
  210. package/dist/tempo/Attribution.js.map +1 -0
  211. package/dist/tempo/Intents.d.ts +132 -0
  212. package/dist/tempo/Intents.d.ts.map +1 -0
  213. package/dist/tempo/Intents.js +81 -0
  214. package/dist/tempo/Intents.js.map +1 -0
  215. package/dist/tempo/client/ChannelOps.d.ts +54 -0
  216. package/dist/tempo/client/ChannelOps.d.ts.map +1 -0
  217. package/dist/tempo/client/ChannelOps.js +138 -0
  218. package/dist/tempo/client/ChannelOps.js.map +1 -0
  219. package/dist/tempo/client/Charge.d.ts +76 -0
  220. package/dist/tempo/client/Charge.d.ts.map +1 -0
  221. package/dist/tempo/client/Charge.js +69 -0
  222. package/dist/tempo/client/Charge.js.map +1 -0
  223. package/dist/tempo/client/MethodIntents.d.ts +157 -0
  224. package/dist/tempo/client/MethodIntents.d.ts.map +1 -0
  225. package/dist/tempo/client/MethodIntents.js +25 -0
  226. package/dist/tempo/client/MethodIntents.js.map +1 -0
  227. package/dist/tempo/client/Session.d.ts +159 -0
  228. package/dist/tempo/client/Session.d.ts.map +1 -0
  229. package/dist/tempo/client/Session.js +263 -0
  230. package/dist/tempo/client/Session.js.map +1 -0
  231. package/dist/tempo/client/SessionManager.d.ts +62 -0
  232. package/dist/tempo/client/SessionManager.d.ts.map +1 -0
  233. package/dist/tempo/client/SessionManager.js +201 -0
  234. package/dist/tempo/client/SessionManager.js.map +1 -0
  235. package/dist/tempo/client/index.d.ts +6 -0
  236. package/dist/tempo/client/index.d.ts.map +1 -0
  237. package/dist/tempo/client/index.js +5 -0
  238. package/dist/tempo/client/index.js.map +1 -0
  239. package/dist/tempo/index.d.ts +3 -0
  240. package/dist/tempo/index.d.ts.map +1 -0
  241. package/dist/tempo/index.js +3 -0
  242. package/dist/tempo/index.js.map +1 -0
  243. package/dist/tempo/internal/account.d.ts +32 -0
  244. package/dist/tempo/internal/account.d.ts.map +1 -0
  245. package/dist/tempo/internal/account.js +33 -0
  246. package/dist/tempo/internal/account.js.map +1 -0
  247. package/dist/tempo/internal/defaults.d.ts +18 -0
  248. package/dist/tempo/internal/defaults.d.ts.map +1 -0
  249. package/dist/tempo/internal/defaults.js +18 -0
  250. package/dist/tempo/internal/defaults.js.map +1 -0
  251. package/dist/tempo/internal/types.d.ts +11 -0
  252. package/dist/tempo/internal/types.d.ts.map +1 -0
  253. package/dist/tempo/internal/types.js +2 -0
  254. package/dist/tempo/internal/types.js.map +1 -0
  255. package/dist/tempo/server/Charge.d.ts +77 -0
  256. package/dist/tempo/server/Charge.d.ts.map +1 -0
  257. package/dist/tempo/server/Charge.js +228 -0
  258. package/dist/tempo/server/Charge.js.map +1 -0
  259. package/dist/tempo/server/MethodIntents.d.ts +140 -0
  260. package/dist/tempo/server/MethodIntents.d.ts.map +1 -0
  261. package/dist/tempo/server/MethodIntents.js +26 -0
  262. package/dist/tempo/server/MethodIntents.js.map +1 -0
  263. package/dist/tempo/server/Session.d.ts +148 -0
  264. package/dist/tempo/server/Session.d.ts.map +1 -0
  265. package/dist/tempo/server/Session.js +529 -0
  266. package/dist/tempo/server/Session.js.map +1 -0
  267. package/dist/tempo/server/internal/transport.d.ts +47 -0
  268. package/dist/tempo/server/internal/transport.d.ts.map +1 -0
  269. package/dist/tempo/server/internal/transport.js +119 -0
  270. package/dist/tempo/server/internal/transport.js.map +1 -0
  271. package/dist/tempo/stream/Chain.d.ts +52 -0
  272. package/dist/tempo/stream/Chain.d.ts.map +1 -0
  273. package/dist/tempo/stream/Chain.js +215 -0
  274. package/dist/tempo/stream/Chain.js.map +1 -0
  275. package/dist/tempo/stream/Channel.d.ts +26 -0
  276. package/dist/tempo/stream/Channel.d.ts.map +1 -0
  277. package/dist/tempo/stream/Channel.js +27 -0
  278. package/dist/tempo/stream/Channel.js.map +1 -0
  279. package/dist/tempo/stream/ChannelStore.d.ts +103 -0
  280. package/dist/tempo/stream/ChannelStore.d.ts.map +1 -0
  281. package/dist/tempo/stream/ChannelStore.js +100 -0
  282. package/dist/tempo/stream/ChannelStore.js.map +1 -0
  283. package/dist/tempo/stream/Receipt.d.ts +22 -0
  284. package/dist/tempo/stream/Receipt.d.ts.map +1 -0
  285. package/dist/tempo/stream/Receipt.js +34 -0
  286. package/dist/tempo/stream/Receipt.js.map +1 -0
  287. package/dist/tempo/stream/Sse.d.ts +134 -0
  288. package/dist/tempo/stream/Sse.d.ts.map +1 -0
  289. package/dist/tempo/stream/Sse.js +288 -0
  290. package/dist/tempo/stream/Sse.js.map +1 -0
  291. package/dist/tempo/stream/Types.d.ts +78 -0
  292. package/dist/tempo/stream/Types.d.ts.map +1 -0
  293. package/dist/tempo/stream/Types.js +2 -0
  294. package/dist/tempo/stream/Types.js.map +1 -0
  295. package/dist/tempo/stream/Voucher.d.ts +20 -0
  296. package/dist/tempo/stream/Voucher.d.ts.map +1 -0
  297. package/dist/tempo/stream/Voucher.js +98 -0
  298. package/dist/tempo/stream/Voucher.js.map +1 -0
  299. package/dist/tempo/stream/escrow.abi.d.ts +598 -0
  300. package/dist/tempo/stream/escrow.abi.d.ts.map +1 -0
  301. package/dist/tempo/stream/escrow.abi.js +760 -0
  302. package/dist/tempo/stream/escrow.abi.js.map +1 -0
  303. package/dist/tempo/stream/index.d.ts +8 -0
  304. package/dist/tempo/stream/index.d.ts.map +1 -0
  305. package/dist/tempo/stream/index.js +8 -0
  306. package/dist/tempo/stream/index.js.map +1 -0
  307. package/dist/viem/Account.d.ts +12 -0
  308. package/dist/viem/Account.d.ts.map +1 -0
  309. package/dist/viem/Account.js +14 -0
  310. package/dist/viem/Account.js.map +1 -0
  311. package/dist/viem/Client.d.ts +21 -0
  312. package/dist/viem/Client.d.ts.map +1 -0
  313. package/dist/viem/Client.js +19 -0
  314. package/dist/viem/Client.js.map +1 -0
  315. package/dist/zod.d.ts +17 -0
  316. package/dist/zod.d.ts.map +1 -0
  317. package/dist/zod.js +35 -0
  318. package/dist/zod.js.map +1 -0
  319. package/package.json +117 -4
  320. package/src/BodyDigest.test.ts +43 -0
  321. package/src/BodyDigest.ts +53 -0
  322. package/src/Challenge.test-d.ts +81 -0
  323. package/src/Challenge.test.ts +414 -0
  324. package/src/Challenge.ts +429 -0
  325. package/src/Credential.test.ts +227 -0
  326. package/src/Credential.ts +154 -0
  327. package/src/Errors.test.ts +402 -0
  328. package/src/Errors.ts +348 -0
  329. package/src/Expires.ts +34 -0
  330. package/src/Intent.test.ts +180 -0
  331. package/src/Intent.ts +109 -0
  332. package/src/Mcp.ts +81 -0
  333. package/src/MethodIntent.test.ts +303 -0
  334. package/src/MethodIntent.ts +388 -0
  335. package/src/PaymentRequest.test.ts +152 -0
  336. package/src/PaymentRequest.ts +107 -0
  337. package/src/Receipt.test.ts +98 -0
  338. package/src/Receipt.ts +129 -0
  339. package/src/Store.ts +84 -0
  340. package/src/cli.test.ts +542 -0
  341. package/src/cli.ts +1319 -0
  342. package/src/client/Methods.ts +3 -0
  343. package/src/client/Mppx.test-d.ts +90 -0
  344. package/src/client/Mppx.test.ts +468 -0
  345. package/src/client/Mppx.ts +165 -0
  346. package/src/client/Transport.test.ts +283 -0
  347. package/src/client/Transport.ts +115 -0
  348. package/src/client/index.ts +4 -0
  349. package/src/client/internal/Fetch.test-d.ts +57 -0
  350. package/src/client/internal/Fetch.test.ts +315 -0
  351. package/src/client/internal/Fetch.ts +169 -0
  352. package/src/env.d.ts +11 -0
  353. package/src/index.ts +12 -0
  354. package/src/internal/types.ts +403 -0
  355. package/src/mcp-sdk/client/McpClient.test-d.ts +109 -0
  356. package/src/mcp-sdk/client/McpClient.test.ts +219 -0
  357. package/src/mcp-sdk/client/McpClient.ts +187 -0
  358. package/src/mcp-sdk/client/index.ts +2 -0
  359. package/src/mcp-sdk/server/Transport.ts +94 -0
  360. package/src/mcp-sdk/server/index.ts +1 -0
  361. package/src/middlewares/elysia.ts +66 -0
  362. package/src/middlewares/express.test.ts +155 -0
  363. package/src/middlewares/express.ts +82 -0
  364. package/src/middlewares/hono.test.ts +148 -0
  365. package/src/middlewares/hono.ts +62 -0
  366. package/src/middlewares/internal/mppx.ts +30 -0
  367. package/src/middlewares/nextjs.test.ts +164 -0
  368. package/src/middlewares/nextjs.ts +66 -0
  369. package/src/proxy/Proxy.test.ts +472 -0
  370. package/src/proxy/Proxy.ts +175 -0
  371. package/src/proxy/Service.test.ts +125 -0
  372. package/src/proxy/Service.ts +227 -0
  373. package/src/proxy/index.ts +6 -0
  374. package/src/proxy/internal/Headers.test.ts +100 -0
  375. package/src/proxy/internal/Headers.ts +40 -0
  376. package/src/proxy/internal/Route.test.ts +143 -0
  377. package/src/proxy/internal/Route.ts +54 -0
  378. package/src/proxy/services/anthropic.ts +45 -0
  379. package/src/proxy/services/openai.test.ts +97 -0
  380. package/src/proxy/services/openai.ts +48 -0
  381. package/src/proxy/services/stripe.ts +49 -0
  382. package/src/server/Methods.ts +2 -0
  383. package/src/server/Mppx.test-d.ts +343 -0
  384. package/src/server/Mppx.test.ts +342 -0
  385. package/src/server/Mppx.ts +378 -0
  386. package/src/server/NodeListener.test.ts +188 -0
  387. package/src/server/NodeListener.ts +3 -0
  388. package/src/server/Request.test.ts +102 -0
  389. package/src/server/Request.ts +33 -0
  390. package/src/server/Response.test.ts +31 -0
  391. package/src/server/Response.ts +27 -0
  392. package/src/server/Transport.test.ts +294 -0
  393. package/src/server/Transport.ts +222 -0
  394. package/src/server/index.ts +8 -0
  395. package/src/stripe/Charge.integration.test.ts +329 -0
  396. package/src/stripe/Intents.test.ts +52 -0
  397. package/src/stripe/Intents.ts +27 -0
  398. package/src/stripe/client/Charge.ts +115 -0
  399. package/src/stripe/client/MethodIntents.ts +37 -0
  400. package/src/stripe/client/index.ts +2 -0
  401. package/src/stripe/index.ts +1 -0
  402. package/src/stripe/server/Charge.ts +121 -0
  403. package/src/stripe/server/MethodIntents.ts +24 -0
  404. package/src/stripe/server/index.ts +2 -0
  405. package/src/tempo/Attribution.test.ts +187 -0
  406. package/src/tempo/Attribution.ts +156 -0
  407. package/src/tempo/Intents.test.ts +84 -0
  408. package/src/tempo/Intents.ts +93 -0
  409. package/src/tempo/client/ChannelOps.ts +233 -0
  410. package/src/tempo/client/Charge.ts +84 -0
  411. package/src/tempo/client/MethodIntents.ts +28 -0
  412. package/src/tempo/client/Session.ts +369 -0
  413. package/src/tempo/client/SessionManager.test.ts +223 -0
  414. package/src/tempo/client/SessionManager.ts +276 -0
  415. package/src/tempo/client/index.ts +5 -0
  416. package/src/tempo/index.ts +2 -0
  417. package/src/tempo/internal/account.ts +47 -0
  418. package/src/tempo/internal/defaults.ts +20 -0
  419. package/src/tempo/internal/types.ts +8 -0
  420. package/src/tempo/server/Charge.test.ts +847 -0
  421. package/src/tempo/server/Charge.ts +309 -0
  422. package/src/tempo/server/MethodIntents.ts +29 -0
  423. package/src/tempo/server/Session.test.ts +1349 -0
  424. package/src/tempo/server/Session.ts +773 -0
  425. package/src/tempo/server/Sse.test.ts +289 -0
  426. package/src/tempo/server/index.ts +5 -0
  427. package/src/tempo/server/internal/transport.ts +154 -0
  428. package/src/tempo/stream/Chain.ts +333 -0
  429. package/src/tempo/stream/Channel.ts +50 -0
  430. package/src/tempo/stream/ChannelStore.test.ts +473 -0
  431. package/src/tempo/stream/ChannelStore.ts +202 -0
  432. package/src/tempo/stream/Receipt.test.ts +84 -0
  433. package/src/tempo/stream/Receipt.ts +45 -0
  434. package/src/tempo/stream/Sse.test.ts +401 -0
  435. package/src/tempo/stream/Sse.ts +375 -0
  436. package/src/tempo/stream/Types.ts +86 -0
  437. package/src/tempo/stream/Voucher.test.ts +134 -0
  438. package/src/tempo/stream/Voucher.ts +123 -0
  439. package/src/tempo/stream/escrow.abi.ts +759 -0
  440. package/src/tempo/stream/index.ts +7 -0
  441. package/src/tsconfig.json +10 -0
  442. package/src/viem/Account.test.ts +71 -0
  443. package/src/viem/Account.ts +30 -0
  444. package/src/viem/Client.test.ts +58 -0
  445. package/src/viem/Client.ts +33 -0
  446. package/src/zod.ts +47 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026-present weth, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,195 @@
1
+ # mppx
2
+
3
+ TypeScript SDK for the [**Machine Payments Protocol**](https://machinepayments.dev)
4
+
5
+ [![npm](https://img.shields.io/npm/v/mppx.svg)](https://www.npmjs.com/package/mppx)
6
+ [![License](https://img.shields.io/npm/l/mppx.svg)](LICENSE)
7
+
8
+ ## Documentation
9
+
10
+ Full documentation, API reference, and guides are available at **[machinepayments.dev/sdk/typescript](https://machinepayments.dev/sdk/typescript)**.
11
+
12
+ ## Install
13
+
14
+ ```bash
15
+ npm i mppx
16
+ ```
17
+
18
+ ## Quick Start
19
+
20
+ ### Server
21
+
22
+ ```ts
23
+ import { Mppx, tempo } from 'mppx/server'
24
+
25
+ const mppx = Mppx.create({
26
+ methods: [
27
+ tempo({
28
+ currency: '0x20c0000000000000000000000000000000000000',
29
+ recipient: '0x742d35Cc6634c0532925a3b844bC9e7595F8fE00',
30
+ }),
31
+ ],
32
+ })
33
+
34
+ export async function handler(request: Request) {
35
+ const response = await mppx.charge({ amount: '1' })(request)
36
+
37
+ if (response.status === 402) return response.challenge
38
+
39
+ return response.withReceipt(Response.json({ data: '...' }))
40
+ }
41
+ ```
42
+
43
+ ### Client
44
+
45
+ ```ts
46
+ import { privateKeyToAccount } from 'viem/accounts'
47
+ import { Mppx, tempo } from 'mppx/client'
48
+
49
+ Mppx.create({
50
+ methods: [tempo({ account: privateKeyToAccount('0x...') })],
51
+ })
52
+
53
+ // Global fetch now handles 402 automatically
54
+ const res = await fetch('https://api.example.com/resource')
55
+ ```
56
+
57
+ ## Examples
58
+
59
+ | Example | Description |
60
+ |---------|-------------|
61
+ | [basic](./examples/basic/) | Payment-gated Fortune Teller API |
62
+ | [session/multi-fetch](./examples/session/multi-fetch/) | Multiple paid requests over a single payment channel |
63
+ | [session/sse](./examples/session/sse/) | Pay-per-token LLM streaming with SSE |
64
+
65
+ ```bash
66
+ npx gitpick wevm/mppx/examples/basic
67
+ ```
68
+
69
+ ## CLI
70
+
71
+ `mppx` includes a basic CLI for making HTTP requests with automatic payment handling.
72
+
73
+ ```bash
74
+ # create account - stored in keychain, autofunded on testnet
75
+ mppx account create
76
+
77
+ # make request - automatic payment handling, curl-like api
78
+ mppx example.com
79
+ ```
80
+
81
+ <details>
82
+ <summary><code>mppx --help</code></summary>
83
+
84
+ ```
85
+ mppx/0.1.0
86
+
87
+ Usage:
88
+ $ mppx [url]
89
+
90
+ Commands:
91
+ [url] Make HTTP request with automatic payment
92
+ account [action] Manage accounts (create, default, delete, fund, list, view)
93
+
94
+ For more info, run any command with the `--help` flag:
95
+ $ mppx --help
96
+ $ mppx account --help
97
+
98
+ Actions:
99
+ create Create new account
100
+ default Set default account
101
+ delete Delete account
102
+ fund Fund account with testnet tokens
103
+ list List all accounts
104
+ view View account address
105
+
106
+ Options:
107
+ -a, --account <name> Account name (env: MPPX_ACCOUNT)
108
+ -d, --data <data> Send request body (implies POST unless -X is set)
109
+ -f, --fail Fail silently on HTTP errors (exit 22)
110
+ -i, --include Include response headers in output
111
+ -k, --insecure Skip TLS certificate verification (true for localhost/.local)
112
+ -r, --rpc-url <url> RPC endpoint, defaults to public RPC for chain (env: MPPX_RPC_URL)
113
+ -s, --silent Silent mode (suppress progress and info)
114
+ -v, --verbose Show request/response headers
115
+ -A, --user-agent <ua> Set User-Agent header
116
+ -H, --header <header> Add header (repeatable)
117
+ -L, --location Follow redirects
118
+ -X, --method <method> HTTP method
119
+ --channel <id> Reuse existing stream channel ID
120
+ --deposit <amount> Deposit amount for stream payments (human-readable units)
121
+ --json <json> Send JSON body (sets Content-Type and Accept, implies POST)
122
+ --yes Skip confirmation prompts
123
+ -V, --version Display version number
124
+ -h, --help Display this message
125
+
126
+ Examples:
127
+ mppx example.com/content
128
+ mppx example.com/api --json '{"key":"value"}'
129
+ ```
130
+
131
+ </details>
132
+
133
+ You can also install globally to use the `mppx` CLI from anywhere:
134
+
135
+ ```bash
136
+ npm i -g mppx
137
+ ```
138
+
139
+ ## Payments Proxy
140
+
141
+ `mppx` exports a `Proxy` server handler so that you can create or define a 402-protected payments proxy for any API.
142
+
143
+ ```ts
144
+ import { openai, stripe, Proxy } from 'mppx/proxy'
145
+ import { Mppx, tempo } from 'mppx/server'
146
+
147
+ const mppx = Mppx.create({ methods: [tempo()] })
148
+
149
+ const proxy = Proxy.create({
150
+ services: [
151
+ openai({
152
+ apiKey: 'sk-...',
153
+ routes: {
154
+ 'POST /v1/chat/completions': mppx.charge({ amount: '0.05' }),
155
+ 'POST /v1/completions': mppx.stream({ amount: '0.0001' }),
156
+ 'GET /v1/models': mppx.free(),
157
+ },
158
+ }),
159
+ stripe({
160
+ apiKey: 'sk-...',
161
+ routes: {
162
+ 'POST /v1/charges': mppx.charge({ amount: '0.01' }),
163
+ 'GET /v1/customers/:id': mppx.free(),
164
+ },
165
+ }),
166
+ ],
167
+ })
168
+
169
+ createServer(proxy.listener) // Node.js
170
+ Bun.serve(proxy) // Bun
171
+ Deno.serve(proxy.fetch) // Deno
172
+ app.use(proxy.listener) // Express
173
+ app.all('*', (c) => proxy.fetch(c.req.raw)) // Hono
174
+ app.all('*', (c) => proxy.fetch(c.request)) // Elysia
175
+ export const GET = proxy.fetch // Next.js
176
+ export const POST = proxy.fetch // Next.js
177
+ ```
178
+
179
+ This exposes the following routes:
180
+
181
+ | Route | Pricing |
182
+ |-------|---------|
183
+ | `POST /openai/v1/chat/completions` | charge **$0.005** |
184
+ | `POST /openai/v1/completions` | stream **$0.0001 per token** |
185
+ | `GET /openai/v1/models` | free |
186
+ | `POST /stripe/v1/charges` | charge **$0.01** |
187
+ | `GET /stripe/v1/customers/:id` | free |
188
+
189
+ ## Protocol
190
+
191
+ Built on the ["Payment" HTTP Authentication Scheme](https://datatracker.ietf.org/doc/draft-ietf-httpauth-payment/). See [payment-auth-spec](https://github.com/tempoxyz/payment-auth-spec) for the full specification.
192
+
193
+ ## License
194
+
195
+ MIT
@@ -0,0 +1,42 @@
1
+ /**
2
+ * A body digest string in the format "algorithm=base64hash".
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { BodyDigest } from 'mppx'
7
+ *
8
+ * const digest: BodyDigest.BodyDigest = 'sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE'
9
+ * ```
10
+ */
11
+ export type BodyDigest = `sha-256=${string}`;
12
+ /**
13
+ * Computes a SHA-256 digest of the given body.
14
+ *
15
+ * @param body - The body to digest (string or object).
16
+ * @returns A digest string in the format "sha-256=base64hash".
17
+ *
18
+ * @example
19
+ * ```ts
20
+ * import { BodyDigest } from 'mppx'
21
+ *
22
+ * const digest = BodyDigest.compute({ amount: '1000' })
23
+ * // => 'sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE'
24
+ * ```
25
+ */
26
+ export declare function compute(body: Record<string, unknown> | string): BodyDigest;
27
+ /**
28
+ * Verifies that a digest matches the given body.
29
+ *
30
+ * @param digest - The digest to verify.
31
+ * @param body - The body to verify against.
32
+ * @returns True if the digest matches, false otherwise.
33
+ *
34
+ * @example
35
+ * ```ts
36
+ * import { BodyDigest } from 'mppx'
37
+ *
38
+ * const isValid = BodyDigest.verify(digest, '{"amount":"1000"}')
39
+ * ```
40
+ */
41
+ export declare function verify(digest: BodyDigest, body: Record<string, unknown> | string): boolean;
42
+ //# sourceMappingURL=BodyDigest.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BodyDigest.d.ts","sourceRoot":"","sources":["../src/BodyDigest.ts"],"names":[],"mappings":"AAEA;;;;;;;;;GASG;AACH,MAAM,MAAM,UAAU,GAAG,WAAW,MAAM,EAAE,CAAA;AAE5C;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,UAAU,CAM1E;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,MAAM,CAAC,MAAM,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,GAAG,OAAO,CAE1F"}
@@ -0,0 +1,40 @@
1
+ import { Base64, Bytes, Hash } from 'ox';
2
+ /**
3
+ * Computes a SHA-256 digest of the given body.
4
+ *
5
+ * @param body - The body to digest (string or object).
6
+ * @returns A digest string in the format "sha-256=base64hash".
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { BodyDigest } from 'mppx'
11
+ *
12
+ * const digest = BodyDigest.compute({ amount: '1000' })
13
+ * // => 'sha-256=X48E9qOokqqrvdts8nOJRJN3OWDUoyWxBf7kbu9DBPE'
14
+ * ```
15
+ */
16
+ export function compute(body) {
17
+ const str = typeof body === 'object' ? JSON.stringify(body) : body;
18
+ const bytes = Bytes.fromString(str);
19
+ const hash = Hash.sha256(bytes, { as: 'Bytes' });
20
+ const base64 = Base64.fromBytes(hash);
21
+ return `sha-256=${base64}`;
22
+ }
23
+ /**
24
+ * Verifies that a digest matches the given body.
25
+ *
26
+ * @param digest - The digest to verify.
27
+ * @param body - The body to verify against.
28
+ * @returns True if the digest matches, false otherwise.
29
+ *
30
+ * @example
31
+ * ```ts
32
+ * import { BodyDigest } from 'mppx'
33
+ *
34
+ * const isValid = BodyDigest.verify(digest, '{"amount":"1000"}')
35
+ * ```
36
+ */
37
+ export function verify(digest, body) {
38
+ return compute(body) === digest;
39
+ }
40
+ //# sourceMappingURL=BodyDigest.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"BodyDigest.js","sourceRoot":"","sources":["../src/BodyDigest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,MAAM,IAAI,CAAA;AAcxC;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,OAAO,CAAC,IAAsC;IAC5D,MAAM,GAAG,GAAG,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAClE,MAAM,KAAK,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAA;IACnC,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE,OAAO,EAAE,CAAC,CAAA;IAChD,MAAM,MAAM,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,CAAA;IACrC,OAAO,WAAW,MAAM,EAAE,CAAA;AAC5B,CAAC;AAED;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,MAAM,CAAC,MAAkB,EAAE,IAAsC;IAC/E,OAAO,OAAO,CAAC,IAAI,CAAC,KAAK,MAAM,CAAA;AACjC,CAAC"}
@@ -0,0 +1,271 @@
1
+ import type { OneOf } from './internal/types.js';
2
+ import type * as MethodIntent from './MethodIntent.js';
3
+ import * as PaymentRequest from './PaymentRequest.js';
4
+ import * as z from './zod.js';
5
+ /**
6
+ * Schema for a payment challenge.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { Challenge } from 'mppx'
11
+ *
12
+ * const challenge = Challenge.Schema.parse(data)
13
+ * ```
14
+ */
15
+ export declare const Schema: z.ZodMiniObject<{
16
+ /** Optional human-readable description of the payment. */
17
+ description: z.ZodMiniOptional<z.ZodMiniString<string>>;
18
+ /** Optional digest of the request body (format: "sha-256=base64hash"). */
19
+ digest: z.ZodMiniOptional<z.ZodMiniString<string>>;
20
+ /** Optional expiration timestamp (ISO 8601). */
21
+ expires: z.ZodMiniOptional<z.ZodMiniString<string>>;
22
+ /** Unique challenge identifier (HMAC-bound). */
23
+ id: z.ZodMiniString<string>;
24
+ /** Intent type (e.g., "charge", "session"). */
25
+ intent: z.ZodMiniString<string>;
26
+ /** Payment method (e.g., "tempo", "stripe"). */
27
+ method: z.ZodMiniString<string>;
28
+ /** Server realm (e.g., hostname). */
29
+ realm: z.ZodMiniString<string>;
30
+ /** Method-specific request data. */
31
+ request: z.ZodMiniRecord<z.ZodMiniString<string>, z.ZodMiniUnknown>;
32
+ }, z.core.$strip>;
33
+ /**
34
+ * A parsed payment challenge from a `WWW-Authenticate` header.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { Challenge } from 'mppx'
39
+ *
40
+ * const challenge: Challenge.Challenge = {
41
+ * id: 'abc123',
42
+ * realm: 'api.example.com',
43
+ * method: 'tempo',
44
+ * intent: 'charge',
45
+ * request: { amount: '1000000', currency: '0x...', recipient: '0x...' },
46
+ * }
47
+ * ```
48
+ */
49
+ export type Challenge<request = Record<string, unknown>, intent extends string = string, method extends string = string> = Omit<z.infer<typeof Schema>, 'intent' | 'method' | 'request'> & {
50
+ intent: intent;
51
+ method: method;
52
+ request: request;
53
+ };
54
+ /**
55
+ * Extracts a union of challenge types from an array of method intents.
56
+ */
57
+ export type FromMethods<methods extends readonly MethodIntent.AnyMethodIntent[]> = {
58
+ [method in keyof methods]: Challenge<z.output<methods[method]['schema']['request']>, methods[method]['name'], methods[method]['method']>;
59
+ }[number];
60
+ /**
61
+ * Creates a challenge from the given parameters.
62
+ *
63
+ * If `secretKey` option is provided, the challenge ID is computed as HMAC-SHA256
64
+ * over the challenge parameters (realm|method|intent|request|expires|digest),
65
+ * cryptographically binding the ID to its contents.
66
+ *
67
+ * @param parameters - Challenge parameters.
68
+ * @param options - Optional settings including secretKey for HMAC-bound ID.
69
+ * @returns A challenge.
70
+ *
71
+ * @example
72
+ * ```ts
73
+ * import { Challenge } from 'mppx'
74
+ *
75
+ * // With HMAC-bound ID (recommended for servers)
76
+ * const challenge = Challenge.from(
77
+ * {
78
+ * realm: 'api.example.com',
79
+ * method: 'tempo',
80
+ * intent: 'charge',
81
+ * request: { amount: '1000000', currency: '0x...', recipient: '0x...' },
82
+ * },
83
+ * { secretKey: 'my-secret' },
84
+ * )
85
+ *
86
+ * // With explicit ID
87
+ * const challenge = Challenge.from({
88
+ * id: 'abc123',
89
+ * realm: 'api.example.com',
90
+ * method: 'tempo',
91
+ * intent: 'charge',
92
+ * request: { amount: '1000000', currency: '0x...', recipient: '0x...' },
93
+ * })
94
+ * ```
95
+ */
96
+ export declare function from<const parameters extends from.Parameters, const methods extends readonly MethodIntent.AnyMethodIntent[] | undefined = undefined>(parameters: parameters, options?: from.Options<methods>): from.ReturnType<parameters, methods>;
97
+ export declare namespace from {
98
+ type Options<methods extends readonly MethodIntent.AnyMethodIntent[] | undefined = undefined> = {
99
+ methods?: methods;
100
+ };
101
+ type Parameters = OneOf<{
102
+ /** Explicit challenge ID. */
103
+ id: string;
104
+ } | {
105
+ /** Secret key for HMAC-bound challenge ID. */
106
+ secretKey: string;
107
+ }> & {
108
+ /** Optional human-readable description of the payment. */
109
+ description?: string | undefined;
110
+ /** Optional digest of the request body. */
111
+ digest?: string | undefined;
112
+ /** Optional expiration timestamp (ISO 8601). */
113
+ expires?: string | undefined;
114
+ /** Intent type (e.g., "charge", "session"). */
115
+ intent: string;
116
+ /** Payment method (e.g., "tempo", "stripe"). */
117
+ method: string;
118
+ /** Server realm (e.g., hostname). */
119
+ realm: string;
120
+ /** Method-specific request data. */
121
+ request: PaymentRequest.Request;
122
+ };
123
+ type ReturnType<parameters extends Parameters, methods extends readonly MethodIntent.AnyMethodIntent[] | undefined = undefined> = methods extends readonly MethodIntent.AnyMethodIntent[] ? FromMethods<methods> : Challenge<parameters['request']>;
124
+ }
125
+ /**
126
+ * Creates a validated challenge from a method intent.
127
+ *
128
+ * If `secretKey` option is provided, the challenge ID is computed as HMAC-SHA256
129
+ * over the challenge parameters, cryptographically binding the ID to its contents.
130
+ *
131
+ * @param intent - The method intent to validate against.
132
+ * @param parameters - Challenge parameters (realm, request, optional expires/digest, and id if no secretKey).
133
+ * @param options - Optional settings including secretKey for HMAC-bound ID.
134
+ * @returns A validated challenge.
135
+ *
136
+ * @example
137
+ * ```ts
138
+ * import { Challenge } from 'mppx'
139
+ * import { Intents } from 'mppx/tempo'
140
+ *
141
+ * // With HMAC-bound ID (recommended for servers)
142
+ * const challenge = Challenge.fromIntent(
143
+ * Intents.charge,
144
+ * {
145
+ * realm: 'api.example.com',
146
+ * request: {
147
+ * amount: '1000000',
148
+ * currency: '0x20c0000000000000000000000000000000000001',
149
+ * recipient: '0x742d35Cc6634C0532925a3b844Bc9e7595f8fE00',
150
+ * expires: '2025-01-06T12:00:00Z',
151
+ * },
152
+ * },
153
+ * { secretKey: 'my-secret' },
154
+ * )
155
+ * ```
156
+ */
157
+ export declare function fromIntent<const intent extends MethodIntent.MethodIntent>(intent: intent, parameters: fromIntent.Parameters<intent>): fromIntent.ReturnType<intent>;
158
+ export declare namespace fromIntent {
159
+ type Parameters<intent extends MethodIntent.MethodIntent> = OneOf<{
160
+ /** Explicit challenge ID. */
161
+ id: string;
162
+ } | {
163
+ /** Secret key for HMAC-bound challenge ID. */
164
+ secretKey: string;
165
+ }> & {
166
+ /** Optional human-readable description of the payment. */
167
+ description?: string | undefined;
168
+ /** Optional digest of the request body. */
169
+ digest?: string | undefined;
170
+ /** Optional expiration timestamp (ISO 8601). */
171
+ expires?: string | undefined;
172
+ /** Server realm (e.g., hostname). */
173
+ realm: string;
174
+ /** Method-specific request data. */
175
+ request: z.input<intent['schema']['request']>;
176
+ };
177
+ type ReturnType<intent extends MethodIntent.MethodIntent> = Challenge<z.output<intent['schema']['request']>>;
178
+ }
179
+ /**
180
+ * Serializes a challenge to the WWW-Authenticate header format.
181
+ *
182
+ * @param challenge - The challenge to serialize.
183
+ * @returns A string suitable for the WWW-Authenticate header value.
184
+ *
185
+ * @example
186
+ * ```ts
187
+ * import { Challenge } from 'mppx'
188
+ *
189
+ * const header = Challenge.serialize(challenge)
190
+ * // => 'Payment id="abc123", realm="api.example.com", method="tempo", intent="charge", request="eyJhbW91bnQiOi..."'
191
+ * ```
192
+ */
193
+ export declare function serialize(challenge: Challenge): string;
194
+ /**
195
+ * Deserializes a WWW-Authenticate header value to a challenge.
196
+ *
197
+ * @example
198
+ * ```ts
199
+ * import { Challenge } from 'mppx'
200
+ *
201
+ * const challenge = Challenge.deserialize(header)
202
+ *
203
+ * // With methods for type narrowing
204
+ * const challenge = Challenge.deserialize(header, { methods })
205
+ * ```
206
+ *
207
+ * @param header - The WWW-Authenticate header value.
208
+ * @param options - Optional settings to narrow the challenge type.
209
+ * @returns The deserialized challenge.
210
+ */
211
+ export declare function deserialize<const methods extends readonly MethodIntent.AnyMethodIntent[] | undefined = undefined>(value: string, options?: from.Options<methods>): from.ReturnType<from.Parameters, methods>;
212
+ /**
213
+ * Extracts the challenge from a Headers object.
214
+ *
215
+ * @param headers - The HTTP headers.
216
+ * @param options - Optional settings to narrow the challenge type.
217
+ * @returns The deserialized challenge.
218
+ *
219
+ * @example
220
+ * ```ts
221
+ * import { Challenge } from 'mppx'
222
+ *
223
+ * const challenge = Challenge.fromHeaders(response.headers)
224
+ *
225
+ * // With methods for type narrowing
226
+ * const challenge = Challenge.fromHeaders(response.headers, { methods })
227
+ * ```
228
+ */
229
+ export declare function fromHeaders<const methods extends readonly MethodIntent.AnyMethodIntent[] | undefined = undefined>(headers: Headers, options?: from.Options<methods>): from.ReturnType<from.Parameters, methods>;
230
+ /**
231
+ * Extracts the challenge from a Response's WWW-Authenticate header.
232
+ *
233
+ * @param response - The HTTP response (must be 402 status).
234
+ * @param options - Optional settings to narrow the challenge type.
235
+ * @returns The deserialized challenge.
236
+ *
237
+ * @example
238
+ * ```ts
239
+ * import { Challenge } from 'mppx'
240
+ *
241
+ * const response = await fetch('/resource')
242
+ * if (response.status === 402)
243
+ * const challenge = Challenge.fromResponse(response)
244
+ *
245
+ * // With methods for type narrowing
246
+ * const challenge = Challenge.fromResponse(response, { methods })
247
+ * ```
248
+ */
249
+ export declare function fromResponse<const methods extends readonly MethodIntent.AnyMethodIntent[] | undefined = undefined>(response: Response, options?: from.Options<methods>): from.ReturnType<from.Parameters, methods>;
250
+ /**
251
+ * Verifies that a challenge ID matches the expected HMAC for the given parameters.
252
+ *
253
+ * @param challenge - The challenge to verify.
254
+ * @param options - Options including the secret key.
255
+ * @returns True if the challenge ID is valid, false otherwise.
256
+ *
257
+ * @example
258
+ * ```ts
259
+ * import { Challenge } from 'mppx'
260
+ *
261
+ * const isValid = Challenge.verify(challenge, { secretKey: 'my-secret' })
262
+ * ```
263
+ */
264
+ export declare function verify(challenge: Challenge, options: verify.Options): boolean;
265
+ export declare namespace verify {
266
+ type Options = {
267
+ /** Secret key for HMAC-bound challenge ID verification. */
268
+ secretKey: string;
269
+ };
270
+ }
271
+ //# sourceMappingURL=Challenge.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Challenge.d.ts","source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