mirror of
https://github.com/bohd4nx/FragmentAPI.git
synced 2026-07-25 14:24:31 +00:00
363e0719ab
- Updated version in pyproject.toml to 2026.2.3. - Refactored wallet utilities: - Moved `clean_decode` and `process_transaction` to `transaction.py`. - Created `balance.py` for balance-related functions. - Created `info.py` for wallet information retrieval. - Created `transfer.py` for sending TON and USDT transfers. - Updated tests to reflect new module structure and imports. - Added new API utility functions for handling Fragment API requests.
95 lines
3.1 KiB
Python
95 lines
3.1 KiB
Python
from __future__ import annotations
|
|
|
|
import json
|
|
from typing import Any, Literal
|
|
|
|
from tonutils.contracts.wallet import WalletV4R2, WalletV5R1
|
|
|
|
# Payment methods
|
|
PaymentMethod = Literal["ton", "usdt_ton"]
|
|
|
|
# Single source of truth for supported wallet versions
|
|
WalletVersion = Literal["V4R2", "V5R1"]
|
|
|
|
# Wallet class map — used to resolve the correct contract from WALLET_VERSION
|
|
WALLET_CLASSES: dict[str, Any] = {"V4R2": WalletV4R2, "V5R1": WalletV5R1}
|
|
|
|
# Minimum TON balance threshold required for payment flows.
|
|
MIN_TON_BALANCE: float = 0.33
|
|
|
|
# USDT (TON) jetton metadata used for payment-method balance checks.
|
|
USDT_TON_MASTER_ADDRESS: str = "EQCxE6mUtQJKFnGfaROTKOt1lZbDiiX1kCixRv7Nw2Id_sDs"
|
|
MIN_USDT_BALANCE: float = 0.75
|
|
|
|
# Default HTTP request timeout in seconds.
|
|
DEFAULT_TIMEOUT: float = 30.0
|
|
|
|
# Required Fragment session cookie keys
|
|
REQUIRED_COOKIE_KEYS: tuple[str, ...] = ("stel_ssid", "stel_dt", "stel_token", "stel_ton_token")
|
|
|
|
# Fragment domain and page URLs
|
|
FRAGMENT_DOMAIN: str = "fragment.com" # for rookiepy
|
|
FRAGMENT_BASE_URL: str = f"https://{FRAGMENT_DOMAIN}"
|
|
STARS_PAGE: str = f"{FRAGMENT_BASE_URL}/stars/buy"
|
|
STARS_GIVEAWAY_PAGE: str = f"{FRAGMENT_BASE_URL}/stars/giveaway"
|
|
PREMIUM_PAGE: str = f"{FRAGMENT_BASE_URL}/premium/gift"
|
|
PREMIUM_GIVEAWAY_PAGE: str = f"{FRAGMENT_BASE_URL}/premium/giveaway"
|
|
ADS_TOPUP_PAGE: str = f"{FRAGMENT_BASE_URL}/ads/topup"
|
|
NUMBERS_PAGE: str = f"{FRAGMENT_BASE_URL}/numbers"
|
|
GIFTS_PAGE: str = f"{FRAGMENT_BASE_URL}/gifts"
|
|
|
|
# Browsers supported by get_cookies_from_browser()
|
|
SUPPORTED_BROWSERS: frozenset[str] = frozenset(
|
|
{
|
|
"arc",
|
|
"brave",
|
|
"chrome",
|
|
"chromium",
|
|
"chromium_based",
|
|
"edge",
|
|
"firefox",
|
|
"firefox_based",
|
|
"librewolf",
|
|
"opera",
|
|
"opera_gx",
|
|
"safari",
|
|
"vivaldi",
|
|
}
|
|
)
|
|
|
|
# Tonkeeper device fingerprint — serialized once, reused in every tx_data payload.
|
|
DEVICE: str = json.dumps(
|
|
{
|
|
"platform": "iphone",
|
|
"appName": "Tonkeeper",
|
|
"appVersion": "26.04.0",
|
|
"maxProtocolVersion": 2,
|
|
"features": [
|
|
"SendTransaction",
|
|
{"name": "SendTransaction", "maxMessages": 255},
|
|
{"name": "SignData", "types": ["text", "binary", "cell"]},
|
|
],
|
|
}
|
|
)
|
|
|
|
# Base HTTP headers — shared across all Fragment API requests.
|
|
# Each method merges these with its own "referer" and "x-aj-referer".
|
|
BASE_HEADERS: dict[str, str] = {
|
|
"accept": "application/json, text/javascript, */*; q=0.01",
|
|
"accept-language": "en-US,en;q=0.9,uk;q=0.8,ru;q=0.7",
|
|
"content-type": "application/x-www-form-urlencoded; charset=UTF-8",
|
|
"origin": FRAGMENT_BASE_URL,
|
|
"priority": "u=1, i",
|
|
"sec-ch-ua": '"Google Chrome";v="147", "Not.A/Brand";v="8", "Chromium";v="147"',
|
|
"sec-ch-ua-mobile": "?1",
|
|
"sec-ch-ua-platform": '"Android"',
|
|
"sec-fetch-dest": "empty",
|
|
"sec-fetch-mode": "cors",
|
|
"sec-fetch-site": "same-origin",
|
|
"user-agent": (
|
|
"Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) "
|
|
"AppleWebKit/537.36 (KHTML, like Gecko) Chrome/147.0.0.0 Mobile Safari/537.36"
|
|
),
|
|
"x-requested-with": "XMLHttpRequest",
|
|
}
|