37 lines
1.0 KiB
Python
37 lines
1.0 KiB
Python
from os import getenv, urandom
|
|
import os
|
|
|
|
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.logger import make_log
|
|
|
|
|
|
def _load_seed_from_env_or_generate() -> bytes:
|
|
seed_hex = os.getenv("TON_INIT_HOT_SEED")
|
|
if seed_hex:
|
|
make_log("HotWallet", "Loaded seed from env")
|
|
return bytes.fromhex(seed_hex)
|
|
make_log("HotWallet", "No seed provided; generating ephemeral seed", level='info')
|
|
return urandom(32)
|
|
|
|
|
|
_extra_ton_wallet_options = {}
|
|
if getenv('TON_CUSTOM_WALLET_ADDRESS'):
|
|
_extra_ton_wallet_options['address'] = Address(getenv('TON_CUSTOM_WALLET_ADDRESS'))
|
|
|
|
|
|
def _init_wallet():
|
|
hot_seed_bytes = _load_seed_from_env_or_generate()
|
|
pub, priv = crypto_sign_seed_keypair(hot_seed_bytes)
|
|
wallet = WalletV3CR3(
|
|
private_key=priv,
|
|
public_key=pub,
|
|
**_extra_ton_wallet_options
|
|
)
|
|
return hot_seed_bytes, pub, priv, wallet
|
|
|
|
|
|
hot_seed, hot_pubkey, hot_privkey, service_wallet = _init_wallet()
|