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,24 @@
|
|
|
1
|
+
import { charge as charge_ } from './Charge.js'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Creates a Stripe `charge` method intent for usage on the server.
|
|
5
|
+
*
|
|
6
|
+
* @example
|
|
7
|
+
* ```ts
|
|
8
|
+
* import { Mppx, stripe } from 'mppx/server'
|
|
9
|
+
*
|
|
10
|
+
* const mppx = Mppx.create({
|
|
11
|
+
* methods: [stripe({ secretKey: 'sk_...' })],
|
|
12
|
+
* })
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
export function stripe<const parameters extends stripe.Parameters>(parameters: parameters) {
|
|
16
|
+
return [stripe.charge(parameters)] as const
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export namespace stripe {
|
|
20
|
+
export type Parameters = charge_.Parameters
|
|
21
|
+
|
|
22
|
+
/** Creates a Stripe `charge` method intent for SPT-based payments. */
|
|
23
|
+
export const charge = charge_
|
|
24
|
+
}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
import { Bytes, Hash, Hex } from 'ox'
|
|
2
|
+
import { describe, expect, test } from 'vitest'
|
|
3
|
+
import * as Attribution from './Attribution.js'
|
|
4
|
+
|
|
5
|
+
describe('Attribution', () => {
|
|
6
|
+
describe('tag', () => {
|
|
7
|
+
test('is a 4-byte hex string', () => {
|
|
8
|
+
expect(Attribution.tag).toMatch(/^0x[0-9a-f]{8}$/i)
|
|
9
|
+
})
|
|
10
|
+
|
|
11
|
+
test('is deterministic (keccak256("mpp")[0..3])', () => {
|
|
12
|
+
expect(Attribution.tag).toBe('0xef1ed712')
|
|
13
|
+
})
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
describe('encode', () => {
|
|
17
|
+
test('returns a 32-byte hex string', () => {
|
|
18
|
+
const memo = Attribution.encode({ serverId: 'api.example.com' })
|
|
19
|
+
// 0x prefix + 64 hex chars = 32 bytes
|
|
20
|
+
expect(memo).toMatch(/^0x[0-9a-f]{64}$/i)
|
|
21
|
+
})
|
|
22
|
+
|
|
23
|
+
test('starts with TAG + version byte', () => {
|
|
24
|
+
const memo = Attribution.encode({ serverId: 'api.example.com' })
|
|
25
|
+
const tag = memo.slice(0, 10) // 0x + 8 hex chars
|
|
26
|
+
expect(tag.toLowerCase()).toBe(Attribution.tag.toLowerCase())
|
|
27
|
+
const version = memo.slice(10, 12)
|
|
28
|
+
expect(version).toBe('01')
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
test('generates unique memos (random nonce)', () => {
|
|
32
|
+
const a = Attribution.encode({ serverId: 'api.example.com' })
|
|
33
|
+
const b = Attribution.encode({ serverId: 'api.example.com' })
|
|
34
|
+
expect(a).not.toBe(b)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('encodes server fingerprint from serverId', () => {
|
|
38
|
+
const memo = Attribution.encode({ serverId: 'api.example.com' })
|
|
39
|
+
const expectedFingerprint = Hex.slice(
|
|
40
|
+
Hash.keccak256(Bytes.fromString('api.example.com'), { as: 'Hex' }),
|
|
41
|
+
0,
|
|
42
|
+
10,
|
|
43
|
+
)
|
|
44
|
+
const serverHex = `0x${memo.slice(12, 32)}` as `0x${string}`
|
|
45
|
+
expect(serverHex.toLowerCase()).toBe(expectedFingerprint.toLowerCase())
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
test('encodes client fingerprint from clientId', () => {
|
|
49
|
+
const memo = Attribution.encode({ serverId: 'api.example.com', clientId: 'my-app' })
|
|
50
|
+
const expectedFingerprint = Hex.slice(
|
|
51
|
+
Hash.keccak256(Bytes.fromString('my-app'), { as: 'Hex' }),
|
|
52
|
+
0,
|
|
53
|
+
10,
|
|
54
|
+
)
|
|
55
|
+
const clientHex = `0x${memo.slice(32, 52)}` as `0x${string}`
|
|
56
|
+
expect(clientHex.toLowerCase()).toBe(expectedFingerprint.toLowerCase())
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
test('encodes zero client bytes when no clientId', () => {
|
|
60
|
+
const memo = Attribution.encode({ serverId: 'api.example.com' })
|
|
61
|
+
const clientHex = `0x${memo.slice(32, 52)}` as `0x${string}`
|
|
62
|
+
expect(clientHex).toBe(Attribution.anonymous)
|
|
63
|
+
})
|
|
64
|
+
|
|
65
|
+
test('treats empty string clientId as anonymous', () => {
|
|
66
|
+
const memo = Attribution.encode({ serverId: 'api.example.com', clientId: '' })
|
|
67
|
+
const clientHex = `0x${memo.slice(32, 52)}` as `0x${string}`
|
|
68
|
+
expect(clientHex).toBe(Attribution.anonymous)
|
|
69
|
+
const decoded = Attribution.decode(memo)
|
|
70
|
+
expect(decoded).not.toBeNull()
|
|
71
|
+
expect(decoded!.clientFingerprint).toBeNull()
|
|
72
|
+
})
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
describe('isMppMemo', () => {
|
|
76
|
+
test('returns true for encoded memos', () => {
|
|
77
|
+
const memo = Attribution.encode({ serverId: 'api.example.com' })
|
|
78
|
+
expect(Attribution.isMppMemo(memo)).toBe(true)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
test('returns true for encoded memos with clientId', () => {
|
|
82
|
+
const memo = Attribution.encode({ serverId: 'api.example.com', clientId: 'my-app' })
|
|
83
|
+
expect(Attribution.isMppMemo(memo)).toBe(true)
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
test('returns false for zero memo', () => {
|
|
87
|
+
const zero =
|
|
88
|
+
'0x0000000000000000000000000000000000000000000000000000000000000000' as `0x${string}`
|
|
89
|
+
expect(Attribution.isMppMemo(zero)).toBe(false)
|
|
90
|
+
})
|
|
91
|
+
|
|
92
|
+
test('returns false for arbitrary memo', () => {
|
|
93
|
+
const arbitrary =
|
|
94
|
+
'0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' as `0x${string}`
|
|
95
|
+
expect(Attribution.isMppMemo(arbitrary)).toBe(false)
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
test('returns false for short hex', () => {
|
|
99
|
+
expect(Attribution.isMppMemo('0x1234' as `0x${string}`)).toBe(false)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
test('returns false for wrong version', () => {
|
|
103
|
+
const memo = Attribution.encode({ serverId: 'api.example.com' })
|
|
104
|
+
const wrongVersion = `${memo.slice(0, 10)}ff${memo.slice(12)}` as `0x${string}`
|
|
105
|
+
expect(Attribution.isMppMemo(wrongVersion)).toBe(false)
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
test('handles mixed case hex', () => {
|
|
109
|
+
const memo = Attribution.encode({ serverId: 'api.example.com' })
|
|
110
|
+
const tagUpper = memo.slice(0, 10).toUpperCase()
|
|
111
|
+
const mixed = `0x${tagUpper.slice(2)}${memo.slice(10)}` as `0x${string}`
|
|
112
|
+
expect(Attribution.isMppMemo(mixed)).toBe(true)
|
|
113
|
+
})
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
describe('verifyServer', () => {
|
|
117
|
+
test('returns true for matching serverId', () => {
|
|
118
|
+
const memo = Attribution.encode({ serverId: 'api.example.com' })
|
|
119
|
+
expect(Attribution.verifyServer(memo, 'api.example.com')).toBe(true)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
test('returns true for matching serverId with clientId', () => {
|
|
123
|
+
const memo = Attribution.encode({ serverId: 'api.example.com', clientId: 'my-app' })
|
|
124
|
+
expect(Attribution.verifyServer(memo, 'api.example.com')).toBe(true)
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
test('returns false for wrong serverId', () => {
|
|
128
|
+
const memo = Attribution.encode({ serverId: 'api.example.com' })
|
|
129
|
+
expect(Attribution.verifyServer(memo, 'other.example.com')).toBe(false)
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
test('returns false for non-MPP memo', () => {
|
|
133
|
+
const arbitrary =
|
|
134
|
+
'0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' as `0x${string}`
|
|
135
|
+
expect(Attribution.verifyServer(arbitrary, 'api.example.com')).toBe(false)
|
|
136
|
+
})
|
|
137
|
+
})
|
|
138
|
+
|
|
139
|
+
describe('decode', () => {
|
|
140
|
+
test('decodes an encoded memo with serverId and clientId', () => {
|
|
141
|
+
const memo = Attribution.encode({ serverId: 'api.example.com', clientId: 'my-app' })
|
|
142
|
+
const result = Attribution.decode(memo)
|
|
143
|
+
expect(result).not.toBeNull()
|
|
144
|
+
expect(result!.version).toBe(1)
|
|
145
|
+
expect(result!.serverFingerprint).toMatch(/^0x[0-9a-f]{20}$/i) // 10 bytes = 20 hex chars
|
|
146
|
+
expect(result!.clientFingerprint).toMatch(/^0x[0-9a-f]{20}$/i)
|
|
147
|
+
expect(result!.clientFingerprint).not.toBeNull()
|
|
148
|
+
expect(result!.nonce).toMatch(/^0x[0-9a-f]{14}$/i) // 7 bytes = 14 hex chars
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
test('decodes anonymous client as null', () => {
|
|
152
|
+
const memo = Attribution.encode({ serverId: 'api.example.com' })
|
|
153
|
+
const result = Attribution.decode(memo)
|
|
154
|
+
expect(result).not.toBeNull()
|
|
155
|
+
expect(result!.clientFingerprint).toBeNull()
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
test('returns null for non-MPP memo', () => {
|
|
159
|
+
const arbitrary =
|
|
160
|
+
'0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef' as `0x${string}`
|
|
161
|
+
expect(Attribution.decode(arbitrary)).toBeNull()
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
test('different encodes produce different nonces', () => {
|
|
165
|
+
const a = Attribution.decode(Attribution.encode({ serverId: 'api.example.com' }))
|
|
166
|
+
const b = Attribution.decode(Attribution.encode({ serverId: 'api.example.com' }))
|
|
167
|
+
expect(a!.nonce).not.toBe(b!.nonce)
|
|
168
|
+
})
|
|
169
|
+
|
|
170
|
+
test('serverId fingerprint matches expected keccak hash', () => {
|
|
171
|
+
const memo = Attribution.encode({ serverId: 'api.example.com', clientId: 'my-app' })
|
|
172
|
+
const result = Attribution.decode(memo)!
|
|
173
|
+
const expectedServer = Hex.slice(
|
|
174
|
+
Hash.keccak256(Bytes.fromString('api.example.com'), { as: 'Hex' }),
|
|
175
|
+
0,
|
|
176
|
+
10,
|
|
177
|
+
)
|
|
178
|
+
expect(result.serverFingerprint.toLowerCase()).toBe(expectedServer.toLowerCase())
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
test('returns null for wrong version via decode', () => {
|
|
182
|
+
const memo = Attribution.encode({ serverId: 'api.example.com' })
|
|
183
|
+
const corrupted = `${memo.slice(0, 10)}ff${memo.slice(12)}` as `0x${string}`
|
|
184
|
+
expect(Attribution.decode(corrupted)).toBeNull()
|
|
185
|
+
})
|
|
186
|
+
})
|
|
187
|
+
})
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
import { Bytes, Hash, Hex } from 'ox'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* MPP attribution memo encoding for TIP-20 `transferWithMemo`.
|
|
5
|
+
*
|
|
6
|
+
* When no user-provided memo is present, the SDK auto-generates an
|
|
7
|
+
* attribution memo so MPP transactions are identifiable on-chain.
|
|
8
|
+
*
|
|
9
|
+
* ## Byte Layout (32 bytes)
|
|
10
|
+
*
|
|
11
|
+
* | Offset | Size | Field |
|
|
12
|
+
* |--------|------|-------------------------------------------|
|
|
13
|
+
* | 0..3 | 4 | TAG = keccak256("mpp")[0..3] |
|
|
14
|
+
* | 4 | 1 | version (0x01) |
|
|
15
|
+
* | 5..14 | 10 | serverId = keccak256(serverId)[0..9] |
|
|
16
|
+
* | 15..24 | 10 | clientId = keccak256(clientId)[0..9] or 0s |
|
|
17
|
+
* | 25..31 | 7 | nonce (random bytes) |
|
|
18
|
+
*
|
|
19
|
+
* The TAG prefix makes MPP transactions trivially distinguishable
|
|
20
|
+
* from arbitrary memos via `TransferWithMemo` event topic filtering.
|
|
21
|
+
*
|
|
22
|
+
* @module
|
|
23
|
+
*/
|
|
24
|
+
|
|
25
|
+
/** First 4 bytes of keccak256("mpp") — the on-chain MPP tag. */
|
|
26
|
+
export const tag = Hex.slice(Hash.keccak256(Bytes.fromString('mpp'), { as: 'Hex' }), 0, 4)
|
|
27
|
+
|
|
28
|
+
/** Current memo version. */
|
|
29
|
+
const version = 0x01
|
|
30
|
+
|
|
31
|
+
/** 10 zero bytes representing an anonymous (no clientId) client. */
|
|
32
|
+
export const anonymous = '0x00000000000000000000' as const
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Computes a 10-byte fingerprint from a string via keccak256.
|
|
36
|
+
* @internal
|
|
37
|
+
*/
|
|
38
|
+
function fingerprint(value: string): Uint8Array {
|
|
39
|
+
const hash = Hash.keccak256(Bytes.fromString(value), { as: 'Hex' })
|
|
40
|
+
return Hex.toBytes(Hex.slice(hash, 0, 10))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Encodes an MPP attribution memo as a `bytes32` hex string.
|
|
45
|
+
*
|
|
46
|
+
* @param parameters - The serverId (server identity) and optional clientId.
|
|
47
|
+
* @returns A `0x`-prefixed 64-char hex string (32 bytes).
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* import * as Attribution from './Attribution.js'
|
|
52
|
+
*
|
|
53
|
+
* const memo = Attribution.encode({ serverId: 'api.example.com', clientId: 'my-app' })
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
export function encode(parameters: encode.Parameters) {
|
|
57
|
+
const { serverId, clientId } = parameters
|
|
58
|
+
const buf = new Uint8Array(32)
|
|
59
|
+
|
|
60
|
+
buf.set(Hex.toBytes(tag), 0)
|
|
61
|
+
buf[4] = version
|
|
62
|
+
buf.set(fingerprint(serverId), 5)
|
|
63
|
+
if (clientId) buf.set(fingerprint(clientId), 15)
|
|
64
|
+
|
|
65
|
+
const nonce = crypto.getRandomValues(new Uint8Array(7))
|
|
66
|
+
buf.set(nonce, 25)
|
|
67
|
+
|
|
68
|
+
return Hex.fromBytes(buf)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export declare namespace encode {
|
|
72
|
+
type Parameters = {
|
|
73
|
+
/** Server identity used to derive the server fingerprint. */
|
|
74
|
+
serverId: string
|
|
75
|
+
/** Optional client identity used to derive the client fingerprint. */
|
|
76
|
+
clientId?: string | undefined
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Checks whether a memo was generated by the MPP attribution system.
|
|
82
|
+
*
|
|
83
|
+
* @param memo - A `0x`-prefixed hex string (bytes32).
|
|
84
|
+
* @returns `true` if the memo starts with the MPP tag and version byte.
|
|
85
|
+
*
|
|
86
|
+
* @example
|
|
87
|
+
* ```ts
|
|
88
|
+
* import * as Attribution from './Attribution.js'
|
|
89
|
+
*
|
|
90
|
+
* Attribution.isMppMemo(Attribution.encode({ serverId: 'api.example.com' })) // true
|
|
91
|
+
* Attribution.isMppMemo('0x0000...0000') // false
|
|
92
|
+
* ```
|
|
93
|
+
*/
|
|
94
|
+
export function isMppMemo(memo: `0x${string}`): boolean {
|
|
95
|
+
if (memo.length !== 66) return false
|
|
96
|
+
const memoTag = memo.slice(0, 10) as `0x${string}`
|
|
97
|
+
const memoVersion = Number.parseInt(memo.slice(10, 12), 16)
|
|
98
|
+
return memoTag.toLowerCase() === tag.toLowerCase() && memoVersion === version
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Verifies that a memo's server fingerprint matches the given serverId.
|
|
103
|
+
*
|
|
104
|
+
* Checks TAG, version byte, and that bytes 5–14 equal keccak256(serverId)[0..9].
|
|
105
|
+
*
|
|
106
|
+
* @param memo - A `0x`-prefixed hex string (bytes32).
|
|
107
|
+
* @param serverId - The expected server identity.
|
|
108
|
+
* @returns `true` if the memo has a valid MPP tag and matching server fingerprint.
|
|
109
|
+
*/
|
|
110
|
+
export function verifyServer(memo: `0x${string}`, serverId: string): boolean {
|
|
111
|
+
if (!isMppMemo(memo)) return false
|
|
112
|
+
const memoServerHex = `0x${memo.slice(12, 32)}` as `0x${string}`
|
|
113
|
+
const expectedHex = Hex.fromBytes(fingerprint(serverId)) as `0x${string}`
|
|
114
|
+
return memoServerHex.toLowerCase() === expectedHex.toLowerCase()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Decodes an MPP attribution memo into its constituent parts.
|
|
119
|
+
*
|
|
120
|
+
* @param memo - A `0x`-prefixed hex string (bytes32).
|
|
121
|
+
* @returns The decoded fields, or `null` if the memo is not an MPP memo.
|
|
122
|
+
*
|
|
123
|
+
* @example
|
|
124
|
+
* ```ts
|
|
125
|
+
* import * as Attribution from './Attribution.js'
|
|
126
|
+
*
|
|
127
|
+
* const memo = Attribution.encode({ serverId: 'api.example.com', clientId: 'my-app' })
|
|
128
|
+
* const decoded = Attribution.decode(memo)
|
|
129
|
+
* // { version: 1, serverFingerprint: '0x...', clientFingerprint: '0x...', nonce: '0x...' }
|
|
130
|
+
* ```
|
|
131
|
+
*/
|
|
132
|
+
export function decode(memo: `0x${string}`): decode.Result | null {
|
|
133
|
+
if (!isMppMemo(memo)) return null
|
|
134
|
+
|
|
135
|
+
const memoVersion = Number.parseInt(memo.slice(10, 12), 16)
|
|
136
|
+
const serverFingerprint = `0x${memo.slice(12, 32)}` as `0x${string}`
|
|
137
|
+
const clientHex = `0x${memo.slice(32, 52)}` as `0x${string}`
|
|
138
|
+
const nonce = `0x${memo.slice(52)}` as `0x${string}`
|
|
139
|
+
|
|
140
|
+
const clientFingerprint = clientHex.toLowerCase() === anonymous.toLowerCase() ? null : clientHex
|
|
141
|
+
|
|
142
|
+
return { version: memoVersion, serverFingerprint, clientFingerprint, nonce }
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
export declare namespace decode {
|
|
146
|
+
type Result = {
|
|
147
|
+
/** Memo version (currently always 1). */
|
|
148
|
+
version: number
|
|
149
|
+
/** 10-byte server fingerprint hex (keccak256(serverId)[0..9]). */
|
|
150
|
+
serverFingerprint: `0x${string}`
|
|
151
|
+
/** 10-byte client fingerprint hex, or `null` if anonymous. */
|
|
152
|
+
clientFingerprint: `0x${string}` | null
|
|
153
|
+
/** 7-byte random nonce hex. */
|
|
154
|
+
nonce: `0x${string}`
|
|
155
|
+
}
|
|
156
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { MethodIntents } from 'mppx/tempo'
|
|
2
|
+
import { describe, expect, expectTypeOf, test } from 'vitest'
|
|
3
|
+
|
|
4
|
+
describe('charge', () => {
|
|
5
|
+
test('has correct name and method', () => {
|
|
6
|
+
expect(MethodIntents.charge.name).toBe('charge')
|
|
7
|
+
expect(MethodIntents.charge.method).toBe('tempo')
|
|
8
|
+
})
|
|
9
|
+
|
|
10
|
+
test('types: name is literal', () => {
|
|
11
|
+
expectTypeOf(MethodIntents.charge.name).toEqualTypeOf<'charge'>()
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
test('types: method is literal', () => {
|
|
15
|
+
expectTypeOf(MethodIntents.charge.method).toEqualTypeOf<'tempo'>()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('schema: validates valid request', () => {
|
|
19
|
+
const result = MethodIntents.charge.schema.request.safeParse({
|
|
20
|
+
amount: '1',
|
|
21
|
+
currency: '0x20c0000000000000000000000000000000000001',
|
|
22
|
+
decimals: 6,
|
|
23
|
+
expires: '2025-02-05T12:05:00Z',
|
|
24
|
+
recipient: '0x1234567890abcdef1234567890abcdef12345678',
|
|
25
|
+
})
|
|
26
|
+
expect(result.success).toBe(true)
|
|
27
|
+
})
|
|
28
|
+
|
|
29
|
+
test('schema: validates request with methodDetails', () => {
|
|
30
|
+
const result = MethodIntents.charge.schema.request.safeParse({
|
|
31
|
+
amount: '1',
|
|
32
|
+
currency: '0x20c0000000000000000000000000000000000001',
|
|
33
|
+
decimals: 6,
|
|
34
|
+
expires: '2025-02-05T12:05:00Z',
|
|
35
|
+
chainId: 42431,
|
|
36
|
+
feePayer: true,
|
|
37
|
+
recipient: '0x1234567890abcdef1234567890abcdef12345678',
|
|
38
|
+
})
|
|
39
|
+
expect(result.success).toBe(true)
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
test('schema: validates request with memo', () => {
|
|
43
|
+
const result = MethodIntents.charge.schema.request.safeParse({
|
|
44
|
+
amount: '1',
|
|
45
|
+
currency: '0x20c0000000000000000000000000000000000001',
|
|
46
|
+
decimals: 6,
|
|
47
|
+
expires: '2025-02-05T12:05:00Z',
|
|
48
|
+
memo: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
|
|
49
|
+
recipient: '0x1234567890abcdef1234567890abcdef12345678',
|
|
50
|
+
})
|
|
51
|
+
expect(result.success).toBe(true)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
test('schema: rejects invalid request', () => {
|
|
55
|
+
const result = MethodIntents.charge.schema.request.safeParse({
|
|
56
|
+
amount: '1',
|
|
57
|
+
})
|
|
58
|
+
expect(result.success).toBe(false)
|
|
59
|
+
})
|
|
60
|
+
|
|
61
|
+
test('schema: validates transaction payload', () => {
|
|
62
|
+
const result = MethodIntents.charge.schema.credential.payload.safeParse({
|
|
63
|
+
signature: '0x76f90100000000000000000000000000000000000000000000000000000000000000000000',
|
|
64
|
+
type: 'transaction',
|
|
65
|
+
})
|
|
66
|
+
expect(result.success).toBe(true)
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
test('schema: validates hash payload', () => {
|
|
70
|
+
const result = MethodIntents.charge.schema.credential.payload.safeParse({
|
|
71
|
+
hash: '0x1a2b3c4d5e6f7890abcdef1234567890abcdef1234567890abcdef1234567890',
|
|
72
|
+
type: 'hash',
|
|
73
|
+
})
|
|
74
|
+
expect(result.success).toBe(true)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('schema: rejects invalid payload type', () => {
|
|
78
|
+
const result = MethodIntents.charge.schema.credential.payload.safeParse({
|
|
79
|
+
signature: '0x...',
|
|
80
|
+
type: 'keyAuthorization',
|
|
81
|
+
})
|
|
82
|
+
expect(result.success).toBe(false)
|
|
83
|
+
})
|
|
84
|
+
})
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import type { Account } from 'viem'
|
|
2
|
+
import * as Intent from '../Intent.js'
|
|
3
|
+
import * as MethodIntent from '../MethodIntent.js'
|
|
4
|
+
import * as z from '../zod.js'
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Tempo charge intent for one-time TIP-20 token transfers.
|
|
8
|
+
*
|
|
9
|
+
* @see https://github.com/tempoxyz/payment-auth-spec/blob/main/specs/methods/tempo/draft-tempo-charge-00.md
|
|
10
|
+
*/
|
|
11
|
+
export const charge = MethodIntent.fromIntent(Intent.charge, {
|
|
12
|
+
method: 'tempo',
|
|
13
|
+
schema: {
|
|
14
|
+
credential: {
|
|
15
|
+
payload: z.discriminatedUnion('type', [
|
|
16
|
+
z.object({ hash: z.hash(), type: z.literal('hash') }),
|
|
17
|
+
z.object({ signature: z.signature(), type: z.literal('transaction') }),
|
|
18
|
+
]),
|
|
19
|
+
},
|
|
20
|
+
request: {
|
|
21
|
+
methodDetails: z.object({
|
|
22
|
+
chainId: z.optional(z.number()),
|
|
23
|
+
feePayer: z.optional(
|
|
24
|
+
z.pipe(
|
|
25
|
+
z.union([z.boolean(), z.custom<Account>()]),
|
|
26
|
+
z.transform((v): boolean => (typeof v === 'object' ? true : v)),
|
|
27
|
+
),
|
|
28
|
+
),
|
|
29
|
+
memo: z.optional(z.hash()),
|
|
30
|
+
}),
|
|
31
|
+
requires: ['decimals', 'recipient'],
|
|
32
|
+
},
|
|
33
|
+
},
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Tempo session intent for pay-as-you-go streaming payments.
|
|
38
|
+
*
|
|
39
|
+
* Uses cumulative vouchers over a payment channel. Credential payloads
|
|
40
|
+
* are a discriminated union on `action`: open, topUp, voucher, close.
|
|
41
|
+
*/
|
|
42
|
+
export const session = MethodIntent.fromIntent(Intent.session, {
|
|
43
|
+
method: 'tempo',
|
|
44
|
+
schema: {
|
|
45
|
+
credential: {
|
|
46
|
+
payload: z.discriminatedUnion('action', [
|
|
47
|
+
z.object({
|
|
48
|
+
action: z.literal('open'),
|
|
49
|
+
type: z.literal('transaction'),
|
|
50
|
+
channelId: z.hash(),
|
|
51
|
+
transaction: z.signature(),
|
|
52
|
+
authorizedSigner: z.optional(z.string()),
|
|
53
|
+
cumulativeAmount: z.amount(),
|
|
54
|
+
signature: z.signature(),
|
|
55
|
+
}),
|
|
56
|
+
z.object({
|
|
57
|
+
action: z.literal('topUp'),
|
|
58
|
+
type: z.literal('transaction'),
|
|
59
|
+
channelId: z.hash(),
|
|
60
|
+
transaction: z.signature(),
|
|
61
|
+
additionalDeposit: z.amount(),
|
|
62
|
+
}),
|
|
63
|
+
z.object({
|
|
64
|
+
action: z.literal('voucher'),
|
|
65
|
+
channelId: z.hash(),
|
|
66
|
+
cumulativeAmount: z.amount(),
|
|
67
|
+
signature: z.signature(),
|
|
68
|
+
}),
|
|
69
|
+
z.object({
|
|
70
|
+
action: z.literal('close'),
|
|
71
|
+
channelId: z.hash(),
|
|
72
|
+
cumulativeAmount: z.amount(),
|
|
73
|
+
signature: z.signature(),
|
|
74
|
+
}),
|
|
75
|
+
]),
|
|
76
|
+
},
|
|
77
|
+
request: {
|
|
78
|
+
methodDetails: z.object({
|
|
79
|
+
escrowContract: z.string(),
|
|
80
|
+
channelId: z.optional(z.hash()),
|
|
81
|
+
minVoucherDelta: z.optional(z.amount()),
|
|
82
|
+
chainId: z.optional(z.number()),
|
|
83
|
+
feePayer: z.optional(
|
|
84
|
+
z.pipe(
|
|
85
|
+
z.union([z.boolean(), z.custom<Account>()]),
|
|
86
|
+
z.transform((v): boolean => (typeof v === 'object' ? true : v)),
|
|
87
|
+
),
|
|
88
|
+
),
|
|
89
|
+
}),
|
|
90
|
+
requires: ['decimals', 'recipient', 'currency'],
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
})
|