nexaroa 0.0.111__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.
- neuroshard/__init__.py +93 -0
- neuroshard/__main__.py +4 -0
- neuroshard/cli.py +466 -0
- neuroshard/core/__init__.py +92 -0
- neuroshard/core/consensus/verifier.py +252 -0
- neuroshard/core/crypto/__init__.py +20 -0
- neuroshard/core/crypto/ecdsa.py +392 -0
- neuroshard/core/economics/__init__.py +52 -0
- neuroshard/core/economics/constants.py +387 -0
- neuroshard/core/economics/ledger.py +2111 -0
- neuroshard/core/economics/market.py +975 -0
- neuroshard/core/economics/wallet.py +168 -0
- neuroshard/core/governance/__init__.py +74 -0
- neuroshard/core/governance/proposal.py +561 -0
- neuroshard/core/governance/registry.py +545 -0
- neuroshard/core/governance/versioning.py +332 -0
- neuroshard/core/governance/voting.py +453 -0
- neuroshard/core/model/__init__.py +30 -0
- neuroshard/core/model/dynamic.py +4186 -0
- neuroshard/core/model/llm.py +905 -0
- neuroshard/core/model/registry.py +164 -0
- neuroshard/core/model/scaler.py +387 -0
- neuroshard/core/model/tokenizer.py +568 -0
- neuroshard/core/network/__init__.py +56 -0
- neuroshard/core/network/connection_pool.py +72 -0
- neuroshard/core/network/dht.py +130 -0
- neuroshard/core/network/dht_plan.py +55 -0
- neuroshard/core/network/dht_proof_store.py +516 -0
- neuroshard/core/network/dht_protocol.py +261 -0
- neuroshard/core/network/dht_service.py +506 -0
- neuroshard/core/network/encrypted_channel.py +141 -0
- neuroshard/core/network/nat.py +201 -0
- neuroshard/core/network/nat_traversal.py +695 -0
- neuroshard/core/network/p2p.py +929 -0
- neuroshard/core/network/p2p_data.py +150 -0
- neuroshard/core/swarm/__init__.py +106 -0
- neuroshard/core/swarm/aggregation.py +729 -0
- neuroshard/core/swarm/buffers.py +643 -0
- neuroshard/core/swarm/checkpoint.py +709 -0
- neuroshard/core/swarm/compute.py +624 -0
- neuroshard/core/swarm/diloco.py +844 -0
- neuroshard/core/swarm/factory.py +1288 -0
- neuroshard/core/swarm/heartbeat.py +669 -0
- neuroshard/core/swarm/logger.py +487 -0
- neuroshard/core/swarm/router.py +658 -0
- neuroshard/core/swarm/service.py +640 -0
- neuroshard/core/training/__init__.py +29 -0
- neuroshard/core/training/checkpoint.py +600 -0
- neuroshard/core/training/distributed.py +1602 -0
- neuroshard/core/training/global_tracker.py +617 -0
- neuroshard/core/training/production.py +276 -0
- neuroshard/governance_cli.py +729 -0
- neuroshard/grpc_server.py +895 -0
- neuroshard/runner.py +3223 -0
- neuroshard/sdk/__init__.py +92 -0
- neuroshard/sdk/client.py +990 -0
- neuroshard/sdk/errors.py +101 -0
- neuroshard/sdk/types.py +282 -0
- neuroshard/tracker/__init__.py +0 -0
- neuroshard/tracker/server.py +864 -0
- neuroshard/ui/__init__.py +0 -0
- neuroshard/ui/app.py +102 -0
- neuroshard/ui/templates/index.html +1052 -0
- neuroshard/utils/__init__.py +0 -0
- neuroshard/utils/autostart.py +81 -0
- neuroshard/utils/hardware.py +121 -0
- neuroshard/utils/serialization.py +90 -0
- neuroshard/version.py +1 -0
- nexaroa-0.0.111.dist-info/METADATA +283 -0
- nexaroa-0.0.111.dist-info/RECORD +78 -0
- nexaroa-0.0.111.dist-info/WHEEL +5 -0
- nexaroa-0.0.111.dist-info/entry_points.txt +4 -0
- nexaroa-0.0.111.dist-info/licenses/LICENSE +190 -0
- nexaroa-0.0.111.dist-info/top_level.txt +2 -0
- protos/__init__.py +0 -0
- protos/neuroshard.proto +651 -0
- protos/neuroshard_pb2.py +160 -0
- protos/neuroshard_pb2_grpc.py +1298 -0
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Wallet Utilities - BIP39 Mnemonic and Key Derivation
|
|
3
|
+
Similar to MetaMask: Users control their own private keys via seed phrases.
|
|
4
|
+
"""
|
|
5
|
+
|
|
6
|
+
from mnemonic import Mnemonic
|
|
7
|
+
import hashlib
|
|
8
|
+
from cryptography.hazmat.primitives.asymmetric import ec
|
|
9
|
+
from cryptography.hazmat.primitives import serialization
|
|
10
|
+
from cryptography.hazmat.backends import default_backend
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class WalletManager:
|
|
14
|
+
"""Manages BIP39 mnemonic seed phrases and key derivation"""
|
|
15
|
+
|
|
16
|
+
def __init__(self):
|
|
17
|
+
self.mnemo = Mnemonic("english")
|
|
18
|
+
|
|
19
|
+
def generate_mnemonic(self, strength: int = 128) -> str:
|
|
20
|
+
"""
|
|
21
|
+
Generate a new BIP39 mnemonic seed phrase.
|
|
22
|
+
|
|
23
|
+
Args:
|
|
24
|
+
strength: Entropy strength in bits (128 = 12 words, 256 = 24 words)
|
|
25
|
+
|
|
26
|
+
Returns:
|
|
27
|
+
12-word mnemonic seed phrase
|
|
28
|
+
"""
|
|
29
|
+
return self.mnemo.generate(strength=strength)
|
|
30
|
+
|
|
31
|
+
def validate_mnemonic(self, mnemonic: str) -> bool:
|
|
32
|
+
"""
|
|
33
|
+
Validate a BIP39 mnemonic seed phrase.
|
|
34
|
+
|
|
35
|
+
Args:
|
|
36
|
+
mnemonic: The seed phrase to validate
|
|
37
|
+
|
|
38
|
+
Returns:
|
|
39
|
+
True if valid, False otherwise
|
|
40
|
+
"""
|
|
41
|
+
return self.mnemo.check(mnemonic)
|
|
42
|
+
|
|
43
|
+
def mnemonic_to_token(self, mnemonic: str) -> str:
|
|
44
|
+
"""
|
|
45
|
+
Derive a node token from a mnemonic seed phrase.
|
|
46
|
+
|
|
47
|
+
Args:
|
|
48
|
+
mnemonic: The BIP39 seed phrase
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
Deterministic node token (hex string)
|
|
52
|
+
"""
|
|
53
|
+
if not self.validate_mnemonic(mnemonic):
|
|
54
|
+
raise ValueError("Invalid mnemonic seed phrase")
|
|
55
|
+
|
|
56
|
+
# Convert mnemonic to seed (deterministic)
|
|
57
|
+
seed = self.mnemo.to_seed(mnemonic, passphrase="")
|
|
58
|
+
|
|
59
|
+
# Use first 32 bytes of seed as token
|
|
60
|
+
# This ensures the token is deterministic from the mnemonic
|
|
61
|
+
token = seed[:32].hex()
|
|
62
|
+
|
|
63
|
+
return token
|
|
64
|
+
|
|
65
|
+
def token_to_node_id(self, token: str) -> str:
|
|
66
|
+
"""
|
|
67
|
+
Derive the public node_id from a token using ECDSA.
|
|
68
|
+
|
|
69
|
+
This matches the derivation in neuroshard/core/crypto.py:
|
|
70
|
+
1. private_key = SHA256(token)
|
|
71
|
+
2. public_key = ECDSA_derive(private_key) on secp256k1
|
|
72
|
+
3. node_id = SHA256(public_key)[:32]
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
token: The node token (hex string or regular string)
|
|
76
|
+
|
|
77
|
+
Returns:
|
|
78
|
+
Public node_id (32-char hex string)
|
|
79
|
+
"""
|
|
80
|
+
# Derive private key from token
|
|
81
|
+
private_key_bytes = hashlib.sha256(token.encode()).digest()
|
|
82
|
+
|
|
83
|
+
# Create ECDSA private key on secp256k1 curve
|
|
84
|
+
private_key = ec.derive_private_key(
|
|
85
|
+
int.from_bytes(private_key_bytes, 'big'),
|
|
86
|
+
ec.SECP256K1(),
|
|
87
|
+
default_backend()
|
|
88
|
+
)
|
|
89
|
+
|
|
90
|
+
# Get compressed public key
|
|
91
|
+
public_key = private_key.public_key()
|
|
92
|
+
public_key_bytes = public_key.public_bytes(
|
|
93
|
+
encoding=serialization.Encoding.X962,
|
|
94
|
+
format=serialization.PublicFormat.CompressedPoint
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
# node_id = SHA256(public_key)[:32]
|
|
98
|
+
node_id = hashlib.sha256(public_key_bytes).hexdigest()[:32]
|
|
99
|
+
|
|
100
|
+
return node_id
|
|
101
|
+
|
|
102
|
+
def create_wallet(self) -> dict:
|
|
103
|
+
"""
|
|
104
|
+
Create a complete new wallet with mnemonic, token, and node_id.
|
|
105
|
+
|
|
106
|
+
Returns:
|
|
107
|
+
{
|
|
108
|
+
'mnemonic': '12-word seed phrase',
|
|
109
|
+
'token': 'node token (PRIVATE - derived from mnemonic)',
|
|
110
|
+
'node_id': 'public wallet address',
|
|
111
|
+
'wallet_id': 'short display ID'
|
|
112
|
+
}
|
|
113
|
+
"""
|
|
114
|
+
# Generate new mnemonic
|
|
115
|
+
mnemonic = self.generate_mnemonic()
|
|
116
|
+
|
|
117
|
+
# Derive token from mnemonic
|
|
118
|
+
token = self.mnemonic_to_token(mnemonic)
|
|
119
|
+
|
|
120
|
+
# Derive public node_id from token
|
|
121
|
+
node_id = self.token_to_node_id(token)
|
|
122
|
+
|
|
123
|
+
# Wallet ID is first 16 chars of node_id (for display)
|
|
124
|
+
wallet_id = node_id[:16]
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
'mnemonic': mnemonic,
|
|
128
|
+
'token': token,
|
|
129
|
+
'node_id': node_id,
|
|
130
|
+
'wallet_id': wallet_id
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
def recover_wallet(self, mnemonic: str) -> dict:
|
|
134
|
+
"""
|
|
135
|
+
Recover wallet from mnemonic seed phrase.
|
|
136
|
+
|
|
137
|
+
Args:
|
|
138
|
+
mnemonic: The 12-word seed phrase
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
{
|
|
142
|
+
'token': 'node token (PRIVATE)',
|
|
143
|
+
'node_id': 'public wallet address',
|
|
144
|
+
'wallet_id': 'short display ID'
|
|
145
|
+
}
|
|
146
|
+
"""
|
|
147
|
+
if not self.validate_mnemonic(mnemonic):
|
|
148
|
+
raise ValueError("Invalid mnemonic seed phrase")
|
|
149
|
+
|
|
150
|
+
# Derive token from mnemonic
|
|
151
|
+
token = self.mnemonic_to_token(mnemonic)
|
|
152
|
+
|
|
153
|
+
# Derive public node_id from token
|
|
154
|
+
node_id = self.token_to_node_id(token)
|
|
155
|
+
|
|
156
|
+
# Wallet ID is first 16 chars of node_id (for display)
|
|
157
|
+
wallet_id = node_id[:16]
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
'token': token,
|
|
161
|
+
'node_id': node_id,
|
|
162
|
+
'wallet_id': wallet_id
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
# Global instance
|
|
167
|
+
wallet_manager = WalletManager()
|
|
168
|
+
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"""
|
|
2
|
+
NeuroShard Governance System
|
|
3
|
+
|
|
4
|
+
This module implements decentralized governance for protocol upgrades.
|
|
5
|
+
|
|
6
|
+
Philosophy:
|
|
7
|
+
===========
|
|
8
|
+
LLM architecture and economics are DEEPLY COUPLED. You cannot change one
|
|
9
|
+
without affecting the other. This governance system ensures:
|
|
10
|
+
|
|
11
|
+
1. TRANSPARENCY: All changes are proposed, reviewed, and voted on
|
|
12
|
+
2. ECONOMIC PARITY: Upgrade paths include economic adjustments
|
|
13
|
+
3. BACKWARD COMPATIBILITY: Grace periods for nodes to upgrade
|
|
14
|
+
4. STAKE-WEIGHTED VOTING: Validators with skin in the game decide
|
|
15
|
+
|
|
16
|
+
NEP (NeuroShard Enhancement Proposal) Types:
|
|
17
|
+
============================================
|
|
18
|
+
- NEP-ARCH: Architecture changes (MLA, MTP, new layers)
|
|
19
|
+
- NEP-ECON: Economic parameter changes (reward rates, fees)
|
|
20
|
+
- NEP-TRAIN: Training algorithm changes (DiLoCo params, gradient handling)
|
|
21
|
+
- NEP-NET: Network protocol changes (gossip, routing)
|
|
22
|
+
|
|
23
|
+
Lifecycle:
|
|
24
|
+
==========
|
|
25
|
+
1. DRAFT → Proposal created, open for discussion
|
|
26
|
+
2. REVIEW → Formal review period (7 days)
|
|
27
|
+
3. VOTING → Stake-weighted voting (7 days)
|
|
28
|
+
4. SCHEDULED → Approved, waiting for activation block
|
|
29
|
+
5. ACTIVE → Live on network
|
|
30
|
+
6. DEPRECATED → Superseded by newer NEP
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
from .proposal import (
|
|
34
|
+
NEP,
|
|
35
|
+
NEPType,
|
|
36
|
+
NEPStatus,
|
|
37
|
+
create_proposal,
|
|
38
|
+
EconomicImpact,
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
from .registry import (
|
|
42
|
+
NEPRegistry,
|
|
43
|
+
get_active_neps,
|
|
44
|
+
get_pending_neps,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
from .voting import (
|
|
48
|
+
cast_vote,
|
|
49
|
+
get_vote_tally,
|
|
50
|
+
VoteResult,
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
from .versioning import (
|
|
54
|
+
ProtocolVersion,
|
|
55
|
+
get_current_version,
|
|
56
|
+
is_compatible,
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
__all__ = [
|
|
60
|
+
'NEP',
|
|
61
|
+
'NEPType',
|
|
62
|
+
'NEPStatus',
|
|
63
|
+
'create_proposal',
|
|
64
|
+
'EconomicImpact',
|
|
65
|
+
'NEPRegistry',
|
|
66
|
+
'get_active_neps',
|
|
67
|
+
'get_pending_neps',
|
|
68
|
+
'cast_vote',
|
|
69
|
+
'get_vote_tally',
|
|
70
|
+
'VoteResult',
|
|
71
|
+
'ProtocolVersion',
|
|
72
|
+
'get_current_version',
|
|
73
|
+
'is_compatible',
|
|
74
|
+
]
|