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,154 @@
|
|
|
1
|
+
import { Base64 } from 'ox'
|
|
2
|
+
import * as Challenge from './Challenge.js'
|
|
3
|
+
import * as PaymentRequest from './PaymentRequest.js'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A payment credential containing the challenge and payment proof.
|
|
7
|
+
*/
|
|
8
|
+
export type Credential<
|
|
9
|
+
payload = unknown,
|
|
10
|
+
challenge extends Challenge.Challenge = Challenge.Challenge,
|
|
11
|
+
> = {
|
|
12
|
+
/** The challenge from the 402 response. */
|
|
13
|
+
challenge: challenge
|
|
14
|
+
/** Method-specific payment proof. */
|
|
15
|
+
payload: payload
|
|
16
|
+
/** Optional payer identifier as a DID (e.g., "did:pkh:eip155:1:0x..."). */
|
|
17
|
+
source?: string
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Deserializes an Authorization header value to a credential.
|
|
22
|
+
*
|
|
23
|
+
* @param header - The Authorization header value.
|
|
24
|
+
* @returns The deserialized credential.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* import { Credential } from 'mppx'
|
|
29
|
+
*
|
|
30
|
+
* const credential = Credential.deserialize(header)
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export function deserialize<payload = unknown>(value: string): Credential<payload> {
|
|
34
|
+
const prefixMatch = value.match(/^Payment\s+(.+)$/i)
|
|
35
|
+
if (!prefixMatch?.[1]) throw new Error('Missing Payment scheme.')
|
|
36
|
+
try {
|
|
37
|
+
const json = Base64.toString(prefixMatch[1])
|
|
38
|
+
const parsed = JSON.parse(json) as {
|
|
39
|
+
challenge: Omit<Challenge.Challenge, 'request'> & { request: string }
|
|
40
|
+
payload: payload
|
|
41
|
+
source?: string
|
|
42
|
+
}
|
|
43
|
+
const challenge = Challenge.Schema.parse({
|
|
44
|
+
...parsed.challenge,
|
|
45
|
+
request: PaymentRequest.deserialize(parsed.challenge.request),
|
|
46
|
+
})
|
|
47
|
+
return {
|
|
48
|
+
challenge,
|
|
49
|
+
payload: parsed.payload,
|
|
50
|
+
...(parsed.source && { source: parsed.source }),
|
|
51
|
+
} as Credential<payload>
|
|
52
|
+
} catch {
|
|
53
|
+
throw new Error('Invalid base64url or JSON.')
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Creates a credential from the given parameters.
|
|
59
|
+
*
|
|
60
|
+
* @param parameters - Credential parameters with a Challenge object.
|
|
61
|
+
* @returns A credential.
|
|
62
|
+
*
|
|
63
|
+
* @example
|
|
64
|
+
* ```ts
|
|
65
|
+
* import { Credential, Challenge } from 'mppx'
|
|
66
|
+
*
|
|
67
|
+
* const credential = Credential.from({
|
|
68
|
+
* challenge,
|
|
69
|
+
* payload: { signature: '0x...' },
|
|
70
|
+
* })
|
|
71
|
+
* ```
|
|
72
|
+
*/
|
|
73
|
+
export function from<const parameters extends from.Parameters>(
|
|
74
|
+
parameters: parameters,
|
|
75
|
+
): Credential<parameters['payload'], parameters['challenge']> {
|
|
76
|
+
const { challenge, payload, source } = parameters
|
|
77
|
+
return {
|
|
78
|
+
challenge,
|
|
79
|
+
payload,
|
|
80
|
+
...(source && { source }),
|
|
81
|
+
} as Credential<parameters['payload'], parameters['challenge']>
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export declare namespace from {
|
|
85
|
+
type Parameters = {
|
|
86
|
+
/** The challenge from the 402 response. */
|
|
87
|
+
challenge: Challenge.Challenge
|
|
88
|
+
/** Method-specific payment proof. */
|
|
89
|
+
payload: unknown
|
|
90
|
+
/** Optional payer identifier as a DID (e.g., "did:pkh:eip155:1:0x..."). */
|
|
91
|
+
source?: string
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Extracts the credential from a Request's Authorization header.
|
|
97
|
+
*
|
|
98
|
+
* @param request - The HTTP request.
|
|
99
|
+
* @returns The deserialized credential.
|
|
100
|
+
*
|
|
101
|
+
* @example
|
|
102
|
+
* ```ts
|
|
103
|
+
* import { Credential } from 'mppx'
|
|
104
|
+
*
|
|
105
|
+
* const credential = Credential.fromRequest(request)
|
|
106
|
+
* ```
|
|
107
|
+
*/
|
|
108
|
+
export function fromRequest<payload = unknown>(request: Request): Credential<payload> {
|
|
109
|
+
const header = request.headers.get('Authorization')
|
|
110
|
+
if (!header) throw new Error('Missing Authorization header.')
|
|
111
|
+
const payment = extractPaymentScheme(header)
|
|
112
|
+
if (!payment) throw new Error('Missing Payment scheme.')
|
|
113
|
+
return deserialize<payload>(payment)
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Serializes a credential to the Authorization header format.
|
|
118
|
+
*
|
|
119
|
+
* @param credential - The credential to serialize.
|
|
120
|
+
* @returns A string suitable for the Authorization header value.
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```ts
|
|
124
|
+
* import { Credential } from 'mppx'
|
|
125
|
+
*
|
|
126
|
+
* const header = Credential.serialize(credential)
|
|
127
|
+
* // => 'Payment eyJjaGFsbGVuZ2UiOnsi...'
|
|
128
|
+
* ```
|
|
129
|
+
*/
|
|
130
|
+
export function serialize(credential: Credential): string {
|
|
131
|
+
const wire = {
|
|
132
|
+
challenge: {
|
|
133
|
+
...credential.challenge,
|
|
134
|
+
request: PaymentRequest.serialize(credential.challenge.request),
|
|
135
|
+
},
|
|
136
|
+
payload: credential.payload,
|
|
137
|
+
...(credential.source && { source: credential.source }),
|
|
138
|
+
}
|
|
139
|
+
const json = JSON.stringify(wire)
|
|
140
|
+
const encoded = Base64.fromString(json, { pad: false, url: true })
|
|
141
|
+
return `Payment ${encoded}`
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Extracts the `Payment` scheme from an Authorization header value
|
|
146
|
+
* that may contain multiple schemes (comma-separated per RFC 9110).
|
|
147
|
+
*
|
|
148
|
+
* @param header - The raw Authorization header value.
|
|
149
|
+
* @returns The `Payment ...` scheme string, or `null` if not found.
|
|
150
|
+
*/
|
|
151
|
+
export function extractPaymentScheme(header: string): string | null {
|
|
152
|
+
const schemes = header.split(',').map((s) => s.trim())
|
|
153
|
+
return schemes.find((s) => /^Payment\s+/i.test(s)) ?? null
|
|
154
|
+
}
|
|
@@ -0,0 +1,402 @@
|
|
|
1
|
+
import { describe, expect, test } from 'vitest'
|
|
2
|
+
import {
|
|
3
|
+
AmountExceedsDepositError,
|
|
4
|
+
BadRequestError,
|
|
5
|
+
ChannelClosedError,
|
|
6
|
+
ChannelNotFoundError,
|
|
7
|
+
DeltaTooSmallError,
|
|
8
|
+
InsufficientBalanceError,
|
|
9
|
+
InvalidChallengeError,
|
|
10
|
+
InvalidPayloadError,
|
|
11
|
+
InvalidSignatureError,
|
|
12
|
+
MalformedCredentialError,
|
|
13
|
+
PaymentExpiredError,
|
|
14
|
+
PaymentRequiredError,
|
|
15
|
+
SignerMismatchError,
|
|
16
|
+
VerificationFailedError,
|
|
17
|
+
} from './Errors.js'
|
|
18
|
+
|
|
19
|
+
function errorSnapshot(error: Error & { type: string; status: number }) {
|
|
20
|
+
return {
|
|
21
|
+
name: error.name,
|
|
22
|
+
message: error.message,
|
|
23
|
+
type: error.type,
|
|
24
|
+
status: error.status,
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
describe('MalformedCredentialError', () => {
|
|
29
|
+
test('default', () => {
|
|
30
|
+
expect(errorSnapshot(new MalformedCredentialError())).toMatchInlineSnapshot(`
|
|
31
|
+
{
|
|
32
|
+
"message": "Credential is malformed.",
|
|
33
|
+
"name": "MalformedCredentialError",
|
|
34
|
+
"status": 402,
|
|
35
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/malformed-credential",
|
|
36
|
+
}
|
|
37
|
+
`)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
test('with reason', () => {
|
|
41
|
+
expect(
|
|
42
|
+
errorSnapshot(new MalformedCredentialError({ reason: 'invalid base64url' })),
|
|
43
|
+
).toMatchInlineSnapshot(`
|
|
44
|
+
{
|
|
45
|
+
"message": "Credential is malformed: invalid base64url.",
|
|
46
|
+
"name": "MalformedCredentialError",
|
|
47
|
+
"status": 402,
|
|
48
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/malformed-credential",
|
|
49
|
+
}
|
|
50
|
+
`)
|
|
51
|
+
})
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
describe('InvalidChallengeError', () => {
|
|
55
|
+
test('default', () => {
|
|
56
|
+
expect(errorSnapshot(new InvalidChallengeError())).toMatchInlineSnapshot(`
|
|
57
|
+
{
|
|
58
|
+
"message": "Challenge is invalid.",
|
|
59
|
+
"name": "InvalidChallengeError",
|
|
60
|
+
"status": 402,
|
|
61
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/invalid-challenge",
|
|
62
|
+
}
|
|
63
|
+
`)
|
|
64
|
+
})
|
|
65
|
+
|
|
66
|
+
test('with id', () => {
|
|
67
|
+
expect(errorSnapshot(new InvalidChallengeError({ id: 'abc123' }))).toMatchInlineSnapshot(`
|
|
68
|
+
{
|
|
69
|
+
"message": "Challenge "abc123" is invalid.",
|
|
70
|
+
"name": "InvalidChallengeError",
|
|
71
|
+
"status": 402,
|
|
72
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/invalid-challenge",
|
|
73
|
+
}
|
|
74
|
+
`)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
test('with reason', () => {
|
|
78
|
+
expect(errorSnapshot(new InvalidChallengeError({ reason: 'expired' }))).toMatchInlineSnapshot(`
|
|
79
|
+
{
|
|
80
|
+
"message": "Challenge is invalid: expired.",
|
|
81
|
+
"name": "InvalidChallengeError",
|
|
82
|
+
"status": 402,
|
|
83
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/invalid-challenge",
|
|
84
|
+
}
|
|
85
|
+
`)
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
test('with id and reason', () => {
|
|
89
|
+
expect(
|
|
90
|
+
errorSnapshot(new InvalidChallengeError({ id: 'abc123', reason: 'already used' })),
|
|
91
|
+
).toMatchInlineSnapshot(`
|
|
92
|
+
{
|
|
93
|
+
"message": "Challenge "abc123" is invalid: already used.",
|
|
94
|
+
"name": "InvalidChallengeError",
|
|
95
|
+
"status": 402,
|
|
96
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/invalid-challenge",
|
|
97
|
+
}
|
|
98
|
+
`)
|
|
99
|
+
})
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
describe('VerificationFailedError', () => {
|
|
103
|
+
test('default', () => {
|
|
104
|
+
expect(errorSnapshot(new VerificationFailedError())).toMatchInlineSnapshot(`
|
|
105
|
+
{
|
|
106
|
+
"message": "Payment verification failed.",
|
|
107
|
+
"name": "VerificationFailedError",
|
|
108
|
+
"status": 402,
|
|
109
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/verification-failed",
|
|
110
|
+
}
|
|
111
|
+
`)
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
test('with reason', () => {
|
|
115
|
+
expect(
|
|
116
|
+
errorSnapshot(new VerificationFailedError({ reason: 'invalid signature' })),
|
|
117
|
+
).toMatchInlineSnapshot(`
|
|
118
|
+
{
|
|
119
|
+
"message": "Payment verification failed: invalid signature.",
|
|
120
|
+
"name": "VerificationFailedError",
|
|
121
|
+
"status": 402,
|
|
122
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/verification-failed",
|
|
123
|
+
}
|
|
124
|
+
`)
|
|
125
|
+
})
|
|
126
|
+
})
|
|
127
|
+
|
|
128
|
+
describe('PaymentExpiredError', () => {
|
|
129
|
+
test('default', () => {
|
|
130
|
+
expect(errorSnapshot(new PaymentExpiredError())).toMatchInlineSnapshot(`
|
|
131
|
+
{
|
|
132
|
+
"message": "Payment has expired.",
|
|
133
|
+
"name": "PaymentExpiredError",
|
|
134
|
+
"status": 402,
|
|
135
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/payment-expired",
|
|
136
|
+
}
|
|
137
|
+
`)
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
test('with expires', () => {
|
|
141
|
+
expect(
|
|
142
|
+
errorSnapshot(new PaymentExpiredError({ expires: '2025-01-26T12:00:00Z' })),
|
|
143
|
+
).toMatchInlineSnapshot(`
|
|
144
|
+
{
|
|
145
|
+
"message": "Payment expired at 2025-01-26T12:00:00Z.",
|
|
146
|
+
"name": "PaymentExpiredError",
|
|
147
|
+
"status": 402,
|
|
148
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/payment-expired",
|
|
149
|
+
}
|
|
150
|
+
`)
|
|
151
|
+
})
|
|
152
|
+
})
|
|
153
|
+
|
|
154
|
+
describe('PaymentRequiredError', () => {
|
|
155
|
+
test('default', () => {
|
|
156
|
+
expect(errorSnapshot(new PaymentRequiredError())).toMatchInlineSnapshot(`
|
|
157
|
+
{
|
|
158
|
+
"message": "Payment is required.",
|
|
159
|
+
"name": "PaymentRequiredError",
|
|
160
|
+
"status": 402,
|
|
161
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/payment-required",
|
|
162
|
+
}
|
|
163
|
+
`)
|
|
164
|
+
})
|
|
165
|
+
|
|
166
|
+
test('with realm', () => {
|
|
167
|
+
expect(
|
|
168
|
+
errorSnapshot(new PaymentRequiredError({ realm: 'api.example.com' })),
|
|
169
|
+
).toMatchInlineSnapshot(`
|
|
170
|
+
{
|
|
171
|
+
"message": "Payment is required for "api.example.com".",
|
|
172
|
+
"name": "PaymentRequiredError",
|
|
173
|
+
"status": 402,
|
|
174
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/payment-required",
|
|
175
|
+
}
|
|
176
|
+
`)
|
|
177
|
+
})
|
|
178
|
+
|
|
179
|
+
test('with realm and description', () => {
|
|
180
|
+
expect(
|
|
181
|
+
errorSnapshot(
|
|
182
|
+
new PaymentRequiredError({ realm: 'api.example.com', description: 'API access fee' }),
|
|
183
|
+
),
|
|
184
|
+
).toMatchInlineSnapshot(`
|
|
185
|
+
{
|
|
186
|
+
"message": "Payment is required for "api.example.com" (API access fee).",
|
|
187
|
+
"name": "PaymentRequiredError",
|
|
188
|
+
"status": 402,
|
|
189
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/payment-required",
|
|
190
|
+
}
|
|
191
|
+
`)
|
|
192
|
+
})
|
|
193
|
+
})
|
|
194
|
+
|
|
195
|
+
describe('InvalidPayloadError', () => {
|
|
196
|
+
test('default', () => {
|
|
197
|
+
expect(errorSnapshot(new InvalidPayloadError())).toMatchInlineSnapshot(`
|
|
198
|
+
{
|
|
199
|
+
"message": "Credential payload is invalid.",
|
|
200
|
+
"name": "InvalidPayloadError",
|
|
201
|
+
"status": 402,
|
|
202
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/invalid-payload",
|
|
203
|
+
}
|
|
204
|
+
`)
|
|
205
|
+
})
|
|
206
|
+
|
|
207
|
+
test('with reason', () => {
|
|
208
|
+
expect(
|
|
209
|
+
errorSnapshot(new InvalidPayloadError({ reason: 'missing signature field' })),
|
|
210
|
+
).toMatchInlineSnapshot(`
|
|
211
|
+
{
|
|
212
|
+
"message": "Credential payload is invalid: missing signature field.",
|
|
213
|
+
"name": "InvalidPayloadError",
|
|
214
|
+
"status": 402,
|
|
215
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/invalid-payload",
|
|
216
|
+
}
|
|
217
|
+
`)
|
|
218
|
+
})
|
|
219
|
+
})
|
|
220
|
+
|
|
221
|
+
describe('BadRequestError', () => {
|
|
222
|
+
test('default', () => {
|
|
223
|
+
expect(errorSnapshot(new BadRequestError())).toMatchInlineSnapshot(`
|
|
224
|
+
{
|
|
225
|
+
"message": "Bad request.",
|
|
226
|
+
"name": "BadRequestError",
|
|
227
|
+
"status": 400,
|
|
228
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/bad-request",
|
|
229
|
+
}
|
|
230
|
+
`)
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
test('with reason', () => {
|
|
234
|
+
expect(
|
|
235
|
+
errorSnapshot(new BadRequestError({ reason: 'cannot combine hash type with feePayer' })),
|
|
236
|
+
).toMatchInlineSnapshot(`
|
|
237
|
+
{
|
|
238
|
+
"message": "Bad request: cannot combine hash type with feePayer.",
|
|
239
|
+
"name": "BadRequestError",
|
|
240
|
+
"status": 400,
|
|
241
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/bad-request",
|
|
242
|
+
}
|
|
243
|
+
`)
|
|
244
|
+
})
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
describe('InsufficientBalanceError', () => {
|
|
248
|
+
test('default', () => {
|
|
249
|
+
expect(errorSnapshot(new InsufficientBalanceError())).toMatchInlineSnapshot(`
|
|
250
|
+
{
|
|
251
|
+
"message": "Insufficient balance.",
|
|
252
|
+
"name": "InsufficientBalanceError",
|
|
253
|
+
"status": 402,
|
|
254
|
+
"type": "https://paymentauth.org/problems/stream/insufficient-balance",
|
|
255
|
+
}
|
|
256
|
+
`)
|
|
257
|
+
})
|
|
258
|
+
|
|
259
|
+
test('with reason', () => {
|
|
260
|
+
expect(
|
|
261
|
+
errorSnapshot(new InsufficientBalanceError({ reason: 'requested 500, available 100' })),
|
|
262
|
+
).toMatchInlineSnapshot(`
|
|
263
|
+
{
|
|
264
|
+
"message": "Insufficient balance: requested 500, available 100.",
|
|
265
|
+
"name": "InsufficientBalanceError",
|
|
266
|
+
"status": 402,
|
|
267
|
+
"type": "https://paymentauth.org/problems/stream/insufficient-balance",
|
|
268
|
+
}
|
|
269
|
+
`)
|
|
270
|
+
})
|
|
271
|
+
})
|
|
272
|
+
|
|
273
|
+
describe('InvalidSignatureError', () => {
|
|
274
|
+
test('default', () => {
|
|
275
|
+
expect(errorSnapshot(new InvalidSignatureError())).toMatchInlineSnapshot(`
|
|
276
|
+
{
|
|
277
|
+
"message": "Invalid signature.",
|
|
278
|
+
"name": "InvalidSignatureError",
|
|
279
|
+
"status": 402,
|
|
280
|
+
"type": "https://paymentauth.org/problems/stream/invalid-signature",
|
|
281
|
+
}
|
|
282
|
+
`)
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
test('with reason', () => {
|
|
286
|
+
expect(
|
|
287
|
+
errorSnapshot(new InvalidSignatureError({ reason: 'ECDSA recovery failed' })),
|
|
288
|
+
).toMatchInlineSnapshot(`
|
|
289
|
+
{
|
|
290
|
+
"message": "Invalid signature: ECDSA recovery failed.",
|
|
291
|
+
"name": "InvalidSignatureError",
|
|
292
|
+
"status": 402,
|
|
293
|
+
"type": "https://paymentauth.org/problems/stream/invalid-signature",
|
|
294
|
+
}
|
|
295
|
+
`)
|
|
296
|
+
})
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
describe('SignerMismatchError', () => {
|
|
300
|
+
test('default', () => {
|
|
301
|
+
expect(errorSnapshot(new SignerMismatchError())).toMatchInlineSnapshot(`
|
|
302
|
+
{
|
|
303
|
+
"message": "Signer is not authorized for this channel.",
|
|
304
|
+
"name": "SignerMismatchError",
|
|
305
|
+
"status": 402,
|
|
306
|
+
"type": "https://paymentauth.org/problems/stream/signer-mismatch",
|
|
307
|
+
}
|
|
308
|
+
`)
|
|
309
|
+
})
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
describe('AmountExceedsDepositError', () => {
|
|
313
|
+
test('default', () => {
|
|
314
|
+
expect(errorSnapshot(new AmountExceedsDepositError())).toMatchInlineSnapshot(`
|
|
315
|
+
{
|
|
316
|
+
"message": "Voucher amount exceeds channel deposit.",
|
|
317
|
+
"name": "AmountExceedsDepositError",
|
|
318
|
+
"status": 402,
|
|
319
|
+
"type": "https://paymentauth.org/problems/stream/amount-exceeds-deposit",
|
|
320
|
+
}
|
|
321
|
+
`)
|
|
322
|
+
})
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
describe('DeltaTooSmallError', () => {
|
|
326
|
+
test('default', () => {
|
|
327
|
+
expect(errorSnapshot(new DeltaTooSmallError())).toMatchInlineSnapshot(`
|
|
328
|
+
{
|
|
329
|
+
"message": "Amount increase below minimum voucher delta.",
|
|
330
|
+
"name": "DeltaTooSmallError",
|
|
331
|
+
"status": 402,
|
|
332
|
+
"type": "https://paymentauth.org/problems/stream/delta-too-small",
|
|
333
|
+
}
|
|
334
|
+
`)
|
|
335
|
+
})
|
|
336
|
+
})
|
|
337
|
+
|
|
338
|
+
describe('ChannelNotFoundError', () => {
|
|
339
|
+
test('default', () => {
|
|
340
|
+
expect(errorSnapshot(new ChannelNotFoundError())).toMatchInlineSnapshot(`
|
|
341
|
+
{
|
|
342
|
+
"message": "No channel with this ID exists.",
|
|
343
|
+
"name": "ChannelNotFoundError",
|
|
344
|
+
"status": 410,
|
|
345
|
+
"type": "https://paymentauth.org/problems/stream/channel-not-found",
|
|
346
|
+
}
|
|
347
|
+
`)
|
|
348
|
+
})
|
|
349
|
+
})
|
|
350
|
+
|
|
351
|
+
describe('ChannelClosedError', () => {
|
|
352
|
+
test('default', () => {
|
|
353
|
+
expect(errorSnapshot(new ChannelClosedError())).toMatchInlineSnapshot(`
|
|
354
|
+
{
|
|
355
|
+
"message": "Channel is closed.",
|
|
356
|
+
"name": "ChannelClosedError",
|
|
357
|
+
"status": 410,
|
|
358
|
+
"type": "https://paymentauth.org/problems/stream/channel-finalized",
|
|
359
|
+
}
|
|
360
|
+
`)
|
|
361
|
+
})
|
|
362
|
+
|
|
363
|
+
test('with reason', () => {
|
|
364
|
+
expect(
|
|
365
|
+
errorSnapshot(new ChannelClosedError({ reason: 'channel is finalized on-chain' })),
|
|
366
|
+
).toMatchInlineSnapshot(`
|
|
367
|
+
{
|
|
368
|
+
"message": "Channel closed: channel is finalized on-chain.",
|
|
369
|
+
"name": "ChannelClosedError",
|
|
370
|
+
"status": 410,
|
|
371
|
+
"type": "https://paymentauth.org/problems/stream/channel-finalized",
|
|
372
|
+
}
|
|
373
|
+
`)
|
|
374
|
+
})
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
describe('toProblemDetails', () => {
|
|
378
|
+
test('without challengeId', () => {
|
|
379
|
+
const error = new MalformedCredentialError({ reason: 'invalid JSON' })
|
|
380
|
+
expect(error.toProblemDetails()).toMatchInlineSnapshot(`
|
|
381
|
+
{
|
|
382
|
+
"detail": "Credential is malformed: invalid JSON.",
|
|
383
|
+
"status": 402,
|
|
384
|
+
"title": "MalformedCredentialError",
|
|
385
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/malformed-credential",
|
|
386
|
+
}
|
|
387
|
+
`)
|
|
388
|
+
})
|
|
389
|
+
|
|
390
|
+
test('with challengeId', () => {
|
|
391
|
+
const error = new InvalidChallengeError({ id: 'abc123', reason: 'expired' })
|
|
392
|
+
expect(error.toProblemDetails('abc123')).toMatchInlineSnapshot(`
|
|
393
|
+
{
|
|
394
|
+
"challengeId": "abc123",
|
|
395
|
+
"detail": "Challenge "abc123" is invalid: expired.",
|
|
396
|
+
"status": 402,
|
|
397
|
+
"title": "InvalidChallengeError",
|
|
398
|
+
"type": "https://tempoxyz.github.io/payment-auth-spec/problems/invalid-challenge",
|
|
399
|
+
}
|
|
400
|
+
`)
|
|
401
|
+
})
|
|
402
|
+
})
|