hippius 0.2.38__tar.gz → 0.2.39__tar.gz
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.38 → hippius-0.2.39}/PKG-INFO +1 -1
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/__init__.py +2 -3
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/ipfs.py +28 -38
- {hippius-0.2.38 → hippius-0.2.39}/pyproject.toml +1 -1
- {hippius-0.2.38 → hippius-0.2.39}/README.md +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/cli.py +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/cli_assets.py +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/cli_handlers.py +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/cli_parser.py +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/cli_rich.py +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/client.py +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/config.py +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/db/README.md +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/db/env.db.template +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/db/migrations/20241201000001_create_key_storage_tables.sql +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/db/migrations/20241202000001_switch_to_subaccount_encryption.sql +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/db/setup_database.sh +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/db_utils.py +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/errors.py +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/ipfs_core.py +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/key_storage.py +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/substrate.py +0 -0
- {hippius-0.2.38 → hippius-0.2.39}/hippius_sdk/utils.py +0 -0
@@ -23,15 +23,14 @@ from hippius_sdk.config import (
|
|
23
23
|
set_encryption_key,
|
24
24
|
set_seed_phrase,
|
25
25
|
)
|
26
|
-
from hippius_sdk.ipfs import IPFSClient, S3PublishResult,
|
26
|
+
from hippius_sdk.ipfs import IPFSClient, S3PublishResult, S3DownloadResult
|
27
27
|
from hippius_sdk.utils import format_cid, format_size, hex_to_ipfs_cid
|
28
28
|
|
29
|
-
__version__ = "0.2.
|
29
|
+
__version__ = "0.2.39"
|
30
30
|
__all__ = [
|
31
31
|
"HippiusClient",
|
32
32
|
"IPFSClient",
|
33
33
|
"S3PublishResult",
|
34
|
-
"S3PublishPin",
|
35
34
|
"S3DownloadResult",
|
36
35
|
"get_config_value",
|
37
36
|
"set_config_value",
|
@@ -2203,7 +2203,7 @@ class IPFSClient:
|
|
2203
2203
|
"""
|
2204
2204
|
start_time = time.time()
|
2205
2205
|
|
2206
|
-
# Download the file directly from the specified download_node
|
2206
|
+
# Download the file directly into memory from the specified download_node
|
2207
2207
|
try:
|
2208
2208
|
# Create parent directories if they don't exist
|
2209
2209
|
os.makedirs(os.path.dirname(os.path.abspath(output_path)), exist_ok=True)
|
@@ -2211,41 +2211,29 @@ class IPFSClient:
|
|
2211
2211
|
download_client = AsyncIPFSClient(api_url=download_node)
|
2212
2212
|
|
2213
2213
|
download_url = f"{download_node.rstrip('/')}/api/v0/cat?arg={cid}"
|
2214
|
+
|
2215
|
+
# Download file into memory
|
2216
|
+
file_data = bytearray()
|
2214
2217
|
async with download_client.client.stream("POST", download_url) as response:
|
2215
2218
|
response.raise_for_status()
|
2219
|
+
async for chunk in response.aiter_bytes(chunk_size=8192):
|
2220
|
+
file_data.extend(chunk)
|
2216
2221
|
|
2217
|
-
|
2218
|
-
|
2219
|
-
|
2220
|
-
|
2221
|
-
logger.info(f"File downloaded from {download_node} with CID: {cid}")
|
2222
|
+
# Convert to bytes for consistency
|
2223
|
+
file_data = bytes(file_data)
|
2224
|
+
logger.info(f"File downloaded from {download_node} with CID: {cid} ({len(file_data)} bytes)")
|
2222
2225
|
|
2223
2226
|
except Exception as e:
|
2224
2227
|
raise HippiusIPFSError(
|
2225
2228
|
f"Failed to download file from {download_node}: {str(e)}"
|
2226
2229
|
)
|
2227
2230
|
|
2228
|
-
# Get file info after download
|
2229
|
-
size_bytes = os.path.getsize(output_path)
|
2230
|
-
elapsed_time = time.time() - start_time
|
2231
|
-
|
2232
2231
|
# Attempt automatic decryption if requested
|
2233
2232
|
decrypted = False
|
2234
2233
|
encryption_key_used = None
|
2234
|
+
final_data = file_data # This will hold either encrypted or decrypted data
|
2235
2235
|
|
2236
2236
|
if auto_decrypt:
|
2237
|
-
# Check if key storage is enabled and available
|
2238
|
-
try:
|
2239
|
-
key_storage_available = is_key_storage_enabled()
|
2240
|
-
logger.debug(f"Key storage enabled: {key_storage_available}")
|
2241
|
-
except ImportError:
|
2242
|
-
logger.debug("Key storage module not available")
|
2243
|
-
key_storage_available = False
|
2244
|
-
|
2245
|
-
# Read the downloaded file content
|
2246
|
-
with open(output_path, "rb") as f:
|
2247
|
-
file_data = f.read()
|
2248
|
-
|
2249
2237
|
# Check if file is empty - this indicates a problem
|
2250
2238
|
if len(file_data) == 0:
|
2251
2239
|
logger.error(f"Downloaded file is empty (0 bytes) for CID: {cid}")
|
@@ -2263,6 +2251,14 @@ class IPFSClient:
|
|
2263
2251
|
decrypted = False
|
2264
2252
|
encryption_key_used = None
|
2265
2253
|
else:
|
2254
|
+
# Check if key storage is enabled and available
|
2255
|
+
try:
|
2256
|
+
key_storage_available = is_key_storage_enabled()
|
2257
|
+
logger.debug(f"Key storage enabled: {key_storage_available}")
|
2258
|
+
except ImportError:
|
2259
|
+
logger.debug("Key storage module not available")
|
2260
|
+
key_storage_available = False
|
2261
|
+
|
2266
2262
|
# File has content, attempt decryption if requested
|
2267
2263
|
decryption_attempted = False
|
2268
2264
|
decryption_successful = False
|
@@ -2292,17 +2288,10 @@ class IPFSClient:
|
|
2292
2288
|
existing_key_b64
|
2293
2289
|
)
|
2294
2290
|
box = nacl.secret.SecretBox(encryption_key_bytes)
|
2295
|
-
|
2296
|
-
|
2297
|
-
# Write the decrypted data back to the file
|
2298
|
-
with open(output_path, "wb") as f:
|
2299
|
-
f.write(decrypted_data)
|
2291
|
+
final_data = box.decrypt(file_data)
|
2300
2292
|
|
2301
2293
|
decryption_successful = True
|
2302
2294
|
decrypted = True
|
2303
|
-
size_bytes = len(
|
2304
|
-
decrypted_data
|
2305
|
-
) # Update size to decrypted size
|
2306
2295
|
logger.info(
|
2307
2296
|
"Successfully decrypted file using stored key"
|
2308
2297
|
)
|
@@ -2326,17 +2315,10 @@ class IPFSClient:
|
|
2326
2315
|
decryption_attempted = True
|
2327
2316
|
|
2328
2317
|
try:
|
2329
|
-
|
2330
|
-
|
2331
|
-
# Write the decrypted data back to the file
|
2332
|
-
with open(output_path, "wb") as f:
|
2333
|
-
f.write(decrypted_data)
|
2318
|
+
final_data = self.decrypt_data(file_data)
|
2334
2319
|
|
2335
2320
|
decryption_successful = True
|
2336
2321
|
decrypted = True
|
2337
|
-
size_bytes = len(
|
2338
|
-
decrypted_data
|
2339
|
-
) # Update size to decrypted size
|
2340
2322
|
|
2341
2323
|
# Store the encryption key for the result
|
2342
2324
|
encryption_key_used = (
|
@@ -2361,6 +2343,14 @@ class IPFSClient:
|
|
2361
2343
|
elif not decryption_attempted:
|
2362
2344
|
logger.debug("No decryption attempted - no keys available")
|
2363
2345
|
|
2346
|
+
# Write the final data (encrypted or decrypted) to disk once
|
2347
|
+
with open(output_path, "wb") as f:
|
2348
|
+
f.write(final_data)
|
2349
|
+
|
2350
|
+
# Get final file info
|
2351
|
+
size_bytes = len(final_data)
|
2352
|
+
elapsed_time = time.time() - start_time
|
2353
|
+
|
2364
2354
|
return S3DownloadResult(
|
2365
2355
|
cid=cid,
|
2366
2356
|
output_path=output_path,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|