t402 1.9.0__py3-none-any.whl → 1.10.0__py3-none-any.whl

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.
Files changed (134) hide show
  1. t402/__init__.py +2 -1
  2. t402/a2a/__init__.py +73 -0
  3. t402/a2a/helpers.py +158 -0
  4. t402/a2a/types.py +145 -0
  5. t402/bridge/client.py +13 -5
  6. t402/bridge/constants.py +4 -2
  7. t402/bridge/router.py +1 -1
  8. t402/bridge/scan.py +3 -1
  9. t402/chains.py +268 -1
  10. t402/cli.py +31 -9
  11. t402/common.py +2 -0
  12. t402/cosmos_paywall_template.py +2 -0
  13. t402/django/__init__.py +42 -0
  14. t402/django/middleware.py +596 -0
  15. t402/encoding.py +9 -3
  16. t402/erc4337/accounts.py +56 -51
  17. t402/erc4337/bundlers.py +105 -99
  18. t402/erc4337/paymasters.py +100 -109
  19. t402/erc4337/types.py +39 -26
  20. t402/errors.py +213 -0
  21. t402/evm_paywall_template.py +1 -1
  22. t402/facilitator.py +125 -0
  23. t402/fastapi/middleware.py +1 -3
  24. t402/mcp/constants.py +3 -6
  25. t402/mcp/server.py +501 -84
  26. t402/mcp/web3_utils.py +493 -0
  27. t402/multisig/__init__.py +120 -0
  28. t402/multisig/constants.py +54 -0
  29. t402/multisig/safe.py +441 -0
  30. t402/multisig/signature.py +228 -0
  31. t402/multisig/transaction.py +238 -0
  32. t402/multisig/types.py +108 -0
  33. t402/multisig/utils.py +77 -0
  34. t402/near_paywall_template.py +2 -0
  35. t402/networks.py +34 -1
  36. t402/paywall.py +1 -3
  37. t402/schemes/__init__.py +143 -0
  38. t402/schemes/aptos/__init__.py +70 -0
  39. t402/schemes/aptos/constants.py +349 -0
  40. t402/schemes/aptos/exact_direct/__init__.py +44 -0
  41. t402/schemes/aptos/exact_direct/client.py +202 -0
  42. t402/schemes/aptos/exact_direct/facilitator.py +426 -0
  43. t402/schemes/aptos/exact_direct/server.py +272 -0
  44. t402/schemes/aptos/types.py +237 -0
  45. t402/schemes/cosmos/__init__.py +114 -0
  46. t402/schemes/cosmos/constants.py +211 -0
  47. t402/schemes/cosmos/exact_direct/__init__.py +21 -0
  48. t402/schemes/cosmos/exact_direct/client.py +198 -0
  49. t402/schemes/cosmos/exact_direct/facilitator.py +493 -0
  50. t402/schemes/cosmos/exact_direct/server.py +315 -0
  51. t402/schemes/cosmos/types.py +501 -0
  52. t402/schemes/evm/__init__.py +46 -1
  53. t402/schemes/evm/exact/__init__.py +11 -0
  54. t402/schemes/evm/exact/client.py +3 -1
  55. t402/schemes/evm/exact/facilitator.py +894 -0
  56. t402/schemes/evm/exact/server.py +1 -1
  57. t402/schemes/evm/exact_legacy/__init__.py +38 -0
  58. t402/schemes/evm/exact_legacy/client.py +291 -0
  59. t402/schemes/evm/exact_legacy/facilitator.py +777 -0
  60. t402/schemes/evm/exact_legacy/server.py +231 -0
  61. t402/schemes/evm/upto/__init__.py +12 -0
  62. t402/schemes/evm/upto/client.py +6 -2
  63. t402/schemes/evm/upto/facilitator.py +625 -0
  64. t402/schemes/evm/upto/server.py +243 -0
  65. t402/schemes/evm/upto/types.py +3 -1
  66. t402/schemes/interfaces.py +6 -2
  67. t402/schemes/near/__init__.py +137 -0
  68. t402/schemes/near/constants.py +189 -0
  69. t402/schemes/near/exact_direct/__init__.py +21 -0
  70. t402/schemes/near/exact_direct/client.py +204 -0
  71. t402/schemes/near/exact_direct/facilitator.py +455 -0
  72. t402/schemes/near/exact_direct/server.py +303 -0
  73. t402/schemes/near/types.py +419 -0
  74. t402/schemes/near/upto/__init__.py +54 -0
  75. t402/schemes/near/upto/types.py +272 -0
  76. t402/schemes/polkadot/__init__.py +72 -0
  77. t402/schemes/polkadot/constants.py +155 -0
  78. t402/schemes/polkadot/exact_direct/__init__.py +43 -0
  79. t402/schemes/polkadot/exact_direct/client.py +235 -0
  80. t402/schemes/polkadot/exact_direct/facilitator.py +428 -0
  81. t402/schemes/polkadot/exact_direct/server.py +292 -0
  82. t402/schemes/polkadot/types.py +385 -0
  83. t402/schemes/registry.py +6 -2
  84. t402/schemes/stacks/__init__.py +68 -0
  85. t402/schemes/stacks/constants.py +122 -0
  86. t402/schemes/stacks/exact_direct/__init__.py +43 -0
  87. t402/schemes/stacks/exact_direct/client.py +222 -0
  88. t402/schemes/stacks/exact_direct/facilitator.py +424 -0
  89. t402/schemes/stacks/exact_direct/server.py +292 -0
  90. t402/schemes/stacks/types.py +380 -0
  91. t402/schemes/svm/__init__.py +44 -0
  92. t402/schemes/svm/exact/__init__.py +35 -0
  93. t402/schemes/svm/exact/client.py +23 -0
  94. t402/schemes/svm/exact/facilitator.py +24 -0
  95. t402/schemes/svm/exact/server.py +20 -0
  96. t402/schemes/svm/upto/__init__.py +23 -0
  97. t402/schemes/svm/upto/types.py +193 -0
  98. t402/schemes/tezos/__init__.py +84 -0
  99. t402/schemes/tezos/constants.py +372 -0
  100. t402/schemes/tezos/exact_direct/__init__.py +22 -0
  101. t402/schemes/tezos/exact_direct/client.py +226 -0
  102. t402/schemes/tezos/exact_direct/facilitator.py +491 -0
  103. t402/schemes/tezos/exact_direct/server.py +277 -0
  104. t402/schemes/tezos/types.py +220 -0
  105. t402/schemes/ton/__init__.py +24 -2
  106. t402/schemes/ton/exact/__init__.py +7 -0
  107. t402/schemes/ton/exact/facilitator.py +730 -0
  108. t402/schemes/ton/exact/server.py +1 -1
  109. t402/schemes/ton/upto/__init__.py +31 -0
  110. t402/schemes/ton/upto/types.py +215 -0
  111. t402/schemes/tron/__init__.py +28 -2
  112. t402/schemes/tron/exact/__init__.py +9 -0
  113. t402/schemes/tron/exact/facilitator.py +673 -0
  114. t402/schemes/tron/exact/server.py +1 -1
  115. t402/schemes/tron/upto/__init__.py +30 -0
  116. t402/schemes/tron/upto/types.py +213 -0
  117. t402/stacks_paywall_template.py +2 -0
  118. t402/starlette/__init__.py +38 -0
  119. t402/starlette/middleware.py +522 -0
  120. t402/svm.py +45 -11
  121. t402/svm_paywall_template.py +1 -1
  122. t402/ton.py +6 -2
  123. t402/ton_paywall_template.py +1 -192
  124. t402/tron.py +2 -0
  125. t402/tron_paywall_template.py +2 -0
  126. t402/types.py +103 -3
  127. t402/wdk/chains.py +1 -1
  128. t402/wdk/errors.py +15 -5
  129. t402/wdk/signer.py +11 -2
  130. {t402-1.9.0.dist-info → t402-1.10.0.dist-info}/METADATA +42 -1
  131. t402-1.10.0.dist-info/RECORD +156 -0
  132. t402-1.9.0.dist-info/RECORD +0 -72
  133. {t402-1.9.0.dist-info → t402-1.10.0.dist-info}/WHEEL +0 -0
  134. {t402-1.9.0.dist-info → t402-1.10.0.dist-info}/entry_points.txt +0 -0
@@ -0,0 +1,44 @@
1
+ """Solana SVM Blockchain Payment Schemes.
2
+
3
+ This package provides payment scheme implementations for Solana blockchain.
4
+
5
+ Supported schemes:
6
+ - exact: SPL Token TransferChecked with facilitator fee payer
7
+ - upto: SPL Token ApproveChecked with delegated transferFrom
8
+ """
9
+
10
+ from t402.schemes.svm.exact import (
11
+ ExactSvmClientScheme,
12
+ ExactSvmServerScheme,
13
+ ExactSvmFacilitatorScheme,
14
+ ClientSvmSigner,
15
+ FacilitatorSvmSigner,
16
+ SCHEME_EXACT,
17
+ )
18
+
19
+ from t402.schemes.svm.upto import (
20
+ UptoSvmAuthorization,
21
+ UptoSvmPayload,
22
+ UptoSvmExtra,
23
+ is_upto_svm_payload,
24
+ upto_payload_from_dict,
25
+ )
26
+
27
+ __all__ = [
28
+ # Client
29
+ "ExactSvmClientScheme",
30
+ "ClientSvmSigner",
31
+ # Server
32
+ "ExactSvmServerScheme",
33
+ # Facilitator
34
+ "ExactSvmFacilitatorScheme",
35
+ "FacilitatorSvmSigner",
36
+ # Constants
37
+ "SCHEME_EXACT",
38
+ # Upto types
39
+ "UptoSvmAuthorization",
40
+ "UptoSvmPayload",
41
+ "UptoSvmExtra",
42
+ "is_upto_svm_payload",
43
+ "upto_payload_from_dict",
44
+ ]
@@ -0,0 +1,35 @@
1
+ """Solana SVM Exact Payment Scheme.
2
+
3
+ This package provides the exact payment scheme implementation for Solana
4
+ using SPL Token TransferChecked instructions with a facilitator fee payer.
5
+
6
+ The exact scheme allows users to sign transactions that transfer SPL tokens
7
+ to a recipient. The facilitator pays for gas (transaction fees) and broadcasts
8
+ the transaction.
9
+ """
10
+
11
+ from t402.schemes.svm.exact.client import (
12
+ ExactSvmClientScheme,
13
+ ClientSvmSigner,
14
+ SCHEME_EXACT,
15
+ )
16
+ from t402.schemes.svm.exact.server import (
17
+ ExactSvmServerScheme,
18
+ )
19
+ from t402.schemes.svm.exact.facilitator import (
20
+ ExactSvmFacilitatorScheme,
21
+ FacilitatorSvmSigner,
22
+ )
23
+
24
+ __all__ = [
25
+ # Client
26
+ "ExactSvmClientScheme",
27
+ "ClientSvmSigner",
28
+ # Server
29
+ "ExactSvmServerScheme",
30
+ # Facilitator
31
+ "ExactSvmFacilitatorScheme",
32
+ "FacilitatorSvmSigner",
33
+ # Constants
34
+ "SCHEME_EXACT",
35
+ ]
@@ -0,0 +1,23 @@
1
+ """Solana SVM Exact Scheme - Client Implementation.
2
+
3
+ This module provides the client-side implementation of the exact payment scheme
4
+ for Solana network using SPL Token TransferChecked instructions.
5
+
6
+ The client creates and signs a Solana transaction containing a TransferChecked
7
+ instruction, which the facilitator then co-signs (as fee payer) and broadcasts.
8
+
9
+ This module re-exports the client implementation from the monolithic svm module,
10
+ providing the standard scheme package structure.
11
+ """
12
+
13
+ from t402.svm import (
14
+ SCHEME_EXACT,
15
+ ExactSvmClientScheme,
16
+ ClientSvmSigner,
17
+ )
18
+
19
+ __all__ = [
20
+ "SCHEME_EXACT",
21
+ "ExactSvmClientScheme",
22
+ "ClientSvmSigner",
23
+ ]
@@ -0,0 +1,24 @@
1
+ """Solana SVM Exact Scheme - Facilitator Implementation.
2
+
3
+ This module provides the facilitator-side implementation of the exact payment
4
+ scheme for Solana network using SPL Token TransferChecked instructions.
5
+
6
+ The facilitator:
7
+ 1. Verifies signed transactions by checking transfer instruction parameters,
8
+ ensuring the facilitator's funds are not being stolen, and simulating
9
+ 2. Settles payments by co-signing (as fee payer) and broadcasting the transaction
10
+ 3. Waits for transaction confirmation
11
+
12
+ This module re-exports the facilitator implementation from the monolithic svm module,
13
+ providing the standard scheme package structure.
14
+ """
15
+
16
+ from t402.svm import (
17
+ ExactSvmFacilitatorScheme,
18
+ FacilitatorSvmSigner,
19
+ )
20
+
21
+ __all__ = [
22
+ "ExactSvmFacilitatorScheme",
23
+ "FacilitatorSvmSigner",
24
+ ]
@@ -0,0 +1,20 @@
1
+ """Solana SVM Exact Scheme - Server Implementation.
2
+
3
+ This module provides the server-side implementation of the exact payment scheme
4
+ for Solana network.
5
+
6
+ The server parses user-friendly prices into atomic token amounts and enhances
7
+ payment requirements with the facilitator's fee payer address so clients can
8
+ build transactions correctly.
9
+
10
+ This module re-exports the server implementation from the monolithic svm module,
11
+ providing the standard scheme package structure.
12
+ """
13
+
14
+ from t402.svm import (
15
+ ExactSvmServerScheme,
16
+ )
17
+
18
+ __all__ = [
19
+ "ExactSvmServerScheme",
20
+ ]
@@ -0,0 +1,23 @@
1
+ """Solana SVM Up-To Payment Scheme Types.
2
+
3
+ This package provides types for the upto payment scheme on Solana
4
+ using SPL ApproveChecked. The client approves the facilitator (delegate)
5
+ to transfer up to maxAmount of tokens from the client's associated
6
+ token account.
7
+ """
8
+
9
+ from t402.schemes.svm.upto.types import (
10
+ UptoSvmAuthorization,
11
+ UptoSvmPayload,
12
+ UptoSvmExtra,
13
+ upto_payload_from_dict,
14
+ is_upto_svm_payload,
15
+ )
16
+
17
+ __all__ = [
18
+ "UptoSvmAuthorization",
19
+ "UptoSvmPayload",
20
+ "UptoSvmExtra",
21
+ "upto_payload_from_dict",
22
+ "is_upto_svm_payload",
23
+ ]
@@ -0,0 +1,193 @@
1
+ """Solana SVM Up-To Scheme Types.
2
+
3
+ SVM-specific types for the up-to payment scheme using SPL ApproveChecked.
4
+ The client signs an approve transaction that authorizes the facilitator
5
+ to transfer up to maxAmount tokens from the client's ATA.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ from typing import Any, Dict, Optional
11
+
12
+ from pydantic import BaseModel, ConfigDict, Field
13
+ from pydantic.alias_generators import to_camel
14
+
15
+
16
+ class UptoSvmAuthorization(BaseModel):
17
+ """SPL ApproveChecked authorization metadata.
18
+
19
+ Contains the details of the delegate approval including the owner,
20
+ delegate (facilitator), token mint, maximum amount, and source ATA.
21
+ """
22
+
23
+ owner: str = Field(description="Token owner address (base58)")
24
+ delegate: str = Field(description="Approved delegate address - facilitator (base58)")
25
+ mint: str = Field(description="SPL token mint address (base58)")
26
+ max_amount: str = Field(
27
+ alias="maxAmount",
28
+ description="Maximum approved amount in smallest units (as string)",
29
+ )
30
+ source_ata: str = Field(
31
+ alias="sourceATA",
32
+ description="Owner's associated token account (base58)",
33
+ )
34
+
35
+ model_config = ConfigDict(
36
+ alias_generator=to_camel,
37
+ populate_by_name=True,
38
+ from_attributes=True,
39
+ )
40
+
41
+ def to_dict(self) -> Dict[str, Any]:
42
+ """Convert to dictionary for JSON serialization."""
43
+ return {
44
+ "owner": self.owner,
45
+ "delegate": self.delegate,
46
+ "mint": self.mint,
47
+ "maxAmount": self.max_amount,
48
+ "sourceATA": self.source_ata,
49
+ }
50
+
51
+
52
+ class UptoSvmPayload(BaseModel):
53
+ """Up-to SVM payment payload containing a signed approve transaction.
54
+
55
+ The facilitator uses the delegated authority to transfer tokens
56
+ up to the approved maxAmount.
57
+ """
58
+
59
+ transaction: str = Field(description="Base64 encoded signed approve transaction")
60
+ authorization: UptoSvmAuthorization = Field(
61
+ description="Approval authorization metadata"
62
+ )
63
+ payment_nonce: str = Field(
64
+ alias="paymentNonce",
65
+ description="Unique nonce for replay protection (hex string)",
66
+ )
67
+
68
+ model_config = ConfigDict(
69
+ alias_generator=to_camel,
70
+ populate_by_name=True,
71
+ from_attributes=True,
72
+ )
73
+
74
+ def to_dict(self) -> Dict[str, Any]:
75
+ """Convert to dictionary for JSON serialization."""
76
+ return {
77
+ "transaction": self.transaction,
78
+ "authorization": self.authorization.to_dict(),
79
+ "paymentNonce": self.payment_nonce,
80
+ }
81
+
82
+
83
+ class UptoSvmExtra(BaseModel):
84
+ """SVM-specific extra fields for the upto scheme.
85
+
86
+ Included in the PaymentRequirements.extra field to provide
87
+ billing configuration for upto payments.
88
+ """
89
+
90
+ fee_payer: Optional[str] = Field(
91
+ default=None,
92
+ alias="feePayer",
93
+ description="Facilitator address that will pay transaction fees (base58)",
94
+ )
95
+ max_amount: Optional[str] = Field(
96
+ default=None,
97
+ alias="maxAmount",
98
+ description="Maximum payment amount authorized",
99
+ )
100
+ min_amount: Optional[str] = Field(
101
+ default=None,
102
+ alias="minAmount",
103
+ description="Minimum acceptable settlement amount",
104
+ )
105
+ unit: Optional[str] = Field(
106
+ default=None,
107
+ description="Billing unit (e.g., 'token', 'request', 'second')",
108
+ )
109
+ unit_price: Optional[str] = Field(
110
+ default=None,
111
+ alias="unitPrice",
112
+ description="Price per unit in smallest denomination",
113
+ )
114
+
115
+ model_config = ConfigDict(
116
+ alias_generator=to_camel,
117
+ populate_by_name=True,
118
+ from_attributes=True,
119
+ )
120
+
121
+
122
+ def upto_payload_from_dict(data: Dict[str, Any]) -> UptoSvmPayload:
123
+ """Create an UptoSvmPayload from a dictionary.
124
+
125
+ Args:
126
+ data: Dictionary containing payload data with keys:
127
+ - transaction: base64 encoded transaction
128
+ - authorization: dict with owner, delegate, mint, maxAmount, sourceATA
129
+ - paymentNonce: hex string nonce
130
+
131
+ Returns:
132
+ UptoSvmPayload instance
133
+
134
+ Raises:
135
+ ValueError: If required fields are missing
136
+ """
137
+ auth_data = data.get("authorization", {})
138
+ if not isinstance(auth_data, dict):
139
+ raise ValueError("authorization must be a dictionary")
140
+
141
+ transaction = data.get("transaction")
142
+ if not isinstance(transaction, str) or not transaction:
143
+ raise ValueError("missing or invalid transaction field")
144
+
145
+ payment_nonce = data.get("paymentNonce")
146
+ if not isinstance(payment_nonce, str) or not payment_nonce:
147
+ raise ValueError("missing or invalid paymentNonce field")
148
+
149
+ owner = auth_data.get("owner")
150
+ if not isinstance(owner, str) or not owner:
151
+ raise ValueError("missing or invalid authorization.owner field")
152
+
153
+ delegate = auth_data.get("delegate")
154
+ if not isinstance(delegate, str) or not delegate:
155
+ raise ValueError("missing or invalid authorization.delegate field")
156
+
157
+ return UptoSvmPayload(
158
+ transaction=transaction,
159
+ authorization=UptoSvmAuthorization(
160
+ owner=owner,
161
+ delegate=delegate,
162
+ mint=auth_data.get("mint", ""),
163
+ max_amount=auth_data.get("maxAmount", ""),
164
+ source_ata=auth_data.get("sourceATA", ""),
165
+ ),
166
+ payment_nonce=payment_nonce,
167
+ )
168
+
169
+
170
+ def is_upto_svm_payload(data: Any) -> bool:
171
+ """Check if the given data represents an SVM upto payload.
172
+
173
+ Args:
174
+ data: Data to check
175
+
176
+ Returns:
177
+ True if data has the correct SVM upto payload structure
178
+ """
179
+ if not isinstance(data, dict):
180
+ return False
181
+
182
+ if not isinstance(data.get("transaction"), str):
183
+ return False
184
+
185
+ if not isinstance(data.get("paymentNonce"), str):
186
+ return False
187
+
188
+ auth = data.get("authorization")
189
+ if not isinstance(auth, dict):
190
+ return False
191
+
192
+ required_fields = ["owner", "delegate", "mint", "maxAmount", "sourceATA"]
193
+ return all(isinstance(auth.get(f), str) for f in required_fields)
@@ -0,0 +1,84 @@
1
+ """Tezos Blockchain Payment Schemes.
2
+
3
+ This package provides payment scheme implementations for the Tezos blockchain.
4
+
5
+ Supported schemes:
6
+ - exact-direct: Client executes FA2 transfer directly, provides opHash as proof
7
+
8
+ Usage:
9
+ ```python
10
+ from t402.schemes.tezos import (
11
+ ExactDirectTezosClient,
12
+ ExactDirectTezosServer,
13
+ ExactDirectTezosFacilitator,
14
+ ClientTezosSigner,
15
+ FacilitatorTezosSigner,
16
+ SCHEME_EXACT_DIRECT,
17
+ )
18
+ ```
19
+ """
20
+
21
+ from t402.schemes.tezos.constants import (
22
+ SCHEME_EXACT_DIRECT,
23
+ TEZOS_MAINNET,
24
+ TEZOS_GHOSTNET,
25
+ USDT_MAINNET_CONTRACT,
26
+ USDT_MAINNET_TOKEN_ID,
27
+ USDT_DECIMALS,
28
+ USDT_MAINNET,
29
+ NETWORK_CONFIGS,
30
+ TOKEN_REGISTRY,
31
+ is_tezos_network,
32
+ is_valid_address,
33
+ is_valid_operation_hash,
34
+ create_asset_identifier,
35
+ parse_asset_identifier,
36
+ get_network_config,
37
+ get_token_info,
38
+ get_token_by_contract,
39
+ decimal_to_atomic,
40
+ parse_decimal_to_atomic,
41
+ )
42
+ from t402.schemes.tezos.types import (
43
+ ClientTezosSigner,
44
+ FacilitatorTezosSigner,
45
+ ExactDirectPayload,
46
+ )
47
+ from t402.schemes.tezos.exact_direct import (
48
+ ExactDirectTezosClient,
49
+ ExactDirectTezosServer,
50
+ ExactDirectTezosFacilitator,
51
+ )
52
+
53
+ __all__ = [
54
+ # Scheme classes
55
+ "ExactDirectTezosClient",
56
+ "ExactDirectTezosServer",
57
+ "ExactDirectTezosFacilitator",
58
+ # Signer protocols
59
+ "ClientTezosSigner",
60
+ "FacilitatorTezosSigner",
61
+ # Payload type
62
+ "ExactDirectPayload",
63
+ # Constants
64
+ "SCHEME_EXACT_DIRECT",
65
+ "TEZOS_MAINNET",
66
+ "TEZOS_GHOSTNET",
67
+ "USDT_MAINNET_CONTRACT",
68
+ "USDT_MAINNET_TOKEN_ID",
69
+ "USDT_DECIMALS",
70
+ "USDT_MAINNET",
71
+ "NETWORK_CONFIGS",
72
+ "TOKEN_REGISTRY",
73
+ # Utility functions
74
+ "is_tezos_network",
75
+ "is_valid_address",
76
+ "is_valid_operation_hash",
77
+ "create_asset_identifier",
78
+ "parse_asset_identifier",
79
+ "get_network_config",
80
+ "get_token_info",
81
+ "get_token_by_contract",
82
+ "decimal_to_atomic",
83
+ "parse_decimal_to_atomic",
84
+ ]