hippius 0.2.2__tar.gz → 0.2.3__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: hippius
3
- Version: 0.2.2
3
+ Version: 0.2.3
4
4
  Summary: Python SDK and CLI for Hippius blockchain storage
5
5
  Home-page: https://github.com/thenervelab/hippius-sdk
6
6
  Author: Dubs
@@ -24,6 +24,7 @@ Requires-Dist: pynacl (>=1.5.0,<2.0.0)
24
24
  Requires-Dist: pyperclip (>=1.8.2,<2.0.0) ; extra == "clipboard"
25
25
  Requires-Dist: python-dotenv (>=1.0.0,<2.0.0)
26
26
  Requires-Dist: requests (>=2.28.1,<3.0.0)
27
+ Requires-Dist: rich (>=14.0.0,<15.0.0)
27
28
  Requires-Dist: substrate-interface (>=1.4.2,<2.0.0)
28
29
  Requires-Dist: zfec (>=1.5.3,<2.0.0)
29
30
  Project-URL: Documentation, https://github.com/thenervelab/hippius-sdk/docs
@@ -67,7 +68,7 @@ client = HippiusClient()
67
68
 
68
69
  # Or specify custom endpoints
69
70
  client = HippiusClient(
70
- ipfs_gateway="https://ipfs.io", # For downloads (default)
71
+ ipfs_gateway="https://get.hippius.network", # For downloads (default)
71
72
  ipfs_api_url="https://store.hippius.network", # For uploads (default)
72
73
  )
73
74
 
@@ -428,7 +429,7 @@ The Hippius SDK includes a powerful command-line interface (CLI) that provides a
428
429
  hippius --help
429
430
 
430
431
  # Set global options
431
- hippius --gateway https://ipfs.io --api-url https://store.hippius.network --verbose
432
+ hippius --gateway https://get.hippius.network --api-url https://store.hippius.network --verbose
432
433
  ```
433
434
 
434
435
  ### IPFS Operations
@@ -520,7 +521,7 @@ The `ec-files` command has been optimized for performance and can now handle lar
520
521
  The CLI automatically reads from your `.env` file for common settings:
521
522
 
522
523
  ```
523
- IPFS_GATEWAY=https://ipfs.io
524
+ IPFS_GATEWAY=https://get.hippius.network
524
525
  IPFS_API_URL=https://store.hippius.network
525
526
  SUBSTRATE_URL=wss://rpc.hippius.network
526
527
  SUBSTRATE_SEED_PHRASE="your twelve word seed phrase..."
@@ -541,7 +542,7 @@ ipfs_client = IPFSClient()
541
542
 
542
543
  # Or specify custom endpoints
543
544
  ipfs_client = IPFSClient(
544
- gateway="https://ipfs.io", # For downloads
545
+ gateway="https://get.hippius.network", # For downloads
545
546
  api_url="http://relay-fr.hippius.network:5001" # For uploads
546
547
  )
547
548
 
@@ -611,7 +612,7 @@ hippius config list
611
612
  hippius config get ipfs gateway
612
613
 
613
614
  # Set a configuration value
614
- hippius config set ipfs gateway https://ipfs.io
615
+ hippius config set ipfs gateway https://get.hippius.network
615
616
 
616
617
  # Import settings from your .env file
617
618
  hippius config import-env
@@ -627,7 +628,7 @@ The configuration is organized in the following sections:
627
628
  ```json
628
629
  {
629
630
  "ipfs": {
630
- "gateway": "https://ipfs.io",
631
+ "gateway": "https://get.hippius.network",
631
632
  "api_url": "https://store.hippius.network",
632
633
  "local_ipfs": false
633
634
  },
@@ -35,7 +35,7 @@ client = HippiusClient()
35
35
 
36
36
  # Or specify custom endpoints
37
37
  client = HippiusClient(
38
- ipfs_gateway="https://ipfs.io", # For downloads (default)
38
+ ipfs_gateway="https://get.hippius.network", # For downloads (default)
39
39
  ipfs_api_url="https://store.hippius.network", # For uploads (default)
40
40
  )
41
41
 
@@ -396,7 +396,7 @@ The Hippius SDK includes a powerful command-line interface (CLI) that provides a
396
396
  hippius --help
397
397
 
398
398
  # Set global options
399
- hippius --gateway https://ipfs.io --api-url https://store.hippius.network --verbose
399
+ hippius --gateway https://get.hippius.network --api-url https://store.hippius.network --verbose
400
400
  ```
401
401
 
402
402
  ### IPFS Operations
@@ -488,7 +488,7 @@ The `ec-files` command has been optimized for performance and can now handle lar
488
488
  The CLI automatically reads from your `.env` file for common settings:
489
489
 
490
490
  ```
491
- IPFS_GATEWAY=https://ipfs.io
491
+ IPFS_GATEWAY=https://get.hippius.network
492
492
  IPFS_API_URL=https://store.hippius.network
493
493
  SUBSTRATE_URL=wss://rpc.hippius.network
494
494
  SUBSTRATE_SEED_PHRASE="your twelve word seed phrase..."
@@ -509,7 +509,7 @@ ipfs_client = IPFSClient()
509
509
 
510
510
  # Or specify custom endpoints
511
511
  ipfs_client = IPFSClient(
512
- gateway="https://ipfs.io", # For downloads
512
+ gateway="https://get.hippius.network", # For downloads
513
513
  api_url="http://relay-fr.hippius.network:5001" # For uploads
514
514
  )
515
515
 
@@ -579,7 +579,7 @@ hippius config list
579
579
  hippius config get ipfs gateway
580
580
 
581
581
  # Set a configuration value
582
- hippius config set ipfs gateway https://ipfs.io
582
+ hippius config set ipfs gateway https://get.hippius.network
583
583
 
584
584
  # Import settings from your .env file
585
585
  hippius config import-env
@@ -595,7 +595,7 @@ The configuration is organized in the following sections:
595
595
  ```json
596
596
  {
597
597
  "ipfs": {
598
- "gateway": "https://ipfs.io",
598
+ "gateway": "https://get.hippius.network",
599
599
  "api_url": "https://store.hippius.network",
600
600
  "local_ipfs": false
601
601
  },
@@ -26,7 +26,7 @@ from hippius_sdk.config import (
26
26
  from hippius_sdk.ipfs import IPFSClient
27
27
  from hippius_sdk.utils import format_cid, format_size, hex_to_ipfs_cid
28
28
 
29
- __version__ = "0.2.2"
29
+ __version__ = "0.2.3"
30
30
  __all__ = [
31
31
  "HippiusClient",
32
32
  "IPFSClient",
@@ -0,0 +1,449 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ Command Line Interface tools for Hippius SDK.
4
+
5
+ This module provides CLI tools for working with the Hippius SDK, including
6
+ utilities for encryption key generation, file operations, and marketplace interactions.
7
+ """
8
+
9
+ import asyncio
10
+ import inspect
11
+ import os
12
+ import sys
13
+ from typing import Callable
14
+
15
+ from dotenv import load_dotenv
16
+
17
+ from hippius_sdk import cli_handlers, initialize_from_env
18
+ from hippius_sdk.cli_assets import HERO_TITLE
19
+ from hippius_sdk.cli_parser import create_parser, get_subparser, parse_arguments
20
+ from hippius_sdk.cli_rich import console, error
21
+ from hippius_sdk.utils import generate_key
22
+
23
+ # Import SDK components
24
+
25
+ load_dotenv()
26
+ initialize_from_env()
27
+
28
+
29
+ def generate_encryption_key(copy_to_clipboard=False):
30
+ """Generate an encryption key and display it to the user."""
31
+ # Generate the key
32
+ encoded_key = generate_key()
33
+
34
+ # Copy to clipboard if requested
35
+ if copy_to_clipboard:
36
+ try:
37
+ import pyperclip
38
+
39
+ pyperclip.copy(encoded_key)
40
+ console.print("[green]Key copied to clipboard![/green]")
41
+ except ImportError:
42
+ console.print(
43
+ "[yellow]Warning:[/yellow] Could not copy to clipboard. Install pyperclip with: [bold]pip install pyperclip[/bold]"
44
+ )
45
+
46
+ return encoded_key
47
+
48
+
49
+ def key_generation_cli():
50
+ """Standalone CLI tool for encryption key generation with Rich formatting."""
51
+ # Display the Hippius logo banner with Rich formatting
52
+ console.print(HERO_TITLE, style="bold cyan")
53
+ console.print("[bold]Encryption Key Generator[/bold]", style="blue")
54
+
55
+ try:
56
+ # Generate the key
57
+ encoded_key = generate_encryption_key(copy_to_clipboard=True)
58
+
59
+ # Display the key with Rich formatting
60
+ console.print("\n[bold green]Your encryption key:[/bold green]")
61
+ console.print(f"[yellow]{encoded_key}[/yellow]")
62
+ console.print("\n[dim]This key has been copied to your clipboard.[/dim]")
63
+ console.print("[bold blue]Usage instructions:[/bold blue]")
64
+ console.print("1. Store this key securely")
65
+ console.print("2. Use it to encrypt/decrypt files with the Hippius SDK")
66
+ console.print("3. [yellow]Never share this key with others[/yellow]")
67
+
68
+ return 0
69
+ except Exception as e:
70
+ console.print(f"[bold red]Error:[/bold red] {e}")
71
+ return 1
72
+
73
+
74
+ def main():
75
+ """Main CLI entry point for hippius command."""
76
+ # Parse arguments
77
+ args = parse_arguments()
78
+
79
+ if not args.command:
80
+ # Display the Hippius logo banner with Rich formatting
81
+ console.print(HERO_TITLE, style="bold cyan")
82
+
83
+ # Use Rich formatting for help text
84
+ from hippius_sdk.cli_rich import print_help_text
85
+
86
+ print_help_text(create_parser())
87
+
88
+ try:
89
+ # Parse miner IDs if provided
90
+ miner_ids = None
91
+ if args.miner_ids:
92
+ miner_ids = [miner.strip() for miner in args.miner_ids.split(",")]
93
+ elif os.getenv("SUBSTRATE_DEFAULT_MINERS"):
94
+ miner_ids = [
95
+ miner.strip()
96
+ for miner in os.getenv("SUBSTRATE_DEFAULT_MINERS").split(",")
97
+ ]
98
+
99
+ # Create client
100
+ client = cli_handlers.create_client(args)
101
+
102
+ # Helper function to handle async handlers
103
+ def run_async_handler(handler_func: Callable, *args, **kwargs) -> int:
104
+ # Check if the handler is async
105
+ if inspect.iscoroutinefunction(handler_func):
106
+ # Run the async handler in the event loop
107
+ return asyncio.run(handler_func(*args, **kwargs))
108
+ else:
109
+ # Run the handler directly
110
+ return handler_func(*args, **kwargs)
111
+
112
+ # Process encrypted flags for common parameters
113
+ encrypt = True if args.encrypt else (False if args.no_encrypt else None)
114
+ decrypt = True if args.decrypt else (False if args.no_decrypt else None)
115
+
116
+ # Handle commands with the helper function
117
+ if args.command == "download":
118
+ return run_async_handler(
119
+ cli_handlers.handle_download,
120
+ client,
121
+ args.cid,
122
+ args.output_path,
123
+ decrypt=decrypt,
124
+ )
125
+
126
+ elif args.command == "exists":
127
+ return run_async_handler(cli_handlers.handle_exists, client, args.cid)
128
+
129
+ elif args.command == "cat":
130
+ return run_async_handler(
131
+ cli_handlers.handle_cat,
132
+ client,
133
+ args.cid,
134
+ args.max_size,
135
+ decrypt=decrypt,
136
+ )
137
+
138
+ elif args.command == "store":
139
+ return run_async_handler(
140
+ cli_handlers.handle_store,
141
+ client,
142
+ args.file_path,
143
+ miner_ids,
144
+ encrypt=encrypt,
145
+ )
146
+
147
+ elif args.command == "store-dir":
148
+ return run_async_handler(
149
+ cli_handlers.handle_store_dir,
150
+ client,
151
+ args.dir_path,
152
+ miner_ids,
153
+ encrypt=encrypt,
154
+ )
155
+
156
+ elif args.command == "credits":
157
+ return run_async_handler(
158
+ cli_handlers.handle_credits, client, args.account_address
159
+ )
160
+
161
+ elif args.command == "files":
162
+ return run_async_handler(
163
+ cli_handlers.handle_files,
164
+ client,
165
+ args.account_address if hasattr(args, "account_address") else None,
166
+ show_all_miners=(
167
+ args.all_miners if hasattr(args, "all_miners") else False
168
+ ),
169
+ file_cid=args.cid if hasattr(args, "cid") else None,
170
+ )
171
+
172
+ elif args.command == "pinning-status":
173
+ show_contents = (
174
+ not args.no_contents if hasattr(args, "no_contents") else True
175
+ )
176
+ return run_async_handler(
177
+ cli_handlers.handle_pinning_status,
178
+ client,
179
+ args.account_address if hasattr(args, "account_address") else None,
180
+ verbose=args.verbose,
181
+ show_contents=show_contents,
182
+ )
183
+
184
+ elif args.command == "ec-files":
185
+ return run_async_handler(
186
+ cli_handlers.handle_ec_files,
187
+ client,
188
+ args.account_address if hasattr(args, "account_address") else None,
189
+ show_all_miners=(
190
+ args.all_miners if hasattr(args, "all_miners") else False
191
+ ),
192
+ show_chunks=args.show_chunks if hasattr(args, "show_chunks") else False,
193
+ filter_metadata_cid=args.cid if hasattr(args, "cid") else None,
194
+ )
195
+
196
+ elif args.command == "erasure-code":
197
+ return run_async_handler(
198
+ cli_handlers.handle_erasure_code,
199
+ client,
200
+ args.file_path,
201
+ args.k,
202
+ args.m,
203
+ args.chunk_size,
204
+ miner_ids,
205
+ encrypt=args.encrypt if hasattr(args, "encrypt") else None,
206
+ publish=not args.no_publish if hasattr(args, "no_publish") else True,
207
+ verbose=args.verbose,
208
+ )
209
+
210
+ elif args.command == "reconstruct":
211
+ return run_async_handler(
212
+ cli_handlers.handle_reconstruct,
213
+ client,
214
+ args.metadata_cid,
215
+ args.output_file,
216
+ verbose=args.verbose,
217
+ )
218
+
219
+ elif args.command == "delete":
220
+ return run_async_handler(
221
+ cli_handlers.handle_delete,
222
+ client,
223
+ args.cid,
224
+ force=args.force if hasattr(args, "force") else False,
225
+ )
226
+
227
+ elif args.command == "ec-delete":
228
+ return run_async_handler(
229
+ cli_handlers.handle_ec_delete,
230
+ client,
231
+ args.metadata_cid,
232
+ force=args.force if hasattr(args, "force") else False,
233
+ )
234
+
235
+ elif args.command == "keygen":
236
+ # Generate and save an encryption key
237
+ copy_to_clipboard = args.copy if hasattr(args, "copy") else False
238
+ encryption_key = generate_encryption_key(
239
+ copy_to_clipboard=copy_to_clipboard
240
+ )
241
+
242
+ # Display the key with Rich formatting
243
+ console.print("\n[bold green]Your encryption key:[/bold green]")
244
+ console.print(f"[yellow]{encryption_key}[/yellow]")
245
+
246
+ if hasattr(args, "save") and args.save:
247
+ console.print(
248
+ "\n[bold]Saving encryption key to configuration...[/bold]"
249
+ )
250
+ cli_handlers.handle_config_set(
251
+ "encryption", "encryption_key", encryption_key
252
+ )
253
+ console.print(
254
+ "[green]Encryption key saved.[/green] Files will not be automatically encrypted unless you set [cyan]encryption.encrypt_by_default[/cyan] to [cyan]true[/cyan]"
255
+ )
256
+ return 0
257
+
258
+ elif args.command == "config":
259
+ if args.config_action == "get":
260
+ return cli_handlers.handle_config_get(args.section, args.key)
261
+ elif args.config_action == "set":
262
+ return cli_handlers.handle_config_set(
263
+ args.section, args.key, args.value
264
+ )
265
+ elif args.config_action == "list":
266
+ return cli_handlers.handle_config_list()
267
+ elif args.config_action == "reset":
268
+ return cli_handlers.handle_config_reset()
269
+ elif args.config_action == "import-env":
270
+ initialize_from_env()
271
+ print("Successfully imported configuration from environment variables")
272
+ return 0
273
+ else:
274
+ # Display the Hippius logo banner with Rich formatting
275
+ console.print(HERO_TITLE, style="bold cyan")
276
+
277
+ config_parser = get_subparser("config")
278
+ from hippius_sdk.cli_rich import print_help_text
279
+
280
+ print_help_text(config_parser)
281
+ return 1
282
+
283
+ elif args.command == "seed":
284
+ if args.seed_action == "set":
285
+ return cli_handlers.handle_seed_phrase_set(
286
+ args.seed_phrase,
287
+ args.encode if hasattr(args, "encode") else False,
288
+ args.account if hasattr(args, "account") else None,
289
+ )
290
+ elif args.seed_action == "encode":
291
+ return cli_handlers.handle_seed_phrase_encode(
292
+ args.account if hasattr(args, "account") else None
293
+ )
294
+ elif args.seed_action == "decode":
295
+ return cli_handlers.handle_seed_phrase_decode(
296
+ args.account if hasattr(args, "account") else None
297
+ )
298
+ elif args.seed_action == "status":
299
+ return cli_handlers.handle_seed_phrase_status(
300
+ args.account if hasattr(args, "account") else None
301
+ )
302
+ else:
303
+ # Display the Hippius logo banner with Rich formatting
304
+ console.print(HERO_TITLE, style="bold cyan")
305
+
306
+ seed_parser = get_subparser("seed")
307
+ from hippius_sdk.cli_rich import print_help_text
308
+
309
+ print_help_text(seed_parser)
310
+ return 1
311
+
312
+ # Handle the account commands
313
+ elif args.command == "account":
314
+ if args.account_action == "list":
315
+ return cli_handlers.handle_account_list()
316
+ elif args.account_action == "create" and hasattr(args, "name"):
317
+ return cli_handlers.handle_account_create(
318
+ client,
319
+ args.name,
320
+ encrypt=args.encrypt if hasattr(args, "encrypt") else False,
321
+ )
322
+ elif args.account_action == "export":
323
+ return cli_handlers.handle_account_export(
324
+ client,
325
+ args.name if hasattr(args, "name") else None,
326
+ args.file_path if hasattr(args, "file_path") else None,
327
+ )
328
+ elif args.account_action == "import" and hasattr(args, "file_path"):
329
+ return cli_handlers.handle_account_import(
330
+ client,
331
+ args.file_path,
332
+ encrypt=args.encrypt if hasattr(args, "encrypt") else False,
333
+ )
334
+ elif args.account_action == "switch" and hasattr(args, "account_name"):
335
+ return cli_handlers.handle_account_switch(args.account_name)
336
+ elif args.account_action == "delete" and hasattr(args, "account_name"):
337
+ return cli_handlers.handle_account_delete(args.account_name)
338
+ elif args.account_action == "balance":
339
+ # Get account address - prioritize direct address over account name
340
+ account_address = None
341
+ if hasattr(args, "address") and args.address:
342
+ # If address is directly provided, use it
343
+ account_address = args.address
344
+ elif hasattr(args, "name") and args.name:
345
+ # If name is provided, get the address from the account
346
+ try:
347
+ account_address = cli_handlers.get_account_address(args.name)
348
+ except Exception as e:
349
+ error(f"Error getting address for account '{args.name}': {e}")
350
+ return 1
351
+
352
+ return run_async_handler(
353
+ cli_handlers.handle_account_balance,
354
+ client,
355
+ account_address,
356
+ )
357
+ else:
358
+ # Display the Hippius logo banner with Rich formatting
359
+ console.print(HERO_TITLE, style="bold cyan")
360
+
361
+ account_parser = get_subparser("account")
362
+ from hippius_sdk.cli_rich import print_help_text
363
+
364
+ print_help_text(account_parser)
365
+ return 1
366
+
367
+ # Handle address commands
368
+ elif args.command == "address":
369
+ if args.address_action == "set-default" and hasattr(args, "address"):
370
+ return cli_handlers.handle_default_address_set(args.address)
371
+ elif args.address_action == "get-default":
372
+ return cli_handlers.handle_default_address_get()
373
+ elif args.address_action == "clear-default":
374
+ return cli_handlers.handle_default_address_clear()
375
+ else:
376
+ # Display the Hippius logo banner with Rich formatting
377
+ console.print(HERO_TITLE, style="bold cyan")
378
+
379
+ address_parser = get_subparser("address")
380
+ from hippius_sdk.cli_rich import print_help_text
381
+
382
+ print_help_text(address_parser)
383
+ return 1
384
+
385
+ else:
386
+ # Command not recognized
387
+ error(f"Unknown command: [bold]{args.command}[/bold]")
388
+ return 1
389
+
390
+ except KeyboardInterrupt:
391
+ error("\nOperation cancelled by user")
392
+ return 1
393
+ except Exception as e:
394
+ error(f"{str(e)}")
395
+ if args.verbose:
396
+ import traceback
397
+
398
+ console.print("\n[bold red]Traceback:[/bold red]")
399
+ traceback.print_exc()
400
+ return 1
401
+
402
+
403
+ def key_generation_cli():
404
+ """Standalone CLI tool for generating encryption keys."""
405
+ # Check if help flag is present
406
+ if "--help" in sys.argv or "-h" in sys.argv:
407
+ # Display the logo and help text with nice formatting
408
+ console.print(HERO_TITLE, style="bold cyan")
409
+
410
+ # Parse arguments
411
+ import argparse
412
+
413
+ parser = argparse.ArgumentParser(
414
+ description="Generate an encryption key for Hippius SDK"
415
+ )
416
+ parser.add_argument(
417
+ "--clipboard",
418
+ "-c",
419
+ action="store_true",
420
+ help="Copy the key to clipboard",
421
+ )
422
+ parser.add_argument(
423
+ "--save", "-s", action="store_true", help="Save the key to configuration"
424
+ )
425
+
426
+ args = parser.parse_args()
427
+
428
+ # Display encryption key generator title
429
+ console.print("[bold blue]Encryption Key Generator[/bold blue]\n")
430
+
431
+ # Generate and display the key
432
+ key = generate_encryption_key(copy_to_clipboard=args.clipboard)
433
+
434
+ # Display the key in a panel with formatting
435
+ console.print("\n[bold]Your encryption key:[/bold]")
436
+ console.print(f"[yellow]{key}[/yellow]", highlight=False)
437
+
438
+ # Save to config if requested
439
+ if args.save:
440
+ from hippius_sdk import cli_handlers
441
+
442
+ cli_handlers.handle_config_set("encryption", "encryption_key", key)
443
+ console.print(
444
+ "\n[green]Encryption key saved to configuration.[/green] Files will not be automatically encrypted unless you set [bold]encryption.encrypt_by_default[/bold] to [bold]true[/bold]."
445
+ )
446
+
447
+
448
+ if __name__ == "__main__":
449
+ sys.exit(main())
@@ -0,0 +1,8 @@
1
+ HERO_TITLE = """
2
+ ██╗ ██╗██╗██████╗ ██████╗ ██╗██╗ ██╗███████╗
3
+ ██║ ██║██║██╔══██╗██╔══██╗██║██║ ██║██╔════╝
4
+ ███████║██║██████╔╝██████╔╝██║██║ ██║███████╗
5
+ ██╔══██║██║██╔═══╝ ██╔═══╝ ██║██║ ██║╚════██║
6
+ ██║ ██║██║██║ ██║ ██║╚██████╔╝███████║
7
+ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝ ╚═╝ ╚═════╝ ╚══════╝
8
+ """