GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — cortex/src/cortex/wallet.py at main · CortexLM/cortex Expand file tree/ Copy pathwallet.pyMore file actions 78 lines (65 loc) · 2.97 KB / Copy pathwallet.pyFile metadata and controls78 lines (65 loc) · 2.97 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 """Bittensor hotkeys with the distinct Cortex and Substrate signing contexts.""" from __future__ import annotations import hmac import json from dataclasses import dataclass, field from pathlib import Path import sr25519 from cortex.errors import ServiceError from cortex.http import read_private_file from cortex.protocol.crypto import encode_hotkey, sign_raw_keypair from cortex.protocol.scale import ProtocolError, fixed @dataclass(frozen=True) class HotkeySigner: public_key: bytes _secret: bytes = field(repr=False) def __post_init__(self) -> None: fixed(self.public_key, 32) fixed(self._secret, 64) if not hmac.compare_digest(self.public_key, sr25519.public_from_secret_key(self._secret)): raise ProtocolError("sr25519 public key mismatch") @classmethod def from_dev_seed(cls, seed: bytes) -> HotkeySigner: """Raw seeds are only for deterministic local development fixtures.""" public, secret = sr25519.pair_from_seed(fixed(seed, 32)) return cls(public, secret) @property def ss58_address(self) -> str: return encode_hotkey(self.public_key) def sign(self, domain: bytes, payload: bytes) -> bytes: return sign_raw_keypair(self.public_key, self._secret, domain, payload) def sign_substrate(self, payload: bytes) -> bytes: return sr25519.sign((self.public_key, self._secret), payload) def load_wallet_hotkey( *, name: str, hotkey: str, path: str | Path = "~/.bittensor/wallets", password_file: Path | None = None, ) -> HotkeySigner: """Unlock the selected hotkey only; never create or modify wallet files.""" try: from bittensor_wallet import Wallet from bittensor_wallet.keyfile import serialized_keypair_to_keyfile_data except ImportError: raise ServiceError(503, "install cortex-subnet[chain] for Bittensor wallets") from None password = read_private_file(password_file) if password_file is not None else None try: wallet = Wallet(name=name, hotkey=hotkey, path=str(Path(path).expanduser())) if wallet.hotkey_file.is_encrypted() and password is None: raise ServiceError(503, "encrypted Bittensor hotkey password file required") keypair = wallet.get_hotkey(password=password) if keypair.crypto_type != 1: raise ServiceError(503, "Bittensor hotkey must use sr25519") public = keypair.public_key if public is None: raise ServiceError(503, "Bittensor hotkey unavailable") # The SDK serializer supports derived hotkeys without an exportable mini-seed. # Expanded secret material stays in memory and never enters a diagnostic. data = json.loads(serialized_keypair_to_keyfile_data(keypair)) secret = bytes.fromhex(data["privateKey"].removeprefix("0x")) return HotkeySigner(public, secret) except ServiceError: raise except Exception: raise ServiceError(503, "Bittensor hotkey unavailable") from None |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |