hippius 0.2.2__py3-none-any.whl → 0.2.3__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.
- {hippius-0.2.2.dist-info → hippius-0.2.3.dist-info}/METADATA +8 -7
- hippius-0.2.3.dist-info/RECORD +16 -0
- hippius_sdk/__init__.py +1 -1
- hippius_sdk/cli.py +277 -2628
- hippius_sdk/cli_assets.py +8 -0
- hippius_sdk/cli_handlers.py +2370 -0
- hippius_sdk/cli_parser.py +602 -0
- hippius_sdk/cli_rich.py +253 -0
- hippius_sdk/client.py +56 -8
- hippius_sdk/config.py +1 -1
- hippius_sdk/ipfs.py +372 -16
- hippius_sdk/ipfs_core.py +22 -1
- hippius_sdk/substrate.py +215 -525
- hippius_sdk/utils.py +84 -2
- hippius-0.2.2.dist-info/RECORD +0 -12
- {hippius-0.2.2.dist-info → hippius-0.2.3.dist-info}/WHEEL +0 -0
- {hippius-0.2.2.dist-info → hippius-0.2.3.dist-info}/entry_points.txt +0 -0
hippius_sdk/utils.py
CHANGED
@@ -4,8 +4,21 @@ Utility functions for the Hippius SDK.
|
|
4
4
|
This module provides common utility functions used across the SDK.
|
5
5
|
"""
|
6
6
|
|
7
|
-
import
|
8
|
-
|
7
|
+
import base64
|
8
|
+
import sys
|
9
|
+
from typing import Any, Optional, Tuple
|
10
|
+
|
11
|
+
# Import here to avoid circular imports when these functions are used from utils
|
12
|
+
from substrateinterface import SubstrateInterface
|
13
|
+
|
14
|
+
# Try importing PyNaCl for encryption functionality
|
15
|
+
try:
|
16
|
+
import nacl.secret
|
17
|
+
import nacl.utils
|
18
|
+
|
19
|
+
ENCRYPTION_AVAILABLE = True
|
20
|
+
except ImportError:
|
21
|
+
ENCRYPTION_AVAILABLE = False
|
9
22
|
|
10
23
|
|
11
24
|
def format_size(size_bytes: int) -> str:
|
@@ -150,3 +163,72 @@ def format_cid(cid: str) -> str:
|
|
150
163
|
str: Formatted CID string
|
151
164
|
"""
|
152
165
|
return hex_to_ipfs_cid(cid)
|
166
|
+
|
167
|
+
|
168
|
+
def generate_key() -> str:
|
169
|
+
"""
|
170
|
+
Generate a random encryption key for NaCl secretbox.
|
171
|
+
|
172
|
+
Returns:
|
173
|
+
str: A base64-encoded encryption key that can be used with the SDK's
|
174
|
+
encryption functions or stored in configuration.
|
175
|
+
|
176
|
+
Raises:
|
177
|
+
SystemExit: If PyNaCl is not installed
|
178
|
+
"""
|
179
|
+
if not ENCRYPTION_AVAILABLE:
|
180
|
+
print(
|
181
|
+
"Error: PyNaCl is required for encryption. Install it with: pip install pynacl"
|
182
|
+
)
|
183
|
+
sys.exit(1)
|
184
|
+
|
185
|
+
# Generate a random key
|
186
|
+
key = nacl.utils.random(nacl.secret.SecretBox.KEY_SIZE)
|
187
|
+
|
188
|
+
# Encode to base64 for storage and configuration
|
189
|
+
encoded_key = base64.b64encode(key).decode()
|
190
|
+
|
191
|
+
return encoded_key
|
192
|
+
|
193
|
+
|
194
|
+
def initialize_substrate_connection(
|
195
|
+
self_obj: Any,
|
196
|
+
) -> Tuple[SubstrateInterface, Optional[str]]:
|
197
|
+
"""
|
198
|
+
Initialize a Substrate connection if not already connected and set up the account.
|
199
|
+
This function handles initializing the substrate connection and determining the account address
|
200
|
+
to use in blockchain operations.
|
201
|
+
|
202
|
+
Args:
|
203
|
+
self_obj: The object (usually SubstrateClient instance) with required attributes
|
204
|
+
|
205
|
+
Returns:
|
206
|
+
Tuple[SubstrateInterface, Optional[str]]: A tuple containing the Substrate interface
|
207
|
+
object and the account address (or None if no address is available)
|
208
|
+
"""
|
209
|
+
# Initialize Substrate connection if not already connected
|
210
|
+
if not hasattr(self_obj, "_substrate") or self_obj._substrate is None:
|
211
|
+
print("Initializing Substrate connection...")
|
212
|
+
self_obj._substrate = SubstrateInterface(
|
213
|
+
url=self_obj.url,
|
214
|
+
ss58_format=42, # Substrate default
|
215
|
+
type_registry_preset="substrate-node-template",
|
216
|
+
)
|
217
|
+
print(f"Connected to Substrate node at {self_obj.url}")
|
218
|
+
|
219
|
+
# Use provided account address or default to keypair/configured address
|
220
|
+
account_address = None
|
221
|
+
if hasattr(self_obj, "_account_address") and self_obj._account_address:
|
222
|
+
account_address = self_obj._account_address
|
223
|
+
|
224
|
+
elif hasattr(self_obj, "_ensure_keypair") and callable(self_obj._ensure_keypair):
|
225
|
+
# Try to get the address from the keypair (requires seed phrase)
|
226
|
+
if not self_obj._ensure_keypair():
|
227
|
+
# No keypair available, so we'll return None for account_address
|
228
|
+
return self_obj._substrate, None
|
229
|
+
|
230
|
+
if hasattr(self_obj, "_keypair") and self_obj._keypair:
|
231
|
+
account_address = self_obj._keypair.ss58_address
|
232
|
+
print(f"Using keypair address: {account_address}")
|
233
|
+
|
234
|
+
return self_obj._substrate, account_address
|
hippius-0.2.2.dist-info/RECORD
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
hippius_sdk/__init__.py,sha256=jIwroAMjn-FSQ1lRnW95UhpLbGGronX4i-HEg7bGatA,1391
|
2
|
-
hippius_sdk/cli.py,sha256=kPcz1CWh2M4yiajTrYWtc6KZGE_WowLL6WBxY66w7aU,103906
|
3
|
-
hippius_sdk/client.py,sha256=mMKX_m2ZwfbGVAU3zasHZQF0ddToqypkxGKTylruB3Y,14901
|
4
|
-
hippius_sdk/config.py,sha256=WqocYwx-UomLeZ-iFUNDjg9vRcagOBA1Th68XELbuTs,22950
|
5
|
-
hippius_sdk/ipfs.py,sha256=WWSQuBe4Pqsp5WYavpTkMDk7OLgiHGl-CrPnv7LQlzA,56738
|
6
|
-
hippius_sdk/ipfs_core.py,sha256=w6ljgFdUzL-ffKxr4x_W-aYZTNpgyJg5HOFDrLKPILA,6690
|
7
|
-
hippius_sdk/substrate.py,sha256=9SkjIkMClkyE004H855C4t2VoJr6ypi87r6geBFEFeA,60091
|
8
|
-
hippius_sdk/utils.py,sha256=-N0w0RfXhwxJgSkSroxqFMw-0zJQXvcmxM0OS5UtWEY,4145
|
9
|
-
hippius-0.2.2.dist-info/METADATA,sha256=l6upZwM5i0zjMqxcuOwikusXMpvp_nIOkd-ImcMpwVA,28032
|
10
|
-
hippius-0.2.2.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
11
|
-
hippius-0.2.2.dist-info/entry_points.txt,sha256=b1lo60zRXmv1ud-c5BC-cJcAfGE5FD4qM_nia6XeQtM,98
|
12
|
-
hippius-0.2.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|