from os import getenv, urandom from nacl.bindings import crypto_sign_seed_keypair from tonsdk.utils import Address from app.core._blockchain.ton.wallet_v3cr3 import WalletV3CR3 from app.core.models._config import ServiceConfig from app.core.storage import db_session from app.core.logger import make_log import os def load_hot_pair(): with db_session() as session: service_config = ServiceConfig(session) hot_seed = service_config.get('private_key') if hot_seed is None: make_log("HotWallet", "No seed found, generating new one", level='info') hot_seed = os.getenv("TON_INIT_HOT_SEED") if not hot_seed: hot_seed = urandom(32) make_log("HotWallet", f"Generated random seed") else: hot_seed = bytes.fromhex(hot_seed) make_log("HotWallet", f"Loaded seed from env") service_config.set('private_key', hot_seed.hex()) return load_hot_pair() hot_seed = bytes.fromhex(hot_seed) public_key, private_key = crypto_sign_seed_keypair(hot_seed) return hot_seed, public_key, private_key _extra_ton_wallet_options = {} if getenv('TON_CUSTOM_WALLET_ADDRESS'): _extra_ton_wallet_options['address'] = Address(getenv('TON_CUSTOM_WALLET_ADDRESS')) hot_seed, hot_pubkey, hot_privkey = load_hot_pair() service_wallet = WalletV3CR3( private_key=hot_privkey, public_key=hot_pubkey, **_extra_ton_wallet_options )