mppx 0.0.1 → 0.1.0
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.
- package/LICENSE +21 -0
- package/README.md +195 -0
- package/dist/BodyDigest.d.ts +42 -0
- package/dist/BodyDigest.d.ts.map +1 -0
- package/dist/BodyDigest.js +40 -0
- package/dist/BodyDigest.js.map +1 -0
- package/dist/Challenge.d.ts +271 -0
- package/dist/Challenge.d.ts.map +1 -0
- package/dist/Challenge.js +291 -0
- package/dist/Challenge.js.map +1 -0
- package/dist/Credential.d.ts +91 -0
- package/dist/Credential.d.ts.map +1 -0
- package/dist/Credential.js +122 -0
- package/dist/Credential.js.map +1 -0
- package/dist/Errors.d.ts +243 -0
- package/dist/Errors.d.ts.map +1 -0
- package/dist/Errors.js +201 -0
- package/dist/Errors.js.map +1 -0
- package/dist/Expires.d.ts +15 -0
- package/dist/Expires.d.ts.map +1 -0
- package/dist/Expires.js +29 -0
- package/dist/Expires.js.map +1 -0
- package/dist/Intent.d.ts +101 -0
- package/dist/Intent.d.ts.map +1 -0
- package/dist/Intent.js +83 -0
- package/dist/Intent.js.map +1 -0
- package/dist/Mcp.d.ts +74 -0
- package/dist/Mcp.d.ts.map +1 -0
- package/dist/Mcp.js +9 -0
- package/dist/Mcp.js.map +1 -0
- package/dist/MethodIntent.d.ts +225 -0
- package/dist/MethodIntent.d.ts.map +1 -0
- package/dist/MethodIntent.js +156 -0
- package/dist/MethodIntent.js.map +1 -0
- package/dist/PaymentRequest.d.ts +88 -0
- package/dist/PaymentRequest.d.ts.map +1 -0
- package/dist/PaymentRequest.js +81 -0
- package/dist/PaymentRequest.js.map +1 -0
- package/dist/Receipt.d.ts +110 -0
- package/dist/Receipt.d.ts.map +1 -0
- package/dist/Receipt.js +105 -0
- package/dist/Receipt.js.map +1 -0
- package/dist/Store.d.ts +28 -0
- package/dist/Store.d.ts.map +1 -0
- package/dist/Store.js +61 -0
- package/dist/Store.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +1219 -0
- package/dist/cli.js.map +1 -0
- package/dist/client/Methods.d.ts +4 -0
- package/dist/client/Methods.d.ts.map +1 -0
- package/dist/client/Methods.js +4 -0
- package/dist/client/Methods.js.map +1 -0
- package/dist/client/Mppx.d.ts +84 -0
- package/dist/client/Mppx.d.ts.map +1 -0
- package/dist/client/Mppx.js +64 -0
- package/dist/client/Mppx.js.map +1 -0
- package/dist/client/Transport.d.ts +56 -0
- package/dist/client/Transport.d.ts.map +1 -0
- package/dist/client/Transport.js +81 -0
- package/dist/client/Transport.js.map +1 -0
- package/dist/client/index.d.ts +5 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +5 -0
- package/dist/client/index.js.map +1 -0
- package/dist/client/internal/Fetch.d.ts +85 -0
- package/dist/client/internal/Fetch.d.ts.map +1 -0
- package/dist/client/internal/Fetch.js +95 -0
- package/dist/client/internal/Fetch.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/types.d.ts +302 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +2 -0
- package/dist/internal/types.js.map +1 -0
- package/dist/mcp-sdk/client/McpClient.d.ts +78 -0
- package/dist/mcp-sdk/client/McpClient.d.ts.map +1 -0
- package/dist/mcp-sdk/client/McpClient.js +98 -0
- package/dist/mcp-sdk/client/McpClient.js.map +1 -0
- package/dist/mcp-sdk/client/index.d.ts +3 -0
- package/dist/mcp-sdk/client/index.d.ts.map +1 -0
- package/dist/mcp-sdk/client/index.js +3 -0
- package/dist/mcp-sdk/client/index.js.map +1 -0
- package/dist/mcp-sdk/server/Transport.d.ts +43 -0
- package/dist/mcp-sdk/server/Transport.d.ts.map +1 -0
- package/dist/mcp-sdk/server/Transport.js +71 -0
- package/dist/mcp-sdk/server/Transport.js.map +1 -0
- package/dist/mcp-sdk/server/index.d.ts +2 -0
- package/dist/mcp-sdk/server/index.d.ts.map +1 -0
- package/dist/mcp-sdk/server/index.js +2 -0
- package/dist/mcp-sdk/server/index.js.map +1 -0
- package/dist/middlewares/elysia.d.ts +51 -0
- package/dist/middlewares/elysia.d.ts.map +1 -0
- package/dist/middlewares/elysia.js +59 -0
- package/dist/middlewares/elysia.js.map +1 -0
- package/dist/middlewares/express.d.ts +46 -0
- package/dist/middlewares/express.d.ts.map +1 -0
- package/dist/middlewares/express.js +69 -0
- package/dist/middlewares/express.js.map +1 -0
- package/dist/middlewares/hono.d.ts +46 -0
- package/dist/middlewares/hono.d.ts.map +1 -0
- package/dist/middlewares/hono.js +57 -0
- package/dist/middlewares/hono.js.map +1 -0
- package/dist/middlewares/internal/mppx.d.ts +16 -0
- package/dist/middlewares/internal/mppx.d.ts.map +1 -0
- package/dist/middlewares/internal/mppx.js +16 -0
- package/dist/middlewares/internal/mppx.js.map +1 -0
- package/dist/middlewares/nextjs.d.ts +45 -0
- package/dist/middlewares/nextjs.d.ts.map +1 -0
- package/dist/middlewares/nextjs.js +57 -0
- package/dist/middlewares/nextjs.js.map +1 -0
- package/dist/proxy/Proxy.d.ts +47 -0
- package/dist/proxy/Proxy.d.ts.map +1 -0
- package/dist/proxy/Proxy.js +126 -0
- package/dist/proxy/Proxy.js.map +1 -0
- package/dist/proxy/Service.d.ts +100 -0
- package/dist/proxy/Service.d.ts.map +1 -0
- package/dist/proxy/Service.js +147 -0
- package/dist/proxy/Service.js.map +1 -0
- package/dist/proxy/index.d.ts +7 -0
- package/dist/proxy/index.d.ts.map +1 -0
- package/dist/proxy/index.js +7 -0
- package/dist/proxy/index.js.map +1 -0
- package/dist/proxy/internal/Headers.d.ts +3 -0
- package/dist/proxy/internal/Headers.d.ts.map +1 -0
- package/dist/proxy/internal/Headers.js +41 -0
- package/dist/proxy/internal/Headers.js.map +1 -0
- package/dist/proxy/internal/Route.d.ts +14 -0
- package/dist/proxy/internal/Route.d.ts.map +1 -0
- package/dist/proxy/internal/Route.js +47 -0
- package/dist/proxy/internal/Route.js.map +1 -0
- package/dist/proxy/services/anthropic.d.ts +29 -0
- package/dist/proxy/services/anthropic.d.ts.map +1 -0
- package/dist/proxy/services/anthropic.js +30 -0
- package/dist/proxy/services/anthropic.js.map +1 -0
- package/dist/proxy/services/openai.d.ts +29 -0
- package/dist/proxy/services/openai.d.ts.map +1 -0
- package/dist/proxy/services/openai.js +30 -0
- package/dist/proxy/services/openai.js.map +1 -0
- package/dist/proxy/services/stripe.d.ts +29 -0
- package/dist/proxy/services/stripe.d.ts.map +1 -0
- package/dist/proxy/services/stripe.js +30 -0
- package/dist/proxy/services/stripe.js.map +1 -0
- package/dist/server/Methods.d.ts +3 -0
- package/dist/server/Methods.d.ts.map +1 -0
- package/dist/server/Methods.js +3 -0
- package/dist/server/Methods.js.map +1 -0
- package/dist/server/Mppx.d.ts +116 -0
- package/dist/server/Mppx.d.ts.map +1 -0
- package/dist/server/Mppx.js +207 -0
- package/dist/server/Mppx.js.map +1 -0
- package/dist/server/NodeListener.d.ts +3 -0
- package/dist/server/NodeListener.d.ts.map +1 -0
- package/dist/server/NodeListener.js +3 -0
- package/dist/server/NodeListener.js.map +1 -0
- package/dist/server/Request.d.ts +24 -0
- package/dist/server/Request.d.ts.map +1 -0
- package/dist/server/Request.js +26 -0
- package/dist/server/Request.js.map +1 -0
- package/dist/server/Response.d.ts +10 -0
- package/dist/server/Response.d.ts.map +1 -0
- package/dist/server/Response.js +15 -0
- package/dist/server/Response.js.map +1 -0
- package/dist/server/Transport.d.ts +93 -0
- package/dist/server/Transport.d.ts.map +1 -0
- package/dist/server/Transport.js +132 -0
- package/dist/server/Transport.js.map +1 -0
- package/dist/server/index.d.ts +9 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +9 -0
- package/dist/server/index.js.map +1 -0
- package/dist/stripe/Intents.d.ts +54 -0
- package/dist/stripe/Intents.d.ts.map +1 -0
- package/dist/stripe/Intents.js +27 -0
- package/dist/stripe/Intents.js.map +1 -0
- package/dist/stripe/client/Charge.d.ts +114 -0
- package/dist/stripe/client/Charge.d.ts.map +1 -0
- package/dist/stripe/client/Charge.js +77 -0
- package/dist/stripe/client/Charge.js.map +1 -0
- package/dist/stripe/client/MethodIntents.d.ts +80 -0
- package/dist/stripe/client/MethodIntents.d.ts.map +1 -0
- package/dist/stripe/client/MethodIntents.js +34 -0
- package/dist/stripe/client/MethodIntents.js.map +1 -0
- package/dist/stripe/client/index.d.ts +3 -0
- package/dist/stripe/client/index.d.ts.map +1 -0
- package/dist/stripe/client/index.js +3 -0
- package/dist/stripe/client/index.js.map +1 -0
- package/dist/stripe/index.d.ts +2 -0
- package/dist/stripe/index.d.ts.map +1 -0
- package/dist/stripe/index.js +2 -0
- package/dist/stripe/index.js.map +1 -0
- package/dist/stripe/server/Charge.d.ts +74 -0
- package/dist/stripe/server/Charge.d.ts.map +1 -0
- package/dist/stripe/server/Charge.js +79 -0
- package/dist/stripe/server/Charge.js.map +1 -0
- package/dist/stripe/server/MethodIntents.d.ts +65 -0
- package/dist/stripe/server/MethodIntents.d.ts.map +1 -0
- package/dist/stripe/server/MethodIntents.js +21 -0
- package/dist/stripe/server/MethodIntents.js.map +1 -0
- package/dist/stripe/server/index.d.ts +3 -0
- package/dist/stripe/server/index.d.ts.map +1 -0
- package/dist/stripe/server/index.js +3 -0
- package/dist/stripe/server/index.js.map +1 -0
- package/dist/tempo/Attribution.d.ts +101 -0
- package/dist/tempo/Attribution.d.ts.map +1 -0
- package/dist/tempo/Attribution.js +124 -0
- package/dist/tempo/Attribution.js.map +1 -0
- package/dist/tempo/Intents.d.ts +132 -0
- package/dist/tempo/Intents.d.ts.map +1 -0
- package/dist/tempo/Intents.js +81 -0
- package/dist/tempo/Intents.js.map +1 -0
- package/dist/tempo/client/ChannelOps.d.ts +54 -0
- package/dist/tempo/client/ChannelOps.d.ts.map +1 -0
- package/dist/tempo/client/ChannelOps.js +138 -0
- package/dist/tempo/client/ChannelOps.js.map +1 -0
- package/dist/tempo/client/Charge.d.ts +76 -0
- package/dist/tempo/client/Charge.d.ts.map +1 -0
- package/dist/tempo/client/Charge.js +69 -0
- package/dist/tempo/client/Charge.js.map +1 -0
- package/dist/tempo/client/MethodIntents.d.ts +157 -0
- package/dist/tempo/client/MethodIntents.d.ts.map +1 -0
- package/dist/tempo/client/MethodIntents.js +25 -0
- package/dist/tempo/client/MethodIntents.js.map +1 -0
- package/dist/tempo/client/Session.d.ts +159 -0
- package/dist/tempo/client/Session.d.ts.map +1 -0
- package/dist/tempo/client/Session.js +263 -0
- package/dist/tempo/client/Session.js.map +1 -0
- package/dist/tempo/client/SessionManager.d.ts +62 -0
- package/dist/tempo/client/SessionManager.d.ts.map +1 -0
- package/dist/tempo/client/SessionManager.js +196 -0
- package/dist/tempo/client/SessionManager.js.map +1 -0
- package/dist/tempo/client/index.d.ts +6 -0
- package/dist/tempo/client/index.d.ts.map +1 -0
- package/dist/tempo/client/index.js +5 -0
- package/dist/tempo/client/index.js.map +1 -0
- package/dist/tempo/index.d.ts +3 -0
- package/dist/tempo/index.d.ts.map +1 -0
- package/dist/tempo/index.js +3 -0
- package/dist/tempo/index.js.map +1 -0
- package/dist/tempo/internal/account.d.ts +32 -0
- package/dist/tempo/internal/account.d.ts.map +1 -0
- package/dist/tempo/internal/account.js +33 -0
- package/dist/tempo/internal/account.js.map +1 -0
- package/dist/tempo/internal/defaults.d.ts +18 -0
- package/dist/tempo/internal/defaults.d.ts.map +1 -0
- package/dist/tempo/internal/defaults.js +18 -0
- package/dist/tempo/internal/defaults.js.map +1 -0
- package/dist/tempo/internal/types.d.ts +11 -0
- package/dist/tempo/internal/types.d.ts.map +1 -0
- package/dist/tempo/internal/types.js +2 -0
- package/dist/tempo/internal/types.js.map +1 -0
- package/dist/tempo/server/Charge.d.ts +77 -0
- package/dist/tempo/server/Charge.d.ts.map +1 -0
- package/dist/tempo/server/Charge.js +228 -0
- package/dist/tempo/server/Charge.js.map +1 -0
- package/dist/tempo/server/MethodIntents.d.ts +140 -0
- package/dist/tempo/server/MethodIntents.d.ts.map +1 -0
- package/dist/tempo/server/MethodIntents.js +26 -0
- package/dist/tempo/server/MethodIntents.js.map +1 -0
- package/dist/tempo/server/Session.d.ts +148 -0
- package/dist/tempo/server/Session.d.ts.map +1 -0
- package/dist/tempo/server/Session.js +529 -0
- package/dist/tempo/server/Session.js.map +1 -0
- package/dist/tempo/server/internal/transport.d.ts +47 -0
- package/dist/tempo/server/internal/transport.d.ts.map +1 -0
- package/dist/tempo/server/internal/transport.js +118 -0
- package/dist/tempo/server/internal/transport.js.map +1 -0
- package/dist/tempo/stream/Chain.d.ts +52 -0
- package/dist/tempo/stream/Chain.d.ts.map +1 -0
- package/dist/tempo/stream/Chain.js +215 -0
- package/dist/tempo/stream/Chain.js.map +1 -0
- package/dist/tempo/stream/Channel.d.ts +26 -0
- package/dist/tempo/stream/Channel.d.ts.map +1 -0
- package/dist/tempo/stream/Channel.js +27 -0
- package/dist/tempo/stream/Channel.js.map +1 -0
- package/dist/tempo/stream/ChannelStore.d.ts +103 -0
- package/dist/tempo/stream/ChannelStore.d.ts.map +1 -0
- package/dist/tempo/stream/ChannelStore.js +100 -0
- package/dist/tempo/stream/ChannelStore.js.map +1 -0
- package/dist/tempo/stream/Receipt.d.ts +22 -0
- package/dist/tempo/stream/Receipt.d.ts.map +1 -0
- package/dist/tempo/stream/Receipt.js +34 -0
- package/dist/tempo/stream/Receipt.js.map +1 -0
- package/dist/tempo/stream/Sse.d.ts +134 -0
- package/dist/tempo/stream/Sse.d.ts.map +1 -0
- package/dist/tempo/stream/Sse.js +288 -0
- package/dist/tempo/stream/Sse.js.map +1 -0
- package/dist/tempo/stream/Types.d.ts +78 -0
- package/dist/tempo/stream/Types.d.ts.map +1 -0
- package/dist/tempo/stream/Types.js +2 -0
- package/dist/tempo/stream/Types.js.map +1 -0
- package/dist/tempo/stream/Voucher.d.ts +20 -0
- package/dist/tempo/stream/Voucher.d.ts.map +1 -0
- package/dist/tempo/stream/Voucher.js +98 -0
- package/dist/tempo/stream/Voucher.js.map +1 -0
- package/dist/tempo/stream/escrow.abi.d.ts +598 -0
- package/dist/tempo/stream/escrow.abi.d.ts.map +1 -0
- package/dist/tempo/stream/escrow.abi.js +760 -0
- package/dist/tempo/stream/escrow.abi.js.map +1 -0
- package/dist/tempo/stream/index.d.ts +8 -0
- package/dist/tempo/stream/index.d.ts.map +1 -0
- package/dist/tempo/stream/index.js +8 -0
- package/dist/tempo/stream/index.js.map +1 -0
- package/dist/viem/Account.d.ts +12 -0
- package/dist/viem/Account.d.ts.map +1 -0
- package/dist/viem/Account.js +14 -0
- package/dist/viem/Account.js.map +1 -0
- package/dist/viem/Client.d.ts +21 -0
- package/dist/viem/Client.d.ts.map +1 -0
- package/dist/viem/Client.js +19 -0
- package/dist/viem/Client.js.map +1 -0
- package/dist/zod.d.ts +17 -0
- package/dist/zod.d.ts.map +1 -0
- package/dist/zod.js +35 -0
- package/dist/zod.js.map +1 -0
- package/package.json +117 -4
- package/src/BodyDigest.test.ts +43 -0
- package/src/BodyDigest.ts +53 -0
- package/src/Challenge.test-d.ts +81 -0
- package/src/Challenge.test.ts +414 -0
- package/src/Challenge.ts +429 -0
- package/src/Credential.test.ts +227 -0
- package/src/Credential.ts +154 -0
- package/src/Errors.test.ts +402 -0
- package/src/Errors.ts +348 -0
- package/src/Expires.ts +34 -0
- package/src/Intent.test.ts +180 -0
- package/src/Intent.ts +109 -0
- package/src/Mcp.ts +81 -0
- package/src/MethodIntent.test.ts +303 -0
- package/src/MethodIntent.ts +388 -0
- package/src/PaymentRequest.test.ts +152 -0
- package/src/PaymentRequest.ts +107 -0
- package/src/Receipt.test.ts +98 -0
- package/src/Receipt.ts +129 -0
- package/src/Store.ts +84 -0
- package/src/cli.test.ts +542 -0
- package/src/cli.ts +1319 -0
- package/src/client/Methods.ts +3 -0
- package/src/client/Mppx.test-d.ts +90 -0
- package/src/client/Mppx.test.ts +468 -0
- package/src/client/Mppx.ts +149 -0
- package/src/client/Transport.test.ts +283 -0
- package/src/client/Transport.ts +115 -0
- package/src/client/index.ts +4 -0
- package/src/client/internal/Fetch.test-d.ts +57 -0
- package/src/client/internal/Fetch.test.ts +281 -0
- package/src/client/internal/Fetch.ts +157 -0
- package/src/env.d.ts +11 -0
- package/src/index.ts +12 -0
- package/src/internal/types.ts +403 -0
- package/src/mcp-sdk/client/McpClient.test-d.ts +109 -0
- package/src/mcp-sdk/client/McpClient.test.ts +219 -0
- package/src/mcp-sdk/client/McpClient.ts +187 -0
- package/src/mcp-sdk/client/index.ts +2 -0
- package/src/mcp-sdk/server/Transport.ts +94 -0
- package/src/mcp-sdk/server/index.ts +1 -0
- package/src/middlewares/elysia.ts +66 -0
- package/src/middlewares/express.test.ts +155 -0
- package/src/middlewares/express.ts +82 -0
- package/src/middlewares/hono.test.ts +148 -0
- package/src/middlewares/hono.ts +62 -0
- package/src/middlewares/internal/mppx.ts +30 -0
- package/src/middlewares/nextjs.test.ts +164 -0
- package/src/middlewares/nextjs.ts +66 -0
- package/src/proxy/Proxy.test.ts +472 -0
- package/src/proxy/Proxy.ts +175 -0
- package/src/proxy/Service.test.ts +125 -0
- package/src/proxy/Service.ts +227 -0
- package/src/proxy/index.ts +6 -0
- package/src/proxy/internal/Headers.test.ts +100 -0
- package/src/proxy/internal/Headers.ts +40 -0
- package/src/proxy/internal/Route.test.ts +143 -0
- package/src/proxy/internal/Route.ts +54 -0
- package/src/proxy/services/anthropic.ts +45 -0
- package/src/proxy/services/openai.test.ts +97 -0
- package/src/proxy/services/openai.ts +48 -0
- package/src/proxy/services/stripe.ts +49 -0
- package/src/server/Methods.ts +2 -0
- package/src/server/Mppx.test-d.ts +343 -0
- package/src/server/Mppx.test.ts +342 -0
- package/src/server/Mppx.ts +378 -0
- package/src/server/NodeListener.test.ts +188 -0
- package/src/server/NodeListener.ts +3 -0
- package/src/server/Request.test.ts +102 -0
- package/src/server/Request.ts +33 -0
- package/src/server/Response.test.ts +31 -0
- package/src/server/Response.ts +27 -0
- package/src/server/Transport.test.ts +294 -0
- package/src/server/Transport.ts +222 -0
- package/src/server/index.ts +8 -0
- package/src/stripe/Charge.integration.test.ts +326 -0
- package/src/stripe/Intents.test.ts +52 -0
- package/src/stripe/Intents.ts +27 -0
- package/src/stripe/client/Charge.ts +119 -0
- package/src/stripe/client/MethodIntents.ts +37 -0
- package/src/stripe/client/index.ts +2 -0
- package/src/stripe/index.ts +1 -0
- package/src/stripe/server/Charge.ts +121 -0
- package/src/stripe/server/MethodIntents.ts +24 -0
- package/src/stripe/server/index.ts +2 -0
- package/src/tempo/Attribution.test.ts +187 -0
- package/src/tempo/Attribution.ts +156 -0
- package/src/tempo/Intents.test.ts +84 -0
- package/src/tempo/Intents.ts +93 -0
- package/src/tempo/client/ChannelOps.ts +233 -0
- package/src/tempo/client/Charge.ts +84 -0
- package/src/tempo/client/MethodIntents.ts +28 -0
- package/src/tempo/client/Session.ts +369 -0
- package/src/tempo/client/SessionManager.test.ts +223 -0
- package/src/tempo/client/SessionManager.ts +270 -0
- package/src/tempo/client/index.ts +5 -0
- package/src/tempo/index.ts +2 -0
- package/src/tempo/internal/account.ts +47 -0
- package/src/tempo/internal/defaults.ts +20 -0
- package/src/tempo/internal/types.ts +8 -0
- package/src/tempo/server/Charge.test.ts +847 -0
- package/src/tempo/server/Charge.ts +309 -0
- package/src/tempo/server/MethodIntents.ts +29 -0
- package/src/tempo/server/Session.test.ts +1349 -0
- package/src/tempo/server/Session.ts +773 -0
- package/src/tempo/server/Sse.test.ts +289 -0
- package/src/tempo/server/index.ts +5 -0
- package/src/tempo/server/internal/transport.ts +153 -0
- package/src/tempo/stream/Chain.ts +333 -0
- package/src/tempo/stream/Channel.ts +50 -0
- package/src/tempo/stream/ChannelStore.test.ts +473 -0
- package/src/tempo/stream/ChannelStore.ts +202 -0
- package/src/tempo/stream/Receipt.test.ts +84 -0
- package/src/tempo/stream/Receipt.ts +45 -0
- package/src/tempo/stream/Sse.test.ts +401 -0
- package/src/tempo/stream/Sse.ts +375 -0
- package/src/tempo/stream/Types.ts +86 -0
- package/src/tempo/stream/Voucher.test.ts +134 -0
- package/src/tempo/stream/Voucher.ts +123 -0
- package/src/tempo/stream/escrow.abi.ts +759 -0
- package/src/tempo/stream/index.ts +7 -0
- package/src/tsconfig.json +10 -0
- package/src/viem/Account.test.ts +71 -0
- package/src/viem/Account.ts +30 -0
- package/src/viem/Client.test.ts +58 -0
- package/src/viem/Client.ts +33 -0
- package/src/zod.ts +47 -0
|
@@ -0,0 +1,309 @@
|
|
|
1
|
+
import {
|
|
2
|
+
decodeFunctionData,
|
|
3
|
+
isAddressEqual,
|
|
4
|
+
parseEventLogs,
|
|
5
|
+
type TransactionReceipt,
|
|
6
|
+
toFunctionSelector,
|
|
7
|
+
} from 'viem'
|
|
8
|
+
import { getTransactionReceipt, sendRawTransactionSync, signTransaction } from 'viem/actions'
|
|
9
|
+
import { tempo as tempo_chain } from 'viem/chains'
|
|
10
|
+
import { Abis, Transaction } from 'viem/tempo'
|
|
11
|
+
import { PaymentExpiredError } from '../../Errors.js'
|
|
12
|
+
import type { LooseOmit } from '../../internal/types.js'
|
|
13
|
+
import * as MethodIntent from '../../MethodIntent.js'
|
|
14
|
+
import * as Client from '../../viem/Client.js'
|
|
15
|
+
import * as Intents from '../Intents.js'
|
|
16
|
+
import * as Account from '../internal/account.js'
|
|
17
|
+
import * as defaults from '../internal/defaults.js'
|
|
18
|
+
import type * as types from '../internal/types.js'
|
|
19
|
+
|
|
20
|
+
const transferSelector = /*#__PURE__*/ toFunctionSelector(
|
|
21
|
+
'function transfer(address to, uint256 amount)',
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
const transferWithMemoSelector = /*#__PURE__*/ toFunctionSelector(
|
|
25
|
+
'function transferWithMemo(address to, uint256 amount, bytes32 memo)',
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Creates a Tempo charge method intent for usage on the server.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* import { tempo } from 'mppx/server'
|
|
34
|
+
*
|
|
35
|
+
* const charge = tempo.charge()
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
export function charge<const parameters extends charge.Parameters>(
|
|
39
|
+
parameters: parameters = {} as parameters,
|
|
40
|
+
) {
|
|
41
|
+
const {
|
|
42
|
+
amount,
|
|
43
|
+
currency,
|
|
44
|
+
decimals = defaults.decimals,
|
|
45
|
+
description,
|
|
46
|
+
externalId,
|
|
47
|
+
memo,
|
|
48
|
+
} = parameters
|
|
49
|
+
|
|
50
|
+
const { recipient, feePayer } = Account.resolve(parameters)
|
|
51
|
+
|
|
52
|
+
const getClient = Client.getResolver({
|
|
53
|
+
chain: { ...tempo_chain, experimental_preconfirmationTime: 500 },
|
|
54
|
+
getClient: parameters.getClient,
|
|
55
|
+
rpcUrl: defaults.rpcUrl,
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
type Defaults = charge.DeriveDefaults<parameters>
|
|
59
|
+
return MethodIntent.toServer<typeof Intents.charge, Defaults>(Intents.charge, {
|
|
60
|
+
defaults: {
|
|
61
|
+
amount,
|
|
62
|
+
currency,
|
|
63
|
+
decimals,
|
|
64
|
+
description,
|
|
65
|
+
externalId,
|
|
66
|
+
memo,
|
|
67
|
+
recipient,
|
|
68
|
+
} as unknown as Defaults,
|
|
69
|
+
|
|
70
|
+
// TODO: dedupe `{charge,stream}.request`
|
|
71
|
+
async request({ credential, request }) {
|
|
72
|
+
const chainId = await (async () => {
|
|
73
|
+
if (request.chainId) return request.chainId
|
|
74
|
+
if (parameters.testnet) return defaults.testnetChainId
|
|
75
|
+
return (await getClient({})).chain?.id
|
|
76
|
+
})()
|
|
77
|
+
|
|
78
|
+
const client = await (async () => {
|
|
79
|
+
try {
|
|
80
|
+
return await getClient({ chainId })
|
|
81
|
+
} catch {
|
|
82
|
+
throw new Error(`No client configured with chainId ${chainId}.`)
|
|
83
|
+
}
|
|
84
|
+
})()
|
|
85
|
+
if (client.chain?.id !== chainId)
|
|
86
|
+
throw new Error(`Client not configured with chainId ${chainId}.`)
|
|
87
|
+
|
|
88
|
+
const resolvedFeePayer = (() => {
|
|
89
|
+
const account = typeof request.feePayer === 'object' ? request.feePayer : feePayer
|
|
90
|
+
const requested = request.feePayer !== false && (account ?? feePayer)
|
|
91
|
+
if (credential) return account
|
|
92
|
+
if (requested) return true
|
|
93
|
+
return undefined
|
|
94
|
+
})()
|
|
95
|
+
|
|
96
|
+
return {
|
|
97
|
+
...request,
|
|
98
|
+
chainId,
|
|
99
|
+
feePayer: resolvedFeePayer,
|
|
100
|
+
memo: request.memo || undefined,
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
|
|
104
|
+
async verify({ credential, request }) {
|
|
105
|
+
const { challenge } = credential
|
|
106
|
+
const { chainId, feePayer } = request
|
|
107
|
+
|
|
108
|
+
const client = await getClient({ chainId })
|
|
109
|
+
|
|
110
|
+
const { request: challengeRequest } = challenge
|
|
111
|
+
const { amount, expires, methodDetails } = challengeRequest
|
|
112
|
+
|
|
113
|
+
const currency = challengeRequest.currency as `0x${string}`
|
|
114
|
+
const recipient = challengeRequest.recipient as `0x${string}`
|
|
115
|
+
|
|
116
|
+
if (expires && new Date(expires) < new Date()) throw new PaymentExpiredError({ expires })
|
|
117
|
+
|
|
118
|
+
const memo = methodDetails?.memo as `0x${string}` | undefined
|
|
119
|
+
|
|
120
|
+
const payload = credential.payload
|
|
121
|
+
|
|
122
|
+
switch (payload.type) {
|
|
123
|
+
case 'hash': {
|
|
124
|
+
const hash = payload.hash as `0x${string}`
|
|
125
|
+
const receipt = await getTransactionReceipt(client, {
|
|
126
|
+
hash,
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
if (memo) {
|
|
130
|
+
const memoLogs = parseEventLogs({
|
|
131
|
+
abi: Abis.tip20,
|
|
132
|
+
eventName: 'TransferWithMemo',
|
|
133
|
+
logs: receipt.logs,
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
const match = memoLogs.find(
|
|
137
|
+
(log) =>
|
|
138
|
+
isAddressEqual(log.address, currency) &&
|
|
139
|
+
isAddressEqual(log.args.to, recipient) &&
|
|
140
|
+
log.args.amount.toString() === amount &&
|
|
141
|
+
log.args.memo.toLowerCase() === memo.toLowerCase(),
|
|
142
|
+
)
|
|
143
|
+
|
|
144
|
+
if (!match)
|
|
145
|
+
throw new MismatchError(
|
|
146
|
+
'Payment verification failed: no matching transfer with memo found.',
|
|
147
|
+
{
|
|
148
|
+
amount,
|
|
149
|
+
currency,
|
|
150
|
+
memo,
|
|
151
|
+
recipient,
|
|
152
|
+
},
|
|
153
|
+
)
|
|
154
|
+
} else {
|
|
155
|
+
const transferLogs = parseEventLogs({
|
|
156
|
+
abi: Abis.tip20,
|
|
157
|
+
eventName: 'Transfer',
|
|
158
|
+
logs: receipt.logs,
|
|
159
|
+
})
|
|
160
|
+
|
|
161
|
+
const memoLogs = parseEventLogs({
|
|
162
|
+
abi: Abis.tip20,
|
|
163
|
+
eventName: 'TransferWithMemo',
|
|
164
|
+
logs: receipt.logs,
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
const match = [...transferLogs, ...memoLogs].find(
|
|
168
|
+
(log) =>
|
|
169
|
+
isAddressEqual(log.address, currency) &&
|
|
170
|
+
isAddressEqual(log.args.to, recipient) &&
|
|
171
|
+
log.args.amount.toString() === amount,
|
|
172
|
+
)
|
|
173
|
+
|
|
174
|
+
if (!match)
|
|
175
|
+
throw new MismatchError('Payment verification failed: no matching transfer found.', {
|
|
176
|
+
amount,
|
|
177
|
+
currency,
|
|
178
|
+
recipient,
|
|
179
|
+
})
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
return toReceipt(receipt)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
case 'transaction': {
|
|
186
|
+
const serializedTransaction = payload.signature as Transaction.TransactionSerializedTempo
|
|
187
|
+
const transaction = Transaction.deserialize(serializedTransaction)
|
|
188
|
+
|
|
189
|
+
const calls = transaction.calls ?? []
|
|
190
|
+
|
|
191
|
+
const call = calls.find((call) => {
|
|
192
|
+
if (!call.to || !isAddressEqual(call.to, currency)) return false
|
|
193
|
+
if (!call.data) return false
|
|
194
|
+
|
|
195
|
+
const selector = call.data.slice(0, 10)
|
|
196
|
+
|
|
197
|
+
if (memo) {
|
|
198
|
+
if (selector !== transferWithMemoSelector) return false
|
|
199
|
+
try {
|
|
200
|
+
const { args } = decodeFunctionData({ abi: Abis.tip20, data: call.data })
|
|
201
|
+
const [to, amount_, memo_] = args as [`0x${string}`, bigint, `0x${string}`]
|
|
202
|
+
return (
|
|
203
|
+
isAddressEqual(to, recipient) &&
|
|
204
|
+
amount_.toString() === amount &&
|
|
205
|
+
memo_.toLowerCase() === memo.toLowerCase()
|
|
206
|
+
)
|
|
207
|
+
} catch {
|
|
208
|
+
return false
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (selector === transferSelector) {
|
|
213
|
+
try {
|
|
214
|
+
const { args } = decodeFunctionData({ abi: Abis.tip20, data: call.data })
|
|
215
|
+
const [to, amount_] = args as [`0x${string}`, bigint]
|
|
216
|
+
return isAddressEqual(to, recipient) && amount_.toString() === amount
|
|
217
|
+
} catch {
|
|
218
|
+
return false
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
if (selector === transferWithMemoSelector) {
|
|
223
|
+
try {
|
|
224
|
+
const { args } = decodeFunctionData({ abi: Abis.tip20, data: call.data })
|
|
225
|
+
const [to, amount_] = args as [`0x${string}`, bigint, `0x${string}`]
|
|
226
|
+
return isAddressEqual(to, recipient) && amount_.toString() === amount
|
|
227
|
+
} catch {
|
|
228
|
+
return false
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return false
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
if (!call)
|
|
236
|
+
throw new MismatchError('Invalid transaction: no matching payment call found', {
|
|
237
|
+
amount,
|
|
238
|
+
currency,
|
|
239
|
+
recipient,
|
|
240
|
+
})
|
|
241
|
+
|
|
242
|
+
const serializedTransaction_final = await (async () => {
|
|
243
|
+
if (feePayer && methodDetails?.feePayer !== false) {
|
|
244
|
+
return signTransaction(client, {
|
|
245
|
+
...transaction,
|
|
246
|
+
account: feePayer,
|
|
247
|
+
feePayer,
|
|
248
|
+
} as never)
|
|
249
|
+
}
|
|
250
|
+
return serializedTransaction
|
|
251
|
+
})()
|
|
252
|
+
|
|
253
|
+
const receipt = await sendRawTransactionSync(client, {
|
|
254
|
+
serializedTransaction: serializedTransaction_final,
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
return toReceipt(receipt)
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
default:
|
|
261
|
+
throw new Error(`Unsupported credential type "${(payload as { type: string }).type}".`)
|
|
262
|
+
}
|
|
263
|
+
},
|
|
264
|
+
})
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export declare namespace charge {
|
|
268
|
+
type Defaults = LooseOmit<
|
|
269
|
+
MethodIntent.RequestDefaults<typeof Intents.charge>,
|
|
270
|
+
'feePayer' | 'recipient'
|
|
271
|
+
>
|
|
272
|
+
|
|
273
|
+
type Parameters = {
|
|
274
|
+
/** Testnet mode. */
|
|
275
|
+
testnet?: boolean | undefined
|
|
276
|
+
} & Client.getResolver.Parameters &
|
|
277
|
+
Account.resolve.Parameters &
|
|
278
|
+
Defaults
|
|
279
|
+
|
|
280
|
+
type DeriveDefaults<parameters extends Parameters> = types.DeriveDefaults<
|
|
281
|
+
parameters,
|
|
282
|
+
Defaults
|
|
283
|
+
> & {
|
|
284
|
+
decimals: number
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
/** @internal */
|
|
289
|
+
function toReceipt(receipt: TransactionReceipt) {
|
|
290
|
+
const { status, transactionHash } = receipt
|
|
291
|
+
if (status !== 'success') {
|
|
292
|
+
throw new Error(`Transaction reverted: ${transactionHash}`)
|
|
293
|
+
}
|
|
294
|
+
return {
|
|
295
|
+
method: 'tempo',
|
|
296
|
+
status: 'success',
|
|
297
|
+
timestamp: new Date().toISOString(),
|
|
298
|
+
reference: transactionHash,
|
|
299
|
+
} as const
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
/** @internal */
|
|
303
|
+
class MismatchError extends Error {
|
|
304
|
+
override readonly name = 'MismatchError'
|
|
305
|
+
|
|
306
|
+
constructor(reason: string, details: Record<string, string>) {
|
|
307
|
+
super([reason, ...Object.entries(details).map(([k, v]) => ` - ${k}: ${v}`)].join('\n'))
|
|
308
|
+
}
|
|
309
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { charge as charge_ } from './Charge.js'
|
|
2
|
+
import { session as session_, settle as settle_ } from './Session.js'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Creates both Tempo `charge` and `session` method intents from shared parameters.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* import { Mppx, tempo } from 'mppx/server'
|
|
10
|
+
*
|
|
11
|
+
* const mppx = Mppx.create({
|
|
12
|
+
* methods: [tempo({ currency: '0x...', recipient: '0x...' })],
|
|
13
|
+
* })
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function tempo<const parameters extends tempo.Parameters>(parameters?: parameters) {
|
|
17
|
+
return [tempo.charge(parameters), tempo.session(parameters)] as const
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export namespace tempo {
|
|
21
|
+
export type Parameters = charge_.Parameters & session_.Parameters
|
|
22
|
+
|
|
23
|
+
/** Creates a Tempo `charge` method intent for one-time TIP-20 token transfers. */
|
|
24
|
+
export const charge = charge_
|
|
25
|
+
/** Creates a Tempo `session` method intent for session-based TIP-20 token payments. */
|
|
26
|
+
export const session = session_
|
|
27
|
+
/** One-shot settle: reads highest voucher from storage and submits on-chain. */
|
|
28
|
+
export const settle = settle_
|
|
29
|
+
}
|