t402 1.9.0__py3-none-any.whl → 1.9.1__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 (100) hide show
  1. t402/__init__.py +2 -1
  2. t402/bridge/client.py +13 -5
  3. t402/bridge/constants.py +3 -1
  4. t402/bridge/router.py +1 -1
  5. t402/bridge/scan.py +3 -1
  6. t402/chains.py +268 -1
  7. t402/cli.py +31 -9
  8. t402/common.py +2 -0
  9. t402/cosmos_paywall_template.py +2 -0
  10. t402/encoding.py +9 -3
  11. t402/erc4337/accounts.py +56 -51
  12. t402/erc4337/bundlers.py +105 -99
  13. t402/erc4337/paymasters.py +100 -109
  14. t402/erc4337/types.py +39 -26
  15. t402/evm_paywall_template.py +1 -1
  16. t402/fastapi/middleware.py +1 -3
  17. t402/mcp/server.py +79 -46
  18. t402/near_paywall_template.py +2 -0
  19. t402/networks.py +34 -1
  20. t402/paywall.py +1 -3
  21. t402/schemes/__init__.py +124 -0
  22. t402/schemes/aptos/__init__.py +70 -0
  23. t402/schemes/aptos/constants.py +349 -0
  24. t402/schemes/aptos/exact_direct/__init__.py +44 -0
  25. t402/schemes/aptos/exact_direct/client.py +202 -0
  26. t402/schemes/aptos/exact_direct/facilitator.py +426 -0
  27. t402/schemes/aptos/exact_direct/server.py +272 -0
  28. t402/schemes/aptos/types.py +237 -0
  29. t402/schemes/evm/__init__.py +46 -1
  30. t402/schemes/evm/exact/__init__.py +11 -0
  31. t402/schemes/evm/exact/client.py +3 -1
  32. t402/schemes/evm/exact/facilitator.py +894 -0
  33. t402/schemes/evm/exact/server.py +1 -1
  34. t402/schemes/evm/exact_legacy/__init__.py +38 -0
  35. t402/schemes/evm/exact_legacy/client.py +291 -0
  36. t402/schemes/evm/exact_legacy/facilitator.py +777 -0
  37. t402/schemes/evm/exact_legacy/server.py +231 -0
  38. t402/schemes/evm/upto/__init__.py +12 -0
  39. t402/schemes/evm/upto/client.py +6 -2
  40. t402/schemes/evm/upto/facilitator.py +625 -0
  41. t402/schemes/evm/upto/server.py +243 -0
  42. t402/schemes/evm/upto/types.py +3 -1
  43. t402/schemes/interfaces.py +6 -2
  44. t402/schemes/near/__init__.py +112 -0
  45. t402/schemes/near/constants.py +189 -0
  46. t402/schemes/near/exact_direct/__init__.py +21 -0
  47. t402/schemes/near/exact_direct/client.py +204 -0
  48. t402/schemes/near/exact_direct/facilitator.py +455 -0
  49. t402/schemes/near/exact_direct/server.py +303 -0
  50. t402/schemes/near/types.py +419 -0
  51. t402/schemes/polkadot/__init__.py +72 -0
  52. t402/schemes/polkadot/constants.py +155 -0
  53. t402/schemes/polkadot/exact_direct/__init__.py +43 -0
  54. t402/schemes/polkadot/exact_direct/client.py +235 -0
  55. t402/schemes/polkadot/exact_direct/facilitator.py +428 -0
  56. t402/schemes/polkadot/exact_direct/server.py +292 -0
  57. t402/schemes/polkadot/types.py +385 -0
  58. t402/schemes/registry.py +6 -2
  59. t402/schemes/stacks/__init__.py +68 -0
  60. t402/schemes/stacks/constants.py +122 -0
  61. t402/schemes/stacks/exact_direct/__init__.py +43 -0
  62. t402/schemes/stacks/exact_direct/client.py +222 -0
  63. t402/schemes/stacks/exact_direct/facilitator.py +424 -0
  64. t402/schemes/stacks/exact_direct/server.py +292 -0
  65. t402/schemes/stacks/types.py +380 -0
  66. t402/schemes/svm/__init__.py +29 -0
  67. t402/schemes/svm/exact/__init__.py +35 -0
  68. t402/schemes/svm/exact/client.py +23 -0
  69. t402/schemes/svm/exact/facilitator.py +24 -0
  70. t402/schemes/svm/exact/server.py +20 -0
  71. t402/schemes/tezos/__init__.py +84 -0
  72. t402/schemes/tezos/constants.py +372 -0
  73. t402/schemes/tezos/exact_direct/__init__.py +22 -0
  74. t402/schemes/tezos/exact_direct/client.py +226 -0
  75. t402/schemes/tezos/exact_direct/facilitator.py +491 -0
  76. t402/schemes/tezos/exact_direct/server.py +277 -0
  77. t402/schemes/tezos/types.py +220 -0
  78. t402/schemes/ton/__init__.py +9 -2
  79. t402/schemes/ton/exact/__init__.py +7 -0
  80. t402/schemes/ton/exact/facilitator.py +730 -0
  81. t402/schemes/ton/exact/server.py +1 -1
  82. t402/schemes/tron/__init__.py +11 -2
  83. t402/schemes/tron/exact/__init__.py +9 -0
  84. t402/schemes/tron/exact/facilitator.py +673 -0
  85. t402/schemes/tron/exact/server.py +1 -1
  86. t402/stacks_paywall_template.py +2 -0
  87. t402/svm.py +45 -11
  88. t402/svm_paywall_template.py +1 -1
  89. t402/ton.py +5 -1
  90. t402/ton_paywall_template.py +1 -192
  91. t402/tron.py +2 -0
  92. t402/tron_paywall_template.py +2 -0
  93. t402/types.py +3 -1
  94. t402/wdk/errors.py +15 -5
  95. t402/wdk/signer.py +11 -2
  96. {t402-1.9.0.dist-info → t402-1.9.1.dist-info}/METADATA +42 -1
  97. t402-1.9.1.dist-info/RECORD +125 -0
  98. t402-1.9.0.dist-info/RECORD +0 -72
  99. {t402-1.9.0.dist-info → t402-1.9.1.dist-info}/WHEEL +0 -0
  100. {t402-1.9.0.dist-info → t402-1.9.1.dist-info}/entry_points.txt +0 -0
t402/svm.py CHANGED
@@ -17,7 +17,16 @@ from __future__ import annotations
17
17
  import re
18
18
  import time
19
19
  import base64
20
- from typing import Any, Dict, Optional, List, Callable, Awaitable, Protocol, runtime_checkable
20
+ from typing import (
21
+ Any,
22
+ Dict,
23
+ Optional,
24
+ List,
25
+ Callable,
26
+ Awaitable,
27
+ Protocol,
28
+ runtime_checkable,
29
+ )
21
30
  from typing_extensions import TypedDict
22
31
 
23
32
  from pydantic import BaseModel, ConfigDict, Field, field_validator
@@ -33,6 +42,7 @@ try:
33
42
  from solders.instruction import CompiledInstruction
34
43
  from solana.rpc.async_api import AsyncClient
35
44
  from solana.rpc.commitment import Commitment, Confirmed
45
+
36
46
  SOLANA_AVAILABLE = True
37
47
  except ImportError:
38
48
  SOLANA_AVAILABLE = False
@@ -703,7 +713,9 @@ def get_token_payer_from_transaction(tx_base64: str) -> Optional[str]:
703
713
  try:
704
714
  tx = decode_versioned_transaction(tx_base64)
705
715
  message = tx.message
706
- account_keys = list(message.account_keys) if hasattr(message, "account_keys") else []
716
+ account_keys = (
717
+ list(message.account_keys) if hasattr(message, "account_keys") else []
718
+ )
707
719
 
708
720
  # Look for token program instructions
709
721
  for ix in message.instructions:
@@ -729,6 +741,7 @@ def get_token_payer_from_transaction(tx_base64: str) -> Optional[str]:
729
741
 
730
742
  class TransferDetails(TypedDict):
731
743
  """Details of a token transfer instruction."""
744
+
732
745
  source: str
733
746
  mint: str
734
747
  destination: str
@@ -755,7 +768,9 @@ def parse_transfer_checked_instruction(
755
768
  try:
756
769
  tx = decode_versioned_transaction(tx_base64)
757
770
  message = tx.message
758
- account_keys = list(message.account_keys) if hasattr(message, "account_keys") else []
771
+ account_keys = (
772
+ list(message.account_keys) if hasattr(message, "account_keys") else []
773
+ )
759
774
 
760
775
  for ix in message.instructions:
761
776
  program_idx = ix.program_id_index
@@ -789,10 +804,18 @@ def parse_transfer_checked_instruction(
789
804
  authority_idx = accounts[3]
790
805
 
791
806
  return {
792
- "source": str(account_keys[source_idx]) if source_idx < len(account_keys) else "",
793
- "mint": str(account_keys[mint_idx]) if mint_idx < len(account_keys) else "",
794
- "destination": str(account_keys[dest_idx]) if dest_idx < len(account_keys) else "",
795
- "authority": str(account_keys[authority_idx]) if authority_idx < len(account_keys) else "",
807
+ "source": str(account_keys[source_idx])
808
+ if source_idx < len(account_keys)
809
+ else "",
810
+ "mint": str(account_keys[mint_idx])
811
+ if mint_idx < len(account_keys)
812
+ else "",
813
+ "destination": str(account_keys[dest_idx])
814
+ if dest_idx < len(account_keys)
815
+ else "",
816
+ "authority": str(account_keys[authority_idx])
817
+ if authority_idx < len(account_keys)
818
+ else "",
796
819
  "amount": amount,
797
820
  "decimals": decimals,
798
821
  }
@@ -1101,12 +1124,14 @@ class RpcSvmSigner:
1101
1124
 
1102
1125
  class ExactSvmPayloadV2(TypedDict):
1103
1126
  """Exact SVM payment payload (V2 format)."""
1127
+
1104
1128
  transaction: str
1105
1129
  authorization: Optional[Dict[str, Any]]
1106
1130
 
1107
1131
 
1108
1132
  class SvmPaymentRequirementsExtra(TypedDict, total=False):
1109
1133
  """Extra fields for SVM payment requirements."""
1134
+
1110
1135
  feePayer: str
1111
1136
 
1112
1137
 
@@ -1159,7 +1184,9 @@ class ExactSvmClientScheme:
1159
1184
  transfer = parse_transfer_checked_instruction(signed_tx)
1160
1185
 
1161
1186
  now = int(time.time())
1162
- valid_until = now + requirements.get("maxTimeoutSeconds", DEFAULT_VALIDITY_DURATION)
1187
+ valid_until = now + requirements.get(
1188
+ "maxTimeoutSeconds", DEFAULT_VALIDITY_DURATION
1189
+ )
1163
1190
 
1164
1191
  authorization = None
1165
1192
  if transfer:
@@ -1339,7 +1366,10 @@ class ExactSvmFacilitatorScheme:
1339
1366
  }
1340
1367
 
1341
1368
  # Validate scheme
1342
- if payload.get("scheme") != SCHEME_EXACT or requirements.get("scheme") != SCHEME_EXACT:
1369
+ if (
1370
+ payload.get("scheme") != SCHEME_EXACT
1371
+ or requirements.get("scheme") != SCHEME_EXACT
1372
+ ):
1343
1373
  return {
1344
1374
  "isValid": False,
1345
1375
  "invalidReason": "unsupported_scheme",
@@ -1474,7 +1504,9 @@ class ExactSvmFacilitatorScheme:
1474
1504
  "success": False,
1475
1505
  "network": network,
1476
1506
  "transaction": "",
1477
- "errorReason": verify_result.get("invalidReason", "verification_failed"),
1507
+ "errorReason": verify_result.get(
1508
+ "invalidReason", "verification_failed"
1509
+ ),
1478
1510
  "payer": verify_result.get("payer", ""),
1479
1511
  }
1480
1512
 
@@ -1539,7 +1571,9 @@ def create_server_scheme() -> ExactSvmServerScheme:
1539
1571
  return ExactSvmServerScheme()
1540
1572
 
1541
1573
 
1542
- def create_facilitator_scheme(signer: FacilitatorSvmSigner) -> ExactSvmFacilitatorScheme:
1574
+ def create_facilitator_scheme(
1575
+ signer: FacilitatorSvmSigner,
1576
+ ) -> ExactSvmFacilitatorScheme:
1543
1577
  """
1544
1578
  Create a facilitator scheme for SVM payments.
1545
1579