activeledger 1.3.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.
@@ -0,0 +1,93 @@
1
+ """Python SDK for Activeledger, with post-quantum identity support.
2
+
3
+ The core is stdlib-only. Post-quantum keys need the optional extra::
4
+
5
+ pip install 'activeledger-sdk[pq]'
6
+
7
+ Everything else -- canonical JSON, transaction building, submission and event
8
+ subscription -- works with no compiled dependency at all, so an application
9
+ that signs elsewhere (an HSM, a remote service, a user's wallet) never needs a
10
+ C toolchain.
11
+
12
+ from activeledger import Activeledger, KeyPair, KeyType
13
+
14
+ ledger = Activeledger("http://localhost:5260")
15
+ identity = ledger.onboard(KeyPair.generate(KeyType.ML_DSA_65))
16
+ """
17
+
18
+ from .canonical import canonical_bytes, canonical_json
19
+ from .connection import Connection, Identity, LedgerResponse
20
+ from .events import EventStream, LedgerEvent
21
+ from . import recovery
22
+ from .keys import KeyType, Signer
23
+ from .transaction import Transaction, TransactionBuilder, onboard_transaction
24
+
25
+ __all__ = [
26
+ "Activeledger",
27
+ "Connection",
28
+ "EventStream",
29
+ "Identity",
30
+ "KeyType",
31
+ "LedgerEvent",
32
+ "LedgerResponse",
33
+ "Signer",
34
+ "Transaction",
35
+ "TransactionBuilder",
36
+ "canonical_bytes",
37
+ "canonical_json",
38
+ "onboard_transaction",
39
+ "KeyPair",
40
+ "PostQuantumUnavailable",
41
+ "Secp256k1KeyPair",
42
+ "recovery",
43
+ ]
44
+
45
+ __version__ = "1.3.0"
46
+
47
+
48
+ class Activeledger:
49
+ """Entry point.
50
+
51
+ There is deliberately no storage endpoint here. A node's storage service
52
+ listens only on the node's own host, so it is not something a client can
53
+ reach. State is read through a transaction: name streams in ``$r`` with
54
+ :meth:`TransactionBuilder.readonly` and have the contract return values
55
+ with ``returnToRemote``, which arrive in ``LedgerResponse.responses``.
56
+ """
57
+
58
+ def __init__(self, base_url: str, timeout: float = 30.0) -> None:
59
+ self.connection = Connection(base_url, timeout=timeout)
60
+ self.events = EventStream(base_url)
61
+
62
+ def onboard(self, signer, label: str = "identity") -> Identity:
63
+ return self.connection.onboard(signer, label)
64
+
65
+ def submit(self, transaction: Transaction) -> LedgerResponse:
66
+ return self.connection.submit(transaction)
67
+
68
+ @staticmethod
69
+ def transaction() -> TransactionBuilder:
70
+ return TransactionBuilder()
71
+
72
+
73
+ def __getattr__(name):
74
+ """Expose KeyPair lazily so importing this package never needs liboqs.
75
+
76
+ `from activeledger import KeyPair` works whether or not the [pq] extra is
77
+ installed; it is only actually using one that raises, and with a message
78
+ naming the extra rather than a CMake traceback.
79
+ """
80
+ if name in ("KeyPair", "PostQuantumUnavailable"):
81
+ from . import pq
82
+
83
+ return getattr(pq, name)
84
+
85
+ # Same reasoning for secp256k1: importing this package must not require
86
+ # the [ec] extra either, and a caller who never touches secp256k1 should
87
+ # never be asked to install python-ecdsa.
88
+ if name == "Secp256k1KeyPair":
89
+ from . import ec
90
+
91
+ return ec.Secp256k1KeyPair
92
+
93
+ raise AttributeError(f"module {__name__!r} has no attribute {name!r}")