quantumsafe 1.0.0__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 QuantumSafe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,3 @@
1
+ include LICENSE
2
+ include README.md
3
+ recursive-exclude tests *
@@ -0,0 +1,85 @@
1
+ Metadata-Version: 2.4
2
+ Name: quantumsafe
3
+ Version: 1.0.0
4
+ Summary: QuantumSafe — Post-quantum cryptography SDK for blockchain
5
+ License: MIT
6
+ Project-URL: Homepage, https://qsafe.dev
7
+ Project-URL: Documentation, https://docs.qsafe.dev
8
+ Project-URL: Repository, https://github.com/quantumsafe/sdk
9
+ Keywords: quantum,pqc,blockchain,ml-dsa,post-quantum,cryptography,ethereum,solana,bitcoin
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Security :: Cryptography
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: httpx>=0.27.0
22
+ Requires-Dist: pqcrypto>=0.1.0
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=8.0; extra == "dev"
25
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
26
+ Requires-Dist: ruff>=0.4.0; extra == "dev"
27
+ Requires-Dist: respx>=0.21.0; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # quantumsafe
31
+
32
+ Post-quantum cryptography SDK for blockchain. Scan wallets for quantum risk, generate PQC keys, and verify hybrid signatures.
33
+
34
+ ## Install
35
+
36
+ ```bash
37
+ pip install quantumsafe
38
+ ```
39
+
40
+ ## Quick Start
41
+
42
+ ```python
43
+ import asyncio
44
+ from quantumsafe import QuantumSafe
45
+
46
+ async def main():
47
+ qs = QuantumSafe(api_key="your-api-key")
48
+
49
+ # 1. Scan a wallet for quantum risk
50
+ scan = await qs.scan_wallet(chain="ethereum", address="0xYourAddress")
51
+ print(f"Risk score: {scan.risk_score}")
52
+
53
+ # 2. Generate a post-quantum key pair
54
+ keys = await qs.generate_key(algorithm="ml-dsa-65", chain="ethereum")
55
+ print(f"Public key: {keys.public_key}")
56
+
57
+ # 3. Register key on-chain & verify
58
+ registered = await qs.register_key(chain="ethereum", public_key=keys.public_key)
59
+
60
+ result = await qs.verify(
61
+ chain="ethereum",
62
+ address="0xYourAddress",
63
+ attestation_id=registered.attestation_id,
64
+ )
65
+ print(f"Verified: {result.verified}")
66
+
67
+ asyncio.run(main())
68
+ ```
69
+
70
+ ## Supported Chains
71
+
72
+ - Ethereum
73
+ - Solana
74
+ - Bitcoin
75
+ - Polygon
76
+ - Avalanche
77
+ - Cosmos
78
+
79
+ ## Documentation
80
+
81
+ Full API docs: [https://docs.qsafe.dev](https://docs.qsafe.dev)
82
+
83
+ ## License
84
+
85
+ MIT — see [LICENSE](./LICENSE)
@@ -0,0 +1,56 @@
1
+ # quantumsafe
2
+
3
+ Post-quantum cryptography SDK for blockchain. Scan wallets for quantum risk, generate PQC keys, and verify hybrid signatures.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ pip install quantumsafe
9
+ ```
10
+
11
+ ## Quick Start
12
+
13
+ ```python
14
+ import asyncio
15
+ from quantumsafe import QuantumSafe
16
+
17
+ async def main():
18
+ qs = QuantumSafe(api_key="your-api-key")
19
+
20
+ # 1. Scan a wallet for quantum risk
21
+ scan = await qs.scan_wallet(chain="ethereum", address="0xYourAddress")
22
+ print(f"Risk score: {scan.risk_score}")
23
+
24
+ # 2. Generate a post-quantum key pair
25
+ keys = await qs.generate_key(algorithm="ml-dsa-65", chain="ethereum")
26
+ print(f"Public key: {keys.public_key}")
27
+
28
+ # 3. Register key on-chain & verify
29
+ registered = await qs.register_key(chain="ethereum", public_key=keys.public_key)
30
+
31
+ result = await qs.verify(
32
+ chain="ethereum",
33
+ address="0xYourAddress",
34
+ attestation_id=registered.attestation_id,
35
+ )
36
+ print(f"Verified: {result.verified}")
37
+
38
+ asyncio.run(main())
39
+ ```
40
+
41
+ ## Supported Chains
42
+
43
+ - Ethereum
44
+ - Solana
45
+ - Bitcoin
46
+ - Polygon
47
+ - Avalanche
48
+ - Cosmos
49
+
50
+ ## Documentation
51
+
52
+ Full API docs: [https://docs.qsafe.dev](https://docs.qsafe.dev)
53
+
54
+ ## License
55
+
56
+ MIT — see [LICENSE](./LICENSE)
@@ -0,0 +1,55 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "quantumsafe"
7
+ version = "1.0.0"
8
+ description = "QuantumSafe — Post-quantum cryptography SDK for blockchain"
9
+ readme = "README.md"
10
+ requires-python = ">=3.10"
11
+ license = {text = "MIT"}
12
+ keywords = ["quantum", "pqc", "blockchain", "ml-dsa", "post-quantum", "cryptography", "ethereum", "solana", "bitcoin"]
13
+ classifiers = [
14
+ "Development Status :: 5 - Production/Stable",
15
+ "Intended Audience :: Developers",
16
+ "License :: OSI Approved :: MIT License",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.10",
19
+ "Programming Language :: Python :: 3.11",
20
+ "Programming Language :: Python :: 3.12",
21
+ "Topic :: Security :: Cryptography",
22
+ ]
23
+ dependencies = [
24
+ "httpx>=0.27.0",
25
+ "pqcrypto>=0.1.0",
26
+ ]
27
+
28
+ [project.urls]
29
+ Homepage = "https://qsafe.dev"
30
+ Documentation = "https://docs.qsafe.dev"
31
+ Repository = "https://github.com/quantumsafe/sdk"
32
+
33
+ [project.optional-dependencies]
34
+ dev = [
35
+ "pytest>=8.0",
36
+ "pytest-asyncio>=0.23.0",
37
+ "ruff>=0.4.0",
38
+ "respx>=0.21.0",
39
+ ]
40
+
41
+ [tool.setuptools.packages.find]
42
+ include = ["quantumsafe*"]
43
+
44
+ [tool.ruff]
45
+ target-version = "py310"
46
+ line-length = 100
47
+
48
+ [tool.ruff.lint]
49
+ select = ["E", "F", "W", "I"]
50
+ # SECURITY: 'import random' 금지 — CI에서 grep으로 별도 체크
51
+ # ruff에서 커스텀 import 금지 rule이 없으므로 grep/CI로 보완
52
+
53
+ [tool.pytest.ini_options]
54
+ asyncio_mode = "auto"
55
+ testpaths = ["tests"]
@@ -0,0 +1,26 @@
1
+ # SECURITY: Only use secrets/os.urandom for randomness. Never import random.
2
+ """QuantumSafe Python SDK — PQC 키 관리, 하이브리드 서명, 지갑 스캔"""
3
+
4
+ from quantumsafe.client import QuantumSafe
5
+ from quantumsafe.types import (
6
+ Algorithm,
7
+ Attestation,
8
+ Chain,
9
+ KeyPair,
10
+ RegisteredKey,
11
+ ScanResult,
12
+ VerifyResult,
13
+ )
14
+
15
+ __version__ = "0.1.0"
16
+
17
+ __all__ = [
18
+ "QuantumSafe",
19
+ "Algorithm",
20
+ "Chain",
21
+ "KeyPair",
22
+ "RegisteredKey",
23
+ "Attestation",
24
+ "VerifyResult",
25
+ "ScanResult",
26
+ ]
@@ -0,0 +1,114 @@
1
+ # SECURITY: Only use secrets/os.urandom for randomness. Never import random.
2
+ """QuantumSafe SDK 메인 클라이언트"""
3
+
4
+ import json
5
+ import logging
6
+ from typing import Any, Optional
7
+
8
+ import httpx
9
+
10
+ from quantumsafe.modules.keys import KeysModule
11
+ from quantumsafe.modules.scan import ScanModule
12
+ from quantumsafe.modules.sign import SignModule
13
+ from quantumsafe.modules.verify import VerifyModule
14
+ from quantumsafe.types import VerifyResult
15
+
16
+ logger = logging.getLogger("quantumsafe")
17
+
18
+
19
+ class QuantumSafe:
20
+ """QuantumSafe Python SDK 메인 클라이언트
21
+
22
+ Args:
23
+ api_key: API 키 (X-API-Key 헤더로 전송)
24
+ base_url: 백엔드 API 기본 URL
25
+ timeout: 요청 타임아웃 (초)
26
+
27
+ Example::
28
+
29
+ qs = QuantumSafe(api_key="qs_sec_live_...", base_url="https://api.qsafe.dev")
30
+ key_pair = qs.keys.generate(algorithm="ml-dsa-65")
31
+ """
32
+
33
+ def __init__(
34
+ self,
35
+ api_key: str,
36
+ base_url: str = "https://api.qsafe.dev",
37
+ timeout: float = 30.0,
38
+ ) -> None:
39
+ if not api_key:
40
+ raise ValueError("QuantumSafe: api_key는 필수입니다.")
41
+
42
+ self.api_key = api_key
43
+ self.base_url = base_url.rstrip("/")
44
+ self.timeout = timeout
45
+
46
+ # HTTP 클라이언트 (연결 재사용)
47
+ self._http = httpx.Client(
48
+ base_url=self.base_url,
49
+ headers={
50
+ "Content-Type": "application/json",
51
+ "X-API-Key": self.api_key,
52
+ },
53
+ timeout=self.timeout,
54
+ )
55
+
56
+ # 모듈 초기화
57
+ self.keys = KeysModule(self)
58
+ self.sign = SignModule(self)
59
+ self._verify_module = VerifyModule(self)
60
+ self.scan = ScanModule(self)
61
+
62
+ def verify(
63
+ self,
64
+ public_key: str,
65
+ message: str,
66
+ signature: str,
67
+ algorithm: str = "ml-dsa-65",
68
+ ) -> VerifyResult:
69
+ """PQC 서명 검증 (최상위 메서드)"""
70
+ return self._verify_module.verify(
71
+ public_key=public_key,
72
+ message=message,
73
+ signature=signature,
74
+ algorithm=algorithm,
75
+ )
76
+
77
+ def _request(
78
+ self,
79
+ method: str,
80
+ path: str,
81
+ body: Optional[dict[str, Any]] = None,
82
+ ) -> dict[str, Any]:
83
+ """내부 HTTP 요청 헬퍼
84
+
85
+ CRITICAL: body에 private_key가 포함되면 즉시 에러
86
+ """
87
+ # ★ 프라이빗 키 유출 방지 런타임 체크
88
+ if body is not None:
89
+ body_str = json.dumps(body)
90
+ if '"private_key"' in body_str or '"privateKey"' in body_str:
91
+ raise SecurityError(
92
+ "SECURITY: private_key가 네트워크 요청 body에 포함되었습니다. "
93
+ "프라이빗 키는 절대 서버로 전송되면 안 됩니다."
94
+ )
95
+
96
+ url = path
97
+ response = self._http.request(method, url, json=body)
98
+ response.raise_for_status()
99
+ result: dict[str, Any] = response.json()
100
+ return result
101
+
102
+ def close(self) -> None:
103
+ """HTTP 클라이언트 종료"""
104
+ self._http.close()
105
+
106
+ def __enter__(self) -> "QuantumSafe":
107
+ return self
108
+
109
+ def __exit__(self, *args: Any) -> None:
110
+ self.close()
111
+
112
+
113
+ class SecurityError(Exception):
114
+ """프라이빗 키 유출 방지 보안 에러"""
@@ -0,0 +1 @@
1
+ # SECURITY: Only use secrets/os.urandom for randomness. Never import random.
@@ -0,0 +1,153 @@
1
+ # SECURITY: Only use secrets/os.urandom for randomness. Never import random.
2
+ """키 생성/등록 모듈 — 실 PQC 키 생성 (pqcrypto 사용)"""
3
+
4
+ from __future__ import annotations
5
+
6
+ import importlib
7
+ import logging
8
+ import warnings
9
+ from typing import TYPE_CHECKING, Any
10
+
11
+ from quantumsafe.types import AlgorithmInfo, KeyPair, RegisteredKey
12
+
13
+ if TYPE_CHECKING:
14
+ from quantumsafe.client import QuantumSafe
15
+
16
+ logger = logging.getLogger("quantumsafe.keys")
17
+
18
+ # 알고리즘 메타정보 (NIST 표준명 → pqcrypto 모듈 매핑)
19
+ ALGORITHM_INFO: dict[str, AlgorithmInfo] = {
20
+ "ml-dsa-44": AlgorithmInfo(
21
+ nist_level=2,
22
+ public_key_size=1312,
23
+ secret_key_size=2560,
24
+ signature_size=2420,
25
+ pqcrypto_module="pqcrypto.sign.ml_dsa_44",
26
+ ),
27
+ "ml-dsa-65": AlgorithmInfo(
28
+ nist_level=3,
29
+ public_key_size=1952,
30
+ secret_key_size=4032,
31
+ signature_size=3309,
32
+ pqcrypto_module="pqcrypto.sign.ml_dsa_65",
33
+ ),
34
+ "ml-dsa-87": AlgorithmInfo(
35
+ nist_level=5,
36
+ public_key_size=2592,
37
+ secret_key_size=4896,
38
+ signature_size=4627,
39
+ pqcrypto_module="pqcrypto.sign.ml_dsa_87",
40
+ ),
41
+ "slh-dsa-128s": AlgorithmInfo(
42
+ nist_level=1,
43
+ public_key_size=32,
44
+ secret_key_size=64,
45
+ signature_size=7856,
46
+ pqcrypto_module="pqcrypto.sign.sphincs_sha2_128s_simple",
47
+ ),
48
+ }
49
+
50
+ # pqcrypto 모듈 캐시
51
+ _modules: dict[str, Any] = {}
52
+
53
+
54
+ def _get_pqc_module(algorithm: str) -> Any:
55
+ """알고리즘에 해당하는 pqcrypto 모듈 로드 (캐시)"""
56
+ if algorithm not in _modules:
57
+ info = ALGORITHM_INFO.get(algorithm)
58
+ if not info:
59
+ raise ValueError(f"지원하지 않는 알고리즘: {algorithm}")
60
+ _modules[algorithm] = importlib.import_module(info.pqcrypto_module)
61
+ return _modules[algorithm]
62
+
63
+
64
+ class KeysModule:
65
+ """키 생성/등록 모듈
66
+
67
+ - generate(): 로컬에서 실 PQC 키 쌍 생성 (pqcrypto 사용, 네트워크 미사용)
68
+ - register(): 공개키를 서버에 등록 (프라이빗 키 전송 안 함)
69
+ """
70
+
71
+ def __init__(self, client: QuantumSafe) -> None:
72
+ self._client = client
73
+
74
+ def generate(self, algorithm: str = "ml-dsa-65") -> KeyPair:
75
+ """로컬 PQC 키 쌍 생성 (pqcrypto 사용)
76
+
77
+ 프라이빗 키는 절대 서버로 전송되지 않습니다.
78
+
79
+ Args:
80
+ algorithm: PQC 알고리즘 (기본: ml-dsa-65)
81
+
82
+ Returns:
83
+ KeyPair: 공개키/프라이빗키 (hex 인코딩)
84
+ """
85
+ info = ALGORITHM_INFO.get(algorithm)
86
+ if not info:
87
+ raise ValueError(f"지원하지 않는 알고리즘: {algorithm}")
88
+
89
+ # SLH-DSA KMS 비호환 경고
90
+ if algorithm == "slh-dsa-128s":
91
+ warnings.warn(
92
+ "QuantumSafe: SLH-DSA does not support Managed (KMS) mode upgrade. "
93
+ "Consider ML-DSA-65 for future KMS compatibility.",
94
+ UserWarning,
95
+ stacklevel=2,
96
+ )
97
+
98
+ # pqcrypto로 실 PQC 키 생성
99
+ mod = _get_pqc_module(algorithm)
100
+ pk, sk = mod.generate_keypair()
101
+
102
+ return KeyPair(
103
+ public_key=pk.hex(),
104
+ private_key=sk.hex(),
105
+ algorithm=algorithm,
106
+ nist_level=info.nist_level,
107
+ )
108
+
109
+ def register(
110
+ self,
111
+ public_key: str,
112
+ algorithm: str = "ml-dsa-65",
113
+ chain: str = "ethereum",
114
+ ) -> RegisteredKey:
115
+ """공개키를 서버에 등록 (BYOK)
116
+
117
+ 프라이빗 키는 전송하지 않습니다.
118
+
119
+ Args:
120
+ public_key: hex 인코딩된 공개키
121
+ algorithm: PQC 알고리즘 (기본: ml-dsa-65)
122
+ chain: 블록체인 (기본: ethereum)
123
+
124
+ Returns:
125
+ RegisteredKey: 등록된 키 정보
126
+ """
127
+ # SLH-DSA KMS 비호환 경고
128
+ if algorithm == "slh-dsa-128s":
129
+ warnings.warn(
130
+ "QuantumSafe: SLH-DSA does not support Managed (KMS) mode upgrade. "
131
+ "Consider ML-DSA-65 for future KMS compatibility.",
132
+ UserWarning,
133
+ stacklevel=2,
134
+ )
135
+
136
+ res = self._client._request(
137
+ "POST",
138
+ "/v1/keys/generate",
139
+ body={
140
+ "algorithm": algorithm,
141
+ "chain": chain,
142
+ "format": "hex",
143
+ "public_key": public_key,
144
+ },
145
+ )
146
+
147
+ return RegisteredKey(
148
+ key_id=res["key_id"],
149
+ algorithm=res["algorithm"],
150
+ nist_level=res["nist_level"],
151
+ chain=res["chain"],
152
+ custody=res["custody"],
153
+ )
@@ -0,0 +1,76 @@
1
+ # SECURITY: Only use secrets/os.urandom for randomness. Never import random.
2
+ """지갑 양자 위협 스캔 모듈"""
3
+
4
+ from __future__ import annotations
5
+
6
+ import logging
7
+ from typing import TYPE_CHECKING
8
+
9
+ from quantumsafe.types import ChainFactor, RiskFactor, ScanResult
10
+
11
+ if TYPE_CHECKING:
12
+ from quantumsafe.client import QuantumSafe
13
+
14
+ logger = logging.getLogger("quantumsafe.scan")
15
+
16
+
17
+ class ScanModule:
18
+ """지갑 양자 위협 스캔 모듈"""
19
+
20
+ def __init__(self, client: QuantumSafe) -> None:
21
+ self._client = client
22
+
23
+ def wallet(
24
+ self,
25
+ address: str,
26
+ chain: str = "ethereum",
27
+ ) -> ScanResult:
28
+ """지갑 양자 위협 스캔
29
+
30
+ Args:
31
+ address: 이더리움 주소 (0x...)
32
+ chain: 블록체인 (기본: ethereum)
33
+
34
+ Returns:
35
+ ScanResult: 스캔 결과
36
+ """
37
+ res = self._client._request(
38
+ "POST",
39
+ "/v1/scan/wallet",
40
+ body={
41
+ "address": address,
42
+ "chain": chain,
43
+ },
44
+ )
45
+
46
+ risk_factors = [
47
+ RiskFactor(
48
+ category=f["category"],
49
+ name=f["name"],
50
+ score=f["score"],
51
+ max_score=f["max_score"],
52
+ detail=f["detail"],
53
+ )
54
+ for f in res.get("risk_factors", [])
55
+ ]
56
+
57
+ chain_factors = [
58
+ ChainFactor(
59
+ factor=f["factor"],
60
+ impact=f["impact"],
61
+ )
62
+ for f in res.get("chain_factors", [])
63
+ ]
64
+
65
+ return ScanResult(
66
+ address=res["address"],
67
+ chain=res["chain"],
68
+ address_risk_score=res["address_risk_score"],
69
+ address_risk_grade=res["address_risk_grade"],
70
+ chain_readiness_grade=res["chain_readiness_grade"],
71
+ methodology_version=res.get("methodology_version", "v1.0"),
72
+ risk_factors=risk_factors,
73
+ chain_factors=chain_factors,
74
+ scan_timestamp=res.get("scan_timestamp", ""),
75
+ asset_value_usd=res.get("asset_value_usd"),
76
+ )
@@ -0,0 +1,100 @@
1
+ # SECURITY: Only use secrets/os.urandom for randomness. Never import random.
2
+ """하이브리드 서명 모듈 — 로컬 PQC 서명 + 서버 Attestation"""
3
+
4
+ from __future__ import annotations
5
+
6
+ import hashlib
7
+ import logging
8
+ from typing import TYPE_CHECKING, Optional
9
+
10
+ from quantumsafe.modules.keys import _get_pqc_module
11
+ from quantumsafe.types import Attestation
12
+
13
+ if TYPE_CHECKING:
14
+ from quantumsafe.client import QuantumSafe
15
+
16
+ logger = logging.getLogger("quantumsafe.sign")
17
+
18
+
19
+ class SignModule:
20
+ """하이브리드 서명 모듈
21
+
22
+ 로컬에서 PQC 서명 생성 후, 공개키 + 서명 + 메시지만 서버로 전송.
23
+ 프라이빗 키는 절대 네트워크로 전송하지 않습니다.
24
+ """
25
+
26
+ def __init__(self, client: QuantumSafe) -> None:
27
+ self._client = client
28
+
29
+ def hybrid(
30
+ self,
31
+ message: str,
32
+ private_key: str,
33
+ ecdsa_signature: Optional[str] = None,
34
+ chain: str = "ethereum",
35
+ algorithm: str = "ml-dsa-65",
36
+ public_key: Optional[str] = None,
37
+ linked_tx_hash: Optional[str] = None,
38
+ tx_status: Optional[str] = None,
39
+ ) -> Attestation:
40
+ """하이브리드 서명 + 서버 Attestation
41
+
42
+ 1. 로컬에서 PQC 서명 생성 (pqcrypto 사용)
43
+ 2. combined_hash 생성
44
+ 3. 서버에 공개키 + 서명 + 메시지 전송 (프라이빗 키 제외!)
45
+
46
+ Args:
47
+ message: hex 인코딩된 메시지
48
+ private_key: hex 인코딩된 PQC 프라이빗 키 (로컬 전용, 서버 미전송)
49
+ ecdsa_signature: hex 인코딩된 ECDSA 서명 (선택)
50
+ chain: 블록체인 (기본: ethereum)
51
+ algorithm: PQC 알고리즘 (기본: ml-dsa-65)
52
+ public_key: hex 인코딩된 공개키 (지정하지 않으면 프라이빗 키에서 추출 불가 → 필수)
53
+ linked_tx_hash: 연결된 온체인 TX 해시 (선택)
54
+ tx_status: TX 상태 (선택)
55
+
56
+ Returns:
57
+ Attestation: 서버 Attestation 결과
58
+ """
59
+ sk_bytes = bytes.fromhex(private_key)
60
+ msg_bytes = bytes.fromhex(message)
61
+
62
+ # pqcrypto로 실 PQC 서명 생성
63
+ mod = _get_pqc_module(algorithm)
64
+ pqc_sig = mod.sign(sk_bytes, msg_bytes)
65
+ pqc_sig_hex = pqc_sig.hex()
66
+
67
+ # combined_hash 생성
68
+ hash_input = pqc_sig_hex + (ecdsa_signature or "")
69
+ combined_hash = hashlib.sha256(hash_input.encode()).hexdigest()
70
+
71
+ if not public_key:
72
+ raise ValueError(
73
+ "public_key는 필수입니다. keys.generate()에서 받은 공개키를 전달하세요."
74
+ )
75
+
76
+ # ★ 서버 요청: 프라이빗 키 제외, 공개키 + 서명 + 메시지만 전송
77
+ body: dict = {
78
+ "public_key": public_key,
79
+ "message": message,
80
+ "pqc_signature": pqc_sig_hex,
81
+ "combined_hash": combined_hash,
82
+ "chain": chain,
83
+ "algorithm": algorithm,
84
+ }
85
+
86
+ if ecdsa_signature:
87
+ body["ecdsa_signature"] = ecdsa_signature
88
+ if linked_tx_hash:
89
+ body["linked_tx_hash"] = linked_tx_hash
90
+ if tx_status:
91
+ body["tx_status"] = tx_status
92
+
93
+ res = self._client._request("POST", "/v1/sign/hybrid", body=body)
94
+
95
+ return Attestation(
96
+ attestation_id=res["attestation_id"],
97
+ combined_hash=res["combined_hash"],
98
+ verified_at=res["verified_at"],
99
+ chain=res["chain"],
100
+ )
@@ -0,0 +1,61 @@
1
+ # SECURITY: Only use secrets/os.urandom for randomness. Never import random.
2
+ """서명 검증 모듈"""
3
+
4
+ from __future__ import annotations
5
+
6
+ import logging
7
+ from typing import TYPE_CHECKING
8
+
9
+ from quantumsafe.types import VerifyResult
10
+
11
+ if TYPE_CHECKING:
12
+ from quantumsafe.client import QuantumSafe
13
+
14
+ logger = logging.getLogger("quantumsafe.verify")
15
+
16
+
17
+ class VerifyModule:
18
+ """서명 검증 모듈
19
+
20
+ 서버에서 PQC 서명을 검증합니다.
21
+ 프라이빗 키는 요청에 포함되지 않습니다.
22
+ """
23
+
24
+ def __init__(self, client: QuantumSafe) -> None:
25
+ self._client = client
26
+
27
+ def verify(
28
+ self,
29
+ public_key: str,
30
+ message: str,
31
+ signature: str,
32
+ algorithm: str = "ml-dsa-65",
33
+ ) -> VerifyResult:
34
+ """PQC 서명 검증
35
+
36
+ Args:
37
+ public_key: hex 인코딩된 공개키
38
+ message: hex 인코딩된 메시지
39
+ signature: hex 인코딩된 서명
40
+ algorithm: PQC 알고리즘 (기본: ml-dsa-65)
41
+
42
+ Returns:
43
+ VerifyResult: 검증 결과
44
+ """
45
+ res = self._client._request(
46
+ "POST",
47
+ "/v1/verify",
48
+ body={
49
+ "public_key": public_key,
50
+ "message": message,
51
+ "signature": signature,
52
+ "algorithm": algorithm,
53
+ },
54
+ )
55
+
56
+ return VerifyResult(
57
+ valid=res["valid"],
58
+ algorithm=res["algorithm"],
59
+ nist_level=res["nist_level"],
60
+ verified_at=res["verified_at"],
61
+ )
@@ -0,0 +1,98 @@
1
+ # SECURITY: Only use secrets/os.urandom for randomness. Never import random.
2
+ """QuantumSafe SDK 데이터 타입 정의"""
3
+
4
+ from dataclasses import dataclass, field
5
+ from typing import Literal, Optional
6
+
7
+ # 지원 알고리즘 (NIST 표준명만)
8
+ Algorithm = Literal["ml-dsa-44", "ml-dsa-65", "ml-dsa-87", "slh-dsa-128s"]
9
+
10
+ # 지원 체인
11
+ Chain = Literal["ethereum", "base", "arbitrum"]
12
+
13
+
14
+ @dataclass(frozen=True)
15
+ class AlgorithmInfo:
16
+ """알고리즘 메타정보"""
17
+
18
+ nist_level: int
19
+ public_key_size: int
20
+ secret_key_size: int
21
+ signature_size: int
22
+ pqcrypto_module: str
23
+
24
+
25
+ @dataclass(frozen=True)
26
+ class KeyPair:
27
+ """로컬 생성된 PQC 키 쌍"""
28
+
29
+ public_key: str
30
+ private_key: str
31
+ algorithm: str
32
+ nist_level: int
33
+
34
+
35
+ @dataclass(frozen=True)
36
+ class RegisteredKey:
37
+ """서버 등록된 공개키"""
38
+
39
+ key_id: str
40
+ algorithm: str
41
+ nist_level: int
42
+ chain: str
43
+ custody: str
44
+
45
+
46
+ @dataclass(frozen=True)
47
+ class Attestation:
48
+ """하이브리드 서명 Attestation 결과"""
49
+
50
+ attestation_id: str
51
+ combined_hash: str
52
+ verified_at: str
53
+ chain: str
54
+
55
+
56
+ @dataclass(frozen=True)
57
+ class VerifyResult:
58
+ """서명 검증 결과"""
59
+
60
+ valid: bool
61
+ algorithm: str
62
+ nist_level: int
63
+ verified_at: str
64
+
65
+
66
+ @dataclass(frozen=True)
67
+ class RiskFactor:
68
+ """위험 요인"""
69
+
70
+ category: str
71
+ name: str
72
+ score: int
73
+ max_score: int
74
+ detail: str
75
+
76
+
77
+ @dataclass(frozen=True)
78
+ class ChainFactor:
79
+ """체인 PQC 준비도 요인"""
80
+
81
+ factor: str
82
+ impact: str
83
+
84
+
85
+ @dataclass(frozen=True)
86
+ class ScanResult:
87
+ """지갑 양자 위협 스캔 결과"""
88
+
89
+ address: str
90
+ chain: str
91
+ address_risk_score: int
92
+ address_risk_grade: str
93
+ chain_readiness_grade: str
94
+ methodology_version: str
95
+ risk_factors: list[RiskFactor] = field(default_factory=list)
96
+ chain_factors: list[ChainFactor] = field(default_factory=list)
97
+ scan_timestamp: str = ""
98
+ asset_value_usd: Optional[float] = None
@@ -0,0 +1,85 @@
1
+ Metadata-Version: 2.4
2
+ Name: quantumsafe
3
+ Version: 1.0.0
4
+ Summary: QuantumSafe — Post-quantum cryptography SDK for blockchain
5
+ License: MIT
6
+ Project-URL: Homepage, https://qsafe.dev
7
+ Project-URL: Documentation, https://docs.qsafe.dev
8
+ Project-URL: Repository, https://github.com/quantumsafe/sdk
9
+ Keywords: quantum,pqc,blockchain,ml-dsa,post-quantum,cryptography,ethereum,solana,bitcoin
10
+ Classifier: Development Status :: 5 - Production/Stable
11
+ Classifier: Intended Audience :: Developers
12
+ Classifier: License :: OSI Approved :: MIT License
13
+ Classifier: Programming Language :: Python :: 3
14
+ Classifier: Programming Language :: Python :: 3.10
15
+ Classifier: Programming Language :: Python :: 3.11
16
+ Classifier: Programming Language :: Python :: 3.12
17
+ Classifier: Topic :: Security :: Cryptography
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: httpx>=0.27.0
22
+ Requires-Dist: pqcrypto>=0.1.0
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=8.0; extra == "dev"
25
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
26
+ Requires-Dist: ruff>=0.4.0; extra == "dev"
27
+ Requires-Dist: respx>=0.21.0; extra == "dev"
28
+ Dynamic: license-file
29
+
30
+ # quantumsafe
31
+
32
+ Post-quantum cryptography SDK for blockchain. Scan wallets for quantum risk, generate PQC keys, and verify hybrid signatures.
33
+
34
+ ## Install
35
+
36
+ ```bash
37
+ pip install quantumsafe
38
+ ```
39
+
40
+ ## Quick Start
41
+
42
+ ```python
43
+ import asyncio
44
+ from quantumsafe import QuantumSafe
45
+
46
+ async def main():
47
+ qs = QuantumSafe(api_key="your-api-key")
48
+
49
+ # 1. Scan a wallet for quantum risk
50
+ scan = await qs.scan_wallet(chain="ethereum", address="0xYourAddress")
51
+ print(f"Risk score: {scan.risk_score}")
52
+
53
+ # 2. Generate a post-quantum key pair
54
+ keys = await qs.generate_key(algorithm="ml-dsa-65", chain="ethereum")
55
+ print(f"Public key: {keys.public_key}")
56
+
57
+ # 3. Register key on-chain & verify
58
+ registered = await qs.register_key(chain="ethereum", public_key=keys.public_key)
59
+
60
+ result = await qs.verify(
61
+ chain="ethereum",
62
+ address="0xYourAddress",
63
+ attestation_id=registered.attestation_id,
64
+ )
65
+ print(f"Verified: {result.verified}")
66
+
67
+ asyncio.run(main())
68
+ ```
69
+
70
+ ## Supported Chains
71
+
72
+ - Ethereum
73
+ - Solana
74
+ - Bitcoin
75
+ - Polygon
76
+ - Avalanche
77
+ - Cosmos
78
+
79
+ ## Documentation
80
+
81
+ Full API docs: [https://docs.qsafe.dev](https://docs.qsafe.dev)
82
+
83
+ ## License
84
+
85
+ MIT — see [LICENSE](./LICENSE)
@@ -0,0 +1,17 @@
1
+ LICENSE
2
+ MANIFEST.in
3
+ README.md
4
+ pyproject.toml
5
+ quantumsafe/__init__.py
6
+ quantumsafe/client.py
7
+ quantumsafe/types.py
8
+ quantumsafe.egg-info/PKG-INFO
9
+ quantumsafe.egg-info/SOURCES.txt
10
+ quantumsafe.egg-info/dependency_links.txt
11
+ quantumsafe.egg-info/requires.txt
12
+ quantumsafe.egg-info/top_level.txt
13
+ quantumsafe/modules/__init__.py
14
+ quantumsafe/modules/keys.py
15
+ quantumsafe/modules/scan.py
16
+ quantumsafe/modules/sign.py
17
+ quantumsafe/modules/verify.py
@@ -0,0 +1,8 @@
1
+ httpx>=0.27.0
2
+ pqcrypto>=0.1.0
3
+
4
+ [dev]
5
+ pytest>=8.0
6
+ pytest-asyncio>=0.23.0
7
+ ruff>=0.4.0
8
+ respx>=0.21.0
@@ -0,0 +1 @@
1
+ quantumsafe
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+