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,333 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type Account,
|
|
3
|
+
type Address,
|
|
4
|
+
type Client,
|
|
5
|
+
decodeFunctionData,
|
|
6
|
+
getAbiItem,
|
|
7
|
+
type Hex,
|
|
8
|
+
isAddressEqual,
|
|
9
|
+
type ReadContractReturnType,
|
|
10
|
+
toFunctionSelector,
|
|
11
|
+
} from 'viem'
|
|
12
|
+
import { readContract, sendRawTransactionSync, signTransaction, writeContract } from 'viem/actions'
|
|
13
|
+
import { Transaction } from 'viem/tempo'
|
|
14
|
+
import { BadRequestError, ChannelClosedError, VerificationFailedError } from '../../Errors.js'
|
|
15
|
+
import { escrowAbi } from './escrow.abi.js'
|
|
16
|
+
import type { SignedVoucher } from './Types.js'
|
|
17
|
+
|
|
18
|
+
export { escrowAbi }
|
|
19
|
+
|
|
20
|
+
const UINT128_MAX = 2n ** 128n - 1n
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* On-chain channel state from the escrow contract.
|
|
24
|
+
*/
|
|
25
|
+
export type OnChainChannel = ReadContractReturnType<typeof escrowAbi, 'getChannel'>
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Read channel state from the escrow contract.
|
|
29
|
+
*/
|
|
30
|
+
export async function getOnChainChannel(
|
|
31
|
+
client: Client,
|
|
32
|
+
escrowContract: Address,
|
|
33
|
+
channelId: Hex,
|
|
34
|
+
): Promise<OnChainChannel> {
|
|
35
|
+
return readContract(client, {
|
|
36
|
+
address: escrowContract,
|
|
37
|
+
abi: escrowAbi,
|
|
38
|
+
functionName: 'getChannel',
|
|
39
|
+
args: [channelId],
|
|
40
|
+
})
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Verify a topUp by re-reading on-chain channel state.
|
|
45
|
+
*/
|
|
46
|
+
export async function verifyTopUpTransaction(
|
|
47
|
+
client: Client,
|
|
48
|
+
escrowContract: Address,
|
|
49
|
+
channelId: Hex,
|
|
50
|
+
previousDeposit: bigint,
|
|
51
|
+
): Promise<{ deposit: bigint }> {
|
|
52
|
+
const channel = await getOnChainChannel(client, escrowContract, channelId)
|
|
53
|
+
|
|
54
|
+
if (channel.finalized) {
|
|
55
|
+
throw new ChannelClosedError({ reason: 'channel is finalized on-chain' })
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
if (channel.deposit <= previousDeposit) {
|
|
59
|
+
throw new VerificationFailedError({ reason: 'channel deposit did not increase' })
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return { deposit: channel.deposit }
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function assertUint128(amount: bigint): void {
|
|
66
|
+
if (amount < 0n || amount > UINT128_MAX) {
|
|
67
|
+
throw new VerificationFailedError({ reason: 'cumulativeAmount exceeds uint128 range' })
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Submit a settle transaction on-chain.
|
|
73
|
+
*/
|
|
74
|
+
export async function settleOnChain(
|
|
75
|
+
client: Client,
|
|
76
|
+
escrowContract: Address,
|
|
77
|
+
voucher: SignedVoucher,
|
|
78
|
+
): Promise<Hex> {
|
|
79
|
+
assertUint128(voucher.cumulativeAmount)
|
|
80
|
+
return writeContract(client, {
|
|
81
|
+
account: client.account!,
|
|
82
|
+
chain: client.chain,
|
|
83
|
+
address: escrowContract,
|
|
84
|
+
abi: escrowAbi,
|
|
85
|
+
functionName: 'settle',
|
|
86
|
+
args: [voucher.channelId, voucher.cumulativeAmount, voucher.signature],
|
|
87
|
+
})
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Submit a close transaction on-chain.
|
|
92
|
+
*/
|
|
93
|
+
export async function closeOnChain(
|
|
94
|
+
client: Client,
|
|
95
|
+
escrowContract: Address,
|
|
96
|
+
voucher: SignedVoucher,
|
|
97
|
+
account?: Account,
|
|
98
|
+
): Promise<Hex> {
|
|
99
|
+
assertUint128(voucher.cumulativeAmount)
|
|
100
|
+
const resolved = account ?? client.account
|
|
101
|
+
if (!resolved)
|
|
102
|
+
throw new Error(
|
|
103
|
+
'Cannot close channel: no account available. Provide an `account` in the session config or a `getClient` that returns an account-bearing client.',
|
|
104
|
+
)
|
|
105
|
+
return writeContract(client, {
|
|
106
|
+
account: resolved,
|
|
107
|
+
chain: client.chain,
|
|
108
|
+
address: escrowContract,
|
|
109
|
+
abi: escrowAbi,
|
|
110
|
+
functionName: 'close',
|
|
111
|
+
args: [voucher.channelId, voucher.cumulativeAmount, voucher.signature],
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
const escrowOpenSelector = /*#__PURE__*/ toFunctionSelector(
|
|
116
|
+
getAbiItem({ abi: escrowAbi, name: 'open' }),
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
const escrowTopUpSelector = /*#__PURE__*/ toFunctionSelector(
|
|
120
|
+
getAbiItem({ abi: escrowAbi, name: 'topUp' }),
|
|
121
|
+
)
|
|
122
|
+
|
|
123
|
+
const erc20ApproveSelector = /*#__PURE__*/ toFunctionSelector(
|
|
124
|
+
'function approve(address spender, uint256 amount)',
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
export type BroadcastResult = {
|
|
128
|
+
txHash: Hex | undefined
|
|
129
|
+
onChain: OnChainChannel
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export async function broadcastOpenTransaction(parameters: {
|
|
133
|
+
client: Client
|
|
134
|
+
serializedTransaction: Hex
|
|
135
|
+
escrowContract: Address
|
|
136
|
+
channelId: Hex
|
|
137
|
+
recipient: Address
|
|
138
|
+
currency: Address
|
|
139
|
+
feePayer?: Account | undefined
|
|
140
|
+
}): Promise<BroadcastResult> {
|
|
141
|
+
const {
|
|
142
|
+
client,
|
|
143
|
+
serializedTransaction,
|
|
144
|
+
escrowContract,
|
|
145
|
+
channelId,
|
|
146
|
+
recipient,
|
|
147
|
+
currency,
|
|
148
|
+
feePayer,
|
|
149
|
+
} = parameters
|
|
150
|
+
|
|
151
|
+
const transaction = Transaction.deserialize(
|
|
152
|
+
serializedTransaction as Transaction.TransactionSerializedTempo,
|
|
153
|
+
)
|
|
154
|
+
const calls = transaction.calls ?? []
|
|
155
|
+
|
|
156
|
+
const openCall = calls.find((call) => {
|
|
157
|
+
if (!call.to || !isAddressEqual(call.to, escrowContract)) return false
|
|
158
|
+
if (!call.data) return false
|
|
159
|
+
return call.data.slice(0, 10) === escrowOpenSelector
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
if (!openCall)
|
|
163
|
+
throw new BadRequestError({
|
|
164
|
+
reason: 'transaction does not contain a valid escrow open call',
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
if (feePayer) {
|
|
168
|
+
for (const call of calls) {
|
|
169
|
+
if (!call.to || !call.data) {
|
|
170
|
+
throw new BadRequestError({
|
|
171
|
+
reason: 'fee-sponsored transactions must not contain calls without target or data',
|
|
172
|
+
})
|
|
173
|
+
}
|
|
174
|
+
const selector = call.data.slice(0, 10)
|
|
175
|
+
const isEscrowOpen =
|
|
176
|
+
isAddressEqual(call.to, escrowContract) && selector === escrowOpenSelector
|
|
177
|
+
const isTokenApprove = isAddressEqual(call.to, currency) && selector === erc20ApproveSelector
|
|
178
|
+
if (!isEscrowOpen && !isTokenApprove) {
|
|
179
|
+
throw new BadRequestError({
|
|
180
|
+
reason: 'fee-sponsored open transaction contains an unauthorized call',
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
const { args: openArgs } = decodeFunctionData({ abi: escrowAbi, data: openCall.data! })
|
|
187
|
+
const [payee, token] = openArgs as readonly [Address, Address, ...unknown[]]
|
|
188
|
+
|
|
189
|
+
if (!isAddressEqual(payee, recipient)) {
|
|
190
|
+
throw new VerificationFailedError({
|
|
191
|
+
reason: 'open transaction payee does not match server recipient',
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
if (!isAddressEqual(token, currency)) {
|
|
195
|
+
throw new VerificationFailedError({
|
|
196
|
+
reason: 'open transaction token does not match server currency',
|
|
197
|
+
})
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
const serializedTransaction_final = await (async () => {
|
|
201
|
+
if (feePayer) {
|
|
202
|
+
return signTransaction(client, {
|
|
203
|
+
...transaction,
|
|
204
|
+
account: feePayer,
|
|
205
|
+
feePayer,
|
|
206
|
+
} as never)
|
|
207
|
+
}
|
|
208
|
+
return serializedTransaction
|
|
209
|
+
})()
|
|
210
|
+
|
|
211
|
+
let txHash: Hex | undefined
|
|
212
|
+
try {
|
|
213
|
+
const receipt = await sendRawTransactionSync(client, {
|
|
214
|
+
serializedTransaction: serializedTransaction_final as Transaction.TransactionSerializedTempo,
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
if (receipt.status !== 'success') {
|
|
218
|
+
throw new VerificationFailedError({
|
|
219
|
+
reason: `open transaction reverted: ${receipt.transactionHash}`,
|
|
220
|
+
})
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
txHash = receipt.transactionHash
|
|
224
|
+
} catch (error) {
|
|
225
|
+
const onChain = await getOnChainChannel(client, escrowContract, channelId)
|
|
226
|
+
if (onChain.deposit > 0n) {
|
|
227
|
+
return { txHash: undefined, onChain }
|
|
228
|
+
}
|
|
229
|
+
throw error
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
const onChain = await getOnChainChannel(client, escrowContract, channelId)
|
|
233
|
+
|
|
234
|
+
return { txHash, onChain }
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
export async function broadcastTopUpTransaction(parameters: {
|
|
238
|
+
client: Client
|
|
239
|
+
serializedTransaction: Hex
|
|
240
|
+
escrowContract: Address
|
|
241
|
+
channelId: Hex
|
|
242
|
+
declaredDeposit: bigint
|
|
243
|
+
previousDeposit: bigint
|
|
244
|
+
feePayer?: Account | undefined
|
|
245
|
+
}): Promise<{ txHash: Hex; newDeposit: bigint }> {
|
|
246
|
+
const {
|
|
247
|
+
client,
|
|
248
|
+
serializedTransaction,
|
|
249
|
+
escrowContract,
|
|
250
|
+
channelId,
|
|
251
|
+
declaredDeposit,
|
|
252
|
+
previousDeposit,
|
|
253
|
+
feePayer,
|
|
254
|
+
} = parameters
|
|
255
|
+
|
|
256
|
+
const transaction = Transaction.deserialize(
|
|
257
|
+
serializedTransaction as Transaction.TransactionSerializedTempo,
|
|
258
|
+
)
|
|
259
|
+
const calls = transaction.calls ?? []
|
|
260
|
+
|
|
261
|
+
const topUpCall = calls.find((call) => {
|
|
262
|
+
if (!call.to || !isAddressEqual(call.to, escrowContract)) return false
|
|
263
|
+
if (!call.data) return false
|
|
264
|
+
return call.data.slice(0, 10) === escrowTopUpSelector
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
if (!topUpCall)
|
|
268
|
+
throw new BadRequestError({
|
|
269
|
+
reason: 'transaction does not contain a valid escrow topUp call',
|
|
270
|
+
})
|
|
271
|
+
|
|
272
|
+
if (feePayer) {
|
|
273
|
+
for (const call of calls) {
|
|
274
|
+
if (!call.to || !call.data) {
|
|
275
|
+
throw new BadRequestError({
|
|
276
|
+
reason: 'fee-sponsored transactions must not contain calls without target or data',
|
|
277
|
+
})
|
|
278
|
+
}
|
|
279
|
+
const selector = call.data.slice(0, 10)
|
|
280
|
+
const isEscrowTopUp =
|
|
281
|
+
isAddressEqual(call.to, escrowContract) && selector === escrowTopUpSelector
|
|
282
|
+
const isTokenApprove = selector === erc20ApproveSelector
|
|
283
|
+
if (!isEscrowTopUp && !isTokenApprove) {
|
|
284
|
+
throw new BadRequestError({
|
|
285
|
+
reason: 'fee-sponsored topUp transaction contains an unauthorized call',
|
|
286
|
+
})
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
const { args: topUpArgs } = decodeFunctionData({ abi: escrowAbi, data: topUpCall.data! })
|
|
292
|
+
const [txChannelId, txAmount] = topUpArgs as [Hex, bigint]
|
|
293
|
+
|
|
294
|
+
if (txChannelId.toLowerCase() !== channelId.toLowerCase()) {
|
|
295
|
+
throw new VerificationFailedError({
|
|
296
|
+
reason: 'topUp transaction channelId does not match payload channelId',
|
|
297
|
+
})
|
|
298
|
+
}
|
|
299
|
+
if (BigInt(txAmount) !== declaredDeposit) {
|
|
300
|
+
throw new VerificationFailedError({
|
|
301
|
+
reason: `topUp transaction amount (${txAmount}) does not match declared additionalDeposit (${declaredDeposit})`,
|
|
302
|
+
})
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
const serializedTransaction_final = await (async () => {
|
|
306
|
+
if (feePayer) {
|
|
307
|
+
return signTransaction(client, {
|
|
308
|
+
...transaction,
|
|
309
|
+
account: feePayer,
|
|
310
|
+
feePayer,
|
|
311
|
+
} as never)
|
|
312
|
+
}
|
|
313
|
+
return serializedTransaction
|
|
314
|
+
})()
|
|
315
|
+
|
|
316
|
+
const receipt = await sendRawTransactionSync(client, {
|
|
317
|
+
serializedTransaction: serializedTransaction_final as Transaction.TransactionSerializedTempo,
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
if (receipt.status !== 'success') {
|
|
321
|
+
throw new VerificationFailedError({
|
|
322
|
+
reason: `topUp transaction reverted: ${receipt.transactionHash}`,
|
|
323
|
+
})
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const onChain = await getOnChainChannel(client, escrowContract, channelId)
|
|
327
|
+
|
|
328
|
+
if (onChain.deposit <= previousDeposit) {
|
|
329
|
+
throw new VerificationFailedError({ reason: 'channel deposit did not increase after topUp' })
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
return { txHash: receipt.transactionHash, newDeposit: onChain.deposit }
|
|
333
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { AbiParameters, Hash } from 'ox'
|
|
2
|
+
import type * as Hex from 'ox/Hex'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Computes a channel ID from its parameters.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors the onchain `computeChannelId` function: `keccak256(abi.encode(payer, payee, token, salt, authorizedSigner, escrowContract, chainId))`.
|
|
8
|
+
*/
|
|
9
|
+
export function computeId(parameters: computeId.Parameters): Hex.Hex {
|
|
10
|
+
const encoded = AbiParameters.encode(
|
|
11
|
+
AbiParameters.from([
|
|
12
|
+
'address payer',
|
|
13
|
+
'address payee',
|
|
14
|
+
'address token',
|
|
15
|
+
'bytes32 salt',
|
|
16
|
+
'address authorizedSigner',
|
|
17
|
+
'address escrowContract',
|
|
18
|
+
'uint256 chainId',
|
|
19
|
+
]),
|
|
20
|
+
[
|
|
21
|
+
parameters.payer,
|
|
22
|
+
parameters.payee,
|
|
23
|
+
parameters.token,
|
|
24
|
+
parameters.salt,
|
|
25
|
+
parameters.authorizedSigner,
|
|
26
|
+
parameters.escrowContract,
|
|
27
|
+
BigInt(parameters.chainId),
|
|
28
|
+
],
|
|
29
|
+
)
|
|
30
|
+
return Hash.keccak256(encoded)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export declare namespace computeId {
|
|
34
|
+
type Parameters = {
|
|
35
|
+
/** Address authorized to sign vouchers on behalf of the payer. */
|
|
36
|
+
authorizedSigner: Hex.Hex
|
|
37
|
+
/** Chain ID of the network the escrow contract is deployed on. */
|
|
38
|
+
chainId: number
|
|
39
|
+
/** Address of the escrow contract. */
|
|
40
|
+
escrowContract: Hex.Hex
|
|
41
|
+
/** Address of the payee (recipient). */
|
|
42
|
+
payee: Hex.Hex
|
|
43
|
+
/** Address of the payer (sender). */
|
|
44
|
+
payer: Hex.Hex
|
|
45
|
+
/** Unique salt to differentiate channels with the same parameters. */
|
|
46
|
+
salt: Hex.Hex
|
|
47
|
+
/** Address of the token used for payment. */
|
|
48
|
+
token: Hex.Hex
|
|
49
|
+
}
|
|
50
|
+
}
|