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,1333 +0,0 @@
|
|
|
1
|
-
import { Base64 } from 'ox'
|
|
2
|
-
import { KeyAuthorization } from 'ox/tempo'
|
|
3
|
-
import {
|
|
4
|
-
encodeFunctionData,
|
|
5
|
-
isAddressEqual,
|
|
6
|
-
parseEventLogs,
|
|
7
|
-
type Address,
|
|
8
|
-
type Client as ViemClient,
|
|
9
|
-
type TransactionReceipt,
|
|
10
|
-
} from 'viem'
|
|
11
|
-
import {
|
|
12
|
-
call as viem_call,
|
|
13
|
-
prepareTransactionRequest,
|
|
14
|
-
sendRawTransaction,
|
|
15
|
-
sendRawTransactionSync,
|
|
16
|
-
signTransaction,
|
|
17
|
-
} from 'viem/actions'
|
|
18
|
-
import { Abis, Account as TempoAccount, Transaction } from 'viem/tempo'
|
|
19
|
-
import { tempo as tempo_chain } from 'viem/tempo/chains'
|
|
20
|
-
|
|
21
|
-
import { VerificationFailedError } from '../../Errors.js'
|
|
22
|
-
import type { LooseOmit, MaybePromise, NoExtraKeys } from '../../internal/types.js'
|
|
23
|
-
import * as Method from '../../Method.js'
|
|
24
|
-
import * as Store from '../../Store.js'
|
|
25
|
-
import type * as Client from '../../viem/Client.js'
|
|
26
|
-
import * as ClientResolver from '../../viem/Client.js'
|
|
27
|
-
import * as Attribution from '../Attribution.js'
|
|
28
|
-
import * as Account from '../internal/account.js'
|
|
29
|
-
import * as defaults from '../internal/defaults.js'
|
|
30
|
-
import * as FeePayer from '../internal/fee-payer.js'
|
|
31
|
-
import * as Proof from '../internal/proof.js'
|
|
32
|
-
import type * as types from '../internal/types.js'
|
|
33
|
-
import * as Methods from '../Methods.js'
|
|
34
|
-
import {
|
|
35
|
-
assertSubscriptionTiming,
|
|
36
|
-
toSubscriptionPeriodSeconds,
|
|
37
|
-
verifySubscriptionKeyAuthorization,
|
|
38
|
-
} from '../subscription/KeyAuthorization.js'
|
|
39
|
-
import * as SubscriptionReceipt from '../subscription/Receipt.js'
|
|
40
|
-
import * as SubscriptionStore from '../subscription/Store.js'
|
|
41
|
-
import type {
|
|
42
|
-
SubscriptionAccessKey,
|
|
43
|
-
SubscriptionCredentialPayload,
|
|
44
|
-
SubscriptionLookup,
|
|
45
|
-
SubscriptionPeriodUnit,
|
|
46
|
-
SubscriptionRecord,
|
|
47
|
-
SubscriptionReceipt as SubscriptionReceiptValue,
|
|
48
|
-
} from '../subscription/Types.js'
|
|
49
|
-
|
|
50
|
-
type SubscriptionRequest = ReturnType<typeof Methods.subscription.schema.request.parse>
|
|
51
|
-
type RenewalHandler = NonNullable<subscription.Parameters['renew']>
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Creates a Tempo subscription method for recurring TIP-20 token payments.
|
|
55
|
-
*
|
|
56
|
-
* The method handles activation, request-path reuse, and optional lazy renewals.
|
|
57
|
-
*/
|
|
58
|
-
export function subscription<const parameters extends subscription.Parameters>(
|
|
59
|
-
p: NoExtraKeys<parameters, subscription.Parameters>,
|
|
60
|
-
) {
|
|
61
|
-
const parameters = p as parameters
|
|
62
|
-
const rawStore = (parameters.store ?? Store.memory()) as Store.AtomicStore<
|
|
63
|
-
Record<string, unknown>
|
|
64
|
-
>
|
|
65
|
-
if (typeof rawStore.update !== 'function') {
|
|
66
|
-
throw new Error('tempo.subscription() requires an atomic store with `update`.')
|
|
67
|
-
}
|
|
68
|
-
const defaultChainId = parameters.chainId ?? defaults.chainId.testnet
|
|
69
|
-
const {
|
|
70
|
-
amount,
|
|
71
|
-
currency = defaults.resolveCurrency({ chainId: defaultChainId }),
|
|
72
|
-
decimals = defaults.decimals,
|
|
73
|
-
description,
|
|
74
|
-
externalId,
|
|
75
|
-
periodCount,
|
|
76
|
-
periodUnit,
|
|
77
|
-
subscriptionExpires,
|
|
78
|
-
} = parameters
|
|
79
|
-
|
|
80
|
-
const { recipient } = Account.resolve(parameters)
|
|
81
|
-
const context = createContext(parameters, {
|
|
82
|
-
store: Store.from(rawStore, { keyPrefix: parameters.storeKeyPrefix }),
|
|
83
|
-
options: {
|
|
84
|
-
activationTimeoutMs: parameters.activationTimeoutMs,
|
|
85
|
-
renewalTimeoutMs: parameters.renewalTimeoutMs,
|
|
86
|
-
},
|
|
87
|
-
})
|
|
88
|
-
const { feePayer, feePayerPolicy, getClient, store, waitForConfirmation } = context
|
|
89
|
-
|
|
90
|
-
type Defaults = subscription.DeriveDefaults<parameters>
|
|
91
|
-
const method = Method.toServer<
|
|
92
|
-
typeof Methods.subscription,
|
|
93
|
-
Defaults,
|
|
94
|
-
undefined,
|
|
95
|
-
subscription.Extensions
|
|
96
|
-
>(Methods.subscription, {
|
|
97
|
-
defaults: {
|
|
98
|
-
amount,
|
|
99
|
-
currency,
|
|
100
|
-
decimals,
|
|
101
|
-
description,
|
|
102
|
-
externalId,
|
|
103
|
-
periodCount,
|
|
104
|
-
periodUnit,
|
|
105
|
-
recipient,
|
|
106
|
-
subscriptionExpires,
|
|
107
|
-
} as unknown as Defaults,
|
|
108
|
-
extensions: {
|
|
109
|
-
renew: (parameters) =>
|
|
110
|
-
renewWithContext({
|
|
111
|
-
context: {
|
|
112
|
-
...context,
|
|
113
|
-
feePayerPolicy: parameters.feePayerPolicy
|
|
114
|
-
? resolveFeePayerPolicy(context.feePayerPolicy, parameters.feePayerPolicy)
|
|
115
|
-
: context.feePayerPolicy,
|
|
116
|
-
waitForConfirmation: parameters.waitForConfirmation ?? context.waitForConfirmation,
|
|
117
|
-
},
|
|
118
|
-
subscriptionId: parameters.subscriptionId,
|
|
119
|
-
}),
|
|
120
|
-
},
|
|
121
|
-
|
|
122
|
-
async authorize({ input, request }) {
|
|
123
|
-
if (parameters.requireCredential) return undefined
|
|
124
|
-
|
|
125
|
-
const resolved = await parameters.resolve({ input, request })
|
|
126
|
-
if (!resolved) return undefined
|
|
127
|
-
|
|
128
|
-
const subscription = await store.getByKey(resolved.key)
|
|
129
|
-
if (!subscription || !isActive(subscription)) return undefined
|
|
130
|
-
if (!subscriptionMatchesRequest(subscription, request)) return undefined
|
|
131
|
-
|
|
132
|
-
const periodIndex = getPeriodIndex(subscription)
|
|
133
|
-
if (periodIndex > subscription.lastChargedPeriod) {
|
|
134
|
-
const renew = resolveRenewalHandler({
|
|
135
|
-
feePayer,
|
|
136
|
-
feePayerPolicy,
|
|
137
|
-
getClient,
|
|
138
|
-
parameters,
|
|
139
|
-
store,
|
|
140
|
-
subscription,
|
|
141
|
-
waitForConfirmation,
|
|
142
|
-
})
|
|
143
|
-
if (!renew) return undefined
|
|
144
|
-
|
|
145
|
-
const renewal = await settleRenewal({
|
|
146
|
-
expectedLookupKey: resolved.key,
|
|
147
|
-
periodIndex,
|
|
148
|
-
renew,
|
|
149
|
-
request,
|
|
150
|
-
store,
|
|
151
|
-
subscription,
|
|
152
|
-
})
|
|
153
|
-
if (!renewal) return undefined
|
|
154
|
-
if (renewal.status === 'charged') return { receipt: renewal.receipt }
|
|
155
|
-
if (renewal.status === 'inFlight') {
|
|
156
|
-
return {
|
|
157
|
-
receipt: renewal.receipt,
|
|
158
|
-
response: new Response(null, {
|
|
159
|
-
headers: { 'Retry-After': '1' },
|
|
160
|
-
status: 409,
|
|
161
|
-
}),
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
await parameters.hooks?.renewed?.({
|
|
166
|
-
periodIndex,
|
|
167
|
-
receipt: renewal.result.receipt,
|
|
168
|
-
subscription: renewal.result.subscription,
|
|
169
|
-
})
|
|
170
|
-
return {
|
|
171
|
-
receipt: renewal.result.receipt,
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
return {
|
|
176
|
-
receipt: SubscriptionReceipt.fromRecord(subscription),
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
|
|
180
|
-
async request({ capturedRequest, credential, request }) {
|
|
181
|
-
const credentialRequest = credential?.challenge.request as SubscriptionRequest | undefined
|
|
182
|
-
const chainId =
|
|
183
|
-
request.chainId ??
|
|
184
|
-
parameters.chainId ??
|
|
185
|
-
credentialRequest?.methodDetails?.chainId ??
|
|
186
|
-
defaults.chainId.testnet
|
|
187
|
-
const parsedRequest = Methods.subscription.schema.request.parse({
|
|
188
|
-
...request,
|
|
189
|
-
chainId,
|
|
190
|
-
})
|
|
191
|
-
const input = requestFromCaptured(capturedRequest)
|
|
192
|
-
const resolved = await parameters.resolve({ input, request: parsedRequest })
|
|
193
|
-
const existing = resolved ? await store.getByKey(resolved.key) : null
|
|
194
|
-
const accessKey = !credential
|
|
195
|
-
? resolved
|
|
196
|
-
? await resolveChallengeAccessKey({
|
|
197
|
-
existing,
|
|
198
|
-
input,
|
|
199
|
-
parameters,
|
|
200
|
-
request: parsedRequest,
|
|
201
|
-
resolved,
|
|
202
|
-
store,
|
|
203
|
-
})
|
|
204
|
-
: parameters.requireCredential && !parameters.activate
|
|
205
|
-
? await createUnboundChallengeAccessKey({ store })
|
|
206
|
-
: undefined
|
|
207
|
-
: (credentialRequest?.methodDetails?.accessKey ?? parsedRequest.methodDetails?.accessKey)
|
|
208
|
-
if (!accessKey) {
|
|
209
|
-
throw new VerificationFailedError({ reason: 'subscription accessKey is missing' })
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
// Challenges carry the server-generated key in methodDetails so the shared request shape stays spec-compatible.
|
|
213
|
-
return {
|
|
214
|
-
...request,
|
|
215
|
-
methodDetails: {
|
|
216
|
-
...request.methodDetails,
|
|
217
|
-
accessKey,
|
|
218
|
-
},
|
|
219
|
-
chainId,
|
|
220
|
-
}
|
|
221
|
-
},
|
|
222
|
-
|
|
223
|
-
stableBinding: subscriptionBinding,
|
|
224
|
-
|
|
225
|
-
async verify({ credential, envelope, request }) {
|
|
226
|
-
const input = requestFromCaptured(envelope?.capturedRequest)
|
|
227
|
-
const parsed = Methods.subscription.schema.request.safeParse(request)
|
|
228
|
-
const parsedRequest = parsed.success ? parsed.data : (request as SubscriptionRequest)
|
|
229
|
-
assertSubscriptionTiming({
|
|
230
|
-
challengeExpires: credential.challenge.expires,
|
|
231
|
-
request: parsedRequest,
|
|
232
|
-
})
|
|
233
|
-
const challengeRequest = credential.challenge.request as SubscriptionRequest
|
|
234
|
-
let resolved: subscription.ResolvedSubscription | null = null
|
|
235
|
-
let accessKey =
|
|
236
|
-
challengeRequest.methodDetails?.accessKey ?? parsedRequest.methodDetails?.accessKey
|
|
237
|
-
if (!accessKey) {
|
|
238
|
-
resolved = await parameters.resolve({ input, request: parsedRequest })
|
|
239
|
-
if (!resolved) {
|
|
240
|
-
throw new VerificationFailedError({ reason: 'subscription could not be resolved' })
|
|
241
|
-
}
|
|
242
|
-
accessKey = await resolveAccessKey({ input, parameters, request: parsedRequest, resolved })
|
|
243
|
-
}
|
|
244
|
-
if (!accessKey) {
|
|
245
|
-
throw new VerificationFailedError({ reason: 'subscription accessKey is missing' })
|
|
246
|
-
}
|
|
247
|
-
const verified = verifySubscriptionKeyAuthorization({
|
|
248
|
-
accessKey,
|
|
249
|
-
chainId: parsedRequest.methodDetails?.chainId ?? defaults.chainId.testnet,
|
|
250
|
-
payload: credential.payload as SubscriptionCredentialPayload,
|
|
251
|
-
request: parsedRequest,
|
|
252
|
-
})
|
|
253
|
-
const declaredSource = credential.source ? Proof.parsePkhSource(credential.source) : null
|
|
254
|
-
if (
|
|
255
|
-
declaredSource &&
|
|
256
|
-
(declaredSource.chainId !== verified.source.chainId ||
|
|
257
|
-
!isAddressEqual(declaredSource.address, verified.source.address))
|
|
258
|
-
) {
|
|
259
|
-
throw new VerificationFailedError({
|
|
260
|
-
reason: 'credential source does not match signature',
|
|
261
|
-
})
|
|
262
|
-
}
|
|
263
|
-
resolved =
|
|
264
|
-
(await parameters.resolve({ input, request: parsedRequest, source: verified.source })) ??
|
|
265
|
-
resolved
|
|
266
|
-
|
|
267
|
-
if (!resolved) {
|
|
268
|
-
throw new VerificationFailedError({ reason: 'subscription could not be resolved' })
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
const activation = await store.activate({
|
|
272
|
-
challengeId: credential.challenge.id,
|
|
273
|
-
isReusable: (subscription) =>
|
|
274
|
-
parameters.requireCredential
|
|
275
|
-
? isActiveSubscriptionForRequest(subscription, parsedRequest)
|
|
276
|
-
: isReusableSubscription(subscription, parsedRequest),
|
|
277
|
-
lookupKey: resolved.key,
|
|
278
|
-
async create() {
|
|
279
|
-
const activation = withSubscriptionAccessKey(
|
|
280
|
-
await activateSubscription({
|
|
281
|
-
accessKey,
|
|
282
|
-
auto: {
|
|
283
|
-
challengeId: credential.challenge.id,
|
|
284
|
-
feePayer,
|
|
285
|
-
feePayerPolicy,
|
|
286
|
-
getClient,
|
|
287
|
-
keyAuthorization: (credential.payload as SubscriptionCredentialPayload).signature,
|
|
288
|
-
realm: credential.challenge.realm,
|
|
289
|
-
store,
|
|
290
|
-
waitForConfirmation,
|
|
291
|
-
},
|
|
292
|
-
credential: credential as typeof credential & {
|
|
293
|
-
payload: SubscriptionCredentialPayload
|
|
294
|
-
},
|
|
295
|
-
input,
|
|
296
|
-
parameters,
|
|
297
|
-
request: parsedRequest,
|
|
298
|
-
resolved,
|
|
299
|
-
source: verified.source,
|
|
300
|
-
}),
|
|
301
|
-
accessKey,
|
|
302
|
-
)
|
|
303
|
-
validateSubscriptionSettlement(activation, {
|
|
304
|
-
expectedLookupKey: resolved.key,
|
|
305
|
-
expectedPeriodIndex: 0,
|
|
306
|
-
request: parsedRequest,
|
|
307
|
-
})
|
|
308
|
-
return activation
|
|
309
|
-
},
|
|
310
|
-
})
|
|
311
|
-
if (activation.status === 'replayed') {
|
|
312
|
-
throw new VerificationFailedError({
|
|
313
|
-
reason: 'subscription credential has already been used',
|
|
314
|
-
})
|
|
315
|
-
}
|
|
316
|
-
if (activation.status === 'inFlight') {
|
|
317
|
-
throw new VerificationFailedError({
|
|
318
|
-
reason: 'subscription activation is already in flight',
|
|
319
|
-
})
|
|
320
|
-
}
|
|
321
|
-
if (activation.status === 'claimMismatch') {
|
|
322
|
-
throw new VerificationFailedError({ reason: 'subscription activation claim mismatch' })
|
|
323
|
-
}
|
|
324
|
-
if (activation.status === 'existing') {
|
|
325
|
-
const subscription = activation.subscription
|
|
326
|
-
assertSubscriptionPayer(subscription, verified.source, {
|
|
327
|
-
required: parameters.requireCredential,
|
|
328
|
-
})
|
|
329
|
-
|
|
330
|
-
const periodIndex = getPeriodIndex(subscription)
|
|
331
|
-
if (periodIndex > subscription.lastChargedPeriod) {
|
|
332
|
-
const renew = resolveRenewalHandler({
|
|
333
|
-
feePayer,
|
|
334
|
-
feePayerPolicy,
|
|
335
|
-
getClient,
|
|
336
|
-
parameters,
|
|
337
|
-
store,
|
|
338
|
-
subscription,
|
|
339
|
-
waitForConfirmation,
|
|
340
|
-
})
|
|
341
|
-
if (!renew) {
|
|
342
|
-
throw new VerificationFailedError({ reason: 'subscription renewal is required' })
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
const renewal = await settleRenewal({
|
|
346
|
-
expectedLookupKey: resolved.key,
|
|
347
|
-
periodIndex,
|
|
348
|
-
renew,
|
|
349
|
-
request: parsedRequest,
|
|
350
|
-
store,
|
|
351
|
-
subscription,
|
|
352
|
-
})
|
|
353
|
-
if (!renewal) {
|
|
354
|
-
throw new VerificationFailedError({ reason: 'subscription renewal failed' })
|
|
355
|
-
}
|
|
356
|
-
if (renewal.status === 'charged' || renewal.status === 'inFlight') {
|
|
357
|
-
return renewal.receipt
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
await parameters.hooks?.renewed?.({
|
|
361
|
-
periodIndex,
|
|
362
|
-
receipt: renewal.result.receipt,
|
|
363
|
-
subscription: renewal.result.subscription,
|
|
364
|
-
})
|
|
365
|
-
return renewal.result.receipt
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
return SubscriptionReceipt.fromRecord(subscription)
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
await parameters.hooks?.activated?.({
|
|
372
|
-
receipt: activation.result.receipt,
|
|
373
|
-
subscription: activation.result.subscription,
|
|
374
|
-
})
|
|
375
|
-
return activation.result.receipt
|
|
376
|
-
},
|
|
377
|
-
})
|
|
378
|
-
return method
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
// Access-key provisioning can cost around 4M gas.
|
|
382
|
-
const defaultFeePayerPolicy = {
|
|
383
|
-
maxGas: 5_000_000n,
|
|
384
|
-
maxTotalFee: 200_000_000_000_000_000n,
|
|
385
|
-
} satisfies Partial<FeePayer.Policy>
|
|
386
|
-
|
|
387
|
-
function resolveFeePayerPolicy(
|
|
388
|
-
...policies: (Partial<FeePayer.Policy> | undefined)[]
|
|
389
|
-
): Partial<FeePayer.Policy> {
|
|
390
|
-
return Object.assign({}, defaultFeePayerPolicy, ...policies)
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
function requestFromCaptured(capturedRequest: Method.CapturedRequest | undefined): Request {
|
|
394
|
-
if (!capturedRequest) return new Request('https://subscription.invalid')
|
|
395
|
-
return new Request(capturedRequest.url, {
|
|
396
|
-
headers: capturedRequest.headers,
|
|
397
|
-
method: capturedRequest.method,
|
|
398
|
-
})
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
async function resolveAccessKey(parameters: {
|
|
402
|
-
input: Request
|
|
403
|
-
parameters: subscription.Parameters
|
|
404
|
-
request: SubscriptionRequest
|
|
405
|
-
resolved: subscription.ResolvedSubscription
|
|
406
|
-
}) {
|
|
407
|
-
const { input, parameters: subscriptionParameters, request, resolved } = parameters
|
|
408
|
-
return (
|
|
409
|
-
resolved.accessKey ??
|
|
410
|
-
(subscriptionParameters.accessKey
|
|
411
|
-
? await subscriptionParameters.accessKey({ input, request, resolved })
|
|
412
|
-
: undefined)
|
|
413
|
-
)
|
|
414
|
-
}
|
|
415
|
-
|
|
416
|
-
async function resolveChallengeAccessKey(parameters: {
|
|
417
|
-
existing: SubscriptionRecord | null
|
|
418
|
-
input: Request
|
|
419
|
-
parameters: subscription.Parameters
|
|
420
|
-
request: SubscriptionRequest
|
|
421
|
-
resolved: subscription.ResolvedSubscription
|
|
422
|
-
store: SubscriptionStore.SubscriptionStore
|
|
423
|
-
}) {
|
|
424
|
-
const {
|
|
425
|
-
existing,
|
|
426
|
-
input,
|
|
427
|
-
parameters: subscriptionParameters,
|
|
428
|
-
request,
|
|
429
|
-
resolved,
|
|
430
|
-
store,
|
|
431
|
-
} = parameters
|
|
432
|
-
if (!subscriptionParameters.activate) {
|
|
433
|
-
// In automatic mode, the SDK owns the server access key so apps can issue
|
|
434
|
-
// challenges from only their resolved subscription lookup key.
|
|
435
|
-
const accessKey = await store.getOrCreateAccessKey(resolved.key)
|
|
436
|
-
return {
|
|
437
|
-
accessKeyAddress: accessKey.accessKeyAddress,
|
|
438
|
-
keyType: accessKey.keyType,
|
|
439
|
-
} satisfies SubscriptionAccessKey
|
|
440
|
-
}
|
|
441
|
-
// Manual activation keeps the lower-level API: callers can provide the
|
|
442
|
-
// access key for new challenges, while active subscriptions reuse the stored key.
|
|
443
|
-
return (
|
|
444
|
-
(await resolveAccessKey({ input, parameters: subscriptionParameters, request, resolved })) ??
|
|
445
|
-
(existing && isActive(existing) ? existing.accessKey : undefined)
|
|
446
|
-
)
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
async function createUnboundChallengeAccessKey(parameters: {
|
|
450
|
-
store: SubscriptionStore.SubscriptionStore
|
|
451
|
-
}) {
|
|
452
|
-
const accessKey = await parameters.store.getOrCreateAccessKey(
|
|
453
|
-
`challenge:${createSubscriptionId()}`,
|
|
454
|
-
)
|
|
455
|
-
return {
|
|
456
|
-
accessKeyAddress: accessKey.accessKeyAddress,
|
|
457
|
-
keyType: accessKey.keyType,
|
|
458
|
-
} satisfies SubscriptionAccessKey
|
|
459
|
-
}
|
|
460
|
-
|
|
461
|
-
async function activateSubscription(parameters: {
|
|
462
|
-
accessKey: SubscriptionAccessKey
|
|
463
|
-
auto: {
|
|
464
|
-
challengeId: string
|
|
465
|
-
feePayer?: ReturnType<typeof Account.resolve>['feePayer'] | undefined
|
|
466
|
-
feePayerPolicy?: Partial<FeePayer.Policy> | undefined
|
|
467
|
-
getClient: (parameters: { chainId?: number | undefined }) => MaybePromise<ViemClient>
|
|
468
|
-
keyAuthorization: `0x${string}`
|
|
469
|
-
realm: string
|
|
470
|
-
store: SubscriptionStore.SubscriptionStore
|
|
471
|
-
waitForConfirmation: boolean
|
|
472
|
-
}
|
|
473
|
-
credential: {
|
|
474
|
-
payload: SubscriptionCredentialPayload
|
|
475
|
-
source?: string | undefined
|
|
476
|
-
}
|
|
477
|
-
input: Request
|
|
478
|
-
parameters: subscription.Parameters
|
|
479
|
-
request: SubscriptionRequest
|
|
480
|
-
resolved: subscription.ResolvedSubscription
|
|
481
|
-
source: { address: Address; chainId: number } | null
|
|
482
|
-
}) {
|
|
483
|
-
const {
|
|
484
|
-
accessKey,
|
|
485
|
-
auto,
|
|
486
|
-
credential,
|
|
487
|
-
input,
|
|
488
|
-
parameters: subscriptionParameters,
|
|
489
|
-
request,
|
|
490
|
-
resolved,
|
|
491
|
-
source,
|
|
492
|
-
} = parameters
|
|
493
|
-
if (subscriptionParameters.activate) {
|
|
494
|
-
// A custom activate hook owns settlement and record creation.
|
|
495
|
-
return subscriptionParameters.activate({
|
|
496
|
-
accessKey,
|
|
497
|
-
credential,
|
|
498
|
-
input,
|
|
499
|
-
request,
|
|
500
|
-
resolved,
|
|
501
|
-
source,
|
|
502
|
-
})
|
|
503
|
-
}
|
|
504
|
-
if (!source) {
|
|
505
|
-
throw new VerificationFailedError({ reason: 'subscription payer is missing' })
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
// Automatic activation bills the first period and persists the recurring
|
|
509
|
-
// billing authority needed for request-path and background renewals.
|
|
510
|
-
const reference = await submitSubscriptionPayment({
|
|
511
|
-
accessKey,
|
|
512
|
-
feePayer: auto.feePayer,
|
|
513
|
-
feePayerPolicy: auto.feePayerPolicy,
|
|
514
|
-
getClient: auto.getClient,
|
|
515
|
-
keyAuthorization: auto.keyAuthorization,
|
|
516
|
-
lookupKey: resolved.key,
|
|
517
|
-
request,
|
|
518
|
-
settlementReference: auto.challengeId,
|
|
519
|
-
source,
|
|
520
|
-
store: auto.store,
|
|
521
|
-
waitForConfirmation: auto.waitForConfirmation,
|
|
522
|
-
})
|
|
523
|
-
const timestamp = new Date().toISOString()
|
|
524
|
-
const subscription = {
|
|
525
|
-
accessKey,
|
|
526
|
-
amount: request.amount,
|
|
527
|
-
billingAnchor: timestamp,
|
|
528
|
-
chainId: request.methodDetails?.chainId,
|
|
529
|
-
currency: request.currency,
|
|
530
|
-
externalId: request.externalId,
|
|
531
|
-
keyAuthorization: auto.keyAuthorization,
|
|
532
|
-
lastChargedPeriod: 0,
|
|
533
|
-
lookupKey: resolved.key,
|
|
534
|
-
payer: source,
|
|
535
|
-
periodCount: request.periodCount,
|
|
536
|
-
periodUnit: request.periodUnit,
|
|
537
|
-
recipient: request.recipient,
|
|
538
|
-
reference,
|
|
539
|
-
subscriptionExpires: request.subscriptionExpires,
|
|
540
|
-
subscriptionId: createSubscriptionId(),
|
|
541
|
-
timestamp,
|
|
542
|
-
} satisfies SubscriptionRecord
|
|
543
|
-
|
|
544
|
-
return {
|
|
545
|
-
receipt: SubscriptionReceipt.createSubscriptionReceipt(subscription),
|
|
546
|
-
subscription,
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
async function settleRenewal(parameters: {
|
|
551
|
-
expectedLookupKey: string
|
|
552
|
-
periodIndex: number
|
|
553
|
-
renew: (parameters: {
|
|
554
|
-
inFlightReference: string
|
|
555
|
-
periodIndex: number
|
|
556
|
-
subscription: SubscriptionRecord
|
|
557
|
-
}) => Promise<subscription.RenewalResult>
|
|
558
|
-
request?: SubscriptionRequest | undefined
|
|
559
|
-
store: SubscriptionStore.SubscriptionStore
|
|
560
|
-
subscription: SubscriptionRecord
|
|
561
|
-
}): Promise<
|
|
562
|
-
| { status: 'charged'; receipt: SubscriptionReceiptValue }
|
|
563
|
-
| { status: 'inFlight'; receipt: SubscriptionReceiptValue }
|
|
564
|
-
| { status: 'renewed'; result: subscription.RenewalResult }
|
|
565
|
-
| null
|
|
566
|
-
> {
|
|
567
|
-
const { expectedLookupKey, periodIndex, renew, request, store, subscription } = parameters
|
|
568
|
-
const inFlightReference = renewalReference(subscription.subscriptionId, periodIndex)
|
|
569
|
-
const renewal = await store.renew({
|
|
570
|
-
inFlightReference,
|
|
571
|
-
periodIndex,
|
|
572
|
-
async renew({ inFlightReference, periodIndex, subscription: started }) {
|
|
573
|
-
const renewed = withSubscriptionAccessKey(
|
|
574
|
-
await renew({
|
|
575
|
-
inFlightReference,
|
|
576
|
-
periodIndex,
|
|
577
|
-
subscription: started,
|
|
578
|
-
}),
|
|
579
|
-
started.accessKey,
|
|
580
|
-
)
|
|
581
|
-
validateSubscriptionSettlement(renewed, {
|
|
582
|
-
expectedLookupKey,
|
|
583
|
-
expectedPeriodIndex: periodIndex,
|
|
584
|
-
expectedSubscriptionId: subscription.subscriptionId,
|
|
585
|
-
previous: started,
|
|
586
|
-
request,
|
|
587
|
-
})
|
|
588
|
-
return renewed
|
|
589
|
-
},
|
|
590
|
-
subscriptionId: subscription.subscriptionId,
|
|
591
|
-
})
|
|
592
|
-
|
|
593
|
-
if (renewal.status === 'charged') {
|
|
594
|
-
return { receipt: SubscriptionReceipt.fromRecord(renewal.subscription), status: 'charged' }
|
|
595
|
-
}
|
|
596
|
-
if (renewal.status === 'inFlight') {
|
|
597
|
-
return { receipt: SubscriptionReceipt.fromRecord(renewal.subscription), status: 'inFlight' }
|
|
598
|
-
}
|
|
599
|
-
if (renewal.status === 'renewed') return { result: renewal.result, status: 'renewed' }
|
|
600
|
-
if (renewal.status === 'claimMismatch') {
|
|
601
|
-
throw new VerificationFailedError({ reason: 'subscription renewal claim mismatch' })
|
|
602
|
-
}
|
|
603
|
-
return null
|
|
604
|
-
}
|
|
605
|
-
|
|
606
|
-
function renewalReference(subscriptionId: string, periodIndex: number): string {
|
|
607
|
-
// This stable identifier is persisted before the billing hook runs so apps can
|
|
608
|
-
// use it as an idempotency/reconciliation key if a renewal crashes mid-flight.
|
|
609
|
-
return `renewal:${subscriptionId}:${periodIndex}`
|
|
610
|
-
}
|
|
611
|
-
|
|
612
|
-
function withSubscriptionAccessKey<
|
|
613
|
-
result extends subscription.ActivationResult | subscription.RenewalResult,
|
|
614
|
-
>(result: result, accessKey: SubscriptionAccessKey | undefined): result {
|
|
615
|
-
if (!accessKey || result.subscription.accessKey) return result
|
|
616
|
-
return {
|
|
617
|
-
...result,
|
|
618
|
-
subscription: {
|
|
619
|
-
...result.subscription,
|
|
620
|
-
accessKey,
|
|
621
|
-
},
|
|
622
|
-
}
|
|
623
|
-
}
|
|
624
|
-
|
|
625
|
-
function getPeriodIndex(subscription: SubscriptionRecord): number {
|
|
626
|
-
const anchor = new Date(subscription.billingAnchor).getTime()
|
|
627
|
-
const expires = new Date(subscription.subscriptionExpires).getTime()
|
|
628
|
-
const now = Date.now()
|
|
629
|
-
if (!Number.isFinite(anchor) || !Number.isFinite(expires) || now >= expires) {
|
|
630
|
-
return Number.POSITIVE_INFINITY
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
let periodSeconds: number
|
|
634
|
-
try {
|
|
635
|
-
periodSeconds = toSubscriptionPeriodSeconds(subscription)
|
|
636
|
-
} catch {
|
|
637
|
-
return Number.POSITIVE_INFINITY
|
|
638
|
-
}
|
|
639
|
-
|
|
640
|
-
return Math.max(0, Math.floor((now - anchor) / (periodSeconds * 1_000)))
|
|
641
|
-
}
|
|
642
|
-
|
|
643
|
-
function isActive(subscription: SubscriptionRecord): boolean {
|
|
644
|
-
if (subscription.canceledAt || subscription.revokedAt) return false
|
|
645
|
-
return new Date(subscription.subscriptionExpires).getTime() > Date.now()
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
function isActiveSubscriptionForRequest(
|
|
649
|
-
subscription: SubscriptionRecord,
|
|
650
|
-
request: SubscriptionRequest,
|
|
651
|
-
): boolean {
|
|
652
|
-
return isActive(subscription) && subscriptionMatchesRequest(subscription, request)
|
|
653
|
-
}
|
|
654
|
-
|
|
655
|
-
function isReusableSubscription(
|
|
656
|
-
subscription: SubscriptionRecord,
|
|
657
|
-
request: SubscriptionRequest,
|
|
658
|
-
): boolean {
|
|
659
|
-
return (
|
|
660
|
-
isActiveSubscriptionForRequest(subscription, request) &&
|
|
661
|
-
getPeriodIndex(subscription) <= subscription.lastChargedPeriod
|
|
662
|
-
)
|
|
663
|
-
}
|
|
664
|
-
|
|
665
|
-
function subscriptionMatchesRequest(
|
|
666
|
-
subscription: SubscriptionRecord,
|
|
667
|
-
request: SubscriptionRequest | SubscriptionRecord,
|
|
668
|
-
): boolean {
|
|
669
|
-
const actual = comparableSubscriptionBinding(subscription)
|
|
670
|
-
const expected = comparableSubscriptionBinding(request)
|
|
671
|
-
return (Object.keys(expected) as (keyof typeof expected)[]).every(
|
|
672
|
-
(key) => actual[key] === expected[key],
|
|
673
|
-
)
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
function assertSubscriptionPayer(
|
|
677
|
-
subscription: SubscriptionRecord,
|
|
678
|
-
source: { address: Address; chainId: number },
|
|
679
|
-
options?: { required?: boolean | undefined },
|
|
680
|
-
) {
|
|
681
|
-
if (!subscription.payer) {
|
|
682
|
-
if (options?.required) {
|
|
683
|
-
throw new VerificationFailedError({ reason: 'subscription payer is missing' })
|
|
684
|
-
}
|
|
685
|
-
return
|
|
686
|
-
}
|
|
687
|
-
if (
|
|
688
|
-
subscription.payer.chainId !== source.chainId ||
|
|
689
|
-
!isAddressEqual(subscription.payer.address, source.address)
|
|
690
|
-
) {
|
|
691
|
-
throw new VerificationFailedError({ reason: 'subscription payer mismatch' })
|
|
692
|
-
}
|
|
693
|
-
}
|
|
694
|
-
|
|
695
|
-
function comparableSubscriptionBinding(value: SubscriptionRecord | SubscriptionRequest) {
|
|
696
|
-
const chainId =
|
|
697
|
-
'chainId' in value ? value.chainId : (value as SubscriptionRequest).methodDetails?.chainId
|
|
698
|
-
return {
|
|
699
|
-
amount: value.amount,
|
|
700
|
-
chainId,
|
|
701
|
-
currency: value.currency.toLowerCase(),
|
|
702
|
-
externalId: value.externalId,
|
|
703
|
-
periodCount: value.periodCount,
|
|
704
|
-
periodUnit: value.periodUnit,
|
|
705
|
-
recipient: value.recipient.toLowerCase(),
|
|
706
|
-
subscriptionExpires: value.subscriptionExpires,
|
|
707
|
-
}
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
function validateSubscriptionSettlement(
|
|
711
|
-
result: subscription.ActivationResult | subscription.RenewalResult,
|
|
712
|
-
options: {
|
|
713
|
-
expectedLookupKey: string
|
|
714
|
-
expectedPeriodIndex: number
|
|
715
|
-
expectedSubscriptionId?: string | undefined
|
|
716
|
-
previous?: SubscriptionRecord | undefined
|
|
717
|
-
request?: SubscriptionRequest | undefined
|
|
718
|
-
},
|
|
719
|
-
) {
|
|
720
|
-
const { receipt, subscription } = result
|
|
721
|
-
assertSubscriptionReceipt(receipt, subscription)
|
|
722
|
-
assertSubscriptionRecord(subscription, options)
|
|
723
|
-
|
|
724
|
-
if (options.request) {
|
|
725
|
-
assertSubscriptionRequestMatch(subscription, options.request)
|
|
726
|
-
} else if (options.previous) {
|
|
727
|
-
assertSubscriptionRequestMatch(subscription, options.previous)
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
|
|
731
|
-
function assertSubscriptionReceipt(
|
|
732
|
-
receipt: SubscriptionReceiptValue,
|
|
733
|
-
subscription: SubscriptionRecord,
|
|
734
|
-
) {
|
|
735
|
-
if (receipt.method !== 'tempo' || receipt.status !== 'success') {
|
|
736
|
-
throw new VerificationFailedError({ reason: 'subscription receipt is invalid' })
|
|
737
|
-
}
|
|
738
|
-
if (receipt.subscriptionId !== subscription.subscriptionId) {
|
|
739
|
-
throw new VerificationFailedError({ reason: 'subscription receipt id mismatch' })
|
|
740
|
-
}
|
|
741
|
-
if (receipt.reference !== subscription.reference) {
|
|
742
|
-
throw new VerificationFailedError({ reason: 'subscription receipt reference mismatch' })
|
|
743
|
-
}
|
|
744
|
-
if (receipt.timestamp !== subscription.timestamp) {
|
|
745
|
-
throw new VerificationFailedError({ reason: 'subscription receipt timestamp mismatch' })
|
|
746
|
-
}
|
|
747
|
-
assertTransactionHash(receipt.reference, 'subscription reference must be a transaction hash')
|
|
748
|
-
assertValidDate(receipt.timestamp, 'subscription receipt timestamp is invalid')
|
|
749
|
-
}
|
|
750
|
-
|
|
751
|
-
function assertSubscriptionRecord(
|
|
752
|
-
subscription: SubscriptionRecord,
|
|
753
|
-
options: {
|
|
754
|
-
expectedLookupKey: string
|
|
755
|
-
expectedPeriodIndex: number
|
|
756
|
-
expectedSubscriptionId?: string | undefined
|
|
757
|
-
},
|
|
758
|
-
) {
|
|
759
|
-
assertBase64Url(subscription.subscriptionId, 'subscriptionId must be base64url')
|
|
760
|
-
assertTransactionHash(subscription.reference, 'subscription reference must be a transaction hash')
|
|
761
|
-
const billingAnchor = assertValidDate(
|
|
762
|
-
subscription.billingAnchor,
|
|
763
|
-
'subscription billingAnchor is invalid',
|
|
764
|
-
)
|
|
765
|
-
const subscriptionExpires = assertValidDate(
|
|
766
|
-
subscription.subscriptionExpires,
|
|
767
|
-
'subscriptionExpires is invalid',
|
|
768
|
-
)
|
|
769
|
-
|
|
770
|
-
assertEqual(subscription.lookupKey, options.expectedLookupKey, {
|
|
771
|
-
reason: 'subscription lookupKey does not match the resolved key',
|
|
772
|
-
})
|
|
773
|
-
assertEqual(subscription.lastChargedPeriod, options.expectedPeriodIndex, {
|
|
774
|
-
reason: 'subscription lastChargedPeriod does not match the settled period',
|
|
775
|
-
})
|
|
776
|
-
if (options.expectedSubscriptionId) {
|
|
777
|
-
assertEqual(subscription.subscriptionId, options.expectedSubscriptionId, {
|
|
778
|
-
reason: 'subscriptionId does not match the active subscription',
|
|
779
|
-
})
|
|
780
|
-
}
|
|
781
|
-
if (billingAnchor >= subscriptionExpires) {
|
|
782
|
-
throw new VerificationFailedError({
|
|
783
|
-
reason: 'subscription billingAnchor must be before subscriptionExpires',
|
|
784
|
-
})
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
|
|
788
|
-
function assertSubscriptionRequestMatch(
|
|
789
|
-
subscription: SubscriptionRecord,
|
|
790
|
-
request: SubscriptionRequest | SubscriptionRecord,
|
|
791
|
-
) {
|
|
792
|
-
if (!subscriptionMatchesRequest(subscription, request)) {
|
|
793
|
-
throw new VerificationFailedError({ reason: 'subscription record does not match request' })
|
|
794
|
-
}
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
function assertBase64Url(value: string, reason: string) {
|
|
798
|
-
if (!/^[A-Za-z0-9_-]+$/.test(value)) {
|
|
799
|
-
throw new VerificationFailedError({ reason })
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
|
|
803
|
-
function assertTransactionHash(value: string, reason: string) {
|
|
804
|
-
if (!/^0x[0-9a-fA-F]{64}$/.test(value)) {
|
|
805
|
-
throw new VerificationFailedError({ reason })
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
|
|
809
|
-
function assertValidDate(value: string, reason: string) {
|
|
810
|
-
const milliseconds = new Date(value).getTime()
|
|
811
|
-
if (!Number.isFinite(milliseconds)) {
|
|
812
|
-
throw new VerificationFailedError({ reason })
|
|
813
|
-
}
|
|
814
|
-
return milliseconds
|
|
815
|
-
}
|
|
816
|
-
|
|
817
|
-
function assertEqual<value>(actual: value, expected: value, options: { reason: string }) {
|
|
818
|
-
if (actual !== expected) {
|
|
819
|
-
throw new VerificationFailedError(options)
|
|
820
|
-
}
|
|
821
|
-
}
|
|
822
|
-
|
|
823
|
-
function subscriptionBinding(request: SubscriptionRequest) {
|
|
824
|
-
return {
|
|
825
|
-
amount: request.amount,
|
|
826
|
-
chainId: request.methodDetails?.chainId,
|
|
827
|
-
currency: request.currency,
|
|
828
|
-
externalId: request.externalId,
|
|
829
|
-
periodCount: request.periodCount,
|
|
830
|
-
periodUnit: request.periodUnit,
|
|
831
|
-
recipient: request.recipient,
|
|
832
|
-
subscriptionExpires: request.subscriptionExpires,
|
|
833
|
-
}
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
function resolveRenewalHandler(parameters: {
|
|
837
|
-
feePayer?: ReturnType<typeof Account.resolve>['feePayer'] | undefined
|
|
838
|
-
feePayerPolicy?: Partial<FeePayer.Policy> | undefined
|
|
839
|
-
getClient: (parameters: { chainId?: number | undefined }) => MaybePromise<ViemClient>
|
|
840
|
-
parameters: Pick<createContext.Parameters, 'renew'>
|
|
841
|
-
store: SubscriptionStore.SubscriptionStore
|
|
842
|
-
subscription: SubscriptionRecord
|
|
843
|
-
waitForConfirmation: boolean
|
|
844
|
-
}): RenewalHandler | undefined {
|
|
845
|
-
const {
|
|
846
|
-
feePayer,
|
|
847
|
-
feePayerPolicy,
|
|
848
|
-
getClient,
|
|
849
|
-
parameters: subscriptionParameters,
|
|
850
|
-
store,
|
|
851
|
-
subscription,
|
|
852
|
-
waitForConfirmation,
|
|
853
|
-
} = parameters
|
|
854
|
-
if (subscriptionParameters.renew) return subscriptionParameters.renew
|
|
855
|
-
if (!subscription.accessKey || !subscription.payer) return undefined
|
|
856
|
-
return async ({ inFlightReference, periodIndex, subscription }) => {
|
|
857
|
-
const reference = await submitSubscriptionPayment({
|
|
858
|
-
accessKey: subscription.accessKey!,
|
|
859
|
-
feePayer,
|
|
860
|
-
feePayerPolicy,
|
|
861
|
-
getClient,
|
|
862
|
-
lookupKey: subscription.lookupKey,
|
|
863
|
-
request: subscription,
|
|
864
|
-
settlementReference: inFlightReference,
|
|
865
|
-
source: subscription.payer!,
|
|
866
|
-
store,
|
|
867
|
-
waitForConfirmation,
|
|
868
|
-
})
|
|
869
|
-
const record = {
|
|
870
|
-
...subscription,
|
|
871
|
-
lastChargedPeriod: periodIndex,
|
|
872
|
-
reference,
|
|
873
|
-
timestamp: new Date().toISOString(),
|
|
874
|
-
} satisfies SubscriptionRecord
|
|
875
|
-
return {
|
|
876
|
-
receipt: SubscriptionReceipt.createSubscriptionReceipt(record),
|
|
877
|
-
subscription: record,
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
}
|
|
881
|
-
|
|
882
|
-
async function submitSubscriptionPayment(parameters: {
|
|
883
|
-
accessKey: SubscriptionAccessKey
|
|
884
|
-
feePayer?: ReturnType<typeof Account.resolve>['feePayer'] | undefined
|
|
885
|
-
feePayerPolicy?: Partial<FeePayer.Policy> | undefined
|
|
886
|
-
getClient: (parameters: { chainId?: number | undefined }) => MaybePromise<ViemClient>
|
|
887
|
-
keyAuthorization?: `0x${string}` | undefined
|
|
888
|
-
lookupKey: string
|
|
889
|
-
request: Pick<SubscriptionRequest, 'amount'> & {
|
|
890
|
-
methodDetails?: { chainId?: number | undefined } | undefined
|
|
891
|
-
} & { currency: Address | string; recipient: Address | string }
|
|
892
|
-
settlementReference: string
|
|
893
|
-
source: { address: Address; chainId: number }
|
|
894
|
-
store: SubscriptionStore.SubscriptionStore
|
|
895
|
-
waitForConfirmation: boolean
|
|
896
|
-
}) {
|
|
897
|
-
const {
|
|
898
|
-
accessKey,
|
|
899
|
-
feePayer,
|
|
900
|
-
feePayerPolicy,
|
|
901
|
-
getClient,
|
|
902
|
-
keyAuthorization,
|
|
903
|
-
lookupKey,
|
|
904
|
-
request,
|
|
905
|
-
settlementReference,
|
|
906
|
-
source,
|
|
907
|
-
store,
|
|
908
|
-
waitForConfirmation,
|
|
909
|
-
} = parameters
|
|
910
|
-
const stored =
|
|
911
|
-
(await store.getAccessKey(lookupKey)) ??
|
|
912
|
-
(await store.getAccessKeyByAddress(accessKey.accessKeyAddress))
|
|
913
|
-
if (!stored) {
|
|
914
|
-
throw new VerificationFailedError({ reason: 'subscription access key is missing' })
|
|
915
|
-
}
|
|
916
|
-
const rawAccessAccount = TempoAccount.fromSecp256k1(stored.privateKey)
|
|
917
|
-
if (!isAddressEqual(rawAccessAccount.address, accessKey.accessKeyAddress)) {
|
|
918
|
-
throw new VerificationFailedError({
|
|
919
|
-
reason: 'subscription access key does not match stored key',
|
|
920
|
-
})
|
|
921
|
-
}
|
|
922
|
-
|
|
923
|
-
const chainId = request.methodDetails?.chainId ?? source.chainId
|
|
924
|
-
const client = await getClient({ chainId })
|
|
925
|
-
const account = TempoAccount.fromSecp256k1(stored.privateKey, {
|
|
926
|
-
access: source.address,
|
|
927
|
-
})
|
|
928
|
-
const memo = Attribution.encode({
|
|
929
|
-
challengeId: settlementReference,
|
|
930
|
-
serverId: lookupKey,
|
|
931
|
-
})
|
|
932
|
-
const baseTransaction = {
|
|
933
|
-
account,
|
|
934
|
-
calls: [
|
|
935
|
-
{
|
|
936
|
-
data: encodeFunctionData({
|
|
937
|
-
abi: Abis.tip20,
|
|
938
|
-
functionName: 'transferWithMemo',
|
|
939
|
-
args: [request.recipient as Address, BigInt(request.amount), memo],
|
|
940
|
-
}),
|
|
941
|
-
to: request.currency as Address,
|
|
942
|
-
},
|
|
943
|
-
],
|
|
944
|
-
chainId,
|
|
945
|
-
...(keyAuthorization
|
|
946
|
-
? { keyAuthorization: KeyAuthorization.deserialize(keyAuthorization) }
|
|
947
|
-
: {}),
|
|
948
|
-
}
|
|
949
|
-
const serializedTransaction = await (async () => {
|
|
950
|
-
if (!feePayer) return await signTransaction(client, baseTransaction as never)
|
|
951
|
-
// For sponsored payments, prepare the tx via `prepareTransactionRequest`
|
|
952
|
-
// (without `feePayer: true`) so viem returns the chain's full
|
|
953
|
-
// proof-inclusive gas estimate. With `feePayer: true` viem sets a
|
|
954
|
-
// dummy sig + null feePayerSignature, dropping signature and key
|
|
955
|
-
// authorization verification costs -- see chainConfig.js FIXME. We add
|
|
956
|
-
// a small buffer for fee-payer overhead, then flip `feePayer = true`
|
|
957
|
-
// and re-sign with the fee-payer-sponsored envelope.
|
|
958
|
-
const prepared = await prepareTransactionRequest(client, {
|
|
959
|
-
...baseTransaction,
|
|
960
|
-
nonceKey: 'expiring',
|
|
961
|
-
} as never)
|
|
962
|
-
prepared.gas = (prepared.gas ?? 0n) + 5_000n
|
|
963
|
-
;(prepared as Record<string, unknown>).feePayer = true
|
|
964
|
-
const userSerialized = await signTransaction(client, prepared as never)
|
|
965
|
-
const userTransaction = Transaction.deserialize(
|
|
966
|
-
userSerialized as Transaction.TransactionSerializedTempo,
|
|
967
|
-
)
|
|
968
|
-
const completed = await FeePayer.preflightSponsorship({
|
|
969
|
-
transaction: userTransaction,
|
|
970
|
-
simulate: (request) => viem_call(client, request as never),
|
|
971
|
-
async complete() {
|
|
972
|
-
const sponsored = FeePayer.prepareSponsoredTransaction({
|
|
973
|
-
account: feePayer,
|
|
974
|
-
chainId: chainId ?? client.chain!.id,
|
|
975
|
-
details: {
|
|
976
|
-
amount: String(request.amount),
|
|
977
|
-
currency: String(request.currency),
|
|
978
|
-
recipient: String(request.recipient),
|
|
979
|
-
},
|
|
980
|
-
...(feePayerPolicy ? { policy: feePayerPolicy } : {}),
|
|
981
|
-
transaction: userTransaction as never,
|
|
982
|
-
})
|
|
983
|
-
return { feePayer: feePayer.address, transaction: sponsored }
|
|
984
|
-
},
|
|
985
|
-
})
|
|
986
|
-
return await signTransaction(client, completed.transaction as never)
|
|
987
|
-
})()
|
|
988
|
-
const transaction = Transaction.deserialize(
|
|
989
|
-
serializedTransaction as Transaction.TransactionSerializedTempo,
|
|
990
|
-
)
|
|
991
|
-
if (!feePayer)
|
|
992
|
-
await viem_call(client, {
|
|
993
|
-
...transaction,
|
|
994
|
-
account: transaction.from,
|
|
995
|
-
calls: transaction.calls,
|
|
996
|
-
feePayerSignature: undefined,
|
|
997
|
-
} as never)
|
|
998
|
-
|
|
999
|
-
if (!waitForConfirmation) {
|
|
1000
|
-
// Optimistic mode has no receipt to inspect, so it cannot detect a T6
|
|
1001
|
-
// (TIP-1028) held transfer. Use `waitForConfirmation: true` for T6-safe proof.
|
|
1002
|
-
return sendRawTransaction(client, {
|
|
1003
|
-
serializedTransaction: serializedTransaction as Transaction.TransactionSerializedTempo,
|
|
1004
|
-
})
|
|
1005
|
-
}
|
|
1006
|
-
|
|
1007
|
-
const receipt = await sendRawTransactionSync(client, {
|
|
1008
|
-
serializedTransaction: serializedTransaction as Transaction.TransactionSerializedTempo,
|
|
1009
|
-
})
|
|
1010
|
-
if (receipt.status !== 'success') {
|
|
1011
|
-
throw new VerificationFailedError({
|
|
1012
|
-
reason: `subscription transaction reverted: ${receipt.transactionHash}`,
|
|
1013
|
-
})
|
|
1014
|
-
}
|
|
1015
|
-
assertSubscriptionTransfer(receipt, {
|
|
1016
|
-
amount: BigInt(request.amount),
|
|
1017
|
-
currency: request.currency as Address,
|
|
1018
|
-
memo,
|
|
1019
|
-
recipient: request.recipient as Address,
|
|
1020
|
-
})
|
|
1021
|
-
return receipt.transactionHash
|
|
1022
|
-
}
|
|
1023
|
-
|
|
1024
|
-
/**
|
|
1025
|
-
* Asserts a confirmed subscription payment credited the recipient.
|
|
1026
|
-
*
|
|
1027
|
-
* Transaction success alone is not proof: under Tempo T6 (TIP-1028) a recipient
|
|
1028
|
-
* receive policy can hold the funds in `ReceivePolicyGuard` while the tx still
|
|
1029
|
-
* succeeds. Settlement always emits one `transferWithMemo(recipient, amount,
|
|
1030
|
-
* memo)`, so this requires a matching `TransferWithMemo` log on the expected
|
|
1031
|
-
* token. A held transfer fails because its `to` is the guard, and the memo
|
|
1032
|
-
* binding excludes unrelated transfer effects in the same receipt.
|
|
1033
|
-
*/
|
|
1034
|
-
function assertSubscriptionTransfer(
|
|
1035
|
-
receipt: TransactionReceipt,
|
|
1036
|
-
parameters: { amount: bigint; currency: Address; memo: `0x${string}`; recipient: Address },
|
|
1037
|
-
): void {
|
|
1038
|
-
const { amount, currency, memo, recipient } = parameters
|
|
1039
|
-
const credited = parseEventLogs({
|
|
1040
|
-
abi: Abis.tip20,
|
|
1041
|
-
eventName: 'TransferWithMemo',
|
|
1042
|
-
logs: receipt.logs,
|
|
1043
|
-
}).some(
|
|
1044
|
-
(log) =>
|
|
1045
|
-
isAddressEqual(log.address, currency) &&
|
|
1046
|
-
isAddressEqual(log.args.to, recipient) &&
|
|
1047
|
-
log.args.amount === amount &&
|
|
1048
|
-
log.args.memo.toLowerCase() === memo.toLowerCase(),
|
|
1049
|
-
)
|
|
1050
|
-
if (!credited) {
|
|
1051
|
-
throw new VerificationFailedError({
|
|
1052
|
-
reason:
|
|
1053
|
-
`subscription transfer was not credited to the recipient ` +
|
|
1054
|
-
`(funds may have been held by a receive policy): ${receipt.transactionHash}`,
|
|
1055
|
-
})
|
|
1056
|
-
}
|
|
1057
|
-
}
|
|
1058
|
-
|
|
1059
|
-
function createSubscriptionId() {
|
|
1060
|
-
const bytes = new Uint8Array(18)
|
|
1061
|
-
globalThis.crypto.getRandomValues(bytes)
|
|
1062
|
-
return Base64.fromBytes(bytes, { url: true }).replace(/=+$/, '')
|
|
1063
|
-
}
|
|
1064
|
-
|
|
1065
|
-
/**
|
|
1066
|
-
* Renews an overdue subscription outside of the HTTP request path.
|
|
1067
|
-
* Intended for cron jobs or background workers that bill subscriptions on a schedule.
|
|
1068
|
-
*
|
|
1069
|
-
* Returns the renewal result if the subscription was overdue, or `null` if already current.
|
|
1070
|
-
*/
|
|
1071
|
-
export async function renew(parameters: renew.Parameters): Promise<renew.Result | null> {
|
|
1072
|
-
const context = createContext(parameters, {
|
|
1073
|
-
store: parameters.store,
|
|
1074
|
-
options: {
|
|
1075
|
-
renewalTimeoutMs: parameters.renewalTimeoutMs,
|
|
1076
|
-
},
|
|
1077
|
-
})
|
|
1078
|
-
|
|
1079
|
-
return renewWithContext({
|
|
1080
|
-
context,
|
|
1081
|
-
subscriptionId: parameters.subscriptionId,
|
|
1082
|
-
})
|
|
1083
|
-
}
|
|
1084
|
-
|
|
1085
|
-
async function renewWithContext(parameters: {
|
|
1086
|
-
context: createContext.Return
|
|
1087
|
-
subscriptionId: string
|
|
1088
|
-
}): Promise<renew.Result | null> {
|
|
1089
|
-
const { context, subscriptionId } = parameters
|
|
1090
|
-
const record = await context.store.get(subscriptionId)
|
|
1091
|
-
if (!record) return null
|
|
1092
|
-
if (!isActive(record)) return null
|
|
1093
|
-
const active = await context.store.getByKey(record.lookupKey)
|
|
1094
|
-
if (active?.subscriptionId !== record.subscriptionId) return null
|
|
1095
|
-
|
|
1096
|
-
const periodIndex = getPeriodIndex(record)
|
|
1097
|
-
if (periodIndex <= record.lastChargedPeriod) return null
|
|
1098
|
-
|
|
1099
|
-
const renew = resolveRenewalHandler({
|
|
1100
|
-
feePayer: context.feePayer,
|
|
1101
|
-
feePayerPolicy: context.feePayerPolicy,
|
|
1102
|
-
getClient: context.getClient,
|
|
1103
|
-
parameters: context.parameters,
|
|
1104
|
-
store: context.store,
|
|
1105
|
-
subscription: record,
|
|
1106
|
-
waitForConfirmation: context.waitForConfirmation,
|
|
1107
|
-
})
|
|
1108
|
-
if (!renew) return null
|
|
1109
|
-
|
|
1110
|
-
const renewal = await settleRenewal({
|
|
1111
|
-
expectedLookupKey: record.lookupKey,
|
|
1112
|
-
periodIndex,
|
|
1113
|
-
renew,
|
|
1114
|
-
store: context.store,
|
|
1115
|
-
subscription: record,
|
|
1116
|
-
})
|
|
1117
|
-
if (renewal?.status !== 'renewed') return null
|
|
1118
|
-
|
|
1119
|
-
await context.parameters.hooks?.renewed?.({
|
|
1120
|
-
periodIndex,
|
|
1121
|
-
receipt: renewal.result.receipt,
|
|
1122
|
-
subscription: renewal.result.subscription,
|
|
1123
|
-
})
|
|
1124
|
-
return renewal.result
|
|
1125
|
-
}
|
|
1126
|
-
|
|
1127
|
-
export declare namespace renew {
|
|
1128
|
-
/** Parameters for renewing an overdue subscription outside the request path. */
|
|
1129
|
-
type Parameters = Account.resolve.Parameters &
|
|
1130
|
-
Client.getResolver.Parameters & {
|
|
1131
|
-
/** The subscription to renew. */
|
|
1132
|
-
subscriptionId: string
|
|
1133
|
-
/** Billing callback -- same signature as the `renew` hook on {@link subscription}. */
|
|
1134
|
-
renew?: subscription.Parameters['renew']
|
|
1135
|
-
/** Store containing subscription records. */
|
|
1136
|
-
store: Store.AtomicStore<Record<string, unknown>>
|
|
1137
|
-
/**
|
|
1138
|
-
* Milliseconds before an in-flight renewal lock can be replaced.
|
|
1139
|
-
* Keeps concurrent renewal safe while allowing recovery from abandoned attempts.
|
|
1140
|
-
*/
|
|
1141
|
-
renewalTimeoutMs?: number | undefined
|
|
1142
|
-
/**
|
|
1143
|
-
* Override the fee-payer policy for sponsored subscription payments.
|
|
1144
|
-
* Useful when the access key renewal tx requires more gas than the default policy allows.
|
|
1145
|
-
*/
|
|
1146
|
-
feePayerPolicy?: Partial<FeePayer.Policy> | undefined
|
|
1147
|
-
waitForConfirmation?: boolean | undefined
|
|
1148
|
-
}
|
|
1149
|
-
|
|
1150
|
-
/** Renewal result returned by {@link renew}. */
|
|
1151
|
-
type Result = subscription.RenewalResult
|
|
1152
|
-
}
|
|
1153
|
-
|
|
1154
|
-
export declare namespace subscription {
|
|
1155
|
-
/** Request-scoped lookup key used to find the active subscription. */
|
|
1156
|
-
type ResolvedSubscription = SubscriptionLookup
|
|
1157
|
-
|
|
1158
|
-
/** Activation result returned after the initial credential is verified. */
|
|
1159
|
-
type ActivationResult = {
|
|
1160
|
-
receipt: SubscriptionReceiptValue
|
|
1161
|
-
subscription: SubscriptionRecord
|
|
1162
|
-
}
|
|
1163
|
-
|
|
1164
|
-
/** Renewal result returned when an overdue subscription is charged. */
|
|
1165
|
-
type RenewalResult = {
|
|
1166
|
-
receipt: SubscriptionReceiptValue
|
|
1167
|
-
subscription: SubscriptionRecord
|
|
1168
|
-
}
|
|
1169
|
-
|
|
1170
|
-
/** Parameters for renewing through a configured `mppx.tempo.subscription` handler. */
|
|
1171
|
-
type RenewParameters = {
|
|
1172
|
-
/** The subscription to renew. */
|
|
1173
|
-
subscriptionId: string
|
|
1174
|
-
/**
|
|
1175
|
-
* Override the fee-payer policy for sponsored subscription payments.
|
|
1176
|
-
* Useful when the access key renewal tx requires more gas than the default policy allows.
|
|
1177
|
-
*/
|
|
1178
|
-
feePayerPolicy?: Partial<FeePayer.Policy> | undefined
|
|
1179
|
-
waitForConfirmation?: boolean | undefined
|
|
1180
|
-
}
|
|
1181
|
-
|
|
1182
|
-
/** Handler extensions attached to `mppx.tempo.subscription`. */
|
|
1183
|
-
type Extensions = {
|
|
1184
|
-
renew: (parameters: RenewParameters) => Promise<renew.Result | null>
|
|
1185
|
-
}
|
|
1186
|
-
|
|
1187
|
-
/** Request defaults supported by the subscription method. */
|
|
1188
|
-
type Defaults = LooseOmit<
|
|
1189
|
-
Method.RequestDefaults<typeof Methods.subscription>,
|
|
1190
|
-
'accessKey' | 'recipient'
|
|
1191
|
-
>
|
|
1192
|
-
|
|
1193
|
-
/** Parameters for configuring a Tempo subscription method. */
|
|
1194
|
-
type Parameters = Account.resolve.Parameters &
|
|
1195
|
-
Client.getResolver.Parameters & {
|
|
1196
|
-
accessKey?:
|
|
1197
|
-
| ((parameters: {
|
|
1198
|
-
input: Request
|
|
1199
|
-
request: SubscriptionRequest
|
|
1200
|
-
resolved: ResolvedSubscription
|
|
1201
|
-
}) => MaybePromise<SubscriptionAccessKey>)
|
|
1202
|
-
| undefined
|
|
1203
|
-
/**
|
|
1204
|
-
* Milliseconds before an in-flight activation lock can be replaced.
|
|
1205
|
-
* Keeps concurrent activation safe while allowing recovery from abandoned attempts.
|
|
1206
|
-
*/
|
|
1207
|
-
activationTimeoutMs?: number | undefined
|
|
1208
|
-
/**
|
|
1209
|
-
* Milliseconds before an in-flight renewal lock can be replaced.
|
|
1210
|
-
* Keeps concurrent renewal safe while allowing recovery from abandoned attempts.
|
|
1211
|
-
*/
|
|
1212
|
-
renewalTimeoutMs?: number | undefined
|
|
1213
|
-
/**
|
|
1214
|
-
* Requires a fresh subscription Credential even when a subscription is active.
|
|
1215
|
-
* This binds access reuse to the stored payer instead of trusting request metadata alone.
|
|
1216
|
-
*/
|
|
1217
|
-
requireCredential?: boolean | undefined
|
|
1218
|
-
/**
|
|
1219
|
-
* Override the fee-payer policy for sponsored subscription payments.
|
|
1220
|
-
* Useful when the access key + key authorization tx requires more gas
|
|
1221
|
-
* than the default policy allows.
|
|
1222
|
-
*/
|
|
1223
|
-
feePayerPolicy?: Partial<FeePayer.Policy> | undefined
|
|
1224
|
-
activate?:
|
|
1225
|
-
| ((parameters: {
|
|
1226
|
-
/** Custom activation must verify this access key matches the resolved subscription. */
|
|
1227
|
-
accessKey: SubscriptionAccessKey
|
|
1228
|
-
credential: {
|
|
1229
|
-
payload: SubscriptionCredentialPayload
|
|
1230
|
-
source?: string | undefined
|
|
1231
|
-
}
|
|
1232
|
-
input: Request
|
|
1233
|
-
request: SubscriptionRequest
|
|
1234
|
-
resolved: ResolvedSubscription
|
|
1235
|
-
source: { address: Address; chainId: number } | null
|
|
1236
|
-
}) => Promise<ActivationResult>)
|
|
1237
|
-
| undefined
|
|
1238
|
-
hooks?:
|
|
1239
|
-
| {
|
|
1240
|
-
activated?:
|
|
1241
|
-
| ((parameters: {
|
|
1242
|
-
receipt: SubscriptionReceiptValue
|
|
1243
|
-
subscription: SubscriptionRecord
|
|
1244
|
-
}) => MaybePromise<void>)
|
|
1245
|
-
| undefined
|
|
1246
|
-
renewed?:
|
|
1247
|
-
| ((parameters: {
|
|
1248
|
-
periodIndex: number
|
|
1249
|
-
receipt: SubscriptionReceiptValue
|
|
1250
|
-
subscription: SubscriptionRecord
|
|
1251
|
-
}) => MaybePromise<void>)
|
|
1252
|
-
| undefined
|
|
1253
|
-
}
|
|
1254
|
-
| undefined
|
|
1255
|
-
periodCount?: Methods.SubscriptionPeriodCountInput | undefined
|
|
1256
|
-
periodUnit?: SubscriptionPeriodUnit | undefined
|
|
1257
|
-
/**
|
|
1258
|
-
* Resolves the request identity. This callback must authenticate and
|
|
1259
|
-
* authorize the caller before returning a key; automatic mode may create
|
|
1260
|
-
* a server-owned access key for that key while issuing a challenge.
|
|
1261
|
-
*/
|
|
1262
|
-
resolve: (parameters: {
|
|
1263
|
-
input: Request
|
|
1264
|
-
request: SubscriptionRequest
|
|
1265
|
-
/** Verified payer identity recovered from a signed subscription credential. */
|
|
1266
|
-
source?: { address: Address; chainId: number } | undefined
|
|
1267
|
-
}) => MaybePromise<ResolvedSubscription | null>
|
|
1268
|
-
renew?: (parameters: {
|
|
1269
|
-
/** Stable idempotency/reconciliation reference persisted before the renewal hook runs. */
|
|
1270
|
-
inFlightReference: string
|
|
1271
|
-
periodIndex: number
|
|
1272
|
-
/** Custom renewal hooks must preserve amount, currency, recipient, period, expiry, and lookup key. */
|
|
1273
|
-
subscription: SubscriptionRecord
|
|
1274
|
-
}) => Promise<RenewalResult>
|
|
1275
|
-
store?: Store.AtomicStore<Record<string, unknown>> | undefined
|
|
1276
|
-
/**
|
|
1277
|
-
* Prefix prepended to all subscription store keys.
|
|
1278
|
-
*
|
|
1279
|
-
* By default, no prefix is applied.
|
|
1280
|
-
*/
|
|
1281
|
-
storeKeyPrefix?: string | undefined
|
|
1282
|
-
testnet?: boolean | undefined
|
|
1283
|
-
waitForConfirmation?: boolean | undefined
|
|
1284
|
-
} & Defaults
|
|
1285
|
-
|
|
1286
|
-
/** Derived defaults after account and chain configuration are applied. */
|
|
1287
|
-
type DeriveDefaults<parameters extends Parameters> = types.DeriveDefaults<
|
|
1288
|
-
parameters,
|
|
1289
|
-
Defaults,
|
|
1290
|
-
{
|
|
1291
|
-
currency: string
|
|
1292
|
-
decimals: number
|
|
1293
|
-
}
|
|
1294
|
-
>
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1297
|
-
function createContext<const parameters extends createContext.Parameters>(
|
|
1298
|
-
parameters: parameters,
|
|
1299
|
-
options: createContext.Options,
|
|
1300
|
-
) {
|
|
1301
|
-
const { feePayer } = Account.resolve(parameters)
|
|
1302
|
-
const store = SubscriptionStore.fromStore(options.store, options.options)
|
|
1303
|
-
const getClient = ClientResolver.getResolver({
|
|
1304
|
-
chain: tempo_chain,
|
|
1305
|
-
getClient: parameters.getClient,
|
|
1306
|
-
rpcUrl: defaults.rpcUrl,
|
|
1307
|
-
})
|
|
1308
|
-
return {
|
|
1309
|
-
feePayer,
|
|
1310
|
-
feePayerPolicy: resolveFeePayerPolicy(parameters.feePayerPolicy),
|
|
1311
|
-
getClient,
|
|
1312
|
-
parameters,
|
|
1313
|
-
store,
|
|
1314
|
-
waitForConfirmation: parameters.waitForConfirmation ?? true,
|
|
1315
|
-
}
|
|
1316
|
-
}
|
|
1317
|
-
|
|
1318
|
-
declare namespace createContext {
|
|
1319
|
-
type Parameters = Account.resolve.Parameters &
|
|
1320
|
-
Client.getResolver.Parameters & {
|
|
1321
|
-
feePayerPolicy?: Partial<FeePayer.Policy> | undefined
|
|
1322
|
-
hooks?: subscription.Parameters['hooks']
|
|
1323
|
-
renew?: subscription.Parameters['renew']
|
|
1324
|
-
waitForConfirmation?: boolean | undefined
|
|
1325
|
-
}
|
|
1326
|
-
|
|
1327
|
-
type Options = {
|
|
1328
|
-
store: Store.AtomicStore<Record<string, unknown>>
|
|
1329
|
-
options?: SubscriptionStore.fromStore.Options | undefined
|
|
1330
|
-
}
|
|
1331
|
-
|
|
1332
|
-
type Return = ReturnType<typeof createContext>
|
|
1333
|
-
}
|