hippius 0.1.6__py3-none-any.whl → 0.1.9__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_sdk/client.py CHANGED
@@ -3,9 +3,13 @@ Main client for the Hippius SDK.
3
3
  """
4
4
 
5
5
  import os
6
- from typing import Dict, Any, Optional, List, Union
6
+ from typing import Dict, Any, Optional, List, Union, Tuple, Set
7
7
  from hippius_sdk.ipfs import IPFSClient
8
8
  from hippius_sdk.substrate import SubstrateClient, FileInput
9
+ from hippius_sdk.config import (
10
+ get_config_value,
11
+ get_encryption_key,
12
+ )
9
13
 
10
14
 
11
15
  class HippiusClient:
@@ -17,10 +21,12 @@ class HippiusClient:
17
21
 
18
22
  def __init__(
19
23
  self,
20
- ipfs_gateway: str = "https://ipfs.io",
21
- ipfs_api_url: str = "https://relay-fr.hippius.network",
22
- substrate_url: str = None,
23
- substrate_seed_phrase: str = None,
24
+ ipfs_gateway: Optional[str] = None,
25
+ ipfs_api_url: Optional[str] = None,
26
+ substrate_url: Optional[str] = None,
27
+ substrate_seed_phrase: Optional[str] = None,
28
+ seed_phrase_password: Optional[str] = None,
29
+ account_name: Optional[str] = None,
24
30
  encrypt_by_default: Optional[bool] = None,
25
31
  encryption_key: Optional[bytes] = None,
26
32
  ):
@@ -28,13 +34,45 @@ class HippiusClient:
28
34
  Initialize the Hippius client.
29
35
 
30
36
  Args:
31
- ipfs_gateway: IPFS gateway URL for downloading content
32
- ipfs_api_url: IPFS API URL for uploading content. Defaults to Hippius relay node.
33
- substrate_url: WebSocket URL of the Hippius substrate node
34
- substrate_seed_phrase: Seed phrase for Substrate account
35
- encrypt_by_default: Whether to encrypt files by default (from .env if None)
36
- encryption_key: Encryption key for NaCl secretbox (from .env if None)
37
+ ipfs_gateway: IPFS gateway URL for downloading content (from config if None)
38
+ ipfs_api_url: IPFS API URL for uploading content (from config if None)
39
+ substrate_url: WebSocket URL of the Hippius substrate node (from config if None)
40
+ substrate_seed_phrase: Seed phrase for Substrate account (from config if None)
41
+ seed_phrase_password: Password to decrypt the seed phrase if it's encrypted
42
+ account_name: Name of the account to use (uses active account if None)
43
+ encrypt_by_default: Whether to encrypt files by default (from config if None)
44
+ encryption_key: Encryption key for NaCl secretbox (from config if None)
37
45
  """
46
+ # Load configuration values if not explicitly provided
47
+ if ipfs_gateway is None:
48
+ ipfs_gateway = get_config_value("ipfs", "gateway", "https://ipfs.io")
49
+
50
+ if ipfs_api_url is None:
51
+ ipfs_api_url = get_config_value(
52
+ "ipfs", "api_url", "https://store.hippius.network"
53
+ )
54
+
55
+ # Check if local IPFS is enabled in config
56
+ if get_config_value("ipfs", "local_ipfs", False):
57
+ ipfs_api_url = "http://localhost:5001"
58
+
59
+ if substrate_url is None:
60
+ substrate_url = get_config_value(
61
+ "substrate", "url", "wss://rpc.hippius.network"
62
+ )
63
+
64
+ if substrate_seed_phrase is None:
65
+ substrate_seed_phrase = get_config_value("substrate", "seed_phrase")
66
+
67
+ if encrypt_by_default is None:
68
+ encrypt_by_default = get_config_value(
69
+ "encryption", "encrypt_by_default", False
70
+ )
71
+
72
+ if encryption_key is None:
73
+ encryption_key = get_encryption_key()
74
+
75
+ # Initialize IPFS client
38
76
  self.ipfs_client = IPFSClient(
39
77
  gateway=ipfs_gateway,
40
78
  api_url=ipfs_api_url,
@@ -45,7 +83,10 @@ class HippiusClient:
45
83
  # Initialize Substrate client
46
84
  try:
47
85
  self.substrate_client = SubstrateClient(
48
- url=substrate_url, seed_phrase=substrate_seed_phrase
86
+ url=substrate_url,
87
+ seed_phrase=substrate_seed_phrase,
88
+ password=seed_phrase_password,
89
+ account_name=account_name,
49
90
  )
50
91
  except Exception as e:
51
92
  print(f"Warning: Could not initialize Substrate client: {e}")