Skip to content

Commit bc7bc03

Browse files
authored
Merge pull request #553 from singnet/development
Release 3.1.1
2 parents b5831d8 + e9b4fe6 commit bc7bc03

File tree

4 files changed

+32
-29
lines changed

4 files changed

+32
-29
lines changed

pyproject.toml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ build-backend = "setuptools.build_meta"
99

1010
[project]
1111
name = "snet-cli"
12-
version = "3.1.0"
12+
version = "3.1.1"
1313
description = "SingularityNET CLI"
1414
readme = "README.md"
1515
requires-python = ">=3.10"
16-
license = {text = "MIT"}
16+
license = "MIT"
1717
authors = [
1818
{name = "SingularityNET Foundation", email = "info@singularitynet.io"}
1919
]
@@ -30,8 +30,7 @@ dependencies = [
3030
"mnemonic==0.21",
3131
"pyyaml~=6.0.1",
3232
"ipfshttpclient==0.4.13.2",
33-
"pymultihash==0.8.2",
34-
"base58==2.1.1",
33+
"py-multihash~=3.0",
3534
"argcomplete~=3.1",
3635
"grpcio-health-checking~=1.59",
3736
"jsonschema~=4.1",

requirements.txt

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,12 @@ protobuf~=6.30
22
grpcio~=1.59
33
grpcio-tools~=1.59
44
wheel~=0.45
5-
# jsonrpcclient~=4.0
6-
# eth-hash~=0.5
75
rlp~=4.0
8-
# eth-rlp~=2.0
96
web3~=7.0
107
mnemonic==0.21
11-
# pycoin==0.92.20241201
128
pyyaml~=6.0.1
139
ipfshttpclient==0.4.13.2
14-
pymultihash==0.8.2
15-
base58==2.1.1
10+
py-multihash~=3.0
1611
argcomplete~=3.1
1712
grpcio-health-checking~=1.59
1813
jsonschema~=4.1

setup.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
import os
21
from pathlib import Path
32
from setuptools import setup
43
from setuptools.command.develop import develop as _develop
54
from setuptools.command.install import install as _install
65
from setuptools.command.build_py import build_py as _build_py
76
from grpc_tools import protoc
8-
from pkg_resources import resource_filename
7+
import importlib.resources
8+
99

1010
def install_and_compile_proto():
1111
"""
@@ -14,8 +14,7 @@ def install_and_compile_proto():
1414
proto_dir = Path(__file__).absolute().parent.joinpath(
1515
"snet", "cli", "resources", "proto")
1616

17-
# Locate the standard grpc_tools internal protos (google/protobuf/...)
18-
grpc_protos_include = resource_filename('grpc_tools', '_proto')
17+
grpc_protos_include = str(importlib.resources.files('grpc_tools').joinpath('_proto'))
1918

2019
print(f"Proto directory: {proto_dir}")
2120
print(f"Grpc include directory: {grpc_protos_include}")
@@ -31,7 +30,7 @@ def install_and_compile_proto():
3130
command = [
3231
'grpc_tools.protoc',
3332
f'-I{proto_dir}',
34-
f'-I{grpc_protos_include}', # <--- CRITICAL FIX: Add standard protos to include path
33+
f'-I{grpc_protos_include}',
3534
f'--python_out={proto_dir}',
3635
f'--grpc_python_out={proto_dir}',
3736
str(fn)
@@ -41,27 +40,30 @@ def install_and_compile_proto():
4140
print(f"Error: Failed to compile {fn}")
4241
raise RuntimeError(f"Protocol buffer compilation failed for {fn}")
4342

43+
4444
class build_py(_build_py):
4545
"""
46-
Override build_py to compile protos before building the wheel.
4746
This is the hook used by 'python -m build'.
4847
"""
4948
def run(self):
5049
self.execute(install_and_compile_proto, (), msg="Compile protocol buffers")
5150
_build_py.run(self)
5251

52+
5353
class develop(_develop):
5454
"""Post-installation for development mode (pip install -e .)."""
5555
def run(self):
5656
self.execute(install_and_compile_proto, (), msg="Compile protocol buffers")
5757
_develop.run(self)
5858

59+
5960
class install(_install):
6061
"""Post-installation for legacy installation mode."""
6162
def run(self):
6263
self.execute(install_and_compile_proto, (), msg="Compile protocol buffers")
6364
_install.run(self)
6465

66+
6567
setup(
6668
cmdclass={
6769
'develop': develop,

snet/cli/utils/ipfs_utils.py

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import io
55
import os
66

7-
import base58
87
import multihash
8+
import hashlib
99

1010

1111
def publish_file_in_ipfs(ipfs_client, filepath, wrap_with_directory=True):
@@ -96,26 +96,33 @@ def publish_proto_in_filecoin(filecoin_client, protodir):
9696

9797
def get_from_ipfs_and_checkhash(ipfs_client, ipfs_hash_base58, validate=True):
9898
"""
99-
Get file from IPFS. If validate is True, verify the integrity of the file using its hash.
99+
Get file from IPFS and validate hash
100100
"""
101-
102101
data = ipfs_client.cat(ipfs_hash_base58)
103102

104103
if validate:
105104
block_data = ipfs_client.block.get(ipfs_hash_base58)
106105

107-
# print(f"IPFS hash (Base58): {ipfs_hash_base58}")
108-
# print(f"Block data length: {len(block_data)}")
109-
110-
# Decode Base58 bash to multihash
111106
try:
112-
decoded_hash_bytes = base58.b58decode(ipfs_hash_base58)
113-
mh = multihash.decode(decoded_hash_bytes)
114-
except Exception as e:
115-
raise ValueError(f"Invalid multihash for IPFS hash: {ipfs_hash_base58}. Error: {str(e)}") from e
107+
mh_bytes = multihash.from_b58_string(ipfs_hash_base58)
108+
decoded = multihash.decode(mh_bytes)
109+
110+
hash_func_name = decoded.name
111+
expected_digest = decoded.digest
116112

117-
if not mh.verify(block_data): # Correctly using mh instance for verification
118-
raise Exception("IPFS hash mismatch with data")
113+
if hash_func_name == 'sha2-256': # Standard for IPFS (CIDv0)
114+
actual_digest = hashlib.sha256(block_data).digest()
115+
else:
116+
# Handle other algorithms supported by hashlib if necessary
117+
h = hashlib.new(hash_func_name.replace('-', ''))
118+
h.update(block_data)
119+
actual_digest = h.digest()
120+
121+
if actual_digest != expected_digest:
122+
raise Exception("IPFS hash mismatch with data")
123+
124+
except Exception as e:
125+
raise ValueError(f"Integrity check failed: {str(e)}") from e
119126

120127
return data
121128

0 commit comments

Comments
 (0)