mppx 0.8.15 → 0.8.18
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/CHANGELOG.md +91 -0
- package/README.md +15 -0
- package/dist/Challenge.js +61 -39
- package/dist/Constants.d.ts +17 -17
- package/dist/Errors.d.ts +3 -3
- package/dist/Method.d.ts +35 -5
- package/dist/Method.js +7 -22
- package/dist/Store.d.ts +19 -0
- package/dist/Store.js +43 -0
- package/dist/attestation/Client.d.ts +17 -0
- package/dist/attestation/Client.js +28 -0
- package/dist/attestation/Constants.d.ts +15 -0
- package/dist/attestation/Constants.js +15 -0
- package/dist/attestation/Server.d.ts +4 -0
- package/dist/attestation/Server.js +8 -0
- package/dist/attestation/Types.d.ts +76 -0
- package/dist/attestation/Types.js +2 -0
- package/dist/attestation/index.d.ts +6 -0
- package/dist/attestation/index.js +6 -0
- package/dist/attestation/internal/HttpMessageSignature.d.ts +73 -0
- package/dist/attestation/internal/HttpMessageSignature.js +320 -0
- package/dist/attestation/internal/SigningContext.d.ts +4 -0
- package/dist/attestation/internal/SigningContext.js +11 -0
- package/dist/bin.js +3 -3
- package/dist/cli/THIRD-PARTY-LICENSES.txt +328 -0
- package/dist/cli/account.d.ts +14 -14
- package/dist/cli/cli.d.ts +6 -6
- package/dist/cli/cli.js +253 -1504
- package/dist/cli/plugins/index.js +19 -5
- package/dist/cli/plugins/tempo.js +7 -3
- package/dist/cli/sessions/Manager.js +7 -4
- package/dist/cli/sessions/commands.d.ts +4 -4
- package/dist/cli/sessions/request.d.ts +2 -0
- package/dist/cli/sessions/request.js +18 -0
- package/dist/cli/sessions/store.js +28 -14
- package/dist/cli/utils.d.ts +1 -1
- package/dist/cli/validate/index.d.ts +3 -3
- package/dist/client/Mppx.d.ts +3 -0
- package/dist/client/Mppx.js +13 -5
- package/dist/client/Transport.d.ts +3 -5
- package/dist/client/Transport.js +1 -17
- package/dist/client/internal/Fetch.js +2 -6
- package/dist/discovery/Discovery.js +2 -1
- package/dist/discovery/OpenApi.d.ts +3 -5
- package/dist/discovery/OpenApi.js +13 -34
- package/dist/discovery/internal/Metadata.d.ts +20 -0
- package/dist/discovery/internal/Metadata.js +36 -0
- package/dist/evm/Methods.d.ts +11 -11
- package/dist/evm/Types.d.ts +17 -17
- package/dist/evm/client/Charge.d.ts +11 -11
- package/dist/evm/client/Charge.js +8 -0
- package/dist/evm/client/Methods.d.ts +11 -11
- package/dist/evm/server/Charge.d.ts +1 -1
- package/dist/evm/server/Charge.js +2 -0
- package/dist/evm/server/Methods.d.ts +11 -11
- package/dist/internal/HeaderCodec.d.ts +2 -2
- package/dist/internal/types.d.ts +6 -0
- package/dist/proxy/Proxy.d.ts +2 -0
- package/dist/proxy/Proxy.js +117 -9
- package/dist/proxy/Service.d.ts +36 -1
- package/dist/proxy/Service.js +9 -8
- package/dist/proxy/services/anthropic.js +1 -0
- package/dist/proxy/services/openai.js +1 -0
- package/dist/proxy/services/stripe.js +1 -0
- package/dist/server/Mppx.d.ts +75 -13
- package/dist/server/Mppx.js +201 -23
- package/dist/server/core.d.ts +9 -0
- package/dist/server/core.js +9 -0
- package/dist/server/internal/html/config.d.ts +9 -9
- package/dist/server/internal/html/constants.d.ts +17 -17
- package/dist/stripe/Methods.d.ts +10 -10
- package/dist/stripe/client/Charge.d.ts +10 -10
- package/dist/stripe/client/Methods.d.ts +10 -10
- package/dist/stripe/internal/constants.d.ts +1 -1
- package/dist/stripe/internal/constants.js +1 -1
- package/dist/stripe/internal/types.d.ts +1 -0
- package/dist/stripe/server/Charge.d.ts +11 -11
- package/dist/stripe/server/Charge.js +51 -5
- package/dist/stripe/server/Methods.d.ts +137 -48
- package/dist/stripe/server/Methods.js +265 -4
- package/dist/stripe/server/internal/deposit-address.d.ts +13 -0
- package/dist/stripe/server/internal/deposit-address.js +28 -0
- package/dist/stripe/server/internal/html.gen.d.ts +1 -1
- package/dist/stripe/server/internal/html.gen.js +1 -1
- package/dist/stripe/server/internal/record-payment.d.ts +15 -0
- package/dist/stripe/server/internal/record-payment.js +42 -0
- package/dist/stripe/server/internal/request.d.ts +25 -0
- package/dist/stripe/server/internal/request.js +29 -0
- package/dist/stripe/server/spt.d.ts +8 -0
- package/dist/stripe/server/spt.js +8 -0
- package/dist/tap/Constants.d.ts +28 -0
- package/dist/tap/Constants.js +32 -0
- package/dist/tap/Types.d.ts +11 -0
- package/dist/tap/Types.js +2 -0
- package/dist/tap/client/index.d.ts +26 -0
- package/dist/tap/client/index.js +33 -0
- package/dist/tap/index.d.ts +5 -0
- package/dist/tap/index.js +5 -0
- package/dist/tap/server/index.d.ts +20 -0
- package/dist/tap/server/index.js +36 -0
- package/dist/tempo/Attribution.d.ts +1 -1
- package/dist/tempo/Methods.d.ts +73 -60
- package/dist/tempo/Methods.js +14 -3
- package/dist/tempo/Proof.d.ts +16 -16
- package/dist/tempo/client/Charge.d.ts +22 -19
- package/dist/tempo/client/Charge.js +32 -16
- package/dist/tempo/client/Methods.d.ts +51 -38
- package/dist/tempo/client/Subscription.d.ts +23 -23
- package/dist/tempo/internal/address.d.ts +2 -1
- package/dist/tempo/internal/address.js +3 -1
- package/dist/tempo/internal/auto-swap.js +4 -19
- package/dist/tempo/internal/defaults.d.ts +17 -6
- package/dist/tempo/internal/defaults.js +11 -0
- package/dist/tempo/internal/fee-payer.d.ts +12 -12
- package/dist/tempo/internal/machine-token-charge.d.ts +51 -0
- package/dist/tempo/internal/machine-token-charge.js +113 -0
- package/dist/tempo/internal/machine-token-session.d.ts +88 -0
- package/dist/tempo/internal/machine-token-session.js +173 -0
- package/dist/tempo/internal/proof.d.ts +17 -17
- package/dist/tempo/internal/signature-envelope.d.ts +14 -0
- package/dist/tempo/internal/signature-envelope.js +28 -0
- package/dist/tempo/legacy/client/ChannelOps.d.ts +2 -2
- package/dist/tempo/legacy/client/ChannelOps.js +11 -5
- package/dist/tempo/legacy/client/Session.d.ts +33 -21
- package/dist/tempo/legacy/client/Session.js +3 -3
- package/dist/tempo/legacy/client/SessionManager.d.ts +3 -1
- package/dist/tempo/legacy/client/SessionManager.js +2 -0
- package/dist/tempo/legacy/index.d.ts +1 -3
- package/dist/tempo/legacy/index.js +1 -3
- package/dist/tempo/legacy/session/escrow.abi.d.ts +374 -374
- package/dist/tempo/server/Charge.d.ts +28 -11
- package/dist/tempo/server/Charge.js +101 -55
- package/dist/tempo/server/Methods.d.ts +58 -56
- package/dist/tempo/server/Methods.js +8 -18
- package/dist/tempo/server/Relay.d.ts +1 -1
- package/dist/tempo/server/Relay.js +2 -2
- package/dist/tempo/server/Subscription.d.ts +25 -25
- package/dist/tempo/server/Subscription.js +2 -0
- package/dist/tempo/server/index.d.ts +1 -1
- package/dist/tempo/server/index.js +1 -1
- package/dist/tempo/server/internal/html.gen.d.ts +1 -1
- package/dist/tempo/server/internal/html.gen.js +1 -1
- package/dist/tempo/server/internal/transport.d.ts +2 -0
- package/dist/tempo/server/internal/transport.js +9 -2
- package/dist/tempo/session/client/ChannelOps.d.ts +18 -3
- package/dist/tempo/session/client/ChannelOps.js +35 -6
- package/dist/tempo/session/client/ChannelStore.d.ts +0 -5
- package/dist/tempo/session/client/ChannelStore.js +2 -2
- package/dist/tempo/session/client/CredentialState.d.ts +18 -3
- package/dist/tempo/session/client/CredentialState.js +77 -76
- package/dist/tempo/session/client/Runtime.d.ts +4 -2
- package/dist/tempo/session/client/Runtime.js +21 -5
- package/dist/tempo/session/client/Session.d.ts +34 -22
- package/dist/tempo/session/client/Session.js +186 -63
- package/dist/tempo/session/client/SessionManager.d.ts +3 -1
- package/dist/tempo/session/client/SessionManager.js +35 -11
- package/dist/tempo/session/client/Transports.d.ts +2 -0
- package/dist/tempo/session/client/Transports.js +12 -2
- package/dist/tempo/session/precompile/Chain.d.ts +37 -2
- package/dist/tempo/session/precompile/Chain.js +116 -15
- package/dist/tempo/session/precompile/Protocol.d.ts +15 -0
- package/dist/tempo/session/precompile/Protocol.js +7 -0
- package/dist/tempo/session/precompile/Voucher.d.ts +7 -5
- package/dist/tempo/session/precompile/Voucher.js +6 -12
- package/dist/tempo/session/precompile/escrow.abi.d.ts +306 -306
- package/dist/tempo/session/server/ChannelStore.d.ts +15 -0
- package/dist/tempo/session/server/ChannelStore.js +27 -12
- package/dist/tempo/session/server/CredentialVerification.d.ts +39 -20
- package/dist/tempo/session/server/CredentialVerification.js +359 -89
- package/dist/tempo/session/server/MeteredStream.d.ts +4 -1
- package/dist/tempo/session/server/MeteredStream.js +8 -5
- package/dist/tempo/session/server/RequestState.d.ts +19 -0
- package/dist/tempo/session/server/RequestState.js +61 -15
- package/dist/tempo/session/server/Session.d.ts +46 -23
- package/dist/tempo/session/server/Session.js +150 -56
- package/dist/tempo/session/server/Settlement.d.ts +11 -4
- package/dist/tempo/session/server/Settlement.js +53 -21
- package/dist/tempo/session/server/Sse.d.ts +3 -1
- package/dist/tempo/session/server/Sse.js +2 -1
- package/dist/tempo/session/server/Transports.d.ts +1 -1
- package/dist/tempo/session/server/Transports.js +1 -0
- package/dist/tempo/session/server/Ws.d.ts +6 -1
- package/dist/tempo/session/server/Ws.js +1 -0
- package/dist/tempo/subscription/KeyAuthorization.d.ts +39 -39
- package/dist/web-bot-auth/Constants.d.ts +20 -0
- package/dist/web-bot-auth/Constants.js +24 -0
- package/dist/web-bot-auth/Types.d.ts +10 -0
- package/dist/web-bot-auth/Types.js +2 -0
- package/dist/web-bot-auth/client/index.d.ts +29 -0
- package/dist/web-bot-auth/client/index.js +64 -0
- package/dist/web-bot-auth/index.d.ts +7 -0
- package/dist/web-bot-auth/index.js +7 -0
- package/dist/web-bot-auth/internal/JwkThumbprint.d.ts +5 -0
- package/dist/web-bot-auth/internal/JwkThumbprint.js +20 -0
- package/dist/web-bot-auth/internal/SignatureAgent.d.ts +3 -0
- package/dist/web-bot-auth/internal/SignatureAgent.js +18 -0
- package/dist/web-bot-auth/server/index.d.ts +35 -0
- package/dist/web-bot-auth/server/index.js +88 -0
- package/dist/x402/Types.d.ts +6 -6
- package/dist/x402/client/Exact.d.ts +8 -0
- package/dist/x402/client/Exact.js +40 -10
- package/dist/x402/server/EvmCharge.d.ts +22 -0
- package/dist/x402/server/EvmCharge.js +54 -20
- package/package.json +28 -34
- package/dist/BodyDigest.d.ts.map +0 -1
- package/dist/BodyDigest.js.map +0 -1
- package/dist/Challenge.d.ts.map +0 -1
- package/dist/Challenge.js.map +0 -1
- package/dist/Constants.d.ts.map +0 -1
- package/dist/Constants.js.map +0 -1
- package/dist/Credential.d.ts.map +0 -1
- package/dist/Credential.js.map +0 -1
- package/dist/Errors.d.ts.map +0 -1
- package/dist/Errors.js.map +0 -1
- package/dist/Expires.d.ts.map +0 -1
- package/dist/Expires.js.map +0 -1
- package/dist/Html.d.ts.map +0 -1
- package/dist/Html.js.map +0 -1
- package/dist/Mcp.d.ts.map +0 -1
- package/dist/Mcp.js.map +0 -1
- package/dist/Method.d.ts.map +0 -1
- package/dist/Method.js.map +0 -1
- package/dist/PaymentRequest.d.ts.map +0 -1
- package/dist/PaymentRequest.js.map +0 -1
- package/dist/Receipt.d.ts.map +0 -1
- package/dist/Receipt.js.map +0 -1
- package/dist/Store.d.ts.map +0 -1
- package/dist/Store.js.map +0 -1
- package/dist/bin.d.ts.map +0 -1
- package/dist/bin.js.map +0 -1
- package/dist/cli/account.d.ts.map +0 -1
- package/dist/cli/account.js.map +0 -1
- package/dist/cli/cli.d.ts.map +0 -1
- package/dist/cli/cli.js.map +0 -1
- package/dist/cli/config.d.ts.map +0 -1
- package/dist/cli/config.js.map +0 -1
- package/dist/cli/internal.d.ts.map +0 -1
- package/dist/cli/internal.js.map +0 -1
- package/dist/cli/plugins/evm.d.ts.map +0 -1
- package/dist/cli/plugins/evm.js.map +0 -1
- package/dist/cli/plugins/index.d.ts.map +0 -1
- package/dist/cli/plugins/index.js.map +0 -1
- package/dist/cli/plugins/plugin.d.ts.map +0 -1
- package/dist/cli/plugins/plugin.js.map +0 -1
- package/dist/cli/plugins/stripe.d.ts.map +0 -1
- package/dist/cli/plugins/stripe.js.map +0 -1
- package/dist/cli/plugins/tempo.d.ts.map +0 -1
- package/dist/cli/plugins/tempo.js.map +0 -1
- package/dist/cli/sessions/Manager.d.ts.map +0 -1
- package/dist/cli/sessions/Manager.js.map +0 -1
- package/dist/cli/sessions/commands.d.ts.map +0 -1
- package/dist/cli/sessions/commands.js.map +0 -1
- package/dist/cli/sessions/request.d.ts.map +0 -1
- package/dist/cli/sessions/request.js.map +0 -1
- package/dist/cli/sessions/store.d.ts.map +0 -1
- package/dist/cli/sessions/store.js.map +0 -1
- package/dist/cli/utils.d.ts.map +0 -1
- package/dist/cli/utils.js.map +0 -1
- package/dist/cli/validate/challenge.d.ts.map +0 -1
- package/dist/cli/validate/challenge.js.map +0 -1
- package/dist/cli/validate/discovery.d.ts.map +0 -1
- package/dist/cli/validate/discovery.js.map +0 -1
- package/dist/cli/validate/helpers.d.ts.map +0 -1
- package/dist/cli/validate/helpers.js.map +0 -1
- package/dist/cli/validate/index.d.ts.map +0 -1
- package/dist/cli/validate/index.js.map +0 -1
- package/dist/cli/validate/messages.d.ts.map +0 -1
- package/dist/cli/validate/messages.js.map +0 -1
- package/dist/cli/validate/payment.d.ts.map +0 -1
- package/dist/cli/validate/payment.js.map +0 -1
- package/dist/client/Methods.d.ts.map +0 -1
- package/dist/client/Methods.js.map +0 -1
- package/dist/client/Mppx.d.ts.map +0 -1
- package/dist/client/Mppx.js.map +0 -1
- package/dist/client/Transport.d.ts.map +0 -1
- package/dist/client/Transport.js.map +0 -1
- package/dist/client/index.d.ts.map +0 -1
- package/dist/client/index.js.map +0 -1
- package/dist/client/internal/Fetch.d.ts.map +0 -1
- package/dist/client/internal/Fetch.js.map +0 -1
- package/dist/client/internal/MethodChallenge.d.ts.map +0 -1
- package/dist/client/internal/MethodChallenge.js.map +0 -1
- package/dist/client/internal/MethodResponse.d.ts.map +0 -1
- package/dist/client/internal/MethodResponse.js.map +0 -1
- package/dist/client/internal/protocols/Mcp.d.ts.map +0 -1
- package/dist/client/internal/protocols/Mcp.js.map +0 -1
- package/dist/client/internal/protocols/Mpp.d.ts.map +0 -1
- package/dist/client/internal/protocols/Mpp.js.map +0 -1
- package/dist/client/internal/protocols/Protocol.d.ts.map +0 -1
- package/dist/client/internal/protocols/Protocol.js.map +0 -1
- package/dist/client/internal/protocols/Shared.d.ts.map +0 -1
- package/dist/client/internal/protocols/Shared.js.map +0 -1
- package/dist/client/internal/protocols/X402.d.ts.map +0 -1
- package/dist/client/internal/protocols/X402.js.map +0 -1
- package/dist/client/node.d.ts.map +0 -1
- package/dist/client/node.js.map +0 -1
- package/dist/discovery/Discovery.d.ts.map +0 -1
- package/dist/discovery/Discovery.js.map +0 -1
- package/dist/discovery/OpenApi.d.ts.map +0 -1
- package/dist/discovery/OpenApi.js.map +0 -1
- package/dist/discovery/Validate.d.ts.map +0 -1
- package/dist/discovery/Validate.js.map +0 -1
- package/dist/discovery/index.d.ts.map +0 -1
- package/dist/discovery/index.js.map +0 -1
- package/dist/evm/Assets.d.ts.map +0 -1
- package/dist/evm/Assets.js.map +0 -1
- package/dist/evm/Chains.d.ts.map +0 -1
- package/dist/evm/Chains.js.map +0 -1
- package/dist/evm/Methods.d.ts.map +0 -1
- package/dist/evm/Methods.js.map +0 -1
- package/dist/evm/Types.d.ts.map +0 -1
- package/dist/evm/Types.js.map +0 -1
- package/dist/evm/client/Charge.d.ts.map +0 -1
- package/dist/evm/client/Charge.js.map +0 -1
- package/dist/evm/client/Methods.d.ts.map +0 -1
- package/dist/evm/client/Methods.js.map +0 -1
- package/dist/evm/client/index.d.ts.map +0 -1
- package/dist/evm/client/index.js.map +0 -1
- package/dist/evm/index.d.ts.map +0 -1
- package/dist/evm/index.js.map +0 -1
- package/dist/evm/server/Charge.d.ts.map +0 -1
- package/dist/evm/server/Charge.js.map +0 -1
- package/dist/evm/server/Methods.d.ts.map +0 -1
- package/dist/evm/server/Methods.js.map +0 -1
- package/dist/evm/server/index.d.ts.map +0 -1
- package/dist/evm/server/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/internal/AcceptPayment.d.ts.map +0 -1
- package/dist/internal/AcceptPayment.js.map +0 -1
- package/dist/internal/HeaderCodec.d.ts.map +0 -1
- package/dist/internal/HeaderCodec.js.map +0 -1
- package/dist/internal/constantTimeEqual.d.ts.map +0 -1
- package/dist/internal/constantTimeEqual.js.map +0 -1
- package/dist/internal/env.d.ts.map +0 -1
- package/dist/internal/env.js.map +0 -1
- package/dist/internal/types.d.ts.map +0 -1
- package/dist/internal/types.js.map +0 -1
- package/dist/mcp/client/McpClient.d.ts.map +0 -1
- package/dist/mcp/client/McpClient.js.map +0 -1
- package/dist/mcp/client/index.d.ts.map +0 -1
- package/dist/mcp/client/index.js.map +0 -1
- package/dist/mcp/server/Transport.d.ts.map +0 -1
- package/dist/mcp/server/Transport.js.map +0 -1
- package/dist/mcp/server/index.d.ts.map +0 -1
- package/dist/mcp/server/index.js.map +0 -1
- package/dist/middlewares/elysia.d.ts.map +0 -1
- package/dist/middlewares/elysia.js.map +0 -1
- package/dist/middlewares/express.d.ts.map +0 -1
- package/dist/middlewares/express.js.map +0 -1
- package/dist/middlewares/hono.d.ts.map +0 -1
- package/dist/middlewares/hono.js.map +0 -1
- package/dist/middlewares/internal/mppx.d.ts.map +0 -1
- package/dist/middlewares/internal/mppx.js.map +0 -1
- package/dist/middlewares/nextjs.d.ts.map +0 -1
- package/dist/middlewares/nextjs.js.map +0 -1
- package/dist/proxy/Proxy.d.ts.map +0 -1
- package/dist/proxy/Proxy.js.map +0 -1
- package/dist/proxy/Service.d.ts.map +0 -1
- package/dist/proxy/Service.js.map +0 -1
- package/dist/proxy/index.d.ts.map +0 -1
- package/dist/proxy/index.js.map +0 -1
- package/dist/proxy/internal/Headers.d.ts.map +0 -1
- package/dist/proxy/internal/Headers.js.map +0 -1
- package/dist/proxy/internal/Route.d.ts.map +0 -1
- package/dist/proxy/internal/Route.js.map +0 -1
- package/dist/proxy/services/anthropic.d.ts.map +0 -1
- package/dist/proxy/services/anthropic.js.map +0 -1
- package/dist/proxy/services/openai.d.ts.map +0 -1
- package/dist/proxy/services/openai.js.map +0 -1
- package/dist/proxy/services/stripe.d.ts.map +0 -1
- package/dist/proxy/services/stripe.js.map +0 -1
- package/dist/server/Methods.d.ts.map +0 -1
- package/dist/server/Methods.js.map +0 -1
- package/dist/server/Mppx.d.ts.map +0 -1
- package/dist/server/Mppx.js.map +0 -1
- package/dist/server/NodeListener.d.ts.map +0 -1
- package/dist/server/NodeListener.js.map +0 -1
- package/dist/server/Request.d.ts.map +0 -1
- package/dist/server/Request.js.map +0 -1
- package/dist/server/Response.d.ts.map +0 -1
- package/dist/server/Response.js.map +0 -1
- package/dist/server/Transport.d.ts.map +0 -1
- package/dist/server/Transport.js.map +0 -1
- package/dist/server/index.d.ts.map +0 -1
- package/dist/server/index.js.map +0 -1
- package/dist/server/internal/html/compose.main.gen.d.ts.map +0 -1
- package/dist/server/internal/html/compose.main.gen.js.map +0 -1
- package/dist/server/internal/html/config.d.ts.map +0 -1
- package/dist/server/internal/html/config.js.map +0 -1
- package/dist/server/internal/html/constants.d.ts.map +0 -1
- package/dist/server/internal/html/constants.js.map +0 -1
- package/dist/server/internal/html/serviceWorker.client.d.ts.map +0 -1
- package/dist/server/internal/html/serviceWorker.client.js.map +0 -1
- package/dist/server/internal/html/serviceWorker.gen.d.ts.map +0 -1
- package/dist/server/internal/html/serviceWorker.gen.js.map +0 -1
- package/dist/server/internal/scope.d.ts.map +0 -1
- package/dist/server/internal/scope.js.map +0 -1
- package/dist/stripe/Methods.d.ts.map +0 -1
- package/dist/stripe/Methods.js.map +0 -1
- package/dist/stripe/client/Charge.d.ts.map +0 -1
- package/dist/stripe/client/Charge.js.map +0 -1
- package/dist/stripe/client/Methods.d.ts.map +0 -1
- package/dist/stripe/client/Methods.js.map +0 -1
- package/dist/stripe/client/index.d.ts.map +0 -1
- package/dist/stripe/client/index.js.map +0 -1
- package/dist/stripe/index.d.ts.map +0 -1
- package/dist/stripe/index.js.map +0 -1
- package/dist/stripe/internal/constants.d.ts.map +0 -1
- package/dist/stripe/internal/constants.js.map +0 -1
- package/dist/stripe/internal/types.d.ts.map +0 -1
- package/dist/stripe/internal/types.js.map +0 -1
- package/dist/stripe/server/Charge.d.ts.map +0 -1
- package/dist/stripe/server/Charge.js.map +0 -1
- package/dist/stripe/server/Methods.d.ts.map +0 -1
- package/dist/stripe/server/Methods.js.map +0 -1
- package/dist/stripe/server/index.d.ts.map +0 -1
- package/dist/stripe/server/index.js.map +0 -1
- package/dist/stripe/server/internal/html/types.d.ts.map +0 -1
- package/dist/stripe/server/internal/html/types.js.map +0 -1
- package/dist/stripe/server/internal/html.gen.d.ts.map +0 -1
- package/dist/stripe/server/internal/html.gen.js.map +0 -1
- package/dist/tempo/Attribution.d.ts.map +0 -1
- package/dist/tempo/Attribution.js.map +0 -1
- package/dist/tempo/Methods.d.ts.map +0 -1
- package/dist/tempo/Methods.js.map +0 -1
- package/dist/tempo/Proof.d.ts.map +0 -1
- package/dist/tempo/Proof.js.map +0 -1
- package/dist/tempo/client/Charge.d.ts.map +0 -1
- package/dist/tempo/client/Charge.js.map +0 -1
- package/dist/tempo/client/Methods.d.ts.map +0 -1
- package/dist/tempo/client/Methods.js.map +0 -1
- package/dist/tempo/client/ResolveAccount.d.ts.map +0 -1
- package/dist/tempo/client/ResolveAccount.js.map +0 -1
- package/dist/tempo/client/Subscription.d.ts.map +0 -1
- package/dist/tempo/client/Subscription.js.map +0 -1
- package/dist/tempo/client/index.d.ts.map +0 -1
- package/dist/tempo/client/index.js.map +0 -1
- package/dist/tempo/index.d.ts.map +0 -1
- package/dist/tempo/index.js.map +0 -1
- package/dist/tempo/internal/account.d.ts.map +0 -1
- package/dist/tempo/internal/account.js.map +0 -1
- package/dist/tempo/internal/address.d.ts.map +0 -1
- package/dist/tempo/internal/address.js.map +0 -1
- package/dist/tempo/internal/auto-swap.d.ts.map +0 -1
- package/dist/tempo/internal/auto-swap.js.map +0 -1
- package/dist/tempo/internal/charge.d.ts.map +0 -1
- package/dist/tempo/internal/charge.js.map +0 -1
- package/dist/tempo/internal/defaults.d.ts.map +0 -1
- package/dist/tempo/internal/defaults.js.map +0 -1
- package/dist/tempo/internal/fee-payer.d.ts.map +0 -1
- package/dist/tempo/internal/fee-payer.js.map +0 -1
- package/dist/tempo/internal/fee-token.d.ts.map +0 -1
- package/dist/tempo/internal/fee-token.js.map +0 -1
- package/dist/tempo/internal/proof.d.ts.map +0 -1
- package/dist/tempo/internal/proof.js.map +0 -1
- package/dist/tempo/internal/selectors.d.ts.map +0 -1
- package/dist/tempo/internal/selectors.js.map +0 -1
- package/dist/tempo/internal/types.d.ts.map +0 -1
- package/dist/tempo/internal/types.js.map +0 -1
- package/dist/tempo/legacy/client/ChannelOps.d.ts.map +0 -1
- package/dist/tempo/legacy/client/ChannelOps.js.map +0 -1
- package/dist/tempo/legacy/client/Session.d.ts.map +0 -1
- package/dist/tempo/legacy/client/Session.js.map +0 -1
- package/dist/tempo/legacy/client/SessionManager.d.ts.map +0 -1
- package/dist/tempo/legacy/client/SessionManager.js.map +0 -1
- package/dist/tempo/legacy/client/index.d.ts.map +0 -1
- package/dist/tempo/legacy/client/index.js.map +0 -1
- package/dist/tempo/legacy/index.d.ts.map +0 -1
- package/dist/tempo/legacy/index.js.map +0 -1
- package/dist/tempo/legacy/server/Session.d.ts +0 -208
- package/dist/tempo/legacy/server/Session.d.ts.map +0 -1
- package/dist/tempo/legacy/server/Session.js +0 -698
- package/dist/tempo/legacy/server/Session.js.map +0 -1
- package/dist/tempo/legacy/server/index.d.ts +0 -5
- package/dist/tempo/legacy/server/index.d.ts.map +0 -1
- package/dist/tempo/legacy/server/index.js +0 -5
- package/dist/tempo/legacy/server/index.js.map +0 -1
- package/dist/tempo/legacy/session/Chain.d.ts.map +0 -1
- package/dist/tempo/legacy/session/Chain.js.map +0 -1
- package/dist/tempo/legacy/session/Channel.d.ts.map +0 -1
- package/dist/tempo/legacy/session/Channel.js.map +0 -1
- package/dist/tempo/legacy/session/ChannelStore.d.ts +0 -22
- package/dist/tempo/legacy/session/ChannelStore.d.ts.map +0 -1
- package/dist/tempo/legacy/session/ChannelStore.js +0 -6
- package/dist/tempo/legacy/session/ChannelStore.js.map +0 -1
- package/dist/tempo/legacy/session/Types.d.ts.map +0 -1
- package/dist/tempo/legacy/session/Types.js.map +0 -1
- package/dist/tempo/legacy/session/Voucher.d.ts.map +0 -1
- package/dist/tempo/legacy/session/Voucher.js.map +0 -1
- package/dist/tempo/legacy/session/escrow.abi.d.ts.map +0 -1
- package/dist/tempo/legacy/session/escrow.abi.js.map +0 -1
- package/dist/tempo/legacy/session/index.d.ts.map +0 -1
- package/dist/tempo/legacy/session/index.js.map +0 -1
- package/dist/tempo/server/Charge.d.ts.map +0 -1
- package/dist/tempo/server/Charge.js.map +0 -1
- package/dist/tempo/server/Methods.d.ts.map +0 -1
- package/dist/tempo/server/Methods.js.map +0 -1
- package/dist/tempo/server/Relay.d.ts.map +0 -1
- package/dist/tempo/server/Relay.js.map +0 -1
- package/dist/tempo/server/SponsorBudget.d.ts.map +0 -1
- package/dist/tempo/server/SponsorBudget.js.map +0 -1
- package/dist/tempo/server/Subscription.d.ts.map +0 -1
- package/dist/tempo/server/Subscription.js.map +0 -1
- package/dist/tempo/server/index.d.ts.map +0 -1
- package/dist/tempo/server/index.js.map +0 -1
- package/dist/tempo/server/internal/html.gen.d.ts.map +0 -1
- package/dist/tempo/server/internal/html.gen.js.map +0 -1
- package/dist/tempo/server/internal/request-body.d.ts.map +0 -1
- package/dist/tempo/server/internal/request-body.js.map +0 -1
- package/dist/tempo/server/internal/transport.d.ts.map +0 -1
- package/dist/tempo/server/internal/transport.js.map +0 -1
- package/dist/tempo/session/Snapshot.d.ts.map +0 -1
- package/dist/tempo/session/Snapshot.js.map +0 -1
- package/dist/tempo/session/client/ChannelOps.d.ts.map +0 -1
- package/dist/tempo/session/client/ChannelOps.js.map +0 -1
- package/dist/tempo/session/client/ChannelStore.d.ts.map +0 -1
- package/dist/tempo/session/client/ChannelStore.js.map +0 -1
- package/dist/tempo/session/client/CredentialState.d.ts.map +0 -1
- package/dist/tempo/session/client/CredentialState.js.map +0 -1
- package/dist/tempo/session/client/ReceiptCoordinator.d.ts.map +0 -1
- package/dist/tempo/session/client/ReceiptCoordinator.js.map +0 -1
- package/dist/tempo/session/client/Runtime.d.ts.map +0 -1
- package/dist/tempo/session/client/Runtime.js.map +0 -1
- package/dist/tempo/session/client/Session.d.ts.map +0 -1
- package/dist/tempo/session/client/Session.js.map +0 -1
- package/dist/tempo/session/client/SessionManager.d.ts.map +0 -1
- package/dist/tempo/session/client/SessionManager.js.map +0 -1
- package/dist/tempo/session/client/Transports.d.ts.map +0 -1
- package/dist/tempo/session/client/Transports.js.map +0 -1
- package/dist/tempo/session/client/index.d.ts.map +0 -1
- package/dist/tempo/session/client/index.js.map +0 -1
- package/dist/tempo/session/client/internal/SessionManager.d.ts.map +0 -1
- package/dist/tempo/session/client/internal/SessionManager.js.map +0 -1
- package/dist/tempo/session/index.d.ts.map +0 -1
- package/dist/tempo/session/index.js.map +0 -1
- package/dist/tempo/session/precompile/Chain.d.ts.map +0 -1
- package/dist/tempo/session/precompile/Chain.js.map +0 -1
- package/dist/tempo/session/precompile/Channel.d.ts.map +0 -1
- package/dist/tempo/session/precompile/Channel.js.map +0 -1
- package/dist/tempo/session/precompile/Protocol.d.ts.map +0 -1
- package/dist/tempo/session/precompile/Protocol.js.map +0 -1
- package/dist/tempo/session/precompile/Voucher.d.ts.map +0 -1
- package/dist/tempo/session/precompile/Voucher.js.map +0 -1
- package/dist/tempo/session/precompile/escrow.abi.d.ts.map +0 -1
- package/dist/tempo/session/precompile/escrow.abi.js.map +0 -1
- package/dist/tempo/session/precompile/index.d.ts.map +0 -1
- package/dist/tempo/session/precompile/index.js.map +0 -1
- package/dist/tempo/session/server/ChannelOps.d.ts.map +0 -1
- package/dist/tempo/session/server/ChannelOps.js.map +0 -1
- package/dist/tempo/session/server/ChannelStore.d.ts.map +0 -1
- package/dist/tempo/session/server/ChannelStore.js.map +0 -1
- package/dist/tempo/session/server/CredentialVerification.d.ts.map +0 -1
- package/dist/tempo/session/server/CredentialVerification.js.map +0 -1
- package/dist/tempo/session/server/MeteredStream.d.ts.map +0 -1
- package/dist/tempo/session/server/MeteredStream.js.map +0 -1
- package/dist/tempo/session/server/RequestState.d.ts.map +0 -1
- package/dist/tempo/session/server/RequestState.js.map +0 -1
- package/dist/tempo/session/server/Session.d.ts.map +0 -1
- package/dist/tempo/session/server/Session.js.map +0 -1
- package/dist/tempo/session/server/Settlement.d.ts.map +0 -1
- package/dist/tempo/session/server/Settlement.js.map +0 -1
- package/dist/tempo/session/server/Sse.d.ts.map +0 -1
- package/dist/tempo/session/server/Sse.js.map +0 -1
- package/dist/tempo/session/server/Transports.d.ts.map +0 -1
- package/dist/tempo/session/server/Transports.js.map +0 -1
- package/dist/tempo/session/server/Ws.d.ts.map +0 -1
- package/dist/tempo/session/server/Ws.js.map +0 -1
- package/dist/tempo/session/server/index.d.ts.map +0 -1
- package/dist/tempo/session/server/index.js.map +0 -1
- package/dist/tempo/subscription/KeyAuthorization.d.ts.map +0 -1
- package/dist/tempo/subscription/KeyAuthorization.js.map +0 -1
- package/dist/tempo/subscription/Receipt.d.ts.map +0 -1
- package/dist/tempo/subscription/Receipt.js.map +0 -1
- package/dist/tempo/subscription/Store.d.ts.map +0 -1
- package/dist/tempo/subscription/Store.js.map +0 -1
- package/dist/tempo/subscription/Types.d.ts.map +0 -1
- package/dist/tempo/subscription/Types.js.map +0 -1
- package/dist/tempo/subscription/index.d.ts.map +0 -1
- package/dist/tempo/subscription/index.js.map +0 -1
- package/dist/validation/core.d.ts.map +0 -1
- package/dist/validation/core.js.map +0 -1
- package/dist/validation/index.d.ts.map +0 -1
- package/dist/validation/index.js.map +0 -1
- package/dist/viem/Account.d.ts.map +0 -1
- package/dist/viem/Account.js.map +0 -1
- package/dist/viem/Client.d.ts.map +0 -1
- package/dist/viem/Client.js.map +0 -1
- package/dist/x402/Assets.d.ts.map +0 -1
- package/dist/x402/Assets.js.map +0 -1
- package/dist/x402/Header.d.ts.map +0 -1
- package/dist/x402/Header.js.map +0 -1
- package/dist/x402/Types.d.ts.map +0 -1
- package/dist/x402/Types.js.map +0 -1
- package/dist/x402/client/Exact.d.ts.map +0 -1
- package/dist/x402/client/Exact.js.map +0 -1
- package/dist/x402/index.d.ts.map +0 -1
- package/dist/x402/index.js.map +0 -1
- package/dist/x402/internal/ChallengeBrand.d.ts.map +0 -1
- package/dist/x402/internal/ChallengeBrand.js.map +0 -1
- package/dist/x402/internal/RouteBinding.d.ts.map +0 -1
- package/dist/x402/internal/RouteBinding.js.map +0 -1
- package/dist/x402/server/EvmCharge.d.ts.map +0 -1
- package/dist/x402/server/EvmCharge.js.map +0 -1
- package/dist/x402/server/Facilitator.d.ts.map +0 -1
- package/dist/x402/server/Facilitator.js.map +0 -1
- package/dist/zod.d.ts.map +0 -1
- package/dist/zod.js.map +0 -1
- package/src/BodyDigest.test.ts +0 -43
- package/src/BodyDigest.ts +0 -55
- package/src/Challenge.fuzz.test.ts +0 -121
- package/src/Challenge.test-d.ts +0 -82
- package/src/Challenge.test.ts +0 -995
- package/src/Challenge.ts +0 -683
- package/src/Constants.ts +0 -58
- package/src/Credential.fuzz.test.ts +0 -62
- package/src/Credential.test.ts +0 -378
- package/src/Credential.ts +0 -217
- package/src/Errors.test.ts +0 -520
- package/src/Errors.ts +0 -448
- package/src/Expires.test.ts +0 -112
- package/src/Expires.ts +0 -59
- package/src/Html.ts +0 -67
- package/src/Mcp.ts +0 -85
- package/src/Method.test.ts +0 -177
- package/src/Method.ts +0 -617
- package/src/PaymentRequest.test.ts +0 -147
- package/src/PaymentRequest.ts +0 -108
- package/src/Receipt.test.ts +0 -151
- package/src/Receipt.ts +0 -146
- package/src/Store.test-d.ts +0 -195
- package/src/Store.test.ts +0 -357
- package/src/Store.ts +0 -329
- package/src/bin.ts +0 -4
- package/src/cli/account.ts +0 -269
- package/src/cli/cli.test.ts +0 -2221
- package/src/cli/cli.ts +0 -1649
- package/src/cli/config.test.ts +0 -89
- package/src/cli/config.ts +0 -50
- package/src/cli/internal.ts +0 -114
- package/src/cli/mcp.test.ts +0 -262
- package/src/cli/plugins/evm.ts +0 -55
- package/src/cli/plugins/index.ts +0 -4
- package/src/cli/plugins/plugin.ts +0 -84
- package/src/cli/plugins/stripe.ts +0 -174
- package/src/cli/plugins/tempo.ts +0 -1102
- package/src/cli/sessions/Manager.test.ts +0 -249
- package/src/cli/sessions/Manager.ts +0 -93
- package/src/cli/sessions/commands.ts +0 -444
- package/src/cli/sessions/request.test.ts +0 -51
- package/src/cli/sessions/request.ts +0 -353
- package/src/cli/sessions/store.test.ts +0 -581
- package/src/cli/sessions/store.ts +0 -940
- package/src/cli/utils.test.ts +0 -156
- package/src/cli/utils.ts +0 -394
- package/src/cli/validate/challenge.ts +0 -565
- package/src/cli/validate/discovery.test.ts +0 -435
- package/src/cli/validate/discovery.ts +0 -221
- package/src/cli/validate/helpers.ts +0 -166
- package/src/cli/validate/index.ts +0 -229
- package/src/cli/validate/messages.ts +0 -7
- package/src/cli/validate/payment.ts +0 -774
- package/src/cli/validate.test.ts +0 -843
- package/src/client/Methods.ts +0 -8
- package/src/client/Mppx.test-d.ts +0 -270
- package/src/client/Mppx.test.ts +0 -1065
- package/src/client/Mppx.ts +0 -466
- package/src/client/Transport.test.ts +0 -619
- package/src/client/Transport.ts +0 -191
- package/src/client/index.ts +0 -29
- package/src/client/internal/Fetch.browser.test.ts +0 -197
- package/src/client/internal/Fetch.test-d.ts +0 -109
- package/src/client/internal/Fetch.test.ts +0 -2336
- package/src/client/internal/Fetch.ts +0 -1079
- package/src/client/internal/MethodChallenge.ts +0 -35
- package/src/client/internal/MethodResponse.ts +0 -67
- package/src/client/internal/protocols/Mcp.test.ts +0 -220
- package/src/client/internal/protocols/Mcp.ts +0 -186
- package/src/client/internal/protocols/Mpp.ts +0 -21
- package/src/client/internal/protocols/Protocol.ts +0 -10
- package/src/client/internal/protocols/Shared.ts +0 -25
- package/src/client/internal/protocols/X402.ts +0 -46
- package/src/client/node.test.ts +0 -115
- package/src/client/node.ts +0 -247
- package/src/discovery/Discovery.test.ts +0 -214
- package/src/discovery/Discovery.ts +0 -105
- package/src/discovery/OpenApi.test.ts +0 -453
- package/src/discovery/OpenApi.ts +0 -224
- package/src/discovery/Validate.test.ts +0 -305
- package/src/discovery/Validate.ts +0 -77
- package/src/discovery/index.ts +0 -3
- package/src/env.d.ts +0 -12
- package/src/evm/Assets.ts +0 -1
- package/src/evm/Chains.ts +0 -11
- package/src/evm/Methods.ts +0 -44
- package/src/evm/PublicInterface.test-d.ts +0 -134
- package/src/evm/Types.ts +0 -140
- package/src/evm/client/Charge.test.ts +0 -347
- package/src/evm/client/Charge.ts +0 -187
- package/src/evm/client/Methods.ts +0 -19
- package/src/evm/client/index.ts +0 -6
- package/src/evm/index.ts +0 -16
- package/src/evm/server/Charge.test.ts +0 -339
- package/src/evm/server/Charge.ts +0 -290
- package/src/evm/server/Methods.ts +0 -22
- package/src/evm/server/index.ts +0 -6
- package/src/index.ts +0 -14
- package/src/internal/AcceptPayment.test.ts +0 -343
- package/src/internal/AcceptPayment.ts +0 -366
- package/src/internal/HeaderCodec.ts +0 -36
- package/src/internal/changeset.test.ts +0 -106
- package/src/internal/constantTimeEqual.test.ts +0 -47
- package/src/internal/constantTimeEqual.ts +0 -10
- package/src/internal/env.test.ts +0 -42
- package/src/internal/env.ts +0 -49
- package/src/internal/types.test-d.ts +0 -21
- package/src/internal/types.ts +0 -470
- package/src/mcp/client/McpClient.integration.test.ts +0 -652
- package/src/mcp/client/McpClient.test-d.ts +0 -144
- package/src/mcp/client/McpClient.test.ts +0 -463
- package/src/mcp/client/McpClient.ts +0 -307
- package/src/mcp/client/McpClient.unit.test.ts +0 -135
- package/src/mcp/client/index.ts +0 -2
- package/src/mcp/server/Transport.test.ts +0 -191
- package/src/mcp/server/Transport.ts +0 -111
- package/src/mcp/server/index.ts +0 -1
- package/src/middlewares/elysia.test.ts +0 -295
- package/src/middlewares/elysia.ts +0 -116
- package/src/middlewares/express.test.ts +0 -371
- package/src/middlewares/express.ts +0 -140
- package/src/middlewares/hono.test.ts +0 -476
- package/src/middlewares/hono.ts +0 -153
- package/src/middlewares/internal/mppx.test.ts +0 -177
- package/src/middlewares/internal/mppx.ts +0 -67
- package/src/middlewares/nextjs.test.ts +0 -369
- package/src/middlewares/nextjs.ts +0 -107
- package/src/proxy/Proxy.test.ts +0 -1031
- package/src/proxy/Proxy.ts +0 -345
- package/src/proxy/Service.test.ts +0 -182
- package/src/proxy/Service.ts +0 -253
- package/src/proxy/index.ts +0 -6
- package/src/proxy/internal/Headers.test.ts +0 -139
- package/src/proxy/internal/Headers.ts +0 -66
- package/src/proxy/internal/Route.test.ts +0 -217
- package/src/proxy/internal/Route.ts +0 -64
- package/src/proxy/services/anthropic.test.ts +0 -132
- package/src/proxy/services/anthropic.ts +0 -52
- package/src/proxy/services/openai.test.ts +0 -157
- package/src/proxy/services/openai.ts +0 -59
- package/src/proxy/services/stripe.test.ts +0 -175
- package/src/proxy/services/stripe.ts +0 -58
- package/src/server/Methods.ts +0 -3
- package/src/server/Mppx.authorize.test.ts +0 -210
- package/src/server/Mppx.test-d.ts +0 -360
- package/src/server/Mppx.test.ts +0 -5813
- package/src/server/Mppx.ts +0 -2623
- package/src/server/NodeListener.test.ts +0 -293
- package/src/server/NodeListener.ts +0 -45
- package/src/server/Request.test.ts +0 -255
- package/src/server/Request.ts +0 -155
- package/src/server/Response.test.ts +0 -32
- package/src/server/Response.ts +0 -45
- package/src/server/Transport.test.ts +0 -598
- package/src/server/Transport.ts +0 -320
- package/src/server/index.ts +0 -9
- package/src/server/internal/html/compose.main.gen.ts +0 -2
- package/src/server/internal/html/compose.main.ts +0 -88
- package/src/server/internal/html/config.ts +0 -672
- package/src/server/internal/html/constants.ts +0 -28
- package/src/server/internal/html/serviceWorker.client.ts +0 -28
- package/src/server/internal/html/serviceWorker.gen.ts +0 -2
- package/src/server/internal/html/serviceWorker.ts +0 -27
- package/src/server/internal/html/tsconfig.compose.json +0 -8
- package/src/server/internal/html/tsconfig.worker.client.json +0 -8
- package/src/server/internal/html/tsconfig.worker.json +0 -8
- package/src/server/internal/scope.ts +0 -43
- package/src/stripe/Charge.integration.test.ts +0 -329
- package/src/stripe/Methods.test.ts +0 -62
- package/src/stripe/Methods.ts +0 -44
- package/src/stripe/client/Charge.test.ts +0 -205
- package/src/stripe/client/Charge.ts +0 -132
- package/src/stripe/client/Methods.ts +0 -37
- package/src/stripe/client/index.ts +0 -2
- package/src/stripe/index.ts +0 -1
- package/src/stripe/internal/constants.ts +0 -7
- package/src/stripe/internal/types.ts +0 -46
- package/src/stripe/server/Charge.test-d.ts +0 -66
- package/src/stripe/server/Charge.test.ts +0 -621
- package/src/stripe/server/Charge.ts +0 -434
- package/src/stripe/server/Methods.ts +0 -24
- package/src/stripe/server/index.ts +0 -2
- package/src/stripe/server/internal/html/main.ts +0 -165
- package/src/stripe/server/internal/html/node_modules/.bin/mppx +0 -22
- package/src/stripe/server/internal/html/node_modules/.bin/mppx.src +0 -22
- package/src/stripe/server/internal/html/package.json +0 -9
- package/src/stripe/server/internal/html/stripe-js-pure.d.ts +0 -7
- package/src/stripe/server/internal/html/tsconfig.json +0 -8
- package/src/stripe/server/internal/html/types.ts +0 -5
- package/src/stripe/server/internal/html.gen.ts +0 -2
- package/src/tempo/AccessKeyAuthorization.test.ts +0 -141
- package/src/tempo/Attribution.test.ts +0 -294
- package/src/tempo/Attribution.ts +0 -185
- package/src/tempo/Methods.test.ts +0 -425
- package/src/tempo/Methods.ts +0 -367
- package/src/tempo/Proof.conformance.test.ts +0 -146
- package/src/tempo/Proof.test-d.ts +0 -32
- package/src/tempo/Proof.test.ts +0 -40
- package/src/tempo/Proof.ts +0 -69
- package/src/tempo/PublicExports.test-d.ts +0 -130
- package/src/tempo/Subscription.integration.test.ts +0 -591
- package/src/tempo/client/Charge.test.ts +0 -501
- package/src/tempo/client/Charge.ts +0 -289
- package/src/tempo/client/Methods.ts +0 -45
- package/src/tempo/client/ResolveAccount.ts +0 -46
- package/src/tempo/client/Subscription.test.ts +0 -180
- package/src/tempo/client/Subscription.ts +0 -156
- package/src/tempo/client/index.ts +0 -17
- package/src/tempo/index.ts +0 -5
- package/src/tempo/internal/account.ts +0 -56
- package/src/tempo/internal/address.ts +0 -6
- package/src/tempo/internal/auto-swap.test.ts +0 -198
- package/src/tempo/internal/auto-swap.ts +0 -188
- package/src/tempo/internal/charge.test.ts +0 -66
- package/src/tempo/internal/charge.ts +0 -43
- package/src/tempo/internal/defaults.test.ts +0 -95
- package/src/tempo/internal/defaults.ts +0 -53
- package/src/tempo/internal/fee-payer.test.ts +0 -1177
- package/src/tempo/internal/fee-payer.ts +0 -808
- package/src/tempo/internal/fee-token.test.ts +0 -165
- package/src/tempo/internal/fee-token.ts +0 -72
- package/src/tempo/internal/proof.test.ts +0 -97
- package/src/tempo/internal/proof.ts +0 -87
- package/src/tempo/internal/selectors.ts +0 -10
- package/src/tempo/internal/types.ts +0 -19
- package/src/tempo/legacy/AccessKeyAuthorization.test.ts +0 -162
- package/src/tempo/legacy/README.md +0 -9
- package/src/tempo/legacy/client/ChannelOps.test.ts +0 -379
- package/src/tempo/legacy/client/ChannelOps.ts +0 -271
- package/src/tempo/legacy/client/Session.test.ts +0 -800
- package/src/tempo/legacy/client/Session.ts +0 -397
- package/src/tempo/legacy/client/SessionManager.test.ts +0 -468
- package/src/tempo/legacy/client/SessionManager.ts +0 -909
- package/src/tempo/legacy/client/index.ts +0 -6
- package/src/tempo/legacy/index.ts +0 -6
- package/src/tempo/legacy/server/Defaults.test-d.ts +0 -9
- package/src/tempo/legacy/server/Session.test.ts +0 -6370
- package/src/tempo/legacy/server/Session.ts +0 -1024
- package/src/tempo/legacy/server/index.ts +0 -4
- package/src/tempo/legacy/session/Chain.test.ts +0 -1349
- package/src/tempo/legacy/session/Chain.ts +0 -830
- package/src/tempo/legacy/session/Channel.test.ts +0 -109
- package/src/tempo/legacy/session/Channel.ts +0 -51
- package/src/tempo/legacy/session/ChannelStore.test.ts +0 -58
- package/src/tempo/legacy/session/ChannelStore.ts +0 -39
- package/src/tempo/legacy/session/Types.ts +0 -91
- package/src/tempo/legacy/session/Voucher.test.ts +0 -410
- package/src/tempo/legacy/session/Voucher.ts +0 -183
- package/src/tempo/legacy/session/escrow.abi.ts +0 -760
- package/src/tempo/legacy/session/index.ts +0 -8
- package/src/tempo/server/AtomicStore.test-d.ts +0 -50
- package/src/tempo/server/Charge.test.ts +0 -6121
- package/src/tempo/server/Charge.ts +0 -1351
- package/src/tempo/server/Methods.ts +0 -106
- package/src/tempo/server/Relay.test.ts +0 -677
- package/src/tempo/server/Relay.ts +0 -297
- package/src/tempo/server/SponsorBudget.test.ts +0 -154
- package/src/tempo/server/SponsorBudget.ts +0 -219
- package/src/tempo/server/Sse.test.ts +0 -321
- package/src/tempo/server/Subscription.test.ts +0 -1944
- package/src/tempo/server/Subscription.ts +0 -1333
- package/src/tempo/server/index.ts +0 -12
- package/src/tempo/server/internal/html/main.ts +0 -115
- package/src/tempo/server/internal/html/node_modules/.bin/mppx +0 -22
- package/src/tempo/server/internal/html/node_modules/.bin/mppx.src +0 -22
- package/src/tempo/server/internal/html/package.json +0 -10
- package/src/tempo/server/internal/html/tsconfig.json +0 -8
- package/src/tempo/server/internal/html.gen.ts +0 -2
- package/src/tempo/server/internal/request-body.test.ts +0 -210
- package/src/tempo/server/internal/request-body.ts +0 -61
- package/src/tempo/server/internal/transport.test.ts +0 -903
- package/src/tempo/server/internal/transport.ts +0 -310
- package/src/tempo/session/README.md +0 -208
- package/src/tempo/session/Snapshot.test.ts +0 -41
- package/src/tempo/session/Snapshot.ts +0 -95
- package/src/tempo/session/client/ChannelOps.test.ts +0 -218
- package/src/tempo/session/client/ChannelOps.ts +0 -348
- package/src/tempo/session/client/ChannelStore.ts +0 -111
- package/src/tempo/session/client/CredentialState.test.ts +0 -789
- package/src/tempo/session/client/CredentialState.ts +0 -942
- package/src/tempo/session/client/ReceiptCoordinator.ts +0 -95
- package/src/tempo/session/client/Runtime.test.ts +0 -1104
- package/src/tempo/session/client/Runtime.ts +0 -1008
- package/src/tempo/session/client/Session.test.ts +0 -1355
- package/src/tempo/session/client/Session.ts +0 -420
- package/src/tempo/session/client/SessionManager.test.ts +0 -1899
- package/src/tempo/session/client/SessionManager.ts +0 -996
- package/src/tempo/session/client/Transports.test.ts +0 -1141
- package/src/tempo/session/client/Transports.ts +0 -1534
- package/src/tempo/session/client/index.ts +0 -40
- package/src/tempo/session/client/internal/SessionManager.ts +0 -36
- package/src/tempo/session/index.ts +0 -7
- package/src/tempo/session/precompile/Chain.integration.test.ts +0 -339
- package/src/tempo/session/precompile/Chain.test.ts +0 -1641
- package/src/tempo/session/precompile/Chain.ts +0 -1149
- package/src/tempo/session/precompile/Channel.test.ts +0 -147
- package/src/tempo/session/precompile/Channel.ts +0 -108
- package/src/tempo/session/precompile/Protocol.test.ts +0 -358
- package/src/tempo/session/precompile/Protocol.ts +0 -520
- package/src/tempo/session/precompile/Voucher.test.ts +0 -354
- package/src/tempo/session/precompile/Voucher.ts +0 -162
- package/src/tempo/session/precompile/escrow.abi.ts +0 -226
- package/src/tempo/session/precompile/index.ts +0 -33
- package/src/tempo/session/server/ChannelOps.test.ts +0 -129
- package/src/tempo/session/server/ChannelOps.ts +0 -157
- package/src/tempo/session/server/ChannelStore.test.ts +0 -1093
- package/src/tempo/session/server/ChannelStore.ts +0 -835
- package/src/tempo/session/server/CredentialVerification.test.ts +0 -299
- package/src/tempo/session/server/CredentialVerification.ts +0 -775
- package/src/tempo/session/server/MeteredStream.ts +0 -95
- package/src/tempo/session/server/RequestState.test.ts +0 -574
- package/src/tempo/session/server/RequestState.ts +0 -507
- package/src/tempo/session/server/Session.integration.test.ts +0 -449
- package/src/tempo/session/server/Session.test.ts +0 -3862
- package/src/tempo/session/server/Session.ts +0 -570
- package/src/tempo/session/server/Settlement.test.ts +0 -345
- package/src/tempo/session/server/Settlement.ts +0 -527
- package/src/tempo/session/server/Sse.fuzz.test.ts +0 -138
- package/src/tempo/session/server/Sse.test.ts +0 -557
- package/src/tempo/session/server/Sse.ts +0 -254
- package/src/tempo/session/server/Transports.test.ts +0 -346
- package/src/tempo/session/server/Transports.ts +0 -255
- package/src/tempo/session/server/Ws.test.ts +0 -594
- package/src/tempo/session/server/Ws.ts +0 -385
- package/src/tempo/session/server/index.ts +0 -12
- package/src/tempo/subscription/KeyAuthorization.test.ts +0 -282
- package/src/tempo/subscription/KeyAuthorization.ts +0 -396
- package/src/tempo/subscription/Receipt.ts +0 -28
- package/src/tempo/subscription/Store.test.ts +0 -609
- package/src/tempo/subscription/Store.ts +0 -449
- package/src/tempo/subscription/Types.ts +0 -68
- package/src/tempo/subscription/index.ts +0 -23
- package/src/tsconfig.json +0 -10
- package/src/validation/core.ts +0 -386
- package/src/validation/index.ts +0 -11
- package/src/viem/Account.test.ts +0 -72
- package/src/viem/Account.ts +0 -30
- package/src/viem/Client.test.ts +0 -366
- package/src/viem/Client.ts +0 -93
- package/src/x402/Assets.test.ts +0 -253
- package/src/x402/Assets.ts +0 -221
- package/src/x402/Exact.e2e.test.ts +0 -448
- package/src/x402/Exact.localnet.test.ts +0 -475
- package/src/x402/Header.test.ts +0 -73
- package/src/x402/Header.ts +0 -79
- package/src/x402/PublicInterface.test-d.ts +0 -39
- package/src/x402/Types.ts +0 -248
- package/src/x402/client/Exact.test.ts +0 -309
- package/src/x402/client/Exact.ts +0 -186
- package/src/x402/index.ts +0 -6
- package/src/x402/internal/ChallengeBrand.ts +0 -14
- package/src/x402/internal/RouteBinding.ts +0 -18
- package/src/x402/server/EvmCharge.ts +0 -394
- package/src/x402/server/Facilitator.test.ts +0 -111
- package/src/x402/server/Facilitator.ts +0 -56
- package/src/zod.test.ts +0 -169
- package/src/zod.ts +0 -71
|
@@ -1,1355 +0,0 @@
|
|
|
1
|
-
import { type Address, createClient, custom, decodeFunctionData, encodeFunctionResult } from 'viem'
|
|
2
|
-
import { privateKeyToAccount } from 'viem/accounts'
|
|
3
|
-
import { Account as TempoAccount, Secp256k1, Transaction } from 'viem/tempo'
|
|
4
|
-
import { describe, expect, test, vi } from 'vp/test'
|
|
5
|
-
|
|
6
|
-
import { serialize as serializeChallenge, type Challenge } from '../../../Challenge.js'
|
|
7
|
-
import * as Fetch from '../../../client/internal/Fetch.js'
|
|
8
|
-
import * as MethodChallenge from '../../../client/internal/MethodChallenge.js'
|
|
9
|
-
import * as Constants from '../../../Constants.js'
|
|
10
|
-
import * as Credential from '../../../Credential.js'
|
|
11
|
-
import * as z from '../../../zod.js'
|
|
12
|
-
import * as AutoSwap from '../../internal/auto-swap.js'
|
|
13
|
-
import * as Methods from '../../Methods.js'
|
|
14
|
-
import * as Channel from '../precompile/Channel.js'
|
|
15
|
-
import { escrowAbi } from '../precompile/escrow.abi.js'
|
|
16
|
-
import { tip20ChannelEscrow } from '../precompile/Protocol.js'
|
|
17
|
-
import * as Types from '../precompile/Protocol.js'
|
|
18
|
-
import * as Voucher from '../precompile/Voucher.js'
|
|
19
|
-
import { channelKey, createChannelStore } from './ChannelStore.js'
|
|
20
|
-
import { session } from './Session.js'
|
|
21
|
-
|
|
22
|
-
const account = privateKeyToAccount(
|
|
23
|
-
'0xac0974bec39a17e36ba6a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80',
|
|
24
|
-
)
|
|
25
|
-
const chainId = 42431
|
|
26
|
-
const client = createClient({
|
|
27
|
-
account,
|
|
28
|
-
chain: { id: chainId } as never,
|
|
29
|
-
transport: custom({
|
|
30
|
-
async request(args) {
|
|
31
|
-
if (args.method === 'eth_chainId') return `0x${chainId.toString(16)}`
|
|
32
|
-
if (args.method === 'eth_getTransactionCount') return '0x0'
|
|
33
|
-
if (args.method === 'eth_estimateGas') return '0x5208'
|
|
34
|
-
if (args.method === 'eth_maxPriorityFeePerGas') return '0x1'
|
|
35
|
-
if (args.method === 'eth_getBlockByNumber') return { baseFeePerGas: '0x1' }
|
|
36
|
-
if (args.method === 'eth_call')
|
|
37
|
-
return encodeFunctionResult({
|
|
38
|
-
abi: escrowAbi,
|
|
39
|
-
functionName: 'getChannelState',
|
|
40
|
-
result: { settled: 0n, deposit: 1_000n, closeRequestedAt: 0 },
|
|
41
|
-
})
|
|
42
|
-
throw new Error(`unexpected rpc request: ${args.method}`)
|
|
43
|
-
},
|
|
44
|
-
}),
|
|
45
|
-
})
|
|
46
|
-
|
|
47
|
-
const descriptor = {
|
|
48
|
-
payer: account.address,
|
|
49
|
-
payee: '0x0000000000000000000000000000000000000002' as Address,
|
|
50
|
-
operator: '0x0000000000000000000000000000000000000000' as Address,
|
|
51
|
-
token: '0x0000000000000000000000000000000000000003' as Address,
|
|
52
|
-
salt: `0x${'11'.repeat(32)}` as `0x${string}`,
|
|
53
|
-
authorizedSigner: account.address,
|
|
54
|
-
expiringNonceHash: `0x${'22'.repeat(32)}` as `0x${string}`,
|
|
55
|
-
} satisfies Channel.ChannelDescriptor
|
|
56
|
-
|
|
57
|
-
type SessionChallenge = Challenge<
|
|
58
|
-
z.output<typeof Methods.session.schema.request>,
|
|
59
|
-
typeof Methods.session.intent,
|
|
60
|
-
typeof Methods.session.name
|
|
61
|
-
>
|
|
62
|
-
|
|
63
|
-
const defaultChannelKey = channelKey({
|
|
64
|
-
chainId,
|
|
65
|
-
escrow: tip20ChannelEscrow,
|
|
66
|
-
payee: descriptor.payee,
|
|
67
|
-
token: descriptor.token,
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
function makeChallenge(overrides: Partial<SessionChallenge['request']> = {}): SessionChallenge {
|
|
71
|
-
const request: SessionChallenge['request'] = {
|
|
72
|
-
amount: '100',
|
|
73
|
-
currency: descriptor.token,
|
|
74
|
-
recipient: descriptor.payee,
|
|
75
|
-
unitType: 'request',
|
|
76
|
-
methodDetails: { chainId, escrowContract: tip20ChannelEscrow },
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return {
|
|
80
|
-
id: 'test-id',
|
|
81
|
-
realm: 'test.com',
|
|
82
|
-
method: 'tempo',
|
|
83
|
-
intent: 'session',
|
|
84
|
-
request: Object.assign(request, overrides),
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
function makeSessionChallenge(
|
|
89
|
-
overrides: Partial<SessionChallenge['request']> = {},
|
|
90
|
-
): SessionChallenge {
|
|
91
|
-
return makeChallenge({
|
|
92
|
-
...overrides,
|
|
93
|
-
methodDetails: {
|
|
94
|
-
chainId,
|
|
95
|
-
escrowContract: tip20ChannelEscrow,
|
|
96
|
-
sessionProtocol: Constants.SessionProtocols.v2,
|
|
97
|
-
...overrides.methodDetails,
|
|
98
|
-
},
|
|
99
|
-
})
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function paymentRequired(challenge: SessionChallenge, headers?: HeadersInit): Response {
|
|
103
|
-
const responseHeaders = new Headers(headers)
|
|
104
|
-
responseHeaders.set(Constants.Headers.wwwAuthenticate, serializeChallenge(challenge))
|
|
105
|
-
return new Response(null, {
|
|
106
|
-
headers: responseHeaders,
|
|
107
|
-
status: 402,
|
|
108
|
-
})
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
function withSnapshot(
|
|
112
|
-
payload: Types.SessionCredentialPayload,
|
|
113
|
-
acceptedCumulative?: string,
|
|
114
|
-
): SessionChallenge {
|
|
115
|
-
if (payload.action !== 'open') throw new Error('expected open credential')
|
|
116
|
-
return {
|
|
117
|
-
...makeSessionChallenge({
|
|
118
|
-
methodDetails: {
|
|
119
|
-
chainId,
|
|
120
|
-
escrowContract: tip20ChannelEscrow,
|
|
121
|
-
sessionProtocol: Constants.SessionProtocols.v2,
|
|
122
|
-
sessionSnapshot: {
|
|
123
|
-
acceptedCumulative: acceptedCumulative ?? payload.cumulativeAmount,
|
|
124
|
-
chainId,
|
|
125
|
-
channelId: payload.channelId,
|
|
126
|
-
deposit: '1000',
|
|
127
|
-
descriptor: payload.descriptor,
|
|
128
|
-
escrow: tip20ChannelEscrow,
|
|
129
|
-
requiredCumulative: '200',
|
|
130
|
-
settled: '0',
|
|
131
|
-
spent: payload.cumulativeAmount,
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
}),
|
|
135
|
-
id: 'replacement-id',
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
function makeSessionMethod(
|
|
140
|
-
channelStore = createChannelStore(),
|
|
141
|
-
parameters: Partial<session.Parameters> = {},
|
|
142
|
-
) {
|
|
143
|
-
return session({
|
|
144
|
-
account,
|
|
145
|
-
channelStore,
|
|
146
|
-
decimals: 0,
|
|
147
|
-
getClient: () => client,
|
|
148
|
-
maxDeposit: '1000',
|
|
149
|
-
...parameters,
|
|
150
|
-
})
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
function makeSessionFetch(
|
|
154
|
-
fetch: typeof globalThis.fetch,
|
|
155
|
-
channelStore = createChannelStore(),
|
|
156
|
-
maxPaymentRetries?: number,
|
|
157
|
-
) {
|
|
158
|
-
return Fetch.from({
|
|
159
|
-
fetch,
|
|
160
|
-
maxPaymentRetries,
|
|
161
|
-
methods: [makeSessionMethod(channelStore)],
|
|
162
|
-
})
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
function deserialize(credential: string) {
|
|
166
|
-
return Credential.deserialize(credential).payload as Types.SessionCredentialPayload
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
function deserializeCredential(credential: string) {
|
|
170
|
-
return Credential.deserialize<Types.SessionCredentialPayload>(credential)
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
function openArgs(payload: Types.SessionCredentialPayload) {
|
|
174
|
-
if (payload.action !== 'open') throw new Error('expected open payload')
|
|
175
|
-
const transaction = Transaction.deserialize(payload.transaction)
|
|
176
|
-
if (!('calls' in transaction)) throw new Error('expected tempo calls')
|
|
177
|
-
const calls = transaction.calls as readonly { to?: Address; data?: `0x${string}` }[]
|
|
178
|
-
const call = calls[0]!
|
|
179
|
-
const decoded = decodeFunctionData({ abi: escrowAbi, data: call.data! })
|
|
180
|
-
if (decoded.functionName !== 'open') throw new Error('expected open call')
|
|
181
|
-
return decoded.args
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
function openDeposit(payload: Types.SessionCredentialPayload): bigint {
|
|
185
|
-
return openArgs(payload)[3]
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
function transactionCalls(payload: Types.SessionCredentialPayload) {
|
|
189
|
-
if (payload.action !== 'open' && payload.action !== 'topUp')
|
|
190
|
-
throw new Error('expected transaction payload')
|
|
191
|
-
const transaction = Transaction.deserialize(payload.transaction)
|
|
192
|
-
if (!('calls' in transaction)) throw new Error('expected tempo calls')
|
|
193
|
-
return transaction.calls as readonly { to?: Address; data?: `0x${string}` }[]
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
describe('precompile client session', () => {
|
|
197
|
-
test('handles only TIP-1034 session challenges', () => {
|
|
198
|
-
const method = session({ account, getClient: () => client })
|
|
199
|
-
|
|
200
|
-
expect(
|
|
201
|
-
method.canHandleChallenge?.({
|
|
202
|
-
challenge: makeChallenge({
|
|
203
|
-
methodDetails: {
|
|
204
|
-
chainId,
|
|
205
|
-
escrowContract: tip20ChannelEscrow,
|
|
206
|
-
sessionProtocol: Constants.SessionProtocols.v2,
|
|
207
|
-
},
|
|
208
|
-
}),
|
|
209
|
-
}),
|
|
210
|
-
).toBe(true)
|
|
211
|
-
expect(method.canHandleChallenge?.({ challenge: makeChallenge() })).toBe(false)
|
|
212
|
-
expect(
|
|
213
|
-
method.canHandleChallenge?.({
|
|
214
|
-
challenge: makeChallenge({
|
|
215
|
-
methodDetails: {
|
|
216
|
-
chainId,
|
|
217
|
-
escrowContract: tip20ChannelEscrow,
|
|
218
|
-
sessionProtocol: Constants.SessionProtocols.v1,
|
|
219
|
-
},
|
|
220
|
-
}),
|
|
221
|
-
}),
|
|
222
|
-
).toBe(false)
|
|
223
|
-
})
|
|
224
|
-
|
|
225
|
-
test('drives paid SSE responses with a supplied credential', async () => {
|
|
226
|
-
const challenge = makeChallenge({
|
|
227
|
-
suggestedDeposit: '100',
|
|
228
|
-
methodDetails: {
|
|
229
|
-
chainId,
|
|
230
|
-
escrowContract: tip20ChannelEscrow,
|
|
231
|
-
sessionProtocol: Constants.SessionProtocols.v2,
|
|
232
|
-
},
|
|
233
|
-
})
|
|
234
|
-
const channelStore = createChannelStore()
|
|
235
|
-
const parameters = {
|
|
236
|
-
account,
|
|
237
|
-
channelStore,
|
|
238
|
-
decimals: 0,
|
|
239
|
-
getClient: () => client,
|
|
240
|
-
maxDeposit: '300',
|
|
241
|
-
} as const
|
|
242
|
-
// The response handler must follow the credential selected by `onChallenge`.
|
|
243
|
-
const externalCredential = await session(parameters).createCredential({
|
|
244
|
-
challenge,
|
|
245
|
-
context: {},
|
|
246
|
-
})
|
|
247
|
-
let useExternalCredential = true
|
|
248
|
-
const actions: Types.SessionCredentialPayload['action'][] = []
|
|
249
|
-
const rawFetch: typeof globalThis.fetch = async (_input, init) => {
|
|
250
|
-
const authorization = new Headers(init?.headers).get(Constants.Headers.authorization)
|
|
251
|
-
if (!authorization)
|
|
252
|
-
return new Response(null, {
|
|
253
|
-
status: 402,
|
|
254
|
-
headers: { [Constants.Headers.wwwAuthenticate]: serializeChallenge(challenge) },
|
|
255
|
-
})
|
|
256
|
-
|
|
257
|
-
const payload = deserialize(authorization)
|
|
258
|
-
actions.push(payload.action)
|
|
259
|
-
if (init?.method === 'POST' || payload.action === 'open')
|
|
260
|
-
return new Response(null, { status: 204 })
|
|
261
|
-
if (payload.action !== 'voucher') throw new Error('expected voucher')
|
|
262
|
-
|
|
263
|
-
const receipt = Types.createSessionReceipt({
|
|
264
|
-
acceptedCumulative: 200n,
|
|
265
|
-
challengeId: challenge.id,
|
|
266
|
-
channelId: payload.channelId,
|
|
267
|
-
spent: 200n,
|
|
268
|
-
})
|
|
269
|
-
return new Response(
|
|
270
|
-
[
|
|
271
|
-
Types.formatMessageEvent('first'),
|
|
272
|
-
Types.formatNeedVoucherEvent({
|
|
273
|
-
acceptedCumulative: '100',
|
|
274
|
-
channelId: payload.channelId,
|
|
275
|
-
deposit: '100',
|
|
276
|
-
requiredCumulative: '200',
|
|
277
|
-
}),
|
|
278
|
-
Types.formatMessageEvent('second'),
|
|
279
|
-
Types.formatReceiptEvent(receipt),
|
|
280
|
-
].join(''),
|
|
281
|
-
{ headers: { 'content-type': 'text/event-stream' } },
|
|
282
|
-
)
|
|
283
|
-
}
|
|
284
|
-
const fetch = Fetch.from({
|
|
285
|
-
fetch: rawFetch,
|
|
286
|
-
methods: [session(parameters)],
|
|
287
|
-
async onChallenge() {
|
|
288
|
-
if (!useExternalCredential) return undefined
|
|
289
|
-
useExternalCredential = false
|
|
290
|
-
return externalCredential
|
|
291
|
-
},
|
|
292
|
-
})
|
|
293
|
-
|
|
294
|
-
const response = await fetch('https://example.com/stream', {
|
|
295
|
-
headers: { accept: 'text/event-stream' },
|
|
296
|
-
})
|
|
297
|
-
|
|
298
|
-
expect(response.headers.get('content-type')).toBe('text/event-stream')
|
|
299
|
-
expect(await response.text()).toBe(
|
|
300
|
-
`${Types.formatMessageEvent('first')}${Types.formatMessageEvent('second')}`,
|
|
301
|
-
)
|
|
302
|
-
expect(actions).toEqual(['open', 'topUp', 'voucher', 'voucher'])
|
|
303
|
-
})
|
|
304
|
-
|
|
305
|
-
test('tops up before signing plain HTTP vouchers through Fetch.from', async () => {
|
|
306
|
-
const challenge = makeChallenge({
|
|
307
|
-
suggestedDeposit: '100',
|
|
308
|
-
methodDetails: {
|
|
309
|
-
chainId,
|
|
310
|
-
escrowContract: tip20ChannelEscrow,
|
|
311
|
-
sessionProtocol: Constants.SessionProtocols.v2,
|
|
312
|
-
},
|
|
313
|
-
})
|
|
314
|
-
const actions: Types.SessionCredentialPayload['action'][] = []
|
|
315
|
-
const paidRequests: {
|
|
316
|
-
body: BodyInit | null
|
|
317
|
-
header: string | null
|
|
318
|
-
method: string | undefined
|
|
319
|
-
}[] = []
|
|
320
|
-
const vouchers: string[] = []
|
|
321
|
-
let opened: Extract<Types.SessionCredentialPayload, { action: 'open' }> | undefined
|
|
322
|
-
const paymentRequired = () =>
|
|
323
|
-
new Response(null, {
|
|
324
|
-
status: 402,
|
|
325
|
-
headers: { [Constants.Headers.wwwAuthenticate]: serializeChallenge(challenge) },
|
|
326
|
-
})
|
|
327
|
-
const rawFetch: typeof globalThis.fetch = async (_input, init) => {
|
|
328
|
-
const authorization = new Headers(init?.headers).get(Constants.Headers.authorization)
|
|
329
|
-
if (!authorization) return paymentRequired()
|
|
330
|
-
|
|
331
|
-
const payload = deserialize(authorization)
|
|
332
|
-
actions.push(payload.action)
|
|
333
|
-
if (payload.action === 'open') {
|
|
334
|
-
opened = payload
|
|
335
|
-
return new Response('opened')
|
|
336
|
-
}
|
|
337
|
-
if (payload.action === 'topUp') return new Response(null, { status: 204 })
|
|
338
|
-
if (payload.action !== 'voucher' || !opened) throw new Error('expected open voucher')
|
|
339
|
-
vouchers.push(authorization)
|
|
340
|
-
if (vouchers.length === 1) return paymentRequired()
|
|
341
|
-
|
|
342
|
-
paidRequests.push({
|
|
343
|
-
body: init?.body ?? null,
|
|
344
|
-
header: new Headers(init?.headers).get('x-test'),
|
|
345
|
-
method: init?.method,
|
|
346
|
-
})
|
|
347
|
-
return new Response('paid')
|
|
348
|
-
}
|
|
349
|
-
const fetch = Fetch.from({
|
|
350
|
-
fetch: rawFetch,
|
|
351
|
-
methods: [
|
|
352
|
-
session({
|
|
353
|
-
account,
|
|
354
|
-
decimals: 0,
|
|
355
|
-
getClient: () => client,
|
|
356
|
-
maxDeposit: '300',
|
|
357
|
-
}),
|
|
358
|
-
],
|
|
359
|
-
})
|
|
360
|
-
|
|
361
|
-
expect(await (await fetch('https://example.com/resource')).text()).toBe('opened')
|
|
362
|
-
const response = await fetch('https://example.com/resource', {
|
|
363
|
-
body: 'request-body',
|
|
364
|
-
headers: { 'x-test': 'preserved' },
|
|
365
|
-
method: 'POST',
|
|
366
|
-
})
|
|
367
|
-
|
|
368
|
-
expect(await response.text()).toBe('paid')
|
|
369
|
-
expect(actions).toEqual(['open', 'topUp', 'voucher', 'voucher'])
|
|
370
|
-
expect(new Set(vouchers).size).toBe(1)
|
|
371
|
-
expect(paidRequests).toEqual([{ body: 'request-body', header: 'preserved', method: 'POST' }])
|
|
372
|
-
})
|
|
373
|
-
|
|
374
|
-
test('retries an open rejected by a replacement challenge', async () => {
|
|
375
|
-
const challenge = makeSessionChallenge({ suggestedDeposit: '1000' })
|
|
376
|
-
const replacement = { ...challenge, id: 'replacement-id' }
|
|
377
|
-
const channelStore = createChannelStore()
|
|
378
|
-
const actions: Types.SessionCredentialPayload['action'][] = []
|
|
379
|
-
let paidRequests = 0
|
|
380
|
-
const fetch = makeSessionFetch(async (_input, init) => {
|
|
381
|
-
const authorization = new Headers(init?.headers).get(Constants.Headers.authorization)
|
|
382
|
-
if (!authorization) return paymentRequired(challenge)
|
|
383
|
-
actions.push(deserialize(authorization).action)
|
|
384
|
-
if (++paidRequests === 1) return paymentRequired(replacement)
|
|
385
|
-
return new Response('rejected', { status: 500 })
|
|
386
|
-
}, channelStore)
|
|
387
|
-
|
|
388
|
-
expect((await fetch('https://example.com/resource')).status).toBe(500)
|
|
389
|
-
expect(actions).toEqual(['open', 'open'])
|
|
390
|
-
expect(await channelStore.get(defaultChannelKey)).toBeUndefined()
|
|
391
|
-
})
|
|
392
|
-
|
|
393
|
-
test('retries an open after the paid request throws', async () => {
|
|
394
|
-
const challenge = makeSessionChallenge({ suggestedDeposit: '1000' })
|
|
395
|
-
const actions: Types.SessionCredentialPayload['action'][] = []
|
|
396
|
-
const fetch = makeSessionFetch(async (_input, init) => {
|
|
397
|
-
const authorization = new Headers(init?.headers).get(Constants.Headers.authorization)
|
|
398
|
-
if (!authorization) return paymentRequired(challenge)
|
|
399
|
-
actions.push(deserialize(authorization).action)
|
|
400
|
-
throw new Error('paid request failed')
|
|
401
|
-
})
|
|
402
|
-
|
|
403
|
-
await expect(fetch('https://example.com/resource')).rejects.toThrow('paid request failed')
|
|
404
|
-
await expect(fetch('https://example.com/resource')).rejects.toThrow('paid request failed')
|
|
405
|
-
expect(actions).toEqual(['open', 'open'])
|
|
406
|
-
})
|
|
407
|
-
|
|
408
|
-
test('keeps an open acknowledged by a payment receipt', async () => {
|
|
409
|
-
const challenge = makeSessionChallenge({ suggestedDeposit: '1000' })
|
|
410
|
-
const channelStore = createChannelStore()
|
|
411
|
-
const actions: Types.SessionCredentialPayload['action'][] = []
|
|
412
|
-
const credentials: string[] = []
|
|
413
|
-
let paidRequests = 0
|
|
414
|
-
const fetch = makeSessionFetch(async (_input, init) => {
|
|
415
|
-
const authorization = new Headers(init?.headers).get(Constants.Headers.authorization)
|
|
416
|
-
if (!authorization) return paymentRequired(challenge)
|
|
417
|
-
const payload = deserialize(authorization)
|
|
418
|
-
actions.push(payload.action)
|
|
419
|
-
credentials.push(authorization)
|
|
420
|
-
if (++paidRequests === 1) return paymentRequired(challenge)
|
|
421
|
-
if (paidRequests > 2) return new Response('rejected', { status: 500 })
|
|
422
|
-
return paymentRequired(challenge, {
|
|
423
|
-
[Constants.Headers.paymentReceipt]: Types.serializeSessionReceipt(
|
|
424
|
-
Types.createSessionReceipt({
|
|
425
|
-
acceptedCumulative: 100n,
|
|
426
|
-
challengeId: challenge.id,
|
|
427
|
-
channelId: payload.channelId,
|
|
428
|
-
spent: 100n,
|
|
429
|
-
}),
|
|
430
|
-
),
|
|
431
|
-
})
|
|
432
|
-
}, channelStore)
|
|
433
|
-
|
|
434
|
-
expect((await fetch('https://example.com/resource')).status).toBe(500)
|
|
435
|
-
expect(actions).toEqual(['open', 'open', 'voucher'])
|
|
436
|
-
expect(credentials[0]).toBe(credentials[1])
|
|
437
|
-
expect(await channelStore.get(defaultChannelKey)).toMatchObject({ opened: true })
|
|
438
|
-
})
|
|
439
|
-
|
|
440
|
-
test.each([
|
|
441
|
-
[
|
|
442
|
-
'keeps an open acknowledged by the final session snapshot',
|
|
443
|
-
undefined,
|
|
444
|
-
['open', 'voucher'],
|
|
445
|
-
true,
|
|
446
|
-
],
|
|
447
|
-
[
|
|
448
|
-
'fails closed on malformed acknowledgement snapshots without leaking the open lock',
|
|
449
|
-
'not-a-number',
|
|
450
|
-
['open', 'open'],
|
|
451
|
-
undefined,
|
|
452
|
-
],
|
|
453
|
-
])('%s', async (_name, acceptedCumulative, expectedActions, expectedOpened) => {
|
|
454
|
-
const challenge = makeSessionChallenge({ suggestedDeposit: '1000' })
|
|
455
|
-
const channelStore = createChannelStore()
|
|
456
|
-
const actions: Types.SessionCredentialPayload['action'][] = []
|
|
457
|
-
let paidRequests = 0
|
|
458
|
-
const fetch = makeSessionFetch(
|
|
459
|
-
async (_input, init) => {
|
|
460
|
-
const authorization = new Headers(init?.headers).get(Constants.Headers.authorization)
|
|
461
|
-
if (!authorization) return paymentRequired(challenge)
|
|
462
|
-
const payload = deserialize(authorization)
|
|
463
|
-
actions.push(payload.action)
|
|
464
|
-
if (++paidRequests > 1) return new Response('rejected', { status: 500 })
|
|
465
|
-
return paymentRequired(withSnapshot(payload, acceptedCumulative))
|
|
466
|
-
},
|
|
467
|
-
channelStore,
|
|
468
|
-
1,
|
|
469
|
-
)
|
|
470
|
-
|
|
471
|
-
expect((await fetch('https://example.com/resource')).status).toBe(402)
|
|
472
|
-
expect((await fetch('https://example.com/resource')).status).toBe(500)
|
|
473
|
-
expect(actions).toEqual(expectedActions)
|
|
474
|
-
expect((await channelStore.get(defaultChannelKey))?.opened).toBe(expectedOpened)
|
|
475
|
-
})
|
|
476
|
-
|
|
477
|
-
test('keeps an acknowledged open when challenge ordering throws', async () => {
|
|
478
|
-
const challenge = makeSessionChallenge({ suggestedDeposit: '1000' })
|
|
479
|
-
const channelStore = createChannelStore()
|
|
480
|
-
const actions: Types.SessionCredentialPayload['action'][] = []
|
|
481
|
-
let ordered = 0
|
|
482
|
-
let paidRequests = 0
|
|
483
|
-
const fetch = Fetch.from({
|
|
484
|
-
fetch: async (_input, init) => {
|
|
485
|
-
const authorization = new Headers(init?.headers).get(Constants.Headers.authorization)
|
|
486
|
-
if (!authorization) return paymentRequired(challenge)
|
|
487
|
-
const payload = deserialize(authorization)
|
|
488
|
-
actions.push(payload.action)
|
|
489
|
-
if (++paidRequests > 1) return new Response('paid')
|
|
490
|
-
return paymentRequired(withSnapshot(payload))
|
|
491
|
-
},
|
|
492
|
-
methods: [makeSessionMethod(channelStore)],
|
|
493
|
-
orderChallenges(candidates) {
|
|
494
|
-
if (++ordered === 2) throw new Error('ordering failed')
|
|
495
|
-
return candidates
|
|
496
|
-
},
|
|
497
|
-
})
|
|
498
|
-
|
|
499
|
-
await expect(fetch('https://example.com/resource')).rejects.toThrow('ordering failed')
|
|
500
|
-
expect(await (await fetch('https://example.com/resource')).text()).toBe('paid')
|
|
501
|
-
expect(actions).toEqual(['open', 'voucher'])
|
|
502
|
-
expect(await channelStore.get(defaultChannelKey)).toMatchObject({ opened: true })
|
|
503
|
-
})
|
|
504
|
-
|
|
505
|
-
test('serializes concurrent opens against the committed channel', async () => {
|
|
506
|
-
const challenge = makeSessionChallenge()
|
|
507
|
-
const channelStore = createChannelStore()
|
|
508
|
-
const actions: Types.SessionCredentialPayload['action'][] = []
|
|
509
|
-
const vouchers: bigint[] = []
|
|
510
|
-
const firstGate = Promise.withResolvers<void>()
|
|
511
|
-
const firstRequest = Promise.withResolvers<void>()
|
|
512
|
-
const waitersReady = Promise.withResolvers<void>()
|
|
513
|
-
let credentialPlans = 0
|
|
514
|
-
const fetch = Fetch.from({
|
|
515
|
-
fetch: async (input, init) => {
|
|
516
|
-
const authorization = new Headers(init?.headers).get(Constants.Headers.authorization)
|
|
517
|
-
if (!authorization) return paymentRequired(challenge)
|
|
518
|
-
const payload = deserialize(authorization)
|
|
519
|
-
actions.push(payload.action)
|
|
520
|
-
if (payload.action === 'topUp') return new Response(null, { status: 204 })
|
|
521
|
-
if (payload.action === 'voucher') vouchers.push(BigInt(payload.cumulativeAmount))
|
|
522
|
-
if (input.toString().endsWith('/first')) {
|
|
523
|
-
firstRequest.resolve()
|
|
524
|
-
await firstGate.promise
|
|
525
|
-
return new Response('paid')
|
|
526
|
-
}
|
|
527
|
-
return new Response('rejected', { status: 500 })
|
|
528
|
-
},
|
|
529
|
-
methods: [
|
|
530
|
-
makeSessionMethod(channelStore, {
|
|
531
|
-
resolveAccount() {
|
|
532
|
-
if (++credentialPlans === 3) waitersReady.resolve()
|
|
533
|
-
return account
|
|
534
|
-
},
|
|
535
|
-
}),
|
|
536
|
-
],
|
|
537
|
-
})
|
|
538
|
-
|
|
539
|
-
const first = fetch('https://example.com/first')
|
|
540
|
-
await firstRequest.promise
|
|
541
|
-
const second = fetch('https://example.com/second')
|
|
542
|
-
const third = fetch('https://example.com/third')
|
|
543
|
-
await waitersReady.promise
|
|
544
|
-
firstGate.resolve()
|
|
545
|
-
|
|
546
|
-
expect((await first).status).toBe(200)
|
|
547
|
-
expect((await second).status).toBe(500)
|
|
548
|
-
expect((await third).status).toBe(500)
|
|
549
|
-
expect(actions).toEqual(['open', 'topUp', 'voucher', 'topUp', 'voucher'])
|
|
550
|
-
expect(vouchers).toEqual([200n, 300n])
|
|
551
|
-
expect(await channelStore.get(defaultChannelKey)).toMatchObject({ opened: true })
|
|
552
|
-
})
|
|
553
|
-
|
|
554
|
-
test('replaces a stored channel owned by another account', async () => {
|
|
555
|
-
const channelStore = createChannelStore()
|
|
556
|
-
const foreign = '0x0000000000000000000000000000000000000004' as Address
|
|
557
|
-
await channelStore.set({
|
|
558
|
-
chainId,
|
|
559
|
-
channelId: `0x${'44'.repeat(32)}`,
|
|
560
|
-
cumulativeAmount: 100n,
|
|
561
|
-
deposit: 100n,
|
|
562
|
-
descriptor: { ...descriptor, authorizedSigner: foreign, payer: foreign },
|
|
563
|
-
escrow: tip20ChannelEscrow,
|
|
564
|
-
opened: true,
|
|
565
|
-
})
|
|
566
|
-
const actions: Types.SessionCredentialPayload['action'][] = []
|
|
567
|
-
const challenge = makeSessionChallenge({ suggestedDeposit: '1000' })
|
|
568
|
-
const fetch = makeSessionFetch(async (_input, init) => {
|
|
569
|
-
const authorization = new Headers(init?.headers).get(Constants.Headers.authorization)
|
|
570
|
-
if (!authorization) return paymentRequired(challenge)
|
|
571
|
-
actions.push(deserialize(authorization).action)
|
|
572
|
-
return new Response('paid')
|
|
573
|
-
}, channelStore)
|
|
574
|
-
|
|
575
|
-
expect(await (await fetch('https://example.com/resource')).text()).toBe('paid')
|
|
576
|
-
expect(await (await fetch('https://example.com/resource')).text()).toBe('paid')
|
|
577
|
-
expect(actions).toEqual(['open', 'voucher'])
|
|
578
|
-
expect(await channelStore.get(defaultChannelKey)).toMatchObject({
|
|
579
|
-
descriptor: { authorizedSigner: account.address, payer: account.address },
|
|
580
|
-
opened: true,
|
|
581
|
-
})
|
|
582
|
-
})
|
|
583
|
-
|
|
584
|
-
test('uses a matching server snapshot deposit when checking headroom', async () => {
|
|
585
|
-
const channelStore = createChannelStore()
|
|
586
|
-
const channelId = Channel.computeId({ ...descriptor, chainId, escrow: tip20ChannelEscrow })
|
|
587
|
-
await channelStore.set({
|
|
588
|
-
chainId,
|
|
589
|
-
channelId,
|
|
590
|
-
cumulativeAmount: 100n,
|
|
591
|
-
deposit: 100n,
|
|
592
|
-
descriptor,
|
|
593
|
-
escrow: tip20ChannelEscrow,
|
|
594
|
-
opened: true,
|
|
595
|
-
})
|
|
596
|
-
const challenge = makeChallenge({
|
|
597
|
-
methodDetails: {
|
|
598
|
-
chainId,
|
|
599
|
-
escrowContract: tip20ChannelEscrow,
|
|
600
|
-
sessionProtocol: Constants.SessionProtocols.v2,
|
|
601
|
-
sessionSnapshot: {
|
|
602
|
-
acceptedCumulative: '100',
|
|
603
|
-
chainId,
|
|
604
|
-
channelId,
|
|
605
|
-
deposit: '200',
|
|
606
|
-
descriptor,
|
|
607
|
-
escrow: tip20ChannelEscrow,
|
|
608
|
-
requiredCumulative: '200',
|
|
609
|
-
settled: '0',
|
|
610
|
-
spent: '100',
|
|
611
|
-
units: 1,
|
|
612
|
-
},
|
|
613
|
-
},
|
|
614
|
-
})
|
|
615
|
-
let updatedDeposit = 0n
|
|
616
|
-
const method = session({
|
|
617
|
-
account,
|
|
618
|
-
channelStore,
|
|
619
|
-
decimals: 0,
|
|
620
|
-
getClient: () => client,
|
|
621
|
-
onChannelUpdate: (entry) => {
|
|
622
|
-
updatedDeposit = entry.deposit
|
|
623
|
-
},
|
|
624
|
-
})
|
|
625
|
-
|
|
626
|
-
await expect(
|
|
627
|
-
MethodChallenge.handle(method, {
|
|
628
|
-
challenge,
|
|
629
|
-
context: {},
|
|
630
|
-
fetch: async () => {
|
|
631
|
-
throw new Error('unexpected top-up')
|
|
632
|
-
},
|
|
633
|
-
input: 'https://example.com/resource',
|
|
634
|
-
}),
|
|
635
|
-
).resolves.toBeUndefined()
|
|
636
|
-
expect(updatedDeposit).toBe(200n)
|
|
637
|
-
})
|
|
638
|
-
|
|
639
|
-
test('opens for the current amount without client deposit configuration', async () => {
|
|
640
|
-
const method = session({ account, getClient: () => client })
|
|
641
|
-
const payload = deserialize(
|
|
642
|
-
await method.createCredential({ challenge: makeChallenge(), context: {} }),
|
|
643
|
-
)
|
|
644
|
-
|
|
645
|
-
expect(payload.action).toBe('open')
|
|
646
|
-
expect(openDeposit(payload)).toBe(100n)
|
|
647
|
-
})
|
|
648
|
-
|
|
649
|
-
test('atomically auto-swaps before opening a session channel', async () => {
|
|
650
|
-
const sourceToken = '0x0000000000000000000000000000000000000007' as Address
|
|
651
|
-
const swapCalls = [
|
|
652
|
-
{ to: sourceToken, data: '0x1234' as const },
|
|
653
|
-
{ to: '0x0000000000000000000000000000000000000008' as Address, data: '0x5678' as const },
|
|
654
|
-
]
|
|
655
|
-
const findCalls = vi.spyOn(AutoSwap, 'findCalls').mockResolvedValue(swapCalls)
|
|
656
|
-
try {
|
|
657
|
-
const method = session({
|
|
658
|
-
account,
|
|
659
|
-
autoSwap: { slippage: 2, tokenIn: [sourceToken] },
|
|
660
|
-
getClient: () => client,
|
|
661
|
-
})
|
|
662
|
-
const payload = deserialize(
|
|
663
|
-
await method.createCredential({ challenge: makeChallenge(), context: {} }),
|
|
664
|
-
)
|
|
665
|
-
|
|
666
|
-
expect(findCalls).toHaveBeenCalledWith(expect.any(Object), {
|
|
667
|
-
account: account.address,
|
|
668
|
-
amountOut: 100n,
|
|
669
|
-
slippage: 2,
|
|
670
|
-
tokenIn: expect.arrayContaining([sourceToken]),
|
|
671
|
-
tokenOut: descriptor.token,
|
|
672
|
-
})
|
|
673
|
-
const calls = transactionCalls(payload)
|
|
674
|
-
expect(calls.slice(0, 2)).toEqual(swapCalls)
|
|
675
|
-
expect(calls[2]!.to?.toLowerCase()).toBe(tip20ChannelEscrow.toLowerCase())
|
|
676
|
-
expect(decodeFunctionData({ abi: escrowAbi, data: calls[2]!.data! }).functionName).toBe(
|
|
677
|
-
'open',
|
|
678
|
-
)
|
|
679
|
-
} finally {
|
|
680
|
-
findCalls.mockRestore()
|
|
681
|
-
}
|
|
682
|
-
})
|
|
683
|
-
|
|
684
|
-
test('atomically auto-swaps before topping up a session channel', async () => {
|
|
685
|
-
const sourceToken = '0x0000000000000000000000000000000000000007' as Address
|
|
686
|
-
const swapCalls = [{ to: sourceToken, data: '0x1234' as const }]
|
|
687
|
-
const findCalls = vi.spyOn(AutoSwap, 'findCalls').mockResolvedValue(swapCalls)
|
|
688
|
-
try {
|
|
689
|
-
const method = session({ account, autoSwap: true, getClient: () => client })
|
|
690
|
-
const payload = deserialize(
|
|
691
|
-
await method.createCredential({
|
|
692
|
-
challenge: makeChallenge(),
|
|
693
|
-
context: { action: 'topUp', additionalDepositRaw: '250', descriptor },
|
|
694
|
-
}),
|
|
695
|
-
)
|
|
696
|
-
|
|
697
|
-
expect(findCalls).toHaveBeenCalledWith(expect.any(Object), {
|
|
698
|
-
account: account.address,
|
|
699
|
-
amountOut: 250n,
|
|
700
|
-
slippage: 1,
|
|
701
|
-
tokenIn: AutoSwap.defaultCurrencies,
|
|
702
|
-
tokenOut: descriptor.token,
|
|
703
|
-
})
|
|
704
|
-
const calls = transactionCalls(payload)
|
|
705
|
-
expect(calls[0]).toEqual(swapCalls[0])
|
|
706
|
-
expect(calls[1]!.to?.toLowerCase()).toBe(tip20ChannelEscrow.toLowerCase())
|
|
707
|
-
expect(decodeFunctionData({ abi: escrowAbi, data: calls[1]!.data! }).functionName).toBe(
|
|
708
|
-
'topUp',
|
|
709
|
-
)
|
|
710
|
-
} finally {
|
|
711
|
-
findCalls.mockRestore()
|
|
712
|
-
}
|
|
713
|
-
})
|
|
714
|
-
|
|
715
|
-
test('uses client chain ID when the challenge omits chain ID', async () => {
|
|
716
|
-
const method = session({ account, getClient: () => client })
|
|
717
|
-
const credential = deserializeCredential(
|
|
718
|
-
await method.createCredential({
|
|
719
|
-
challenge: makeChallenge({
|
|
720
|
-
methodDetails: { escrowContract: tip20ChannelEscrow },
|
|
721
|
-
}),
|
|
722
|
-
context: {},
|
|
723
|
-
}),
|
|
724
|
-
)
|
|
725
|
-
const payload = credential.payload
|
|
726
|
-
|
|
727
|
-
if (payload.action !== 'open') throw new Error('expected open payload')
|
|
728
|
-
expect(credential.source).toBe(`did:pkh:eip155:${chainId}:${account.address}`)
|
|
729
|
-
expect(payload.channelId).toBe(
|
|
730
|
-
Channel.computeId({ ...payload.descriptor, chainId, escrow: tip20ChannelEscrow }),
|
|
731
|
-
)
|
|
732
|
-
})
|
|
733
|
-
|
|
734
|
-
test('uses explicit context depositRaw before server hints', async () => {
|
|
735
|
-
const method = session({ account, getClient: () => client })
|
|
736
|
-
const payload = deserialize(
|
|
737
|
-
await method.createCredential({
|
|
738
|
-
challenge: makeChallenge(),
|
|
739
|
-
context: { depositRaw: '500' },
|
|
740
|
-
}),
|
|
741
|
-
)
|
|
742
|
-
|
|
743
|
-
expect(payload.action).toBe('open')
|
|
744
|
-
expect(openDeposit(payload)).toBe(500n)
|
|
745
|
-
})
|
|
746
|
-
|
|
747
|
-
test('caps suggestedDeposit by maxDeposit', async () => {
|
|
748
|
-
const method = session({ account, decimals: 0, maxDeposit: '500', getClient: () => client })
|
|
749
|
-
const payload = deserialize(
|
|
750
|
-
await method.createCredential({
|
|
751
|
-
challenge: makeChallenge({ suggestedDeposit: '1000' }),
|
|
752
|
-
context: {},
|
|
753
|
-
}),
|
|
754
|
-
)
|
|
755
|
-
|
|
756
|
-
expect(payload.action).toBe('open')
|
|
757
|
-
expect(openDeposit(payload)).toBe(500n)
|
|
758
|
-
})
|
|
759
|
-
|
|
760
|
-
test('uses suggestedDeposit when below maxDeposit', async () => {
|
|
761
|
-
const method = session({ account, decimals: 0, maxDeposit: '1000', getClient: () => client })
|
|
762
|
-
const payload = deserialize(
|
|
763
|
-
await method.createCredential({
|
|
764
|
-
challenge: makeChallenge({ suggestedDeposit: '700' }),
|
|
765
|
-
context: {},
|
|
766
|
-
}),
|
|
767
|
-
)
|
|
768
|
-
|
|
769
|
-
expect(payload.action).toBe('open')
|
|
770
|
-
expect(openDeposit(payload)).toBe(700n)
|
|
771
|
-
})
|
|
772
|
-
|
|
773
|
-
test('uses current amount without suggestedDeposit even when maxDeposit is higher', async () => {
|
|
774
|
-
const method = session({ account, decimals: 0, maxDeposit: '1000', getClient: () => client })
|
|
775
|
-
const payload = deserialize(
|
|
776
|
-
await method.createCredential({ challenge: makeChallenge(), context: {} }),
|
|
777
|
-
)
|
|
778
|
-
|
|
779
|
-
expect(payload.action).toBe('open')
|
|
780
|
-
expect(openDeposit(payload)).toBe(100n)
|
|
781
|
-
})
|
|
782
|
-
|
|
783
|
-
test('rejects open above maxDeposit without leaking the Fetch lock', async () => {
|
|
784
|
-
const method = session({ account, decimals: 0, maxDeposit: '50', getClient: () => client })
|
|
785
|
-
const fetch = Fetch.from({
|
|
786
|
-
fetch: async () => paymentRequired(makeSessionChallenge()),
|
|
787
|
-
methods: [method],
|
|
788
|
-
})
|
|
789
|
-
|
|
790
|
-
for (let attempt = 0; attempt < 2; attempt++)
|
|
791
|
-
await expect(fetch('https://example.com/resource')).rejects.toThrow(
|
|
792
|
-
'requested voucher amount 100 exceeds local maxDeposit 50',
|
|
793
|
-
)
|
|
794
|
-
})
|
|
795
|
-
|
|
796
|
-
test('rejects explicit opening deposits below the request amount', async () => {
|
|
797
|
-
const method = session({ account, decimals: 0, maxDeposit: '1000', getClient: () => client })
|
|
798
|
-
|
|
799
|
-
await expect(
|
|
800
|
-
method.createCredential({
|
|
801
|
-
challenge: makeChallenge(),
|
|
802
|
-
context: { depositRaw: '50' },
|
|
803
|
-
}),
|
|
804
|
-
).rejects.toThrow('opening deposit 50 below request amount 100')
|
|
805
|
-
})
|
|
806
|
-
|
|
807
|
-
test('uses resolved escrow address for open transactions', async () => {
|
|
808
|
-
const challengeEscrow = '0x0000000000000000000000000000000000000005' as Address
|
|
809
|
-
const method = session({ account, decimals: 0, getClient: () => client })
|
|
810
|
-
const payload = deserialize(
|
|
811
|
-
await method.createCredential({
|
|
812
|
-
challenge: makeChallenge({
|
|
813
|
-
methodDetails: { chainId, escrowContract: challengeEscrow },
|
|
814
|
-
}),
|
|
815
|
-
context: {},
|
|
816
|
-
}),
|
|
817
|
-
)
|
|
818
|
-
|
|
819
|
-
if (payload.action !== 'open') throw new Error('expected open payload')
|
|
820
|
-
const transaction = Transaction.deserialize(payload.transaction)
|
|
821
|
-
if (!('calls' in transaction)) throw new Error('expected tempo calls')
|
|
822
|
-
const calls = transaction.calls as readonly { to?: Address; data?: `0x${string}` }[]
|
|
823
|
-
expect(calls[0]!.to?.toLowerCase()).toBe(challengeEscrow.toLowerCase())
|
|
824
|
-
expect(payload.channelId).toBe(
|
|
825
|
-
Channel.computeId({ ...payload.descriptor, chainId, escrow: challengeEscrow }),
|
|
826
|
-
)
|
|
827
|
-
})
|
|
828
|
-
|
|
829
|
-
test('uses challenge-advertised operator for open transactions', async () => {
|
|
830
|
-
const operator = '0x0000000000000000000000000000000000000006' as Address
|
|
831
|
-
const method = session({ account, decimals: 0, getClient: () => client })
|
|
832
|
-
const payload = deserialize(
|
|
833
|
-
await method.createCredential({
|
|
834
|
-
challenge: makeChallenge({
|
|
835
|
-
methodDetails: { chainId, escrowContract: tip20ChannelEscrow, operator },
|
|
836
|
-
}),
|
|
837
|
-
context: {},
|
|
838
|
-
}),
|
|
839
|
-
)
|
|
840
|
-
|
|
841
|
-
if (payload.action !== 'open') throw new Error('expected open payload')
|
|
842
|
-
expect(openArgs(payload)[1].toLowerCase()).toBe(operator.toLowerCase())
|
|
843
|
-
expect(payload.descriptor.operator.toLowerCase()).toBe(operator.toLowerCase())
|
|
844
|
-
})
|
|
845
|
-
|
|
846
|
-
test('tracks cumulative amount and calls onChannelUpdate in auto mode', async () => {
|
|
847
|
-
const updates: bigint[] = []
|
|
848
|
-
const method = session({
|
|
849
|
-
account,
|
|
850
|
-
decimals: 0,
|
|
851
|
-
maxDeposit: '1000',
|
|
852
|
-
getClient: () => client,
|
|
853
|
-
onChannelUpdate: (entry) => updates.push(entry.cumulativeAmount),
|
|
854
|
-
})
|
|
855
|
-
const first = deserialize(
|
|
856
|
-
await method.createCredential({ challenge: makeChallenge(), context: {} }),
|
|
857
|
-
)
|
|
858
|
-
const second = deserialize(
|
|
859
|
-
await method.createCredential({ challenge: makeChallenge(), context: {} }),
|
|
860
|
-
)
|
|
861
|
-
|
|
862
|
-
expect(first.action).toBe('open')
|
|
863
|
-
expect(second.action).toBe('voucher')
|
|
864
|
-
if (second.action !== 'voucher') throw new Error('expected voucher')
|
|
865
|
-
expect(second.channelId).toBe(first.channelId)
|
|
866
|
-
expect(second.cumulativeAmount).toBe('200')
|
|
867
|
-
expect(updates).toEqual([100n, 200n])
|
|
868
|
-
})
|
|
869
|
-
|
|
870
|
-
test('passes existing channel authority to resolveAccount before reusing session channel', async () => {
|
|
871
|
-
const accessKey = TempoAccount.fromSecp256k1(Secp256k1.randomPrivateKey(), {
|
|
872
|
-
access: account,
|
|
873
|
-
})
|
|
874
|
-
const calls: session.ResolveAccountInfo[] = []
|
|
875
|
-
const method = session({
|
|
876
|
-
account,
|
|
877
|
-
decimals: 0,
|
|
878
|
-
maxDeposit: '1000',
|
|
879
|
-
getClient: () => client,
|
|
880
|
-
resolveAccount(info) {
|
|
881
|
-
calls.push(info)
|
|
882
|
-
return accessKey
|
|
883
|
-
},
|
|
884
|
-
})
|
|
885
|
-
const first = deserializeCredential(
|
|
886
|
-
await method.createCredential({ challenge: makeChallenge(), context: {} }),
|
|
887
|
-
)
|
|
888
|
-
const second = deserializeCredential(
|
|
889
|
-
await method.createCredential({ challenge: makeChallenge(), context: {} }),
|
|
890
|
-
)
|
|
891
|
-
|
|
892
|
-
expect(calls).toHaveLength(2)
|
|
893
|
-
expect(calls[0]!.account.address).toBe(account.address)
|
|
894
|
-
expect(calls[0]!.operation).toEqual({ kind: 'authorizePaymentChannel' })
|
|
895
|
-
expect(calls[1]!.operation).toEqual({
|
|
896
|
-
kind: 'authorizePaymentChannel',
|
|
897
|
-
authority: accessKey.accessKeyAddress,
|
|
898
|
-
})
|
|
899
|
-
expect(first.source).toBe(`did:pkh:eip155:${chainId}:${account.address}`)
|
|
900
|
-
expect(second.source).toBe(`did:pkh:eip155:${chainId}:${account.address}`)
|
|
901
|
-
expect(first.payload.action).toBe('open')
|
|
902
|
-
if (first.payload.action !== 'open' || second.payload.action !== 'voucher')
|
|
903
|
-
throw new Error('expected open then voucher payloads')
|
|
904
|
-
expect(first.payload.descriptor.payer).toBe(account.address)
|
|
905
|
-
expect(first.payload.descriptor.authorizedSigner).toBe(accessKey.accessKeyAddress)
|
|
906
|
-
expect(second.payload.channelId).toBe(first.payload.channelId)
|
|
907
|
-
expect(second.payload.cumulativeAmount).toBe('200')
|
|
908
|
-
})
|
|
909
|
-
|
|
910
|
-
test('enforces maxDeposit when reusing a cached auto-mode channel', async () => {
|
|
911
|
-
const updates: bigint[] = []
|
|
912
|
-
const method = session({
|
|
913
|
-
account,
|
|
914
|
-
decimals: 0,
|
|
915
|
-
maxDeposit: '150',
|
|
916
|
-
getClient: () => client,
|
|
917
|
-
onChannelUpdate: (entry) => updates.push(entry.cumulativeAmount),
|
|
918
|
-
})
|
|
919
|
-
|
|
920
|
-
await method.createCredential({ challenge: makeChallenge(), context: {} })
|
|
921
|
-
|
|
922
|
-
await expect(
|
|
923
|
-
method.createCredential({ challenge: makeChallenge(), context: {} }),
|
|
924
|
-
).rejects.toThrow('requested voucher amount 200 exceeds local maxDeposit 150')
|
|
925
|
-
expect(updates).toEqual([100n])
|
|
926
|
-
})
|
|
927
|
-
|
|
928
|
-
test('recovers and reuses a descriptor supplied in context', async () => {
|
|
929
|
-
const updates: bigint[] = []
|
|
930
|
-
const method = session({
|
|
931
|
-
account,
|
|
932
|
-
decimals: 0,
|
|
933
|
-
maxDeposit: '1000',
|
|
934
|
-
getClient: () => client,
|
|
935
|
-
onChannelUpdate: (entry) => updates.push(entry.cumulativeAmount),
|
|
936
|
-
})
|
|
937
|
-
const channelId = Channel.computeId({ ...descriptor, chainId, escrow: tip20ChannelEscrow })
|
|
938
|
-
const recovered = deserialize(
|
|
939
|
-
await method.createCredential({
|
|
940
|
-
challenge: makeChallenge(),
|
|
941
|
-
context: { channelId, descriptor },
|
|
942
|
-
}),
|
|
943
|
-
)
|
|
944
|
-
const next = deserialize(
|
|
945
|
-
await method.createCredential({ challenge: makeChallenge(), context: {} }),
|
|
946
|
-
)
|
|
947
|
-
|
|
948
|
-
expect(recovered.action).toBe('voucher')
|
|
949
|
-
if (recovered.action !== 'voucher' || next.action !== 'voucher')
|
|
950
|
-
throw new Error('expected voucher')
|
|
951
|
-
expect(recovered.channelId).toBe(channelId)
|
|
952
|
-
expect(recovered.cumulativeAmount).toBe('100')
|
|
953
|
-
expect(next.channelId).toBe(channelId)
|
|
954
|
-
expect(next.cumulativeAmount).toBe('200')
|
|
955
|
-
expect(updates).toEqual([100n, 200n])
|
|
956
|
-
})
|
|
957
|
-
|
|
958
|
-
test('increments stored cumulative when recovering without a server snapshot', async () => {
|
|
959
|
-
const method = session({ account, decimals: 0, maxDeposit: '1000', getClient: () => client })
|
|
960
|
-
const channelId = Channel.computeId({ ...descriptor, chainId, escrow: tip20ChannelEscrow })
|
|
961
|
-
const payload = deserialize(
|
|
962
|
-
await method.createCredential({
|
|
963
|
-
challenge: makeChallenge(),
|
|
964
|
-
context: { channelId, cumulativeAmountRaw: '100', descriptor },
|
|
965
|
-
}),
|
|
966
|
-
)
|
|
967
|
-
|
|
968
|
-
expect(payload.action).toBe('voucher')
|
|
969
|
-
if (payload.action !== 'voucher') throw new Error('expected voucher')
|
|
970
|
-
expect(payload.channelId).toBe(channelId)
|
|
971
|
-
expect(payload.cumulativeAmount).toBe('200')
|
|
972
|
-
})
|
|
973
|
-
|
|
974
|
-
test('uses required server snapshot cumulative when recovering a channel', async () => {
|
|
975
|
-
const method = session({ account, decimals: 0, maxDeposit: '1000', getClient: () => client })
|
|
976
|
-
const channelId = Channel.computeId({ ...descriptor, chainId, escrow: tip20ChannelEscrow })
|
|
977
|
-
const payload = deserialize(
|
|
978
|
-
await method.createCredential({
|
|
979
|
-
challenge: makeChallenge({
|
|
980
|
-
methodDetails: {
|
|
981
|
-
chainId,
|
|
982
|
-
escrowContract: tip20ChannelEscrow,
|
|
983
|
-
sessionSnapshot: {
|
|
984
|
-
acceptedCumulative: '400',
|
|
985
|
-
chainId,
|
|
986
|
-
channelId,
|
|
987
|
-
deposit: '1000',
|
|
988
|
-
descriptor,
|
|
989
|
-
escrow: tip20ChannelEscrow,
|
|
990
|
-
requiredCumulative: '400',
|
|
991
|
-
settled: '0',
|
|
992
|
-
spent: '300',
|
|
993
|
-
units: 3,
|
|
994
|
-
},
|
|
995
|
-
},
|
|
996
|
-
}),
|
|
997
|
-
context: {},
|
|
998
|
-
}),
|
|
999
|
-
)
|
|
1000
|
-
|
|
1001
|
-
expect(payload.action).toBe('voucher')
|
|
1002
|
-
if (payload.action !== 'voucher') throw new Error('expected voucher')
|
|
1003
|
-
expect(payload.channelId).toBe(channelId)
|
|
1004
|
-
expect(payload.descriptor).toEqual(descriptor)
|
|
1005
|
-
expect(payload.cumulativeAmount).toBe('400')
|
|
1006
|
-
})
|
|
1007
|
-
|
|
1008
|
-
test('does not decrease recovered authorization below accepted snapshot headroom', async () => {
|
|
1009
|
-
const method = session({ account, decimals: 0, maxDeposit: '1000', getClient: () => client })
|
|
1010
|
-
const channelId = Channel.computeId({ ...descriptor, chainId, escrow: tip20ChannelEscrow })
|
|
1011
|
-
const payload = deserialize(
|
|
1012
|
-
await method.createCredential({
|
|
1013
|
-
challenge: makeChallenge({
|
|
1014
|
-
methodDetails: {
|
|
1015
|
-
chainId,
|
|
1016
|
-
escrowContract: tip20ChannelEscrow,
|
|
1017
|
-
sessionSnapshot: {
|
|
1018
|
-
acceptedCumulative: '500',
|
|
1019
|
-
chainId,
|
|
1020
|
-
channelId,
|
|
1021
|
-
deposit: '1000',
|
|
1022
|
-
descriptor,
|
|
1023
|
-
escrow: tip20ChannelEscrow,
|
|
1024
|
-
requiredCumulative: '400',
|
|
1025
|
-
settled: '0',
|
|
1026
|
-
spent: '300',
|
|
1027
|
-
units: 3,
|
|
1028
|
-
},
|
|
1029
|
-
},
|
|
1030
|
-
}),
|
|
1031
|
-
context: {},
|
|
1032
|
-
}),
|
|
1033
|
-
)
|
|
1034
|
-
|
|
1035
|
-
expect(payload.action).toBe('voucher')
|
|
1036
|
-
if (payload.action !== 'voucher') throw new Error('expected voucher')
|
|
1037
|
-
expect(payload.cumulativeAmount).toBe('500')
|
|
1038
|
-
})
|
|
1039
|
-
|
|
1040
|
-
test('caps recovered voucher authorization by maxDeposit', async () => {
|
|
1041
|
-
const method = session({ account, decimals: 0, maxDeposit: '300', getClient: () => client })
|
|
1042
|
-
const channelId = Channel.computeId({ ...descriptor, chainId, escrow: tip20ChannelEscrow })
|
|
1043
|
-
|
|
1044
|
-
await expect(
|
|
1045
|
-
method.createCredential({
|
|
1046
|
-
challenge: makeChallenge({
|
|
1047
|
-
methodDetails: {
|
|
1048
|
-
chainId,
|
|
1049
|
-
escrowContract: tip20ChannelEscrow,
|
|
1050
|
-
sessionSnapshot: {
|
|
1051
|
-
acceptedCumulative: '300',
|
|
1052
|
-
chainId,
|
|
1053
|
-
channelId,
|
|
1054
|
-
deposit: '1000',
|
|
1055
|
-
descriptor,
|
|
1056
|
-
escrow: tip20ChannelEscrow,
|
|
1057
|
-
requiredCumulative: '300',
|
|
1058
|
-
settled: '0',
|
|
1059
|
-
spent: '200',
|
|
1060
|
-
},
|
|
1061
|
-
},
|
|
1062
|
-
}),
|
|
1063
|
-
context: {},
|
|
1064
|
-
}),
|
|
1065
|
-
).resolves.toBeDefined()
|
|
1066
|
-
|
|
1067
|
-
const overLimitMethod = session({
|
|
1068
|
-
account,
|
|
1069
|
-
decimals: 0,
|
|
1070
|
-
maxDeposit: '300',
|
|
1071
|
-
getClient: () => client,
|
|
1072
|
-
})
|
|
1073
|
-
await expect(
|
|
1074
|
-
overLimitMethod.createCredential({
|
|
1075
|
-
challenge: makeChallenge({
|
|
1076
|
-
amount: '400',
|
|
1077
|
-
methodDetails: {
|
|
1078
|
-
chainId,
|
|
1079
|
-
escrowContract: tip20ChannelEscrow,
|
|
1080
|
-
sessionSnapshot: {
|
|
1081
|
-
acceptedCumulative: '1000',
|
|
1082
|
-
chainId,
|
|
1083
|
-
channelId,
|
|
1084
|
-
deposit: '1000',
|
|
1085
|
-
descriptor,
|
|
1086
|
-
escrow: tip20ChannelEscrow,
|
|
1087
|
-
requiredCumulative: '1000',
|
|
1088
|
-
settled: '0',
|
|
1089
|
-
spent: '300',
|
|
1090
|
-
},
|
|
1091
|
-
},
|
|
1092
|
-
}),
|
|
1093
|
-
context: {},
|
|
1094
|
-
}),
|
|
1095
|
-
).rejects.toThrow('requested voucher amount 1000 exceeds local maxDeposit 300')
|
|
1096
|
-
})
|
|
1097
|
-
|
|
1098
|
-
test('rejects descriptor recovery for closed or missing channels', async () => {
|
|
1099
|
-
const closedClient = createClient({
|
|
1100
|
-
account,
|
|
1101
|
-
chain: { id: chainId } as never,
|
|
1102
|
-
transport: custom({
|
|
1103
|
-
async request(args) {
|
|
1104
|
-
if (args.method === 'eth_chainId') return `0x${chainId.toString(16)}`
|
|
1105
|
-
if (args.method === 'eth_call')
|
|
1106
|
-
return encodeFunctionResult({
|
|
1107
|
-
abi: escrowAbi,
|
|
1108
|
-
functionName: 'getChannelState',
|
|
1109
|
-
result: { settled: 0n, deposit: 0n, closeRequestedAt: 0 },
|
|
1110
|
-
})
|
|
1111
|
-
throw new Error(`unexpected rpc request: ${args.method}`)
|
|
1112
|
-
},
|
|
1113
|
-
}),
|
|
1114
|
-
})
|
|
1115
|
-
const method = session({
|
|
1116
|
-
account,
|
|
1117
|
-
decimals: 0,
|
|
1118
|
-
maxDeposit: '1000',
|
|
1119
|
-
getClient: () => closedClient,
|
|
1120
|
-
})
|
|
1121
|
-
const channelId = Channel.computeId({ ...descriptor, chainId, escrow: tip20ChannelEscrow })
|
|
1122
|
-
|
|
1123
|
-
await expect(
|
|
1124
|
-
method.createCredential({
|
|
1125
|
-
challenge: makeChallenge(),
|
|
1126
|
-
context: { channelId, descriptor },
|
|
1127
|
-
}),
|
|
1128
|
-
).rejects.toThrow(/cannot be reused \(closed or not found on-chain\)/)
|
|
1129
|
-
})
|
|
1130
|
-
|
|
1131
|
-
test('rejects channel recovery without descriptor', async () => {
|
|
1132
|
-
const method = session({ account, decimals: 0, maxDeposit: '1000', getClient: () => client })
|
|
1133
|
-
|
|
1134
|
-
await expect(
|
|
1135
|
-
method.createCredential({
|
|
1136
|
-
challenge: makeChallenge(),
|
|
1137
|
-
context: { channelId: `0x${'33'.repeat(32)}` },
|
|
1138
|
-
}),
|
|
1139
|
-
).rejects.toThrow('descriptor required to reuse TIP-1034 channel')
|
|
1140
|
-
})
|
|
1141
|
-
|
|
1142
|
-
test('defaults precompile authorizedSigner to account access key address', async () => {
|
|
1143
|
-
const accessKeyAddress = '0x0000000000000000000000000000000000000009' as Address
|
|
1144
|
-
const accessKeyAccount = Object.assign({}, account, { accessKeyAddress })
|
|
1145
|
-
const method = session({
|
|
1146
|
-
account: accessKeyAccount,
|
|
1147
|
-
decimals: 0,
|
|
1148
|
-
maxDeposit: '1000',
|
|
1149
|
-
getClient: () => client,
|
|
1150
|
-
})
|
|
1151
|
-
const payload = deserialize(
|
|
1152
|
-
await method.createCredential({ challenge: makeChallenge(), context: {} }),
|
|
1153
|
-
)
|
|
1154
|
-
|
|
1155
|
-
expect(payload.action).toBe('open')
|
|
1156
|
-
if (payload.action !== 'open') throw new Error('expected open payload')
|
|
1157
|
-
expect(payload.descriptor.authorizedSigner).toBe(accessKeyAddress)
|
|
1158
|
-
})
|
|
1159
|
-
|
|
1160
|
-
test('manual open requires transaction', async () => {
|
|
1161
|
-
const method = session({ account, getClient: () => client })
|
|
1162
|
-
|
|
1163
|
-
await expect(
|
|
1164
|
-
method.createCredential({
|
|
1165
|
-
challenge: makeChallenge(),
|
|
1166
|
-
context: { action: 'open', descriptor, cumulativeAmountRaw: '100' },
|
|
1167
|
-
}),
|
|
1168
|
-
).rejects.toThrow('transaction required for open action')
|
|
1169
|
-
})
|
|
1170
|
-
|
|
1171
|
-
test('manual open requires cumulativeAmount', async () => {
|
|
1172
|
-
const method = session({ account, getClient: () => client })
|
|
1173
|
-
|
|
1174
|
-
await expect(
|
|
1175
|
-
method.createCredential({
|
|
1176
|
-
challenge: makeChallenge(),
|
|
1177
|
-
context: { action: 'open', descriptor, transaction: '0x1234' },
|
|
1178
|
-
}),
|
|
1179
|
-
).rejects.toThrow('cumulativeAmount required for open action')
|
|
1180
|
-
})
|
|
1181
|
-
|
|
1182
|
-
test('manual topUp requires additionalDeposit', async () => {
|
|
1183
|
-
const method = session({ account, getClient: () => client })
|
|
1184
|
-
|
|
1185
|
-
await expect(
|
|
1186
|
-
method.createCredential({
|
|
1187
|
-
challenge: makeChallenge(),
|
|
1188
|
-
context: { action: 'topUp', descriptor, transaction: '0x1234' },
|
|
1189
|
-
}),
|
|
1190
|
-
).rejects.toThrow('additionalDeposit required for topUp action')
|
|
1191
|
-
})
|
|
1192
|
-
|
|
1193
|
-
test('manual voucher requires cumulativeAmount', async () => {
|
|
1194
|
-
const method = session({ account, getClient: () => client })
|
|
1195
|
-
|
|
1196
|
-
await expect(
|
|
1197
|
-
method.createCredential({
|
|
1198
|
-
challenge: makeChallenge(),
|
|
1199
|
-
context: { action: 'voucher', descriptor },
|
|
1200
|
-
}),
|
|
1201
|
-
).rejects.toThrow('cumulativeAmount required for voucher action')
|
|
1202
|
-
})
|
|
1203
|
-
|
|
1204
|
-
test('manual close requires cumulativeAmount', async () => {
|
|
1205
|
-
const method = session({ account, getClient: () => client })
|
|
1206
|
-
|
|
1207
|
-
await expect(
|
|
1208
|
-
method.createCredential({
|
|
1209
|
-
challenge: makeChallenge(),
|
|
1210
|
-
context: { action: 'close', descriptor },
|
|
1211
|
-
}),
|
|
1212
|
-
).rejects.toThrow('cumulativeAmount required for close action')
|
|
1213
|
-
})
|
|
1214
|
-
|
|
1215
|
-
test('manual actions require descriptors', async () => {
|
|
1216
|
-
const method = session({ account, getClient: () => client })
|
|
1217
|
-
|
|
1218
|
-
await expect(
|
|
1219
|
-
method.createCredential({
|
|
1220
|
-
challenge: makeChallenge(),
|
|
1221
|
-
context: { action: 'voucher', cumulativeAmountRaw: '100' },
|
|
1222
|
-
}),
|
|
1223
|
-
).rejects.toThrow('descriptor required for TIP-1034 session action')
|
|
1224
|
-
})
|
|
1225
|
-
|
|
1226
|
-
test('creates manual voucher credentials with descriptor payloads', async () => {
|
|
1227
|
-
const method = session({ account, getClient: () => client })
|
|
1228
|
-
const credential = await method.createCredential({
|
|
1229
|
-
challenge: makeChallenge(),
|
|
1230
|
-
context: {
|
|
1231
|
-
action: 'voucher',
|
|
1232
|
-
descriptor,
|
|
1233
|
-
cumulativeAmountRaw: '250',
|
|
1234
|
-
},
|
|
1235
|
-
})
|
|
1236
|
-
|
|
1237
|
-
const decoded = deserializeCredential(credential)
|
|
1238
|
-
const payload = decoded.payload as Types.SessionCredentialPayload
|
|
1239
|
-
const cumulativeAmount = Types.uint96(250n)
|
|
1240
|
-
const channelId = Channel.computeId({ ...descriptor, chainId, escrow: tip20ChannelEscrow })
|
|
1241
|
-
|
|
1242
|
-
expect(decoded.challenge.id).toBe('test-id')
|
|
1243
|
-
expect(decoded.challenge.realm).toBe('test.com')
|
|
1244
|
-
expect(decoded.challenge.method).toBe('tempo')
|
|
1245
|
-
expect(decoded.challenge.intent).toBe('session')
|
|
1246
|
-
expect(payload.action).toBe('voucher')
|
|
1247
|
-
if (payload.action !== 'voucher') throw new Error('expected voucher payload')
|
|
1248
|
-
expect(payload.channelId).toBe(channelId)
|
|
1249
|
-
expect(payload.descriptor).toEqual(descriptor)
|
|
1250
|
-
expect(payload.cumulativeAmount).toBe('250')
|
|
1251
|
-
expect(decoded.source).toBe(`did:pkh:eip155:${chainId}:${account.address}`)
|
|
1252
|
-
expect(
|
|
1253
|
-
Voucher.verifyVoucher(
|
|
1254
|
-
tip20ChannelEscrow,
|
|
1255
|
-
chainId,
|
|
1256
|
-
{ channelId, cumulativeAmount, signature: payload.signature },
|
|
1257
|
-
descriptor.authorizedSigner,
|
|
1258
|
-
),
|
|
1259
|
-
).toBe(true)
|
|
1260
|
-
})
|
|
1261
|
-
|
|
1262
|
-
test('creates manual open credentials with descriptor payloads', async () => {
|
|
1263
|
-
const method = session({ account, getClient: () => client })
|
|
1264
|
-
const credential = await method.createCredential({
|
|
1265
|
-
challenge: makeChallenge(),
|
|
1266
|
-
context: {
|
|
1267
|
-
action: 'open',
|
|
1268
|
-
descriptor,
|
|
1269
|
-
cumulativeAmountRaw: '250',
|
|
1270
|
-
transaction: '0x1234',
|
|
1271
|
-
},
|
|
1272
|
-
})
|
|
1273
|
-
|
|
1274
|
-
const decoded = deserializeCredential(credential)
|
|
1275
|
-
const payload = decoded.payload
|
|
1276
|
-
const cumulativeAmount = Types.uint96(250n)
|
|
1277
|
-
const channelId = Channel.computeId({ ...descriptor, chainId, escrow: tip20ChannelEscrow })
|
|
1278
|
-
|
|
1279
|
-
expect(decoded.challenge.id).toBe('test-id')
|
|
1280
|
-
expect(payload.action).toBe('open')
|
|
1281
|
-
if (payload.action !== 'open') throw new Error('expected open payload')
|
|
1282
|
-
expect(payload.type).toBe('transaction')
|
|
1283
|
-
expect(payload.channelId).toBe(channelId)
|
|
1284
|
-
expect(payload.descriptor).toEqual(descriptor)
|
|
1285
|
-
expect(payload.transaction).toBe('0x1234')
|
|
1286
|
-
expect(payload.cumulativeAmount).toBe('250')
|
|
1287
|
-
expect(payload.authorizedSigner).toBe(descriptor.authorizedSigner)
|
|
1288
|
-
expect(decoded.source).toBe(`did:pkh:eip155:${chainId}:${account.address}`)
|
|
1289
|
-
expect(
|
|
1290
|
-
Voucher.verifyVoucher(
|
|
1291
|
-
tip20ChannelEscrow,
|
|
1292
|
-
chainId,
|
|
1293
|
-
{ channelId, cumulativeAmount, signature: payload.signature },
|
|
1294
|
-
descriptor.authorizedSigner,
|
|
1295
|
-
),
|
|
1296
|
-
).toBe(true)
|
|
1297
|
-
})
|
|
1298
|
-
|
|
1299
|
-
test('creates manual top-up credentials from provided transactions', async () => {
|
|
1300
|
-
const method = session({ account, getClient: () => client })
|
|
1301
|
-
const credential = await method.createCredential({
|
|
1302
|
-
challenge: makeChallenge(),
|
|
1303
|
-
context: {
|
|
1304
|
-
action: 'topUp',
|
|
1305
|
-
descriptor,
|
|
1306
|
-
additionalDepositRaw: '500',
|
|
1307
|
-
transaction: '0x1234',
|
|
1308
|
-
},
|
|
1309
|
-
})
|
|
1310
|
-
|
|
1311
|
-
const decoded = deserializeCredential(credential)
|
|
1312
|
-
const payload = decoded.payload as Types.SessionCredentialPayload
|
|
1313
|
-
const channelId = Channel.computeId({ ...descriptor, chainId, escrow: tip20ChannelEscrow })
|
|
1314
|
-
|
|
1315
|
-
expect(payload.action).toBe('topUp')
|
|
1316
|
-
if (payload.action !== 'topUp') throw new Error('expected topUp payload')
|
|
1317
|
-
expect(payload.channelId).toBe(channelId)
|
|
1318
|
-
expect(payload.descriptor).toEqual(descriptor)
|
|
1319
|
-
expect(payload.additionalDeposit).toBe('500')
|
|
1320
|
-
expect(payload.transaction).toBe('0x1234')
|
|
1321
|
-
expect(decoded.source).toBe(`did:pkh:eip155:${chainId}:${account.address}`)
|
|
1322
|
-
})
|
|
1323
|
-
|
|
1324
|
-
test('creates manual close credentials with descriptor payloads', async () => {
|
|
1325
|
-
const method = session({ account, getClient: () => client })
|
|
1326
|
-
const credential = await method.createCredential({
|
|
1327
|
-
challenge: makeChallenge(),
|
|
1328
|
-
context: {
|
|
1329
|
-
action: 'close',
|
|
1330
|
-
descriptor,
|
|
1331
|
-
cumulativeAmountRaw: '250',
|
|
1332
|
-
},
|
|
1333
|
-
})
|
|
1334
|
-
|
|
1335
|
-
const decoded = deserializeCredential(credential)
|
|
1336
|
-
const payload = decoded.payload
|
|
1337
|
-
const cumulativeAmount = Types.uint96(250n)
|
|
1338
|
-
const channelId = Channel.computeId({ ...descriptor, chainId, escrow: tip20ChannelEscrow })
|
|
1339
|
-
|
|
1340
|
-
expect(payload.action).toBe('close')
|
|
1341
|
-
if (payload.action !== 'close') throw new Error('expected close payload')
|
|
1342
|
-
expect(payload.channelId).toBe(channelId)
|
|
1343
|
-
expect(payload.descriptor).toEqual(descriptor)
|
|
1344
|
-
expect(payload.cumulativeAmount).toBe('250')
|
|
1345
|
-
expect(decoded.source).toBe(`did:pkh:eip155:${chainId}:${account.address}`)
|
|
1346
|
-
expect(
|
|
1347
|
-
Voucher.verifyVoucher(
|
|
1348
|
-
tip20ChannelEscrow,
|
|
1349
|
-
chainId,
|
|
1350
|
-
{ channelId, cumulativeAmount, signature: payload.signature },
|
|
1351
|
-
descriptor.authorizedSigner,
|
|
1352
|
-
),
|
|
1353
|
-
).toBe(true)
|
|
1354
|
-
})
|
|
1355
|
-
})
|