agirails 2.0.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 (94) hide show
  1. agirails/__init__.py +547 -0
  2. agirails/abi/ACTPKernel.json +1340 -0
  3. agirails/abi/ERC20.json +40 -0
  4. agirails/abi/EscrowVault.json +134 -0
  5. agirails/abis/actp_kernel.json +1617 -0
  6. agirails/abis/agent_registry.json +782 -0
  7. agirails/abis/eas.json +110 -0
  8. agirails/abis/escrow_vault.json +337 -0
  9. agirails/abis/usdc.json +185 -0
  10. agirails/adapters/__init__.py +59 -0
  11. agirails/adapters/base.py +285 -0
  12. agirails/adapters/basic.py +288 -0
  13. agirails/adapters/standard.py +378 -0
  14. agirails/builders/__init__.py +50 -0
  15. agirails/builders/delivery_proof.py +655 -0
  16. agirails/builders/quote.py +357 -0
  17. agirails/cli/__init__.py +15 -0
  18. agirails/cli/commands/__init__.py +19 -0
  19. agirails/cli/commands/balance.py +93 -0
  20. agirails/cli/commands/batch.py +378 -0
  21. agirails/cli/commands/config.py +174 -0
  22. agirails/cli/commands/init.py +104 -0
  23. agirails/cli/commands/mint.py +100 -0
  24. agirails/cli/commands/pay.py +115 -0
  25. agirails/cli/commands/simulate.py +348 -0
  26. agirails/cli/commands/time.py +233 -0
  27. agirails/cli/commands/tx.py +263 -0
  28. agirails/cli/commands/watch.py +264 -0
  29. agirails/cli/main.py +138 -0
  30. agirails/cli/utils/__init__.py +39 -0
  31. agirails/cli/utils/client.py +283 -0
  32. agirails/cli/utils/output.py +252 -0
  33. agirails/cli/utils/validation.py +297 -0
  34. agirails/client.py +431 -0
  35. agirails/config/__init__.py +27 -0
  36. agirails/config/abis/AgentRegistry.json +782 -0
  37. agirails/config/networks.py +239 -0
  38. agirails/errors/__init__.py +116 -0
  39. agirails/errors/agent.py +282 -0
  40. agirails/errors/base.py +161 -0
  41. agirails/errors/mock.py +106 -0
  42. agirails/errors/network.py +139 -0
  43. agirails/errors/storage.py +243 -0
  44. agirails/errors/transaction.py +271 -0
  45. agirails/errors/validation.py +129 -0
  46. agirails/level0/__init__.py +68 -0
  47. agirails/level0/directory.py +410 -0
  48. agirails/level0/provide.py +237 -0
  49. agirails/level0/provider.py +815 -0
  50. agirails/level0/request.py +964 -0
  51. agirails/level1/__init__.py +70 -0
  52. agirails/level1/agent.py +917 -0
  53. agirails/level1/config.py +210 -0
  54. agirails/level1/job.py +258 -0
  55. agirails/level1/pricing.py +230 -0
  56. agirails/protocol/__init__.py +148 -0
  57. agirails/protocol/agent_registry.py +820 -0
  58. agirails/protocol/did.py +611 -0
  59. agirails/protocol/eas.py +739 -0
  60. agirails/protocol/escrow.py +753 -0
  61. agirails/protocol/events.py +785 -0
  62. agirails/protocol/kernel.py +728 -0
  63. agirails/protocol/messages.py +686 -0
  64. agirails/protocol/nonce.py +354 -0
  65. agirails/protocol/proofs.py +468 -0
  66. agirails/py.typed +0 -0
  67. agirails/runtime/__init__.py +72 -0
  68. agirails/runtime/base.py +329 -0
  69. agirails/runtime/blockchain_runtime.py +673 -0
  70. agirails/runtime/mock_runtime.py +645 -0
  71. agirails/runtime/mock_state_manager.py +340 -0
  72. agirails/runtime/types.py +427 -0
  73. agirails/types/__init__.py +69 -0
  74. agirails/types/did.py +278 -0
  75. agirails/types/message.py +717 -0
  76. agirails/types/transaction.py +391 -0
  77. agirails/utils/__init__.py +86 -0
  78. agirails/utils/canonical_json.py +334 -0
  79. agirails/utils/helpers.py +927 -0
  80. agirails/utils/logger.py +185 -0
  81. agirails/utils/logging.py +200 -0
  82. agirails/utils/nonce_tracker.py +542 -0
  83. agirails/utils/received_nonce_tracker.py +472 -0
  84. agirails/utils/secure_nonce.py +96 -0
  85. agirails/utils/security.py +1156 -0
  86. agirails/utils/semaphore.py +233 -0
  87. agirails/utils/used_attestation_tracker.py +325 -0
  88. agirails/utils/validation.py +657 -0
  89. agirails/version.py +4 -0
  90. agirails-2.0.0.dist-info/METADATA +546 -0
  91. agirails-2.0.0.dist-info/RECORD +94 -0
  92. agirails-2.0.0.dist-info/WHEEL +4 -0
  93. agirails-2.0.0.dist-info/entry_points.txt +2 -0
  94. agirails-2.0.0.dist-info/licenses/LICENSE +190 -0
agirails/__init__.py ADDED
@@ -0,0 +1,547 @@
1
+ """
2
+ AGIRAILS Python SDK - Agent Commerce Transaction Protocol.
3
+
4
+ This SDK provides a complete implementation of the ACTP protocol for AI agents.
5
+
6
+ Quick Start:
7
+ >>> from agirails import ACTPClient
8
+ >>> import asyncio
9
+ >>>
10
+ >>> async def main():
11
+ ... client = await ACTPClient.create(
12
+ ... mode="mock",
13
+ ... requester_address="0x1234567890123456789012345678901234567890"
14
+ ... )
15
+ ... result = await client.basic.pay({
16
+ ... "to": "0xabcdefABCDEFabcdefABCDEFabcdefABCDEFabcd",
17
+ ... "amount": 100
18
+ ... })
19
+ ... print(f"Transaction: {result.tx_id}")
20
+ ...
21
+ >>> asyncio.run(main())
22
+
23
+ The SDK provides three levels of API:
24
+ - **Basic**: Simple `pay()` method for quick payments
25
+ - **Standard**: Explicit lifecycle control with `create_transaction()`, `link_escrow()`, etc.
26
+ - **Advanced**: Direct runtime access for custom workflows
27
+
28
+ Modules:
29
+ - `client`: ACTPClient factory and configuration
30
+ - `adapters`: BasicAdapter, StandardAdapter
31
+ - `runtime`: MockRuntime and BlockchainRuntime implementations
32
+ - `errors`: Exception hierarchy for ACTP errors
33
+ - `utils`: Helpers, security, logging, and concurrency utilities
34
+ """
35
+
36
+ from agirails.version import __version__, __version_info__
37
+
38
+ # Client
39
+ from agirails.client import (
40
+ ACTPClient,
41
+ ACTPClientConfig,
42
+ ACTPClientInfo,
43
+ ACTPClientMode,
44
+ )
45
+
46
+ # Adapters
47
+ from agirails.adapters import (
48
+ BaseAdapter,
49
+ BasicAdapter,
50
+ BasicPayParams,
51
+ BasicPayResult,
52
+ CheckStatusResult,
53
+ StandardAdapter,
54
+ StandardTransactionParams,
55
+ TransactionDetails,
56
+ DEFAULT_DEADLINE_SECONDS,
57
+ DEFAULT_DISPUTE_WINDOW_SECONDS,
58
+ MIN_AMOUNT_WEI,
59
+ MAX_DEADLINE_HOURS,
60
+ MAX_DEADLINE_DAYS,
61
+ )
62
+
63
+ # Runtime Layer
64
+ from agirails.runtime import (
65
+ # Types
66
+ State,
67
+ TransactionStateValue,
68
+ MockTransaction,
69
+ MockEscrow,
70
+ MockAccount,
71
+ MockBlockchain,
72
+ MockEvent,
73
+ MockState,
74
+ STATE_TRANSITIONS,
75
+ is_valid_transition,
76
+ is_terminal_state,
77
+ MOCK_STATE_DEFAULTS,
78
+ # Interfaces
79
+ CreateTransactionParams,
80
+ TimeInterface,
81
+ IACTPRuntime,
82
+ IMockRuntime,
83
+ is_mock_runtime,
84
+ # Implementations
85
+ MockStateManager,
86
+ MockRuntime,
87
+ )
88
+
89
+ # Errors
90
+ from agirails.errors import (
91
+ ACTPError,
92
+ TransactionNotFoundError,
93
+ InvalidStateTransitionError,
94
+ EscrowNotFoundError,
95
+ DeadlinePassedError,
96
+ DeadlineExpiredError,
97
+ DisputeWindowActiveError,
98
+ ContractPausedError,
99
+ InsufficientBalanceError,
100
+ ValidationError,
101
+ InvalidAddressError,
102
+ InvalidAmountError,
103
+ NetworkError,
104
+ TransactionRevertedError,
105
+ SignatureVerificationError,
106
+ StorageError,
107
+ InvalidCIDError,
108
+ UploadTimeoutError,
109
+ DownloadTimeoutError,
110
+ FileSizeLimitExceededError,
111
+ StorageAuthenticationError,
112
+ StorageRateLimitError,
113
+ ContentNotFoundError,
114
+ NoProviderFoundError,
115
+ ACTPTimeoutError,
116
+ ProviderRejectedError,
117
+ DeliveryFailedError,
118
+ DisputeRaisedError,
119
+ ServiceConfigError,
120
+ AgentLifecycleError,
121
+ QueryCapExceededError,
122
+ MockStateCorruptedError,
123
+ MockStateVersionError,
124
+ MockStateLockError,
125
+ )
126
+
127
+ # Utilities - Security
128
+ from agirails.utils import (
129
+ timing_safe_equal,
130
+ validate_path,
131
+ validate_service_name,
132
+ is_valid_address,
133
+ safe_json_parse,
134
+ LRUCache,
135
+ Logger,
136
+ Semaphore,
137
+ RateLimiter,
138
+ # PARITY: SecureNonce
139
+ generate_secure_nonce,
140
+ is_valid_nonce,
141
+ generate_secure_nonces,
142
+ # PARITY: UsedAttestationTracker
143
+ IUsedAttestationTracker,
144
+ InMemoryUsedAttestationTracker,
145
+ FileBasedUsedAttestationTracker,
146
+ create_used_attestation_tracker,
147
+ # PARITY: ReceivedNonceTracker
148
+ NonceValidationResult,
149
+ IReceivedNonceTracker,
150
+ InMemoryReceivedNonceTracker,
151
+ SetBasedReceivedNonceTracker,
152
+ create_received_nonce_tracker,
153
+ )
154
+
155
+ # Utilities - Helpers
156
+ from agirails.utils.helpers import (
157
+ USDC,
158
+ Deadline,
159
+ Address,
160
+ Bytes32,
161
+ StateHelper,
162
+ DisputeWindow,
163
+ ServiceHash,
164
+ ServiceMetadata,
165
+ parse_usdc,
166
+ format_usdc,
167
+ shorten_address,
168
+ hash_service_metadata,
169
+ )
170
+
171
+ # Utilities - Validation
172
+ from agirails.utils.validation import (
173
+ validate_address,
174
+ validate_amount,
175
+ validate_deadline,
176
+ validate_tx_id,
177
+ validate_endpoint_url,
178
+ validate_dispute_window,
179
+ validate_bytes32,
180
+ )
181
+
182
+ # Utilities - Canonical JSON
183
+ from agirails.utils.canonical_json import (
184
+ canonical_json_dumps,
185
+ compute_type_hash,
186
+ hash_struct,
187
+ compute_domain_separator,
188
+ )
189
+
190
+ # Level 0 API - Low-level primitives
191
+ from agirails.level0 import (
192
+ ServiceDirectory,
193
+ ServiceEntry,
194
+ ServiceQuery,
195
+ Provider,
196
+ ProviderConfig,
197
+ ProviderStatus,
198
+ provide,
199
+ ProvideOptions,
200
+ request,
201
+ RequestOptions,
202
+ RequestResult,
203
+ )
204
+
205
+ # Level 1 API - Agent abstraction
206
+ from agirails.level1 import (
207
+ Agent,
208
+ AgentConfig,
209
+ AgentBehavior,
210
+ AgentStatus,
211
+ AgentStats,
212
+ AgentBalance,
213
+ Job,
214
+ JobContext,
215
+ JobHandler,
216
+ JobResult,
217
+ ServiceConfig,
218
+ ServiceFilter,
219
+ RetryConfig,
220
+ PricingStrategy,
221
+ CostModel,
222
+ PriceCalculation,
223
+ calculate_price,
224
+ )
225
+
226
+ # Types
227
+ from agirails.types import (
228
+ AgentDID,
229
+ DIDDocument,
230
+ Transaction,
231
+ TransactionState,
232
+ TransactionReceipt,
233
+ TransactionFilter,
234
+ EIP712Domain,
235
+ ServiceRequest,
236
+ ServiceResponse,
237
+ DeliveryProof,
238
+ DeliveryProofMessage,
239
+ DeliveryProofMetadata,
240
+ SignedMessage,
241
+ TypedData,
242
+ compute_result_hash,
243
+ )
244
+
245
+ # Protocol Layer (PARITY: Match TS SDK exports)
246
+ from agirails.protocol import (
247
+ # Messages
248
+ MessageSigner,
249
+ SignatureComponents,
250
+ hash_typed_data,
251
+ create_typed_data,
252
+ HAS_MESSAGES,
253
+ # Proofs
254
+ ProofGenerator,
255
+ ContentProof,
256
+ MerkleProof,
257
+ verify_merkle_proof,
258
+ hash_service_input,
259
+ hash_service_output,
260
+ # DID
261
+ DIDManager,
262
+ DIDResolver,
263
+ VerificationMethod,
264
+ ServiceEndpoint,
265
+ create_did_from_address,
266
+ did_to_address,
267
+ )
268
+
269
+ # Protocol modules (conditional, require web3)
270
+ try:
271
+ from agirails.protocol import (
272
+ # Kernel
273
+ ACTPKernel,
274
+ TransactionView,
275
+ # Escrow
276
+ EscrowVault,
277
+ CreateEscrowParams,
278
+ EscrowInfo,
279
+ generate_escrow_id,
280
+ # Events
281
+ EventMonitor,
282
+ EventFilter,
283
+ EventType,
284
+ ACTPEvent,
285
+ TransactionCreatedEvent,
286
+ StateTransitionedEvent,
287
+ EscrowCreatedEvent,
288
+ EscrowPayoutEvent,
289
+ # Nonce
290
+ NonceManager,
291
+ NonceManagerPool,
292
+ # EAS
293
+ EASHelper,
294
+ Attestation,
295
+ DeliveryAttestationData,
296
+ Schema,
297
+ DELIVERY_SCHEMA,
298
+ ZERO_BYTES32,
299
+ # Agent Registry
300
+ AgentRegistry,
301
+ AgentProfile,
302
+ ServiceDescriptor,
303
+ compute_service_type_hash,
304
+ )
305
+ HAS_WEB3_PROTOCOL = True
306
+ except ImportError:
307
+ HAS_WEB3_PROTOCOL = False
308
+
309
+ # Builders
310
+ from agirails.builders import (
311
+ DeliveryProofBuilder,
312
+ QuoteBuilder,
313
+ )
314
+
315
+ __all__ = [
316
+ # Version
317
+ "__version__",
318
+ "__version_info__",
319
+ # Client
320
+ "ACTPClient",
321
+ "ACTPClientConfig",
322
+ "ACTPClientInfo",
323
+ "ACTPClientMode",
324
+ # Adapters
325
+ "BaseAdapter",
326
+ "BasicAdapter",
327
+ "BasicPayParams",
328
+ "BasicPayResult",
329
+ "CheckStatusResult",
330
+ "StandardAdapter",
331
+ "StandardTransactionParams",
332
+ "TransactionDetails",
333
+ "DEFAULT_DEADLINE_SECONDS",
334
+ "DEFAULT_DISPUTE_WINDOW_SECONDS",
335
+ "MIN_AMOUNT_WEI",
336
+ "MAX_DEADLINE_HOURS",
337
+ "MAX_DEADLINE_DAYS",
338
+ # Runtime Types
339
+ "State",
340
+ "TransactionStateValue",
341
+ "MockTransaction",
342
+ "MockEscrow",
343
+ "MockAccount",
344
+ "MockBlockchain",
345
+ "MockEvent",
346
+ "MockState",
347
+ "STATE_TRANSITIONS",
348
+ "is_valid_transition",
349
+ "is_terminal_state",
350
+ "MOCK_STATE_DEFAULTS",
351
+ # Runtime Interfaces
352
+ "CreateTransactionParams",
353
+ "TimeInterface",
354
+ "IACTPRuntime",
355
+ "IMockRuntime",
356
+ "is_mock_runtime",
357
+ # Runtime Implementations
358
+ "MockStateManager",
359
+ "MockRuntime",
360
+ # Errors - Base
361
+ "ACTPError",
362
+ # Errors - Transaction
363
+ "TransactionNotFoundError",
364
+ "InvalidStateTransitionError",
365
+ "EscrowNotFoundError",
366
+ "DeadlinePassedError",
367
+ "DeadlineExpiredError",
368
+ "DisputeWindowActiveError",
369
+ "ContractPausedError",
370
+ "InsufficientBalanceError",
371
+ # Errors - Validation
372
+ "ValidationError",
373
+ "InvalidAddressError",
374
+ "InvalidAmountError",
375
+ # Errors - Network
376
+ "NetworkError",
377
+ "TransactionRevertedError",
378
+ "SignatureVerificationError",
379
+ # Errors - Storage
380
+ "StorageError",
381
+ "InvalidCIDError",
382
+ "UploadTimeoutError",
383
+ "DownloadTimeoutError",
384
+ "FileSizeLimitExceededError",
385
+ "StorageAuthenticationError",
386
+ "StorageRateLimitError",
387
+ "ContentNotFoundError",
388
+ # Errors - Agent
389
+ "NoProviderFoundError",
390
+ "ACTPTimeoutError",
391
+ "ProviderRejectedError",
392
+ "DeliveryFailedError",
393
+ "DisputeRaisedError",
394
+ "ServiceConfigError",
395
+ "AgentLifecycleError",
396
+ "QueryCapExceededError",
397
+ # Errors - Mock
398
+ "MockStateCorruptedError",
399
+ "MockStateVersionError",
400
+ "MockStateLockError",
401
+ # Utilities - Security
402
+ "timing_safe_equal",
403
+ "validate_path",
404
+ "validate_service_name",
405
+ "is_valid_address",
406
+ "safe_json_parse",
407
+ "LRUCache",
408
+ "Logger",
409
+ "Semaphore",
410
+ "RateLimiter",
411
+ # PARITY: SecureNonce
412
+ "generate_secure_nonce",
413
+ "is_valid_nonce",
414
+ "generate_secure_nonces",
415
+ # PARITY: UsedAttestationTracker
416
+ "IUsedAttestationTracker",
417
+ "InMemoryUsedAttestationTracker",
418
+ "FileBasedUsedAttestationTracker",
419
+ "create_used_attestation_tracker",
420
+ # PARITY: ReceivedNonceTracker
421
+ "NonceValidationResult",
422
+ "IReceivedNonceTracker",
423
+ "InMemoryReceivedNonceTracker",
424
+ "SetBasedReceivedNonceTracker",
425
+ "create_received_nonce_tracker",
426
+ # Utilities - Helpers
427
+ "USDC",
428
+ "Deadline",
429
+ "Address",
430
+ "Bytes32",
431
+ "StateHelper",
432
+ "DisputeWindow",
433
+ "ServiceHash",
434
+ "ServiceMetadata",
435
+ "parse_usdc",
436
+ "format_usdc",
437
+ "shorten_address",
438
+ "hash_service_metadata",
439
+ # Utilities - Validation
440
+ "validate_address",
441
+ "validate_amount",
442
+ "validate_deadline",
443
+ "validate_tx_id",
444
+ "validate_endpoint_url",
445
+ "validate_dispute_window",
446
+ "validate_bytes32",
447
+ # Utilities - Canonical JSON
448
+ "canonical_json_dumps",
449
+ "compute_type_hash",
450
+ "hash_struct",
451
+ "compute_domain_separator",
452
+ # Level 0 API
453
+ "ServiceDirectory",
454
+ "ServiceEntry",
455
+ "ServiceQuery",
456
+ "Provider",
457
+ "ProviderConfig",
458
+ "ProviderStatus",
459
+ "provide",
460
+ "ProvideOptions",
461
+ "request",
462
+ "RequestOptions",
463
+ "RequestResult",
464
+ # Level 1 API
465
+ "Agent",
466
+ "AgentConfig",
467
+ "AgentBehavior",
468
+ "AgentStatus",
469
+ "AgentStats",
470
+ "AgentBalance",
471
+ "Job",
472
+ "JobContext",
473
+ "JobHandler",
474
+ "JobResult",
475
+ "ServiceConfig",
476
+ "ServiceFilter",
477
+ "RetryConfig",
478
+ "PricingStrategy",
479
+ "CostModel",
480
+ "PriceCalculation",
481
+ "calculate_price",
482
+ # Types
483
+ "AgentDID",
484
+ "DIDDocument",
485
+ "Transaction",
486
+ "TransactionState",
487
+ "TransactionReceipt",
488
+ "TransactionFilter",
489
+ "EIP712Domain",
490
+ "ServiceRequest",
491
+ "ServiceResponse",
492
+ "DeliveryProof",
493
+ "DeliveryProofMessage",
494
+ "DeliveryProofMetadata",
495
+ "SignedMessage",
496
+ "TypedData",
497
+ "compute_result_hash",
498
+ # Protocol Layer (PARITY with TS SDK)
499
+ "MessageSigner",
500
+ "SignatureComponents",
501
+ "hash_typed_data",
502
+ "create_typed_data",
503
+ "HAS_MESSAGES",
504
+ "ProofGenerator",
505
+ "ContentProof",
506
+ "MerkleProof",
507
+ "verify_merkle_proof",
508
+ "hash_service_input",
509
+ "hash_service_output",
510
+ "DIDManager",
511
+ "DIDResolver",
512
+ "VerificationMethod",
513
+ "ServiceEndpoint",
514
+ "create_did_from_address",
515
+ "did_to_address",
516
+ # Protocol (web3 required)
517
+ "HAS_WEB3_PROTOCOL",
518
+ "ACTPKernel",
519
+ "TransactionView",
520
+ "EscrowVault",
521
+ "CreateEscrowParams",
522
+ "EscrowInfo",
523
+ "generate_escrow_id",
524
+ "EventMonitor",
525
+ "EventFilter",
526
+ "EventType",
527
+ "ACTPEvent",
528
+ "TransactionCreatedEvent",
529
+ "StateTransitionedEvent",
530
+ "EscrowCreatedEvent",
531
+ "EscrowPayoutEvent",
532
+ "NonceManager",
533
+ "NonceManagerPool",
534
+ "EASHelper",
535
+ "Attestation",
536
+ "DeliveryAttestationData",
537
+ "Schema",
538
+ "DELIVERY_SCHEMA",
539
+ "ZERO_BYTES32",
540
+ "AgentRegistry",
541
+ "AgentProfile",
542
+ "ServiceDescriptor",
543
+ "compute_service_type_hash",
544
+ # Builders
545
+ "DeliveryProofBuilder",
546
+ "QuoteBuilder",
547
+ ]