hotstuff-python-sdk 0.0.1b1__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.
- hotstuff/__init__.py +53 -0
- hotstuff/apis/__init__.py +10 -0
- hotstuff/apis/exchange.py +510 -0
- hotstuff/apis/info.py +291 -0
- hotstuff/apis/subscription.py +278 -0
- hotstuff/methods/__init__.py +10 -0
- hotstuff/methods/exchange/__init__.py +14 -0
- hotstuff/methods/exchange/account.py +120 -0
- hotstuff/methods/exchange/collateral.py +94 -0
- hotstuff/methods/exchange/op_codes.py +28 -0
- hotstuff/methods/exchange/trading.py +117 -0
- hotstuff/methods/exchange/vault.py +59 -0
- hotstuff/methods/info/__init__.py +14 -0
- hotstuff/methods/info/account.py +371 -0
- hotstuff/methods/info/explorer.py +57 -0
- hotstuff/methods/info/global.py +249 -0
- hotstuff/methods/info/vault.py +86 -0
- hotstuff/methods/subscription/__init__.py +8 -0
- hotstuff/methods/subscription/global.py +200 -0
- hotstuff/transports/__init__.py +9 -0
- hotstuff/transports/http.py +142 -0
- hotstuff/transports/websocket.py +401 -0
- hotstuff/types/__init__.py +62 -0
- hotstuff/types/clients.py +34 -0
- hotstuff/types/exchange.py +88 -0
- hotstuff/types/transports.py +110 -0
- hotstuff/utils/__init__.py +13 -0
- hotstuff/utils/address.py +37 -0
- hotstuff/utils/endpoints.py +15 -0
- hotstuff/utils/nonce.py +25 -0
- hotstuff/utils/signing.py +76 -0
- hotstuff_python_sdk-0.0.1b1.dist-info/LICENSE +21 -0
- hotstuff_python_sdk-0.0.1b1.dist-info/METADATA +985 -0
- hotstuff_python_sdk-0.0.1b1.dist-info/RECORD +35 -0
- hotstuff_python_sdk-0.0.1b1.dist-info/WHEEL +4 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"""Utilities package."""
|
|
2
|
+
from hotstuff.utils.endpoints import ENDPOINTS_URLS
|
|
3
|
+
from hotstuff.utils.nonce import NonceManager
|
|
4
|
+
from hotstuff.utils.signing import sign_action
|
|
5
|
+
from hotstuff.methods.exchange.op_codes import EXCHANGE_OP_CODES
|
|
6
|
+
|
|
7
|
+
__all__ = [
|
|
8
|
+
"ENDPOINTS_URLS",
|
|
9
|
+
"NonceManager",
|
|
10
|
+
"sign_action",
|
|
11
|
+
"EXCHANGE_OP_CODES",
|
|
12
|
+
]
|
|
13
|
+
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"""Ethereum address validation utilities."""
|
|
2
|
+
from typing import Annotated
|
|
3
|
+
from pydantic import Field, field_validator
|
|
4
|
+
from eth_utils import is_address, to_checksum_address
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def validate_ethereum_address(value: str) -> str:
|
|
8
|
+
"""
|
|
9
|
+
Validate and normalize an Ethereum address.
|
|
10
|
+
|
|
11
|
+
Args:
|
|
12
|
+
value: The address string to validate
|
|
13
|
+
|
|
14
|
+
Returns:
|
|
15
|
+
Checksummed address string
|
|
16
|
+
|
|
17
|
+
Raises:
|
|
18
|
+
ValueError: If the address is invalid
|
|
19
|
+
"""
|
|
20
|
+
if not isinstance(value, str):
|
|
21
|
+
raise ValueError(f"Address must be a string, got {type(value)}")
|
|
22
|
+
|
|
23
|
+
if not is_address(value):
|
|
24
|
+
raise ValueError(f"Invalid Ethereum address: {value}")
|
|
25
|
+
|
|
26
|
+
return to_checksum_address(value)
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
EthereumAddress = Annotated[
|
|
30
|
+
str,
|
|
31
|
+
Field(
|
|
32
|
+
...,
|
|
33
|
+
description="Ethereum address (validated and checksummed)",
|
|
34
|
+
examples=["0x1234567890123456789012345678901234567890"],
|
|
35
|
+
),
|
|
36
|
+
field_validator('*', mode='before')(validate_ethereum_address),
|
|
37
|
+
]
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"""Endpoint URLs configuration."""
|
|
2
|
+
|
|
3
|
+
ENDPOINTS_URLS = {
|
|
4
|
+
"mainnet": {
|
|
5
|
+
"api": "https://testnet-api.hotstuff.trade/",
|
|
6
|
+
"rpc": "https://rpc.hotstuff.trade/",
|
|
7
|
+
"ws": "wss://testnet-api.hotstuff.trade/ws/",
|
|
8
|
+
},
|
|
9
|
+
"testnet": {
|
|
10
|
+
"api": "https://testnet-api.hotstuff.trade/",
|
|
11
|
+
"rpc": "https://testnet-api.hotstuff.trade/",
|
|
12
|
+
"ws": "wss://testnet-api.hotstuff.trade/ws/",
|
|
13
|
+
},
|
|
14
|
+
}
|
|
15
|
+
|
hotstuff/utils/nonce.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"""Nonce management utility."""
|
|
2
|
+
import time
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
class NonceManager:
|
|
6
|
+
"""Manages nonces for transactions."""
|
|
7
|
+
|
|
8
|
+
def __init__(self):
|
|
9
|
+
"""Initialize the nonce manager."""
|
|
10
|
+
self._last_nonce = 0
|
|
11
|
+
|
|
12
|
+
async def get_nonce(self) -> int:
|
|
13
|
+
"""
|
|
14
|
+
Get a new nonce.
|
|
15
|
+
|
|
16
|
+
Returns:
|
|
17
|
+
int: A new nonce value
|
|
18
|
+
"""
|
|
19
|
+
current_time = int(time.time() * 1000)
|
|
20
|
+
if current_time <= self._last_nonce:
|
|
21
|
+
self._last_nonce += 1
|
|
22
|
+
else:
|
|
23
|
+
self._last_nonce = current_time
|
|
24
|
+
return self._last_nonce
|
|
25
|
+
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"""Signing utilities for EIP-712 typed data."""
|
|
2
|
+
import msgpack
|
|
3
|
+
from eth_account import Account
|
|
4
|
+
from eth_account.messages import encode_structured_data
|
|
5
|
+
from eth_utils import keccak
|
|
6
|
+
from hotstuff.methods.exchange.op_codes import EXCHANGE_OP_CODES
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
async def sign_action(
|
|
10
|
+
wallet: Account,
|
|
11
|
+
action: dict,
|
|
12
|
+
tx_type: int,
|
|
13
|
+
is_testnet: bool = False
|
|
14
|
+
) -> str:
|
|
15
|
+
"""
|
|
16
|
+
Sign an action using EIP-712.
|
|
17
|
+
|
|
18
|
+
Args:
|
|
19
|
+
wallet: The account to sign with
|
|
20
|
+
action: The action data
|
|
21
|
+
tx_type: The transaction type code
|
|
22
|
+
is_testnet: Whether this is for testnet
|
|
23
|
+
|
|
24
|
+
Returns:
|
|
25
|
+
str: The signature
|
|
26
|
+
"""
|
|
27
|
+
# Encode action to msgpack
|
|
28
|
+
action_bytes = msgpack.packb(action)
|
|
29
|
+
|
|
30
|
+
# Hash the payload
|
|
31
|
+
payload_hash = keccak(action_bytes)
|
|
32
|
+
|
|
33
|
+
# EIP-712 domain
|
|
34
|
+
domain = {
|
|
35
|
+
"name": "HotstuffCore",
|
|
36
|
+
"version": "1",
|
|
37
|
+
"chainId": 1,
|
|
38
|
+
"verifyingContract": "0x1234567890123456789012345678901234567890",
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
# EIP-712 types
|
|
42
|
+
types = {
|
|
43
|
+
"EIP712Domain": [
|
|
44
|
+
{"name": "name", "type": "string"},
|
|
45
|
+
{"name": "version", "type": "string"},
|
|
46
|
+
{"name": "chainId", "type": "uint256"},
|
|
47
|
+
{"name": "verifyingContract", "type": "address"},
|
|
48
|
+
],
|
|
49
|
+
"Action": [
|
|
50
|
+
{"name": "source", "type": "string"},
|
|
51
|
+
{"name": "hash", "type": "bytes32"},
|
|
52
|
+
{"name": "txType", "type": "uint16"},
|
|
53
|
+
],
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
# Message
|
|
57
|
+
message = {
|
|
58
|
+
"source": "Testnet" if is_testnet else "Mainnet",
|
|
59
|
+
"hash": payload_hash,
|
|
60
|
+
"txType": tx_type,
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
# Create structured data
|
|
64
|
+
structured_data = {
|
|
65
|
+
"types": types,
|
|
66
|
+
"primaryType": "Action",
|
|
67
|
+
"domain": domain,
|
|
68
|
+
"message": message,
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
# Encode and sign
|
|
72
|
+
encoded_data = encode_structured_data(structured_data)
|
|
73
|
+
signed_message = wallet.sign_message(encoded_data)
|
|
74
|
+
|
|
75
|
+
return signed_message.signature.hex()
|
|
76
|
+
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Hotstuff Labs
|
|
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.
|