sidan-gin 0.1.1__tar.gz → 0.1.5__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.

Potentially problematic release.


This version of sidan-gin might be problematic. Click here for more details.

Files changed (52) hide show
  1. sidan_gin-0.1.5/PKG-INFO +63 -0
  2. sidan_gin-0.1.5/README.md +38 -0
  3. {sidan_gin-0.1.1 → sidan_gin-0.1.5}/pyproject.toml +3 -2
  4. sidan_gin-0.1.5/src/sidan_gin/__init__.py +5 -0
  5. sidan_gin-0.1.5/src/sidan_gin/encryption/__init__.py +3 -0
  6. sidan_gin-0.1.5/src/sidan_gin/encryption/cipher.py +127 -0
  7. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/.git +1 -0
  8. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/.gitignore +11 -0
  9. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/.vscode/settings.json +32 -0
  10. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/Cargo.lock +1914 -0
  11. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/Cargo.toml +14 -0
  12. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/README.md +2 -0
  13. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/__init__.py +1 -0
  14. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/build.rs +9 -0
  15. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/build.sh +9 -0
  16. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/src/CardanoSigner.py +70 -0
  17. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/src/_CardanoSigner.cpython-311-x86_64-linux-gnu.so +0 -0
  18. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/src/__init__.py +0 -0
  19. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/src/build/lib.linux-x86_64-cpython-311/_CardanoSigner.cpython-311-x86_64-linux-gnu.so +0 -0
  20. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/src/build/temp.linux-x86_64-cpython-311/signer.o +0 -0
  21. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/src/build/temp.linux-x86_64-cpython-311/signer_wrap.o +0 -0
  22. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/src/cxx.h +1149 -0
  23. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/src/lib.rs +57 -0
  24. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/src/lib.rs.h +403 -0
  25. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/src/libsigner.a +0 -0
  26. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/src/setup.py +16 -0
  27. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/src/signer.cpp +73 -0
  28. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/src/signer.h +37 -0
  29. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/src/signer.i +16 -0
  30. sidan_gin-0.1.5/src/sidan_gin/python_signing_module/src/signer_wrap.cxx +4092 -0
  31. sidan_gin-0.1.5/src/sidan_gin/wallet/__init__.py +3 -0
  32. sidan_gin-0.1.5/src/sidan_gin/wallet/cli.py +13 -0
  33. sidan_gin-0.1.5/src/sidan_gin/wallet/derivation_indices.py +30 -0
  34. sidan_gin-0.1.5/src/sidan_gin/wallet/mnemonic.py +24 -0
  35. sidan_gin-0.1.5/src/sidan_gin/wallet/root_key.py +24 -0
  36. sidan_gin-0.1.5/src/sidan_gin/wallet/wallet.py +48 -0
  37. sidan_gin-0.1.1/PKG-INFO +0 -33
  38. sidan_gin-0.1.1/README.md +0 -9
  39. sidan_gin-0.1.1/src/sidan_gin/__init__.py +0 -4
  40. sidan_gin-0.1.1/src/sidan_gin/signing/__init__.py +0 -3
  41. sidan_gin-0.1.1/src/sidan_gin/signing/wallet.py +0 -40
  42. {sidan_gin-0.1.1 → sidan_gin-0.1.5}/LICENSE +0 -0
  43. {sidan_gin-0.1.1 → sidan_gin-0.1.5}/src/sidan_gin/types/__init__.py +0 -0
  44. {sidan_gin-0.1.1 → sidan_gin-0.1.5}/src/sidan_gin/types/account_info.py +0 -0
  45. {sidan_gin-0.1.1 → sidan_gin-0.1.5}/src/sidan_gin/types/asset.py +0 -0
  46. {sidan_gin-0.1.1 → sidan_gin-0.1.5}/src/sidan_gin/types/asset_metadata.py +0 -0
  47. {sidan_gin-0.1.1 → sidan_gin-0.1.5}/src/sidan_gin/types/block_info.py +0 -0
  48. {sidan_gin-0.1.1 → sidan_gin-0.1.5}/src/sidan_gin/types/network.py +0 -0
  49. {sidan_gin-0.1.1 → sidan_gin-0.1.5}/src/sidan_gin/types/protocol.py +0 -0
  50. {sidan_gin-0.1.1 → sidan_gin-0.1.5}/src/sidan_gin/types/transaction_info.py +0 -0
  51. {sidan_gin-0.1.1 → sidan_gin-0.1.5}/src/sidan_gin/types/utxo.py +0 -0
  52. {sidan_gin-0.1.1 → sidan_gin-0.1.5}/src/sidan_gin/types/value.py +0 -0
@@ -0,0 +1,63 @@
1
+ Metadata-Version: 2.3
2
+ Name: sidan-gin
3
+ Version: 0.1.5
4
+ Summary: A python library for Cardano development, compatible with Mesh and Whisky types.
5
+ License: Apache-2.0
6
+ Keywords: cardano
7
+ Author: HinsonSIDAN
8
+ Author-email: wongkahinhinson@gmail.com
9
+ Requires-Python: >3.11,<4.0.0
10
+ Classifier: Intended Audience :: Developers
11
+ Classifier: License :: OSI Approved :: Apache Software License
12
+ Classifier: Natural Language :: English
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Programming Language :: Python :: 3.11
17
+ Requires-Dist: cbor2 (>=5.6.5,<6.0.0)
18
+ Requires-Dist: cryptography (>=44.0.2,<45.0.0)
19
+ Requires-Dist: pycardano (>=0.12.3,<0.13.0)
20
+ Requires-Dist: requests (>=2.25,<3.0)
21
+ Project-URL: Documentation, https://github.com/sidan-lab/gin
22
+ Project-URL: Homepage, https://github.com/sidan-lab/gin
23
+ Description-Content-Type: text/markdown
24
+
25
+ <div align="center">
26
+ <hr />
27
+ <h2 align="center" style="border-bottom: none"><img style="position: relative; top: 0.25rem;" src="https://raw.githubusercontent.com/sidan-lab/brand_assets/main/sidan_s_square.png" alt="Whisky" height="30" /> Gin - Cardano Python SDK</h2>
28
+
29
+ [![Licence](https://img.shields.io/github/license/sidan-lab/gin)](https://github.com/sidan-lab/gin/blob/master/LICENSE)
30
+ [![Test](https://github.com/sidan-lab/gin/actions/workflows/build.yml/badge.svg)](https://github.com/sidan-lab/gin/actions/workflows/build.yml)
31
+ [![Publish](https://github.com/sidan-lab/bin/actions/workflows/publish.yml/badge.svg)](https://github.com/sidan-lab/bin/actions/workflows/publish.yml)
32
+
33
+ [![PyPi version](https://badgen.net/pypi/v/sidan_gin)](https://pypi.python.org/pypi/sidan_gin/)
34
+ [![PyPI pyversions](https://img.shields.io/pypi/pyversions/sidan_gin)](https://pypi.python.org/pypi/sidan_gin/)
35
+ [![PyPI download month](https://img.shields.io/pypi/dm/sidan_gin)](https://pypi.python.org/pypi/sidan_gin/)
36
+
37
+ [![Twitter/X](https://img.shields.io/badge/Follow%20us-@sidan__lab-blue?logo=x&style=for-the-badge)](https://x.com/sidan_lab)
38
+
39
+ <hr/>
40
+ </div>
41
+
42
+ # gin
43
+
44
+ Gin is a Python library for Cardano development, compatible with Mesh and Whisky types. It also re-export core logics implemented in Whisky to support stable serialization in Python. Supported features:
45
+
46
+ - Identical type system with Mesh and Whisky.
47
+ - Transaction signing
48
+ - Cipher data encryption and decryption
49
+
50
+ ## Installation
51
+
52
+ ```sh
53
+ pip install sidan_gin
54
+ ```
55
+
56
+ ## Getting Started
57
+
58
+ ## Documentation
59
+
60
+ - Coming soon
61
+
62
+ ![Alt](https://repobeats.axiom.co/api/embed/0446bd7a0e9d2cd208432845cda9182f263321cd.svg "Repobeats analytics image")
63
+
@@ -0,0 +1,38 @@
1
+ <div align="center">
2
+ <hr />
3
+ <h2 align="center" style="border-bottom: none"><img style="position: relative; top: 0.25rem;" src="https://raw.githubusercontent.com/sidan-lab/brand_assets/main/sidan_s_square.png" alt="Whisky" height="30" /> Gin - Cardano Python SDK</h2>
4
+
5
+ [![Licence](https://img.shields.io/github/license/sidan-lab/gin)](https://github.com/sidan-lab/gin/blob/master/LICENSE)
6
+ [![Test](https://github.com/sidan-lab/gin/actions/workflows/build.yml/badge.svg)](https://github.com/sidan-lab/gin/actions/workflows/build.yml)
7
+ [![Publish](https://github.com/sidan-lab/bin/actions/workflows/publish.yml/badge.svg)](https://github.com/sidan-lab/bin/actions/workflows/publish.yml)
8
+
9
+ [![PyPi version](https://badgen.net/pypi/v/sidan_gin)](https://pypi.python.org/pypi/sidan_gin/)
10
+ [![PyPI pyversions](https://img.shields.io/pypi/pyversions/sidan_gin)](https://pypi.python.org/pypi/sidan_gin/)
11
+ [![PyPI download month](https://img.shields.io/pypi/dm/sidan_gin)](https://pypi.python.org/pypi/sidan_gin/)
12
+
13
+ [![Twitter/X](https://img.shields.io/badge/Follow%20us-@sidan__lab-blue?logo=x&style=for-the-badge)](https://x.com/sidan_lab)
14
+
15
+ <hr/>
16
+ </div>
17
+
18
+ # gin
19
+
20
+ Gin is a Python library for Cardano development, compatible with Mesh and Whisky types. It also re-export core logics implemented in Whisky to support stable serialization in Python. Supported features:
21
+
22
+ - Identical type system with Mesh and Whisky.
23
+ - Transaction signing
24
+ - Cipher data encryption and decryption
25
+
26
+ ## Installation
27
+
28
+ ```sh
29
+ pip install sidan_gin
30
+ ```
31
+
32
+ ## Getting Started
33
+
34
+ ## Documentation
35
+
36
+ - Coming soon
37
+
38
+ ![Alt](https://repobeats.axiom.co/api/embed/0446bd7a0e9d2cd208432845cda9182f263321cd.svg "Repobeats analytics image")
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "sidan-gin"
3
- version = "0.1.1"
3
+ version = "0.1.5"
4
4
  classifiers = [
5
5
  "Intended Audience :: Developers",
6
6
  "License :: OSI Approved :: Apache Software License",
@@ -21,8 +21,9 @@ python = ">3.11,<4.0.0"
21
21
  requests = "^2.25"
22
22
  cbor2 = "^5.6.5"
23
23
  pycardano = "^0.12.3"
24
+ cryptography = "^44.0.2"
24
25
 
25
- [tool.poetry.dev-dependencies]
26
+ [tool.poetry.group.dev.dependencies]
26
27
  pytest = "^8.2.0"
27
28
  pytest-xdist = "^3.5.0"
28
29
  pytest-cov = "^5.0.0"
@@ -0,0 +1,5 @@
1
+ # flake8: noqa
2
+
3
+ from .encryption import *
4
+ from .types import *
5
+ from .wallet import *
@@ -0,0 +1,3 @@
1
+ # flake8: noqa
2
+
3
+ from .cipher import *
@@ -0,0 +1,127 @@
1
+ import base64
2
+ import json
3
+ import os
4
+
5
+ from cryptography.hazmat.backends import default_backend
6
+ from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
7
+ from cryptography.hazmat.primitives.hashes import SHA256
8
+ from cryptography.hazmat.primitives.kdf.pbkdf2 import PBKDF2HMAC
9
+
10
+
11
+ def encrypt_with_cipher(
12
+ data: str, key: str, initialization_vector_size: int = 12
13
+ ) -> str:
14
+ """
15
+ Encrypt data using AES-GCM with a derived key from PBKDF2 and SHA-256.
16
+
17
+ :param data: The plaintext data to encrypt.
18
+ :param key: The input key used for encryption.
19
+ :param initialization_vector_size: The size of the IV (default is 12 bytes for AES-GCM).
20
+ :return: A JSON string containing the IV and ciphertext (both base64-encoded).
21
+ :raises ValueError: If encryption fails or input data is invalid.
22
+ """
23
+ # Derive a cryptographic key from the input key using PBKDF2 and SHA-256
24
+ salt = bytes(
25
+ initialization_vector_size
26
+ ) # Using a fixed salt (empty for simplicity)
27
+ kdf = PBKDF2HMAC(
28
+ algorithm=SHA256(),
29
+ length=32, # AES-256 requires a 256-bit key (32 bytes)
30
+ salt=salt,
31
+ iterations=100_000,
32
+ backend=default_backend(),
33
+ )
34
+ derived_key = kdf.derive(key.encode())
35
+
36
+ # Generate a random IV
37
+ iv = os.urandom(initialization_vector_size) # Generate a random IV
38
+ try:
39
+ # Initialize AES-GCM cipher
40
+ cipher = Cipher(
41
+ algorithms.AES(derived_key),
42
+ modes.GCM(iv),
43
+ backend=default_backend(),
44
+ )
45
+ encryptor = cipher.encryptor()
46
+
47
+ # Encrypt the data
48
+ ciphertext = encryptor.update(data.encode()) + encryptor.finalize()
49
+
50
+ # Get the authentication tag
51
+ tag = encryptor.tag
52
+
53
+ # Append the tag to the ciphertext to match Web Crypto API behavior
54
+ ciphertext_with_tag = ciphertext + tag
55
+ except Exception as e:
56
+ raise ValueError("Encryption failed") from e
57
+
58
+ # Encode the IV and ciphertext (with tag) in base64
59
+ iv_base64 = base64.b64encode(iv).decode("utf-8")
60
+ ciphertext_base64 = base64.b64encode(ciphertext_with_tag).decode("utf-8")
61
+
62
+ # Create a JSON-like string containing the IV and ciphertext
63
+ result = {
64
+ "iv": iv_base64,
65
+ "ciphertext": ciphertext_base64,
66
+ }
67
+
68
+ return json.dumps(result)
69
+
70
+
71
+ def decrypt_with_cipher(encrypted_data_json: str, key: str) -> str:
72
+ """
73
+ Decrypt data encrypted with AES-GCM using a derived key from PBKDF2 and SHA-256.
74
+ """
75
+ # Parse the encrypted data from JSON
76
+ try:
77
+ encrypted_data = json.loads(encrypted_data_json)
78
+ iv_base64 = encrypted_data["iv"]
79
+ ciphertext_base64 = encrypted_data["ciphertext"]
80
+ except (KeyError, json.JSONDecodeError) as e:
81
+ raise ValueError("Invalid encrypted data JSON") from e
82
+
83
+ # Decode the IV and ciphertext from base64
84
+ try:
85
+ iv = base64.b64decode(iv_base64)
86
+ ciphertext_with_tag = base64.b64decode(ciphertext_base64)
87
+ except base64.binascii.Error as e:
88
+ raise ValueError("Base64 decoding failed") from e
89
+
90
+ # In Web Crypto API, the tag is appended to the ciphertext
91
+ # Standard GCM tag length is 16 bytes (128 bits)
92
+ tag_length = 16
93
+ ciphertext = ciphertext_with_tag[:-tag_length]
94
+ tag = ciphertext_with_tag[-tag_length:]
95
+
96
+ # Derive a cryptographic key from the input key using PBKDF2 and SHA-256
97
+ salt = bytes(len(iv)) # Use the same salt size as the IV
98
+ kdf = PBKDF2HMAC(
99
+ algorithm=SHA256(),
100
+ length=32, # AES-256 requires a 256-bit key (32 bytes)
101
+ salt=salt,
102
+ iterations=100_000,
103
+ backend=default_backend(),
104
+ )
105
+ derived_key = kdf.derive(key.encode())
106
+
107
+ # Initialize AES-GCM cipher for decryption
108
+ try:
109
+ cipher = Cipher(
110
+ algorithms.AES(derived_key),
111
+ modes.GCM(iv, tag), # Pass the extracted tag to GCM mode
112
+ backend=default_backend(),
113
+ )
114
+ decryptor = cipher.decryptor()
115
+
116
+ # Decrypt the data
117
+ decrypted_data = decryptor.update(ciphertext) + decryptor.finalize()
118
+ except Exception as e:
119
+ raise ValueError("Decryption failed") from e
120
+
121
+ # Convert the decrypted data back to a string
122
+ try:
123
+ decrypted_str = decrypted_data.decode("utf-8")
124
+ except UnicodeDecodeError as e:
125
+ raise ValueError("Failed to convert decrypted data to UTF-8") from e
126
+
127
+ return decrypted_str
@@ -0,0 +1 @@
1
+ gitdir: ../../../.git/modules/src/sidan_gin/python_signing_module
@@ -0,0 +1,11 @@
1
+ /.idea
2
+ /cmake-build-*
3
+ build
4
+ /target
5
+ Cargo.lock
6
+ lib.rs.h
7
+ libsigner.a
8
+ *.so
9
+ CardanoSigner.py
10
+ __pycache__/
11
+ *.h
@@ -0,0 +1,32 @@
1
+ {
2
+ "files.associations": {
3
+ "iosfwd": "cpp",
4
+ "vector": "cpp",
5
+ "stdexcept": "cpp",
6
+ "string": "cpp",
7
+ "__verbose_abort": "cpp",
8
+ "array": "cpp",
9
+ "cstddef": "cpp",
10
+ "cstdint": "cpp",
11
+ "cstdio": "cpp",
12
+ "cstdlib": "cpp",
13
+ "cstring": "cpp",
14
+ "cwchar": "cpp",
15
+ "execution": "cpp",
16
+ "memory": "cpp",
17
+ "initializer_list": "cpp",
18
+ "limits": "cpp",
19
+ "new": "cpp",
20
+ "string_view": "cpp",
21
+ "typeinfo": "cpp",
22
+ "variant": "cpp",
23
+ "cctype": "cpp",
24
+ "cmath": "cpp",
25
+ "ctime": "cpp",
26
+ "cwctype": "cpp",
27
+ "optional": "cpp",
28
+ "ratio": "cpp",
29
+ "algorithm": "cpp",
30
+ "*.rs": "rust"
31
+ }
32
+ }